mirror of
https://github.com/0glabs/0g-chain.git
synced 2024-11-10 10:05:18 +00:00
fix: don't accumulate if borrow interest rounds to zero (#808)
This commit is contained in:
parent
58db05f8e2
commit
7d4235ca87
@ -120,6 +120,12 @@ func (k Keeper) AccrueInterest(ctx sdk.Context, denom string) error {
|
||||
// Calculate borrow interest factor and update
|
||||
borrowInterestFactor := CalculateBorrowInterestFactor(borrowRateSpy, sdk.NewInt(timeElapsed))
|
||||
interestBorrowAccumulated := (borrowInterestFactor.Mul(sdk.NewDecFromInt(borrowedPrior.Amount)).TruncateInt()).Sub(borrowedPrior.Amount)
|
||||
|
||||
if interestBorrowAccumulated.IsZero() && borrowRateApy.IsPositive() {
|
||||
// don't accumulate if borrow interest is rounding to zero
|
||||
return nil
|
||||
}
|
||||
|
||||
totalBorrowInterestAccumulated := sdk.NewCoins(sdk.NewCoin(denom, interestBorrowAccumulated))
|
||||
reservesNew := interestBorrowAccumulated.ToDec().Mul(mm.ReserveFactor).TruncateInt()
|
||||
borrowInterestFactorNew := borrowInterestFactorPrior.Mul(borrowInterestFactor)
|
||||
|
Loading…
Reference in New Issue
Block a user