Skip to content

Commit

Permalink
Merge pull request #508 from ComposableFi/rustninja/priority-fee-upgr…
Browse files Browse the repository at this point in the history
…ade-handler

Priority fee upgrade handler + tx to update priority config.
  • Loading branch information
RustNinja committed Apr 29, 2024
2 parents 58b184c + be273fa commit 0427e0a
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 65 deletions.
20 changes: 20 additions & 0 deletions app/upgrades/v6_5_5/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package v6_5_5

import (
store "github.com/cosmos/cosmos-sdk/store/types"
"github.com/notional-labs/composable/v6/app/upgrades"
)

const (
// UpgradeName defines the on-chain upgrade name for the composable upgrade.
UpgradeName = "v6_5_5"
)

var Upgrade = upgrades.Upgrade{
UpgradeName: UpgradeName,
CreateUpgradeHandler: CreateUpgradeHandler,
StoreUpgrades: store.StoreUpgrades{
Added: []string{},
Deleted: []string{},
},
}
24 changes: 24 additions & 0 deletions app/upgrades/v6_5_5/upgrade.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package v6_5_5

import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/module"
upgradetypes "github.com/cosmos/cosmos-sdk/x/upgrade/types"

"github.com/cosmos/cosmos-sdk/codec"
"github.com/notional-labs/composable/v6/app/keepers"

"github.com/notional-labs/composable/v6/app/upgrades"
)

func CreateUpgradeHandler(
mm *module.Manager,
configurator module.Configurator,
_ upgrades.BaseAppParamManager,
_ codec.Codec,
keepers *keepers.AppKeepers,
) upgradetypes.UpgradeHandler {
return func(ctx sdk.Context, plan upgradetypes.Plan, vm module.VersionMap) (module.VersionMap, error) {
return mm.RunMigrations(ctx, configurator, vm)
}
}
2 changes: 1 addition & 1 deletion custom/ibc-transfer/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func NewKeeper(
func (k Keeper) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
params := k.IbcTransfermiddleware.GetParams(ctx)
charge_coin := sdk.NewCoin("", sdk.ZeroInt())
charge_coin := sdk.NewCoin(msg.Token.Denom, sdk.ZeroInt())
if params.ChannelFees != nil && len(params.ChannelFees) > 0 {
channelFee := findChannelParams(params.ChannelFees, msg.SourceChannel)
if channelFee != nil {
Expand Down
2 changes: 1 addition & 1 deletion custom/ibc-transfer/keeper/msg_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func NewMsgServerImpl(ibcKeeper Keeper, bankKeeper custombankkeeper.Keeper) type
func (k msgServer) Transfer(goCtx context.Context, msg *types.MsgTransfer) (*types.MsgTransferResponse, error) {
ctx := sdk.UnwrapSDKContext(goCtx)
params := k.Keeper.IbcTransfermiddleware.GetParams(ctx)
charge_coin := sdk.NewCoin("", sdk.ZeroInt())
charge_coin := sdk.NewCoin(msg.Token.Denom, sdk.ZeroInt())
if params.ChannelFees != nil && len(params.ChannelFees) > 0 {
channelFee := findChannelParams(params.ChannelFees, msg.SourceChannel)
if channelFee != nil {
Expand Down
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
1 change: 1 addition & 0 deletions x/ibctransfermiddleware/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ func (k Keeper) GetSequenceFee(ctx sdk.Context, sequence uint64) (coin sdk.Coin,
fee := types.MustUnmarshalCoin(k.cdc, value)
return fee, true
}

func (k Keeper) SetSequenceFee(ctx sdk.Context, sequence uint64, coin sdk.Coin) {
store := ctx.KVStore(k.storeKey)
store.Set(types.GetSequenceKey(sequence), types.MustMarshalCoin(k.cdc, &coin))
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.

1 change: 0 additions & 1 deletion x/transfermiddleware/ibc_middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ func (im IBCMiddleware) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Pac
fee_address, err := sdk.AccAddressFromBech32(сhannelFeeAddress)
if err != nil {
return nil
// return errors.Wrapf(err, "failed to decode receiver address: %s", сhannelFeeAddress)
}

refund_err := im.keeper.RefundChannelCosmosFee(ctx, fee_address, sdk.AccAddress(data.Sender), []sdk.Coin{fee})
Expand Down

0 comments on commit 0427e0a

Please sign in to comment.