The GRAPH and Uniswap v2 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 v2 playground.
Code 1:
I want to see uniswap v2 general liquidity situation
{
uniswapFactories
{
# factory address
id
# pair info
pairCount
# total volume from genesis to today
totalVolumeUSD
totalVolumeETH
# total liquidity
totalLiquidityUSD
totalLiquidityETH
# transactions
txCount
}
}
Result 1:
“id” is uniswap v2 factory, “pairCount” is the number of pairs in uniswap v2, “TotalLiquidityETH” is TVL amount in the uniswap v2 as ETH and “TotalLiquidityUSD” is TVL amount in the uniswap v2 as USD.
Code 2:
I want to see most traded tokens.
{
tokens (first:5, orderBy:tradeVolumeUSD, orderDirection:desc)
{
# token address
id
# mirrored from the smart contract
symbol
name
decimals
# used for other stats like marketcap
totalSupply
# token specific volume
tradeVolume
tradeVolumeUSD
# transactions
txCount
# liquidity
totalLiquidity
}
}
Result 2:
total liquidity 882.128 ETHER for Wrapped Ether
882.128*2.721$=2.4 b
txCount: 43.171.995 transactions are realized with this token.
Code 3:
I want to see spesific pair
{
pair(id:”0x94b0a3d511b6ecdb17ebf877278ab030acb0a878")
{
reserve0,
reserve1,
reserveUSD,
trackedReserveETH
}
}
Result 3:
“0x94b0a3d511b6ecdb17ebf877278ab030acb0a878” is FEI/ETH pool, “reserve0” is FEI amount, “reserve1” is ETH amount, “reserveUSD” is total liquidity amount of the pool as $ and “trackedreserveETH” is total liquidity amount of the pool as ETHER.
Cross check !
Extra code:
{
pair(id:”0x94b0a3d511b6ecdb17ebf877278ab030acb0a878")
{
token0{name},
token1{name},
reserve0,
reserve1,
reserveUSD,
trackedReserveETH
}
}
Code 4:
I want to see most reserved pairs
{
pairs(first:5, orderBy:trackedReserveETH, orderDirection:desc)
{
# pair address
id
# mirrored from the smart contract
token0{symbol}
token1{symbol}
reserve0
reserve1
totalSupply
# derived liquidity
reserveETH
reserveUSD
trackedReserveETH
# Price in terms of the asset pair
token0Price
token1Price
# lifetime volume stats
volumeToken0
volumeToken1
volumeUSD
txCount
# Fields used to help derived relationship
liquidityProviderCount
}
}
Results 4:
token0 is FEI; token1 is WETH,
reserve0 is amount of FEI, reserve1 is amount of WETH
reserveUSD is all liquidity amount as $
cross check !
Little problem, this code can not hide untracked pairs.
Code 5:
I want to see swaps transactions of spesific pool
{
swaps(orderBy: timestamp, orderDirection: desc, where:{ pair: “0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852” } )
{
pair
{
token0 {symbol},
token1 {symbol}
},
amount0In,
amount0Out,
amount1In,
amount1Out,
amountUSD ,
transaction {id}
}
}
Result 5:
Token0 is WETH and Token1 is USDT
User “Swap USDT for ETH”, takes 1.01 WETH and gives 2.358 Tether.
Cross check!
Code 6 :
I want to see mints transactions of spesific pool
{
mints(orderBy: timestamp, orderDirection: desc, where:
{ pair: “0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852” }
)
{
pair {token0 {symbol},token1 {symbol}},
amount0,
amount1,
liquidity
}
}
Results 6:
“liquidity” variable is the minted amount as UNI .
Cross check!
Code 7 :
I want to see burns transactions of spesific pool
{
burns(orderBy: timestamp, orderDirection: desc, where:
{ pair: “0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852” }
)
{
pair {token0 {symbol},token1 {symbol}},
amount0,
amount1,
liquidity
}
}
Results 7:
The liquidity is the burned amount as UNI.
Cross check:
Code 8 :
I want to see swaps transactions of spesific user
{
swaps(first:5, where:{to:“0xee1F07F88934C2811E3DcAbdf438d975C3d62cd3"}, orderBy:timestamp,orderDirection:desc)
{
pair
{
token0{name},
token1{name}
},
amount0In,
amount0Out,
amount1In,
amount1Out,
amountUSD,
}
}
Results 8:
Code 9:
I want to see mints transactions of spesific user
{
mints(first:5, where:{to:“0x5acedba6c402e2682d312a7b4982eda0ccf2d2e3"}, orderBy:timestamp,orderDirection:desc)
{
pair
{
token0{name},
token1{name}
},
amount0,
amount1,
amountUSD,
liquidity
transaction {
id
}
}
}
Results 9:
Code 10
I want to see burns transactions of spesific user
{
burns (first:1, where:{sender:“0x1ae4e247eb47bf8a2f126b34e67c4df2aab5a024"}, orderBy:timestamp,orderDirection:desc)
{
pair
{
token0{name},
token1{name}
},
amount0,
amount1,
amountUSD
transaction {
id
}
}
}
Result 10:
Code 11:
I want to see daily transactions of spesific token
{
tokenDayDatas(orderBy: date, orderDirection: desc,
where: {
token: “0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9”
}
)
{
id
date
priceUSD
totalLiquidityToken
totalLiquidityUSD
totalLiquidityETH
dailyVolumeToken
dailyVolumeUSD
}
}
Result 11:
totalLiquidityUSD: 17.557.960
Aave Token (AAVE) ($357.8)
totalLiquidityToken: 49.071 =(17.557.960/357.8)
ETH= 2.604 USD
totalLiquidityETH: 6.742 = (17.557.960/2.604)
dailyVolumeUSD: 3.654.158
Aave Token (AAVE) ($357.8)
dailyVolumeToken: 10.212=(3.654.158/357.8)
Code 12:
I want to see daily mints transactions of spesific user
{
users(where:{id:”0x9ad4a47e223312b4d8b15d514bd1f7fb7ee6ab8b”})
{
id
}
mints(first: 3, orderBy: timestamp, orderDirection: desc)
{
transaction {
id
timestamp
}
to
liquidity
amount0
amount1
amountUSD
}
}
Results 12:
Code 13:
I want to see daily all transactions of spesific user
{
users(where:{id:”0x9ad4a47e223312b4d8b15d514bd1f7fb7ee6ab8b”})
{
id
}
mints(first: 3, orderBy: timestamp, orderDirection: desc)
{
transaction {
id
timestamp
}
to
liquidity
amount0
amount1
amountUSD
}
burns(first: 3, orderBy: timestamp, orderDirection: desc) {
transaction {
id
timestamp
}
to
liquidity
amount0
amount1
amountUSD
}
swaps(first: 3, orderBy: timestamp, orderDirection: desc) {
transaction {
id
timestamp
}
amount0In
amount0Out
amount1In
amount1Out
amountUSD
to
}
}
Result 13:
Note : 13 extra
{
users(where:{id:”0x9ad4a47e223312b4d8b15d514bd1f7fb7ee6ab8b”})
{
id
}
mints(first: 3, orderBy: timestamp, orderDirection: desc)
{
transaction {
id
timestamp
}
pair{token0{symbol},token1{symbol}}
to
liquidity
amount0
amount1
amountUSD
}
burns(first: 3, orderBy: timestamp, orderDirection: desc) {
transaction {
id
timestamp
}
pair{token0{symbol},token1{symbol}}
to
liquidity
amount0
amount1
amountUSD
}
swaps(first: 3, orderBy: timestamp, orderDirection: desc) {
transaction {
id
timestamp
}
pair{token0{symbol},token1{symbol}}
amount0In
amount0Out
amount1In
amount1Out
amountUSD
to
}
}
Code 14:
I want to see daily transactions amount in uniswap
{
uniswapDayDatas(first:50,orderBy:date,orderDirection:desc)
{
id # timestamp rounded to current day by dividing by 86400
date
dailyVolumeETH
dailyVolumeUSD
dailyVolumeUntracked
totalVolumeETH
totalLiquidityETH
totalVolumeUSD # Accumulate at each trade, not just calculated off whatever totalVolume is. making it more accurate as it is a live conversion
totalLiquidityUSD
txCount
}}
Result 14:
Cross Check
Code 15:
I want to see most reserved pools
{
pairs(first: 10, orderBy: trackedReserveETH, orderDirection: desc)
{
id
token0{name},
token1{name}
trackedReserveETH
}
}
Result 15:
Code 16:
I want to see pools daily amounts
{
pairDayDatas(first: 10, orderBy: date, orderDirection: desc,
where: {pairAddress: “0x94b0a3d511b6ecdb17ebf877278ab030acb0a878”})
{
token0{name}
token1{name}
dailyVolumeUSD
reserveUSD
}
}
Result 16:
cross check!
Code 17:
I want to see hourly pool datas
{
pairHourDatas(first: 10, orderBy:hourStartUnix orderDirection: desc,
where: {pair:”0x94b0a3d511b6ecdb17ebf877278ab030acb0a878"})
{
pair
{
token0{name}
token1{name}
},
hourlyVolumeToken0
hourlyVolumeToken1
hourlyVolumeUSD
reserve0
reserve1
reserveUSD
}
}
Result 17:
Dr. Engin YILMAZ
27.05.2021
Ankara