diff --git a/contracts/cli/newClrFund.ts b/contracts/cli/newClrFund.ts index 4d9d1ad81..22a29ec8a 100644 --- a/contracts/cli/newClrFund.ts +++ b/contracts/cli/newClrFund.ts @@ -20,6 +20,7 @@ * * If token is not provided, a new ERC20 token will be created */ +import { BigNumber } from 'ethers' import { ethers, network } from 'hardhat' import { getEventArg } from '../utils/contracts' import { newMaciPrivateKey } from '../utils/maci' @@ -31,11 +32,13 @@ import { setCoordinator, } from '../utils/deployment' import { JSONFile } from '../utils/JSONFile' -import { program } from 'commander' +import { Option, program } from 'commander' import dotenv from 'dotenv' import { UNIT } from '../utils/constants' dotenv.config() +const DEFAULT_DEPOSIT_AMOUNT = '0.001' + program .description('Deploy a new ClrFund instance') .requiredOption( @@ -44,16 +47,43 @@ program ) .option('-c --coordinator ', 'The coordinator ETH address') .option('-t --token
', 'The native token address') - .option('-a --initial-token-supply ', 'Initial token amount', '1000') - .option('-u --user-registry-type ', 'The user registry type') + .addOption( + new Option( + '-a --initial-token-supply ', + 'Initial token amount for new token' + ).default(1000) + ) + .addOption( + new Option( + '-u --user-registry-type ', + 'The user registry type' + ).choices(['simple', 'brightid', 'merkle', 'storage']) + ) .option('-x --brightid-context ', 'The brightid context') - .option('-v --brightid-verifier ', 'The brightid verifier address') + .addOption( + new Option( + '-v --brightid-verifier ', + 'The brightid verifier address' + ).default('0xdbf0b2ee9887fe11934789644096028ed3febe9c') + ) .option( '-o --brightid-sponsor ', 'The brightid sponsor contract address' ) - .option('-r --recipient-registry-type ', 'The recipient registry type') - .option('-b --deposit ', 'The optimistic recipient registry deposit') + .addOption( + new Option( + '-r --recipient-registry-type ', + 'The recipient registry type' + ) + .choices(['simple', 'optimistic']) + .default('optimistic') + ) + .addOption( + new Option( + '-b --deposit ', + 'The optimistic recipient registry deposit' + ).default(DEFAULT_DEPOSIT_AMOUNT) + ) .option( '-p --challenge-period ', 'The optimistic recipient registry challenge period in seconds', @@ -149,20 +179,23 @@ async function main(args: any) { // set recipient registry let recipientRegistryAddress = args.recipientRegistryAddress if (!recipientRegistryAddress) { + const deposit = parseDeposit(args.deposit) const recipientRegistryContract = await deployRecipientRegistry({ ethers, signer, type: args.recipientRegistryType, challengePeriod: args.challengePeriod, - deposit: args.deposit, + deposit, controller: clrfund, }) recipientRegistryAddress = recipientRegistryContract.address } + const setRecipientRegistryTx = await clrfundContract.setRecipientRegistry( recipientRegistryAddress ) await setRecipientRegistryTx.wait() + console.log( `Set ${args.recipientRegistryType} recipient registry: ${recipientRegistryAddress}` ) @@ -172,6 +205,14 @@ async function main(args: any) { } } +function parseDeposit(deposit: string): BigNumber { + try { + return ethers.utils.parseUnits(deposit) + } catch (e) { + throw new Error(`Error parsing deposit ${(e as Error).message}`) + } +} + main(program.opts()) .then(() => { process.exit(0) diff --git a/contracts/cli/newRound.ts b/contracts/cli/newRound.ts index 951dcb5ce..e13f5bdc4 100644 --- a/contracts/cli/newRound.ts +++ b/contracts/cli/newRound.ts @@ -25,9 +25,18 @@ program 'Create a new BrightId user registry', false ) - .option('-x --context ', 'The brightid context') - .option('-v --verifier ', 'The brightid verifier address') - .option('-o --sponsor ', 'The brightid sponsor contract address') + .option( + '-x --context ', + 'The brightid context for the new user registry' + ) + .option( + '-v --verifier ', + 'The brightid verifier address for the new user registry' + ) + .option( + '-o --sponsor ', + 'The brightid sponsor contract address for the new user registry' + ) .option( '-s --state-file ', 'File to store the ClrFundDeployer address for e2e testing' diff --git a/contracts/hardhat.config.ts b/contracts/hardhat.config.ts index 36b27c28f..8a7d3a827 100644 --- a/contracts/hardhat.config.ts +++ b/contracts/hardhat.config.ts @@ -8,6 +8,7 @@ import '@nomiclabs/hardhat-waffle' import '@nomiclabs/hardhat-ganache' import 'hardhat-contract-sizer' import '@nomiclabs/hardhat-etherscan' +import './tasks' dotenv.config() diff --git a/contracts/tasks/index.ts b/contracts/tasks/index.ts index 12beb4e12..16be9d08d 100644 --- a/contracts/tasks/index.ts +++ b/contracts/tasks/index.ts @@ -1,35 +1,6 @@ -import './newDeployer' -import './newClrFund' -import './newMaciKey' -import './newRound' -import './setToken' -import './setCoordinator' -import './setUserRegistry' -import './setRecipientRegistry' -import './setMaciParameters' -import './setPollFactory' -import './cancelRound' -import './addContributors' -import './addRecipients' -import './contribute' -import './vote' -import './timeTravel' -import './finalize' -import './claim' - import './verifyAll' import './verifyMaciFactory' import './verifyRound' import './verifyMaci' import './verifyRecipientRegistry' import './verifyUserRegistry' -import './auditTally' -import './exportRound' -import './mergeAllocations' -import './deploySponsor' -import './loadUsers' -import './findStorageSlot' -import './setStorageRoot' -import './loadMerkleUsers' - -import './pubkey' diff --git a/contracts/tasks/verifyAll.ts b/contracts/tasks/verifyAll.ts index 2b9da8ac3..a7f94d291 100644 --- a/contracts/tasks/verifyAll.ts +++ b/contracts/tasks/verifyAll.ts @@ -102,8 +102,9 @@ async function verifyTally(tally: Contract, run: any): Promise { async function verifyPoll(pollContract: Contract, run: any): Promise { try { + const [, duration] = await pollContract.getDeployTimeAndDuration() const constructorArguments = await Promise.all([ - pollContract.duration(), + Promise.resolve(duration), pollContract.maxValues(), pollContract.treeDepths(), pollContract.batchSizes(), diff --git a/contracts/tasks/verifyMaci.ts b/contracts/tasks/verifyMaci.ts index 11d8057ae..560c1c921 100644 --- a/contracts/tasks/verifyMaci.ts +++ b/contracts/tasks/verifyMaci.ts @@ -4,43 +4,19 @@ import { task } from 'hardhat/config' * Verifies the MACI contract * - it constructs the constructor arguments by querying the MACI contract * - it calls the etherscan hardhat plugin to verify the contract + * + * Sample usage: + * yarn hardhat verify-maci --network */ task('verify-maci', 'Verify a MACI contract') .addPositionalParam('maciAddress', 'MACI contract address') .setAction(async ({ maciAddress }, { run, ethers }) => { const maci = await ethers.getContractAt('MACI', maciAddress) - const treeDepths = await maci.treeDepths() - const tallyBatchSize = await maci.tallyBatchSize() - const messageBatchSize = await maci.messageBatchSize() - const maxUsers = await maci.maxUsers() - const maxMessages = await maci.maxMessages() - const maxVoteOptions = await maci.voteOptionsMaxLeafIndex() - const signUpGatekeeper = await maci.signUpGatekeeper() - const batchUstVerifier = await ethers.provider.getStorageAt(maciAddress, 1) - const qvtVerifier = await ethers.provider.getStorageAt(maciAddress, 2) - const signUpDurationSeconds = await maci.signUpDurationSeconds() - const votingDurationSeconds = await maci.votingDurationSeconds() - const initialVoiceCreditProxy = await maci.initialVoiceCreditProxy() - const coordinatorAddress = await maci.coordinatorAddress() - const coordinatorPubKey = await maci.coordinatorPubKey() - - const constructorArguments = [ - { - stateTreeDepth: treeDepths[0], - messageTreeDepth: treeDepths[1], - voteOptionTreeDepth: treeDepths[2], - }, - { tallyBatchSize, messageBatchSize }, - { maxUsers, maxMessages, maxVoteOptions }, - signUpGatekeeper, - ethers.utils.hexDataSlice(batchUstVerifier, 12), - ethers.utils.hexDataSlice(qvtVerifier, 12), - signUpDurationSeconds, - votingDurationSeconds, - initialVoiceCreditProxy, - { x: coordinatorPubKey.x, y: coordinatorPubKey.y }, - coordinatorAddress, - ] + const constructorArguments = await Promise.all([ + maci.pollFactory(), + maci.signUpGatekeeper(), + maci.initialVoiceCreditProxy(), + ]) console.log('Verifying the MACI contract', maciAddress) console.log('Constructor arguments', constructorArguments)