abstract_ica/
chain_type.rs

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
use std::fmt::Display;

use abstract_sdk::std::constants::*;
use abstract_sdk::std::objects::TruncatedChainId;

#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ChainType {
    Evm,
    Cosmos,
}

impl Display for ChainType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ChainType::Evm => write!(f, "EVM"),
            ChainType::Cosmos => write!(f, "Cosmos"),
        }
    }
}

pub trait CastChainType {
    fn chain_type(&self) -> Option<ChainType>;
}

impl CastChainType for TruncatedChainId {
    // Return the type of chain based on the chain-id.
    // Note: chain-ids for EVM chains are numbers!
    fn chain_type(&self) -> Option<ChainType> {
        let chains = map_macro::hash_map! {
            ARCHWAY[0] => ChainType::Cosmos,
            ARCHWAY[1] => ChainType::Cosmos,
            NEUTRON[0] => ChainType::Cosmos,
            NEUTRON[1] => ChainType::Cosmos,
            KUJIRA[0] => ChainType::Cosmos,
            KUJIRA[1] => ChainType::Cosmos,
            TERRA[0] => ChainType::Cosmos,
            TERRA[1] => ChainType::Cosmos,
            OSMOSIS[0] => ChainType::Cosmos,
            OSMOSIS[1] => ChainType::Cosmos,
            JUNO[0] => ChainType::Cosmos,
            JUNO[1] => ChainType::Cosmos,

            // Only Testnet
            UNION[0] => ChainType::Cosmos,
            XION[0] => ChainType::Cosmos,

            // EVM
            BERACHAIN[0] => ChainType::Evm,
            ETHEREUM[0] => ChainType::Evm,
            ETHEREUM[1] => ChainType::Evm,
        };

        chains.get(self.as_str()).copied()
    }
}