Skip to content

Commit

Permalink
Merge branch 'main' into tuan/upgrade-sdk-v0.50.x
Browse files Browse the repository at this point in the history
  • Loading branch information
tuantran1702 authored Jan 23, 2024
2 parents 5878e76 + e9baead commit 006e766
Show file tree
Hide file tree
Showing 6 changed files with 176 additions and 72 deletions.
1 change: 1 addition & 0 deletions app/keepers/keepers.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,7 @@ func (appKeepers *AppKeepers) InitKeepers(
authtypes.NewModuleAddress(govtypes.ModuleName).String(),
[]wasmkeeper.Option{}...,
)
ibcStack = interchainstaking.NewTransferMiddleware(ibcStack, appKeepers.InterchainstakingKeeper)

// Create Transfer Stack
var transferStack porttypes.IBCModule
Expand Down
2 changes: 1 addition & 1 deletion icq-relayer/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.21.5-alpine3.18 as build
FROM golang:1.21.5-alpine3.19 as build

WORKDIR /src/app

Expand Down
30 changes: 16 additions & 14 deletions utils/coins.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package utils

import (
"fmt"
"strings"

sdk "github.com/cosmos/cosmos-sdk/types"
ibctransfertypes "github.com/cosmos/ibc-go/v8/modules/apps/transfer/types"
bankutils "github.com/quicksilver-zone/quicksilver/v7/utils/bankutils"

)

