Swaps
Introduction
Token swaps play a critical role within Euler’s lending platform, enabling leverage building, position rebalancing, and collateral liquidation. Traditionally, users seeking leverage would either manually loop transactions (borrow, swap on an external DEX, deposit, and repeat) or use external flash loans, both of which are costly in gas fees and cumbersome in execution. To streamline this process, Euler natively integrates swapping within the platform, eliminating inefficiencies.
Efficient leverage management
Swapping is essential when creating or closing leveraged positions:
- Opening a leveraged position: Borrowed assets are swapped for collateral assets and deposited directly into the collateral vault. Deferred liquidity checks allow this to happen in a single transaction, replicating traditional looping but with significantly lower gas costs.
- Closing a leveraged position: The collateral asset is withdrawn, swapped for the debt asset, and used to repay the liability—all within a single batch transaction.
How Euler executes swaps
Instead of requiring users to manually withdraw and swap assets, Euler integrates DEX-based trading directly into the Ethereum Vault Connector (EVC) batch system:
-
Asset withdrawal and trade execution
- The sold asset is withdrawn and sent to a periphery contract.
- This contract executes the trade on an external DEX.
-
Optimised trade routing
- An off-chain meta-aggregator queries multiple swap aggregators (e.g., 1Inch, LI.FI, Paraswap) to find the best quote.
- The optimal trade route is selected and passed to the swapping contract.
-
Deposit or debt repayment
- The proceeds from the swap are either deposited back into a vault or used to repay debt in the liability vault.
- This ensures seamless position adjustments without requiring manual asset transfers.
Meta-aggregator API: automated swap execution
Euler provides an open-source meta-aggregator API, which:
- Accepts trade parameters and identifies the best execution route.
- Generates a ready-to-use transaction payload for inclusion in an EVC batch.
- Allows developers and users to execute swaps programmatically with minimal overhead.
Further reading
For more details on Euler’s swapping infrastructure, explore:
- Swapping periphery contracts – Technical documentation on swap execution within Euler.
- Swaps meta-aggregator API – API reference for accessing swap aggregation services.