Skip to content

Commit

Permalink
introduce query rpc to get the fee config by channel and denom name (#…
Browse files Browse the repository at this point in the history
…522)

1. add config to channel
`picad tx ibctransferparamsmodule add-allowed-ibc-token --from mykey
--fees=30ppica channel-1 10 99999999999ppica`
2. add denom to channel 
`picad tx ibctransferparamsmodule add-allowed-ibc-token --from mykey
--fees=30ppica channel-1 10 99999999999ssss 10low 100medium 10000high`
3. query config by denom and channel
`picad query ibctransferparamsmodule FeeConfigByChannelAndDenom
channel-1 ppica`
4. response: 
```
min_fee:
  amount: "99999999999"
  denom: ppica
percentage: "10"
tx_priority_fee:
- priority: low
  priority_fee:
    amount: "10"
    denom: ppica
- priority: med
  priority_fee:
    amount: "100"
    denom: ppica
- priority: high
  priority_fee:
    amount: "10000"
    denom: ppica
```
5. response if denom does not allowed for this channel or channel does
not exists.
`fee configuration not found for channel channel-1 and denom sss:
invalid request`
  • Loading branch information
RustNinja authored Jun 21, 2024
1 parent 6805a95 commit 51c6ee1
Show file tree
Hide file tree
Showing 5 changed files with 612 additions and 19 deletions.
14 changes: 14 additions & 0 deletions proto/composable/ibctransfermiddleware/v1beta1/query.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ service Query {
rpc Params(QueryParamsRequest) returns (QueryParamsResponse) {
option (google.api.http).get = "/composable/ibctransfermiddleware/params";
}

rpc FeeConfigByChannelAndDenom(QueryFeeConfigByChannelAndDenomRequest) returns (QueryFeeConfigByChannelAndDenomResponse) {
option (google.api.http).get = "/composable/ibctransfermiddleware/feeconfigbychannelanddenom";
}
}

// QueryParamsRequest is the request type for the Query/Params RPC method.
Expand All @@ -23,3 +27,13 @@ message QueryParamsResponse {
// params defines the parameters of the module.
Params params = 1 [ (gogoproto.nullable) = false ];
}

message QueryFeeConfigByChannelAndDenomRequest {
string channel = 1;
string denom = 2;
}

message QueryFeeConfigByChannelAndDenomResponse {
// params defines the parameters of the module.
CoinItem fees = 1 [ (gogoproto.nullable) = false ];
}
35 changes: 35 additions & 0 deletions x/ibctransfermiddleware/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package cli

import (
"fmt"

"github.com/spf13/cobra"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/version"
"github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
)

Expand All @@ -20,6 +23,7 @@ func GetQueryCmd() *cobra.Command {

ibctransfermiddlewareParamsQueryCmd.AddCommand(
GetCmdQueryParams(),
GetFeeConfigByChannelAndDenom(),
)

return ibctransfermiddlewareParamsQueryCmd
Expand Down Expand Up @@ -53,3 +57,34 @@ func GetCmdQueryParams() *cobra.Command {

return cmd
}

func GetFeeConfigByChannelAndDenom() *cobra.Command {
cmd := &cobra.Command{
Use: "FeeConfigByChannelAndDenom",
Short: "Query bridge fee config by channel and denom",
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s query ibctransfermiddleware FeeConfigByChannelAndDenom [channel] [denom]", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

params := &types.QueryFeeConfigByChannelAndDenomRequest{
Channel: args[0],
Denom: args[1],
}
res, err := queryClient.FeeConfigByChannelAndDenom(cmd.Context(), params)
if err != nil {
return err
}

return clientCtx.PrintProto(&res.Fees)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}
18 changes: 18 additions & 0 deletions x/ibctransfermiddleware/keeper/grpc_query.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keeper

import (
"context"
"fmt"

sdk "github.com/cosmos/cosmos-sdk/types"

Expand All @@ -17,3 +18,20 @@ func (k Keeper) Params(c context.Context, _ *types.QueryParamsRequest) (*types.Q

return &types.QueryParamsResponse{Params: params}, nil
}

// ChannelFees returns channel fees of the staking middleware module.
func (k Keeper) FeeConfigByChannelAndDenom(c context.Context, req *types.QueryFeeConfigByChannelAndDenomRequest) (*types.QueryFeeConfigByChannelAndDenomResponse, error) {
ctx := sdk.UnwrapSDKContext(c)
feeConfig := k.GetCoin(ctx, req.Channel, req.Denom)
if feeConfig == nil {
return nil, fmt.Errorf("fee configuration not found for channel %s and denom %s", req.Channel, req.Denom)
} else {
ret_fee_config := types.CoinItem{
MinFee: feeConfig.MinFee,
Percentage: feeConfig.Percentage,
TxPriorityFee: feeConfig.TxPriorityFee,
}
return &types.QueryFeeConfigByChannelAndDenomResponse{Fees: ret_fee_config}, nil
}

}
Loading

0 comments on commit 51c6ee1

Please sign in to comment.