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: query RegisteredTokenMarkets #2369

Merged
merged 9 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
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
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ Ref: https://keepachangelog.com/en/1.0.0/

## Unreleased

### Features

- [2369](https://github.com/umee-network/umee/pull/2369) Add query RegisteredTokenMarkets to fetch Registered Tokens and their Market Summaries for frontend in fewer queries.

## v6.2.0 - 2023-12-01

### Bug Fixes

- [2315](https://github.com/umee-network/umee/pull/2215) Improve reliability of MaxBorrow, MaxWithdraw when special asset pairs present.
- [2315](https://github.com/umee-network/umee/pull/2315) Improve reliability of MaxBorrow, MaxWithdraw when special asset pairs present.
- [2346](https://github.com/umee-network/umee/pull/2346) Fix an issue where metokens were not included in historic data.

### Improvements
Expand Down
24 changes: 24 additions & 0 deletions proto/umee/leverage/v1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ service Query {
option (google.api.http).get = "/umee/leverage/v1/registered_tokens";
}

// RegisteredTokenMarkets queries for all the registered tokens and their market summaries.
rpc RegisteredTokenMarkets(QueryRegisteredTokenMarkets)
returns (QueryRegisteredTokenMarketsResponse) {
option (google.api.http).get = "/umee/leverage/v1/registered_token_markets";
toteki marked this conversation as resolved.
Show resolved Hide resolved
}

// SpecialAssets queries for all special asset pairs.
rpc SpecialAssets(QuerySpecialAssets)
returns (QuerySpecialAssetsResponse) {
Expand Down Expand Up @@ -112,6 +118,24 @@ message QueryRegisteredTokensResponse {
repeated Token registry = 1 [(gogoproto.nullable) = false];
}

// QueryRegisteredTokenMarkets defines the request structure for the RegisteredTokenMarkets
// gRPC service handler.
message QueryRegisteredTokenMarkets {}

// QueryRegisteredTokenMarketsResponse defines the response structure for the
// RegisteredTokenMarkets gRPC service handler.
message QueryRegisteredTokenMarketsResponse {
repeated TokenMarket markets = 1 [(gogoproto.nullable) = false];
}

// TokenMarket is a token and its market summary.
message TokenMarket {
// Token is a registered token and its parameters.
Token token = 1 [(gogoproto.nullable) = false];
// Market is the market summary for the token.
QueryMarketSummaryResponse market = 2 [(gogoproto.nullable) = false];
}

// QuerySpecialAssets defines the request structure for the SpecialAssets
// gRPC service handler.
message QuerySpecialAssets {
Expand Down
29 changes: 29 additions & 0 deletions x/leverage/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,35 @@ func (q Querier) RegisteredTokens(
}, nil
}

func (q Querier) RegisteredTokenMarkets(
goCtx context.Context,
req *types.QueryRegisteredTokenMarkets,
) (*types.QueryRegisteredTokenMarketsResponse, error) {
if req == nil {
return nil, status.Error(codes.InvalidArgument, "empty request")
}

ctx := sdk.UnwrapSDKContext(goCtx)
tokens := q.Keeper.GetAllRegisteredTokens(ctx)
markets := []types.TokenMarket{}

for _, token := range tokens {
marketSumnmary, err := q.MarketSummary(goCtx, &types.QueryMarketSummary{Denom: token.BaseDenom})
if err != nil {
// absorb overall query error into struct, which may be empty, but proceed with this query
marketSumnmary.Errors += err.Error()
toteki marked this conversation as resolved.
Show resolved Hide resolved
}
markets = append(markets, types.TokenMarket{
Token: token,
Market: *marketSumnmary,
})
}

return &types.QueryRegisteredTokenMarketsResponse{
Markets: markets,
}, nil
}
robert-zaremba marked this conversation as resolved.
Show resolved Hide resolved

func (q Querier) SpecialAssets(
goCtx context.Context,
req *types.QuerySpecialAssets,
Expand Down
23 changes: 23 additions & 0 deletions x/leverage/keeper/grpc_query_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,29 @@ func (s *IntegrationTestSuite) TestQuerier_MarketSummary() {
require.Equal(expected, *resp)
}

func (s *IntegrationTestSuite) TestQuerier_TokenMarkets() {
require := s.Require()

req := &types.QueryRegisteredTokenMarkets{}
resp, err := s.queryClient.RegisteredTokenMarkets(context.Background(), req)
require.NoError(err)

expected := types.QueryRegisteredTokenMarketsResponse{
Markets: []types.TokenMarket{},
}
tokens := s.tk.GetAllRegisteredTokens(s.ctx)
for _, token := range tokens {
ms, err := s.queryClient.MarketSummary(context.Background(), &types.QueryMarketSummary{Denom: token.BaseDenom})
require.NoError(err)
expected.Markets = append(expected.Markets, types.TokenMarket{
Token: token,
Market: *ms,
})
}

require.Equal(expected, *resp)
}
toteki marked this conversation as resolved.
Show resolved Hide resolved

func (s *IntegrationTestSuite) TestQuerier_AccountBalances() {
ctx, require := s.ctx, s.Require()

Expand Down
Loading
Loading