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)!: Condense redundant queries into market_summary #1188

Merged
merged 9 commits into from
Aug 1, 2022

Conversation

toteki
Copy link
Member

@toteki toteki commented Aug 1, 2022

Description

closes: #1164


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)

@codecov-commenter
Copy link

codecov-commenter commented Aug 1, 2022

Codecov Report

❗ No coverage uploaded for pull request base (main@bcd9aaa). Click here to learn what that means.
The diff coverage is 75.30%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #1188   +/-   ##
=======================================
  Coverage        ?   47.95%           
=======================================
  Files           ?       65           
  Lines           ?     7551           
  Branches        ?        0           
=======================================
  Hits            ?     3621           
  Misses          ?     3684           
  Partials        ?      246           
Impacted Files Coverage Δ
x/leverage/client/cli/query.go 0.00% <ø> (ø)
x/leverage/types/query.pb.gw.go 0.00% <0.00%> (ø)
x/leverage/keeper/grpc_query.go 22.07% <96.77%> (ø)
x/leverage/client/tests/tests.go 100.00% <100.00%> (ø)

- **Total Supplied** queries the [Total Supplied](01_concepts.md#Total-Supplied) of a specified denomination.
- **Total Supplied Value** queries the equivalent USD value of [Total Supplied](01_concepts.md#Total-Supplied) of a specified denomination.
- **Market Summary** combines several asset-specifying queries for more efficient frontend access.
- **Market Summary** collects data on a given `Token` denomination. A description of each response field can be found in the [QueryMarketSummaryResponse proto definition](../../../proto/umee/leverage/v1/query.proto)
Copy link
Member Author

Choose a reason for hiding this comment

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

Since the line numbers in the destination file are unstable whether I use the proto or the pb.go, the best I can do right now is link to the smaller one and put the relevant type name in the displayed text for the link.

@toteki toteki marked this pull request as ready for review August 1, 2022 03:49
@toteki toteki requested review from a team as code owners August 1, 2022 03:49
@toteki
Copy link
Member Author

toteki commented Aug 1, 2022

Heads up analytics (@khoerling) frontend (@EbrahimUmee) - query changes here, most importantly eliminating solo queries for anything that is a field in market summary.

For frontend, note that just like available_borrow, there are also available_withdraw and available_collateralize fields that could place upper limits on whale-sized transactions (or any transactions if market conditions were extreme).

In addition, a lot of the new market summary fields could make good graphs if we're really getting into market details (e.g. graphing liquidity vs collateral * uToken exchange rate and minimum_liqudity.

Note: This only takes effect when v3 binaries are released, assuming this gets merged.

Copy link
Contributor

@RafilxTenfen RafilxTenfen left a comment

Choose a reason for hiding this comment

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

Right now, if this was merged, the user cannot retrieve what we have in the TODO's
neither with the specific queries

Maybe we could let the specific ones, until we finish the TODO's or even let both

@@ -224,33 +216,6 @@ func GetCmdQuerySuppliedValue() *cobra.Command {
return cmd
}

// GetCmdQueryReserveAmount creates a Cobra command to query for the
// reserved amount of a specific token.
func GetCmdQueryReserveAmount() *cobra.Command {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of condensing queries, but why remove the specific ones?
Sometimes the user can need only part of that full information '-'

Copy link
Member Author

@toteki toteki Aug 1, 2022

Choose a reason for hiding this comment

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

but why remove the specific ones?

The idea is to reduce the API surface so there's less to maintain - that said, it's possible that this measure is a bit aggressive. We could keep the specific ones as well as the improved market summary.

edit: Also eliminates the possibility of the queries and the market summary ever being out of sync, and ensures that downstream every use case started with the same data.

The cons are of course doing extra computation when only one thing is needed (might be a gas problem in wasm?) and having to get the specific thing out of a struct field.

Copy link
Contributor

Choose a reason for hiding this comment

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

It could increase the gas consumption if someone doesn't need all those fields, but I don't know if that is a big problem

Copy link
Contributor

Choose a reason for hiding this comment

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

The part of less to maintain is definitely significant on all sides...

Comment on lines +400 to +420
availableBorrow := q.Keeper.GetAvailableToBorrow(ctx, req.Denom) // TODO #1162 #1163 - update implementation

resp := types.QueryMarketSummaryResponse{
SymbolDenom: token.SymbolDenom,
Exponent: token.Exponent,
UTokenExchangeRate: rate,
Supply_APY: supplyAPY,
Borrow_APY: borrowAPY,
Supplied: supplied.Amount,
Reserved: reserved,
Collateral: uCollateral,
Borrowed: borrowed.Amount,
Liquidity: balance.Sub(reserved),
MaximumBorrow: supplied.Amount, // TODO #1162 #1163 - implement limits
MaximumCollateral: uSupply.Amount, // TODO #1163 - implement limits
MinimumLiquidity: sdk.ZeroInt(), // TODO #1163 - implement limits
UTokenSupply: uSupply.Amount,
AvailableBorrow: availableBorrow,
AvailableWithdraw: uSupply.Amount, // TODO #1163 - implement limits
AvailableCollateralize: uSupply.Amount.Sub(uCollateral), // TODO #1163 - implement limits
}
Copy link
Member Author

Choose a reason for hiding this comment

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

Note that the current fields in market summary are all working - only the new ones having to do with safety limits have TODOs.

I would prefer to do them in a separate PR, since they'll require some math and module behavior changes. This PR would meanwhile merge everything proto-breaking, reducing the impact of the implementation PR.

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.

leverage: split available_borrow query into available_borrow, available_withdraw, and available_supply
3 participants