use std::{fmt, str::FromStr};
use crate::B256;
use crate::bridge::Contracts;
use crate::utils::Address;
pub const TESTNET_CHAIN_ID: u64 = 99_801;
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash)]
pub enum Network {
#[default]
Testnet,
}
#[derive(Debug, Clone, PartialEq, Eq, thiserror::Error)]
#[error("`{0}` is not an Elysium network; expected testnet")]
pub struct UnknownNetwork(pub String);
impl Network {
pub const ALL: [Network; 1] = [Network::Testnet];
#[must_use]
pub const fn chain_id(self) -> u64 {
match self {
Network::Testnet => TESTNET_CHAIN_ID,
}
}
#[must_use]
pub const fn rpc_url(self) -> &'static str {
match self {
Network::Testnet => "https://testnet-rpc.elysium.kinetiq.xyz",
}
}
#[must_use]
pub const fn conduit_rpc_url(self) -> &'static str {
match self {
Network::Testnet => "https://rpc-elysium-testnet.t.conduit.xyz",
}
}
#[must_use]
pub const fn log_span(self) -> u64 {
match self {
Network::Testnet => 2_000,
}
}
#[must_use]
pub const fn explorer_url(self) -> &'static str {
match self {
Network::Testnet => "https://test-explorer.elysium.kinetiq.xyz",
}
}
#[must_use]
pub fn tx_url(self, hash: B256) -> String {
format!("{}/tx/{hash}", self.explorer_url())
}
#[must_use]
pub fn address_url(self, address: Address) -> String {
format!("{}/address/{address}", self.explorer_url())
}
#[must_use]
pub fn block_url(self, number: u64) -> String {
format!("{}/block/{number}", self.explorer_url())
}
#[must_use]
pub const fn verifier_url(self) -> &'static str {
match self {
Network::Testnet => "https://contracts.conduit.xyz",
}
}
#[must_use]
pub const fn faucet_url(self) -> &'static str {
match self {
Network::Testnet => "https://elysium.kinetiq.xyz/testnet-faucet",
}
}
#[must_use]
pub const fn bridge_url(self) -> &'static str {
match self {
Network::Testnet => "https://elysium.kinetiq.xyz/testnet-bridge",
}
}
#[must_use]
pub const fn hyperliquid(self) -> df_hyperliquid_core::Network {
match self {
Network::Testnet => df_hyperliquid_core::Network::Testnet,
}
}
#[must_use]
pub const fn parent_chain_id(self) -> u64 {
self.hyperliquid().evm_chain_id()
}
#[must_use]
pub const fn contracts(self) -> Contracts {
match self {
Network::Testnet => crate::bridge::contracts::TESTNET,
}
}
#[must_use]
pub const fn name(self) -> &'static str {
match self {
Network::Testnet => "testnet",
}
}
#[must_use]
pub const fn is_mainnet(self) -> bool {
match self {
Network::Testnet => false,
}
}
#[must_use]
pub const fn of_chain(chain_id: u64) -> Option<Network> {
match chain_id {
TESTNET_CHAIN_ID => Some(Network::Testnet),
_ => None,
}
}
}
impl fmt::Display for Network {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.write_str(self.name())
}
}
impl FromStr for Network {
type Err = UnknownNetwork;
fn from_str(text: &str) -> Result<Self, Self::Err> {
match text.trim().to_ascii_lowercase().as_str() {
"testnet" | "test" => Ok(Network::Testnet),
_ => Err(UnknownNetwork(text.trim().to_owned())),
}
}
}
#[cfg(test)]
#[path = "tests/network.rs"]
mod tests;