Skip to main content

solid_moneymarket/
liquidation_queue.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Decimal256, Uint128, Uint256};
5use cw20::Cw20ReceiveMsg;
6
7use crate::tokens::TokensHuman;
8
9#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
10pub struct InstantiateMsg {
11    pub owner: String,
12    pub oracle_contract: String,
13    pub stable_contract: String,
14    /// borrow_amount / borrow_limit must always be bigger than  
15    /// safe_ratio.
16    pub safe_ratio: Decimal256,
17    /// Fee applied to executed bids
18    /// Sent to Overseer interest buffer
19    pub bid_fee: Decimal256,
20    /// Fee applied to executed bids
21    /// Sent to the address executing the liquidation
22    pub liquidator_fee: Decimal256,
23    /// Liquidation threshold amount in stable denom.
24    /// When the current collaterals value is smaller than
25    /// the threshold, all collaterals will be liquidated
26    pub liquidation_threshold: Uint256,
27    /// Valid oracle price timeframe
28    pub price_timeframe: u64,
29    /// Time period that needs to pass for a bid to be activated (seconds)
30    pub waiting_period: u64,
31    pub overseer: String,
32}
33
34#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
35#[serde(rename_all = "snake_case")]
36pub enum ExecuteMsg {
37    Receive(Cw20ReceiveMsg),
38    UpdateConfig {
39        owner: Option<String>,
40        oracle_contract: Option<String>,
41        safe_ratio: Option<Decimal256>,
42        bid_fee: Option<Decimal256>,
43        liquidator_fee: Option<Decimal256>,
44        liquidation_threshold: Option<Uint256>,
45        price_timeframe: Option<u64>,
46        waiting_period: Option<u64>,
47        overseer: Option<String>,
48    },
49    /// Owner operation to whitelist a new collateral
50    WhitelistCollateral {
51        collateral_token: String,
52        bid_threshold: Uint256,
53        max_slot: u8,
54        premium_rate_per_slot: Decimal256,
55    },
56    UpdateCollateralInfo {
57        collateral_token: String,
58        bid_threshold: Option<Uint256>,
59        max_slot: Option<u8>,
60    },
61
62    /// Withdraw a bid
63    RetractBid {
64        bid_idx: Uint128,
65        amount: Option<Uint256>,
66    },
67    /// After waiting_period expires, user can activate the bid
68    ActivateBids {
69        collateral_token: String,
70        bids_idx: Option<Vec<Uint128>>,
71    },
72    /// Claim the corresponding amount of liquidated collateral
73    ClaimLiquidations {
74        collateral_token: String,
75        bids_idx: Option<Vec<Uint128>>,
76    },
77}
78
79#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
80#[serde(rename_all = "snake_case")]
81pub enum Cw20HookMsg {
82    /// Custody interface to liquidate the sent collateral
83    ExecuteBid {
84        liquidator: String, // Legacy parameter, ignored
85        fee_address: Option<String>,
86        repay_address: Option<String>,
87        borrower_address: Option<String>,
88    },
89    SubmitBid {
90        collateral_token: String,
91        premium_slot: u8,
92    },
93}
94
95#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
96#[serde(rename_all = "snake_case")]
97pub enum QueryMsg {
98    Config {},
99    LiquidationAmount {
100        borrow_amount: Uint256,
101        borrow_limit: Uint256,
102        collaterals: TokensHuman,
103        collateral_prices: Vec<Decimal256>,
104    },
105    CollateralInfo {
106        collateral_token: String,
107    },
108    Bid {
109        bid_idx: Uint128,
110    },
111    BidsByUser {
112        collateral_token: String,
113        bidder: String,
114        start_after: Option<Uint128>,
115        limit: Option<u8>,
116    },
117    BidPool {
118        collateral_token: String,
119        bid_slot: u8,
120    },
121    BidPoolsByCollateral {
122        collateral_token: String,
123        start_after: Option<u8>,
124        limit: Option<u8>,
125    },
126}
127
128#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
129pub struct ConfigResponse {
130    pub owner: String,
131    pub oracle_contract: String,
132    pub stable_contract: String,
133    pub safe_ratio: Decimal256,
134    pub bid_fee: Decimal256,
135    pub liquidator_fee: Decimal256,
136    pub liquidation_threshold: Uint256,
137    pub price_timeframe: u64,
138    pub waiting_period: u64,
139    pub overseer: String,
140}
141
142#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
143pub struct LiquidationAmountResponse {
144    pub collaterals: TokensHuman,
145}
146
147#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
148pub struct BidResponse {
149    pub idx: Uint128,
150    pub collateral_token: String,
151    pub premium_slot: u8,
152    pub bidder: String,
153    pub amount: Uint256,
154    pub product_snapshot: Decimal256,
155    pub sum_snapshot: Decimal256,
156    pub pending_liquidated_collateral: Uint256,
157    pub wait_end: Option<u64>,
158    pub epoch_snapshot: Uint128,
159    pub scale_snapshot: Uint128,
160}
161
162#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
163pub struct BidsResponse {
164    pub bids: Vec<BidResponse>,
165}
166
167#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
168pub struct BidPoolResponse {
169    pub sum_snapshot: Decimal256,
170    pub product_snapshot: Decimal256,
171    pub total_bid_amount: Uint256,
172    pub premium_rate: Decimal256,
173    pub current_epoch: Uint128,
174    pub current_scale: Uint128,
175}
176
177#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
178pub struct CollateralInfoResponse {
179    pub collateral_token: String,
180    pub bid_threshold: Uint256,
181    pub max_slot: u8,
182    pub premium_rate_per_slot: Decimal256,
183}
184
185#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
186pub struct BidPoolsResponse {
187    pub bid_pools: Vec<BidPoolResponse>,
188}
189
190#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
191#[serde(rename_all = "snake_case")]
192pub struct MigrateMsg {}