Skip to content

Commit

Permalink
Memo field apis (#412)
Browse files Browse the repository at this point in the history
Co-authored-by: cyberhoward <[email protected]>
Co-authored-by: CyberHoward <[email protected]>
  • Loading branch information
3 people authored Oct 25, 2024
1 parent 750adcf commit 744539f
Show file tree
Hide file tree
Showing 43 changed files with 1,645 additions and 137 deletions.
182 changes: 99 additions & 83 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 @@ -44,6 +44,7 @@ cw-asset = { version = "4.0" }
cw-ownable = { version = "2.0" }
cw-address-like = { version = "2.0" }
cw-clearable = { version = "0.2.0" }
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-xion.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_account.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_ica_client.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_module_factory.wasm
Binary file not shown.
Binary file modified framework/artifacts/abstract_registry.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 @@
04f4407f6bcd706a28327afb3bf5b2f16a18d75d0adc376ef44f8a4768d41877 abstract_account-xion.wasm
55124e42532e6cbfa306a8d85d3c8a634ec92d2803fe4dfeb8ed7918cd7e0e0c abstract_account.wasm
5f94f255722d33689eeb631bc796fbc1598985f8922d1987573644525dab4a1c abstract_ans_host.wasm
5e920677063397df022ce9ca9dd5e4f799c5ab7f601b7927cef013ca6be2486e abstract_ibc_client.wasm
3a14e2a3beeecc21d830367be33406dd2b5a33ab6733302b07fed0f3046f45dd abstract_ibc_host.wasm
9fb8a8e96e94977fd0b17265f1d4276484fe728ed943e3adcf9b4eca35ebf96a abstract_ica_client.wasm
11f769be8bf52d69c4af2d0ed539747ae359586740e3d05cb4ef20b1f8589422 abstract_module_factory.wasm
dea92cb8f17c18cb3b8ab64b832951d187f7c28747727811eecd640a096d7b35 abstract_registry.wasm
29611e9e921466d6b5848019abb4a27d7a2b385d02997bd8dd3ded25133b6570 abstract_account-xion.wasm
73a9ee61aa92f9203a513e9657d106ecfa8e01d93454126b0144d336294da8e3 abstract_account.wasm
c406ce2d7bc972ea6c320a9a366cf0d3717add9a7ffe63128c17be95a2e76f53 abstract_ans_host.wasm
2b22bd8dfa7529682e66a9304c241c15ff94cb1f83e3ce86ab39401eef3f7e69 abstract_ibc_client.wasm
582f99ce30af486b5b8891e402715947e9d1ef42981dee6ce742ef5e19d7691e abstract_ibc_host.wasm
2154914284863ad50c710dde01c754fb7bd713e203585c5115175161a6f1be5e abstract_ica_client.wasm
1348f236fd26251ddeef941d3c03a9b7fcb323e608b680ef2581734105bd7f29 abstract_module_factory.wasm
97ec7bfd1f89693c1826689153fb7661512e577be2dde6c4dbda38731197a136 abstract_registry.wasm
2 changes: 2 additions & 0 deletions framework/contracts/account/src/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,7 @@ mod test {
exec_msg: to_json_binary(&abstract_std::ibc_client::ExecuteMsg::SendFunds {
host_chain: "juno".parse()?,
memo: None,
receiver: None,
})?,
funds: funds.clone(),
};
Expand Down Expand Up @@ -386,6 +387,7 @@ mod test {
msg: to_json_binary(&abstract_std::ibc_client::ExecuteMsg::SendFunds {
host_chain: "juno".parse()?,
memo: None,
receiver: None,
})?,
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 @@ -371,6 +371,7 @@ pub fn execute_send_funds(
info: MessageInfo,
host_chain: TruncatedChainId,
memo: Option<String>,
receiver: Option<String>,
) -> IbcClientResult {
host_chain.verify()?;

Expand All @@ -380,13 +381,18 @@ pub fn execute_send_funds(

let account = registry.assert_account(&info.sender, &deps.querier)?;

// get account_id of Account
let account_id = account.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.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
12 changes: 9 additions & 3 deletions framework/contracts/native/ibc-client/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,12 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> I
ExecuteMsg::RegisterInfrastructure { chain, note, host } => {
commands::execute_register_infrastructure(deps, env, info, chain, host, note)
}
ExecuteMsg::SendFunds { host_chain, memo } => {
commands::execute_send_funds(deps, env, info, host_chain, memo).map_err(Into::into)
}
ExecuteMsg::SendFunds {
host_chain,
receiver,
memo,
} => commands::execute_send_funds(deps, env, info, host_chain, memo, receiver)
.map_err(Into::into),
ExecuteMsg::Register {
host_chain,
namespace,
Expand Down Expand Up @@ -637,6 +640,7 @@ mod tests {

let msg = ExecuteMsg::SendFunds {
host_chain: chain_name,
receiver: None,
memo: None,
};

Expand Down Expand Up @@ -678,6 +682,7 @@ mod tests {

let msg = ExecuteMsg::SendFunds {
host_chain: chain_name.clone(),
receiver: None,
memo: None,
};

Expand Down Expand Up @@ -711,6 +716,7 @@ mod tests {

let msg = ExecuteMsg::SendFunds {
host_chain: chain_name,
receiver: None,
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 }

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
workspace-hack = { version = "0.1", path = "../../../workspace-hack" }
Expand Down
3 changes: 2 additions & 1 deletion framework/docs/src/releases/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Added

- Abstract Account authentication when building account with `xion` feature.
- Added `PfmMemoBuilder` API for building middleware forwarding memo
- Added `HookMemoBuilder` API for building wasm ibc hook memo
- `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 @@ -429,6 +429,7 @@ impl<Chain: IbcQueryHandler, IBC: InterchainEnv<Chain>> RemoteAccount<Chain, IBC
ibc_client::ExecuteMsg::SendFunds {
host_chain: self.host_chain_id(),
memo,
receiver: None,
},
funds,
)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// This script is used for testing a connection between 2 chains
// This script sets up tokens and channels between transfer ports to transfer those tokens
// This also mints tokens to the chain sender for future interactions

use std::time::{Duration, SystemTime, UNIX_EPOCH};

use abstract_interchain_tests::{setup::set_starship_env, JUNO};
use abstract_interface::{connection::connect_one_way_to, Abstract};
use abstract_sdk::HookMemoBuilder;
use abstract_std::{
ans_host::ExecuteMsgFns,
objects::{TruncatedChainId, UncheckedChannelEntry},
ICS20, PROXY,
};
use anyhow::Result as AnyResult;
use cosmwasm_std::{coin, coins};
use counter_contract::CounterContract;
use cw_orch::{daemon::RUNTIME, prelude::*};
use cw_orch_interchain::prelude::*;
use cw_orch_proto::tokenfactory::{create_denom, get_denom, mint};

// Note: Truncated chain id have to be different
pub const JUNO2: &str = "junotwo-1";

pub fn test_pfm() -> AnyResult<()> {
dotenv::dotenv().ok();
set_starship_env();
env_logger::init();

let starship = Starship::new(None).unwrap();
let interchain = starship.interchain_env();

let juno = interchain.get_chain(JUNO).unwrap();
let juno2 = interchain.get_chain(JUNO2).unwrap();

// Create a channel between the 2 chains for the transfer ports
// JUNO>JUNO2
let juno_juno2_channel = interchain
.create_channel(
JUNO,
JUNO2,
&PortId::transfer(),
&PortId::transfer(),
"ics20-1",
Some(cosmwasm_std::IbcOrder::Unordered),
)?
.interchain_channel;

let abstr_juno = Abstract::deploy_on(juno.clone(), juno.sender_addr().to_string())?;
let abstr_juno2 = Abstract::deploy_on(juno2.clone(), juno2.sender_addr().to_string())?;
connect_one_way_to(&abstr_juno, &abstr_juno2, &interchain)?;

// Faster to load if deployed
// let abstr_juno = Abstract::load_from(juno.clone())?;
// let abstr_juno2 = Abstract::load_from(juno2.clone())?;

let counter_juno2 = init_counter(juno2.clone())?;

let sender = juno.sender_addr().to_string();

let test_amount: u128 = 100_000_000_000;
let token_subdenom = format!(
"testtoken{}",
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs()
);

// Create Denom
create_denom(&juno, token_subdenom.as_str())?;

// Mint Denom
mint(&juno, sender.as_str(), token_subdenom.as_str(), test_amount)?;

// Register this channel with the abstract ibc implementation for sending tokens
abstr_juno.ans_host.update_channels(
vec![(
UncheckedChannelEntry {
connected_chain: TruncatedChainId::from_chain_id(JUNO2).to_string(),
protocol: ICS20.to_string(),
},
juno_juno2_channel
.get_chain(JUNO)?
.channel
.unwrap()
.to_string(),
)],
vec![],
)?;

// Create a test account + Remote account

let origin_account = abstr_juno.account_factory.create_default_account(
abstract_client::GovernanceDetails::Monarchy {
monarch: juno.sender_addr().to_string(),
},
)?;
origin_account.manager.set_ibc_status(true)?;

// Send funds to the remote account
RUNTIME.block_on(juno.sender().bank_send(
&origin_account.proxy.address()?,
vec![coin(test_amount, get_denom(&juno, token_subdenom.as_str()))],
))?;

let memo = HookMemoBuilder::new(
counter_juno2.address()?,
&counter_contract::msg::ExecuteMsg::Increment {},
)
.build()?;
// We send from osmosis to juno funds with pfm memo that includes juno-stargaze channel
origin_account.manager.execute_on_module(
PROXY,
abstract_std::proxy::ExecuteMsg::IbcAction {
msg: abstract_std::ibc_client::ExecuteMsg::SendFunds {
host_chain: TruncatedChainId::from_chain_id(JUNO2),
funds: coins(10_000_000_000, get_denom(&juno, token_subdenom.as_str())),
memo: Some(memo.clone()),
receiver: Some(counter_juno2.addr_str()?),
},
},
)?;
origin_account.manager.execute_on_module(
PROXY,
abstract_std::proxy::ExecuteMsg::IbcAction {
msg: abstract_std::ibc_client::ExecuteMsg::SendFunds {
host_chain: TruncatedChainId::from_chain_id(JUNO2),
funds: coins(10_000_000_000, get_denom(&juno, token_subdenom.as_str())),
memo: Some(memo.clone()),
receiver: Some(counter_juno2.addr_str()?),
},
},
)?;
origin_account.manager.execute_on_module(
PROXY,
abstract_std::proxy::ExecuteMsg::IbcAction {
msg: abstract_std::ibc_client::ExecuteMsg::SendFunds {
host_chain: TruncatedChainId::from_chain_id(JUNO2),
funds: coins(10_000_000_000, get_denom(&juno, token_subdenom.as_str())),
memo: Some(memo),
receiver: Some(counter_juno2.addr_str()?),
},
},
)?;
log::info!("waiting for ibc_hook to finish tx");
std::thread::sleep(Duration::from_secs(15));

let count_juno2 = counter_juno2.query(&counter_contract::msg::QueryMsg::GetCount {})?;
log::info!("count juno2: {count_juno2:?}");

// Verify the funds have been received
let count_juno2_balance = juno2
.bank_querier()
.balance(&counter_juno2.address()?, None)?;

log::info!("count_juno2 balance, {:?}", count_juno2_balance);
Ok(())
}

pub fn init_counter<Chain: CwEnv>(chain: Chain) -> anyhow::Result<CounterContract<Chain>> {
let counter = CounterContract::new(chain);
counter.upload()?;
counter.instantiate(
&counter_contract::msg::InstantiateMsg { count: 0 },
None,
&[],
)?;
Ok(counter)
}

pub fn main() {
test_pfm().unwrap();
}
Loading

0 comments on commit 744539f

Please sign in to comment.