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

Memo field apis #412

Merged
merged 37 commits into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
672bcd8
middleware forward memo builder
Buckram123 Jul 18, 2024
ba480c4
ibc memo
Buckram123 Jul 18, 2024
caa93b2
clippy
Buckram123 Jul 19, 2024
0711fbe
rename types
CyberHoward Jul 22, 2024
6232c92
Move impls and format
CyberHoward Jul 22, 2024
17f9d0b
Merge branch 'main' into misha/abs-464-memo-field-apis
CyberHoward Jul 25, 2024
cb4986c
Merge branch 'main' into misha/abs-464-memo-field-apis
CyberHoward Jul 25, 2024
c87d9da
Merge remote-tracking branch 'origin/main' into misha/abs-464-memo-fi…
Buckram123 Jul 26, 2024
bbaf64e
small starship config edit
Buckram123 Jul 30, 2024
268a852
add pfm test
Buckram123 Aug 2, 2024
ae567d1
4chain
Buckram123 Aug 5, 2024
22adde7
add receiver to ibc sendfunds
Buckram123 Aug 6, 2024
7bb2ecd
Merge branch 'main' into misha/abs-464-memo-field-apis
Buckram123 Aug 6, 2024
c2a8993
ibc send memo demo
Buckram123 Aug 6, 2024
f40a545
memo api improvements
Buckram123 Aug 6, 2024
facc3a3
finalize tests
Buckram123 Aug 6, 2024
a63b750
remove branch dep
Buckram123 Aug 12, 2024
38d3440
clippy
Buckram123 Aug 12, 2024
0d74784
bizarre handling of different cw_orchs for testing ibc_hook
Buckram123 Aug 12, 2024
1fdfc2b
Merge remote-tracking branch 'origin/main' into misha/abs-464-memo-fi…
Buckram123 Aug 12, 2024
e156b41
Merge remote-tracking branch 'origin/main' into misha/abs-464-memo-fi…
CyberHoward Aug 27, 2024
ada4787
update cargo lock
CyberHoward Aug 27, 2024
24fa712
formatting [skip ci]
CyberHoward Aug 27, 2024
8f82cea
apply suggestions
Buckram123 Sep 6, 2024
708faae
update names
Buckram123 Sep 6, 2024
c8962ed
Merge remote-tracking branch 'origin/buckram/cosmwasm-2.0-bump' into …
Buckram123 Sep 6, 2024
5b53d78
update tests
Buckram123 Sep 6, 2024
2b9d3ca
Merge branch 'buckram/cosmwasm-2.0-bump' into misha/abs-464-memo-fiel…
Buckram123 Oct 18, 2024
be87663
Merge remote-tracking branch 'origin/main' into misha/abs-464-memo-fi…
Buckram123 Oct 18, 2024
57419cc
fix recursive ours merge
Buckram123 Oct 18, 2024
46bd7ca
fix ibc-hook and pfm tests
Buckram123 Oct 22, 2024
44ba5fb
Merge remote-tracking branch 'origin/main' into misha/abs-464-memo-fi…
Buckram123 Oct 22, 2024
02ba585
move todo to task
Buckram123 Oct 22, 2024
ea8a1e9
typo in filename
Buckram123 Oct 25, 2024
3b7239e
Removed warnings
Kayanski Oct 25, 2024
ca4e6ff
Merge branch 'misha/abs-464-memo-field-apis' of github.com:AbstractSD…
Kayanski Oct 25, 2024
f6b121e
Merge remote-tracking branch 'origin/main' into misha/abs-464-memo-fi…
Kayanski Oct 25, 2024
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
332 changes: 330 additions & 2 deletions framework/Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions framework/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ cw-asset = { version = "3.0" }
cw-ownable = { version = "0.5" }
cw-address-like = { version = "1.0" }
cw-clearable = { version = "0.1.2" }
serde-cw-value = "0.7.0"

