@@ -180,8 +180,7 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
180
180
IForeignGateway public foreignGateway; // Foreign gateway contract.
181
181
IERC20 public weth; // WETH token address.
182
182
183
- mapping (uint256 => uint256 ) public disputeNbRounds; // Number of rounds of the dispute.
184
- mapping (uint256 => mapping (uint256 => uint256 )) public disputeNbVotesInRound; // Number of votes in the round. [disputeID][RoundID]
183
+ mapping (uint256 => uint256 ) public disputesRuling;
185
184
186
185
/* Modifiers */
187
186
@@ -242,26 +241,29 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
242
241
RNGenerator = _RNGenerator;
243
242
minStakingTime = _minStakingTime;
244
243
maxDrawingTime = _maxDrawingTime;
244
+ phase = Phase.staking;
245
245
lastPhaseChange = block .timestamp ;
246
246
lockInsolventTransfers = true ;
247
- nextDelayedSetStake = 1 ;
247
+ if (nextDelayedSetStake == 0 ) nextDelayedSetStake = 1 ;
248
248
foreignGateway = _foreignGateway;
249
249
weth = _weth;
250
250
251
251
// Create the general court.
252
- courts.push (
253
- Court ({
254
- parent: 0 ,
255
- children: new uint256 [](0 ),
256
- hiddenVotes: _hiddenVotes,
257
- minStake: _courtParameters[0 ],
258
- alpha: _courtParameters[1 ],
259
- feeForJuror: _courtParameters[2 ],
260
- jurorsForCourtJump: _courtParameters[3 ],
261
- timesPerPeriod: _timesPerPeriod
262
- })
263
- );
264
- sortitionSumTrees.createTree (bytes32 (0 ), _sortitionSumTreeK);
252
+ if (courts.length == 0 ) {
253
+ courts.push (
254
+ Court ({
255
+ parent: 0 ,
256
+ children: new uint256 [](0 ),
257
+ hiddenVotes: _hiddenVotes,
258
+ minStake: _courtParameters[0 ],
259
+ alpha: _courtParameters[1 ],
260
+ feeForJuror: _courtParameters[2 ],
261
+ jurorsForCourtJump: _courtParameters[3 ],
262
+ timesPerPeriod: _timesPerPeriod
263
+ })
264
+ );
265
+ sortitionSumTrees.createTree (bytes32 (0 ), _sortitionSumTreeK);
266
+ }
265
267
}
266
268
267
269
/* External */
@@ -462,9 +464,12 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
462
464
Dispute storage dispute = disputes[_disputeID];
463
465
require (! dispute.ruled, "Ruling already executed. " );
464
466
dispute.ruled = true ;
467
+ disputesRuling[_disputeID] = _ruling;
465
468
466
469
// Send the relayed ruling to the arbitrable while fully bypassing the dispute flow.
467
470
dispute.arbitrated.rule (_disputeID, _ruling);
471
+
472
+ emit Ruling (dispute.arbitrated, _disputeID, _ruling);
468
473
}
469
474
470
475
/* Public */
@@ -479,35 +484,12 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
479
484
bytes memory _extraData
480
485
) public payable override returns (uint256 disputeID ) {
481
486
require (msg .value == 0 , "Fees should be paid in WETH " );
482
- uint256 fee = foreignGateway. arbitrationCost (_extraData);
487
+ uint256 fee = arbitrationCost (_extraData);
483
488
require (weth.transferFrom (msg .sender , address (this ), fee), "Not enough WETH for arbitration " );
484
489
485
- (uint96 subcourtID , uint256 minJurors ) = extraDataToSubcourtIDAndMinJurors (_extraData);
486
490
disputeID = totalDisputes++ ;
487
491
Dispute storage dispute = disputes[disputeID];
488
- dispute.subcourtID = subcourtID;
489
492
dispute.arbitrated = IArbitrable (msg .sender );
490
- dispute.numberOfChoices = _numberOfChoices;
491
- dispute.period = Period.evidence;
492
- dispute.lastPeriodChange = block .timestamp ;
493
- // As many votes that can be afforded by the provided funds.
494
-
495
- uint256 nbVotes = fee / courts[dispute.subcourtID].feeForJuror;
496
-
497
- uint256 newLastRoundID = disputeNbRounds[disputeID];
498
- disputeNbVotesInRound[disputeID][newLastRoundID] = nbVotes;
499
- disputeNbRounds[disputeID]++ ;
500
-
501
- VoteCounter storage voteCounter = dispute.voteCounters.push ();
502
- voteCounter.tied = true ;
503
- dispute.tokensAtStakePerJuror.push (
504
- (courts[dispute.subcourtID].minStake * courts[dispute.subcourtID].alpha) / ALPHA_DIVISOR
505
- );
506
- dispute.totalFeesForJurors.push (fee);
507
- dispute.votesInEachRound.push (0 );
508
- dispute.repartitionsInEachRound.push (0 );
509
- dispute.penaltiesInEachRound.push (0 );
510
- disputesWithoutJurors++ ;
511
493
512
494
require (weth.transfer (address (foreignGateway), fee), "Fee transfer to gateway failed " );
513
495
foreignGateway.createDisputeERC20 (_numberOfChoices, _extraData, fee);
@@ -555,8 +537,7 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
555
537
* @return cost The cost.
556
538
*/
557
539
function arbitrationCost (bytes memory _extraData ) public view override returns (uint256 cost ) {
558
- (uint96 subcourtID , uint256 minJurors ) = extraDataToSubcourtIDAndMinJurors (_extraData);
559
- cost = courts[subcourtID].feeForJuror * minJurors;
540
+ cost = foreignGateway.arbitrationCost (_extraData);
560
541
}
561
542
562
543
/** @dev Gets the current ruling of a specified dispute.
@@ -565,9 +546,13 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
565
546
*/
566
547
function currentRuling (uint256 _disputeID ) public view returns (uint256 ruling ) {
567
548
Dispute storage dispute = disputes[_disputeID];
568
- ruling = dispute.voteCounters[dispute.voteCounters.length - 1 ].tied
569
- ? 0
570
- : dispute.voteCounters[dispute.voteCounters.length - 1 ].winningChoice;
549
+ if (dispute.voteCounters.length == 0 ) {
550
+ ruling = disputesRuling[_disputeID];
551
+ } else {
552
+ ruling = dispute.voteCounters[dispute.voteCounters.length - 1 ].tied
553
+ ? 0
554
+ : dispute.voteCounters[dispute.voteCounters.length - 1 ].winningChoice;
555
+ }
571
556
}
572
557
573
558
/* Internal */
@@ -586,16 +571,6 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
586
571
function _setStake (address _account , uint96 _subcourtID , uint128 _stake ) internal returns (bool succeeded ) {
587
572
if (! (_subcourtID < courts.length )) return false ;
588
573
589
- // Delayed action logic.
590
- if (phase != Phase.staking) {
591
- delayedSetStakes[++ lastDelayedSetStake] = DelayedSetStake ({
592
- account: _account,
593
- subcourtID: _subcourtID,
594
- stake: _stake
595
- });
596
- return true ;
597
- }
598
-
599
574
if (! (_stake == 0 || courts[_subcourtID].minStake <= _stake)) return false ; // The juror's stake cannot be lower than the minimum stake for the subcourt.
600
575
Juror storage juror = jurors[_account];
601
576
bytes32 stakePathID = accountAndSubcourtIDToStakePathID (_account, _subcourtID);
@@ -763,15 +738,8 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
763
738
)
764
739
{
765
740
Dispute storage dispute = disputes[_disputeID];
766
- votesLengths = new uint256 [](disputeNbRounds[_disputeID]);
767
- // Use votes array to get info of old disputes.
768
- if (disputeNbRounds[_disputeID] != 0 ) {
769
- for (uint256 i = 0 ; i < disputeNbRounds[_disputeID]; i++ )
770
- votesLengths[i] = disputeNbVotesInRound[_disputeID][i];
771
- } else {
772
- votesLengths = new uint256 [](dispute.votes.length );
773
- for (uint256 i = 0 ; i < dispute.votes.length ; i++ ) votesLengths[i] = dispute.votes[i].length ;
774
- }
741
+ votesLengths = new uint256 [](dispute.votes.length );
742
+ for (uint256 i = 0 ; i < dispute.votes.length ; i++ ) votesLengths[i] = dispute.votes[i].length ;
775
743
tokensAtStakePerJuror = dispute.tokensAtStakePerJuror;
776
744
totalFeesForJurors = dispute.totalFeesForJurors;
777
745
votesInEachRound = dispute.votesInEachRound;
0 commit comments