Skip to content

Commit

Permalink
update contract address to target for ether v6
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jan 18, 2024
1 parent 1edf7c8 commit 3000493
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 32 deletions.
20 changes: 10 additions & 10 deletions contracts/cli/newDeployer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,43 +42,43 @@ 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 })
}
}

main(program.opts())
.then(() => {
process.exit(0)
})
.catch((err) => {
.catch(err => {
console.error(err)
process.exit(-1)
})
5 changes: 3 additions & 2 deletions contracts/cli/newRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -111,7 +112,7 @@ main(program.opts())
.then(() => {
process.exit(0)
})
.catch((err) => {
.catch(err => {
console.error(err)
process.exit(-1)
})
2 changes: 1 addition & 1 deletion contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
52 changes: 34 additions & 18 deletions contracts/tasks/verifyAll.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Contract } from 'ethers'
import { task } from 'hardhat/config'
import { ZERO_ADDRESS } from '../utils/constants'

const SUCCESS = 'success'

Expand All @@ -10,14 +11,16 @@ type Result = {

async function verifyDeployer(deployer: Contract, run: any): Promise<string> {
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
Expand All @@ -30,7 +33,9 @@ async function verifyMaciFactory(
): Promise<string> {
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
Expand All @@ -39,7 +44,7 @@ async function verifyMaciFactory(

async function verifyClrFund(clrfund: Contract, run: any): Promise<string> {
try {
await run('verify', { address: clrfund.address })
await run('verify', { address: clrfund.target })
return SUCCESS
} catch (error) {
return (error as Error).message
Expand All @@ -52,20 +57,24 @@ async function verifyRecipientRegistry(
): Promise<string> {
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
}
}

async function verifyUserRegistry(
factory: Contract,
clrfund: Contract,
run: any
): Promise<string> {
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
Expand Down Expand Up @@ -93,7 +102,7 @@ async function verifyMaci(maciAddress: string, run: any): Promise<string> {
async function verifyTally(tally: Contract, run: any): Promise<string> {
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
Expand All @@ -111,8 +120,11 @@ async function verifyPoll(pollContract: Contract, run: any): Promise<string> {
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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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 })
Expand All @@ -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
)
Expand Down
3 changes: 2 additions & 1 deletion contracts/tasks/verifyMaciFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import { Contract } from 'ethers'
async function getConstructorArguments(maciFactory: Contract): Promise<any[]> {
const result = await Promise.all([
maciFactory.vkRegistry(),
maciFactory.pollFactory(),
maciFactory.factories(),
maciFactory.verifier(),
])
return result
}
Expand Down

0 comments on commit 3000493

Please sign in to comment.