func DenomFromRequestKey(query []byte, accAddr sdk.AccAddress) (string, error) {
Expand All @@ -26,18 +28,18 @@ func DenomFromRequestKey(query []byte, accAddr sdk.AccAddress) (string, error) {
return denom, nil
}

func DeriveIbcDenom(port, channel, denom string) string {
return DeriveIbcDenomTrace(port, channel, denom).IBCDenom()
}

func DeriveIbcDenomTrace(port, channel, denom string) ibctransfertypes.DenomTrace {
// generate denomination prefix
sourcePrefix := ibctransfertypes.GetDenomPrefix(port, channel)
// NOTE: sourcePrefix contains the trailing "/"
prefixedDenom := sourcePrefix + denom

// construct the denomination trace from the full raw denomination
denomTrace := ibctransfertypes.ParseDenomTrace(prefixedDenom)

return denomTrace
// DeriveIbcDenom mirrors getDenomForThisChain from the packet-forward-middleware/v5, used under MIT License.
// See: https://github.com/strangelove-ventures/packet-forward-middleware/blob/86f045c12cc48ffc1f016ff122b89a9f6ac8ed63/router/ibc_middleware.go#L104
func DeriveIbcDenom(port, channel, counterpartyPort, counterpartyChannel, denom string) string {
counterpartyPrefix := transfertypes.GetDenomPrefix(counterpartyPort, counterpartyChannel)

Check failure on line 34 in utils/coins.go

View workflow job for this annotation

GitHub Actions / lint

undefined: transfertypes
if strings.HasPrefix(denom, counterpartyPrefix) {
unwoundDenom := denom[len(counterpartyPrefix):]
denomTrace := transfertypes.ParseDenomTrace(unwoundDenom)

Check failure on line 37 in utils/coins.go

View workflow job for this annotation

GitHub Actions / lint

undefined: transfertypes
if denomTrace.Path == "" {
return unwoundDenom
}
return denomTrace.IBCDenom()
}
prefixedDenom := transfertypes.GetDenomPrefix(port, channel) + denom

Check failure on line 43 in utils/coins.go

View workflow job for this annotation

GitHub Actions / lint

undefined: transfertypes
return transfertypes.ParseDenomTrace(prefixedDenom).IBCDenom()

Check failure on line 44 in utils/coins.go

View workflow job for this annotation

GitHub Actions / lint

undefined: transfertypes
}
54 changes: 12 additions & 42 deletions x/interchainstaking/keeper/ibc_packet_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,21 +274,9 @@ func (k *Keeper) HandleAcknowledgement(ctx sdk.Context, packet channeltypes.Pack
return err
}
case "/ibc.applications.transfer.v1.MsgTransfer":
// this should be okay to fail; we'll pick it up next time around.
if !success {
return nil
}
response := ibctransfertypes.MsgTransferResponse{}
err = proto.Unmarshal(msgResponse, &response)
if err != nil {
k.Logger(ctx).Error("unable to unpack MsgTransfer response", "error", err)
return err
}
k.Logger(ctx).Debug("Received MsgTransfer acknowledgement; no action")
return nil

k.Logger(ctx).Info("MsgTranfer acknowledgement received")
if err := k.HandleMsgTransfer(ctx, msg.Msg); err != nil {
return err
}
default:
k.Logger(ctx).Error("unhandled acknowledgement packet", "type", reflect.TypeOf(msg.Msg).Name())
}
Expand All @@ -303,46 +291,28 @@ func (*Keeper) HandleTimeout(_ sdk.Context, _ channeltypes.Packet) error {

// ----------------------------------------------------------------

func (k *Keeper) HandleMsgTransfer(ctx sdk.Context, msg sdk.Msg) error {
func (k *Keeper) HandleMsgTransfer(ctx sdk.Context, msg ibctransfertypes.FungibleTokenPacketData, ibcDenom string) error {
k.Logger(ctx).Info("Received MsgTransfer acknowledgement")
// first, type assertion. we should have ibctransfertypes.MsgTransfer
sMsg, ok := msg.(*ibctransfertypes.MsgTransfer)
if !ok {
k.Logger(ctx).Error("unable to cast source message to MsgTransfer")
return errors.New("unable to cast source message to MsgTransfer")
}

// check if destination is interchainstaking module account (spoiler: it was)
if sMsg.Receiver != k.AccountKeeper.GetModuleAddress(types.ModuleName).String() {
if msg.Receiver != k.AccountKeeper.GetModuleAddress(types.ModuleName).String() {
k.Logger(ctx).Error("msgTransfer to unknown account!")
return errors.New("unexpected recipient")
}

receivedCoin := sMsg.Token

zone, found := k.GetZoneForWithdrawalAccount(ctx, sMsg.Sender)
if !found {
return fmt.Errorf("zone not found for withdrawal account %s", sMsg.Sender)
receivedAmount, ok := sdkmath.NewIntFromString(msg.Amount)
if !ok {
return fmt.Errorf("unable to marshal amount into math.Int: %s", msg.Amount)
}
receivedCoin := sdk.NewCoin(ibcDenom, receivedAmount)

var channel *channeltypes.IdentifiedChannel
k.IBCKeeper.ChannelKeeper.IterateChannels(ctx, func(ic channeltypes.IdentifiedChannel) bool {
if ic.Counterparty.ChannelId == sMsg.SourceChannel && ic.Counterparty.PortId == sMsg.SourcePort && len(ic.ConnectionHops) == 1 && ic.ConnectionHops[0] == zone.ConnectionId && ic.State == channeltypes.OPEN {
channel = &ic
return true
}
return false
})

if channel == nil {
k.Logger(ctx).Error("channel not found for the packet", "port", sMsg.SourcePort, "channel", sMsg.SourceChannel)
return errors.New("channel not found for the packet")
zone, found := k.GetZoneForWithdrawalAccount(ctx, msg.Sender)
if !found {
return fmt.Errorf("zone not found for withdrawal account %s", msg.Sender)
}

denomTrace := utils.DeriveIbcDenomTrace(channel.PortId, channel.ChannelId, receivedCoin.Denom)
receivedCoin.Denom = denomTrace.IBCDenom()

if found && denomTrace.BaseDenom != zone.BaseDenom {
if found && msg.Denom != zone.BaseDenom {
// k.Logger(ctx).Error("got withdrawal account and NOT staking denom", "rx", receivedCoin.Denom, "trace_base_denom", denomTrace.BaseDenom, "zone_base_denom", zone.BaseDenom)
feeAmount := sdkmath.LegacyNewDecFromInt(receivedCoin.Amount).Mul(k.GetCommissionRate(ctx)).TruncateInt()
rewardCoin := receivedCoin.SubAmount(feeAmount)
Expand Down
38 changes: 23 additions & 15 deletions x/interchainstaking/keeper/ibc_packet_handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ func (suite *KeeperTestSuite) TestHandleMsgTransferGood() {
fcAmount: math.NewInt(100),
withdrawalAmount: math.ZeroInt(),
},
{
name: "ibc denom denom - all goes to fc",
amount: sdk.NewCoin("transfer/channel-569/untrn", math.NewInt(100)),
fcAmount: math.NewInt(2),
withdrawalAmount: math.NewInt(98),
},
{
name: "non staking denom - default (2.5%) to fc, remainder to withdrawal",
amount: sdk.NewCoin("ujuno", math.NewInt(100)),
Expand All @@ -82,7 +88,7 @@ func (suite *KeeperTestSuite) TestHandleMsgTransferGood() {
channel, cfound := quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.GetChannel(ctx, "transfer", "channel-0")
suite.True(cfound)

ibcDenom := utils.DeriveIbcDenom(channel.Counterparty.PortId, channel.Counterparty.ChannelId, tc.amount.Denom)
ibcDenom := utils.DeriveIbcDenom("transfer", "channel-0", channel.Counterparty.PortId, channel.Counterparty.ChannelId, tc.amount.Denom)

err := quicksilver.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(ibcDenom, tc.amount.Amount)))
suite.NoError(err)
Expand All @@ -102,14 +108,14 @@ func (suite *KeeperTestSuite) TestHandleMsgTransferGood() {
txMacc := quicksilver.AccountKeeper.GetModuleAddress(types.ModuleName)
feeMacc := quicksilver.AccountKeeper.GetModuleAddress(authtypes.FeeCollectorName)

transferMsg := ibctransfertypes.MsgTransfer{
SourcePort: "transfer",
SourceChannel: "channel-0",
Token: tc.amount,
Sender: sender,
Receiver: quicksilver.AccountKeeper.GetModuleAddress(types.ModuleName).String(),
transferPacket := ibctransfertypes.FungibleTokenPacketData{
Amount: tc.amount.Amount.String(),
Denom: tc.amount.Denom,
Sender: sender,
Receiver: quicksilver.AccountKeeper.GetModuleAddress(types.ModuleName).String(),
}
suite.NoError(quicksilver.InterchainstakingKeeper.HandleMsgTransfer(ctx, &transferMsg))

suite.NoError(quicksilver.InterchainstakingKeeper.HandleMsgTransfer(ctx, transferPacket, utils.DeriveIbcDenom("transfer", "channel-0", channel.Counterparty.PortId, channel.Counterparty.ChannelId, tc.amount.Denom)))

txMaccBalance := quicksilver.BankKeeper.GetAllBalances(ctx, txMacc)
feeMaccBalance := quicksilver.BankKeeper.GetAllBalances(ctx, feeMacc)
Expand Down Expand Up @@ -152,8 +158,9 @@ func TestHandleMsgTransferBadRecipient(t *testing.T) {
Token: sdk.NewCoin("denom", sdkmath.NewInt(100)),
Sender: senderAddr,
Receiver: recipient.String(),

}
require.Error(t, quicksilver.InterchainstakingKeeper.HandleMsgTransfer(ctx, &transferMsg))
require.Error(t, quicksilver.InterchainstakingKeeper.HandleMsgTransfer(ctx, transferMsg, "raa"))
}

func (suite *KeeperTestSuite) TestHandleQueuedUnbondings() {
Expand Down Expand Up @@ -1809,9 +1816,8 @@ func (suite *KeeperTestSuite) Test_v045Callback() {
if !found {
suite.Fail("unable to retrieve zone for test")
}
sender := zone.WithdrawalAddress.Address

quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel)
val := quicksilver.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)[0]

ibcDenom := utils.DeriveIbcDenom("transfer", "channel-0", zone.BaseDenom)
err := quicksilver.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(ibcDenom, sdkmath.NewInt(100))))
Expand All @@ -1827,9 +1833,10 @@ func (suite *KeeperTestSuite) Test_v045Callback() {
response := ibctransfertypes.MsgTransferResponse{
Sequence: 1,
}
response := stakingtypes.MsgDelegateResponse{}

respBytes := icatypes.ModuleCdc.MustMarshal(&response)
return []sdk.Msg{&transferMsg}, respBytes
return []sdk.Msg{&sendMsg}, respBytes
},
assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool {
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
Expand Down Expand Up @@ -1939,9 +1946,8 @@ func (suite *KeeperTestSuite) Test_v046Callback() {
if !found {
suite.Fail("unable to retrieve zone for test")
}
sender := zone.WithdrawalAddress.Address

quicksilver.InterchainstakingKeeper.IBCKeeper.ChannelKeeper.SetChannel(ctx, "transfer", "channel-0", TestChannel)
val := quicksilver.InterchainstakingKeeper.GetValidatorAddresses(ctx, zone.ChainId)[0]

ibcDenom := utils.DeriveIbcDenom("transfer", "channel-0", zone.BaseDenom)
err := quicksilver.BankKeeper.MintCoins(ctx, types.ModuleName, sdk.NewCoins(sdk.NewCoin(ibcDenom, sdkmath.NewInt(100))))
Expand All @@ -1957,10 +1963,11 @@ func (suite *KeeperTestSuite) Test_v046Callback() {
response := ibctransfertypes.MsgTransferResponse{
Sequence: 1,
}
response := stakingtypes.MsgDelegateResponse{}

anyResponse, err := codectypes.NewAnyWithValue(&response)
suite.NoError(err)
return []sdk.Msg{&transferMsg}, anyResponse
return []sdk.Msg{&sendMsg}, anyResponse
},
assertStatements: func(ctx sdk.Context, quicksilver *app.Quicksilver) bool {
zone, found := quicksilver.InterchainstakingKeeper.GetZone(ctx, suite.chainB.ChainID)
Expand Down Expand Up @@ -2050,6 +2057,7 @@ func (suite *KeeperTestSuite) Test_v046Callback() {
Data: packetBytes,
}

ctx = ctx.WithContext(context.WithValue(ctx.Context(), utils.ContextKey("connectionID"), "connection-0"))
suite.NoError(quicksilver.InterchainstakingKeeper.HandleAcknowledgement(ctx, packet, icatypes.ModuleCdc.MustMarshalJSON(&acknowledgement)))

suite.True(test.assertStatements(ctx, quicksilver))
Expand Down
123 changes: 123 additions & 0 deletions x/interchainstaking/transfer_middleware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
package interchainstaking

import (
sdk "github.com/cosmos/cosmos-sdk/types"
capabilitytypes "github.com/cosmos/cosmos-sdk/x/capability/types"

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/cosmos-sdk/x/capability/types; to add it:

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/cosmos-sdk/x/capability/types; to add it:

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

no required module provides package github.com/cosmos/cosmos-sdk/x/capability/types; to add it:

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

no required module provides package github.com/cosmos/cosmos-sdk/x/capability/types; to add it:

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/cosmos-sdk/x/capability/types; to add it:

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/cosmos-sdk/x/capability/types; to add it:

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

Check failure on line 5 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / Analyze

cannot find module providing package github.com/cosmos/cosmos-sdk/x/capability/types: import lookup disabled by -mod=readonly

transfertypes "github.com/cosmos/ibc-go/v5/modules/apps/transfer/types"

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types; to add it:

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types; to add it:

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

no required module provides package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types; to add it:

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

no required module provides package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types; to add it:

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types; to add it:

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types; to add it:

Check failure on line 7 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/apps/transfer/types: import lookup disabled by -mod=readonly
channeltypes "github.com/cosmos/ibc-go/v5/modules/core/04-channel/types"

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types: import lookup disabled by -mod=readonly

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types; to add it:

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types; to add it:

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types; to add it:

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types; to add it:

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types: import lookup disabled by -mod=readonly

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types: import lookup disabled by -mod=readonly

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types; to add it:

Check failure on line 8 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/04-channel/types; to add it:
porttypes "github.com/cosmos/ibc-go/v5/modules/core/05-port/types"

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/05-port/types: import lookup disabled by -mod=readonly

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/05-port/types; to add it:

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/05-port/types; to add it:

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/05-port/types; to add it:

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/05-port/types; to add it:

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/05-port/types: import lookup disabled by -mod=readonly

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/05-port/types: import lookup disabled by -mod=readonly

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/05-port/types; to add it:

Check failure on line 9 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/05-port/types; to add it:
ibcexported "github.com/cosmos/ibc-go/v5/modules/core/exported"

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/exported: import lookup disabled by -mod=readonly

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/exported; to add it:

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/exported; to add it:

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/exported; to add it:

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/exported; to add it:

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/exported: import lookup disabled by -mod=readonly

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

cannot find module providing package github.com/cosmos/ibc-go/v5/modules/core/exported: import lookup disabled by -mod=readonly

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/exported; to add it:

Check failure on line 10 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/cosmos/ibc-go/v5/modules/core/exported; to add it:

"github.com/quicksilver-zone/quicksilver/utils"

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

cannot find module providing package github.com/quicksilver-zone/quicksilver/utils: import lookup disabled by -mod=readonly

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/quicksilver-zone/quicksilver/utils; to add it:

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/quicksilver-zone/quicksilver/utils; to add it:

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

no required module provides package github.com/quicksilver-zone/quicksilver/utils; to add it:

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

no required module provides package github.com/quicksilver-zone/quicksilver/utils; to add it:

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

cannot find module providing package github.com/quicksilver-zone/quicksilver/utils: import lookup disabled by -mod=readonly

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

cannot find module providing package github.com/quicksilver-zone/quicksilver/utils: import lookup disabled by -mod=readonly

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/quicksilver-zone/quicksilver/utils; to add it:

Check failure on line 12 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/quicksilver-zone/quicksilver/utils; to add it:
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper"

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

cannot find module providing package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper: import lookup disabled by -mod=readonly

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper; to add it:

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper; to add it:

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper; to add it:

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper; to add it:

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

cannot find module providing package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper: import lookup disabled by -mod=readonly

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

cannot find module providing package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper: import lookup disabled by -mod=readonly

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper; to add it:

Check failure on line 13 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/keeper; to add it:
"github.com/quicksilver-zone/quicksilver/x/interchainstaking/types"

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, linux)

cannot find module providing package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types: import lookup disabled by -mod=readonly

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types; to add it:

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types; to add it:

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (darwin, arm64)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types; to add it:

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, linux)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types; to add it:

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, windows)

cannot find module providing package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types: import lookup disabled by -mod=readonly

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / build quicksilver (amd64, darwin)

cannot find module providing package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types: import lookup disabled by -mod=readonly

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, darwin)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types; to add it:

Check failure on line 14 in x/interchainstaking/transfer_middleware.go

View workflow job for this annotation

GitHub Actions / test quicksilver (amd64, windows)

no required module provides package github.com/quicksilver-zone/quicksilver/x/interchainstaking/types; to add it:
)

var _ porttypes.IBCModule = &TransferMiddleware{}

// IBCModule implements the ICS26 interface for interchain accounts controller chains.
type TransferMiddleware struct {
app porttypes.IBCModule
keeper *keeper.Keeper
}

// NewIBCModule creates a new IBCModule given the keeper.
func NewTransferMiddleware(app porttypes.IBCModule, k *keeper.Keeper) TransferMiddleware {
return TransferMiddleware{
app: app,
keeper: k,
}
}

// OnChanOpenInit implements the IBCModule interface.
func (im TransferMiddleware) OnChanOpenInit(
ctx sdk.Context,
order channeltypes.Order,
connectionHops []string,
portID string,
channelID string,
chanCap *capabilitytypes.Capability,
counterparty channeltypes.Counterparty,
version string,
) (string, error) {
return im.app.OnChanOpenInit(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, version)
}

// OnChanOpenTry implements the IBCModule interface.
func (im TransferMiddleware) OnChanOpenTry(
ctx sdk.Context,
order channeltypes.Order,
connectionHops []string,
portID, channelID string,
chanCap *capabilitytypes.Capability,
counterparty channeltypes.Counterparty,
counterpartyVersion string,
) (version string, err error) {
return im.app.OnChanOpenTry(ctx, order, connectionHops, portID, channelID, chanCap, counterparty, counterpartyVersion)
}

// OnChanOpenAck implements the IBCModule interface.
func (im TransferMiddleware) OnChanOpenAck(
ctx sdk.Context,
portID, channelID string,
counterpartyChannelID string,
counterpartyVersion string,
) error {
return im.app.OnChanOpenAck(ctx, portID, channelID, counterpartyChannelID, counterpartyVersion)
}

// OnChanOpenConfirm implements the IBCModule interface.
func (im TransferMiddleware) OnChanOpenConfirm(ctx sdk.Context, portID, channelID string) error {
return im.app.OnChanOpenConfirm(ctx, portID, channelID)
}

// OnChanCloseInit implements the IBCModule interface.
func (im TransferMiddleware) OnChanCloseInit(ctx sdk.Context, portID, channelID string) error {
return im.app.OnChanCloseInit(ctx, portID, channelID)
}

// OnChanCloseConfirm implements the IBCModule interface.
func (im TransferMiddleware) OnChanCloseConfirm(ctx sdk.Context, portID, channelID string) error {
return im.app.OnChanCloseConfirm(ctx, portID, channelID)
}

// OnRecvPacket checks implements the IBCModule interface.
func (im TransferMiddleware) OnRecvPacket(
ctx sdk.Context,
packet channeltypes.Packet,
relayer sdk.AccAddress,
) ibcexported.Acknowledgement {
var data transfertypes.FungibleTokenPacketData
if err := transfertypes.ModuleCdc.UnmarshalJSON(packet.GetData(), &data); err != nil {
return channeltypes.NewErrorAcknowledgement(err)
}

_, found := im.keeper.GetZoneForWithdrawalAccount(ctx, data.Sender)
if found {
if data.Receiver == im.keeper.AccountKeeper.GetModuleAddress(types.ModuleName).String() {
im.keeper.Logger(ctx).Info("msgTransfer to ics module account from withdrawal address")
err := im.keeper.HandleMsgTransfer(ctx, data, utils.DeriveIbcDenom(packet.DestinationPort, packet.DestinationChannel, packet.SourcePort, packet.SourceChannel, data.Denom))
if err != nil {
im.keeper.Logger(ctx).Error("unable to disperse rewards", "error", err.Error())
}
}
}

return im.app.OnRecvPacket(ctx, packet, relayer)
}

// OnAcknowledgementPacket implements the IBCModule interface.
func (im TransferMiddleware) OnAcknowledgementPacket(
ctx sdk.Context,
packet channeltypes.Packet,
acknowledgement []byte,
relayer sdk.AccAddress,
) error {
return im.app.OnAcknowledgementPacket(ctx, packet, acknowledgement, relayer)
}

// OnTimeoutPacket implements the IBCModule interface.
func (im TransferMiddleware) OnTimeoutPacket(ctx sdk.Context, packet channeltypes.Packet, relayer sdk.AccAddress) error {
return im.app.OnTimeoutPacket(ctx, packet, relayer)
}

0 comments on commit 006e766

Please sign in to comment.