Skip to content

Commit c805981

Browse files
committed
update contribute and vote scripts to make many contributions and votes
1 parent 8e74169 commit c805981

File tree

4 files changed

+128
-54
lines changed

4 files changed

+128
-54
lines changed

contracts/package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
"deployTestRound:local": "hardhat run --network localhost scripts/deployTestRound.ts",
1212
"contribute:local": "hardhat run --network localhost scripts/contribute.ts",
1313
"vote:local": "hardhat run --network localhost scripts/vote.ts",
14+
"deploy:rinkarby": "hardhat run --network rinkarby scripts/deployRound.ts",
15+
"contribute:rinkarby": "hardhat run --network rinkarby scripts/contribute.ts",
16+
"vote:rinkarby": "hardhat run --network rinkarby scripts/vote.ts",
1417
"tally:local": "hardhat run --network localhost scripts/tally.ts",
1518
"finalize:local": "hardhat run --network localhost scripts/finalize.ts",
1619
"claim:local": "hardhat run --network localhost scripts/claim.ts",

contracts/scripts/contribute.ts

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,32 @@
11
import fs from 'fs'
2+
import { Wallet } from 'ethers'
23
import { ethers } from 'hardhat'
34
import { Keypair } from 'maci-domainobjs'
45

56
import { UNIT } from '../utils/constants'
67
import { getEventArg } from '../utils/contracts'
78

