use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use cosmwasm_std::{Addr, Uint128};
use cw20::Cw20ReceiveMsg;
use crate::asset::AssetInfo;
pub const MAX_SWAP_OPERATIONS: usize = 50;
/// ## Description
/// This structure holds the parameters used for creating a contract.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct InstantiateMsg {
/// The astroport factory contract address
pub astroport_factory: String,
}
/// ## Description
/// This enum describes a swap operation.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
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(),
}
}
}
/// ## Description
/// This structure describes the execute messages available in the contract.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
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<Addr>,
},
/// Internal use
/// ExecuteSwapOperation executes a single swap operation
ExecuteSwapOperation {
operation: SwapOperation,
to: Option<String>,
},
/// Internal use
/// AssertMinimumReceive checks that a receiver will get a minimum amount of tokens from a swap
AssertMinimumReceive {
asset_info: AssetInfo,
prev_balance: Uint128,
minimum_receive: Uint128,
receiver: String,
},
}
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
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>,
///
to: Option<String>,
},
}
/// ## Description
/// This structure describes the query messages available in the contract.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
#[serde(rename_all = "snake_case")]
pub enum QueryMsg {
/// Config returns configuration parameters for the contract using a custom [`ConfigResponse`] structure
Config {},
/// SimulateSwapOperations simulates multi-hop swap operations
SimulateSwapOperations {
/// The amount of tokens to swap
offer_amount: Uint128,
/// The swap operations to perform, each swap involving a specific pool
operations: Vec<SwapOperation>,
},
}
/// ## Description
/// This structure describes a custom struct to return a query response containing the base contract configuration.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct ConfigResponse {
/// The Astroport factory contract address
pub astroport_factory: String,
}
/// ## Description
/// This structure describes a custom struct to return a query response containing the end amount of a swap simulation
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct SimulateSwapOperationsResponse {
/// The amount of tokens received in a swap simulation
pub amount: Uint128,
}
/// ## Description
/// This structure describes a migration message.
/// We currently take no arguments for migrations.
#[derive(Serialize, Deserialize, Clone, Debug, PartialEq, JsonSchema)]
pub struct MigrateMsg {}