Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add ICS20 TransferV2 #2317

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ jobs:
keys:
- cargocache-v2-contract_ibc_callbacks-rust:1.74-{{ checksum "Cargo.lock" }}
- check_contract:
min_version: "2.1"
min_version: "3.0"
- save_cache:
paths:
- /usr/local/cargo/registry
Expand Down Expand Up @@ -1120,7 +1120,7 @@ jobs:
name: Clippy linting on std (all feature flags)
working_directory: ~/project/packages/std
# change to --all-features once `abort` is removed
command: cargo clippy --all-targets --tests --features staking,stargate,cosmwasm_2_2 -- -D warnings
command: cargo clippy --all-targets --tests --features staking,stargate,cosmwasm_3_0 -- -D warnings
- run:
name: Clippy linting on vm (no feature flags)
working_directory: ~/project/packages/vm
Expand Down
1 change: 1 addition & 0 deletions contracts/ibc-callbacks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ cosmwasm-schema = { path = "../../packages/schema" }
cosmwasm-std = { path = "../../packages/std", features = [
"iterator",
"stargate",
"cosmwasm_3_0",
] }
schemars = "0.8.3"
serde = { version = "1.0.103", default-features = false, features = ["derive"] }
Expand Down
16 changes: 16 additions & 0 deletions contracts/ibc-callbacks/schema/ibc-callbacks.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"type": "object",
"required": [
"channel_id",
"channel_version",
"timeout_seconds",
"to_address"
],
Expand All @@ -40,6 +41,14 @@
"description": "The channel to send the packet through",
"type": "string"
},
"channel_version": {
"description": "IBC channel version",
"allOf": [
{
"$ref": "#/definitions/ChannelVersion"
}
]
},
"timeout_seconds": {
"description": "The amount of seconds from now the transfer should timeout at",
"type": "integer",
Expand Down Expand Up @@ -82,6 +91,13 @@
]
}
]
},
"ChannelVersion": {
"type": "string",
"enum": [
"v1",
"v2"
]
}
}
},
Expand Down
16 changes: 16 additions & 0 deletions contracts/ibc-callbacks/schema/raw/execute.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"type": "object",
"required": [
"channel_id",
"channel_version",
"timeout_seconds",
"to_address"
],
Expand All @@ -29,6 +30,14 @@
"description": "The channel to send the packet through",
"type": "string"
},
"channel_version": {
"description": "IBC channel version",
"allOf": [
{
"$ref": "#/definitions/ChannelVersion"
}
]
},
"timeout_seconds": {
"description": "The amount of seconds from now the transfer should timeout at",
"type": "integer",
Expand Down Expand Up @@ -71,6 +80,13 @@
]
}
]
},
"ChannelVersion": {
"type": "string",
"enum": [
"v1",
"v2"
]
}
}
}
69 changes: 46 additions & 23 deletions contracts/ibc-callbacks/src/contract.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use cosmwasm_std::{
entry_point, to_json_binary, Binary, Deps, DepsMut, Empty, Env, IbcBasicResponse,
IbcDestinationCallbackMsg, IbcDstCallback, IbcSourceCallbackMsg, IbcSrcCallback, IbcTimeout,
MessageInfo, Response, StdError, StdResult, TransferMsgBuilder,
MessageInfo, Response, StdError, StdResult, TransferMsgBuilder, TransferMsgBuilderV2,
};

use crate::msg::{CallbackType, ExecuteMsg, QueryMsg};
use crate::msg::{CallbackType, ChannelVersion, ExecuteMsg, QueryMsg};
use crate::state::{load_stats, save_stats, CallbackStats};

