Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Interpret x/0 collateral liquidity as 100% #1357

Merged
merged 8 commits into from
Sep 8, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
// - 0/0 liquidity / collateral: Empty market, system is considered healthy by default
// - x/0 liquidity / collateral: No collateral but plenty of liquidity, also considered healthy
toteki marked this conversation as resolved.
Show resolved Hide resolved
// 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