pub struct TychoStreamDecoder<H>where
H: HeaderLike,{ /* private fields */ }Expand description
A decoder to process raw messages.
This struct decodes incoming messages of type FeedMessage and converts it into the
BlockUpdate struct.
§Important:
- Supports registering exchanges and their associated filters for specific protocol components.
- Allows the addition of client-side filters for custom conditions.
Note: Tokens provided via set_tokens are used to decode startup
snapshots and initialize protocol states. This is not an ongoing filter — components arriving
after startup include their own token metadata.
Implementations§
Source§impl<H> TychoStreamDecoder<H>
impl<H> TychoStreamDecoder<H>
pub fn new() -> Self
Sourcepub async fn set_tokens(&self, tokens: HashMap<Bytes, Token>)
pub async fn set_tokens(&self, tokens: HashMap<Bytes, Token>)
Provides token metadata used to decode startup snapshots and initialize protocol states.
This is not an ongoing stream filter. Components arriving after startup include their own token metadata for decoding.
pub fn skip_state_decode_failures(&mut self, skip: bool)
Sourcepub fn min_token_quality(&mut self, quality: u32)
pub fn min_token_quality(&mut self, quality: u32)
Sets the minimum token quality for decoding.
Tokens arriving in stream deltas below this threshold are ignored. Defaults to 100.
Set this to the same value used in load_all_tokens() to
apply consistent filtering.
Sourcepub fn register_decoder_with_context<T>(
&mut self,
exchange: &str,
context: DecoderContext,
)where
T: ProtocolSim + TryFromWithBlock<ComponentWithState, H, Error = InvalidSnapshotError> + Send + 'static,
pub fn register_decoder_with_context<T>(
&mut self,
exchange: &str,
context: DecoderContext,
)where
T: ProtocolSim + TryFromWithBlock<ComponentWithState, H, Error = InvalidSnapshotError> + Send + 'static,
Registers a decoder for a given exchange with a decoder context.
This method maps an exchange identifier to a specific protocol simulation type.
The associated type must implement the TryFromWithBlock trait to enable decoding
of state updates from ComponentWithState objects. This allows the decoder to transform
the component data into the appropriate protocol simulation type based on the current
blockchain state and the provided block header.
For example, to register a decoder for the uniswap_v2 exchange with an additional decoder
context, you must call this function with
register_decoder_with_context::<UniswapV2State>("uniswap_v2", context).
This ensures that the exchange ID uniswap_v2 is properly associated with the
UniswapV2State decoder for use in the protocol stream.
Sourcepub fn register_decoder<T>(&mut self, exchange: &str)where
T: ProtocolSim + TryFromWithBlock<ComponentWithState, H, Error = InvalidSnapshotError> + Send + 'static,
pub fn register_decoder<T>(&mut self, exchange: &str)where
T: ProtocolSim + TryFromWithBlock<ComponentWithState, H, Error = InvalidSnapshotError> + Send + 'static,
Registers a decoder for a given exchange.
This method maps an exchange identifier to a specific protocol simulation type.
The associated type must implement the TryFromWithBlock trait to enable decoding
of state updates from ComponentWithState objects. This allows the decoder to transform
the component data into the appropriate protocol simulation type based on the current
blockchain state and the provided block header.
For example, to register a decoder for the uniswap_v2 exchange, you must call
this function with register_decoder::<UniswapV2State>("uniswap_v2", vm_attributes).
This ensures that the exchange ID uniswap_v2 is properly associated with the
UniswapV2State decoder for use in the protocol stream.
Sourcepub fn register_filter(
&mut self,
exchange: &str,
predicate: fn(&ComponentWithState) -> bool,
)
pub fn register_filter( &mut self, exchange: &str, predicate: fn(&ComponentWithState) -> bool, )
Registers a client-side filter function for a given exchange.
Associates a filter function with an exchange ID, enabling custom filtering of protocol components. The filter function is applied client-side to refine the data received from the stream. It can be used to exclude certain components based on attributes or conditions that are not supported by the server-side filtering logic. This is particularly useful for implementing custom behaviors, such as:
- Filtering out pools with specific attributes (e.g., unsupported features).
- Blacklisting pools based on custom criteria.
- Excluding pools that do not meet certain requirements (e.g., token pairs or liquidity constraints).
For example, you might use a filter to exclude pools that are not fully supported in the protocol, or to ignore pools with certain attributes that are irrelevant to your application.
Sourcepub async fn decode(
&self,
msg: &FeedMessage<H>,
) -> Result<Update, StreamDecodeError>
pub async fn decode( &self, msg: &FeedMessage<H>, ) -> Result<Update, StreamDecodeError>
Decodes a FeedMessage into a BlockUpdate containing the updated states of protocol
components
Sourcepub async fn apply_deltas_ephemeral(
&self,
pending_deltas: &HashMap<String, BlockAggregatedChanges>,
header: H,
) -> Result<Update, StreamDecodeError>
pub async fn apply_deltas_ephemeral( &self, pending_deltas: &HashMap<String, BlockAggregatedChanges>, header: H, ) -> Result<Update, StreamDecodeError>
Applies pending deltas from one or more TxDeltaIndexers against the current confirmed
state and returns an ephemeral Update.
This is the read-only counterpart of decode(). It clones pool states, applies the
supplied pending_deltas, and returns the result — without writing back to
DecoderState. Calling this method twice with the same input produces identical results.
Only native protocols are supported. VM protocols (extractor prefix "vm:") are rejected
at registration time in
with_pending_indexer.
§Parameters
pending_deltas— map from extractor name to theBlockAggregatedChangesproduced by the correspondingTxDeltaIndexer::generate_deltas()call.header— the target block header. Itsblock_number_or_timestamp()is stamped on the returnedUpdate; itsblock_numberandblock_timestampare injected into each state delta so that protocols relying on block context (e.g. aerodrome slipstreams, etherfi) receive correct values.
Trait Implementations§
Auto Trait Implementations§
impl<H> !RefUnwindSafe for TychoStreamDecoder<H>
impl<H> !UnwindSafe for TychoStreamDecoder<H>
impl<H> Freeze for TychoStreamDecoder<H>
impl<H> Send for TychoStreamDecoder<H>
impl<H> Sync for TychoStreamDecoder<H>
impl<H> Unpin for TychoStreamDecoder<H>
impl<H> UnsafeUnpin for TychoStreamDecoder<H>
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<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,
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.