The GRAPH and Uniswap v3 Queries
The Graph is an indexing protocol for querying networks like Ethereum and AVAX. Anyone can build and publish open APIs, called subgraphs, making data easily accessible.
We go to the Uniswap v3 playground.Uniswap uses multiple subgraphs for indexing and organizing data from the Uniswap smart contracts. These subgraphs are hosted on The Graph hosted service and can be used to query Uniswap data.
More information :https://docs.uniswap.org/sdk/Subgraph%20data
Code 1:
I want to take the general information on uniswap v3.
{
factories(skip:0) {
# factory address
id
# amount of pools created
poolCount
# amoutn of transactions all time
txCount
# total volume all time in derived USD
totalVolumeUSD
# total volume all time in derived ETH
totalVolumeETH
# total swap fees all time in USD
totalFeesUSD
# total swap fees all time in USD
totalFeesETH
# all volume even through less reliable USD values
untrackedVolumeUSD
# TVL derived in USD
totalValueLockedUSD
# TVL derived in ETH
totalValueLockedETH
# TVL derived in USD untracked
totalValueLockedUSDUntracked
# TVL derived in ETH untracked
totalValueLockedETHUntracked
}
}
We talk about json logic:
type(response) is dict
{'factories': [{'id': '0x1F98431c8aD98523631AE4a59f267346ea31F984', 'poolCount': '3108', 'totalFeesETH': '64339.17528605831564341428863547072', 'totalFeesUSD': '166191908.6852649421824730816523766', 'totalValueLockedETH': '789392.1702101651299368866954142591', 'totalValueLockedETHUntracked': '0', 'totalValueLockedUSD': '1682173968.841804802459660889464065', 'totalValueLockedUSDUntracked': '0', 'totalVolumeETH': '26493050.66265835052862303122447492', 'totalVolumeUSD': '66082975195.4531151739114271769025', 'txCount': '2620728', 'untrackedVolumeUSD': '65991950057.08766333021566538189752'}]}
type(response[“factories”]) is list
[{'id': '0x1F98431c8aD98523631AE4a59f267346ea31F984',
'poolCount': '3108',
'totalFeesETH': '64339.17528605831564341428863547072',
'totalFeesUSD': '166191908.6852649421824730816523766',
'totalValueLockedETH': '789392.1702101651299368866954142591',
'totalValueLockedETHUntracked': '0',
'totalValueLockedUSD': '1682173968.841804802459660889464065',
'totalValueLockedUSDUntracked': '0',
'totalVolumeETH': '26493050.66265835052862303122447492',
'totalVolumeUSD': '66082975195.4531151739114271769025',
'txCount': '2620728',
'untrackedVolumeUSD': '65991950057.08766333021566538189752'}]
type(response[“factories”][0]) is dict
{'id': '0x1F98431c8aD98523631AE4a59f267346ea31F984',
'poolCount': '3108',
'totalFeesETH': '64339.17528605831564341428863547072',
'totalFeesUSD': '166191908.6852649421824730816523766',
'totalValueLockedETH': '789392.1702101651299368866954142591',
'totalValueLockedETHUntracked': '0',
'totalValueLockedUSD': '1682173968.841804802459660889464065',
'totalValueLockedUSDUntracked': '0',
'totalVolumeETH': '26493050.66265835052862303122447492',
'totalVolumeUSD': '66082975195.4531151739114271769025',
'txCount': '2620728',
'untrackedVolumeUSD': '65991950057.08766333021566538189752'}
type(response[“factories”][0][“poolCount”])is str
'3108'
Code 2:
{
tokens(first:5, orderBy:totalValueLockedUSD, orderDirection:desc)
{
# token address
id
# token symbol
symbol
# token name
name
# token decimals
decimals
# token total supply
totalSupply
# volume in token units
volume
# volume in derived USD
volumeUSD
# volume in USD even on pools with less reliable USD values
untrackedVolumeUSD
# fees in USD
feesUSD
# transactions across all pools that include this token
txCount
# number of pools containing this token
poolCount
# liquidity across all pools in token units
totalValueLocked
# liquidity across all pools in derived USD
totalValueLockedUSD
# TVL derived in USD untracked
totalValueLockedUSDUntracked
# derived price in ETH
derivedETH
# pools token is in that are white listed for USD pricing
}
}
Code 3:
{
pools(first: 5, orderBy:totalValueLockedUSD,orderDirection:desc) {
# pool address
id
# creation
createdAtTimestamp
# block pool was created at
createdAtBlockNumber
# token0
token0{name}
# token1
token1{name}
# fee amount
feeTier
# in range liquidity
liquidity
# current price tracker
sqrtPrice
# tracker for global fee growth
feeGrowthGlobal0X128
# tracker for global fee growth
feeGrowthGlobal1X128
# token0 per token1
token0Price
# token1 per token0
token1Price
# current tick
tick
# current observation index
observationIndex
# all time token0 swapped
volumeToken0
# all time token1 swapped
volumeToken1
# all time USD swapped
volumeUSD
# all time USD swapped, unfiltered for unreliable USD pools
untrackedVolumeUSD
# fees in USD
feesUSD
# all time number of transactions
txCount
# all time fees collected token0
collectedFeesToken0
# all time fees collected token1
collectedFeesToken1
# all time fees collected derived USD
collectedFeesUSD
# total token 0 across all ticks
totalValueLockedToken0
# total token 1 across all ticks
totalValueLockedToken1
# tvl derived ETH
totalValueLockedETH
# tvl USD
totalValueLockedUSD
# TVL derived in USD untracked
totalValueLockedUSDUntracked
# Fields used to help derived relationship
liquidityProviderCount # used to detect new exchanges
# hourly snapshots of pool data
}
}