Skip to main content

df_hyperliquid_core/client/evm/
chain.rs

1//! The four EVM chains a Hyperliquid account touches: HyperEVM and the Arbitrum
2//! chain its bridge is on, for each network. HyperEVM's RPC comes from
3//! [`Network::evm_rpc_url`]; an Arbitrum RPC is whatever URL the caller has.
4
5use crate::client::Network;
6
7pub const ARBITRUM_ONE: u64 = 42_161;
8pub const ARBITRUM_SEPOLIA: u64 = 421_614;
9
10/// HYPE on HyperEVM and ETH on Arbitrum both have 18 decimals.
11pub 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    /// The coin gas is paid in.
54    #[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;