-
Notifications
You must be signed in to change notification settings - Fork 170
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(proto)!: aggregate queries on account address to account_balances and account_summary queries #1199
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of queries affected
Queries with addr
but no denom
are simply moved:
Supplied(addr)
->AccountBalances(addr).Supplied
Collateral(addr)
->AccountBalances(addr).Collateral * MarketSummary(denom).UTokenExchangeRate
Borrowed(addr)
->AccountBalances(addr).Borrowed
Note that collateral is a uToken amount, so it needs an exchange rate multiplier to be interpreted properly (we were doing this already, right?)
Queries with both addr
and denom
can be extracted from the combined coins:
Supplied(addr, denom)
->AccountBalances(addr).Supplied.AmountOf(denom)
Collateral(addr, denom)
->AccountBalances(addr).Collateral.AmountOf(denom) * MarketSummary(denom).UTokenExchangeRate
Borrowed(addr, denom)
->AccountBalances(addr).Borrowed.AmountOf(denom)
Queries for USD value with addr
but no denom
are simply moved:
SuppliedValue(addr)
->AccountSummary(addr).SuppliedValue
CollateralValue(addr)
->AccountSummary(addr).CollateralValue
BorrowedValue(addr)
->AccountSummary(addr).BorrowedValue
BorrowLimit(addr)
->AccountSummary(addr).BorrowLimit
LiquidationThreshold(addr)
->AccountSummary(addr).LiquidationThreshold
Queries for USD values with both addr
and denom
should now be computed with help from market_summary
:
SuppliedValue(addr, denom)
->AccountBalances(addr).Supplied.AmountOf(denom) * MarketSummary(denom).OraclePrice
CollateralValue(addr, denom)
->AccountBalances(addr).Collateral.AmountOf(denom) * MarketSummary(denom).OraclePrice * MarketSummary(denom).UTokenExchangeRate
BorrowedValue(addr,denom)
->AccountBalances(addr).Borrowed.AmountOf(denom) * MarketSummary(denom).OraclePrice
Final State of the Proto
The remaining queries (which I have moved into a consistent order in the files affected) are:
Params()
RegisteredTokens()
MarketSummary(denom)
AccountBalances(addr)
AccountSummary(addr)
LiquidationTargets()
Codecov Report
@@ Coverage Diff @@
## main #1199 +/- ##
==========================================
+ Coverage 47.95% 51.10% +3.15%
==========================================
Files 65 65
Lines 7551 6647 -904
==========================================
- Hits 3621 3397 -224
+ Misses 3684 2983 -701
- Partials 246 267 +21
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's think a bit more about the API
proto/umee/leverage/v1/query.proto
Outdated
|
||
// QueryAccountHealthResponse defines the response structure for the AccountHealth gRPC service handler. | ||
message QueryAccountHealthResponse { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With Health
I would expect some kind of metric, maybe 0-100%. Here we are returning aggregated balances.
Let's change Health in the query, request and response names to something else. Maybe:
- we can rename
QueryAccountSummary
toQueryAccountBalances
and use the former name here (renamingQueryAccountHealth
toQueryAccountSummary
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good idea - that solves the naming ambiguity
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Description
Similarly to #1188, this PR combines individual queries into aggregate ones to reduce API surface.
Since some of the fields depend heavily on oracle prices and some do not, they were separate into token-only (
account_balances
) and price-sensitive (account_summary
) queries. The latter will error when oracle is down.This aggregation also clears the way for future performance optimizations - in particular the
account_summary
fields fetch the same token prices, values, and parameters multiple times during computation. This was unavoidable when they were separate queries, but can be improved soon.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...
!
to the type prefix if API or client breaking changeCHANGELOG.md
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...