#[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<Chain>
pub fn builtin_from_str(s: &str) -> Option<Chain>
Parses only the built-in chains, ignoring any custom-chain registry.
Sourcepub fn custom(name: &str) -> Result<Chain, ChainConfigError>
pub fn custom(name: &str) -> Result<Chain, 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<Chain, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Chain, <__D as Deserializer<'de>>::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<Chain, <Chain as FromStr>::Err>
fn from_str(s: &str) -> Result<Chain, <Chain as FromStr>::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
Source§impl Serialize for Chain
impl Serialize for Chain
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
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
impl<'de, T> BorrowedRpcObject<'de> for 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<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
impl<T> ErasedDestructor for Twhere
T: 'static,
Source§impl<T> FmtForward for T
impl<T> FmtForward for T
Source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.Source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.Source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.Source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.Source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.Source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.Source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.Source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.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> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
Source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
Source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moreSource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
Source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
Source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.Source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.Source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<'de, T> RpcBorrow<'de> for T
impl<T> RpcObject for T
impl<T> RpcRecv for T
impl<T> RpcSend for T
Source§impl<T> Serialize for T
impl<T> Serialize for T
fn erased_serialize(&self, serializer: &mut dyn Serializer) -> Result<(), Error>
fn do_erased_serialize( &self, serializer: &mut dyn Serializer, ) -> Result<(), ErrorImpl>
Source§impl<T> Tap for T
impl<T> Tap for T
Source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moreSource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moreSource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moreSource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moreSource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moreSource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.Source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.Source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.Source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.Source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.Source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.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.