server works with backend via redis, serves chainInfo, more

This commit is contained in:
Tim Olson
2023-10-04 03:42:21 -04:00
parent e36f7812eb
commit c05c9b9c16
12 changed files with 404 additions and 209 deletions

41
misc.js
View File

@@ -1,6 +1,45 @@
import fs from "fs";
import util from "util";
import {keccak256} from "ethers";
export const readFile = (fileName) => util.promisify(fs.readFile)(fileName, 'utf8');
export const ALL_CHAINS = [42161,]
const vaultCode = JSON.parse(fs.readFileSync('./contract/out/Vault.sol/Vault.json').toString())
export const VAULT_INIT_CODE_HASH = keccak256(vaultCode.bytecode.object)
export const chainInfo = {}
const _chains = [
{id:42161, name:'Arbitrum'},
{id:1338, name:'Mock'},
]
function _setChainInfo(c, k, v) {
c.update(v)
chainInfo[c][k] = v
}
for (const chain of _chains) {
const path = `contract/broadcast/Deploy.sol/${chain.id}/run-${process.env['DEXORDER_DEPLOYMENT_' + chain.id]}.json`;
let deployment
try {
deployment = JSON.parse(fs.readFileSync(path, 'utf8')) //null synchronous is ok we only do this once on init
}
catch {
continue
}
for (const tx of deployment.transactions) {
if (tx.contractName === 'Factory')
chain.factory = tx.contractAddress
else if (tx.contractName === 'QueryHelper')
chain.helper = tx.contractAddress
else if (tx.contractName === 'MockEnv') {
// todo set up mock coins, etc
}
}
if (chain.factory === undefined)
throw Error(`No Factory deployment found for chainId ${chain.id} ${path}`)
if (chain.helper === undefined)
throw Error(`No QueryHelper deployment found for chainId ${chain.id} ${path}`)
chainInfo[chain.id] = chain
}