abstract_core/native/
ibc_host.rs

1//! # Abstract Api Base
2//!
3//! `abstract_core::adapter` implements shared functionality that's useful for creating new Abstract adapters.
4//!
5//! ## Description
6//! An Abstract adapter contract is a contract that is allowed to perform actions on a [proxy](crate::proxy) contract.
7//! It is not migratable and its functionality is shared between users, meaning that all users call the same contract address to perform operations on the Account.
8//! The api structure is well-suited for implementing standard interfaces to external services like dexes, lending platforms, etc.
9
10use cosmwasm_schema::QueryResponses;
11use cosmwasm_std::Addr;
12
13use crate::{
14    manager,
15    manager::ModuleInstallConfig,
16    objects::{account::AccountId, chain_name::ChainName, AssetEntry},
17};
18
19pub mod state {
20    use cw_storage_plus::{Item, Map};
21
22    use super::*;
23    use crate::objects::{ans_host::AnsHost, version_control::VersionControlContract};
24
25    /// Maps a chain name to the proxy it uses to interact on this local chain
26    pub const CHAIN_PROXIES: Map<&ChainName, Addr> = Map::new("ccl");
27    pub const REVERSE_CHAIN_PROXIES: Map<&Addr, ChainName> = Map::new("rev-ccl");
28    /// Configuration of the IBC host
29    pub const CONFIG: Item<Config> = Item::new("cfg");
30
31    // Temporary structure to hold actions to be executed after account creation
32    pub const TEMP_ACTION_AFTER_CREATION: Item<ActionAfterCreationCache> = Item::new("act");
33
34    /// The BaseState contains the main addresses needed for sending and verifying messages
35    #[cosmwasm_schema::cw_serde]
36    pub struct Config {
37        /// AnsHost contract struct (address)
38        pub ans_host: AnsHost,
39        /// Address of the account factory, used to create remote accounts
40        pub account_factory: Addr,
41        /// Address of the local version control, for retrieving account information
42        pub version_control: VersionControlContract,
43    }
44
45    #[cosmwasm_schema::cw_serde]
46    pub struct ActionAfterCreationCache {
47        pub client_proxy_address: String,
48        pub account_id: AccountId,
49        pub action: HostAction,
50        pub chain_name: ChainName,
51    }
52}
53/// Used by Abstract to instantiate the contract
54/// The contract is then registered on the version control contract using [`crate::version_control::ExecuteMsg::ProposeModules`].
55#[cosmwasm_schema::cw_serde]
56pub struct InstantiateMsg {
57    /// Used to easily perform address translation on the app chain
58    pub ans_host_address: String,
59    /// Used to create remote abstract accounts
60    pub account_factory_address: String,
61    /// Version control address
62    pub version_control_address: String,
63}
64
65#[cosmwasm_schema::cw_serde]
66pub struct MigrateMsg {}
67
68#[cosmwasm_schema::cw_serde]
69#[non_exhaustive]
70pub enum InternalAction {
71    /// Registers a new account from a remote chain
72    Register {
73        name: String,
74        description: Option<String>,
75        link: Option<String>,
76        base_asset: Option<AssetEntry>,
77        namespace: Option<String>,
78        install_modules: Vec<ModuleInstallConfig>,
79    },
80}
81
82#[cosmwasm_schema::cw_serde]
83#[non_exhaustive]
84pub enum HelperAction {
85    /// What do we need here ? TODO
86    SendAllBack,
87}
88
89/// Callable actions on a remote host
90#[cosmwasm_schema::cw_serde]
91pub enum HostAction {
92    Dispatch {
93        manager_msg: manager::ExecuteMsg,
94    },
95    /// Can't be called by an account directly. These are permissioned messages that only the IBC Client is allowed to call by itself.
96    Internal(InternalAction),
97    /// Some helpers that allow calling dispatch messages faster (for actions that are called regularly)
98    Helpers(HelperAction),
99}
100
101/// Interface to the Host.
102#[cosmwasm_schema::cw_serde]
103#[cfg_attr(feature = "interface", derive(cw_orch::ExecuteFns))]
104pub enum ExecuteMsg {
105    UpdateOwnership(cw_ownable::Action),
106    UpdateConfig {
107        ans_host_address: Option<String>,
108        account_factory_address: Option<String>,
109        version_control_address: Option<String>,
110    },
111    /// Register the Polytone proxy for a specific chain.
112    /// proxy should be a local address (will be validated)
113    RegisterChainProxy {
114        chain: String,
115        proxy: String,
116    },
117    /// Remove the Polytone proxy for a specific chain.
118    RemoveChainProxy {
119        chain: String,
120    },
121    /// Allows for remote execution from the Polytone implementation
122    #[cfg_attr(feature = "interface", fn_name("ibc_execute"))]
123    Execute {
124        account_id: AccountId,
125        /// The address of the calling account id. This is used purely for the send-all-back method.
126        /// We include it in all messages one-the-less to simpify the users life
127        proxy_address: String,
128        action: HostAction,
129    },
130}
131
132/// Query Host message
133#[cosmwasm_schema::cw_serde]
134#[derive(QueryResponses)]
135#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
136pub enum QueryMsg {
137    /// Queries the ownership of the ibc client contract
138    /// Returns [`cw_ownable::Ownership<Addr>`]
139    #[returns(cw_ownable::Ownership<Addr> )]
140    Ownership {},
141    /// Returns [`ConfigResponse`].
142    #[returns(ConfigResponse)]
143    Config {},
144    /// Lists all the polytone proxy contracts and their respective client chain registered with the host.
145    /// Returns [`ClientProxiesResponse`].
146    #[returns(ClientProxiesResponse)]
147    ClientProxies {
148        start_after: Option<String>,
149        limit: Option<u32>,
150    },
151    /// Returns the polytone proxy contract address for a specific client chain.
152    /// Returns [`ClientProxyResponse`].
153    #[returns(ClientProxyResponse)]
154    ClientProxy { chain: String },
155}
156
157#[cosmwasm_schema::cw_serde]
158pub struct ConfigResponse {
159    pub ans_host_address: Addr,
160    pub account_factory_address: Addr,
161    pub version_control_address: Addr,
162}
163
164#[cosmwasm_schema::cw_serde]
165pub struct ClientProxiesResponse {
166    pub chains: Vec<(ChainName, Addr)>,
167}
168
169#[cosmwasm_schema::cw_serde]
170pub struct ClientProxyResponse {
171    pub proxy: Addr,
172}