2023-04-13 23:03:12 +03:00
|
|
|
require('dotenv').config()
|
|
|
|
|
2023-04-14 22:16:26 +03:00
|
|
|
const hre = require('hardhat')
|
|
|
|
const { ethers } = hre
|
2023-04-13 23:03:12 +03:00
|
|
|
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')
|
2023-04-13 23:03:12 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const prompter = createInterface({ input: process.stdin, output: process.stdout })
|
|
|
|
|
|
|
|
function _prompt(prompt, resolve) {
|
|
|
|
prompter.question(prompt, (answer) => {
|
|
|
|
if (answer == 'y') {
|
|
|
|
userInput.close()
|
|
|
|
resolve(true)
|
|
|
|
} else if (answer == 'n') {
|
|
|
|
userInput.close()
|
|
|
|
resolve(false)
|
2023-04-14 22:16:26 +03:00
|
|
|
} else _prompt('', resolve)
|
2023-04-13 23:03:12 +03:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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-13 23:03:12 +03:00
|
|
|
}
|
|
|
|
|
2023-04-14 22:16:26 +03:00
|
|
|
function happyVerifiedMessage(name, address) {
|
|
|
|
return `\n${name} @ ${address} successfully verified on Etherscan! 🥳\n`
|
2023-04-13 23:03:12 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
const promptMessageBase = (middle) => `\n${middle}\n\nAre you sure you would like to continue? 🧐 (y/n): `
|
|
|
|
|
|
|
|
async function main() {
|
2023-04-14 22:16:26 +03:00
|
|
|
const minimalFactoryContractFactory = await ethers.getContractFactory('MinimalInstanceFactory')
|
|
|
|
const proposalFactoryContractFactory = await ethers.getContractFactory('InstanceProposalFactory')
|
2023-04-13 23:03:12 +03:00
|
|
|
|
2023-04-14 22:16:26 +03:00
|
|
|
let minimalFactory, proposalFactory, nativeCloneableImplAddr, erc20CloneableImplAddr
|
2023-04-13 23:03:12 +03:00
|
|
|
|
2023-04-14 22:16:26 +03:00
|
|
|
if (await prompt(promptMessageBase('Continuing to MinimalInstanceFactory deployment.'))) {
|
|
|
|
minimalFactory = await minimalFactoryContractFactory.deploy(
|
|
|
|
config.verifier,
|
|
|
|
config.hasher,
|
|
|
|
config.merkleTreeHeight,
|
|
|
|
)
|
|
|
|
} else {
|
|
|
|
return '\nDecided to stop at InstanceProposalFactory deployment.\n'
|
|
|
|
}
|
|
|
|
|
|
|
|
console.log(happyDeployedMessage('MinimalInstanceFactory', minimalFactory.address))
|
|
|
|
|
|
|
|
nativeCloneableImplAddr = await minimalFactory.nativeCurImpl()
|
|
|
|
erc20CloneableImplAddr = await minimalFactory.ERC20Impl()
|
|
|
|
|
|
|
|
console.log(happyDeployedMessage('ETHTornadoCloneable', nativeCloneableImplAddr))
|
|
|
|
console.log(happyDeployedMessage('ERC20TornadoCloneable', erc20CloneableImplAddr))
|
2023-04-13 23:03:12 +03:00
|
|
|
|
|
|
|
if (await prompt(promptMessageBase('Continuing to InstanceProposalFactory deployment.'))) {
|
2023-04-14 22:16:26 +03:00
|
|
|
proposalFactory = await proposalFactoryContractFactory.deploy(
|
2023-04-13 23:03:12 +03:00
|
|
|
config.governance,
|
2023-04-14 22:16:26 +03:00
|
|
|
minimalFactory.address,
|
2023-04-13 23:03:12 +03:00
|
|
|
config.instanceRegistry,
|
|
|
|
config.UniswapV3Factory,
|
|
|
|
config.WETH,
|
|
|
|
config.TWAPSlotsMin,
|
|
|
|
)
|
|
|
|
|
2023-04-14 22:16:26 +03:00
|
|
|
console.log(happyDeployedMessage('InstanceProposalFactory', proposalFactory.address))
|
2023-04-13 23:03:12 +03:00
|
|
|
} else {
|
|
|
|
return '\nDecided to stop at InstanceProposalFactory deployment.\n'
|
|
|
|
}
|
|
|
|
|
|
|
|
if (await prompt(promptMessageBase('Continuing to contract verification.'))) {
|
2023-04-14 22:16:26 +03:00
|
|
|
await hre.run('verify:verify', {
|
|
|
|
address: minimalFactory.address,
|
|
|
|
constructorArguments: [config.verifier, config.hasher, config.merkleTreeHeight],
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(happyVerifiedMessage('MinimalInstanceFactory', minimalFactory.address))
|
|
|
|
|
|
|
|
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))
|
|
|
|
|
|
|
|
await hre.run('verify:verify', {
|
|
|
|
address: nativeCloneableImplAddr,
|
|
|
|
constructorArguments: [config.verifier, config.hasher],
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(happyVerifiedMessage('ETHTornadoCloneable', nativeCloneableImplAddr))
|
|
|
|
|
|
|
|
await hre.run('verify:verify', {
|
|
|
|
address: erc20CloneableImplAddr,
|
|
|
|
constructorArguments: [config.verifier, config.hasher],
|
|
|
|
})
|
|
|
|
|
|
|
|
console.log(happyVerifiedMessage('ERC20TornadoCloneable', erc20CloneableImplAddr))
|
2023-04-13 23:03:12 +03:00
|
|
|
} 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')
|
2023-04-13 23:03:12 +03:00
|
|
|
})
|