Skip to content

Commit

Permalink
temporary checkin for adding scroll support
Browse files Browse the repository at this point in the history
  • Loading branch information
yuetloo committed Jan 26, 2024
1 parent 5879ba7 commit a0654f9
Show file tree
Hide file tree
Showing 27 changed files with 6,362 additions and 822 deletions.
80 changes: 70 additions & 10 deletions contracts/cli/newRound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import { JSONFile } from '../utils/JSONFile'
import { program } from 'commander'
import { deployUserRegistry } from '../utils/deployment'
import { ZERO_ADDRESS } from '../utils/constants'
import { BaseContract } from 'ethers'
import { ClrFund, FundingRound } from '../typechain-types'

program
.description('Deploy a new funding round contract')
Expand All @@ -38,6 +40,11 @@ program
'-o --sponsor <sponsor>',
'The brightid sponsor contract address for the new user registry'
)
.option(
'-t --dry-run',
'Dry run is only used to estimate gas used, no execution',
false
)
.option(
'-s --state-file <file>',
'File to store the ClrFundDeployer address for e2e testing'
Expand All @@ -53,13 +60,17 @@ async function main(args: any) {
verifier,
sponsor,
stateFile,
dryRun,
} = args

const [signer] = await ethers.getSigners()
console.log(`Deploying from address: ${signer.address}`)
console.log('args', args)

const clrfundContract = await ethers.getContractAt('ClrFund', clrfund)
const clrfundContract = (await ethers.getContractAt(
'ClrFund',
clrfund
)) as BaseContract as ClrFund

// check if the current round is finalized before starting a new round to avoid revert
const currentRoundAddress = await clrfundContract.getCurrentRound()
Expand All @@ -76,7 +87,7 @@ async function main(args: any) {
}
}

