DeFi and Swap Routing
Find optimal paths for entering/exiting DeFi positions or swapping ERC20 tokens.
The route
API calculates an optimal path from one position to another by analyzing different protocols in real time.
This API takes specification of DeFi route endpoints and returns a transaction object with calldata ready for on-chain submission.
The route
API supports tokenized protocols, meaning you receive a token representing your position (like aTokens in Aave).
To enter a non-tokenized position, use the GET route/nontokenized
endpoint.
In this guide we’ll obtain optimal transaction to enter a Curve position with ETH.
Authentication
- Create an API key using Enso Dashboard.
- Securely store your API key and make it available in your environment:
Get Optimal Path Calldata
To use the route
API, you need to provide several parameters: input and output token, amount, slippage, and participating account addresses.
Set protocol
parameter to enso
when signing transactions through an EOA, and use delegatecall
when signing through a smart wallet. Learn more about routing strategies.
The API response will contain:
route
: A human-readable sequence of actions against supported protocolstx
: A transaction object with calldata—the executable form of the calculated routeamountOut
: Expected output amountgas
: Estimated gas for the transactioncreatedAt
: Block number when the response was generated
The route response returns the tx
object containing executable transaction data. The tx.data
executes the optimal path and must be submitted directly to the EnsoShortcutRouter
contract at the address specified in tx.to
.
Send transaction on-chain
Use the result’s tx
field to send the transaction on-chain.
Next steps
- Check out the API Reference for full parameter details.
- Explore Bundling Actions to construct transactions for custom DeFi strategies.
- Check out Shortucts Library for common DeFi workflows.