schemars = "0.8"
serde = { version = "1.0", default-features = false, features = ["derive"] }
Expand Down
Binary file modified framework/artifacts/abstract_account_factory.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_ans_host.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_ibc_client.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_ibc_host.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_manager.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_module_factory.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_proxy.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_version_control.wasm
Binary file not shown.
16 changes: 8 additions & 8 deletions framework/artifacts/checksums.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
e52a29a8e6ce0dc4b48eda18e4ee2bd86db3040e00aa7e329b613773490a437e abstract_account_factory.wasm
573236548390ecbc23f296a19901a349741b83b4978594875b1c8d8e2da52ab8 abstract_ans_host.wasm
a8cee255061830e7462ae638972b16ac5ad67b8d2bb30d18e131cf4936780cb8 abstract_ibc_client.wasm
a1c6e90962ea9ff1852b8bbb8731b453bc14cdb99e47eb8d71083672d8ac6059 abstract_ibc_host.wasm
6a4cf0798133903612165c1cbf6685b727f077f28bc73b7ef88a659379085b35 abstract_manager.wasm
1ec89477602b7064a22f7015fe0626bdee350b0a35d2b73f21710bdd61992869 abstract_module_factory.wasm
116b268e33d2083e953a2eaed717b149368559423730786fc68ecfee53e4b42b abstract_proxy.wasm
a0f924ea484c8b7d960fdd99bd1d65e3603d9c43e04c384a002a1fed5f83c1e7 abstract_version_control.wasm
d325a93479fad1f3b743a55f780be8a73ff4d2da160768c2fe9d46faba2d2636 abstract_account_factory.wasm
ca88c075ed87ead750681e27c288c0c24d2e84fd99cb63db435e297c135c9a33 abstract_ans_host.wasm
c2f3cb93a4483a58b1297dd8e04cca2e0f1e1819975152ce94e221abb9602229 abstract_ibc_client.wasm
182a89a785777f9172cae444ef902fab8a99f6bf02213bcf3ba40571535a8131 abstract_ibc_host.wasm
f84aecce86bb294168cb753099529307b252a6b1e5b5fd203693091dc4c2d204 abstract_manager.wasm
fb8c42627e08d4b0c1581f422cd7de406817f09fafbafb5ef768426937ace198 abstract_module_factory.wasm
f24ce1a97c5ec32b8acaa501715d10657e594198e90e7a7ecc58bfc9e7de1467 abstract_proxy.wasm
5b1ea9939e02a5764064a8c51410109dcfe88ad0625d5ca9968d5ad9a75e60d7 abstract_version_control.wasm
2 changes: 2 additions & 0 deletions framework/contracts/account/proxy/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ mod test {
host_chain: "juno".parse().unwrap(),
funds: funds.clone(),
memo: None,
receiver: None,
},
};

