Add surplus and debt auction lot params (#531)

* wip: add lot size param for surplus and debt auctions

* update tests with new params

* update spec

* address review comments
This commit is contained in:
Kevin Davis 2020-05-31 09:59:40 -04:00 committed by GitHub
parent 2ea06e4c80
commit 5336ccc0c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 185 additions and 18 deletions

View File

@ -103,6 +103,7 @@ var (
ErrLoadingAugmentedCDP = types.ErrLoadingAugmentedCDP ErrLoadingAugmentedCDP = types.ErrLoadingAugmentedCDP
ErrInvalidDebtRequest = types.ErrInvalidDebtRequest ErrInvalidDebtRequest = types.ErrInvalidDebtRequest
ErrDenomPrefixNotFound = types.ErrDenomPrefixNotFound ErrDenomPrefixNotFound = types.ErrDenomPrefixNotFound
ErrPricefeedDown = types.ErrPricefeedDown
CdpIDKeyPrefix = types.CdpIDKeyPrefix CdpIDKeyPrefix = types.CdpIDKeyPrefix
CdpKeyPrefix = types.CdpKeyPrefix CdpKeyPrefix = types.CdpKeyPrefix
CollateralRatioIndexPrefix = types.CollateralRatioIndexPrefix CollateralRatioIndexPrefix = types.CollateralRatioIndexPrefix
@ -112,13 +113,16 @@ var (
DepositKeyPrefix = types.DepositKeyPrefix DepositKeyPrefix = types.DepositKeyPrefix
PrincipalKeyPrefix = types.PrincipalKeyPrefix PrincipalKeyPrefix = types.PrincipalKeyPrefix
PreviousDistributionTimeKey = types.PreviousDistributionTimeKey PreviousDistributionTimeKey = types.PreviousDistributionTimeKey
PricefeedStatusKeyPrefix = types.PricefeedStatusKeyPrefix
KeyGlobalDebtLimit = types.KeyGlobalDebtLimit KeyGlobalDebtLimit = types.KeyGlobalDebtLimit
KeyCollateralParams = types.KeyCollateralParams KeyCollateralParams = types.KeyCollateralParams
KeyDebtParam = types.KeyDebtParam KeyDebtParam = types.KeyDebtParam
KeyDistributionFrequency = types.KeyDistributionFrequency KeyDistributionFrequency = types.KeyDistributionFrequency
KeyCircuitBreaker = types.KeyCircuitBreaker KeyCircuitBreaker = types.KeyCircuitBreaker
KeyDebtThreshold = types.KeyDebtThreshold KeyDebtThreshold = types.KeyDebtThreshold
KeyDebtLot = types.KeyDebtLot
KeySurplusThreshold = types.KeySurplusThreshold KeySurplusThreshold = types.KeySurplusThreshold
KeySurplusLot = types.KeySurplusLot
DefaultGlobalDebt = types.DefaultGlobalDebt DefaultGlobalDebt = types.DefaultGlobalDebt
DefaultCircuitBreaker = types.DefaultCircuitBreaker DefaultCircuitBreaker = types.DefaultCircuitBreaker
DefaultCollateralParams = types.DefaultCollateralParams DefaultCollateralParams = types.DefaultCollateralParams
@ -129,6 +133,8 @@ var (
DefaultStableDenom = types.DefaultStableDenom DefaultStableDenom = types.DefaultStableDenom
DefaultSurplusThreshold = types.DefaultSurplusThreshold DefaultSurplusThreshold = types.DefaultSurplusThreshold
DefaultDebtThreshold = types.DefaultDebtThreshold DefaultDebtThreshold = types.DefaultDebtThreshold
DefaultSurplusLot = types.DefaultSurplusLot
DefaultDebtLot = types.DefaultDebtLot
DefaultPreviousDistributionTime = types.DefaultPreviousDistributionTime DefaultPreviousDistributionTime = types.DefaultPreviousDistributionTime
DefaultSavingsDistributionFrequency = types.DefaultSavingsDistributionFrequency DefaultSavingsDistributionFrequency = types.DefaultSavingsDistributionFrequency
MaxSortableDec = types.MaxSortableDec MaxSortableDec = types.MaxSortableDec

View File

@ -42,7 +42,9 @@ func NewCDPGenState(asset string, liquidationRatio sdk.Dec) app.GenesisState {
Params: cdp.Params{ Params: cdp.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, SurplusAuctionThreshold: cdp.DefaultSurplusThreshold,
SurplusAuctionLot: cdp.DefaultSurplusLot,
DebtAuctionThreshold: cdp.DefaultDebtThreshold, DebtAuctionThreshold: cdp.DefaultDebtThreshold,
DebtAuctionLot: cdp.DefaultDebtLot,
SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency,
CollateralParams: cdp.CollateralParams{ CollateralParams: cdp.CollateralParams{
{ {
@ -105,7 +107,9 @@ func NewCDPGenStateMulti() app.GenesisState {
Params: cdp.Params{ Params: cdp.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, SurplusAuctionThreshold: cdp.DefaultSurplusThreshold,
SurplusAuctionLot: cdp.DefaultSurplusLot,
DebtAuctionThreshold: cdp.DefaultDebtThreshold, DebtAuctionThreshold: cdp.DefaultDebtThreshold,
DebtAuctionLot: cdp.DefaultDebtLot,
SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency,
CollateralParams: cdp.CollateralParams{ CollateralParams: cdp.CollateralParams{
{ {

View File

@ -109,7 +109,10 @@ func (k Keeper) RunSurplusAndDebtAuctions(ctx sdk.Context) error {
remainingDebt := k.GetTotalDebt(ctx, types.LiquidatorMacc) remainingDebt := k.GetTotalDebt(ctx, types.LiquidatorMacc)
params := k.GetParams(ctx) params := k.GetParams(ctx)
if remainingDebt.GTE(params.DebtAuctionThreshold) { if remainingDebt.GTE(params.DebtAuctionThreshold) {
_, err := k.auctionKeeper.StartDebtAuction(ctx, types.LiquidatorMacc, sdk.NewCoin("usdx", remainingDebt), sdk.NewCoin(k.GetGovDenom(ctx), remainingDebt.Mul(sdk.NewInt(dump))), sdk.NewCoin(k.GetDebtDenom(ctx), remainingDebt)) debtLot := sdk.NewCoin(k.GetDebtDenom(ctx), params.DebtAuctionLot)
bidCoin := sdk.NewCoin(params.DebtParam.Denom, debtLot.Amount)
_, err := k.auctionKeeper.StartDebtAuction(
ctx, types.LiquidatorMacc, bidCoin, sdk.NewCoin(k.GetGovDenom(ctx), debtLot.Amount.Mul(sdk.NewInt(dump))), debtLot)
if err != nil { if err != nil {
return err return err
} }
@ -119,7 +122,7 @@ func (k Keeper) RunSurplusAndDebtAuctions(ctx sdk.Context) error {
if !surplus.GTE(params.SurplusAuctionThreshold) { if !surplus.GTE(params.SurplusAuctionThreshold) {
return nil return nil
} }
surplusLot := sdk.NewCoin(params.DebtParam.Denom, surplus) surplusLot := sdk.NewCoin(params.DebtParam.Denom, sdk.MinInt(params.SurplusAuctionLot, surplus))
_, err := k.auctionKeeper.StartSurplusAuction(ctx, types.LiquidatorMacc, surplusLot, k.GetGovDenom(ctx)) _, err := k.auctionKeeper.StartSurplusAuction(ctx, types.LiquidatorMacc, surplusLot, k.GetGovDenom(ctx))
return err return err
} }

View File

@ -53,24 +53,28 @@ func (suite *AuctionTestSuite) TestNetDebtSurplus() {
func (suite *AuctionTestSuite) TestSurplusAuction() { func (suite *AuctionTestSuite) TestSurplusAuction() {
sk := suite.app.GetSupplyKeeper() sk := suite.app.GetSupplyKeeper()
err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 10000000000))) err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 600000000000)))
suite.NoError(err) suite.NoError(err)
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 1000000000))) err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 100000000000)))
suite.NoError(err) suite.NoError(err)
suite.keeper.RunSurplusAndDebtAuctions(suite.ctx) suite.keeper.RunSurplusAndDebtAuctions(suite.ctx)
acc := sk.GetModuleAccount(suite.ctx, auction.ModuleName) acc := sk.GetModuleAccount(suite.ctx, auction.ModuleName)
suite.Equal(cs(c("usdx", 9000000000)), acc.GetCoins()) suite.Equal(cs(c("usdx", 10000000000)), acc.GetCoins())
acc = sk.GetModuleAccount(suite.ctx, types.LiquidatorMacc)
suite.Equal(cs(c("usdx", 490000000000)), acc.GetCoins())
} }
func (suite *AuctionTestSuite) TestDebtAuction() { func (suite *AuctionTestSuite) TestDebtAuction() {
sk := suite.app.GetSupplyKeeper() sk := suite.app.GetSupplyKeeper()
err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 1000000000))) err := sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("usdx", 100000000000)))
suite.NoError(err) suite.NoError(err)
err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 10000000000))) err = sk.MintCoins(suite.ctx, types.LiquidatorMacc, cs(c("debt", 200000000000)))
suite.NoError(err) suite.NoError(err)
suite.keeper.RunSurplusAndDebtAuctions(suite.ctx) suite.keeper.RunSurplusAndDebtAuctions(suite.ctx)
acc := sk.GetModuleAccount(suite.ctx, auction.ModuleName) acc := sk.GetModuleAccount(suite.ctx, auction.ModuleName)
suite.Equal(cs(c("debt", 9000000000)), acc.GetCoins()) suite.Equal(cs(c("debt", 10000000000)), acc.GetCoins())
acc = sk.GetModuleAccount(suite.ctx, types.LiquidatorMacc)
suite.Equal(cs(c("debt", 90000000000)), acc.GetCoins())
} }
func TestAuctionTestSuite(t *testing.T) { func TestAuctionTestSuite(t *testing.T) {

View File

@ -42,7 +42,9 @@ func NewCDPGenState(asset string, liquidationRatio sdk.Dec) app.GenesisState {
Params: cdp.Params{ Params: cdp.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, SurplusAuctionThreshold: cdp.DefaultSurplusThreshold,
SurplusAuctionLot: cdp.DefaultSurplusLot,
DebtAuctionThreshold: cdp.DefaultDebtThreshold, DebtAuctionThreshold: cdp.DefaultDebtThreshold,
DebtAuctionLot: cdp.DefaultDebtLot,
SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency,
CollateralParams: cdp.CollateralParams{ CollateralParams: cdp.CollateralParams{
{ {
@ -105,7 +107,9 @@ func NewCDPGenStateMulti() app.GenesisState {
Params: cdp.Params{ Params: cdp.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, SurplusAuctionThreshold: cdp.DefaultSurplusThreshold,
SurplusAuctionLot: cdp.DefaultSurplusLot,
DebtAuctionThreshold: cdp.DefaultDebtThreshold, DebtAuctionThreshold: cdp.DefaultDebtThreshold,
DebtAuctionLot: cdp.DefaultDebtLot,
SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency,
CollateralParams: cdp.CollateralParams{ CollateralParams: cdp.CollateralParams{
{ {
@ -155,7 +159,9 @@ func NewCDPGenStateHighDebtLimit() app.GenesisState {
Params: cdp.Params{ Params: cdp.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000), GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000),
SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, SurplusAuctionThreshold: cdp.DefaultSurplusThreshold,
SurplusAuctionLot: cdp.DefaultSurplusLot,
DebtAuctionThreshold: cdp.DefaultDebtThreshold, DebtAuctionThreshold: cdp.DefaultDebtThreshold,
DebtAuctionLot: cdp.DefaultDebtLot,
SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency,
CollateralParams: cdp.CollateralParams{ CollateralParams: cdp.CollateralParams{
{ {

View File

@ -72,6 +72,8 @@ func randomCdpGenState(selection int) types.GenesisState {
Params: types.Params{ Params: types.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000), GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000),
SurplusAuctionThreshold: types.DefaultSurplusThreshold, SurplusAuctionThreshold: types.DefaultSurplusThreshold,
SurplusAuctionLot: types.DefaultSurplusLot,
DebtAuctionLot: types.DefaultDebtLot,
DebtAuctionThreshold: types.DefaultDebtThreshold, DebtAuctionThreshold: types.DefaultDebtThreshold,
SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency, SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency,
CollateralParams: types.CollateralParams{ CollateralParams: types.CollateralParams{
@ -132,6 +134,8 @@ func randomCdpGenState(selection int) types.GenesisState {
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000), GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000),
SurplusAuctionThreshold: types.DefaultSurplusThreshold, SurplusAuctionThreshold: types.DefaultSurplusThreshold,
DebtAuctionThreshold: types.DefaultDebtThreshold, DebtAuctionThreshold: types.DefaultDebtThreshold,
SurplusAuctionLot: types.DefaultSurplusLot,
DebtAuctionLot: types.DefaultDebtLot,
SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency, SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency,
CollateralParams: types.CollateralParams{ CollateralParams: types.CollateralParams{
{ {

View File

@ -8,7 +8,11 @@ The cdp module contains the following parameters:
| DebtParams | DebtParam | {see below} | array of params for each enabled pegged asset | | DebtParams | DebtParam | {see below} | array of params for each enabled pegged asset |
| GlobalDebtLimit | coin | {"denom":"usdx","amount":"1000"} | maximum pegged assets that can be minted across the whole system | | GlobalDebtLimit | coin | {"denom":"usdx","amount":"1000"} | maximum pegged assets that can be minted across the whole system |
| SavingsDistributionFrequency | string (int) | "84600" | number of seconds between distribution of the savings rate | | SavingsDistributionFrequency | string (int) | "84600" | number of seconds between distribution of the savings rate |
| CircuitBreaker | bool | false | flag to disable user interactions with the system | | GlobalDebtLimit | coin | {"denom":"usdx","amount":"1000"} | maximum pegged assets that can be minted across the whole system |
| DebtAuctionThreshold | string (int) | "100000000000" | amount of system debt before a debt auction is triggered |
| SurplusAuctionThreshold | string (int) | "100000000000" | amount of system surplus before a surplus auction is triggered |
| DebtAuctionLot | string (int) | "10000000000" | amount of debt that each debt auction will attempt to recoup |
| SurplusAuctionLot | string (int) | "10000000000" | amount of surplus that will be sold at each surplus auction |
Each CollateralParam has the following parameters: Each CollateralParam has the following parameters:

View File

@ -20,7 +20,9 @@ var (
KeyDistributionFrequency = []byte("DistributionFrequency") KeyDistributionFrequency = []byte("DistributionFrequency")
KeyCircuitBreaker = []byte("CircuitBreaker") KeyCircuitBreaker = []byte("CircuitBreaker")
KeyDebtThreshold = []byte("DebtThreshold") KeyDebtThreshold = []byte("DebtThreshold")
KeyDebtLot = []byte("DebtLot")
KeySurplusThreshold = []byte("SurplusThreshold") KeySurplusThreshold = []byte("SurplusThreshold")
KeySurplusLot = []byte("SurplusLot")
DefaultGlobalDebt = sdk.NewCoin(DefaultStableDenom, sdk.ZeroInt()) DefaultGlobalDebt = sdk.NewCoin(DefaultStableDenom, sdk.ZeroInt())
DefaultCircuitBreaker = false DefaultCircuitBreaker = false
DefaultCollateralParams = CollateralParams{} DefaultCollateralParams = CollateralParams{}
@ -35,8 +37,10 @@ var (
DefaultDebtDenom = "debt" DefaultDebtDenom = "debt"
DefaultGovDenom = "ukava" DefaultGovDenom = "ukava"
DefaultStableDenom = "usdx" DefaultStableDenom = "usdx"
DefaultSurplusThreshold = sdk.NewInt(1000000000) DefaultSurplusThreshold = sdk.NewInt(500000000000)
DefaultDebtThreshold = sdk.NewInt(1000000000) DefaultDebtThreshold = sdk.NewInt(100000000000)
DefaultSurplusLot = sdk.NewInt(10000000000)
DefaultDebtLot = sdk.NewInt(10000000000)
DefaultPreviousDistributionTime = tmtime.Canonical(time.Unix(0, 0)) DefaultPreviousDistributionTime = tmtime.Canonical(time.Unix(0, 0))
DefaultSavingsDistributionFrequency = time.Hour * 12 DefaultSavingsDistributionFrequency = time.Hour * 12
minCollateralPrefix = 0 minCollateralPrefix = 0
@ -50,7 +54,9 @@ type Params struct {
DebtParam DebtParam `json:"debt_param" yaml:"debt_param"` DebtParam DebtParam `json:"debt_param" yaml:"debt_param"`
GlobalDebtLimit sdk.Coin `json:"global_debt_limit" yaml:"global_debt_limit"` GlobalDebtLimit sdk.Coin `json:"global_debt_limit" yaml:"global_debt_limit"`
SurplusAuctionThreshold sdk.Int `json:"surplus_auction_threshold" yaml:"surplus_auction_threshold"` SurplusAuctionThreshold sdk.Int `json:"surplus_auction_threshold" yaml:"surplus_auction_threshold"`
SurplusAuctionLot sdk.Int `json:"surplus_auction_lot" yaml:"surplus_auction_lot"`
DebtAuctionThreshold sdk.Int `json:"debt_auction_threshold" yaml:"debt_auction_threshold"` DebtAuctionThreshold sdk.Int `json:"debt_auction_threshold" yaml:"debt_auction_threshold"`
DebtAuctionLot sdk.Int `json:"debt_auction_lot" yaml:"debt_auction_lot"`
SavingsDistributionFrequency time.Duration `json:"savings_distribution_frequency" yaml:"savings_distribution_frequency"` SavingsDistributionFrequency time.Duration `json:"savings_distribution_frequency" yaml:"savings_distribution_frequency"`
CircuitBreaker bool `json:"circuit_breaker" yaml:"circuit_breaker"` CircuitBreaker bool `json:"circuit_breaker" yaml:"circuit_breaker"`
} }
@ -62,21 +68,29 @@ func (p Params) String() string {
Collateral Params: %s Collateral Params: %s
Debt Params: %s Debt Params: %s
Surplus Auction Threshold: %s Surplus Auction Threshold: %s
Surplus Auction Lot: %s
Debt Auction Threshold: %s Debt Auction Threshold: %s
Debt Auction Lot: %s
Savings Distribution Frequency: %s Savings Distribution Frequency: %s
Circuit Breaker: %t`, Circuit Breaker: %t`,
p.GlobalDebtLimit, p.CollateralParams, p.DebtParam, p.SurplusAuctionThreshold, p.DebtAuctionThreshold, p.SavingsDistributionFrequency, p.CircuitBreaker, p.GlobalDebtLimit, p.CollateralParams, p.DebtParam, p.SurplusAuctionThreshold, p.SurplusAuctionLot,
p.DebtAuctionThreshold, p.DebtAuctionLot, p.SavingsDistributionFrequency, p.CircuitBreaker,
) )
} }
// NewParams returns a new params object // NewParams returns a new params object
func NewParams(debtLimit sdk.Coin, collateralParams CollateralParams, debtParam DebtParam, surplusThreshold sdk.Int, debtThreshold sdk.Int, distributionFreq time.Duration, breaker bool) Params { func NewParams(
debtLimit sdk.Coin, collateralParams CollateralParams, debtParam DebtParam, surplusThreshold,
surplusLot, debtThreshold, debtLot sdk.Int, distributionFreq time.Duration, breaker bool,
) Params {
return Params{ return Params{
GlobalDebtLimit: debtLimit, GlobalDebtLimit: debtLimit,
CollateralParams: collateralParams, CollateralParams: collateralParams,
DebtParam: debtParam, DebtParam: debtParam,
DebtAuctionThreshold: debtThreshold,
SurplusAuctionThreshold: surplusThreshold, SurplusAuctionThreshold: surplusThreshold,
SurplusAuctionLot: surplusLot,
DebtAuctionThreshold: debtThreshold,
DebtAuctionLot: debtLot,
SavingsDistributionFrequency: distributionFreq, SavingsDistributionFrequency: distributionFreq,
CircuitBreaker: breaker, CircuitBreaker: breaker,
} }
@ -84,7 +98,11 @@ func NewParams(debtLimit sdk.Coin, collateralParams CollateralParams, debtParam
// DefaultParams returns default params for cdp module // DefaultParams returns default params for cdp module
func DefaultParams() Params { func DefaultParams() Params {
return NewParams(DefaultGlobalDebt, DefaultCollateralParams, DefaultDebtParam, DefaultSurplusThreshold, DefaultDebtThreshold, DefaultSavingsDistributionFrequency, DefaultCircuitBreaker) return NewParams(
DefaultGlobalDebt, DefaultCollateralParams, DefaultDebtParam, DefaultSurplusThreshold,
DefaultSurplusLot, DefaultDebtThreshold, DefaultDebtLot, DefaultSavingsDistributionFrequency,
DefaultCircuitBreaker,
)
} }
// CollateralParam governance parameters for each collateral type within the cdp module // CollateralParam governance parameters for each collateral type within the cdp module
@ -175,7 +193,9 @@ func (p *Params) ParamSetPairs() params.ParamSetPairs {
params.NewParamSetPair(KeyDebtParam, &p.DebtParam, validateDebtParam), params.NewParamSetPair(KeyDebtParam, &p.DebtParam, validateDebtParam),
params.NewParamSetPair(KeyCircuitBreaker, &p.CircuitBreaker, validateCircuitBreakerParam), params.NewParamSetPair(KeyCircuitBreaker, &p.CircuitBreaker, validateCircuitBreakerParam),
params.NewParamSetPair(KeySurplusThreshold, &p.SurplusAuctionThreshold, validateSurplusAuctionThresholdParam), params.NewParamSetPair(KeySurplusThreshold, &p.SurplusAuctionThreshold, validateSurplusAuctionThresholdParam),
params.NewParamSetPair(KeySurplusLot, &p.SurplusAuctionLot, validateSurplusAuctionLotParam),
params.NewParamSetPair(KeyDebtThreshold, &p.DebtAuctionThreshold, validateDebtAuctionThresholdParam), params.NewParamSetPair(KeyDebtThreshold, &p.DebtAuctionThreshold, validateDebtAuctionThresholdParam),
params.NewParamSetPair(KeyDebtLot, &p.DebtAuctionLot, validateDebtAuctionLotParam),
params.NewParamSetPair(KeyDistributionFrequency, &p.SavingsDistributionFrequency, validateSavingsDistributionFrequencyParam), params.NewParamSetPair(KeyDistributionFrequency, &p.SavingsDistributionFrequency, validateSavingsDistributionFrequencyParam),
} }
} }
@ -202,10 +222,18 @@ func (p Params) Validate() error {
return err return err
} }
if err := validateSurplusAuctionLotParam(p.SurplusAuctionLot); err != nil {
return err
}
if err := validateDebtAuctionThresholdParam(p.DebtAuctionThreshold); err != nil { if err := validateDebtAuctionThresholdParam(p.DebtAuctionThreshold); err != nil {
return err return err
} }
if err := validateDebtAuctionLotParam(p.DebtAuctionLot); err != nil {
return err
}
if err := validateSavingsDistributionFrequencyParam(p.SavingsDistributionFrequency); err != nil { if err := validateSavingsDistributionFrequencyParam(p.SavingsDistributionFrequency); err != nil {
return err return err
} }
@ -360,6 +388,19 @@ func validateSurplusAuctionThresholdParam(i interface{}) error {
return nil return nil
} }
func validateSurplusAuctionLotParam(i interface{}) error {
sal, ok := i.(sdk.Int)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if !sal.IsPositive() {
return fmt.Errorf("surplus auction lot should be positive: %s", sal)
}
return nil
}
func validateDebtAuctionThresholdParam(i interface{}) error { func validateDebtAuctionThresholdParam(i interface{}) error {
dat, ok := i.(sdk.Int) dat, ok := i.(sdk.Int)
if !ok { if !ok {
@ -373,6 +414,19 @@ func validateDebtAuctionThresholdParam(i interface{}) error {
return nil return nil
} }
func validateDebtAuctionLotParam(i interface{}) error {
dal, ok := i.(sdk.Int)
if !ok {
return fmt.Errorf("invalid parameter type: %T", i)
}
if !dal.IsPositive() {
return fmt.Errorf("debt auction lot should be positive: %s", dal)
}
return nil
}
func validateSavingsDistributionFrequencyParam(i interface{}) error { func validateSavingsDistributionFrequencyParam(i interface{}) error {
sdf, ok := i.(time.Duration) sdf, ok := i.(time.Duration)
if !ok { if !ok {

View File

@ -25,7 +25,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
collateralParams types.CollateralParams collateralParams types.CollateralParams
debtParam types.DebtParam debtParam types.DebtParam
surplusThreshold sdk.Int surplusThreshold sdk.Int
surplusLot sdk.Int
debtThreshold sdk.Int debtThreshold sdk.Int
debtLot sdk.Int
distributionFreq time.Duration distributionFreq time.Duration
breaker bool breaker bool
} }
@ -46,7 +48,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
collateralParams: types.DefaultCollateralParams, collateralParams: types.DefaultCollateralParams,
debtParam: types.DefaultDebtParam, debtParam: types.DefaultDebtParam,
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -81,7 +85,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -116,7 +122,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -151,7 +159,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -198,7 +208,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -245,7 +257,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -292,7 +306,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -327,7 +343,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -362,7 +380,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -409,7 +429,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -456,7 +478,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -491,7 +515,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -526,7 +552,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -561,7 +589,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -596,7 +626,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -631,7 +663,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("0.95"), SavingsRate: sdk.MustNewDecFromStr("0.95"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -666,7 +700,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
SavingsRate: sdk.MustNewDecFromStr("1.05"), SavingsRate: sdk.MustNewDecFromStr("1.05"),
}, },
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -682,7 +718,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
collateralParams: types.DefaultCollateralParams, collateralParams: types.DefaultCollateralParams,
debtParam: types.DefaultDebtParam, debtParam: types.DefaultDebtParam,
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -698,7 +736,9 @@ func (suite *ParamsTestSuite) TestParamValidation() {
collateralParams: types.DefaultCollateralParams, collateralParams: types.DefaultCollateralParams,
debtParam: types.DefaultDebtParam, debtParam: types.DefaultDebtParam,
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: time.Second * 0, distributionFreq: time.Second * 0,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -708,13 +748,15 @@ func (suite *ParamsTestSuite) TestParamValidation() {
}, },
}, },
{ {
name: "zero surplus auction", name: "zero surplus auction threshold",
args: args{ args: args{
globalDebtLimit: types.DefaultGlobalDebt, globalDebtLimit: types.DefaultGlobalDebt,
collateralParams: types.DefaultCollateralParams, collateralParams: types.DefaultCollateralParams,
debtParam: types.DefaultDebtParam, debtParam: types.DefaultDebtParam,
surplusThreshold: sdk.ZeroInt(), surplusThreshold: sdk.ZeroInt(),
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold, debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -724,13 +766,15 @@ func (suite *ParamsTestSuite) TestParamValidation() {
}, },
}, },
{ {
name: "zero debt auction", name: "zero debt auction threshold",
args: args{ args: args{
globalDebtLimit: types.DefaultGlobalDebt, globalDebtLimit: types.DefaultGlobalDebt,
collateralParams: types.DefaultCollateralParams, collateralParams: types.DefaultCollateralParams,
debtParam: types.DefaultDebtParam, debtParam: types.DefaultDebtParam,
surplusThreshold: types.DefaultSurplusThreshold, surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: sdk.ZeroInt(), debtThreshold: sdk.ZeroInt(),
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency, distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker, breaker: types.DefaultCircuitBreaker,
}, },
@ -739,10 +783,46 @@ func (suite *ParamsTestSuite) TestParamValidation() {
contains: "debt auction threshold should be positive", contains: "debt auction threshold should be positive",
}, },
}, },
{
name: "zero surplus auction lot",
args: args{
globalDebtLimit: types.DefaultGlobalDebt,
collateralParams: types.DefaultCollateralParams,
debtParam: types.DefaultDebtParam,
surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: sdk.ZeroInt(),
debtThreshold: types.DefaultDebtThreshold,
debtLot: types.DefaultDebtLot,
distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker,
},
errArgs: errArgs{
expectPass: false,
contains: "surplus auction lot should be positive",
},
},
{
name: "zero debt auction lot",
args: args{
globalDebtLimit: types.DefaultGlobalDebt,
collateralParams: types.DefaultCollateralParams,
debtParam: types.DefaultDebtParam,
surplusThreshold: types.DefaultSurplusThreshold,
surplusLot: types.DefaultSurplusLot,
debtThreshold: types.DefaultDebtThreshold,
debtLot: sdk.ZeroInt(),
distributionFreq: types.DefaultSavingsDistributionFrequency,
breaker: types.DefaultCircuitBreaker,
},
errArgs: errArgs{
expectPass: false,
contains: "debt auction lot should be positive",
},
},
} }
for _, tc := range testCases { for _, tc := range testCases {
suite.Run(tc.name, func() { suite.Run(tc.name, func() {
params := types.NewParams(tc.args.globalDebtLimit, tc.args.collateralParams, tc.args.debtParam, tc.args.surplusThreshold, tc.args.debtThreshold, tc.args.distributionFreq, tc.args.breaker) params := types.NewParams(tc.args.globalDebtLimit, tc.args.collateralParams, tc.args.debtParam, tc.args.surplusThreshold, tc.args.surplusLot, tc.args.debtThreshold, tc.args.debtLot, tc.args.distributionFreq, tc.args.breaker)
err := params.Validate() err := params.Validate()
if tc.errArgs.expectPass { if tc.errArgs.expectPass {
suite.Require().NoError(err) suite.Require().NoError(err)

View File

@ -179,7 +179,9 @@ func (suite *KeeperTestSuite) setupCdpChain() {
Params: cdp.Params{ Params: cdp.Params{
GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000),
SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, SurplusAuctionThreshold: cdp.DefaultSurplusThreshold,
SurplusAuctionLot: cdp.DefaultSurplusLot,
DebtAuctionThreshold: cdp.DefaultDebtThreshold, DebtAuctionThreshold: cdp.DefaultDebtThreshold,
DebtAuctionLot: cdp.DefaultDebtLot,
SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency,
CollateralParams: cdp.CollateralParams{ CollateralParams: cdp.CollateralParams{
{ {