Skip to content

Commit 0031a25

Browse files
committed
feat: Add TransferV2
1 parent e17ecc4 commit 0031a25

File tree

1 file changed

+59
-1
lines changed

1 file changed

+59
-1
lines changed

packages/std/src/ibc.rs

+59-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use schemars::JsonSchema;
66
use serde::{Deserialize, Serialize};
77

88
use crate::coin::Coin;
9-
use crate::prelude::*;
9+
use crate::{prelude::*, Uint256};
1010
use crate::results::{Attribute, CosmosMsg, Empty, Event, SubMsg};
1111
use crate::StdResult;
1212
use crate::{to_json_binary, Binary};
@@ -18,6 +18,32 @@ mod transfer_msg_builder;
1818
pub use callbacks::*;
1919
pub use transfer_msg_builder::*;
2020

21+
22+
#[non_exhaustive]
23+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
24+
#[serde(rename_all = "snake_case")]
25+
pub struct Token {
26+
base: String,
27+
trace: Vec<Hop>,
28+
amount: Uint256,
29+
}
30+
31+
#[non_exhaustive]
32+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
33+
#[serde(rename_all = "snake_case")]
34+
pub struct Forwarding {
35+
hops: Vec<Hop>,
36+
memo: String,
37+
}
38+
39+
#[non_exhaustive]
40+
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
41+
#[serde(rename_all = "snake_case")]
42+
pub struct Hop {
43+
port_id: String,
44+
channel_id: String,
45+
}
46+
2147
/// These are messages in the IBC lifecycle. Only usable by IBC-enabled contracts
2248
/// (contracts that directly speak the IBC protocol via 6 entry points)
2349
#[non_exhaustive]
@@ -52,6 +78,38 @@ pub enum IbcMsg {
5278
/// protobuf encoder instead.
5379
memo: Option<String>,
5480
},
81+
/// Sends bank tokens owned by the contract to the given address on another chain.
82+
/// The channel must already be established between the ibctransfer module on this chain
83+
/// and a matching module on the remote chain.
84+
/// We cannot select the port_id, this is whatever the local chain has bound the ibctransfer
85+
/// module to.
86+
TransferV2 {
87+
/// existing channel to send the tokens over
88+
channel_id: String,
89+
/// address on the remote chain to receive these tokens
90+
to_address: String,
91+
/// packet data only supports one coin
92+
/// https://github.com/cosmos/cosmos-sdk/blob/v0.40.0/proto/ibc/applications/transfer/v1/transfer.proto#L11-L20
93+
tokens: Vec<Token>,
94+
/// when packet times out, measured on remote chain
95+
timeout: IbcTimeout,
96+
/// An optional memo. See the blog post
97+
/// ["Moving Beyond Simple Token Transfers"](https://medium.com/the-interchain-foundation/moving-beyond-simple-token-transfers-d42b2b1dc29b)
98+
/// for more information.
99+
///
100+
/// There is no difference between setting this to `None` or an empty string.
101+
///
102+
/// This field is only supported on chains with CosmWasm >= 2.0 and silently
103+
/// ignored on older chains.
104+
/// If you need support for both 1.x and 2.x chain with the same codebase,
105+
/// it is recommended to use `CosmosMsg::Stargate` with a custom MsgTransfer
106+
/// protobuf encoder instead.
107+
memo: Option<String>,
108+
// a struct containing the list of next hops,
109+
// determining where the tokens must be forwarded next,
110+
// and the memo for the final hop
111+
forwarding: Forwarding,
112+
},
55113
/// Sends an IBC packet with given data over the existing channel.
56114
/// Data should be encoded in a format defined by the channel version,
57115
/// and the module on the other side should know how to parse this.

0 commit comments

Comments
 (0)