Composite Liquidity Router API

The Composite Liquidity Router can be used to interact with Balancer onchain via state changing operations or used to query operations in an off-chain context.

This is not the final version; more operations will likely be added.

State-changing functions

Composite Liquidity operations on ERC4626 pools

addLiquidityUnbalancedToERC4626Pool

function addLiquidityUnbalancedToERC4626Pool(
    address pool,
    uint256[] memory exactUnderlyingAmountsIn,
    uint256 minBptAmountOut,
    bool wethIsEth,
    bytes memory userData
) external payable returns (uint256 bptAmountOut);

Add arbitrary amounts of underlying tokens to an ERC4626 pool through the buffer. An "ERC4626 pool" contains IERC4626 yield-bearing tokens (e.g., waDAI).

Parameters:

NameTypeDescription
pooladdressAddress of the liquidity pool
exactUnderlyingAmountsInuint256[] memoryExact amounts of underlying tokens in, sorted in token registration order of wrapped tokens in the pool
minBptAmountOutuint256Minimum amount of pool tokens to be received
wethIsEthboolIf true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH
userDatabytes calldataAdditional (optional) data required for the operation

Returns:

NameTypeDescription
bptAmountOutuint256Actual amount of pool tokens received

addLiquidityProportionalToERC4626Pool

function addLiquidityProportionalToERC4626Pool(
    address pool,
    uint256[] memory maxUnderlyingAmountsIn,
    uint256 exactBptAmountOut,
    bool wethIsEth,
    bytes memory userData
) external payable returns (uint256[] memory underlyingAmountsIn);

Add proportional amounts of underlying tokens to an ERC4626 pool through the buffer. An "ERC4626 pool" contains IERC4626 yield-bearing tokens (e.g., waDAI).

Parameters:

|------------|------------------------------------|----------------------------------------------------------------------------------------------| | pool | address | Address of the liquidity pool | | maxUnderlyingAmountsIn | uint256[] memory | Maximum amounts of underlying tokens in, sorted in token registration order of wrapped tokens in the pool | | exactBptAmountOut | uint256 | Exact amount of pool tokens to be received | | wethIsEth | bool | If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH | | userData | bytes calldata | Additional (optional) data required for the operation |

Returns:

NameTypeDescription
underlyingAmountsInuint256[] memoryCalculated amounts of input tokens corresponding to the first step of each given path

removeLiquidityProportionalFromERC4626Pool

function removeLiquidityProportionalFromERC4626Pool(
    address pool,
    uint256 exactBptAmountIn,
    uint256[] memory minUnderlyingAmountsOut,
    bool wethIsEth,
    bytes memory userData
) external payable returns (uint256[] memory underlyingAmountsOut);

Remove proportional amounts of underlying from an ERC4626 pool, burning an exact pool token amount. An "ERC4626 pool" contains IERC4626 yield-bearing tokens (e.g., waDAI).

Parameters:

|------------|------------------------------------|----------------------------------------------------------------------------------------------| | pool | address | Address of the liquidity pool | | exactBptAmountIn | uint256 | Exact amount of pool tokens provided | | minUnderlyingAmountsOut | uint256[] memory | Minimum amounts of underlying tokens out, sorted in token registration order of wrapped tokens in the pool | | wethIsEth | bool | If true, incoming ETH will be wrapped to WETH and outgoing WETH will be unwrapped to ETH | | userData | bytes calldata | Additional (optional) data required for the operation |

Returns:

NameTypeDescription
underlyingAmountsOutuint256[] memoryActual amounts of tokens received, sorted in token registration order of wrapped wrapped tokens in the pool

Composite Liquidity operations on nested pools

addLiquidityUnbalancedNestedPool

function addLiquidityUnbalancedNestedPool(
    address parentPool,
    address[] memory tokensIn,
    uint256[] memory exactAmountsIn,
    uint256 minBptAmountOut,
    bytes memory userData
) external returns (uint256 bptAmountOut);

Adds liquidity unbalanced to a nested pool. A nested pool is one in which one or more tokens are BPTs from another pool (child pool). Since there are multiple pools involved, the token order is not given, so the user must specify the preferred order to inform the token in amounts.

Parameters:

NameTypeDescription
parentPooladdressAddress of the highest level pool (which contains BPTs of other pools)
tokensInuint256[] memoryInput token addresses, sorted by user preference. tokensIn array must have all tokens from child pools and all tokens that are not BPTs from the nested pool (parent pool).
exactAmountsInuint256[] memoryAmount of each underlying token in, sorted according to tokensIn array
minBptAmountOutuint256Expected minimum amount of parent pool tokens to receive
userDatabytes calldataAdditional (optional) data required for the operation

Returns:

NameTypeDescription
bptAmountOutuint256Expected amount of parent pool tokens to receive

removeLiquidityProportionalNestedPool

function removeLiquidityProportionalNestedPool(
    address parentPool,
    uint256 exactBptAmountIn,
    address[] memory tokensOut,
    uint256[] memory minAmountsOut,
    bytes memory userData
) external returns (uint256[] memory amountsOut);

