pub struct Chain(/* private fields */);Expand description
Type-safe chain identifier with convenient constructors
Provides ergonomic helpers for accessing supported chains while
maintaining full compatibility with alloy_chains::NamedChain.
§Examples
use odos_sdk::{Chain, OdosChain};
// Convenient constructors
let chain = Chain::ethereum();
let chain = Chain::arbitrum();
let chain = Chain::base();
// From chain ID
let chain = Chain::from_chain_id(1)?; // Ethereum
let chain = Chain::from_chain_id(42161)?; // Arbitrum
// Access inner NamedChain
let named = chain.inner();
// Use OdosChain trait methods
let router = chain.v3_router_address()?;Implementations§
Source§impl Chain
impl Chain
Sourcepub const fn ethereum() -> Self
pub const fn ethereum() -> Self
Ethereum Mainnet (Chain ID: 1)
§Examples
use odos_sdk::Chain;
let chain = Chain::ethereum();
assert_eq!(chain.id(), 1);Sourcepub const fn arbitrum() -> Self
pub const fn arbitrum() -> Self
Arbitrum One (Chain ID: 42161)
§Examples
use odos_sdk::Chain;
let chain = Chain::arbitrum();
assert_eq!(chain.id(), 42161);Sourcepub const fn optimism() -> Self
pub const fn optimism() -> Self
Optimism (Chain ID: 10)
§Examples
use odos_sdk::Chain;
let chain = Chain::optimism();
assert_eq!(chain.id(), 10);Sourcepub const fn polygon() -> Self
pub const fn polygon() -> Self
Polygon (Chain ID: 137)
§Examples
use odos_sdk::Chain;
let chain = Chain::polygon();
assert_eq!(chain.id(), 137);Sourcepub const fn base() -> Self
pub const fn base() -> Self
Base (Chain ID: 8453)
§Examples
use odos_sdk::Chain;
let chain = Chain::base();
assert_eq!(chain.id(), 8453);Sourcepub const fn bsc() -> Self
pub const fn bsc() -> Self
BNB Smart Chain (Chain ID: 56)
§Examples
use odos_sdk::Chain;
let chain = Chain::bsc();
assert_eq!(chain.id(), 56);Sourcepub const fn avalanche() -> Self
pub const fn avalanche() -> Self
Avalanche C-Chain (Chain ID: 43114)
§Examples
use odos_sdk::Chain;
let chain = Chain::avalanche();
assert_eq!(chain.id(), 43114);Sourcepub const fn linea() -> Self
pub const fn linea() -> Self
Linea (Chain ID: 59144)
§Examples
use odos_sdk::Chain;
let chain = Chain::linea();
assert_eq!(chain.id(), 59144);Sourcepub const fn zksync() -> Self
pub const fn zksync() -> Self
ZkSync Era (Chain ID: 324)
§Examples
use odos_sdk::Chain;
let chain = Chain::zksync();
assert_eq!(chain.id(), 324);Sourcepub const fn mantle() -> Self
pub const fn mantle() -> Self
Mantle (Chain ID: 5000)
§Examples
use odos_sdk::Chain;
let chain = Chain::mantle();
assert_eq!(chain.id(), 5000);Sourcepub const fn fraxtal() -> Self
pub const fn fraxtal() -> Self
Fraxtal (Chain ID: 252)
§Examples
use odos_sdk::Chain;
let chain = Chain::fraxtal();
assert_eq!(chain.id(), 252);Sourcepub const fn sonic() -> Self
pub const fn sonic() -> Self
Sonic (Chain ID: 146)
§Examples
use odos_sdk::Chain;
let chain = Chain::sonic();
assert_eq!(chain.id(), 146);Sourcepub const fn unichain() -> Self
pub const fn unichain() -> Self
Unichain (Chain ID: 130)
§Examples
use odos_sdk::Chain;
let chain = Chain::unichain();
assert_eq!(chain.id(), 130);Sourcepub fn from_chain_id(id: u64) -> OdosChainResult<Self>
pub fn from_chain_id(id: u64) -> OdosChainResult<Self>
Create a chain from a chain ID
§Arguments
id- The EVM chain ID
§Returns
Ok(Chain)- If the chain ID is recognizedErr(OdosChainError)- If the chain ID is not supported
§Examples
use odos_sdk::Chain;
let chain = Chain::from_chain_id(1)?; // Ethereum
let chain = Chain::from_chain_id(42161)?; // Arbitrum
let chain = Chain::from_chain_id(8453)?; // Base
// Unsupported chain
assert!(Chain::from_chain_id(999999).is_err());Sourcepub fn id(&self) -> u64
pub fn id(&self) -> u64
Get the chain ID
§Examples
use odos_sdk::Chain;
assert_eq!(Chain::ethereum().id(), 1);
assert_eq!(Chain::arbitrum().id(), 42161);
assert_eq!(Chain::base().id(), 8453);Sourcepub const fn inner(&self) -> NamedChain
pub const fn inner(&self) -> NamedChain
Get the inner NamedChain
§Examples
use odos_sdk::Chain;
use alloy_chains::NamedChain;
let chain = Chain::ethereum();
assert_eq!(chain.inner(), NamedChain::Mainnet);Sourcepub fn from_name(name: &str) -> OdosChainResult<Self>
pub fn from_name(name: &str) -> OdosChainResult<Self>
Parse a supported Odos chain from a common human-readable name or alias.
Accepts common aliases such as mainnet, ethereum, arb, op, and
numeric chain IDs encoded as strings.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Chain
impl<'de> Deserialize<'de> for Chain
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 From<Chain> for NamedChain
impl From<Chain> for NamedChain
Source§impl From<NamedChain> for Chain
impl From<NamedChain> for Chain
Source§fn from(chain: NamedChain) -> Self
fn from(chain: NamedChain) -> Self
Source§impl OdosChain for Chain
impl OdosChain for Chain
Source§fn lo_router_address(&self) -> OdosChainResult<Address>
fn lo_router_address(&self) -> OdosChainResult<Address>
Source§fn v2_router_address(&self) -> OdosChainResult<Address>
fn v2_router_address(&self) -> OdosChainResult<Address>
Source§fn v3_router_address(&self) -> OdosChainResult<Address>
fn v3_router_address(&self) -> OdosChainResult<Address>
Source§fn supports_odos(&self) -> bool
fn supports_odos(&self) -> bool
Source§fn supports_lo(&self) -> bool
fn supports_lo(&self) -> bool
Source§fn supports_v2(&self) -> bool
fn supports_v2(&self) -> bool
Source§fn supports_v3(&self) -> bool
fn supports_v3(&self) -> bool
Source§fn router_availability(&self) -> RouterAvailability
fn router_availability(&self) -> RouterAvailability
Source§fn try_lo_router_address(&self) -> Option<Address>
fn try_lo_router_address(&self) -> Option<Address>
Source§impl Ord for Chain
impl Ord for Chain
Source§impl PartialOrd for Chain
impl PartialOrd for Chain
impl Copy for Chain
impl Eq for Chain
impl StructuralPartialEq for Chain
Auto Trait Implementations§
impl Freeze for Chain
impl RefUnwindSafe for Chain
impl Send for Chain
impl Sync for Chain
impl Unpin for Chain
impl UnsafeUnpin for Chain
impl UnwindSafe for Chain
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> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> OdosRouterSelection for Twhere
T: OdosChain,
impl<T> OdosRouterSelection for Twhere
T: OdosChain,
Source§fn recommended_router_address(&self) -> OdosChainResult<Address>
fn recommended_router_address(&self) -> OdosChainResult<Address>
Source§fn router_address_with_fallback(&self) -> OdosChainResult<Address>
fn router_address_with_fallback(&self) -> OdosChainResult<Address>
Source§fn router_address_by_preference(
&self,
prefer_v3: bool,
) -> OdosChainResult<Address>
fn router_address_by_preference( &self, prefer_v3: bool, ) -> OdosChainResult<Address>
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.