tornado-deploy/src/execute.js
2021-03-11 23:20:09 +03:00

45 lines
1.6 KiB
JavaScript

require('dotenv').config()
const ethers = require('ethers')
const actions = require('../actions.json')
const abi = require('../abi/deployer.abi.json')
const prefix = {
1: '',
42: 'kovan.',
5: 'goerli.',
}
const explorer = `https://${prefix[process.env.NET_ID]}etherscan.io`
async function main() {
const privateKey = process.env.PRIVATE_KEY
const provider = new ethers.providers.JsonRpcProvider(process.env.RPC_URL)
const wallet = new ethers.Wallet(privateKey, provider)
const deployer = new ethers.Contract(actions.deployer, abi, wallet)
for (const action of actions.actions) {
let code = await provider.getCode(action.expectedAddress)
if (code && code !== '0x') {
console.log(`${action.contract} is already deployed at ${explorer}/address/${action.expectedAddress}`)
continue
}
console.log(`Deploying ${action.contract} to ${action.domain} (${action.expectedAddress})`)
const tx = await deployer.deploy(action.bytecode, actions.salt, { gasLimit: 7e6, gasPrice: 1e6 })
console.log(`TX hash ${explorer}/tx/${tx.hash}`)
try {
await tx.wait()
console.log(`Deployed ${action.contract} to ${explorer}/address/${action.expectedAddress}\n`)
} catch (e) {
console.error(`Failed to deploy ${action.contract}, sending debug tx`)
const tx = await wallet.sendTransaction({ gasLimit: 8e6, data: action.bytecode })
console.log(`TX hash ${explorer}/tx/${tx.hash}`)
await tx.wait()
console.log('Mined, check revert reason on etherscan')
return
// throw new Error(`Failed to deploy ${action.contract}`)
}
}
}
main()