From ffef7e6312ef784c764d1842f783e9b091e8c2d8 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 12 Jul 2024 15:32:06 -0400 Subject: [PATCH] chainInfo loads from version.json --- chain.js | 57 +++----------------------------------------------------- 1 file changed, 3 insertions(+), 54 deletions(-) diff --git a/chain.js b/chain.js index cabec99..802f849 100644 --- a/chain.js +++ b/chain.js @@ -2,60 +2,9 @@ import fs from "fs"; import {keccak256} from "ethers"; const vaultCode = JSON.parse(fs.readFileSync('../contract/out/Vault.sol/Vault.json').toString()) +// todo this is a per-chain value found in chainInfo export const VAULT_INIT_CODE_HASH = keccak256(vaultCode.bytecode.object) console.log('VAULT_INIT_CODE_HASH', VAULT_INIT_CODE_HASH) -export const chainInfo = {} - -const _chains = [ - {id:42161, name:'Arbitrum'}, - {id:421614, name:'Arbitrum Sepolia'}, - {id:31337, name:'Mockchain'}, - {id:1337, name:'Dexorder Alpha'}, -] - -for (const chain of _chains) { - fs.readdir('../contract/broadcast', (err, files) => { - if (err) throw err; - for (const deploymentClassDir of files) { - if (deploymentClassDir.startsWith('Deploy') && deploymentClassDir.endsWith('.sol')) { - const path = `${deploymentClassDir}/${chain.id}/run-latest.json`; - let deployment - try { - deployment = JSON.parse(fs.readFileSync(path, 'utf8')) //null synchronous is ok we only do this once on init - } - catch { - console.log(`warning: could not read deployment files for ${chain.id}`) - continue - } - let maybeFactory = null - for (const tx of deployment.transactions) { - if (tx.contractName === 'VaultFactory') - chain.factory = tx.contractAddress - else if (tx.contractName === 'QueryHelper') - chain.helper = tx.contractAddress - else if (tx.contractName === null) { - if( maybeFactory !== null ) { - console.warn('Multiple broadcast deployments found with a null contractAddress') - maybeFactory = -1 // prevent ever using the null labeled contracts - } - else if (maybeFactory !== -1) - maybeFactory = tx.contractAddress - } - } - if (chain.factory === undefined) { - if ( maybeFactory !== null && maybeFactory !== -1) - chain.factory = maybeFactory - else - throw Error(`No VaultFactory deployment found for chainId ${chain.id} ${path}`) - } - if (chain.helper === undefined) - throw Error(`No QueryHelper deployment found for chainId ${chain.id} ${path}`) - console.log('VaultFactory', chain.factory) - console.log('QueryHelper', chain.helper) - chainInfo[chain.id] = chain - - } - } - }); -} +export const chainInfo = JSON.parse(fs.readFileSync('../contract/version.json')).chainInfo +console.log('chainInfo', chainInfo)