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

feat: add inspector queries #2085

Merged
merged 34 commits into from
Jun 21, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
59a640c
add inspector queries
toteki Jun 6, 2023
402c325
simplify query structure for web interaction
toteki Jun 6, 2023
ee53cde
Revert "simplify query structure for web interaction"
toteki Jun 6, 2023
5d76ffd
retry reverted commit
toteki Jun 6, 2023
cd6f68b
lint
toteki Jun 6, 2023
42e66b6
depguard
toteki Jun 6, 2023
d127dbd
fix web urls
toteki Jun 6, 2023
a819b60
++
toteki Jun 6, 2023
cb3b855
Merge branch 'main' into adam/inspector2
toteki Jun 6, 2023
21d8a2f
suggestion++
toteki Jun 7, 2023
e97f767
Merge branch 'main' into adam/inspector2
toteki Jun 7, 2023
edc9f45
Merge branch 'main' into adam/inspector2
toteki Jun 13, 2023
8b236b4
suggestion
toteki Jun 15, 2023
93cae07
comment++
toteki Jun 15, 2023
8044094
simplify risk and inspector queries into one
toteki Jun 15, 2023
4e126aa
tests for decimal neatify
toteki Jun 15, 2023
8a9a1a8
edge case test
toteki Jun 15, 2023
5937a4f
fix
toteki Jun 15, 2023
ecdea8a
fix uToken display
toteki Jun 15, 2023
570c8f9
fix exponent display in DecBalances
toteki Jun 15, 2023
7e86d26
changelog
toteki Jun 15, 2023
5c8f563
Merge branch 'main' into adam/inspector2
toteki Jun 16, 2023
a628c88
Merge branch 'main' into adam/inspector2
toteki Jun 19, 2023
5b2718d
Merge branch 'main' into adam/inspector2
toteki Jun 20, 2023
8689c8b
filter on first iterate
toteki Jun 20, 2023
e840178
simplify sort
toteki Jun 20, 2023
86b725a
Merge branch 'main' into adam/inspector2
toteki Jun 20, 2023
fe191a0
simplify cli query construction
toteki Jun 20, 2023
0075f02
proto update
toteki Jun 20, 2023
473cec2
better proto doc
toteki Jun 20, 2023
118dac7
struct suggestion++
toteki Jun 20, 2023
ebc9784
update mock keepers for unit test
toteki Jun 21, 2023
e32f0e9
Revert "update mock keepers for unit test"
toteki Jun 21, 2023
9935dbf
fix refactor and add unit test
toteki Jun 21, 2023
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
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ linters:
# - wsl
- asciicheck
- bodyclose
- depguard
# - depguard
toteki marked this conversation as resolved.
Show resolved Hide resolved
- dogsled
- errcheck
- exportloopref
Expand Down
152 changes: 152 additions & 0 deletions proto/umee/leverage/v1/inspector.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
syntax = "proto3";
package umee.leverage.v1;

import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

option go_package = "github.com/umee-network/umee/v5/x/leverage/types";

option (gogoproto.goproto_getters_all) = false;

