-
Notifications
You must be signed in to change notification settings - Fork 170
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: allow safe leverage operations during partial oracle outages (#…
…1821) ## Description This one does a lot of things: - Allows `account_summary` to work during price outages, treating all unknown prices as zero. - In such cases, supplied value and other fields will appear lower than it really is, since some assets were skipped - Liquidation threshold will be null when it can't be computed, since there's no safe way to do that with missing prices - `borrow_limit` in queries as well as messages is computed using only collateral with known prices - If the portion of your collateral with known prices is enough to cover a borrow, then it still works. - Same for withdraw and decollateralize - `MaxWithdraw` and `MaxBorrow` (both queries and messages) now function with missing collateral prices, respecting the borrow limit policy above. The queries return zero on missing borrow prices, or a missing price for the specific token being asked for. - `liquidation_targets` query skips addresses where liquidation threshold cannot be computed, instead of returning an error for the whole query - `MsgLiquidate` will be able to function with some missing prices on the target's borrowed assets, if their other borrows are high enough to still put them above their liquidation threshold API Breaking: - `liquidation_threshold` field in `account_summary` field can now be null --- ### Author Checklist _All items are required. Please add a note to the item if the item is not applicable and please add links to any relevant follow up issues._ I have... - [x] included the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [x] added `!` to the type prefix if API or client breaking change - [x] added appropriate labels to the PR - [x] targeted the correct branch (see [PR Targeting](https://github.com/umee-network/umee/blob/main/CONTRIBUTING.md#pr-targeting)) - [ ] provided a link to the relevant issue or specification - [x] added a changelog entry to `CHANGELOG.md` - [x] included comments for [documenting Go code](https://blog.golang.org/godoc) - [ ] updated the relevant documentation or specification - [x] reviewed "Files changed" and left comments if necessary - [ ] confirmed all CI checks have passed ### Reviewers Checklist _All items are required. Please add a note if the item is not applicable and please add your handle next to the items reviewed if you only reviewed selected items._ I have... - [ ] confirmed the correct [type prefix](https://github.com/commitizen/conventional-commit-types/blob/v3.0.0/index.json) in the PR title - [ ] confirmed all author checklist items have been addressed - [ ] reviewed state machine logic - [ ] reviewed API design and naming - [ ] reviewed documentation is accurate - [ ] reviewed tests and test coverage - [ ] manually tested (if applicable) (cherry picked from commit 87b9ed4) # Conflicts: # proto/umee/leverage/v1/query.proto # swagger/swagger.yaml # x/leverage/types/query.pb.go
- Loading branch information
1 parent
0682da0
commit 5372fa4
Showing
19 changed files
with
866 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package keeper | ||
|
||
import ( | ||
"strings" | ||
|
||
"cosmossdk.io/errors" | ||
|
||
"github.com/umee-network/umee/v4/util/decmath" | ||
leveragetypes "github.com/umee-network/umee/v4/x/leverage/types" | ||
oracletypes "github.com/umee-network/umee/v4/x/oracle/types" | ||
) | ||
|
||
// nonOracleError returns true if an error is non-nil | ||
// and also not one of ErrEmptyList, ErrUnknownDenom, or ErrNoHistoricMedians | ||
// which are errors which can result from missing prices | ||
func nonOracleError(err error) bool { | ||
if err == nil { | ||
return false | ||
} | ||
// check typed errors | ||
if errors.IsOf(err, | ||
leveragetypes.ErrInvalidOraclePrice, | ||
leveragetypes.ErrNoHistoricMedians, | ||
oracletypes.ErrUnknownDenom, | ||
) { | ||
return false | ||
} | ||
// this error needs to be checked by string comparison | ||
if strings.Contains(err.Error(), decmath.ErrEmptyList.Error()) { | ||
return false | ||
} | ||
return true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package keeper | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"cosmossdk.io/errors" | ||
|
||
"github.com/umee-network/umee/v4/util/decmath" | ||
leveragetypes "github.com/umee-network/umee/v4/x/leverage/types" | ||
oracletypes "github.com/umee-network/umee/v4/x/oracle/types" | ||
) | ||
|
||
func TestErrorMatching(t *testing.T) { | ||
// oracle errors | ||
err1 := errors.Wrap(decmath.ErrEmptyList, "denom: UMEE") | ||
err2 := oracletypes.ErrUnknownDenom.Wrap("UMEE") | ||
err3 := leveragetypes.ErrNoHistoricMedians.Wrapf( | ||
"requested %d, got %d", | ||
16, | ||
12, | ||
) | ||
// not oracle errors | ||
err4 := leveragetypes.ErrBlacklisted | ||
err5 := leveragetypes.ErrUToken | ||
err6 := leveragetypes.ErrNotRegisteredToken | ||
err7 := errors.New("foo", 1, "bar") | ||
|
||
require.Equal(t, false, nonOracleError(nil)) | ||
require.Equal(t, false, nonOracleError(err1)) | ||
require.Equal(t, false, nonOracleError(err2)) | ||
require.Equal(t, false, nonOracleError(err3)) | ||
require.Equal(t, true, nonOracleError(err4)) | ||
require.Equal(t, true, nonOracleError(err5)) | ||
require.Equal(t, true, nonOracleError(err6)) | ||
require.Equal(t, true, nonOracleError(err7)) | ||
} |
Oops, something went wrong.