Skip to main content

EVM Router Swap Functions

EVM Router is the advanced router contract for executing token swaps across multiple protocols on EVM-compatible chains. It supports native token handling, multi-hop swaps, integrator fee/surplus sharing, and permit-based approvals.

Overview

EVM Router provides three main swap functions:
  1. swap - Standard swap function for normal token exchanges
  2. swapIntegrator - Swap with integrator fee or surplus sharing
  3. swapWithPermit - Swap with ERC-20 permit signature (gasless approval)
All swap functions support:
  • Multi-hop swaps across different protocols
  • Native token handling (MONAD ↔ WMONAD conversion)
  • Rate-based amount distribution for splitting input across multiple swaps
  • Surplus handling to cap output at expected amount
  • Minimum received protection to ensure slippage tolerance

Contract ABI

Router Contract ABI: The complete Application Binary Interface (ABI) for EVM Router is available on GitHub:🔗 View Router ABI on GitHubThe ABI includes all function signatures, event definitions, and error types needed for integration.

Function: swap

Performs a standard token swap using the provided route and swap parameters.

Signature

Parameters

route (RouteParam)

The route parameters defining the overall swap path.

swap_parameters (SwapParams[])

Array of swap parameters for each hop in the multi-hop swap.

Returns

  • uint256: Amount of output tokens received by the destination address

Behavior

  1. Validation: Checks that token_in != token_out, amount_in > 0, min_received > 0, and swap_parameters.length > 0
  2. Token Transfer:
    • For tokenToToken and tokenToEth: Transfers amount_in from msg.sender to contract
    • For ethToToken: Expects ETH sent with transaction (msg.value)
  3. Multi-Hop Execution:
    • For first swap: Uses route.amount_in multiplied by first swap’s rate
    • For subsequent swaps: Uses previous swap’s output multiplied by current swap’s rate
    • Handles native token conversion (MONAD ↔ WMONAD) if protocol supports it
  4. Surplus Handling:
    • If actual output > route.amount_out, caps output at route.amount_out
    • User receives capped amount, surplus stays in contract
  5. Slippage Protection:
    • Verifies actual_output >= route.min_received
    • Reverts with MinReceivedAmountNotReached if check fails
  6. Token Transfer: Sends output tokens to destination (or msg.sender if destination == address(0))

Example

See EVM Router Events for complete event documentation.

Errors


Function: swapIntegrator

Performs a swap with integrator fee or surplus sharing. Integrators can monetize by taking a percentage fee from output or sharing in surplus profits.

Signature

Parameters

route (RouteParam)

Same as swap function. See swap route parameters.

swap_parameters (SwapParams[])

Same as swap function. See swap parameters.

integrator_data (bytes)

Encoded IntegratorParams struct:
Important: You cannot use both fee_percentage and surplus_percentage simultaneously. Choose one monetization model.

Returns

  • uint256: Amount of output tokens received by the user (after integrator fee/surplus)

Behavior

Fee-Based Model (fee_percentage > 0)

  1. Executes swaps normally
  2. Calculates total amount received
  3. Calculates integrator fee: fee_amount = (total_received * fee_percentage) / 10000
  4. User receives: total_received - fee_amount
  5. Integrator receives: fee_amount
Example:
  • Total received: 1000 tokens
  • Fee percentage: 100 bips (1%)
  • Integrator fee: 10 tokens
  • User receives: 990 tokens

Surplus-Based Model (surplus_percentage > 0)

  1. Executes swaps normally
  2. Calculates total amount received
  3. Calculates surplus: surplus = max(0, total_received - route.amount_out)
  4. If surplus > 0:
    • Integrator share: (surplus * surplus_percentage) / 10000
    • User receives: route.amount_out (capped at expected)
    • Integrator receives: integrator share of surplus
  5. If surplus == 0:
    • User receives: total_received
    • Integrator receives: 0
Example:
  • Expected output: 1000 tokens
  • Actual received: 1050 tokens
  • Surplus: 50 tokens
  • Surplus percentage: 2000 bips (20%)
  • Integrator share: 10 tokens
  • User receives: 1000 tokens (capped)
  • Integrator receives: 10 tokens

min_received Calculation

Critical: When using integrator fees, min_received is checked AFTER deducting the fee. This ensures users receive at least min_received after all fees.
Formula:

Example

See EVM Router Events for complete event documentation, including IntegratorFeeDistribution event details.

Errors

All errors from swap function, plus:

Function: swapWithPermit

Performs a swap using ERC-20 permit signature for gasless token approval. This allows users to approve tokens without a separate transaction.

Signature

Parameters

route (RouteParam)

Same as swap function. See swap route parameters. Note: route.token_in must be an ERC-20 token that supports permit (ERC-2612).

swap_parameters (SwapParams[])

Same as swap function. See swap parameters.

deadline (uint256)

Unix timestamp after which the permit signature expires. Must be >= block.timestamp.

v, r, s (uint8, bytes32, bytes32)

ECDSA signature components for the permit. Generated by signing:

Returns

  • uint256: Amount of output tokens received by the destination address

Behavior

  1. Permit Validation: Checks deadline >= block.timestamp
  2. Permit Execution: Calls IERC20Permit(route.token_in).permit(...) with signature
  3. Swap Execution: Executes swap using same logic as swap function

Example

Errors

All errors from swap function, plus:

Advanced Features

Native Token Support

EVM Router supports native token swaps through automatic wrapped token conversion. How it works:
  • Protocols can support native token pairs (e.g., ETH/TOKEN) or wrapped pairs (e.g., WETH/TOKEN)
  • EVM Router automatically converts native ↔ wrapped tokens when needed
  • Conversion is controlled by shouldConvertInput flag in extra_data
Example Scenarios:
  1. MONAD → USDC (using WMONAD/USDC pool):
    • User sends MONAD
    • Router wraps to WMONAD
    • Swaps WMONAD → USDC
  2. WMONAD → USDC (using MONAD/USDC pool):
    • User sends WMONAD
    • Router unwraps to MONAD
    • Swaps MONAD → USDC
extra_data Format (for protocols with native support):

Rate-Based Amount Distribution

Each swap in swap_parameters has a rate field that determines what percentage of input to use. Rate Calculation:
Example:
  • First swap: rate = 1000000 (100%) → Uses all input
  • Second swap: rate = 500000 (50%) → Uses 50% of first swap’s output
  • Third swap: rate = 1000000 (100%) → Uses all of second swap’s output
Use Cases:
  • Splitting input across multiple pools for better execution
  • Partial swaps with different protocols
  • Complex routing strategies

Surplus Handling

EVM Router caps output at route.amount_out to prevent users from receiving unexpected excess. Surplus Calculation:
Why it matters:
  • Protects against unexpected price improvements
  • Ensures predictable output amounts
  • Enables integrator surplus sharing

Common Patterns

Simple Token-to-Token Swap

Multi-Hop Swap

Integrator Fee Swap


Error Reference


Contract Address

EVM Router is deployed on multiple EVM-compatible networks. Check Contract Addresses for the latest deployment addresses. Contract ABI: View on GitHub