Aggregator Router API

The Aggregator Router executes single-pool swaps for contract callers such as aggregators, solvers, and smart wallets. It is the prepaid counterpart to the Balancer Router: instead of pulling the input token through Permit2, the caller transfers the input token to the Vault before invoking the swap, and the router settles that payment. There are no token approvals and no Permit2 signatures, and the swap functions do not take a wethIsEth flag or accept ETH. See Token Approvals for how the prepaid and Permit2 models compare.

Paying the Vault

The caller must transfer the input token to the Vault in the same transaction, before the router runs. The Vault's settlement accounting reverts the swap if the prepayment does not cover the input the swap requires.

State-changing functions

swapSingleTokenExactIn

function swapSingleTokenExactIn(
    address pool,
    IERC20 tokenIn,
    IERC20 tokenOut,
    uint256 exactAmountIn,
    uint256 minAmountOut,
    uint256 deadline,
    bytes calldata userData
) external returns (uint256 amountOut);

Swaps an exact amount of tokenIn for tokenOut through a single pool. The caller must have transferred exactAmountIn of tokenIn to the Vault before this call.

Parameters:

NameTypeDescription
pooladdressAddress of the liquidity pool
tokenInIERC20Token being sent to the pool
tokenOutIERC20Token being received from the pool
exactAmountInuint256Exact amount of tokenIn (raw token decimals) the caller has pre-sent to the Vault
minAmountOutuint256Minimum amount of tokenOut to receive (slippage protection)
deadlineuint256Timestamp after which the transaction will revert
userDatabytes calldataAdditional (optional) data required for the swap

Returns:

NameTypeDescription
amountOutuint256Calculated amount of tokenOut received

swapSingleTokenExactOut

function swapSingleTokenExactOut(
    address pool,
    IERC20 tokenIn,
    IERC20 tokenOut,
    uint256 exactAmountOut,
    uint256 maxAmountIn,
    uint256 deadline,
    bytes calldata userData
) external returns (uint256 amountIn);

Swaps tokenIn for an exact amount of tokenOut through a single pool. The caller funds the Vault with tokenIn up to maxAmountIn before this call.

Parameters:

NameTypeDescription
pooladdressAddress of the liquidity pool
tokenInIERC20Token being sent to the pool
tokenOutIERC20Token being received from the pool
exactAmountOutuint256Exact amount of tokenOut to receive
maxAmountInuint256Maximum amount of tokenIn to spend (slippage protection)
deadlineuint256Timestamp after which the transaction will revert
userDatabytes calldataAdditional (optional) data required for the swap

Returns:

NameTypeDescription
amountInuint256Calculated amount of tokenIn spent

Queries

Query functions simulate a swap against current on-chain state without executing it or moving any tokens, so they require no prepayment and no approvals.

querySwapSingleTokenExactIn

function querySwapSingleTokenExactIn(
    address pool,
    IERC20 tokenIn,
    IERC20 tokenOut,
    uint256 exactAmountIn,
    address sender,
    bytes calldata userData
) external returns (uint256 amountOut);

Simulates swapSingleTokenExactIn and returns the calculated output amount.

Parameters:

NameTypeDescription
pooladdressAddress of the liquidity pool
tokenInIERC20Token being sent to the pool
tokenOutIERC20Token being received from the pool
exactAmountInuint256Exact amount of tokenIn to swap
senderaddressThe sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
userDatabytes calldataAdditional (optional) data required for the query

Returns:

NameTypeDescription
amountOutuint256Calculated amount of tokenOut received

querySwapSingleTokenExactOut

function querySwapSingleTokenExactOut(
    address pool,
    IERC20 tokenIn,
    IERC20 tokenOut,
    uint256 exactAmountOut,
    address sender,
    bytes calldata userData
) external returns (uint256 amountIn);

Simulates swapSingleTokenExactOut and returns the calculated input amount.

Parameters:

NameTypeDescription
pooladdressAddress of the liquidity pool
tokenInIERC20Token being sent to the pool
tokenOutIERC20Token being received from the pool
exactAmountOutuint256Exact amount of tokenOut to receive
senderaddressThe sender passed to the operation. It can influence results (e.g., with user-dependent hooks)
userDatabytes calldataAdditional (optional) data required for the query

Returns:

NameTypeDescription
amountInuint256Calculated amount of tokenIn spent