Tycho Client
Last updated
Last updated
Tycho Client helps you consume data from Tycho Indexer. It's the recommended way to connect to the Indexer data stream, whether you're using our or running your own instance.
In this guide, you'll learn more about the Tycho Client and the streamed data models.
Real-Time Streaming: Get low-latency updates to stay in sync with the latest protocol changes. Discover new pools as they’re created.
TVL Filtering: Receive updates only for pools exceeding a specified TVL threshold (denominated in the Chain's Native Token).
Support for multiple protocols and chains
The client is written in Rust and available as:
Follow one of the guides above to learn how to set up the client appropriate for you.
We welcome community contributions to expand language support. See our contribution guidelines How to Contribute.
Currently, interacting with the hosted Tycho Indexer doesn't require a personalized API Key; you can use the key sampletoken
. For broader rate-limiting, priority support, and access to new products, please contact @tanay_j
on Telegram.
Tycho Client provides a stream of protocol components, snapshots, their state changes, and associated tokens. For simplicity, we will use Tycho Client Binary as a reference, but the parameters described below are also available for our Rust and Python versions.
You can request individual pools or use a minimum TVL threshold to filter the components. If you choose minimum TVL tracking, Tycho-client will automatically add snapshots for any components that exceed the TVL threshold, e.g., because more liquidity was provided. It will also notify you and remove any components that fall below the TVL threshold. Note that the TVL values are estimates intended solely for filtering the most relevant components.
TVL Filtering:
TVL is measured in the chain's native currency (e.g., 1 00 ETH on Ethereum Mainnet).
You can filter by TVL in 2 ways:
Set an exact TVL boundary:
This will stream updates for all components whose TVL exceeds the minimum threshold set. Note: if a pool fluctuates in TVL close to this boundary, the client will emit a message to add/remove that pool every time it crosses that boundary. To mitigate this, please use the ranged tv boundary described below.
Set a ranged TVL boundary (recommended):
This will stream state updates for all components whose TVL exceeds the add-tvl-threshold
. It will continue to track already added components if they drop below the add-tvl-threshold
, only emitting a message to remove them if they drop below remove-tvl-threshold
.
Tycho emits data in an easy-to-read JSON format. Get granular updates on each block:
Snapshots for complete component (or pool) states,
Deltas for specific updates, and
Removal notices for components that no longer match your filtration criteria.
Extractor status for keeping track of the sync status of each extractor.
Each message includes block details to help you stay on track with the latest block data.
FeedMessage
The main outer message type. It contains both the individual SynchronizerState (one per extractor) and the StateSyncMessage (also one per extractor). Each extractor is supposed to emit one message per block (even if no changes happened in that block) and metadata about the extractor's block synchronization state. The latter allows consumers to handle delayed extractors gracefully.
SynchronizerState (sync_states
)
This struct contains metadata about the extractor's block synchronization state. It allows consumers to handle delayed extractors gracefully. Extractors can have any of the following states:
Ready
: the extractor is in sync with the expected block
Advanced
: the extractor is ahead of the expected block
Delayed
: the extractor has fallen behind on recent blocks but is still active and trying to catch up
Stale
: the extractor has made no progress for a significant amount of time and is flagged to be deactivated
Ended
: the synchronizer has ended, usually due to a termination or an error
StateSyncMessage (state_msgs
)
This struct, as the name states, serves to synchronize the state of any consumer to be up-to-date with the blockchain.
The attributes of this struct include the header (block information), snapshots, deltas, and removed components.
Snapshots are provided for any components that have NOT been observed yet by the client. A snapshot contains the entire state at the header.
Deltas contain state updates observed after or at the snapshot. Any components mentioned in the snapshots and deltas within the same StateSynchronization message must have the deltas applied to their snapshot to arrive at a correct state for the current header.
Removed components is a map of components that should be removed by consumers. Any components mentioned here will not appear in any further messages/updates.
Snapshots
Snapshots are simple messages that contain the complete state of a component (ComponentWithState) along with the related contract data (ResponseAccount). Contract data is only emitted for protocols that require vm simulations, it is omitted for protocols implemented natively (like UniswapV2 - see the list of Supported Protocolsand how they're implemented).
Snapshots are only emitted once per protocol, upon the client's startup. All the state is updated later via deltas from the next block onwards.
ComponentWithState
Tycho differentiates between component and component state.
The component itself is static: it describes, for example, which tokens are involved or how much fees are charged (if this value is static).
The component state is dynamic: it contains attributes that can change at any block, such as reserves, balances, etc.
ResponseAccount
This contains all contract data needed to perform simulations. This includes the contract address, code, storage slots, native balance, account balances, etc.
Deltas
Deltas contain only targeted changes to the component state. They are designed to be lightweight and always contain absolute new values. They will never contain delta values so that clients have an easy time updating their internal state.
Deltas include the following few special attributes:
account_updates
: Includes contract storage changes given as a contract storage key-value mapping for each involved contract address. Here, both keys and values are bytes.
new_protocol_components
: Components that were created on this block. Must not necessarily pass the tvl filter to appear here.
deleted_protocol_components
: Any components mentioned here have been removed from the protocol and are not available anymore.
new_tokens
: Token metadata of all newly created components.
component_balances
: Balances changes are emitted for every tracked protocol component.
component_tvl
: If there was a balance change in a tracked component, the new tvl for the component is emitted.
account_balances
: For protocols that need the balance (both native and ERC-20) of accounts tracked for the simulation package (like BalancerV3 which needs the Vault balances), the updated balances are emitted.
Note: exact byte encoding might differ depending on the protocol, but as a general guideline integers are big-endian encoded.
Note: for related tokens, only their addresses are emitted with the component snapshots. If you require more token information, you can request using Tycho RPC's endpoint
state_updates
: Includes attribute changes, given as a component to state key-value mapping, with keys being strings and values being bytes. The attributes provided are protocol-specific. Tycho occasionally makes use of reserved attributes, see for more details.