Executing
Once you have the calldata from Encoding, you can execute your trade in one of two ways:
Via the Tycho Router – Execute trades through our audited router for seamless execution.
Directly to the Executor – Bypass the Tycho Router and execute the trade using your own router.
Tycho Router
The source code for the Tycho Router is here (see contract addresses here). To execute a trade, simply send the calldata generated by the TychoRouterEncoder
to the router. The setup for token transfers will vary depending on the token allowance method you chose: if you're using Permit2, ensure the Permit2 contract is approved; for standard ERC-20 approvals, approve the router to spend the token; and if you're using direct transfers, make sure you send tokens to the router before execution.
For an example of how to execute trades using the Tycho Router, refer to the Quickstart.
Executing Directly to the Executor Contract
If you use the TychoExecutorEncoder
(see here how to select encoders), you will receive only the calldata for a single swap without any Tycho Router-specific data.
This provides greater control on the token transfers and approvals. But also gives you greater responsibility to make sure that the swap was executed correctly. You are responsible for token approvals, token transfers and error handling in your execution flow.
You need to integrate Tycho Executors into your own router contract. Implement a mechanism similar to our Dispatcher
, which uses delegate calls to interact with the Executor
contracts.
Steps to integrate Tycho Executors into your own router:
Implement something similar to Dispatcher that routes calldata to the correct
Executor
contract for swap and in case of callbacks.Ensure that your router contract correctly manages token approvals and transfers.
Append the calldata for the swap to your overall execution flow.
⚠️ Security Considerations
Tycho's Router has been audited, and its entire execution flow has been verified. However, when using direct execution, Tycho is not responsible for security checks, validation, or execution guarantees. You assume full responsibility for managing token approvals, transfers, and error handling. Ensure that your router contract implements the necessary security measures to prevent reentrancy, slippage manipulation, or loss of funds.
Last updated