Batch Router API

The Batch Router can be used to interact with Balancer onchain via state changing operations or used to query operations in an offchain context.

State-changing functions

Batch swaps

swapExactIn

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

Executes a swap operation involving multiple paths (steps), specifying exact input token amounts.

Parameters:

NameTypeDescription
pathsSwapPathExactAmountIn[] memorySwap paths from token in to token out, specifying exact amounts in.
deadlineuint256Deadline for the swap, after which it will revert
wethIsEthboolIf true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
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[] memoryCalculated output token addresses
amountsOutuint256[] memoryCalculated amounts of output tokens, ordered by output token address

swapExactOut

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

Executes a swap operation involving multiple paths (steps), specifying exact output token amounts.

Parameters:

NameTypeDescription
pathsSwapPathExactAmountOut[] memorySwap paths from token in to token out, specifying exact amounts out.
deadlineuint256Deadline for the swap, after which it will revert
wethIsEthboolIf true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
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[] memoryCalculated input token addresses
amountsInuint256[] memoryCalculated amounts of input tokens, ordered by input token address

Queries

querySwapExactIn

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

Queries a swap operation involving multiple paths (steps), specifying exact input token amounts.

Parameters:

NameTypeDescription
pathsSwapPathExactAmountIn[] memorySwap paths from token in to token out, specifying exact amounts in.
userDatabytes calldataAdditional (optional) data required for the query

Returns:

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

querySwapExactOut

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

Queries a swap operation involving multiple paths (steps), specifying exact output token amounts.

Parameters:

NameTypeDescription
pathsSwapPathExactAmountOut[] memorySwap paths from token in to token out, specifying exact amounts out.
userDatabytes calldataAdditional (optional) data required for the query

Returns:

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

Router common

See the bottom of the Router for functions common to both the Router and BatchRouter.