instances/scripts/deploy.js

114 lines
3.3 KiB
JavaScript
Raw Normal View History

require('dotenv').config()
2023-04-14 22:16:26 +03:00
const hre = require('hardhat')
const { ethers } = hre
const config = require('../config')
const { createInterface } = require('readline')
function idToNetwork(id) {
switch (id) {
case 1:
return 'Mainnet'
case 3:
return 'Ropsten'
case 4:
return 'Rinkeby'
case 5:
return 'Goerli'
case 11155111:
return 'Sepolia'
default:
2023-04-14 22:16:26 +03:00
throw Error('\nChain Id could not be recognized. What network are you using?\n')
}
}
const prompter = createInterface({ input: process.stdin, output: process.stdout })
function _prompt(prompt, resolve) {
prompter.question(prompt, (answer) => {
if (answer == 'y') {
resolve(true)
} else if (answer == 'n') {
resolve(false)
2023-04-14 22:16:26 +03:00
} else _prompt('', resolve)
})
}
function prompt(prompt) {
return new Promise((resolve) => _prompt(prompt, resolve))
}
function happyDeployedMessage(name, chainId, address) {
2023-04-14 22:16:26 +03:00
return `\n${name} successfully deployed on ${idToNetwork(chainId)} @ ${address} 🥳\n`
}
2023-04-14 22:16:26 +03:00
function happyVerifiedMessage(name, address) {
return `\n${name} @ ${address} successfully verified on Etherscan! 🥳\n`
}
2023-04-15 20:51:29 +03:00
function timeout(seconds) {
return new Promise((resolve) => setTimeout(resolve, seconds * 1000))
}
const promptMessageBase = (middle) => `\n${middle}\n\nAre you sure you would like to continue? 🧐 (y/n): `
async function main() {
2023-04-15 20:51:29 +03:00
const minimalFactoryFactory = await ethers.getContractFactory('MinimalInstanceFactory')
const chainId = (await ethers.provider.getNetwork()).chainId
let minimalFactory, ethImplAddr, ERC20ImplAddr
2023-04-14 22:16:26 +03:00
if (await prompt(promptMessageBase('Continuing to MinimalInstanceFactory deployment.'))) {
2023-04-15 20:51:29 +03:00
minimalFactory = await minimalFactoryFactory.deploy(
2023-04-14 22:16:26 +03:00
config.verifier,
config.hasher,
config.router,
2023-04-14 22:16:26 +03:00
config.merkleTreeHeight,
)
2023-04-15 20:51:29 +03:00
console.log(happyDeployedMessage('MinimalInstanceFactory', chainId, minimalFactory.address))
await hre.run('verify:verify', {
address: minimalFactory.address,
constructorArguments: [config.verifier, config.hasher, config.router, config.merkleTreeHeight],
})
2023-04-14 22:16:26 +03:00
} else {
2023-04-15 20:51:29 +03:00
return '\nDecided to stop at MinimalInstanceFactory deployment.\n'
2023-04-14 22:16:26 +03:00
}
2023-04-15 20:51:29 +03:00
console.log(happyDeployedMessage('MinimalInstanceFactory', chainId, minimalFactory.address))
2023-04-14 22:16:26 +03:00
ethImplAddr = await minimalFactory.ethImpl()
ERC20ImplAddr = await minimalFactory.ERC20Impl()
console.log(happyDeployedMessage('ETHTornadoCloneable', chainId, ethImplAddr))
console.log(happyDeployedMessage('ERC20TornadoCloneable', chainId, ERC20ImplAddr))
if (await prompt(promptMessageBase('Continuing to impl verifications.'))) {
console.log('\nWaiting 3 seconds.\n')
await timeout(3)
2023-04-14 22:16:26 +03:00
await hre.run('verify:verify', {
address: ethImplAddr,
2023-04-14 22:16:26 +03:00
constructorArguments: [config.verifier, config.hasher],
})
console.log(happyVerifiedMessage('ETHTornadoCloneable', ethImplAddr))
2023-04-15 20:51:29 +03:00
console.log('\nWaiting 5 seconds.\n')
await timeout(5)
2023-04-14 22:16:26 +03:00
await hre.run('verify:verify', {
address: ERC20ImplAddr,
2023-04-14 22:16:26 +03:00
constructorArguments: [config.verifier, config.hasher],
})
console.log(happyVerifiedMessage('ERC20TornadoCloneable', ERC20ImplAddr))
} else {
return '\nDecided to stop at contract verification.\n'
}
}
main().then((res) => {
2023-04-14 22:16:26 +03:00
console.log(res ?? '\nScript succesfully finished.\n')
})