mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25:18 +00:00
Fix withdraw panic (#315)
* fix: remove redundant debt limit param * wip: test pricefeed genesis * fix: pricefeed querier * fix: comments, naming * fix: query path * fix: store methods * fix: query methods * feat: Liquidation Penalty * feat: enforce debt floor on repayment * fix: don't panic if withdrawing full amount * fix: remove debt from liquidation penalty
This commit is contained in:
parent
22dc15f757
commit
58deb49e55
@ -412,6 +412,9 @@ func (k Keeper) CalculateCollateralToDebtRatio(ctx sdk.Context, collateral sdk.C
|
|||||||
|
|
||||||
// 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.Coins, principal sdk.Coins, fees sdk.Coins) (sdk.Dec, sdk.Error) {
|
func (k Keeper) CalculateCollateralizationRatio(ctx sdk.Context, collateral sdk.Coins, principal sdk.Coins, fees sdk.Coins) (sdk.Dec, sdk.Error) {
|
||||||
|
if collateral.IsZero() {
|
||||||
|
return sdk.ZeroDec(), nil
|
||||||
|
}
|
||||||
marketID := k.getMarketID(ctx, collateral[0].Denom)
|
marketID := k.getMarketID(ctx, collateral[0].Denom)
|
||||||
price, err := k.pricefeedKeeper.GetCurrentPrice(ctx, marketID)
|
price, err := k.pricefeedKeeper.GetCurrentPrice(ctx, marketID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -93,7 +93,9 @@ func (suite *DepositTestSuite) TestDepositCollateral() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (suite *DepositTestSuite) TestWithdrawCollateral() {
|
func (suite *DepositTestSuite) TestWithdrawCollateral() {
|
||||||
err := suite.keeper.WithdrawCollateral(suite.ctx, suite.addrs[0], suite.addrs[0], cs(c("xrp", 321000000)))
|
err := suite.keeper.WithdrawCollateral(suite.ctx, suite.addrs[0], suite.addrs[0], cs(c("xrp", 400000000)))
|
||||||
|
suite.Equal(types.CodeInvalidCollateralRatio, err.Result().Code)
|
||||||
|
err = suite.keeper.WithdrawCollateral(suite.ctx, suite.addrs[0], suite.addrs[0], cs(c("xrp", 321000000)))
|
||||||
suite.Equal(types.CodeInvalidCollateralRatio, err.Result().Code)
|
suite.Equal(types.CodeInvalidCollateralRatio, err.Result().Code)
|
||||||
err = suite.keeper.WithdrawCollateral(suite.ctx, suite.addrs[1], suite.addrs[0], cs(c("xrp", 10000000)))
|
err = suite.keeper.WithdrawCollateral(suite.ctx, suite.addrs[1], suite.addrs[0], cs(c("xrp", 10000000)))
|
||||||
suite.Equal(types.CodeCdpNotFound, err.Result().Code)
|
suite.Equal(types.CodeCdpNotFound, err.Result().Code)
|
||||||
|
Loading…
Reference in New Issue
Block a user