diff --git a/contracts/cli/newDeployer.ts b/contracts/cli/newDeployer.ts index c3d87148e..7c2954e47 100644 --- a/contracts/cli/newDeployer.ts +++ b/contracts/cli/newDeployer.ts @@ -42,35 +42,35 @@ async function main(args: any) { console.log('Deployed Poseidons', libraries) const maciFactory = await deployMaciFactory({ libraries, ethers }) - console.log('Deployed MaciFactory at', maciFactory.address) + console.log('Deployed MaciFactory at', maciFactory.target) await setMaciParameters(maciFactory, args.directory, args.circuit) const clrfundTemplate = await deployContract({ name: 'ClrFund', ethers, }) - console.log('Deployed ClrFund Template at', clrfundTemplate.address) + console.log('Deployed ClrFund Template at', clrfundTemplate.target) const fundingRoundFactory = await deployContract({ name: 'FundingRoundFactory', - libraries, ethers, }) - console.log('Deployed FundingRoundFactory at', fundingRoundFactory.address) + console.log('Deployed FundingRoundFactory at', fundingRoundFactory.target) const clrfundDeployer = await deployContract({ name: 'ClrFundDeployer', ethers, contractArgs: [ - clrfundTemplate.address, - maciFactory.address, - fundingRoundFactory.address, + clrfundTemplate.target, + maciFactory.target, + fundingRoundFactory.target, ], }) - console.log('Deployed ClrfundDeployer at', clrfundDeployer.address) + console.log('Deployed ClrfundDeployer at', clrfundDeployer.target) if (args.stateFile) { - JSONFile.update(args.stateFile, { deployer: clrfundDeployer.address }) + const clrfundDeployerAddress = await clrfundDeployer.getAddress() + JSONFile.update(args.stateFile, { deployer: clrfundDeployerAddress }) } } @@ -78,7 +78,7 @@ main(program.opts()) .then(() => { process.exit(0) }) - .catch((err) => { + .catch(err => { console.error(err) process.exit(-1) }) diff --git a/contracts/cli/newRound.ts b/contracts/cli/newRound.ts index e13f5bdc4..9abb59c7e 100644 --- a/contracts/cli/newRound.ts +++ b/contracts/cli/newRound.ts @@ -12,6 +12,7 @@ import { ethers } from 'hardhat' import { JSONFile } from '../utils/JSONFile' import { program } from 'commander' import { deployUserRegistry } from '../utils/deployment' +import { ZERO_ADDRESS } from '../utils/constants' program .description('Deploy a new funding round contract') @@ -62,7 +63,7 @@ async function main(args: any) { // check if the current round is finalized before starting a new round to avoid revert const currentRoundAddress = await clrfundContract.getCurrentRound() - if (currentRoundAddress !== ethers.constants.AddressZero) { + if (currentRoundAddress !== ZERO_ADDRESS) { const currentRound = await ethers.getContractAt( 'FundingRound', currentRoundAddress @@ -111,7 +112,7 @@ main(program.opts()) .then(() => { process.exit(0) }) - .catch((err) => { + .catch(err => { console.error(err) process.exit(-1) }) diff --git a/contracts/package.json b/contracts/package.json index 6cf2f96ae..6595da5eb 100644 --- a/contracts/package.json +++ b/contracts/package.json @@ -31,7 +31,7 @@ "@nomicfoundation/hardhat-ethers": "^3.0.5", "@nomicfoundation/hardhat-network-helpers": "^1.0.10", "@nomicfoundation/hardhat-toolbox": "^4.0.0", - "@nomicfoundation/hardhat-verify": "^2.0.0", + "@nomicfoundation/hardhat-verify": "^2.0.3", "@nomiclabs/hardhat-ganache": "^2.0.1", "@typechain/ethers-v6": "^0.5.1", "@typechain/hardhat": "^9.1.0", diff --git a/contracts/tasks/verifyAll.ts b/contracts/tasks/verifyAll.ts index a7f94d291..e9578ff84 100644 --- a/contracts/tasks/verifyAll.ts +++ b/contracts/tasks/verifyAll.ts @@ -1,5 +1,6 @@ import { Contract } from 'ethers' import { task } from 'hardhat/config' +import { ZERO_ADDRESS } from '../utils/constants' const SUCCESS = 'success' @@ -10,14 +11,16 @@ type Result = { async function verifyDeployer(deployer: Contract, run: any): Promise { try { - const { address } = deployer const constructorArguments = await Promise.all([ deployer.clrfundTemplate(), deployer.maciFactory(), deployer.roundFactory(), ]) - await run('verify:verify', { address, constructorArguments }) + await run('verify:verify', { + address: deployer.target, + constructorArguments, + }) return SUCCESS } catch (error) { return (error as Error).message @@ -30,7 +33,9 @@ async function verifyMaciFactory( ): Promise { try { const address = await deployer.maciFactory() - await run('verify-maci-factory', { address }) + if (address !== ZERO_ADDRESS) { + await run('verify-maci-factory', { address }) + } return SUCCESS } catch (error) { return (error as Error).message @@ -39,7 +44,7 @@ async function verifyMaciFactory( async function verifyClrFund(clrfund: Contract, run: any): Promise { try { - await run('verify', { address: clrfund.address }) + await run('verify', { address: clrfund.target }) return SUCCESS } catch (error) { return (error as Error).message @@ -52,7 +57,9 @@ async function verifyRecipientRegistry( ): Promise { try { const address = await factory.recipientRegistry() - await run('verify-recipient-registry', { address }) + if (address !== ZERO_ADDRESS) { + await run('verify-recipient-registry', { address }) + } return SUCCESS } catch (error) { return (error as Error).message @@ -60,12 +67,14 @@ async function verifyRecipientRegistry( } async function verifyUserRegistry( - factory: Contract, + clrfund: Contract, run: any ): Promise { try { - const address = await factory.userRegistry() - await run('verify-user-registry', { address }) + const address = await clrfund.userRegistry() + if (address !== ZERO_ADDRESS) { + await run('verify-user-registry', { address }) + } return SUCCESS } catch (error) { return (error as Error).message @@ -93,7 +102,7 @@ async function verifyMaci(maciAddress: string, run: any): Promise { async function verifyTally(tally: Contract, run: any): Promise { try { const constructorArguments = await Promise.all([tally.verifier()]) - await run('verify:verify', { address: tally.address, constructorArguments }) + await run('verify:verify', { address: tally.target, constructorArguments }) return SUCCESS } catch (error) { return (error as Error).message @@ -111,8 +120,11 @@ async function verifyPoll(pollContract: Contract, run: any): Promise { pollContract.coordinatorPubKey(), pollContract.extContracts(), ]) - const { address } = pollContract - await run('verify:verify', { address, constructorArguments }) + + await run('verify:verify', { + address: pollContract.target, + constructorArguments, + }) return SUCCESS } catch (error) { return (error as Error).message @@ -172,7 +184,7 @@ task('verify-all', 'Verify all clrfund contracts') let status = await verifyDeployer(deployerContract, run) results.push({ name: 'ClrFund Deployer', status }) status = await verifyMaciFactory(deployerContract, run) - results.push({ name: 'Maci facotry', status }) + results.push({ name: 'Maci factory', status }) if (clrfund) { const clrfundContract = await ethers.getContractAt('ClrFund', clrfund) @@ -181,14 +193,14 @@ task('verify-all', 'Verify all clrfund contracts') status = await verifyRecipientRegistry(clrfundContract, run) results.push({ name: 'Recipient registry', status }) status = await verifyUserRegistry(clrfundContract, run) - results.push({ name: 'User factory', status }) + results.push({ name: 'User registry', status }) const sponsor = await getBrightIdSponsor(clrfundContract, ethers) if (sponsor) { await verifyContract('Sponsor', sponsor, run, results) } const roundAddress = await clrfundContract.getCurrentRound() - if (roundAddress !== ethers.constants.AddressZero) { + if (roundAddress !== ZERO_ADDRESS) { const round = await ethers.getContractAt('FundingRound', roundAddress) const maciAddress = await round.maci() status = await verifyRound(roundAddress, run) @@ -197,14 +209,14 @@ task('verify-all', 'Verify all clrfund contracts') results.push({ name: 'MACI', status }) const poll = await round.poll() - if (poll !== ethers.constants.AddressZero) { + if (poll !== ZERO_ADDRESS) { const pollContract = await ethers.getContractAt('Poll', poll) status = await verifyPoll(pollContract, run) results.push({ name: 'Poll', status }) } const tally = await round.tally() - if (tally !== ethers.constants.AddressZero) { + if (tally !== ZERO_ADDRESS) { const tallyContract = await ethers.getContractAt('Tally', tally) status = await verifyTally(tallyContract, run) results.push({ name: 'Tally', status }) @@ -231,9 +243,13 @@ task('verify-all', 'Verify all clrfund contracts') run, results ) + + const factories = await maciFactory.factories() + await verifyContract('PollFactory', factories.pollFactory, run, results) + await verifyContract('TallyFactory', factories.tallyFactory, run, results) await verifyContract( - 'PollFactory', - await maciFactory.pollFactory(), + 'MessageProcessorFactory', + factories.messageProcessorFactory, run, results ) diff --git a/contracts/tasks/verifyMaciFactory.ts b/contracts/tasks/verifyMaciFactory.ts index 54fdcf86f..911fecfd3 100644 --- a/contracts/tasks/verifyMaciFactory.ts +++ b/contracts/tasks/verifyMaciFactory.ts @@ -4,7 +4,8 @@ import { Contract } from 'ethers' async function getConstructorArguments(maciFactory: Contract): Promise { const result = await Promise.all([ maciFactory.vkRegistry(), - maciFactory.pollFactory(), + maciFactory.factories(), + maciFactory.verifier(), ]) return result }