Skip to content
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
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@

1. Create a new subgraph config in `src/utils/chains.ts`. This will require adding a new `<NETWORK_NAME>_NETWORK_NAME` const for the corresponding network.
2. Add a new entry in `networks.json` for the new chain. The network name should be derived from the CLI Name in The Graph's [supported networks documenation](https://thegraph.com/docs/en/developing/supported-networks/). The factory address can be derived from Uniswap's deployments documentation (not yet available).
3. To deploy to Alchemy, run the following command:

3. Deploy subgraph, run the following command:
#### Deploy to The Graph
```
graph deploy <SUBGRAPH_NAME>
```
#### Deploy to Alchemy
```
yarn run deploy:alchemy --
<SUBGRAPH_NAME>
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"prepare": "husky install"
},
"devDependencies": {
"@graphprotocol/graph-cli": "^0.64.1",
"@graphprotocol/graph-ts": "^0.32.0",
"@graphprotocol/graph-cli": "^0.96.0",
"@graphprotocol/graph-ts": "^0.35.0",
"@typescript-eslint/eslint-plugin": "^2.0.0",
"@typescript-eslint/parser": "^2.0.0",
"@uniswap/eslint-config": "^1.2.0",
Expand Down
56 changes: 28 additions & 28 deletions schema.graphql
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
type PoolManager @entity {
# poolManager address
id: ID!
id: Bytes!
# amount of pools created
poolCount: BigInt!
# amoutn of transactions all time
Expand All @@ -24,19 +24,19 @@ type PoolManager @entity {
# TVL derived in ETH untracked
totalValueLockedETHUntracked: BigDecimal!
# current owner of the factory
owner: ID!
owner: Bytes!
}

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

type Token @entity {
# token address
id: ID!
id: Bytes!
# token symbol
symbol: String!
# token name
Expand Down Expand Up @@ -75,7 +75,7 @@ type Token @entity {

type Pool @entity {
# pool address
id: ID!
id: Bytes!
# creation
createdAtTimestamp: BigInt!
# block pool was created at
Expand Down Expand Up @@ -135,7 +135,7 @@ type Pool @entity {
# daily snapshots of pool data
poolDayData: [PoolDayData!]! @derivedFrom(field: "pool")
# hooks address
hooks: String!
hooks: Bytes!
# derived fields
modifyLiquiditys: [ModifyLiquidity!]! @derivedFrom(field: "pool")
swaps: [Swap!]! @derivedFrom(field: "pool")
Expand All @@ -144,9 +144,9 @@ type Pool @entity {

type Tick @entity {
# format: <pool address>#<tick index>
id: ID!
id: Bytes!
# pool address
poolAddress: String
poolAddress: Bytes
# tick index
tickIdx: BigInt!
# pointer to pool
Expand All @@ -165,9 +165,9 @@ type Tick @entity {
createdAtBlockNumber: BigInt!
}

type Transaction @entity {
type Transaction @entity(immutable: true) {
# txn hash
id: ID!
id: Bytes!
# block txn was included in
blockNumber: BigInt!
# timestamp txn was confirmed
Expand All @@ -183,9 +183,9 @@ type Transaction @entity {
unsubscriptions: [Unsubscribe]! @derivedFrom(field: "transaction")
}

type Swap @entity {
type Swap @entity(immutable: true) {
# transaction hash + "#" + index in swaps Transaction array
id: ID!
id: Bytes!
# pointer to transaction
transaction: Transaction!
# timestamp of transaction
Expand Down Expand Up @@ -218,7 +218,7 @@ type Swap @entity {

type ModifyLiquidity @entity {
# transaction hash + "#" + index in mints Transaction array
id: ID!
id: Bytes!
# which txn the ModifyLiquidity was included in
transaction: Transaction!
# time of txn
Expand Down Expand Up @@ -419,9 +419,9 @@ type Position @entity {
# tokenId
tokenId: BigInt!
# address of current owner
owner: String!
owner: Bytes!
# the EOA that minted the position
origin: String!
origin: Bytes!
# created time
createdAtTimestamp: BigInt!
# subscribe events
Expand All @@ -432,61 +432,61 @@ type Position @entity {
transfers: [Transfer!]! @derivedFrom(field: "position")
}

type Subscribe @entity {
type Subscribe @entity(immutable: true) {
# transaction hash + '-' + log index
id: ID!
id: Bytes!
# token id of position subscribed to
tokenId: BigInt!
# address of subscriber
address: String!
address: Bytes!
# pointer to transaction
transaction: Transaction!
# log index
logIndex: BigInt!
# time of tx
timestamp: BigInt!
# the EOA that initiated the tx
origin: String!
origin: Bytes!
# pointer to position
position: Position!
}

type Unsubscribe @entity {
type Unsubscribe @entity(immutable: true) {
# transaction hash + '-' + log index
id: ID!
id: Bytes!
# token id of position unsubscribed from
tokenId: BigInt!
# address of unsubscriber
address: String!
address: Bytes!
# pointer to transaction
transaction: Transaction!
# log index
logIndex: BigInt!
# time of tx
timestamp: BigInt!
# the EOA that initiated the tx
origin: String!
origin: Bytes!
# pointer to position
position: Position!
}

type Transfer @entity {
type Transfer @entity(immutable: true) {
# transaction hash + '-' + log index
id: ID!
id: Bytes!
# token id of position
tokenId: BigInt!
# address of previous owner
from: String!
from: Bytes!
# address of new owner
to: String!
to: Bytes!
# pointer to transaction
transaction: Transaction!
# log index
logIndex: BigInt!
# time of tx
timestamp: BigInt!
# the EOA that initiated the tx
origin: String!
origin: Bytes!
# pointer to position
position: Position!
}
20 changes: 10 additions & 10 deletions src/mappings/modifyLiquidity.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt, log } from '@graphprotocol/graph-ts'
import { BigInt, Bytes, log } from '@graphprotocol/graph-ts'

import { ModifyLiquidity as ModifyLiquidityEvent } from '../types/PoolManager/PoolManager'
import { Bundle, ModifyLiquidity, Pool, PoolManager, Tick, Token } from '../types/schema'
Expand Down Expand Up @@ -26,18 +26,18 @@ export function handleModifyLiquidityHelper(
): void {
const poolManagerAddress = subgraphConfig.poolManagerAddress

const bundle = Bundle.load('1')!
const poolId = event.params.id.toHexString()
const bundle = Bundle.load(Bytes.fromI32(1))!
const poolId = event.params.id
const pool = Pool.load(poolId)
const poolManager = PoolManager.load(poolManagerAddress)

if (pool === null) {
log.debug('handleModifyLiquidityHelper: pool not found {}', [poolId])
log.debug('handleModifyLiquidityHelper: pool not found {}', [poolId.toHexString()])
return
}

if (poolManager === null) {
log.debug('handleModifyLiquidityHelper: pool manager not found {}', [poolManagerAddress])
log.debug('handleModifyLiquidityHelper: pool manager not found {}', [poolManagerAddress.toHexString()])
return
}

Expand Down Expand Up @@ -109,7 +109,7 @@ export function handleModifyLiquidityHelper(
poolManager.totalValueLockedUSD = poolManager.totalValueLockedETH.times(bundle.ethPriceUSD)

const transaction = loadTransaction(event)
const modifyLiquidity = new ModifyLiquidity(transaction.id.toString() + '-' + event.logIndex.toString())
const modifyLiquidity = new ModifyLiquidity(transaction.id.concatI32(event.logIndex.toI32()))
modifyLiquidity.transaction = transaction.id
modifyLiquidity.timestamp = transaction.timestamp
modifyLiquidity.pool = pool.id
Expand All @@ -129,8 +129,8 @@ export function handleModifyLiquidityHelper(
const lowerTickIdx = event.params.tickLower
const upperTickIdx = event.params.tickUpper

const lowerTickId = poolId + '#' + BigInt.fromI32(event.params.tickLower).toString()
const upperTickId = poolId + '#' + BigInt.fromI32(event.params.tickUpper).toString()
const lowerTickId = poolId.concatI32(event.params.tickLower)
const upperTickId = poolId.concatI32(event.params.tickUpper)

let lowerTick = Tick.load(lowerTickId)
let upperTick = Tick.load(upperTickId)
Expand All @@ -156,8 +156,8 @@ export function handleModifyLiquidityHelper(
upperTick.save()

updateUniswapDayData(event, poolManagerAddress)
updatePoolDayData(event.params.id.toHexString(), event)
updatePoolHourData(event.params.id.toHexString(), event)
updatePoolDayData(event.params.id, event)
updatePoolHourData(event.params.id, event)
updateTokenDayData(token0, event)
updateTokenDayData(token1, event)
updateTokenHourData(token0, event)
Expand Down
18 changes: 9 additions & 9 deletions src/mappings/poolManager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigInt, log } from '@graphprotocol/graph-ts'
import { BigInt, Bytes, log } from '@graphprotocol/graph-ts'

import { Initialize as InitializeEvent } from '../types/PoolManager/PoolManager'
import { PoolManager } from '../types/schema'
Expand Down Expand Up @@ -29,7 +29,7 @@ export function handleInitializeHelper(
const stablecoinAddresses = subgraphConfig.stablecoinAddresses
const minimumNativeLocked = subgraphConfig.minimumNativeLocked
const nativeTokenDetails = subgraphConfig.nativeTokenDetails
const poolId = event.params.id.toHexString()
const poolId = event.params.id

if (poolsToSkip.includes(poolId)) {
return
Expand All @@ -53,19 +53,19 @@ export function handleInitializeHelper(
poolManager.owner = ADDRESS_ZERO

// create new bundle for tracking eth price
const bundle = new Bundle('1')
const bundle = new Bundle(Bytes.fromI32(1))
bundle.ethPriceUSD = ZERO_BD
bundle.save()
}

poolManager.poolCount = poolManager.poolCount.plus(ONE_BI)
const pool = new Pool(poolId)
let token0 = Token.load(event.params.currency0.toHexString())
let token1 = Token.load(event.params.currency1.toHexString())
let token0 = Token.load(event.params.currency0)
let token1 = Token.load(event.params.currency1)

// fetch info if null
if (token0 === null) {
token0 = new Token(event.params.currency0.toHexString())
token0 = new Token(event.params.currency0)
token0.symbol = fetchTokenSymbol(event.params.currency0, tokenOverrides, nativeTokenDetails)
token0.name = fetchTokenName(event.params.currency0, tokenOverrides, nativeTokenDetails)
token0.totalSupply = fetchTokenTotalSupply(event.params.currency0)
Expand All @@ -92,7 +92,7 @@ export function handleInitializeHelper(
}

if (token1 === null) {
token1 = new Token(event.params.currency1.toHexString())
token1 = new Token(event.params.currency1)
token1.symbol = fetchTokenSymbol(event.params.currency1, tokenOverrides, nativeTokenDetails)
token1.name = fetchTokenName(event.params.currency1, tokenOverrides, nativeTokenDetails)
token1.totalSupply = fetchTokenTotalSupply(event.params.currency1)
Expand Down Expand Up @@ -132,7 +132,7 @@ export function handleInitializeHelper(
pool.token0 = token0.id
pool.token1 = token1.id
pool.feeTier = BigInt.fromI32(event.params.fee)
pool.hooks = event.params.hooks.toHexString()
pool.hooks = event.params.hooks
pool.tickSpacing = BigInt.fromI32(event.params.tickSpacing)
pool.createdAtTimestamp = event.block.timestamp
pool.createdAtBlockNumber = event.block.number
Expand Down Expand Up @@ -172,7 +172,7 @@ export function handleInitializeHelper(

// update prices
// update ETH price now that prices could have changed
const bundle = Bundle.load('1')!
const bundle = Bundle.load(Bytes.fromI32(1))!
bundle.ethPriceUSD = getNativePriceInUSD(stablecoinWrappedNativePoolId, stablecoinIsToken0)
bundle.save()
updatePoolDayData(poolId, event)
Expand Down
4 changes: 2 additions & 2 deletions src/mappings/subscribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ export function handleSubscriptionHelper(event: SubscriptionEvent): void {
const transaction = loadTransaction(event)

subscription.tokenId = event.params.tokenId
subscription.address = event.params.subscriber.toHexString()
subscription.origin = event.transaction.from.toHexString()
subscription.address = event.params.subscriber
subscription.origin = event.transaction.from
subscription.transaction = transaction.id
subscription.logIndex = event.logIndex
subscription.timestamp = transaction.timestamp
Expand Down
12 changes: 6 additions & 6 deletions src/mappings/swap.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigDecimal, BigInt } from '@graphprotocol/graph-ts'
import { BigDecimal, BigInt, Bytes } from '@graphprotocol/graph-ts'

import { Swap as SwapEvent } from '../types/PoolManager/PoolManager'
import { Bundle, Pool, PoolManager, Swap, Token } from '../types/schema'
Expand Down Expand Up @@ -33,9 +33,9 @@ export function handleSwapHelper(event: SwapEvent, subgraphConfig: SubgraphConfi
const whitelistTokens = subgraphConfig.whitelistTokens
const nativeTokenDetails = subgraphConfig.nativeTokenDetails

const bundle = Bundle.load('1')!
const bundle = Bundle.load(Bytes.fromI32(1))!
const poolManager = PoolManager.load(poolManagerAddress)!
const poolId = event.params.id.toHexString()
const poolId = event.params.id
const pool = Pool.load(poolId)!

const token0 = Token.load(pool.token0)
Expand Down Expand Up @@ -144,7 +144,7 @@ export function handleSwapHelper(event: SwapEvent, subgraphConfig: SubgraphConfi

// create Swap event
const transaction = loadTransaction(event)
const swap = new Swap(transaction.id + '-' + event.logIndex.toString())
const swap = new Swap(transaction.id.concatI32(event.logIndex.toI32()))
swap.transaction = transaction.id
swap.timestamp = transaction.timestamp
swap.pool = pool.id
Expand All @@ -161,8 +161,8 @@ export function handleSwapHelper(event: SwapEvent, subgraphConfig: SubgraphConfi

// interval data
const uniswapDayData = updateUniswapDayData(event, poolManagerAddress)
const poolDayData = updatePoolDayData(event.params.id.toHexString(), event)
const poolHourData = updatePoolHourData(event.params.id.toHexString(), event)
const poolDayData = updatePoolDayData(event.params.id, event)
const poolHourData = updatePoolHourData(event.params.id, event)
const token0DayData = updateTokenDayData(token0, event)
const token1DayData = updateTokenDayData(token1, event)
const token0HourData = updateTokenHourData(token0, event)
Expand Down
Loading