Skip to content

Commit

Permalink
feat: account summary to display both spot and leverage prices (#2263)
Browse files Browse the repository at this point in the history
* add inspectAccount query

* --

* --

* unstable field note

* new query fields and logic

* fix tests

* suggestion++

Co-authored-by: Robert Zaremba <robert@zaremba.ch>

* fix suggestion

* cl++

---------

Co-authored-by: Robert Zaremba <robert@zaremba.ch>
  • Loading branch information
toteki and robert-zaremba authored Sep 27, 2023
1 parent 498bd30 commit 8fe5d42
Show file tree
Hide file tree
Showing 10 changed files with 1,210 additions and 148 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/
### Improvements

- [2261](https://github.com/umee-network/umee/pull/2261) Use go 1.21
- [2263](https://github.com/umee-network/umee/pull/2263) Add spot price fields to account summary, and ensure all other fields use leverage logic prices.

### Bug Fixes

Expand Down
40 changes: 39 additions & 1 deletion proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ service Query {
returns (QueryInspectResponse) {
option (google.api.http).get = "/umee/leverage/v1/inspect";
}

// InspectAccount runs the inspect query on a single address
rpc InspectAccount(QueryInspectAccount)
returns (QueryInspectAccountResponse) {
option (google.api.http).get = "/umee/leverage/v1/inspect-account";
}
}

// QueryParams defines the request structure for the Params gRPC service
Expand Down Expand Up @@ -254,21 +260,23 @@ message QueryAccountSummary {
// QueryAccountSummaryResponse defines the response structure for the AccountSummary gRPC service handler.
message QueryAccountSummaryResponse {
// Supplied Value is the sum of the USD value of all tokens the account has supplied, including interest earned.
// It uses the lower of spot or historic price for each token.
// Computation skips assets which are missing oracle prices, potentially resulting in a lower supplied
// value than if prices were all available.
string supplied_value = 1 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Collateral Value is the sum of the USD value of all uTokens the account has collateralized.
// It uses the lower of spot or historic price for each token.
// Computation skips collateral which is missing an oracle price, potentially resulting in a lower collateral
// value than if prices were all available.
string collateral_value = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Borrowed Value is the sum of the USD value of all tokens the account has borrowed, including interest owed.
// It always uses spot prices.
// It uses the higher of spot or historic price for each token.
// Computation skips borrows which are missing oracle prices, potentially resulting in a lower borrowed
// value than if prices were all available.
string borrowed_value = 3 [
Expand All @@ -289,6 +297,21 @@ message QueryAccountSummaryResponse {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = true
];
// Spot Supplied Value is supplied value but always uses spot prices.
string spot_supplied_value = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Spot Collateral Value is collateral value but always uses spot prices.
string spot_collateral_value = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Spot Borrowed Value is borrowed value but always uses spot prices.
string spot_borrowed_value = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// QueryLiquidationTargets defines the request structure for the LiquidationTargets gRPC service handler.
Expand Down Expand Up @@ -366,13 +389,25 @@ message QueryInspect {
double ltv = 5;
}

// QueryInspectAccount defines the request structure for the InspectAccount gRPC service handler.
message QueryInspectAccount {
string address = 1;
}

// QueryInspectResponse defines the response structure for the Inspect gRPC service handler.
message QueryInspectResponse {
repeated InspectAccount borrowers = 1 [
(gogoproto.nullable) = false
];
}

// QueryInspectAccountResponse defines the response structure for the InspectAccount gRPC service handler.
message QueryInspectAccountResponse {
InspectAccount borrower = 1 [
(gogoproto.nullable) = false
];
}

// InspectAccount contains risk and balance info for a single account for the inspector query.
message InspectAccount {
// Address of a borrower
Expand All @@ -381,6 +416,9 @@ message InspectAccount {
RiskInfo analysis = 2;
// Collateral and borrowed tokens, denoted in human-readable symbol denom instead of ibc denom.
DecBalances position = 3;
// Info is a string which can be used to report additional information of any type.
// UNSTABLE: We do not guarantee consistency of any data structures contained within the string.
string info = 4;
}

// RiskInfo defines a borrower's account health without requiring sdk.Dec formatting.
Expand Down
Loading

0 comments on commit 8fe5d42

Please sign in to comment.