diff --git a/README.md b/README.md index 311c029..c940fd5 100644 --- a/README.md +++ b/README.md @@ -11,8 +11,12 @@ 1. Create a new subgraph config in `src/utils/chains.ts`. This will require adding a new `_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 +``` +#### Deploy to Alchemy ``` yarn run deploy:alchemy -- diff --git a/package.json b/package.json index 774d2fc..f1a60d2 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/schema.graphql b/schema.graphql index 99a5ba4..f2dbd6a 100644 --- a/schema.graphql +++ b/schema.graphql @@ -1,6 +1,6 @@ type PoolManager @entity { # poolManager address - id: ID! + id: Bytes! # amount of pools created poolCount: BigInt! # amoutn of transactions all time @@ -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 @@ -75,7 +75,7 @@ type Token @entity { type Pool @entity { # pool address - id: ID! + id: Bytes! # creation createdAtTimestamp: BigInt! # block pool was created at @@ -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") @@ -144,9 +144,9 @@ type Pool @entity { type Tick @entity { # format: # - id: ID! + id: Bytes! # pool address - poolAddress: String + poolAddress: Bytes # tick index tickIdx: BigInt! # pointer to pool @@ -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 @@ -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 @@ -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 @@ -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 @@ -432,13 +432,13 @@ 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 @@ -446,18 +446,18 @@ type Subscribe @entity { # 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 @@ -465,20 +465,20 @@ type Unsubscribe @entity { # 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 @@ -486,7 +486,7 @@ type Transfer @entity { # time of tx timestamp: BigInt! # the EOA that initiated the tx - origin: String! + origin: Bytes! # pointer to position position: Position! } diff --git a/src/mappings/modifyLiquidity.ts b/src/mappings/modifyLiquidity.ts index 02d0b6c..9ce9f83 100644 --- a/src/mappings/modifyLiquidity.ts +++ b/src/mappings/modifyLiquidity.ts @@ -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' @@ -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 } @@ -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 @@ -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) @@ -153,8 +153,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) diff --git a/src/mappings/poolManager.ts b/src/mappings/poolManager.ts index 4462219..75a13a1 100644 --- a/src/mappings/poolManager.ts +++ b/src/mappings/poolManager.ts @@ -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' @@ -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 @@ -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) @@ -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) @@ -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 @@ -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) diff --git a/src/mappings/subscribe.ts b/src/mappings/subscribe.ts index d2a25c6..ee1b525 100644 --- a/src/mappings/subscribe.ts +++ b/src/mappings/subscribe.ts @@ -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 diff --git a/src/mappings/swap.ts b/src/mappings/swap.ts index 812f217..433cc24 100644 --- a/src/mappings/swap.ts +++ b/src/mappings/swap.ts @@ -1,4 +1,4 @@ -import { BigDecimal, BigInt, log } from '@graphprotocol/graph-ts' +import { BigDecimal, BigInt, Bytes, log } from '@graphprotocol/graph-ts' import { Swap as SwapEvent } from '../types/PoolManager/PoolManager' import { Bundle, Pool, PoolManager, Swap, Token } from '../types/schema' @@ -33,13 +33,14 @@ 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) if (!pool) { - log.warning('Pool not found: {}', [poolId]) + log.warning('Pool not found: {}', [poolId.toHexString()]) return } @@ -152,7 +153,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 @@ -169,8 +170,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) diff --git a/src/mappings/transfer.ts b/src/mappings/transfer.ts index d20522f..2225186 100644 --- a/src/mappings/transfer.ts +++ b/src/mappings/transfer.ts @@ -18,19 +18,19 @@ export function handleTransferHelper(event: TransferEvent): void { if (position === null) { position = new Position(tokenId) position.tokenId = event.params.id - position.origin = event.transaction.from.toHexString() + position.origin = event.transaction.from position.createdAtTimestamp = event.block.timestamp } - position.owner = to.toHexString() + position.owner = to const transaction = loadTransaction(event) const transfer = new Transfer(eventId(event.transaction.hash, event.logIndex)) transfer.tokenId = event.params.id - transfer.from = from.toHexString() - transfer.to = to.toHexString() - transfer.origin = event.transaction.from.toHexString() + transfer.from = from + transfer.to = to + transfer.origin = event.transaction.from transfer.transaction = transaction.id transfer.logIndex = event.logIndex transfer.timestamp = transaction.timestamp diff --git a/src/mappings/unsubscribe.ts b/src/mappings/unsubscribe.ts index 6827b30..b5324d7 100644 --- a/src/mappings/unsubscribe.ts +++ b/src/mappings/unsubscribe.ts @@ -15,8 +15,8 @@ export function handleUnsubscriptionHelper(event: UnsubscriptionEvent): void { const transaction = loadTransaction(event) unsubscription.tokenId = event.params.tokenId - unsubscription.address = event.params.subscriber.toHexString() - unsubscription.origin = event.transaction.from.toHexString() + unsubscription.address = event.params.subscriber + unsubscription.origin = event.transaction.from unsubscription.transaction = transaction.id unsubscription.logIndex = event.logIndex unsubscription.timestamp = transaction.timestamp diff --git a/src/utils/chains.ts b/src/utils/chains.ts index 1d28173..af468b8 100644 --- a/src/utils/chains.ts +++ b/src/utils/chains.ts @@ -1,4 +1,4 @@ -import { Address, BigDecimal, BigInt, dataSource } from '@graphprotocol/graph-ts' +import { Address, BigDecimal, BigInt, Bytes, dataSource } from '@graphprotocol/graph-ts' import { NativeTokenDetails } from './nativeTokenDetails' import { StaticTokenDefinition } from './staticTokenDefinition' @@ -27,12 +27,12 @@ const SONEIUM_MAINNET_NETWORK_NAME = 'soneium-mainnet' // Note: All token and pool addresses should be lowercased! export class SubgraphConfig { // deployment address - poolManagerAddress: string + poolManagerAddress: Bytes // the address of a pool where one token is a stablecoin and the other is a // token that tracks the price of the native token use this to calculate the // price of the native token, so prefer a pool with highest liquidity - stablecoinWrappedNativePoolId: string + stablecoinWrappedNativePoolId: Bytes // true is stablecoin is token0, false if stablecoin is token1 stablecoinIsToken0: boolean @@ -40,29 +40,29 @@ export class SubgraphConfig { // the address of a token that tracks the price of the native token, most of // the time, this is a wrapped asset but could also be the native token itself // for some chains - wrappedNativeAddress: string + wrappedNativeAddress: Bytes // the mimimum liquidity in a pool needed for it to be used to help calculate // token prices. for new chains, this should be initialized to ~4000 USD minimumNativeLocked: BigDecimal // list of stablecoin addresses - stablecoinAddresses: string[] + stablecoinAddresses: Bytes[] // a token must be in a pool with one of these tokens in order to derive a // price (in addition to passing the minimumEthLocked check). This is also // used to determine whether volume is tracked or not. - whitelistTokens: string[] + whitelistTokens: Bytes[] // token overrides are used to override RPC calls for the symbol, name, and // decimals for tokens. for new chains this is typically empty. tokenOverrides: StaticTokenDefinition[] // skip the creation of these pools in handlePoolCreated. for new chains this is typically empty. - poolsToSkip: string[] + poolsToSkip: Bytes[] // initialize this list of pools and token addresses on factory creation. for new chains this is typically empty. - poolMappings: Array + poolMappings: Array // native token details for the chain. nativeTokenDetails: NativeTokenDetails @@ -74,20 +74,22 @@ export function getSubgraphConfig(): SubgraphConfig { if (selectedNetwork == SEPOLIA_NETWORK_NAME) { return { - poolManagerAddress: '0xe03a1074c86cfedd5c142c4f04f1a1536e203543', - stablecoinWrappedNativePoolId: '0xabdb9820d36431e092c155f7151c4c781f09fb4e1b7894fa918a0aadcac87e16', + poolManagerAddress: Address.fromString('0xe03a1074c86cfedd5c142c4f04f1a1536e203543'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0xabdb9820d36431e092c155f7151c4c781f09fb4e1b7894fa918a0aadcac87e16', + ), stablecoinIsToken0: true, - wrappedNativeAddress: '0xfff9976782d46cc05630d1f6ebab18b2324d6b14', // WETH + wrappedNativeAddress: Address.fromString('0xfff9976782d46cc05630d1f6ebab18b2324d6b14'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x1c7d4b196cb0c7b01d743fbc6116a902379c7238', // USDC - '0xaa8e23fb1079ea71e0a56f48a2aa51851d8433d0', // USDT + Address.fromString('0x1c7d4b196cb0c7b01d743fbc6116a902379c7238'), // USDC + Address.fromString('0xaa8e23fb1079ea71e0a56f48a2aa51851d8433d0'), // USDT ], whitelistTokens: [ - '0x0000000000000000000000000000000000000000', // Native ETH - '0x1c7d4b196cb0c7b01d743fbc6116a902379c7238', // USDC - '0xaa8e23fb1079ea71e0a56f48a2aa51851d8433d0', // USDT, - '0xfff9976782d46cc05630d1f6ebab18b2324d6b14', // WETH + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH + Address.fromString('0x1c7d4b196cb0c7b01d743fbc6116a902379c7238'), // USDC + Address.fromString('0xaa8e23fb1079ea71e0a56f48a2aa51851d8433d0'), // USDT + Address.fromString('0xfff9976782d46cc05630d1f6ebab18b2324d6b14'), // WETH ], tokenOverrides: [], poolsToSkip: [], @@ -100,18 +102,20 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == UNICHAIN_SEPOLIA_NETWORK_NAME) { return { - poolManagerAddress: '0x00b036b58a818b1bc34d502d3fe730db729e62ac', - stablecoinWrappedNativePoolId: '0x1927686e9757bb312fc499e480536d466c788dcdc86a1b62c82643157f05b603', // https://unichain-sepolia.blockscout.com/tx/0x6461a80bbdd78222097c8f0437952dba852f25c3822df50660e347ccd6436f6f?tab=logs + poolManagerAddress: Address.fromString('0x00b036b58a818b1bc34d502d3fe730db729e62ac'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x1927686e9757bb312fc499e480536d466c788dcdc86a1b62c82643157f05b603', + ), // https://unichain-sepolia.blockscout.com/tx/0x6461a80bbdd78222097c8f0437952dba852f25c3822df50660e347ccd6436f6f?tab=logs stablecoinIsToken0: true, - wrappedNativeAddress: '0x4200000000000000000000000000000000000006', // WETH + wrappedNativeAddress: Address.fromString('0x4200000000000000000000000000000000000006'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x31d0220469e10c4e71834a79b1f276d740d3768f', // USDC + Address.fromString('0x31d0220469e10c4e71834a79b1f276d740d3768f'), // USDC ], whitelistTokens: [ - '0x0000000000000000000000000000000000000000', // Native ETH - '0x31d0220469e10c4e71834a79b1f276d740d3768f', // USDC - '0x4200000000000000000000000000000000000006', // WETH + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH + Address.fromString('0x31d0220469e10c4e71834a79b1f276d740d3768f'), // USDC + Address.fromString('0x4200000000000000000000000000000000000006'), // WETH ], tokenOverrides: [], poolsToSkip: [], @@ -124,18 +128,18 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == ARBITRUM_SEPOLIA_NETWORK_NAME) { return { - poolManagerAddress: '0xfb3e0c6f74eb1a21cc1da29aec80d2dfe6c9a317', - stablecoinWrappedNativePoolId: '', // no v4 pool exists on arbitrum sepolia yet, this will result in $0 prices + poolManagerAddress: Address.fromString('0xfb3e0c6f74eb1a21cc1da29aec80d2dfe6c9a317'), + stablecoinWrappedNativePoolId: Bytes.empty(), // no v4 pool exists on arbitrum sepolia yet, this will result in $0 prices stablecoinIsToken0: true, - wrappedNativeAddress: '0x980b62da83eff3d4576c647993b0c1d7faf17c73', // WETH + wrappedNativeAddress: Address.fromString('0x980b62da83eff3d4576c647993b0c1d7faf17c73'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x75faf114eafb1bdbe2f0316df893fd58ce46aa4d', // USDC + Address.fromString('0x75faf114eafb1bdbe2f0316df893fd58ce46aa4d'), // USDC ], whitelistTokens: [ - '0x0000000000000000000000000000000000000000', // Native ETH - '0x75faf114eafb1bdbe2f0316df893fd58ce46aa4d', // USDC - '0x980b62da83eff3d4576c647993b0c1d7faf17c73', // WETH + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH + Address.fromString('0x75faf114eafb1bdbe2f0316df893fd58ce46aa4d'), // USDC + Address.fromString('0x980b62da83eff3d4576c647993b0c1d7faf17c73'), // WETH ], tokenOverrides: [], poolsToSkip: [], @@ -148,19 +152,21 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == BASE_SEPOLIA_NETWORK_NAME) { return { - poolManagerAddress: '0x05e73354cfdd6745c338b50bcfdfa3aa6fa03408', - stablecoinWrappedNativePoolId: '0xcafe1ec4f71a632f8fc57506c478d0b25b399a9aa003c9bc02c444639578ae46', // https://sepolia.basescan.org/tx/0xa8a8ad7ed9fe1e44ce264f240821a33bfd93a385397b46fd7142deee242be2fa#eventlog + poolManagerAddress: Address.fromString('0x05e73354cfdd6745c338b50bcfdfa3aa6fa03408'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0xcafe1ec4f71a632f8fc57506c478d0b25b399a9aa003c9bc02c444639578ae46', + ), // https://sepolia.basescan.org/tx/0xa8a8ad7ed9fe1e44ce264f240821a33bfd93a385397b46fd7142deee242be2fa#eventlog stablecoinIsToken0: true, - wrappedNativeAddress: '0x4200000000000000000000000000000000000006', // WETH + wrappedNativeAddress: Address.fromString('0x4200000000000000000000000000000000000006'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x036cbd53842c5426634e7929541ec2318f3dcf7e', // USDC + Address.fromString('0x036cbd53842c5426634e7929541ec2318f3dcf7e'), // USDC ], whitelistTokens: [ - '0x0000000000000000000000000000000000000000', // Native ETH - '0x036cbd53842c5426634e7929541ec2318f3dcf7e', // USDC - '0x4200000000000000000000000000000000000006', // WETH - '0x1111111111166b7fe7bd91427724b487980afc69', // ZORA + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH + Address.fromString('0x036cbd53842c5426634e7929541ec2318f3dcf7e'), // USDC + Address.fromString('0x4200000000000000000000000000000000000006'), // WETH + Address.fromString('0x1111111111166b7fe7bd91427724b487980afc69'), // ZORA ], tokenOverrides: [], poolsToSkip: [], @@ -173,24 +179,26 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == ARBITRUM_ONE_NETWORK_NAME) { return { - poolManagerAddress: '0x360e68faccca8ca495c1b759fd9eee466db9fb32', - stablecoinWrappedNativePoolId: '0xfc7b3ad139daaf1e9c3637ed921c154d1b04286f8a82b805a6c352da57028653', // https://arbiscan.io/tx/0xd2542ab5fa8cb1b0606c6f114d9589e35db6d02dee426b7d874bda7c6e05f641#eventlog + poolManagerAddress: Address.fromString('0x360e68faccca8ca495c1b759fd9eee466db9fb32'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0xfc7b3ad139daaf1e9c3637ed921c154d1b04286f8a82b805a6c352da57028653', + ), // https://arbiscan.io/tx/0xd2542ab5fa8cb1b0606c6f114d9589e35db6d02dee426b7d874bda7c6e05f641#eventlog stablecoinIsToken0: false, - wrappedNativeAddress: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', // WETH + wrappedNativeAddress: Address.fromString('0x82af49447d8a07e3bd95bd0d56f35241523fbab1'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e - '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', // DAI - '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', // USDT - '0xaf88d065e77c8cc2239327c5edb3a432268e5831', // USDC + Address.fromString('0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'), // USDC.e + Address.fromString('0xda10009cbd5d07dd0cecc66161fc93d7c9000da1'), // DAI + Address.fromString('0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9'), // USDT + Address.fromString('0xaf88d065e77c8cc2239327c5edb3a432268e5831'), // USDC ], whitelistTokens: [ - '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', // WETH - '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC.e - '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', // DAI - '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', // USDT - '0xaf88d065e77c8cc2239327c5edb3a432268e5831', // USDC - '0x0000000000000000000000000000000000000000', // Native ETH + Address.fromString('0x82af49447d8a07e3bd95bd0d56f35241523fbab1'), // WETH + Address.fromString('0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'), // USDC.e + Address.fromString('0xda10009cbd5d07dd0cecc66161fc93d7c9000da1'), // DAI + Address.fromString('0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9'), // USDT + Address.fromString('0xaf88d065e77c8cc2239327c5edb3a432268e5831'), // USDC + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH ], tokenOverrides: [ { @@ -216,19 +224,21 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == BASE_NETWORK_NAME) { return { - poolManagerAddress: '0x498581ff718922c3f8e6a244956af099b2652b2b', - stablecoinWrappedNativePoolId: '0x90333bb05c258fe0dddb2840ef66f1a05165aa7dac6815d24e807cc6ebd943a0', // https://basescan.org/tx/0xf7f4eb1aef74a635a1bf42d598049afbed8ec9e303be81bf168b94a71045decb#eventlog + poolManagerAddress: Address.fromString('0x498581ff718922c3f8e6a244956af099b2652b2b'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x90333bb05c258fe0dddb2840ef66f1a05165aa7dac6815d24e807cc6ebd943a0', + ), // https://basescan.org/tx/0xf7f4eb1aef74a635a1bf42d598049afbed8ec9e303be81bf168b94a71045decb#eventlog stablecoinIsToken0: false, - wrappedNativeAddress: '0x4200000000000000000000000000000000000006', // WETH + wrappedNativeAddress: Address.fromString('0x4200000000000000000000000000000000000006'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC + Address.fromString('0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'), // USDC ], whitelistTokens: [ - '0x4200000000000000000000000000000000000006', // WETH - '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC - '0x0000000000000000000000000000000000000000', // Native ETH - '0x1111111111166b7fe7bd91427724b487980afc69', // ZORA + Address.fromString('0x4200000000000000000000000000000000000006'), // WETH + Address.fromString('0x833589fcd6edb6e08f4c7c32d4f71b54bda02913'), // USDC + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH + Address.fromString('0x1111111111166b7fe7bd91427724b487980afc69'), // ZORA ], tokenOverrides: [], poolsToSkip: [], @@ -241,23 +251,25 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == MATIC_NETWORK_NAME) { return { - poolManagerAddress: '0x67366782805870060151383f4bbff9dab53e5cd6', - stablecoinWrappedNativePoolId: '0x15484bc239f7554e7ead77c45834c722d3f74a9b20826fdf21bbb1b026444286', // https://polygonscan.com/tx/0x6c94e24c0ddff6dd9bfa860561945330c81df85ebb4b1ecf75a459b016719314 + poolManagerAddress: Address.fromString('0x67366782805870060151383f4bbff9dab53e5cd6'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x15484bc239f7554e7ead77c45834c722d3f74a9b20826fdf21bbb1b026444286', + ), // https://polygonscan.com/tx/0x6c94e24c0ddff6dd9bfa860561945330c81df85ebb4b1ecf75a459b016719314 stablecoinIsToken0: false, - wrappedNativeAddress: '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', // WMATIC + wrappedNativeAddress: Address.fromString('0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'), // WMATIC minimumNativeLocked: BigDecimal.fromString('20000'), stablecoinAddresses: [ - '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', // USDC.e - '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063', // DAI - '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', // USDC + Address.fromString('0x2791bca1f2de4661ed88a30c99a7a9449aa84174'), // USDC.e + Address.fromString('0x8f3cf7ad23cd3cadbd9735aff958023239c6a063'), // DAI + Address.fromString('0x3c499c542cef5e3811e1192ce70d8cc03d5c3359'), // USDC ], whitelistTokens: [ - '0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270', // WMATIC - '0x7ceb23fd6bc0add59e62ac25578270cff1b9f619', // WETH - '0x2791bca1f2de4661ed88a30c99a7a9449aa84174', // USDC.e - '0x8f3cf7ad23cd3cadbd9735aff958023239c6a063', // DAI - '0x3c499c542cef5e3811e1192ce70d8cc03d5c3359', // USDC - '0x0000000000000000000000000000000000000000', // Native POL + Address.fromString('0x0d500b1d8e8ef31e21c99d1db9a6444d3adf1270'), // WMATIC + Address.fromString('0x7ceb23fd6bc0add59e62ac25578270cff1b9f619'), // WETH + Address.fromString('0x2791bca1f2de4661ed88a30c99a7a9449aa84174'), // USDC.e + Address.fromString('0x8f3cf7ad23cd3cadbd9735aff958023239c6a063'), // DAI + Address.fromString('0x3c499c542cef5e3811e1192ce70d8cc03d5c3359'), // USDC + Address.fromString('0x0000000000000000000000000000000000000000'), // Native POL ], tokenOverrides: [], poolsToSkip: [], @@ -270,20 +282,22 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == BSC_NETWORK_NAME) { return { - poolManagerAddress: '0x28e2ea090877bf75740558f6bfb36a5ffee9e9df', - stablecoinWrappedNativePoolId: '0x4c9dff5169d88f7fbf5e43fc8e2eb56bf9791785729b9fc8c22064a47af12052', // https://bscscan.com/tx/0x36c1e4c7b4105a0be337addc32b5564dd3494fccfe331bf9fe7c647163d27d05#eventlog + poolManagerAddress: Address.fromString('0x28e2ea090877bf75740558f6bfb36a5ffee9e9df'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x4c9dff5169d88f7fbf5e43fc8e2eb56bf9791785729b9fc8c22064a47af12052', + ), // https://bscscan.com/tx/0x36c1e4c7b4105a0be337addc32b5564dd3494fccfe331bf9fe7c647163d27d05#eventlog stablecoinIsToken0: true, - wrappedNativeAddress: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', // WBNB + wrappedNativeAddress: Address.fromString('0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'), // WBNB minimumNativeLocked: BigDecimal.fromString('10'), stablecoinAddresses: [ - '0x55d398326f99059ff775485246999027b3197955', // USDT - '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', // USDC + Address.fromString('0x55d398326f99059ff775485246999027b3197955'), // USDT + Address.fromString('0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d'), // USDC ], whitelistTokens: [ - '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', // WBNB - '0x55d398326f99059ff775485246999027b3197955', // USDT - '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', // USDC - '0x0000000000000000000000000000000000000000', // Native BNB + Address.fromString('0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c'), // WBNB + Address.fromString('0x55d398326f99059ff775485246999027b3197955'), // USDT + Address.fromString('0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d'), // USDC + Address.fromString('0x0000000000000000000000000000000000000000'), // Native BNB ], tokenOverrides: [], poolsToSkip: [], @@ -296,28 +310,30 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == OPTIMISM_NETWORK_NAME) { return { - poolManagerAddress: '0x9a13f98cb987694c9f086b1f5eb990eea8264ec3', - stablecoinWrappedNativePoolId: '0xedba0a2a9dc73acf4b130e07605cb4c212bbd98a31c9cd442cfb8cf5b4e093e7', // https://optimistic.etherscan.io/tx/0x5a7ce7eaa8a1ae27a84846b0152d2910ec8db0c4d62b0968e0a49830d882ad28 + poolManagerAddress: Address.fromString('0x9a13f98cb987694c9f086b1f5eb990eea8264ec3'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0xedba0a2a9dc73acf4b130e07605cb4c212bbd98a31c9cd442cfb8cf5b4e093e7', + ), // https://optimistic.etherscan.io/tx/0x5a7ce7eaa8a1ae27a84846b0152d2910ec8db0c4d62b0968e0a49830d882ad28 stablecoinIsToken0: true, - wrappedNativeAddress: '0x4200000000000000000000000000000000000006', // WETH + wrappedNativeAddress: Address.fromString('0x4200000000000000000000000000000000000006'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', // DAI - '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC.e - '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', // USDT - '0x0b2c639c533813f4aa9d7837caf62653d097ff85', // USDC + Address.fromString('0xda10009cbd5d07dd0cecc66161fc93d7c9000da1'), // DAI + Address.fromString('0x7f5c764cbc14f9669b88837ca1490cca17c31607'), // USDC.e + Address.fromString('0x94b008aa00579c1307b0ef2c499ad98a8ce58e58'), // USDT + Address.fromString('0x0b2c639c533813f4aa9d7837caf62653d097ff85'), // USDC ], whitelistTokens: [ - '0x4200000000000000000000000000000000000006', // WETH - '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', // DAI - '0x7f5c764cbc14f9669b88837ca1490cca17c31607', // USDC.e - '0x94b008aa00579c1307b0ef2c499ad98a8ce58e58', // USDT - '0x4200000000000000000000000000000000000042', // OP - '0x9e1028f5f1d5ede59748ffcee5532509976840e0', // PERP - '0x50c5725949a6f0c72e6c4a641f24049a917db0cb', // LYRA - '0x68f180fcce6836688e9084f035309e29bf0a2095', // WBTC - '0x0b2c639c533813f4aa9d7837caf62653d097ff85', // USDC - '0x0000000000000000000000000000000000000000', // Native ETH + Address.fromString('0x4200000000000000000000000000000000000006'), // WETH + Address.fromString('0xda10009cbd5d07dd0cecc66161fc93d7c9000da1'), // DAI + Address.fromString('0x7f5c764cbc14f9669b88837ca1490cca17c31607'), // USDC.e + Address.fromString('0x94b008aa00579c1307b0ef2c499ad98a8ce58e58'), // USDT + Address.fromString('0x4200000000000000000000000000000000000042'), // OP + Address.fromString('0x9e1028f5f1d5ede59748ffcee5532509976840e0'), // PERP + Address.fromString('0x50c5725949a6f0c72e6c4a641f24049a917db0cb'), // LYRA + Address.fromString('0x68f180fcce6836688e9084f035309e29bf0a2095'), // WBTC + Address.fromString('0x0b2c639c533813f4aa9d7837caf62653d097ff85'), // USDC + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH ], tokenOverrides: [ { @@ -337,29 +353,31 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == AVALANCHE_NETWORK_NAME) { return { - poolManagerAddress: '0x06380c0e0912312b5150364b9dc4542ba0dbbc85', - stablecoinWrappedNativePoolId: '0xd7a8035ddd9ec1dba25e3b27b685927fe63d65281f21c1c1d21d122fc48caeb7', // https://snowtrace.io/tx/0x008bbcac5d411e48621c94f75f3dedf025a031d2633a548fb372f45f73db111d/eventlog?chainid=43114 + poolManagerAddress: Address.fromString('0x06380c0e0912312b5150364b9dc4542ba0dbbc85'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0xd7a8035ddd9ec1dba25e3b27b685927fe63d65281f21c1c1d21d122fc48caeb7', + ), // https://snowtrace.io/tx/0x008bbcac5d411e48621c94f75f3dedf025a031d2633a548fb372f45f73db111d/eventlog?chainid=43114 stablecoinIsToken0: false, - wrappedNativeAddress: '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7', // WAVAX + wrappedNativeAddress: Address.fromString('0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7'), // WAVAX minimumNativeLocked: BigDecimal.fromString('100'), stablecoinAddresses: [ - '0xd586e7f844cea2f87f50152665bcbc2c279d8d70', // DAI_E - '0xba7deebbfc5fa1100fb055a87773e1e99cd3507a', // DAI - '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664', // USDC_E - '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e', // USDC - '0xc7198437980c041c805a1edcba50c1ce5db95118', // USDT_E - '0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7', // USDT + Address.fromString('0xd586e7f844cea2f87f50152665bcbc2c279d8d70'), // DAI_E + Address.fromString('0xba7deebbfc5fa1100fb055a87773e1e99cd3507a'), // DAI + Address.fromString('0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664'), // USDC_E + Address.fromString('0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e'), // USDC + Address.fromString('0xc7198437980c041c805a1edcba50c1ce5db95118'), // USDT_E + Address.fromString('0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7'), // USDT ], whitelistTokens: [ - '0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7', // WAVAX - '0xd586e7f844cea2f87f50152665bcbc2c279d8d70', // DAI_E - '0xba7deebbfc5fa1100fb055a87773e1e99cd3507a', // DAI - '0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664', // USDC_E - '0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e', // USDC - '0xc7198437980c041c805a1edcba50c1ce5db95118', // USDT_E - '0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7', // USDT - '0x130966628846bfd36ff31a822705796e8cb8c18d', // MIM - '0x0000000000000000000000000000000000000000', // Native AVX + Address.fromString('0xb31f66aa3c1e785363f0875a1b74e27b85fd66c7'), // WAVAX + Address.fromString('0xd586e7f844cea2f87f50152665bcbc2c279d8d70'), // DAI_E + Address.fromString('0xba7deebbfc5fa1100fb055a87773e1e99cd3507a'), // DAI + Address.fromString('0xa7d7079b0fead91f3e65f86e8915cb59c1a4c664'), // USDC_E + Address.fromString('0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e'), // USDC + Address.fromString('0xc7198437980c041c805a1edcba50c1ce5db95118'), // USDT_E + Address.fromString('0x9702230a8ea53601f5cd2dc00fdbc13d4df4a8c7'), // USDT + Address.fromString('0x130966628846bfd36ff31a822705796e8cb8c18d'), // MIM + Address.fromString('0x0000000000000000000000000000000000000000'), // Native AVX ], tokenOverrides: [], poolsToSkip: [], @@ -372,21 +390,23 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == WORLDCHAIN_MAINNET_NETWORK_NAME) { return { - poolManagerAddress: '0xb1860d529182ac3bc1f51fa2abd56662b7d13f33', - stablecoinWrappedNativePoolId: '0x45c70c27c25654e8c73bc0d63ba350144de8207a73c53d38409d3e127d993dc7', // https://worldchain-mainnet.explorer.alchemy.com/tx/0x042848d1377542415c68a8f8901923f2e54a4596016890eefb7c5094e45775d7?tab=logs + poolManagerAddress: Address.fromString('0xb1860d529182ac3bc1f51fa2abd56662b7d13f33'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x45c70c27c25654e8c73bc0d63ba350144de8207a73c53d38409d3e127d993dc7', + ), // https://worldchain-mainnet.explorer.alchemy.com/tx/0x042848d1377542415c68a8f8901923f2e54a4596016890eefb7c5094e45775d7?tab=logs stablecoinIsToken0: false, - wrappedNativeAddress: '0x4200000000000000000000000000000000000006', // WETH + wrappedNativeAddress: Address.fromString('0x4200000000000000000000000000000000000006'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x79a02482a880bce3f13e09da970dc34db4cd24d1', // USDC.e + Address.fromString('0x79a02482a880bce3f13e09da970dc34db4cd24d1'), // USDC.e ], whitelistTokens: [ - '0x4200000000000000000000000000000000000006', // WETH - '0x79a02482a880bce3f13e09da970dc34db4cd24d1', // USDC.e - '0x03c7054bcb39f7b2e5b2c7acb37583e32d70cfa3', // WBTC - '0x2cfc85d8e48f8eab294be644d9e25c3030863003', // WLD - '0x859dbe24b90c9f2f7742083d3cf59ca41f55be5d', // sDAI - '0x0000000000000000000000000000000000000000', // Native ETH + Address.fromString('0x4200000000000000000000000000000000000006'), // WETH + Address.fromString('0x79a02482a880bce3f13e09da970dc34db4cd24d1'), // USDC.e + Address.fromString('0x03c7054bcb39f7b2e5b2c7acb37583e32d70cfa3'), // WBTC + Address.fromString('0x2cfc85d8e48f8eab294be644d9e25c3030863003'), // WLD + Address.fromString('0x859dbe24b90c9f2f7742083d3cf59ca41f55be5d'), // sDAI + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH ], tokenOverrides: [], poolsToSkip: [], @@ -399,18 +419,20 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == ZORA_MAINNET_NETWORK_NAME) { return { - poolManagerAddress: '0x0575338e4c17006ae181b47900a84404247ca30f', - stablecoinWrappedNativePoolId: '0x8362fda2356bf98851192da5b5b89553dd92ad73f8e8d6be97f154ce72b0adfe', // https://explorer.zora.energy/tx/0x8a0cd1856e3c95918e78478ccc993a6e745e364d5036852f44033827be880a17 + poolManagerAddress: Address.fromString('0x0575338e4c17006ae181b47900a84404247ca30f'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x8362fda2356bf98851192da5b5b89553dd92ad73f8e8d6be97f154ce72b0adfe', + ), // https://explorer.zora.energy/tx/0x8a0cd1856e3c95918e78478ccc993a6e745e364d5036852f44033827be880a17 stablecoinIsToken0: false, - wrappedNativeAddress: '0x4200000000000000000000000000000000000006', // WETH + wrappedNativeAddress: Address.fromString('0x4200000000000000000000000000000000000006'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0xcccccccc7021b32ebb4e8c08314bd62f7c653ec4', // USDzC + Address.fromString('0xcccccccc7021b32ebb4e8c08314bd62f7c653ec4'), // USDzC ], whitelistTokens: [ - '0x4200000000000000000000000000000000000006', // WETH - '0xcccccccc7021b32ebb4e8c08314bd62f7c653ec4', // USDzC - '0x0000000000000000000000000000000000000000', // Native ETH + Address.fromString('0x4200000000000000000000000000000000000006'), // WETH + Address.fromString('0xcccccccc7021b32ebb4e8c08314bd62f7c653ec4'), // USDzC + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH ], tokenOverrides: [], poolsToSkip: [], @@ -423,41 +445,43 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == MAINNET_NETWORK_NAME) { return { - poolManagerAddress: '0x000000000004444c5dc75cb358380d2e3de08a90', - stablecoinWrappedNativePoolId: '0x4f88f7c99022eace4740c6898f59ce6a2e798a1e64ce54589720b7153eb224a7', // https://etherscan.io/tx/0x4e63fcc0dd42a2b317e77d17e236cadf77464a08ccece33a354bd8648b5f7419#eventlog + poolManagerAddress: Address.fromString('0x000000000004444c5dc75cb358380d2e3de08a90'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x4f88f7c99022eace4740c6898f59ce6a2e798a1e64ce54589720b7153eb224a7', + ), // https://etherscan.io/tx/0x4e63fcc0dd42a2b317e77d17e236cadf77464a08ccece33a354bd8648b5f7419#eventlog stablecoinIsToken0: true, - wrappedNativeAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH + wrappedNativeAddress: Address.fromString('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x6b175474e89094c44da98b954eedeac495271d0f', // DAI - '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC - '0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT - '0x0000000000085d4780b73119b644ae5ecd22b376', // TUSD - '0x956f47f50a910163d8bf957cf5846d573e7f87ca', // FEI + Address.fromString('0x6b175474e89094c44da98b954eedeac495271d0f'), // DAI + Address.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'), // USDC + Address.fromString('0xdac17f958d2ee523a2206206994597c13d831ec7'), // USDT + Address.fromString('0x0000000000085d4780b73119b644ae5ecd22b376'), // TUSD + Address.fromString('0x956f47f50a910163d8bf957cf5846d573e7f87ca'), // FEI ], whitelistTokens: [ - '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH - '0x6b175474e89094c44da98b954eedeac495271d0f', // DAI - '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', // USDC - '0xdac17f958d2ee523a2206206994597c13d831ec7', // USDT - '0x0000000000085d4780b73119b644ae5ecd22b376', // TUSD - '0x2260fac5e5542a773aa44fbcfedf7c193bc2c599', // WBTC - '0x5d3a536e4d6dbd6114cc1ead35777bab948e3643', // cDAI - '0x39aa39c021dfbae8fac545936693ac917d5e7563', // cUSDC - '0x86fadb80d8d2cff3c3680819e4da99c10232ba0f', // EBASE - '0x57ab1ec28d129707052df4df418d58a2d46d5f51', // sUSD - '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2', // MKR - '0xc00e94cb662c3520282e6f5717214004a7f26888', // COMP - '0x514910771af9ca656af840dff83e8264ecf986ca', // LINK - '0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f', // SNX - '0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e', // YFI - '0x111111111117dc0aa78b770fa6a738034120c302', // 1INCH - '0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8', // yCurv - '0x956f47f50a910163d8bf957cf5846d573e7f87ca', // FEI - '0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0', // MATIC - '0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9', // AAVE - '0xfe2e637202056d30016725477c5da089ab0a043a', // sETH2 - '0x0000000000000000000000000000000000000000', // Native ETH + Address.fromString('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2'), // WETH + Address.fromString('0x6b175474e89094c44da98b954eedeac495271d0f'), // DAI + Address.fromString('0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48'), // USDC + Address.fromString('0xdac17f958d2ee523a2206206994597c13d831ec7'), // USDT + Address.fromString('0x0000000000085d4780b73119b644ae5ecd22b376'), // TUSD + Address.fromString('0x2260fac5e5542a773aa44fbcfedf7c193bc2c599'), // WBTC + Address.fromString('0x5d3a536e4d6dbd6114cc1ead35777bab948e3643'), // cDAI + Address.fromString('0x39aa39c021dfbae8fac545936693ac917d5e7563'), // cUSDC + Address.fromString('0x86fadb80d8d2cff3c3680819e4da99c10232ba0f'), // EBASE + Address.fromString('0x57ab1ec28d129707052df4df418d58a2d46d5f51'), // sUSD + Address.fromString('0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2'), // MKR + Address.fromString('0xc00e94cb662c3520282e6f5717214004a7f26888'), // COMP + Address.fromString('0x514910771af9ca656af840dff83e8264ecf986ca'), // LINK + Address.fromString('0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f'), // SNX + Address.fromString('0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e'), // YFI + Address.fromString('0x111111111117dc0aa78b770fa6a738034120c302'), // 1INCH + Address.fromString('0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8'), // yCurv + Address.fromString('0x956f47f50a910163d8bf957cf5846d573e7f87ca'), // FEI + Address.fromString('0x7d1afa7b718fb893db30a3abc0cfc608aacfebb0'), // MATIC + Address.fromString('0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'), // AAVE + Address.fromString('0xfe2e637202056d30016725477c5da089ab0a043a'), // sETH2 + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH ], tokenOverrides: [ { @@ -507,18 +531,20 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == BLAST_MAINNET_NETWORK_NAME) { return { - poolManagerAddress: '0x1631559198a9e474033433b2958dabc135ab6446', - stablecoinWrappedNativePoolId: '0x83e7c9f12348a95a5fe02c8af7074dd52defd1e108e19e51234c49da56d7c635', // https://blastscan.io/tx/0x96ecf330532a794388405835ba7cc6687f281d3e44dee502fb89dc8d789fdf33 + poolManagerAddress: Address.fromString('0x1631559198a9e474033433b2958dabc135ab6446'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x83e7c9f12348a95a5fe02c8af7074dd52defd1e108e19e51234c49da56d7c635', + ), // https://blastscan.io/tx/0x96ecf330532a794388405835ba7cc6687f281d3e44dee502fb89dc8d789fdf33 stablecoinIsToken0: true, - wrappedNativeAddress: '0x4300000000000000000000000000000000000004', // WETH + wrappedNativeAddress: Address.fromString('0x4300000000000000000000000000000000000004'), // WETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x4300000000000000000000000000000000000003', // USDB + Address.fromString('0x4300000000000000000000000000000000000003'), // USDB ], whitelistTokens: [ - '0x4300000000000000000000000000000000000004', // WETH - '0x4300000000000000000000000000000000000003', // USDB - '0x0000000000000000000000000000000000000000', // Native ETH + Address.fromString('0x4300000000000000000000000000000000000004'), // WETH + Address.fromString('0x4300000000000000000000000000000000000003'), // USDB + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH ], tokenOverrides: [], poolsToSkip: [], @@ -531,23 +557,25 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == UNICHAIN_MAINNET_NETWORK_NAME) { return { - poolManagerAddress: '0x1f98400000000000000000000000000000000004', - stablecoinWrappedNativePoolId: '0x25939956ef14a098d95051d86c75890cfd623a9eeba055e46d8dd9135980b37c', + poolManagerAddress: Address.fromString('0x1f98400000000000000000000000000000000004'), + stablecoinWrappedNativePoolId: Bytes.fromHexString( + '0x25939956ef14a098d95051d86c75890cfd623a9eeba055e46d8dd9135980b37c', + ), stablecoinIsToken0: false, - wrappedNativeAddress: '0x0000000000000000000000000000000000000000', // Native ETH + wrappedNativeAddress: Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0x078d782b760474a361dda0af3839290b0ef57ad6', // USDC - '0x20cab320a855b39f724131c69424240519573f81', // DAI - '0x9151434b16b9763660705744891fa906f660ecc5', // USDT0 + Address.fromString('0x078d782b760474a361dda0af3839290b0ef57ad6'), // USDC + Address.fromString('0x20cab320a855b39f724131c69424240519573f81'), // DAI + Address.fromString('0x9151434b16b9763660705744891fa906f660ecc5'), // USDT0 ], whitelistTokens: [ - '0x4200000000000000000000000000000000000006', // WETH - '0x078d782b760474a361dda0af3839290b0ef57ad6', // USDC - '0x20cab320a855b39f724131c69424240519573f81', // DAI - '0x0000000000000000000000000000000000000000', // Native ETH - '0x9151434b16b9763660705744891fa906f660ecc5', // USDT0 - '0x927b51f251480a681271180da4de28d44ec4afb8', // WBTC + Address.fromString('0x4200000000000000000000000000000000000006'), // WETH + Address.fromString('0x078d782b760474a361dda0af3839290b0ef57ad6'), // USDC + Address.fromString('0x20cab320a855b39f724131c69424240519573f81'), // DAI + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH + Address.fromString('0x9151434b16b9763660705744891fa906f660ecc5'), // USDT0 + Address.fromString('0x927b51f251480a681271180da4de28d44ec4afb8'), // WBTC ], tokenOverrides: [], poolsToSkip: [], @@ -560,18 +588,20 @@ export function getSubgraphConfig(): SubgraphConfig { } } else if (selectedNetwork == SONEIUM_MAINNET_NETWORK_NAME) { return { - poolManagerAddress: '0x360e68faccca8ca495c1b759fd9eee466db9fb32', - stablecoinWrappedNativePoolId: '0x3d18457ff1dcfa8ffb14b162ae3def9eda618569ac4a6aadc827628f5981b515', + poolManagerAddress: Address.fromString('0x360e68faccca8ca495c1b759fd9eee466db9fb32'), + stablecoinWrappedNativePoolId: Address.fromString( + '0x3d18457ff1dcfa8ffb14b162ae3def9eda618569ac4a6aadc827628f5981b515', + ), stablecoinIsToken0: false, - wrappedNativeAddress: '0x0000000000000000000000000000000000000000', // Native ETH + wrappedNativeAddress: Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH minimumNativeLocked: BigDecimal.fromString('1'), stablecoinAddresses: [ - '0xba9986d2381edf1da03b0b9c1f8b00dc4aacc369', // USDC + Address.fromString('0xba9986d2381edf1da03b0b9c1f8b00dc4aacc369'), // USDC ], whitelistTokens: [ - '0x4200000000000000000000000000000000000006', // WETH - '0xba9986d2381edf1da03b0b9c1f8b00dc4aacc369', // USDC - '0x0000000000000000000000000000000000000000', // Native ETH + Address.fromString('0x4200000000000000000000000000000000000006'), // WETH + Address.fromString('0xba9986d2381edf1da03b0b9c1f8b00dc4aacc369'), // USDC + Address.fromString('0x0000000000000000000000000000000000000000'), // Native ETH ], tokenOverrides: [], poolsToSkip: [], diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 27ff634..fbbc097 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,8 +1,8 @@ -import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' +import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts' import { hexToBigInt } from './index' -export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000' +export const ADDRESS_ZERO = Address.fromString('0x0000000000000000000000000000000000000000') export const ZERO_BI = BigInt.fromI32(0) export const ONE_BI = BigInt.fromI32(1) diff --git a/src/utils/id.ts b/src/utils/id.ts index 94d7dea..af129c1 100644 --- a/src/utils/id.ts +++ b/src/utils/id.ts @@ -4,8 +4,8 @@ export function positionId(tokenId: BigInt): string { return tokenId.toString() } -export function eventId(transactionHash: Bytes, logIndex: BigInt): string { - return `${transactionHash.toHexString()}-${logIndex.toString()}` +export function eventId(transactionHash: Bytes, logIndex: BigInt): Bytes { + return transactionHash.concatI32(logIndex.toI32()) } export function poolKeyId(token0: Address, token1: Address, fee: BigInt, tickSpacing: BigInt, hooks: Address): string { diff --git a/src/utils/index.ts b/src/utils/index.ts index 075432d..953c78c 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -80,9 +80,9 @@ export function convertTokenToDecimal(tokenAmount: BigInt, exchangeDecimals: Big } export function loadTransaction(event: ethereum.Event): Transaction { - let transaction = Transaction.load(event.transaction.hash.toHexString()) + let transaction = Transaction.load(event.transaction.hash) if (transaction === null) { - transaction = new Transaction(event.transaction.hash.toHexString()) + transaction = new Transaction(event.transaction.hash) } transaction.blockNumber = event.block.number transaction.timestamp = event.block.timestamp diff --git a/src/utils/intervalUpdates.ts b/src/utils/intervalUpdates.ts index 5ecc92c..678a623 100644 --- a/src/utils/intervalUpdates.ts +++ b/src/utils/intervalUpdates.ts @@ -1,4 +1,4 @@ -import { ethereum } from '@graphprotocol/graph-ts' +import { Address, Bytes, ethereum } from '@graphprotocol/graph-ts' import { Bundle, @@ -17,7 +17,7 @@ import { ONE_BI, ZERO_BD, ZERO_BI } from './constants' * Tracks global aggregate data over daily windows * @param event */ -export function updateUniswapDayData(event: ethereum.Event, poolId: string): UniswapDayData { +export function updateUniswapDayData(event: ethereum.Event, poolId: Bytes): UniswapDayData { const uniswap = PoolManager.load(poolId)! const timestamp = event.block.timestamp.toI32() const dayID = timestamp / 86400 // rounded @@ -37,11 +37,11 @@ export function updateUniswapDayData(event: ethereum.Event, poolId: string): Uni return uniswapDayData as UniswapDayData } -export function updatePoolDayData(poolId: string, event: ethereum.Event): PoolDayData { +export function updatePoolDayData(poolId: Bytes, event: ethereum.Event): PoolDayData { const timestamp = event.block.timestamp.toI32() const dayID = timestamp / 86400 const dayStartTimestamp = dayID * 86400 - const dayPoolID = poolId.concat('-').concat(dayID.toString()) + const dayPoolID = poolId.toHexString().concat('-').concat(dayID.toString()) const pool = Pool.load(poolId)! let poolDayData = PoolDayData.load(dayPoolID) if (poolDayData === null) { @@ -79,11 +79,11 @@ export function updatePoolDayData(poolId: string, event: ethereum.Event): PoolDa return poolDayData as PoolDayData } -export function updatePoolHourData(poolId: string, event: ethereum.Event): PoolHourData { +export function updatePoolHourData(poolId: Bytes, event: ethereum.Event): PoolHourData { const timestamp = event.block.timestamp.toI32() const hourIndex = timestamp / 3600 // get unique hour within unix history const hourStartUnix = hourIndex * 3600 // want the rounded effect - const hourPoolID = poolId.concat('-').concat(hourIndex.toString()) + const hourPoolID = poolId.toHexString().concat('-').concat(hourIndex.toString()) const pool = Pool.load(poolId)! let poolHourData = PoolHourData.load(hourPoolID) if (poolHourData === null) { @@ -123,7 +123,7 @@ export function updatePoolHourData(poolId: string, event: ethereum.Event): PoolH } export function updateTokenDayData(token: Token, event: ethereum.Event): TokenDayData { - const bundle = Bundle.load('1')! + const bundle = Bundle.load(Bytes.fromI32(1))! const timestamp = event.block.timestamp.toI32() const dayID = timestamp / 86400 const dayStartTimestamp = dayID * 86400 @@ -163,7 +163,7 @@ export function updateTokenDayData(token: Token, event: ethereum.Event): TokenDa } export function updateTokenHourData(token: Token, event: ethereum.Event): TokenHourData { - const bundle = Bundle.load('1')! + const bundle = Bundle.load(Bytes.fromI32(1))! const timestamp = event.block.timestamp.toI32() const hourIndex = timestamp / 3600 // get unique hour within unix history const hourStartUnix = hourIndex * 3600 // want the rounded effect diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index 8809b43..39bd76e 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -1,4 +1,4 @@ -import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' +import { Address, BigDecimal, BigInt, Bytes } from '@graphprotocol/graph-ts' import { exponentToBigDecimal, safeDiv } from '../utils/index' import { Bundle, Pool, Token } from './../types/schema' @@ -23,7 +23,7 @@ export function sqrtPriceX96ToTokenPrices( return [price0, price1] } -export function getNativePriceInUSD(stablecoinWrappedNativePoolId: string, stablecoinIsToken0: boolean): BigDecimal { +export function getNativePriceInUSD(stablecoinWrappedNativePoolId: Bytes, stablecoinIsToken0: boolean): BigDecimal { const stablecoinWrappedNativePool = Pool.load(stablecoinWrappedNativePoolId) if (stablecoinWrappedNativePool !== null) { return stablecoinIsToken0 ? stablecoinWrappedNativePool.token0Price : stablecoinWrappedNativePool.token1Price @@ -38,8 +38,8 @@ export function getNativePriceInUSD(stablecoinWrappedNativePoolId: string, stabl **/ export function findNativePerToken( token: Token, - wrappedNativeAddress: string, - stablecoinAddresses: string[], + wrappedNativeAddress: Bytes, + stablecoinAddresses: Bytes[], minimumNativeLocked: BigDecimal, ): BigDecimal { if (token.id == wrappedNativeAddress || token.id == ADDRESS_ZERO) { @@ -50,7 +50,7 @@ export function findNativePerToken( // need to update this to actually detect best rate based on liquidity distribution let largestLiquidityETH = ZERO_BD let priceSoFar = ZERO_BD - const bundle = Bundle.load('1')! + const bundle = Bundle.load(Bytes.fromI32(1))! // hardcoded fix for incorrect rates // if whitelist includes token - get the safe price @@ -106,9 +106,9 @@ export function getTrackedAmountUSD( token0: Token, tokenAmount1: BigDecimal, token1: Token, - whitelistTokens: string[], + whitelistTokens: Bytes[], ): BigDecimal { - const bundle = Bundle.load('1')! + const bundle = Bundle.load(Bytes.fromI32(1))! const price0USD = token0.derivedETH.times(bundle.ethPriceUSD) const price1USD = token1.derivedETH.times(bundle.ethPriceUSD) diff --git a/src/utils/tick.ts b/src/utils/tick.ts index 1ded563..1b93a5d 100644 --- a/src/utils/tick.ts +++ b/src/utils/tick.ts @@ -1,11 +1,11 @@ -import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' +import { BigDecimal, BigInt, Bytes } from '@graphprotocol/graph-ts' import { ModifyLiquidity } from '../types/PoolManager/PoolManager' import { Tick } from '../types/schema' import { ONE_BD, ZERO_BI } from './constants' import { fastExponentiation, safeDiv } from './index' -export function createTick(tickId: string, tickIdx: i32, poolId: string, event: ModifyLiquidity): Tick { +export function createTick(tickId: Bytes, tickIdx: i32, poolId: Bytes, event: ModifyLiquidity): Tick { const tick = new Tick(tickId) tick.tickIdx = BigInt.fromI32(tickIdx) tick.pool = poolId diff --git a/src/utils/token.ts b/src/utils/token.ts index 586c0d4..17a2832 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -13,7 +13,7 @@ export function fetchTokenSymbol( tokenOverrides: StaticTokenDefinition[], nativeTokenDetails: NativeTokenDetails, ): string { - if (tokenAddress.equals(Address.fromString(ADDRESS_ZERO))) { + if (tokenAddress.equals(ADDRESS_ZERO)) { return nativeTokenDetails.symbol } // try with the static definition @@ -48,7 +48,7 @@ export function fetchTokenName( tokenOverrides: StaticTokenDefinition[], nativeTokenDetails: NativeTokenDetails, ): string { - if (tokenAddress.equals(Address.fromString(ADDRESS_ZERO))) { + if (tokenAddress.equals(ADDRESS_ZERO)) { return nativeTokenDetails.name } // try with the static definition @@ -79,7 +79,7 @@ export function fetchTokenName( } export function fetchTokenTotalSupply(tokenAddress: Address): BigInt { - if (tokenAddress.equals(Address.fromString(ADDRESS_ZERO))) { + if (tokenAddress.equals(ADDRESS_ZERO)) { return ZERO_BI } const contract = ERC20.bind(tokenAddress) @@ -96,7 +96,7 @@ export function fetchTokenDecimals( tokenOverrides: StaticTokenDefinition[], nativeTokenDetails: NativeTokenDetails, ): BigInt | null { - if (tokenAddress.equals(Address.fromString(ADDRESS_ZERO))) { + if (tokenAddress.equals(ADDRESS_ZERO)) { return nativeTokenDetails.decimals } // try with the static definition diff --git a/subgraph.yaml b/subgraph.yaml index 4a50f5a..febe250 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -1,11 +1,10 @@ -specVersion: 0.0.4 +specVersion: 1.2.0 description: Uniswap is a decentralized protocol for automated token exchange on Ethereum. repository: https://github.com/Uniswap/v4-subgraph schema: file: ./schema.graphql features: - nonFatalErrors - - grafting dataSources: - kind: ethereum/contract name: PoolManager @@ -16,7 +15,7 @@ dataSources: startBlock: 21688329 mapping: kind: ethereum/events - apiVersion: 0.0.7 + apiVersion: 0.0.9 language: wasm/assemblyscript file: ./src/mappings/index.ts entities: @@ -32,14 +31,11 @@ dataSources: - name: PoolManager file: ./abis/PoolManager.json eventHandlers: - - event: Initialize(indexed bytes32,indexed address,indexed - address,uint24,int24,address,uint160,int24) + - event: Initialize(indexed bytes32,indexed address,indexed address,uint24,int24,address,uint160,int24) handler: handleInitialize - - event: ModifyLiquidity(indexed bytes32,indexed - address,int24,int24,int256,bytes32) + - event: ModifyLiquidity(indexed bytes32,indexed address,int24,int24,int256,bytes32) handler: handleModifyLiquidity - - event: Swap(indexed bytes32,indexed - address,int128,int128,uint160,uint128,int24,uint24) + - event: Swap(indexed bytes32,indexed address,int128,int128,uint160,uint128,int24,uint24) handler: handleSwap - kind: ethereum/contract name: PositionManager @@ -50,7 +46,7 @@ dataSources: startBlock: 21689089 mapping: kind: ethereum/events - apiVersion: 0.0.7 + apiVersion: 0.0.9 language: wasm/assemblyscript file: ./src/mappings/index.ts entities: diff --git a/tests/handlers/constants.ts b/tests/handlers/constants.ts index 5497e8d..849d843 100644 --- a/tests/handlers/constants.ts +++ b/tests/handlers/constants.ts @@ -7,15 +7,19 @@ import { Pool, Token } from '../../src/types/schema' import { SubgraphConfig } from '../../src/utils/chains' import { ADDRESS_ZERO, ZERO_BD, ZERO_BI } from '../../src/utils/constants' -const POOL_MANAGER_ADDRESS = '0xE8E23e97Fa135823143d6b9Cba9c699040D51F70' -const USDC_MAINNET_ADDRESS = '0x5d1abc83973c773d122ae7c551251cc9be2baecc' -const WETH_MAINNET_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' -const WBTC_MAINNET_ADDRESS = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' -const NATIVE_TOKEN_ADDRESS = '0x0000000000000000000000000000000000000000' +const POOL_MANAGER_ADDRESS = Address.fromString('0xE8E23e97Fa135823143d6b9Cba9c699040D51F70') +const USDC_MAINNET_ADDRESS = Address.fromString('0x5d1abc83973c773d122ae7c551251cc9be2baecc') +const WETH_MAINNET_ADDRESS = Address.fromString('0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2') +const WBTC_MAINNET_ADDRESS = Address.fromString('0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599') +const NATIVE_TOKEN_ADDRESS = Address.fromString('0x0000000000000000000000000000000000000000') export const POOL_FEE_TIER_05 = 500 -export const USDC_WETH_POOL_ID = '0x85c41d6535ebab7661979fa7a5d331e4cb229b4d1e7dde1a78ae298fab8ca5bb' -export const WBTC_WETH_POOL_ID = '0x0dac90a31985829dc2bbeb5e70fd7e302ef8ca149f58dc485e71f53735bad8e4' +export const USDC_WETH_POOL_ID = Bytes.fromHexString( + '0x85c41d6535ebab7661979fa7a5d331e4cb229b4d1e7dde1a78ae298fab8ca5bb', +) +export const WBTC_WETH_POOL_ID = Bytes.fromHexString( + '0x0dac90a31985829dc2bbeb5e70fd7e302ef8ca149f58dc485e71f53735bad8e4', +) export const TEST_CONFIG: SubgraphConfig = { poolManagerAddress: POOL_MANAGER_ADDRESS, @@ -36,7 +40,7 @@ export const TEST_CONFIG: SubgraphConfig = { } export class TokenFixture { - address: string + address: Address symbol: string name: string totalSupply: string @@ -80,7 +84,7 @@ export const WBTC_MAINNET_FIXTURE: TokenFixture = { balanceOf: '750', } -export const getTokenFixture = (tokenAddress: string): TokenFixture => { +export const getTokenFixture = (tokenAddress: Address): TokenFixture => { if (tokenAddress == USDC_MAINNET_FIXTURE.address) { return USDC_MAINNET_FIXTURE } else if (tokenAddress == WETH_MAINNET_FIXTURE.address) { @@ -93,13 +97,13 @@ export const getTokenFixture = (tokenAddress: string): TokenFixture => { } export class PoolFixture { - id: string + id: Bytes token0: TokenFixture token1: TokenFixture feeTier: string tickSpacing: string liquidity: string - hooks: string + hooks: Address sqrtPrice: string tick: string } @@ -151,7 +155,7 @@ export class PositionFixture { origin: Address } -export const getPoolFixture = (poolAddress: string): PoolFixture => { +export const getPoolFixture = (poolAddress: Bytes): PoolFixture => { if (poolAddress == WBTC_WETH_POOL_ID) { return WBTC_WETH_03_MAINNET_POOL_FIXTURE } else if (poolAddress == USDC_WETH_POOL_ID) { @@ -186,14 +190,12 @@ export const invokePoolCreatedWithMockedEthCalls = ( const sqrtPriceX96 = pool.sqrtPrice const tick = pool.tick - const token0Address = Address.fromString(token0.address) - const token1Address = Address.fromString(token1.address) - - const id = Bytes.fromHexString(USDC_WETH_POOL_ID) as Bytes + const token0Address = token0.address + const token1Address = token1.address - const hooksAddress = Address.fromString(ADDRESS_ZERO) + const hooksAddress = ADDRESS_ZERO const parameters = [ - new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(id)), + new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(USDC_WETH_POOL_ID)), new ethereum.EventParam('currency0', ethereum.Value.fromAddress(token0Address)), new ethereum.EventParam('currency1', ethereum.Value.fromAddress(token1Address)), new ethereum.EventParam('fee', ethereum.Value.fromI32(parseInt(feeTier) as i32)), diff --git a/tests/handlers/handleInitialize.test.ts b/tests/handlers/handleInitialize.test.ts index 2e39f2c..c479f82 100644 --- a/tests/handlers/handleInitialize.test.ts +++ b/tests/handlers/handleInitialize.test.ts @@ -25,12 +25,12 @@ import { } from './constants' class InitializeFixture { - id: string - currency0: string - currency1: string + id: Bytes + currency0: Address + currency1: Address fee: string tickSpacing: string - hooks: string + hooks: Address sqrtPriceX96: string tick: string } @@ -46,7 +46,7 @@ const INITIALIZE_FIXTURE: InitializeFixture = { tick: '1', } -const id = Bytes.fromHexString(USDC_WETH_POOL_ID) as Bytes +const id = USDC_WETH_POOL_ID const INITIALIZE_EVENT = new Initialize( MOCK_EVENT.address, @@ -57,11 +57,11 @@ const INITIALIZE_EVENT = new Initialize( MOCK_EVENT.transaction, [ new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(id)), - new ethereum.EventParam('currency0', ethereum.Value.fromAddress(Address.fromString(INITIALIZE_FIXTURE.currency0))), - new ethereum.EventParam('currency1', ethereum.Value.fromAddress(Address.fromString(INITIALIZE_FIXTURE.currency1))), + new ethereum.EventParam('currency0', ethereum.Value.fromAddress(INITIALIZE_FIXTURE.currency0)), + new ethereum.EventParam('currency1', ethereum.Value.fromAddress(INITIALIZE_FIXTURE.currency1)), new ethereum.EventParam('fee', ethereum.Value.fromI32(parseInt(INITIALIZE_FIXTURE.fee) as i32)), new ethereum.EventParam('tickSpacing', ethereum.Value.fromI32(parseInt(INITIALIZE_FIXTURE.tickSpacing) as i32)), - new ethereum.EventParam('hooks', ethereum.Value.fromAddress(Address.fromString(INITIALIZE_FIXTURE.hooks))), + new ethereum.EventParam('hooks', ethereum.Value.fromAddress(INITIALIZE_FIXTURE.hooks)), new ethereum.EventParam( 'sqrtPriceX96', ethereum.Value.fromUnsignedBigInt(BigInt.fromString(INITIALIZE_FIXTURE.sqrtPriceX96)), @@ -78,7 +78,7 @@ describe('handleInitialize', () => { const token0 = createAndStoreTestToken(USDC_MAINNET_FIXTURE) const token1 = createAndStoreTestToken(WETH_MAINNET_FIXTURE) - const bundle = new Bundle('1') + const bundle = new Bundle(Bytes.fromUTF8('1')) bundle.ethPriceUSD = TEST_ETH_PRICE_USD bundle.save() @@ -90,12 +90,12 @@ describe('handleInitialize', () => { TEST_CONFIG.nativeTokenDetails, ) - assertObjectMatches('Pool', USDC_WETH_POOL_ID, [ - ['token0', token0.id], - ['token1', token1.id], + assertObjectMatches('Pool', USDC_WETH_POOL_ID.toHexString(), [ + ['token0', token0.id.toHexString()], + ['token1', token1.id.toHexString()], ['feeTier', INITIALIZE_FIXTURE.fee], ['tickSpacing', INITIALIZE_FIXTURE.tickSpacing], - ['hooks', INITIALIZE_FIXTURE.hooks], + ['hooks', INITIALIZE_FIXTURE.hooks.toHexString()], ['sqrtPrice', INITIALIZE_FIXTURE.sqrtPriceX96], ['tick', INITIALIZE_FIXTURE.tick], ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], @@ -113,7 +113,9 @@ describe('handleInitialize', () => { TEST_CONFIG.stablecoinAddresses, TEST_CONFIG.minimumNativeLocked, ) - assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address, [['derivedETH', expectedToken0Price.toString()]]) + assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address.toHexString(), [ + ['derivedETH', expectedToken0Price.toString()], + ]) const expectedToken1Price = findNativePerToken( token1, @@ -121,7 +123,9 @@ describe('handleInitialize', () => { TEST_CONFIG.stablecoinAddresses, TEST_CONFIG.minimumNativeLocked, ) - assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address, [['derivedETH', expectedToken1Price.toString()]]) + assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address.toHexString(), [ + ['derivedETH', expectedToken1Price.toString()], + ]) }) }) @@ -166,7 +170,7 @@ describe('findNativePerToken', () => { beforeEach(() => { clearStore() - const bundle = new Bundle('1') + const bundle = new Bundle(Bytes.fromI32(1)) bundle.ethPriceUSD = TEST_ETH_PRICE_USD bundle.save() }) diff --git a/tests/handlers/handleModifyLiquidity.test.ts b/tests/handlers/handleModifyLiquidity.test.ts index bd17d8b..1fbc096 100644 --- a/tests/handlers/handleModifyLiquidity.test.ts +++ b/tests/handlers/handleModifyLiquidity.test.ts @@ -21,7 +21,7 @@ import { } from './constants' class ModifyLiquidityFixture { - id: string + id: Bytes sender: Address tickLower: i32 tickUpper: i32 @@ -44,8 +44,6 @@ const MODIFY_LIQUIDITY_FIXTURE_REMOVE: ModifyLiquidityFixture = { liquidityDelta: BigInt.fromString('-10000000000000000000000'), // Provided liquidity delta } -const id = Bytes.fromHexString(USDC_WETH_POOL_ID) as Bytes - const MODIFY_LIQUIDITY_EVENT_ADD = new ModifyLiquidity( MOCK_EVENT.address, MOCK_EVENT.logIndex, @@ -54,7 +52,7 @@ const MODIFY_LIQUIDITY_EVENT_ADD = new ModifyLiquidity( MOCK_EVENT.block, MOCK_EVENT.transaction, [ - new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(id)), + new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(USDC_WETH_POOL_ID)), new ethereum.EventParam('sender', ethereum.Value.fromAddress(MODIFY_LIQUIDITY_FIXTURE_ADD.sender)), new ethereum.EventParam('tickLower', ethereum.Value.fromI32(MODIFY_LIQUIDITY_FIXTURE_ADD.tickLower as i32)), new ethereum.EventParam('tickUpper', ethereum.Value.fromI32(MODIFY_LIQUIDITY_FIXTURE_ADD.tickUpper as i32)), @@ -74,7 +72,7 @@ const MODIFY_LIQUIDITY_EVENT_REMOVE = new ModifyLiquidity( MOCK_EVENT.block, MOCK_EVENT.transaction, [ - new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(id)), + new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(USDC_WETH_POOL_ID)), new ethereum.EventParam('sender', ethereum.Value.fromAddress(MODIFY_LIQUIDITY_FIXTURE_REMOVE.sender)), new ethereum.EventParam('tickLower', ethereum.Value.fromI32(MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickLower as i32)), new ethereum.EventParam('tickUpper', ethereum.Value.fromI32(MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickUpper as i32)), @@ -90,7 +88,7 @@ describe('handleModifyLiquidity', () => { beforeEach(() => { invokePoolCreatedWithMockedEthCalls(MOCK_EVENT, TEST_CONFIG) - const bundle = new Bundle('1') + const bundle = new Bundle(Bytes.fromI32(1)) bundle.ethPriceUSD = TEST_ETH_PRICE_USD bundle.save() @@ -132,13 +130,13 @@ describe('handleModifyLiquidity', () => { .plus(amountToken1.times(TEST_WETH_DERIVED_ETH)) const poolTotalValueLockedUSD = poolTotalValueLockedETH.times(TEST_ETH_PRICE_USD) - assertObjectMatches('PoolManager', TEST_CONFIG.poolManagerAddress, [ + assertObjectMatches('PoolManager', TEST_CONFIG.poolManagerAddress.toHexString(), [ ['txCount', '1'], ['totalValueLockedETH', poolTotalValueLockedETH.toString()], ['totalValueLockedUSD', poolTotalValueLockedUSD.toString()], ]) - assertObjectMatches('Pool', USDC_WETH_POOL_ID, [ + assertObjectMatches('Pool', USDC_WETH_POOL_ID.toHexString(), [ ['txCount', '1'], ['liquidity', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.toString()], ['totalValueLockedToken0', amountToken0.toString()], @@ -147,13 +145,13 @@ describe('handleModifyLiquidity', () => { ['totalValueLockedUSD', poolTotalValueLockedUSD.toString()], ]) - assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address, [ + assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address.toHexString(), [ ['txCount', '1'], ['totalValueLocked', amountToken0.toString()], ['totalValueLockedUSD', amountToken0.times(TEST_USDC_DERIVED_ETH.times(TEST_ETH_PRICE_USD)).toString()], ]) - assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address, [ + assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address.toHexString(), [ ['txCount', '1'], ['totalValueLocked', amountToken1.toString()], ['totalValueLockedUSD', amountToken1.times(TEST_WETH_DERIVED_ETH.times(TEST_ETH_PRICE_USD)).toString()], @@ -164,9 +162,9 @@ describe('handleModifyLiquidity', () => { [ ['transaction', MOCK_EVENT.transaction.hash.toHexString()], ['timestamp', MOCK_EVENT.block.timestamp.toString()], - ['pool', USDC_WETH_POOL_ID], - ['token0', USDC_MAINNET_FIXTURE.address], - ['token1', WETH_MAINNET_FIXTURE.address], + ['pool', USDC_WETH_POOL_ID.toHexString()], + ['token0', USDC_MAINNET_FIXTURE.address.toHexString()], + ['token1', WETH_MAINNET_FIXTURE.address.toHexString()], // ['owner', MODIFY_LIQUIDITY_FIXTURE.owner.toHexString()], ['sender', MODIFY_LIQUIDITY_FIXTURE_ADD.sender.toHexString()], ['origin', MOCK_EVENT.transaction.from.toHexString()], @@ -181,30 +179,38 @@ describe('handleModifyLiquidity', () => { ) const lowerTickPrice = fastExponentiation(BigDecimal.fromString('1.0001'), MODIFY_LIQUIDITY_FIXTURE_ADD.tickLower) - assertObjectMatches('Tick', USDC_WETH_POOL_ID + '#' + MODIFY_LIQUIDITY_FIXTURE_ADD.tickLower.toString(), [ - ['tickIdx', MODIFY_LIQUIDITY_FIXTURE_ADD.tickLower.toString()], - ['pool', USDC_WETH_POOL_ID], - ['poolAddress', USDC_WETH_POOL_ID], - ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], - ['createdAtBlockNumber', MOCK_EVENT.block.number.toString()], - ['liquidityGross', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.toString()], - ['liquidityNet', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.toString()], - ['price0', lowerTickPrice.toString()], - ['price1', safeDiv(ONE_BD, lowerTickPrice).toString()], - ]) + assertObjectMatches( + 'Tick', + USDC_WETH_POOL_ID.toHexString() + '#' + MODIFY_LIQUIDITY_FIXTURE_ADD.tickLower.toString(), + [ + ['tickIdx', MODIFY_LIQUIDITY_FIXTURE_ADD.tickLower.toString()], + ['pool', USDC_WETH_POOL_ID.toHexString()], + ['poolAddress', USDC_WETH_POOL_ID.toHexString()], + ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], + ['createdAtBlockNumber', MOCK_EVENT.block.number.toString()], + ['liquidityGross', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.toString()], + ['liquidityNet', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.toString()], + ['price0', lowerTickPrice.toString()], + ['price1', safeDiv(ONE_BD, lowerTickPrice).toString()], + ], + ) const upperTickPrice = fastExponentiation(BigDecimal.fromString('1.0001'), MODIFY_LIQUIDITY_FIXTURE_ADD.tickUpper) - assertObjectMatches('Tick', USDC_WETH_POOL_ID + '#' + MODIFY_LIQUIDITY_FIXTURE_ADD.tickUpper.toString(), [ - ['tickIdx', MODIFY_LIQUIDITY_FIXTURE_ADD.tickUpper.toString()], - ['pool', USDC_WETH_POOL_ID], - ['poolAddress', USDC_WETH_POOL_ID], - ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], - ['createdAtBlockNumber', MOCK_EVENT.block.number.toString()], - ['liquidityGross', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.toString()], - ['liquidityNet', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.neg().toString()], - ['price0', upperTickPrice.toString()], - ['price1', safeDiv(ONE_BD, upperTickPrice).toString()], - ]) + assertObjectMatches( + 'Tick', + USDC_WETH_POOL_ID.toHexString() + '#' + MODIFY_LIQUIDITY_FIXTURE_ADD.tickUpper.toString(), + [ + ['tickIdx', MODIFY_LIQUIDITY_FIXTURE_ADD.tickUpper.toString()], + ['pool', USDC_WETH_POOL_ID.toHexString()], + ['poolAddress', USDC_WETH_POOL_ID.toHexString()], + ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], + ['createdAtBlockNumber', MOCK_EVENT.block.number.toString()], + ['liquidityGross', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.toString()], + ['liquidityNet', MODIFY_LIQUIDITY_FIXTURE_ADD.liquidityDelta.neg().toString()], + ['price0', upperTickPrice.toString()], + ['price1', safeDiv(ONE_BD, upperTickPrice).toString()], + ], + ) }) test('success - remove liquidity event, pool tick is between tickUpper and tickLower', () => { @@ -231,13 +237,13 @@ describe('handleModifyLiquidity', () => { .plus(amountToken1.times(TEST_WETH_DERIVED_ETH)) const poolTotalValueLockedUSD = poolTotalValueLockedETH.times(TEST_ETH_PRICE_USD) - assertObjectMatches('PoolManager', TEST_CONFIG.poolManagerAddress, [ + assertObjectMatches('PoolManager', TEST_CONFIG.poolManagerAddress.toHexString(), [ ['txCount', '1'], ['totalValueLockedETH', poolTotalValueLockedETH.toString()], ['totalValueLockedUSD', poolTotalValueLockedUSD.toString()], ]) - assertObjectMatches('Pool', USDC_WETH_POOL_ID, [ + assertObjectMatches('Pool', USDC_WETH_POOL_ID.toHexString(), [ ['txCount', '1'], ['liquidity', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.toString()], ['totalValueLockedToken0', amountToken0.toString()], @@ -246,13 +252,13 @@ describe('handleModifyLiquidity', () => { ['totalValueLockedUSD', poolTotalValueLockedUSD.toString()], ]) - assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address, [ + assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address.toHexString(), [ ['txCount', '1'], ['totalValueLocked', amountToken0.toString()], ['totalValueLockedUSD', amountToken0.times(TEST_USDC_DERIVED_ETH.times(TEST_ETH_PRICE_USD)).toString()], ]) - assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address, [ + assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address.toHexString(), [ ['txCount', '1'], ['totalValueLocked', amountToken1.toString()], ['totalValueLockedUSD', amountToken1.times(TEST_WETH_DERIVED_ETH.times(TEST_ETH_PRICE_USD)).toString()], @@ -263,9 +269,9 @@ describe('handleModifyLiquidity', () => { [ ['transaction', MOCK_EVENT.transaction.hash.toHexString()], ['timestamp', MOCK_EVENT.block.timestamp.toString()], - ['pool', USDC_WETH_POOL_ID], - ['token0', USDC_MAINNET_FIXTURE.address], - ['token1', WETH_MAINNET_FIXTURE.address], + ['pool', USDC_WETH_POOL_ID.toHexString()], + ['token0', USDC_MAINNET_FIXTURE.address.toHexString()], + ['token1', WETH_MAINNET_FIXTURE.address.toHexString()], ['sender', MODIFY_LIQUIDITY_FIXTURE_REMOVE.sender.toHexString()], ['origin', MOCK_EVENT.transaction.from.toHexString()], ['amount', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.toString()], @@ -282,33 +288,41 @@ describe('handleModifyLiquidity', () => { BigDecimal.fromString('1.0001'), MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickLower, ) - assertObjectMatches('Tick', USDC_WETH_POOL_ID + '#' + MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickLower.toString(), [ - ['tickIdx', MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickLower.toString()], - ['pool', USDC_WETH_POOL_ID], - ['poolAddress', USDC_WETH_POOL_ID], - ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], - ['createdAtBlockNumber', MOCK_EVENT.block.number.toString()], - ['liquidityGross', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.toString()], - ['liquidityNet', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.toString()], - ['price0', lowerTickPrice.toString()], - ['price1', safeDiv(ONE_BD, lowerTickPrice).toString()], - ]) + assertObjectMatches( + 'Tick', + USDC_WETH_POOL_ID.toHexString() + '#' + MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickLower.toString(), + [ + ['tickIdx', MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickLower.toString()], + ['pool', USDC_WETH_POOL_ID.toHexString()], + ['poolAddress', USDC_WETH_POOL_ID.toHexString()], + ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], + ['createdAtBlockNumber', MOCK_EVENT.block.number.toString()], + ['liquidityGross', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.toString()], + ['liquidityNet', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.toString()], + ['price0', lowerTickPrice.toString()], + ['price1', safeDiv(ONE_BD, lowerTickPrice).toString()], + ], + ) const upperTickPrice = fastExponentiation( BigDecimal.fromString('1.0001'), MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickUpper, ) - assertObjectMatches('Tick', USDC_WETH_POOL_ID + '#' + MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickUpper.toString(), [ - ['tickIdx', MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickUpper.toString()], - ['pool', USDC_WETH_POOL_ID], - ['poolAddress', USDC_WETH_POOL_ID], - ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], - ['createdAtBlockNumber', MOCK_EVENT.block.number.toString()], - ['liquidityGross', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.toString()], - ['liquidityNet', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.neg().toString()], - ['price0', upperTickPrice.toString()], - ['price1', safeDiv(ONE_BD, upperTickPrice).toString()], - ]) + assertObjectMatches( + 'Tick', + USDC_WETH_POOL_ID.toHexString() + '#' + MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickUpper.toString(), + [ + ['tickIdx', MODIFY_LIQUIDITY_FIXTURE_REMOVE.tickUpper.toString()], + ['pool', USDC_WETH_POOL_ID.toHexString()], + ['poolAddress', USDC_WETH_POOL_ID.toHexString()], + ['createdAtTimestamp', MOCK_EVENT.block.timestamp.toString()], + ['createdAtBlockNumber', MOCK_EVENT.block.number.toString()], + ['liquidityGross', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.toString()], + ['liquidityNet', MODIFY_LIQUIDITY_FIXTURE_REMOVE.liquidityDelta.neg().toString()], + ['price0', upperTickPrice.toString()], + ['price1', safeDiv(ONE_BD, upperTickPrice).toString()], + ], + ) }) test('success - add liquidity event, pool tick is not between tickUpper and tickLower', () => { @@ -321,7 +335,9 @@ describe('handleModifyLiquidity', () => { handleModifyLiquidityHelper(MODIFY_LIQUIDITY_EVENT_ADD, TEST_CONFIG) // liquidity should not be updated - assertObjectMatches('Pool', USDC_WETH_POOL_ID, [['liquidity', liquidityBeforeModifyLiquidity.toString()]]) + assertObjectMatches('Pool', USDC_WETH_POOL_ID.toHexString(), [ + ['liquidity', liquidityBeforeModifyLiquidity.toString()], + ]) }) test('success - amounts are correct for remove liquidity event with currentTick just under upper tick', () => { @@ -341,7 +357,7 @@ describe('handleModifyLiquidity', () => { MOCK_EVENT.block, MOCK_EVENT.transaction, [ - new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(id)), + new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(USDC_WETH_POOL_ID)), new ethereum.EventParam('sender', ethereum.Value.fromAddress(FIXTURE.sender)), new ethereum.EventParam('tickLower', ethereum.Value.fromI32(FIXTURE.tickLower)), new ethereum.EventParam('tickUpper', ethereum.Value.fromI32(FIXTURE.tickUpper)), diff --git a/tests/handlers/handleSwap.test.ts b/tests/handlers/handleSwap.test.ts index 7b14dc9..93211d8 100644 --- a/tests/handlers/handleSwap.test.ts +++ b/tests/handlers/handleSwap.test.ts @@ -27,7 +27,7 @@ import { } from './constants' class SwapFixture { - id: string + id: Bytes sender: Address amount0: BigInt amount1: BigInt @@ -57,7 +57,7 @@ const SWAP_EVENT = new Swap( MOCK_EVENT.block, MOCK_EVENT.transaction, [ - new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(Bytes.fromHexString(SWAP_FIXTURE.id))), + new ethereum.EventParam('id', ethereum.Value.fromFixedBytes(SWAP_FIXTURE.id)), new ethereum.EventParam('sender', ethereum.Value.fromAddress(SWAP_FIXTURE.sender)), new ethereum.EventParam('amount0', ethereum.Value.fromSignedBigInt(SWAP_FIXTURE.amount0)), new ethereum.EventParam('amount1', ethereum.Value.fromSignedBigInt(SWAP_FIXTURE.amount1)), @@ -73,7 +73,7 @@ describe('handleSwap', () => { beforeAll(() => { invokePoolCreatedWithMockedEthCalls(MOCK_EVENT, TEST_CONFIG) - const bundle = new Bundle('1') + const bundle = new Bundle(Bytes.fromI32(1)) bundle.ethPriceUSD = TEST_ETH_PRICE_USD bundle.save() @@ -146,7 +146,7 @@ describe('handleSwap', () => { const totalValueLockedETH = amount0.times(newToken0DerivedETH).plus(amount1.times(newToken1DerivedETH)) - assertObjectMatches('PoolManager', TEST_CONFIG.poolManagerAddress, [ + assertObjectMatches('PoolManager', TEST_CONFIG.poolManagerAddress.toHexString(), [ ['txCount', '1'], ['totalVolumeETH', amountTotalETHTRacked.toString()], ['totalVolumeUSD', amountTotalUSDTracked.toString()], @@ -157,7 +157,7 @@ describe('handleSwap', () => { ['totalValueLockedUSD', totalValueLockedETH.times(newEthPrice).toString()], ]) - assertObjectMatches('Pool', USDC_WETH_POOL_ID, [ + assertObjectMatches('Pool', USDC_WETH_POOL_ID.toHexString(), [ ['volumeToken0', amount0Abs.toString()], ['volumeToken1', amount1Abs.toString()], ['volumeUSD', amountTotalUSDTracked.toString()], @@ -175,7 +175,7 @@ describe('handleSwap', () => { ['totalValueLockedUSD', totalValueLockedETH.times(newEthPrice).toString()], ]) - assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address, [ + assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address.toHexString(), [ ['volume', amount0Abs.toString()], ['totalValueLocked', amount0.toString()], ['volumeUSD', amountTotalUSDTracked.toString()], @@ -183,10 +183,16 @@ describe('handleSwap', () => { ['feesUSD', feesUSD.toString()], ['txCount', '1'], ['derivedETH', newToken0DerivedETH.toString()], - ['totalValueLockedUSD', amount0.times(newToken0DerivedETH).times(newEthPrice).toString()], + [ + 'totalValueLockedUSD', + amount0 + .times(newToken0DerivedETH) + .times(newEthPrice) + .toString(), + ], ]) - assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address, [ + assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address.toHexString(), [ ['volume', amount1Abs.toString()], ['totalValueLocked', amount1.toString()], ['volumeUSD', amountTotalUSDTracked.toString()], @@ -194,15 +200,21 @@ describe('handleSwap', () => { ['feesUSD', feesUSD.toString()], ['txCount', '1'], ['derivedETH', newToken1DerivedETH.toString()], - ['totalValueLockedUSD', amount1.times(newToken1DerivedETH).times(newEthPrice).toString()], + [ + 'totalValueLockedUSD', + amount1 + .times(newToken1DerivedETH) + .times(newEthPrice) + .toString(), + ], ]) assertObjectMatches('Swap', MOCK_EVENT.transaction.hash.toHexString() + '-' + MOCK_EVENT.logIndex.toString(), [ ['transaction', MOCK_EVENT.transaction.hash.toHexString()], ['timestamp', MOCK_EVENT.block.timestamp.toString()], - ['pool', USDC_WETH_POOL_ID], - ['token0', USDC_MAINNET_FIXTURE.address], - ['token1', WETH_MAINNET_FIXTURE.address], + ['pool', USDC_WETH_POOL_ID.toHexString()], + ['token0', USDC_MAINNET_FIXTURE.address.toHexString()], + ['token1', WETH_MAINNET_FIXTURE.address.toHexString()], ['sender', SWAP_FIXTURE.sender.toHexString()], ['origin', MOCK_EVENT.transaction.from.toHexString()], // ['recipient', SWAP_FIXTURE.recipient.toHexString()], @@ -223,42 +235,42 @@ describe('handleSwap', () => { ['feesUSD', feesUSD.toString()], ]) - assertObjectMatches('PoolDayData', USDC_WETH_POOL_ID + '-' + dayId.toString(), [ + assertObjectMatches('PoolDayData', USDC_WETH_POOL_ID.toHexString() + '-' + dayId.toString(), [ ['volumeUSD', amountTotalUSDTracked.toString()], ['volumeToken0', amount0Abs.toString()], ['volumeToken1', amount1Abs.toString()], ['feesUSD', feesUSD.toString()], ]) - assertObjectMatches('PoolHourData', USDC_WETH_POOL_ID + '-' + hourId.toString(), [ + assertObjectMatches('PoolHourData', USDC_WETH_POOL_ID.toHexString() + '-' + hourId.toString(), [ ['volumeUSD', amountTotalUSDTracked.toString()], ['volumeToken0', amount0Abs.toString()], ['volumeToken1', amount1Abs.toString()], ['feesUSD', feesUSD.toString()], ]) - assertObjectMatches('TokenDayData', USDC_MAINNET_FIXTURE.address + '-' + dayId.toString(), [ + assertObjectMatches('TokenDayData', USDC_MAINNET_FIXTURE.address.toHexString() + '-' + dayId.toString(), [ ['volume', amount0Abs.toString()], ['volumeUSD', amountTotalUSDTracked.toString()], ['untrackedVolumeUSD', amountTotalUSDTracked.toString()], ['feesUSD', feesUSD.toString()], ]) - assertObjectMatches('TokenDayData', WETH_MAINNET_FIXTURE.address + '-' + dayId.toString(), [ + assertObjectMatches('TokenDayData', WETH_MAINNET_FIXTURE.address.toHexString() + '-' + dayId.toString(), [ ['volume', amount1Abs.toString()], ['volumeUSD', amountTotalUSDTracked.toString()], ['untrackedVolumeUSD', amountTotalUSDTracked.toString()], ['feesUSD', feesUSD.toString()], ]) - assertObjectMatches('TokenHourData', USDC_MAINNET_FIXTURE.address + '-' + hourId.toString(), [ + assertObjectMatches('TokenHourData', USDC_MAINNET_FIXTURE.address.toHexString() + '-' + hourId.toString(), [ ['volume', amount0Abs.toString()], ['volumeUSD', amountTotalUSDTracked.toString()], ['untrackedVolumeUSD', amountTotalUSDTracked.toString()], ['feesUSD', feesUSD.toString()], ]) - assertObjectMatches('TokenHourData', WETH_MAINNET_FIXTURE.address + '-' + hourId.toString(), [ + assertObjectMatches('TokenHourData', WETH_MAINNET_FIXTURE.address.toHexString() + '-' + hourId.toString(), [ ['volume', amount1Abs.toString()], ['volumeUSD', amountTotalUSDTracked.toString()], ['untrackedVolumeUSD', amountTotalUSDTracked.toString()], diff --git a/tests/handlers/handleTransfer.test.ts b/tests/handlers/handleTransfer.test.ts index cf56d1f..21462b1 100644 --- a/tests/handlers/handleTransfer.test.ts +++ b/tests/handlers/handleTransfer.test.ts @@ -47,8 +47,8 @@ describe('handleTransfer', () => { test('success - updates position owner', () => { const position = new Position(POSITION_FIXTURE.id) position.tokenId = POSITION_FIXTURE.tokenId - position.owner = POSITION_FIXTURE.owner.toHexString() - position.origin = POSITION_FIXTURE.origin.toHexString() + position.owner = POSITION_FIXTURE.owner + position.origin = POSITION_FIXTURE.origin position.createdAtTimestamp = MOCK_EVENT.block.timestamp position.save()