mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-04-04 15:55:23 +00:00 
			
		
		
		
	fix: enforce cdp denom matches collateral type (#638)
This commit is contained in:
		
							parent
							
								
									5fc85f10a6
								
							
						
					
					
						commit
						a53fbc354a
					
				| @ -350,6 +350,9 @@ func (k Keeper) ValidateCollateral(ctx sdk.Context, collateral sdk.Coin, collate | |||||||
| 	if !found { | 	if !found { | ||||||
| 		return sdkerrors.Wrap(types.ErrCollateralNotSupported, collateral.Denom) | 		return sdkerrors.Wrap(types.ErrCollateralNotSupported, collateral.Denom) | ||||||
| 	} | 	} | ||||||
|  | 	if cp.Denom != collateral.Denom { | ||||||
|  | 		return sdkerrors.Wrapf(types.ErrInvalidCollateral, "collateral type: %s expected denom: %s got: %s", collateralType, cp.Denom, collateral.Denom) | ||||||
|  | 	} | ||||||
| 	ok := k.GetMarketStatus(ctx, cp.SpotMarketID) | 	ok := k.GetMarketStatus(ctx, cp.SpotMarketID) | ||||||
| 	if !ok { | 	if !ok { | ||||||
| 		return sdkerrors.Wrap(types.ErrPricefeedDown, collateral.Denom) | 		return sdkerrors.Wrap(types.ErrPricefeedDown, collateral.Denom) | ||||||
|  | |||||||
| @ -47,7 +47,9 @@ func (suite *CdpTestSuite) TestAddCdp() { | |||||||
| 	acc := ak.NewAccountWithAddress(suite.ctx, addrs[0]) | 	acc := ak.NewAccountWithAddress(suite.ctx, addrs[0]) | ||||||
| 	acc.SetCoins(cs(c("xrp", 200000000), c("btc", 500000000))) | 	acc.SetCoins(cs(c("xrp", 200000000), c("btc", 500000000))) | ||||||
| 	ak.SetAccount(suite.ctx, acc) | 	ak.SetAccount(suite.ctx, acc) | ||||||
| 	err := suite.keeper.AddCdp(suite.ctx, addrs[0], c("xrp", 200000000), c("usdx", 26000000), "xrp-a") | 	err := suite.keeper.AddCdp(suite.ctx, addrs[0], c("xrp", 200000000), c("usdx", 10000000), "btc-a") | ||||||
|  | 	suite.Require().True(errors.Is(err, types.ErrInvalidCollateral)) | ||||||
|  | 	err = suite.keeper.AddCdp(suite.ctx, addrs[0], c("xrp", 200000000), c("usdx", 26000000), "xrp-a") | ||||||
| 	suite.Require().True(errors.Is(err, types.ErrInvalidCollateralRatio)) | 	suite.Require().True(errors.Is(err, types.ErrInvalidCollateralRatio)) | ||||||
| 	err = suite.keeper.AddCdp(suite.ctx, addrs[0], c("xrp", 500000000), c("usdx", 26000000), "xrp-a") | 	err = suite.keeper.AddCdp(suite.ctx, addrs[0], c("xrp", 500000000), c("usdx", 26000000), "xrp-a") | ||||||
| 	suite.Error(err) // insufficient balance
 | 	suite.Error(err) // insufficient balance
 | ||||||
|  | |||||||
| @ -43,4 +43,6 @@ var ( | |||||||
| 	ErrDenomPrefixNotFound = sdkerrors.Register(ModuleName, 18, "denom prefix not found") | 	ErrDenomPrefixNotFound = sdkerrors.Register(ModuleName, 18, "denom prefix not found") | ||||||
| 	// ErrPricefeedDown error for when a price for the input denom is not found
 | 	// ErrPricefeedDown error for when a price for the input denom is not found
 | ||||||
| 	ErrPricefeedDown = sdkerrors.Register(ModuleName, 19, "no price found for collateral") | 	ErrPricefeedDown = sdkerrors.Register(ModuleName, 19, "no price found for collateral") | ||||||
|  | 	// ErrInvalidCollateral error for when the input collateral denom does not match the expected collateral denom
 | ||||||
|  | 	ErrInvalidCollateral = sdkerrors.Register(ModuleName, 20, "invalid collateral for input collateral type") | ||||||
| ) | ) | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Kevin Davis
						Kevin Davis