Skip to content

Commit

Permalink
fix: Interpret x/0 collateral liquidity as 100% (#1357)
Browse files Browse the repository at this point in the history
* fix 0/0 collateral liquidity

* cl++

* comment++

* comment++

* comment++

Co-authored-by: Keith Hörling <keith@hoerling.com>
  • Loading branch information
toteki and khoerling authored Sep 8, 2022
1 parent a9750e8 commit 9675193
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [1018](https://github.com/umee-network/umee/pull/1018) Return nil if negative time elapsed from the last block happens.
- [1156](https://github.com/umee-network/umee/pull/1156) Propagate context correctly.
- [1288](https://github.com/umee-network/umee/pull/1288) Safeguards LastInterestTime against time reversals and unintended interest from hard forks.
- [1357](https://github.com/umee-network/umee/pull/1357) Interptex x/0 collateral liquidity as 100%

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

Expand Down
7 changes: 5 additions & 2 deletions x/leverage/keeper/collateral.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,12 @@ func (k Keeper) CollateralLiquidity(ctx sdk.Context, denom string) sdk.Dec {
exchangeRate := k.DeriveExchangeRate(ctx, denom)
liquidity := k.AvailableLiquidity(ctx, denom)

// Zero collateral will be interpreted as having no liquidity
// Zero collateral will be interpreted as full collateral liquidity. This encompasses two cases:
// - liquidity / collateral = 0/0: Empty market, system is considered healthy by default
// - liquidity / collateral = x/0: No collateral but nonzero liquidity, also considered healthy
// In both cases, "all collateral is liquid" is technically true, given that there is no collateral.
if totalCollateral.IsZero() {
return sdk.ZeroDec()
return sdk.OneDec()
}

collateralLiquidity := toDec(liquidity).Quo(exchangeRate.MulInt(totalCollateral.Amount))
Expand Down

0 comments on commit 9675193

Please sign in to comment.