diff --git a/x/cdp/keeper/draw.go b/x/cdp/keeper/draw.go index 666dbcec..94727045 100644 --- a/x/cdp/keeper/draw.go +++ b/x/cdp/keeper/draw.go @@ -106,12 +106,17 @@ func (k Keeper) RepayPrincipal(ctx sdk.Context, owner sdk.AccAddress, denom stri // burn the corresponding amount of debt coins cdpDebt := k.getModAccountDebt(ctx, types.ModuleName) - paymentAmount := feePayment.Amount.Add(principalPayment.Amount) - coinsToBurn := sdk.NewCoin(k.GetDebtDenom(ctx), paymentAmount) + paymentAmount := feePayment.Add(principalPayment).Amount + + debtDenom := k.GetDebtDenom(ctx) + coinsToBurn := sdk.NewCoin(debtDenom, paymentAmount) + if paymentAmount.GT(cdpDebt) { - coinsToBurn = sdk.NewCoin(k.GetDebtDenom(ctx), cdpDebt) + coinsToBurn = sdk.NewCoin(debtDenom, cdpDebt) } - err = k.BurnDebtCoins(ctx, types.ModuleName, k.GetDebtDenom(ctx), coinsToBurn) + + err = k.BurnDebtCoins(ctx, types.ModuleName, debtDenom, coinsToBurn) + if err != nil { panic(err) }