Skip to main content

liquid_finance/swap/
query_msg.rs

1use cosmwasm_std::{Uint128, Decimal};
2use cosmwasm_schema::QueryResponses;
3use schemars::JsonSchema;
4use serde::{Deserialize, Serialize};
5
6use crate::swap_linked_list::{LinkedList, NodeWithId};
7
8#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
9#[serde(rename_all = "snake_case")]
10pub enum AssetInfo {
11    Token { contract_addr: String },
12    NativeToken { denom: String },
13}
14
15#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
16pub struct Asset {
17    pub info: AssetInfo,
18    pub amount: Uint128,
19}
20
21#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema, QueryResponses)]
22#[serde(rename_all = "snake_case")]
23pub enum QueryMsg {
24    /// Returns the claimable swapped liquid token and native token rewards the address can claim.
25    #[returns(RewardsResponse)]
26    ClaimableOf { address: String },
27    /// Returns the configuration of the contract.
28    #[returns(ConfigResponse)]
29    ConfigInfo {},
30    ///  Returns the staking status of the contract.
31    #[returns(StatusResponse)]
32    StatusInfo {},
33    /// Returns the first 50 orders in the liquidity queue.
34    #[returns(OrderBookResponse)]
35    OrderBook {},
36    /// Returns the order info of the address in the liquidity queue.
37    #[returns(OrderInfoOfResponse)]
38    OrderInfoOf { address: String },
39    /// Return the amount of native token swapper should get.
40    #[returns(SimulationResponse)]
41    Simulation { offer_asset: Asset },
42    /// Return the amount of liquid token swapper should put in to get an ask_asset
43    /// amount of native token.
44    #[returns(ReverseSimulationResponse)]
45    ReverseSimulation { ask_asset: Asset },
46}
47
48#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
49pub struct ConfigResponse {
50    /// should be multi-sig, is able to update the config
51    pub admin: String,
52    /// should be single-sig, is able to pause the contract
53    pub pause_admin: String,
54    /// This is the denomination we can stake (and only one we accept for payments)
55    pub bond_denom: String,
56    /// Liquid token address
57    pub liquid_token_addr: String,
58    /// Staking manager contract address
59    pub staking_manager_addr: String,
60    /// Liquid Treasury contract address
61    pub treasury_contract_addr: String,
62    /// This is the team wallet address
63    pub team_wallet_addr: String,
64    /// Swap fee
65    pub swap_fee_percentage: u16,
66    /// team percentage of swap fee
67    pub team_percentage: u16,
68    /// Minimal amount of new native token being added for liquidity
69    pub liquidity_min: Uint128,
70    /// contract state (active/paused)
71    pub contract_state: bool,
72}
73
74#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
75pub struct StatusResponse {
76    /// issued is how many rewards shares this contract has issued
77    pub issued: Uint128,
78    /// claims is how many tokens need to be reserved paying back those who unbonded
79    pub claims: Uint128,
80    /// available native token balance of this contract
81    pub balance: Uint128,
82    /// available native token balance to claim
83    pub unclaimed_balance: Uint128,
84    /// ratio of balance / issued (or how many native tokens that one rewards share is nominally worth)
85    pub ratio: Decimal,
86    /// total liquidity supply of this contract
87    pub liquidity: Uint128,
88}
89
90#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
91pub struct OrderInfoOfResponse {
92    /// issued is how many rewards shares in the pool this address has
93    pub issued: Uint128,
94    /// native is how many native tokens in the pool this address has
95    pub native: Uint128,
96    /// the block height shows when this address added native token to the pool
97    pub height: u64,
98    /// node_id is the id of adddress order in the linked-list
99    pub node_id: u64,
100    /// last deposit
101    pub last_deposit: Uint128,
102}
103
104#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
105pub struct OrderBookResponse {
106    pub state: LinkedList,
107    pub queue: Vec<NodeWithId>,
108}
109
110#[derive(Serialize, Deserialize, Clone, PartialEq, JsonSchema, Debug)]
111pub struct RewardsResponse {
112    pub staked_token: Uint128,
113    pub native_token: Uint128,
114}
115
116/// SimulationResponse returns swap simulation response
117#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
118pub struct SimulationResponse {
119    pub return_amount: Uint128,
120    pub spread_amount: Uint128,
121    pub commission_amount: Uint128,
122}
123
124/// ReverseSimulationResponse returns reverse swap simulation response
125#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
126pub struct ReverseSimulationResponse {
127    pub offer_amount: Uint128,
128    pub spread_amount: Uint128,
129    pub commission_amount: Uint128,
130}