chainInfo fix

This commit is contained in:
Tim
2024-07-11 14:22:51 -04:00
parent 0f3776b0df
commit 675f4b6bec

View File

@@ -15,39 +15,47 @@ const _chains = [
]
for (const chain of _chains) {
const path = `../contract/broadcast/Deploy.sol/${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
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
}
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
});
}