cw_vault_standard/
msg.rs

1#[cfg(feature = "force-unlock")]
2use crate::extensions::force_unlock::ForceUnlockExecuteMsg;
3#[cfg(feature = "keeper")]
4use crate::extensions::keeper::{KeeperExecuteMsg, KeeperQueryMsg};
5#[cfg(feature = "lockup")]
6use crate::extensions::lockup::{LockupExecuteMsg, LockupQueryMsg};
7
8use cosmwasm_schema::{cw_serde, QueryResponses};
9use cosmwasm_std::{to_json_binary, Coin, CosmosMsg, Empty, StdResult, Uint128, WasmMsg};
10use schemars::JsonSchema;
11
12/// The default ExecuteMsg variants that all vaults must implement.
13/// This enum can be extended with additional variants by defining an extension
14/// enum and then passing it as the generic argument `T` to this enum.
15#[cw_serde]
16pub enum VaultStandardExecuteMsg<T = ExtensionExecuteMsg> {
17    /// Called to deposit into the vault. Native assets are passed in the funds
18    /// parameter.
19    Deposit {
20        /// The amount of base tokens to deposit.
21        #[deprecated(
22            since = "0.4.1",
23            note = "This field will be removed in the next version. The amount \
24            of deposited assets should instead be read from the actual sent funds."
25        )]
26        amount: Uint128,
27        /// The optional recipient of the vault token. If not set, the caller
28        /// address will be used instead.
29        recipient: Option<String>,
30    },
31
32    /// Called to redeem vault tokens and receive assets back from the vault.
33    /// The native vault token must be passed in the funds parameter, unless the
34    /// lockup extension is called, in which case the vault token has already
35    /// been passed to ExecuteMsg::Unlock.
36    Redeem {
37        /// An optional field containing which address should receive the
38        /// withdrawn base tokens. If not set, the caller address will be
39        /// used instead.
40        recipient: Option<String>,
41        /// The amount of vault tokens sent to the contract. In the case that
42        /// the vault token is a Cosmos native denom, we of course have this
43        /// information in info.funds, but if the vault implements the
44        /// Cw4626 API, then we need this argument. We figured it's
45        /// better to have one API for both types of vaults, so we
46        /// require this argument.
47        #[deprecated(
48            since = "0.4.1",
49            note = "This field will be removed in the next version. The amount \
50            of vault tokens should instead be read from the actual amount of sent vault tokens."
51        )]
52        amount: Uint128,
53    },
54
55    /// Called to execute functionality of any enabled extensions.
56    VaultExtension(T),
57}
58
59impl VaultStandardExecuteMsg {
60    /// Convert a [`VaultStandardExecuteMsg`] into a [`CosmosMsg`].
61    pub fn into_cosmos_msg(self, contract_addr: String, funds: Vec<Coin>) -> StdResult<CosmosMsg> {
62        Ok(WasmMsg::Execute {
63            contract_addr,
64            msg: to_json_binary(&self)?,
65            funds,
66        }
67        .into())
68    }
69}
70
71/// Contains ExecuteMsgs of all enabled extensions. To enable extensions defined
72/// outside of this crate, you can define your own `ExtensionExecuteMsg` type
73/// in your contract crate and pass it in as the generic parameter to ExecuteMsg
74#[cw_serde]
75pub enum ExtensionExecuteMsg {
76    #[cfg(feature = "keeper")]
77    Keeper(KeeperExecuteMsg),
78    #[cfg(feature = "lockup")]
79    Lockup(LockupExecuteMsg),
80    #[cfg(feature = "force-unlock")]
81    ForceUnlock(ForceUnlockExecuteMsg),
82}
83
84/// The default QueryMsg variants that all vaults must implement.
85/// This enum can be extended with additional variants by defining an extension
86/// enum and then passing it as the generic argument `T` to this enum.
87#[cw_serde]
88#[derive(QueryResponses)]
89pub enum VaultStandardQueryMsg<T = ExtensionQueryMsg>
90where
91    T: JsonSchema,
92{
93    /// Returns `VaultStandardInfoResponse` with information on the version of
94    /// the vault standard used as well as any enabled extensions.
95    #[returns(VaultStandardInfoResponse)]
96    VaultStandardInfo {},
97
98    /// Returns `VaultInfoResponse` representing vault requirements, lockup, &
99    /// vault token denom.
100    #[returns(VaultInfoResponse)]
101    Info {},
102
103    /// Returns `Uint128` amount of vault tokens that will be returned for the
104    /// passed in `amount` of base tokens.
105    ///
106    /// Allows an on-chain or off-chain user to simulate the effects of their
107    /// deposit at the current block, given current on-chain conditions.
108    ///
109    /// Must return as close to and no more than the exact amount of vault
110    /// tokens that would be minted in a deposit call in the same transaction.
111    /// I.e. Deposit should return the same or more vault tokens as
112    /// PreviewDeposit if called in the same transaction.
113    #[deprecated(
114        since = "0.4.1",
115        note = "PreviewDeposit and PreviewRedeem turned out to be too difficult to implement in most cases. We recommend to use transaction simulation from non-contract clients such as frontends."
116    )]
117    #[returns(Uint128)]
118    PreviewDeposit {
119        /// The amount of base tokens to preview depositing.
120        amount: Uint128,
121    },
122
123    /// Returns `Uint128` amount of base tokens that would be withdrawn in
124    /// exchange for redeeming `amount` of vault tokens.
125    ///
126    /// Allows an on-chain or off-chain user to simulate the effects of their
127    /// redeem at the current block, given current on-chain conditions.
128    ///
129    /// Must return as close to and no more than the exact amount of base tokens
130    /// that would be withdrawn in a redeem call in the same transaction.
131    #[deprecated(
132        since = "0.4.1",
133        note = "PreviewDeposit and PreviewRedeem turned out to be too difficult to implement in most cases. We recommend to use transaction simulation from non-contract clients such as frontends."
134    )]
135    #[returns(Uint128)]
136    PreviewRedeem {
137        /// The amount of vault tokens to preview redeeming.
138        amount: Uint128,
139    },
140
141    /// Returns the amount of assets managed by the vault denominated in base
142    /// tokens. Useful for display purposes, and does not have to confer the
143    /// exact amount of base tokens.
144    #[returns(Uint128)]
145    TotalAssets {},
146
147    /// Returns `Uint128` total amount of vault tokens in circulation.
148    #[returns(Uint128)]
149    TotalVaultTokenSupply {},
150
151    /// Returns the exchange rate of vault tokens quoted in terms of the
152    /// supplied quote_denom. Returns a `Decimal` containing the amount of
153    /// `quote_denom` assets that can be exchanged for 1 unit of vault
154    /// tokens.
155    ///
156    /// May return an error if the quote denom is not supported by the vault.
157    #[returns(cosmwasm_std::Decimal)]
158    VaultTokenExchangeRate {
159        /// The quote denom to quote the exchange rate in.
160        quote_denom: String,
161    },
162
163    /// The amount of vault tokens that the vault would exchange for the amount
164    /// of assets provided, in an ideal scenario where all the conditions
165    /// are met.
166    ///
167    /// Useful for display purposes and does not have to confer the exact amount
168    /// of vault tokens returned by the vault if the passed in assets were
169    /// deposited. This calculation should not reflect the "per-user"
170    /// price-per-share, and instead should reflect the "average-user’s"
171    /// price-per-share, meaning what the average user should expect to see
172    /// when exchanging to and from.
173    #[returns(Uint128)]
174    ConvertToShares {
175        /// The amount of base tokens to convert to vault tokens.
176        amount: Uint128,
177    },
178
179    /// Returns the amount of base tokens that the Vault would exchange for
180    /// the `amount` of vault tokens provided, in an ideal scenario where all
181    /// the conditions are met.
182    ///
183    /// Useful for display purposes and does not have to confer the exact amount
184    /// of assets returned by the vault if the passed in vault tokens were
185    /// redeemed. This calculation should not reflect the "per-user"
186    /// price-per-share, and instead should reflect the "average-user’s"
187    /// price-per-share, meaning what the average user should expect to see
188    /// when exchanging to and from.
189    #[returns(Uint128)]
190    ConvertToAssets {
191        /// The amount of vault tokens to convert to base tokens.
192        amount: Uint128,
193    },
194
195    /// Handle queries of any enabled extensions.
196    #[returns(Empty)]
197    VaultExtension(T),
198}
199
200/// Contains QueryMsgs of all enabled extensions. To enable extensions defined
201/// outside of this crate, you can define your own `ExtensionQueryMsg` type
202/// in your contract crate and pass it in as the generic parameter to QueryMsg
203#[cw_serde]
204pub enum ExtensionQueryMsg {
205    #[cfg(feature = "keeper")]
206    Keeper(KeeperQueryMsg),
207    #[cfg(feature = "lockup")]
208    Lockup(LockupQueryMsg),
209}
210
211/// Struct returned from QueryMsg::VaultStandardInfo with information about the
212/// used version of the vault standard and any extensions used.
213///
214/// This struct should be stored as an Item under the `vault_standard_info` key,
215/// so that other contracts can do a RawQuery and read it directly from storage
216/// instead of needing to do a costly SmartQuery.
217#[cw_serde]
218pub struct VaultStandardInfoResponse {
219    /// The version of the vault standard used by the vault as a semver
220    /// compliant string. E.g. "1.0.0" or "1.2.3-alpha.1"
221    pub version: String,
222    /// A list of vault standard extensions used by the vault.
223    /// E.g. ["lockup", "keeper"]
224    pub extensions: Vec<String>,
225}
226
227/// Returned by QueryMsg::Info and contains information about this vault
228#[cw_serde]
229pub struct VaultInfoResponse {
230    /// The token that is accepted for deposits, withdrawals and used for
231    /// accounting in the vault. The denom if it is a native token and the
232    /// contract address if it is a cw20 token.
233    pub base_token: String,
234    /// Vault token. The denom if it is a native token and the contract address
235    /// if it is a cw20 token.
236    pub vault_token: String,
237}