Skip to content

Commit

Permalink
feat: Add support for ICS-20 TransferV2
Browse files Browse the repository at this point in the history
  • Loading branch information
kulikthebird committed Jan 27, 2025
1 parent 5b1b179 commit 61661b9
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/CosmWasm/wasmd
go 1.23.1

require (
github.com/CosmWasm/wasmvm/v2 v2.2.1
github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250127092931-0322ca5cbd27
github.com/cosmos/cosmos-proto v1.0.0-beta.5
github.com/cosmos/cosmos-sdk v0.50.11
github.com/cosmos/gogogateway v1.2.0 // indirect
Expand Down Expand Up @@ -220,6 +220,7 @@ require (
)

replace (

github.com/99designs/keyring => github.com/cosmos/keyring v1.2.0
// dgrijalva/jwt-go is deprecated and doesn't receive security updates.
// See: https://github.com/cosmos/cosmos-sdk/issues/13134
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
github.com/CosmWasm/wasmvm/v2 v2.2.1 h1:cmOnM+TDfUl2VRugeo1eJBw4U/Lw0WLviuQHKSo9DVQ=
github.com/CosmWasm/wasmvm/v2 v2.2.1/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250127092931-0322ca5cbd27 h1:E7YmMpKjj3wHvtxCesEoCNcg7ft502+U+QSUycqvkDM=
github.com/CosmWasm/wasmvm/v2 v2.2.2-0.20250127092931-0322ca5cbd27/go.mod h1:bMhLQL4Yp9CzJi9A83aR7VO9wockOsSlZbT4ztOl6bg=
github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
github.com/DataDog/datadog-go v4.8.3+incompatible h1:fNGaYSuObuQb5nzeTQqowRAd9bpDIRRV4/gUtIBjh8Q=
github.com/DataDog/datadog-go v4.8.3+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ=
Expand Down
3 changes: 3 additions & 0 deletions tests/e2e/ibc_callbacks_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ func TestIBCCallbacks(t *testing.T) {
ToAddress string `json:"to_address"`
ChannelID string `json:"channel_id"`
TimeoutSeconds uint32 `json:"timeout_seconds"`
ChannelVersion string `json:"channel_version"`
}
// ExecuteMsg is the ibc-callbacks contract's execute msg
type ExecuteMsg struct {
Expand All @@ -88,6 +89,7 @@ func TestIBCCallbacks(t *testing.T) {
Transfer: &TransferExecMsg{
ChannelID: path.EndpointA.ChannelID,
TimeoutSeconds: 100,
ChannelVersion: "V2",
},
},
expAck: true,
Expand All @@ -97,6 +99,7 @@ func TestIBCCallbacks(t *testing.T) {
Transfer: &TransferExecMsg{
ChannelID: path.EndpointA.ChannelID,
TimeoutSeconds: 1,
ChannelVersion: "V2",
},
},
expAck: false,
Expand Down
Binary file modified tests/e2e/testdata/ibc_callbacks.wasm
Binary file not shown.
Binary file added tests/e2e/testdata/ibc_reflect.wasm
Binary file not shown.
Binary file added tests/e2e/testdata/ibc_reflect_send.wasm
Binary file not shown.
Binary file added tests/integration/testdata/ibc_callbacks.wasm
Binary file not shown.
Binary file modified tests/integration/testdata/ibc_reflect.wasm
Binary file not shown.
Binary file modified tests/integration/testdata/ibc_reflect_send.wasm
Binary file not shown.
28 changes: 28 additions & 0 deletions x/wasm/keeper/handler_plugin_encoders.go
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,34 @@ func EncodeIBCMsg(portSource types.ICS20TransferPortSource) func(ctx sdk.Context
Memo: msg.Transfer.Memo,
}
return []sdk.Msg{msg}, nil
case msg.TransferV2 != nil:
tokens := []sdk.Coin{}
for _, token := range msg.TransferV2.Tokens {
trace := []ibctransfertypes.Hop{}
for _, hop := range token.Trace {
newHop := ibctransfertypes.NewHop(hop.PortID, hop.ChannelID)
trace = append(trace, newHop)
}
coin, err := ibctransfertypes.Token{
Amount: token.Amount,
Denom: ibctransfertypes.NewDenom(token.Base, trace...),
}.ToCoin()
if err != nil {
return nil, errorsmod.Wrap(sdkerrors.ErrInvalidCoins, token.Amount+token.Base)
}
tokens = append(tokens, coin)
}
msg := &ibctransfertypes.MsgTransfer{
SourcePort: portSource.GetPort(ctx),
SourceChannel: msg.TransferV2.ChannelID,
Tokens: tokens,
Sender: sender.String(),
Receiver: msg.TransferV2.ToAddress,
TimeoutHeight: ConvertWasmIBCTimeoutHeightToCosmosHeight(msg.TransferV2.Timeout.Block),
TimeoutTimestamp: msg.TransferV2.Timeout.Timestamp,
Memo: msg.TransferV2.Memo,
}
return []sdk.Msg{msg}, nil
case msg.PayPacketFee != nil:
fee, err := ConvertIBCFee(&msg.PayPacketFee.Fee)
if err != nil {
Expand Down

0 comments on commit 61661b9

Please sign in to comment.