if (newBrightid) {
if (newBrightid && !dryRun) {
const userRegistryContract = await deployUserRegistry({
ethers,
signer,
Expand All @@ -96,15 +107,64 @@ async function main(args: any) {
)
}

const tx = await clrfundContract.deployNewRound(duration)
await tx.wait()
const fundingRound = await clrfundContract.getCurrentRound()
console.log('New funding round address: ', fundingRound)
if (dryRun) {
const gas = await clrfundContract.deployNewRound.estimateGas(duration)
console.log('Estimated gas to deploy new round', gas)
} else {
try {
const newRoundTx = await clrfundContract.deployNewRound(duration)
const receipt = await newRoundTx.wait()
if (receipt?.status !== 1) {
throw new Error(
'Failed to deploy a new round, gas used' + receipt?.gasUsed.toString()
)
}

const fundingRound = await clrfundContract.getCurrentRound()
console.log(
`New funding round deployed at: ${fundingRound}.`,
`Gas used: ${receipt.gasUsed.toString()}`
)
if (stateFile) {
const pollId = 0
const state = { fundingRound, pollId, maciTxHash: newRoundTx.hash }
JSONFile.update(stateFile, state)
}
} catch (e) {
throw new Error(
'Error deploying a new funding round' + (e as Error).message
)
}

try {
const fundingRound = await clrfundContract.getCurrentRound()
const fundingRoundContract = (await ethers.getContractAt(
'FundingRound',
fundingRound
)) as BaseContract as FundingRound

if (stateFile) {
const pollId = 0
const state = { fundingRound, pollId, maciTxHash: tx.hash }
JSONFile.update(stateFile, state)
const maciFactory = await clrfundContract.maciFactory()
const coordinatorPubKey = await clrfundContract.coordinatorPubKey()
const tx = await fundingRoundContract.deployPoll(duration, maciFactory, {
x: coordinatorPubKey.x,
y: coordinatorPubKey.y,
})
const pollReceipt = await tx.wait()
if (pollReceipt?.status === 1) {
const pollAddress = await fundingRoundContract.poll()
console.log(
`Poll deployed at ${pollAddress}. Gas used:`,
pollReceipt?.gasUsed.toString()
)
} else {
console.log(
'Failed to deploy Poll. Gas used:',
pollReceipt?.gasUsed.toString()
)
}
} catch (e) {
console.log('Error deploying Poll', e)
}
}
}

Expand Down
12 changes: 6 additions & 6 deletions contracts/contracts/FundingRoundFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ contract FundingRoundFactory is MACICommon {
returns (address)
{
IClrFund clrfund = IClrFund(_clrfund);
address coordinator = clrfund.coordinator();
FundingRound newRound = new FundingRound(
clrfund.nativeToken(),
clrfund.userRegistry(),
clrfund.recipientRegistry(),
clrfund.coordinator()
coordinator
);

IMACIFactory maciFactory = clrfund.maciFactory();
(MACI maci, MACI.PollContracts memory pollContracts) = maciFactory.deployMaci(
MACI maci = maciFactory.deployMaci(
SignUpGatekeeper(newRound),
InitialVoiceCreditProxy(newRound),
address(newRound.topupToken()),
_duration,
newRound.coordinator(),
coordinator,
clrfund.coordinatorPubKey(),
address(this)
address(newRound)
);

// link funding round with maci related contracts
newRound.setMaci(maci, pollContracts);
newRound.setMaci(maci);
newRound.transferOwnership(_clrfund);
maci.transferOwnership(address(newRound));
return address(newRound);
}
}
18 changes: 1 addition & 17 deletions contracts/contracts/MACIFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ contract MACIFactory is Ownable, Params, SnarkCommon, DomainObjs, MACICommon {
address maciOwner
)
external
returns (MACI _maci, MACI.PollContracts memory _pollContracts)
returns (MACI _maci)
{
if (!vkRegistry.hasProcessVk(
stateTreeDepth,
Expand Down Expand Up @@ -193,22 +193,6 @@ contract MACIFactory is Ownable, Params, SnarkCommon, DomainObjs, MACICommon {
stateTreeDepth
);

_pollContracts = _maci.deployPoll(
duration,
maxValues,
treeDepths,
coordinatorPubKey,
address(verifier),
address(vkRegistry),
// pass false to not deploy the subsidy contract
false
);

// transfer ownership to coordinator to run the tally scripts
Ownable(_pollContracts.poll).transferOwnership(coordinator);
Ownable(_pollContracts.messageProcessor).transferOwnership(coordinator);
Ownable(_pollContracts.tally).transferOwnership(coordinator);

_maci.transferOwnership(maciOwner);

emit MaciDeployed(address(_maci));
Expand Down
9 changes: 8 additions & 1 deletion contracts/contracts/interfaces/IFundingRound.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
pragma solidity ^0.8.10;

import {ERC20} from '@openzeppelin/contracts/token/ERC20/ERC20.sol';
import {IMACIFactory} from './IMACIFactory.sol';
import {DomainObjs} from 'maci-contracts/contracts/utilities/DomainObjs.sol';

/**
* @dev FundingRound interface used by the ClrFund contract
Expand All @@ -18,4 +20,9 @@ interface IFundingRound {
uint256 _newResultCommitment,
uint256 _perVOSpentVoiceCreditsHash
) external;
}
function deployPoll(
uint256 _duration,
IMACIFactory _maciFactory,
DomainObjs.PubKey memory _coordinatorPubKey
) external;
}
2 changes: 1 addition & 1 deletion contracts/contracts/interfaces/IMACIFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,5 @@ interface IMACIFactory {
address coordinator,
DomainObjs.PubKey calldata coordinatorPubKey,
address maciOwner
) external returns (MACI _maci, MACI.PollContracts memory _pollContracts);
) external returns (MACI _maci);
}
27 changes: 22 additions & 5 deletions contracts/hardhat.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ export default {
'https://sepolia-rollup.arbitrum.io/rpc',
accounts,
},
'scroll-sepolia': {
url: process.env.JSONRPC_HTTP_URL || 'https://sepolia-rpc.scroll.io',
accounts,
},
scroll: {
url: process.env.JSONRPC_HTTP_URL || 'https://rpc.scroll.io',
accounts,
},
sepolia: {
url: process.env.JSONRPC_HTTP_URL || 'http://127.0.0.1:8545',
accounts,
Expand All @@ -78,6 +86,7 @@ export default {
arbitrum: process.env.ARBISCAN_API_KEY || 'YOUR_ARBISCAN_API_KEY',
'arbitrum-sepolia':
process.env.ARBISCAN_API_KEY || 'YOUR_ARBISCAN_API_KEY',
'scroll-sepolia': process.env.SCROLLSCAN_API_KEY || 'YOUR_API_KEY',
},
customChains: [
{
Expand All @@ -88,6 +97,14 @@ export default {
browserURL: 'https://sepolia.arbiscan.io',
},
},
{
network: 'scroll-sepolia',
chainId: 534351,
urls: {
apiURL: 'https://api-sepolia.scrollscan.com/api',
browserURL: 'https://sepolia.scrollscan.com',
},
},
],
},
sourcify: {
Expand Down Expand Up @@ -116,7 +133,7 @@ export default {
settings: {
optimizer: {
enabled: true,
runs: 1000000,
runs: 200,
},
},
},
Expand All @@ -125,7 +142,7 @@ export default {
settings: {
optimizer: {
enabled: true,
runs: 1000000,
runs: 200,
},
},
},
Expand All @@ -152,7 +169,7 @@ export default {
settings: {
optimizer: {
enabled: true,
runs: 1000000,
runs: 200,
},
},
},
Expand All @@ -161,7 +178,7 @@ export default {
settings: {
optimizer: {
enabled: true,
runs: 1000000,
runs: 200,
},
},
},
Expand All @@ -170,7 +187,7 @@ export default {
settings: {
optimizer: {
enabled: true,
runs: 1000000,
runs: 200,
},
},
},
Expand Down
Loading

0 comments on commit a0654f9

Please sign in to comment.