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

IBC fee config modification via tx from list of authority #470

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,15 @@
)

appKeepers.StakingMiddlewareKeeper = stakingmiddleware.NewKeeper(appCodec, appKeepers.keys[stakingmiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
appKeepers.IbcTransferMiddlewareKeeper = ibctransfermiddleware.NewKeeper(appCodec, appKeepers.keys[ibctransfermiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String())
appKeepers.IbcTransferMiddlewareKeeper = ibctransfermiddleware.NewKeeper(appCodec, appKeepers.keys[ibctransfermiddlewaretypes.StoreKey], authtypes.NewModuleAddress(govtypes.ModuleName).String(),
[]string{"centauri1ay9y5uns9khw2kzaqr3r33v2pkuptfnnr93j5j",

Check failure on line 199 in app/keepers/keepers.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed with `-extra` (gofumpt)
"centauri14lz7gaw92valqjearnye4shex7zg2p05mlx9q0",
"centauri1r2zlh2xn85v8ljmwymnfrnsmdzjl7k6w6lytan",
"centauri10556m38z4x6pqalr9rl5ytf3cff8q46nk85k9m",

"centauri1wkjvpgkuchq0r8425g4z4sf6n85zj5wtmqzjv9",
})
// "centauri1hj5fveer5cjtn4wd6wstzugjfdxzl0xpzxlwgs",

appKeepers.StakingKeeper = customstaking.NewKeeper(
appCodec, appKeepers.keys[stakingtypes.StoreKey], appKeepers.AccountKeeper, appKeepers.BankKeeper, authtypes.NewModuleAddress(govtypes.ModuleName).String(), &appKeepers.StakingMiddlewareKeeper,
Expand Down
97 changes: 97 additions & 0 deletions proto/composable/ibctransfermiddleware/v1beta1/tx.proto
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,16 @@ service Msg {
option (cosmos.msg.v1.service) = true;

rpc UpdateCustomIbcParams(MsgUpdateCustomIbcParams) returns (MsgUpdateParamsCustomIbcResponse);

rpc AddIBCFeeConfig(MsgAddIBCFeeConfig)
returns (MsgAddIBCFeeConfigResponse);
rpc RemoveIBCFeeConfig(MsgRemoveIBCFeeConfig)
returns (MsgRemoveIBCFeeConfigResponse);

rpc AddAllowedIbcToken(MsgAddAllowedIbcToken)
returns (MsgAddAllowedIbcTokenResponse);
rpc RemoveAllowedIbcToken(MsgRemoveAllowedIbcToken)
returns (MsgRemoveAllowedIbcTokenResponse);
}

// MsgUpdateParams is the Msg/UpdateParams request type.
Expand All @@ -39,3 +49,90 @@ message MsgUpdateCustomIbcParams {
//
// Since: cosmos-sdk 0.47
message MsgUpdateParamsCustomIbcResponse {}


// MsgAddParachainInfo represents a message to add new parachain info.
message MsgAddIBCFeeConfig {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (gogoproto.moretags) = "yaml:\"authority\"" ];

string channel_id = 2 [
(gogoproto.moretags) = "yaml:\"channel_id\"",
(gogoproto.customname) = "ChannelID"
];
string fee_address = 3 [ (gogoproto.moretags) = "yaml:\"rly_address\"" ];

int64 min_timeout_timestamp = 4;
}

message MsgAddIBCFeeConfigResponse {}

// MsgRemoveParachainIBCTokenInfo represents a message to remove new parachain
// info.
message MsgRemoveIBCFeeConfig {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (gogoproto.moretags) = "yaml:\"authority\"" ];
;

string channel_id = 2 [
(gogoproto.moretags) = "yaml:\"channel_id\"",
(gogoproto.customname) = "ChannelID"
];
}

message MsgRemoveIBCFeeConfigResponse {}



// MsgAddParachainInfo represents a message to add new parachain info.
message MsgAddAllowedIbcToken {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (gogoproto.moretags) = "yaml:\"authority\"" ];

string channel_id = 2 [
(gogoproto.moretags) = "yaml:\"channel_id\"",
(gogoproto.customname) = "ChannelID"
];

string denom = 3 [
(gogoproto.moretags) = "yaml:\"channel_id\"",
(gogoproto.customname) = "Denom"
];

int64 amount = 4;

int64 percentage = 5;
}

message MsgAddAllowedIbcTokenResponse {}


message MsgRemoveAllowedIbcToken {
option (cosmos.msg.v1.signer) = "authority";

// authority is the address that controls the module (defaults to x/gov unless
// overwritten).
string authority = 1 [ (gogoproto.moretags) = "yaml:\"authority\"" ];
;

string channel_id = 2 [
(gogoproto.moretags) = "yaml:\"channel_id\"",
(gogoproto.customname) = "ChannelID"
];

string denom = 3 [
(gogoproto.moretags) = "yaml:\"channel_id\"",
(gogoproto.customname) = "Denom"
];
}

message MsgRemoveAllowedIbcTokenResponse {}
169 changes: 168 additions & 1 deletion x/ibctransfermiddleware/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
package cli

import (
"fmt"
"strconv"

"github.com/cosmos/cosmos-sdk/client"
"github.com/cosmos/cosmos-sdk/client/flags"
"github.com/cosmos/cosmos-sdk/client/tx"
"github.com/cosmos/cosmos-sdk/version"
"github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types"
"github.com/spf13/cobra"
)
Expand All @@ -16,7 +22,168 @@ func GetTxCmd() *cobra.Command {
RunE: client.ValidateCmd,
}

txCmd.AddCommand()
txCmd.AddCommand(
AddIBCFeeConfig(),
RemoveIBCFeeConfig(),
AddAllowedIbcToken(),
RemoveAllowedIbcToken(),
)

return txCmd
}

func AddIBCFeeConfig() *cobra.Command {
cmd := &cobra.Command{
Use: "add-config [channel] [feeAddress] [minTimeoutTimestamp]",
Short: "add ibc fee config",
Args: cobra.MatchAll(cobra.ExactArgs(3), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s tx ibctransfermiddleware add-config [channel] [feeAddress] [minTimeoutTimestamp]", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
channel := args[0]
feeAddress := args[1]
minTimeoutTimestamp := args[2]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

fromAddress := clientCtx.GetFromAddress().String()

minTimeoutTimestampInt, err := strconv.ParseInt(minTimeoutTimestamp, 10, 64)
if err != nil {
return err
}

msg := types.NewMsgAddIBCFeeConfig(
fromAddress,
channel,
feeAddress,
minTimeoutTimestampInt,
)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)

return cmd
}

func AddAllowedIbcToken() *cobra.Command {
cmd := &cobra.Command{
Use: "add-allowed-ibc-token [channel] [denom] [amount] [percentage]",
Short: "add allowed ibc token",
Args: cobra.MatchAll(cobra.ExactArgs(4), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s tx ibctransfermiddleware add-allowed-ibc-token [channel] [denom] [amount] [percentage] (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]
denom := args[1]
amount := args[2]
percentage := args[3]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

fromAddress := clientCtx.GetFromAddress().String()

amountInt, err := strconv.ParseInt(amount, 10, 64)
if err != nil {
return err
}

percentageInt, errPercentage := strconv.ParseInt(percentage, 10, 64)
if errPercentage != nil {
return errPercentage
}

msg := types.NewMsgAddAllowedIbcToken(
fromAddress,
channel,
denom,
amountInt,
percentageInt,
)

if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)

return cmd
}

func RemoveIBCFeeConfig() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-config [channel]",
Short: "remove ibc fee config",
Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s tx ibctransfermiddleware remove-config [channel]", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
channel := args[0]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

fromAddress := clientCtx.GetFromAddress().String()

msg := types.NewMsgRemoveIBCFeeConfig(
fromAddress,
channel,
)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)

return cmd
}

func RemoveAllowedIbcToken() *cobra.Command {
cmd := &cobra.Command{
Use: "remove-allowed-ibc-token [channel] [denom]",
Short: "remove allowed ibc token",
Args: cobra.MatchAll(cobra.ExactArgs(2), cobra.OnlyValidArgs),
Example: fmt.Sprintf("%s tx ibctransfermiddleware remove-allowed-ibc-token [channel] [denom]", version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
channel := args[0]
denom := args[1]

clientCtx, err := client.GetClientTxContext(cmd)
if err != nil {
return err
}

fromAddress := clientCtx.GetFromAddress().String()

msg := types.NewMsgRemoveAllowedIbcToken(
fromAddress,
channel,
denom,
)
if err := msg.ValidateBasic(); err != nil {
return err
}

return tx.GenerateOrBroadcastTxCLI(clientCtx, cmd.Flags(), msg)
},
}
flags.AddTxFlagsToCmd(cmd)

return cmd
}
4 changes: 4 additions & 0 deletions x/ibctransfermiddleware/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ type Keeper struct {
// the address capable of executing a MsgUpdateParams message. Typically, this
// should be the x/gov module account.
authority string

addresses []string
}

// NewKeeper creates a new middleware Keeper instance
func NewKeeper(
cdc codec.BinaryCodec,
key storetypes.StoreKey,
authority string,
addresses []string,
) Keeper {
return Keeper{
cdc: cdc,
storeKey: key,
authority: authority,
addresses: addresses,
}
}

Expand Down
Loading
Loading