Fetching Pool List
Every Bush pool is created by one of the approved pool factories. The factory addresses for each network are listed under Pool Factories on the Deployment Addresses page, and each factory exposes the full list of pools it has deployed:
/**
* @notice Return a subset of the list of pools deployed by this factory.
* @dev `start` must be a valid index, but if `count` exceeds the total length, it will not revert, but simply
* stop at the end and return fewer results than requested.
*
* @param start The index of the first pool to return
* @param count The maximum number of pools to return
* @return pools The list of pools deployed by this factory, starting at `start` and returning up to `count` pools
*/
function getPoolsInRange(uint256 start, uint256 count) external view returns (address[] memory pools);
/**
* @notice Return the complete list of pools deployed by this factory.
* @return pools The list of pools deployed by this factory
*/
function getPools() external view returns (address[] memory pools);
/**
* @notice Check whether a pool was deployed by this factory.
* @param pool The pool to check
* @return success True if `pool` was created by this factory
*/
function isPoolFromFactory(address pool) external view returns (bool);
Factories also emit PoolCreated(address indexed pool) on every create, so an indexer can discover new pools by subscribing to the factory rather than polling. Because the factory determines the pool type, iterating the approved factories gives you both the pool list and the poolType each pool's maths needs.
Which factories exist?
The full table of approved factories, their pool type and hook, lives in the bush-pool-factories README. Not every factory is deployed on every network; the Deployment Addresses page is authoritative for what is live.
Fetching Pool Data
Swap calculations require a combination of data that can be considered as immutable and dynamic. Every pool exposes both through a pair of view functions that follow the format:
get<POOLTYPE>PoolImmutableData
e.g.:
- function getWeightedPoolImmutableData() external view returns (WeightedPoolImmutableData memory data);
- function getStablePoolImmutableData() external view returns (StablePoolImmutableData memory data);
get<POOLTYPE>PoolDynamicData
e.g.:
- function getWeightedPoolDynamicData() external view returns (WeightedPoolDynamicData memory data);
- function getStablePoolDynamicData() external view returns (StablePoolDynamicData memory data);
Immutable data (tokens, decimal scaling factors, weights, ...) can be fetched once and cached. Dynamic data (live balances, token rates, swap fee, total supply, pause state) should be refreshed per block, or on the events that change it. The exact fields for each pool type, and how they map onto the maths package's state types, are listed in Pool Maths And Details.
Together with getPoolConfig from the Vault (for the aggregate swap fee and liquidity-management flags), these two calls are everything the @bush.fi/maths Vault needs to reproduce a quote. A three-call fetch for a Weighted pool with ethers v6 looks like:
const [immutable, dynamic, config] = await Promise.all([
pool.getWeightedPoolImmutableData(),
pool.getWeightedPoolDynamicData(),
vault.getPoolConfig(POOL_ADDRESS),
]);
If a pool does not expose the helper functions, or you prefer to query for specific data, the following view functions are available on the Vault and can be used to find onchain pool state:
getPoolTokens
getPoolTokenInfo
getPoolTokenRates
getCurrentLiveBalances
getPoolConfig
getStaticSwapFeePercentage
getHooksConfig
totalSupply
isPoolPaused
isPoolInRecoveryMode