fix: set interest last updated to previous accrual time, not block time (#829)

This commit is contained in:
Kevin Davis 2021-02-16 07:43:21 -07:00 committed by GitHub
parent e8d3d877aa
commit ad6ef76979
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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)