From 493371dcb4f52d2f0f4ff326ca142d5700dcd3aa Mon Sep 17 00:00:00 2001 From: Michael Wang <44713145+mzywang@users.noreply.github.com> Date: Fri, 31 May 2024 14:56:58 -0400 Subject: [PATCH] refactor subgraph to support multiple chains --- networks.json | 26 +++++ schema.graphql | 4 +- src/mappings/factory.ts | 30 ++--- src/mappings/pool/burn.ts | 9 +- src/mappings/pool/collect.ts | 16 +-- src/mappings/pool/initialize.ts | 44 ++++---- src/mappings/pool/mint.ts | 9 +- src/mappings/pool/swap.ts | 51 +++++---- src/utils/chains.ts | 187 ++++++++++++++++++++++++++++++++ src/utils/constants.ts | 7 +- src/utils/intervalUpdates.ts | 3 +- src/utils/pricing.ts | 20 ++-- src/utils/token.ts | 55 ++++------ subgraph.yaml | 14 ++- tests/constants.ts | 65 +++++++++-- tests/handleBurn.test.ts | 21 +--- tests/handleCollect.test.ts | 21 ++-- tests/handleInitialize.test.ts | 76 +++++++------ tests/handleMint.test.ts | 21 +--- tests/handlePoolCreated.test.ts | 33 ++---- tests/handleSwap.test.ts | 66 ++++++----- tests/intervalUpdates.test.ts | 11 +- 22 files changed, 513 insertions(+), 276 deletions(-) create mode 100644 networks.json create mode 100644 src/utils/chains.ts diff --git a/networks.json b/networks.json new file mode 100644 index 00000000..d49b4a10 --- /dev/null +++ b/networks.json @@ -0,0 +1,26 @@ +{ + "mainnet": { + "Factory": { + "address": "0x1F98431c8aD98523631AE4a59f267346ea31F984", + "startBlock": 12369621 + } + }, + "bsc": { + "Factory": { + "address": "0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7", + "startBlock": 12369621 + } + }, + "base": { + "Factory": { + "address": "0x33128a8fC17869897dcE68Ed026d694621f6FDfD", + "startBlock": 2009445 + } + }, + "arbitrum-one": { + "Factory": { + "address": "0x1F98431c8aD98523631AE4a59f267346ea31F984", + "startBlock": 165 + } + } +} diff --git a/schema.graphql b/schema.graphql index 5af3066e..19fb45c8 100644 --- a/schema.graphql +++ b/schema.graphql @@ -64,7 +64,9 @@ type Token @entity { totalValueLockedUSD: BigDecimal! # TVL derived in USD untracked totalValueLockedUSDUntracked: BigDecimal! - # derived price in ETH + # NOTE: for chains where ETH is not the native token, this will be the derived + # price of that chain's native token, effectively, this should be renamed + # derivedNative derivedETH: BigDecimal! # pools token is in that are white listed for USD pricing whitelistPools: [Pool!]! diff --git a/src/mappings/factory.ts b/src/mappings/factory.ts index ab2cc02c..86ae0e0b 100644 --- a/src/mappings/factory.ts +++ b/src/mappings/factory.ts @@ -1,13 +1,12 @@ -import { Address, BigInt, log } from '@graphprotocol/graph-ts' +import { BigInt, log } from '@graphprotocol/graph-ts' import { PoolCreated } from '../types/Factory/Factory' import { Factory } from '../types/schema' import { Bundle, Pool, Token } from '../types/schema' import { Pool as PoolTemplate } from '../types/templates' -import { STATIC_TOKEN_DEFINITIONS, StaticTokenDefinition } from '../utils/staticTokenDefinition' +import { getSubgraphConfig, SubgraphConfig } from '../utils/chains' import { fetchTokenDecimals, fetchTokenName, fetchTokenSymbol, fetchTokenTotalSupply } from '../utils/token' -import { ADDRESS_ZERO, FACTORY_ADDRESS, ONE_BI, ZERO_BD, ZERO_BI } from './../utils/constants' -import { WHITELIST_TOKENS } from './../utils/pricing' +import { ADDRESS_ZERO, ONE_BI, ZERO_BD, ZERO_BI } from './../utils/constants' // The subgraph handler must have this signature to be able to handle events, // however, we invoke a helper in order to inject dependencies for unit tests. @@ -18,12 +17,15 @@ export function handlePoolCreated(event: PoolCreated): void { // Exported for unit tests export function handlePoolCreatedHelper( event: PoolCreated, - factoryAddress: string = FACTORY_ADDRESS, - whitelistTokens: string[] = WHITELIST_TOKENS, - staticTokenDefinitions: StaticTokenDefinition[] = STATIC_TOKEN_DEFINITIONS, + subgraphConfig: SubgraphConfig = getSubgraphConfig(), ): void { + const factoryAddress = subgraphConfig.factoryAddress + const whitelistTokens = subgraphConfig.whitelistTokens + const tokenOverrides = subgraphConfig.tokenOverrides + const poolsToSkip = subgraphConfig.poolsToSkip + // temp fix - if (event.params.pool == Address.fromHexString('0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248')) { + if (poolsToSkip.includes(event.params.pool.toHexString())) { return } @@ -59,10 +61,10 @@ export function handlePoolCreatedHelper( // fetch info if null if (token0 === null) { token0 = new Token(event.params.token0.toHexString()) - token0.symbol = fetchTokenSymbol(event.params.token0, staticTokenDefinitions) - token0.name = fetchTokenName(event.params.token0, staticTokenDefinitions) + token0.symbol = fetchTokenSymbol(event.params.token0, tokenOverrides) + token0.name = fetchTokenName(event.params.token0, tokenOverrides) token0.totalSupply = fetchTokenTotalSupply(event.params.token0) - const decimals = fetchTokenDecimals(event.params.token0, staticTokenDefinitions) + const decimals = fetchTokenDecimals(event.params.token0, tokenOverrides) // bail if we couldn't figure out the decimals if (decimals === null) { @@ -86,10 +88,10 @@ export function handlePoolCreatedHelper( if (token1 === null) { token1 = new Token(event.params.token1.toHexString()) - token1.symbol = fetchTokenSymbol(event.params.token1) - token1.name = fetchTokenName(event.params.token1) + token1.symbol = fetchTokenSymbol(event.params.token1, tokenOverrides) + token1.name = fetchTokenName(event.params.token1, tokenOverrides) token1.totalSupply = fetchTokenTotalSupply(event.params.token1) - const decimals = fetchTokenDecimals(event.params.token1) + const decimals = fetchTokenDecimals(event.params.token1, tokenOverrides) // bail if we couldn't figure out the decimals if (decimals === null) { log.debug('mybug the decimal on token 0 was null', []) diff --git a/src/mappings/pool/burn.ts b/src/mappings/pool/burn.ts index 3f924c6c..58ca1cbc 100644 --- a/src/mappings/pool/burn.ts +++ b/src/mappings/pool/burn.ts @@ -3,7 +3,8 @@ import { BigInt } from '@graphprotocol/graph-ts' import { Bundle, Burn, Factory, Pool, Tick, Token } from '../../types/schema' import { Burn as BurnEvent } from '../../types/templates/Pool/Pool' import { convertTokenToDecimal, loadTransaction } from '../../utils' -import { FACTORY_ADDRESS, ONE_BI } from '../../utils/constants' +import { getSubgraphConfig, SubgraphConfig } from '../../utils/chains' +import { ONE_BI } from '../../utils/constants' import { updatePoolDayData, updatePoolHourData, @@ -17,7 +18,9 @@ export function handleBurn(event: BurnEvent): void { } // Note: this handler need not adjust TVL because that is accounted for in the handleCollect handler -export function handleBurnHelper(event: BurnEvent, factoryAddress: string = FACTORY_ADDRESS): void { +export function handleBurnHelper(event: BurnEvent, subgraphConfig: SubgraphConfig = getSubgraphConfig()): void { + const factoryAddress = subgraphConfig.factoryAddress + const bundle = Bundle.load('1')! const poolAddress = event.address.toHexString() const pool = Pool.load(poolAddress)! @@ -91,7 +94,7 @@ export function handleBurnHelper(event: BurnEvent, factoryAddress: string = FACT lowerTick.save() upperTick.save() } - updateUniswapDayData(event) + updateUniswapDayData(event, factoryAddress) updatePoolDayData(event) updatePoolHourData(event) updateTokenDayData(token0 as Token, event) diff --git a/src/mappings/pool/collect.ts b/src/mappings/pool/collect.ts index 6cbf87a4..89417947 100644 --- a/src/mappings/pool/collect.ts +++ b/src/mappings/pool/collect.ts @@ -3,7 +3,8 @@ import { BigInt } from '@graphprotocol/graph-ts' import { Bundle, Collect, Factory, Pool, Token } from '../../types/schema' import { Collect as CollectEvent } from '../../types/templates/Pool/Pool' import { convertTokenToDecimal, loadTransaction } from '../../utils' -import { FACTORY_ADDRESS, ONE_BI } from '../../utils/constants' +import { getSubgraphConfig, SubgraphConfig } from '../../utils/chains' +import { ONE_BI } from '../../utils/constants' import { updatePoolDayData, updatePoolHourData, @@ -11,17 +12,16 @@ import { updateTokenHourData, updateUniswapDayData, } from '../../utils/intervalUpdates' -import { getTrackedAmountUSD, WHITELIST_TOKENS } from '../../utils/pricing' +import { getTrackedAmountUSD } from '../../utils/pricing' export function handleCollect(event: CollectEvent): void { handleCollectHelper(event) } -export function handleCollectHelper( - event: CollectEvent, - factoryAddress: string = FACTORY_ADDRESS, - whitelistTokens: string[] = WHITELIST_TOKENS, -): void { +export function handleCollectHelper(event: CollectEvent, subgraphConfig: SubgraphConfig = getSubgraphConfig()): void { + const factoryAddress = subgraphConfig.factoryAddress + const whitelistTokens = subgraphConfig.whitelistTokens + const bundle = Bundle.load('1')! const pool = Pool.load(event.address.toHexString()) if (pool == null) { @@ -92,7 +92,7 @@ export function handleCollectHelper( collect.tickUpper = BigInt.fromI32(event.params.tickUpper) collect.logIndex = event.logIndex - updateUniswapDayData(event) + updateUniswapDayData(event, factoryAddress) updatePoolDayData(event) updatePoolHourData(event) updateTokenDayData(token0 as Token, event) diff --git a/src/mappings/pool/initialize.ts b/src/mappings/pool/initialize.ts index 3e7c56a0..01cbd1a0 100644 --- a/src/mappings/pool/initialize.ts +++ b/src/mappings/pool/initialize.ts @@ -1,30 +1,22 @@ -import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' +import { BigInt } from '@graphprotocol/graph-ts' import { Bundle, Pool, Token } from '../../types/schema' import { Initialize } from '../../types/templates/Pool/Pool' +import { getSubgraphConfig, SubgraphConfig } from '../../utils/chains' import { updatePoolDayData, updatePoolHourData } from '../../utils/intervalUpdates' -import { - findEthPerToken, - getEthPriceInUSD, - MINIMUM_ETH_LOCKED, - STABLE_COINS, - STABLECOIN_IS_TOKEN0, - USDC_WETH_03_POOL, - WETH_ADDRESS, -} from '../../utils/pricing' +import { findNativePerToken, getNativePriceInUSD } from '../../utils/pricing' export function handleInitialize(event: Initialize): void { handleInitializeHelper(event) } -export function handleInitializeHelper( - event: Initialize, - stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL, - stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, - wrappedNativeAddress: string = WETH_ADDRESS, - stablecoinAddresses: string[] = STABLE_COINS, - minimumEthLocked: BigDecimal = MINIMUM_ETH_LOCKED, -): void { +export function handleInitializeHelper(event: Initialize, subgraphConfig: SubgraphConfig = getSubgraphConfig()): void { + const stablecoinWrappedNativePoolAddress = subgraphConfig.stablecoinWrappedNativePoolAddress + const stablecoinIsToken0 = subgraphConfig.stablecoinIsToken0 + const wrappedNativeAddress = subgraphConfig.wrappedNativeAddress + const stablecoinAddresses = subgraphConfig.stablecoinAddresses + const minimumNativeLocked = subgraphConfig.minimumNativeLocked + // update pool sqrt price and tick const pool = Pool.load(event.address.toHexString())! pool.sqrtPrice = event.params.sqrtPriceX96 @@ -37,7 +29,7 @@ export function handleInitializeHelper( // update ETH price now that prices could have changed const bundle = Bundle.load('1')! - bundle.ethPriceUSD = getEthPriceInUSD(stablecoinWrappedNativePoolAddress, stablecoinIsToken0) + bundle.ethPriceUSD = getNativePriceInUSD(stablecoinWrappedNativePoolAddress, stablecoinIsToken0) bundle.save() updatePoolDayData(event) @@ -45,8 +37,18 @@ export function handleInitializeHelper( // update token prices if (token0 && token1) { - token0.derivedETH = findEthPerToken(token0 as Token, wrappedNativeAddress, stablecoinAddresses, minimumEthLocked) - token1.derivedETH = findEthPerToken(token1 as Token, wrappedNativeAddress, stablecoinAddresses, minimumEthLocked) + token0.derivedETH = findNativePerToken( + token0 as Token, + wrappedNativeAddress, + stablecoinAddresses, + minimumNativeLocked, + ) + token1.derivedETH = findNativePerToken( + token1 as Token, + wrappedNativeAddress, + stablecoinAddresses, + minimumNativeLocked, + ) token0.save() token1.save() } diff --git a/src/mappings/pool/mint.ts b/src/mappings/pool/mint.ts index a71dcf24..d3598368 100644 --- a/src/mappings/pool/mint.ts +++ b/src/mappings/pool/mint.ts @@ -3,7 +3,8 @@ import { BigInt } from '@graphprotocol/graph-ts' import { Bundle, Factory, Mint, Pool, Tick, Token } from '../../types/schema' import { Mint as MintEvent } from '../../types/templates/Pool/Pool' import { convertTokenToDecimal, loadTransaction } from '../../utils' -import { FACTORY_ADDRESS, ONE_BI } from '../../utils/constants' +import { getSubgraphConfig, SubgraphConfig } from '../../utils/chains' +import { ONE_BI } from '../../utils/constants' import { updatePoolDayData, updatePoolHourData, @@ -17,7 +18,9 @@ export function handleMint(event: MintEvent): void { handleMintHelper(event) } -export function handleMintHelper(event: MintEvent, factoryAddress: string = FACTORY_ADDRESS): void { +export function handleMintHelper(event: MintEvent, subgraphConfig: SubgraphConfig = getSubgraphConfig()): void { + const factoryAddress = subgraphConfig.factoryAddress + const bundle = Bundle.load('1')! const poolAddress = event.address.toHexString() const pool = Pool.load(poolAddress)! @@ -122,7 +125,7 @@ export function handleMintHelper(event: MintEvent, factoryAddress: string = FACT // TODO: Update Tick's volume, fees, and liquidity provider count. Computing these on the tick // level requires reimplementing some of the swapping code from v3-core. - updateUniswapDayData(event) + updateUniswapDayData(event, factoryAddress) updatePoolDayData(event) updatePoolHourData(event) updateTokenDayData(token0 as Token, event) diff --git a/src/mappings/pool/swap.ts b/src/mappings/pool/swap.ts index 45458c2d..3bf27c74 100644 --- a/src/mappings/pool/swap.ts +++ b/src/mappings/pool/swap.ts @@ -3,7 +3,8 @@ import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' import { Bundle, Factory, Pool, Swap, Token } from '../../types/schema' import { Swap as SwapEvent } from '../../types/templates/Pool/Pool' import { convertTokenToDecimal, loadTransaction, safeDiv } from '../../utils' -import { FACTORY_ADDRESS, ONE_BI, ZERO_BD } from '../../utils/constants' +import { getSubgraphConfig, SubgraphConfig } from '../../utils/chains' +import { ONE_BI, ZERO_BD } from '../../utils/constants' import { updatePoolDayData, updatePoolHourData, @@ -12,33 +13,27 @@ import { updateUniswapDayData, } from '../../utils/intervalUpdates' import { - findEthPerToken, - getEthPriceInUSD, + findNativePerToken, + getNativePriceInUSD, getTrackedAmountUSD, - MINIMUM_ETH_LOCKED, sqrtPriceX96ToTokenPrices, - STABLE_COINS, - STABLECOIN_IS_TOKEN0, - USDC_WETH_03_POOL, - WETH_ADDRESS, - WHITELIST_TOKENS, } from '../../utils/pricing' export function handleSwap(event: SwapEvent): void { handleSwapHelper(event) } -export function handleSwapHelper( - event: SwapEvent, - stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL, - stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, - wrappedNativeAddress: string = WETH_ADDRESS, - stablecoinAddresses: string[] = STABLE_COINS, - minimumEthLocked: BigDecimal = MINIMUM_ETH_LOCKED, - whitelistTokens: string[] = WHITELIST_TOKENS, -): void { +export function handleSwapHelper(event: SwapEvent, subgraphConfig: SubgraphConfig = getSubgraphConfig()): void { + const factoryAddress = subgraphConfig.factoryAddress + const stablecoinWrappedNativePoolAddress = subgraphConfig.stablecoinWrappedNativePoolAddress + const stablecoinIsToken0 = subgraphConfig.stablecoinIsToken0 + const wrappedNativeAddress = subgraphConfig.wrappedNativeAddress + const stablecoinAddresses = subgraphConfig.stablecoinAddresses + const minimumNativeLocked = subgraphConfig.minimumNativeLocked + const whitelistTokens = subgraphConfig.whitelistTokens + const bundle = Bundle.load('1')! - const factory = Factory.load(FACTORY_ADDRESS)! + const factory = Factory.load(factoryAddress)! const pool = Pool.load(event.address.toHexString())! // hot fix for bad pricing @@ -133,10 +128,20 @@ export function handleSwapHelper( pool.save() // update USD pricing - bundle.ethPriceUSD = getEthPriceInUSD(stablecoinWrappedNativePoolAddress, stablecoinIsToken0) + bundle.ethPriceUSD = getNativePriceInUSD(stablecoinWrappedNativePoolAddress, stablecoinIsToken0) bundle.save() - token0.derivedETH = findEthPerToken(token0 as Token, wrappedNativeAddress, stablecoinAddresses, minimumEthLocked) - token1.derivedETH = findEthPerToken(token1 as Token, wrappedNativeAddress, stablecoinAddresses, minimumEthLocked) + token0.derivedETH = findNativePerToken( + token0 as Token, + wrappedNativeAddress, + stablecoinAddresses, + minimumNativeLocked, + ) + token1.derivedETH = findNativePerToken( + token1 as Token, + wrappedNativeAddress, + stablecoinAddresses, + minimumNativeLocked, + ) /** * Things afffected by new USD rates @@ -171,7 +176,7 @@ export function handleSwapHelper( swap.logIndex = event.logIndex // interval data - const uniswapDayData = updateUniswapDayData(event) + const uniswapDayData = updateUniswapDayData(event, factoryAddress) const poolDayData = updatePoolDayData(event) const poolHourData = updatePoolHourData(event) const token0DayData = updateTokenDayData(token0 as Token, event) diff --git a/src/utils/chains.ts b/src/utils/chains.ts new file mode 100644 index 00000000..41043da3 --- /dev/null +++ b/src/utils/chains.ts @@ -0,0 +1,187 @@ +import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts' + +import { StaticTokenDefinition } from './staticTokenDefinition' + +export enum ChainId { + MAINNET = 1, + OPTIMISM = 10, + BNB = 56, + POLYGON = 137, + BASE = 8453, + ARBITRUM = 42161, + CELO = 42220, + AVALANCHE = 43114, + BLAST = 81457, +} + +// Note: All token and pool addresses should be lowercased! +export class SubgraphConfig { + factoryAddress: string + stablecoinWrappedNativePoolAddress: string + stablecoinIsToken0: boolean // true is stablecoin is token0, false if stablecoin is token1 + wrappedNativeAddress: string + minimumNativeLocked: BigDecimal + poolsToSkip: string[] + stablecoinAddresses: string[] + whitelistTokens: string[] + tokenOverrides: StaticTokenDefinition[] +} + +export function getSubgraphConfig(): SubgraphConfig { + // Update this value to the corresponding chain you want to deploy + const SELECTED_CHAIN = ChainId.BASE + + switch (SELECTED_CHAIN) { + case ChainId.MAINNET: + return { + factoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984', + stablecoinWrappedNativePoolAddress: '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8', // USDC-WETH 0.3% pool + stablecoinIsToken0: true, + wrappedNativeAddress: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', // WETH + minimumNativeLocked: BigDecimal.fromString('20'), + poolsToSkip: ['0x8fe8d9bb8eeba3ed688069c3d6b556c9ca258248'], + stablecoinAddresses: [ + '0x6b175474e89094c44da98b954eedeac495271d0f', + '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', + '0xdac17f958d2ee523a2206206994597c13d831ec7', + '0x0000000000085d4780b73119b644ae5ecd22b376', + '0x956f47f50a910163d8bf957cf5846d573e7f87ca', + '0x4dd28568d05f09b02220b09c2cb307bfd837cb95', + ], + 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 + ], + tokenOverrides: [ + { + address: Address.fromString('0xe0b7927c4af23765cb51314a0e0521a9645f0e2a'), + symbol: 'DGD', + name: 'DGD', + decimals: BigInt.fromI32(9), + }, + { + address: Address.fromString('0x7fc66500c84a76ad7e9c93437bfc5ac33e2ddae9'), + symbol: 'AAVE', + name: 'Aave Token', + decimals: BigInt.fromI32(18), + }, + { + address: Address.fromString('0xeb9951021698b42e4399f9cbb6267aa35f82d59d'), + symbol: 'LIF', + name: 'Lif', + decimals: BigInt.fromI32(18), + }, + { + address: Address.fromString('0xbdeb4b83251fb146687fa19d1c660f99411eefe3'), + symbol: 'SVD', + name: 'savedroid', + decimals: BigInt.fromI32(18), + }, + { + address: Address.fromString('0xbb9bc244d798123fde783fcc1c72d3bb8c189413'), + symbol: 'TheDAO', + name: 'TheDAO', + decimals: BigInt.fromI32(16), + }, + { + address: Address.fromString('0x38c6a68304cdefb9bec48bbfaaba5c5b47818bb2'), + symbol: 'HPB', + name: 'HPBCoin', + decimals: BigInt.fromI32(18), + }, + ], + } + case ChainId.BNB: { + return { + factoryAddress: '0xdB1d10011AD0Ff90774D0C6Bb92e5C5c8b4461F7', + stablecoinWrappedNativePoolAddress: '0x6fe9e9de56356f7edbfcbb29fab7cd69471a4869', // USDC-WBNB 0.3% pool + stablecoinIsToken0: true, + wrappedNativeAddress: '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', // WBNB + minimumNativeLocked: BigDecimal.fromString('100'), + poolsToSkip: [], + stablecoinAddresses: [ + '0x55d398326f99059ff775485246999027b3197955', // USDT + '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', // USDC + ], + whitelistTokens: [ + '0xbb4cdb9cbd36b01bd1cbaebf2de08d9173bc095c', // WBNB + '0x55d398326f99059ff775485246999027b3197955', // USDT + '0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d', // USDC + ], + tokenOverrides: [], + } + } + case ChainId.BASE: + return { + factoryAddress: '0x33128a8fC17869897dcE68Ed026d694621f6FDfD', + stablecoinWrappedNativePoolAddress: '0x4c36388be6f416a29c8d8eee81c771ce6be14b18', // WETH-USDbC 0.05% pool + stablecoinIsToken0: false, + wrappedNativeAddress: '0x4200000000000000000000000000000000000006', // WETH + minimumNativeLocked: BigDecimal.fromString('1'), + poolsToSkip: [], + stablecoinAddresses: [ + '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC + ], + whitelistTokens: [ + '0x4200000000000000000000000000000000000006', // WETH + '0x833589fcd6edb6e08f4c7c32d4f71b54bda02913', // USDC + ], + tokenOverrides: [], + } + case ChainId.ARBITRUM: + return { + factoryAddress: '0x1F98431c8aD98523631AE4a59f267346ea31F984', + stablecoinWrappedNativePoolAddress: '0x17c14d2c404d167802b16c450d3c99f88f2c4f4d', // WETH-USDC 0.3% pool + stablecoinIsToken0: false, + wrappedNativeAddress: '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', // WETH + minimumNativeLocked: BigDecimal.fromString('20'), + poolsToSkip: [], + stablecoinAddresses: [ + '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC + '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', // DAI + '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', // USDT + ], + whitelistTokens: [ + '0x82af49447d8a07e3bd95bd0d56f35241523fbab1', // WETH + '0xff970a61a04b1ca14834a43f5de4533ebddb5cc8', // USDC + '0xda10009cbd5d07dd0cecc66161fc93d7c9000da1', // DAI + '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9', // USDT + ], + tokenOverrides: [ + { + address: Address.fromString('0x82af49447d8a07e3bd95bd0d56f35241523fbab1'), + symbol: 'WETH', + name: 'Wrapped Ethereum', + decimals: BigInt.fromI32(18), + }, + { + address: Address.fromString('0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'), + symbol: 'USDC', + name: 'USD Coin', + decimals: BigInt.fromI32(6), + }, + ], + } + default: + throw new Error('Unsupported chain ID') + } +} diff --git a/src/utils/constants.ts b/src/utils/constants.ts index 6c578871..a087af78 100644 --- a/src/utils/constants.ts +++ b/src/utils/constants.ts @@ -1,14 +1,9 @@ -import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts' - -import { Factory as FactoryContract } from '../types/templates/Pool/Factory' +import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' export const ADDRESS_ZERO = '0x0000000000000000000000000000000000000000' -export const FACTORY_ADDRESS = '0x1F98431c8aD98523631AE4a59f267346ea31F984' export const ZERO_BI = BigInt.fromI32(0) export const ONE_BI = BigInt.fromI32(1) export const ZERO_BD = BigDecimal.fromString('0') export const ONE_BD = BigDecimal.fromString('1') export const BI_18 = BigInt.fromI32(18) - -export const factoryContract = FactoryContract.bind(Address.fromString(FACTORY_ADDRESS)) diff --git a/src/utils/intervalUpdates.ts b/src/utils/intervalUpdates.ts index 2d2232b0..ccbb2f71 100644 --- a/src/utils/intervalUpdates.ts +++ b/src/utils/intervalUpdates.ts @@ -12,13 +12,12 @@ import { UniswapDayData, } from './../types/schema' import { ONE_BI, ZERO_BD, ZERO_BI } from './constants' -import { FACTORY_ADDRESS } from './constants' /** * Tracks global aggregate data over daily windows * @param event */ -export function updateUniswapDayData(event: ethereum.Event, factoryAddress: string = FACTORY_ADDRESS): UniswapDayData { +export function updateUniswapDayData(event: ethereum.Event, factoryAddress: string): UniswapDayData { const uniswap = Factory.load(factoryAddress)! const timestamp = event.block.timestamp.toI32() const dayID = timestamp / 86400 // rounded diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index 6b834ff2..c5a9031c 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -55,9 +55,9 @@ export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, t return [price0, price1] } -export function getEthPriceInUSD( - stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL, - stablecoinIsToken0: boolean = STABLECOIN_IS_TOKEN0, // true is stablecoin is token0, false if stablecoin is token1 +export function getNativePriceInUSD( + stablecoinWrappedNativePoolAddress: string, + stablecoinIsToken0: boolean, ): BigDecimal { const stablecoinWrappedNativePool = Pool.load(stablecoinWrappedNativePoolAddress) if (stablecoinWrappedNativePool !== null) { @@ -71,11 +71,11 @@ export function getEthPriceInUSD( * Search through graph to find derived Eth per token. * @todo update to be derived ETH (add stablecoin estimates) **/ -export function findEthPerToken( +export function findNativePerToken( token: Token, - wrappedNativeAddress: string = WETH_ADDRESS, - stablecoinAddresses: string[] = STABLE_COINS, - minimumEthLocked: BigDecimal = MINIMUM_ETH_LOCKED, + wrappedNativeAddress: string, + stablecoinAddresses: string[], + minimumNativeLocked: BigDecimal, ): BigDecimal { if (token.id == wrappedNativeAddress) { return ONE_BD @@ -104,7 +104,7 @@ export function findEthPerToken( // get the derived ETH in pool if (token1) { const ethLocked = pool.totalValueLockedToken1.times(token1.derivedETH) - if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(minimumEthLocked)) { + if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(minimumNativeLocked)) { largestLiquidityETH = ethLocked // token1 per our token * Eth per token1 priceSoFar = pool.token1Price.times(token1.derivedETH as BigDecimal) @@ -116,7 +116,7 @@ export function findEthPerToken( // get the derived ETH in pool if (token0) { const ethLocked = pool.totalValueLockedToken0.times(token0.derivedETH) - if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(minimumEthLocked)) { + if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(minimumNativeLocked)) { largestLiquidityETH = ethLocked // token0 per our token * ETH per token0 priceSoFar = pool.token0Price.times(token0.derivedETH as BigDecimal) @@ -141,7 +141,7 @@ export function getTrackedAmountUSD( token0: Token, tokenAmount1: BigDecimal, token1: Token, - whitelistTokens: string[] = WHITELIST_TOKENS, + whitelistTokens: string[], ): BigDecimal { const bundle = Bundle.load('1')! const price0USD = token0.derivedETH.times(bundle.ethPriceUSD) diff --git a/src/utils/token.ts b/src/utils/token.ts index 1aca8117..5689bd22 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -4,12 +4,15 @@ import { ERC20 } from '../types/Factory/ERC20' import { ERC20NameBytes } from '../types/Factory/ERC20NameBytes' import { ERC20SymbolBytes } from '../types/Factory/ERC20SymbolBytes' import { isNullEthValue } from '.' -import { getStaticDefinition, STATIC_TOKEN_DEFINITIONS, StaticTokenDefinition } from './staticTokenDefinition' +import { getStaticDefinition, StaticTokenDefinition } from './staticTokenDefinition' + +export function fetchTokenSymbol(tokenAddress: Address, tokenOverrides: StaticTokenDefinition[]): string { + // try with the static definition + const staticTokenDefinition = getStaticDefinition(tokenAddress, tokenOverrides) + if (staticTokenDefinition != null) { + return staticTokenDefinition.symbol + } -export function fetchTokenSymbol( - tokenAddress: Address, - staticTokenDefinitions: StaticTokenDefinition[] = STATIC_TOKEN_DEFINITIONS, -): string { const contract = ERC20.bind(tokenAddress) const contractSymbolBytes = ERC20SymbolBytes.bind(tokenAddress) @@ -18,16 +21,10 @@ export function fetchTokenSymbol( const symbolResult = contract.try_symbol() if (symbolResult.reverted) { const symbolResultBytes = contractSymbolBytes.try_symbol() - if (!symbolResultBytes.reverted) { + if (!symbolResultBytes.reverted && !isNullEthValue(symbolResultBytes.value.toHexString())) { // for broken pairs that have no symbol function exposed if (!isNullEthValue(symbolResultBytes.value.toHexString())) { symbolValue = symbolResultBytes.value.toString() - } else { - // try with the static definition - const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions) - if (staticTokenDefinition != null) { - symbolValue = staticTokenDefinition.symbol - } } } } else { @@ -37,10 +34,13 @@ export function fetchTokenSymbol( return symbolValue } -export function fetchTokenName( - tokenAddress: Address, - staticTokenDefinitions: StaticTokenDefinition[] = STATIC_TOKEN_DEFINITIONS, -): string { +export function fetchTokenName(tokenAddress: Address, tokenOverrides: StaticTokenDefinition[]): string { + // try with the static definition + const staticTokenDefinition = getStaticDefinition(tokenAddress, tokenOverrides) + if (staticTokenDefinition != null) { + return staticTokenDefinition.name + } + const contract = ERC20.bind(tokenAddress) const contractNameBytes = ERC20NameBytes.bind(tokenAddress) @@ -53,12 +53,6 @@ export function fetchTokenName( // for broken exchanges that have no name function exposed if (!isNullEthValue(nameResultBytes.value.toHexString())) { nameValue = nameResultBytes.value.toString() - } else { - // try with the static definition - const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions) - if (staticTokenDefinition != null) { - nameValue = staticTokenDefinition.name - } } } } else { @@ -78,10 +72,13 @@ export function fetchTokenTotalSupply(tokenAddress: Address): BigInt { return totalSupplyValue } -export function fetchTokenDecimals( - tokenAddress: Address, - staticTokenDefinitions: StaticTokenDefinition[] = STATIC_TOKEN_DEFINITIONS, -): BigInt | null { +export function fetchTokenDecimals(tokenAddress: Address, tokenOverrides: StaticTokenDefinition[]): BigInt | null { + // try with the static definition + const staticTokenDefinition = getStaticDefinition(tokenAddress, tokenOverrides) + if (staticTokenDefinition) { + return staticTokenDefinition.decimals + } + const contract = ERC20.bind(tokenAddress) // try types uint8 for decimals const decimalResult = contract.try_decimals() @@ -90,12 +87,6 @@ export function fetchTokenDecimals( if (decimalResult.value.lt(BigInt.fromI32(255))) { return decimalResult.value } - } else { - // try with the static definition - const staticTokenDefinition = getStaticDefinition(tokenAddress, staticTokenDefinitions) - if (staticTokenDefinition) { - return staticTokenDefinition.decimals - } } return null diff --git a/subgraph.yaml b/subgraph.yaml index 10e7cb55..d4024c55 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -9,11 +9,11 @@ features: dataSources: - kind: ethereum/contract name: Factory - network: mainnet + network: base source: - address: '0x1F98431c8aD98523631AE4a59f267346ea31F984' abi: Factory - startBlock: 12369621 + address: "0x33128a8fC17869897dcE68Ed026d694621f6FDfD" + startBlock: 2009445 mapping: kind: ethereum/events apiVersion: 0.0.7 @@ -39,7 +39,7 @@ dataSources: templates: - kind: ethereum/contract name: Pool - network: mainnet + network: base source: abi: Pool mapping: @@ -62,9 +62,11 @@ templates: handler: handleInitialize - event: Swap(indexed address,indexed address,int256,int256,uint160,uint128,int24) handler: handleSwap - - event: Mint(address,indexed address,indexed int24,indexed int24,uint128,uint256,uint256) + - event: Mint(address,indexed address,indexed int24,indexed + int24,uint128,uint256,uint256) handler: handleMint - event: Burn(indexed address,indexed int24,indexed int24,uint128,uint256,uint256) handler: handleBurn - - event: Collect(indexed address,address,indexed int24,indexed int24,uint128,uint128) + - event: Collect(indexed address,address,indexed int24,indexed + int24,uint128,uint128) handler: handleCollect diff --git a/tests/constants.ts b/tests/constants.ts index 4993604a..f3f46d00 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -4,8 +4,10 @@ import { assert, createMockedFunction, newMockEvent } from 'matchstick-as' import { handlePoolCreatedHelper } from '../src/mappings/factory' import { PoolCreated } from '../src/types/Factory/Factory' import { Pool, Token } from '../src/types/schema' +import { SubgraphConfig } from '../src/utils/chains' import { ZERO_BD, ZERO_BI } from '../src/utils/constants' +const FACTORY_ADDRESS = '0x1F98431c8aD98523631AE4a59f267346ea31F984' const USDC_MAINNET_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' const WETH_MAINNET_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' const WBTC_MAINNET_ADDRESS = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' @@ -14,6 +16,18 @@ export const WBTC_WETH_03_MAINNET_POOL = '0xcbcdf9626bc03e24f779434178a73a0b4bad export const POOL_FEE_TIER_03 = 3000 export const POOL_TICK_SPACING_03 = 60 +export const TEST_CONFIG: SubgraphConfig = { + factoryAddress: FACTORY_ADDRESS, + stablecoinWrappedNativePoolAddress: USDC_WETH_03_MAINNET_POOL, + stablecoinIsToken0: true, + wrappedNativeAddress: WETH_MAINNET_ADDRESS, + minimumNativeLocked: ZERO_BD, + poolsToSkip: [], + stablecoinAddresses: [USDC_MAINNET_ADDRESS], + whitelistTokens: [WETH_MAINNET_ADDRESS, USDC_MAINNET_ADDRESS], + tokenOverrides: [], +} + export class TokenFixture { address: string symbol: string @@ -46,6 +60,40 @@ export const WBTC_MAINNET_FIXTURE: TokenFixture = { decimals: '8', } +export const getTokenFixture = (tokenAddress: string): TokenFixture => { + if (tokenAddress == USDC_MAINNET_FIXTURE.address) { + return USDC_MAINNET_FIXTURE + } else if (tokenAddress == WETH_MAINNET_FIXTURE.address) { + return WETH_MAINNET_FIXTURE + } else if (tokenAddress == WBTC_MAINNET_FIXTURE.address) { + return WBTC_MAINNET_FIXTURE + } else { + throw new Error('Token address not found in fixtures') + } +} + +export class PoolFixture { + token0: TokenFixture + token1: TokenFixture + feeTier: number + tickSpacing: number +} + +export const USDC_WETH_03_MAINNET_POOL_FIXTURE: PoolFixture = { + token0: USDC_MAINNET_FIXTURE, + token1: WETH_MAINNET_FIXTURE, + feeTier: POOL_FEE_TIER_03, + tickSpacing: POOL_TICK_SPACING_03, +} + +export const getPoolFixture = (poolAddress: string): PoolFixture => { + if (poolAddress == USDC_WETH_03_MAINNET_POOL) { + return USDC_WETH_03_MAINNET_POOL_FIXTURE + } else { + throw new Error('Pool address not found in fixtures') + } +} + export const TEST_ETH_PRICE_USD = BigDecimal.fromString('2000') export const TEST_USDC_DERIVED_ETH = BigDecimal.fromString('1').div(BigDecimal.fromString('2000')) export const TEST_WETH_DERIVED_ETH = BigDecimal.fromString('1') @@ -54,17 +102,18 @@ export const MOCK_EVENT = newMockEvent() export const invokePoolCreatedWithMockedEthCalls = ( mockEvent: ethereum.Event, - factoryAddress: string, - token0: TokenFixture, - token1: TokenFixture, - poolAddressHexString: string, - feeTier: number, - tickSpacing: number, + subgraphConfig: SubgraphConfig, ): void => { + const pool = getPoolFixture(subgraphConfig.stablecoinWrappedNativePoolAddress) + const feeTier = pool.feeTier + const tickSpacing = pool.tickSpacing + const token0 = getTokenFixture(pool.token0.address) + const token1 = getTokenFixture(pool.token1.address) + const mockEvent = newMockEvent() const token0Address = Address.fromString(token0.address) const token1Address = Address.fromString(token1.address) - const poolAddress = Address.fromString(poolAddressHexString) + const poolAddress = Address.fromString(subgraphConfig.stablecoinWrappedNativePoolAddress) const parameters = [ new ethereum.EventParam('token0', ethereum.Value.fromAddress(token0Address)), new ethereum.EventParam('token1', ethereum.Value.fromAddress(token1Address)), @@ -100,7 +149,7 @@ export const invokePoolCreatedWithMockedEthCalls = ( createMockedFunction(token1Address, 'decimals', 'decimals():(uint32)').returns([ ethereum.Value.fromUnsignedBigInt(BigInt.fromString(token1.decimals)), ]) - handlePoolCreatedHelper(poolCreatedEvent, factoryAddress, [token0.address, token1.address]) + handlePoolCreatedHelper(poolCreatedEvent, subgraphConfig) } // More lightweight than the method above which invokes handlePoolCreated. This diff --git a/tests/handleBurn.test.ts b/tests/handleBurn.test.ts index 618d8c55..b3b1562d 100644 --- a/tests/handleBurn.test.ts +++ b/tests/handleBurn.test.ts @@ -5,13 +5,12 @@ import { handleBurnHelper } from '../src/mappings/pool/burn' import { Bundle, Pool, Tick, Token } from '../src/types/schema' import { Burn } from '../src/types/templates/Pool/Pool' import { convertTokenToDecimal, fastExponentiation, safeDiv } from '../src/utils' -import { FACTORY_ADDRESS, ONE_BD, ZERO_BI } from '../src/utils/constants' +import { ONE_BD, ZERO_BI } from '../src/utils/constants' import { assertObjectMatches, invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, - POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, + TEST_CONFIG, TEST_ETH_PRICE_USD, TEST_USDC_DERIVED_ETH, TEST_WETH_DERIVED_ETH, @@ -59,15 +58,7 @@ const BURN_EVENT = new Burn( describe('handleBurn', () => { beforeAll(() => { - invokePoolCreatedWithMockedEthCalls( - MOCK_EVENT, - FACTORY_ADDRESS, - USDC_MAINNET_FIXTURE, - WETH_MAINNET_FIXTURE, - USDC_WETH_03_MAINNET_POOL, - POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, - ) + invokePoolCreatedWithMockedEthCalls(MOCK_EVENT, TEST_CONFIG) const bundle = new Bundle('1') bundle.ethPriceUSD = TEST_ETH_PRICE_USD @@ -113,7 +104,7 @@ describe('handleBurn', () => { pool.tick = BigInt.fromI32(BURN_FIXTURE.tickLower + BURN_FIXTURE.tickUpper).div(BigInt.fromI32(2)) pool.save() - handleBurnHelper(BURN_EVENT, FACTORY_ADDRESS) + handleBurnHelper(BURN_EVENT, TEST_CONFIG) const amountToken0 = convertTokenToDecimal(BURN_FIXTURE.amount0, BigInt.fromString(USDC_MAINNET_FIXTURE.decimals)) const amountToken1 = convertTokenToDecimal(BURN_FIXTURE.amount1, BigInt.fromString(WETH_MAINNET_FIXTURE.decimals)) @@ -122,7 +113,7 @@ describe('handleBurn', () => { .plus(amountToken1.times(TEST_WETH_DERIVED_ETH)) const poolTotalValueLockedUSD = poolTotalValueLockedETH.times(TEST_ETH_PRICE_USD) - assertObjectMatches('Factory', FACTORY_ADDRESS, [ + assertObjectMatches('Factory', TEST_CONFIG.factoryAddress, [ ['txCount', '1'], ['totalValueLockedETH', '0'], ['totalValueLockedUSD', '0'], @@ -186,7 +177,7 @@ describe('handleBurn', () => { const liquidityBeforeBurn = pool.liquidity pool.save() - handleBurnHelper(BURN_EVENT, FACTORY_ADDRESS) + handleBurnHelper(BURN_EVENT, TEST_CONFIG) // liquidity should not be updated assertObjectMatches('Pool', USDC_WETH_03_MAINNET_POOL, [['liquidity', liquidityBeforeBurn.toString()]]) diff --git a/tests/handleCollect.test.ts b/tests/handleCollect.test.ts index 05b48c85..e2128506 100644 --- a/tests/handleCollect.test.ts +++ b/tests/handleCollect.test.ts @@ -5,13 +5,12 @@ import { handleCollectHelper } from '../src/mappings/pool/collect' import { Bundle, Token } from '../src/types/schema' import { Collect } from '../src/types/templates/Pool/Pool' import { convertTokenToDecimal } from '../src/utils' -import { FACTORY_ADDRESS, ZERO_BD } from '../src/utils/constants' +import { ZERO_BD } from '../src/utils/constants' import { assertObjectMatches, invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, - POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, + TEST_CONFIG, TEST_ETH_PRICE_USD, TEST_USDC_DERIVED_ETH, TEST_WETH_DERIVED_ETH, @@ -59,15 +58,7 @@ const COLLECT_EVENT = new Collect( describe('handleMint', () => { beforeAll(() => { - invokePoolCreatedWithMockedEthCalls( - MOCK_EVENT, - FACTORY_ADDRESS, - USDC_MAINNET_FIXTURE, - WETH_MAINNET_FIXTURE, - USDC_WETH_03_MAINNET_POOL, - POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, - ) + invokePoolCreatedWithMockedEthCalls(MOCK_EVENT, TEST_CONFIG) const bundle = new Bundle('1') bundle.ethPriceUSD = TEST_ETH_PRICE_USD @@ -86,7 +77,9 @@ describe('handleMint', () => { // pass in empty whitelist to simplify this test. Doing so ignores the // effect of getTrackedAmountUSD which we test separately. const trackedCollectedAmountUSD = ZERO_BD - handleCollectHelper(COLLECT_EVENT, FACTORY_ADDRESS, []) + const TEST_CONFIG_WITH_NO_WHITELIST = TEST_CONFIG + TEST_CONFIG_WITH_NO_WHITELIST.whitelistTokens = [] + handleCollectHelper(COLLECT_EVENT, TEST_CONFIG_WITH_NO_WHITELIST) const collectedAmountToken0 = convertTokenToDecimal( COLLECT_FIXTURE.amount0, @@ -101,7 +94,7 @@ describe('handleMint', () => { .plus(collectedAmountToken1.times(TEST_WETH_DERIVED_ETH)) const collectedAmountUSD = collectedAmountETH.times(TEST_ETH_PRICE_USD) - assertObjectMatches('Factory', FACTORY_ADDRESS, [ + assertObjectMatches('Factory', TEST_CONFIG.factoryAddress, [ ['txCount', '1'], ['totalValueLockedETH', collectedAmountETH.neg().toString()], ['totalValueLockedUSD', collectedAmountUSD.neg().toString()], diff --git a/tests/handleInitialize.test.ts b/tests/handleInitialize.test.ts index f9a569b5..cf793cbb 100644 --- a/tests/handleInitialize.test.ts +++ b/tests/handleInitialize.test.ts @@ -5,14 +5,15 @@ import { handleInitializeHelper } from '../src/mappings/pool/initialize' import { Bundle, Pool, Token } from '../src/types/schema' import { Initialize } from '../src/types/templates/Pool/Pool' import { safeDiv } from '../src/utils' -import { ADDRESS_ZERO, ZERO_BD } from '../src/utils/constants' -import { findEthPerToken, getEthPriceInUSD } from '../src/utils/pricing' +import { ADDRESS_ZERO } from '../src/utils/constants' +import { findNativePerToken, getNativePriceInUSD } from '../src/utils/pricing' import { assertObjectMatches, createAndStoreTestPool, createAndStoreTestToken, MOCK_EVENT, POOL_FEE_TIER_03, + TEST_CONFIG, TEST_ETH_PRICE_USD, USDC_MAINNET_FIXTURE, USDC_WETH_03_MAINNET_POOL, @@ -61,42 +62,29 @@ describe('handleInitialize', () => { bundle.ethPriceUSD = TEST_ETH_PRICE_USD bundle.save() - const stablecoinWrappedNativePoolAddress = USDC_WETH_03_MAINNET_POOL - const stablecoinIsToken0 = true - const wrappedNativeAddress = WETH_MAINNET_FIXTURE.address - const stablecoinAddresses = [USDC_MAINNET_FIXTURE.address] - const minimumEthLocked = ZERO_BD - - handleInitializeHelper( - INITIALIZE_EVENT, - stablecoinWrappedNativePoolAddress, - stablecoinIsToken0, - wrappedNativeAddress, - stablecoinAddresses, - minimumEthLocked, - ) + handleInitializeHelper(INITIALIZE_EVENT, TEST_CONFIG) assertObjectMatches('Pool', USDC_WETH_03_MAINNET_POOL, [ ['sqrtPrice', INITIALIZE_FIXTURE.sqrtPriceX96.toString()], ['tick', INITIALIZE_FIXTURE.tick.toString()], ]) - const expectedEthPrice = getEthPriceInUSD(USDC_WETH_03_MAINNET_POOL, true) + const expectedEthPrice = getNativePriceInUSD(USDC_WETH_03_MAINNET_POOL, true) assertObjectMatches('Bundle', '1', [['ethPriceUSD', expectedEthPrice.toString()]]) - const expectedToken0Price = findEthPerToken( + const expectedToken0Price = findNativePerToken( token0 as Token, - wrappedNativeAddress, - stablecoinAddresses, - minimumEthLocked, + TEST_CONFIG.wrappedNativeAddress, + TEST_CONFIG.stablecoinAddresses, + TEST_CONFIG.minimumNativeLocked, ) assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address, [['derivedETH', expectedToken0Price.toString()]]) - const expectedToken1Price = findEthPerToken( + const expectedToken1Price = findNativePerToken( token1 as Token, - wrappedNativeAddress, - stablecoinAddresses, - minimumEthLocked, + TEST_CONFIG.wrappedNativeAddress, + TEST_CONFIG.stablecoinAddresses, + TEST_CONFIG.minimumNativeLocked, ) assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address, [['derivedETH', expectedToken1Price.toString()]]) }) @@ -118,7 +106,7 @@ describe('getEthPriceInUSD', () => { pool.token0Price = BigDecimal.fromString('1') pool.save() - const ethPriceUSD = getEthPriceInUSD(USDC_WETH_03_MAINNET_POOL, true) + const ethPriceUSD = getNativePriceInUSD(USDC_WETH_03_MAINNET_POOL, true) assert.assertTrue(ethPriceUSD == BigDecimal.fromString('1')) }) @@ -128,7 +116,7 @@ describe('getEthPriceInUSD', () => { pool.token1Price = BigDecimal.fromString('1') pool.save() - const ethPriceUSD = getEthPriceInUSD(USDC_WETH_03_MAINNET_POOL, false) + const ethPriceUSD = getNativePriceInUSD(USDC_WETH_03_MAINNET_POOL, false) assert.assertTrue(ethPriceUSD == BigDecimal.fromString('1')) }) @@ -139,12 +127,12 @@ describe('getEthPriceInUSD', () => { pool.token1Price = BigDecimal.fromString('1') pool.save() - const ethPriceUSD = getEthPriceInUSD(ADDRESS_ZERO) + const ethPriceUSD = getNativePriceInUSD(ADDRESS_ZERO, true) assert.assertTrue(ethPriceUSD == BigDecimal.fromString('0')) }) }) -describe('findEthPerToken', () => { +describe('findNativePerToken', () => { beforeEach(() => { clearStore() @@ -155,13 +143,23 @@ describe('findEthPerToken', () => { test('success - token is wrapped native', () => { const token = createAndStoreTestToken(WETH_MAINNET_FIXTURE) - const ethPerToken = findEthPerToken(token as Token, WETH_MAINNET_FIXTURE.address) + const ethPerToken = findNativePerToken( + token as Token, + TEST_CONFIG.wrappedNativeAddress, + TEST_CONFIG.stablecoinAddresses, + TEST_CONFIG.minimumNativeLocked, + ) assert.assertTrue(ethPerToken == BigDecimal.fromString('1')) }) test('success - token is stablecoin', () => { const token = createAndStoreTestToken(USDC_MAINNET_FIXTURE) - const ethPerToken = findEthPerToken(token as Token, WETH_MAINNET_FIXTURE.address, [USDC_MAINNET_FIXTURE.address]) + const ethPerToken = findNativePerToken( + token as Token, + TEST_CONFIG.wrappedNativeAddress, + TEST_CONFIG.stablecoinAddresses, + TEST_CONFIG.minimumNativeLocked, + ) const expectedStablecoinPrice = safeDiv(BigDecimal.fromString('1'), TEST_ETH_PRICE_USD) assert.assertTrue(ethPerToken == expectedStablecoinPrice) }) @@ -189,7 +187,7 @@ describe('findEthPerToken', () => { token1.derivedETH = BigDecimal.fromString('10') token1.save() - const ethPerToken = findEthPerToken( + const ethPerToken = findNativePerToken( token0 as Token, WETH_MAINNET_FIXTURE.address, [USDC_MAINNET_FIXTURE.address], @@ -201,7 +199,12 @@ describe('findEthPerToken', () => { test('success - token is not wrapped native or stablecoin, but has no pools', () => { const token0 = createAndStoreTestToken(WBTC_MAINNET_FIXTURE) - const ethPerToken = findEthPerToken(token0 as Token) + const ethPerToken = findNativePerToken( + token0 as Token, + TEST_CONFIG.wrappedNativeAddress, + TEST_CONFIG.stablecoinAddresses, + TEST_CONFIG.minimumNativeLocked, + ) assert.assertTrue(ethPerToken == BigDecimal.fromString('0')) }) @@ -210,7 +213,12 @@ describe('findEthPerToken', () => { token0.whitelistPools = [WBTC_WETH_03_MAINNET_POOL] token0.save() - const ethPerToken = findEthPerToken(token0 as Token) + const ethPerToken = findNativePerToken( + token0 as Token, + TEST_CONFIG.wrappedNativeAddress, + TEST_CONFIG.stablecoinAddresses, + TEST_CONFIG.minimumNativeLocked, + ) assert.assertTrue(ethPerToken == BigDecimal.fromString('0')) }) }) diff --git a/tests/handleMint.test.ts b/tests/handleMint.test.ts index 4248787c..c6705caa 100644 --- a/tests/handleMint.test.ts +++ b/tests/handleMint.test.ts @@ -5,13 +5,12 @@ import { handleMintHelper } from '../src/mappings/pool/mint' import { Bundle, Pool, Token } from '../src/types/schema' import { Mint } from '../src/types/templates/Pool/Pool' import { convertTokenToDecimal, fastExponentiation, safeDiv } from '../src/utils' -import { FACTORY_ADDRESS, ONE_BD } from '../src/utils/constants' +import { ONE_BD } from '../src/utils/constants' import { assertObjectMatches, invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, - POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, + TEST_CONFIG, TEST_ETH_PRICE_USD, TEST_USDC_DERIVED_ETH, TEST_WETH_DERIVED_ETH, @@ -62,15 +61,7 @@ const MINT_EVENT = new Mint( describe('handleMint', () => { beforeAll(() => { - invokePoolCreatedWithMockedEthCalls( - MOCK_EVENT, - FACTORY_ADDRESS, - USDC_MAINNET_FIXTURE, - WETH_MAINNET_FIXTURE, - USDC_WETH_03_MAINNET_POOL, - POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, - ) + invokePoolCreatedWithMockedEthCalls(MOCK_EVENT, TEST_CONFIG) const bundle = new Bundle('1') bundle.ethPriceUSD = TEST_ETH_PRICE_USD @@ -91,7 +82,7 @@ describe('handleMint', () => { pool.tick = BigInt.fromI32(MINT_FIXTURE.tickLower + MINT_FIXTURE.tickUpper).div(BigInt.fromI32(2)) pool.save() - handleMintHelper(MINT_EVENT, FACTORY_ADDRESS) + handleMintHelper(MINT_EVENT, TEST_CONFIG) const amountToken0 = convertTokenToDecimal(MINT_FIXTURE.amount0, BigInt.fromString(USDC_MAINNET_FIXTURE.decimals)) const amountToken1 = convertTokenToDecimal(MINT_FIXTURE.amount1, BigInt.fromString(WETH_MAINNET_FIXTURE.decimals)) @@ -100,7 +91,7 @@ describe('handleMint', () => { .plus(amountToken1.times(TEST_WETH_DERIVED_ETH)) const poolTotalValueLockedUSD = poolTotalValueLockedETH.times(TEST_ETH_PRICE_USD) - assertObjectMatches('Factory', FACTORY_ADDRESS, [ + assertObjectMatches('Factory', TEST_CONFIG.factoryAddress, [ ['txCount', '1'], ['totalValueLockedETH', poolTotalValueLockedETH.toString()], ['totalValueLockedUSD', poolTotalValueLockedUSD.toString()], @@ -179,7 +170,7 @@ describe('handleMint', () => { const liquidityBeforeMint = pool.liquidity pool.save() - handleMintHelper(MINT_EVENT, FACTORY_ADDRESS) + handleMintHelper(MINT_EVENT, TEST_CONFIG) // liquidity should not be updated assertObjectMatches('Pool', USDC_WETH_03_MAINNET_POOL, [['liquidity', liquidityBeforeMint.toString()]]) diff --git a/tests/handlePoolCreated.test.ts b/tests/handlePoolCreated.test.ts index 74fad2d4..b11ce510 100644 --- a/tests/handlePoolCreated.test.ts +++ b/tests/handlePoolCreated.test.ts @@ -3,7 +3,6 @@ import { assert, createMockedFunction, test } from 'matchstick-as/assembly/index import { describe, test } from 'matchstick-as/assembly/index' import { NULL_ETH_HEX_STRING } from '../src/utils' -import { FACTORY_ADDRESS } from '../src/utils/constants' import { StaticTokenDefinition } from '../src/utils/staticTokenDefinition' import { fetchTokenDecimals, fetchTokenName, fetchTokenSymbol, fetchTokenTotalSupply } from '../src/utils/token' import { @@ -11,7 +10,7 @@ import { invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, + TEST_CONFIG, USDC_MAINNET_FIXTURE, USDC_WETH_03_MAINNET_POOL, WETH_MAINNET_FIXTURE, @@ -19,22 +18,14 @@ import { describe('handlePoolCreated', () => { test('success - create a pool', () => { - assert.notInStore('Factory', FACTORY_ADDRESS) + assert.notInStore('Factory', TEST_CONFIG.factoryAddress) assert.notInStore('Pool', USDC_WETH_03_MAINNET_POOL) assert.notInStore('Token', USDC_MAINNET_FIXTURE.address) assert.notInStore('Token', USDC_MAINNET_FIXTURE.address) - invokePoolCreatedWithMockedEthCalls( - MOCK_EVENT, - FACTORY_ADDRESS, - USDC_MAINNET_FIXTURE, - WETH_MAINNET_FIXTURE, - USDC_WETH_03_MAINNET_POOL, - POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, - ) + invokePoolCreatedWithMockedEthCalls(MOCK_EVENT, TEST_CONFIG) - assertObjectMatches('Factory', FACTORY_ADDRESS, [ + assertObjectMatches('Factory', TEST_CONFIG.factoryAddress, [ ['poolCount', '1'], ['totalVolumeETH', '0'], ['totalVolumeUSD', '0'], @@ -117,7 +108,7 @@ describe('handlePoolCreated', () => { test('success - fetch token symbol', () => { const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address) createMockedFunction(usdcAddress, 'symbol', 'symbol():(string)').returns([ethereum.Value.fromString('USDC')]) - const symbol = fetchTokenSymbol(usdcAddress) + const symbol = fetchTokenSymbol(usdcAddress, []) assert.stringEquals(symbol, 'USDC') }) @@ -127,7 +118,7 @@ describe('handlePoolCreated', () => { createMockedFunction(usdcAddress, 'symbol', 'symbol():(bytes32)').returns([ ethereum.Value.fromBytes(Bytes.fromUTF8('USDC')), ]) - const symbol = fetchTokenSymbol(usdcAddress) + const symbol = fetchTokenSymbol(usdcAddress, []) assert.stringEquals(symbol, 'USDC') }) @@ -153,7 +144,7 @@ describe('handlePoolCreated', () => { const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address) createMockedFunction(usdcAddress, 'symbol', 'symbol():(string)').reverts() createMockedFunction(usdcAddress, 'symbol', 'symbol():(bytes32)').reverts() - const symbol = fetchTokenSymbol(usdcAddress) + const symbol = fetchTokenSymbol(usdcAddress, []) assert.stringEquals(symbol, 'unknown') }) }) @@ -162,7 +153,7 @@ describe('handlePoolCreated', () => { test('success - fetch token name', () => { const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address) createMockedFunction(usdcAddress, 'name', 'name():(string)').returns([ethereum.Value.fromString('USD Coin')]) - const name = fetchTokenName(usdcAddress) + const name = fetchTokenName(usdcAddress, []) assert.stringEquals(name, 'USD Coin') }) @@ -172,7 +163,7 @@ describe('handlePoolCreated', () => { createMockedFunction(usdcAddress, 'name', 'name():(bytes32)').returns([ ethereum.Value.fromBytes(Bytes.fromUTF8('USD Coin')), ]) - const name = fetchTokenName(usdcAddress) + const name = fetchTokenName(usdcAddress, []) assert.stringEquals(name, 'USD Coin') }) @@ -198,7 +189,7 @@ describe('handlePoolCreated', () => { const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address) createMockedFunction(usdcAddress, 'name', 'name():(string)').reverts() createMockedFunction(usdcAddress, 'name', 'name():(bytes32)').reverts() - const name = fetchTokenName(usdcAddress) + const name = fetchTokenName(usdcAddress, []) assert.stringEquals(name, 'unknown') }) }) @@ -227,7 +218,7 @@ describe('handlePoolCreated', () => { createMockedFunction(usdcAddress, 'decimals', 'decimals():(uint32)').returns([ ethereum.Value.fromUnsignedBigInt(BigInt.fromI32(6)), ]) - const decimals = fetchTokenDecimals(usdcAddress) + const decimals = fetchTokenDecimals(usdcAddress, []) assert.assertTrue(decimals == BigInt.fromI32(6)) }) @@ -249,7 +240,7 @@ describe('handlePoolCreated', () => { test('failure - fetch token decimals reverts', () => { const usdcAddress = Address.fromString(USDC_MAINNET_FIXTURE.address) createMockedFunction(usdcAddress, 'decimals', 'decimals():(uint32)').reverts() - const decimals: BigInt | null = fetchTokenDecimals(usdcAddress) + const decimals: BigInt | null = fetchTokenDecimals(usdcAddress, []) assert.assertTrue(decimals === null) }) }) diff --git a/tests/handleSwap.test.ts b/tests/handleSwap.test.ts index 4f6c47de..47c0376c 100644 --- a/tests/handleSwap.test.ts +++ b/tests/handleSwap.test.ts @@ -5,14 +5,19 @@ import { handleSwapHelper } from '../src/mappings/pool/swap' import { Bundle, Token } from '../src/types/schema' import { Swap } from '../src/types/templates/Pool/Pool' import { convertTokenToDecimal, safeDiv } from '../src/utils' -import { FACTORY_ADDRESS, ZERO_BD } from '../src/utils/constants' -import { findEthPerToken, getEthPriceInUSD, getTrackedAmountUSD, sqrtPriceX96ToTokenPrices } from '../src/utils/pricing' +import { ZERO_BD } from '../src/utils/constants' +import { + findNativePerToken, + getNativePriceInUSD, + getTrackedAmountUSD, + sqrtPriceX96ToTokenPrices, +} from '../src/utils/pricing' import { assertObjectMatches, invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, + TEST_CONFIG, TEST_ETH_PRICE_USD, TEST_USDC_DERIVED_ETH, TEST_WETH_DERIVED_ETH, @@ -63,15 +68,7 @@ const SWAP_EVENT = new Swap( describe('handleSwap', () => { beforeAll(() => { - invokePoolCreatedWithMockedEthCalls( - MOCK_EVENT, - FACTORY_ADDRESS, - USDC_MAINNET_FIXTURE, - WETH_MAINNET_FIXTURE, - USDC_WETH_03_MAINNET_POOL, - POOL_FEE_TIER_03, - POOL_TICK_SPACING_03, - ) + invokePoolCreatedWithMockedEthCalls(MOCK_EVENT, TEST_CONFIG) const bundle = new Bundle('1') bundle.ethPriceUSD = TEST_ETH_PRICE_USD @@ -87,13 +84,6 @@ describe('handleSwap', () => { }) test('success', () => { - const stablecoinWrappedNativePoolAddress = USDC_WETH_03_MAINNET_POOL - const stablecoinIsToken0 = true - const wrappedNativeAddress = WETH_MAINNET_FIXTURE.address - const stablecoinAddresses = [USDC_MAINNET_FIXTURE.address] - const minimumEthLocked = ZERO_BD - const whitelistTokens = [USDC_MAINNET_FIXTURE.address, WETH_MAINNET_FIXTURE.address] - const token0 = Token.load(USDC_MAINNET_FIXTURE.address)! const token1 = Token.load(WETH_MAINNET_FIXTURE.address)! @@ -104,9 +94,13 @@ describe('handleSwap', () => { const amount1Abs = amount1.lt(ZERO_BD) ? amount1.times(BigDecimal.fromString('-1')) : amount1 // calculate this before calling handleSwapHelper because it updates the derivedETH of the tokens which will affect calculations - const amountTotalUSDTracked = getTrackedAmountUSD(amount0Abs, token0, amount1Abs, token1, whitelistTokens).div( - BigDecimal.fromString('2'), - ) + const amountTotalUSDTracked = getTrackedAmountUSD( + amount0Abs, + token0, + amount1Abs, + token1, + TEST_CONFIG.whitelistTokens, + ).div(BigDecimal.fromString('2')) const amount0ETH = amount0Abs.times(TEST_USDC_DERIVED_ETH) const amount1ETH = amount1Abs.times(TEST_WETH_DERIVED_ETH) @@ -121,24 +115,26 @@ describe('handleSwap', () => { const feesETH = amountTotalETHTRacked.times(feeTierBD).div(BigDecimal.fromString('1000000')) const feesUSD = amountTotalUSDTracked.times(feeTierBD).div(BigDecimal.fromString('1000000')) - handleSwapHelper( - SWAP_EVENT, - stablecoinWrappedNativePoolAddress, - stablecoinIsToken0, - wrappedNativeAddress, - stablecoinAddresses, - minimumEthLocked, - whitelistTokens, - ) + handleSwapHelper(SWAP_EVENT, TEST_CONFIG) - const newEthPrice = getEthPriceInUSD(USDC_WETH_03_MAINNET_POOL, true) + const newEthPrice = getNativePriceInUSD(USDC_WETH_03_MAINNET_POOL, true) const newPoolPrices = sqrtPriceX96ToTokenPrices(SWAP_FIXTURE.sqrtPriceX96, token0, token1) - const newToken0DerivedETH = findEthPerToken(token0, wrappedNativeAddress, stablecoinAddresses, minimumEthLocked) - const newToken1DerivedETH = findEthPerToken(token1, wrappedNativeAddress, stablecoinAddresses, minimumEthLocked) + const newToken0DerivedETH = findNativePerToken( + token0, + TEST_CONFIG.wrappedNativeAddress, + TEST_CONFIG.stablecoinAddresses, + TEST_CONFIG.minimumNativeLocked, + ) + const newToken1DerivedETH = findNativePerToken( + token1, + TEST_CONFIG.wrappedNativeAddress, + TEST_CONFIG.stablecoinAddresses, + TEST_CONFIG.minimumNativeLocked, + ) const totalValueLockedETH = amount0.times(newToken0DerivedETH).plus(amount1.times(newToken1DerivedETH)) - assertObjectMatches('Factory', FACTORY_ADDRESS, [ + assertObjectMatches('Factory', TEST_CONFIG.factoryAddress, [ ['txCount', '1'], ['totalVolumeETH', amountTotalETHTRacked.toString()], ['totalVolumeUSD', amountTotalUSDTracked.toString()], diff --git a/tests/intervalUpdates.test.ts b/tests/intervalUpdates.test.ts index 120c4e1d..8ed1d5f4 100644 --- a/tests/intervalUpdates.test.ts +++ b/tests/intervalUpdates.test.ts @@ -2,7 +2,7 @@ import { Address, BigDecimal, BigInt } from '@graphprotocol/graph-ts' import { beforeEach, clearStore, describe, test } from 'matchstick-as' import { Bundle, Factory, Pool, Token } from '../src/types/schema' -import { ADDRESS_ZERO, FACTORY_ADDRESS, ZERO_BD, ZERO_BI } from '../src/utils/constants' +import { ADDRESS_ZERO, ZERO_BD, ZERO_BI } from '../src/utils/constants' import { updatePoolDayData, updatePoolHourData, @@ -17,6 +17,7 @@ import { MOCK_EVENT, MOCK_EVENT as poolEvent, POOL_FEE_TIER_03, + TEST_CONFIG, TEST_ETH_PRICE_USD, USDC_MAINNET_FIXTURE, USDC_WETH_03_MAINNET_POOL, @@ -27,7 +28,7 @@ describe('uniswap interval data', () => { beforeEach(() => { clearStore() - const factory = new Factory(FACTORY_ADDRESS) + const factory = new Factory(TEST_CONFIG.factoryAddress) factory.poolCount = ZERO_BI factory.totalVolumeUSD = ZERO_BD factory.totalVolumeETH = ZERO_BD @@ -46,14 +47,14 @@ describe('uniswap interval data', () => { test('success - create and update uniswapDayData', () => { // these are the only two fields that get persisted to uniswapDayData, set them to non-zero values - const factory = Factory.load(FACTORY_ADDRESS)! + const factory = Factory.load(TEST_CONFIG.factoryAddress)! const uniswapTxCount = BigInt.fromString('10') const uniswapTotalValueLockedUSD = BigDecimal.fromString('100') factory.txCount = uniswapTxCount factory.totalValueLockedUSD = uniswapTotalValueLockedUSD factory.save() - updateUniswapDayData(poolEvent) + updateUniswapDayData(poolEvent, TEST_CONFIG.factoryAddress) const dayId = poolEvent.block.timestamp.toI32() / 86400 const dayStartTimestamp = dayId * 86400 @@ -71,7 +72,7 @@ describe('uniswap interval data', () => { factory.txCount = updatedTxCount factory.save() - updateUniswapDayData(poolEvent) + updateUniswapDayData(poolEvent, TEST_CONFIG.factoryAddress) assertObjectMatches('UniswapDayData', dayId.toString(), [['txCount', updatedTxCount.toString()]]) })