Overview
TheSwapData struct defines the parameters needed to execute a token swap on a decentralized exchange (DEX). It’s used throughout the LiFi system whenever tokens need to be swapped before bridging or as part of a multi-step transaction.
This flexible structure supports any DEX by encoding the specific swap calldata, making it protocol-agnostic.
Type Definition
Fields
The address of the DEX contract or router to call for executing the swap.Examples:
- Uniswap V3 Router:
0xE592427A0AEce92De3Edee1F18E0157C05861564 - 1inch Router:
0x1111111254EEB25477B68fb85Ed929f73A960582 - 0x Exchange Proxy:
0xDef1C0ded9bec7F1a1670819833240f027b25EfF
The address to approve for spending the input tokens. Often the same as
callTo, but may differ for some DEX architectures.Examples:- For most DEXs: Same as
callTo - For some aggregators: A separate proxy contract
fromAmount of sendingAssetId before executing the swap.Security: This address must also be whitelisted.The token contract address being swapped (input token).Examples:
- ERC20 token:
0x6B175474E89094C44Da98b954EedeAC495271d0F(DAI) - Native asset:
0x0000000000000000000000000000000000000000
The token contract address being received (output token).Examples:
- ERC20 token:
0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48(USDC) - Native asset:
0x0000000000000000000000000000000000000000
The exact amount of
sendingAssetId tokens to swap.Example: 1000000000000000000 (1 ETH with 18 decimals)Important: Must match the amount specified in the callData. The contract validates this to prevent manipulation.The encoded function call data to execute on the
callTo contract.Purpose: Contains the complete swap instruction including:- Function selector
- Swap path/route
- Minimum output amount (slippage protection)
- Deadline
- Recipient address
exactInputSingle callGeneration: Typically obtained from DEX APIs or SDK functions.Indicates whether the swap requires depositing native assets into a wrapped token contract (e.g., ETH -> WETH).Values:
true: Native asset will be wrapped before swappingfalse: Standard swap execution
- Swapping ETH on a DEX that only supports WETH
- Converting native assets to ERC20 before bridging
Usage Examples
Single Swap Example
Swapping ETH for USDC on Uniswap V3:Multiple Swaps Example
Executing a multi-hop swap path (DAI -> USDC -> WETH):Using with Generic Swap Facet
Generating Swap Calldata
Using DEX Aggregator APIs
Most production systems use DEX aggregator APIs to generate optimal swap routes:Using Uniswap SDK
Security Considerations
DEX Whitelisting
For security, LiFi maintains a whitelist of approved DEX contracts:Amount Validation
The contract validates thatfromAmount matches the actual swap amount to prevent manipulation:
Approval Management
The contract manages token approvals automatically:- Checks current allowance
- Resets to 0 if needed (for tokens like USDT)
- Approves exact
fromAmount - Executes swap
- Revokes any remaining approval