Skip to main content

solid_moneymarket/
liquidation.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Decimal256, 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_denom: 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    /// Maximum fee applied to liquidated collaterals
21    /// Sent to liquidator as incentive
22    pub max_premium_rate: 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}
30
31#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
32#[serde(rename_all = "snake_case")]
33pub enum ExecuteMsg {
34    Receive(Cw20ReceiveMsg),
35    UpdateConfig {
36        owner: Option<String>,
37        oracle_contract: Option<String>,
38        stable_denom: Option<String>,
39        safe_ratio: Option<Decimal256>,
40        bid_fee: Option<Decimal256>,
41        max_premium_rate: Option<Decimal256>,
42        liquidation_threshold: Option<Uint256>,
43        price_timeframe: Option<u64>,
44    },
45    SubmitBid {
46        collateral_token: String,
47        premium_rate: Decimal256,
48    },
49    RetractBid {
50        collateral_token: String,
51        amount: Option<Uint256>,
52    },
53}
54
55#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
56#[serde(rename_all = "snake_case")]
57pub enum Cw20HookMsg {
58    ExecuteBid {
59        liquidator: String,
60        fee_address: Option<String>,
61        repay_address: Option<String>,
62        borrower_address: Option<String>,
63    },
64}
65#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
66#[serde(rename_all = "snake_case")]
67
68pub enum MarketExecuteMsg {
69    RepayStableFromLiquidation { borrower: String },
70}
71
72#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
73#[serde(rename_all = "snake_case")]
74pub enum QueryMsg {
75    Config {},
76    LiquidationAmount {
77        borrow_amount: Uint256,
78        borrow_limit: Uint256,
79        collaterals: TokensHuman,
80        collateral_prices: Vec<Decimal256>,
81    },
82    Bid {
83        collateral_token: String,
84        bidder: String,
85    },
86    BidsByUser {
87        bidder: String,
88        start_after: Option<String>,
89        limit: Option<u32>,
90    },
91    BidsByCollateral {
92        collateral_token: String,
93        start_after: Option<String>,
94        limit: Option<u32>,
95    },
96}
97
98// We define a custom struct for each query response
99#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
100pub struct ConfigResponse {
101    pub owner: String,
102    pub oracle_contract: String,
103    pub stable_denom: String,
104    pub safe_ratio: Decimal256,
105    pub bid_fee: Decimal256,
106    pub max_premium_rate: Decimal256,
107    pub liquidation_threshold: Uint256,
108    pub price_timeframe: u64,
109}
110
111// We define a custom struct for each query response
112#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
113pub struct LiquidationAmountResponse {
114    pub collaterals: TokensHuman,
115}
116
117// We define a custom struct for each query response
118#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
119pub struct BidResponse {
120    pub collateral_token: String,
121    pub bidder: String,
122    pub amount: Uint256,
123    pub premium_rate: Decimal256,
124}
125
126// We define a custom struct for each query response
127#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, Eq, JsonSchema)]
128pub struct BidsResponse {
129    pub bids: Vec<BidResponse>,
130}