From e58d2dc32094f399b98164e8e4be2973349cacfa Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Tue, 31 Mar 2020 08:54:31 -0400 Subject: [PATCH] fix: remove old index when updating fees (#409) --- x/cdp/keeper/fees.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x/cdp/keeper/fees.go b/x/cdp/keeper/fees.go index 53af1138..6f6693ed 100644 --- a/x/cdp/keeper/fees.go +++ b/x/cdp/keeper/fees.go @@ -35,7 +35,6 @@ func (k Keeper) CalculateFees(ctx sdk.Context, principal sdk.Coins, periods sdk. // is when we made the update func (k Keeper) UpdateFeesForRiskyCdps(ctx sdk.Context, collateralDenom string, marketID string) sdk.Error { - price, err := k.pricefeedKeeper.GetCurrentPrice(ctx, marketID) if err != nil { return err @@ -48,7 +47,7 @@ func (k Keeper) UpdateFeesForRiskyCdps(ctx sdk.Context, collateralDenom string, // now iterate over all the cdps based on collateral ratio k.IterateCdpsByCollateralRatio(ctx, collateralDenom, normalizedRatio, func(cdp types.CDP) bool { - + oldCollateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees)) // get the number of periods periods := sdk.NewInt(ctx.BlockTime().Unix()).Sub(sdk.NewInt(cdp.FeesUpdated.Unix())) @@ -61,6 +60,7 @@ func (k Keeper) UpdateFeesForRiskyCdps(ctx sdk.Context, collateralDenom string, // and set the fees updated time to the current block time since we just updated it cdp.FeesUpdated = ctx.BlockTime() collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Principal.Add(cdp.AccumulatedFees)) + k.RemoveCdpCollateralRatioIndex(ctx, cdp.Collateral[0].Denom, cdp.ID, oldCollateralToDebtRatio) k.SetCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio) return false // this returns true when you want to stop iterating. Since we want to iterate through all we return false })