reworked to optionally use Hardhat in mock; chain id 31337; refactored TransactionJob management; execute() mostly commented out for minimalism
This commit is contained in:
69
chain.js
Normal file
69
chain.js
Normal file
@@ -0,0 +1,69 @@
|
||||
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:'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 {
|
||||
console.log(`warning: could not read deployment files for ${chain.id}`)
|
||||
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') {
|
||||
// set up mock coins, etc
|
||||
if( chain.id === 31337 ) {
|
||||
console.log('Detected MockEnv at', tx.contractAddress)
|
||||
const mock = new ethers.Contract(tx.contractAddress, await getAbi('MockEnv'), getProvider(chain.id))
|
||||
const coinAddr = await mock.COIN()
|
||||
const usdAddr = await mock.USD()
|
||||
chain.tokens = [
|
||||
{
|
||||
name: 'Mockcoin',
|
||||
symbol: 'MOCK',
|
||||
decimals: 18,
|
||||
icon: null,
|
||||
address: coinAddr,
|
||||
},
|
||||
{
|
||||
name: 'Universally Stable Denomination',
|
||||
symbol: 'USD',
|
||||
decimals: 6,
|
||||
icon: null,
|
||||
address: usdAddr,
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
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}`)
|
||||
console.log('Factory', chain.factory)
|
||||
chainInfo[chain.id] = chain
|
||||
}
|
||||
Reference in New Issue
Block a user