require('dotenv').config() 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: 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) } else _prompt('', resolve) }) } function prompt(prompt) { return new Promise((resolve) => _prompt(prompt, resolve)) } function happyDeployedMessage(name, chainId, address) { return `\n${name} successfully deployed on ${idToNetwork(chainId)} @ ${address} 🥳\n` } function happyVerifiedMessage(name, address) { return `\n${name} @ ${address} successfully verified on Etherscan! 🥳\n` } 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() { const minimalFactoryFactory = await ethers.getContractFactory('MinimalInstanceFactory') const proposalFactoryFactory = await ethers.getContractFactory('InstanceProposalFactory') const chainId = (await ethers.provider.getNetwork()).chainId const signer = await ethers.getSigner() let minimalFactory, proposalFactory, nativeCloneableImplAddr, erc20CloneableImplAddr if (await prompt(promptMessageBase('Continuing to MinimalInstanceFactory deployment.'))) { minimalFactory = await minimalFactoryFactory.deploy( config.verifier, config.hasher, config.merkleTreeHeight, ) console.log(happyDeployedMessage('MinimalInstanceFactory', chainId, minimalFactory.address)) } else { return '\nDecided to stop at MinimalInstanceFactory deployment.\n' } console.log(happyDeployedMessage('MinimalInstanceFactory', chainId, minimalFactory.address)) nativeCloneableImplAddr = await minimalFactory.nativeCurImpl() erc20CloneableImplAddr = await minimalFactory.ERC20Impl() console.log(happyDeployedMessage('ETHTornadoCloneable', chainId, nativeCloneableImplAddr)) console.log(happyDeployedMessage('ERC20TornadoCloneable', chainId, erc20CloneableImplAddr)) if (await prompt(promptMessageBase('Continuing to InstanceProposalFactory deployment.'))) { proposalFactory = await proposalFactoryFactory.deploy( config.governance, minimalFactory.address, config.instanceRegistry, config.UniswapV3Factory, config.WETH, config.TWAPSlotsMin, ) console.log(happyDeployedMessage('InstanceProposalFactory', chainId, proposalFactory.address)) } else { return '\nDecided to stop at InstanceProposalFactory deployment.\n' } if (await prompt(promptMessageBase('Continuing to contract verification.'))) { await hre.run('verify:verify', { address: minimalFactory.address, constructorArguments: [config.verifier, config.hasher, config.merkleTreeHeight], }) console.log(happyVerifiedMessage('MinimalInstanceFactory', minimalFactory.address)) console.log('\nWaiting 5 seconds.\n') await timeout(5) await hre.run('verify:verify', { address: proposalFactory.address, constructorArguments: [ config.governance, minimalFactory.address, config.instanceRegistry, config.UniswapV3Factory, config.WETH, config.TWAPSlotsMin, ], }) console.log(happyVerifiedMessage('InstanceProposalFactory', proposalFactory.address)) console.log('\nWaiting 5 seconds.\n') await timeout(5) await hre.run('verify:verify', { address: nativeCloneableImplAddr, constructorArguments: [config.verifier, config.hasher], }) console.log(happyVerifiedMessage('ETHTornadoCloneable', nativeCloneableImplAddr)) console.log('\nWaiting 5 seconds.\n') await timeout(5) await hre.run('verify:verify', { address: erc20CloneableImplAddr, constructorArguments: [config.verifier, config.hasher], }) console.log(happyVerifiedMessage('ERC20TornadoCloneable', erc20CloneableImplAddr)) } else { return '\nDecided to stop at contract verification.\n' } } main().then((res) => { console.log(res ?? '\nScript succesfully finished.\n') })