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 scroll() -> Self
pub const fn scroll() -> Self
Scroll (Chain ID: 534352)
§Examples
use odos_sdk::Chain;
let chain = Chain::scroll();
assert_eq!(chain.id(), 534352);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 mode() -> Self
pub const fn mode() -> Self
Mode (Chain ID: 34443)
§Examples
use odos_sdk::Chain;
let chain = Chain::mode();
assert_eq!(chain.id(), 34443);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);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>,
Deserialize this value from the given Serde deserializer. Read more
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
Converts to this type from the input type.
Source§impl OdosChain for Chain
impl OdosChain for Chain
Source§fn lo_router_address(&self) -> OdosChainResult<Address>
fn lo_router_address(&self) -> OdosChainResult<Address>
Get the Limit Order V2 router address for this chain Read more
Source§fn v2_router_address(&self) -> OdosChainResult<Address>
fn v2_router_address(&self) -> OdosChainResult<Address>
Get the V2 router address for this chain Read more
Source§fn v3_router_address(&self) -> OdosChainResult<Address>
fn v3_router_address(&self) -> OdosChainResult<Address>
Get the V3 router address for this chain Read more
Source§fn supports_odos(&self) -> bool
fn supports_odos(&self) -> bool
Check if this chain supports Odos protocol Read more
Source§fn supports_lo(&self) -> bool
fn supports_lo(&self) -> bool
Check if this chain supports Odos Limit Order Read more
Source§fn supports_v2(&self) -> bool
fn supports_v2(&self) -> bool
Check if this chain supports Odos V2 Read more
Source§fn supports_v3(&self) -> bool
fn supports_v3(&self) -> bool
Check if this chain supports Odos V3 Read more
Source§fn router_availability(&self) -> RouterAvailability
fn router_availability(&self) -> RouterAvailability
Get router availability for this chain Read more
Source§fn try_lo_router_address(&self) -> Option<Address>
fn try_lo_router_address(&self) -> Option<Address>
Try to get the LO router address without errors Read more
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 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
Mutably borrows from an owned value. Read more
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§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
Compare self to
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>
Converts
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>
Converts
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>
Get the recommended router address for this chain Read more
Source§fn router_address_with_fallback(&self) -> OdosChainResult<Address>
fn router_address_with_fallback(&self) -> OdosChainResult<Address>
Get router address with fallback strategy Read more
Source§fn router_address_by_preference(
&self,
prefer_v3: bool,
) -> OdosChainResult<Address>
fn router_address_by_preference( &self, prefer_v3: bool, ) -> OdosChainResult<Address>
Get router address based on preference Read more
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.