89
async function main() {
9-
const [, , , , , , , , , , , , contributor1, contributor2] =
10-
await ethers.getSigners()
10+
// const [, , , , , , , , , , , , contributor1, contributor2, contributor3] =
11+
// await ethers.getSigners()
12+
13+
const contributor1 = new Wallet(
14+
process.env.CONTRIBUTOR_PK_1!,
15+
ethers.provider
16+
)
17+
const contributor2 = new Wallet(
18+
process.env.CONTRIBUTOR_PK_2!,
19+
ethers.provider
20+
)
21+
const contributor3 = new Wallet(
22+
process.env.CONTRIBUTOR_PK_3!,
23+
ethers.provider
24+
)
25+
const contributor4 = new Wallet(
26+
process.env.CONTRIBUTOR_PK_4!,
27+
ethers.provider
28+
)
29+
1130
const state = JSON.parse(fs.readFileSync('state.json').toString())
1231
const fundingRound = await ethers.getContractAt(
1332
'FundingRound',
@@ -21,7 +40,12 @@ async function main() {
2140
const contributionAmount = UNIT.mul(16).div(10)
2241
state.contributors = {}
2342

24-
for (const contributor of [contributor1, contributor2]) {
43+
for (const contributor of [
44+
contributor1,
45+
contributor2,
46+
contributor3,
47+
contributor4,
48+
]) {
2549
const contributorAddress = await contributor.getAddress()
2650
const contributorKeypair = new Keypair()
2751
const tokenAsContributor = token.connect(contributor)

contracts/scripts/deployRound.ts

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ async function main() {
4040
deployer
4141
)
4242
userRegistry = await SimpleUserRegistry.deploy()
43+
44+
const users = [
45+
'0x63bb006f4E87Ce48dC62f440d14a114718302db7',
46+
'0xf75E7D74F0C425457E6389e152AEf6241aC62E0e',
47+
'0xa70bd8D67A222F8D8E0D15999A87666da0406Fe4',
48+
'0x03C6464805102E497EA695e8b0423Ae36e5Df240',
49+
]
50+
let addUserTx
51+
for (const account of users) {
52+
addUserTx = await userRegistry.addUser(account)
53+
addUserTx.wait()
54+
}
4355
} else if (userRegistryType === 'brightid') {
4456
const BrightIdUserRegistry = await ethers.getContractFactory(
4557
'BrightIdUserRegistry',
@@ -112,8 +124,8 @@ async function main() {
112124
maciFactory = await ethers.getContractAt('MACIFactory', maciFactory.address)
113125
const maciParameters = await MaciParameters.read(maciFactory)
114126
maciParameters.update({
115-
signUpDuration: 86400 * 14,
116-
votingDuration: 86400 * 3,
127+
signUpDuration: 60 * 30,
128+
votingDuration: 60 * 1,
117129
})
118130
const setMaciParametersTx = await fundingRoundFactory.setMaciParameters(
119131
...maciParameters.values()
@@ -184,52 +196,50 @@ async function main() {
184196
}
185197
} else if (recipientRegistryType === 'optimistic') {
186198
const deposit = await recipientRegistry.baseDeposit()
187-
const recipient1Added = await recipientRegistry.addRecipient(
188-
deployer.address,
189-
JSON.stringify(metadataRecipient1),
190-
{ value: deposit }
191-
)
192-
await recipient1Added.wait()
193199

194-
const recipient1Id = await getEventArg(
195-
recipient1Added,
196-
recipientRegistry,
197-
'RequestSubmitted',
198-
'_recipientId'
199-
)
200-
const executeRequest1 = await recipientRegistry.executeRequest(recipient1Id)
201-
await executeRequest1.wait()
202-
203-
const recipient2Added = await recipientRegistry.addRecipient(
204-
deployer.address,
205-
JSON.stringify(metadataRecipient2),
206-
{ value: deposit }
207-
)
208-
await recipient2Added.wait()
200+
const recipientsNumber = 10
201+
for (
202+
let recipientsIndex = 0;
203+
recipientsIndex < recipientsNumber;
204+
recipientsIndex++
205+
) {
206+
const metadata = {
207+
...metadataRecipient1,
208+
description: `${metadataRecipient1.description}${recipientsIndex}`,
209+
}
210+
const recipient3Added = await recipientRegistry.addRecipient(
211+
deployer.getAddress(),
212+
JSON.stringify(metadata),
213+
{ value: deposit }
214+
)
215+
recipient3Added.wait()
209216

210-
const recipient2Id = await getEventArg(
211-
recipient2Added,
212-
recipientRegistry,
213-
'RequestSubmitted',
214-
'_recipientId'
215-
)
216-
const executeRequest2 = await recipientRegistry.executeRequest(recipient2Id)
217-
await executeRequest2.wait()
217+
const recipient3Id = await getEventArg(
218+
recipient3Added,
219+
recipientRegistry,
220+
'RequestSubmitted',
221+
'_recipientId'
222+
)
223+
const executeRequest3 = await recipientRegistry.executeRequest(
224+
recipient3Id
225+
)
226+
await executeRequest3.wait()
227+
}
228+
}
218229

219-
const fundingRoundAddress = await fundingRoundFactory.getCurrentRound()
220-
console.log('fundingRound.address: ', fundingRoundAddress)
230+
const fundingRoundAddress = await fundingRoundFactory.getCurrentRound()
231+
console.log('fundingRound.address: ', fundingRoundAddress)
221232

222-
const fundingRound = await ethers.getContractAt(
223-
'FundingRound',
224-
fundingRoundAddress
225-
)
226-
const maciAddress = await fundingRound.maci()
227-
console.log('maci.address: ', maciAddress)
233+
const fundingRound = await ethers.getContractAt(
234+
'FundingRound',
235+
fundingRoundAddress
236+
)
237+
const maciAddress = await fundingRound.maci()
238+
console.log('maci.address: ', maciAddress)
228239

229-
console.log('*******************')
230-
console.log('Deploy complete!')
231-
console.log('*******************')
232-
}
240+
console.log('*******************')
241+
console.log('Deploy complete!')
242+
console.log('*******************')
233243
}
234244

235245
main()

contracts/scripts/vote.ts

Lines changed: 45 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,42 @@
11
import fs from 'fs'
22
import { ethers } from 'hardhat'
3-
import { BigNumber } from 'ethers'
3+
import { BigNumber, Wallet } from 'ethers'
44
import { PrivKey, Keypair } from 'maci-domainobjs'
55

66
import { createMessage } from '../utils/maci'
77

88
async function main() {
9-
const [, , , , , , , , , , , , contributor1, contributor2] =
10-
await ethers.getSigners()
9+
// const [, , , , , , , , , , , , contributor1, contributor2, contributor3] =
10+
// await ethers.getSigners()
11+
12+
const contributor1 = new Wallet(
13+
process.env.CONTRIBUTOR_PK_1!,
14+
ethers.provider
15+
)
16+
const contributor2 = new Wallet(
17+
process.env.CONTRIBUTOR_PK_2!,
18+
ethers.provider
19+
)
20+
const contributor3 = new Wallet(
21+
process.env.CONTRIBUTOR_PK_3!,
22+
ethers.provider
23+
)
24+
const contributor4 = new Wallet(
25+
process.env.CONTRIBUTOR_PK_4!,
26+
ethers.provider
27+
)
28+
1129
const state = JSON.parse(fs.readFileSync('state.json').toString())
1230
const coordinatorKeyPair = new Keypair(
1331
PrivKey.unserialize(state.coordinatorPrivKey)
1432
)
1533

16-
for (const contributor of [contributor1, contributor2]) {
34+
for (const contributor of [
35+
contributor1,
36+
contributor2,
37+
contributor3,
38+
contributor4,
39+
]) {
1740
const contributorAddress = await contributor.getAddress()
1841
const contributorData = state.contributors[contributorAddress]
1942
const contributorKeyPair = new Keypair(
@@ -37,8 +60,11 @@ async function main() {
3760
encPubKeys.push(encPubKey.asContractParam())
3861
nonce += 1
3962
// Vote
40-
for (const recipientIndex of [1, 2]) {
41-
const votes = BigNumber.from(contributorData.voiceCredits).div(4)
63+
const recipients = [1, 2, 3, 4, 5, 6, 7]
64+
for (const recipientIndex of recipients) {
65+
const votes = BigNumber.from(contributorData.voiceCredits).div(
66+
recipients.length
67+
)
4268
const [message, encPubKey] = createMessage(
4369
contributorData.stateIndex,
4470
newContributorKeypair,
@@ -58,10 +84,21 @@ async function main() {
5884
state.fundingRound,
5985
contributor
6086
)
61-
await fundingRoundAsContributor.submitMessageBatch(
87+
88+
const tx = await fundingRoundAsContributor.submitMessageBatch(
6289
messages.reverse(),
63-
encPubKeys.reverse()
90+
encPubKeys.reverse(),
91+
{
92+
gasLimit: 20000000,
93+
}
6494
)
95+
try {
96+
await tx.wait()
97+
} catch (err) {
98+
console.log('error!', err)
99+
return
100+
}
101+
65102
console.log(`Contributor ${contributorAddress} voted.`)
66103
}
67104
}

0 commit comments

Comments
 (0)