mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-12-24 15:25:18 +00:00
fix: avoid panic when closing cdp via repayment (#353)
This commit is contained in:
parent
3c8209cbcc
commit
bdff81b2a2
@ -110,7 +110,7 @@ func (k Keeper) MintDebtCoins(ctx sdk.Context, moduleAccount string, denom strin
|
||||
return nil
|
||||
}
|
||||
|
||||
// BurnDebtCoins burns debts coins from the cdp module account
|
||||
// BurnDebtCoins burns debt coins from the cdp module account
|
||||
func (k Keeper) BurnDebtCoins(ctx sdk.Context, moduleAccount string, denom string, paymentCoins sdk.Coins) sdk.Error {
|
||||
coinsToBurn := sdk.NewCoins()
|
||||
for _, pc := range paymentCoins {
|
||||
|
@ -110,7 +110,16 @@ func (k Keeper) RepayPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom stri
|
||||
}
|
||||
|
||||
// burn the corresponding amount of debt coins
|
||||
err = k.BurnDebtCoins(ctx, types.ModuleName, k.GetDebtDenom(ctx), feePayment.Add(principalPayment))
|
||||
cdpDebt := k.getModAccountDebt(ctx, types.ModuleName)
|
||||
paymentAmount := sdk.ZeroInt()
|
||||
for _, c := range feePayment.Add(principalPayment) {
|
||||
paymentAmount = paymentAmount.Add(c.Amount)
|
||||
}
|
||||
coinsToBurn := sdk.NewCoins(sdk.NewCoin(k.GetDebtDenom(ctx), paymentAmount))
|
||||
if paymentAmount.GT(cdpDebt) {
|
||||
coinsToBurn = sdk.NewCoins(sdk.NewCoin(k.GetDebtDenom(ctx), cdpDebt))
|
||||
}
|
||||
err = k.BurnDebtCoins(ctx, types.ModuleName, k.GetDebtDenom(ctx), coinsToBurn)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user