mars_core/red_bank/
msg.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Addr, Uint128};
5
6use cw20::Cw20ReceiveMsg;
7
8use crate::asset::Asset;
9use crate::math::decimal::Decimal;
10
11use super::interest_rate_models::InterestRateModelParams;
12
13#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
14pub struct InstantiateMsg {
15    /// Market configuration
16    pub config: CreateOrUpdateConfig,
17}
18
19#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
20#[serde(rename_all = "snake_case")]
21#[allow(clippy::large_enum_variant)]
22pub enum ExecuteMsg {
23    /// Implementation of cw20 receive msg
24    Receive(Cw20ReceiveMsg),
25
26    /// Update contract config (only owner can call)
27    UpdateConfig { config: CreateOrUpdateConfig },
28
29    /// Initialize an asset on the money market (only owner can call)
30    InitAsset {
31        /// Asset related info
32        asset: Asset,
33        /// Asset parameters
34        asset_params: InitOrUpdateAssetParams,
35        /// Asset symbol to be used in maToken name and description. If non is provided,
36        /// denom will be used for native and token symbol will be used for cw20. Mostly
37        /// useful for native assets since it's denom (e.g.: uluna, uusd) does not match it's
38        /// user facing symbol (LUNA, UST) which should be used in maToken's attributes
39        /// for the sake of consistency
40        asset_symbol: Option<String>,
41    },
42
43    /// Callback sent from maToken contract after instantiated
44    InitAssetTokenCallback {
45        /// Either the denom for a terra native asset or address for a cw20 token
46        /// in bytes
47        reference: Vec<u8>,
48    },
49
50    /// Update an asset on the money market (only owner can call)
51    UpdateAsset {
52        /// Asset related info
53        asset: Asset,
54        /// Asset parameters
55        asset_params: InitOrUpdateAssetParams,
56    },
57
58    /// Update uncollateralized loan limit for a given user and asset.
59    /// Overrides previous value if any. A limit of zero means no
60    /// uncollateralized limit and the debt in that asset needs to be
61    /// collateralized (only owner can call)
62    UpdateUncollateralizedLoanLimit {
63        /// Address that receives the credit
64        user_address: String,
65        /// Asset the user receives the credit in
66        asset: Asset,
67        /// Limit for the uncolateralize loan.
68        new_limit: Uint128,
69    },
70
71    /// Deposit Terra native coins. Deposited coins must be sent in the transaction
72    /// this call is made
73    DepositNative {
74        /// Denom used in Terra (e.g: uluna, uusd)
75        denom: String,
76        /// Address that will receive the maTokens
77        on_behalf_of: Option<String>,
78    },
79
80    /// Withdraw an amount of the asset burning an equivalent amount of maTokens.
81    /// If asset is a Terra native token, the amount sent to the user
82    /// is selected so that the sum of the transfered amount plus the stability tax
83    /// payed is equal to the withdrawn amount.
84    Withdraw {
85        /// Asset to withdraw
86        asset: Asset,
87        /// Amount to be withdrawn. If None is specified, the full maToken balance will be
88        /// burned in exchange for the equivalent asset amount.
89        amount: Option<Uint128>,
90        /// The address where the withdrawn amount is sent
91        recipient: Option<String>,
92    },
93
94    /// Borrow Terra native coins. If borrow allowed, amount is added to caller's debt
95    /// and sent to the address. If asset is a Terra native token, the amount sent
96    /// is selected so that the sum of the transfered amount plus the stability tax
97    /// payed is equal to the borrowed amount.
98    Borrow {
99        /// Asset to borrow
100        asset: Asset,
101        /// Amount to borrow
102        amount: Uint128,
103        /// The address where the borrowed amount is sent
104        recipient: Option<String>,
105    },
106
107    /// Repay Terra native coins loan. Coins used to repay must be sent in the
108    /// transaction this call is made.
109    RepayNative {
110        /// Denom used in Terra (e.g: uluna, uusd)
111        denom: String,
112        /// Repay the funds for the user
113        on_behalf_of: Option<String>,
114    },
115
116    /// Liquidate under-collateralized native loans. Coins used to repay must be sent in the
117    /// transaction this call is made.
118    LiquidateNative {
119        /// Collateral asset liquidator gets from the borrower
120        collateral_asset: Asset,
121        /// Denom used in Terra (e.g: uluna, uusd) of the debt asset
122        debt_asset_denom: String,
123        /// The address of the borrower getting liquidated
124        user_address: String,
125        /// Whether the liquidator gets liquidated collateral in maToken (true) or
126        /// the underlying collateral asset (false)
127        receive_ma_token: bool,
128    },
129
130    /// Update (enable / disable) asset as collateral for the caller
131    UpdateAssetCollateralStatus {
132        /// Asset to update status for
133        asset: Asset,
134        /// Option to enable (true) / disable (false) asset as collateral
135        enable: bool,
136    },
137
138    /// Called by liquidity token (maToken). Validate liquidity token transfer is valid
139    /// and update collateral status
140    FinalizeLiquidityTokenTransfer {
141        /// Token sender. Address is trusted because it should have been verified in
142        /// the token contract
143        sender_address: Addr,
144        /// Token recipient. Address is trusted because it should have been verified in
145        /// the token contract
146        recipient_address: Addr,
147        /// Sender's balance before the token transfer
148        sender_previous_balance: Uint128,
149        /// Recipient's balance before the token transfer
150        recipient_previous_balance: Uint128,
151        /// Transfer amount
152        amount: Uint128,
153    },
154}
155
156#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
157#[serde(rename_all = "snake_case")]
158pub enum ReceiveMsg {
159    /// Deposit sent cw20 tokens
160    DepositCw20 {
161        /// Deposit the funds for the user
162        on_behalf_of: Option<String>,
163    },
164    /// Repay sent cw20 tokens
165    RepayCw20 {
166        /// Repay the funds for the user
167        on_behalf_of: Option<String>,
168    },
169    /// Liquidate under-collateralized cw20 loan using the sent cw20 tokens.
170    LiquidateCw20 {
171        /// Collateral asset liquidator gets from the borrower
172        collateral_asset: Asset,
173        /// The address of the borrower getting liquidated
174        user_address: String,
175        /// Whether the liquidator gets liquidated collateral in maToken (true) or
176        /// the underlying collateral asset (false)
177        receive_ma_token: bool,
178    },
179}
180
181#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
182pub struct CreateOrUpdateConfig {
183    pub owner: Option<String>,
184    pub address_provider_address: Option<String>,
185    pub ma_token_code_id: Option<u64>,
186    pub close_factor: Option<Decimal>,
187}
188
189#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
190pub struct InitOrUpdateAssetParams {
191    /// Initial borrow rate
192    pub initial_borrow_rate: Option<Decimal>,
193
194    /// Portion of the borrow rate that is kept as protocol rewards
195    pub reserve_factor: Option<Decimal>,
196    /// Max uusd that can be borrowed per uusd of collateral when using the asset as collateral
197    pub max_loan_to_value: Option<Decimal>,
198    /// uusd amount in debt position per uusd of asset collateral that if surpassed makes the user's position liquidatable.
199    pub liquidation_threshold: Option<Decimal>,
200    /// Bonus amount of collateral liquidator get when repaying user's debt (Will get collateral
201    /// from user in an amount equal to debt repayed + bonus)
202    pub liquidation_bonus: Option<Decimal>,
203
204    /// Interest rate strategy to calculate borrow_rate and liquidity_rate
205    pub interest_rate_model_params: Option<InterestRateModelParams>,
206
207    /// If false cannot do any action (deposit/withdraw/borrow/repay/liquidate)
208    pub active: Option<bool>,
209    /// If false cannot deposit
210    pub deposit_enabled: Option<bool>,
211    /// If false cannot borrow
212    pub borrow_enabled: Option<bool>,
213}
214
215#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
216#[serde(rename_all = "snake_case")]
217pub enum QueryMsg {
218    /// Get config
219    Config {},
220
221    /// Get asset market
222    Market { asset: Asset },
223
224    /// Get a list of all markets. Returns MarketsListResponse
225    MarketsList {},
226
227    /// Get uncollateralized limit for given asset and user.
228    /// Returns UncollateralizedLoanLimitResponse
229    UncollateralizedLoanLimit { user_address: String, asset: Asset },
230
231    /// Get all debt positions for a user. Returns UsetDebtResponse
232    UserDebt { user_address: String },
233
234    /// Get user debt position for a specific asset. Returns UserAssetDebtResponse
235    UserAssetDebt { user_address: String, asset: Asset },
236
237    /// Get info about whether or not user is using each asset as collateral.
238    /// Returns UserCollateralResponse
239    UserCollateral { user_address: String },
240
241    /// Get user position. Returns UserPositionResponse
242    UserPosition { user_address: String },
243
244    /// Get liquidity scaled amount for a given underlying asset amount
245    /// (i.e: how much maTokens will get minted if the given amount is deposited)
246    ScaledLiquidityAmount { asset: Asset, amount: Uint128 },
247
248    /// Get equivalent scaled debt for a given underlying asset amount.
249    /// (i.e: how much scaled debt is added if the given amount is borrowed)
250    ScaledDebtAmount { asset: Asset, amount: Uint128 },
251
252    /// Get underlying asset amount for a given maToken balance.
253    UnderlyingLiquidityAmount {
254        ma_token_address: String,
255        amount_scaled: Uint128,
256    },
257
258    /// Get underlying debt amount for a given asset and scaled amounts.
259    /// (i.e: How much underlying asset needs to be repaid to cancel a given scaled debt
260    /// amount stored in state)
261    UnderlyingDebtAmount {
262        asset: Asset,
263        amount_scaled: Uint128,
264    },
265}