Skip to content

Commit

Permalink
chore: clarify negative time elapsed error (backport #1012) (#1013)
Browse files Browse the repository at this point in the history
* chore: clarify negative time elapsed error (#1012)

* chore: clarify negative time elapsed error

* cl++

(cherry picked from commit 650016f)

# Conflicts:
#	CHANGELOG.md

* fix conflicts

* newline++

Co-authored-by: toteki <63419657+toteki@users.noreply.github.com>
  • Loading branch information
mergify[bot] and toteki authored Jun 8, 2022
1 parent 971f1af commit 49247bb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ Ref: https://keepachangelog.com/en/1.0.0/

- [918](https://github.com/umee-network/umee/pull/918) Add MarketSummary query to CLI

### Improvements

- [1012](https://github.com/umee-network/umee/pull/1012) Improve negative time elapsed error message

## [v2.0.2](https://github.com/umee-network/umee/releases/tag/v2.0.2) - 2022-05-13

### Features
Expand Down
8 changes: 3 additions & 5 deletions x/leverage/keeper/interest.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"
sdkerrors "github.com/cosmos/cosmos-sdk/types/errors"
gogotypes "github.com/gogo/protobuf/types"

"github.com/umee-network/umee/v2/x/leverage/types"
Expand Down Expand Up @@ -72,11 +71,10 @@ func (k Keeper) AccrueAllInterest(ctx sdk.Context) error {
}

// calculate time elapsed since last interest accrual (measured in years for APR math)
secondsElapsed := currentTime - prevInterestTime
if secondsElapsed < 0 {
return sdkerrors.Wrap(types.ErrNegativeTimeElapsed, fmt.Sprintf("%d seconds", secondsElapsed))
if currentTime < prevInterestTime {
return types.ErrNegativeTimeElapsed.Wrap(fmt.Sprintf("current: %d, prev: %d", currentTime, prevInterestTime))
}
yearsElapsed := sdk.NewDec(secondsElapsed).QuoInt64(types.SecondsPerYear)
yearsElapsed := sdk.NewDec(currentTime - prevInterestTime).QuoInt64(types.SecondsPerYear)

// fetch required parameters
tokens := k.GetAllRegisteredTokens(ctx)
Expand Down

0 comments on commit 49247bb

Please sign in to comment.