chainInfo loads from version.json
This commit is contained in:
57
chain.js
57
chain.js
@@ -2,60 +2,9 @@ import fs from "fs";
|
|||||||
import {keccak256} from "ethers";
|
import {keccak256} from "ethers";
|
||||||
|
|
||||||
const vaultCode = JSON.parse(fs.readFileSync('../contract/out/Vault.sol/Vault.json').toString())
|
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)
|
export const VAULT_INIT_CODE_HASH = keccak256(vaultCode.bytecode.object)
|
||||||
console.log('VAULT_INIT_CODE_HASH', VAULT_INIT_CODE_HASH)
|
console.log('VAULT_INIT_CODE_HASH', VAULT_INIT_CODE_HASH)
|
||||||
|
|
||||||
export const chainInfo = {}
|
export const chainInfo = JSON.parse(fs.readFileSync('../contract/version.json')).chainInfo
|
||||||
|
console.log('chainInfo', 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
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user