abstract_os/core/
proxy.rs

1//! # OS Proxy
2//!
3//! `abstract_os::proxy` hold all the assets associated with the OS instance. It accepts Cosmos messages from whitelisted addresses and executes them.
4//!
5//! ## Description
6//! The proxy is part of the Core OS contracts along with the [`crate::manager`] contract.
7//! This contract is responsible for executing Cosmos messages and calculating the value of its internal assets.
8//!
9//! ## Proxy assets
10//! [Proxy assets](crate::objects::proxy_asset) are what allow the proxy contract to provide value queries for its assets. It needs to be configured using the [`ExecuteMsg::UpdateAssets`] endpoint.
11//! After configuring the proxy assets [`QueryMsg::TotalValue`] can be called to get the total holding value.
12
13use crate::{
14    ibc_client::ExecuteMsg as IbcClientMsg,
15    objects::{
16        core::OsId,
17        proxy_asset::{ProxyAsset, UncheckedProxyAsset},
18        AssetEntry,
19    },
20};
21use cosmwasm_schema::QueryResponses;
22use cosmwasm_std::{CosmosMsg, Empty, Uint128};
23
24pub mod state {
25    pub use crate::objects::core::OS_ID;
26    use cw_controllers::Admin;
27
28    use cosmwasm_std::Addr;
29    use cw_storage_plus::{Item, Map};
30
31    use crate::objects::{
32        ans_host::AnsHost, asset_entry::AssetEntry, common_namespace::ADMIN_NAMESPACE,
33        proxy_asset::ProxyAsset,
34    };
35    #[cosmwasm_schema::cw_serde]
36    pub struct State {
37        pub modules: Vec<Addr>,
38    }
39    pub const ANS_HOST: Item<AnsHost> = Item::new("\u{0}{6}ans_host");
40    pub const STATE: Item<State> = Item::new("\u{0}{5}state");
41    pub const ADMIN: Admin = Admin::new(ADMIN_NAMESPACE);
42    pub const VAULT_ASSETS: Map<&AssetEntry, ProxyAsset> = Map::new("proxy_assets");
43}
44
45#[cosmwasm_schema::cw_serde]
46pub struct InstantiateMsg {
47    pub os_id: OsId,
48    pub ans_host_address: String,
49}
50
51// hot fix
52#[cosmwasm_schema::cw_serde]
53#[cfg_attr(feature = "boot", derive(boot_core::ExecuteFns))]
54pub enum ExecuteMsg {
55    /// Sets the admin
56    SetAdmin { admin: String },
57    /// Executes the provided messages if sender is whitelisted
58    ModuleAction { msgs: Vec<CosmosMsg<Empty>> },
59    /// Execute IBC action on Client
60    IbcAction { msgs: Vec<IbcClientMsg> },
61    /// Adds the provided address to whitelisted dapps
62    AddModule { module: String },
63    /// Removes the provided address from the whitelisted dapps
64    RemoveModule { module: String },
65    /// Updates the VAULT_ASSETS map
66    UpdateAssets {
67        to_add: Vec<UncheckedProxyAsset>,
68        to_remove: Vec<String>,
69    },
70}
71#[cosmwasm_schema::cw_serde]
72pub struct MigrateMsg {}
73
74#[cosmwasm_schema::cw_serde]
75#[derive(QueryResponses)]
76#[cfg_attr(feature = "boot", derive(boot_core::QueryFns))]
77pub enum QueryMsg {
78    /// Returns [`ConfigResponse`]
79    #[returns(ConfigResponse)]
80    Config {},
81    /// Returns the total value of all held assets
82    /// [`TotalValueResponse`]
83    #[returns(TotalValueResponse)]
84    TotalValue {},
85    /// Returns the value of amount OR one token of a specific asset
86    /// [`TokenValueResponse`]
87    #[returns(TokenValueResponse)]
88    TokenValue {
89        identifier: String,
90        amount: Option<Uint128>,
91    },
92    /// Returns the value of one specific asset
93    /// [`HoldingValueResponse`]
94    #[returns(HoldingValueResponse)]
95    HoldingValue { identifier: String },
96    /// Returns the amount of specified tokens this contract holds
97    /// [`HoldingAmountResponse`]
98    #[returns(HoldingAmountResponse)]
99    HoldingAmount { identifier: String },
100    /// Returns the VAULT_ASSETS value for the specified key
101    /// [`AssetConfigResponse`]
102    #[returns(AssetConfigResponse)]
103    AssetConfig { identifier: String },
104    /// Returns [`AssetsResponse`]
105    #[returns(AssetsResponse)]
106    Assets {
107        start_after: Option<String>,
108        limit: Option<u8>,
109    },
110    /// Returns [`ValidityResponse`]
111    #[returns(ValidityResponse)]
112    CheckValidity {},
113    /// Returns [`BaseAssetResponse`]
114    #[returns(BaseAssetResponse)]
115    BaseAsset {},
116}
117
118#[cosmwasm_schema::cw_serde]
119pub struct ConfigResponse {
120    pub modules: Vec<String>,
121}
122
123#[cosmwasm_schema::cw_serde]
124pub struct TotalValueResponse {
125    pub value: Uint128,
126}
127
128#[cosmwasm_schema::cw_serde]
129pub struct TokenValueResponse {
130    pub value: Uint128,
131}
132
133#[cosmwasm_schema::cw_serde]
134pub struct HoldingValueResponse {
135    pub value: Uint128,
136}
137
138#[cosmwasm_schema::cw_serde]
139pub struct ValidityResponse {
140    /// Assets that have unresolvable dependencies in their value calculation
141    pub unresolvable_assets: Option<Vec<AssetEntry>>,
142    /// Assets that are missing in the VAULT_ASSET map which caused some assets to be unresolvable.
143    pub missing_dependencies: Option<Vec<AssetEntry>>,
144}
145
146#[cosmwasm_schema::cw_serde]
147pub struct BaseAssetResponse {
148    pub base_asset: ProxyAsset,
149}
150
151#[cosmwasm_schema::cw_serde]
152pub struct HoldingAmountResponse {
153    pub amount: Uint128,
154}
155
156#[cosmwasm_schema::cw_serde]
157pub struct AssetConfigResponse {
158    pub proxy_asset: ProxyAsset,
159}
160
161#[cosmwasm_schema::cw_serde]
162pub struct AssetsResponse {
163    pub assets: Vec<(AssetEntry, ProxyAsset)>,
164}
165
166/// Query message to external contract to get asset value
167#[cosmwasm_schema::cw_serde]
168
169pub struct ValueQueryMsg {
170    pub asset: AssetEntry,
171    pub amount: Uint128,
172}
173/// External contract value response
174#[cosmwasm_schema::cw_serde]
175pub struct ExternalValueResponse {
176    pub value: Uint128,
177}