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

minimal mainnet subgraph #180

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ build/
node_modules/
src/types/
.DS_STORE
yarn-error.log
yarn-error.log
.vscode/
3 changes: 0 additions & 3 deletions .vscode/settings.json

This file was deleted.

17 changes: 0 additions & 17 deletions abis/ERC20NameBytes.json

This file was deleted.

17 changes: 0 additions & 17 deletions abis/ERC20SymbolBytes.json

This file was deleted.

7 changes: 1 addition & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@
"build": "run-s codegen && graph build",
"buildonly": "graph build",
"deploy:alchemy": "graph deploy --node https://subgraphs.alchemy.com/api/subgraphs/deploy --ipfs https://ipfs.satsuma.xyz",
"codegen": "graph codegen --output-dir src/types/",
"create-local": "graph create davekaj/uniswap --node http://127.0.0.1:8020",
"deploy-local": "graph deploy davekaj/uniswap --debug --ipfs http://localhost:5001 --node http://127.0.0.1:8020",
"deploy": "graph deploy ianlapham/uniswap-v2-dev --ipfs https://api.thegraph.com/ipfs/ --node https://api.thegraph.com/deploy/ --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 graphprotocol/Uniswap2 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001"
"codegen": "graph codegen --output-dir src/types/"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.64.1",
Expand Down
279 changes: 40 additions & 239 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -1,274 +1,75 @@
type UniswapFactory @entity {
# factory address
id: ID!

# pair info
pairCount: Int!

# total volume
totalVolumeUSD: BigDecimal!
totalVolumeETH: BigDecimal!

# untracked values - less confident USD scores
untrackedVolumeUSD: BigDecimal!

# total liquidity
totalLiquidityUSD: BigDecimal!
totalLiquidityETH: BigDecimal!

# transactions
txCount: BigInt!
id: ID! # factory address, checksummed
}

type Token @entity {
# token address
id: ID!

# mirrored from the smart contract
symbol: String!
name: String!
id: ID! # token address, lowercased
decimals: BigInt!

# used for other stats like marketcap
totalSupply: BigInt!

# token specific volume
tradeVolume: BigDecimal!
tradeVolumeUSD: BigDecimal!
untrackedVolumeUSD: BigDecimal!

# transactions across all pairs
txCount: BigInt!

# liquidity across all pairs

totalLiquidity: BigDecimal!

# derived prices
derivedETH: BigDecimal!

# derived fields
tokenDayData: [TokenDayData!]! @derivedFrom(field: "token")
pairDayDataBase: [PairDayData!]! @derivedFrom(field: "token0")
pairDayDataQuote: [PairDayData!]! @derivedFrom(field: "token1")
pairBase: [Pair!]! @derivedFrom(field: "token0")
pairQuote: [Pair!]! @derivedFrom(field: "token1")

pairsAsToken0: [Pair!]! @derivedFrom(field: "token0")
pairsAsToken1: [Pair!]! @derivedFrom(field: "token1")
mintsAsToken0: [Mint!]! @derivedFrom(field: "token0")
mintsAsToken1: [Mint!]! @derivedFrom(field: "token1")
burnsAsToken0: [Burn!]! @derivedFrom(field: "token0")
burnsAsToken1: [Burn!]! @derivedFrom(field: "token1")
swapsAsToken0: [Swap!]! @derivedFrom(field: "token0")
swapsAsToken1: [Swap!]! @derivedFrom(field: "token1")
}

type Pair @entity {
# pair address
id: ID!

# mirrored from the smart contract
id: ID! # pair address, lowercased
token0: Token!
token1: Token!
reserve0: BigDecimal!
reserve1: BigDecimal!
totalSupply: BigDecimal!

# derived liquidity
reserveETH: BigDecimal!
reserveUSD: BigDecimal!
# used for separating per pair reserves and global
trackedReserveETH: BigDecimal!

# Price in terms of the asset pair
token0Price: BigDecimal!
token1Price: BigDecimal!

# lifetime volume stats
volumeToken0: BigDecimal!
volumeToken1: BigDecimal!
volumeUSD: BigDecimal!
untrackedVolumeUSD: BigDecimal!
txCount: BigInt!

# creation stats
createdAtTimestamp: BigInt!
createdAtBlockNumber: BigInt!

# Fields used to help derived relationship
liquidityProviderCount: BigInt! # used to detect new exchanges
# derived fields
pairHourData: [PairHourData!]! @derivedFrom(field: "pair")

reserve0: BigDecimal!
reserve1: BigDecimal!

mints: [Mint!]! @derivedFrom(field: "pair")
burns: [Burn!]! @derivedFrom(field: "pair")
swaps: [Swap!]! @derivedFrom(field: "pair")
}

type User @entity {
id: ID!
usdSwapped: BigDecimal!
}

