Skip to content

Commit 2bbf87e

Browse files
unknownunknown1jaybuidl
authored andcommitted
fix(xLiquid): jb's feedback
1 parent b7f4190 commit 2bbf87e

File tree

1 file changed

+32
-64
lines changed

1 file changed

+32
-64
lines changed

contracts/src/kleros-v1/kleros-liquid-xdai/xKlerosLiquidToV2.sol

+32-64
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,7 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
180180
IForeignGateway public foreignGateway; // Foreign gateway contract.
181181
IERC20 public weth; // WETH token address.
182182

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;
185184

186185
/* Modifiers */
187186

@@ -242,26 +241,29 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
242241
RNGenerator = _RNGenerator;
243242
minStakingTime = _minStakingTime;
244243
maxDrawingTime = _maxDrawingTime;
244+
phase = Phase.staking;
245245
lastPhaseChange = block.timestamp;
246246
lockInsolventTransfers = true;
247-
nextDelayedSetStake = 1;
247+
if (nextDelayedSetStake == 0) nextDelayedSetStake = 1;
248248
foreignGateway = _foreignGateway;
249249
weth = _weth;
250250

251251
// 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+
}
265267
}
266268

267269
/* External */
@@ -462,9 +464,12 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
462464
Dispute storage dispute = disputes[_disputeID];
463465
require(!dispute.ruled, "Ruling already executed.");
464466
dispute.ruled = true;
467+
disputesRuling[_disputeID] = _ruling;
465468

466469
// Send the relayed ruling to the arbitrable while fully bypassing the dispute flow.
467470
dispute.arbitrated.rule(_disputeID, _ruling);
471+
472+
emit Ruling(dispute.arbitrated, _disputeID, _ruling);
468473
}
469474

470475
/* Public */
@@ -479,35 +484,12 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
479484
bytes memory _extraData
480485
) public payable override returns (uint256 disputeID) {
481486
require(msg.value == 0, "Fees should be paid in WETH");
482-
uint256 fee = foreignGateway.arbitrationCost(_extraData);
487+
uint256 fee = arbitrationCost(_extraData);
483488
require(weth.transferFrom(msg.sender, address(this), fee), "Not enough WETH for arbitration");
484489

485-
(uint96 subcourtID, uint256 minJurors) = extraDataToSubcourtIDAndMinJurors(_extraData);
486490
disputeID = totalDisputes++;
487491
Dispute storage dispute = disputes[disputeID];
488-
dispute.subcourtID = subcourtID;
489492
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++;
511493

512494
require(weth.transfer(address(foreignGateway), fee), "Fee transfer to gateway failed");
513495
foreignGateway.createDisputeERC20(_numberOfChoices, _extraData, fee);
@@ -555,8 +537,7 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
555537
* @return cost The cost.
556538
*/
557539
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);
560541
}
561542

562543
/** @dev Gets the current ruling of a specified dispute.
@@ -565,9 +546,13 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
565546
*/
566547
function currentRuling(uint256 _disputeID) public view returns (uint256 ruling) {
567548
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+
}
571556
}
572557

573558
/* Internal */
@@ -586,16 +571,6 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
586571
function _setStake(address _account, uint96 _subcourtID, uint128 _stake) internal returns (bool succeeded) {
587572
if (!(_subcourtID < courts.length)) return false;
588573

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-
599574
if (!(_stake == 0 || courts[_subcourtID].minStake <= _stake)) return false; // The juror's stake cannot be lower than the minimum stake for the subcourt.
600575
Juror storage juror = jurors[_account];
601576
bytes32 stakePathID = accountAndSubcourtIDToStakePathID(_account, _subcourtID);
@@ -763,15 +738,8 @@ contract xKlerosLiquidToV2 is Initializable, ITokenController, IArbitrator {
763738
)
764739
{
765740
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;
775743
tokensAtStakePerJuror = dispute.tokensAtStakePerJuror;
776744
totalFeesForJurors = dispute.totalFeesForJurors;
777745
votesInEachRound = dispute.votesInEachRound;

0 commit comments

Comments
 (0)