DEXPools Cube on EVM Chains
This section explains how the dexpool data is built and shared via APIs and Kafka streams. It also explains how to understand each entry of the response.
Note: In GraphQL, DEXPools data is accessed through two schema cubes:
DEXPoolEvents: Provides pool event data (swaps, mints, burns, etc.)DEXPoolSlippages: Provides slippage and price impact data for different trade sizes
Concept Explanation
Liquidity pools are fundamental components of decentralized exchanges that enable token swaps without traditional order books. Each pool contains two tokens (CurrencyA and CurrencyB), and the ratio of these tokens determines the exchange rate.
When a user wants to swap tokens, they interact with a liquidity pool. The pool calculates the output amount based on:
- Current liquidity reserves
- The amount being swapped
- Price impact and slippage tolerance
For example, if you want to sell ANKR tokens for WETH in a pool:
Pool: 0x13dc0a39dc00f394e030b97b0b569dedbe634c0d
DEX: uniswap_v3 (3)
Token0: ANKR (decimals: 18)
Token1: WETH (decimals: 18)
Liquidity: 604099.111169 ANKR, 1.074933 WETH
Direction: Sell ANKR → Buy WETH
slippage: 0.1%, MaxIn: 205.504593 ANKR, MinOut: 0.000434 WETH, ratio: 473132.526201 ANKR/WETH
slippage: 0.5%, MaxIn: 997.299766 ANKR, MinOut: 0.002097 WETH, ratio: 475456.664617 ANKR/WETH
slippage: 1.0%, MaxIn: 2012.776732 ANKR, MinOut: 0.004205 WETH, ratio: 478581.192432 ANKR/WETH
slippage: 2.0%, MaxIn: 4067.602247 ANKR, MinOut: 0.008289 WETH, ratio: 490722.489031 ANKR/WETH
slippage: 5.0%, MaxIn: 10501.563247 ANKR, MinOut: 0.020650 WETH, ratio: 508535.330236 ANKR/WETH
slippage: 10.0%, MaxIn: 22396.241185 ANKR, MinOut: 0.040771 WETH, ratio: 549306.392584 ANKR/WETH
If you are willing to accept a price impact and slippage of up to 10.0% against the current spot price, you can sell a maximum of 22396.241185 ANKR into the pool. In return, you are guaranteed to receive at least 0.040771 WETH. The average execution price for this trade would be approximately 549306.392584 ANKR per 1 WETH.
The calculation considers the price impact plus the worst-case scenario of slippage for different amounts, with limited losses for each, by simulating a swap by iterating through initialized ticks in the TickBitmap.
Important note: The liquidity calculation differs by protocol version:
- For Uniswap V2 and V3, liquidity reflects exactly the balance of the pool
- For Uniswap V4, liquidity is the token balances in PoolManager
Understanding Pool Structure
In DEXPools, each pool is represented with several key components:
Pool: The pool smart contract address and token pair informationDex: The DEX protocol details (name, version, family)Liquidity: Current token reserves in the poolPoolPriceTable: Price calculations for different slippage tolerances in both directions
Example Data Structure
A sample entry for a token pair shared via Bitquery Kafka streams is available here
Understanding Price Tables
The PoolPriceTable provides price information for swaps in both directions:
AtoBPrices: Array of price calculations for swapping CurrencyA to CurrencyB at different slippage tolerancesBtoAPrices: Array of price calculations for swapping CurrencyB to CurrencyA at different slippage tolerancesAtoBPrice: Current spot price for CurrencyA to CurrencyBBtoAPrice: Current spot price for CurrencyB to CurrencyA
Each price entry in the arrays contains:
SlippageBasisPoints: Slippage tolerance in basis points (100 = 1%)MaxAmountIn: Maximum input amount that can be swapped at this slippage levelMinAmountOut: Minimum output amount guaranteed at this slippage levelPrice: Average execution price for swaps at this slippage level
The following slippage levels are available in the data:
- 10 basis points (0.1%)
- 50 basis points (0.5%)
- 100 basis points (1.0%)
- 200 basis points (2.0%)
- 500 basis points (5.0%)
- 1000 basis points (10.0%)
For example, in the AtoBPrices array above, with a 10 basis point (0.1%) slippage tolerance, you can swap up to 2,557,952,147 units of CurrencyA (USDC) and receive at least 860,478,002,991,619,427 units of CurrencyB (WETH), at an average price of 0.0003364734002389014 USDC per WETH.
When is a new DEXPool record emitted in the APIs & Streams?
A new DEXPool record is emitted in the APIs and Kafka streams when specific events occur that change the pool's liquidity or state. The events tracked vary by protocol version:
Uniswap V2
The following events trigger a new DEXPool entry:
Swap(address,uint256,uint256,uint256,uint256,address)- Emitted when tokens are swapped in the poolMint(address,uint256,uint256)- Emitted when liquidity is added to the poolBurn(address,uint256,uint256,address)- Emitted when liquidity is removed from the pool