type Transaction @entity {
id: ID! # txn hash
blockNumber: BigInt!
timestamp: BigInt!
# This is not the reverse of Mint.transaction; it is only used to
# track incomplete mints (similar for burns and swaps)
mints: [Mint!]!
burns: [Burn!]!
swaps: [Swap!]!
}

type Mint @entity {
# transaction hash + "-" + index in mints Transaction array
id: ID!
transaction: Transaction!
timestamp: BigInt! # need this to pull recent txns for specific token or pair
pair: Pair!

# populated from the primary Transfer event
id: ID! # transactionhash#logIndex
timestamp: BigInt!
blockNumber: BigInt!
to: Bytes!
liquidity: BigDecimal!

# populated from the Mint event
sender: Bytes
amount0: BigDecimal
amount1: BigDecimal
logIndex: BigInt
# derived amount based on available prices of tokens
amountUSD: BigDecimal

# optional fee fields, if a Transfer event is fired in _mintFee
feeTo: Bytes
feeLiquidity: BigDecimal
pair: Pair!
token0: Token!
token1: Token!
sender: Bytes!
amount0: BigDecimal!
amount1: BigDecimal!
}

type Burn @entity {
# transaction hash + "-" + index in mints Transaction array
id: ID!
transaction: Transaction!
timestamp: BigInt! # need this to pull recent txns for specific token or pair
id: ID! # transactionhash#logIndex
timestamp: BigInt!
blockNumber: BigInt!
pair: Pair!

# populated from the primary Transfer event
liquidity: BigDecimal!

# populated from the Burn event
sender: Bytes
amount0: BigDecimal
amount1: BigDecimal
to: Bytes
logIndex: BigInt
# derived amount based on available prices of tokens
amountUSD: BigDecimal

# mark uncomplete in ETH case
needsComplete: Boolean!

# optional fee fields, if a Transfer event is fired in _mintFee
feeTo: Bytes
feeLiquidity: BigDecimal
token0: Token!
token1: Token!
sender: Bytes!
amount0: BigDecimal!
amount1: BigDecimal!
to: Bytes!
}

type Swap @entity {
# transaction hash + "-" + index in swaps Transaction array
id: ID!
transaction: Transaction!
timestamp: BigInt! # need this to pull recent txns for specific token or pair
id: ID! # transactionhash#logIndex
timestamp: BigInt!
blockNumber: BigInt!
pair: Pair!

# populated from the Swap event
token0: Token!
token1: Token!
sender: Bytes!
from: Bytes! # the EOA that initiated the txn
amount0In: BigDecimal!
amount1In: BigDecimal!
amount0Out: BigDecimal!
amount1Out: BigDecimal!
to: Bytes!
logIndex: BigInt

# derived info
amountUSD: BigDecimal!
}

# stores for USD calculations
type Bundle @entity {
id: ID!
ethPrice: BigDecimal! # price of ETH usd
}

# Data accumulated and condensed into day stats for all of Uniswap
type UniswapDayData @entity {
id: ID! # timestamp rounded to current day by dividing by 86400
date: Int!

dailyVolumeETH: BigDecimal!
dailyVolumeUSD: BigDecimal!
dailyVolumeUntracked: BigDecimal!

totalVolumeETH: BigDecimal!
totalLiquidityETH: BigDecimal!
totalVolumeUSD: BigDecimal! # Accumulate at each trade, not just calculated off whatever totalVolume is. making it more accurate as it is a live conversion
totalLiquidityUSD: BigDecimal!

txCount: BigInt!
}

type PairHourData @entity {
id: ID!
hourStartUnix: Int! # unix timestamp for start of hour
pair: Pair!

# reserves
reserve0: BigDecimal!
reserve1: BigDecimal!

# total supply for LP historical returns
totalSupply: BigDecimal

# derived liquidity
reserveUSD: BigDecimal!

# volume stats
hourlyVolumeToken0: BigDecimal!
hourlyVolumeToken1: BigDecimal!
hourlyVolumeUSD: BigDecimal!
hourlyTxns: BigInt!
}

# Data accumulated and condensed into day stats for each exchange
type PairDayData @entity {
id: ID!
date: Int!
pairAddress: Bytes!
token0: Token!
token1: Token!

# reserves
reserve0: BigDecimal!
reserve1: BigDecimal!

# total supply for LP historical returns
totalSupply: BigDecimal

# derived liquidity
reserveUSD: BigDecimal!

# volume stats
dailyVolumeToken0: BigDecimal!
dailyVolumeToken1: BigDecimal!
dailyVolumeUSD: BigDecimal!
dailyTxns: BigInt!
}

type TokenDayData @entity {
id: ID!
date: Int!
token: Token!

# volume stats
dailyVolumeToken: BigDecimal!
dailyVolumeETH: BigDecimal!
dailyVolumeUSD: BigDecimal!
dailyTxns: BigInt!

# liquidity stats
totalLiquidityToken: BigDecimal!
totalLiquidityETH: BigDecimal!
totalLiquidityUSD: BigDecimal!

# price stats
priceUSD: BigDecimal!
}
Loading