From ad6ef769799d760e983af79677fd916ef66c0cc7 Mon Sep 17 00:00:00 2001 From: Kevin Davis Date: Tue, 16 Feb 2021 07:43:21 -0700 Subject: [PATCH] fix: set interest last updated to previous accrual time, not block time (#829) --- x/cdp/keeper/interest.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/x/cdp/keeper/interest.go b/x/cdp/keeper/interest.go index e841653c..17268e5b 100644 --- a/x/cdp/keeper/interest.go +++ b/x/cdp/keeper/interest.go @@ -116,24 +116,23 @@ func (k Keeper) SynchronizeInterest(ctx sdk.Context, cdp types.CDP) types.CDP { } accumulatedInterest := k.CalculateNewInterest(ctx, cdp) + prevAccrualTime, found := k.GetPreviousAccrualTime(ctx, cdp.Type) + if !found { + return cdp + } if accumulatedInterest.IsZero() { // accumulated interest is zero if apy is zero or are if the total fees for all cdps round to zero - - prevAccrualTime, found := k.GetPreviousAccrualTime(ctx, cdp.Type) - if !found { - return cdp - } if cdp.FeesUpdated.Equal(prevAccrualTime) { // if all fees are rounding to zero, don't update FeesUpdated return cdp } // if apy is zero, we need to update FeesUpdated - cdp.FeesUpdated = ctx.BlockTime() + cdp.FeesUpdated = prevAccrualTime k.SetCDP(ctx, cdp) } cdp.AccumulatedFees = cdp.AccumulatedFees.Add(accumulatedInterest) - cdp.FeesUpdated = ctx.BlockTime() + cdp.FeesUpdated = prevAccrualTime cdp.InterestFactor = globalInterestFactor collateralToDebtRatio := k.CalculateCollateralToDebtRatio(ctx, cdp.Collateral, cdp.Type, cdp.GetTotalPrincipal()) k.UpdateCdpAndCollateralRatioIndex(ctx, cdp, collateralToDebtRatio)