Execution
Supporting New Protocols
To integrate a new protocol into Tycho, you need to implement two key components:
SwapEncoder (Rust struct) – Handles swap encoding.
Executor (Solidity contract) – Executes the swap on-chain.
Main Encoder Interface
Each new protocol requires a dedicated SwapEncoder
that implements the SwapEncoder
trait. This trait defines how swaps for the protocol are encoded into calldata.
This function encodes a swap and its relevant context information into calldata that is compatible with the Executor
contract. The output of the SwapEncoder
is the input of the Executor
(see next section). See current implementations here.
Main Swap Interface
Every integrated protocol requires its own swap executor contract. This contract must conform to the IExecutor
interface, allowing it to interact with the protocol and perform swaps. See currently implemented executors here.
It has the main method:
This function:
Accepts the input amount (
givenAmount
).Processes the swap using the provided calldata (
data
) which is the output of theSwapEncoder
.Returns the final output amount (
calculatedAmount
).
Ensure that the implementation supports transferring received tokens to a designated receiver address, either within the swap function or through an additional transfer step.
If the protocol requires token approvals (allowances) before swaps can occur, manage these approvals within the implementation to ensure smooth execution of the swap.
Make sure to have an integration test that uses the calldata from the SwapEncoder
as input.
Protocols Supporting Consecutive Swap Optimizations
As described in the Swap Group section in our solver encoding docs, our swap strategies support protocols which save token transfers between consecutive swaps using systems such as flash accounting. In such cases, as shown in the diagram below using Uniswap V4 as an example, the SwapEncoder
is still only in charge of encoding a single swap. These swaps will then be concatenated at the SwapStrategy
level as a single executor call.
Depending on the index of the swap in the swap group, the executor may be responsible for adding additional information which is not necessary in other swaps of the sequence (see the first swap in the diagram below).
Deployment and Whitelisting
Once your implementation is approved:
Deploy the executor contract on the appropriate network.
Contact us to whitelist the new executor address on our main router contract.
Update the configuration by adding the new executor address to
executor_addresses.json
and register theSwapEncoder
within theSwapEncoderBuilder
.
By following these steps, your protocol will be fully integrated with Tycho, enabling it to execute swaps seamlessly.
Last updated