From da4a52d5fecbad87a8ea2d819f2a401c23d47980 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= <998369+prevostc@users.noreply.github.com> Date: Thu, 19 Dec 2024 19:56:48 +0100 Subject: [PATCH] Fix firstBlock and add check for negative balances --- bin/check-config.ts | 77 ++++++++++++++++++++++++++++++++++++--- config/avax.json | 2 +- config/base.json | 2 +- config/bsc.json | 2 +- config/fantom.json | 2 +- config/mantle.json | 2 +- config/moonbeam.json | 2 +- config/optimism.json | 2 +- config/zksync.json | 2 +- data/optimism_data.json | 6 +-- src/common/interaction.ts | 24 ++++++------ 11 files changed, 94 insertions(+), 29 deletions(-) diff --git a/bin/check-config.ts b/bin/check-config.ts index 1921102..e4a2869 100644 --- a/bin/check-config.ts +++ b/bin/check-config.ts @@ -489,14 +489,22 @@ async function main() { if (!result.ok) { console.error(`Failed to fetch data from subgraph: ${result.statusText}`) + console.error(await result.text()) continue } - const resultData = (await result.json()) as { - data: { - duplicate_config: { id: string }[] - none_config: { id: string }[] - } + const resultData = (await result.json()) as + | { + data: { + duplicate_config: { id: string }[] + none_config: { id: string }[] + } + } + | { errors: { location: string[]; message: string }[] } + + if ("errors" in resultData) { + console.error(`Failed to fetch data from subgraph: ${JSON.stringify(resultData.errors, null, 2)}`) + continue } for (const contract of resultData.data.duplicate_config) { @@ -511,6 +519,65 @@ async function main() { } } } + + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + // check that no balance is below 0, if that's the case that's probably because "firstBlock" is not set correctly + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// + for (const chain of uniqChains) { + const fs = require("fs") + if (!fs.existsSync(`./config/${chain}.json`)) { + continue + } + + const gql = `{ + tokens(where: {balances_: {amount_lt: 0}}) { + id + } + }` + + // only use the next version of the subgraph + const subgraphUrl = `https://api.goldsky.com/api/public/project_clu2walwem1qm01w40v3yhw1f/subgraphs/beefy-balances-${chain}/latest/gn` + const result = await fetch(subgraphUrl, { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ query: gql }), + }) + + if (!result.ok) { + console.error(`Failed to fetch data from subgraph: ${result.statusText}`) + console.error(await result.text()) + continue + } + + const resultData = (await result.json()) as + | { + data: { + tokens: { + id: string + }[] + } + } + | { errors: { location: string[]; message: string }[] } + + if ("errors" in resultData) { + console.error(`Failed to fetch data from subgraph: ${JSON.stringify(resultData.errors, null, 2)}`) + continue + } + + if (resultData.data.tokens.length > 0) { + const duneChain = chain === "bsc" ? "bnb" : chain === "avax" ? "avalanche_c" : chain + const duneQuery = ` + SELECT to, min(block_number) + FROM ${duneChain}.transactions + WHERE ${resultData.data.tokens.map((t) => `to = ${t.id}`).join("\n OR ")} + group by to + order by min(block_number) + ` + console.error(`${chain}: Found ${resultData.data.tokens.length} tokens with balances below 0, please fix firstBlock in config. + ${duneQuery} + `) + } + } } main() diff --git a/config/avax.json b/config/avax.json index 07a87af..0af9b03 100644 --- a/config/avax.json +++ b/config/avax.json @@ -3,7 +3,7 @@ "indexerHintPrune": 1000000, "shareTokenMintAddress": "0x0000000000000000000000000000000000000000", "burnAddress": "0x000000000000000000000000000000000000dead", - "firstBlock": 10097386, + "firstBlock": 591621, "clmManagerFactoryAddress": "0xAF393b8ded8b8C1bd0c8707f43E6972C9bF19EE5", "clmManagerFactoryStartBlock": 50895319, diff --git a/config/base.json b/config/base.json index 618afb4..12e2958 100644 --- a/config/base.json +++ b/config/base.json @@ -3,7 +3,7 @@ "indexerHintPrune": 3000000, "shareTokenMintAddress": "0x0000000000000000000000000000000000000000", "burnAddress": "0x000000000000000000000000000000000000dead", - "firstBlock": 10003201, + "firstBlock": 6082018, "clmManagerFactoryAddress": "0x7bC78990AC1ef0754CFdE935B2D84E9acF13ed29", "clmManagerFactoryStartBlock": 15530271, diff --git a/config/bsc.json b/config/bsc.json index d357250..cd1f1eb 100644 --- a/config/bsc.json +++ b/config/bsc.json @@ -3,7 +3,7 @@ "indexerHintPrune": 2000000, "shareTokenMintAddress": "0x0000000000000000000000000000000000000000", "burnAddress": "0x000000000000000000000000000000000000dead", - "firstBlock": 10052768, + "firstBlock": 1573192, "clmManagerFactoryAddress": "0xAe8b53413862984C4e10929D41735800E0A4EdF9", "clmManagerFactoryStartBlock": 40991490, diff --git a/config/fantom.json b/config/fantom.json index 9d4686d..d4982d4 100644 --- a/config/fantom.json +++ b/config/fantom.json @@ -3,7 +3,7 @@ "indexerHintPrune": 10000000, "shareTokenMintAddress": "0x0000000000000000000000000000000000000000", "burnAddress": "0x000000000000000000000000000000000000dead", - "firstBlock": 11532306, + "firstBlock": 5541765, "beefyClassicVaultFactoryAddress": "0x740ce0674af6eec113a435faa53b297536a3e89b", "beefyClassicVaultFactoryStartBlock": 54563817, diff --git a/config/mantle.json b/config/mantle.json index 5eb2223..da439f3 100644 --- a/config/mantle.json +++ b/config/mantle.json @@ -3,7 +3,7 @@ "indexerHintPrune": 3000000, "shareTokenMintAddress": "0x0000000000000000000000000000000000000000", "burnAddress": "0x000000000000000000000000000000000000dead", - "firstBlock": 48140585, + "firstBlock": 48135884, "clmManagerFactoryAddress": "0xfBf758dbe280bD988ba0E13713b40ff8cea8565E", "clmManagerFactoryStartBlock": 66470980, diff --git a/config/moonbeam.json b/config/moonbeam.json index ddf081a..c3c8299 100644 --- a/config/moonbeam.json +++ b/config/moonbeam.json @@ -3,7 +3,7 @@ "indexerHintPrune": 1200000, "shareTokenMintAddress": "0x0000000000000000000000000000000000000000", "burnAddress": "0x000000000000000000000000000000000000dead", - "firstBlock": 1099729, + "firstBlock": 389840, "clmManagerFactoryAddress": "0x168Da2e2c8a87a053135c49127afbD092E72c8c5", "clmManagerFactoryStartBlock": 6347542, diff --git a/config/optimism.json b/config/optimism.json index 7f9f8ae..1ecb85d 100644 --- a/config/optimism.json +++ b/config/optimism.json @@ -3,7 +3,7 @@ "indexerHintPrune": 3000000, "shareTokenMintAddress": "0x0000000000000000000000000000000000000000", "burnAddress": "0x000000000000000000000000000000000000dead", - "firstBlock": 100477090, + "firstBlock": 13334163, "clmManagerFactoryAddress": "0x55D0efec44ee905fC3e12CcB9f25bBd5ccE0ab9C", "clmManagerFactoryStartBlock": 121125456, diff --git a/config/zksync.json b/config/zksync.json index ab71594..c063b7b 100644 --- a/config/zksync.json +++ b/config/zksync.json @@ -3,7 +3,7 @@ "indexerHintPrune": 6000000, "shareTokenMintAddress": "0x0000000000000000000000000000000000000000", "burnAddress": "0x000000000000000000000000000000000000dead", - "firstBlock": 10766888, + "firstBlock": 2295741, "clmManagerFactoryAddress": "0x59c7EC7387A480c0a5d953fCb45513D01B94286D", "clmManagerFactoryStartBlock": 37399642, diff --git a/data/optimism_data.json b/data/optimism_data.json index 999ef50..a378271 100644 --- a/data/optimism_data.json +++ b/data/optimism_data.json @@ -72,9 +72,5 @@ "0xfc7a31e1c5c3846d36e49223fae905e28315c1e0", "0xff504594edd93e09309d5eab775e7c35f642931b" ], - "no_factory_boosts": [ - "0x4200000000000000000000000000000000000042", - "0xcdb4bb51801a1f399d4402c61bc098a72c382e65", - "0xfdb794692724153d1488ccdbe0c56c252596735f" - ] + "no_factory_boosts": ["0xcdb4bb51801a1f399d4402c61bc098a72c382e65", "0xfdb794692724153d1488ccdbe0c56c252596735f"] } diff --git a/src/common/interaction.ts b/src/common/interaction.ts index acf3133..18c7ee0 100644 --- a/src/common/interaction.ts +++ b/src/common/interaction.ts @@ -9,27 +9,29 @@ import { ZERO_BI } from "./utils/decimal" import { fetchAndSaveTokenData } from "./utils/token" export function handleProductTransfer(event: TransferEvent): void { - if (event.params.value.equals(ZERO_BI)) { + const tokenAddress = event.address + const transferAmount = event.params.value + const sender = event.params.from + const receiver = event.params.to + + if (transferAmount.equals(ZERO_BI)) { log.debug("Ignoring transfer with zero value: {}", [event.transaction.hash.toHexString()]) return } - const tokenAddress = event.address fetchAndSaveTokenData(tokenAddress) const statistic = getTokenStatistic(tokenAddress) - if (event.params.from.notEqual(SHARE_TOKEN_MINT_ADDRESS) && event.params.from.notEqual(BURN_ADDRESS)) { - const holder = event.params.from - const rawAmountDiff = event.params.value.neg() - const amountDiff = shouldIgnoreContract(holder) ? ZERO_BI : event.params.value.neg() - const balDiff = updateAccountBalance(tokenAddress, holder, amountDiff, rawAmountDiff) + if (sender.notEqual(SHARE_TOKEN_MINT_ADDRESS) && sender.notEqual(BURN_ADDRESS)) { + const rawAmountDiff = transferAmount.neg() + const amountDiff = shouldIgnoreContract(sender) ? ZERO_BI : rawAmountDiff + const balDiff = updateAccountBalance(tokenAddress, sender, amountDiff, rawAmountDiff) statistic.holderCount = statistic.holderCount.plus(balDiff.holderCountChange()) } - if (event.params.to.notEqual(SHARE_TOKEN_MINT_ADDRESS) && event.params.to.notEqual(BURN_ADDRESS)) { - const receiver = event.params.to - const rawAmountDiff = event.params.value - const amountDiff = shouldIgnoreContract(receiver) ? ZERO_BI : event.params.value + if (receiver.notEqual(SHARE_TOKEN_MINT_ADDRESS) && receiver.notEqual(BURN_ADDRESS)) { + const rawAmountDiff = transferAmount + const amountDiff = shouldIgnoreContract(receiver) ? ZERO_BI : rawAmountDiff const balDiff = updateAccountBalance(tokenAddress, receiver, amountDiff, rawAmountDiff) statistic.holderCount = statistic.holderCount.plus(balDiff.holderCountChange()) }