Skip to main content

Swaps in Euler

Token swaps are essential within a lending platform for three main reasons: building leverage, rebalancing positions, and selling collateral during liquidations. Traditionally, to build leverage, users would either loop manually (borrow, swap on an external DEX, deposit, repeat) or use external flash loans. Both methods are suboptimal in terms of gas costs and user experience. To address these shortcomings, Euler integrates swapping directly into the system.

Creating or closing leveraged positions requires swapping between collateral and borrowed assets. When a multiply position is created, borrowed assets are swapped for collateral assets and deposited into the collateral vault. Thanks to deferred liquidity checks, this can happen in a single transaction, achieving the same effect as traditional looping. To close a leveraged position, the collateral asset is withdrawn from the collateral vault, swapped for the debt asset, and used to repay the debt in the liability vault—all within a single transaction.

The trade itself is executed on an external DEX. Users do not need to withdraw assets to their wallets or send separate transactions. Instead, within a single EVC batch, the sold assets are withdrawn to a periphery contract, which executes the trade on the DEX. The proceeds are then deposited back into the selected vault or used to repay the debt. To ensure the best possible trade execution, multiple swap aggregators like 1Inch, LI.FI, and Paraswap are queried by an off-chain meta-aggregator, which selects the best quote and passes it to the swapping contract. The periphery contracts then deposit the acquired assets back for the user or use them to repay the user's debt.

The meta-aggregator is available as an open-source API. Given the trade parameters, it generates complete transaction payloads that can be used directly in an EVC batch.

To find out more about the swapping infrastructure, please see: