Skip to content

Commit

Permalink
fix: amount reserved per block rounds up (#1957)
Browse files Browse the repository at this point in the history
* fix: amount reserved per block rounds up

* #1957

* ciel().round()

* back to truncate
  • Loading branch information
toteki authored Mar 29, 2023
1 parent 4fd6105 commit 863b5f9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
### Fixes

- [1929](https://github.com/umee-network/umee/pull/1929) Leverage: `MaxWithdraw` now accounts for `MinCollateralLiquidity`
- [1957](https://github.com/umee-network/umee/pull/1957) Leverage: Reserved amount per block now rounds up.
- [1956](https://github.com/umee-network/umee/pull/1956) Leverage: token liquidation threshold must be bigger than collateral_weight.

## [v4.2.0](https://github.com/umee-network/umee/releases/tag/v4.2.0) - 2023-03-15
Expand Down
15 changes: 9 additions & 6 deletions x/leverage/keeper/interest.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func (k Keeper) AccrueAllInterest(ctx sdk.Context) error {

// calculate time elapsed since last interest accrual (measured in years for APR math)
if currentTime < prevInterestTime {
// TODO fix this when tendermint solves https://github.com/tendermint/tendermint/issues/8773
// precaution against this and similar issues: https://github.com/tendermint/tendermint/issues/8773
k.Logger(ctx).With("AccrueAllInterest will wait for block time > prevInterestTime").Error(
types.ErrNegativeTimeElapsed.Error(),
"current", currentTime,
Expand Down Expand Up @@ -133,11 +133,14 @@ func (k Keeper) AccrueAllInterest(ctx sdk.Context) error {
interestAccrued.TruncateInt(),
))

// calculate new reserves accrued for this denom
newReserves = newReserves.Add(sdk.NewCoin(
token.BaseDenom,
interestAccrued.Mul(token.ReserveFactor).TruncateInt(),
))
// if interest accrued on this denom is at least one base token
if interestAccrued.GT(sdk.OneDec()) {
// calculate new reserves gained for this denom, rounding up
newReserves = newReserves.Add(sdk.NewCoin(
token.BaseDenom,
interestAccrued.Mul(token.ReserveFactor).Ceil().TruncateInt(),
))
}

// calculate oracle rewards accrued for this denom
oracleRewards = oracleRewards.Add(sdk.NewCoin(
Expand Down

0 comments on commit 863b5f9

Please sign in to comment.