@@ -339,30 +339,30 @@ async function main() {
339
339
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
340
340
// // write data files with missing holder counts
341
341
// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
342
- // for (const chain of Object.keys(dataFileContentPerChain)) {
343
- // const fs = require("fs")
342
+ for ( const chain of Object . keys ( dataFileContentPerChain ) ) {
343
+ const fs = require ( "fs" )
344
344
345
- // // only if the chain has a config file
346
- // if (!fs.existsSync(`./config/${chain}.json`)) {
347
- // continue
348
- // }
345
+ // only if the chain has a config file
346
+ if ( ! fs . existsSync ( `./config/${ chain } .json` ) ) {
347
+ continue
348
+ }
349
349
350
- // const targetFile = `./data/${chain}_data.json`
351
- // const dataFileContent = dataFileContentPerChain[chain]
352
- // const existingDataFileContentIfAny = fs.existsSync(targetFile)
353
- // ? JSON.parse(fs.readFileSync(targetFile, "utf8"))
354
- // : { no_factory_vaults: [], no_factory_boosts: [] }
350
+ const targetFile = `./data/${ chain } _data.json`
351
+ const dataFileContent = dataFileContentPerChain [ chain ]
352
+ const existingDataFileContentIfAny = fs . existsSync ( targetFile )
353
+ ? JSON . parse ( fs . readFileSync ( targetFile , "utf8" ) )
354
+ : { no_factory_vaults : [ ] , no_factory_boosts : [ ] }
355
355
356
- // dataFileContent.no_factory_vaults = dataFileContent.no_factory_vaults.concat(existingDataFileContentIfAny.no_factory_vaults)
357
- // dataFileContent.no_factory_boosts = dataFileContent.no_factory_boosts.concat(existingDataFileContentIfAny.no_factory_boosts)
358
- // dataFileContent.no_factory_vaults = Array.from(new Set(dataFileContent.no_factory_vaults))
359
- // dataFileContent.no_factory_boosts = Array.from(new Set(dataFileContent.no_factory_boosts))
356
+ dataFileContent . no_factory_vaults = dataFileContent . no_factory_vaults . concat ( existingDataFileContentIfAny . no_factory_vaults )
357
+ dataFileContent . no_factory_boosts = dataFileContent . no_factory_boosts . concat ( existingDataFileContentIfAny . no_factory_boosts )
358
+ dataFileContent . no_factory_vaults = Array . from ( new Set ( dataFileContent . no_factory_vaults ) )
359
+ dataFileContent . no_factory_boosts = Array . from ( new Set ( dataFileContent . no_factory_boosts ) )
360
360
361
- // dataFileContent.no_factory_vaults.sort()
362
- // dataFileContent.no_factory_boosts.sort()
361
+ dataFileContent . no_factory_vaults . sort ( )
362
+ dataFileContent . no_factory_boosts . sort ( )
363
363
364
- // fs.writeFileSync(targetFile, JSON.stringify(dataFileContent, null, 2))
365
- // }
364
+ fs . writeFileSync ( targetFile , JSON . stringify ( dataFileContent , null , 2 ) )
365
+ }
366
366
367
367
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
368
368
// display top 30 missing TVL to focus on the most important vaults
@@ -488,7 +488,7 @@ async function main() {
488
488
} )
489
489
490
490
if ( ! result . ok ) {
491
- console . error ( `Failed to fetch data from subgraph: ${ result . statusText } ` )
491
+ console . error ( `Failed to fetch data from ${ subgraphUrl } subgraph ${ chain } ( ${ result . statusText } ): ${ gql } ` )
492
492
console . error ( await result . text ( ) )
493
493
continue
494
494
}
@@ -503,7 +503,8 @@ async function main() {
503
503
| { errors : { location : string [ ] ; message : string } [ ] }
504
504
505
505
if ( "errors" in resultData ) {
506
- console . error ( `Failed to fetch data from subgraph: ${ JSON . stringify ( resultData . errors , null , 2 ) } ` )
506
+ console . error ( `Failed to fetch data from ${ subgraphUrl } subgraph ${ chain } (${ result . statusText } ): ${ gql } ` )
507
+ console . error ( JSON . stringify ( resultData . errors , null , 2 ) )
507
508
continue
508
509
}
509
510
@@ -530,8 +531,12 @@ async function main() {
530
531
}
531
532
532
533
const gql = `{
533
- tokens(where: {balances_: {rawAmount_lt: 0}}) {
534
- id
534
+ tokenBalances(where: {rawAmount_lt: 0}, skip: 0, first: 1000) {
535
+ token {
536
+ id
537
+ }
538
+ amount
539
+ rawAmount
535
540
}
536
541
}`
537
542
@@ -544,36 +549,43 @@ async function main() {
544
549
} )
545
550
546
551
if ( ! result . ok ) {
547
- console . error ( `Failed to fetch data from subgraph ${ chain } : ${ result . statusText } ` )
552
+ console . error ( `Failed to fetch data from ${ subgraphUrl } subgraph ${ chain } ( ${ result . statusText } ): ${ gql } ` )
548
553
console . error ( await result . text ( ) )
549
554
continue
550
555
}
551
556
552
557
const resultData = ( await result . json ( ) ) as
553
558
| {
554
559
data : {
555
- tokens : {
556
- id : string
560
+ tokenBalances : {
561
+ token : {
562
+ id : string
563
+ }
564
+ amount : string
565
+ rawAmount : string
557
566
} [ ]
558
567
}
559
568
}
560
569
| { errors : { location : string [ ] ; message : string } [ ] }
561
570
562
571
if ( "errors" in resultData ) {
563
- console . error ( `Failed to fetch data from subgraph: ${ JSON . stringify ( resultData . errors , null , 2 ) } ` )
572
+ console . error ( `Failed to fetch data from ${ subgraphUrl } subgraph ${ chain } (${ result . statusText } ): ${ gql } ` )
573
+ console . error ( JSON . stringify ( resultData . errors , null , 2 ) )
564
574
continue
565
575
}
566
576
567
- if ( resultData . data . tokens . length > 0 ) {
577
+ if ( resultData . data . tokenBalances . length > 0 ) {
568
578
const duneChain = chain === "bsc" ? "bnb" : chain === "avax" ? "avalanche_c" : chain
569
579
const duneQuery = `
570
580
SELECT to, min(block_number)
571
581
FROM ${ duneChain } .transactions
572
- WHERE ${ resultData . data . tokens . map ( ( t ) => `to = ${ t . id } ` ) . join ( "\n OR " ) }
582
+ WHERE ${ uniq ( resultData . data . tokenBalances . map ( ( t ) => t . token . id ) )
583
+ . map ( ( t ) => `to = ${ t } ` )
584
+ . join ( "\n OR " ) }
573
585
group by to
574
586
order by min(block_number)
575
587
`
576
- console . error ( `${ chain } : Found ${ resultData . data . tokens . length } tokens with balances below 0, please fix firstBlock in config.
588
+ console . error ( `${ chain } : Found ${ resultData . data . tokenBalances . length } token balances with balances below 0, please fix firstBlock in config.
577
589
${ duneQuery }
578
590
` )
579
591
}
0 commit comments