Skip to content

Commit

Permalink
Fix firstBlock and add check for negative balances
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Dec 19, 2024
1 parent e7663fa commit da4a52d
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 29 deletions.
77 changes: 72 additions & 5 deletions bin/check-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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()
2 changes: 1 addition & 1 deletion config/avax.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"indexerHintPrune": 1000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 10097386,
"firstBlock": 591621,

"clmManagerFactoryAddress": "0xAF393b8ded8b8C1bd0c8707f43E6972C9bF19EE5",
"clmManagerFactoryStartBlock": 50895319,
Expand Down
2 changes: 1 addition & 1 deletion config/base.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"indexerHintPrune": 3000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 10003201,
"firstBlock": 6082018,

"clmManagerFactoryAddress": "0x7bC78990AC1ef0754CFdE935B2D84E9acF13ed29",
"clmManagerFactoryStartBlock": 15530271,
Expand Down
2 changes: 1 addition & 1 deletion config/bsc.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"indexerHintPrune": 2000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 10052768,
"firstBlock": 1573192,

"clmManagerFactoryAddress": "0xAe8b53413862984C4e10929D41735800E0A4EdF9",
"clmManagerFactoryStartBlock": 40991490,
Expand Down
2 changes: 1 addition & 1 deletion config/fantom.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"indexerHintPrune": 10000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 11532306,
"firstBlock": 5541765,

"beefyClassicVaultFactoryAddress": "0x740ce0674af6eec113a435faa53b297536a3e89b",
"beefyClassicVaultFactoryStartBlock": 54563817,
Expand Down
2 changes: 1 addition & 1 deletion config/mantle.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"indexerHintPrune": 3000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 48140585,
"firstBlock": 48135884,

"clmManagerFactoryAddress": "0xfBf758dbe280bD988ba0E13713b40ff8cea8565E",
"clmManagerFactoryStartBlock": 66470980,
Expand Down
2 changes: 1 addition & 1 deletion config/moonbeam.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"indexerHintPrune": 1200000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 1099729,
"firstBlock": 389840,

"clmManagerFactoryAddress": "0x168Da2e2c8a87a053135c49127afbD092E72c8c5",
"clmManagerFactoryStartBlock": 6347542,
Expand Down
2 changes: 1 addition & 1 deletion config/optimism.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"indexerHintPrune": 3000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 100477090,
"firstBlock": 13334163,

"clmManagerFactoryAddress": "0x55D0efec44ee905fC3e12CcB9f25bBd5ccE0ab9C",
"clmManagerFactoryStartBlock": 121125456,
Expand Down
2 changes: 1 addition & 1 deletion config/zksync.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"indexerHintPrune": 6000000,
"shareTokenMintAddress": "0x0000000000000000000000000000000000000000",
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 10766888,
"firstBlock": 2295741,

"clmManagerFactoryAddress": "0x59c7EC7387A480c0a5d953fCb45513D01B94286D",
"clmManagerFactoryStartBlock": 37399642,
Expand Down
6 changes: 1 addition & 5 deletions data/optimism_data.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,5 @@
"0xfc7a31e1c5c3846d36e49223fae905e28315c1e0",
"0xff504594edd93e09309d5eab775e7c35f642931b"
],
"no_factory_boosts": [
"0x4200000000000000000000000000000000000042",
"0xcdb4bb51801a1f399d4402c61bc098a72c382e65",
"0xfdb794692724153d1488ccdbe0c56c252596735f"
]
"no_factory_boosts": ["0xcdb4bb51801a1f399d4402c61bc098a72c382e65", "0xfdb794692724153d1488ccdbe0c56c252596735f"]
}
24 changes: 13 additions & 11 deletions src/common/interaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down

0 comments on commit da4a52d

Please sign in to comment.