kujira_fin/
query.rs

1use cosmwasm_schema::cw_serde;
2use cosmwasm_std::{Addr, Decimal256, Timestamp, Uint128, Uint256};
3use cw20::Denom;
4use kujira_std::{Asset, Precision};
5
6/// Standard interface to query contract state
7#[cw_serde]
8pub enum QueryMsg {
9    /// Current config. Returns [ConfigResponse]
10    Config {},
11
12    /// Simulate an market swap based on the current order book. Returns [terraswap::pair::SimulationResponse]
13    Simulation { offer_asset: Asset },
14
15    /// Query a specific order by idx. Returns [OrderResponse]
16    Order { order_idx: Uint128 },
17
18    /// Paginate user orders. Upper limit of 30 per page. Returns [OrdersResponse]
19    OrdersByUser {
20        address: Addr,
21        start_after: Option<Uint128>,
22        limit: Option<u8>,
23    },
24
25    /// Query a specific price. Returns [PriceResponse]
26    Price { price: Decimal256 },
27
28    /// Returns the order totals of the current order book, paged out from the spread. Returns [BookResponse]
29    Book {
30        limit: Option<u8>,
31        offset: Option<u8>,
32    },
33}
34
35#[cw_serde]
36pub struct ConfigResponse {
37    /// See [InstantiateMsg::owner]
38    pub owner: Addr,
39
40    /// See [InstantiateMsg::denoms]
41    pub denoms: [Denom; 2],
42
43    /// See [InstantiateMsg::price_precision]
44    pub price_precision: Precision,
45
46    /// See [InstantiateMsg::decimal_delta]
47    pub decimal_delta: i8,
48
49    /// When a book is bootstrapping, it can accept orders but trades are not yet executed
50    pub is_bootstrapping: bool,
51
52    /// See [InstantiateMsg::fee_taker]    
53    pub fee_taker: Decimal256,
54
55    /// See [InstantiateMsg::fee_maker]
56    pub fee_maker: Decimal256,
57
58    /// See [InstantiateMsg::fee_address]
59    pub fee_address: Addr,
60}
61
62#[cw_serde]
63pub struct OrderResponse {
64    /// A unnique ID for the order
65    pub idx: Uint128,
66
67    /// The address used to place the order
68    pub owner: Addr,
69
70    /// THe quote price of this order
71    pub quote_price: Decimal256,
72
73    /// The denom offered
74    pub offer_denom: Denom,
75
76    /// The remaining order amount
77    pub offer_amount: Uint256,
78
79    /// Amount of filled order awaiting withdrawal
80    pub filled_amount: Uint256,
81
82    /// Timestamp of original creation
83    pub created_at: Timestamp,
84
85    /// Offer amount at time of creation
86    pub original_offer_amount: Uint256,
87}
88
89#[cw_serde]
90pub struct OrdersResponse {
91    pub orders: Vec<OrderResponse>,
92}
93
94#[cw_serde]
95pub struct PoolResponse {
96    /// THe quote price of this pool
97    pub quote_price: Decimal256,
98
99    /// The offer denom for this pool
100    pub offer_denom: Denom,
101
102    /// Total amount of all offers in this pool
103    pub total_offer_amount: Uint256,
104}
105
106#[cw_serde]
107pub struct PriceResponse {
108    /// The two offer pools for this price. The [PoolResponse::offer_denom] will match the order supplied in [InstantiateMsg::denoms]
109    pub pools: [PoolResponse; 2],
110}
111
112#[cw_serde]
113pub struct BookResponse {
114    pub base: Vec<PoolResponse>,
115    pub quote: Vec<PoolResponse>,
116}
117
118#[cw_serde]
119pub struct SimulationResponse {
120    pub return_amount: Uint256,
121    pub spread_amount: Uint256,
122    pub commission_amount: Uint256,
123}