Swaps
Swaps are a core building block in Euler. They let users open leveraged positions, replace collateral, repay debt, and complete liquidations without splitting the workflow across several transactions. The EVC can combine vault operations, an external swap, and explicit result checks in one atomic batch.
Why swaps matter
Swaps support several common workflows:
- Open a leveraged position: borrow an asset, swap it for collateral, and deposit the result.
- Replace collateral: withdraw one collateral asset, swap it, and deposit the replacement.
- Repay debt: withdraw collateral, swap it for the liability asset, and repay the outstanding debt.
- Complete a liquidation: swap received collateral for the liability asset needed to repay debt.
If a required operation or post-swap check fails, the EVC batch reverts as a single transaction.
How swaps are executed
A typical EVC batch follows this progression:
- Withdraw or borrow the asset to be swapped.
- Send it to the
Swapper. - Execute the route through an external venue.
- Deposit the output, repay debt, or transfer the result as required.
- Use
SwapVerifierto check the resulting amount or remaining debt. - Complete the EVC account and vault status checks.
Swapper and SwapVerifier
Euler's reference flow separates execution from verification:
Swapperexecutes the route. It calls handlers for external venues and supports exact-input, exact-output, and target-debt modes. It is permissionless and should not retain funds or standing approvals.SwapVerifierchecks the result. The caller supplies a minimum output or maximum remaining debt and a deadline. The selected verifier function checks that condition and reverts if it is not met.- The EVC provides atomic sequencing. Place the verifier after the swap operations in the same batch so a failed postcondition reverts the transaction.
SwapVerifier checks caller-selected amount or debt bounds. It does not quote a route or calculate oracle-based price impact.
Use the Swapper source, SwapVerifier source, and periphery swap documentation for the version you integrate.
Swap modes
- Exact input: spend a specified input amount and receive the output produced by the route.
- Exact output: buy a specified output amount. Supporting handlers return unused input to the configured input vault or account.
- Target debt: calculate the amount needed to reach a debt target, execute the swap, and call
repayor_repayAndDeposit.verifyDebtMaxthen checks the remaining debt.
Handler behavior depends on the selected route and mode. Generic handlers can execute calldata built offchain, so applications should review the complete payload rather than assume every SwapParams field is enforced onchain.
Verifier output paths
| Function | Checked condition | Action after the check |
|---|---|---|
verifyAmountMinAndSkim | At least amountMin assets are available to skim from an EVault before deadline | Skims the available assets to receiver |
verifyAmountMinAndDeposit | The verifier holds at least amountMin underlying assets before deadline | Deposits its balance into the selected ERC-4626 vault for receiver |
verifyAmountMinAndTransfer | The verifier holds at least amountMin of the asset before deadline | Transfers its balance to receiver |
verifyDebtMax | Account debt is no greater than amountMax before deadline | Checks the resulting debt without performing repayment |
Example: swap collateral to repay debt
- Withdraw collateral to
Swapper. - Execute the swap in target-debt mode.
Swapperperforms the repayment and can deposit surplus output according to the selected mode. - Call
SwapVerifier.verifyDebtMaxto check that the remaining debt is within the configured maximum. - Complete the EVC account and vault status checks.
Security and integration checks
- Confirm the chain, contracts, tokens, vaults, account, receiver, handler, target, calldata, approvals, and output destination.
- Set amount or debt bounds and deadlines from the quote reviewed by the user, allowing for fees, slippage, interest accrual, and rounding.
- Simulate the complete ordered batch against current state.
- Keep approvals to
Swapperscoped to the intended transaction. - Check the resulting balances, debt, controller, collateral set, and account health after execution.