|
1 |
| -import { groupBy } from "lodash" |
| 1 | +import { chain, groupBy } from "lodash" |
| 2 | +import { addressBook, Chain as AddressBookChain } from "blockchain-addressbook" |
2 | 3 |
|
3 | 4 | type Hex = `0x${string}`
|
4 | 5 |
|
@@ -269,74 +270,161 @@ async function main() {
|
269 | 270 |
|
270 | 271 | const dataFileContentPerChain = {} as any
|
271 | 272 |
|
| 273 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
272 | 274 | // check for missing holder counts
|
| 275 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
273 | 276 | const missingHolderCounts: BeefyVault[] = []
|
274 | 277 | for (const vault of allConfigs) {
|
275 | 278 | const subgraphchain = vault.chain === "one" ? "harmony" : vault.chain
|
276 |
| - dataFileContentPerChain[subgraphchain] = dataFileContentPerChain[subgraphchain] || { old_vaults: [], old_boosts: [] } |
| 279 | + dataFileContentPerChain[subgraphchain] = dataFileContentPerChain[subgraphchain] || { no_factory_vaults: [], no_factory_boosts: [] } |
277 | 280 |
|
278 | 281 | const level = vault.eol ? "ERROR" : "WARN"
|
279 | 282 | if (!countsPerToken[`${subgraphchain}:${vault.vault_address}`]) {
|
280 |
| - console.error(`${level}: Missing holder count for ${vault.id} with address ${subgraphchain}:${vault.vault_address}`) |
| 283 | + console.error( |
| 284 | + `${level}: Missing holder count in balance api for ${vault.chain}:${vault.id} with address ${subgraphchain}:${vault.vault_address}`, |
| 285 | + ) |
281 | 286 | missingHolderCounts.push(vault)
|
282 |
| - dataFileContentPerChain[subgraphchain].old_vaults.push(vault.vault_address) |
| 287 | + dataFileContentPerChain[subgraphchain].no_factory_vaults.push(vault.vault_address) |
283 | 288 | }
|
284 | 289 | if (vault.protocol_type === "beefy_clm_vault") {
|
285 | 290 | if (!countsPerToken[`${subgraphchain}:${vault.beefy_clm_manager.vault_address}`]) {
|
286 |
| - console.error(`${level}: Missing holder count for ${vault.id} with CLM address ${subgraphchain}:${vault.beefy_clm_manager.vault_address}`) |
| 291 | + console.error( |
| 292 | + `${level}: Missing holder count in balance api for ${vault.chain}:${vault.id} with CLM address ${subgraphchain}:${vault.beefy_clm_manager.vault_address}`, |
| 293 | + ) |
287 | 294 | missingHolderCounts.push(vault)
|
288 |
| - dataFileContentPerChain[subgraphchain].old_vaults.push(vault.beefy_clm_manager.vault_address) |
| 295 | + dataFileContentPerChain[subgraphchain].no_factory_vaults.push(vault.beefy_clm_manager.vault_address) |
289 | 296 | }
|
290 | 297 | }
|
291 | 298 | for (const pool of vault.reward_pools) {
|
292 | 299 | if (!countsPerToken[`${subgraphchain}:${pool.clm_address}`]) {
|
293 |
| - console.error(`${level}: Missing holder count for ${vault.id}'s Reward Pool with address ${subgraphchain}:${pool.reward_pool_address}`) |
| 300 | + console.error( |
| 301 | + `${level}: Missing holder count in balance api for ${vault.chain}:${vault.id}'s Reward Pool with address ${subgraphchain}:${pool.reward_pool_address}`, |
| 302 | + ) |
294 | 303 | missingHolderCounts.push(vault)
|
295 |
| - dataFileContentPerChain[subgraphchain].old_boosts.push(pool.reward_pool_address) |
| 304 | + dataFileContentPerChain[subgraphchain].no_factory_boosts.push(pool.reward_pool_address) |
296 | 305 | }
|
297 | 306 | }
|
298 | 307 | for (const boost of vault.boosts) {
|
299 | 308 | if (!countsPerToken[`${subgraphchain}:${boost.underlying_address}`]) {
|
300 |
| - console.error(`${level}: Missing holder count for ${vault.id}'s BOOST with address ${subgraphchain}:${boost.boost_address}`) |
| 309 | + console.error( |
| 310 | + `${level}: Missing holder count in balance api for ${vault.chain}:${vault.id}'s BOOST with address ${subgraphchain}:${boost.boost_address}`, |
| 311 | + ) |
301 | 312 | missingHolderCounts.push(vault)
|
302 |
| - dataFileContentPerChain[subgraphchain].old_boosts.push(boost.boost_address) |
| 313 | + dataFileContentPerChain[subgraphchain].no_factory_boosts.push(boost.boost_address) |
303 | 314 | }
|
304 | 315 | }
|
305 | 316 | }
|
306 | 317 |
|
307 |
| - // write data files |
308 |
| - for (const chain of Object.keys(dataFileContentPerChain)) { |
| 318 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 319 | + // write data files with missing holder counts |
| 320 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 321 | + // for (const chain of Object.keys(dataFileContentPerChain)) { |
| 322 | + // const fs = require("fs") |
| 323 | + |
| 324 | + // // only if the chain has a config file |
| 325 | + // if (!fs.existsSync(`./config/${chain}.json`)) { |
| 326 | + // continue |
| 327 | + // } |
| 328 | + |
| 329 | + // const targetFile = `./data/${chain}_data.json` |
| 330 | + // const dataFileContent = dataFileContentPerChain[chain] |
| 331 | + // const existingDataFileContentIfAny = fs.existsSync(targetFile) |
| 332 | + // ? JSON.parse(fs.readFileSync(targetFile, "utf8")) |
| 333 | + // : { no_factory_vaults: [], no_factory_boosts: [] } |
| 334 | + |
| 335 | + // dataFileContent.no_factory_vaults = dataFileContent.no_factory_vaults.concat(existingDataFileContentIfAny.no_factory_vaults) |
| 336 | + // dataFileContent.no_factory_boosts = dataFileContent.no_factory_boosts.concat(existingDataFileContentIfAny.no_factory_boosts) |
| 337 | + // dataFileContent.no_factory_vaults = Array.from(new Set(dataFileContent.no_factory_vaults)) |
| 338 | + // dataFileContent.no_factory_boosts = Array.from(new Set(dataFileContent.no_factory_boosts)) |
| 339 | + |
| 340 | + // dataFileContent.no_factory_vaults.sort() |
| 341 | + // dataFileContent.no_factory_boosts.sort() |
| 342 | + |
| 343 | + // fs.writeFileSync(targetFile, JSON.stringify(dataFileContent, null, 2)) |
| 344 | + // } |
| 345 | + |
| 346 | + // // display top 30 missing TVL to focus on the most important vaults |
| 347 | + // missingHolderCounts.sort((a, b) => b.tvl - a.tvl) |
| 348 | + // console.error(`\n\nMissing TVL for top 30 vaults:`) |
| 349 | + // missingHolderCounts.slice(0, 100).forEach((v) => { |
| 350 | + // const level = v.eol ? "ERROR" : "WARN" |
| 351 | + // console.error(`${level}: Missing TVL for ${v.chain}:${v.id}:${v.vault_address}: ${v.tvl}`) |
| 352 | + // }) |
| 353 | + |
| 354 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 355 | + // check that the chain config contains all the factory addresses in the addressbook |
| 356 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 357 | + const uniqChains = Array.from(new Set(allConfigs.map((v) => v.chain))) |
| 358 | + for (const chain of uniqChains) { |
309 | 359 | const fs = require("fs")
|
310 | 360 |
|
311 | 361 | // only if the chain has a config file
|
312 | 362 | if (!fs.existsSync(`./config/${chain}.json`)) {
|
313 | 363 | continue
|
314 | 364 | }
|
315 | 365 |
|
316 |
| - const targetFile = `./data/${chain}_data.json` |
317 |
| - const dataFileContent = dataFileContentPerChain[chain] |
318 |
| - const existingDataFileContentIfAny = fs.existsSync(targetFile) |
319 |
| - ? JSON.parse(fs.readFileSync(targetFile, "utf8")) |
320 |
| - : { old_vaults: [], old_boosts: [] } |
321 |
| - |
322 |
| - dataFileContent.old_vaults = dataFileContent.old_vaults.concat(existingDataFileContentIfAny.old_vaults) |
323 |
| - dataFileContent.old_boosts = dataFileContent.old_boosts.concat(existingDataFileContentIfAny.old_boosts) |
324 |
| - dataFileContent.old_vaults = Array.from(new Set(dataFileContent.old_vaults)) |
325 |
| - dataFileContent.old_boosts = Array.from(new Set(dataFileContent.old_boosts)) |
326 |
| - |
327 |
| - dataFileContent.old_vaults.sort() |
328 |
| - dataFileContent.old_boosts.sort() |
| 366 | + const file = `./config/${chain}.json` |
| 367 | + const config = JSON.parse(fs.readFileSync(file, "utf8")) |
| 368 | + type BeefyConfig = AddressBookChain["platforms"]["beefyfinance"] |
| 369 | + // @ts-ignore |
| 370 | + const addressbookChainConfig: BeefyConfig = addressBook[chain as any].platforms.beefyfinance |
| 371 | + |
| 372 | + // clm |
| 373 | + if ( |
| 374 | + addressbookChainConfig.clmFactory?.toLowerCase() !== config.clmManagerFactoryAddress?.toLowerCase() && |
| 375 | + addressbookChainConfig.clmFactory?.toLowerCase() !== config.clmManagerFactoryAddress_2?.toLowerCase() |
| 376 | + ) { |
| 377 | + console.error( |
| 378 | + `${chain}: clmFactory address mismatch in config: ${addressbookChainConfig.clmFactory} !== ${config.clmManagerFactoryAddress} or ${config.clmManagerFactoryAddress_2}`, |
| 379 | + ) |
| 380 | + } |
| 381 | + if ( |
| 382 | + addressbookChainConfig.clmStrategyFactory?.toLowerCase() !== config.clmStrategyFactoryAddress?.toLowerCase() && |
| 383 | + addressbookChainConfig.clmStrategyFactory?.toLowerCase() !== config.clmStrategyFactoryAddress_2?.toLowerCase() |
| 384 | + ) { |
| 385 | + console.error( |
| 386 | + `${chain}: clmStrategyFactory address mismatch in config: ${addressbookChainConfig.clmStrategyFactory} !== ${config.clmStrategyFactoryAddress} or ${config.clmStrategyFactoryAddress_2}`, |
| 387 | + ) |
| 388 | + } |
| 389 | + if ( |
| 390 | + addressbookChainConfig.clmRewardPoolFactory?.toLowerCase() !== config.rewardPoolFactoryAddress?.toLowerCase() && |
| 391 | + addressbookChainConfig.clmRewardPoolFactory?.toLowerCase() !== config.rewardPoolFactoryAddress_2?.toLowerCase() |
| 392 | + ) { |
| 393 | + console.error( |
| 394 | + `${chain}: clmRewardPoolFactory address mismatch in config: ${addressbookChainConfig.clmRewardPoolFactory} !== ${config.rewardPoolFactoryAddress} or ${config.rewardPoolFactoryAddress_2}`, |
| 395 | + ) |
| 396 | + } |
329 | 397 |
|
330 |
| - fs.writeFileSync(targetFile, JSON.stringify(dataFileContent, null, 2)) |
| 398 | + // beefy classic |
| 399 | + if ( |
| 400 | + addressbookChainConfig.vaultFactory?.toLowerCase() !== config.beefyClassicVaultFactoryAddress?.toLowerCase() && |
| 401 | + addressbookChainConfig.vaultFactory?.toLowerCase() !== config.beefyClassicVaultFactoryAddress_2?.toLowerCase() |
| 402 | + ) { |
| 403 | + console.error( |
| 404 | + `${chain}: vaultFactory address mismatch in config: ${addressbookChainConfig.vaultFactory} !== ${config.beefyClassicVaultFactoryAddress} or ${config.beefyClassicVaultFactoryAddress_2}`, |
| 405 | + ) |
| 406 | + } |
331 | 407 | }
|
332 | 408 |
|
333 |
| - // display top 30 missing TVL to focus on the most important vaults |
334 |
| - missingHolderCounts.sort((a, b) => b.tvl - a.tvl) |
335 |
| - console.error(`\n\nMissing TVL for top 30 vaults:`) |
336 |
| - missingHolderCounts.slice(0, 100).forEach((v) => { |
337 |
| - const level = v.eol ? "ERROR" : "WARN" |
338 |
| - console.error(`${level}: Missing TVL for ${v.chain}:${v.id}:${v.vault_address}: ${v.tvl}`) |
339 |
| - }) |
| 409 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 410 | + // check that reward pools are never considered as boosts in data files |
| 411 | + //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 412 | + for (const chain of uniqChains) { |
| 413 | + const fs = require("fs") |
| 414 | + if (!fs.existsSync(`./data/${chain}_data.json`)) { |
| 415 | + continue |
| 416 | + } |
| 417 | + const data = JSON.parse(fs.readFileSync(`./data/${chain}_data.json`, "utf8")) |
| 418 | + |
| 419 | + for (const potentially_a_misclassified_boost_address of data.no_factory_boosts) { |
| 420 | + const rewardPool = clmRewardPoolData.find( |
| 421 | + (r) => r.earnContractAddress.toLowerCase() === potentially_a_misclassified_boost_address.toLowerCase(), |
| 422 | + ) |
| 423 | + if (rewardPool) { |
| 424 | + console.error(`${chain}:${potentially_a_misclassified_boost_address} is a reward pool but is considered as a boost in data file`) |
| 425 | + } |
| 426 | + } |
| 427 | + } |
340 | 428 | }
|
341 | 429 |
|
342 | 430 | main()
|
0 commit comments