Initial commit: add .gitignore and README
This commit is contained in:
225
examples/subgraphs/aave-positions.graphql
Normal file
225
examples/subgraphs/aave-positions.graphql
Normal file
@@ -0,0 +1,225 @@
|
||||
# Aave v3: Query user positions and reserves
|
||||
#
|
||||
# Endpoint: https://api.thegraph.com/subgraphs/name/aave/aave-v3-[chain]
|
||||
# Replace [chain] with: ethereum, base, arbitrum, etc.
|
||||
#
|
||||
# Example queries for:
|
||||
# - User positions (supplies, borrows)
|
||||
# - Reserve data
|
||||
# - Historical data
|
||||
|
||||
# Query user position (supplies and borrows)
|
||||
query GetUserPosition($userAddress: String!) {
|
||||
user(id: $userAddress) {
|
||||
id
|
||||
reserves {
|
||||
id
|
||||
reserve {
|
||||
id
|
||||
symbol
|
||||
name
|
||||
decimals
|
||||
underlyingAsset
|
||||
liquidityRate
|
||||
variableBorrowRate
|
||||
stableBorrowRate
|
||||
aToken {
|
||||
id
|
||||
}
|
||||
vToken {
|
||||
id
|
||||
}
|
||||
sToken {
|
||||
id
|
||||
}
|
||||
}
|
||||
currentATokenBalance
|
||||
currentStableDebt
|
||||
currentVariableDebt
|
||||
principalStableDebt
|
||||
scaledVariableDebt
|
||||
liquidityRate
|
||||
usageAsCollateralEnabledOnUser
|
||||
reserve {
|
||||
price {
|
||||
priceInEth
|
||||
priceInUsd
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Query reserve data
|
||||
query GetReserves($first: Int = 100) {
|
||||
reserves(
|
||||
orderBy: totalLiquidity
|
||||
orderDirection: desc
|
||||
first: $first
|
||||
) {
|
||||
id
|
||||
symbol
|
||||
name
|
||||
decimals
|
||||
underlyingAsset
|
||||
pool {
|
||||
id
|
||||
}
|
||||
price {
|
||||
priceInEth
|
||||
priceInUsd
|
||||
}
|
||||
totalLiquidity
|
||||
availableLiquidity
|
||||
totalATokenSupply
|
||||
totalCurrentVariableDebt
|
||||
totalStableDebt
|
||||
liquidityRate
|
||||
variableBorrowRate
|
||||
stableBorrowRate
|
||||
utilizationRate
|
||||
baseLTVasCollateral
|
||||
liquidationThreshold
|
||||
liquidationBonus
|
||||
reserveLiquidationThreshold
|
||||
reserveLiquidationBonus
|
||||
reserveFactor
|
||||
aToken {
|
||||
id
|
||||
}
|
||||
vToken {
|
||||
id
|
||||
}
|
||||
sToken {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Query user transaction history
|
||||
query GetUserTransactions($userAddress: String!, $first: Int = 100) {
|
||||
userTransactions(
|
||||
where: { user: $userAddress }
|
||||
orderBy: timestamp
|
||||
orderDirection: desc
|
||||
first: $first
|
||||
) {
|
||||
id
|
||||
timestamp
|
||||
pool {
|
||||
id
|
||||
}
|
||||
user {
|
||||
id
|
||||
}
|
||||
reserve {
|
||||
symbol
|
||||
underlyingAsset
|
||||
}
|
||||
action
|
||||
amount
|
||||
referrer
|
||||
onBehalfOf
|
||||
}
|
||||
}
|
||||
|
||||
# Query deposits
|
||||
query GetDeposits($userAddress: String!, $first: Int = 100) {
|
||||
deposits(
|
||||
where: { user: $userAddress }
|
||||
orderBy: timestamp
|
||||
orderDirection: desc
|
||||
first: $first
|
||||
) {
|
||||
id
|
||||
timestamp
|
||||
user {
|
||||
id
|
||||
}
|
||||
reserve {
|
||||
symbol
|
||||
underlyingAsset
|
||||
}
|
||||
amount
|
||||
onBehalfOf
|
||||
referrer
|
||||
}
|
||||
}
|
||||
|
||||
# Query borrows
|
||||
query GetBorrows($userAddress: String!, $first: Int = 100) {
|
||||
borrows(
|
||||
where: { user: $userAddress }
|
||||
orderBy: timestamp
|
||||
orderDirection: desc
|
||||
first: $first
|
||||
) {
|
||||
id
|
||||
timestamp
|
||||
user {
|
||||
id
|
||||
}
|
||||
reserve {
|
||||
symbol
|
||||
underlyingAsset
|
||||
}
|
||||
amount
|
||||
borrowRate
|
||||
borrowRateMode
|
||||
onBehalfOf
|
||||
referrer
|
||||
}
|
||||
}
|
||||
|
||||
# Query repays
|
||||
query GetRepays($userAddress: String!, $first: Int = 100) {
|
||||
repays(
|
||||
where: { user: $userAddress }
|
||||
orderBy: timestamp
|
||||
orderDirection: desc
|
||||
first: $first
|
||||
) {
|
||||
id
|
||||
timestamp
|
||||
user {
|
||||
id
|
||||
}
|
||||
reserve {
|
||||
symbol
|
||||
underlyingAsset
|
||||
}
|
||||
amount
|
||||
useATokens
|
||||
onBehalfOf
|
||||
}
|
||||
}
|
||||
|
||||
# Query liquidations
|
||||
query GetLiquidations($first: Int = 100) {
|
||||
liquidations(
|
||||
orderBy: timestamp
|
||||
orderDirection: desc
|
||||
first: $first
|
||||
) {
|
||||
id
|
||||
timestamp
|
||||
pool {
|
||||
id
|
||||
}
|
||||
user {
|
||||
id
|
||||
}
|
||||
collateralReserve {
|
||||
symbol
|
||||
underlyingAsset
|
||||
}
|
||||
collateralAmount
|
||||
principalReserve {
|
||||
symbol
|
||||
underlyingAsset
|
||||
}
|
||||
principalAmount
|
||||
liquidator
|
||||
}
|
||||
}
|
||||
|
||||
146
examples/subgraphs/cross-protocol-analytics.graphql
Normal file
146
examples/subgraphs/cross-protocol-analytics.graphql
Normal file
@@ -0,0 +1,146 @@
|
||||
# Cross-Protocol Analytics: Query data across multiple protocols
|
||||
#
|
||||
# This is a conceptual example showing how you might query multiple subgraphs
|
||||
# to analyze cross-protocol strategies and positions.
|
||||
#
|
||||
# In production, you would:
|
||||
# 1. Query multiple subgraphs (Uniswap, Aave, etc.)
|
||||
# 2. Combine the data
|
||||
# 3. Calculate metrics like:
|
||||
# - Total TVL across protocols
|
||||
# - Cross-protocol arbitrage opportunities
|
||||
# - User positions across protocols
|
||||
# - Protocol interaction patterns
|
||||
|
||||
# Example: Query user's Aave position and Uniswap LP positions
|
||||
# (This would require querying two separate subgraphs and combining results)
|
||||
|
||||
# Query 1: Get user's Aave positions
|
||||
# (Use Aave subgraph - see aave-positions.graphql)
|
||||
|
||||
# Query 2: Get user's Uniswap v3 positions
|
||||
query GetUserUniswapPositions($userAddress: String!) {
|
||||
positions(
|
||||
where: { owner: $userAddress }
|
||||
first: 100
|
||||
) {
|
||||
id
|
||||
owner
|
||||
pool {
|
||||
id
|
||||
token0 {
|
||||
symbol
|
||||
}
|
||||
token1 {
|
||||
symbol
|
||||
}
|
||||
feeTier
|
||||
}
|
||||
liquidity
|
||||
depositedToken0
|
||||
depositedToken1
|
||||
withdrawnToken0
|
||||
withdrawnToken1
|
||||
collectedFeesToken0
|
||||
collectedFeesToken1
|
||||
transaction {
|
||||
timestamp
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
# Query 3: Get protocol volumes (for analytics)
|
||||
query GetProtocolVolumes {
|
||||
# Uniswap volume (example)
|
||||
uniswapDayDatas(
|
||||
orderBy: date
|
||||
orderDirection: desc
|
||||
first: 30
|
||||
) {
|
||||
date
|
||||
dailyVolumeUSD
|
||||
totalVolumeUSD
|
||||
tvlUSD
|
||||
}
|
||||
|
||||
# Aave volume (example - would need Aave subgraph)
|
||||
# aaveDayDatas {
|
||||
# date
|
||||
# dailyDepositsUSD
|
||||
# dailyBorrowsUSD
|
||||
# totalValueLockedUSD
|
||||
# }
|
||||
}
|
||||
|
||||
# Query 4: Get token prices across protocols
|
||||
query GetTokenPrices($tokenAddress: String!) {
|
||||
# Uniswap price
|
||||
token(id: $tokenAddress) {
|
||||
id
|
||||
symbol
|
||||
name
|
||||
decimals
|
||||
derivedETH
|
||||
poolCount
|
||||
totalValueLocked
|
||||
totalValueLockedUSD
|
||||
volume
|
||||
volumeUSD
|
||||
feesUSD
|
||||
txCount
|
||||
pools {
|
||||
id
|
||||
token0 {
|
||||
symbol
|
||||
}
|
||||
token1 {
|
||||
symbol
|
||||
}
|
||||
token0Price
|
||||
token1Price
|
||||
totalValueLockedUSD
|
||||
}
|
||||
}
|
||||
|
||||
# Aave reserve price (would need Aave subgraph)
|
||||
# reserve(id: $tokenAddress) {
|
||||
# id
|
||||
# symbol
|
||||
# price {
|
||||
# priceInUsd
|
||||
# }
|
||||
# }
|
||||
}
|
||||
|
||||
# Query 5: Get arbitrage opportunities
|
||||
# (Conceptual - would require real-time price comparison)
|
||||
query GetArbitrageOpportunities {
|
||||
# Get pools with significant price differences
|
||||
# This is a simplified example - real arbitrage detection is more complex
|
||||
pools(
|
||||
where: {
|
||||
# Filter by high volume and liquidity
|
||||
totalValueLockedUSD_gt: "1000000"
|
||||
volumeUSD_gt: "100000"
|
||||
}
|
||||
orderBy: volumeUSD
|
||||
orderDirection: desc
|
||||
first: 50
|
||||
) {
|
||||
id
|
||||
token0 {
|
||||
symbol
|
||||
}
|
||||
token1 {
|
||||
symbol
|
||||
}
|
||||
token0Price
|
||||
token1Price
|
||||
feeTier
|
||||
volumeUSD
|
||||
tvlUSD
|
||||
# Compare with prices from other DEXes/AMMs
|
||||
# (would require additional queries)
|
||||
}
|
||||
}
|
||||
|
||||
137
examples/subgraphs/uniswap-v3-pools.graphql
Normal file
137
examples/subgraphs/uniswap-v3-pools.graphql
Normal file
@@ -0,0 +1,137 @@
|
||||
# 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
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user