1
1
/* eslint-disable promise/param-names */
2
- import { BigNumber , utils } from "ethers" ;
2
+ import { toBigInt , BigNumberish , AddressLike } from "ethers" ;
3
+ import { ethers } from "ethers" ;
3
4
import { task } from "hardhat/config" ;
4
5
import {
5
6
Period ,
@@ -34,7 +35,10 @@ task("simulate:approve", "Grants permission to KlerosCore to use your PNK tokens
34
35
35
36
// Approve PNK tokens for transfer to KlerosCore
36
37
try {
37
- const approvePNKFunctionArgs : [ string , BigNumber ] = [ core . address , utils . parseEther ( pnkamount . toString ( ) ) ] ;
38
+ const approvePNKFunctionArgs : [ AddressLike , BigNumberish ] = [
39
+ await core . getAddress ( ) ,
40
+ ethers . parseEther ( pnkamount . toString ( ) ) ,
41
+ ] ;
38
42
const resultApproveTx = await pnk . connect ( wallet ) . approve ( ...approvePNKFunctionArgs , options ) ;
39
43
await resultApproveTx . wait ( ) ;
40
44
console . log ( `Approved ${ pnkamount } PNK tokens for transfer to KlerosCore from wallet ${ wallet . address } ` ) ;
@@ -56,7 +60,7 @@ task("simulate:set-stake", "Stakes PNK tokens to participate in the Kleros dispu
56
60
57
61
// Stakes PNK tokens in the Court you specified as parameter of this task
58
62
try {
59
- const setStakeFunctionArgs : [ string , BigNumber ] = [ courtid , utils . parseEther ( pnkamount . toString ( ) ) ] ;
63
+ const setStakeFunctionArgs : [ string , bigint ] = [ courtid , ethers . parseEther ( pnkamount . toString ( ) ) ] ;
60
64
const resultSetStakeTx = await core . connect ( wallet ) . setStake ( ...setStakeFunctionArgs , options ) ;
61
65
await resultSetStakeTx . wait ( ) ;
62
66
console . log ( `setStake wallet ${ wallet . address } , txID: %s` , resultSetStakeTx ?. hash ) ;
@@ -73,15 +77,15 @@ task("simulate:create-court", "callable by Governor only. Create a new Court")
73
77
74
78
const { wallet } = await getWallet ( hre , walletindex ) ;
75
79
76
- const parent = 1 ;
77
- const minStake = BigNumber . from ( 10 ) . pow ( 20 ) . mul ( 2 ) ;
78
- const alpha = 10000 ;
79
- const feeForJuror = BigNumber . from ( 10 ) . pow ( 17 ) ;
80
- const jurorsForCourtJump = 3 ;
81
- const hiddenVotes = false ;
82
- const timesPerPeriod = [ 300 , 300 , 300 , 300 ] as any ;
83
- const sortitionSumTreeK = 3 ;
84
- const supportedDisputeKits = [ 1 ] ; // IDs of supported dispute kits
80
+ const parent = toBigInt ( 1 ) as BigNumberish ;
81
+ const minStake = ( toBigInt ( 10 ) ** toBigInt ( 20 ) * toBigInt ( 2 ) ) as BigNumberish ;
82
+ const alpha = toBigInt ( 10000 ) as BigNumberish ;
83
+ const feeForJuror = ( toBigInt ( 10 ) ** toBigInt ( 17 ) ) as BigNumberish ;
84
+ const jurorsForCourtJump = toBigInt ( 3 ) as BigNumberish ;
85
+ const hiddenVotes = false as boolean ;
86
+ const timesPerPeriod = [ 300 , 300 , 300 , 300 ] as [ BigNumberish , BigNumberish , BigNumberish , BigNumberish ] ;
87
+ const sortitionSumTreeK = ethers . toBeHex ( 3 ) ;
88
+ const supportedDisputeKits = [ 1 ] as BigNumberish [ ] ; // IDs of supported dispute kits
85
89
let courtID ;
86
90
try {
87
91
const tx = await (
@@ -99,10 +103,10 @@ task("simulate:create-court", "callable by Governor only. Create a new Court")
99
103
supportedDisputeKits
100
104
)
101
105
) . wait ( ) ;
102
- console . log ( "createCourt txID: %s" , tx ?. transactionHash ) ;
106
+ console . log ( "createCourt txID: %s" , tx ?. hash ) ;
103
107
// Get the court ID from the KlerosCore contract event logs
104
108
const filter = core . filters . CourtCreated ( ) ;
105
- const logs = await core . queryFilter ( filter , tx . blockNumber , tx . blockNumber ) ;
109
+ const logs = await core . queryFilter ( filter , tx ? .blockNumber , tx ? .blockNumber ) ;
106
110
const courtCreatedLog = logs [ logs . length - 1 ] ;
107
111
courtID = courtCreatedLog . args . _courtID ;
108
112
console . log (
@@ -130,19 +134,12 @@ task("simulate:create-dispute", "Creates a dispute on an arbitrable contract")
130
134
const { wallet } = await getWallet ( hre , walletindex ) ;
131
135
132
136
// Create a random evidence group ID
133
- const evidenceGroupID = ethers . BigNumber . from ( ethers . utils . randomBytes ( 32 ) ) . toString ( ) ;
137
+ const evidenceGroupID = toBigInt ( ethers . randomBytes ( 32 ) ) . toString ( ) ;
134
138
135
139
let disputeID ;
136
-
137
- // Construct the arbitratorExtraData parameter
138
- const courtIdBytes = ethers . utils . defaultAbiCoder . encode ( [ "uint256" ] , [ courtid ] ) ;
139
- const minJurorsBytes = ethers . utils . defaultAbiCoder . encode ( [ "uint256" ] , [ 3 ] ) ; // default value for minimum jurors
140
-
141
- const arbitratorExtraData = ethers . utils . hexConcat ( [ courtIdBytes , minJurorsBytes ] ) ;
142
-
143
140
try {
144
141
// Create a dispute on the arbitrable contract
145
- const tx = await arbitrable . connect ( wallet ) . createDispute ( nbofchoices , arbitratorExtraData , evidenceGroupID , {
142
+ const tx = await arbitrable . connect ( wallet ) [ " createDispute(string)" ] ( "hello world" , {
146
143
value : getArbitrationFees ( hre , nbofjurors , feeforjuror ) ,
147
144
...options ,
148
145
} ) ;
@@ -151,7 +148,7 @@ task("simulate:create-dispute", "Creates a dispute on an arbitrable contract")
151
148
152
149
// Get the dispute ID from the KlerosCore contract event logs
153
150
const filter = core . filters . DisputeCreation ( ) ;
154
- const logs = await core . queryFilter ( filter , tx . blockNumber , tx . blockNumber ) ;
151
+ const logs = await core . queryFilter ( filter ) ;
155
152
disputeID = logs [ logs . length - 1 ] ?. args ?. _disputeID ;
156
153
console . log ( "Created Dispute %s on Court %s with evidenceGroupID %s" , disputeID , courtid , evidenceGroupID ) ;
157
154
} catch ( e ) {
@@ -175,7 +172,7 @@ task("simulate:pass-phase", "Pass the phase of the SortitionModule")
175
172
const before = await sortition . phase ( ) ;
176
173
try {
177
174
const tx = await ( await sortition . connect ( wallet ) . passPhase ( options ) ) . wait ( ) ;
178
- console . log ( "passPhaseCore txID: %s" , tx ?. transactionHash ) ;
175
+ console . log ( "passPhaseCore txID: %s" , tx ?. hash ) ;
179
176
} catch ( e ) {
180
177
handleError ( e ) ;
181
178
} finally {
@@ -189,6 +186,7 @@ task("simulate:wait-for-rng", "Waits for the RNG to be ready").setAction(async (
189
186
const { wallet } = await getWallet ( hre , walletIndex ) ;
190
187
191
188
let ready : boolean ;
189
+
192
190
try {
193
191
ready = await isRngReady ( wallet , hre ) ;
194
192
} catch ( e ) {
@@ -213,7 +211,7 @@ task("simulate:draw", "Draws jurors for a dispute on Kleros")
213
211
console . log ( "Drawn jurors before: %O" , info . drawnJurors ) ;
214
212
try {
215
213
const tx = await ( await core . connect ( wallet ) . draw ( disputeid , 10 , options ) ) . wait ( ) ;
216
- console . log ( "draw txID: %s" , tx ?. transactionHash ) ;
214
+ console . log ( "draw txID: %s" , tx ?. hash ) ;
217
215
} catch ( e ) {
218
216
handleError ( e ) ;
219
217
} finally {
@@ -234,7 +232,7 @@ task("simulate:pass-period", "Passes the period of a dispute on Kleros Core")
234
232
235
233
try {
236
234
const tx = await ( await core . connect ( wallet ) . passPeriod ( disputeid , options ) ) . wait ( ) ;
237
- console . log ( "passPeriod txID: %s" , tx ?. transactionHash ) ;
235
+ console . log ( "passPeriod txID: %s" , tx ?. hash ) ;
238
236
} catch ( e ) {
239
237
handleError ( e ) ;
240
238
} finally {
@@ -256,8 +254,8 @@ task("simulate:cast-commit", "Casts a commit for a drawn juror")
256
254
const salt = "123" ;
257
255
console . log ( "salt used on juror %s is: %s" , walletindex , salt ) ;
258
256
const generateCommit = ( choice : number , justification : string ) => {
259
- const hash = utils . solidityKeccak256 ( [ "string" , "string" , "string" ] , [ choice , justification , salt ] ) ;
260
- return utils . hexlify ( hash ) ;
257
+ const hash = ethers . solidityPackedKeccak256 ( [ "string" , "string" , "string" ] , [ choice , justification , salt ] ) ;
258
+ return ethers . toBeHex ( hash ) ;
261
259
} ;
262
260
const commitHash = generateCommit ( choice , taskArgs . justification ) ;
263
261
const drawnJurors = await getDrawnJurors ( hre , disputeid , getRoundId ( taskArgs , hre , disputeid ) ) ;
@@ -307,7 +305,7 @@ task("simulate:fund-appeal", "Funds an appeal on a dispute")
307
305
const { disputeid, walletindex, appealchoice } = taskArgs ;
308
306
const { wallet } = await getWallet ( hre , walletindex ) ;
309
307
310
- const fundAppealFunctionArgs : [ number , number , { value : BigNumber } ] = [
308
+ const fundAppealFunctionArgs : [ number , number , { value : BigNumberish } ] = [
311
309
disputeid ,
312
310
appealchoice ,
313
311
{ value : await getAppealCost ( hre , disputeid ) } ,
@@ -319,7 +317,7 @@ task("simulate:fund-appeal", "Funds an appeal on a dispute")
319
317
await mineBlocks ( numberOfBlocksToMine , hre . network ) ;
320
318
}
321
319
const fundAppealTx = await ( await disputeKitClassic . connect ( wallet ) . fundAppeal ( ...fundAppealFunctionArgs ) ) . wait ( ) ;
322
- console . log ( "fundAppeal (in DisputeKitClassic) txID: %s" , fundAppealTx ?. transactionHash ) ;
320
+ console . log ( "fundAppeal (in DisputeKitClassic) txID: %s" , fundAppealTx ?. hash ) ;
323
321
} catch ( e ) {
324
322
handleError ( e ) ;
325
323
}
@@ -337,7 +335,7 @@ task("simulate:execute-ruling", "Executes the ruling for a dispute on KlerosCore
337
335
let executeRulingTx ;
338
336
try {
339
337
const executeTx = await ( await connectedKlerosCore . execute ( disputeid , 0 , 10 ) ) . wait ( ) ; // redistribute
340
- console . log ( "txID execute: %s" , executeTx ?. transactionHash ) ;
338
+ console . log ( "txID execute: %s" , executeTx ?. hash ) ;
341
339
342
340
executeRulingTx = await ( await connectedKlerosCore . executeRuling ( disputeid ) ) . wait ( ) ; // rule
343
341
console . log ( "txID executeRuling: %s" , executeRulingTx ?. transactionHash ) ;
@@ -363,14 +361,20 @@ task("simulate:withdraw-fees-and-rewards", "Withdraws fees and rewards for peopl
363
361
const { disputeid, walletindex, beneficiary, choice } = taskArgs ;
364
362
365
363
const { wallet } = await getWallet ( hre , walletindex ) ;
366
-
364
+ // disputeid, beneficiary, getRoundId(taskArgs, hre, disputeid), choice
365
+ // toBigInt(disputeid),
366
+ // await ethers.getAddress(beneficiary),
367
+ // getRoundId(taskArgs, hre, disputeid),
368
+ // choice
369
+ const _disputeId : BigNumberish = disputeid ;
370
+ const _beneficiary : AddressLike = beneficiary ;
371
+ const _coreRoundId : BigNumberish = await getRoundId ( taskArgs , hre , disputeid ) ;
372
+ const _choice : BigNumberish = choice ;
367
373
try {
368
374
const withdrawTx = await (
369
- await disputeKitClassic
370
- . connect ( wallet )
371
- . withdrawFeesAndRewards ( disputeid , beneficiary , getRoundId ( taskArgs , hre , disputeid ) , choice )
375
+ await disputeKitClassic . connect ( wallet ) . withdrawFeesAndRewards ( _disputeId , _beneficiary , _coreRoundId , _choice )
372
376
) . wait ( ) ; // redistribute
373
- console . log ( "txID withdrawFeesAndRewards: %s" , withdrawTx ?. transactionHash ) ;
377
+ console . log ( "txID withdrawFeesAndRewards: %s" , withdrawTx ?. hash ) ;
374
378
} catch ( e ) {
375
379
handleError ( e ) ;
376
380
}
@@ -408,7 +412,7 @@ task("simulate:to-freezing-and-generating-phase", "Pass phase from 'staking' to
408
412
const { wallet } = await getWallet ( hre , walletindex ) ;
409
413
const numberOfBlocksToMine = Number ( await sortition . rngLookahead ( ) ) ;
410
414
await mineBlocks ( numberOfBlocksToMine , hre . network ) ;
411
- await randomizerMock . connect ( wallet ) . relay ( randomizerRng . address , 0 , utils . randomBytes ( 32 ) ) ;
415
+ await randomizerMock . connect ( wallet ) . relay ( randomizerRng . target , 0 , ethers . randomBytes ( 32 ) ) ;
412
416
}
413
417
} ) ;
414
418
@@ -431,7 +435,8 @@ task("simulate:split-pnk", "one wallet funds with PNK the other 4 wallets")
431
435
const { pnk } = await getContracts ( hre ) ;
432
436
const { walletindex, pnkperwallet } = taskArgs ;
433
437
const { wallet } = await getWallet ( hre , walletindex ) ;
434
- const amount = utils . parseUnits ( pnkperwallet . toString ( ) , "18" ) ;
438
+ const amount = ethers . parseEther ( pnkperwallet . toString ( ) ) ;
439
+
435
440
const firstWallet = await ( await getWallet ( hre , 1 ) ) . wallet ;
436
441
const secondWallet = await ( await getWallet ( hre , 2 ) ) . wallet ;
437
442
const thirdWallet = await ( await getWallet ( hre , 3 ) ) . wallet ;
@@ -450,14 +455,14 @@ task("simulate:submit-evidence", "Submits evidence to a dispute")
450
455
. addParam ( "walletindex" , "Index of the wallet to use for submitting evidence" )
451
456
. addParam ( "evidencegroupid" , "The evidenceGroupID, which is linked to the dispute" )
452
457
. setAction ( async ( taskArgs , hre ) => {
453
- const { disputeKitClassic } = await getContracts ( hre ) ;
458
+ const { evidenceModule } = await getContracts ( hre ) ;
454
459
const { walletindex, evidencegroupid } = taskArgs ;
455
460
456
461
const { wallet } = await getWallet ( hre , walletindex ) ;
457
462
const evidence = "/ipfs/QmaNEknCUEKDy74sDNLFXo8Vc3PqX7QC1ZyvUx4n7V6q1L/evidence.json" ;
458
463
try {
459
- const tx = await ( await disputeKitClassic . connect ( wallet ) . submitEvidence ( evidencegroupid , evidence ) ) . wait ( ) ;
460
- console . log ( "txID submitEvidence: %s" , tx ?. transactionHash ) ;
464
+ const tx = await ( await evidenceModule . connect ( wallet ) . submitEvidence ( evidencegroupid , evidence ) ) . wait ( ) ;
465
+ console . log ( "txID submitEvidence: %s" , tx ?. hash ) ;
461
466
} catch ( e ) {
462
467
handleError ( e ) ;
463
468
}
@@ -471,55 +476,64 @@ task("simulate:all", "Simulates arbitration activity to troubleshoot the subgrap
471
476
const courtId = "1" ;
472
477
const appealChoice = "1" ;
473
478
479
+ console . log ( "split pnk....." ) ;
474
480
await hre . run ( "simulate:split-pnk" , { walletindex : operator . toString ( ) , pnkperwallet : stake . toString ( ) } ) ;
475
481
482
+ console . log ( "stake five jurors...." ) ;
476
483
await hre . run ( "simulate:stake-five-jurors" , {
477
484
walletindexes : "0,1,2,3,4" ,
478
485
pnkamounts : `${ stake } ,${ stake } ,${ stake } ,${ stake } ,${ stake } ` ,
479
486
courtid : courtId ,
480
487
} ) ;
481
488
489
+ console . log ( "create dispute...." ) ;
482
490
const dispute = await hre . run ( "simulate:create-dispute" , {
483
491
walletindex : operator . toString ( ) ,
484
492
courtid : courtId . toString ( ) ,
485
493
nbofchoices : "2" ,
486
494
nbofjurors : "3" ,
487
- feeforjuror : utils . parseEther ( "0.1" ) . toString ( ) ,
495
+ feeforjuror : ethers . parseEther ( "0.1" ) . toString ( ) ,
488
496
} ) ;
489
497
490
498
// Wait for minStakingTime
491
499
const minStakingTime = await sortition . minStakingTime ( ) ;
492
- await waitFor ( minStakingTime . toNumber ( ) , hre ) ;
500
+ await waitFor ( ethers . getNumber ( minStakingTime ) , hre ) ;
493
501
494
502
// Phase Staking -> Generating
503
+ console . log ( "to freezing and generating phase....." ) ;
495
504
await hre . run ( "simulate:to-freezing-and-generating-phase" , { walletindex : operator . toString ( ) } ) ;
496
505
497
506
// Wait for RNG
507
+ console . log ( "wait for rng...." ) ;
498
508
await hre . run ( "simulate:wait-for-rng" ) ;
499
509
500
510
// Phase: Generating -> Drawing
501
511
// Draws
502
512
// Phase: Drawing -> Staking
513
+ console . log ( "pass phase draw unfreeze....." ) ;
503
514
await hre . run ( "simulate:pass-phase-draw-unfreeze" , {
504
515
walletindex : operator . toString ( ) ,
505
516
disputeid : dispute . id . toString ( ) ,
506
517
} ) ;
507
518
508
519
// Submit evidence
520
+ console . log ( "submit evidence....." ) ;
509
521
await hre . run ( "simulate:submit-evidence" , {
510
522
walletindex : operator . toString ( ) ,
511
523
evidencegroupid : dispute . evidenceGroupID ,
512
524
} ) ;
513
525
514
526
// Period: Evidence -> Vote
515
527
await waitForPeriod ( dispute . id , Period . Evidence , hre ) ;
528
+ console . log ( "pass period....." ) ;
516
529
await hre . run ( "simulate:pass-period" , { walletindex : operator . toString ( ) , disputeid : dispute . id . toString ( ) } ) ;
517
530
518
531
// Find the first drawn juror and the corresponding wallet index
519
532
const drawnJurors = await getDrawnJurors ( hre , dispute . id , getLatestRoundId ( hre , dispute . id ) ) ;
520
533
const firstDrawnJurorWalletIndex = ( await findFirstDrawnJurorWalletIndex ( hre , drawnJurors ) ) as number ;
521
534
522
535
// Vote
536
+ console . log ( "cast vote....." ) ;
523
537
await hre . run ( "simulate:cast-vote" , {
524
538
walletindex : firstDrawnJurorWalletIndex . toString ( ) ,
525
539
disputeid : dispute . id . toString ( ) ,
@@ -529,9 +543,11 @@ task("simulate:all", "Simulates arbitration activity to troubleshoot the subgrap
529
543
530
544
// Period: Vote -> Appeal
531
545
await waitForPeriod ( dispute . id , Period . Vote , hre ) ;
546
+ console . log ( "pass period...." ) ;
532
547
await hre . run ( "simulate:pass-period" , { walletindex : operator . toString ( ) , disputeid : dispute . id . toString ( ) } ) ;
533
548
534
549
// Fund Appeal
550
+ console . log ( "fund appeal...." ) ;
535
551
await hre . run ( "simulate:fund-appeal" , {
536
552
walletindex : operator . toString ( ) ,
537
553
disputeid : dispute . id . toString ( ) ,
@@ -540,9 +556,11 @@ task("simulate:all", "Simulates arbitration activity to troubleshoot the subgrap
540
556
541
557
// Period: Appeal -> Execution
542
558
await waitForPeriod ( dispute . id , Period . Appeal , hre ) ;
559
+ console . log ( "pass period...." ) ;
543
560
await hre . run ( "simulate:pass-period" , { walletindex : operator . toString ( ) , disputeid : dispute . id . toString ( ) } ) ;
544
561
545
562
// Execution
563
+ console . log ( "execute ruling...." ) ;
546
564
await hre . run ( "simulate:execute-ruling" , { walletindex : operator . toString ( ) , disputeid : dispute . id . toString ( ) } ) ;
547
565
}
548
566
) ;
0 commit comments