Files
237-combo/examples/subgraphs/uniswap-v3-pools.graphql
2026-02-09 21:51:30 -08:00

138 lines
2.1 KiB
GraphQL

# Uniswap v3: Query pool data and swap information
#
# Endpoint: https://api.thegraph.com/subgraphs/name/uniswap/uniswap-v3
#
# Example queries for:
# - Pool information
# - Token prices
# - Swap history
# - Liquidity data
# Query pool by token pair
query GetPoolByPair($token0: String!, $token1: String!, $fee: BigInt!) {
pools(
where: {
token0: $token0,
token1: $token1,
feeTier: $fee
}
orderBy: totalValueLockedUSD
orderDirection: desc
first: 1
) {
id
token0 {
id
symbol
name
decimals
}
token1 {
id
symbol
name
decimals
}
feeTier
liquidity
sqrtPrice
tick
token0Price
token1Price
volumeUSD
tvlUSD
totalValueLockedUSD
}
}
# Query swap history for a pool
query GetPoolSwaps($poolId: String!, $first: Int = 100) {
swaps(
where: { pool: $poolId }
orderBy: timestamp
orderDirection: desc
first: $first
) {
id
timestamp
transaction {
id
blockNumber
}
pool {
id
token0 {
symbol
}
token1 {
symbol
}
}
sender
recipient
amount0
amount1
amountUSD
sqrtPriceX96
tick
}
}
# Query pool day data for historical analysis
query GetPoolDayData($poolId: String!, $days: Int = 30) {
poolDayDatas(
where: { pool: $poolId }
orderBy: date
orderDirection: desc
first: $days
) {
id
date
pool {
id
token0 {
symbol
}
token1 {
symbol
}
}
liquidity
sqrtPrice
token0Price
token1Price
volumeUSD
tvlUSD
feesUSD
open
high
low
close
}
}
# Query top pools by TVL
query GetTopPoolsByTVL($first: Int = 10) {
pools(
orderBy: totalValueLockedUSD
orderDirection: desc
first: $first
) {
id
token0 {
symbol
name
}
token1 {
symbol
name
}
feeTier
liquidity
volumeUSD
tvlUSD
totalValueLockedUSD
}
}