Skip to content

Commit

Permalink
feat: add symbol name to the x/uibc QueryInflowsResponse (#2377)
Browse files Browse the repository at this point in the history
* feat: add symbol name to the x/uibc QueryInflowsResponse

* add missing file

* changelog
  • Loading branch information
robert-zaremba authored Jan 3, 2024
1 parent 007207a commit cbf1d36
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 86 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Ref: https://keepachangelog.com/en/1.0.0/
- [2363](https://github.com/umee-network/umee/pull/2363) Upgrade Cosmos SDK to v0.47.7.
- [2370](https://github.com/umee-network/umee/pull/2370) Add missing params to `uibc/MsgGovUpdateQuota`.
- [2374](https://github.com/umee-network/umee/pull/2374) Add symbol name to the x/uibc QueryAllOutflowsResponse `outflows` entry.
- [2377](https://github.com/umee-network/umee/pull/2377) Add symbol name to the x/uibc QueryInflowsResponse `inflows` entry.

### Features

Expand Down
6 changes: 1 addition & 5 deletions proto/umee/uibc/v1/query.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
syntax = "proto3";
package umee.uibc.v1;

import "cosmos/base/v1beta1/coin.proto";
import "cosmos_proto/cosmos.proto";
import "gogoproto/gogo.proto";
import "google/api/annotations.proto";
Expand Down Expand Up @@ -68,10 +67,7 @@ message QueryInflowsResponse {
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.Dec",
(gogoproto.nullable) = false
];
repeated cosmos.base.v1beta1.DecCoin inflows = 2 [
(gogoproto.customtype) = "github.com/cosmos/cosmos-sdk/types.DecCoin",
(gogoproto.nullable) = false
];
repeated DecCoinSymbol inflows = 2 [(gogoproto.nullable) = false];
}

// QueryParams defines the request structure for the Params gRPC service
Expand Down
24 changes: 11 additions & 13 deletions swagger/swagger.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3180,15 +3180,12 @@ paths:
type: string
amount:
type: string
symbol:
type: string
title: token symbol name
description: >-
DecCoin defines a token with a denomination and a decimal
amount.
NOTE: The amount field is an Dec which implements the custom
method
signatures required by gogoproto.
DecCoinSymbol extends the Cosmos SDK DecCoin type and adds
symbol name.
title: QueryInflowsResponse defines response type of Query/Inflows
default:
description: An unexpected error response.
Expand Down Expand Up @@ -9249,11 +9246,12 @@ definitions:
type: string
amount:
type: string
description: |-
DecCoin defines a token with a denomination and a decimal amount.
NOTE: The amount field is an Dec which implements the custom method
signatures required by gogoproto.
symbol:
type: string
title: token symbol name
description: >-
DecCoinSymbol extends the Cosmos SDK DecCoin type and adds symbol
name.
title: QueryInflowsResponse defines response type of Query/Inflows
umee.uibc.v1.QueryOutflowsResponse:
type: object
Expand Down
104 changes: 50 additions & 54 deletions x/uibc/query.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 7 additions & 14 deletions x/uibc/quota/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,28 @@ func (q Querier) AllOutflows(goCtx context.Context, _ *uibc.QueryAllOutflows) (
if err != nil {
return nil, err
}
tokenSymbols := map[string]string{}
for _, t := range k.leverage.GetAllRegisteredTokens(ctx) {
tokenSymbols[t.BaseDenom] = t.SymbolDenom
}
outflows := make([]uibc.DecCoinSymbol, len(o))
for i := range o {
outflows[i].Denom = o[i].Denom
outflows[i].Amount = o[i].Amount
outflows[i].Symbol = tokenSymbols[o[i].Denom]
}
outflows := k.coinsWithTokenSymbols(ctx, o)
return &uibc.QueryAllOutflowsResponse{Outflows: outflows}, nil
}

// Inflows returns sum of inflows and registered IBC denoms inflows in the current quota period.
func (q Querier) Inflows(goCtx context.Context, req *uibc.QueryInflows) (*uibc.QueryInflowsResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
var (
inflows sdk.DecCoins
err error
inflowCoins sdk.DecCoins
err error
k = q.Keeper(&ctx)
)

if len(req.Denom) != 0 {
inflows = append(inflows, q.Keeper(&ctx).GetTokenInflow(req.Denom))
inflowCoins = sdk.NewDecCoins(k.GetTokenInflow(req.Denom))
} else {
inflows, err = q.Keeper(&ctx).GetAllInflows()
inflowCoins, err = k.GetAllInflows()
if err != nil {
return nil, err
}
}
inflows := k.coinsWithTokenSymbols(ctx, inflowCoins)
return &uibc.QueryInflowsResponse{Sum: q.Keeper(&ctx).GetInflowSum(), Inflows: inflows}, nil
}

Expand Down
21 changes: 21 additions & 0 deletions x/uibc/quota/token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package quota

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/umee-network/umee/v6/x/uibc"
)

// returns mapping of token denom (according to x/bank) to token symbol name.
func (k Keeper) coinsWithTokenSymbols(ctx sdk.Context, coins sdk.DecCoins) []uibc.DecCoinSymbol {
tokenSymbols := map[string]string{}
for _, t := range k.leverage.GetAllRegisteredTokens(ctx) {
tokenSymbols[t.BaseDenom] = t.SymbolDenom
}
cs := make([]uibc.DecCoinSymbol, len(coins))
for i := range coins {
cs[i].Denom = coins[i].Denom
cs[i].Amount = coins[i].Amount
cs[i].Symbol = tokenSymbols[coins[i].Denom]
}
return cs
}

0 comments on commit cbf1d36

Please sign in to comment.