From 4554f420e4d07de069c46b39e9c216c58f7faafc Mon Sep 17 00:00:00 2001 From: Kayanski Date: Wed, 6 Mar 2024 14:47:55 +0000 Subject: [PATCH 1/4] Added verifiedsender to ibc-callback --- .../native/ibc-client/src/commands.rs | 25 +++++++++++-- .../native/ibc-client/src/contract.rs | 31 +++++++++++----- .../contracts/native/ibc-client/src/ibc.rs | 6 ++- .../packages/abstract-core/src/native/ibc.rs | 7 +++- .../abstract-core/src/native/ibc_client.rs | 37 +++++++++++-------- .../abstract-sdk/src/base/contract_base.rs | 4 +- .../src/base/endpoints/ibc_callback.rs | 3 +- 7 files changed, 78 insertions(+), 35 deletions(-) diff --git a/framework/contracts/native/ibc-client/src/commands.rs b/framework/contracts/native/ibc-client/src/commands.rs index b42d6ef402..0451b70636 100644 --- a/framework/contracts/native/ibc-client/src/commands.rs +++ b/framework/contracts/native/ibc-client/src/commands.rs @@ -6,8 +6,8 @@ use abstract_core::{ state::{IbcInfrastructure, IBC_INFRA, REVERSE_POLYTONE_NOTE}, IbcClientCallback, }, - ibc_host, manager, - manager::ModuleInstallConfig, + ibc_host, + manager::{self, ModuleInstallConfig}, objects::{chain_name::ChainName, AccountId, AssetEntry}, version_control::AccountBase, }; @@ -221,7 +221,11 @@ pub fn execute_send_packet( let callback_request = callback_info.map(|c| CallbackRequest { receiver: env.contract.address.to_string(), - msg: to_json_binary(&IbcClientCallback::UserRemoteAction(c)).unwrap(), + msg: to_json_binary(&IbcClientCallback::UserRemoteAction { + sender: account_id.clone(), + callback_info: c, + }) + .unwrap(), }); let note_message = send_remote_host_action( @@ -240,15 +244,28 @@ pub fn execute_send_packet( pub fn execute_send_query( deps: DepsMut, env: Env, + info: MessageInfo, host_chain: String, queries: Vec>, callback_info: CallbackInfo, ) -> IbcClientResult { let host_chain = ChainName::from_str(&host_chain)?; + let cfg = CONFIG.load(deps.storage)?; + + // Verify that the sender is a proxy contract + let account_base = cfg + .version_control + .assert_proxy(&info.sender, &deps.querier)?; + // get account_id + let account_id = account_base.account_id(deps.as_ref())?; let callback_request = CallbackRequest { receiver: env.contract.address.to_string(), - msg: to_json_binary(&IbcClientCallback::UserRemoteAction(callback_info)).unwrap(), + msg: to_json_binary(&IbcClientCallback::UserRemoteAction { + sender: account_id, + callback_info, + }) + .unwrap(), }; let note_message = diff --git a/framework/contracts/native/ibc-client/src/contract.rs b/framework/contracts/native/ibc-client/src/contract.rs index 3bfbcd7fb7..bdad8ee9b6 100644 --- a/framework/contracts/native/ibc-client/src/contract.rs +++ b/framework/contracts/native/ibc-client/src/contract.rs @@ -70,7 +70,7 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> I host_chain, queries, callback_info, - } => commands::execute_send_query(deps, env, host_chain, queries, callback_info), + } => commands::execute_send_query(deps, env, info, host_chain, queries, callback_info), ExecuteMsg::RegisterInfrastructure { chain, note, host } => { commands::execute_register_infrastructure(deps, env, info, chain, host, note) } @@ -462,7 +462,7 @@ mod tests { manager, objects::{ account::TEST_ACCOUNT_ID, chain_name::ChainName, - version_control::VersionControlError, + version_control::VersionControlError, AccountId, }, }; use abstract_testing::prelude::{ @@ -632,7 +632,10 @@ mod tests { }; let callback_request = CallbackRequest { - msg: to_json_binary(&IbcClientCallback::UserRemoteAction(callback_info.clone()))?, + msg: to_json_binary(&IbcClientCallback::UserRemoteAction { + callback_info: callback_info.clone(), + sender: AccountId::local(1), + })?, receiver: mock_env().contract.address.to_string(), }; @@ -675,7 +678,10 @@ mod tests { mod remote_query { use std::str::FromStr; - use abstract_core::{ibc::CallbackInfo, objects::chain_name::ChainName}; + use abstract_core::{ + ibc::CallbackInfo, + objects::{account::TEST_ACCOUNT_ID, chain_name::ChainName}, + }; use cosmwasm_std::{wasm_execute, BankQuery, Binary, QueryRequest}; use polytone::callbacks::CallbackRequest; @@ -709,7 +715,10 @@ mod tests { }; let callback_request = CallbackRequest { - msg: to_json_binary(&IbcClientCallback::UserRemoteAction(callback_info.clone()))?, + msg: to_json_binary(&IbcClientCallback::UserRemoteAction { + sender: TEST_ACCOUNT_ID, + callback_info: callback_info.clone(), + })?, receiver: mock_env().contract.address.to_string(), }; @@ -723,7 +732,7 @@ mod tests { callback_info, }; - let res = execute_as(deps.as_mut(), "sender", msg)?; + let res = execute_as(deps.as_mut(), TEST_PROXY, msg)?; let note_message = wasm_execute( note_contract.to_string(), @@ -1132,7 +1141,7 @@ mod tests { use abstract_core::{ ibc::{CallbackInfo, IbcResponseMsg}, - objects::{account::TEST_ACCOUNT_ID, chain_name::ChainName}, + objects::{account::TEST_ACCOUNT_ID, chain_name::ChainName, AccountId}, }; use cosmwasm_std::{from_json, Binary, Event, SubMsgResponse}; use polytone::callbacks::{Callback, CallbackMessage, ExecutionResponse}; @@ -1525,13 +1534,14 @@ mod tests { let receiver = String::from("receiver"); let callback_msg = CallbackMessage { initiator: env.contract.address, - initiator_msg: to_json_binary(&IbcClientCallback::UserRemoteAction( - CallbackInfo { + initiator_msg: to_json_binary(&IbcClientCallback::UserRemoteAction { + callback_info: CallbackInfo { id: id.clone(), msg: Some(callback_info_msg.clone()), receiver: receiver.clone(), }, - ))?, + sender: AccountId::local(1), + })?, result: Callback::Execute(Ok(ExecutionResponse { executed_by: remote_proxy.clone(), result: vec![], @@ -1548,6 +1558,7 @@ mod tests { id: id.clone(), msg: Some(callback_info_msg), result: callback_msg.result, + sender: AccountId::local(1) } .into_cosmos_msg(receiver)? ) diff --git a/framework/contracts/native/ibc-client/src/ibc.rs b/framework/contracts/native/ibc-client/src/ibc.rs index 4fac7b4999..9e742dc5c1 100644 --- a/framework/contracts/native/ibc-client/src/ibc.rs +++ b/framework/contracts/native/ibc-client/src/ibc.rs @@ -88,12 +88,16 @@ pub fn receive_action_callback( .add_attribute("chain", host_chain.to_string()), ) } - IbcClientCallback::UserRemoteAction(callback_info) => { + IbcClientCallback::UserRemoteAction { + sender, + callback_info, + } => { // Here we transfer the callback back to the module that requested it let callback = IbcResponseMsg { id: callback_info.id.clone(), msg: callback_info.msg, result: callback.result, + sender, }; Ok(IbcClientResponse::action("user_specific_callback") .add_message(callback.into_cosmos_msg(callback_info.receiver)?) diff --git a/framework/packages/abstract-core/src/native/ibc.rs b/framework/packages/abstract-core/src/native/ibc.rs index b740ecc4ed..85fc9b3bf2 100644 --- a/framework/packages/abstract-core/src/native/ibc.rs +++ b/framework/packages/abstract-core/src/native/ibc.rs @@ -2,6 +2,8 @@ use cosmwasm_std::{to_json_binary, wasm_execute, Binary, CosmosMsg, StdResult}; use polytone::callbacks::Callback; use schemars::JsonSchema; +use crate::objects::AccountId; + // CallbackInfo from modules, that is turned into an IbcResponseMsg by the ibc client #[cosmwasm_schema::cw_serde] pub struct CallbackInfo { @@ -22,6 +24,9 @@ pub struct IbcResponseMsg { /// The msg sent with the callback request. /// This is usually used to provide information to the ibc callback function for context pub msg: Option, + /// The account id of the sender of the original IBC message + /// This is verified by the ibc-client and can be trusted inside applications + pub sender: AccountId, pub result: Callback, } @@ -49,6 +54,6 @@ impl IbcResponseMsg { /// This is just a helper to properly serialize the above message. /// The actual receiver should include this variant in the larger ExecuteMsg enum #[cosmwasm_schema::cw_serde] -enum IbcCallbackMsg { +pub(crate) enum IbcCallbackMsg { IbcCallback(IbcResponseMsg), } diff --git a/framework/packages/abstract-core/src/native/ibc_client.rs b/framework/packages/abstract-core/src/native/ibc_client.rs index 88e5643ad9..45726cdada 100644 --- a/framework/packages/abstract-core/src/native/ibc_client.rs +++ b/framework/packages/abstract-core/src/native/ibc_client.rs @@ -132,8 +132,13 @@ pub enum ExecuteMsg { /// This enum is used for sending callbacks to the note contract of the IBC client #[cosmwasm_schema::cw_serde] pub enum IbcClientCallback { - UserRemoteAction(CallbackInfo), - CreateAccount { account_id: AccountId }, + UserRemoteAction { + sender: AccountId, + callback_info: CallbackInfo, + }, + CreateAccount { + account_id: AccountId, + }, WhoAmI {}, } @@ -243,8 +248,9 @@ mod tests { use polytone::callbacks::Callback; use speculoos::prelude::*; + use crate::ibc::IbcCallbackMsg; use crate::ibc::IbcResponseMsg; - + use crate::objects::AccountId; // ... (other test functions) #[test] @@ -259,20 +265,19 @@ mod tests { id: callback_id, msg: Some(callback_msg), result, + sender: AccountId::local(1), }; - let actual: CosmosMsg = response_msg.into_cosmos_msg(receiver.clone()).unwrap(); - - assert_that!(actual).matches(|e| { - matches!( - e, - CosmosMsg::Wasm(cosmwasm_std::WasmMsg::Execute { - contract_addr: _receiver, - // we can't test the message because the fields in it are private - msg: _, - funds: _ - }) - ) - }); + let actual: CosmosMsg = response_msg + .clone() + .into_cosmos_msg(receiver.clone()) + .unwrap(); + + assert_that!(actual).is_equal_to(CosmosMsg::Wasm(cosmwasm_std::WasmMsg::Execute { + contract_addr: receiver, + // we can't test the message because the fields in it are private + msg: to_json_binary(&IbcCallbackMsg::IbcCallback(response_msg)).unwrap(), + funds: vec![], + })) } } diff --git a/framework/packages/abstract-sdk/src/base/contract_base.rs b/framework/packages/abstract-sdk/src/base/contract_base.rs index c7565fb07f..1df6a827ec 100644 --- a/framework/packages/abstract-sdk/src/base/contract_base.rs +++ b/framework/packages/abstract-sdk/src/base/contract_base.rs @@ -1,3 +1,4 @@ +use abstract_core::objects::AccountId; use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, Storage}; use cw2::{ContractVersion, CONTRACT}; use cw_storage_plus::Item; @@ -29,7 +30,6 @@ pub type QueryHandlerFn = fn(Deps, Env, &Module, CustomQueryMsg) -> Result; // ANCHOR_END: query -type CallbackId = String; type CallbackMessage = Option; // ANCHOR: ibc /// Function signature for an IBC callback handler. @@ -38,7 +38,7 @@ pub type IbcCallbackHandlerFn = fn( Env, MessageInfo, Module, - CallbackId, + AccountId, CallbackMessage, Callback, ) -> Result; diff --git a/framework/packages/abstract-sdk/src/base/endpoints/ibc_callback.rs b/framework/packages/abstract-sdk/src/base/endpoints/ibc_callback.rs index f4a50cd77c..cdf3248c91 100644 --- a/framework/packages/abstract-sdk/src/base/endpoints/ibc_callback.rs +++ b/framework/packages/abstract-sdk/src/base/endpoints/ibc_callback.rs @@ -29,11 +29,12 @@ pub trait IbcCallbackEndpoint: Handler { id, msg: callback_msg, result, + sender, } = msg; let maybe_handler = self.maybe_ibc_callback_handler(&id); maybe_handler.map_or_else( || Ok(Response::new()), - |handler| handler(deps, env, info, self, id, callback_msg, result), + |handler| handler(deps, env, info, self, sender, callback_msg, result), ) } } From 883a09a203d83d6767e82c48049ac51dc2a1f232 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Thu, 7 Mar 2024 08:46:11 +0000 Subject: [PATCH 2/4] Added test --- framework/packages/abstract-app/src/lib.rs | 19 ++- interchain/tests/src/interchain_accounts.rs | 137 ++++++++++++++++++++ 2 files changed, 153 insertions(+), 3 deletions(-) diff --git a/framework/packages/abstract-app/src/lib.rs b/framework/packages/abstract-app/src/lib.rs index 9187de57c7..7fa6996a50 100644 --- a/framework/packages/abstract-app/src/lib.rs +++ b/framework/packages/abstract-app/src/lib.rs @@ -33,7 +33,7 @@ pub mod mock { pub use abstract_core::app; use abstract_core::{ manager::ModuleInstallConfig, - objects::{dependency::StaticDependency, module::ModuleInfo}, + objects::{dependency::StaticDependency, module::ModuleInfo, AccountId}, }; use abstract_interface::{AppDeployer, DependencyCreation}; use cosmwasm_schema::QueryResponses; @@ -41,7 +41,7 @@ pub mod mock { use cosmwasm_std::{to_json_binary, Response, StdError}; use cw_controllers::AdminError; use cw_orch::prelude::*; - use cw_storage_plus::Item; + use cw_storage_plus::{Item, Map}; pub type AppTestResult = Result<(), MockError>; @@ -68,6 +68,9 @@ pub mod mock { #[returns(ReceivedIbcCallbackStatus)] GetReceivedIbcCallbackStatus {}, + + #[returns(ReceivedIbcCallbackStatus)] + GetReceivedIbcCallbackSenderStatus { sender: AccountId }, } #[cosmwasm_schema::cw_serde] @@ -134,6 +137,7 @@ pub mod mock { // Easy way to see if an ibc-callback was actually received. pub const IBC_CALLBACK_RECEIVED: Item = Item::new("ibc_callback_received"); + pub const IBC_CALLBACK_SENDER: Map = Map::new("ibc_callback_sender"); pub const MOCK_APP_WITH_DEP: MockAppContract = MockAppContract::new(TEST_WITH_DEP_MODULE_ID, TEST_VERSION, None) @@ -152,11 +156,20 @@ pub mod mock { }) .map_err(Into::into) } + MockQueryMsg::GetReceivedIbcCallbackSenderStatus { sender } => { + to_json_binary(&ReceivedIbcCallbackStatus { + received: IBC_CALLBACK_SENDER.load(deps.storage, sender)?, + }) + .map_err(Into::into) + } }) .with_sudo(|_, _, _, _| Ok(Response::new().set_data("mock_sudo".as_bytes()))) .with_receive(|_, _, _, _, _| Ok(Response::new().set_data("mock_receive".as_bytes()))) - .with_ibc_callbacks(&[("c_id", |deps, _, _, _, _, _, _| { + .with_ibc_callbacks(&[("c_id", |deps, _, _, _, sender, _, _| { IBC_CALLBACK_RECEIVED.save(deps.storage, &true).unwrap(); + IBC_CALLBACK_SENDER + .save(deps.storage, sender, &true) + .unwrap(); Ok(Response::new().add_attribute("mock_callback", "executed")) })]) .with_dependencies(&[StaticDependency::new(TEST_MODULE_ID, &[TEST_VERSION])]) diff --git a/interchain/tests/src/interchain_accounts.rs b/interchain/tests/src/interchain_accounts.rs index 64e032d983..7b8b9b6095 100644 --- a/interchain/tests/src/interchain_accounts.rs +++ b/interchain/tests/src/interchain_accounts.rs @@ -278,6 +278,129 @@ mod test { Ok(()) } + #[test] + fn anyone_can_call_account_ibc_app_callback() -> AnyResult<()> { + logger_test_init(); + let mock_interchain = + MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]); + + // We just verified all steps pass + let (abstr_origin, _abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?; + + let remote_name = ChainName::from_chain_id(STARGAZE).to_string(); + + let (origin_account, _remote_account_id) = + create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?; + + let app = MockAppWithDepI::new( + TEST_WITH_DEP_MODULE_ID, + abstr_origin.version_control.get_chain().clone(), + ); + + let app_dep = MockAppI::new( + TEST_MODULE_ID, + abstr_origin.version_control.get_chain().clone(), + ); + + let app_account = + abstr_origin + .account_factory + .create_default_account(GovernanceDetails::Monarchy { + monarch: abstr_origin + .version_control + .get_chain() + .sender() + .into_string(), + })?; + + let app_deps_account = + abstr_origin + .account_factory + .create_default_account(GovernanceDetails::Monarchy { + monarch: abstr_origin + .version_control + .get_chain() + .sender() + .into_string(), + })?; + + abstr_origin.version_control.claim_namespace( + app_account.manager.config()?.account_id, + TEST_WITH_DEP_NAMESPACE.to_owned(), + )?; + abstr_origin.version_control.claim_namespace( + app_deps_account.manager.config()?.account_id, + TEST_NAMESPACE.to_owned(), + )?; + + app.deploy(TEST_VERSION.parse()?, DeployStrategy::Try)?; + app_dep.deploy(TEST_VERSION.parse()?, DeployStrategy::Try)?; + + origin_account.install_app(&app_dep, &MockInitMsg {}, None)?; + origin_account.install_app(&app, &MockInitMsg {}, None)?; + let res: ModuleAddressesResponse = origin_account + .manager + .module_addresses(vec![TEST_WITH_DEP_MODULE_ID.to_owned()])?; + + assert_eq!(1, res.modules.len()); + + let module_address = res.modules[0].1.to_string(); + + let new_name = "Funky Crazy Name"; + let new_description = "Funky new account with wonderful capabilities"; + let new_link = "https://abstract.money"; + + // The user on origin chain wants to change the account description + let ibc_action_result = origin_account.manager.execute_on_remote( + &remote_name, + ManagerExecuteMsg::UpdateInfo { + name: Some(new_name.to_string()), + description: Some(new_description.to_string()), + link: Some(new_link.to_string()), + }, + Some(CallbackInfo { + id: String::from("c_id"), + msg: None, + receiver: module_address.clone(), + }), + )?; + + assert_callback_status(&app, false)?; + assert_callback_sender(&app, origin_account.id()?, false)?; + + mock_interchain.wait_ibc(JUNO, ibc_action_result)?; + + // Switched to true by the callback. + assert_callback_status(&app, true)?; + assert_callback_sender(&app, origin_account.id()?, true)?; + + // A new account sends an action with a callback on another account user on origin chain wants to change the account description + let (new_account, _) = + create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?; + let ibc_action_result = new_account.manager.execute_on_remote( + &remote_name, + ManagerExecuteMsg::UpdateInfo { + name: Some(new_name.to_string()), + description: Some(new_description.to_string()), + link: Some(new_link.to_string()), + }, + Some(CallbackInfo { + id: String::from("c_id"), + msg: None, + receiver: module_address, + }), + )?; + + assert_callback_sender(&app, new_account.id()?, false)?; + + mock_interchain.wait_ibc(JUNO, ibc_action_result)?; + + // Switched to true by the callback. + assert_callback_sender(&app, new_account.id()?, true)?; + + Ok(()) + } + #[test] fn ibc_adapter_callback() -> AnyResult<()> { logger_test_init(); @@ -368,6 +491,20 @@ mod test { Ok(()) } + fn assert_callback_sender( + app: &MockAppWithDepI, + account_id: AccountId, + status: bool, + ) -> AnyResult<()> { + let get_received_ibc_callback_status_res = app + .get_received_ibc_callback_sender_status(account_id) + .map(|r| r.received) + .unwrap_or(false); + + assert_eq!(status, get_received_ibc_callback_status_res); + Ok(()) + } + fn assert_adapter_callback_status( app: &MockAdapterI, status: bool, From 46d2920503afd468a30dcf910ff01f78ea3755b8 Mon Sep 17 00:00:00 2001 From: Kayanski Date: Mon, 11 Mar 2024 10:42:10 +0000 Subject: [PATCH 3/4] Removed user initiated callbacks --- .../native/ibc-client/src/commands.rs | 74 +--- .../native/ibc-client/src/contract.rs | 234 +----------- .../contracts/native/ibc-client/src/ibc.rs | 17 - .../packages/abstract-adapter/src/lib.rs | 2 +- .../packages/abstract-adapter/src/state.rs | 2 +- framework/packages/abstract-app/src/lib.rs | 20 +- framework/packages/abstract-app/src/state.rs | 2 +- .../packages/abstract-core/src/native/ibc.rs | 5 - .../abstract-core/src/native/ibc_client.rs | 29 +- .../abstract-interface/src/account/manager.rs | 7 - .../packages/abstract-sdk/src/apis/ibc.rs | 58 +-- .../abstract-sdk/src/base/contract_base.rs | 14 +- .../src/base/endpoints/ibc_callback.rs | 3 +- interchain/tests/src/interchain_accounts.rs | 356 +----------------- .../cw-staking/src/handlers/execute.rs | 4 +- .../adapters/dex/src/handlers/execute.rs | 4 +- 16 files changed, 30 insertions(+), 801 deletions(-) diff --git a/framework/contracts/native/ibc-client/src/commands.rs b/framework/contracts/native/ibc-client/src/commands.rs index 0451b70636..82297f7d33 100644 --- a/framework/contracts/native/ibc-client/src/commands.rs +++ b/framework/contracts/native/ibc-client/src/commands.rs @@ -1,7 +1,6 @@ use std::str::FromStr; use abstract_core::{ - ibc::CallbackInfo, ibc_client::{ state::{IbcInfrastructure, IBC_INFRA, REVERSE_POLYTONE_NOTE}, IbcClientCallback, @@ -23,7 +22,7 @@ use abstract_sdk::{ }; use cosmwasm_std::{ to_json_binary, wasm_execute, Coin, CosmosMsg, Deps, DepsMut, Empty, Env, IbcMsg, MessageInfo, - QueryRequest, Storage, + Storage, }; use polytone::callbacks::CallbackRequest; @@ -169,38 +168,14 @@ fn send_remote_host_action( Ok(note_message.into()) } -/// Perform a ICQ on a remote chain -fn send_remote_host_query( - deps: Deps, - host_chain: ChainName, - queries: Vec>, - callback_request: CallbackRequest, -) -> IbcClientResult> { - // Send this message via the Polytone infra - let note_contract = IBC_INFRA.load(deps.storage, &host_chain)?.polytone_note; - - let note_message = wasm_execute( - note_contract.to_string(), - &polytone_note::msg::ExecuteMsg::Query { - msgs: queries, - callback: callback_request, - timeout_seconds: PACKET_LIFETIME.into(), - }, - vec![], - )?; - - Ok(note_message.into()) -} - /// Sends a packet with an optional callback. /// This is the top-level function to do IBC related actions. pub fn execute_send_packet( deps: DepsMut, - env: Env, + _env: Env, info: MessageInfo, host_chain: String, action: HostAction, - callback_info: Option, ) -> IbcClientResult { let host_chain = ChainName::from_str(&host_chain)?; @@ -219,61 +194,18 @@ pub fn execute_send_packet( return Err(IbcClientError::ForbiddenInternalCall {}); } - let callback_request = callback_info.map(|c| CallbackRequest { - receiver: env.contract.address.to_string(), - msg: to_json_binary(&IbcClientCallback::UserRemoteAction { - sender: account_id.clone(), - callback_info: c, - }) - .unwrap(), - }); - let note_message = send_remote_host_action( deps.as_ref(), account_id, account_base, host_chain, action, - callback_request, + None, )?; Ok(IbcClientResponse::action("handle_send_msgs").add_message(note_message)) } -// Top-level function for performing queries. -pub fn execute_send_query( - deps: DepsMut, - env: Env, - info: MessageInfo, - host_chain: String, - queries: Vec>, - callback_info: CallbackInfo, -) -> IbcClientResult { - let host_chain = ChainName::from_str(&host_chain)?; - let cfg = CONFIG.load(deps.storage)?; - - // Verify that the sender is a proxy contract - let account_base = cfg - .version_control - .assert_proxy(&info.sender, &deps.querier)?; - // get account_id - let account_id = account_base.account_id(deps.as_ref())?; - - let callback_request = CallbackRequest { - receiver: env.contract.address.to_string(), - msg: to_json_binary(&IbcClientCallback::UserRemoteAction { - sender: account_id, - callback_info, - }) - .unwrap(), - }; - - let note_message = - send_remote_host_query(deps.as_ref(), host_chain, queries, callback_request)?; - - Ok(IbcClientResponse::action("handle_send_msgs").add_message(note_message)) -} - /// Registers an Abstract Account on a remote chain. pub fn execute_register_account( deps: DepsMut, diff --git a/framework/contracts/native/ibc-client/src/contract.rs b/framework/contracts/native/ibc-client/src/contract.rs index bdad8ee9b6..8b170aec76 100644 --- a/framework/contracts/native/ibc-client/src/contract.rs +++ b/framework/contracts/native/ibc-client/src/contract.rs @@ -61,16 +61,9 @@ pub fn execute(deps: DepsMut, env: Env, info: MessageInfo, msg: ExecuteMsg) -> I version_control, } => commands::execute_update_config(deps, info, ans_host, version_control) .map_err(Into::into), - ExecuteMsg::RemoteAction { - host_chain, - action, - callback_info, - } => commands::execute_send_packet(deps, env, info, host_chain, action, callback_info), - ExecuteMsg::RemoteQueries { - host_chain, - queries, - callback_info, - } => commands::execute_send_query(deps, env, info, host_chain, queries, callback_info), + ExecuteMsg::RemoteAction { host_chain, action } => { + commands::execute_send_packet(deps, env, info, host_chain, action) + } ExecuteMsg::RegisterInfrastructure { chain, note, host } => { commands::execute_register_infrastructure(deps, env, info, chain, host, note) } @@ -457,19 +450,17 @@ mod tests { use std::str::FromStr; use abstract_core::{ - ibc::CallbackInfo, ibc_host::{self, HostAction, InternalAction}, manager, objects::{ account::TEST_ACCOUNT_ID, chain_name::ChainName, - version_control::VersionControlError, AccountId, + version_control::VersionControlError, }, }; use abstract_testing::prelude::{ mocked_account_querier_builder, TEST_CHAIN, TEST_MANAGER, TEST_PROXY, }; - use cosmwasm_std::{wasm_execute, Binary}; - use polytone::callbacks::CallbackRequest; + use cosmwasm_std::wasm_execute; use super::*; use crate::commands::PACKET_LIFETIME; @@ -491,7 +482,6 @@ mod tests { link: None, }, }, - callback_info: None, }; let res = execute_as(deps.as_mut(), TEST_MANAGER, msg); @@ -523,7 +513,6 @@ mod tests { namespace: None, install_modules: vec![], }), - callback_info: None, }; let res = execute_as(deps.as_mut(), TEST_PROXY, msg); @@ -565,7 +554,6 @@ mod tests { let msg = ExecuteMsg::RemoteAction { host_chain: chain_name.to_string(), action: action.clone(), - callback_info: None, }; let res = execute_as(deps.as_mut(), TEST_PROXY, msg)?; @@ -596,161 +584,6 @@ mod tests { ); Ok(()) } - - #[test] - fn send_packet_with_callback() -> IbcClientTestResult { - let mut deps = mock_dependencies(); - deps.querier = mocked_account_querier_builder().build(); - mock_init(deps.as_mut())?; - - let chain_name = ChainName::from_str(TEST_CHAIN)?; - let note_contract = Addr::unchecked("note"); - let remote_ibc_host = String::from("test_remote_host"); - - IBC_INFRA.save( - deps.as_mut().storage, - &chain_name, - &IbcInfrastructure { - polytone_note: note_contract.clone(), - remote_abstract_host: remote_ibc_host.clone(), - remote_proxy: None, - }, - )?; - - let action = HostAction::Dispatch { - manager_msg: manager::ExecuteMsg::UpdateInfo { - name: None, - description: None, - link: None, - }, - }; - - let callback_info = CallbackInfo { - id: String::from("id"), - receiver: String::from("receiver"), - msg: Some(Binary(vec![])), - }; - - let callback_request = CallbackRequest { - msg: to_json_binary(&IbcClientCallback::UserRemoteAction { - callback_info: callback_info.clone(), - sender: AccountId::local(1), - })?, - receiver: mock_env().contract.address.to_string(), - }; - - let msg = ExecuteMsg::RemoteAction { - host_chain: chain_name.to_string(), - action: action.clone(), - callback_info: Some(callback_info), - }; - - let res = execute_as(deps.as_mut(), TEST_PROXY, msg)?; - - let note_message = wasm_execute( - note_contract.to_string(), - &polytone_note::msg::ExecuteMsg::Execute { - msgs: vec![wasm_execute( - // The note's remote proxy will call the ibc host - remote_ibc_host, - &ibc_host::ExecuteMsg::Execute { - proxy_address: TEST_PROXY.to_owned(), - account_id: TEST_ACCOUNT_ID, - action, - }, - vec![], - )? - .into()], - callback: Some(callback_request), - timeout_seconds: PACKET_LIFETIME.into(), - }, - vec![], - )?; - - assert_eq!( - IbcClientResponse::action("handle_send_msgs").add_message(note_message), - res - ); - Ok(()) - } - } - - mod remote_query { - use std::str::FromStr; - - use abstract_core::{ - ibc::CallbackInfo, - objects::{account::TEST_ACCOUNT_ID, chain_name::ChainName}, - }; - use cosmwasm_std::{wasm_execute, BankQuery, Binary, QueryRequest}; - use polytone::callbacks::CallbackRequest; - - use super::*; - use crate::commands::PACKET_LIFETIME; - - #[test] - fn works() -> IbcClientTestResult { - let mut deps = mock_dependencies(); - deps.querier = mocked_account_querier_builder().build(); - mock_init(deps.as_mut())?; - - let chain_name = ChainName::from_str(TEST_CHAIN)?; - let note_contract = Addr::unchecked("note"); - let remote_ibc_host = String::from("test_remote_host"); - - IBC_INFRA.save( - deps.as_mut().storage, - &chain_name, - &IbcInfrastructure { - polytone_note: note_contract.clone(), - remote_abstract_host: remote_ibc_host.clone(), - remote_proxy: None, - }, - )?; - - let callback_info = CallbackInfo { - id: String::from("id"), - receiver: String::from("receiver"), - msg: Some(Binary(vec![])), - }; - - let callback_request = CallbackRequest { - msg: to_json_binary(&IbcClientCallback::UserRemoteAction { - sender: TEST_ACCOUNT_ID, - callback_info: callback_info.clone(), - })?, - receiver: mock_env().contract.address.to_string(), - }; - - let queries = vec![QueryRequest::Bank(BankQuery::AllBalances { - address: String::from("addr"), - })]; - - let msg = ExecuteMsg::RemoteQueries { - host_chain: chain_name.to_string(), - queries: queries.clone(), - callback_info, - }; - - let res = execute_as(deps.as_mut(), TEST_PROXY, msg)?; - - let note_message = wasm_execute( - note_contract.to_string(), - &polytone_note::msg::ExecuteMsg::Query { - msgs: queries, - callback: callback_request, - timeout_seconds: PACKET_LIFETIME.into(), - }, - vec![], - )?; - - assert_eq!( - IbcClientResponse::action("handle_send_msgs").add_message(note_message), - res - ); - - Ok(()) - } } mod send_funds { @@ -1139,10 +972,7 @@ mod tests { mod callback { use std::str::FromStr; - use abstract_core::{ - ibc::{CallbackInfo, IbcResponseMsg}, - objects::{account::TEST_ACCOUNT_ID, chain_name::ChainName, AccountId}, - }; + use abstract_core::objects::{account::TEST_ACCOUNT_ID, chain_name::ChainName}; use cosmwasm_std::{from_json, Binary, Event, SubMsgResponse}; use polytone::callbacks::{Callback, CallbackMessage, ExecutionResponse}; @@ -1517,58 +1347,6 @@ mod tests { Ok(()) } - - #[test] - fn user_remote_action() -> IbcClientTestResult { - let mut deps = mock_dependencies(); - mock_init(deps.as_mut())?; - let env = mock_env(); - - let chain_name = ChainName::from_str(TEST_CHAIN)?; - let note = Addr::unchecked("note"); - let remote_proxy = String::from("remote_proxy"); - - REVERSE_POLYTONE_NOTE.save(deps.as_mut().storage, ¬e, &chain_name)?; - let id = String::from("id"); - let callback_info_msg = Binary(vec![]); - let receiver = String::from("receiver"); - let callback_msg = CallbackMessage { - initiator: env.contract.address, - initiator_msg: to_json_binary(&IbcClientCallback::UserRemoteAction { - callback_info: CallbackInfo { - id: id.clone(), - msg: Some(callback_info_msg.clone()), - receiver: receiver.clone(), - }, - sender: AccountId::local(1), - })?, - result: Callback::Execute(Ok(ExecutionResponse { - executed_by: remote_proxy.clone(), - result: vec![], - })), - }; - let msg = ExecuteMsg::Callback(callback_msg.clone()); - - let res = execute_as(deps.as_mut(), note.as_ref(), msg)?; - - assert_eq!( - IbcClientResponse::action("user_specific_callback") - .add_message( - IbcResponseMsg { - id: id.clone(), - msg: Some(callback_info_msg), - result: callback_msg.result, - sender: AccountId::local(1) - } - .into_cosmos_msg(receiver)? - ) - .add_attribute("chain", chain_name.to_string()) - .add_attribute("callback_id", id), - res - ); - - Ok(()) - } } mod list_proxies_by_account_id { use std::str::FromStr; diff --git a/framework/contracts/native/ibc-client/src/ibc.rs b/framework/contracts/native/ibc-client/src/ibc.rs index 9e742dc5c1..014f0576d5 100644 --- a/framework/contracts/native/ibc-client/src/ibc.rs +++ b/framework/contracts/native/ibc-client/src/ibc.rs @@ -1,5 +1,4 @@ use abstract_core::{ - ibc::IbcResponseMsg, ibc_client::{ state::{IBC_INFRA, REVERSE_POLYTONE_NOTE}, IbcClientCallback, @@ -88,21 +87,5 @@ pub fn receive_action_callback( .add_attribute("chain", host_chain.to_string()), ) } - IbcClientCallback::UserRemoteAction { - sender, - callback_info, - } => { - // Here we transfer the callback back to the module that requested it - let callback = IbcResponseMsg { - id: callback_info.id.clone(), - msg: callback_info.msg, - result: callback.result, - sender, - }; - Ok(IbcClientResponse::action("user_specific_callback") - .add_message(callback.into_cosmos_msg(callback_info.receiver)?) - .add_attribute("chain", host_chain.to_string()) - .add_attribute("callback_id", callback_info.id)) - } } } diff --git a/framework/packages/abstract-adapter/src/lib.rs b/framework/packages/abstract-adapter/src/lib.rs index aa33191167..b3f51aadc3 100644 --- a/framework/packages/abstract-adapter/src/lib.rs +++ b/framework/packages/abstract-adapter/src/lib.rs @@ -124,7 +124,7 @@ pub mod mock { }) .with_sudo(|_, _, _, _| Ok(Response::new().set_data("mock_sudo".as_bytes()))) .with_receive(|_, _, _, _, _| Ok(Response::new().set_data("mock_receive".as_bytes()))) - .with_ibc_callbacks(&[("c_id", |deps, _, _, _, _, _, _| { + .with_ibc_callbacks(&[("c_id", |deps, _, _, _, _, _| { IBC_CALLBACK_RECEIVED.save(deps.storage, &true).unwrap(); Ok(Response::new().set_data("mock_callback".as_bytes())) })]) diff --git a/framework/packages/abstract-adapter/src/state.rs b/framework/packages/abstract-adapter/src/state.rs index e9400f231d..40e1379ca9 100644 --- a/framework/packages/abstract-adapter/src/state.rs +++ b/framework/packages/abstract-adapter/src/state.rs @@ -183,7 +183,7 @@ mod tests { .with_query(|_, _, _, _| cosmwasm_std::to_json_binary("mock_query").map_err(Into::into)) .with_sudo(|_, _, _, _| Ok(Response::new().set_data("mock_sudo".as_bytes()))) .with_receive(|_, _, _, _, _| Ok(Response::new().set_data("mock_receive".as_bytes()))) - .with_ibc_callbacks(&[("c_id", |_, _, _, _, _, _, _| { + .with_ibc_callbacks(&[("c_id", |_, _, _, _, _, _| { Ok(Response::new().set_data("mock_callback".as_bytes())) })]) .with_replies(&[(1u64, |_, _, _, msg| { diff --git a/framework/packages/abstract-app/src/lib.rs b/framework/packages/abstract-app/src/lib.rs index 7fa6996a50..30f1d46bf8 100644 --- a/framework/packages/abstract-app/src/lib.rs +++ b/framework/packages/abstract-app/src/lib.rs @@ -33,7 +33,7 @@ pub mod mock { pub use abstract_core::app; use abstract_core::{ manager::ModuleInstallConfig, - objects::{dependency::StaticDependency, module::ModuleInfo, AccountId}, + objects::{dependency::StaticDependency, module::ModuleInfo}, }; use abstract_interface::{AppDeployer, DependencyCreation}; use cosmwasm_schema::QueryResponses; @@ -41,7 +41,7 @@ pub mod mock { use cosmwasm_std::{to_json_binary, Response, StdError}; use cw_controllers::AdminError; use cw_orch::prelude::*; - use cw_storage_plus::{Item, Map}; + use cw_storage_plus::Item; pub type AppTestResult = Result<(), MockError>; @@ -68,9 +68,6 @@ pub mod mock { #[returns(ReceivedIbcCallbackStatus)] GetReceivedIbcCallbackStatus {}, - - #[returns(ReceivedIbcCallbackStatus)] - GetReceivedIbcCallbackSenderStatus { sender: AccountId }, } #[cosmwasm_schema::cw_serde] @@ -137,7 +134,6 @@ pub mod mock { // Easy way to see if an ibc-callback was actually received. pub const IBC_CALLBACK_RECEIVED: Item = Item::new("ibc_callback_received"); - pub const IBC_CALLBACK_SENDER: Map = Map::new("ibc_callback_sender"); pub const MOCK_APP_WITH_DEP: MockAppContract = MockAppContract::new(TEST_WITH_DEP_MODULE_ID, TEST_VERSION, None) @@ -156,20 +152,12 @@ pub mod mock { }) .map_err(Into::into) } - MockQueryMsg::GetReceivedIbcCallbackSenderStatus { sender } => { - to_json_binary(&ReceivedIbcCallbackStatus { - received: IBC_CALLBACK_SENDER.load(deps.storage, sender)?, - }) - .map_err(Into::into) - } }) .with_sudo(|_, _, _, _| Ok(Response::new().set_data("mock_sudo".as_bytes()))) .with_receive(|_, _, _, _, _| Ok(Response::new().set_data("mock_receive".as_bytes()))) - .with_ibc_callbacks(&[("c_id", |deps, _, _, _, sender, _, _| { + .with_ibc_callbacks(&[("c_id", |deps, _, _, _, _, _| { IBC_CALLBACK_RECEIVED.save(deps.storage, &true).unwrap(); - IBC_CALLBACK_SENDER - .save(deps.storage, sender, &true) - .unwrap(); + Ok(Response::new().add_attribute("mock_callback", "executed")) })]) .with_dependencies(&[StaticDependency::new(TEST_MODULE_ID, &[TEST_VERSION])]) diff --git a/framework/packages/abstract-app/src/state.rs b/framework/packages/abstract-app/src/state.rs index 1b85431a9d..e0651a835a 100644 --- a/framework/packages/abstract-app/src/state.rs +++ b/framework/packages/abstract-app/src/state.rs @@ -193,7 +193,7 @@ mod tests { .with_query(|_, _, _, _| cosmwasm_std::to_json_binary("mock_query").map_err(Into::into)) .with_sudo(|_, _, _, _| Ok(Response::new().set_data("mock_sudo".as_bytes()))) .with_receive(|_, _, _, _, _| Ok(Response::new().set_data("mock_receive".as_bytes()))) - .with_ibc_callbacks(&[("c_id", |_, _, _, _, _, _, _| { + .with_ibc_callbacks(&[("c_id", |_, _, _, _, _, _| { Ok(Response::new().set_data("mock_callback".as_bytes())) })]) .with_replies(&[(1u64, |_, _, _, msg| { diff --git a/framework/packages/abstract-core/src/native/ibc.rs b/framework/packages/abstract-core/src/native/ibc.rs index 85fc9b3bf2..65b62bf881 100644 --- a/framework/packages/abstract-core/src/native/ibc.rs +++ b/framework/packages/abstract-core/src/native/ibc.rs @@ -2,8 +2,6 @@ use cosmwasm_std::{to_json_binary, wasm_execute, Binary, CosmosMsg, StdResult}; use polytone::callbacks::Callback; use schemars::JsonSchema; -use crate::objects::AccountId; - // CallbackInfo from modules, that is turned into an IbcResponseMsg by the ibc client #[cosmwasm_schema::cw_serde] pub struct CallbackInfo { @@ -24,9 +22,6 @@ pub struct IbcResponseMsg { /// The msg sent with the callback request. /// This is usually used to provide information to the ibc callback function for context pub msg: Option, - /// The account id of the sender of the original IBC message - /// This is verified by the ibc-client and can be trusted inside applications - pub sender: AccountId, pub result: Callback, } diff --git a/framework/packages/abstract-core/src/native/ibc_client.rs b/framework/packages/abstract-core/src/native/ibc_client.rs index 45726cdada..150ece3b1c 100644 --- a/framework/packages/abstract-core/src/native/ibc_client.rs +++ b/framework/packages/abstract-core/src/native/ibc_client.rs @@ -1,10 +1,9 @@ use cosmwasm_schema::QueryResponses; -use cosmwasm_std::{Addr, Coin, Empty, QueryRequest}; +use cosmwasm_std::{Addr, Coin}; use polytone::callbacks::CallbackMessage; use self::state::IbcInfrastructure; use crate::{ - ibc::CallbackInfo, ibc_host::HostAction, manager::ModuleInstallConfig, objects::{account::AccountId, chain_name::ChainName, AssetEntry}, @@ -106,39 +105,19 @@ pub enum ExecuteMsg { host_chain: String, // execute the custom host function action: HostAction, - // optional callback info - callback_info: Option, - }, - /// Allows to query something on a remote contract and act on that query result - /// This has to be an Execute variant for IBC queries - RemoteQueries { - // host chain to be executed on - // Example: "osmosis" - host_chain: String, - // execute following queries - queries: Vec>, - // mandatory callback info - callback_info: CallbackInfo, }, RemoveHost { host_chain: String, }, - /// Callback from the Polytone implementation - /// This is only triggered when a contract execution is succesful + /// This is NOT ONLY triggered when a contract execution is successful Callback(CallbackMessage), } /// This enum is used for sending callbacks to the note contract of the IBC client #[cosmwasm_schema::cw_serde] pub enum IbcClientCallback { - UserRemoteAction { - sender: AccountId, - callback_info: CallbackInfo, - }, - CreateAccount { - account_id: AccountId, - }, + CreateAccount { account_id: AccountId }, WhoAmI {}, } @@ -250,7 +229,6 @@ mod tests { use crate::ibc::IbcCallbackMsg; use crate::ibc::IbcResponseMsg; - use crate::objects::AccountId; // ... (other test functions) #[test] @@ -265,7 +243,6 @@ mod tests { id: callback_id, msg: Some(callback_msg), result, - sender: AccountId::local(1), }; let actual: CosmosMsg = response_msg diff --git a/framework/packages/abstract-interface/src/account/manager.rs b/framework/packages/abstract-interface/src/account/manager.rs index ef5e65adec..cd3c7d5bad 100644 --- a/framework/packages/abstract-interface/src/account/manager.rs +++ b/framework/packages/abstract-interface/src/account/manager.rs @@ -1,7 +1,6 @@ pub use abstract_core::manager::{ExecuteMsgFns as ManagerExecFns, QueryMsgFns as ManagerQueryFns}; use abstract_core::{ adapter::{self, AdapterBaseMsg}, - ibc::CallbackInfo, ibc_host::{HelperAction, HostAction}, manager::*, module_factory::SimulateInstallModulesResponse, @@ -208,14 +207,12 @@ impl Manager { &self, host_chain: &str, msg: ExecuteMsg, - callback_info: Option, ) -> Result<::Response, crate::AbstractInterfaceError> { let msg = abstract_core::proxy::ExecuteMsg::IbcAction { msgs: vec![abstract_core::ibc_client::ExecuteMsg::RemoteAction { host_chain: host_chain.into(), action: HostAction::Dispatch { manager_msg: msg }, - callback_info, }], }; @@ -227,7 +224,6 @@ impl Manager { host_chain: &str, module_id: &str, msg: Binary, - callback_info: Option, ) -> Result<::Response, crate::AbstractInterfaceError> { let msg = abstract_core::proxy::ExecuteMsg::IbcAction { @@ -239,7 +235,6 @@ impl Manager { exec_msg: msg, }, }, - callback_info, }], }; @@ -249,14 +244,12 @@ impl Manager { pub fn send_all_funds_back( &self, host_chain: &str, - callback_info: Option, ) -> Result<::Response, crate::AbstractInterfaceError> { let msg = abstract_core::proxy::ExecuteMsg::IbcAction { msgs: vec![abstract_core::ibc_client::ExecuteMsg::RemoteAction { host_chain: host_chain.into(), action: HostAction::Helpers(HelperAction::SendAllBack), - callback_info, }], }; diff --git a/framework/packages/abstract-sdk/src/apis/ibc.rs b/framework/packages/abstract-sdk/src/apis/ibc.rs index 1c17a55afc..424851c8fd 100644 --- a/framework/packages/abstract-sdk/src/apis/ibc.rs +++ b/framework/packages/abstract-sdk/src/apis/ibc.rs @@ -3,7 +3,6 @@ //! use abstract_core::{ - ibc::CallbackInfo, ibc_client::ExecuteMsg as IbcClientMsg, ibc_host::HostAction, manager::ModuleInstallConfig, @@ -131,7 +130,6 @@ impl<'a, T: IbcInterface> IbcClient<'a, T> { )], }, }, - None, ) } @@ -148,7 +146,6 @@ impl<'a, T: IbcInterface> IbcClient<'a, T> { modules: vec![ModuleInstallConfig::new(module, None)], }, }, - None, ) } @@ -167,7 +164,6 @@ impl<'a, T: IbcInterface> IbcClient<'a, T> { exec_msg: to_json_binary(exec_msg)?, }, }, - None, ) } /// Call a [`HostAction`] on the host of the provided `host_chain`. @@ -175,16 +171,11 @@ impl<'a, T: IbcInterface> IbcClient<'a, T> { &self, host_chain: String, action: HostAction, - callback: Option, ) -> AbstractSdkResult { Ok(wasm_execute( self.base.proxy_address(self.deps)?.to_string(), &ExecuteMsg::IbcAction { - msgs: vec![IbcClientMsg::RemoteAction { - host_chain, - action, - callback_info: callback, - }], + msgs: vec![IbcClientMsg::RemoteAction { host_chain, action }], }, vec![], )? @@ -233,7 +224,6 @@ mod test { is_suspended: None, }, }, - None, ); assert_that!(msg).is_ok(); @@ -247,7 +237,6 @@ mod test { is_suspended: None, }, }, - callback_info: None, }], }) .unwrap(), @@ -256,51 +245,6 @@ mod test { assert_that!(msg.unwrap()).is_equal_to::(expected); } - /// Tests that a host_action can be built with a callback with more retries - #[test] - fn test_host_action_with_callback() { - let deps = mock_dependencies(); - let stub = MockModule::new(); - let client = stub.ibc_client(deps.as_ref()); - - let expected_callback = CallbackInfo { - receiver: "callback_receiver".to_string(), - id: "callback_id".to_string(), - msg: None, - }; - - let actual = client.host_action( - TEST_HOST_CHAIN.into(), - HostAction::Dispatch { - manager_msg: abstract_core::manager::ExecuteMsg::UpdateStatus { - is_suspended: None, - }, - }, - Some(expected_callback.clone()), - ); - - assert_that!(actual).is_ok(); - - let expected = CosmosMsg::Wasm(WasmMsg::Execute { - contract_addr: TEST_PROXY.to_string(), - msg: to_json_binary(&ExecuteMsg::IbcAction { - msgs: vec![IbcClientMsg::RemoteAction { - host_chain: TEST_HOST_CHAIN.into(), - action: HostAction::Dispatch { - manager_msg: abstract_core::manager::ExecuteMsg::UpdateStatus { - is_suspended: None, - }, - }, - callback_info: Some(expected_callback), - }], - }) - .unwrap(), - funds: vec![], - }); - - assert_that!(actual.unwrap()).is_equal_to::(expected); - } - /// Tests that the ics_20 transfer can be built and that the funds are passed into the sendFunds message not the execute message #[test] fn test_ics20_transfer() { diff --git a/framework/packages/abstract-sdk/src/base/contract_base.rs b/framework/packages/abstract-sdk/src/base/contract_base.rs index 1df6a827ec..65955c26c2 100644 --- a/framework/packages/abstract-sdk/src/base/contract_base.rs +++ b/framework/packages/abstract-sdk/src/base/contract_base.rs @@ -1,4 +1,3 @@ -use abstract_core::objects::AccountId; use cosmwasm_std::{Binary, Deps, DepsMut, Env, MessageInfo, Reply, Response, Storage}; use cw2::{ContractVersion, CONTRACT}; use cw_storage_plus::Item; @@ -33,15 +32,8 @@ pub type QueryHandlerFn = type CallbackMessage = Option; // ANCHOR: ibc /// Function signature for an IBC callback handler. -pub type IbcCallbackHandlerFn = fn( - DepsMut, - Env, - MessageInfo, - Module, - AccountId, - CallbackMessage, - Callback, -) -> Result; +pub type IbcCallbackHandlerFn = + fn(DepsMut, Env, MessageInfo, Module, CallbackMessage, Callback) -> Result; // ANCHOR_END: ibc // ANCHOR: mig @@ -368,7 +360,7 @@ mod test { fn test_with_ibc_callback_handlers() { const IBC_ID: &str = "aoeu"; const HANDLER: IbcCallbackHandlerFn = - |_, _, _, _, _, _, _| Ok(Response::default().add_attribute("test", "ibc")); + |_, _, _, _, _, _| Ok(Response::default().add_attribute("test", "ibc")); let contract = MockAppContract::new("test_contract", "0.1.0", ModuleMetadata::default()) .with_ibc_callbacks(&[(IBC_ID, HANDLER)]); diff --git a/framework/packages/abstract-sdk/src/base/endpoints/ibc_callback.rs b/framework/packages/abstract-sdk/src/base/endpoints/ibc_callback.rs index cdf3248c91..6e11c4c6a0 100644 --- a/framework/packages/abstract-sdk/src/base/endpoints/ibc_callback.rs +++ b/framework/packages/abstract-sdk/src/base/endpoints/ibc_callback.rs @@ -29,12 +29,11 @@ pub trait IbcCallbackEndpoint: Handler { id, msg: callback_msg, result, - sender, } = msg; let maybe_handler = self.maybe_ibc_callback_handler(&id); maybe_handler.map_or_else( || Ok(Response::new()), - |handler| handler(deps, env, info, self, sender, callback_msg, result), + |handler| handler(deps, env, info, self, callback_msg, result), ) } } diff --git a/interchain/tests/src/interchain_accounts.rs b/interchain/tests/src/interchain_accounts.rs index 7b8b9b6095..0edc782ea9 100644 --- a/interchain/tests/src/interchain_accounts.rs +++ b/interchain/tests/src/interchain_accounts.rs @@ -74,35 +74,24 @@ pub fn create_test_remote_account AnyResult<()> { - logger_test_init(); - let mock_interchain = - MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]); - - // We just verified all steps pass - let (abstr_origin, _abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?; - - let remote_name = ChainName::from_chain_id(STARGAZE).to_string(); - - let (origin_account, _remote_account_id) = - create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?; - - let app = MockAppWithDepI::new( - TEST_WITH_DEP_MODULE_ID, - abstr_origin.version_control.get_chain().clone(), - ); - - let app_dep = MockAppI::new( - TEST_MODULE_ID, - abstr_origin.version_control.get_chain().clone(), - ); - - let app_account = - abstr_origin - .account_factory - .create_default_account(GovernanceDetails::Monarchy { - monarch: abstr_origin - .version_control - .get_chain() - .sender() - .into_string(), - })?; - - let app_deps_account = - abstr_origin - .account_factory - .create_default_account(GovernanceDetails::Monarchy { - monarch: abstr_origin - .version_control - .get_chain() - .sender() - .into_string(), - })?; - - abstr_origin.version_control.claim_namespace( - app_account.manager.config()?.account_id, - TEST_WITH_DEP_NAMESPACE.to_owned(), - )?; - abstr_origin.version_control.claim_namespace( - app_deps_account.manager.config()?.account_id, - TEST_NAMESPACE.to_owned(), - )?; - - app.deploy(TEST_VERSION.parse()?, DeployStrategy::Try)?; - app_dep.deploy(TEST_VERSION.parse()?, DeployStrategy::Try)?; - - origin_account.install_app(&app_dep, &MockInitMsg {}, None)?; - origin_account.install_app(&app, &MockInitMsg {}, None)?; - let res: ModuleAddressesResponse = origin_account - .manager - .module_addresses(vec![TEST_WITH_DEP_MODULE_ID.to_owned()])?; - - assert_eq!(1, res.modules.len()); - - let module_address = res.modules[0].1.to_string(); - - let new_name = "Funky Crazy Name"; - let new_description = "Funky new account with wonderful capabilities"; - let new_link = "https://abstract.money"; - - // The user on origin chain wants to change the account description - let ibc_action_result = origin_account.manager.execute_on_remote( - &remote_name, - ManagerExecuteMsg::UpdateInfo { - name: Some(new_name.to_string()), - description: Some(new_description.to_string()), - link: Some(new_link.to_string()), - }, - Some(CallbackInfo { - id: String::from("c_id"), - msg: None, - receiver: module_address, - }), - )?; - - assert_callback_status(&app, false)?; - - mock_interchain.wait_ibc(JUNO, ibc_action_result)?; - - // Switched to true by the callback. - assert_callback_status(&app, true)?; - - Ok(()) - } - - #[test] - fn anyone_can_call_account_ibc_app_callback() -> AnyResult<()> { - logger_test_init(); - let mock_interchain = - MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]); - - // We just verified all steps pass - let (abstr_origin, _abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?; - - let remote_name = ChainName::from_chain_id(STARGAZE).to_string(); - - let (origin_account, _remote_account_id) = - create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?; - - let app = MockAppWithDepI::new( - TEST_WITH_DEP_MODULE_ID, - abstr_origin.version_control.get_chain().clone(), - ); - - let app_dep = MockAppI::new( - TEST_MODULE_ID, - abstr_origin.version_control.get_chain().clone(), - ); - - let app_account = - abstr_origin - .account_factory - .create_default_account(GovernanceDetails::Monarchy { - monarch: abstr_origin - .version_control - .get_chain() - .sender() - .into_string(), - })?; - - let app_deps_account = - abstr_origin - .account_factory - .create_default_account(GovernanceDetails::Monarchy { - monarch: abstr_origin - .version_control - .get_chain() - .sender() - .into_string(), - })?; - - abstr_origin.version_control.claim_namespace( - app_account.manager.config()?.account_id, - TEST_WITH_DEP_NAMESPACE.to_owned(), - )?; - abstr_origin.version_control.claim_namespace( - app_deps_account.manager.config()?.account_id, - TEST_NAMESPACE.to_owned(), - )?; - - app.deploy(TEST_VERSION.parse()?, DeployStrategy::Try)?; - app_dep.deploy(TEST_VERSION.parse()?, DeployStrategy::Try)?; - - origin_account.install_app(&app_dep, &MockInitMsg {}, None)?; - origin_account.install_app(&app, &MockInitMsg {}, None)?; - let res: ModuleAddressesResponse = origin_account - .manager - .module_addresses(vec![TEST_WITH_DEP_MODULE_ID.to_owned()])?; - - assert_eq!(1, res.modules.len()); - - let module_address = res.modules[0].1.to_string(); - - let new_name = "Funky Crazy Name"; - let new_description = "Funky new account with wonderful capabilities"; - let new_link = "https://abstract.money"; - - // The user on origin chain wants to change the account description - let ibc_action_result = origin_account.manager.execute_on_remote( - &remote_name, - ManagerExecuteMsg::UpdateInfo { - name: Some(new_name.to_string()), - description: Some(new_description.to_string()), - link: Some(new_link.to_string()), - }, - Some(CallbackInfo { - id: String::from("c_id"), - msg: None, - receiver: module_address.clone(), - }), - )?; - - assert_callback_status(&app, false)?; - assert_callback_sender(&app, origin_account.id()?, false)?; - - mock_interchain.wait_ibc(JUNO, ibc_action_result)?; - - // Switched to true by the callback. - assert_callback_status(&app, true)?; - assert_callback_sender(&app, origin_account.id()?, true)?; - - // A new account sends an action with a callback on another account user on origin chain wants to change the account description - let (new_account, _) = - create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?; - let ibc_action_result = new_account.manager.execute_on_remote( - &remote_name, - ManagerExecuteMsg::UpdateInfo { - name: Some(new_name.to_string()), - description: Some(new_description.to_string()), - link: Some(new_link.to_string()), - }, - Some(CallbackInfo { - id: String::from("c_id"), - msg: None, - receiver: module_address, - }), - )?; - - assert_callback_sender(&app, new_account.id()?, false)?; - - mock_interchain.wait_ibc(JUNO, ibc_action_result)?; - - // Switched to true by the callback. - assert_callback_sender(&app, new_account.id()?, true)?; - - Ok(()) - } - - #[test] - fn ibc_adapter_callback() -> AnyResult<()> { - logger_test_init(); - let mock_interchain = - MockBech32InterchainEnv::new(vec![(JUNO, "juno"), (STARGAZE, "stargaze")]); - - // We just verified all steps pass - let (abstr_origin, _abstr_remote) = ibc_abstract_setup(&mock_interchain, JUNO, STARGAZE)?; - - let remote_name = ChainName::from_chain_id(STARGAZE).to_string(); - - let (origin_account, _remote_account_id) = - create_test_remote_account(&abstr_origin, JUNO, STARGAZE, &mock_interchain, None)?; - - let adapter = MockAdapterI::new( - TEST_MODULE_ID, - abstr_origin.version_control.get_chain().clone(), - ); - - let adapter_account = - abstr_origin - .account_factory - .create_default_account(GovernanceDetails::Monarchy { - monarch: abstr_origin - .version_control - .get_chain() - .sender() - .into_string(), - })?; - - abstr_origin.version_control.claim_namespace( - adapter_account.manager.config()?.account_id, - TEST_NAMESPACE.to_owned(), - )?; - - adapter.deploy( - TEST_VERSION.parse()?, - abstract_adapter::mock::MockInitMsg {}, - DeployStrategy::Try, - )?; - - origin_account.install_adapter(&adapter, None)?; - let res: ModuleAddressesResponse = origin_account - .manager - .module_addresses(vec![TEST_MODULE_ID.to_owned()])?; - - assert_eq!(1, res.modules.len()); - - let module_address = res.modules[0].1.to_string(); - - let new_name = "Funky Crazy Name"; - let new_description = "Funky new account with wonderful capabilities"; - let new_link = "https://abstract.money"; - - // The user on origin chain wants to change the account description - let ibc_action_result = origin_account.manager.execute_on_remote( - &remote_name, - ManagerExecuteMsg::UpdateInfo { - name: Some(new_name.to_string()), - description: Some(new_description.to_string()), - link: Some(new_link.to_string()), - }, - Some(CallbackInfo { - id: String::from("c_id"), - msg: None, - receiver: module_address, - }), - )?; - - assert_adapter_callback_status(&adapter, false)?; - - mock_interchain.wait_ibc(JUNO, ibc_action_result)?; - - // Switched to true by the callback. - assert_adapter_callback_status(&adapter, true)?; - - Ok(()) - } - - fn assert_callback_status(app: &MockAppWithDepI, status: bool) -> AnyResult<()> { - let get_received_ibc_callback_status_res: ReceivedIbcCallbackStatus = - app.get_received_ibc_callback_status()?; - - assert_eq!( - ReceivedIbcCallbackStatus { received: status }, - get_received_ibc_callback_status_res - ); - Ok(()) - } - - fn assert_callback_sender( - app: &MockAppWithDepI, - account_id: AccountId, - status: bool, - ) -> AnyResult<()> { - let get_received_ibc_callback_status_res = app - .get_received_ibc_callback_sender_status(account_id) - .map(|r| r.received) - .unwrap_or(false); - - assert_eq!(status, get_received_ibc_callback_status_res); - Ok(()) - } - - fn assert_adapter_callback_status( - app: &MockAdapterI, - status: bool, - ) -> AnyResult<()> { - let get_received_ibc_callback_status_res = app.get_received_ibc_callback_status()?; - - assert_eq!( - abstract_adapter::mock::ReceivedIbcCallbackStatus { received: status }, - get_received_ibc_callback_status_res - ); - Ok(()) - } - #[test] fn test_multi_hop_account_creation() -> AnyResult<()> { logger_test_init(); @@ -616,7 +267,6 @@ mod test { ManagerExecuteMsg::UpdateSettings { ibc_enabled: Some(true), }, - None, )?; mock_interchain.wait_ibc(JUNO, enable_ibc_tx)?; @@ -633,7 +283,6 @@ mod test { install_modules: vec![], }], })?, - None, )?; mock_interchain.wait_ibc(JUNO, create_account_remote_tx)?; @@ -740,7 +389,6 @@ mod test { )? .into()], })?, - None, )?; // The create remote account tx is passed ? @@ -1086,7 +734,7 @@ mod test { // Send all back. let send_funds_back_tx = origin_account .manager - .send_all_funds_back(&ChainName::from_chain_id(STARGAZE).to_string(), None)?; + .send_all_funds_back(&ChainName::from_chain_id(STARGAZE).to_string())?; mock_interchain.wait_ibc(JUNO, send_funds_back_tx)?; diff --git a/modules/contracts/adapters/cw-staking/src/handlers/execute.rs b/modules/contracts/adapters/cw-staking/src/handlers/execute.rs index 0f9c25231d..59fe6985b0 100644 --- a/modules/contracts/adapters/cw-staking/src/handlers/execute.rs +++ b/modules/contracts/adapters/cw-staking/src/handlers/execute.rs @@ -92,7 +92,7 @@ fn handle_ibc_request( // If the calling entity is a contract, we provide a callback on successful cross-chain-staking let maybe_contract_info = deps.querier.query_wasm_contract_info(info.sender.clone()); - let callback = if maybe_contract_info.is_err() { + let _callback = if maybe_contract_info.is_err() { None } else { Some(CallbackInfo { @@ -104,7 +104,7 @@ fn handle_ibc_request( receiver: info.sender.into_string(), }) }; - let ibc_action_msg = ibc_client.host_action(host_chain.to_string(), host_action, callback)?; + let ibc_action_msg = ibc_client.host_action(host_chain.to_string(), host_action)?; Ok(adapter .custom_response("handle_ibc_request", vec![("provider", provider_name)]) diff --git a/modules/contracts/adapters/dex/src/handlers/execute.rs b/modules/contracts/adapters/dex/src/handlers/execute.rs index 73285b18e0..ca4b72c217 100644 --- a/modules/contracts/adapters/dex/src/handlers/execute.rs +++ b/modules/contracts/adapters/dex/src/handlers/execute.rs @@ -167,7 +167,7 @@ fn handle_ibc_request( // If the calling entity is a contract, we provide a callback on successful swap let maybe_contract_info = deps.querier.query_wasm_contract_info(info.sender.clone()); - let callback = if maybe_contract_info.is_err() { + let _callback = if maybe_contract_info.is_err() { None } else { Some(CallbackInfo { @@ -179,7 +179,7 @@ fn handle_ibc_request( receiver: info.sender.into_string(), }) }; - let ibc_action_msg = ibc_client.host_action(host_chain.to_string(), host_action, callback)?; + let ibc_action_msg = ibc_client.host_action(host_chain.to_string(), host_action)?; // call both messages on the proxy Ok(Response::new().add_messages(vec![ics20_transfer_msg, ibc_action_msg])) From 0edff78155e508ba8e65930dd971ae846b4bfc0a Mon Sep 17 00:00:00 2001 From: Kayanski Date: Tue, 30 Apr 2024 09:45:06 +0000 Subject: [PATCH 4/4] formatting [skip ci] --- framework/contracts/native/ibc-client/src/commands.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/framework/contracts/native/ibc-client/src/commands.rs b/framework/contracts/native/ibc-client/src/commands.rs index 07fc01a16b..c117e74612 100644 --- a/framework/contracts/native/ibc-client/src/commands.rs +++ b/framework/contracts/native/ibc-client/src/commands.rs @@ -2,7 +2,8 @@ use std::str::FromStr; use abstract_sdk::{ feature_objects::{AnsHost, VersionControlContract}, - features::AccountIdentification, Resolve, + features::AccountIdentification, + Resolve, }; use abstract_std::{ ibc_client::{