// QueryInspect defines the request structure for the Inspect gRPC service handler.
message QueryInspect {
toteki marked this conversation as resolved.
Show resolved Hide resolved
// Mode is a string which selects the logic behind the inspector query.
toteki marked this conversation as resolved.
Show resolved Hide resolved
string mode = 1;
// Symbol optionally selects a symbol denom for query modes that allow one to be specified.
string symbol = 2;
// Sort is an optional string which controls how accounts are sorted.
string sort = 3;
toteki marked this conversation as resolved.
Show resolved Hide resolved
// Mode minimum is the mode value below which accounts will be filtered. For example,
// in collateral mode this is the minimum collateral value an account must have to
// be displayed.
string mode_min = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Sort minimum is the sorted value below which accounts will be filtered. For example,
// in risk mode this is the minimum LTV an account must have to be displayed.
string sort_min = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// QueryInspectNeat defines the request structure for the InspectNeat gRPC service handler.
message QueryInspectNeat {
// Mode is a string which selects the logic behind the inspector query.
string mode = 1;
// Symbol optionally selects a symbol denom for query modes that allow one to be specified.
string symbol = 2;
// Sort is an optional string which controls how accounts are sorted.
string sort = 3;
toteki marked this conversation as resolved.
Show resolved Hide resolved
// Mode minimum is the mode value below which accounts will be filtered. For example,
// in collateral mode this is the minimum collateral value an account must have to
// be displayed.
string mode_min = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Sort minimum is the sorted value below which accounts will be filtered. For example,
// in risk mode this is the minimum LTV an account must have to be displayed.
string sort_min = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// QueryRiskData defines the request structure for the RiskData gRPC service handler.
message QueryRiskData {}

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

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

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

// BorrowerSummary defines a borrower's address and account health.
message BorrowerSummary {
string address = 1;
// Supplied Value is the total USD value of all tokens the account has supplied, includng interest earned.
string supplied_value = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Collateral Value is the total USD value of the account's collateral.
string collateral_value = 3 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Borrowed Value is the total USD value of all tokens the account has borrowed, including interest owed.
string borrowed_value = 4 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Borrow Limit is the maximum Borrowed Value the account is allowed to reach through direct borrowing.
string borrow_limit = 5 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// Liquidation Threshold is the Borrowed Value at which the account becomes eligible for liquidation.
string liquidation_threshold = 6 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// SpecificCollateralValue is the amount of Collateral Value which is the result of a specified collateral denom.
string specific_collateral_value = 7 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
// SpecificBorrowValue is the amount of Borrowed Value which is the result of a specified borrowed denom.
string specific_borrow_value = 8 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
}

// BorrowerSummaryNeat defines a borrower's address and account health without requiring sdk.Dec formatting
message BorrowerSummaryNeat {
string Account = 1;
// Borrowed is account's borrowed value, either in total or just a specified denom.
double Borrowed = 2;
// X is borrowed value as a portion of borrow limit.
double X = 3;
// Y is borrowed value as a portion of liquidation threshold.
double Y = 4;
// Z is the borrowed value as a portion of collateral value.
double Z = 5;
toteki marked this conversation as resolved.
Show resolved Hide resolved
}

// AccountSymbolBalances contains an account's position denoted in symbol denom tokens.
message AccountSymbolBalances {
toteki marked this conversation as resolved.
Show resolved Hide resolved
string Account = 1;
// Supplied contains all tokens the account has supplied, including interest earned.
repeated cosmos.base.v1beta1.DecCoin supplied = 2 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];
// Collateral contains all uTokens the account has collateralized. It has been converted from uTokens to tokens.
repeated cosmos.base.v1beta1.DecCoin collateral = 3 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];
// Borrowed contains all tokens the account has borrowed, including interest owed.
repeated cosmos.base.v1beta1.DecCoin borrowed = 4 [
(gogoproto.nullable) = false,
(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.DecCoins"
];
}
22 changes: 22 additions & 0 deletions proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import "umee/leverage/v1/leverage.proto";
import "gogoproto/gogo.proto";
import "cosmos/base/v1beta1/coin.proto";

import "umee/leverage/v1/inspector.proto";

option go_package = "github.com/umee-network/umee/v5/x/leverage/types";

option (gogoproto.goproto_getters_all) = false;
Expand Down Expand Up @@ -65,6 +67,26 @@ service Query {
returns (QueryMaxBorrowResponse) {
option (google.api.http).get = "/umee/leverage/v1/max_borrow";
}

// Inspect is the customizable inspector query.
toteki marked this conversation as resolved.
Show resolved Hide resolved
rpc Inspect(QueryInspect)
returns (QueryInspectResponse) {
option (google.api.http).get = "/umee/leverage/v1/inspect";
}

// InspectNeat is the inspector query, with a different response structure
// optimized for human readability on the CLI.
rpc InspectNeat(QueryInspectNeat)
returns (QueryInspectNeatResponse) {
option (google.api.http).get = "/umee/leverage/v1/inspect_neat";
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved
}

// RiskData returns filtered and sorted account balances by symbol
// denom for all qualifying accounts.
rpc RiskData(QueryRiskData)
returns (QueryRiskDataResponse) {
option (google.api.http).get = "/umee/leverage/v1/risk_data";
}
}

// QueryParams defines the request structure for the Params gRPC service
Expand Down
Loading