instances/scripts/deploy.js

84 lines
2.3 KiB
JavaScript
Raw Normal View History

require('dotenv').config()
const { ethers } = require('hardhat')
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') {
userInput.close()
resolve(true)
} else if (answer == 'n') {
userInput.close()
resolve(false)
} else wipeCachePrompt('', resolve)
})
}
function prompt(prompt) {
return new Promise((resolve) => _prompt(prompt, resolve))
}
function happyDeployedMessage(name, chainId, address) {
return `\n${name} successfully deployed on ${idToNetwork(chainId)} at ${address} 🥳\n`
}
function happyVerifiedMessage(name) {
return `\n${name} successfully verified on Etherscan!`
}
const promptMessageBase = (middle) => `\n${middle}\n\nAre you sure you would like to continue? 🧐 (y/n): `
async function main() {
const minFacFac = await ethers.getContractFactory('MinimalInstanceFactory')
const proposalFacFac = await ethers.getContractFactory('InstanceProposalFactory')
const minFac = await minFacFac.deploy(config.verifier, config.hasher, config.merkleTreeHeight)
console.log(happyDeployedMessage('MinimalInstanceFactory', minFac.address))
if (await prompt(promptMessageBase('Continuing to InstanceProposalFactory deployment.'))) {
const proposalFac = await proposalFacFac.deploy(
config.governance,
minFac.address,
config.instanceRegistry,
config.UniswapV3Factory,
config.WETH,
config.TWAPSlotsMin,
)
console.log(happyDeployedMessage('InstanceProposalFactory', proposalFac.address))
} else {
return '\nDecided to stop at InstanceProposalFactory deployment.\n'
}
if (await prompt(promptMessageBase('Continuing to contract verification.'))) {
} else {
return '\nDecided to stop at contract verification.\n'
}
}
main().then((res) => {
console.log(res ?? '\nScript succesfully finished.')
})