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
//! Chain Support and Pool Type Management
//!
//! This module defines the supported blockchain networks (Chains) and manages
//! the mapping of supported pool types for each chain.
use crate::PoolType;
use once_cell::sync::Lazy;
use std::collections::{HashMap, HashSet};
use std::fmt;
/// Enum representing supported blockchain networks
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub enum Chain {
/// Ethereum mainnet
Ethereum,
/// Base chain
Base,
// Additional chains can be added here
}
/// Static mapping of supported pool types for each chain
///
/// This mapping is important because not all protocols are deployed on all chains,
/// and the contract addresses for the same protocol may differ across chains.
static CHAIN_POOLS: Lazy<HashMap<Chain, HashSet<PoolType>>> = Lazy::new(|| {
let mut m = HashMap::new();
// Protocols supported by Ethereum
m.insert(
Chain::Ethereum,
[
PoolType::UniswapV2,
PoolType::UniswapV3,
PoolType::SushiSwapV2,
PoolType::SushiSwapV3,
PoolType::PancakeSwapV2,
PoolType::PancakeSwapV3,
]
.iter()
.cloned()
.collect(),
);
// Protocols supported by Base
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::AlienBase,
]
.iter()
.cloned()
.collect(),
);
// Additional chains can be configured here
m
});
impl Chain {
/// Determines if a given pool type is supported on this chain
pub fn supported(&self, pool_type: &PoolType) -> bool {
CHAIN_POOLS
.get(self)
.map(|pools| pools.contains(pool_type))
.unwrap_or(false)
}
}
// Display implementation for Chain, used for file naming and debugging purposes
impl fmt::Display for Chain {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{:?}", self)
}
}