kujira_orca/
query.rs

1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{Addr, Decimal, Uint128};
3use kujira_std::{Denom, Proof};
4
5/// Standard interface to query contract state
6#[cw_serde]
7pub enum QueryMsg {
8    /// Current config. Returns [ConfigResponse]
9    Config {},
10
11    /// Checks the validity of an address against the merkle root
12    Verify { address: Addr, proof: Proof },
13
14    /// Simulate a liquidation based on the current pool balances. Returns [SimulationResponse]
15    Simulate {
16        collateral_amount: Uint128,
17        #[deprecated(
18            note = "Ignored if None, must be equal to bid_denom if Some. Will be removed in later versions."
19        )]
20        #[serde(skip_serializing)]
21        repay_denom: Option<Denom>,
22        exchange_rate: Decimal,
23    },
24
25    /// Calculates the amount of collateral needed to return a required repay_amount,
26    /// based on the current pool balances. Returns [SimulationResponse]
27    SimulateReverse {
28        repay_amount: Uint128,
29        #[deprecated(
30            note = "Ignored if None, must be equal to bid_denom if Some. Will be removed in later versions."
31        )]
32        #[serde(skip_serializing)]
33        repay_denom: Option<Denom>,
34        exchange_rate: Decimal,
35    },
36
37    /// Given the current collateral and debt amounts, calculates the amount of collateral
38    /// that needs to be liquidated to bring the LTV to the target LTV. Returns [SimulationResponse]
39    SimulateWithTarget {
40        collateral_amount: Uint128,
41        debt_amount: Uint128,
42        target_ltv: Decimal,
43        #[deprecated(
44            note = "Ignored if None, must be equal to bid_denom if Some. Will be removed in later versions."
45        )]
46        #[serde(skip_serializing)]
47        repay_denom: Option<Denom>,
48        exchange_rate: Decimal,
49    },
50
51    /// Query a specific bid by idx. Returns [BidResponse]
52    Bid { bid_idx: Uint128 },
53
54    /// Paginate user bids. Upper limit of 30 per page. Returns [BidsResponse]
55    BidsByUser {
56        bidder: Addr,
57        start_after: Option<Uint128>,
58        limit: Option<u8>,
59    },
60
61    /// Query a specific bid pool. Returns [BidPoolResponse]
62    BidPool { bid_slot: u8 },
63
64    /// Paginate bid pools. Upper limit of 30 per page. Returns [BidPoolsResponse]
65    BidPools {
66        start_after: Option<u8>,
67        limit: Option<u8>,
68    },
69}
70
71#[cw_serde]
72pub struct ConfigResponse {
73    /// See [InstantiateMsg::owner]
74    pub owner: Addr,
75    /// See [ExecuteMsg::AddMarket]
76    pub markets: Vec<Addr>,
77    /// See [InstantiateMsg::bid_denom]
78    pub bid_denom: Denom,
79    /// See [InstantiateMsg::collateral_denom]
80    pub collateral_denom: Denom,
81    /// See [InstantiateMsg::bid_threshold]
82    pub bid_threshold: Uint128,
83    /// See [InstantiateMsg::max_slot]
84    pub max_slot: u8,
85    /// See [InstantiateMsg::premium_rate_per_slot]
86    pub premium_rate_per_slot: Decimal,
87    /// See [ExecuteMsg::UpdateConfig::closed_slots]
88    pub closed_slots: Vec<u8>,
89
90    /// See [InstantiateMsg::waiting_period]
91    pub waiting_period: u64,
92
93    /// See [InstantiateMsg::liquidation_fee]
94    pub liquidation_fee: Decimal,
95    /// See [InstantiateMsg::withdrawal_fee]
96    pub withdrawal_fee: Decimal,
97    /// See [InstantiateMsg::fee_address]
98    pub fee_address: Addr,
99}
100
101#[cw_serde]
102pub struct SimulationResponse {
103    /// A confirmation of the amount of collateral consumed in this liquidation.
104    /// The simulation will fail if there are insufficient bids to execute the
105    /// liquidation
106    pub collateral_amount: Uint128,
107
108    /// The simulated amount repaid to the market
109    pub repay_amount: Uint128,
110}
111
112#[cw_serde]
113pub struct BidResponse {
114    /// A unnique ID for the bid
115    pub idx: Uint128,
116
117    /// The premium slot selected in [ExecuteMsg::SubmitBid::premium_slot]
118    pub premium_slot: u8,
119
120    /// The address used to place the bid
121    pub bidder: Addr,
122
123    /// The remaining bid amount
124    pub amount: Uint128,
125    /// Allocated and unclaimed liquidated collateral
126    pub pending_liquidated_collateral: Uint128,
127    /// The epoch timestamp at which the bid can be activated.
128    /// IF None, it's already active
129    pub wait_end: Option<u64>,
130
131    /// An optionally selected delegate address who may activate the bid
132    /// on behalf of the bidder
133    pub delegate: Option<Addr>,
134
135    pub product_snapshot: Decimal,
136    pub sum_snapshot: Decimal,
137    pub epoch_snapshot: Uint128,
138    pub scale_snapshot: Uint128,
139}
140
141#[cw_serde]
142pub struct BidsResponse {
143    pub bids: Vec<BidResponse>,
144}
145
146#[cw_serde]
147pub struct BidPoolResponse {
148    /// Total amount of all active bids in this pool
149    pub total_bid_amount: Uint128,
150    /// The discount applied to bids in this pool
151    pub premium_rate: Decimal,
152
153    /// Whether or not this pool has been closed with [ExecuteMsg::UpdateConfig::closed_slots]
154    pub is_closed: bool,
155    pub sum_snapshot: Decimal,
156    pub product_snapshot: Decimal,
157    pub current_epoch: Uint128,
158    pub current_scale: Uint128,
159}
160
161#[cw_serde]
162pub struct BidPoolsResponse {
163    pub bid_pools: Vec<BidPoolResponse>,
164}