use crate::pools::buffer::BufferState;
use alloy_primitives::U256;
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum SwapKind {
GivenIn = 0,
GivenOut = 1,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum AddLiquidityKind {
Unbalanced = 0,
SingleTokenExactOut = 1,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum RemoveLiquidityKind {
Proportional = 0,
SingleTokenExactIn = 1,
SingleTokenExactOut = 2,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SwapInput {
pub amount_raw: U256,
pub swap_kind: SwapKind,
pub token_in: String,
pub token_out: String,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AddLiquidityInput {
pub pool: String,
pub max_amounts_in_raw: Vec<U256>,
pub min_bpt_amount_out_raw: U256,
pub kind: AddLiquidityKind,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RemoveLiquidityInput {
pub pool: String,
pub min_amounts_out_raw: Vec<U256>,
pub max_bpt_amount_in_raw: U256,
pub kind: RemoveLiquidityKind,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct BasePoolState {
pub pool_address: String,
pub pool_type: String,
pub tokens: Vec<String>,
pub scaling_factors: Vec<U256>,
pub token_rates: Vec<U256>,
pub balances_live_scaled_18: Vec<U256>,
pub swap_fee: U256,
pub aggregate_swap_fee: U256,
pub total_supply: U256,
pub supports_unbalanced_liquidity: bool,
pub hook_type: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(untagged)]
pub enum PoolState {
Base(BasePoolState),
Weighted(crate::pools::weighted::WeightedState),
Stable(crate::pools::stable::stable_data::StableState),
GyroECLP(crate::pools::gyro::gyro_eclp_data::GyroECLPState),
ReClamm(crate::pools::reclamm::reclamm_data::ReClammState),
ReClammV2(crate::pools::reclammv2::reclammv2_data::ReClammV2State),
QuantAmm(crate::pools::quantamm::quantamm_data::QuantAmmState),
LiquidityBootstrapping(crate::pools::liquidity_bootstrapping::liquidity_bootstrapping_data::LiquidityBootstrappingState),
FixedPriceLBP(crate::pools::fixed_price_lbp::fixed_price_lbp_data::FixedPriceLBPState),
}
#[derive(Debug, Clone)]
pub enum PoolStateOrBuffer {
Pool(Box<PoolState>),
Buffer(Box<BufferState>),
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SwapResult {
pub amount_out_raw: U256,
pub fee_amount_raw: U256,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct AddLiquidityResult {
pub bpt_amount_out_raw: U256,
pub amounts_in_raw: Vec<U256>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct RemoveLiquidityResult {
pub bpt_amount_in_raw: U256,
pub amounts_out_raw: Vec<U256>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct SwapParams {
pub swap_kind: SwapKind,
pub token_in_index: usize,
pub token_out_index: usize,
pub amount_scaled_18: U256,
pub balances_live_scaled_18: Vec<U256>,
}
pub trait HookStateBase {
fn hook_type(&self) -> &str;
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum Rounding {
RoundDown = 0,
RoundUp = 1,
}
impl PoolState {
pub fn base(&self) -> &BasePoolState {
match self {
PoolState::Base(base) => base,
PoolState::Weighted(weighted) => weighted.base(),
PoolState::Stable(stable) => &stable.base,
PoolState::GyroECLP(gyro_eclp) => &gyro_eclp.base,
PoolState::ReClamm(re_clamm) => &re_clamm.base,
PoolState::ReClammV2(re_clamm_v2) => &re_clamm_v2.base,
PoolState::QuantAmm(quant_amm) => &quant_amm.base,
PoolState::LiquidityBootstrapping(liquidity_bootstrapping) => {
&liquidity_bootstrapping.base
}
PoolState::FixedPriceLBP(fixed_price_lbp) => &fixed_price_lbp.base,
}
}
pub fn pool_type(&self) -> &str {
&self.base().pool_type
}
pub fn pool_address(&self) -> &str {
&self.base().pool_address
}
}