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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
use cosmwasm_schema::{cw_serde, QueryResponses};
use cosmwasm_std::{Decimal, Uint128};
use cw20::Cw20ReceiveMsg;
use crate::asset::AssetInfo;
pub const MAX_SWAP_OPERATIONS: usize = 50;
/// This structure holds the parameters used for creating a contract.
#[cw_serde]
pub struct InstantiateMsg {
/// The astroport factory contract address
pub astroport_factory: String,
}
/// This enum describes a swap operation.
#[cw_serde]
pub enum SwapOperation {
/// Native swap
NativeSwap {
/// The name (denomination) of the native asset to swap from
offer_denom: String,
/// The name (denomination) of the native asset to swap to
ask_denom: String,
},
/// ASTRO swap
AstroSwap {
/// Information about the asset being swapped
offer_asset_info: AssetInfo,
/// Information about the asset we swap to
ask_asset_info: AssetInfo,
},
}
impl SwapOperation {
pub fn get_target_asset_info(&self) -> AssetInfo {
match self {
SwapOperation::NativeSwap { ask_denom, .. } => AssetInfo::NativeToken {
denom: ask_denom.clone(),
},
SwapOperation::AstroSwap { ask_asset_info, .. } => ask_asset_info.clone(),
}
}
}
/// This structure describes the execute messages available in the contract.
#[cw_serde]
pub enum ExecuteMsg {
/// Receive receives a message of type [`Cw20ReceiveMsg`] and processes it depending on the received template
Receive(Cw20ReceiveMsg),
/// ExecuteSwapOperations processes multiple swaps while mentioning the minimum amount of tokens to receive for the last swap operation
ExecuteSwapOperations {
operations: Vec<SwapOperation>,
minimum_receive: Option<Uint128>,
to: Option<String>,
max_spread: Option<Decimal>,
},
/// Internal use
/// ExecuteSwapOperation executes a single swap operation
ExecuteSwapOperation {
operation: SwapOperation,
to: Option<String>,
max_spread: Option<Decimal>,
single: bool,
},
}
#[cw_serde]
pub struct SwapResponseData {
pub return_amount: Uint128,
}
#[cw_serde]
pub enum Cw20HookMsg {
ExecuteSwapOperations {
/// A vector of swap operations
operations: Vec<SwapOperation>,
/// The minimum amount of tokens to get from a swap
minimum_receive: Option<Uint128>,
/// The recipient
to: Option<String>,
/// Max spread
max_spread: Option<Decimal>,
},
}
/// This structure describes the query messages available in the contract.
#[cw_serde]
#[derive(QueryResponses)]
pub enum QueryMsg {
/// Config returns configuration parameters for the contract using a custom [`ConfigResponse`] structure
#[returns(ConfigResponse)]
Config {},
/// SimulateSwapOperations simulates multi-hop swap operations
#[returns(SimulateSwapOperationsResponse)]
SimulateSwapOperations {
/// The amount of tokens to swap
offer_amount: Uint128,
/// The swap operations to perform, each swap involving a specific pool
operations: Vec<SwapOperation>,
},
#[returns(Uint128)]
ReverseSimulateSwapOperations {
/// The amount of tokens one is willing to receive
ask_amount: Uint128,
/// The swap operations to perform, each swap involving a specific pool
operations: Vec<SwapOperation>,
},
}
/// This structure describes a custom struct to return a query response containing the base contract configuration.
#[cw_serde]
pub struct ConfigResponse {
/// The Astroport factory contract address
pub astroport_factory: String,
}
/// This structure describes a custom struct to return a query response containing the end amount of a swap simulation
#[cw_serde]
pub struct SimulateSwapOperationsResponse {
/// The amount of tokens received in a swap simulation
pub amount: Uint128,
}