Skip to main content

SupportedChainId

Enum SupportedChainId 

Source
#[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

Source

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).

Source

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);
Source

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.

Source

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.

Source

pub const fn is_testnet(self) -> bool

Whether this chain is a testnet.

§Returns

true for Sepolia, false for all other chains.

Source

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());
Source

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());
Source

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

Source§

fn clone(&self) -> SupportedChainId

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for SupportedChainId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for SupportedChainId

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Display for SupportedChainId

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<SupportedChainId> for u64

Source§

fn from(id: SupportedChainId) -> Self

Converts to this type from the input type.
Source§

impl Hash for SupportedChainId

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SupportedChainId

Source§

fn eq(&self, other: &SupportedChainId) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for SupportedChainId

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl TryFrom<&str> for SupportedChainId

Source§

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§

type Error = CowError

The type returned in the event of a conversion error.
Source§

impl TryFrom<u64> for SupportedChainId

Source§

type Error = u64

The type returned in the event of a conversion error.
Source§

fn try_from(chain_id: u64) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Copy for SupportedChainId

Source§

impl Eq for SupportedChainId

Source§

impl StructuralPartialEq for SupportedChainId

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,