From 25abdd10b5971608786b4c8649cff3534c0712cd Mon Sep 17 00:00:00 2001 From: Nick DeLuca Date: Thu, 11 Jun 2020 14:32:39 -0500 Subject: [PATCH] Remove some redunancy in RepayPrinciple (#577) * fix exhibit 30 - remove redunant conversions in adding principle to fee amount, and store debt denom in local var to avoid calling getter several times * add deleted comment back --- x/cdp/keeper/draw.go | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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) }