pool_sync_mantle/
chain.rs

1//! Chain Support and Pool Type Management
2//!
3//! This module defines the supported blockchain networks (Chains) and manages
4//! the mapping of supported pool types for each chain.
5
6use crate::PoolType;
7use once_cell::sync::Lazy;
8use std::collections::{HashMap, HashSet};
9use std::fmt;
10
11/// Enum representing supported blockchain networks
12#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
13pub enum Chain {
14    /// Mantle chain
15    Mantle,
16}
17
18/// Static mapping of supported pool types for each chain
19///
20/// This mapping is important because not all protocols are deployed on all chains,
21/// and the contract addresses for the same protocol may differ across chains.
22static CHAIN_POOLS: Lazy<HashMap<Chain, HashSet<PoolType>>> = Lazy::new(|| {
23    let mut m = HashMap::new();
24
25    // Protocols supported by Mantle
26    m.insert(
27        Chain::Mantle,
28        [
29            PoolType::UniswapV3,
30            PoolType::MerchantMoe,
31            PoolType::Agni,
32        ]
33        .iter()
34        .cloned()
35        .collect(),
36    );
37
38    m
39});
40
41impl Chain {
42    /// Determines if a given pool type is supported on this chain
43    pub fn supported(&self, pool_type: &PoolType) -> bool {
44        CHAIN_POOLS
45            .get(self)
46            .map(|pools| pools.contains(pool_type))
47            .unwrap_or(false)
48    }
49}
50
51// Display implementation for Chain, used for file naming and debugging purposes
52impl fmt::Display for Chain {
53    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54        write!(f, "{:?}", self)
55    }
56}