Skip to content

Commit

Permalink
Stricter config checks and fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Dec 18, 2024
1 parent e54c7a2 commit 3c82361
Show file tree
Hide file tree
Showing 34 changed files with 269 additions and 91 deletions.
154 changes: 121 additions & 33 deletions bin/check-config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { groupBy } from "lodash"
import { chain, groupBy } from "lodash"
import { addressBook, Chain as AddressBookChain } from "blockchain-addressbook"

type Hex = `0x${string}`

Expand Down Expand Up @@ -269,74 +270,161 @@ async function main() {

const dataFileContentPerChain = {} as any

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// check for missing holder counts
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const missingHolderCounts: BeefyVault[] = []
for (const vault of allConfigs) {
const subgraphchain = vault.chain === "one" ? "harmony" : vault.chain
dataFileContentPerChain[subgraphchain] = dataFileContentPerChain[subgraphchain] || { old_vaults: [], old_boosts: [] }
dataFileContentPerChain[subgraphchain] = dataFileContentPerChain[subgraphchain] || { no_factory_vaults: [], no_factory_boosts: [] }

const level = vault.eol ? "ERROR" : "WARN"
if (!countsPerToken[`${subgraphchain}:${vault.vault_address}`]) {
console.error(`${level}: Missing holder count for ${vault.id} with address ${subgraphchain}:${vault.vault_address}`)
console.error(
`${level}: Missing holder count in balance api for ${vault.chain}:${vault.id} with address ${subgraphchain}:${vault.vault_address}`,
)
missingHolderCounts.push(vault)
dataFileContentPerChain[subgraphchain].old_vaults.push(vault.vault_address)
dataFileContentPerChain[subgraphchain].no_factory_vaults.push(vault.vault_address)
}
if (vault.protocol_type === "beefy_clm_vault") {
if (!countsPerToken[`${subgraphchain}:${vault.beefy_clm_manager.vault_address}`]) {
console.error(`${level}: Missing holder count for ${vault.id} with CLM address ${subgraphchain}:${vault.beefy_clm_manager.vault_address}`)
console.error(
`${level}: Missing holder count in balance api for ${vault.chain}:${vault.id} with CLM address ${subgraphchain}:${vault.beefy_clm_manager.vault_address}`,
)
missingHolderCounts.push(vault)
dataFileContentPerChain[subgraphchain].old_vaults.push(vault.beefy_clm_manager.vault_address)
dataFileContentPerChain[subgraphchain].no_factory_vaults.push(vault.beefy_clm_manager.vault_address)
}
}
for (const pool of vault.reward_pools) {
if (!countsPerToken[`${subgraphchain}:${pool.clm_address}`]) {
console.error(`${level}: Missing holder count for ${vault.id}'s Reward Pool with address ${subgraphchain}:${pool.reward_pool_address}`)
console.error(
`${level}: Missing holder count in balance api for ${vault.chain}:${vault.id}'s Reward Pool with address ${subgraphchain}:${pool.reward_pool_address}`,
)
missingHolderCounts.push(vault)
dataFileContentPerChain[subgraphchain].old_boosts.push(pool.reward_pool_address)
dataFileContentPerChain[subgraphchain].no_factory_boosts.push(pool.reward_pool_address)
}
}
for (const boost of vault.boosts) {
if (!countsPerToken[`${subgraphchain}:${boost.underlying_address}`]) {
console.error(`${level}: Missing holder count for ${vault.id}'s BOOST with address ${subgraphchain}:${boost.boost_address}`)
console.error(
`${level}: Missing holder count in balance api for ${vault.chain}:${vault.id}'s BOOST with address ${subgraphchain}:${boost.boost_address}`,
)
missingHolderCounts.push(vault)
dataFileContentPerChain[subgraphchain].old_boosts.push(boost.boost_address)
dataFileContentPerChain[subgraphchain].no_factory_boosts.push(boost.boost_address)
}
}
}

// write data files
for (const chain of Object.keys(dataFileContentPerChain)) {
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// write data files with missing holder counts
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// for (const chain of Object.keys(dataFileContentPerChain)) {
// const fs = require("fs")

// // only if the chain has a config file
// if (!fs.existsSync(`./config/${chain}.json`)) {
// continue
// }

// const targetFile = `./data/${chain}_data.json`
// const dataFileContent = dataFileContentPerChain[chain]
// const existingDataFileContentIfAny = fs.existsSync(targetFile)
// ? JSON.parse(fs.readFileSync(targetFile, "utf8"))
// : { no_factory_vaults: [], no_factory_boosts: [] }

// dataFileContent.no_factory_vaults = dataFileContent.no_factory_vaults.concat(existingDataFileContentIfAny.no_factory_vaults)
// dataFileContent.no_factory_boosts = dataFileContent.no_factory_boosts.concat(existingDataFileContentIfAny.no_factory_boosts)
// dataFileContent.no_factory_vaults = Array.from(new Set(dataFileContent.no_factory_vaults))
// dataFileContent.no_factory_boosts = Array.from(new Set(dataFileContent.no_factory_boosts))

// dataFileContent.no_factory_vaults.sort()
// dataFileContent.no_factory_boosts.sort()

// fs.writeFileSync(targetFile, JSON.stringify(dataFileContent, null, 2))
// }

// // display top 30 missing TVL to focus on the most important vaults
// missingHolderCounts.sort((a, b) => b.tvl - a.tvl)
// console.error(`\n\nMissing TVL for top 30 vaults:`)
// missingHolderCounts.slice(0, 100).forEach((v) => {
// const level = v.eol ? "ERROR" : "WARN"
// console.error(`${level}: Missing TVL for ${v.chain}:${v.id}:${v.vault_address}: ${v.tvl}`)
// })

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// check that the chain config contains all the factory addresses in the addressbook
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
const uniqChains = Array.from(new Set(allConfigs.map((v) => v.chain)))
for (const chain of uniqChains) {
const fs = require("fs")

// only if the chain has a config file
if (!fs.existsSync(`./config/${chain}.json`)) {
continue
}

const targetFile = `./data/${chain}_data.json`
const dataFileContent = dataFileContentPerChain[chain]
const existingDataFileContentIfAny = fs.existsSync(targetFile)
? JSON.parse(fs.readFileSync(targetFile, "utf8"))
: { old_vaults: [], old_boosts: [] }

dataFileContent.old_vaults = dataFileContent.old_vaults.concat(existingDataFileContentIfAny.old_vaults)
dataFileContent.old_boosts = dataFileContent.old_boosts.concat(existingDataFileContentIfAny.old_boosts)
dataFileContent.old_vaults = Array.from(new Set(dataFileContent.old_vaults))
dataFileContent.old_boosts = Array.from(new Set(dataFileContent.old_boosts))

dataFileContent.old_vaults.sort()
dataFileContent.old_boosts.sort()
const file = `./config/${chain}.json`
const config = JSON.parse(fs.readFileSync(file, "utf8"))
type BeefyConfig = AddressBookChain["platforms"]["beefyfinance"]
// @ts-ignore
const addressbookChainConfig: BeefyConfig = addressBook[chain as any].platforms.beefyfinance

// clm
if (
addressbookChainConfig.clmFactory?.toLowerCase() !== config.clmManagerFactoryAddress?.toLowerCase() &&
addressbookChainConfig.clmFactory?.toLowerCase() !== config.clmManagerFactoryAddress_2?.toLowerCase()
) {
console.error(
`${chain}: clmFactory address mismatch in config: ${addressbookChainConfig.clmFactory} !== ${config.clmManagerFactoryAddress} or ${config.clmManagerFactoryAddress_2}`,
)
}
if (
addressbookChainConfig.clmStrategyFactory?.toLowerCase() !== config.clmStrategyFactoryAddress?.toLowerCase() &&
addressbookChainConfig.clmStrategyFactory?.toLowerCase() !== config.clmStrategyFactoryAddress_2?.toLowerCase()
) {
console.error(
`${chain}: clmStrategyFactory address mismatch in config: ${addressbookChainConfig.clmStrategyFactory} !== ${config.clmStrategyFactoryAddress} or ${config.clmStrategyFactoryAddress_2}`,
)
}
if (
addressbookChainConfig.clmRewardPoolFactory?.toLowerCase() !== config.rewardPoolFactoryAddress?.toLowerCase() &&
addressbookChainConfig.clmRewardPoolFactory?.toLowerCase() !== config.rewardPoolFactoryAddress_2?.toLowerCase()
) {
console.error(
`${chain}: clmRewardPoolFactory address mismatch in config: ${addressbookChainConfig.clmRewardPoolFactory} !== ${config.rewardPoolFactoryAddress} or ${config.rewardPoolFactoryAddress_2}`,
)
}

fs.writeFileSync(targetFile, JSON.stringify(dataFileContent, null, 2))
// beefy classic
if (
addressbookChainConfig.vaultFactory?.toLowerCase() !== config.beefyClassicVaultFactoryAddress?.toLowerCase() &&
addressbookChainConfig.vaultFactory?.toLowerCase() !== config.beefyClassicVaultFactoryAddress_2?.toLowerCase()
) {
console.error(
`${chain}: vaultFactory address mismatch in config: ${addressbookChainConfig.vaultFactory} !== ${config.beefyClassicVaultFactoryAddress} or ${config.beefyClassicVaultFactoryAddress_2}`,
)
}
}

// display top 30 missing TVL to focus on the most important vaults
missingHolderCounts.sort((a, b) => b.tvl - a.tvl)
console.error(`\n\nMissing TVL for top 30 vaults:`)
missingHolderCounts.slice(0, 100).forEach((v) => {
const level = v.eol ? "ERROR" : "WARN"
console.error(`${level}: Missing TVL for ${v.chain}:${v.id}:${v.vault_address}: ${v.tvl}`)
})
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// check that reward pools are never considered as boosts in data files
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
for (const chain of uniqChains) {
const fs = require("fs")
if (!fs.existsSync(`./data/${chain}_data.json`)) {
continue
}
const data = JSON.parse(fs.readFileSync(`./data/${chain}_data.json`, "utf8"))

for (const potentially_a_misclassified_boost_address of data.no_factory_boosts) {
const rewardPool = clmRewardPoolData.find(
(r) => r.earnContractAddress.toLowerCase() === potentially_a_misclassified_boost_address.toLowerCase(),
)
if (rewardPool) {
console.error(`${chain}:${potentially_a_misclassified_boost_address} is a reward pool but is considered as a boost in data file`)
}
}
}
}

main()
6 changes: 6 additions & 0 deletions config/avax.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
"burnAddress": "0x000000000000000000000000000000000000dead",
"firstBlock": 10097386,

"clmManagerFactoryAddress": "0xAF393b8ded8b8C1bd0c8707f43E6972C9bF19EE5",
"clmManagerFactoryStartBlock": 50895319,
"clmStrategyFactoryAddress": "0xEB385232b72dAFe4Ad1906BC6C4968D064a30FC4",
"clmStrategyFactoryStartBlock": 50895349,
"rewardPoolFactoryAddress": "0xbE03cb9f257bBA76178965D9391cA283767FF7Fe",
"rewardPoolFactoryStartBlock": 50895324,
"beefyClassicVaultFactoryAddress": "0xee78529E158E82AC54c89608A9664F5597050526",
"beefyClassicVaultFactoryStartBlock": 23297126,

Expand Down
7 changes: 7 additions & 0 deletions config/mode.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
"beefyClassicVaultFactoryAddress": "0xBC4a342B0c057501E081484A2d24e576E854F823",
"beefyClassicVaultFactoryStartBlock": 7558107,

"clmManagerFactoryAddress": "0xd1bAb603eee03fA99A378d90d5d83186fEB81aA9",
"clmManagerFactoryStartBlock": 15023980,
"clmStrategyFactoryAddress": "0x5E0d19ACe839b2257F1A10Ee1E8b25E6D8930244",
"clmStrategyFactoryStartBlock": 15024000,
"rewardPoolFactoryAddress": "0x99097E6C293982f0e05937fdfB45F69eF8914F0e",
"rewardPoolFactoryStartBlock": 15024000,

"beefyContractDeployerAddress": "0xcc536552A6214d6667fBC3EC38965F7f556A6391",
"beefyContractDeployerStartBlock": 7587005,

Expand Down
2 changes: 2 additions & 0 deletions config/zksync.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

"clmManagerFactoryAddress": "0x59c7EC7387A480c0a5d953fCb45513D01B94286D",
"clmManagerFactoryStartBlock": 37399642,
"clmManagerFactoryAddress_2": "0x0e02963318CD71f3084b89520b4c7dc7588db228",
"clmManagerFactoryStartBlock_2": 37377539,
"clmStrategyFactoryAddress": "0x3Da3658959D9Fc5233716487D050F73A3F659c2E",
"clmStrategyFactoryStartBlock": 37377982,
"rewardPoolFactoryAddress": "0x6Ff30Fde5b530d052d24AC104eC87ADbc33384Fd",
Expand Down
4 changes: 2 additions & 2 deletions data/arbitrum_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"old_vaults": [
"no_factory_vaults": [
"0x07db98358d58ba9be90cd0a18cd86af807ac3b4e",
"0x0b7ea1b9fbc9860f4a508e9d0dde04f2552d2ade",
"0x14555a3dd091aa0bd4657591b843ea4c2f83e6ef",
Expand Down Expand Up @@ -46,5 +46,5 @@
"0xf785ef43a082c85abbe19ca888f91748aa604ac5",
"0xfcdd5a02c611ba6fe2802f885281500ec95805d7"
],
"old_boosts": ["0x13ad51ed4f1b7e9dc168d8a00cb3f4ddd85efa60"]
"no_factory_boosts": ["0x13ad51ed4f1b7e9dc168d8a00cb3f4ddd85efa60"]
}
14 changes: 2 additions & 12 deletions data/avax_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"old_vaults": [
"no_factory_vaults": [
"0x02a0c97be6d8f4f144afe5f41c51b5cef192480c",
"0x02be142346cbcaf2a1d8a8f7b4a5f2d929259270",
"0x0421ae152e3967361a54396486c970257c14e096",
Expand Down Expand Up @@ -171,15 +171,5 @@
"0xfe27d61f8386370d6cfa63ea06470ed55f6dbfe7",
"0xfea7976733f47557860f4483f2147a3e99c76b58"
],
"old_boosts": [
"0x03e73383c9a8ed221c6c134bcc08555fa93fe091",
"0x051b9d5f40727a35038a9ba1f1c27cbddd5fb54c",
"0x0fad7fa9d3d71eea524f7989831c4eb031488cc7",
"0x240248628b7b6850352764c5dfa50d1592a033a8",
"0x35c038032ae84b6ea6dab218914a60e0e9ef69a9",
"0x4a132000670179d6497170e315c1311aefc66e8e",
"0x86fc9a6cdeb75cc6461120a000e925672524c0d4",
"0xba245c7ed7a440466802f316c202a25570e4d424",
"0xe87e3721a89d4a9a2782996afbe86adf07997567"
]
"no_factory_boosts": []
}
4 changes: 2 additions & 2 deletions data/base_data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"old_vaults": ["0x62e5b9934dcb87618cfc74b222305d16c997e8c1"],
"old_boosts": []
"no_factory_vaults": ["0x62e5b9934dcb87618cfc74b222305d16c997e8c1"],
"no_factory_boosts": []
}
4 changes: 2 additions & 2 deletions data/bsc_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"old_vaults": [
"no_factory_vaults": [
"0x00aec34489a7ade91a0507b6b9dbb0a50938b7c0",
"0x00ecbb8f9853dbc621b39ab205a148a26eac3b11",
"0x00f204f524a433f45a6278c2c0e10f5292b3c5b9",
Expand Down Expand Up @@ -742,7 +742,7 @@
"0xff494b7cb341311f86da21a49c5ff176637aa85e",
"0xff750ee63f1e428de1d6c8d9d92676b5fc8376a8"
],
"old_boosts": [
"no_factory_boosts": [
"0x04756126f044634c9a0f0e985e60c88a51acc206",
"0x3bc5ac0dfdc871b365d159f728dd1b9a0b5481e8",
"0xc3c7d422809852031b44ab29eec9f1eff2a58756"
Expand Down
4 changes: 2 additions & 2 deletions data/ethereum_data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"old_vaults": ["0xa95a7c9413b562f8d0581b91ec9d51a4fb5bab7e"],
"old_boosts": []
"no_factory_vaults": ["0xa95a7c9413b562f8d0581b91ec9d51a4fb5bab7e"],
"no_factory_boosts": []
}
4 changes: 2 additions & 2 deletions data/fantom_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"old_vaults": [
"no_factory_vaults": [
"0x0139c853539bf1edf221cf9d665f282c2701335a",
"0x01760ea1e63aa89b5e567ed616e104220b4e2e9b",
"0x01cc6c3262e24e0d7f45c968e84a8b2ddc12b9cf",
Expand Down Expand Up @@ -286,5 +286,5 @@
"0xfd30cead8e54568fe535747929775e95fdb6d3f7",
"0xfd393c038deaaf14d3186d6da638d2dd6bfed90b"
],
"old_boosts": ["0x13ad51ed4f1b7e9dc168d8a00cb3f4ddd85efa60"]
"no_factory_boosts": ["0x13ad51ed4f1b7e9dc168d8a00cb3f4ddd85efa60"]
}
4 changes: 2 additions & 2 deletions data/fraxtal_data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"old_vaults": [],
"old_boosts": []
"no_factory_vaults": [],
"no_factory_boosts": []
}
4 changes: 2 additions & 2 deletions data/gnosis_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"old_vaults": [
"no_factory_vaults": [
"0x1de0375e770efb9c92d7958cbb5b53c9fb8eb1cb",
"0x21c4d71882364b395209c07a7710a9251c285d73",
"0x3e442af13db47e27b48de6caf2708b2d180b10f9",
Expand All @@ -14,5 +14,5 @@
"0xf49de23df72c886946eef19d1b751b3d997ef668",
"0xf9ac09ec1ab2e4cd5ca2cf9451d3a49fd6b25cc5"
],
"old_boosts": []
"no_factory_boosts": []
}
4 changes: 2 additions & 2 deletions data/linea_data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"old_vaults": [],
"old_boosts": []
"no_factory_vaults": [],
"no_factory_boosts": []
}
4 changes: 2 additions & 2 deletions data/lisk_data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"old_vaults": [],
"old_boosts": []
"no_factory_vaults": [],
"no_factory_boosts": []
}
4 changes: 2 additions & 2 deletions data/manta_data.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"old_vaults": [],
"old_boosts": []
"no_factory_vaults": [],
"no_factory_boosts": []
}
4 changes: 2 additions & 2 deletions data/mantle_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"old_vaults": [
"no_factory_vaults": [
"0x08175349da602674a255398516187984fedd5738",
"0x15a318cfc01b50bd77c3a8d0dd560fdf44b5c046",
"0x15f5169d7fd528f6c8bcfb0a239833d53f454ff2",
Expand Down Expand Up @@ -28,5 +28,5 @@
"0xf2605791de7b82a903f369364797cf10c57712f3",
"0xfb038d9f7ed2e754612381af193f5570470c5182"
],
"old_boosts": ["0x25356aeca4210ef7553140edb9b8026089e49396"]
"no_factory_boosts": ["0x25356aeca4210ef7553140edb9b8026089e49396"]
}
4 changes: 2 additions & 2 deletions data/metis_data.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"old_vaults": [
"no_factory_vaults": [
"0x085bf6f912a42d0d8ed53d4998b07f9a535315f0",
"0x0d281ff551351c8b88d019ecd23481723a1cc8e3",
"0x0fb94775d16e14627678391d24e4576fda05e3ed",
Expand Down Expand Up @@ -31,5 +31,5 @@
"0xea01ca0423acb8476e1d3bae572021c2aa9bd410",
"0xfe118360beac5c2ac9da77d2366b8738bbfeb2d9"
],
"old_boosts": []
"no_factory_boosts": []
}
Loading

0 comments on commit 3c82361

Please sign in to comment.