use crate::PoolType;
use once_cell::sync::Lazy;
use std::collections::{HashMap, HashSet};
use std::fmt;
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Chain {
Ethereum,
Base,
}
static CHAIN_POOLS: Lazy<HashMap<Chain, HashSet<PoolType>>> = Lazy::new(|| {
let mut m = HashMap::new();
m.insert(
Chain::Ethereum,
[
PoolType::UniswapV2,
PoolType::UniswapV3,
PoolType::SushiSwapV2,
PoolType::SushiSwapV3,
PoolType::PancakeSwapV2,
PoolType::PancakeSwapV3,
PoolType::MaverickV1,
PoolType::MaverickV2,
PoolType::CurveTwoCrypto,
PoolType::CurveTriCrypto,
PoolType::BalancerV2,
]
.iter()
.cloned()
.collect(),
);
m.insert(
Chain::Base,
[
PoolType::UniswapV2,
PoolType::UniswapV3,
PoolType::SushiSwapV2,
PoolType::SushiSwapV3,
PoolType::PancakeSwapV2,
PoolType::PancakeSwapV3,
PoolType::Aerodrome,
PoolType::Slipstream,
PoolType::BaseSwapV2,
PoolType::BaseSwapV3,
PoolType::AlienBaseV2,
PoolType::AlienBaseV3,
PoolType::MaverickV1,
PoolType::MaverickV2,
PoolType::CurveTwoCrypto,
PoolType::CurveTriCrypto,
PoolType::BalancerV2,
PoolType::SwapBasedV2,
PoolType::SwapBasedV3,
PoolType::DackieSwapV2,
PoolType::DackieSwapV3,
]
.iter()
.cloned()
.collect(),
);
m
});
impl Chain {
pub fn supported(&self, pool_type: &PoolType) -> bool {
CHAIN_POOLS
.get(self)
.map(|pools| pools.contains(pool_type))
.unwrap_or(false)
}
}
impl fmt::Display for Chain {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}