abstract_os/
ibc_host.rs

1//! # Abstract Api Base
2//!
3//! `abstract_os::api` implements shared functionality that's useful for creating new Abstract apis.
4//!
5//! ## Description
6//! An Abstract api 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 OS.
8//! The api structure is well-suited for implementing standard interfaces to external services like dexes, lending platforms, etc.
9
10use crate::{
11    base::{
12        ExecuteMsg as MiddlewareExecMsg, InstantiateMsg as MiddlewareInstantiateMsg,
13        MigrateMsg as MiddlewareMigrateMsg, QueryMsg as MiddlewareQueryMsg,
14    },
15    ibc_client::CallbackInfo,
16    objects::core::OsId,
17};
18use cosmwasm_schema::QueryResponses;
19use cosmwasm_std::{Addr, Binary, CosmosMsg, Empty, QueryRequest};
20
21pub type ExecuteMsg<T, R = Empty> = MiddlewareExecMsg<BaseExecuteMsg, T, R>;
22pub type QueryMsg<T = Empty> = MiddlewareQueryMsg<BaseQueryMsg, T>;
23pub type InstantiateMsg<T = Empty> = MiddlewareInstantiateMsg<BaseInstantiateMsg, T>;
24pub type MigrateMsg<T = Empty> = MiddlewareMigrateMsg<BaseMigrateMsg, T>;
25
26/// Used by Abstract to instantiate the contract
27/// The contract is then registered on the version control contract using [`crate::version_control::ExecuteMsg::AddModules`].
28#[cosmwasm_schema::cw_serde]
29pub struct BaseInstantiateMsg {
30    /// Used to easily perform address translation on the app chain
31    pub ans_host_address: String,
32    /// Code-id for cw1 proxy contract
33    pub cw1_code_id: u64,
34}
35
36#[cosmwasm_schema::cw_serde]
37pub struct BaseMigrateMsg {}
38
39#[cosmwasm_schema::cw_serde]
40pub enum InternalAction {
41    Register { os_proxy_address: String },
42    WhoAmI,
43}
44
45/// Callable actions on a remote host
46#[cosmwasm_schema::cw_serde]
47pub enum HostAction {
48    App {
49        msg: Binary,
50    },
51    Dispatch {
52        msgs: Vec<CosmosMsg<Empty>>,
53    },
54    Query {
55        msgs: Vec<QueryRequest<Empty>>,
56    },
57    SendAllBack {},
58    Balances {},
59    /// Can't be called through the packet endpoint directly
60    Internal(InternalAction),
61}
62
63impl HostAction {
64    pub fn into_packet(
65        self,
66        os_id: OsId,
67        retries: u8,
68        client_chain: String,
69        callback_info: Option<CallbackInfo>,
70    ) -> PacketMsg {
71        PacketMsg {
72            client_chain,
73            retries,
74            callback_info,
75            os_id,
76            action: self,
77        }
78    }
79}
80/// This is the message we send over the IBC channel
81#[cosmwasm_schema::cw_serde]
82pub struct PacketMsg {
83    /// Chain of the client
84    pub client_chain: String,
85    /// Amount of retries to attempt if packet returns with StdAck::Error
86    pub retries: u8,
87    pub os_id: OsId,
88    /// Callback performed after receiving an StdAck::Result
89    pub callback_info: Option<CallbackInfo>,
90    /// execute the custom host function
91    pub action: HostAction,
92}
93
94/// Interface to the Host.
95#[cosmwasm_schema::cw_serde]
96pub enum BaseExecuteMsg {
97    /// Update the Admin
98    UpdateAdmin { admin: String },
99    UpdateConfig {
100        ans_host_address: Option<String>,
101        cw1_code_id: Option<u64>,
102    },
103    /// Allow for fund recovery through the Admin
104    RecoverAccount {
105        closed_channel: String,
106        os_id: OsId,
107        msgs: Vec<CosmosMsg>,
108    },
109}
110
111/// Query Host message
112#[cosmwasm_schema::cw_serde]
113#[derive(QueryResponses)]
114pub enum BaseQueryMsg {
115    /// Returns [`HostConfigResponse`].
116    #[returns(HostConfigResponse)]
117    Config {},
118    /// Returns (reflect) account that is attached to this channel,
119    /// or none.
120    #[returns(AccountResponse)]
121    Account { client_chain: String, os_id: OsId },
122    /// Returns all (channel, reflect_account) pairs.
123    /// No pagination - this is a test contract
124    #[returns(ListAccountsResponse)]
125    ListAccounts {},
126}
127
128#[cosmwasm_schema::cw_serde]
129pub struct HostConfigResponse {
130    pub ans_host_address: Addr,
131}
132
133#[cosmwasm_schema::cw_serde]
134pub struct AccountResponse {
135    pub account: Option<String>,
136}
137
138#[cosmwasm_schema::cw_serde]
139pub struct ListAccountsResponse {
140    pub accounts: Vec<AccountInfo>,
141}
142
143#[cosmwasm_schema::cw_serde]
144pub struct AccountInfo {
145    pub os_id: OsId,
146    pub account: String,
147    pub channel_id: String,
148}