abstract_core/core/
proxy.rs

1//! # Account Proxy
2//!
3//! `abstract_core::proxy` hold all the assets associated with the Account instance. It accepts Cosmos messages from whitelisted addresses and executes them.
4//!
5//! ## Description
6//! The proxy is part of the Core Account 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//! ## Price Sources
10//! [price sources](crate::objects::price_source) 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 price sources [`QueryMsg::TotalValue`] can be called to get the total holding value.
12
13use cosmwasm_schema::QueryResponses;
14use cosmwasm_std::{CosmosMsg, Empty, Uint128};
15use cw_asset::{Asset, AssetInfo};
16
17#[allow(unused_imports)]
18use crate::{
19    ibc_client::ExecuteMsg as IbcClientMsg,
20    objects::{
21        account::AccountId,
22        oracle::{AccountValue, Complexity},
23        price_source::{PriceSource, UncheckedPriceSource},
24        AssetEntry,
25    },
26};
27
28pub mod state {
29    use cosmwasm_std::Addr;
30    use cw_controllers::Admin;
31    use cw_storage_plus::Item;
32
33    pub use crate::objects::account::ACCOUNT_ID;
34    use crate::objects::{ans_host::AnsHost, common_namespace::ADMIN_NAMESPACE};
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}
43
44#[cosmwasm_schema::cw_serde]
45pub struct InstantiateMsg {
46    pub account_id: AccountId,
47    pub ans_host_address: String,
48    pub manager_addr: String,
49    pub base_asset: Option<AssetEntry>,
50}
51
52#[cosmwasm_schema::cw_serde]
53#[cfg_attr(feature = "interface", derive(cw_orch::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 a message and forward the Response data
60    ModuleActionWithData { msg: CosmosMsg<Empty> },
61    /// Execute IBC action on Client
62    IbcAction { msgs: Vec<IbcClientMsg> },
63    /// Adds the provided address to whitelisted dapps
64    AddModules { modules: Vec<String> },
65    /// Removes the provided address from the whitelisted dapps
66    RemoveModule { module: String },
67    /// Updates the VAULT_ASSETS map
68    UpdateAssets {
69        to_add: Vec<(AssetEntry, UncheckedPriceSource)>,
70        to_remove: Vec<AssetEntry>,
71    },
72}
73#[cosmwasm_schema::cw_serde]
74pub struct MigrateMsg {}
75
76#[cosmwasm_schema::cw_serde]
77#[derive(QueryResponses)]
78#[cfg_attr(feature = "interface", derive(cw_orch::QueryFns))]
79pub enum QueryMsg {
80    /// Contains the enabled modules
81    /// Returns [`ConfigResponse`]
82    #[returns(ConfigResponse)]
83    Config {},
84    /// Returns the total value of the assets held by this account
85    /// [`AccountValue`]
86    #[returns(AccountValue)]
87    TotalValue {},
88    /// Returns the value of one token with an optional amount set.
89    /// If amount is not set, the account's balance of the token is used.
90    /// [`TokenValueResponse`]
91    #[returns(TokenValueResponse)]
92    TokenValue { identifier: AssetEntry },
93    /// Returns the amount of specified tokens this contract holds
94    /// [`HoldingAmountResponse`]
95    #[returns(HoldingAmountResponse)]
96    HoldingAmount { identifier: AssetEntry },
97    /// Returns the oracle configuration value for the specified key
98    /// [`AssetConfigResponse`]
99    #[returns(AssetConfigResponse)]
100    AssetConfig { identifier: AssetEntry },
101    /// Returns [`AssetsConfigResponse`]
102    /// Human readable
103    #[returns(AssetsConfigResponse)]
104    AssetsConfig {
105        start_after: Option<AssetEntry>,
106        limit: Option<u8>,
107    },
108    /// Returns [`AssetsInfoResponse`]
109    /// Not human readable
110    #[returns(AssetsInfoResponse)]
111    AssetsInfo {
112        start_after: Option<AssetInfo>,
113        limit: Option<u8>,
114    },
115    /// Returns [`BaseAssetResponse`]
116    #[returns(BaseAssetResponse)]
117    BaseAsset {},
118}
119
120#[cosmwasm_schema::cw_serde]
121pub struct ConfigResponse {
122    pub modules: Vec<String>,
123}
124
125#[cosmwasm_schema::cw_serde]
126pub struct TokenValueResponse {
127    pub value: Uint128,
128}
129
130#[cosmwasm_schema::cw_serde]
131pub struct BaseAssetResponse {
132    pub base_asset: AssetInfo,
133}
134
135#[cosmwasm_schema::cw_serde]
136pub struct HoldingAmountResponse {
137    pub amount: Uint128,
138}
139
140/// Human readable config for a single asset
141#[cosmwasm_schema::cw_serde]
142pub struct AssetConfigResponse {
143    pub price_source: UncheckedPriceSource,
144}
145
146/// non-human readable asset configuration
147#[cosmwasm_schema::cw_serde]
148pub struct AssetsInfoResponse {
149    pub assets: Vec<(AssetInfo, OracleAsset)>,
150}
151
152/// Human readable asset configuration
153#[cosmwasm_schema::cw_serde]
154pub struct AssetsConfigResponse {
155    pub assets: Vec<(AssetEntry, UncheckedPriceSource)>,
156}
157
158#[cosmwasm_schema::cw_serde]
159pub struct OracleAsset {
160    pub price_source: PriceSource,
161    pub complexity: Complexity,
162}
163/// Query message to external contract to get asset value
164#[cosmwasm_schema::cw_serde]
165pub struct ValueQueryMsg {
166    pub asset: AssetInfo,
167    pub amount: Uint128,
168}
169/// External contract value response
170#[cosmwasm_schema::cw_serde]
171pub struct ExternalValueResponse {
172    pub value: Asset,
173}