Expand Down Expand Up @@ -512,6 +513,7 @@ mod test {
host_chain: "juno".parse().unwrap(),
funds: funds.clone(),
memo: None,
receiver: None,
})
.unwrap(),
funds,
Expand Down
20 changes: 13 additions & 7 deletions framework/contracts/native/ibc-client/src/commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,7 @@ pub fn execute_send_funds(
host_chain: TruncatedChainId,
funds: Vec<Coin>,
memo: Option<String>,
receiver: Option<String>,
) -> IbcClientResult {
host_chain.verify()?;

Expand All @@ -428,13 +429,18 @@ pub fn execute_send_funds(
.version_control
.assert_proxy(&info.sender, &deps.querier)?;

// get account_id of Account
let account_id = account_base.account_id(deps.as_ref())?;
// load remote account
let remote_addr = ACCOUNTS.load(
deps.storage,
(account_id.trace(), account_id.seq(), &host_chain),
)?;
let remote_addr = match receiver {
Some(addr) => addr,
None => {
// get account_id of Account
let account_id = account_base.account_id(deps.as_ref())?;
// load remote account
ACCOUNTS.load(
deps.storage,
(account_id.trace(), account_id.seq(), &host_chain),
)?
}
};

let ics20_channel_entry = ChannelEntry {
connected_chain: host_chain,
Expand Down
6 changes: 5 additions & 1 deletion framework/contracts/native/ibc-client/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> I
}
ExecuteMsg::SendFunds {
host_chain,
receiver,
funds,
memo,
} => commands::execute_send_funds(deps, env, info, host_chain, funds, memo)
} => commands::execute_send_funds(deps, env, info, host_chain, funds, memo, receiver)
.map_err(Into::into),
ExecuteMsg::Register {
host_chain,
Expand Down Expand Up @@ -619,6 +620,7 @@ mod tests {

let msg = ExecuteMsg::SendFunds {
host_chain: chain_name,
receiver: None,
funds: coins(1, "denom"),
memo: None,
};
Expand Down Expand Up @@ -659,6 +661,7 @@ mod tests {

let msg = ExecuteMsg::SendFunds {
host_chain: chain_name.clone(),
receiver: None,
funds: funds.clone(),
memo: None,
};
Expand Down Expand Up @@ -688,6 +691,7 @@ mod tests {

let msg = ExecuteMsg::SendFunds {
host_chain: chain_name,
receiver: None,
funds: funds.clone(),
memo: memo.clone(),
};
Expand Down
2 changes: 1 addition & 1 deletion framework/contracts/native/module-factory/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ abstract-std = { workspace = true }
abstract-macros = { workspace = true }
cw-asset = { workspace = true }
cw-ownable = { workspace = true }
serde-cw-value = "0.7.0"
serde-cw-value = { workspace = true }
workspace-hack = { version = "0.1", path = "../../../workspace-hack" }

[dev-dependencies]
Expand Down
2 changes: 2 additions & 0 deletions framework/docs/src/releases/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

### Added

- Added `MiddlewareForwardMemoBuilder` API for building middleware forwarding memo
- Added `ExecuteWasmContractMemoBuilder` API for building wasm ibc hook memo
Buckram123 marked this conversation as resolved.
Show resolved Hide resolved
- `execute_with_funds` to Executor to attach funds to execution.
- `stargate` feature for abstract-app, abstract-standalone and abstract-adapter packages.
- New module type: `Service`, behaves the same as Native, but can be registered by any namespace.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ impl<'a, Chain: IbcQueryHandler, IBC: InterchainEnv<Chain>> RemoteAccount<'a, Ch
host_chain: self.host_chain_id(),
funds,
memo,
receiver: None,
})
}

Expand Down
2 changes: 2 additions & 0 deletions framework/packages/abstract-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ abstract-std = { workspace = true }
semver = { workspace = true }
abstract-macros = { workspace = true }
cw-clearable = { workspace = true }
serde-cw-value = { workspace = true }

# test-utils feature
abstract-testing = { workspace = true, optional = true }
Expand All @@ -50,3 +51,4 @@ doc-comment = "0.3.3"
# Set our own feature when running tests!
abstract-sdk = { path = ".", features = ["test-utils"] }
cw-ownable = { workspace = true }
serde_json = "1.0.79"
1 change: 1 addition & 0 deletions framework/packages/abstract-sdk/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub mod app;
pub mod bank;
pub mod execution;
pub mod ibc;
pub mod ibc_memo;
pub mod modules;
pub mod respond;
mod splitter;
Expand Down
4 changes: 4 additions & 0 deletions framework/packages/abstract-sdk/src/apis/ibc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,14 @@ impl<'a, T: IbcInterface + AccountExecutor> IbcClient<'a, T> {
host_chain: TruncatedChainId,
funds: Vec<Coin>,
memo: Option<String>,
receiver: Option<String>,
) -> AbstractSdkResult<CosmosMsg> {
Ok(wasm_execute(
self.base.proxy_address(self.deps)?.to_string(),
&ExecuteMsg::IbcAction {
msg: IbcClientMsg::SendFunds {
host_chain,
receiver,
funds,
memo,
},
Expand Down Expand Up @@ -395,6 +397,7 @@ mod test {
TEST_HOST_CHAIN.parse().unwrap(),
expected_funds.clone(),
None,
None,
);
assert_that!(msg).is_ok();

Expand All @@ -405,6 +408,7 @@ mod test {
host_chain: TEST_HOST_CHAIN.parse().unwrap(),
funds: expected_funds,
memo: None,
receiver: None,
},
})
.unwrap(),
Expand Down
141 changes: 141 additions & 0 deletions framework/packages/abstract-sdk/src/apis/ibc_memo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
mod hooks;
mod pfm;
// mod pfm;
Buckram123 marked this conversation as resolved.
Show resolved Hide resolved

use std::collections::BTreeMap;

pub use hooks::IbcHooksBuilder;
pub use pfm::PacketForwardMiddlewareBuilder;
use serde_cw_value::Value;

/// Trait for memo-based IBC message builders.
pub trait IbcMemoBuilder {
/// Build the memo json [Value] object.
fn build_value_map(self) -> BTreeMap<Value, Value>;
Buckram123 marked this conversation as resolved.
Show resolved Hide resolved
/// Build the memo json string.
fn build(self) -> cosmwasm_std::StdResult<String>
where
Self: Sized,
{
cosmwasm_std::to_json_string(&self.build_value_map())
}
}

#[cfg(test)]
mod test {
use super::*;
use cosmwasm_std::Addr;
use serde_json::json;

#[test]
fn memo_middleware() {
let empty = PacketForwardMiddlewareBuilder::new("who").build().unwrap();
let value: serde_json::Value = serde_json::from_str(&empty).unwrap();
let expected_value = json!({});
assert_eq!(value, expected_value);

let minimal = PacketForwardMiddlewareBuilder::new("foo")
.hop("channel-1")
.build()
.unwrap();
let value: serde_json::Value = serde_json::from_str(&minimal).unwrap();
let expected_value = json!({
"forward": {
"channel": "channel-1",
"port": "transfer",
"receiver": "foo",
}
});
assert_eq!(value, expected_value);

let complete = PacketForwardMiddlewareBuilder::new("foo")
.port("different_port")
.hop("channel-1")
.timeout("10m")
.retries(4)
.hop("channel-2")
.build()
.unwrap();
let value: serde_json::Value = serde_json::from_str(&complete).unwrap();
let expected_value = json!({
"forward": {
"channel": "channel-1",
"port": "different_port",
"receiver": "pfm",
"timeout": "10m",
"retries": 4,
"next": {
"forward": {
"channel": "channel-2",
"port": "different_port",
"receiver": "foo",
}
}
}
});
assert_eq!(value, expected_value);

let multimultihop = PacketForwardMiddlewareBuilder::new("receiver")
.hop("channel-1")
.hop("channel-2")
.hop("channel-3")
.build()
.unwrap();
let value: serde_json::Value = serde_json::from_str(&multimultihop).unwrap();
let expected_value = json!({
"forward": {
"channel": "channel-1",
"port": "transfer",
"receiver": "pfm",
"next": {
"forward": {
"channel": "channel-2",
"port": "transfer",
"receiver": "pfm",
"next": {
"forward": {
"channel": "channel-3",
"port": "transfer",
"receiver": "receiver",
}
}
}
}
}
});
assert_eq!(value, expected_value);
}

#[test]
fn memo_wasm_hook() {
let msg = json!({
"withdraw": {}
});

let minimal = IbcHooksBuilder::new("mock_addr".to_owned(), &msg)
.build()
.unwrap();
let value: serde_json::Value = serde_json::from_str(&minimal).unwrap();
let expected_value = json!({
"wasm": {
"contract": "mock_addr",
"msg": {"withdraw": {}}
}
});
assert_eq!(value, expected_value);

let complete = IbcHooksBuilder::new("mock_addr".to_owned(), &msg)
.callback_contract(Addr::unchecked("callback_addr"))
.build()
.unwrap();
let value: serde_json::Value = serde_json::from_str(&complete).unwrap();
let expected_value = json!({
"wasm": {
"contract": "mock_addr",
"msg": {"withdraw": {}},
},
"ibc_callback": "callback_addr"
});
assert_eq!(value, expected_value);
}
}
60 changes: 60 additions & 0 deletions framework/packages/abstract-sdk/src/apis/ibc_memo/hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
use std::collections::BTreeMap;

use cosmwasm_std::{from_json, to_json_binary, Addr, Binary};
use serde_cw_value::Value;

use super::IbcMemoBuilder;

/// Builder for [IbcHooks](https://github.com/cosmos/ibc-apps/tree/main/modules/ibc-hooks) memo field.
pub struct IbcHooksBuilder {
contract_addr: String,
msg: Binary,
ibc_callback: Option<Addr>,
}

impl IbcHooksBuilder {
/// New Wasm Contract Memo IBC Hook
/// Note: contract_addr should be the same as "receiver"
pub fn new(contract_addr: impl Into<String>, msg: &impl serde::Serialize) -> Self {
let msg = to_json_binary(&msg).unwrap();
Self {
contract_addr: contract_addr.into(),
msg,
ibc_callback: None,
}
}

/// Contract that will receive callback, see:
/// https://github.com/cosmos/ibc-apps/blob/main/modules/ibc-hooks/README.md#interface-for-receiving-the-acks-and-timeouts
pub fn callback_contract(mut self, callback_contract: Addr) -> Self {
self.ibc_callback = Some(callback_contract);
self
}
}

impl IbcMemoBuilder for IbcHooksBuilder {
fn build_value_map(self) -> BTreeMap<Value, Value> {
let execute_wasm_value = BTreeMap::from([
(
Value::String("contract".to_owned()),
Kayanski marked this conversation as resolved.
Show resolved Hide resolved
Value::String(self.contract_addr),
),
(
Value::String("msg".to_owned()),
from_json(&self.msg).expect("expected valid json message"),
),
]);

let mut memo = BTreeMap::from([(
Value::String("wasm".to_owned()),
Value::Map(execute_wasm_value.into_iter().collect()),
)]);
if let Some(contract_addr) = self.ibc_callback {
memo.insert(
Value::String("ibc_callback".to_owned()),
Value::String(contract_addr.into_string()),
);
}
memo
}
}
Loading