1
0
tornado-governance/deploy/deployStaking.js

107 lines
3.0 KiB
JavaScript
Raw Permalink Normal View History

require('dotenv').config()
const config = require('../config')
const hre = require('hardhat')
const { ethers } = hre
const { createInterface } = require('readline')
const prompter = createInterface({ input: process.stdin, output: process.stdout })
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')
}
}
function _prompt(prompt, resolve) {
prompter.question(prompt, (answer) => {
if (answer == 'y') {
resolve(true)
} else {
resolve(false)
}
})
}
function prompt(prompt) {
return new Promise((resolve) => _prompt(prompt, resolve))
}
function deployedMessage(name, chainId, address) {
return `\n${name} deployed on ${idToNetwork(chainId)} @ ${address}\n`
}
function verifiedMessage(name, address) {
return `\n${name} @ ${address} 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 deploy() {
const signer = await ethers.getSigner()
const _network = await ethers.provider.getNetwork()
const stakingDeployer = (await ethers.getContractFactory('TornadoStakingRewards')).connect(signer)
const proxyDeployer = (await ethers.getContractFactory('AdminUpgradeableProxy')).connect(signer)
let impl, proxy
if (await prompt(promptMessageBase('Continuing to TornadoStakingRewards (Implementation) deployment.'))) {
impl = await stakingDeployer.deploy(config.governance, config.TORN, config.registry)
console.log(deployedMessage('TornadoStakingRewards (Implementation)', _network.chainId, impl.address))
} else {
return '\nDecided to stop at TornadoStakingRewards (Implementation) deployment.\n'
}
if (await prompt(promptMessageBase('Continuing to Staking Proxy deployment.'))) {
proxy = await proxyDeployer.deploy(impl.address, config.governance, [])
console.log(deployedMessage('Staking Proxy', _network.chainId, proxy.address))
} else {
return '\nDecided to stop at Staking Proxy deployment.\n'
}
if (await prompt(promptMessageBase('Continuing to contract verification.'))) {
console.log('\nWaiting 20 seconds.\n')
await timeout(20)
await hre.run('verify:verify', {
address: impl.address,
constructorArguments: [config.governance, config.TORN, config.registry],
})
console.log(verifiedMessage('TornadoStakingRewards (Implementation)', impl.address))
console.log('\nWaiting 20 seconds.\n')
await timeout(20)
await hre.run('verify:verify', {
address: proxy.address,
constructorArguments: [impl.address, config.governance, []],
})
console.log(verifiedMessage('Staking Proxy', proxy.address))
} else {
return '\nDecided to stop at contract verification.\n'
}
}
deploy()