1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
use cosmwasm_schema::{cw_serde, QueryResponses};
use crate::asset::{Asset, AssetInfo, PairInfo};
use crate::pair::{
ConfigResponse, CumulativePricesResponse, PoolResponse, ReverseSimulationResponse,
SimulationResponse,
};
use cosmwasm_std::{Addr, Binary, Decimal, Uint128};
use cw20::Cw20ReceiveMsg;
/// The default swap slippage
pub const DEFAULT_SLIPPAGE: &str = "0.005";
/// The maximum allowed swap slippage
pub const MAX_ALLOWED_SLIPPAGE: &str = "0.5";
/// This structure stores the main config parameters for a constant product pair contract.
#[cw_serde]
pub struct Config {
/// General pair information (e.g pair type)
pub pair_info: PairInfo,
/// The factory contract address
pub factory_addr: Addr,
}
/// This structure describes the execute messages available in the contract.
#[cw_serde]
pub enum ExecuteMsg {
/// Receives a message of type [`Cw20ReceiveMsg`]
Receive(Cw20ReceiveMsg),
/// ProvideLiquidity allows someone to provide liquidity in the pool
ProvideLiquidity {
/// The assets available in the pool
assets: [Asset; 2],
/// The slippage tolerance that allows liquidity provision only if the price in the pool doesn't move too much
slippage_tolerance: Option<Decimal>,
/// Determines whether the LP tokens minted for the user is auto_staked in the Generator contract
auto_stake: Option<bool>,
/// The receiver of LP tokens
receiver: Option<String>,
},
/// Swap performs a swap in the pool
Swap {
offer_asset: Asset,
belief_price: Option<Decimal>,
max_spread: Option<Decimal>,
to: Option<String>,
},
/// Update the pair configuration
UpdateConfig { params: Binary },
/// Callback to process post-swap operation
AssertAndSend {
offer_asset: Asset,
/// Information about an asset stored in a [`AssetInfo`] struct
ask_asset_info: AssetInfo,
/// Receiver who should receive the funds
receiver: Addr,
/// Sender who initiated the transaction
sender: Addr,
},
}
/// This structure describes the query messages available in the contract.
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Returns information about a pair in an object of type [`super::asset::PairInfo`].
#[returns(PairInfo)]
Pair {},
/// Returns information about a pool in an object of type [`PoolResponse`].
#[returns(PoolResponse)]
Pool {},
/// Returns contract configuration settings in a custom [`ConfigResponse`] structure.
#[returns(ConfigResponse)]
Config {},
/// Returns information about the share of the pool in a vector that contains objects of type [`Asset`].
#[returns(Vec<Asset>)]
Share { amount: Uint128 },
/// Returns information about a swap simulation in a [`SimulationResponse`] object.
#[returns(SimulationResponse)]
Simulation { offer_asset: Asset },
/// Returns information about cumulative prices in a [`ReverseSimulationResponse`] object.
#[returns(ReverseSimulationResponse)]
ReverseSimulation { ask_asset: Asset },
/// Returns information about the cumulative prices in a [`CumulativePricesResponse`] object
#[returns(CumulativePricesResponse)]
CumulativePrices {},
}