diff --git a/.eslintrc.js b/.eslintrc.js index 3d6e4080..321f4b26 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,20 +3,21 @@ require('@uniswap/eslint-config/load') module.exports = { extends: ['@uniswap/eslint-config/node'], rules: { + '@typescript-eslint/no-inferrable-types': 'off', 'import/no-unused-modules': 'off', '@typescript-eslint/no-restricted-imports': 'off', '@typescript-eslint/no-unused-vars': [ 'error', - { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' } + { argsIgnorePattern: '^_', varsIgnorePattern: '^_', caughtErrorsIgnorePattern: '^_' }, ], '@typescript-eslint/no-this-alias': [ 'error', { allowDestructuring: true, // Allow `const { props, state } = this`; false by default allowedNames: [ - 'self' // Allow `const self= this`; `[]` by default - ] - } + 'self', // Allow `const self= this`; `[]` by default + ], + }, ], '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/no-explicit-any': 'off', @@ -25,22 +26,22 @@ module.exports = { { types: { // Allow BigInt (uppercase) - BigInt: false - } - } - ] + BigInt: false, + }, + }, + ], }, overrides: [ { files: ['tests/**/*.ts'], settings: { jest: { - version: 26 + version: 26, }, // jest is added as a plugin in our org's eslint config, but we use // matchstick, and this would crash when linting matchstick files. - 'disable/plugins': ['jest'] - } - } - ] + 'disable/plugins': ['jest'], + }, + }, + ], } diff --git a/src/mappings/pool/initialize.ts b/src/mappings/pool/initialize.ts index 9e2cc3be..29617ab2 100644 --- a/src/mappings/pool/initialize.ts +++ b/src/mappings/pool/initialize.ts @@ -1,11 +1,29 @@ -import { BigInt } from '@graphprotocol/graph-ts' +import { BigDecimal, BigInt } from '@graphprotocol/graph-ts' import { Bundle, Pool, Token } from '../../types/schema' import { Initialize } from '../../types/templates/Pool/Pool' import { updatePoolDayData, updatePoolHourData } from '../../utils/intervalUpdates' -import { findEthPerToken, getEthPriceInUSD } from '../../utils/pricing' +import { + findEthPerToken, + getEthPriceInUSD, + MINIMUM_ETH_LOCKED, + STABLE_COINS, + USDC_WETH_03_POOL, + WETH_ADDRESS, +} from '../../utils/pricing' export function handleInitialize(event: Initialize): void { + handleInitializeHelper(event) +} + +export function handleInitializeHelper( + event: Initialize, + stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL, + stablecoinIsToken0: boolean = true, + wrappedNativeAddress: string = WETH_ADDRESS, + stablecoinAddresses: string[] = STABLE_COINS, + minimumEthLocked: BigDecimal = MINIMUM_ETH_LOCKED, +): void { // update pool sqrt price and tick const pool = Pool.load(event.address.toHexString())! pool.sqrtPrice = event.params.sqrtPriceX96 @@ -18,7 +36,7 @@ export function handleInitialize(event: Initialize): void { // update ETH price now that prices could have changed const bundle = Bundle.load('1')! - bundle.ethPriceUSD = getEthPriceInUSD() + bundle.ethPriceUSD = getEthPriceInUSD(stablecoinWrappedNativePoolAddress, stablecoinIsToken0) bundle.save() updatePoolDayData(event) @@ -26,8 +44,8 @@ export function handleInitialize(event: Initialize): void { // update token prices if (token0 && token1) { - token0.derivedETH = findEthPerToken(token0 as Token) - token1.derivedETH = findEthPerToken(token1 as Token) + token0.derivedETH = findEthPerToken(token0 as Token, wrappedNativeAddress, stablecoinAddresses, minimumEthLocked) + token1.derivedETH = findEthPerToken(token1 as Token, wrappedNativeAddress, stablecoinAddresses, minimumEthLocked) token0.save() token1.save() } diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index 1ec27745..b9ff7d4d 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -4,8 +4,8 @@ import { exponentToBigDecimal, safeDiv } from '../utils/index' import { Bundle, Pool, Token } from './../types/schema' import { ONE_BD, ZERO_BD, ZERO_BI } from './constants' -const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' -const USDC_WETH_03_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8' +export const WETH_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' +export const USDC_WETH_03_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8' // token where amounts should contribute to tracked volume and liquidity // usually tokens that many tokens are paired with s @@ -33,7 +33,7 @@ export const WHITELIST_TOKENS: string[] = [ '0xfe2e637202056d30016725477c5da089ab0a043a', // sETH2 ] -const STABLE_COINS: string[] = [ +export const STABLE_COINS: string[] = [ '0x6b175474e89094c44da98b954eedeac495271d0f', '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48', '0xdac17f958d2ee523a2206206994597c13d831ec7', @@ -42,7 +42,7 @@ const STABLE_COINS: string[] = [ '0x4dd28568d05f09b02220b09c2cb307bfd837cb95', ] -const MINIMUM_ETH_LOCKED = BigDecimal.fromString('60') +export const MINIMUM_ETH_LOCKED = BigDecimal.fromString('60') const Q192 = BigInt.fromI32(2).pow(192 as u8) export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] { @@ -54,11 +54,13 @@ export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, t return [price0, price1] } -export function getEthPriceInUSD(): BigDecimal { - // fetch eth prices for each stablecoin - const usdcPool = Pool.load(USDC_WETH_03_POOL) // dai is token0 - if (usdcPool !== null) { - return usdcPool.token0Price +export function getEthPriceInUSD( + stablecoinWrappedNativePoolAddress: string = USDC_WETH_03_POOL, + stablecoinIsToken0: boolean = true, // true is stablecoin is token0, false if stablecoin is token1 +): BigDecimal { + const stablecoinWrappedNativePool = Pool.load(stablecoinWrappedNativePoolAddress) + if (stablecoinWrappedNativePool !== null) { + return stablecoinIsToken0 ? stablecoinWrappedNativePool.token0Price : stablecoinWrappedNativePool.token1Price } else { return ZERO_BD } @@ -68,8 +70,13 @@ export function getEthPriceInUSD(): BigDecimal { * Search through graph to find derived Eth per token. * @todo update to be derived ETH (add stablecoin estimates) **/ -export function findEthPerToken(token: Token): BigDecimal { - if (token.id == WETH_ADDRESS) { +export function findEthPerToken( + token: Token, + wrappedNativeAddress: string = WETH_ADDRESS, + stablecoinAddresses: string[] = STABLE_COINS, + minimumEthLocked: BigDecimal = MINIMUM_ETH_LOCKED, +): BigDecimal { + if (token.id == wrappedNativeAddress) { return ONE_BD } const whiteList = token.whitelistPools @@ -81,7 +88,7 @@ export function findEthPerToken(token: Token): BigDecimal { // hardcoded fix for incorrect rates // if whitelist includes token - get the safe price - if (STABLE_COINS.includes(token.id)) { + if (stablecoinAddresses.includes(token.id)) { priceSoFar = safeDiv(ONE_BD, bundle.ethPriceUSD) } else { for (let i = 0; i < whiteList.length; ++i) { @@ -96,7 +103,7 @@ export function findEthPerToken(token: Token): BigDecimal { // get the derived ETH in pool if (token1) { const ethLocked = pool.totalValueLockedToken1.times(token1.derivedETH) - if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(MINIMUM_ETH_LOCKED)) { + if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(minimumEthLocked)) { largestLiquidityETH = ethLocked // token1 per our token * Eth per token1 priceSoFar = pool.token1Price.times(token1.derivedETH as BigDecimal) @@ -108,7 +115,7 @@ export function findEthPerToken(token: Token): BigDecimal { // get the derived ETH in pool if (token0) { const ethLocked = pool.totalValueLockedToken0.times(token0.derivedETH) - if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(MINIMUM_ETH_LOCKED)) { + if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(minimumEthLocked)) { largestLiquidityETH = ethLocked // token0 per our token * ETH per token0 priceSoFar = pool.token0Price.times(token0.derivedETH as BigDecimal) diff --git a/tests/constants.ts b/tests/constants.ts index 39e45c6b..4993604a 100644 --- a/tests/constants.ts +++ b/tests/constants.ts @@ -3,10 +3,14 @@ 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 { ZERO_BD, ZERO_BI } from '../src/utils/constants' const USDC_MAINNET_ADDRESS = '0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48' const WETH_MAINNET_ADDRESS = '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2' +const WBTC_MAINNET_ADDRESS = '0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599' export const USDC_WETH_03_MAINNET_POOL = '0x8ad599c3a0ff1de082011efddc58f1908eb6e6d8' +export const WBTC_WETH_03_MAINNET_POOL = '0xcbcdf9626bc03e24f779434178a73a0b4bad62ed' export const POOL_FEE_TIER_03 = 3000 export const POOL_TICK_SPACING_03 = 60 @@ -34,13 +38,21 @@ export const WETH_MAINNET_FIXTURE: TokenFixture = { decimals: '18', } +export const WBTC_MAINNET_FIXTURE: TokenFixture = { + address: WBTC_MAINNET_ADDRESS, + symbol: 'WBTC', + name: 'Wrapped Bitcoin', + totalSupply: '200', + decimals: '8', +} + 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') export const MOCK_EVENT = newMockEvent() -export const createTestPool = ( +export const invokePoolCreatedWithMockedEthCalls = ( mockEvent: ethereum.Event, factoryAddress: string, token0: TokenFixture, @@ -91,6 +103,69 @@ export const createTestPool = ( handlePoolCreatedHelper(poolCreatedEvent, factoryAddress, [token0.address, token1.address]) } +// More lightweight than the method above which invokes handlePoolCreated. This +// method only creates the pool entity while the above method also creates the +// relevant token and factory entities. +export const createAndStoreTestPool = ( + poolAddress: string, + token0Address: string, + token1Address: string, + feeTier: i32, +): Pool => { + const pool = new Pool(poolAddress) + pool.createdAtTimestamp = ZERO_BI + pool.createdAtBlockNumber = ZERO_BI + pool.token0 = token0Address + pool.token1 = token1Address + pool.feeTier = BigInt.fromI32(feeTier) + pool.liquidity = ZERO_BI + pool.sqrtPrice = ZERO_BI + pool.token0Price = ZERO_BD + pool.token1Price = ZERO_BD + pool.tick = ZERO_BI + pool.observationIndex = ZERO_BI + pool.volumeToken0 = ZERO_BD + pool.volumeToken1 = ZERO_BD + pool.volumeUSD = ZERO_BD + pool.untrackedVolumeUSD = ZERO_BD + pool.feesUSD = ZERO_BD + pool.txCount = ZERO_BI + pool.collectedFeesToken0 = ZERO_BD + pool.collectedFeesToken1 = ZERO_BD + pool.collectedFeesUSD = ZERO_BD + pool.totalValueLockedToken0 = ZERO_BD + pool.totalValueLockedToken1 = ZERO_BD + pool.totalValueLockedUSD = ZERO_BD + pool.totalValueLockedETH = ZERO_BD + pool.totalValueLockedUSDUntracked = ZERO_BD + pool.liquidityProviderCount = ZERO_BI + + pool.save() + return pool +} + +export const createAndStoreTestToken = (tokenFixture: TokenFixture): Token => { + const token = new Token(tokenFixture.address) + token.symbol = tokenFixture.symbol + token.name = tokenFixture.name + token.decimals = BigInt.fromString(tokenFixture.decimals) + token.totalSupply = BigInt.fromString(tokenFixture.totalSupply) + token.volume = ZERO_BD + token.volumeUSD = ZERO_BD + token.untrackedVolumeUSD = ZERO_BD + token.feesUSD = ZERO_BD + token.txCount = ZERO_BI + token.poolCount = ZERO_BI + token.totalValueLocked = ZERO_BD + token.totalValueLockedUSD = ZERO_BD + token.totalValueLockedUSDUntracked = ZERO_BD + token.derivedETH = ZERO_BD + token.whitelistPools = [] + + token.save() + return token +} + // Typescript for Subgraphs do not support Record types so we use a 2D string array to represent the object instead. export const assertObjectMatches = (entityType: string, id: string, obj: string[][]): void => { for (let i = 0; i < obj.length; i++) { diff --git a/tests/handleBurn.test.ts b/tests/handleBurn.test.ts index 89ddb76d..618d8c55 100644 --- a/tests/handleBurn.test.ts +++ b/tests/handleBurn.test.ts @@ -8,7 +8,7 @@ import { convertTokenToDecimal, fastExponentiation, safeDiv } from '../src/utils import { FACTORY_ADDRESS, ONE_BD, ZERO_BI } from '../src/utils/constants' import { assertObjectMatches, - createTestPool, + invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, POOL_FEE_TIER_03, POOL_TICK_SPACING_03, @@ -59,7 +59,7 @@ const BURN_EVENT = new Burn( describe('handleBurn', () => { beforeAll(() => { - createTestPool( + invokePoolCreatedWithMockedEthCalls( MOCK_EVENT, FACTORY_ADDRESS, USDC_MAINNET_FIXTURE, diff --git a/tests/handleCollect.test.ts b/tests/handleCollect.test.ts index 92f31db5..05b48c85 100644 --- a/tests/handleCollect.test.ts +++ b/tests/handleCollect.test.ts @@ -8,7 +8,7 @@ import { convertTokenToDecimal } from '../src/utils' import { FACTORY_ADDRESS, ZERO_BD } from '../src/utils/constants' import { assertObjectMatches, - createTestPool, + invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, POOL_FEE_TIER_03, POOL_TICK_SPACING_03, @@ -59,7 +59,7 @@ const COLLECT_EVENT = new Collect( describe('handleMint', () => { beforeAll(() => { - createTestPool( + invokePoolCreatedWithMockedEthCalls( MOCK_EVENT, FACTORY_ADDRESS, USDC_MAINNET_FIXTURE, diff --git a/tests/handleInitialize.test.ts b/tests/handleInitialize.test.ts new file mode 100644 index 00000000..f9a569b5 --- /dev/null +++ b/tests/handleInitialize.test.ts @@ -0,0 +1,216 @@ +import { Address, BigDecimal, BigInt, ethereum } from '@graphprotocol/graph-ts' +import { assert, beforeEach, clearStore, describe, test } from 'matchstick-as' + +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 { + assertObjectMatches, + createAndStoreTestPool, + createAndStoreTestToken, + MOCK_EVENT, + POOL_FEE_TIER_03, + TEST_ETH_PRICE_USD, + USDC_MAINNET_FIXTURE, + USDC_WETH_03_MAINNET_POOL, + WBTC_MAINNET_FIXTURE, + WBTC_WETH_03_MAINNET_POOL, + WETH_MAINNET_FIXTURE, +} from './constants' + +class InitializeFixture { + sqrtPriceX96: BigInt + tick: i32 +} + +const INITIALIZE_FIXTURE: InitializeFixture = { + sqrtPriceX96: BigInt.fromString('1111111111111111'), + tick: 194280, +} + +const INITIALIZE_EVENT = new Initialize( + Address.fromString(USDC_WETH_03_MAINNET_POOL), + MOCK_EVENT.logIndex, + MOCK_EVENT.transactionLogIndex, + MOCK_EVENT.logType, + MOCK_EVENT.block, + MOCK_EVENT.transaction, + [ + new ethereum.EventParam('sqrtPriceX96', ethereum.Value.fromUnsignedBigInt(INITIALIZE_FIXTURE.sqrtPriceX96)), + new ethereum.EventParam('tick', ethereum.Value.fromI32(INITIALIZE_FIXTURE.tick)), + ], + MOCK_EVENT.receipt, +) + +describe('handleInitialize', () => { + test('success', () => { + createAndStoreTestPool( + USDC_WETH_03_MAINNET_POOL, + USDC_MAINNET_FIXTURE.address, + WETH_MAINNET_FIXTURE.address, + POOL_FEE_TIER_03, + ) + + const token0 = createAndStoreTestToken(USDC_MAINNET_FIXTURE) + const token1 = createAndStoreTestToken(WETH_MAINNET_FIXTURE) + + const bundle = new Bundle('1') + 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, + ) + + 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) + assertObjectMatches('Bundle', '1', [['ethPriceUSD', expectedEthPrice.toString()]]) + + const expectedToken0Price = findEthPerToken( + token0 as Token, + wrappedNativeAddress, + stablecoinAddresses, + minimumEthLocked, + ) + assertObjectMatches('Token', USDC_MAINNET_FIXTURE.address, [['derivedETH', expectedToken0Price.toString()]]) + + const expectedToken1Price = findEthPerToken( + token1 as Token, + wrappedNativeAddress, + stablecoinAddresses, + minimumEthLocked, + ) + assertObjectMatches('Token', WETH_MAINNET_FIXTURE.address, [['derivedETH', expectedToken1Price.toString()]]) + }) +}) + +describe('getEthPriceInUSD', () => { + beforeEach(() => { + clearStore() + createAndStoreTestPool( + USDC_WETH_03_MAINNET_POOL, + USDC_MAINNET_FIXTURE.address, + WETH_MAINNET_FIXTURE.address, + POOL_FEE_TIER_03, + ) + }) + + test('success - stablecoin is token0', () => { + const pool = Pool.load(USDC_WETH_03_MAINNET_POOL)! + pool.token0Price = BigDecimal.fromString('1') + pool.save() + + const ethPriceUSD = getEthPriceInUSD(USDC_WETH_03_MAINNET_POOL, true) + + assert.assertTrue(ethPriceUSD == BigDecimal.fromString('1')) + }) + + test('success - stablecoin is token1', () => { + const pool = Pool.load(USDC_WETH_03_MAINNET_POOL)! + pool.token1Price = BigDecimal.fromString('1') + pool.save() + + const ethPriceUSD = getEthPriceInUSD(USDC_WETH_03_MAINNET_POOL, false) + + assert.assertTrue(ethPriceUSD == BigDecimal.fromString('1')) + }) + + test('failure - pool not found', () => { + const pool = Pool.load(USDC_WETH_03_MAINNET_POOL)! + pool.token0Price = BigDecimal.fromString('1') + pool.token1Price = BigDecimal.fromString('1') + pool.save() + + const ethPriceUSD = getEthPriceInUSD(ADDRESS_ZERO) + assert.assertTrue(ethPriceUSD == BigDecimal.fromString('0')) + }) +}) + +describe('findEthPerToken', () => { + beforeEach(() => { + clearStore() + + const bundle = new Bundle('1') + bundle.ethPriceUSD = TEST_ETH_PRICE_USD + bundle.save() + }) + + test('success - token is wrapped native', () => { + const token = createAndStoreTestToken(WETH_MAINNET_FIXTURE) + const ethPerToken = findEthPerToken(token as Token, WETH_MAINNET_FIXTURE.address) + 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 expectedStablecoinPrice = safeDiv(BigDecimal.fromString('1'), TEST_ETH_PRICE_USD) + assert.assertTrue(ethPerToken == expectedStablecoinPrice) + }) + + test('success - token is not wrapped native or stablecoin', () => { + const pool = createAndStoreTestPool( + WBTC_WETH_03_MAINNET_POOL, + WBTC_MAINNET_FIXTURE.address, + WETH_MAINNET_FIXTURE.address, + POOL_FEE_TIER_03, + ) + + const minimumEthLocked = BigDecimal.fromString('0') + + pool.liquidity = BigInt.fromString('100') + pool.totalValueLockedToken1 = BigDecimal.fromString('100') + pool.token1Price = BigDecimal.fromString('5') + pool.save() + + const token0 = createAndStoreTestToken(WBTC_MAINNET_FIXTURE) + token0.whitelistPools = [WBTC_WETH_03_MAINNET_POOL] + token0.save() + + const token1 = createAndStoreTestToken(WETH_MAINNET_FIXTURE) + token1.derivedETH = BigDecimal.fromString('10') + token1.save() + + const ethPerToken = findEthPerToken( + token0 as Token, + WETH_MAINNET_FIXTURE.address, + [USDC_MAINNET_FIXTURE.address], + minimumEthLocked, + ) + + assert.assertTrue(ethPerToken == BigDecimal.fromString('50')) + }) + + 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) + assert.assertTrue(ethPerToken == BigDecimal.fromString('0')) + }) + + test('success - token is not wrapped native or stablecoin, but has no pools with liquidity', () => { + const token0 = createAndStoreTestToken(WBTC_MAINNET_FIXTURE) + token0.whitelistPools = [WBTC_WETH_03_MAINNET_POOL] + token0.save() + + const ethPerToken = findEthPerToken(token0 as Token) + assert.assertTrue(ethPerToken == BigDecimal.fromString('0')) + }) +}) diff --git a/tests/handleMint.test.ts b/tests/handleMint.test.ts index 195f0316..4248787c 100644 --- a/tests/handleMint.test.ts +++ b/tests/handleMint.test.ts @@ -8,7 +8,7 @@ import { convertTokenToDecimal, fastExponentiation, safeDiv } from '../src/utils import { FACTORY_ADDRESS, ONE_BD } from '../src/utils/constants' import { assertObjectMatches, - createTestPool, + invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, POOL_FEE_TIER_03, POOL_TICK_SPACING_03, @@ -62,7 +62,7 @@ const MINT_EVENT = new Mint( describe('handleMint', () => { beforeAll(() => { - createTestPool( + invokePoolCreatedWithMockedEthCalls( MOCK_EVENT, FACTORY_ADDRESS, USDC_MAINNET_FIXTURE, diff --git a/tests/handlePoolCreated.test.ts b/tests/handlePoolCreated.test.ts index 801a67f6..74fad2d4 100644 --- a/tests/handlePoolCreated.test.ts +++ b/tests/handlePoolCreated.test.ts @@ -8,7 +8,7 @@ import { StaticTokenDefinition } from '../src/utils/staticTokenDefinition' import { fetchTokenDecimals, fetchTokenName, fetchTokenSymbol, fetchTokenTotalSupply } from '../src/utils/token' import { assertObjectMatches, - createTestPool, + invokePoolCreatedWithMockedEthCalls, MOCK_EVENT, POOL_FEE_TIER_03, POOL_TICK_SPACING_03, @@ -24,7 +24,7 @@ describe('handlePoolCreated', () => { assert.notInStore('Token', USDC_MAINNET_FIXTURE.address) assert.notInStore('Token', USDC_MAINNET_FIXTURE.address) - createTestPool( + invokePoolCreatedWithMockedEthCalls( MOCK_EVENT, FACTORY_ADDRESS, USDC_MAINNET_FIXTURE, diff --git a/tests/intervalUpdates.test.ts b/tests/intervalUpdates.test.ts index 39d00932..120c4e1d 100644 --- a/tests/intervalUpdates.test.ts +++ b/tests/intervalUpdates.test.ts @@ -12,6 +12,8 @@ import { } from '../src/utils/intervalUpdates' import { assertObjectMatches, + createAndStoreTestPool, + createAndStoreTestToken, MOCK_EVENT, MOCK_EVENT as poolEvent, POOL_FEE_TIER_03, @@ -78,36 +80,12 @@ describe('uniswap interval data', () => { describe('pool interval data', () => { beforeEach(() => { clearStore() - - const pool = new Pool(USDC_WETH_03_MAINNET_POOL) - pool.createdAtTimestamp = ZERO_BI - pool.createdAtBlockNumber = ZERO_BI - pool.token0 = USDC_MAINNET_FIXTURE.address - pool.token1 = WETH_MAINNET_FIXTURE.address - pool.feeTier = BigInt.fromI32(POOL_FEE_TIER_03) - pool.liquidity = ZERO_BI - pool.sqrtPrice = ZERO_BI - pool.token0Price = ZERO_BD - pool.token1Price = ZERO_BD - pool.tick = ZERO_BI - pool.observationIndex = ZERO_BI - pool.volumeToken0 = ZERO_BD - pool.volumeToken1 = ZERO_BD - pool.volumeUSD = ZERO_BD - pool.untrackedVolumeUSD = ZERO_BD - pool.feesUSD = ZERO_BD - pool.txCount = ZERO_BI - pool.collectedFeesToken0 = ZERO_BD - pool.collectedFeesToken1 = ZERO_BD - pool.collectedFeesUSD = ZERO_BD - pool.totalValueLockedToken0 = ZERO_BD - pool.totalValueLockedToken1 = ZERO_BD - pool.totalValueLockedUSD = ZERO_BD - pool.totalValueLockedETH = ZERO_BD - pool.totalValueLockedUSDUntracked = ZERO_BD - pool.liquidityProviderCount = ZERO_BI - - pool.save() + createAndStoreTestPool( + USDC_WETH_03_MAINNET_POOL, + USDC_MAINNET_FIXTURE.address, + WETH_MAINNET_FIXTURE.address, + POOL_FEE_TIER_03, + ) }) test('success - create and update poolDayData', () => { @@ -299,24 +277,7 @@ describe('token interval data', () => { beforeEach(() => { clearStore() - const token = new Token(WETH_MAINNET_FIXTURE.address) - token.symbol = WETH_MAINNET_FIXTURE.symbol - token.name = WETH_MAINNET_FIXTURE.name - token.decimals = BigInt.fromString(WETH_MAINNET_FIXTURE.decimals) - token.totalSupply = BigInt.fromString(WETH_MAINNET_FIXTURE.totalSupply) - token.volume = ZERO_BD - token.volumeUSD = ZERO_BD - token.untrackedVolumeUSD = ZERO_BD - token.feesUSD = ZERO_BD - token.txCount = ZERO_BI - token.poolCount = ZERO_BI - token.totalValueLocked = ZERO_BD - token.totalValueLockedUSD = ZERO_BD - token.totalValueLockedUSDUntracked = ZERO_BD - token.derivedETH = ZERO_BD - token.whitelistPools = [] - - token.save() + createAndStoreTestToken(WETH_MAINNET_FIXTURE) const bundle = new Bundle('1') bundle.ethPriceUSD = ZERO_BD