From 0cdc3baf5a021b20d5691c1bac740e8b37507fdd Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Sun, 27 Mar 2022 15:39:26 -0700 Subject: [PATCH] chore: clarify negative interest time error message (#711) (#713) (cherry picked from commit 7ccbcaba850d7b9c142f6d4e18d9f10360fabf1a) Co-authored-by: Adam Moser <63419657+toteki@users.noreply.github.com> Co-authored-by: Adam Wozniak <29418299+adamewozniak@users.noreply.github.com> --- x/leverage/keeper/interest.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/x/leverage/keeper/interest.go b/x/leverage/keeper/interest.go index 4de16d4144..b9712100ff 100644 --- a/x/leverage/keeper/interest.go +++ b/x/leverage/keeper/interest.go @@ -72,10 +72,11 @@ func (k Keeper) AccrueAllInterest(ctx sdk.Context) error { } // calculate time elapsed since last interest accrual (measured in years for APR math) - yearsElapsed := sdk.NewDec(currentTime - prevInterestTime).QuoInt64(types.SecondsPerYear) - if yearsElapsed.IsNegative() { - return sdkerrors.Wrap(types.ErrNegativeTimeElapsed, yearsElapsed.String()+" years") + secondsElapsed := currentTime - prevInterestTime + if secondsElapsed < 0 { + return sdkerrors.Wrap(types.ErrNegativeTimeElapsed, fmt.Sprintf("%d seconds", secondsElapsed)) } + yearsElapsed := sdk.NewDec(secondsElapsed).QuoInt64(types.SecondsPerYear) // fetch required parameters tokens := k.GetAllRegisteredTokens(ctx)