#[repr(u64)]pub enum SupportedChainId {
Mainnet = 1,
GnosisChain = 100,
ArbitrumOne = 42_161,
Base = 8_453,
Sepolia = 11_155_111,
Polygon = 137,
Avalanche = 43_114,
BnbChain = 56,
Linea = 59_144,
Lens = 232,
Plasma = 9_745,
Ink = 57_073,
}Expand description
Chains supported by the CoW Protocol orderbook.
Each variant’s numeric discriminant matches the EIP-155 chain ID, so
SupportedChainId::Mainnet as u64 == 1. Use try_from_u64
to convert from a raw chain ID, or all to iterate every
supported chain.
§Example
use cow_chains::SupportedChainId;
let chain = SupportedChainId::try_from_u64(1).unwrap();
assert_eq!(chain, SupportedChainId::Mainnet);
assert_eq!(chain.as_u64(), 1);
assert_eq!(chain.as_str(), "mainnet");
assert!(!chain.is_testnet());Variants§
Mainnet = 1
Ethereum mainnet (chain ID 1).
GnosisChain = 100
Gnosis Chain (chain ID 100).
ArbitrumOne = 42_161
Arbitrum One (chain ID 42161).
Base = 8_453
Base (chain ID 8453).
Sepolia = 11_155_111
Ethereum Sepolia testnet (chain ID 11155111).
Polygon = 137
Polygon PoS (chain ID 137).
Avalanche = 43_114
Avalanche C-Chain (chain ID 43114).
BnbChain = 56
BNB Smart Chain (chain ID 56).
Linea = 59_144
Linea (chain ID 59144).
Lens = 232
Lens Network (chain ID 232).
Plasma = 9_745
Plasma (chain ID 9745).
Ink = 57_073
Ink (chain ID 57073).
Implementations§
Source§impl SupportedChainId
impl SupportedChainId
Sourcepub const fn as_u64(self) -> u64
pub const fn as_u64(self) -> u64
Return the numeric EIP-155 chain ID.
§Returns
The u64 chain ID (e.g. 1 for Mainnet, 100 for Gnosis Chain).
Sourcepub const fn try_from_u64(chain_id: u64) -> Option<Self>
pub const fn try_from_u64(chain_id: u64) -> Option<Self>
Try to construct a SupportedChainId from a raw EIP-155 chain ID.
§Parameters
chain_id— the numeric EIP-155 chain ID.
§Returns
Some(variant) if chain_id is supported, None otherwise.
§Example
use cow_chains::SupportedChainId;
assert_eq!(SupportedChainId::try_from_u64(1), Some(SupportedChainId::Mainnet));
assert_eq!(SupportedChainId::try_from_u64(11155111), Some(SupportedChainId::Sepolia));
assert_eq!(SupportedChainId::try_from_u64(9999), None);Sourcepub const fn all() -> &'static [Self]
pub const fn all() -> &'static [Self]
Return a slice of all chains supported by the CoW Protocol orderbook.
§Returns
A static slice containing every SupportedChainId variant.
Sourcepub const fn as_str(self) -> &'static str
pub const fn as_str(self) -> &'static str
Returns the CoW Protocol API path segment for this chain.
Matches the path used in api_base_url, e.g. "mainnet", "xdai",
"sepolia". Useful for constructing API URLs manually.
§Returns
A static string suitable for use in API URL paths.
Sourcepub const fn is_testnet(self) -> bool
pub const fn is_testnet(self) -> bool
Sourcepub const fn is_mainnet(self) -> bool
pub const fn is_mainnet(self) -> bool
Returns true for production chains (i.e. not a testnet).
This is the logical complement of Self::is_testnet.
use cow_chains::SupportedChainId;
assert!(SupportedChainId::Mainnet.is_mainnet());
assert!(!SupportedChainId::Sepolia.is_mainnet());Sourcepub const fn is_layer2(self) -> bool
pub const fn is_layer2(self) -> bool
Returns true for layer-2 networks.
Currently includes Arbitrum One, Base, Linea, Ink, and Polygon.
use cow_chains::SupportedChainId;
assert!(SupportedChainId::ArbitrumOne.is_layer2());
assert!(SupportedChainId::Base.is_layer2());
assert!(SupportedChainId::Polygon.is_layer2());
assert!(!SupportedChainId::Mainnet.is_layer2());
assert!(!SupportedChainId::GnosisChain.is_layer2());Sourcepub const fn explorer_network(self) -> &'static str
pub const fn explorer_network(self) -> &'static str
Return the network segment used in CoW Protocol Explorer URLs.
Mainnet uses an empty segment (orders live at the root path).
§Returns
A static string for the URL path segment (empty for Mainnet).
Trait Implementations§
Source§impl Clone for SupportedChainId
impl Clone for SupportedChainId
Source§fn clone(&self) -> SupportedChainId
fn clone(&self) -> SupportedChainId
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for SupportedChainId
impl Debug for SupportedChainId
Source§impl<'de> Deserialize<'de> for SupportedChainId
impl<'de> Deserialize<'de> for SupportedChainId
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Source§impl Display for SupportedChainId
impl Display for SupportedChainId
Source§impl From<SupportedChainId> for u64
impl From<SupportedChainId> for u64
Source§fn from(id: SupportedChainId) -> Self
fn from(id: SupportedChainId) -> Self
Source§impl Hash for SupportedChainId
impl Hash for SupportedChainId
Source§impl PartialEq for SupportedChainId
impl PartialEq for SupportedChainId
Source§impl Serialize for SupportedChainId
impl Serialize for SupportedChainId
Source§impl TryFrom<&str> for SupportedChainId
impl TryFrom<&str> for SupportedChainId
Source§fn try_from(s: &str) -> Result<Self, Self::Error>
fn try_from(s: &str) -> Result<Self, Self::Error>
Parse a SupportedChainId from the CoW Protocol API path segment.
Accepts the same strings returned by SupportedChainId::as_str:
"mainnet", "xdai", "arbitrum_one", "base", "sepolia",
"polygon", "avalanche", "bnb", "linea", "lens", "plasma", "ink".
Source§impl TryFrom<u64> for SupportedChainId
impl TryFrom<u64> for SupportedChainId
impl Copy for SupportedChainId
impl Eq for SupportedChainId
impl StructuralPartialEq for SupportedChainId
Auto Trait Implementations§
impl Freeze for SupportedChainId
impl RefUnwindSafe for SupportedChainId
impl Send for SupportedChainId
impl Sync for SupportedChainId
impl Unpin for SupportedChainId
impl UnsafeUnpin for SupportedChainId
impl UnwindSafe for SupportedChainId
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.