Adds liquidity unbalanced to a nested pool. A nested pool is one in which one or more tokens are BPTs from another pool (child pool). Since there are multiple pools involved, the token order is not given, so the user must specify the preferred order to inform the token in amounts.

Parameters:

NameTypeDescription
parentPooladdressAddress of the highest level pool (which contains BPTs of other pools)
exactBptAmountInuint256Exact amount of parentPool tokens provided
tokensOutuint256[] memoryOutput token addresses, sorted by user preference. tokensOut array must have all tokens from child pools and all tokens that are not BPTs from the nested pool (parent pool). If not all tokens are informed, balances are not settled and the operation reverts. Tokens that repeat must be informed only once.
minAmountsOutuint256[] memoryAmount of each underlying token in, sorted according to tokensIn array
userDatabytes calldataAdditional (optional) data required for the operation

Returns:

NameTypeDescription
amountsOutuint256[] memoryActual amounts of tokens received, parallel to tokensOut

Queries

queryAddLiquidityUnbalancedToERC4626Pool

function queryAddLiquidityUnbalancedToERC4626Pool(
    address pool,
    uint256[] memory exactUnderlyingAmountsIn,
    bytes memory userData
) external returns (uint256 bptAmountOut);

Query an addLiquidityUnbalancedToERC4626Pool operation.

Parameters:

NameTypeDescription
pooladdressAddress of the liquidity pool
exactUnderlyingAmountsInuint256[] memoryExact amounts of underlying tokens in, sorted in token registration order of wrapped tokens in the pool
userDatabytes calldataAdditional (optional) data required for the operation

Returns:

NameTypeDescription
bptAmountOutuint256Actual amount of pool tokens received

queryAddLiquidityProportionalToERC4626Pool

function queryAddLiquidityProportionalToERC4626Pool(
    address pool,
    uint256 exactBptAmountOut,
    bytes memory userData
) external returns (uint256[] memory underlyingAmountsIn);

Query an addLiquidityProportionalToERC4626Pool operation.

Parameters:

|------------|------------------------------------|----------------------------------------------------------------------------------------------| | pool | address | Address of the liquidity pool | | exactBptAmountOut | uint256 | Exact amount of pool tokens to be received | | userData | bytes calldata | Additional (optional) data required for the operation |

Returns:

NameTypeDescription
underlyingAmountsInuint256[] memoryCalculated amounts of input tokens corresponding to the first step of each given path

queryRemoveLiquidityProportionalFromERC4626Pool

function queryRemoveLiquidityProportionalFromERC4626Pool(
    address pool,
    uint256 exactBptAmountIn,
    bytes memory userData
) external returns (uint256[] memory underlyingAmountsOut);

Query a removeLiquidityProportionalFromERC4626Pool operation.

Parameters:

|------------|------------------------------------|----------------------------------------------------------------------------------------------| | pool | address | Address of the liquidity pool | | exactBptAmountIn | uint256 | Exact amount of pool tokens provided | | userData | bytes calldata | Additional (optional) data required for the operation |

Returns:

NameTypeDescription
underlyingAmountsOutuint256[] memoryActual amounts of tokens received, sorted in token registration order of wrapped wrapped tokens in the pool

queryAddLiquidityUnbalancedNestedPool

function queryAddLiquidityUnbalancedNestedPool(
    address pool,
    address[] memory tokensIn,
    uint256[] memory exactAmountsIn,
    bytes memory userData
) external returns (uint256 bptAmountOut);

Query an addLiquidityUnbalancedNestedPool operation.

Parameters:

NameTypeDescription
pooladdressAddress of the liquidity pool
tokensInaddress[] memoryInput token addresses, sorted by user preference. tokensIn array must have all tokens from child pools and all tokens that are not BPTs from the nested pool (parent pool).
exactAmountsInuint256[] memoryAmount of each underlying token in, sorted according to tokensIn array
userDatabytes calldataAdditional (optional) data required for the operation

Returns:

NameTypeDescription
bptAmountOutuint256Expected amount of parent pool tokens to receive

queryRemoveLiquidityProportionalNestedPool

function queryRemoveLiquidityProportionalNestedPool(
    address parentPool,
    uint256 exactBptAmountIn,
    address[] memory tokensOut,
    bytes memory userData
) external returns (uint256[] memory amountsOut);

Query a removeLiquidityProportionalNestedPool operation.

Parameters:

NameTypeDescription
parentPooladdressAddress of the highest level pool (which contains BPTs of other pools)
exactBptAmountInuint256Exact amount of parentPool tokens provided
tokensOutaddress[] memoryOutput token addresses, sorted by user preference. tokensOut array must have all tokens from child pools and all tokens that are not BPTs from the nested pool (parent pool). If not all tokens are informed, balances are not settled and the operation reverts. Tokens that repeat must be informed only once.
userDatabytes calldataAdditional (optional) data required for the operation

Returns:

NameTypeDescription
amountsOutuint256[] memoryActual amounts of tokens received, parallel to tokensOut

Router common

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