Skip to content
🚧 Under Development! May be incomplete.Some pages/links may be incomplete or subject to change.

BalancerQueries

0x48B1A1A28F5600CAD50dB19c6fECBe9F2458cc8a | ABI JSON

This contract provides quotes on swaps, joins and exits, simulating these operations and returning the exact result they would have if called on the Vault given the current state.

WARNING

Be careful not to use these functions to calculate limits, maxAmountsIn or minAmountsOut from within a smart contract transaction.

Doing so will leave you vulnerable to sandwich attacks.

TIP

All of the functions are defined as mutable functions, instead of view, even though that is a common use case.

For example in ethers.js, the command would look something like:

const quote = await queryContract.callStatic.queryBatchSwap(0, [swap0, swap1], assets, funds)

Functions

querySwap

solidity
function querySwap(IVault.SingleSwap memory singleSwap, IVault.FundManagement memory funds)
    external
    returns (uint256);

queryBatchSwap

solidity
function queryBatchSwap(
    IVault.SwapKind kind,
    IVault.BatchSwapStep[] memory swaps,
    IAsset[] memory assets,
    IVault.FundManagement memory funds
) external returns (int256[] memory assetDeltas);

queryJoin

solidity
function queryJoin(bytes32 poolId, address sender, address recipient, IVault.JoinPoolRequest memory request)
    external
    returns (uint256 bptOut, uint256[] memory amountsIn);

queryExit

solidity
function queryExit(bytes32 poolId, address sender, address recipient, IVault.ExitPoolRequest memory request)
    external
    returns (uint256 bptIn, uint256[] memory amountsOut);

Structs

These structs do not belong to the Query contract, but are used as parameters in the functions above and provided for convenience below:

solidity
enum SwapKind { GIVEN_IN, GIVEN_OUT }

struct SingleSwap {
    bytes32 poolId;
    SwapKind kind;
    IAsset assetIn;
    IAsset assetOut;
    uint256 amount;
    bytes userData; // 0x for most swaps
}

struct FundManagement {
    address sender;
    bool fromInternalBalance;
    address payable recipient;
    bool toInternalBalance;
}

struct JoinPoolRequest {
    address[] assets,
    uint256[] maxAmountsIn,
    bytes userData,
    bool fromInternalBalance
}

struct ExitPoolRequest {
    address[] assets,
    uint256[] minAmountsOut,
    bytes userData,
    bool toInternalBalance
}