Global data refers to data points about the Algebra protocol as a whole. Some examples of global data points are total value locked in the protocol, total pools deployed, or total transaction counts. Thus, to query global data you must pass in the Algebra Factory address 0x8c1eb1e5325049b412b7e71337116bef88a29b3a and select the desired fields. Reference the full factory schema to see all possible fields.
Current Global Data
An example querying total pool count, transaction count, and total volume in USD and Matic:
To get data about a certain pool, pass in the pool address. Reference the full pool schema and adjust the query fields to retrieve the data points you want.
General Pool Query
The query below returns the fee, spot price, and liquidity for the WMATIC-USDC pool.
pool(id: "0xc3c4074fbc2d504fb8ccd28e3ae46914a1ecc5ed") {
tick
token0 {
symbol
id
decimals
}
token1 {
symbol
id
decimals
}
fee
sqrtPrice
liquidity
}
}
All Possible Pools
The maxiumum items you can query at once is 1000. Thus to get all possible pools, you can interate using the skip variable. To get pools beyond the first 1000 you can also set the skip as shown below.
Skipping First 1000 Pools
This query sets the skip value and returns the first 10 responses after the first 1000.
{
pools(first:10, skip:1000){
id
token0 {
id
symbol
}
token1 {
id
symbol
}
}
}
Creating a Skip Variable
This next query sets a skip variable. In your language and environment of choice you can then iterate through a loop, query to get 1000 pools each time, and continually adjust skip by 1000 until all pool responses are returned.
Note: This query will not work in the graph explorer and more resembles the structure of a query you'd pass to some graphql middleware like Apollo.
{
query pools( $skip: Int!) {
pools(
first: 1000
skip: $skip
orderDirection: asc
) {
id
sqrtPrice
token0 {
id
}
token1{
id
}
}
}
Most Liquid Pools
Retrieve the top 1000 most liquid pools. You can use this similar set up to orderBy other variables like number of swaps or volume.
To query data about a particular swap, input the transaction hash + "#" + the index in the swaps the transaction array. This is the reference for the full swap schema.
This query fetches data about the sender, receiver, amounts, transaction data, and timestamp for a particular swap.
{
swap(id: "0x0093521163d96810f7e4b86ca3d2dee27216e1049a3fb9474ebc87d34f86f747#211") {
sender
recipient
amount0
amount1
transaction {
id
blockNumber
gasLimit
gasPrice
}
timestamp
token0 {
id
symbol
}
token1 {
id
symbol
}
}
}
Recent Swaps Within a Pool
You can set the where field to filter swap data by pool address. This example fetches data about multiple swaps for the ALGB-USDC pool, ordered by timestamp.
{
swaps(orderBy: timestamp, orderDirection: desc, where:
{ pool: "0x49c1c3ac4f301ad71f788398c0de919c35eaf565" }
) {
pool {
token0 {
id
symbol
}
token1 {
id
symbol
}
}
sender
recipient
amount0
amount1
}
}
Token Data
Input the token contract address to fetch token data. Any token that exists in at least one Algebra pool can be queried. The output will aggregate data across all pools that include the token.
General Token Data
This queries the decimals, symbol, name, pool count, and volume in USD for the ALGB token. Reference the full token schema for all possible fields you can query.
{
token(id:"0x0169ec1f8f639b32eec6d923e24c2a2ff45b9dd6") {
symbol
name
decimals
volumeUSD
poolCount
}
}
Token Daily Aggregated
You can fetch aggregate data about a specific token over a 24-hour period. This query gets 10-days of the 24-hour volume data for the ALGB token ordered from oldest to newest.
{
tokenDayDatas(first: 10, where: {token: "0x0169ec1f8f639b32eec6d923e24c2a2ff45b9dd6"}, orderBy: date, orderDirection: asc) {
date
token {
id
symbol
}
volumeUSD
}
}
All Tokens
Similar to retrieving all pools, you can fetch all tokens by using skip. Note: This query will not work in the graph sandbox and more resembles the structure of a query you'd pass to some graphql middleware like Apollo.
query tokens($skip: Int!) {
tokens(first: 1000, skip: $skip) {
id
symbol
name
}
}
Position Data
General Position Data
To get data about a specific position, input the NFT tokenId. This queries the collected fees for token0 and token1 and current liquidity for the position with tokedId 3. Reference the full position schema to see all fields.
{
position(id:3) {
id
collectedFeesToken0
collectedFeesToken1
liquidity
token0 {
id
symbol
}
token1
{
id
symbol
}
}
}
Subgraph Schema
Factory entity
{
"factory addressâ
id: ID!
"amount of pools createdâ
poolCount: BigInt!
"amoutn of transactions all timeâ
txCount: BigInt!
"total volume all time in derived USDâ
totalVolumeUSD: BigDecimal!
"total volume all time in derived Maticâ
totalVolumeMatic: BigDecimal!
"total swap fees all time in USDâ
totalFeesUSD: BigDecimal!
"total swap fees all time in USDâ
totalFeesMatic: BigDecimal!
"all volume even through less reliable USD valuesâ
untrackedVolumeUSD: BigDecimal!
"TVL derived in USDâ
totalValueLockedUSD: BigDecimal!
"TVL derived in Maticâ
totalValueLockedMatic: BigDecimal!
"TVL derived in USD untrackedâ
totalValueLockedUSDUntracked: BigDecimal!
"TVL derived in Matic untrackedâ
totalValueLockedMaticUntracked: BigDecimal!
"current owner of the factoryâ
owner: ID!
}
"stores for USD calculationsâ
Bundle entity
{
id: ID!
"price of Matic in usdâ
maticPriceUSD: BigDecimal!
}
Token entity
{
"token addressâ
id: ID!
"token symbolâ
symbol: String!
"token nameâ
name: String!
"token decimalsâ
decimals: BigInt!
"token total supplyâ
totalSupply: BigInt!
"volume in token unitsâ
volume: BigDecimal!
"volume in derived USDâ
volumeUSD: BigDecimal!
"volume in USD even on pools with less reliable USD valuesâ
untrackedVolumeUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"transactions across all pools that include this tokenâ
txCount: BigInt!
"number of pools containing this tokenâ
poolCount: BigInt!
"liquidity across all pools in token unitsâ
totalValueLocked: BigDecimal!
"liquidity across all pools in derived USDâ
totalValueLockedUSD: BigDecimal!
"TVL derived in USD untrackedâ
totalValueLockedUSDUntracked: BigDecimal!
"derived price in Maticâ
derivedMatic: BigDecimal!
"pools token is in that are white listed for USD pricingâ
whitelistPools: [Pool!]!
"derived fieldsâ
tokenDayData: [TokenDayData!]! @derivedFrom(field: "token")
}
Pool entity
{
"pool addressâ
id: ID!
"creationâ
createdAtTimestamp: BigInt!
"block pool was created atâ
createdAtBlockNumber: BigInt!
"token0â
token0: Token!
"token1â
token1: Token!
"fee amount, where 1 = 0.0001%â
fee: BigInt!
"fee tierâ
feeTier: BigInt!
"in range liquidityâ
liquidity: BigInt!
"current price trackerâ
sqrtPrice: BigInt!
"tracker for global fee growthâ
feeGrowthGlobal0X128: BigInt!
"tracker for global fee growthâ
feeGrowthGlobal1X128: BigInt!
"token0 per token1â
token0Price: BigDecimal!
"token1 per token0â
token1Price: BigDecimal!
"current tickâ
tick: BigInt!
"current observation indexâ
observationIndex: BigInt!
"all time token0 swappedâ
volumeToken0: BigDecimal!
"all time token1 swappedâ
volumeToken1: BigDecimal!
"all time USD swappedâ
volumeUSD: BigDecimal!
"all time USD swapped, unfiltered for unreliable USD poolsâ
untrackedVolumeUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"all time number of transactionsâ
txCount: BigInt!
"all time fees collected token0â
collectedFeesToken0: BigDecimal!
"all time fees collected token1â
collectedFeesToken1: BigDecimal!
"all time fees collected derived USDâ
collectedFeesUSD: BigDecimal!
"total token 0 across all ticksâ
totalValueLockedToken0: BigDecimal!
"total token 1 across all ticksâ
totalValueLockedToken1: BigDecimal!
"tvl derived Maticâ
totalValueLockedMatic: BigDecimal!
"tvl USDâ
totalValueLockedUSD: BigDecimal!
"TVL derived in USD untrackedâ
totalValueLockedUSDUntracked: BigDecimal!
"Fields used to help derived relationshipâ
liquidityProviderCount: BigInt! "used to detect new exchanges
"hourly snapshots of pool dataâ
poolHourData: [PoolHourData!]! @derivedFrom(field: "pool")
"daily snapshots of pool dataâ
poolDayData: [PoolDayData!]! @derivedFrom(field: "pool")
"derived fieldsâ
mints: [Mint!]! @derivedFrom(field: "pool")
burns: [Burn!]! @derivedFrom(field: "pool")
swaps: [Swap!]! @derivedFrom(field: "pool")
collects: [Collect!]! @derivedFrom(field: "pool")
ticks: [Tick!]! @derivedFrom(field: "pool")
}
Tick entity
{
"format: <pool address>#<tick index>â
id: ID!
"pool addressâ
poolAddress: String
"tick indexâ
tickIdx: BigInt!
"pointer to poolâ
pool: Pool!
"total liquidity pool has as tick lower or upperâ
liquidityGross: BigInt!
"how much liquidity changes when tick crossedâ
liquidityNet: BigInt!
"calculated price of token0 of tick within this pool - constantâ
price0: BigDecimal!
"calculated price of token1 of tick within this pool - constantâ
price1: BigDecimal!
"lifetime volume of token0 with this tick in rangeâ
volumeToken0: BigDecimal!
"lifetime volume of token1 with this tick in rangeâ
volumeToken1: BigDecimal!
"lifetime volume in derived USD with this tick in rangeâ
volumeUSD: BigDecimal!
"lifetime volume in untracked USD with this tick in rangeâ
untrackedVolumeUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"all time collected fees in token0â
collectedFeesToken0: BigDecimal!
"all time collected fees in token1â
collectedFeesToken1: BigDecimal!
"all time collected fees in USDâ
collectedFeesUSD: BigDecimal!
"created timeâ
createdAtTimestamp: BigInt!
"created blockâ
createdAtBlockNumber: BigInt!
"Fields used to help derived relationshipâ
liquidityProviderCount: BigInt! "used to detect new exchanges
"derived fieldsâ
swaps: [Swap!]! @derivedFrom(field: "tick")
"vars needed for fee computationâ
feeGrowthOutside0X128: BigInt!
feeGrowthOutside1X128: BigInt!
}
Position entity
{
"Positions created through NonfungiblePositionManagerâ
"NFT token idâ
id: ID!
"owner of the NFTâ
owner: Bytes!
"pool position is withinâ
pool: Pool!
"allow indexing by tokensâ
token0: Token!
"allow indexing by tokensâ
token1: Token!
"lower tick of the positionâ
tickLower: Tick!
"upper tick of the positionâ
tickUpper: Tick!
"total position liquidityâ
liquidity: BigInt!
"amount of token 0 ever deposited to positionâ
depositedToken0: BigDecimal!
"amount of token 1 ever deposited to positionâ
depositedToken1: BigDecimal!
"amount of token 0 ever withdrawn from position (without fees)â
withdrawnToken0: BigDecimal!
"amount of token 1 ever withdrawn from position (without fees)â
withdrawnToken1: BigDecimal!
"all time collected token0 (withdrawnToken0 + collectedFeesToken0)â
collectedToken0: BigDecimal!
"all time collected token1 (withdrawnToken1 + collectedFeesToken1)â
collectedToken1: BigDecimal!
"all time collected fees in token0â
collectedFeesToken0: BigDecimal!
"all time collected fees in token1â
collectedFeesToken1: BigDecimal!
"tx in which the position was initializedâ
transaction: Transaction!
"vars needed for fee computationâ
feeGrowthInside0LastX128: BigInt!
feeGrowthInside1LastX128: BigInt!
}
PositionSnapshot entity
{
"<NFT token id>#<block number>â
id: ID!
"owner of the NFTâ
owner: Bytes!
"pool the position is withinâ
pool: Pool!
"position of which the snap was taken ofâ
position: Position!
"block in which the snap was createdâ
blockNumber: BigInt!
"timestamp of block in which the snap was createdâ
timestamp: BigInt!
"total position liquidityâ
liquidity: BigInt!
"amount of token 0 ever deposited to positionâ
depositedToken0: BigDecimal!
"amount of token 1 ever deposited to positionâ
depositedToken1: BigDecimal!
"amount of token 0 ever withdrawn from position (without fees)â
withdrawnToken0: BigDecimal!
"amount of token 1 ever withdrawn from position (without fees)â
withdrawnToken1: BigDecimal!
"all time collected fees in token0â
collectedFeesToken0: BigDecimal!
"all time collected fees in token1â
collectedFeesToken1: BigDecimal!
"tx in which the snapshot was initializedâ
transaction: Transaction!
"internal vars needed for fee computationâ
feeGrowthInside0LastX128: BigInt!
feeGrowthInside1LastX128: BigInt!
}
Transaction entity
{
"txn hashâ
id: ID!
"block txn was included inâ
blockNumber: BigInt!
"timestamp txn was confirmedâ
timestamp: BigInt!
"gas used during txn executionâ
gasLimit: BigInt!
gasPrice: BigInt!
"derived valuesâ
mints: [Mint!]! @derivedFrom(field: "transaction")
burns: [Burn!]! @derivedFrom(field: "transaction")
swaps: [Swap!]! @derivedFrom(field: "transaction")
flashed: [Flash!]! @derivedFrom(field: "transaction")
collects: [Collect!]! @derivedFrom(field: "transaction")
}
Mint entity
{
"transaction hash + "#" + index in mints Transaction arrayâ
id: ID!
"which txn the mint was included inâ
transaction: Transaction!
"time of txnâ
timestamp: BigInt!
"pool position is withinâ
pool: Pool!
"allow indexing by tokensâ
token0: Token!
"allow indexing by tokensâ
token1: Token!
"owner of position where liquidity minted toâ
owner: Bytes!
"the address that minted the liquidityâ
sender: Bytes
"txn originâ
origin: Bytes! "the EOA that initiated the txn
"amount of liquidity mintedâ
amount: BigInt!
"amount of token 0 mintedâ
amount0: BigDecimal!
"amount of token 1 mintedâ
amount1: BigDecimal!
"derived amount based on available prices of tokensâ
amountUSD: BigDecimal
"lower tick of the positionâ
tickLower: BigInt!
"upper tick of the positionâ
tickUpper: BigInt!
"order within the txnâ
logIndex: BigInt
}
Burn entity
{
"transaction hash + "#" + index in mints Transaction arrayâ
id: ID!
"txn burn was included inâ
transaction: Transaction!
"pool position is withinâ
pool: Pool!
"allow indexing by tokensâ
token0: Token!
"allow indexing by tokensâ
token1: Token!
"need this to pull recent txns for specific token or poolâ
timestamp: BigInt!
"owner of position where liquidity was burnedâ
owner: Bytes
"txn originâ
origin: Bytes! "the EOA that initiated the txn
"amouny of liquidity burnedâ
amount: BigInt!
"amount of token 0 burnedâ
amount0: BigDecimal!
"amount of token 1 burnedâ
amount1: BigDecimal!
"derived amount based on available prices of tokensâ
amountUSD: BigDecimal
"lower tick of positionâ
tickLower: BigInt!
"upper tick of positionâ
tickUpper: BigInt!
"position within the transactionsâ
logIndex: BigInt
}
Swap entity
{
"transaction hash + "#" + index in swaps Transaction arrayâ
id: ID!
"pointer to transactionâ
transaction: Transaction!
"timestamp of transactionâ
timestamp: BigInt!
"pool swap occured withinâ
pool: Pool!
"allow indexing by tokensâ
token0: Token!
"allow indexing by tokensâ
token1: Token!
"sender of the swapâ
sender: Bytes!
"recipient of the swapâ
recipient: Bytes!
"txn originâ
origin: Bytes! "the EOA that initiated the txn
"delta of token0 swappedâ
amount0: BigDecimal!
"delta of token1 swappedâ
amount1: BigDecimal!
"derived infoâ
amountUSD: BigDecimal!
"The sqrt(price) of the pool after the swap, as a Q64.96â
price: BigInt!
"the tick after the swapâ
tick: BigInt!
"index within the txnâ
logIndex: BigInt
}
##Collect entity
{
"transaction hash + "#" + index in collect Transaction arrayâ
id: ID!
"pointer to txnâ
transaction: Transaction!
"timestamp of eventâ
timestamp: BigInt!
"pool collect occured withinâ
pool: Pool!
"owner of position collect was performed onâ
owner: Bytes
"amount of token0 collectedâ
amount0: BigDecimal!
"amount of token1 collectedâ
amount1: BigDecimal!
"derived amount based on available prices of tokensâ
amountUSD: BigDecimal
"lower tick of positionâ
tickLower: BigInt!
"uppper tick of positionâ
tickUpper: BigInt!
"index within the txnâ
logIndex: BigInt
}
Flash entity
{
"transaction hash + "-" + index in collect Transaction array
id: ID!
"pointer to txnâ
transaction: Transaction!
"timestamp of eventâ
timestamp: BigInt!
"pool collect occured withinâ
pool: Pool!
"sender of the flashâ
sender: Bytes!
"recipient of the flashâ
recipient: Bytes!
"amount of token0 flashedâ
amount0: BigDecimal!
"amount of token1 flashedâ
amount1: BigDecimal!
"derived amount based on available prices of tokensâ
amountUSD: BigDecimal!
"amount token0 paid for flashâ
amount0Paid: BigDecimal!
"amount token1 paid for flashâ
amount1Paid: BigDecimal!
"index within the txnâ
logIndex: BigInt
}
"Data accumulated and condensed into day stats for all of Algebra
AlgebraDayData entity
{
"timestamp rounded to current day by dividing by 86400â
id: ID!
"timestamp rounded to current day by dividing by 86400â
date: Int!
"total daily volume in Algebra derived in terms of Maticâ
volumeMatic: BigDecimal!
"total daily volume in Algebra derived in terms of USDâ
volumeUSD: BigDecimal!
"total daily volume in Algebra derived in terms of USD untrackedâ
volumeUSDUntracked: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"number of daily transactionsâ
txCount: BigInt!
"tvl in terms of USDâ
tvlUSD: BigDecimal!
}
"Data accumulated and condensed into day stats for each poolâ
PoolDayData entity
{
"timestamp rounded to current day by dividing by 86400â
id: ID!
"timestamp rounded to current day by dividing by 86400â
date: Int!
"pointer to poolâ
pool: Pool!
"in range liquidity at end of periodâ
liquidity: BigInt!
"current price tracker at end of periodâ
sqrtPrice: BigInt!
"price of token0 - derived from sqrtPriceâ
token0Price: BigDecimal!
"price of token1 - derived from sqrtPriceâ
token1Price: BigDecimal!
"current tick at end of periodâ
tick: BigInt
"tracker for global fee growthâ
feeGrowthGlobal0X128: BigInt!
"tracker for global fee growthâ
feeGrowthGlobal1X128: BigInt!
"tvl derived in USD at end of periodâ
tvlUSD: BigDecimal!
"volume in token0â
volumeToken0: BigDecimal!
"volume in token1â
volumeToken1: BigDecimal!
"volume in USDâ
volumeUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"numebr of transactions during periodâ
txCount: BigInt!
"opening price of token0â
open: BigDecimal!
"high price of token0â
high: BigDecimal!
"low price of token0â
low: BigDecimal!
"close price of token0â
close: BigDecimal!
}
{
"format: <pool address>-<timestamp>â
id: ID!
"unix timestamp for start of hourâ
periodStartUnix: Int!
"pointer to poolâ
pool: Pool!
"in range liquidity at end of periodâ
liquidity: BigInt!
"current price tracker at end of periodâ
sqrtPrice: BigInt!
"price of token0 - derived from sqrtPriceâ
token0Price: BigDecimal!
"price of token1 - derived from sqrtPriceâ
token1Price: BigDecimal!
"current tick at end of periodâ
tick: BigInt
"tracker for global fee growthâ
feeGrowthGlobal0X128: BigInt!
"tracker for global fee growthâ
feeGrowthGlobal1X128: BigInt!
"tvl derived in USD at end of periodâ
tvlUSD: BigDecimal!
"volume in token0â
volumeToken0: BigDecimal!
"volume in token1â
volumeToken1: BigDecimal!
"volume in USDâ
volumeUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"numebr of transactions during periodâ
txCount: BigInt!
"opening price of token0â
open: BigDecimal!
"high price of token0â
high: BigDecimal!
"low price of token0â
low: BigDecimal!
"close price of token0â
close: BigDecimal!
}
TickHourData entity
{
"format: <pool address>-<tick index>-<timestamp>â
id: ID!
"unix timestamp for start of hourâ
periodStartUnix: Int!
"pointer to poolâ
pool: Pool!
"pointer to tickâ
tick: Tick!
"total liquidity pool has as tick lower or upper at end of periodâ
liquidityGross: BigInt!
"how much liquidity changes when tick crossed at end of periodâ
liquidityNet: BigInt!
"hourly volume of token0 with this tick in rangeâ
volumeToken0: BigDecimal!
"hourly volume of token1 with this tick in rangeâ
volumeToken1: BigDecimal!
"hourly volume in derived USD with this tick in rangeâ
volumeUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
}
"Data accumulated and condensed into day stats for each exchangeâ "Note: this entity gets saved only if there is a change during the dayâ
TickDayData entity
{
"format: <pool address>-<tick index>-<timestamp>â
id: ID!
"timestamp rounded to current day by dividing by 86400â
date: Int!
"pointer to poolâ
pool: Pool!
"pointer to tickâ
tick: Tick!
"total liquidity pool has as tick lower or upper at end of periodâ
liquidityGross: BigInt!
"how much liquidity changes when tick crossed at end of periodâ
liquidityNet: BigInt!
"hourly volume of token0 with this tick in rangeâ
volumeToken0: BigDecimal!
"hourly volume of token1 with this tick in rangeâ
volumeToken1: BigDecimal!
"hourly volume in derived USD with this tick in rangeâ
volumeUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"vars needed for fee computationâ
feeGrowthOutside0X128: BigInt!
feeGrowthOutside1X128: BigInt!
}
TokenDayData entity
{
"token address concatendated with dateâ
id: ID!
"timestamp rounded to current day by dividing by 86400â
date: Int!
"pointer to tokenâ
token: Token!
"volume in token unitsâ
volume: BigDecimal!
"volume in derived USDâ
volumeUSD: BigDecimal!
"volume in USD even on pools with less reliable USD valuesâ
untrackedVolumeUSD: BigDecimal!
"liquidity across all pools in token unitsâ
totalValueLocked: BigDecimal!
"liquidity across all pools in derived USDâ
totalValueLockedUSD: BigDecimal!
"price at end of period in USDâ
priceUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"opening price USDâ
open: BigDecimal!
"high price USDâ
high: BigDecimal!
"low price USDâ
low: BigDecimal!
"close price USDâ
close: BigDecimal!
}
TokenHourData entity
{
"token address concatendated with dateâ
id: ID!
"unix timestamp for start of hourâ
periodStartUnix: Int!
"pointer to tokenâ
token: Token!
"volume in token unitsâ
volume: BigDecimal!
"volume in derived USDâ
volumeUSD: BigDecimal!
"volume in USD even on pools with less reliable USD valuesâ
untrackedVolumeUSD: BigDecimal!
"liquidity across all pools in token unitsâ
totalValueLocked: BigDecimal!
"liquidity across all pools in derived USDâ
totalValueLockedUSD: BigDecimal!
"price at end of period in USDâ
priceUSD: BigDecimal!
"fees in USDâ
feesUSD: BigDecimal!
"opening price USDâ
open: BigDecimal!
"high price USDâ
high: BigDecimal!
"low price USDâ
low: BigDecimal!
"close price USDâ
close: BigDecimal!
}