white_whale_std/vault_network/
vault.rs

1use crate::fee::VaultFee;
2use crate::pool_network::asset::{Asset, AssetInfo};
3use cosmwasm_schema::{cw_serde, QueryResponses};
4use cosmwasm_std::{Addr, Binary, Uint128};
5
6#[cw_serde]
7pub struct InstantiateMsg {
8    /// The owner of the contract.
9    pub owner: String,
10    /// The asset info the vault should manage.
11    pub asset_info: AssetInfo,
12    /// The code ID of the liquidity token to instantiate
13    pub token_id: u64,
14    /// The fees used for the vault
15    pub vault_fees: VaultFee,
16    /// The address of the fee collector
17    pub fee_collector_addr: String,
18    /// If true, the vault will use the token factory to create the LP token. If false, it will
19    /// use a cw20 token instead.
20    pub token_factory_lp: bool,
21}
22
23/// The callback messages available. Only callable by the vault contract itself.
24#[cw_serde]
25pub enum CallbackMsg {
26    AfterTrade {
27        old_balance: Uint128,
28        loan_amount: Uint128,
29    },
30}
31
32#[cw_serde]
33pub enum Cw20HookMsg {
34    /// Withdraws a given amount from the vault.
35    Withdraw {},
36}
37
38#[cw_serde]
39pub struct Cw20ReceiveMsg {
40    pub sender: String,
41    pub amount: Uint128,
42    pub msg: Binary,
43}
44
45#[cw_serde]
46pub struct UpdateConfigParams {
47    /// If users should be allowed to perform flash-loans.
48    pub flash_loan_enabled: Option<bool>,
49    /// If users should be able to deposit funds to the contract.
50    pub deposit_enabled: Option<bool>,
51    /// if users should be able to withdraw funds from the contract.
52    pub withdraw_enabled: Option<bool>,
53    /// The new owner of the contract.
54    pub new_owner: Option<String>,
55    /// The new fees used for the vault
56    pub new_vault_fees: Option<VaultFee>,
57    /// The new address of the fee collector
58    pub new_fee_collector_addr: Option<String>,
59}
60
61#[cw_serde]
62pub enum ExecuteMsg {
63    /// Deposits a given amount into the vault.
64    Deposit {
65        amount: Uint128,
66    },
67    /// Withdraws from the vault. Used when the LP token is a token factory token.
68    Withdraw {},
69    /// Flash-loans a given amount from the vault.
70    FlashLoan {
71        amount: Uint128,
72        msg: Binary,
73    },
74    /// Collects the Protocol fees
75    CollectProtocolFees {},
76    /// Updates the configuration of the contract.
77    /// If a field is not specified, it will not be modified.
78    UpdateConfig(UpdateConfigParams),
79    Receive(Cw20ReceiveMsg),
80    Callback(CallbackMsg),
81}
82
83#[cw_serde]
84#[derive(QueryResponses)]
85pub enum QueryMsg {
86    /// Retrieves the configuration of the contract.
87    #[returns(Config)]
88    Config {},
89    /// Retrieves the share of the assets stored in the vault that a given `amount` of lp tokens is entitled to.
90    #[returns(Uint128)]
91    Share { amount: Uint128 },
92    /// Retrieves the protocol fees that have been collected. If `all_time` is `true`, will return the all time collected fees.
93    #[returns(ProtocolFeesResponse)]
94    ProtocolFees { all_time: bool },
95    /// Retrieves the fees that have been burned by the vault.
96    #[returns(ProtocolFeesResponse)]
97    BurnedFees {},
98    /// Retrieves the [`Uint128`] amount that must be sent back to the contract to pay off a loan taken out.
99    #[returns(PaybackAmountResponse)]
100    GetPaybackAmount { amount: Uint128 },
101}
102
103#[cw_serde]
104pub struct MigrateMsg {}
105
106/// The `reply` code ID for the submessage after instantiating the LP token.
107pub const INSTANTIATE_LP_TOKEN_REPLY_ID: u64 = 1;
108
109#[cw_serde]
110pub struct ProtocolFeesResponse {
111    pub fees: Asset,
112}
113
114#[cw_serde]
115pub struct Config {
116    /// The owner of the vault
117    pub owner: Addr,
118    /// The asset info the vault manages
119    pub asset_info: AssetInfo,
120    /// If flash-loans are enabled
121    pub flash_loan_enabled: bool,
122    /// If deposits are enabled
123    pub deposit_enabled: bool,
124    /// If withdrawals are enabled
125    pub withdraw_enabled: bool,
126    /// The LP asset
127    pub lp_asset: AssetInfo,
128    /// The address of the fee collector
129    pub fee_collector_addr: Addr,
130    /// The fees associated with this vault
131    pub fees: VaultFee,
132}
133
134#[cw_serde]
135pub struct PaybackAmountResponse {
136    /// The total amount that must be returned. Equivalent to `amount` + `protocol_fee` + `flash_loan_fee`+ `burn_fee`.
137    pub payback_amount: Uint128,
138    /// The amount of fee paid to the protocol
139    pub protocol_fee: Uint128,
140    /// The amount of fee paid to vault holders
141    pub flash_loan_fee: Uint128,
142    /// The amount of fee to be burned
143    pub burn_fee: Uint128,
144}