From 3b6cacbffffd01d95b33ff40295e4f6b10a1a0ff Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 22 May 2024 13:37:29 +0100 Subject: [PATCH 1/8] refactor and extract function responsible for finding fee for channel. --- custom/custompfm/keeper/keeper.go | 4 +- x/ibctransfermiddleware/keeper/keeper.go | 116 +++++++++++++++++++++++ 2 files changed, 118 insertions(+), 2 deletions(-) diff --git a/custom/custompfm/keeper/keeper.go b/custom/custompfm/keeper/keeper.go index b9b7476f..f00cf7a4 100644 --- a/custom/custompfm/keeper/keeper.go +++ b/custom/custompfm/keeper/keeper.go @@ -63,14 +63,14 @@ func (im IBCMiddleware) OnRecvPacket( ) ibcexported.Acknowledgement { logger := im.keeper1.Logger(ctx) - im.ibcfeekeeper.GetParams(ctx) - var data transfertypes.FungibleTokenPacketData if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil { logger.Debug(fmt.Sprintf("packetForwardMiddleware OnRecvPacket payload is not a FungibleTokenPacketData: %s", err.Error())) return im.IBCMiddleware.OnRecvPacket(ctx, packet, relayer) } + // params := im.ibcfeekeeper.GetParams(ctx) + logger.Debug("packetForwardMiddleware OnRecvPacket", "sequence", packet.Sequence, "src-channel", packet.SourceChannel, "src-port", packet.SourcePort, diff --git a/x/ibctransfermiddleware/keeper/keeper.go b/x/ibctransfermiddleware/keeper/keeper.go index 597cf30a..a0f92102 100644 --- a/x/ibctransfermiddleware/keeper/keeper.go +++ b/x/ibctransfermiddleware/keeper/keeper.go @@ -1,12 +1,18 @@ package keeper import ( + "context" + "encoding/json" + "fmt" + "time" + "github.com/cometbft/cometbft/libs/log" "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/types" "github.com/cosmos/cosmos-sdk/codec" storetypes "github.com/cosmos/cosmos-sdk/store/types" sdk "github.com/cosmos/cosmos-sdk/types" + ibctypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" ) // Keeper of the staking middleware store @@ -104,3 +110,113 @@ func (k Keeper) GetChannelFeeAddress(ctx sdk.Context, targetChannelID string) st } return channelFee.FeeAddress } + +type BridgeFee struct { + fee sdk.Coin + sender sdk.AccAddress + reciever sdk.AccAddress +} + +func (k Keeper) Transfer(goCtx context.Context, msg *ibctypes.MsgTransfer) (*BridgeFee, error) { + ctx := sdk.UnwrapSDKContext(goCtx) + params := k.GetParams(ctx) + // 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 { + if channelFee.MinTimeoutTimestamp > 0 { + + goCtx := sdk.UnwrapSDKContext(goCtx) + blockTime := goCtx.BlockTime() + + timeoutTimeInFuture := time.Unix(0, int64(msg.TimeoutTimestamp)) + if timeoutTimeInFuture.Before(blockTime) { + return nil, fmt.Errorf("incorrect timeout timestamp found during ibc transfer. timeout timestamp is in the past") + } + + difference := timeoutTimeInFuture.Sub(blockTime).Nanoseconds() + if difference < channelFee.MinTimeoutTimestamp { + return nil, fmt.Errorf("incorrect timeout timestamp found during ibc transfer. too soon") + } + } + coin := findCoinByDenom(channelFee.AllowedTokens, msg.Token.Denom) + if coin == nil { + return nil, fmt.Errorf("token not allowed to be transferred in this channel") + } + + minFee := coin.MinFee.Amount + priority := GetPriority(msg.Memo) + if priority != nil { + p := findPriority(coin.TxPriorityFee, *priority) + if p != nil && coin.MinFee.Denom == p.PriorityFee.Denom { + minFee = minFee.Add(p.PriorityFee.Amount) + } + } + + charge := minFee + if charge.GT(msg.Token.Amount) { + charge = msg.Token.Amount + } + + newAmount := msg.Token.Amount.Sub(charge) + + if newAmount.IsPositive() { + percentageCharge := newAmount.QuoRaw(coin.Percentage) + newAmount = newAmount.Sub(percentageCharge) + charge = charge.Add(percentageCharge) + } + + msgSender, err := sdk.AccAddressFromBech32(msg.Sender) + if err != nil { + return nil, err + } + + feeAddress, err := sdk.AccAddressFromBech32(channelFee.FeeAddress) + if err != nil { + return nil, err + } + + charge_coin := sdk.NewCoin(msg.Token.Denom, charge) + // send_err := k.bank.SendCoins(ctx, msgSender, feeAddress, sdk.NewCoins(charge_coin)) + // if send_err != nil { + // return nil, send_err + // } + msg.Token.Amount = newAmount + return &BridgeFee{fee: charge_coin, sender: msgSender, reciever: feeAddress}, nil + + // if newAmount.LTE(sdk.ZeroInt()) { + // zeroTransfer := sdk.NewCoin(msg.Token.Denom, sdk.ZeroInt()) + // return &zeroTransfer, nil + // } + } + } + // ret, err := k.Keeper.Transfer(goCtx, msg) + // if err == nil && ret != nil && !charge_coin.IsZero() { + // if !charge_coin.IsZero() { + // k.SetSequenceFee(ctx, ret.Sequence, charge_coin) + // } + return nil, nil +} + +func GetPriority(jsonString string) *string { + var data map[string]interface{} + if err := json.Unmarshal([]byte(jsonString), &data); err != nil { + return nil + } + + priority, ok := data["priority"].(string) + if !ok { + return nil + } + + return &priority +} + +func findPriority(priorities []*types.TxPriorityFee, priority string) *types.TxPriorityFee { + for _, p := range priorities { + if p.Priority == priority { + return p + } + } + return nil +} From 017fbfacb1ba758cd0cda97bf387657b449b3d71 Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 22 May 2024 13:45:20 +0100 Subject: [PATCH 2/8] add bank keeper into custom pfm module --- app/keepers/keepers.go | 1 + custom/custompfm/keeper/keeper.go | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 211b340e..223b9ca9 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -375,6 +375,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( routerkeeper.DefaultForwardTransferPacketTimeoutTimestamp, routerkeeper.DefaultRefundTransferPacketTimeoutTimestamp, appKeepers.TransferMiddlewareKeeper, + &appKeepers.BankKeeper, ) ratelimitMiddlewareStack := ratelimitmodule.NewIBCMiddleware(appKeepers.RatelimitKeeper, ibcMiddlewareStack) hooksTransferMiddleware := ibc_hooks.NewIBCMiddleware(ratelimitMiddlewareStack, &appKeepers.HooksICS4Wrapper) diff --git a/custom/custompfm/keeper/keeper.go b/custom/custompfm/keeper/keeper.go index f00cf7a4..22c29c11 100644 --- a/custom/custompfm/keeper/keeper.go +++ b/custom/custompfm/keeper/keeper.go @@ -16,6 +16,7 @@ import ( channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" + custombankkeeper "github.com/notional-labs/composable/v6/custom/bank/keeper" ibctransfermiddlewarekeeper "github.com/notional-labs/composable/v6/x/transfermiddleware/keeper" ) @@ -33,6 +34,7 @@ type IBCMiddleware struct { retriesOnTimeout1 uint8 forwardTimeout1 time.Duration refundTimeout1 time.Duration + bank *custombankkeeper.Keeper } func NewIBCMiddleware( @@ -42,6 +44,7 @@ func NewIBCMiddleware( forwardTimeout time.Duration, refundTimeout time.Duration, ibcfeekeeper ibctransfermiddlewarekeeper.Keeper, + bankkeeper *custombankkeeper.Keeper, ) IBCMiddleware { return IBCMiddleware{ IBCMiddleware: router.NewIBCMiddleware(app, k, retriesOnTimeout, forwardTimeout, refundTimeout), @@ -53,6 +56,7 @@ func NewIBCMiddleware( retriesOnTimeout1: retriesOnTimeout, forwardTimeout1: forwardTimeout, refundTimeout1: refundTimeout, + bank: bankkeeper, } } From f604b8e29297e93b1fc983924bcd7b224ab8dd84 Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 22 May 2024 14:47:20 +0100 Subject: [PATCH 3/8] charge fee if needed and return ack if fee > amount --- app/keepers/keepers.go | 2 +- custom/custompfm/keeper/keeper.go | 69 ++++++++++++++++++++++-- x/ibctransfermiddleware/keeper/keeper.go | 8 +-- 3 files changed, 70 insertions(+), 9 deletions(-) diff --git a/app/keepers/keepers.go b/app/keepers/keepers.go index 223b9ca9..0c313d38 100644 --- a/app/keepers/keepers.go +++ b/app/keepers/keepers.go @@ -374,7 +374,7 @@ func (appKeepers *AppKeepers) InitNormalKeepers( 0, routerkeeper.DefaultForwardTransferPacketTimeoutTimestamp, routerkeeper.DefaultRefundTransferPacketTimeoutTimestamp, - appKeepers.TransferMiddlewareKeeper, + &appKeepers.IbcTransferMiddlewareKeeper, &appKeepers.BankKeeper, ) ratelimitMiddlewareStack := ratelimitmodule.NewIBCMiddleware(appKeepers.RatelimitKeeper, ibcMiddlewareStack) diff --git a/custom/custompfm/keeper/keeper.go b/custom/custompfm/keeper/keeper.go index 22c29c11..e51ce1b8 100644 --- a/custom/custompfm/keeper/keeper.go +++ b/custom/custompfm/keeper/keeper.go @@ -13,11 +13,12 @@ import ( "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/keeper" "github.com/cosmos/ibc-apps/middleware/packet-forward-middleware/v7/packetforward/types" transfertypes "github.com/cosmos/ibc-go/v7/modules/apps/transfer/types" + clienttypes "github.com/cosmos/ibc-go/v7/modules/core/02-client/types" channeltypes "github.com/cosmos/ibc-go/v7/modules/core/04-channel/types" porttypes "github.com/cosmos/ibc-go/v7/modules/core/05-port/types" ibcexported "github.com/cosmos/ibc-go/v7/modules/core/exported" custombankkeeper "github.com/notional-labs/composable/v6/custom/bank/keeper" - ibctransfermiddlewarekeeper "github.com/notional-labs/composable/v6/x/transfermiddleware/keeper" + ibctransfermiddlewarekeeper "github.com/notional-labs/composable/v6/x/ibctransfermiddleware/keeper" ) var _ porttypes.Middleware = &IBCMiddleware{} @@ -26,7 +27,6 @@ var _ porttypes.Middleware = &IBCMiddleware{} // forward keeper and the underlying application. type IBCMiddleware struct { router.IBCMiddleware - ibcfeekeeper ibctransfermiddlewarekeeper.Keeper app1 porttypes.IBCModule keeper1 *keeper.Keeper @@ -34,6 +34,7 @@ type IBCMiddleware struct { retriesOnTimeout1 uint8 forwardTimeout1 time.Duration refundTimeout1 time.Duration + ibcfeekeeper *ibctransfermiddlewarekeeper.Keeper bank *custombankkeeper.Keeper } @@ -43,7 +44,7 @@ func NewIBCMiddleware( retriesOnTimeout uint8, forwardTimeout time.Duration, refundTimeout time.Duration, - ibcfeekeeper ibctransfermiddlewarekeeper.Keeper, + ibcfeekeeper *ibctransfermiddlewarekeeper.Keeper, bankkeeper *custombankkeeper.Keeper, ) IBCMiddleware { return IBCMiddleware{ @@ -164,6 +165,66 @@ func (im IBCMiddleware) OnRecvPacket( retries = im.retriesOnTimeout1 } + // im.ibcfeekeeper.Transfer() + + feeAmount := sdk.NewDecFromInt(token.Amount).Mul(im.keeper1.GetFeePercentage(ctx)).RoundInt() + packetAmount := token.Amount.Sub(feeAmount) + packetCoin := sdk.NewCoin(token.Denom, packetAmount) + + memo := "" + + // set memo for next transfer with next from this transfer. + if metadata.Next != nil { + memoBz, err := json.Marshal(metadata.Next) + if err != nil { + im.keeper1.Logger(ctx).Error("packetForwardMiddleware error marshaling next as JSON", + "error", err, + ) + // return errorsmod.Wrapf(sdkerrors.ErrJSONMarshal, err.Error()) + } + memo = string(memoBz) + } + + tr := transfertypes.NewMsgTransfer( + metadata.Port, + metadata.Channel, + packetCoin, + overrideReceiver, + metadata.Receiver, + clienttypes.Height{ + RevisionNumber: 0, + RevisionHeight: 0, + }, + uint64(ctx.BlockTime().UnixNano())+uint64(timeout.Nanoseconds()), + memo, + ) + + result, err := im.ibcfeekeeper.ChargeFee(goCtx, tr) + if err != nil { + logger.Error("packetForwardMiddleware OnRecvPacket error charging fee", "error", err) + return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", err)) + } + if result != nil { + if token.Amount.LTE(result.Fee.Amount) { + token = token.SubAmount(result.Fee.Amount) + } else { + ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) //?????? + return ack + // logger.Error("fee is greater than the amount", "error") + // return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", err)) + } + + // else { + // logger.Error("fee is greater than the amount", "error") + // return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", err)) + // } + // token = sdk.NewCoin(result.Fee.Denom, result.Fee.Amount) + } + + // //fi amount < fee. it is spamer. we do not need proceed this packet. no timeout for this packet + // ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) + // return ack + err = im.keeper1.ForwardTransferPacket(ctx, nil, packet, data.Sender, overrideReceiver, metadata, token, retries, timeout, []metrics.Label{}, nonrefundable) if err != nil { logger.Error("packetForwardMiddleware OnRecvPacket error forwarding packet", "error", err) @@ -176,7 +237,7 @@ func (im IBCMiddleware) OnRecvPacket( // charge_coin := sdk.NewCoin(packet.Token.Denom, sdk.ZeroInt()) // return channeltypes.NewErrorAcknowledgement(fmt.Errorf("error parsing forward metadata")) - // return im.IBCMiddleware.OnRecvPacket(ctx, packet, relayer) + return im.IBCMiddleware.OnRecvPacket(ctx, packet, relayer) } func newErrorAcknowledgement(err error) channeltypes.Acknowledgement { diff --git a/x/ibctransfermiddleware/keeper/keeper.go b/x/ibctransfermiddleware/keeper/keeper.go index a0f92102..9ce644f5 100644 --- a/x/ibctransfermiddleware/keeper/keeper.go +++ b/x/ibctransfermiddleware/keeper/keeper.go @@ -112,12 +112,12 @@ func (k Keeper) GetChannelFeeAddress(ctx sdk.Context, targetChannelID string) st } type BridgeFee struct { - fee sdk.Coin - sender sdk.AccAddress - reciever sdk.AccAddress + Fee sdk.Coin + Sender sdk.AccAddress + Reciever sdk.AccAddress } -func (k Keeper) Transfer(goCtx context.Context, msg *ibctypes.MsgTransfer) (*BridgeFee, error) { +func (k Keeper) ChargeFee(goCtx context.Context, msg *ibctypes.MsgTransfer) (*BridgeFee, error) { ctx := sdk.UnwrapSDKContext(goCtx) params := k.GetParams(ctx) // charge_coin := sdk.NewCoin(msg.Token.Denom, sdk.ZeroInt()) From 99eb1374a6b5606d894a80f55d04f73517cedcd6 Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 22 May 2024 14:59:04 +0100 Subject: [PATCH 4/8] added todo. to not forgot. --- custom/custompfm/keeper/keeper.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/custom/custompfm/keeper/keeper.go b/custom/custompfm/keeper/keeper.go index e51ce1b8..2c54111b 100644 --- a/custom/custompfm/keeper/keeper.go +++ b/custom/custompfm/keeper/keeper.go @@ -205,9 +205,10 @@ func (im IBCMiddleware) OnRecvPacket( return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", err)) } if result != nil { - if token.Amount.LTE(result.Fee.Amount) { + if token.Amount.GTE(result.Fee.Amount) { token = token.SubAmount(result.Fee.Amount) } else { + //bank.send.......... ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) //?????? return ack // logger.Error("fee is greater than the amount", "error") From 1e9175d55afc87bb5c72dc5f53894fd34327da72 Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 22 May 2024 15:07:59 +0100 Subject: [PATCH 5/8] use bank. --- custom/custompfm/keeper/keeper.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom/custompfm/keeper/keeper.go b/custom/custompfm/keeper/keeper.go index 2c54111b..aeeb5536 100644 --- a/custom/custompfm/keeper/keeper.go +++ b/custom/custompfm/keeper/keeper.go @@ -208,7 +208,7 @@ func (im IBCMiddleware) OnRecvPacket( if token.Amount.GTE(result.Fee.Amount) { token = token.SubAmount(result.Fee.Amount) } else { - //bank.send.......... + // send_err := im.bank.SendCoins(ctx, msgSender, feeAddress, sdk.NewCoins(charge_coin)) ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) //?????? return ack // logger.Error("fee is greater than the amount", "error") From 378af9d2ec03ada7b8a624627905b0215a031bac Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 22 May 2024 16:52:17 +0100 Subject: [PATCH 6/8] all test passed. with a new custom pfm module with a fee. --- custom/custompfm/keeper/keeper.go | 24 ++++++++---------------- x/ibctransfermiddleware/keeper/keeper.go | 9 +++------ 2 files changed, 11 insertions(+), 22 deletions(-) diff --git a/custom/custompfm/keeper/keeper.go b/custom/custompfm/keeper/keeper.go index aeeb5536..48432a29 100644 --- a/custom/custompfm/keeper/keeper.go +++ b/custom/custompfm/keeper/keeper.go @@ -199,33 +199,25 @@ func (im IBCMiddleware) OnRecvPacket( memo, ) - result, err := im.ibcfeekeeper.ChargeFee(goCtx, tr) + result, err := im.ibcfeekeeper.ChargeFee(ctx, tr) if err != nil { logger.Error("packetForwardMiddleware OnRecvPacket error charging fee", "error", err) return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", err)) } if result != nil { - if token.Amount.GTE(result.Fee.Amount) { + if result.Fee.Amount.LT(token.Amount) { token = token.SubAmount(result.Fee.Amount) } else { - // send_err := im.bank.SendCoins(ctx, msgSender, feeAddress, sdk.NewCoins(charge_coin)) - ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) //?????? + send_err := im.bank.SendCoins(ctx, result.Sender, result.Reciever, sdk.NewCoins(result.Fee)) + if send_err != nil { + logger.Error("packetForwardMiddleware OnRecvPacket error sending fee", "error", send_err) + return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", send_err)) + } + ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) return ack - // logger.Error("fee is greater than the amount", "error") - // return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", err)) } - - // else { - // logger.Error("fee is greater than the amount", "error") - // return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", err)) - // } - // token = sdk.NewCoin(result.Fee.Denom, result.Fee.Amount) } - // //fi amount < fee. it is spamer. we do not need proceed this packet. no timeout for this packet - // ack := channeltypes.NewResultAcknowledgement([]byte{byte(1)}) - // return ack - err = im.keeper1.ForwardTransferPacket(ctx, nil, packet, data.Sender, overrideReceiver, metadata, token, retries, timeout, []metrics.Label{}, nonrefundable) if err != nil { logger.Error("packetForwardMiddleware OnRecvPacket error forwarding packet", "error", err) diff --git a/x/ibctransfermiddleware/keeper/keeper.go b/x/ibctransfermiddleware/keeper/keeper.go index 9ce644f5..bf8b95d0 100644 --- a/x/ibctransfermiddleware/keeper/keeper.go +++ b/x/ibctransfermiddleware/keeper/keeper.go @@ -1,7 +1,6 @@ package keeper import ( - "context" "encoding/json" "fmt" "time" @@ -117,8 +116,7 @@ type BridgeFee struct { Reciever sdk.AccAddress } -func (k Keeper) ChargeFee(goCtx context.Context, msg *ibctypes.MsgTransfer) (*BridgeFee, error) { - ctx := sdk.UnwrapSDKContext(goCtx) +func (k Keeper) ChargeFee(ctx sdk.Context, msg *ibctypes.MsgTransfer) (*BridgeFee, error) { params := k.GetParams(ctx) // charge_coin := sdk.NewCoin(msg.Token.Denom, sdk.ZeroInt()) if params.ChannelFees != nil && len(params.ChannelFees) > 0 { @@ -126,8 +124,7 @@ func (k Keeper) ChargeFee(goCtx context.Context, msg *ibctypes.MsgTransfer) (*Br if channelFee != nil { if channelFee.MinTimeoutTimestamp > 0 { - goCtx := sdk.UnwrapSDKContext(goCtx) - blockTime := goCtx.BlockTime() + blockTime := ctx.BlockTime() timeoutTimeInFuture := time.Unix(0, int64(msg.TimeoutTimestamp)) if timeoutTimeInFuture.Before(blockTime) { @@ -182,7 +179,7 @@ func (k Keeper) ChargeFee(goCtx context.Context, msg *ibctypes.MsgTransfer) (*Br // return nil, send_err // } msg.Token.Amount = newAmount - return &BridgeFee{fee: charge_coin, sender: msgSender, reciever: feeAddress}, nil + return &BridgeFee{Fee: charge_coin, Sender: msgSender, Reciever: feeAddress}, nil // if newAmount.LTE(sdk.ZeroInt()) { // zeroTransfer := sdk.NewCoin(msg.Token.Denom, sdk.ZeroInt()) From 46a2f67fb7df471c7c14e9e265b4039d7d023d48 Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 22 May 2024 16:53:19 +0100 Subject: [PATCH 7/8] remove unreachable code. --- custom/custompfm/keeper/keeper.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/custom/custompfm/keeper/keeper.go b/custom/custompfm/keeper/keeper.go index 48432a29..58e2ee1d 100644 --- a/custom/custompfm/keeper/keeper.go +++ b/custom/custompfm/keeper/keeper.go @@ -74,8 +74,6 @@ func (im IBCMiddleware) OnRecvPacket( return im.IBCMiddleware.OnRecvPacket(ctx, packet, relayer) } - // params := im.ibcfeekeeper.GetParams(ctx) - logger.Debug("packetForwardMiddleware OnRecvPacket", "sequence", packet.Sequence, "src-channel", packet.SourceChannel, "src-port", packet.SourcePort, @@ -227,10 +225,6 @@ func (im IBCMiddleware) OnRecvPacket( // returning nil ack will prevent WriteAcknowledgement from occurring for forwarded packet. // This is intentional so that the acknowledgement will be written later based on the ack/timeout of the forwarded packet. return nil - - // charge_coin := sdk.NewCoin(packet.Token.Denom, sdk.ZeroInt()) - // return channeltypes.NewErrorAcknowledgement(fmt.Errorf("error parsing forward metadata")) - return im.IBCMiddleware.OnRecvPacket(ctx, packet, relayer) } func newErrorAcknowledgement(err error) channeltypes.Acknowledgement { From 1ac76780f2b1814d3ab60a276aeae533d90e2dfa Mon Sep 17 00:00:00 2001 From: rustdev Date: Wed, 22 May 2024 17:00:17 +0100 Subject: [PATCH 8/8] fix lint --- custom/custompfm/keeper/keeper.go | 3 +-- x/ibctransfermiddleware/keeper/keeper.go | 4 ++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/custom/custompfm/keeper/keeper.go b/custom/custompfm/keeper/keeper.go index 58e2ee1d..9496a035 100644 --- a/custom/custompfm/keeper/keeper.go +++ b/custom/custompfm/keeper/keeper.go @@ -51,7 +51,6 @@ func NewIBCMiddleware( IBCMiddleware: router.NewIBCMiddleware(app, k, retriesOnTimeout, forwardTimeout, refundTimeout), ibcfeekeeper: ibcfeekeeper, - //we need this bz this field is not exported in the parent struct app1: app, keeper1: k, retriesOnTimeout1: retriesOnTimeout, @@ -206,7 +205,7 @@ func (im IBCMiddleware) OnRecvPacket( if result.Fee.Amount.LT(token.Amount) { token = token.SubAmount(result.Fee.Amount) } else { - send_err := im.bank.SendCoins(ctx, result.Sender, result.Reciever, sdk.NewCoins(result.Fee)) + send_err := im.bank.SendCoins(ctx, result.Sender, result.Receiver, sdk.NewCoins(result.Fee)) if send_err != nil { logger.Error("packetForwardMiddleware OnRecvPacket error sending fee", "error", send_err) return newErrorAcknowledgement(fmt.Errorf("error charging fee: %w", send_err)) diff --git a/x/ibctransfermiddleware/keeper/keeper.go b/x/ibctransfermiddleware/keeper/keeper.go index bf8b95d0..d43741d6 100644 --- a/x/ibctransfermiddleware/keeper/keeper.go +++ b/x/ibctransfermiddleware/keeper/keeper.go @@ -113,7 +113,7 @@ func (k Keeper) GetChannelFeeAddress(ctx sdk.Context, targetChannelID string) st type BridgeFee struct { Fee sdk.Coin Sender sdk.AccAddress - Reciever sdk.AccAddress + Receiver sdk.AccAddress } func (k Keeper) ChargeFee(ctx sdk.Context, msg *ibctypes.MsgTransfer) (*BridgeFee, error) { @@ -179,7 +179,7 @@ func (k Keeper) ChargeFee(ctx sdk.Context, msg *ibctypes.MsgTransfer) (*BridgeFe // return nil, send_err // } msg.Token.Amount = newAmount - return &BridgeFee{Fee: charge_coin, Sender: msgSender, Reciever: feeAddress}, nil + return &BridgeFee{Fee: charge_coin, Sender: msgSender, Receiver: feeAddress}, nil // if newAmount.LTE(sdk.ZeroInt()) { // zeroTransfer := sdk.NewCoin(msg.Token.Denom, sdk.ZeroInt())