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(proto)!: aggregate queries on account address to account_balances and account_summary queries #1199

Merged
merged 6 commits into from
Aug 4, 2022

Conversation

toteki
Copy link
Member

@toteki toteki commented Aug 1, 2022

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...

  • included the correct type prefix in the PR title
  • added ! to the type prefix if API or client breaking change
  • added appropriate labels to the PR
  • targeted the correct branch (see PR Targeting)
  • provided a link to the relevant issue or specification
  • added a changelog entry to CHANGELOG.md
  • included comments for documenting Go code
  • updated the relevant documentation or specification
  • 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 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)

@toteki toteki added this to the v3 - Calypso milestone Aug 1, 2022
Copy link
Member Author

@toteki toteki left a 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()

@toteki toteki marked this pull request as ready for review August 1, 2022 20:31
@toteki toteki requested review from a team as code owners August 1, 2022 20:31
@codecov-commenter
Copy link

Codecov Report

Merging #1199 (2aaf4f6) into main (57616f6) will increase coverage by 3.15%.
The diff coverage is 53.22%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
x/leverage/client/cli/query.go 0.00% <0.00%> (ø)
x/leverage/types/query.pb.gw.go 0.00% <0.00%> (ø)
x/leverage/keeper/collateral.go 70.58% <60.00%> (-4.42%) ⬇️
x/leverage/keeper/grpc_query.go 63.63% <97.14%> (+41.56%) ⬆️
x/leverage/client/tests/tests.go 100.00% <100.00%> (ø)
x/leverage/keeper/exchange_rate.go 72.72% <0.00%> (+10.90%) ⬆️
x/leverage/keeper/loaned.go 42.85% <0.00%> (+32.14%) ⬆️

Copy link
Member

@robert-zaremba robert-zaremba left a 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


// QueryAccountHealthResponse defines the response structure for the AccountHealth gRPC service handler.
message QueryAccountHealthResponse {
Copy link
Member

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:

  1. we can rename QueryAccountSummary to QueryAccountBalances and use the former name here (renaming QueryAccountHealth to QueryAccountSummary)?

Copy link
Member Author

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

proto/umee/leverage/v1/query.proto Show resolved Hide resolved
Copy link
Member

@robert-zaremba robert-zaremba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@toteki toteki changed the title feat(proto)!: aggregate queries on account address to account_summary and account_health queries feat(proto)!: aggregate queries on account address to account_balances and account_summary queries Aug 4, 2022
@toteki toteki merged commit 72d7137 into main Aug 4, 2022
@toteki toteki deleted the adam/accountsummary branch August 4, 2022 02:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants