Skip to content

Remove ibc callbacks for accounts. #277

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

Merged
merged 6 commits into from
Apr 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
61 changes: 5 additions & 56 deletions framework/contracts/native/ibc-client/src/commands.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
use std::str::FromStr;

use abstract_core::{
ibc::CallbackInfo,
ibc_client::{
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,
};
Expand All @@ -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;

Expand Down Expand Up @@ -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<QueryRequest<Empty>>,
callback_request: CallbackRequest,
) -> IbcClientResult<CosmosMsg<Empty>> {
// 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<CallbackInfo>,
) -> IbcClientResult {
let host_chain = ChainName::from_str(&host_chain)?;

Expand All @@ -219,44 +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(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,
host_chain: String,
queries: Vec<QueryRequest<Empty>>,
callback_info: CallbackInfo,
) -> IbcClientResult {
let host_chain = ChainName::from_str(&host_chain)?;

let callback_request = CallbackRequest {
receiver: env.contract.address.to_string(),
msg: to_json_binary(&IbcClientCallback::UserRemoteAction(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,
Expand Down
221 changes: 5 additions & 216 deletions framework/contracts/native/ibc-client/src/contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, 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)
}
Expand Down Expand Up @@ -457,7 +450,6 @@ mod tests {
use std::str::FromStr;

use abstract_core::{
ibc::CallbackInfo,
ibc_host::{self, HostAction, InternalAction},
manager,
objects::{
Expand All @@ -468,8 +460,7 @@ mod tests {
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;
Expand All @@ -491,7 +482,6 @@ mod tests {
link: None,
},
},
callback_info: None,
};

let res = execute_as(deps.as_mut(), TEST_MANAGER, msg);
Expand Down Expand Up @@ -523,7 +513,6 @@ mod tests {
namespace: None,
install_modules: vec![],
}),
callback_info: None,
};

let res = execute_as(deps.as_mut(), TEST_PROXY, msg);
Expand Down Expand Up @@ -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)?;
Expand Down Expand Up @@ -596,152 +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.clone()))?,
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::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(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(), "sender", 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 {
Expand Down Expand Up @@ -1130,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},
};
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};

Expand Down Expand Up @@ -1508,56 +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, &note, &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(
CallbackInfo {
id: id.clone(),
msg: Some(callback_info_msg.clone()),
receiver: receiver.clone(),
},
))?,
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,
}
.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;
Expand Down
Loading