Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge new logic with monorepo #155

Open
wants to merge 8 commits into
base: mono-repo
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
# Uniswap V3 Subgraph

This code is an updated, more accurate, version of the original v3 subgraph. This code fixes issues in TVL, collect events, and more.

The main difference is that this subgraph does not track data related to positions. The reason is that to track position data accurately, we need to use multiple `eth_calls` within the subgraph mappings - `eth_calls` consume about 60-80% of sync time in the original subgraph. Without these, the subgrpah can be synced in a matter of weeks as opposed to a matter of months.

More documentation will be coming soon.

### Subgraph Endpoint

Synced at: https://thegraph.com/hosted-service/subgraph/ianlapham/uniswap-v3-subgraph?selected=playground
Synced at: https://thegraph.com/hosted-service/subgraph/ianlapham/v3-minimal

Pending Changes at same URL
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "graph build",
"create-local": "graph create ianlapham/uniswap-v3 --node http://127.0.0.1:8020",
"deploy-local": "graph deploy ianlapham/uniswap-v3 --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy uniswap/uniswap-v3 --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy": "graph deploy ianlapham/v3-minimal --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --debug",
"deploy-dev": "graph deploy sommelier/uniswap-v3 --ipfs http://35.197.14.14:5000/ --node http://35.197.14.14:8020/ --debug",
"deploy-staging": "graph deploy $THE_GRAPH_GITHUB_USER/$THE_GRAPH_SUBGRAPH_NAME /Uniswap --ipfs https://api.staging.thegraph.com/ipfs/ --node https://api.staging.thegraph.com/deploy/",
"watch-local": "graph deploy ianlapham/uniswap-v3 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001"
Expand Down
210 changes: 29 additions & 181 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ type Factory @entity {
# amoutn of transactions all time
txCount: BigInt!
# total volume all time in derived USD
totalVolumeUSD: BigDecimal!
volumeUSD: BigDecimal!
# total volume all time in derived ETH
totalVolumeETH: BigDecimal!
volumeETH: BigDecimal!
# all volume even through less reliable USD values
volumeUSDUntracked: BigDecimal!
# total swap fees all time in USD
totalFeesUSD: BigDecimal!
feesUSD: BigDecimal!
# total swap fees all time in USD
totalFeesETH: BigDecimal!
# all volume even through less reliable USD values
untrackedVolumeUSD: BigDecimal!
feesETH: BigDecimal!
# TVL derived in USD
totalValueLockedUSD: BigDecimal!
# TVL derived in ETH
Expand All @@ -23,7 +23,6 @@ type Factory @entity {
totalValueLockedUSDUntracked: BigDecimal!
# TVL derived in ETH untracked
totalValueLockedETHUntracked: BigDecimal!

# current owner of the factory
owner: ID!
}
Expand Down Expand Up @@ -51,7 +50,7 @@ type Token @entity {
# volume in derived USD
volumeUSD: BigDecimal!
# volume in USD even on pools with less reliable USD values
untrackedVolumeUSD: BigDecimal!
volumeUSDUntracked: BigDecimal!
# fees in USD
feesUSD: BigDecimal!
# transactions across all pools that include this token
Expand All @@ -62,8 +61,6 @@ type Token @entity {
totalValueLocked: BigDecimal!
# liquidity across all pools in derived USD
totalValueLockedUSD: BigDecimal!
# TVL derived in USD untracked
totalValueLockedUSDUntracked: BigDecimal!
# derived price in ETH
derivedETH: BigDecimal!
# pools token is in that are white listed for USD pricing
Expand Down Expand Up @@ -108,27 +105,29 @@ type Pool @entity {
# all time USD swapped
volumeUSD: BigDecimal!
# all time USD swapped, unfiltered for unreliable USD pools
untrackedVolumeUSD: BigDecimal!
volumeUSDUntracked: 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 ETH
# TVL derived ETH
totalValueLockedETH: BigDecimal!
# tvl USD
# TVL USD
totalValueLockedUSD: BigDecimal!
# TVL derived in ETH untracked
totalValueLockedETHUntracked: BigDecimal!
# TVL derived in USD untracked
totalValueLockedUSDUntracked: BigDecimal!
# all time fees collected token0
collectedFeesToken0: BigDecimal!
# all time fees collected token1
collectedFeesToken1: BigDecimal!
# all time fees collected derived USD
collectedFeesUSD: BigDecimal!
# Fields used to help derived relationship
liquidityProviderCount: BigInt! # used to detect new exchanges
# hourly snapshots of pool data
Expand All @@ -150,6 +149,10 @@ type Tick @entity {
poolAddress: String
# tick index
tickIdx: BigInt!
# created time
createdAtTimestamp: BigInt!
# created block
createdAtBlockNumber: BigInt!
# pointer to pool
pool: Pool!
# total liquidity pool has as tick lower or upper
Expand All @@ -160,110 +163,6 @@ type Tick @entity {
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!
}

type 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 fees in token0
collectedFeesToken0: BigDecimal!
# all time collected fees in token1
collectedFeesToken1: BigDecimal!
# Total amount deposited in terms of USD
amountDepositedUSD: BigDecimal!
# Total amount withdrawn in terms of USD
amountWithdrawnUSD: BigDecimal!
# Total amount collected in terms of USD
amountCollectedUSD: BigDecimal!
# tx in which the position was initialized
transaction: Transaction!
# vars needed for fee computation
feeGrowthInside0LastX128: BigInt!
feeGrowthInside1LastX128: BigInt!
}

type 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!
}

type Transaction @entity {
Expand Down Expand Up @@ -449,12 +348,12 @@ type UniswapDayData @entity {
volumeUSD: BigDecimal!
# total daily volume in Uniswap derived in terms of USD untracked
volumeUSDUntracked: BigDecimal!
# tvl in terms of USD
totalValueLockedUSD: 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
Expand All @@ -479,8 +378,8 @@ type PoolDayData @entity {
feeGrowthGlobal0X128: BigInt!
# tracker for global fee growth
feeGrowthGlobal1X128: BigInt!
# tvl derived in USD at end of period
tvlUSD: BigDecimal!
# TVL derived in USD at end of period
totalValueLockedUSD: BigDecimal!
# volume in token0
volumeToken0: BigDecimal!
# volume in token1
Expand Down Expand Up @@ -524,7 +423,7 @@ type PoolHourData @entity {
# tracker for global fee growth
feeGrowthGlobal1X128: BigInt!
# tvl derived in USD at end of period
tvlUSD: BigDecimal!
totalValueLockedUSD: BigDecimal!
# volume in token0
volumeToken0: BigDecimal!
# volume in token1
Expand All @@ -545,57 +444,6 @@ type PoolHourData @entity {
close: BigDecimal!
}

type 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
type 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!
}

type TokenDayData @entity {
# token address concatendated with date
id: ID!
Expand All @@ -608,7 +456,7 @@ type TokenDayData @entity {
# volume in derived USD
volumeUSD: BigDecimal!
# volume in USD even on pools with less reliable USD values
untrackedVolumeUSD: BigDecimal!
volumeUSDUntracked: BigDecimal!
# liquidity across all pools in token units
totalValueLocked: BigDecimal!
# liquidity across all pools in derived USD
Expand Down Expand Up @@ -639,7 +487,7 @@ type TokenHourData @entity {
# volume in derived USD
volumeUSD: BigDecimal!
# volume in USD even on pools with less reliable USD values
untrackedVolumeUSD: BigDecimal!
volumeUSDUntracked: BigDecimal!
# liquidity across all pools in token units
totalValueLocked: BigDecimal!
# liquidity across all pools in derived USD
Expand Down
Loading