#[entry_point]
Expand Down Expand Up @@ -35,13 +35,15 @@ pub fn execute(
channel_id,
timeout_seconds,
callback_type,
channel_version,
} => execute_transfer(
env,
info,
to_address,
channel_id,
timeout_seconds,
callback_type,
channel_version,
),
}
}
Expand All @@ -53,6 +55,7 @@ fn execute_transfer(
channel_id: String,
timeout_seconds: u32,
callback_type: CallbackType,
channel_version: ChannelVersion,
) -> StdResult<Response> {
let src_callback = IbcSrcCallback {
address: env.contract.address,
Expand All @@ -62,28 +65,48 @@ fn execute_transfer(
address: to_address.clone(),
gas_limit: None,
};
let coin = match &*info.funds {
[coin] if !coin.amount.is_zero() => coin,
_ => {
return Err(StdError::generic_err(
"Must send exactly one denom to trigger ics-20 transfer",
))
}
};

let builder = TransferMsgBuilder::new(
channel_id,
to_address.clone(),
coin.clone(),
IbcTimeout::with_timestamp(env.block.time.plus_seconds(timeout_seconds as u64)),
);
let transfer_msg = match callback_type {
CallbackType::Both => builder
.with_src_callback(src_callback)
.with_dst_callback(dst_callback)
.build(),
CallbackType::Src => builder.with_src_callback(src_callback).build(),
CallbackType::Dst => builder.with_dst_callback(dst_callback).build(),
let transfer_msg = match channel_version {
ChannelVersion::V1 => {
let coin = match &*info.funds {
[coin] if !coin.amount.is_zero() => coin,
_ => {
return Err(StdError::generic_err(
"Must send exactly one denom to trigger ics-20 transfer",
))
}
};
let builder = TransferMsgBuilder::new(
channel_id,
to_address.clone(),
coin.clone(),
IbcTimeout::with_timestamp(env.block.time.plus_seconds(timeout_seconds as u64)),
);
match callback_type {
CallbackType::Both => builder
.with_src_callback(src_callback)
.with_dst_callback(dst_callback)
.build(),
CallbackType::Src => builder.with_src_callback(src_callback).build(),
CallbackType::Dst => builder.with_dst_callback(dst_callback).build(),
}
}
ChannelVersion::V2 => {
let builder = TransferMsgBuilderV2::new(
channel_id,
to_address.clone(),
info.funds.into_iter().map(Into::into).collect(),
IbcTimeout::with_timestamp(env.block.time.plus_seconds(timeout_seconds as u64)),
);
match callback_type {
CallbackType::Both => builder
.with_src_callback(src_callback)
.with_dst_callback(dst_callback)
.build(),
CallbackType::Src => builder.with_src_callback(src_callback).build(),
CallbackType::Dst => builder.with_dst_callback(dst_callback).build(),
}
}
};

Ok(Response::new()
Expand Down
8 changes: 8 additions & 0 deletions contracts/ibc-callbacks/src/msg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ pub enum QueryMsg {
CallbackStats {},
}

#[cw_serde]
pub enum ChannelVersion {
V1,
V2,
}

#[cw_serde]
pub enum ExecuteMsg {
Transfer {
Expand All @@ -20,6 +26,8 @@ pub enum ExecuteMsg {
/// Who should receive callbacks for the message
#[serde(default)]
callback_type: CallbackType,
/// IBC channel version
channel_version: ChannelVersion,
},
}

Expand Down
2 changes: 1 addition & 1 deletion packages/check/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use cosmwasm_vm::internals::{check_wasm, compile, make_compiling_engine, LogOutp
use cosmwasm_vm::{capabilities_from_csv, WasmLimits};

const DEFAULT_AVAILABLE_CAPABILITIES: &str =
"iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2";
"iterator,staking,stargate,cosmwasm_1_1,cosmwasm_1_2,cosmwasm_1_3,cosmwasm_1_4,cosmwasm_2_0,cosmwasm_2_1,cosmwasm_2_2,cosmwasm_3_0";

pub fn main() {
let matches = Command::new("Contract checking")
Expand Down
2 changes: 1 addition & 1 deletion packages/go-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ release = false

[dependencies]
cosmwasm-std = { version = "2.2.0-rc.1", path = "../std", features = [
"cosmwasm_2_2",
"cosmwasm_3_0",
"staking",
"stargate",
] }
Expand Down
1 change: 1 addition & 0 deletions packages/go-gen/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ pub fn custom_type_of(ty: &str) -> Option<&str> {
match ty {
"Uint64" => Some("Uint64"),
"Uint128" => Some("string"),
"Uint256" => Some("string"),
"Int64" => Some("Int64"),
"Int128" => Some("string"),
"Binary" => Some("[]byte"),
Expand Down
Loading
Loading