From 09a3f2ce48b568cfa05899dc91b72deba2feeab2 Mon Sep 17 00:00:00 2001 From: Data-Nexus Date: Sun, 4 Feb 2024 15:16:29 -0500 Subject: [PATCH 1/7] Upgrade graph-ts handle bad decimals --- abis/ERC20.json | 2 +- package.json | 4 +-- src/mappings/core.ts | 65 +++++++++++++++++++----------------- src/utils/index.ts | 22 +++--------- src/utils/intervalUpdates.ts | 12 +++---- src/utils/pricing.ts | 49 +++++++++++++++------------ src/utils/token.ts | 29 ++++++++-------- subgraph.yaml | 17 +++++----- 8 files changed, 101 insertions(+), 99 deletions(-) diff --git a/abis/ERC20.json b/abis/ERC20.json index 405d6b36..327c0fad 100644 --- a/abis/ERC20.json +++ b/abis/ERC20.json @@ -84,7 +84,7 @@ "outputs": [ { "name": "", - "type": "uint8" + "type": "uint32" } ], "payable": false, diff --git a/package.json b/package.json index 115777c8..9b9689dc 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ "watch-local": "graph deploy ianlapham/uniswap-v3 --watch --debug --node http://127.0.0.1:8020/ --ipfs http://localhost:5001" }, "devDependencies": { - "@graphprotocol/graph-cli": "^0.20.1", - "@graphprotocol/graph-ts": "^0.20.0", + "@graphprotocol/graph-cli": "^0.64.1", + "@graphprotocol/graph-ts": "^0.32.0", "@typescript-eslint/eslint-plugin": "^2.0.0", "@typescript-eslint/parser": "^2.0.0", "eslint": "^6.2.2", diff --git a/src/mappings/core.ts b/src/mappings/core.ts index 9c6da1ec..bf9e5285 100644 --- a/src/mappings/core.ts +++ b/src/mappings/core.ts @@ -1,7 +1,7 @@ /* eslint-disable prefer-const */ import { Bundle, Burn, Factory, Mint, Pool, Swap, Tick, Token } from '../types/schema' import { Pool as PoolABI } from '../types/Factory/Pool' -import { BigDecimal, BigInt, ethereum, } from '@graphprotocol/graph-ts' +import { BigDecimal, BigInt, ethereum } from '@graphprotocol/graph-ts' import { Burn as BurnEvent, Flash as FlashEvent, @@ -23,7 +23,7 @@ import { import { createTick, feeTierToTickSpacing } from '../utils/tick' export function handleInitialize(event: Initialize): void { - let pool = Pool.load(event.address.toHexString()) + let pool = Pool.load(event.address.toHexString())! pool.sqrtPrice = event.params.sqrtPriceX96 pool.tick = BigInt.fromI32(event.params.tick) // update token prices @@ -33,13 +33,13 @@ export function handleInitialize(event: Initialize): void { } export function handleMint(event: MintEvent): void { - let bundle = Bundle.load('1') + let bundle = Bundle.load('1')! let poolAddress = event.address.toHexString() - let pool = Pool.load(poolAddress) - let factory = Factory.load(FACTORY_ADDRESS) + let pool = Pool.load(poolAddress)! + let factory = Factory.load(FACTORY_ADDRESS)! - let token0 = Token.load(pool.token0) - let token1 = Token.load(pool.token1) + let token0 = Token.load(pool.token0)! + let token1 = Token.load(pool.token1)! let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals) let amount1 = convertTokenToDecimal(event.params.amount1, token1.decimals) @@ -145,18 +145,18 @@ export function handleMint(event: MintEvent): void { factory.save() mint.save() - updateTickFeeVarsAndSave(lowerTick!, event) - updateTickFeeVarsAndSave(upperTick!, event) + updateTickFeeVarsAndSave(lowerTick, event) + updateTickFeeVarsAndSave(upperTick, event) } export function handleBurn(event: BurnEvent): void { - let bundle = Bundle.load('1') + let bundle = Bundle.load('1')! let poolAddress = event.address.toHexString() - let pool = Pool.load(poolAddress) - let factory = Factory.load(FACTORY_ADDRESS) + let pool = Pool.load(poolAddress)! + let factory = Factory.load(FACTORY_ADDRESS)! - let token0 = Token.load(pool.token0) - let token1 = Token.load(pool.token1) + let token0 = Token.load(pool.token0)! + let token1 = Token.load(pool.token1)! let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals) let amount1 = convertTokenToDecimal(event.params.amount1, token1.decimals) @@ -226,12 +226,17 @@ export function handleBurn(event: BurnEvent): void { let upperTickId = poolAddress + '#' + BigInt.fromI32(event.params.tickUpper).toString() let lowerTick = Tick.load(lowerTickId) let upperTick = Tick.load(upperTickId) - let amount = event.params.amount - lowerTick.liquidityGross = lowerTick.liquidityGross.minus(amount) - lowerTick.liquidityNet = lowerTick.liquidityNet.minus(amount) - upperTick.liquidityGross = upperTick.liquidityGross.minus(amount) - upperTick.liquidityNet = upperTick.liquidityNet.plus(amount) + if (lowerTick && upperTick) { + let amount = event.params.amount + lowerTick.liquidityGross = lowerTick.liquidityGross.minus(amount) + lowerTick.liquidityNet = lowerTick.liquidityNet.minus(amount) + upperTick.liquidityGross = upperTick.liquidityGross.minus(amount) + upperTick.liquidityNet = upperTick.liquidityNet.plus(amount) + + updateTickFeeVarsAndSave(lowerTick, event) + updateTickFeeVarsAndSave(upperTick, event) + } updateUniswapDayData(event) updatePoolDayData(event) updatePoolHourData(event) @@ -239,8 +244,6 @@ export function handleBurn(event: BurnEvent): void { updateTokenDayData(token1 as Token, event) updateTokenHourData(token0 as Token, event) updateTokenHourData(token1 as Token, event) - updateTickFeeVarsAndSave(lowerTick!, event) - updateTickFeeVarsAndSave(upperTick!, event) token0.save() token1.save() @@ -250,17 +253,17 @@ export function handleBurn(event: BurnEvent): void { } export function handleSwap(event: SwapEvent): void { - let bundle = Bundle.load('1') - let factory = Factory.load(FACTORY_ADDRESS) - let pool = Pool.load(event.address.toHexString()) + let bundle = Bundle.load('1')! + let factory = Factory.load(FACTORY_ADDRESS)! + let pool = Pool.load(event.address.toHexString())! // hot fix for bad pricing if (pool.id == '0x9663f2ca0454accad3e094448ea6f77443880454') { return } - let token0 = Token.load(pool.token0) - let token1 = Token.load(pool.token1) + let token0 = Token.load(pool.token0)! + let token1 = Token.load(pool.token1)! // amounts - 0/1 are token deltas: can be positive or negative let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals) @@ -429,6 +432,7 @@ export function handleSwap(event: SwapEvent): void { token1DayData.save() uniswapDayData.save() poolDayData.save() + poolHourData.save() factory.save() pool.save() token0.save() @@ -469,7 +473,8 @@ export function handleSwap(event: SwapEvent): void { export function handleFlash(event: FlashEvent): void { // update fee growth - let pool = Pool.load(event.address.toHexString()) + + let pool = Pool.load(event.address.toHexString())! pool.save() } @@ -482,7 +487,7 @@ function updateTickFeeVarsAndSave(tick: Tick, event: ethereum.Event): void { // tick.feeGrowthOutside1X128 = tickResult.value3 tick.save() - updateTickDayData(tick!, event) + updateTickDayData(tick, event) } function loadTickUpdateFeeVarsAndSave(tickId: i32, event: ethereum.Event): void { @@ -494,6 +499,6 @@ function loadTickUpdateFeeVarsAndSave(tickId: i32, event: ethereum.Event): void .concat(tickId.toString()) ) if (tick !== null) { - updateTickFeeVarsAndSave(tick!, event) + updateTickFeeVarsAndSave(tick, event) } -} \ No newline at end of file +} diff --git a/src/utils/index.ts b/src/utils/index.ts index b4eb0b40..b25bf1d0 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1,7 +1,7 @@ /* eslint-disable prefer-const */ import { BigInt, BigDecimal, ethereum } from '@graphprotocol/graph-ts' import { Transaction } from '../types/schema' -import { ONE_BI, ZERO_BI, ZERO_BD, ONE_BD, TWO_BI, } from '../utils/constants' +import { ONE_BI, ZERO_BI, ZERO_BD, ONE_BD, TWO_BI } from '../utils/constants' export function exponentToBigDecimal(decimals: BigInt): BigDecimal { let bd = BigDecimal.fromString('1') @@ -24,25 +24,13 @@ export function bigDecimalExponated(value: BigDecimal, power: BigInt): BigDecima if (power.equals(ZERO_BI)) { return ONE_BD } - let negativePower = power.lt(ZERO_BI) - let evenPower = ZERO_BD.plus(value) + let result = ZERO_BD.plus(value) let powerAbs = power.abs() - let oddPower = ONE_BD - - while (powerAbs.lt(ONE_BI)) { - if (powerAbs % TWO_BI == ZERO_BI) { - evenPower = evenPower * evenPower - powerAbs = powerAbs/TWO_BI - } else { - oddPower = evenPower * oddPower - evenPower = evenPower * evenPower - powerAbs = (powerAbs - ONE_BI) / TWO_BI - } + for (let i = ONE_BI; i.lt(powerAbs); i = i.plus(ONE_BI)) { + result = result.times(value) } - let result = evenPower * oddPower - if (negativePower) { result = safeDiv(ONE_BD, result) } @@ -99,7 +87,7 @@ export function loadTransaction(event: ethereum.Event): Transaction { } transaction.blockNumber = event.block.number transaction.timestamp = event.block.timestamp - transaction.gasUsed = event.transaction.gasUsed + transaction.gasUsed = BigInt.zero() //needs to be moved to transaction receipt transaction.gasPrice = event.transaction.gasPrice transaction.save() return transaction as Transaction diff --git a/src/utils/intervalUpdates.ts b/src/utils/intervalUpdates.ts index d74c9500..486da9b6 100644 --- a/src/utils/intervalUpdates.ts +++ b/src/utils/intervalUpdates.ts @@ -21,7 +21,7 @@ import { ethereum } from '@graphprotocol/graph-ts' * @param event */ export function updateUniswapDayData(event: ethereum.Event): UniswapDayData { - let uniswap = Factory.load(FACTORY_ADDRESS) + let uniswap = Factory.load(FACTORY_ADDRESS)! let timestamp = event.block.timestamp.toI32() let dayID = timestamp / 86400 // rounded let dayStartTimestamp = dayID * 86400 @@ -48,8 +48,8 @@ export function updatePoolDayData(event: ethereum.Event): PoolDayData { .toHexString() .concat('-') .concat(dayID.toString()) - let pool = Pool.load(event.address.toHexString()) - let poolDayData = PoolDayData.load(dayPoolID) + let pool = Pool.load(event.address.toHexString())! + let poolDayData = PoolDayData.load(dayPoolID)! if (poolDayData === null) { poolDayData = new PoolDayData(dayPoolID) poolDayData.date = dayStartTimestamp @@ -93,7 +93,7 @@ export function updatePoolHourData(event: ethereum.Event): PoolHourData { .toHexString() .concat('-') .concat(hourIndex.toString()) - let pool = Pool.load(event.address.toHexString()) + let pool = Pool.load(event.address.toHexString())! let poolHourData = PoolHourData.load(hourPoolID) if (poolHourData === null) { poolHourData = new PoolHourData(hourPoolID) @@ -133,7 +133,7 @@ export function updatePoolHourData(event: ethereum.Event): PoolHourData { } export function updateTokenDayData(token: Token, event: ethereum.Event): TokenDayData { - let bundle = Bundle.load('1') + let bundle = Bundle.load('1')! let timestamp = event.block.timestamp.toI32() let dayID = timestamp / 86400 let dayStartTimestamp = dayID * 86400 @@ -176,7 +176,7 @@ export function updateTokenDayData(token: Token, event: ethereum.Event): TokenDa } export function updateTokenHourData(token: Token, event: ethereum.Event): TokenHourData { - let bundle = Bundle.load('1') + let bundle = Bundle.load('1')! let timestamp = event.block.timestamp.toI32() let hourIndex = timestamp / 3600 // get unique hour within unix history let hourStartUnix = hourIndex * 3600 // want the rounded effect diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index d6815ba3..4e5373e9 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -18,7 +18,8 @@ export let WHITELIST_TOKENS: string[] = [ let MINIMUM_ETH_LOCKED = BigDecimal.fromString('4') -let Q192 = 2 ** 192 +let Q192 = BigInt.fromI32(2).pow(192 as u8) + export function sqrtPriceX96ToTokenPrices(sqrtPriceX96: BigInt, token0: Token, token1: Token): BigDecimal[] { let num = sqrtPriceX96.times(sqrtPriceX96).toBigDecimal() let denom = BigDecimal.fromString(Q192.toString()) @@ -61,26 +62,32 @@ export function findEthPerToken(token: Token): BigDecimal { for (let i = 0; i < whiteList.length; ++i) { let poolAddress = whiteList[i] let pool = Pool.load(poolAddress) - if (pool.liquidity.gt(ZERO_BI)) { - if (pool.token0 == token.id) { - // whitelist token is token1 - let token1 = Token.load(pool.token1) - // get the derived ETH in pool - let ethLocked = pool.totalValueLockedToken1.times(token1.derivedETH) - if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(MINIMUM_ETH_LOCKED)) { - largestLiquidityETH = ethLocked - // token1 per our token * Eth per token1 - priceSoFar = pool.token1Price.times(token1.derivedETH as BigDecimal) + if (pool) { + if (pool.liquidity.gt(ZERO_BI)) { + if (pool.token0 == token.id) { + // whitelist token is token1 + let token1 = Token.load(pool.token1) + // get the derived ETH in pool + if (token1) { + let ethLocked = pool.totalValueLockedToken1.times(token1.derivedETH) + if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(MINIMUM_ETH_LOCKED)) { + largestLiquidityETH = ethLocked + // token1 per our token * Eth per token1 + priceSoFar = pool.token1Price.times(token1.derivedETH as BigDecimal) + } + } } - } - if (pool.token1 == token.id) { - let token0 = Token.load(pool.token0) - // get the derived ETH in pool - let ethLocked = pool.totalValueLockedToken0.times(token0.derivedETH) - if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(MINIMUM_ETH_LOCKED)) { - largestLiquidityETH = ethLocked - // token0 per our token * ETH per token0 - priceSoFar = pool.token0Price.times(token0.derivedETH as BigDecimal) + if (pool.token1 == token.id) { + let token0 = Token.load(pool.token0) + // get the derived ETH in pool + if (token0) { + let ethLocked = pool.totalValueLockedToken0.times(token0.derivedETH) + if (ethLocked.gt(largestLiquidityETH) && ethLocked.gt(MINIMUM_ETH_LOCKED)) { + largestLiquidityETH = ethLocked + // token0 per our token * ETH per token0 + priceSoFar = pool.token0Price.times(token0.derivedETH as BigDecimal) + } + } } } } @@ -100,7 +107,7 @@ export function getTrackedAmountUSD( tokenAmount1: BigDecimal, token1: Token ): BigDecimal { - let bundle = Bundle.load('1') + let bundle = Bundle.load('1')! let price0USD = token0.derivedETH.times(bundle.ethPriceUSD) let price1USD = token1.derivedETH.times(bundle.ethPriceUSD) diff --git a/src/utils/token.ts b/src/utils/token.ts index 2ede089a..2f3139cf 100644 --- a/src/utils/token.ts +++ b/src/utils/token.ts @@ -68,29 +68,30 @@ export function fetchTokenName(tokenAddress: Address): string { export function fetchTokenTotalSupply(tokenAddress: Address): BigInt { let contract = ERC20.bind(tokenAddress) - let totalSupplyValue = null + let totalSupplyValue = BigInt.zero() let totalSupplyResult = contract.try_totalSupply() if (!totalSupplyResult.reverted) { - totalSupplyValue = totalSupplyResult as i32 + totalSupplyValue = totalSupplyResult.value } - return BigInt.fromI32(totalSupplyValue as i32) + return totalSupplyValue } -export function fetchTokenDecimals(tokenAddress: Address): BigInt { +export function fetchTokenDecimals(tokenAddress: Address): BigInt | null { let contract = ERC20.bind(tokenAddress) // try types uint8 for decimals - let decimalValue = null - - // try with the static definition - let staticTokenDefinition = StaticTokenDefinition.fromAddress(tokenAddress) - if (staticTokenDefinition != null) { - return staticTokenDefinition.decimals - } - let decimalResult = contract.try_decimals() + if (!decimalResult.reverted) { - decimalValue = decimalResult.value + if (decimalResult.value.lt(BigInt.fromI32(255))) { + return decimalResult.value + } + } else { + // try with the static definition + let staticTokenDefinition = StaticTokenDefinition.fromAddress(tokenAddress) + if (staticTokenDefinition) { + return staticTokenDefinition.decimals + } } - return BigInt.fromI32(decimalValue as i32) + return null } diff --git a/subgraph.yaml b/subgraph.yaml index ffaae0ec..546eb5f3 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -1,13 +1,14 @@ -specVersion: 0.0.2 +specVersion: 0.0.4 description: A copy of Uniswap's Arbitrum subgraph -# graft: -# base: QmYrooNJpZZkpsMxG44wJgkbnSbEsT9B8wbStADdrydewT -# block: 5363973 +graft: + base: QmYrooNJpZZkpsMxG44wJgkbnSbEsT9B8wbStADdrydewT + block: 177453017 repository: https://github.com/vintageplayer/v3-subgraph schema: file: ./schema.graphql features: - nonFatalErrors + - grafting dataSources: - kind: ethereum/contract name: Factory @@ -18,7 +19,7 @@ dataSources: startBlock: 175 mapping: kind: ethereum/events - apiVersion: 0.0.4 + apiVersion: 0.0.7 language: wasm/assemblyscript file: ./src/mappings/factory.ts entities: @@ -46,7 +47,7 @@ templates: abi: Pool mapping: kind: ethereum/events - apiVersion: 0.0.4 + apiVersion: 0.0.7 language: wasm/assemblyscript file: ./src/mappings/core.ts entities: @@ -68,5 +69,5 @@ templates: handler: handleMint - event: Burn(indexed address,indexed int24,indexed int24,uint128,uint256,uint256) handler: handleBurn - - event: Flash(indexed address,indexed address,uint256,uint256,uint256,uint256) - handler: handleFlash + # - event: Flash(indexed address,indexed address,uint256,uint256,uint256,uint256) + # handler: handleFlash From fd039d5f07ecaeabc7601408a8a37332fa733f6b Mon Sep 17 00:00:00 2001 From: Data-Nexus Date: Mon, 5 Feb 2024 11:47:12 -0500 Subject: [PATCH 2/7] Added missing feeTier --- src/utils/tick.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/utils/tick.ts b/src/utils/tick.ts index 07763093..779c0c64 100644 --- a/src/utils/tick.ts +++ b/src/utils/tick.ts @@ -48,6 +48,9 @@ export function feeTierToTickSpacing(feeTier: BigInt): BigInt { if (feeTier.equals(BigInt.fromI32(500))) { return BigInt.fromI32(10) } + if (feeTier.equals(BigInt.fromI32(100))) { + return BigInt.fromI32(1) + } throw Error('Unexpected fee tier') } From 03c4a3ebd7312777d7b703d6748b8d6c5b4ad825 Mon Sep 17 00:00:00 2001 From: Data-Nexus Date: Mon, 5 Feb 2024 11:59:39 -0500 Subject: [PATCH 3/7] Update MIN_ETH_LOCKED --- src/utils/pricing.ts | 2 +- subgraph.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/pricing.ts b/src/utils/pricing.ts index 4e5373e9..c9954f54 100644 --- a/src/utils/pricing.ts +++ b/src/utils/pricing.ts @@ -16,7 +16,7 @@ export let WHITELIST_TOKENS: string[] = [ '0xfd086bc7cd5c481dcc9c85ebe478a1c0b69fcbb9' // USDT ] -let MINIMUM_ETH_LOCKED = BigDecimal.fromString('4') +let MINIMUM_ETH_LOCKED = BigDecimal.fromString('60') let Q192 = BigInt.fromI32(2).pow(192 as u8) diff --git a/subgraph.yaml b/subgraph.yaml index 546eb5f3..88d11822 100644 --- a/subgraph.yaml +++ b/subgraph.yaml @@ -2,7 +2,7 @@ specVersion: 0.0.4 description: A copy of Uniswap's Arbitrum subgraph graft: base: QmYrooNJpZZkpsMxG44wJgkbnSbEsT9B8wbStADdrydewT - block: 177453017 + block: 174340000 repository: https://github.com/vintageplayer/v3-subgraph schema: file: ./schema.graphql From 73d419f048b44682400c5e3cb87cc1c8222bd0f4 Mon Sep 17 00:00:00 2001 From: Data-Nexus Date: Tue, 6 Feb 2024 11:52:44 -0500 Subject: [PATCH 4/7] Fixed nullable load --- src/utils/intervalUpdates.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils/intervalUpdates.ts b/src/utils/intervalUpdates.ts index 486da9b6..36fdcf68 100644 --- a/src/utils/intervalUpdates.ts +++ b/src/utils/intervalUpdates.ts @@ -49,7 +49,7 @@ export function updatePoolDayData(event: ethereum.Event): PoolDayData { .concat('-') .concat(dayID.toString()) let pool = Pool.load(event.address.toHexString())! - let poolDayData = PoolDayData.load(dayPoolID)! + let poolDayData = PoolDayData.load(dayPoolID) if (poolDayData === null) { poolDayData = new PoolDayData(dayPoolID) poolDayData.date = dayStartTimestamp From 81f82f3d0e7a41daa1ee062bdc1f1ad487d07d7e Mon Sep 17 00:00:00 2001 From: Data-Nexus Date: Wed, 7 Feb 2024 13:55:41 -0500 Subject: [PATCH 5/7] fixed holey array --- src/utils/staticTokenDefinition.ts | 34 ++++++++++++------------------ 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/src/utils/staticTokenDefinition.ts b/src/utils/staticTokenDefinition.ts index 96aaec5d..e920c615 100644 --- a/src/utils/staticTokenDefinition.ts +++ b/src/utils/staticTokenDefinition.ts @@ -18,26 +18,20 @@ export class StaticTokenDefinition { // Get all tokens with a static defintion static getStaticDefinitions(): Array { - let staticDefinitions = new Array(6) - - // Add WETH - let tokenWETH = new StaticTokenDefinition( - Address.fromString('0x82af49447d8a07e3bd95bd0d56f35241523fbab1'), - 'WETH', - 'Wrapped Ethereum', - BigInt.fromI32(18) - ) - staticDefinitions.push(tokenWETH) - - // USDC - let tokenUSDC = new StaticTokenDefinition( - Address.fromString('0xff970a61a04b1ca14834a43f5de4533ebddb5cc8'), - 'USDC', - 'USD Coin', - BigInt.fromI32(6) - ) - staticDefinitions.push(tokenUSDC) - + const staticDefinitions: Array = [ + { + 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) + } + ] return staticDefinitions } From fc52c79e432df021b0c934c372ced4dfc434a40d Mon Sep 17 00:00:00 2001 From: Data-Nexus Date: Wed, 7 Feb 2024 14:01:11 -0500 Subject: [PATCH 6/7] holey array fix --- src/utils/staticTokenDefinition.ts | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/utils/staticTokenDefinition.ts b/src/utils/staticTokenDefinition.ts index e920c615..c0e4829d 100644 --- a/src/utils/staticTokenDefinition.ts +++ b/src/utils/staticTokenDefinition.ts @@ -8,14 +8,6 @@ export class StaticTokenDefinition { name: string decimals: BigInt - // Initialize a Token Definition with its attributes - constructor(address: Address, symbol: string, name: string, decimals: BigInt) { - this.address = address - this.symbol = symbol - this.name = name - this.decimals = decimals - } - // Get all tokens with a static defintion static getStaticDefinitions(): Array { const staticDefinitions: Array = [ From e029aec827f8c8cfec83fc2505eedc9b5fe6df28 Mon Sep 17 00:00:00 2001 From: Data-Nexus Date: Thu, 8 Feb 2024 23:10:23 -0500 Subject: [PATCH 7/7] Fix required tick --- src/mappings/core.ts | 44 +++++++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 21 deletions(-) diff --git a/src/mappings/core.ts b/src/mappings/core.ts index bf9e5285..d0f836a8 100644 --- a/src/mappings/core.ts +++ b/src/mappings/core.ts @@ -269,7 +269,7 @@ export function handleSwap(event: SwapEvent): void { let amount0 = convertTokenToDecimal(event.params.amount0, token0.decimals) let amount1 = convertTokenToDecimal(event.params.amount1, token1.decimals) - let oldTick = pool.tick! + let oldTick = pool.tick // need absolute amounts for volume let amount0Abs = amount0 @@ -447,26 +447,28 @@ export function handleSwap(event: SwapEvent): void { loadTickUpdateFeeVarsAndSave(newTick.toI32(), event) } - let numIters = oldTick - .minus(newTick) - .abs() - .div(tickSpacing) - - if (numIters.gt(BigInt.fromI32(100))) { - // In case more than 100 ticks need to be updated ignore the update in - // order to avoid timeouts. From testing this behavior occurs only upon - // pool initialization. This should not be a big issue as the ticks get - // updated later. For early users this error also disappears when calling - // collect - } else if (newTick.gt(oldTick)) { - let firstInitialized = oldTick.plus(tickSpacing.minus(modulo)) - for (let i = firstInitialized; i.le(newTick); i = i.plus(tickSpacing)) { - loadTickUpdateFeeVarsAndSave(i.toI32(), event) - } - } else if (newTick.lt(oldTick)) { - let firstInitialized = oldTick.minus(modulo) - for (let i = firstInitialized; i.ge(newTick); i = i.minus(tickSpacing)) { - loadTickUpdateFeeVarsAndSave(i.toI32(), event) + if (oldTick) { + let numIters = oldTick + .minus(newTick) + .abs() + .div(tickSpacing) + + if (numIters.gt(BigInt.fromI32(100))) { + // In case more than 100 ticks need to be updated ignore the update in + // order to avoid timeouts. From testing this behavior occurs only upon + // pool initialization. This should not be a big issue as the ticks get + // updated later. For early users this error also disappears when calling + // collect + } else if (newTick.gt(oldTick)) { + let firstInitialized = oldTick.plus(tickSpacing.minus(modulo)) + for (let i = firstInitialized; i.le(newTick); i = i.plus(tickSpacing)) { + loadTickUpdateFeeVarsAndSave(i.toI32(), event) + } + } else if (newTick.lt(oldTick)) { + let firstInitialized = oldTick.minus(modulo) + for (let i = firstInitialized; i.ge(newTick); i = i.minus(tickSpacing)) { + loadTickUpdateFeeVarsAndSave(i.toI32(), event) + } } } }