Skip to content

Commit

Permalink
Merge pull request #507 from ComposableFi/rustdev/extend-add-allowedI…
Browse files Browse the repository at this point in the history
…bc-token-tx

Extend AddAllowedIbcToken tx to add the priority of gas for ibc bridge
  • Loading branch information
RustNinja committed Apr 28, 2024
2 parents f805bfa + 8271fef commit 8961903
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 62 deletions.
2 changes: 2 additions & 0 deletions proto/composable/ibctransfermiddleware/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ message MsgAddAllowedIbcToken {
cosmos.base.v1beta1.Coin min_fee = 3 [(gogoproto.nullable) = false, (amino.dont_omitempty) = true];

int64 percentage = 4;

repeated TxPriorityFee tx_priority_fee = 5;
}

message MsgAddAllowedIbcTokenResponse {}
Expand Down
18 changes: 15 additions & 3 deletions x/ibctransfermiddleware/client/cli/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,28 @@ func AddIBCFeeConfig() *cobra.Command {

func AddAllowedIbcToken() *cobra.Command {
cmd := &cobra.Command{
Use: "add-allowed-ibc-token [channel] [percentage] [coin]",
Use: "add-allowed-ibc-token [channel] [percentage] [coin] [Amountlow] [Amountmedium] [Amounthigh] ... [Amountxxx]",
Short: "add allowed ibc token",
Args: cobra.MatchAll(cobra.ExactArgs(3), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s tx ibctransfermiddleware add-allowed-ibc-token [channel] [percentage] [coin] (percentage '5' means 1/5 of amount will be taken as fee) ", version.AppName),
Args: cobra.MatchAll(cobra.RangeArgs(3, 10), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s tx ibctransfermiddleware add-allowed-ibc-token [channel] [percentage] [coin] .. [1000low] [10000medium] [100000high] ... [1000000xxx] (percentage '5' means 1/5 of amount will be taken as fee) ", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
channel := args[0]
percentage := args[1]
coin, err := sdk.ParseCoinNormalized(args[2])
if err != nil {
return err
}
length := len(args)
cc := []*types.TxPriorityFee{}
for i := 3; i < length; i++ {
priority, err := sdk.ParseCoinNormalized(args[i])
if err != nil {
return err
}
priority_str := priority.Denom
priority.Denom = coin.Denom
cc = append(cc, &types.TxPriorityFee{Priority: priority_str, PriorityFee: priority})
}

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
Expand All @@ -106,6 +117,7 @@ func AddAllowedIbcToken() *cobra.Command {
channel,
coin,
percentageInt,
cc,
)

if err := msg.ValidateBasic(); err != nil {
Expand Down
7 changes: 4 additions & 3 deletions x/ibctransfermiddleware/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,11 +105,12 @@ func (ms msgServer) AddAllowedIbcToken(goCtx context.Context, req *types.MsgAddA
if coin != nil {
coin.MinFee = req.MinFee
coin.Percentage = req.Percentage
coin.TxPriorityFee = req.TxPriorityFee
} else {

coin := &types.CoinItem{
MinFee: req.MinFee,
Percentage: req.Percentage,
MinFee: req.MinFee,
Percentage: req.Percentage,
TxPriorityFee: req.TxPriorityFee,
}
channelFee.AllowedTokens = append(channelFee.AllowedTokens, coin)
}
Expand Down
10 changes: 6 additions & 4 deletions x/ibctransfermiddleware/types/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,14 @@ func NewMsgAddAllowedIbcToken(
channelID string,
minFee sdk.Coin,
percentage int64,
txPriorityFee []*TxPriorityFee,
) *MsgAddAllowedIbcToken {
return &MsgAddAllowedIbcToken{
Authority: authority,
ChannelID: channelID,
MinFee: minFee,
Percentage: percentage,
Authority: authority,
ChannelID: channelID,
MinFee: minFee,
Percentage: percentage,
TxPriorityFee: txPriorityFee,
}
}

Expand Down
169 changes: 117 additions & 52 deletions x/ibctransfermiddleware/types/tx.pb.go

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

0 comments on commit 8961903

Please sign in to comment.