diff --git a/x/cdp/alias.go b/x/cdp/alias.go index d9f1e924..b61029b4 100644 --- a/x/cdp/alias.go +++ b/x/cdp/alias.go @@ -103,6 +103,7 @@ var ( ErrLoadingAugmentedCDP = types.ErrLoadingAugmentedCDP ErrInvalidDebtRequest = types.ErrInvalidDebtRequest ErrDenomPrefixNotFound = types.ErrDenomPrefixNotFound + ErrPricefeedDown = types.ErrPricefeedDown CdpIDKeyPrefix = types.CdpIDKeyPrefix CdpKeyPrefix = types.CdpKeyPrefix CollateralRatioIndexPrefix = types.CollateralRatioIndexPrefix @@ -112,13 +113,16 @@ var ( DepositKeyPrefix = types.DepositKeyPrefix PrincipalKeyPrefix = types.PrincipalKeyPrefix PreviousDistributionTimeKey = types.PreviousDistributionTimeKey + PricefeedStatusKeyPrefix = types.PricefeedStatusKeyPrefix KeyGlobalDebtLimit = types.KeyGlobalDebtLimit KeyCollateralParams = types.KeyCollateralParams KeyDebtParam = types.KeyDebtParam KeyDistributionFrequency = types.KeyDistributionFrequency KeyCircuitBreaker = types.KeyCircuitBreaker KeyDebtThreshold = types.KeyDebtThreshold + KeyDebtLot = types.KeyDebtLot KeySurplusThreshold = types.KeySurplusThreshold + KeySurplusLot = types.KeySurplusLot DefaultGlobalDebt = types.DefaultGlobalDebt DefaultCircuitBreaker = types.DefaultCircuitBreaker DefaultCollateralParams = types.DefaultCollateralParams @@ -129,6 +133,8 @@ var ( DefaultStableDenom = types.DefaultStableDenom DefaultSurplusThreshold = types.DefaultSurplusThreshold DefaultDebtThreshold = types.DefaultDebtThreshold + DefaultSurplusLot = types.DefaultSurplusLot + DefaultDebtLot = types.DefaultDebtLot DefaultPreviousDistributionTime = types.DefaultPreviousDistributionTime DefaultSavingsDistributionFrequency = types.DefaultSavingsDistributionFrequency MaxSortableDec = types.MaxSortableDec diff --git a/x/cdp/integration_test.go b/x/cdp/integration_test.go index 7623ae50..377c4852 100644 --- a/x/cdp/integration_test.go +++ b/x/cdp/integration_test.go @@ -42,7 +42,9 @@ func NewCDPGenState(asset string, liquidationRatio sdk.Dec) app.GenesisState { Params: cdp.Params{ GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, + SurplusAuctionLot: cdp.DefaultSurplusLot, DebtAuctionThreshold: cdp.DefaultDebtThreshold, + DebtAuctionLot: cdp.DefaultDebtLot, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, CollateralParams: cdp.CollateralParams{ { @@ -105,7 +107,9 @@ func NewCDPGenStateMulti() app.GenesisState { Params: cdp.Params{ GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, + SurplusAuctionLot: cdp.DefaultSurplusLot, DebtAuctionThreshold: cdp.DefaultDebtThreshold, + DebtAuctionLot: cdp.DefaultDebtLot, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, CollateralParams: cdp.CollateralParams{ { diff --git a/x/cdp/keeper/auctions.go b/x/cdp/keeper/auctions.go index 6741d0f4..baacd1cf 100644 --- a/x/cdp/keeper/auctions.go +++ b/x/cdp/keeper/auctions.go @@ -109,7 +109,10 @@ func (k Keeper) RunSurplusAndDebtAuctions(ctx sdk.Context) error { remainingDebt := k.GetTotalDebt(ctx, types.LiquidatorMacc) params := k.GetParams(ctx) 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 { return err } @@ -119,7 +122,7 @@ func (k Keeper) RunSurplusAndDebtAuctions(ctx sdk.Context) error { if !surplus.GTE(params.SurplusAuctionThreshold) { 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)) return err } diff --git a/x/cdp/keeper/auctions_test.go b/x/cdp/keeper/auctions_test.go index ba276772..75e9fb21 100644 --- a/x/cdp/keeper/auctions_test.go +++ b/x/cdp/keeper/auctions_test.go @@ -53,24 +53,28 @@ func (suite *AuctionTestSuite) TestNetDebtSurplus() { func (suite *AuctionTestSuite) TestSurplusAuction() { 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) - 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.keeper.RunSurplusAndDebtAuctions(suite.ctx) 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() { 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) - 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.keeper.RunSurplusAndDebtAuctions(suite.ctx) 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) { diff --git a/x/cdp/keeper/integration_test.go b/x/cdp/keeper/integration_test.go index f9e4403f..8b11a4d4 100644 --- a/x/cdp/keeper/integration_test.go +++ b/x/cdp/keeper/integration_test.go @@ -42,7 +42,9 @@ func NewCDPGenState(asset string, liquidationRatio sdk.Dec) app.GenesisState { Params: cdp.Params{ GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, + SurplusAuctionLot: cdp.DefaultSurplusLot, DebtAuctionThreshold: cdp.DefaultDebtThreshold, + DebtAuctionLot: cdp.DefaultDebtLot, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, CollateralParams: cdp.CollateralParams{ { @@ -105,7 +107,9 @@ func NewCDPGenStateMulti() app.GenesisState { Params: cdp.Params{ GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, + SurplusAuctionLot: cdp.DefaultSurplusLot, DebtAuctionThreshold: cdp.DefaultDebtThreshold, + DebtAuctionLot: cdp.DefaultDebtLot, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, CollateralParams: cdp.CollateralParams{ { @@ -155,7 +159,9 @@ func NewCDPGenStateHighDebtLimit() app.GenesisState { Params: cdp.Params{ GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000), SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, + SurplusAuctionLot: cdp.DefaultSurplusLot, DebtAuctionThreshold: cdp.DefaultDebtThreshold, + DebtAuctionLot: cdp.DefaultDebtLot, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, CollateralParams: cdp.CollateralParams{ { diff --git a/x/cdp/simulation/genesis.go b/x/cdp/simulation/genesis.go index 4c465346..12f0acf7 100644 --- a/x/cdp/simulation/genesis.go +++ b/x/cdp/simulation/genesis.go @@ -72,6 +72,8 @@ func randomCdpGenState(selection int) types.GenesisState { Params: types.Params{ GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000), SurplusAuctionThreshold: types.DefaultSurplusThreshold, + SurplusAuctionLot: types.DefaultSurplusLot, + DebtAuctionLot: types.DefaultDebtLot, DebtAuctionThreshold: types.DefaultDebtThreshold, SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency, CollateralParams: types.CollateralParams{ @@ -132,6 +134,8 @@ func randomCdpGenState(selection int) types.GenesisState { GlobalDebtLimit: sdk.NewInt64Coin("usdx", 100000000000000), SurplusAuctionThreshold: types.DefaultSurplusThreshold, DebtAuctionThreshold: types.DefaultDebtThreshold, + SurplusAuctionLot: types.DefaultSurplusLot, + DebtAuctionLot: types.DefaultDebtLot, SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency, CollateralParams: types.CollateralParams{ { diff --git a/x/cdp/spec/06_params.md b/x/cdp/spec/06_params.md index df01024b..f43bce88 100644 --- a/x/cdp/spec/06_params.md +++ b/x/cdp/spec/06_params.md @@ -8,7 +8,11 @@ The cdp module contains the following parameters: | 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 | | 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: diff --git a/x/cdp/types/params.go b/x/cdp/types/params.go index e96d6609..da6be4f8 100644 --- a/x/cdp/types/params.go +++ b/x/cdp/types/params.go @@ -20,7 +20,9 @@ var ( KeyDistributionFrequency = []byte("DistributionFrequency") KeyCircuitBreaker = []byte("CircuitBreaker") KeyDebtThreshold = []byte("DebtThreshold") + KeyDebtLot = []byte("DebtLot") KeySurplusThreshold = []byte("SurplusThreshold") + KeySurplusLot = []byte("SurplusLot") DefaultGlobalDebt = sdk.NewCoin(DefaultStableDenom, sdk.ZeroInt()) DefaultCircuitBreaker = false DefaultCollateralParams = CollateralParams{} @@ -35,8 +37,10 @@ var ( DefaultDebtDenom = "debt" DefaultGovDenom = "ukava" DefaultStableDenom = "usdx" - DefaultSurplusThreshold = sdk.NewInt(1000000000) - DefaultDebtThreshold = sdk.NewInt(1000000000) + DefaultSurplusThreshold = sdk.NewInt(500000000000) + DefaultDebtThreshold = sdk.NewInt(100000000000) + DefaultSurplusLot = sdk.NewInt(10000000000) + DefaultDebtLot = sdk.NewInt(10000000000) DefaultPreviousDistributionTime = tmtime.Canonical(time.Unix(0, 0)) DefaultSavingsDistributionFrequency = time.Hour * 12 minCollateralPrefix = 0 @@ -50,7 +54,9 @@ type Params struct { DebtParam DebtParam `json:"debt_param" yaml:"debt_param"` GlobalDebtLimit sdk.Coin `json:"global_debt_limit" yaml:"global_debt_limit"` 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"` + DebtAuctionLot sdk.Int `json:"debt_auction_lot" yaml:"debt_auction_lot"` SavingsDistributionFrequency time.Duration `json:"savings_distribution_frequency" yaml:"savings_distribution_frequency"` CircuitBreaker bool `json:"circuit_breaker" yaml:"circuit_breaker"` } @@ -62,21 +68,29 @@ func (p Params) String() string { Collateral Params: %s Debt Params: %s Surplus Auction Threshold: %s + Surplus Auction Lot: %s Debt Auction Threshold: %s + Debt Auction Lot: %s Savings Distribution Frequency: %s 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 -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{ GlobalDebtLimit: debtLimit, CollateralParams: collateralParams, DebtParam: debtParam, - DebtAuctionThreshold: debtThreshold, SurplusAuctionThreshold: surplusThreshold, + SurplusAuctionLot: surplusLot, + DebtAuctionThreshold: debtThreshold, + DebtAuctionLot: debtLot, SavingsDistributionFrequency: distributionFreq, CircuitBreaker: breaker, } @@ -84,7 +98,11 @@ func NewParams(debtLimit sdk.Coin, collateralParams CollateralParams, debtParam // DefaultParams returns default params for cdp module 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 @@ -175,7 +193,9 @@ func (p *Params) ParamSetPairs() params.ParamSetPairs { params.NewParamSetPair(KeyDebtParam, &p.DebtParam, validateDebtParam), params.NewParamSetPair(KeyCircuitBreaker, &p.CircuitBreaker, validateCircuitBreakerParam), params.NewParamSetPair(KeySurplusThreshold, &p.SurplusAuctionThreshold, validateSurplusAuctionThresholdParam), + params.NewParamSetPair(KeySurplusLot, &p.SurplusAuctionLot, validateSurplusAuctionLotParam), params.NewParamSetPair(KeyDebtThreshold, &p.DebtAuctionThreshold, validateDebtAuctionThresholdParam), + params.NewParamSetPair(KeyDebtLot, &p.DebtAuctionLot, validateDebtAuctionLotParam), params.NewParamSetPair(KeyDistributionFrequency, &p.SavingsDistributionFrequency, validateSavingsDistributionFrequencyParam), } } @@ -202,10 +222,18 @@ func (p Params) Validate() error { return err } + if err := validateSurplusAuctionLotParam(p.SurplusAuctionLot); err != nil { + return err + } + if err := validateDebtAuctionThresholdParam(p.DebtAuctionThreshold); err != nil { return err } + if err := validateDebtAuctionLotParam(p.DebtAuctionLot); err != nil { + return err + } + if err := validateSavingsDistributionFrequencyParam(p.SavingsDistributionFrequency); err != nil { return err } @@ -360,6 +388,19 @@ func validateSurplusAuctionThresholdParam(i interface{}) error { 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 { dat, ok := i.(sdk.Int) if !ok { @@ -373,6 +414,19 @@ func validateDebtAuctionThresholdParam(i interface{}) error { 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 { sdf, ok := i.(time.Duration) if !ok { diff --git a/x/cdp/types/params_test.go b/x/cdp/types/params_test.go index 810b1cf0..ceabd0b4 100644 --- a/x/cdp/types/params_test.go +++ b/x/cdp/types/params_test.go @@ -25,7 +25,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { collateralParams types.CollateralParams debtParam types.DebtParam surplusThreshold sdk.Int + surplusLot sdk.Int debtThreshold sdk.Int + debtLot sdk.Int distributionFreq time.Duration breaker bool } @@ -46,7 +48,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { collateralParams: types.DefaultCollateralParams, debtParam: types.DefaultDebtParam, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -81,7 +85,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -116,7 +122,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -151,7 +159,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -198,7 +208,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -245,7 +257,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -292,7 +306,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -327,7 +343,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -362,7 +380,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -409,7 +429,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -456,7 +478,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -491,7 +515,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -526,7 +552,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -561,7 +589,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -596,7 +626,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -631,7 +663,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("0.95"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -666,7 +700,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { SavingsRate: sdk.MustNewDecFromStr("1.05"), }, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -682,7 +718,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { collateralParams: types.DefaultCollateralParams, debtParam: types.DefaultDebtParam, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -698,7 +736,9 @@ func (suite *ParamsTestSuite) TestParamValidation() { collateralParams: types.DefaultCollateralParams, debtParam: types.DefaultDebtParam, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: time.Second * 0, breaker: types.DefaultCircuitBreaker, }, @@ -708,13 +748,15 @@ func (suite *ParamsTestSuite) TestParamValidation() { }, }, { - name: "zero surplus auction", + name: "zero surplus auction threshold", args: args{ globalDebtLimit: types.DefaultGlobalDebt, collateralParams: types.DefaultCollateralParams, debtParam: types.DefaultDebtParam, surplusThreshold: sdk.ZeroInt(), + surplusLot: types.DefaultSurplusLot, debtThreshold: types.DefaultDebtThreshold, + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -724,13 +766,15 @@ func (suite *ParamsTestSuite) TestParamValidation() { }, }, { - name: "zero debt auction", + name: "zero debt auction threshold", args: args{ globalDebtLimit: types.DefaultGlobalDebt, collateralParams: types.DefaultCollateralParams, debtParam: types.DefaultDebtParam, surplusThreshold: types.DefaultSurplusThreshold, + surplusLot: types.DefaultSurplusLot, debtThreshold: sdk.ZeroInt(), + debtLot: types.DefaultDebtLot, distributionFreq: types.DefaultSavingsDistributionFrequency, breaker: types.DefaultCircuitBreaker, }, @@ -739,10 +783,46 @@ func (suite *ParamsTestSuite) TestParamValidation() { 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 { 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() if tc.errArgs.expectPass { suite.Require().NoError(err) diff --git a/x/incentive/keeper/rewards_test.go b/x/incentive/keeper/rewards_test.go index 1d9afe94..00332b2c 100644 --- a/x/incentive/keeper/rewards_test.go +++ b/x/incentive/keeper/rewards_test.go @@ -179,7 +179,9 @@ func (suite *KeeperTestSuite) setupCdpChain() { Params: cdp.Params{ GlobalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), SurplusAuctionThreshold: cdp.DefaultSurplusThreshold, + SurplusAuctionLot: cdp.DefaultSurplusLot, DebtAuctionThreshold: cdp.DefaultDebtThreshold, + DebtAuctionLot: cdp.DefaultDebtLot, SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, CollateralParams: cdp.CollateralParams{ {