Execution
Execute swaps through any protocol.
Last updated
Execute swaps through any protocol.
Last updated
Tycho Execution provides tools for encoding and executing swaps against Tycho routers and protocol executors. It is divided into two main components:
Encoding: A Rust crate that encodes swaps and generates calldata for execution.
Executing: Solidity contracts for executing trades on-chain.
The source code for Tycho Execution is available here. For a practical example of its usage, please refer to our Quickstart.
Tycho Execution leverages Permit2 for token approvals, simplifying the approval process while improving efficiency and security.
Before executing a swap via our router, you must approve the Permit2 contract for the specified token. You only need to do this once per token. This ensures the router has the necessary permissions to execute trades on your behalf.
When encoding a transaction, we provide functionality to build the Permit
struct. However, generating a valid signature requires access to your private key to sign the permit (that is why providing a private key is a part of the setup for encoding).
For more details on Permit2 and how to use it, see the Permit2 official documentation.
Alternatively, you have the option to transfer input tokens into the router before executing the swap (in the same transaction). This way, no approvals are necessary and a permit2 signature is not needed.
In this version of our Tycho Router, tokens are always transferred through the router before reaching the destination/next pool. This means:
The input token is transferred to the router.
The router forwards the input token to the first pool.
The output token is transferred from the pool back to the router.
The router sends the output token to the user.
For multi-hop swaps, the router handles each intermediate token transfer in the same manner.