astroport_types/
router.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4use cosmwasm_std::{Addr, Decimal, Uint128};
5use cw20::Cw20ReceiveMsg;
6
7use crate::asset::AssetInfo;
8
9pub const MAX_SWAP_OPERATIONS: usize = 50;
10
11#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
12pub struct InstantiateMsg {
13    pub astroport_factory: String,
14}
15
16#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
17#[serde(rename_all = "snake_case")]
18pub enum SwapOperation {
19    NativeSwap {
20        offer_denom: String,
21        ask_denom: String,
22    },
23    AstroSwap {
24        offer_asset_info: AssetInfo,
25        ask_asset_info: AssetInfo,
26    },
27}
28
29impl SwapOperation {
30    pub fn get_target_asset_info(&self) -> AssetInfo {
31        match self {
32            SwapOperation::NativeSwap { ask_denom, .. } => AssetInfo::NativeToken {
33                denom: ask_denom.clone(),
34            },
35            SwapOperation::AstroSwap { ask_asset_info, .. } => ask_asset_info.clone(),
36        }
37    }
38}
39
40#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
41#[serde(rename_all = "snake_case")]
42pub enum ExecuteMsg {
43    Receive(Cw20ReceiveMsg),
44    /// Execute multiple BuyOperation
45    ExecuteSwapOperations {
46        operations: Vec<SwapOperation>,
47        minimum_receive: Option<Uint128>,
48        to: Option<Addr>,
49        max_spread: Option<Decimal>,
50    },
51
52    /// Internal use
53    /// Swap all offer tokens to ask token
54    ExecuteSwapOperation {
55        operation: SwapOperation,
56        to: Option<String>,
57        max_spread: Option<Decimal>,
58    },
59    /// Internal use
60    /// Check the swap amount is exceed minimum_receive
61    AssertMinimumReceive {
62        asset_info: AssetInfo,
63        prev_balance: Uint128,
64        minimum_receive: Uint128,
65        receiver: String,
66    },
67}
68
69#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
70#[serde(rename_all = "snake_case")]
71pub enum Cw20HookMsg {
72    ExecuteSwapOperations {
73        operations: Vec<SwapOperation>,
74        minimum_receive: Option<Uint128>,
75        to: Option<String>,
76        max_spread: Option<Decimal>,
77    },
78}
79
80#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
81#[serde(rename_all = "snake_case")]
82pub enum QueryMsg {
83    Config {},
84    SimulateSwapOperations {
85        offer_amount: Uint128,
86        operations: Vec<SwapOperation>,
87    },
88}
89
90// We define a custom struct for each query response
91#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
92pub struct ConfigResponse {
93    pub astroport_factory: String,
94}
95
96// We define a custom struct for each query response
97#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
98pub struct SimulateSwapOperationsResponse {
99    pub amount: Uint128,
100}
101
102/// We currently take no arguments for migrations
103#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
104pub struct MigrateMsg {}