abstract_ica/
chain_type.rs

1use std::fmt::Display;
2
3use abstract_sdk::std::constants::*;
4use abstract_sdk::std::objects::TruncatedChainId;
5
6#[derive(Debug, Clone, Copy, PartialEq)]
7pub enum ChainType {
8    Evm,
9    Cosmos,
10}
11
12impl Display for ChainType {
13    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
14        match self {
15            ChainType::Evm => write!(f, "EVM"),
16            ChainType::Cosmos => write!(f, "Cosmos"),
17        }
18    }
19}
20
21pub trait CastChainType {
22    fn chain_type(&self) -> Option<ChainType>;
23}
24
25impl CastChainType for TruncatedChainId {
26    // Return the type of chain based on the chain-id.
27    // Note: chain-ids for EVM chains are numbers!
28    fn chain_type(&self) -> Option<ChainType> {
29        let chains = map_macro::hash_map! {
30            ARCHWAY[0] => ChainType::Cosmos,
31            ARCHWAY[1] => ChainType::Cosmos,
32            NEUTRON[0] => ChainType::Cosmos,
33            NEUTRON[1] => ChainType::Cosmos,
34            KUJIRA[0] => ChainType::Cosmos,
35            KUJIRA[1] => ChainType::Cosmos,
36            TERRA[0] => ChainType::Cosmos,
37            TERRA[1] => ChainType::Cosmos,
38            OSMOSIS[0] => ChainType::Cosmos,
39            OSMOSIS[1] => ChainType::Cosmos,
40            JUNO[0] => ChainType::Cosmos,
41            JUNO[1] => ChainType::Cosmos,
42
43            // Only Testnet
44            UNION[0] => ChainType::Cosmos,
45            XION[0] => ChainType::Cosmos,
46
47            // EVM
48            BERACHAIN[0] => ChainType::Evm,
49            ETHEREUM[0] => ChainType::Evm,
50            ETHEREUM[1] => ChainType::Evm,
51        };
52
53        chains.get(self.as_str()).copied()
54    }
55}