mirror of
				https://github.com/0glabs/0g-chain.git
				synced 2025-04-04 15:55:23 +00:00 
			
		
		
		
	fix: set interest last updated to previous accrual time, not block time (#829)
This commit is contained in:
		
							parent
							
								
									e8d3d877aa
								
							
						
					
					
						commit
						ad6ef76979
					
				| @ -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) | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user
	 Kevin Davis
						Kevin Davis