#[non_exhaustive]pub enum Chain {
Ethereum,
Starknet,
ZkSync,
Arbitrum,
Base,
Bsc,
Unichain,
Polygon,
Custom(CustomChainId),
}Expand description
A blockchain Tycho indexes or simulates over.
Built-in chains are first-class variants: their config (id, native token, block time, TVL
tiers) is compile-time and total, so they never fail to resolve. Custom is the escape hatch
for a chain a self-hoster runs without upstreaming a variant — its config lives in the
process-wide registry (see chain_config) rather than in the enum.
Custom wraps a CustomChainId whose inner name is private, so a Chain::Custom can only be
built through the crate’s registry-validating constructors (Chain::custom,
Chain::from_str, From<dto::Chain>) — it cannot be fabricated directly. Because the
registry is set-once, a validated Chain::Custom stays resolvable for its whole lifetime, so
the config accessors only panic on an unreachable invariant; Chain::try_id and its siblings
expose non-panicking variants. The one reachable failure is decoding wire data for a chain the
local registry lacks (From<dto::Chain>), which panics at the decode boundary.
Prefer adding a first-class variant for any chain Tycho officially supports; reserve Custom
for the self-host case. Full rationale in the custom-chain decision record.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Ethereum
Starknet
ZkSync
Arbitrum
Base
Bsc
Unichain
Polygon
Custom(CustomChainId)
User-defined chain resolved via the chain_config registry; see the enum docs.
Implementations§
Source§impl Chain
impl Chain
Sourcepub fn builtin_from_str(s: &str) -> Option<Self>
pub fn builtin_from_str(s: &str) -> Option<Self>
Parses only the built-in chains, ignoring any custom-chain registry.
Sourcepub fn custom(name: &str) -> Result<Self, ChainConfigError>
pub fn custom(name: &str) -> Result<Self, ChainConfigError>
Builds a custom-chain identity, validating that name has a config in the chain registry.
Returns ChainConfigError::UnknownChain when it is absent so typos never silently become
custom chains.
Source§impl Chain
impl Chain
Sourcepub fn id(&self) -> u64
pub fn id(&self) -> u64
Returns the numeric chain id. Panics if a custom chain has no registered config — an
unreachable invariant for a validly-constructed Chain::Custom; use Chain::try_id for a
non-panicking variant.
Sourcepub fn try_id(&self) -> Result<u64, ChainConfigError>
pub fn try_id(&self) -> Result<u64, ChainConfigError>
Returns the numeric chain id, or ChainConfigError::UnknownChain when a custom chain has
no registered config.
Sourcepub fn default_tvl_threshold(&self, tier: TvlThresholdTier) -> f64
pub fn default_tvl_threshold(&self, tier: TvlThresholdTier) -> f64
Returns a default TVL threshold in native token units for the given tier.
Values are approximate and target a USD-equivalent range, not a precise conversion. Native token prices used: ETH ~$2,000, POL ~$0.10, BNB ~$630. These prices are volatile, and used as a reference. They should not be updated often, unless big price movements occour, making an update necessary.
Panics if a custom chain has no registered config; use Chain::try_default_tvl_threshold
for a non-panicking variant.
Sourcepub fn try_default_tvl_threshold(
&self,
tier: TvlThresholdTier,
) -> Result<f64, ChainConfigError>
pub fn try_default_tvl_threshold( &self, tier: TvlThresholdTier, ) -> Result<f64, ChainConfigError>
Like Chain::default_tvl_threshold but returns ChainConfigError::UnknownChain when a
custom chain has no registered config.
Sourcepub fn native_token(&self) -> Token
pub fn native_token(&self) -> Token
Returns the native token for the chain. Panics if a custom chain has no registered config;
use Chain::try_native_token for a non-panicking variant.
Sourcepub fn try_native_token(&self) -> Result<Token, ChainConfigError>
pub fn try_native_token(&self) -> Result<Token, ChainConfigError>
Like Chain::native_token but returns ChainConfigError::UnknownChain when a custom
chain has no registered config.
Sourcepub fn wrapped_native_token(&self) -> Token
pub fn wrapped_native_token(&self) -> Token
Returns the wrapped native token for the chain. Panics if a custom chain has no registered
config; use Chain::try_wrapped_native_token for a non-panicking variant.
Sourcepub fn try_wrapped_native_token(&self) -> Result<Token, ChainConfigError>
pub fn try_wrapped_native_token(&self) -> Result<Token, ChainConfigError>
Like Chain::wrapped_native_token but returns ChainConfigError::UnknownChain when a
custom chain has no registered config.
Sourcepub fn block_time_secs(&self) -> u64
pub fn block_time_secs(&self) -> u64
Returns the expected block time in seconds for the chain. Panics if a custom chain has no
registered config; use Chain::try_block_time_secs for a non-panicking variant.
Sourcepub fn try_block_time_secs(&self) -> Result<u64, ChainConfigError>
pub fn try_block_time_secs(&self) -> Result<u64, ChainConfigError>
Like Chain::block_time_secs but returns ChainConfigError::UnknownChain when a custom
chain has no registered config.
Trait Implementations§
impl Copy for Chain
Source§impl DeepSizeOf for Chain
impl DeepSizeOf for Chain
Source§fn deep_size_of_children(&self, _context: &mut Context) -> usize
fn deep_size_of_children(&self, _context: &mut Context) -> usize
Source§fn deep_size_of(&self) -> usize
fn deep_size_of(&self) -> usize
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>,
impl Eq for Chain
Source§impl FromStr for Chain
impl FromStr for Chain
Source§fn from_str(s: &str) -> Result<Self, Self::Err>
fn from_str(s: &str) -> Result<Self, Self::Err>
Resolves a chain name. Built-in chains parse directly; any other name is accepted only if it
is registered in the global chain config registry, otherwise
ChainConfigError::UnknownChain is returned so typos never silently become custom chains.
Source§type Err = ChainConfigError
type Err = ChainConfigError
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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
key and return true if they are equal.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 more