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 27b8ac6
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 0 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ require (
)

replace (
github.com/CosmWasm/wasmvm/v2 => /home/tkulik/Workspace/wasmvm

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
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: "V1",
},
},
expAck: true,
Expand All @@ -97,6 +99,7 @@ func TestIBCCallbacks(t *testing.T) {
Transfer: &TransferExecMsg{
ChannelID: path.EndpointA.ChannelID,
TimeoutSeconds: 1,
ChannelVersion: "V1",
},
},
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 27b8ac6

Please sign in to comment.