Are you an LLM? Read llms.txt for a summary of the docs, or llms-full.txt for the full context.
Skip to content

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:

  1. Withdraw or borrow the asset to be swapped.
  2. Send it to the Swapper.
  3. Execute the route through an external venue.
  4. Deposit the output, repay debt, or transfer the result as required.
  5. Use SwapVerifier to check the resulting amount or remaining debt.
  6. Complete the EVC account and vault status checks.

Swapper and SwapVerifier

Euler's reference flow separates execution from verification:

  • Swapper executes 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.
  • SwapVerifier checks 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 repay or _repayAndDeposit. verifyDebtMax then 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

FunctionChecked conditionAction after the check
verifyAmountMinAndSkimAt least amountMin assets are available to skim from an EVault before deadlineSkims the available assets to receiver
verifyAmountMinAndDepositThe verifier holds at least amountMin underlying assets before deadlineDeposits its balance into the selected ERC-4626 vault for receiver
verifyAmountMinAndTransferThe verifier holds at least amountMin of the asset before deadlineTransfers its balance to receiver
verifyDebtMaxAccount debt is no greater than amountMax before deadlineChecks the resulting debt without performing repayment

Example: swap collateral to repay debt

  1. Withdraw collateral to Swapper.
  2. Execute the swap in target-debt mode. Swapper performs the repayment and can deposit surplus output according to the selected mode.
  3. Call SwapVerifier.verifyDebtMax to check that the remaining debt is within the configured maximum.
  4. 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 Swapper scoped to the intended transaction.
  • Check the resulting balances, debt, controller, collateral set, and account health after execution.

Read next