df_hyperliquid_core/client/evm/
chain.rs1use crate::client::Network;
6
7pub const ARBITRUM_ONE: u64 = 42_161;
8pub const ARBITRUM_SEPOLIA: u64 = 421_614;
9
10pub const NATIVE_DECIMALS: u32 = 18;
12
13#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
14pub enum Chain {
15 HyperEvm(Network),
16 Arbitrum(Network),
17}
18
19impl Chain {
20 #[must_use]
21 pub const fn id(self) -> u64 {
22 match self {
23 Chain::HyperEvm(network) => network.evm_chain_id(),
24 Chain::Arbitrum(network) => network.arbitrum_chain_id(),
25 }
26 }
27
28 #[must_use]
29 pub fn from_id(id: u64) -> Option<Chain> {
30 [Network::Mainnet, Network::Testnet]
31 .into_iter()
32 .flat_map(|network| [Chain::HyperEvm(network), Chain::Arbitrum(network)])
33 .find(|chain| chain.id() == id)
34 }
35
36 #[must_use]
37 pub const fn network(self) -> Network {
38 match self {
39 Chain::HyperEvm(network) | Chain::Arbitrum(network) => network,
40 }
41 }
42
43 #[must_use]
44 pub const fn name(self) -> &'static str {
45 match self {
46 Chain::HyperEvm(Network::Mainnet) => "HyperEVM",
47 Chain::HyperEvm(Network::Testnet) => "HyperEVM testnet",
48 Chain::Arbitrum(Network::Mainnet) => "Arbitrum One",
49 Chain::Arbitrum(Network::Testnet) => "Arbitrum Sepolia",
50 }
51 }
52
53 #[must_use]
55 pub const fn coin(self) -> &'static str {
56 match self {
57 Chain::HyperEvm(_) => "HYPE",
58 Chain::Arbitrum(_) => "ETH",
59 }
60 }
61}
62
63#[cfg(test)]
64#[path = "tests/chain.rs"]
65mod tests;