From aebb3093ff40fffb754cc2e059ba61fc1228a88e Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Wed, 3 Jun 2020 18:36:58 -0400 Subject: [PATCH] fix: use sdk.Int when loading augmented cdp (#539) --- x/cdp/keeper/cdp.go | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/x/cdp/keeper/cdp.go b/x/cdp/keeper/cdp.go index f808baf7..37ac6f87 100644 --- a/x/cdp/keeper/cdp.go +++ b/x/cdp/keeper/cdp.go @@ -439,17 +439,10 @@ func (k Keeper) LoadAugmentedCDP(ctx sdk.Context, cdp types.CDP) types.Augmented if err != nil { return types.AugmentedCDP{CDP: cdp} } - - // total debt is the sum of all outstanding principal and fees - var totalDebt int64 - totalDebt += cdp.Principal.Amount.Int64() - totalDebt += cdp.AccumulatedFees.Amount.Int64() - // convert collateral value to debt coin - debtBaseAdjusted := sdk.NewDec(totalDebt).QuoInt64(BaseDigitFactor) - collateralValueInDebtDenom := collateralizationRatio.Mul(debtBaseAdjusted) - collateralValueInDebt := sdk.NewInt64Coin(cdp.Principal.Denom, collateralValueInDebtDenom.Int64()) - + totalDebt := cdp.Principal.Amount.Add(cdp.AccumulatedFees.Amount) + collateralValueInDebtDenom := sdk.NewDecFromInt(totalDebt).Mul(collateralizationRatio) + collateralValueInDebt := sdk.NewCoin(cdp.Principal.Denom, collateralValueInDebtDenom.RoundInt()) // create new augmuented cdp augmentedCDP := types.NewAugmentedCDP(cdp, collateralValueInDebt, collateralizationRatio) return augmentedCDP