95 lines
3.7 KiB
JavaScript
95 lines
3.7 KiB
JavaScript
import fs from "fs";
|
|
import {ethers, keccak256} from "ethers";
|
|
import {getProvider} from "./blockchain.js";
|
|
import {getAbi} from "./abi.js";
|
|
|
|
const vaultCode = JSON.parse(fs.readFileSync('../contract/out/Vault.sol/Vault.json').toString())
|
|
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:31337, name:'Mockchain'},
|
|
{id:1337, name:'Dexorder Alpha'},
|
|
]
|
|
|
|
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 {
|
|
console.log(`warning: could not read deployment files for ${chain.id}`)
|
|
continue
|
|
}
|
|
let maybeFactory = null
|
|
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 === 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 Factory deployment found for chainId ${chain.id} ${path}`)
|
|
}
|
|
if (chain.helper === undefined)
|
|
throw Error(`No QueryHelper deployment found for chainId ${chain.id} ${path}`)
|
|
console.log('Factory', chain.factory)
|
|
console.log('QueryHelper', chain.helper)
|
|
|
|
if(chain.id === 31337 || chain.id === 1337) {
|
|
const mockpath = `../contract/broadcast/DeployMock.sol/${chain.id}/run-${process.env['DEXORDER_DEPLOYMENT_' + chain.id]}.json`
|
|
try {
|
|
deployment = JSON.parse(fs.readFileSync(mockpath, 'utf8')) //null synchronous is ok we only do this once on init
|
|
for (const tx of deployment.transactions) {
|
|
if (tx.contractName === 'MockEnv') {
|
|
// set up mock coins, etc
|
|
const mock = new ethers.Contract(tx.contractAddress, await getAbi('MockEnv'), getProvider(chain.id))
|
|
const coinAddr = await mock.COIN()
|
|
const usdAddr = await mock.USD()
|
|
chain.mockenv = tx.contractAddress
|
|
chain.mockCoins = [coinAddr, usdAddr]
|
|
chain.tokens = [
|
|
{
|
|
name: 'Mock Ethereum Hardfork',
|
|
symbol: 'MEH',
|
|
decimals: 18,
|
|
image: null,
|
|
address: coinAddr,
|
|
},
|
|
{
|
|
name: 'Joke Currency XD',
|
|
symbol: 'USXD',
|
|
decimals: 6,
|
|
image: null,
|
|
address: usdAddr,
|
|
},
|
|
]
|
|
console.log('Detected MockEnv at', chain.id, tx.contractAddress)
|
|
}
|
|
}
|
|
} catch {
|
|
}
|
|
}
|
|
chainInfo[chain.id] = chain
|
|
}
|