abstract_std/native/ibc/
ibc_host.rs

1use cosmwasm_schema::QueryResponses;
2use cosmwasm_std::{Addr, Binary};
3
4use crate::{
5    account::{self, ModuleInstallConfig},
6    ibc_client::InstalledModuleIdentification,
7    objects::{account::AccountId, module::ModuleInfo, TruncatedChainId},
8};
9
10pub mod state {
11    use cw_storage_plus::{Item, Map};
12
13    use super::*;
14    use crate::objects::storage_namespaces;
15
16    /// Maps a chain name to the proxy it uses to interact on this local chain
17    pub const CHAIN_PROXIES: Map<&TruncatedChainId, Addr> =
18        Map::new(storage_namespaces::ibc_host::CHAIN_PROXIES);
19    pub const REVERSE_CHAIN_PROXIES: Map<&Addr, TruncatedChainId> =
20        Map::new(storage_namespaces::ibc_host::REVERSE_CHAIN_PROXIES);
21
22    // Temporary structure to hold actions to be executed after account creation
23    pub const TEMP_ACTION_AFTER_CREATION: Item<ActionAfterCreationCache> =
24        Item::new(storage_namespaces::ibc_host::TEMP_ACTION_AFTER_CREATION);
25
26    #[cosmwasm_schema::cw_serde]
27    pub struct ActionAfterCreationCache {
28        pub client_account_address: String,
29        pub account_id: AccountId,
30        pub action: HostAction,
31        pub chain_name: TruncatedChainId,
32    }
33}
34/// Used by Abstract to instantiate the contract
35/// The contract is then registered on the registry contract using [`crate::registry::ExecuteMsg::ProposeModules`].
36#[cosmwasm_schema::cw_serde]
37pub struct InstantiateMsg {}
38
39#[cosmwasm_schema::cw_serde]
40pub struct MigrateMsg {}
41
42// ANCHOR: ibc-host-action
43#[cosmwasm_schema::cw_serde]
44#[non_exhaustive]
45pub enum InternalAction {
46    /// Registers a new account from a remote chain
47    Register {
48        name: Option<String>,
49        description: Option<String>,
50        link: Option<String>,
51        namespace: Option<String>,
52        install_modules: Vec<ModuleInstallConfig>,
53    },
54}
55
56#[cosmwasm_schema::cw_serde]
57#[non_exhaustive]
58pub enum HelperAction {
59    SendAllBack,
60}
61
62/// Callable actions on a remote host
63#[cosmwasm_schema::cw_serde]
64pub enum HostAction {
65    /// Dispatch messages to a remote Account.
66    /// Will create a new Account if required.
67    Dispatch {
68        account_msgs: Vec<account::ExecuteMsg>,
69    },
70    /// Can't be called by an account directly. These are permissioned messages that only the IBC Client is allowed to call by itself.
71    Internal(InternalAction),
72    /// Some helpers that allow calling dispatch messages faster (for actions that are called regularly)
73    Helpers(HelperAction),
74}
75// ANCHOR_END: ibc-host-action
76
77/// Interface to the Host.
78#[cosmwasm_schema::cw_serde]
79#[derive(cw_orch::ExecuteFns)]
80pub enum ExecuteMsg {
81    UpdateOwnership(cw_ownable::Action),
82    /// Register the Polytone proxy for a specific chain.
83    /// proxy should be a local address (will be validated)
84    RegisterChainProxy {
85        chain: TruncatedChainId,
86        proxy: String,
87    },
88    /// Remove the Polytone proxy for a specific chain.
89    RemoveChainProxy {
90        chain: TruncatedChainId,
91    },
92    // ANCHOR: ibc-host-execute
93    /// Allows for remote execution from the Polytone implementation
94    #[cw_orch(fn_name("ibc_execute"))]
95    Execute {
96        account_id: AccountId,
97        /// The address of the calling account id. This is used purely for the send-all-back method.
98        /// We include it in all messages none-the-less to simplify the users life
99        account_address: String,
100        action: HostAction,
101    },
102    // ANCHOR_END: ibc-host-execute
103    /// Performs an execution on a local module
104    ModuleExecute {
105        source_module: InstalledModuleIdentification,
106        target_module: ModuleInfo,
107        msg: Binary,
108    },
109    /// Sends the associated funds to the local account corresponding to the source account id
110    Fund {
111        src_account: AccountId,
112        src_chain: TruncatedChainId,
113    },
114}
115
116/// Query Host message
117#[cosmwasm_schema::cw_serde]
118#[derive(QueryResponses, cw_orch::QueryFns)]
119pub enum QueryMsg {
120    /// Queries the ownership of the ibc client contract
121    /// Returns [`cw_ownable::Ownership<Addr>`]
122    #[returns(cw_ownable::Ownership<Addr> )]
123    Ownership {},
124    /// Returns [`ConfigResponse`].
125    #[returns(ConfigResponse)]
126    Config {},
127    /// Lists all the polytone proxy contracts and their respective client chain registered with the host.
128    /// Returns [`ClientProxiesResponse`].
129    #[returns(ClientProxiesResponse)]
130    ClientProxies {
131        start_after: Option<String>,
132        limit: Option<u32>,
133    },
134    /// Returns the polytone proxy contract address for a specific client chain.
135    /// Returns [`ClientProxyResponse`].
136    #[returns(ClientProxyResponse)]
137    ClientProxy { chain: String },
138    /// Performs an query on a local module
139    #[returns(Binary)]
140    ModuleQuery {
141        target_module: InstalledModuleIdentification,
142        msg: Binary,
143    },
144}
145
146#[cosmwasm_schema::cw_serde]
147pub struct ConfigResponse {
148    pub ans_host_address: Addr,
149    pub module_factory_address: Addr,
150    pub registry_address: Addr,
151}
152
153#[cosmwasm_schema::cw_serde]
154pub struct ClientProxiesResponse {
155    pub chains: Vec<(TruncatedChainId, Addr)>,
156}
157
158#[cosmwasm_schema::cw_serde]
159pub struct ClientProxyResponse {
160    pub proxy: Addr,
161}