Usage
Last updated
Was this helpful?
Last updated
Was this helpful?
This section explains how to integrate and use the Tycho-Orderbook crate in your project.
🔺 The SDK is not yet published on . For now, you can clone the repository and point the SDK dependency to the locally forked SDK.
In the Cargo.toml
of your project.
For a complete code example, please go directly to Quickstart.
The OrderbookBuilder structure is used to build an OrderbookProvider, which creates a stream of data and events for the specified network.
The builder requires a Tycho ProtocolStreamBuilder takes into account numerous configuration parameters, such as supported exchanges (Uniswap, Curve, etc.) and pool filters (minimum TVL).
The OrderbookProvider structure is the crate's main component. It listens to Tycho streams, and opens a stream on which the client will listen for new events. Each time a new event is emitted, you'll know which states have changed, i.e. liquidity pools that have executed swaps.
The OrderbookProvider has a shared memory state which is used to internally update data that includes liquidity pool (= component) data. More importantly, this Arc Mutex structure contains pointers to the simulation functions provided by Tycho for each component, used to compute the orderbooks.
You can now trigger the recalculation of the orderbook.
The solver is used here to find the optimal path for a given trade (for example, how much to allocate for 100 ETH on 5 ETH-USDC pools).
The orderbook returned is as follow.
An orderbook is characterized by a tag, which is the address of base token, a dash '-', and the address of the quote token. For instance, for BTC-USDC on ethereum, BTC is the base token.
The base token is the first token, the quote is the second, in the same order as when you request an orderbook with the 0xTokenBase-0xTokenQuote tag.
To create an orderbook and obtain its formalised bids/asks, using OrderbookProvider, you need to do:
The point structure for SinglePointSimulation can be filled in to simulate a single trade, i.e a given degree of depth in the orderbook in fact.
You can execute any transaction using the SDK, which will build the transaction to be executed on Tycho Router contract, and approve it beforehand with Permit2.
For a complete code example, please go directly to Quickstart.
You will find more information on the Tycho documentation .