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