From 5544eca83b15048bc4f6d44b31e5986bf2b35823 Mon Sep 17 00:00:00 2001 From: AlienTornadosaurusHex <> Date: Thu, 25 May 2023 16:31:55 +0000 Subject: [PATCH] Add all deploy scripts Signed-off-by: AlienTornadosaurusHex <> --- .env.example | 10 ++-- contracts/v1/Delegation.sol | 5 +- contracts/v1/Governance.sol | 17 ++++-- contracts/v1/LoopbackProxy.sol | 6 ++- deploy/deployPatch.js | 31 ++++------- deploy/deployRegistryImplementation.js | 72 ++++++++++++++++++++++++++ deploy/deployStaking.js | 66 +++++++++++++++++++++++ hardhat.config.js | 4 +- 8 files changed, 178 insertions(+), 33 deletions(-) create mode 100644 deploy/deployRegistryImplementation.js create mode 100644 deploy/deployStaking.js diff --git a/.env.example b/.env.example index 3bd1b87..39dfdf3 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,8 @@ -ETHERSCAN_KEY= RPC_URL= -PK= -use_latest_block=false +PRIVATE_KEY= +ETHERSCAN_KEY= +LATEST_BLOCK=false + +# For deploying the proposal +REGISTRY_IMPL_ADDRESS= +STAKING_ADDRESS= \ No newline at end of file diff --git a/contracts/v1/Delegation.sol b/contracts/v1/Delegation.sol index 3324b89..604bfb3 100644 --- a/contracts/v1/Delegation.sol +++ b/contracts/v1/Delegation.sol @@ -13,7 +13,10 @@ abstract contract Delegation is Core { function delegate(address to) external { address previous = delegatedTo[msg.sender]; - require(to != msg.sender && to != address(this) && to != address(0) && to != previous, "Governance: invalid delegatee"); + require( + to != msg.sender && to != address(this) && to != address(0) && to != previous, + "Governance: invalid delegatee" + ); if (previous != address(0)) { emit Undelegated(msg.sender, previous); } diff --git a/contracts/v1/Governance.sol b/contracts/v1/Governance.sol index 7031de8..40e362e 100644 --- a/contracts/v1/Governance.sol +++ b/contracts/v1/Governance.sol @@ -145,7 +145,10 @@ contract Governance is Initializable, Configuration, Delegation, EnsResolve { string memory description ) internal virtual override(Delegation) returns (uint256) { uint256 votingPower = lockedBalance[proposer]; - require(votingPower >= PROPOSAL_THRESHOLD, "Governance::propose: proposer votes below proposal threshold"); + require( + votingPower >= PROPOSAL_THRESHOLD, + "Governance::propose: proposer votes below proposal threshold" + ); // target should be a contract require(Address.isContract(target), "Governance::propose: not a contract"); @@ -153,7 +156,8 @@ contract Governance is Initializable, Configuration, Delegation, EnsResolve { if (latestProposalId != 0) { ProposalState proposersLatestProposalState = state(latestProposalId); require( - proposersLatestProposalState != ProposalState.Active && proposersLatestProposalState != ProposalState.Pending, + proposersLatestProposalState != ProposalState.Active && + proposersLatestProposalState != ProposalState.Pending, "Governance::propose: one live proposal per proposer, found an already active proposal" ); } @@ -182,7 +186,10 @@ contract Governance is Initializable, Configuration, Delegation, EnsResolve { } function execute(uint256 proposalId) public payable virtual { - require(state(proposalId) == ProposalState.AwaitingExecution, "Governance::execute: invalid proposal state"); + require( + state(proposalId) == ProposalState.AwaitingExecution, + "Governance::execute: invalid proposal state" + ); Proposal storage proposal = proposals[proposalId]; proposal.executed = true; @@ -266,7 +273,9 @@ contract Governance is Initializable, Configuration, Delegation, EnsResolve { return ProposalState.Pending; } else if (getBlockTimestamp() <= proposal.endTime) { return ProposalState.Active; - } else if (proposal.forVotes <= proposal.againstVotes || proposal.forVotes + proposal.againstVotes < QUORUM_VOTES) { + } else if ( + proposal.forVotes <= proposal.againstVotes || proposal.forVotes + proposal.againstVotes < QUORUM_VOTES + ) { return ProposalState.Defeated; } else if (proposal.executed) { return ProposalState.Executed; diff --git a/contracts/v1/LoopbackProxy.sol b/contracts/v1/LoopbackProxy.sol index 3910480..49bd2d5 100644 --- a/contracts/v1/LoopbackProxy.sol +++ b/contracts/v1/LoopbackProxy.sol @@ -13,7 +13,11 @@ contract LoopbackProxy is TransparentUpgradeableProxy, EnsResolve { /** * @dev Initializes an upgradeable proxy backed by the implementation at `_logic`. */ - constructor(address _logic, bytes memory _data) public payable TransparentUpgradeableProxy(_logic, address(this), _data) {} + constructor(address _logic, bytes memory _data) + public + payable + TransparentUpgradeableProxy(_logic, address(this), _data) + {} /** * @dev Override to allow admin (itself) access the fallback function. diff --git a/deploy/deployPatch.js b/deploy/deployPatch.js index 4a71dd8..bf4e923 100644 --- a/deploy/deployPatch.js +++ b/deploy/deployPatch.js @@ -39,40 +39,29 @@ const promptMessageBase = (middle) => `\n${middle}\n\nAre you sure you would lik async function deploy() { const signer = await ethers.getSigner() - const patchProposalContractsFactoryDeployer = ( - await ethers.getContractFactory('PatchProposalContractsFactory') - ).connect(signer) + if (process.env.STAKING_ADDRESS === undefined) throw Error('Missing STAKING_ADDRESS.') + + if (process.env.REGISTRY_IMPL_ADDRESS === undefined) throw Error('Missing REGISTRY_IMPL_ADDRESS.') + + const stakingAddress = `${process.env.STAKING_ADDRESS}` + + const registryImplementationAddress = `${process.env.REGISTRY_IMPL_ADDRESS}` const patchProposalDeployer = (await ethers.getContractFactory('PatchProposal')).connect(signer) - let patchProposal, patchProposalContractsFactory - - if (await prompt(promptMessageBase('Continuing to PatchProposalContractsFactory deployment.'))) { - patchProposalContractsFactory = await patchProposalContractsFactoryDeployer.deploy() - console.log(deployedMessage('PatchProposalContractsFactory', 1, patchProposalContractsFactory.address)) - } else { - return '\nDecided to stop at PatchProposalContractsFactory deployment.\n' - } + let patchProposal if (await prompt(promptMessageBase('Continuing to PatchProposal deployment.'))) { - patchProposal = await patchProposalDeployer.deploy(patchProposalContractsFactory.address) + patchProposal = await patchProposalDeployer.deploy(stakingAddress, registryImplementationAddress) console.log(deployedMessage('PatchProposal', 1, patchProposal.address)) } else { return '\nDecided to stop at PatchProposal deployment.\n' } if (await prompt(promptMessageBase('Continuing to contract verification.'))) { - await hre.run('verify:verify', { - address: patchProposalContractsFactory.address, - }) - - console.log(verifiedMessage('PatchProposalContractsFactory')) - console.log('\nWaiting 5 seconds.\n') - await timeout(5) - await hre.run('verify:verify', { address: patchProposal.address, - constructorArguments: [patchProposalContractsFactory.address], + constructorArguments: [stakingAddress, registryImplementationAddress], }) console.log(verifiedMessage('PatchProposal')) diff --git a/deploy/deployRegistryImplementation.js b/deploy/deployRegistryImplementation.js new file mode 100644 index 0000000..1116fe8 --- /dev/null +++ b/deploy/deployRegistryImplementation.js @@ -0,0 +1,72 @@ +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 _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 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 registryImplementationDeployer = (await ethers.getContractFactory('RelayerRegistry')).connect(signer) + + let registry + + if (await prompt(promptMessageBase('Continuing to RelayerRegistry (Implementation) deployment.'))) { + registry = await registryImplementationDeployer.deploy( + config.TORN, + config.governance, + config.ens, + config.staking, + config.feeManager, + ) + console.log(deployedMessage('RelayerRegistry (Implementation)', 1, registry.address)) + } else { + return '\nDecided to stop at RelayerRegistry (Implementation) deployment.\n' + } + + if (await prompt(promptMessageBase('Continuing to contract verification.'))) { + await hre.run('verify:verify', { + address: registry.address, + constructorArguments: [config.TORN, config.governance, config.ens, config.staking, config.feeManager], + }) + console.log(verifiedMessage('RelayerRegistry (Implementation)')) + } else { + return '\nDecided to stop at contract verification.\n' + } +} + +deploy() diff --git a/deploy/deployStaking.js b/deploy/deployStaking.js new file mode 100644 index 0000000..f81dbc2 --- /dev/null +++ b/deploy/deployStaking.js @@ -0,0 +1,66 @@ +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 _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 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 stakingDeployer = (await ethers.getContractFactory('TornadoStakingRewards')).connect(signer) + + let staking + + if (await prompt(promptMessageBase('Continuing to TornadoStakingRewards deployment.'))) { + staking = await stakingDeployer.deploy(config.governance, config.TORN, config.registry) + console.log(deployedMessage('TornadoStakingRewards', 1, staking.address)) + } else { + return '\nDecided to stop at TornadoStakingRewards deployment.\n' + } + + if (await prompt(promptMessageBase('Continuing to contract verification.'))) { + await hre.run('verify:verify', { + address: staking.address, + constructorArguments: [config.governance, config.TORN, config.registry], + }) + console.log(verifiedMessage('TornadoStakingRewards')) + } else { + return '\nDecided to stop at contract verification.\n' + } +} + +deploy() diff --git a/hardhat.config.js b/hardhat.config.js index 52954c0..8ece551 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -8,8 +8,6 @@ require('hardhat-log-remover') require('hardhat-contract-sizer') require('solidity-coverage') -const config = require('./config') - /** * @type import('hardhat/config').HardhatUserConfig */ @@ -61,7 +59,7 @@ module.exports = { }, mainnet: { url: `${process.env.RPC_URL}`, - //accounts: [`${process.env.PK}`], + accounts: process.env.PRIVATE_KEY ? [`${process.env.PRIVATE_KEY}`] : undefined, timeout: 9999999999, }, },