mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-10-31 23:17:27 +00:00 
			
		
		
		
	[R4R] Add liquidation pricefeed (#524)
* add parameter for liquidation pricefeed
This commit is contained in:
		
							parent
							
								
									99537efd24
								
							
						
					
					
						commit
						ade6edb918
					
				| @ -18,7 +18,12 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) { | |||||||
| 
 | 
 | ||||||
| 	for _, cp := range params.CollateralParams { | 	for _, cp := range params.CollateralParams { | ||||||
| 
 | 
 | ||||||
| 		ok := k.UpdatePricefeedStatus(ctx, cp.MarketID) | 		ok := k.UpdatePricefeedStatus(ctx, cp.SpotMarketID) | ||||||
|  | 		if !ok { | ||||||
|  | 			continue | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		ok = k.UpdatePricefeedStatus(ctx, cp.LiquidationMarketID) | ||||||
| 		if !ok { | 		if !ok { | ||||||
| 			continue | 			continue | ||||||
| 		} | 		} | ||||||
| @ -28,8 +33,7 @@ func BeginBlocker(ctx sdk.Context, req abci.RequestBeginBlock, k Keeper) { | |||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			panic(err) | 			panic(err) | ||||||
| 		} | 		} | ||||||
| 
 | 		err = k.LiquidateCdps(ctx, cp.LiquidationMarketID, cp.Denom, cp.LiquidationRatio) | ||||||
| 		err = k.LiquidateCdps(ctx, cp.MarketID, cp.Denom, cp.LiquidationRatio) |  | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			panic(err) | 			panic(err) | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -38,13 +38,21 @@ func InitGenesis(ctx sdk.Context, k Keeper, pk types.PricefeedKeeper, sk types.S | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	for _, col := range gs.Params.CollateralParams { | 	for _, col := range gs.Params.CollateralParams { | ||||||
| 		_, found := collateralMap[col.MarketID] | 		_, found := collateralMap[col.SpotMarketID] | ||||||
| 		if !found { | 		if !found { | ||||||
| 			panic(fmt.Sprintf("%s collateral not found in pricefeed", col.Denom)) | 			panic(fmt.Sprintf("%s collateral not found in pricefeed", col.Denom)) | ||||||
| 		} | 		} | ||||||
| 		// sets the status of the pricefeed in the store
 | 		// sets the status of the pricefeed in the store
 | ||||||
| 		// if pricefeed not active, debt operations are paused
 | 		// if pricefeed not active, debt operations are paused
 | ||||||
| 		_ = k.UpdatePricefeedStatus(ctx, col.MarketID) | 		_ = k.UpdatePricefeedStatus(ctx, col.SpotMarketID) | ||||||
|  | 
 | ||||||
|  | 		_, found = collateralMap[col.LiquidationMarketID] | ||||||
|  | 		if !found { | ||||||
|  | 			panic(fmt.Sprintf("%s collateral not found in pricefeed", col.Denom)) | ||||||
|  | 		} | ||||||
|  | 		// sets the status of the pricefeed in the store
 | ||||||
|  | 		// if pricefeed not active, debt operations are paused
 | ||||||
|  | 		_ = k.UpdatePricefeedStatus(ctx, col.LiquidationMarketID) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	k.SetParams(ctx, gs.Params) | 	k.SetParams(ctx, gs.Params) | ||||||
|  | |||||||
| @ -46,15 +46,16 @@ func NewCDPGenState(asset string, liquidationRatio sdk.Dec) app.GenesisState { | |||||||
| 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | ||||||
| 			CollateralParams: cdp.CollateralParams{ | 			CollateralParams: cdp.CollateralParams{ | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              asset, | 					Denom:               asset, | ||||||
| 					LiquidationRatio:   liquidationRatio, | 					LiquidationRatio:    liquidationRatio, | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | ||||||
| 					LiquidationPenalty: d("0.05"), | 					LiquidationPenalty:  d("0.05"), | ||||||
| 					AuctionSize:        i(1000000000), | 					AuctionSize:         i(1000000000), | ||||||
| 					Prefix:             0x20, | 					Prefix:              0x20, | ||||||
| 					ConversionFactor:   i(6), | 					ConversionFactor:    i(6), | ||||||
| 					MarketID:           asset + ":usd", | 					SpotMarketID:        asset + ":usd", | ||||||
|  | 					LiquidationMarketID: asset + ":usd", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			DebtParam: cdp.DebtParam{ | 			DebtParam: cdp.DebtParam{ | ||||||
| @ -108,26 +109,28 @@ func NewCDPGenStateMulti() app.GenesisState { | |||||||
| 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | ||||||
| 			CollateralParams: cdp.CollateralParams{ | 			CollateralParams: cdp.CollateralParams{ | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              "xrp", | 					Denom:               "xrp", | ||||||
| 					LiquidationRatio:   sdk.MustNewDecFromStr("2.0"), | 					LiquidationRatio:    sdk.MustNewDecFromStr("2.0"), | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 500000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 500000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | ||||||
| 					LiquidationPenalty: d("0.05"), | 					LiquidationPenalty:  d("0.05"), | ||||||
| 					AuctionSize:        i(7000000000), | 					AuctionSize:         i(7000000000), | ||||||
| 					Prefix:             0x20, | 					Prefix:              0x20, | ||||||
| 					MarketID:           "xrp:usd", | 					SpotMarketID:        "xrp:usd", | ||||||
| 					ConversionFactor:   i(6), | 					LiquidationMarketID: "xrp:usd", | ||||||
|  | 					ConversionFactor:    i(6), | ||||||
| 				}, | 				}, | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              "btc", | 					Denom:               "btc", | ||||||
| 					LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 					LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 500000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 500000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000000782997609"), // %2.5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000000782997609"), // %2.5 apr
 | ||||||
| 					LiquidationPenalty: d("0.025"), | 					LiquidationPenalty:  d("0.025"), | ||||||
| 					AuctionSize:        i(10000000), | 					AuctionSize:         i(10000000), | ||||||
| 					Prefix:             0x21, | 					Prefix:              0x21, | ||||||
| 					MarketID:           "btc:usd", | 					SpotMarketID:        "btc:usd", | ||||||
| 					ConversionFactor:   i(8), | 					LiquidationMarketID: "btc:usd", | ||||||
|  | 					ConversionFactor:    i(8), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			DebtParam: cdp.DebtParam{ | 			DebtParam: cdp.DebtParam{ | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| package keeper | package keeper | ||||||
| 
 | 
 | ||||||
| import ( | import ( | ||||||
|  | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"sort" | 	"sort" | ||||||
| 
 | 
 | ||||||
| @ -352,7 +353,11 @@ func (k Keeper) ValidateCollateral(ctx sdk.Context, collateral sdk.Coin) error { | |||||||
| 	if !found { | 	if !found { | ||||||
| 		return sdkerrors.Wrap(types.ErrCollateralNotSupported, collateral.Denom) | 		return sdkerrors.Wrap(types.ErrCollateralNotSupported, collateral.Denom) | ||||||
| 	} | 	} | ||||||
| 	ok := k.GetMarketStatus(ctx, cp.MarketID) | 	ok := k.GetMarketStatus(ctx, cp.SpotMarketID) | ||||||
|  | 	if !ok { | ||||||
|  | 		return sdkerrors.Wrap(types.ErrPricefeedDown, collateral.Denom) | ||||||
|  | 	} | ||||||
|  | 	ok = k.GetMarketStatus(ctx, cp.LiquidationMarketID) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		return sdkerrors.Wrap(types.ErrPricefeedDown, collateral.Denom) | 		return sdkerrors.Wrap(types.ErrPricefeedDown, collateral.Denom) | ||||||
| 	} | 	} | ||||||
| @ -404,7 +409,7 @@ func (k Keeper) ValidateDebtLimit(ctx sdk.Context, collateralDenom string, princ | |||||||
| // ValidateCollateralizationRatio validate that adding the input principal doesn't put the cdp below the liquidation ratio
 | // ValidateCollateralizationRatio validate that adding the input principal doesn't put the cdp below the liquidation ratio
 | ||||||
| func (k Keeper) ValidateCollateralizationRatio(ctx sdk.Context, collateral sdk.Coin, principal sdk.Coin, fees sdk.Coin) error { | func (k Keeper) ValidateCollateralizationRatio(ctx sdk.Context, collateral sdk.Coin, principal sdk.Coin, fees sdk.Coin) error { | ||||||
| 	//
 | 	//
 | ||||||
| 	collateralizationRatio, err := k.CalculateCollateralizationRatio(ctx, collateral, principal, fees) | 	collateralizationRatio, err := k.CalculateCollateralizationRatio(ctx, collateral, principal, fees, spot) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
| @ -430,7 +435,7 @@ func (k Keeper) CalculateCollateralToDebtRatio(ctx sdk.Context, collateral sdk.C | |||||||
| // LoadAugmentedCDP creates a new augmented CDP from an existing CDP
 | // LoadAugmentedCDP creates a new augmented CDP from an existing CDP
 | ||||||
| func (k Keeper) LoadAugmentedCDP(ctx sdk.Context, cdp types.CDP) types.AugmentedCDP { | func (k Keeper) LoadAugmentedCDP(ctx sdk.Context, cdp types.CDP) types.AugmentedCDP { | ||||||
| 	// calculate collateralization ratio
 | 	// calculate collateralization ratio
 | ||||||
| 	collateralizationRatio, err := k.CalculateCollateralizationRatio(ctx, cdp.Collateral, cdp.Principal, cdp.AccumulatedFees) | 	collateralizationRatio, err := k.CalculateCollateralizationRatio(ctx, cdp.Collateral, cdp.Principal, cdp.AccumulatedFees, liquidation) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return types.AugmentedCDP{CDP: cdp} | 		return types.AugmentedCDP{CDP: cdp} | ||||||
| 	} | 	} | ||||||
| @ -451,11 +456,20 @@ func (k Keeper) LoadAugmentedCDP(ctx sdk.Context, cdp types.CDP) types.Augmented | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // CalculateCollateralizationRatio returns the collateralization ratio of the input collateral to the input debt plus fees
 | // CalculateCollateralizationRatio returns the collateralization ratio of the input collateral to the input debt plus fees
 | ||||||
| func (k Keeper) CalculateCollateralizationRatio(ctx sdk.Context, collateral sdk.Coin, principal sdk.Coin, fees sdk.Coin) (sdk.Dec, error) { | func (k Keeper) CalculateCollateralizationRatio(ctx sdk.Context, collateral sdk.Coin, principal sdk.Coin, fees sdk.Coin, pfType pricefeedType) (sdk.Dec, error) { | ||||||
| 	if collateral.IsZero() { | 	if collateral.IsZero() { | ||||||
| 		return sdk.ZeroDec(), nil | 		return sdk.ZeroDec(), nil | ||||||
| 	} | 	} | ||||||
| 	marketID := k.getMarketID(ctx, collateral.Denom) | 	var marketID string | ||||||
|  | 	switch pfType { | ||||||
|  | 	case spot: | ||||||
|  | 		marketID = k.getSpotMarketID(ctx, collateral.Denom) | ||||||
|  | 	case liquidation: | ||||||
|  | 		marketID = k.getliquidationMarketID(ctx, collateral.Denom) | ||||||
|  | 	default: | ||||||
|  | 		return sdk.Dec{}, pfType.IsValid() | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	price, err := k.pricefeedKeeper.GetCurrentPrice(ctx, marketID) | 	price, err := k.pricefeedKeeper.GetCurrentPrice(ctx, marketID) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return sdk.Dec{}, err | 		return sdk.Dec{}, err | ||||||
| @ -473,9 +487,18 @@ func (k Keeper) CalculateCollateralizationRatio(ctx sdk.Context, collateral sdk. | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // CalculateCollateralizationRatioFromAbsoluteRatio takes a coin's denom and an absolute ratio and returns the respective collateralization ratio
 | // CalculateCollateralizationRatioFromAbsoluteRatio takes a coin's denom and an absolute ratio and returns the respective collateralization ratio
 | ||||||
| func (k Keeper) CalculateCollateralizationRatioFromAbsoluteRatio(ctx sdk.Context, collateralDenom string, absoluteRatio sdk.Dec) (sdk.Dec, error) { | func (k Keeper) CalculateCollateralizationRatioFromAbsoluteRatio(ctx sdk.Context, collateralDenom string, absoluteRatio sdk.Dec, pfType pricefeedType) (sdk.Dec, error) { | ||||||
| 	// get price collateral
 | 	// get price of collateral
 | ||||||
| 	marketID := k.getMarketID(ctx, collateralDenom) | 	var marketID string | ||||||
|  | 	switch pfType { | ||||||
|  | 	case spot: | ||||||
|  | 		marketID = k.getSpotMarketID(ctx, collateralDenom) | ||||||
|  | 	case liquidation: | ||||||
|  | 		marketID = k.getliquidationMarketID(ctx, collateralDenom) | ||||||
|  | 	default: | ||||||
|  | 		return sdk.Dec{}, pfType.IsValid() | ||||||
|  | 	} | ||||||
|  | 
 | ||||||
| 	price, err := k.pricefeedKeeper.GetCurrentPrice(ctx, marketID) | 	price, err := k.pricefeedKeeper.GetCurrentPrice(ctx, marketID) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return sdk.Dec{}, err | 		return sdk.Dec{}, err | ||||||
| @ -522,3 +545,18 @@ func (k Keeper) convertDebtToBaseUnits(ctx sdk.Context, debt sdk.Coin) (baseUnit | |||||||
| 	dp, _ := k.GetDebtParam(ctx, debt.Denom) | 	dp, _ := k.GetDebtParam(ctx, debt.Denom) | ||||||
| 	return sdk.NewDecFromInt(debt.Amount).Mul(sdk.NewDecFromIntWithPrec(sdk.OneInt(), dp.ConversionFactor.Int64())) | 	return sdk.NewDecFromInt(debt.Amount).Mul(sdk.NewDecFromIntWithPrec(sdk.OneInt(), dp.ConversionFactor.Int64())) | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | type pricefeedType string | ||||||
|  | 
 | ||||||
|  | const ( | ||||||
|  | 	spot        pricefeedType = "spot" | ||||||
|  | 	liquidation               = "liquidation" | ||||||
|  | ) | ||||||
|  | 
 | ||||||
|  | func (pft pricefeedType) IsValid() error { | ||||||
|  | 	switch pft { | ||||||
|  | 	case spot, liquidation: | ||||||
|  | 		return nil | ||||||
|  | 	} | ||||||
|  | 	return errors.New(fmt.Sprintf("invalid pricefeed type: %s", pft)) | ||||||
|  | } | ||||||
|  | |||||||
| @ -285,11 +285,11 @@ func (suite *CdpTestSuite) TestCalculateCollateralizationRatio() { | |||||||
| 	suite.keeper.IndexCdpByOwner(suite.ctx, c) | 	suite.keeper.IndexCdpByOwner(suite.ctx, c) | ||||||
| 	cr := suite.keeper.CalculateCollateralToDebtRatio(suite.ctx, c.Collateral, c.Principal) | 	cr := suite.keeper.CalculateCollateralToDebtRatio(suite.ctx, c.Collateral, c.Principal) | ||||||
| 	suite.keeper.IndexCdpByCollateralRatio(suite.ctx, c.Collateral.Denom, c.ID, cr) | 	suite.keeper.IndexCdpByCollateralRatio(suite.ctx, c.Collateral.Denom, c.ID, cr) | ||||||
| 	cr, err = suite.keeper.CalculateCollateralizationRatio(suite.ctx, c.Collateral, c.Principal, c.AccumulatedFees) | 	cr, err = suite.keeper.CalculateCollateralizationRatio(suite.ctx, c.Collateral, c.Principal, c.AccumulatedFees, "spot") | ||||||
| 	suite.NoError(err) | 	suite.NoError(err) | ||||||
| 	suite.Equal(d("2.5"), cr) | 	suite.Equal(d("2.5"), cr) | ||||||
| 	c.AccumulatedFees = sdk.NewCoin("usdx", i(10000000)) | 	c.AccumulatedFees = sdk.NewCoin("usdx", i(10000000)) | ||||||
| 	cr, err = suite.keeper.CalculateCollateralizationRatio(suite.ctx, c.Collateral, c.Principal, c.AccumulatedFees) | 	cr, err = suite.keeper.CalculateCollateralizationRatio(suite.ctx, c.Collateral, c.Principal, c.AccumulatedFees, "spot") | ||||||
| 	suite.NoError(err) | 	suite.NoError(err) | ||||||
| 	suite.Equal(d("1.25"), cr) | 	suite.Equal(d("1.25"), cr) | ||||||
| } | } | ||||||
|  | |||||||
| @ -72,7 +72,7 @@ func (k Keeper) WithdrawCollateral(ctx sdk.Context, owner, depositor sdk.AccAddr | |||||||
| 		return sdkerrors.Wrapf(types.ErrInvalidWithdrawAmount, "collateral %s, deposit %s", collateral, deposit.Amount) | 		return sdkerrors.Wrapf(types.ErrInvalidWithdrawAmount, "collateral %s, deposit %s", collateral, deposit.Amount) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	collateralizationRatio, err := k.CalculateCollateralizationRatio(ctx, cdp.Collateral.Sub(collateral), cdp.Principal, cdp.AccumulatedFees) | 	collateralizationRatio, err := k.CalculateCollateralizationRatio(ctx, cdp.Collateral.Sub(collateral), cdp.Principal, cdp.AccumulatedFees, spot) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -46,15 +46,16 @@ func NewCDPGenState(asset string, liquidationRatio sdk.Dec) app.GenesisState { | |||||||
| 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | ||||||
| 			CollateralParams: cdp.CollateralParams{ | 			CollateralParams: cdp.CollateralParams{ | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              asset, | 					Denom:               asset, | ||||||
| 					LiquidationRatio:   liquidationRatio, | 					LiquidationRatio:    liquidationRatio, | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | ||||||
| 					LiquidationPenalty: d("0.05"), | 					LiquidationPenalty:  d("0.05"), | ||||||
| 					AuctionSize:        i(100), | 					AuctionSize:         i(100), | ||||||
| 					Prefix:             0x20, | 					Prefix:              0x20, | ||||||
| 					ConversionFactor:   i(6), | 					ConversionFactor:    i(6), | ||||||
| 					MarketID:           asset + ":usd", | 					SpotMarketID:        asset + ":usd", | ||||||
|  | 					LiquidationMarketID: asset + ":usd", | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			DebtParam: cdp.DebtParam{ | 			DebtParam: cdp.DebtParam{ | ||||||
| @ -108,26 +109,28 @@ func NewCDPGenStateMulti() app.GenesisState { | |||||||
| 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | ||||||
| 			CollateralParams: cdp.CollateralParams{ | 			CollateralParams: cdp.CollateralParams{ | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              "xrp", | 					Denom:               "xrp", | ||||||
| 					LiquidationRatio:   sdk.MustNewDecFromStr("2.0"), | 					LiquidationRatio:    sdk.MustNewDecFromStr("2.0"), | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 500000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 500000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | ||||||
| 					LiquidationPenalty: d("0.05"), | 					LiquidationPenalty:  d("0.05"), | ||||||
| 					AuctionSize:        i(7000000000), | 					AuctionSize:         i(7000000000), | ||||||
| 					Prefix:             0x20, | 					Prefix:              0x20, | ||||||
| 					MarketID:           "xrp:usd", | 					SpotMarketID:        "xrp:usd", | ||||||
| 					ConversionFactor:   i(6), | 					LiquidationMarketID: "xrp:usd", | ||||||
|  | 					ConversionFactor:    i(6), | ||||||
| 				}, | 				}, | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              "btc", | 					Denom:               "btc", | ||||||
| 					LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 					LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 500000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 500000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000000782997609"), // %2.5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000000782997609"), // %2.5 apr
 | ||||||
| 					LiquidationPenalty: d("0.025"), | 					LiquidationPenalty:  d("0.025"), | ||||||
| 					AuctionSize:        i(10000000), | 					AuctionSize:         i(10000000), | ||||||
| 					Prefix:             0x21, | 					Prefix:              0x21, | ||||||
| 					MarketID:           "btc:usd", | 					SpotMarketID:        "btc:usd", | ||||||
| 					ConversionFactor:   i(8), | 					LiquidationMarketID: "btc:usd", | ||||||
|  | 					ConversionFactor:    i(8), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			DebtParam: cdp.DebtParam{ | 			DebtParam: cdp.DebtParam{ | ||||||
| @ -156,26 +159,28 @@ func NewCDPGenStateHighDebtLimit() app.GenesisState { | |||||||
| 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | ||||||
| 			CollateralParams: cdp.CollateralParams{ | 			CollateralParams: cdp.CollateralParams{ | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              "xrp", | 					Denom:               "xrp", | ||||||
| 					LiquidationRatio:   sdk.MustNewDecFromStr("2.0"), | 					LiquidationRatio:    sdk.MustNewDecFromStr("2.0"), | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 50000000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 50000000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | ||||||
| 					LiquidationPenalty: d("0.05"), | 					LiquidationPenalty:  d("0.05"), | ||||||
| 					AuctionSize:        i(7000000000), | 					AuctionSize:         i(7000000000), | ||||||
| 					Prefix:             0x20, | 					Prefix:              0x20, | ||||||
| 					MarketID:           "xrp:usd", | 					SpotMarketID:        "xrp:usd", | ||||||
| 					ConversionFactor:   i(6), | 					LiquidationMarketID: "xrp:usd", | ||||||
|  | 					ConversionFactor:    i(6), | ||||||
| 				}, | 				}, | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              "btc", | 					Denom:               "btc", | ||||||
| 					LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 					LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 50000000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 50000000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000000782997609"), // %2.5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000000782997609"), // %2.5 apr
 | ||||||
| 					LiquidationPenalty: d("0.025"), | 					LiquidationPenalty:  d("0.025"), | ||||||
| 					AuctionSize:        i(10000000), | 					AuctionSize:         i(10000000), | ||||||
| 					Prefix:             0x21, | 					Prefix:              0x21, | ||||||
| 					MarketID:           "btc:usd", | 					SpotMarketID:        "btc:usd", | ||||||
| 					ConversionFactor:   i(8), | 					LiquidationMarketID: "btc:usd", | ||||||
|  | 					ConversionFactor:    i(8), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			DebtParam: cdp.DebtParam{ | 			DebtParam: cdp.DebtParam{ | ||||||
|  | |||||||
| @ -62,12 +62,20 @@ func (k Keeper) getDenomFromByte(ctx sdk.Context, db byte) string { | |||||||
| 	panic(fmt.Sprintf("no collateral denom with prefix %b", db)) | 	panic(fmt.Sprintf("no collateral denom with prefix %b", db)) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (k Keeper) getMarketID(ctx sdk.Context, denom string) string { | func (k Keeper) getSpotMarketID(ctx sdk.Context, denom string) string { | ||||||
| 	cp, found := k.GetCollateral(ctx, denom) | 	cp, found := k.GetCollateral(ctx, denom) | ||||||
| 	if !found { | 	if !found { | ||||||
| 		panic(fmt.Sprintf("collateral not found: %s", denom)) | 		panic(fmt.Sprintf("collateral not found: %s", denom)) | ||||||
| 	} | 	} | ||||||
| 	return cp.MarketID | 	return cp.SpotMarketID | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | func (k Keeper) getliquidationMarketID(ctx sdk.Context, denom string) string { | ||||||
|  | 	cp, found := k.GetCollateral(ctx, denom) | ||||||
|  | 	if !found { | ||||||
|  | 		panic(fmt.Sprintf("collateral not found: %s", denom)) | ||||||
|  | 	} | ||||||
|  | 	return cp.LiquidationMarketID | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (k Keeper) getLiquidationRatio(ctx sdk.Context, denom string) sdk.Dec { | func (k Keeper) getLiquidationRatio(ctx sdk.Context, denom string) sdk.Dec { | ||||||
|  | |||||||
| @ -98,7 +98,7 @@ func queryGetCdpsByRatio(ctx sdk.Context, req abci.RequestQuery, keeper Keeper) | |||||||
| 		return nil, sdkerrors.Wrap(types.ErrCollateralNotSupported, requestParams.CollateralDenom) | 		return nil, sdkerrors.Wrap(types.ErrCollateralNotSupported, requestParams.CollateralDenom) | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	ratio, err := keeper.CalculateCollateralizationRatioFromAbsoluteRatio(ctx, requestParams.CollateralDenom, requestParams.Ratio) | 	ratio, err := keeper.CalculateCollateralizationRatioFromAbsoluteRatio(ctx, requestParams.CollateralDenom, requestParams.Ratio, "liquidation") | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return nil, sdkerrors.Wrap(err, "couldn't get collateralization ratio from absolute ratio") | 		return nil, sdkerrors.Wrap(err, "couldn't get collateralization ratio from absolute ratio") | ||||||
| 	} | 	} | ||||||
|  | |||||||
| @ -183,7 +183,7 @@ func (suite *QuerierTestSuite) TestQueryCdpsByRatio() { | |||||||
| 	expectedBtcIds := []int{} | 	expectedBtcIds := []int{} | ||||||
| 	for _, cdp := range suite.cdps { | 	for _, cdp := range suite.cdps { | ||||||
| 		absoluteRatio := suite.keeper.CalculateCollateralToDebtRatio(suite.ctx, cdp.Collateral, cdp.Principal) | 		absoluteRatio := suite.keeper.CalculateCollateralToDebtRatio(suite.ctx, cdp.Collateral, cdp.Principal) | ||||||
| 		collateralizationRatio, err := suite.keeper.CalculateCollateralizationRatioFromAbsoluteRatio(suite.ctx, cdp.Collateral.Denom, absoluteRatio) | 		collateralizationRatio, err := suite.keeper.CalculateCollateralizationRatioFromAbsoluteRatio(suite.ctx, cdp.Collateral.Denom, absoluteRatio, "liquidation") | ||||||
| 		suite.Nil(err) | 		suite.Nil(err) | ||||||
| 		if cdp.Collateral.Denom == "xrp" { | 		if cdp.Collateral.Denom == "xrp" { | ||||||
| 			if collateralizationRatio.LT(xrpRatio) { | 			if collateralizationRatio.LT(xrpRatio) { | ||||||
|  | |||||||
| @ -76,37 +76,40 @@ func randomCdpGenState(selection int) types.GenesisState { | |||||||
| 				SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency, | 				SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency, | ||||||
| 				CollateralParams: types.CollateralParams{ | 				CollateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "xrp", | 						Denom:               "xrp", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("2.0"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("2.0"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 20000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 20000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000004431822130"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000004431822130"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.075"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.075"), | ||||||
| 						AuctionSize:        sdk.NewInt(100000000000), | 						AuctionSize:         sdk.NewInt(100000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "xrp:usd", | 						SpotMarketID:        "xrp:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(6), | 						LiquidationMarketID: "xrp:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(6), | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "btc", | 						Denom:               "btc", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.25"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.25"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 50000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 50000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000000782997609"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000000782997609"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(1000000000), | 						AuctionSize:         sdk.NewInt(1000000000), | ||||||
| 						Prefix:             0x21, | 						Prefix:              0x21, | ||||||
| 						MarketID:           "btc:usd", | 						SpotMarketID:        "btc:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "btc:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 30000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 30000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000002293273137"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000002293273137"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.15"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.15"), | ||||||
| 						AuctionSize:        sdk.NewInt(1000000000000), | 						AuctionSize:         sdk.NewInt(1000000000000), | ||||||
| 						Prefix:             0x22, | 						Prefix:              0x22, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				DebtParam: types.DebtParam{ | 				DebtParam: types.DebtParam{ | ||||||
| @ -132,15 +135,16 @@ func randomCdpGenState(selection int) types.GenesisState { | |||||||
| 				SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency, | 				SavingsDistributionFrequency: types.DefaultSavingsDistributionFrequency, | ||||||
| 				CollateralParams: types.CollateralParams{ | 				CollateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 100000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 100000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000002293273137"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000002293273137"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.075"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.075"), | ||||||
| 						AuctionSize:        sdk.NewInt(10000000000), | 						AuctionSize:         sdk.NewInt(10000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				DebtParam: types.DebtParam{ | 				DebtParam: types.DebtParam{ | ||||||
|  | |||||||
| @ -64,7 +64,7 @@ func SimulateMsgCdp(ak types.AccountKeeper, k keeper.Keeper, pfk types.Pricefeed | |||||||
| 			return simulation.NoOpMsg(types.ModuleName), nil, nil | 			return simulation.NoOpMsg(types.ModuleName), nil, nil | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		price, err := pfk.GetCurrentPrice(ctx, randCollateralParam.MarketID) | 		price, err := pfk.GetCurrentPrice(ctx, randCollateralParam.SpotMarketID) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return simulation.NoOpMsg(types.ModuleName), nil, err | 			return simulation.NoOpMsg(types.ModuleName), nil, err | ||||||
| 		} | 		} | ||||||
|  | |||||||
| @ -32,7 +32,7 @@ Module interactions: | |||||||
| 
 | 
 | ||||||
| In the event of a decrease in the price of the collateral, the total value of all collateral in CDPs may drop below the value of all the issued stable assets. This undesirable event is countered through two mechanisms: | In the event of a decrease in the price of the collateral, the total value of all collateral in CDPs may drop below the value of all the issued stable assets. This undesirable event is countered through two mechanisms: | ||||||
| 
 | 
 | ||||||
| **CDP Liquidations** The ratio of collateral value to debt value in each CDP is monitored. When this drops too low the collateral and debt is automatically seized by the system. The collateral is sold off through an auction to bring in stable asset which is burned against the seized debt. | **CDP Liquidations** The ratio of collateral value to debt value in each CDP is monitored. When this drops too low the collateral and debt is automatically seized by the system. The collateral is sold off through an auction to bring in stable asset which is burned against the seized debt. The price used to determine liquidation is controlled by the `LiquidationMarketID` parameter, which can be the same as the `SpotMarketID` or use a different calculation of price, such as a time-weighted average. | ||||||
| 
 | 
 | ||||||
| **Debt Auctions** In extreme cases where liquidations fail to raise enough to cover the seized debt, another mechanism kicks in: Debt Auctions. System governance tokens are minted and sold through auction to raise enough stable asset to cover the remaining debt. The governors of the system represent the lenders of last resort. | **Debt Auctions** In extreme cases where liquidations fail to raise enough to cover the seized debt, another mechanism kicks in: Debt Auctions. System governance tokens are minted and sold through auction to raise enough stable asset to cover the remaining debt. The governors of the system represent the lenders of last resort. | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -12,15 +12,16 @@ The cdp module contains the following parameters: | |||||||
| 
 | 
 | ||||||
| Each CollateralParam has the following parameters: | Each CollateralParam has the following parameters: | ||||||
| 
 | 
 | ||||||
| | Key              | Type          | Example                                     | Description                                                                                                    | | | Key                 | Type          | Example                                     | Description                                                                                                    | | ||||||
| |------------------|---------------|---------------------------------------------|----------------------------------------------------------------------------------------------------------------| | |---------------------|   |---------------|---------------------------------------------|----------------------------------------------------------------------------------------------------------------| | ||||||
| | Denom            | string        | "bnb"                                       | collateral coin denom                                                                                          | | | Denom               | string        | "bnb"                                       | collateral coin denom                                                                                          | | ||||||
| | LiquidationRatio | string (dec)  | "1.500000000000000000"                      | the ratio under which a cdp with this collateral type will be liquidated                                       | | | LiquidationRatio    | string (dec)  | "1.500000000000000000"                      | the ratio under which a cdp with this collateral type will be liquidated                                       | | ||||||
| | DebtLimit        | coin          | {"denom":"bnb","amount":"1000000000000"}    | maximum pegged asset that can be minted backed by this collateral type                                         | | | DebtLimit           | coin          | {"denom":"bnb","amount":"1000000000000"}    | maximum pegged asset that can be minted backed by this collateral type                                         | | ||||||
| | StabilityFee     | string (dec)  | "1.000000001547126"                         | per second fee                                                                                                 | | | StabilityFee        | string (dec)  | "1.000000001547126"                         | per second fee                                                                                                 | | ||||||
| | Prefix           | number (byte) | 34                                          | identifier used in store keys - **must** be unique across collateral types                                     | | | Prefix              | number (byte) | 34                                          | identifier used in store keys - **must** be unique across collateral types                                     | | ||||||
| | MarketID         | string        | "bnb:usd"                                   | price feed identifier for this collateral type                                                                 | | | SpotMarketID        | string        | "bnb:usd"                                   | price feed identifier for the spot price of this collateral type                                                       | | ||||||
| | ConversionFactor | string (int)  | "6"                                         | 10^_ multiplier to go from external amount (say BTC1.50) to internal representation of that amount (150000000) | | | LiquidationMarketID | string        | "bnb:usd:30"                                | price feed identifier for the liquidation price of this collateral type                                                       | | ||||||
|  | | ConversionFactor    | string (int)  | "6"                                         | 10^_ multiplier to go from external amount (say BTC1.50) to internal representation of that amount (150000000) | | ||||||
| 
 | 
 | ||||||
| DebtParam has the following parameters: | DebtParam has the following parameters: | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -89,15 +89,16 @@ func DefaultParams() Params { | |||||||
| 
 | 
 | ||||||
| // CollateralParam governance parameters for each collateral type within the cdp module
 | // CollateralParam governance parameters for each collateral type within the cdp module
 | ||||||
| type CollateralParam struct { | type CollateralParam struct { | ||||||
| 	Denom              string   `json:"denom" yaml:"denom"`                             // Coin name of collateral type
 | 	Denom               string   `json:"denom" yaml:"denom"`                             // Coin name of collateral type
 | ||||||
| 	LiquidationRatio   sdk.Dec  `json:"liquidation_ratio" yaml:"liquidation_ratio"`     // The ratio (Collateral (priced in stable coin) / Debt) under which a CDP will be liquidated
 | 	LiquidationRatio    sdk.Dec  `json:"liquidation_ratio" yaml:"liquidation_ratio"`     // The ratio (Collateral (priced in stable coin) / Debt) under which a CDP will be liquidated
 | ||||||
| 	DebtLimit          sdk.Coin `json:"debt_limit" yaml:"debt_limit"`                   // Maximum amount of debt allowed to be drawn from this collateral type
 | 	DebtLimit           sdk.Coin `json:"debt_limit" yaml:"debt_limit"`                   // Maximum amount of debt allowed to be drawn from this collateral type
 | ||||||
| 	StabilityFee       sdk.Dec  `json:"stability_fee" yaml:"stability_fee"`             // per second stability fee for loans opened using this collateral
 | 	StabilityFee        sdk.Dec  `json:"stability_fee" yaml:"stability_fee"`             // per second stability fee for loans opened using this collateral
 | ||||||
| 	AuctionSize        sdk.Int  `json:"auction_size" yaml:"auction_size"`               // Max amount of collateral to sell off in any one auction.
 | 	AuctionSize         sdk.Int  `json:"auction_size" yaml:"auction_size"`               // Max amount of collateral to sell off in any one auction.
 | ||||||
| 	LiquidationPenalty sdk.Dec  `json:"liquidation_penalty" yaml:"liquidation_penalty"` // percentage penalty (between [0, 1]) applied to a cdp if it is liquidated
 | 	LiquidationPenalty  sdk.Dec  `json:"liquidation_penalty" yaml:"liquidation_penalty"` // percentage penalty (between [0, 1]) applied to a cdp if it is liquidated
 | ||||||
| 	Prefix             byte     `json:"prefix" yaml:"prefix"` | 	Prefix              byte     `json:"prefix" yaml:"prefix"` | ||||||
| 	MarketID           string   `json:"market_id" yaml:"market_id"`                 // marketID for fetching price of the asset from the pricefeed
 | 	SpotMarketID        string   `json:"spot_market_id" yaml:"spot_market_id"`              // marketID of the spot price of the asset from the pricefeed - used for opening CDPs, depositing, withdrawing
 | ||||||
| 	ConversionFactor   sdk.Int  `json:"conversion_factor" yaml:"conversion_factor"` // factor for converting internal units to one base unit of collateral
 | 	LiquidationMarketID string   `json:"liquidation_market_id" yaml:"liquidation_market_id` // marketID of the pricefeed used for liquidation
 | ||||||
|  | 	ConversionFactor    sdk.Int  `json:"conversion_factor" yaml:"conversion_factor"`        // factor for converting internal units to one base unit of collateral
 | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // String implements fmt.Stringer
 | // String implements fmt.Stringer
 | ||||||
| @ -110,9 +111,10 @@ func (cp CollateralParam) String() string { | |||||||
| 	Debt Limit: %s | 	Debt Limit: %s | ||||||
| 	Auction Size: %s | 	Auction Size: %s | ||||||
| 	Prefix: %b | 	Prefix: %b | ||||||
| 	Market ID: %s | 	Spot Market ID: %s | ||||||
|  | 	Liquidation Market ID: %s | ||||||
| 	Conversion Factor: %s`, | 	Conversion Factor: %s`, | ||||||
| 		cp.Denom, cp.LiquidationRatio, cp.StabilityFee, cp.LiquidationPenalty, cp.DebtLimit, cp.AuctionSize, cp.Prefix, cp.MarketID, cp.ConversionFactor) | 		cp.Denom, cp.LiquidationRatio, cp.StabilityFee, cp.LiquidationPenalty, cp.DebtLimit, cp.AuctionSize, cp.Prefix, cp.SpotMarketID, cp.LiquidationMarketID, cp.ConversionFactor) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // CollateralParams array of CollateralParam
 | // CollateralParams array of CollateralParam
 | ||||||
| @ -276,8 +278,12 @@ func validateCollateralParams(i interface{}) error { | |||||||
| 			return fmt.Errorf("collateral denom invalid %s", cp.Denom) | 			return fmt.Errorf("collateral denom invalid %s", cp.Denom) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		if strings.TrimSpace(cp.MarketID) == "" { | 		if strings.TrimSpace(cp.SpotMarketID) == "" { | ||||||
| 			return fmt.Errorf("market id cannot be blank %s", cp) | 			return fmt.Errorf("spot market id cannot be blank %s", cp) | ||||||
|  | 		} | ||||||
|  | 
 | ||||||
|  | 		if strings.TrimSpace(cp.LiquidationMarketID) == "" { | ||||||
|  | 			return fmt.Errorf("liquidation market id cannot be blank %s", cp) | ||||||
| 		} | 		} | ||||||
| 
 | 
 | ||||||
| 		prefix := int(cp.Prefix) | 		prefix := int(cp.Prefix) | ||||||
|  | |||||||
| @ -61,15 +61,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 4000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 4000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -95,15 +96,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 4000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 4000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -129,15 +131,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -163,26 +166,28 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 4000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 4000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "xrp", | 						Denom:               "xrp", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x21, | 						Prefix:              0x21, | ||||||
| 						MarketID:           "xrp:usd", | 						SpotMarketID:        "xrp:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(6), | 						LiquidationMarketID: "xrp:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(6), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -208,26 +213,28 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "xrp", | 						Denom:               "xrp", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x21, | 						Prefix:              0x21, | ||||||
| 						MarketID:           "xrp:usd", | 						SpotMarketID:        "xrp:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(6), | 						LiquidationMarketID: "xrp:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(6), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -253,26 +260,28 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 4000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 4000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "xrp", | 						Denom:               "xrp", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("susd", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("susd", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x21, | 						Prefix:              0x21, | ||||||
| 						MarketID:           "xrp:usd", | 						SpotMarketID:        "xrp:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(6), | 						LiquidationMarketID: "xrp:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(6), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -298,15 +307,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "", | 						Denom:               "", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -332,15 +342,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "", | 						SpotMarketID:        "", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -366,26 +377,28 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x21, | 						Prefix:              0x21, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -411,26 +424,28 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "xrp", | 						Denom:               "xrp", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "xrp:usd", | 						SpotMarketID:        "xrp:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "xrp:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -456,15 +471,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.Coin{}, | 						DebtLimit:           sdk.Coin{}, | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -490,15 +506,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("1.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("1.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -524,15 +541,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.ZeroInt(), | 						AuctionSize:         sdk.ZeroInt(), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -558,15 +576,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.1"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.1"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -592,15 +611,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
| @ -626,15 +646,16 @@ func (suite *ParamsTestSuite) TestParamValidation() { | |||||||
| 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | 				globalDebtLimit: sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 				collateralParams: types.CollateralParams{ | 				collateralParams: types.CollateralParams{ | ||||||
| 					{ | 					{ | ||||||
| 						Denom:              "bnb", | 						Denom:               "bnb", | ||||||
| 						LiquidationRatio:   sdk.MustNewDecFromStr("1.5"), | 						LiquidationRatio:    sdk.MustNewDecFromStr("1.5"), | ||||||
| 						DebtLimit:          sdk.NewInt64Coin("usdx", 2000000000000), | 						DebtLimit:           sdk.NewInt64Coin("usdx", 2000000000000), | ||||||
| 						StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), | 						StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), | ||||||
| 						LiquidationPenalty: sdk.MustNewDecFromStr("0.05"), | 						LiquidationPenalty:  sdk.MustNewDecFromStr("0.05"), | ||||||
| 						AuctionSize:        sdk.NewInt(50000000000), | 						AuctionSize:         sdk.NewInt(50000000000), | ||||||
| 						Prefix:             0x20, | 						Prefix:              0x20, | ||||||
| 						MarketID:           "bnb:usd", | 						SpotMarketID:        "bnb:usd", | ||||||
| 						ConversionFactor:   sdk.NewInt(8), | 						LiquidationMarketID: "bnb:usd", | ||||||
|  | 						ConversionFactor:    sdk.NewInt(8), | ||||||
| 					}, | 					}, | ||||||
| 				}, | 				}, | ||||||
| 				debtParam: types.DebtParam{ | 				debtParam: types.DebtParam{ | ||||||
|  | |||||||
| @ -31,26 +31,28 @@ func (suite *PermissionTestSuite) TestSubParamChangePermission_Allows() { | |||||||
| 	// cdp CollateralParams
 | 	// cdp CollateralParams
 | ||||||
| 	testCPs := cdptypes.CollateralParams{ | 	testCPs := cdptypes.CollateralParams{ | ||||||
| 		{ | 		{ | ||||||
| 			Denom:              "bnb", | 			Denom:               "bnb", | ||||||
| 			LiquidationRatio:   d("2.0"), | 			LiquidationRatio:    d("2.0"), | ||||||
| 			DebtLimit:          c("usdx", 1000000000000), | 			DebtLimit:           c("usdx", 1000000000000), | ||||||
| 			StabilityFee:       d("1.000000001547125958"), | 			StabilityFee:        d("1.000000001547125958"), | ||||||
| 			LiquidationPenalty: d("0.05"), | 			LiquidationPenalty:  d("0.05"), | ||||||
| 			AuctionSize:        i(100), | 			AuctionSize:         i(100), | ||||||
| 			Prefix:             0x20, | 			Prefix:              0x20, | ||||||
| 			ConversionFactor:   i(6), | 			ConversionFactor:    i(6), | ||||||
| 			MarketID:           "bnb:usd", | 			SpotMarketID:        "bnb:usd", | ||||||
|  | 			LiquidationMarketID: "bnb:usd", | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Denom:              "btc", | 			Denom:               "btc", | ||||||
| 			LiquidationRatio:   d("1.5"), | 			LiquidationRatio:    d("1.5"), | ||||||
| 			DebtLimit:          c("usdx", 1000000000), | 			DebtLimit:           c("usdx", 1000000000), | ||||||
| 			StabilityFee:       d("1.000000001547125958"), | 			StabilityFee:        d("1.000000001547125958"), | ||||||
| 			LiquidationPenalty: d("0.10"), | 			LiquidationPenalty:  d("0.10"), | ||||||
| 			AuctionSize:        i(1000), | 			AuctionSize:         i(1000), | ||||||
| 			Prefix:             0x30, | 			Prefix:              0x30, | ||||||
| 			ConversionFactor:   i(8), | 			ConversionFactor:    i(8), | ||||||
| 			MarketID:           "btc:usd", | 			SpotMarketID:        "btc:usd", | ||||||
|  | 			LiquidationMarketID: "btc:usd", | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	testCPUpdatedDebtLimit := make(cdptypes.CollateralParams, len(testCPs)) | 	testCPUpdatedDebtLimit := make(cdptypes.CollateralParams, len(testCPs)) | ||||||
|  | |||||||
| @ -86,15 +86,16 @@ func (suite *KeeperTestSuite) TestSubmitProposal() { | |||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
| 	testCP := cdptypes.CollateralParams{{ | 	testCP := cdptypes.CollateralParams{{ | ||||||
| 		Denom:              "bnb", | 		Denom:               "bnb", | ||||||
| 		LiquidationRatio:   d("1.5"), | 		LiquidationRatio:    d("1.5"), | ||||||
| 		DebtLimit:          c("usdx", 1000000000000), | 		DebtLimit:           c("usdx", 1000000000000), | ||||||
| 		StabilityFee:       d("1.000000001547125958"), // %5 apr
 | 		StabilityFee:        d("1.000000001547125958"), // %5 apr
 | ||||||
| 		LiquidationPenalty: d("0.05"), | 		LiquidationPenalty:  d("0.05"), | ||||||
| 		AuctionSize:        i(100), | 		AuctionSize:         i(100), | ||||||
| 		Prefix:             0x20, | 		Prefix:              0x20, | ||||||
| 		ConversionFactor:   i(6), | 		ConversionFactor:    i(6), | ||||||
| 		MarketID:           "bnb:usd", | 		LiquidationMarketID: "bnb:usd", | ||||||
|  | 		SpotMarketID:        "bnb:usd", | ||||||
| 	}} | 	}} | ||||||
| 	testCDPParams := cdptypes.DefaultParams() | 	testCDPParams := cdptypes.DefaultParams() | ||||||
| 	testCDPParams.CollateralParams = testCP | 	testCDPParams.CollateralParams = testCP | ||||||
| @ -106,7 +107,7 @@ func (suite *KeeperTestSuite) TestSubmitProposal() { | |||||||
| 
 | 
 | ||||||
| 	newInvalidCP := make(cdptypes.CollateralParams, len(testCP)) | 	newInvalidCP := make(cdptypes.CollateralParams, len(testCP)) | ||||||
| 	copy(newInvalidCP, testCP) | 	copy(newInvalidCP, testCP) | ||||||
| 	newInvalidCP[0].MarketID = "btc:usd" | 	newInvalidCP[0].SpotMarketID = "btc:usd" | ||||||
| 
 | 
 | ||||||
| 	testcases := []struct { | 	testcases := []struct { | ||||||
| 		name        string | 		name        string | ||||||
|  | |||||||
| @ -16,37 +16,40 @@ func cs(coins ...sdk.Coin) sdk.Coins        { return sdk.NewCoins(coins...) } | |||||||
| func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { | func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { | ||||||
| 	testCPs := cdptypes.CollateralParams{ | 	testCPs := cdptypes.CollateralParams{ | ||||||
| 		{ | 		{ | ||||||
| 			Denom:              "bnb", | 			Denom:               "bnb", | ||||||
| 			LiquidationRatio:   d("2.0"), | 			LiquidationRatio:    d("2.0"), | ||||||
| 			DebtLimit:          c("usdx", 1000000000000), | 			DebtLimit:           c("usdx", 1000000000000), | ||||||
| 			StabilityFee:       d("1.000000001547125958"), | 			StabilityFee:        d("1.000000001547125958"), | ||||||
| 			LiquidationPenalty: d("0.05"), | 			LiquidationPenalty:  d("0.05"), | ||||||
| 			AuctionSize:        i(100), | 			AuctionSize:         i(100), | ||||||
| 			Prefix:             0x20, | 			Prefix:              0x20, | ||||||
| 			ConversionFactor:   i(6), | 			ConversionFactor:    i(6), | ||||||
| 			MarketID:           "bnb:usd", | 			SpotMarketID:        "bnb:usd", | ||||||
|  | 			LiquidationMarketID: "bnb:usd", | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Denom:              "btc", | 			Denom:               "btc", | ||||||
| 			LiquidationRatio:   d("1.5"), | 			LiquidationRatio:    d("1.5"), | ||||||
| 			DebtLimit:          c("usdx", 1000000000), | 			DebtLimit:           c("usdx", 1000000000), | ||||||
| 			StabilityFee:       d("1.000000001547125958"), | 			StabilityFee:        d("1.000000001547125958"), | ||||||
| 			LiquidationPenalty: d("0.10"), | 			LiquidationPenalty:  d("0.10"), | ||||||
| 			AuctionSize:        i(1000), | 			AuctionSize:         i(1000), | ||||||
| 			Prefix:             0x30, | 			Prefix:              0x30, | ||||||
| 			ConversionFactor:   i(8), | 			ConversionFactor:    i(8), | ||||||
| 			MarketID:           "btc:usd", | 			SpotMarketID:        "btc:usd", | ||||||
|  | 			LiquidationMarketID: "btc:usd", | ||||||
| 		}, | 		}, | ||||||
| 		{ | 		{ | ||||||
| 			Denom:              "atom", | 			Denom:               "atom", | ||||||
| 			LiquidationRatio:   d("2.0"), | 			LiquidationRatio:    d("2.0"), | ||||||
| 			DebtLimit:          c("usdx", 1000000000), | 			DebtLimit:           c("usdx", 1000000000), | ||||||
| 			StabilityFee:       d("1.000000001547125958"), | 			StabilityFee:        d("1.000000001547125958"), | ||||||
| 			LiquidationPenalty: d("0.07"), | 			LiquidationPenalty:  d("0.07"), | ||||||
| 			AuctionSize:        i(100), | 			AuctionSize:         i(100), | ||||||
| 			Prefix:             0x40, | 			Prefix:              0x40, | ||||||
| 			ConversionFactor:   i(6), | 			ConversionFactor:    i(6), | ||||||
| 			MarketID:           "atom:usd", | 			SpotMarketID:        "atom:usd", | ||||||
|  | 			LiquidationMarketID: "atom:usd", | ||||||
| 		}, | 		}, | ||||||
| 	} | 	} | ||||||
| 	updatedTestCPs := make(cdptypes.CollateralParams, len(testCPs)) | 	updatedTestCPs := make(cdptypes.CollateralParams, len(testCPs)) | ||||||
| @ -78,15 +81,16 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { | |||||||
| 					StabilityFee: true, | 					StabilityFee: true, | ||||||
| 				}, | 				}, | ||||||
| 				{ // allow all fields
 | 				{ // allow all fields
 | ||||||
| 					Denom:              "atom", | 					Denom:               "atom", | ||||||
| 					LiquidationRatio:   true, | 					LiquidationRatio:    true, | ||||||
| 					DebtLimit:          true, | 					DebtLimit:           true, | ||||||
| 					StabilityFee:       true, | 					StabilityFee:        true, | ||||||
| 					AuctionSize:        true, | 					AuctionSize:         true, | ||||||
| 					LiquidationPenalty: true, | 					LiquidationPenalty:  true, | ||||||
| 					Prefix:             true, | 					Prefix:              true, | ||||||
| 					MarketID:           true, | 					SpotMarketID:        true, | ||||||
| 					ConversionFactor:   true, | 					LiquidationMarketID: true, | ||||||
|  | 					ConversionFactor:    true, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			current:       testCPs[:2], | 			current:       testCPs[:2], | ||||||
| @ -102,15 +106,16 @@ func (suite *PermissionsTestSuite) TestAllowedCollateralParams_Allows() { | |||||||
| 				}, | 				}, | ||||||
| 				{ | 				{ | ||||||
| 					// allow all fields
 | 					// allow all fields
 | ||||||
| 					Denom:              "btc", | 					Denom:               "btc", | ||||||
| 					LiquidationRatio:   true, | 					LiquidationRatio:    true, | ||||||
| 					DebtLimit:          true, | 					DebtLimit:           true, | ||||||
| 					StabilityFee:       true, | 					StabilityFee:        true, | ||||||
| 					AuctionSize:        true, | 					AuctionSize:         true, | ||||||
| 					LiquidationPenalty: true, | 					LiquidationPenalty:  true, | ||||||
| 					Prefix:             true, | 					Prefix:              true, | ||||||
| 					MarketID:           true, | 					SpotMarketID:        true, | ||||||
| 					ConversionFactor:   true, | 					LiquidationMarketID: true, | ||||||
|  | 					ConversionFactor:    true, | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			current:       testCPs[:2], | 			current:       testCPs[:2], | ||||||
| @ -376,24 +381,25 @@ func (suite *PermissionsTestSuite) TestAllowedMarkets_Allows() { | |||||||
| 
 | 
 | ||||||
| func (suite *PermissionsTestSuite) TestAllowedCollateralParam_Allows() { | func (suite *PermissionsTestSuite) TestAllowedCollateralParam_Allows() { | ||||||
| 	testCP := cdptypes.CollateralParam{ | 	testCP := cdptypes.CollateralParam{ | ||||||
| 		Denom:              "bnb", | 		Denom:               "bnb", | ||||||
| 		LiquidationRatio:   d("1.5"), | 		LiquidationRatio:    d("1.5"), | ||||||
| 		DebtLimit:          c("usdx", 1000000000000), | 		DebtLimit:           c("usdx", 1000000000000), | ||||||
| 		StabilityFee:       d("1.000000001547125958"), // %5 apr
 | 		StabilityFee:        d("1.000000001547125958"), // %5 apr
 | ||||||
| 		LiquidationPenalty: d("0.05"), | 		LiquidationPenalty:  d("0.05"), | ||||||
| 		AuctionSize:        i(100), | 		AuctionSize:         i(100), | ||||||
| 		Prefix:             0x20, | 		Prefix:              0x20, | ||||||
| 		ConversionFactor:   i(6), | 		ConversionFactor:    i(6), | ||||||
| 		MarketID:           "bnb:usd", | 		SpotMarketID:        "bnb:usd", | ||||||
|  | 		LiquidationMarketID: "bnb:usd", | ||||||
| 	} | 	} | ||||||
| 	newMarketIDCP := testCP | 	newMarketIDCP := testCP | ||||||
| 	newMarketIDCP.MarketID = "btc:usd" | 	newMarketIDCP.SpotMarketID = "btc:usd" | ||||||
| 
 | 
 | ||||||
| 	newDebtLimitCP := testCP | 	newDebtLimitCP := testCP | ||||||
| 	newDebtLimitCP.DebtLimit = c("usdx", 1000) | 	newDebtLimitCP.DebtLimit = c("usdx", 1000) | ||||||
| 
 | 
 | ||||||
| 	newMarketIDAndDebtLimitCP := testCP | 	newMarketIDAndDebtLimitCP := testCP | ||||||
| 	newMarketIDCP.MarketID = "btc:usd" | 	newMarketIDCP.SpotMarketID = "btc:usd" | ||||||
| 	newDebtLimitCP.DebtLimit = c("usdx", 1000) | 	newDebtLimitCP.DebtLimit = c("usdx", 1000) | ||||||
| 
 | 
 | ||||||
| 	testcases := []struct { | 	testcases := []struct { | ||||||
|  | |||||||
| @ -372,15 +372,16 @@ func (acps AllowedCollateralParams) Allows(current, incoming cdptypes.Collateral | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type AllowedCollateralParam struct { | type AllowedCollateralParam struct { | ||||||
| 	Denom              string `json:"denom" yaml:"denom"` | 	Denom               string `json:"denom" yaml:"denom"` | ||||||
| 	LiquidationRatio   bool   `json:"liquidation_ratio" yaml:"liquidation_ratio"` | 	LiquidationRatio    bool   `json:"liquidation_ratio" yaml:"liquidation_ratio"` | ||||||
| 	DebtLimit          bool   `json:"debt_limit" yaml:"debt_limit"` | 	DebtLimit           bool   `json:"debt_limit" yaml:"debt_limit"` | ||||||
| 	StabilityFee       bool   `json:"stability_fee" yaml:"stability_fee"` | 	StabilityFee        bool   `json:"stability_fee" yaml:"stability_fee"` | ||||||
| 	AuctionSize        bool   `json:"auction_size" yaml:"auction_size"` | 	AuctionSize         bool   `json:"auction_size" yaml:"auction_size"` | ||||||
| 	LiquidationPenalty bool   `json:"liquidation_penalty" yaml:"liquidation_penalty"` | 	LiquidationPenalty  bool   `json:"liquidation_penalty" yaml:"liquidation_penalty"` | ||||||
| 	Prefix             bool   `json:"prefix" yaml:"prefix"` | 	Prefix              bool   `json:"prefix" yaml:"prefix"` | ||||||
| 	MarketID           bool   `json:"market_id" yaml:"market_id"` | 	SpotMarketID        bool   `json:"spot_market_id" yaml:"spot_market_id"` | ||||||
| 	ConversionFactor   bool   `json:"conversion_factor" yaml:"conversion_factor"` | 	LiquidationMarketID bool   `json:"liquidation_market_id" yaml:"liquidation_market_id"` | ||||||
|  | 	ConversionFactor    bool   `json:"conversion_factor" yaml:"conversion_factor"` | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (acp AllowedCollateralParam) Allows(current, incoming cdptypes.CollateralParam) bool { | func (acp AllowedCollateralParam) Allows(current, incoming cdptypes.CollateralParam) bool { | ||||||
| @ -391,7 +392,8 @@ func (acp AllowedCollateralParam) Allows(current, incoming cdptypes.CollateralPa | |||||||
| 		(current.AuctionSize.Equal(incoming.AuctionSize) || acp.AuctionSize) && | 		(current.AuctionSize.Equal(incoming.AuctionSize) || acp.AuctionSize) && | ||||||
| 		(current.LiquidationPenalty.Equal(incoming.LiquidationPenalty) || acp.LiquidationPenalty) && | 		(current.LiquidationPenalty.Equal(incoming.LiquidationPenalty) || acp.LiquidationPenalty) && | ||||||
| 		((current.Prefix == incoming.Prefix) || acp.Prefix) && | 		((current.Prefix == incoming.Prefix) || acp.Prefix) && | ||||||
| 		((current.MarketID == incoming.MarketID) || acp.MarketID) && | 		((current.SpotMarketID == incoming.SpotMarketID) || acp.SpotMarketID) && | ||||||
|  | 		((current.LiquidationMarketID == incoming.LiquidationMarketID) || acp.LiquidationMarketID) && | ||||||
| 		(current.ConversionFactor.Equal(incoming.ConversionFactor) || acp.ConversionFactor) | 		(current.ConversionFactor.Equal(incoming.ConversionFactor) || acp.ConversionFactor) | ||||||
| 	return allowed | 	return allowed | ||||||
| } | } | ||||||
|  | |||||||
| @ -183,15 +183,16 @@ func (suite *KeeperTestSuite) setupCdpChain() { | |||||||
| 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | 			SavingsDistributionFrequency: cdp.DefaultSavingsDistributionFrequency, | ||||||
| 			CollateralParams: cdp.CollateralParams{ | 			CollateralParams: cdp.CollateralParams{ | ||||||
| 				{ | 				{ | ||||||
| 					Denom:              "bnb", | 					Denom:               "bnb", | ||||||
| 					LiquidationRatio:   sdk.MustNewDecFromStr("2.0"), | 					LiquidationRatio:    sdk.MustNewDecFromStr("2.0"), | ||||||
| 					DebtLimit:          sdk.NewInt64Coin("usdx", 1000000000000), | 					DebtLimit:           sdk.NewInt64Coin("usdx", 1000000000000), | ||||||
| 					StabilityFee:       sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | 					StabilityFee:        sdk.MustNewDecFromStr("1.000000001547125958"), // %5 apr
 | ||||||
| 					LiquidationPenalty: d("0.05"), | 					LiquidationPenalty:  d("0.05"), | ||||||
| 					AuctionSize:        i(10000000000), | 					AuctionSize:         i(10000000000), | ||||||
| 					Prefix:             0x20, | 					Prefix:              0x20, | ||||||
| 					MarketID:           "bnb:usd", | 					SpotMarketID:        "bnb:usd", | ||||||
| 					ConversionFactor:   i(8), | 					LiquidationMarketID: "bnb:usd", | ||||||
|  | 					ConversionFactor:    i(8), | ||||||
| 				}, | 				}, | ||||||
| 			}, | 			}, | ||||||
| 			DebtParam: cdp.DebtParam{ | 			DebtParam: cdp.DebtParam{ | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Kevin Davis
						Kevin Davis