Aggregator Batch Router API

The Aggregator Batch Router executes multi-hop swaps across multiple pools and tokens for contract callers such as aggregators, solvers, and smart wallets. It is the prepaid counterpart to the Batch Router: instead of pulling input tokens through Permit2, the caller transfers them to the Vault before invoking the swap, and the router settles that payment. See Token Approvals for how the prepaid and Permit2 models compare.

Paying the Vault

The caller transfers the input tokens to the Vault in the same transaction, before the router runs; the Vault's settlement accounting reverts the swap if the prepayment is insufficient. Unlike the retail Batch Router these functions take no wethIsEth flag, and the router does not use Permit2 (getPermit2 returns the zero address). The permitBatchAndCall and multicall approval helpers inherited from the shared router base are not usable on this prepaid router.

State-changing functions

swapExactIn

function swapExactIn(
    SwapPathExactAmountIn[] memory paths,
    uint256 deadline,
    bytes calldata userData
)
    external
    payable
    returns (uint256[] memory pathAmountsOut, address[] memory tokensOut, uint256[] memory amountsOut);

Executes a swap involving multiple paths (steps), specifying exact input token amounts. Each path is independent and can have multiple hops. The caller must have transferred each path's input token to the Vault before this call.

Example: Swap USDC → DAI → WETH in one path, and USDC → USDT → WETH in another path, all in one transaction.

Parameters:

NameTypeDescription
pathsSwapPathExactAmountIn[] memorySwap paths from token in to token out, specifying exact amounts in
deadlineuint256Deadline for the swap, after which it will revert
userDatabytes calldataAdditional (optional) data required for the swap

Returns:

NameTypeDescription
pathAmountsOutuint256[] memoryCalculated amounts of output tokens corresponding to the last step of each given path
tokensOutaddress[] memoryOutput token addresses
amountsOutuint256[] memoryCalculated amounts of output tokens, ordered by output token address

swapExactOut

function swapExactOut(
    SwapPathExactAmountOut[] memory paths,
    uint256 deadline,
    bytes calldata userData
) external payable returns (uint256[] memory pathAmountsIn, address[] memory tokensIn, uint256[] memory amountsIn);

Executes a swap involving multiple paths (steps), specifying exact output token amounts. The caller funds the Vault with each path's input token, up to the path's maxAmountIn, before this call.

Parameters:

NameTypeDescription
pathsSwapPathExactAmountOut[] memorySwap paths from token in to token out, specifying exact amounts out
deadlineuint256Deadline for the swap, after which it will revert
userDatabytes calldataAdditional (optional) data required for the swap

Returns:

NameTypeDescription
pathAmountsInuint256[] memoryCalculated amounts of input tokens corresponding to the first step of each given path
tokensInaddress[] memoryInput token addresses
amountsInuint256[] memoryCalculated amounts of input tokens, ordered by input token address

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.

querySwapExactIn

function querySwapExactIn(
    SwapPathExactAmountIn[] memory paths,
    address sender,
    bytes calldata userData
) external returns (uint256[] memory pathAmountsOut, address[] memory tokensOut, uint256[] memory amountsOut);

Simulates swapExactIn without executing it.

Parameters:

NameTypeDescription
pathsSwapPathExactAmountIn[] memorySwap paths from token in to token out, specifying exact amounts in
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
pathAmountsOutuint256[] memoryCalculated amounts of output tokens corresponding to the last step of each given path
tokensOutaddress[] memoryCalculated output token addresses
amountsOutuint256[] memoryCalculated amounts of output tokens, ordered by output token address

querySwapExactOut

function querySwapExactOut(
    SwapPathExactAmountOut[] memory paths,
    address sender,
    bytes calldata userData
) external returns (uint256[] memory pathAmountsIn, address[] memory tokensIn, uint256[] memory amountsIn);

Simulates swapExactOut without executing it.

Parameters:

NameTypeDescription
pathsSwapPathExactAmountOut[] memorySwap paths from token in to token out, specifying exact amounts out
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
pathAmountsInuint256[] memoryCalculated amounts of input tokens corresponding to the first step of each given path
tokensInaddress[] memoryCalculated input token addresses
amountsInuint256[] memoryCalculated amounts of input tokens, ordered by input token address

Data Structures

These are the same path structures used by the Batch Router.

SwapPathStep

struct SwapPathStep {
    address pool;        // Pool to swap through
    IERC20 tokenOut;     // Token to receive from this step
    bool isBuffer;       // If true, use ERC4626 buffer instead of pool
}

Defines a single step in a swap path.

Fields:

NameTypeDescription
pooladdressAddress of the pool to swap through
tokenOutIERC20Token to receive from this step
isBufferboolIf true, the "pool" is an ERC4626 Buffer used to wrap/unwrap tokens if the pool doesn't have enough liquidity

SwapPathExactAmountIn

struct SwapPathExactAmountIn {
    IERC20 tokenIn;             // Starting token
    SwapPathStep[] steps;       // Swap steps to execute
    uint256 exactAmountIn;      // Exact amount to send
    uint256 minAmountOut;       // Minimum amount to receive
}

Defines a swap path with an exact input amount.

Fields:

NameTypeDescription
tokenInIERC20Starting token for this path
stepsSwapPathStep[]Array of swap steps to execute
exactAmountInuint256Exact amount of tokenIn to send
minAmountOutuint256Minimum amount of final output token to receive (slippage protection)

SwapPathExactAmountOut

struct SwapPathExactAmountOut {
    IERC20 tokenIn;             // Starting token
    SwapPathStep[] steps;       // Swap steps to execute
    uint256 maxAmountIn;        // Maximum amount to send
    uint256 exactAmountOut;     // Exact amount to receive
}

Defines a swap path with an exact output amount.

Fields:

NameTypeDescription
tokenInIERC20Starting token for this path
stepsSwapPathStep[]Array of swap steps to execute
maxAmountInuint256Maximum amount of tokenIn to send (slippage protection)
exactAmountOutuint256Exact amount of final output token to receive