Skip to content

Commit 746264c

Browse files
committed
refactor: hbarcelos review
1 parent 7b0c1db commit 746264c

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

contracts/kleros/xKlerosLiquid.sol

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pragma solidity ^0.4.24;
1313
import "openzeppelin-eth/contracts/zos-lib/Initializable.sol";
1414
import { TokenController } from "minimetoken/contracts/TokenController.sol";
1515
import { Arbitrator, Arbitrable } from "@kleros/kleros-interaction/contracts/standard/arbitration/Arbitrator.sol";
16-
import { WrappedPinakion as Pinakion } from "../tokens/WrappedPinakion.sol";
16+
import { WrappedPinakion } from "../tokens/WrappedPinakion.sol";
1717
import { IRandomAuRa } from "../interfaces/IRandomAuRa.sol";
1818

1919
import { SortitionSumTreeFactory } from "@kleros/kleros/contracts/data-structures/SortitionSumTreeFactory.sol";
@@ -134,12 +134,13 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
134134
event Draw(address indexed _address, uint indexed _disputeID, uint _appeal, uint _voteID);
135135

136136
/** @dev Emitted when a juror wins or loses tokens and xDai from a dispute.
137+
* The original name from KlerosLiquid is kept in this event to match its ABI.
137138
* @param _address The juror affected.
138139
* @param _disputeID The ID of the dispute.
139140
* @param _tokenAmount The amount of tokens won or lost.
140141
* @param _xDaiAmount The amount of xDai won or lost.
141142
*/
142-
event TokenAndXDaiShift(address indexed _address, uint indexed _disputeID, int _tokenAmount, int _xDaiAmount);
143+
event TokenAndETHShift(address indexed _address, uint indexed _disputeID, int _tokenAmount, int _xDaiAmount);
143144

144145
/* Storage */
145146

@@ -150,7 +151,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
150151
uint public constant ALPHA_DIVISOR = 1e4; // The number to divide `Court.alpha` by.
151152
// General Contracts
152153
address public governor; // The governor of the contract.
153-
Pinakion public pinakion; // The Pinakion token contract.
154+
WrappedPinakion public pinakion; // The Pinakion token contract.
154155
IRandomAuRa public RNGenerator; // The random number generator contract.
155156
// General Dynamic
156157
Phase public phase; // The current phase.
@@ -214,10 +215,11 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
214215
* @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the general court.
215216
* @param _timesPerPeriod The `timesPerPeriod` property value of the general court.
216217
* @param _sortitionSumTreeK The number of children per node of the general court's sortition sum tree.
218+
* @param _maxTotalStakeAllowed The maximum amount of wrapped PNK that is allowed to be staked in this contract.
217219
*/
218220
function initialize(
219221
address _governor,
220-
Pinakion _pinakion,
222+
WrappedPinakion _pinakion,
221223
IRandomAuRa _RNGenerator,
222224
uint _minStakingTime,
223225
uint _maxDrawingTime,
@@ -227,7 +229,8 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
227229
uint _feeForJuror,
228230
uint _jurorsForCourtJump,
229231
uint[4] _timesPerPeriod,
230-
uint _sortitionSumTreeK
232+
uint _sortitionSumTreeK,
233+
uint _maxTotalStakeAllowed
231234
) public initializer {
232235
// Initialize contract.
233236
governor = _governor;
@@ -238,7 +241,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
238241
lastPhaseChange = now;
239242
lockInsolventTransfers = true;
240243
nextDelayedSetStake = 1;
241-
maxTotalStakeAllowed = 30 * 1e24; // 30 Million PNK.
244+
maxTotalStakeAllowed = _maxTotalStakeAllowed;
242245

243246
// Create the general court.
244247
courts.push(Court({
@@ -275,7 +278,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
275278
/** @dev Changes the `pinakion` storage variable.
276279
* @param _pinakion The new value for the `pinakion` storage variable.
277280
*/
278-
function changePinakion(Pinakion _pinakion) external onlyByGovernor {
281+
function changePinakion(WrappedPinakion _pinakion) external onlyByGovernor {
279282
pinakion = _pinakion;
280283
}
281284

@@ -468,6 +471,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
468471
}
469472

470473
/** @dev Executes the next delayed set stakes.
474+
* `O(n)` where `n` is the number of iterations to run.
471475
* @param _iterations The number of delayed set stakes to execute.
472476
*/
473477
function executeDelayedSetStakes(uint _iterations) external onlyDuringPhase(Phase.staking) {
@@ -580,12 +584,13 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
580584
}
581585

582586
/** @dev Computes the token and xDai rewards for a specified appeal in a specified dispute.
587+
* The original name from KlerosLiquid is kept in this function to match its ABI.
583588
* @param _disputeID The ID of the dispute.
584589
* @param _appeal The appeal.
585590
* @return tokenReward The token reward.
586591
* @return xDaiReward The xDai reward.
587592
*/
588-
function computeTokenAndXDaiRewards(uint _disputeID, uint _appeal) private view returns(uint tokenReward, uint xDaiReward) {
593+
function computeTokenAndETHRewards(uint _disputeID, uint _appeal) private view returns(uint tokenReward, uint xDaiReward) {
589594
Dispute storage dispute = disputes[_disputeID];
590595

591596
// Distribute penalties and arbitration fees.
@@ -637,7 +642,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
637642
if (end > dispute.votes[_appeal].length) end = dispute.votes[_appeal].length;
638643
} else {
639644
// We loop over the votes twice, first to collect penalties, and second to distribute them as rewards along with arbitration fees.
640-
(tokenReward, xDaiReward) = dispute.repartitionsInEachRound[_appeal] >= dispute.votes[_appeal].length ? computeTokenAndXDaiRewards(_disputeID, _appeal) : (0, 0); // Compute rewards if rewarding.
645+
(tokenReward, xDaiReward) = dispute.repartitionsInEachRound[_appeal] >= dispute.votes[_appeal].length ? computeTokenAndETHRewards(_disputeID, _appeal) : (0, 0); // Compute rewards if rewarding.
641646
if (end > dispute.votes[_appeal].length * 2) end = dispute.votes[_appeal].length * 2;
642647
}
643648
for (uint i = dispute.repartitionsInEachRound[_appeal]; i < end; i++) {
@@ -652,7 +657,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
652657
pinakion.transfer(vote.account, tokenReward);
653658
// Intentional use to avoid blocking.
654659
vote.account.send(xDaiReward); // solium-disable-line security/no-send
655-
emit TokenAndXDaiShift(vote.account, _disputeID, int(tokenReward), int(xDaiReward));
660+
emit TokenAndETHShift(vote.account, _disputeID, int(tokenReward), int(xDaiReward));
656661
jurors[vote.account].lockedTokens -= dispute.tokensAtStakePerJuror[_appeal];
657662
}
658663
} else { // Juror was inactive, or voted incoherently and it was not a tie.
@@ -661,7 +666,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
661666
// Penalize.
662667
uint penalty = dispute.tokensAtStakePerJuror[_appeal] > pinakion.balanceOf(vote.account) ? pinakion.balanceOf(vote.account) : dispute.tokensAtStakePerJuror[_appeal];
663668
pinakion.transferFrom(vote.account, this, penalty);
664-
emit TokenAndXDaiShift(vote.account, _disputeID, -int(penalty), 0);
669+
emit TokenAndETHShift(vote.account, _disputeID, -int(penalty), 0);
665670
penaltiesInRoundCache += penalty;
666671
jurors[vote.account].lockedTokens -= dispute.tokensAtStakePerJuror[_appeal];
667672

@@ -681,7 +686,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
681686
} else if (i + 1 < end) {
682687
// Compute rewards because we are going into rewarding.
683688
dispute.penaltiesInEachRound[_appeal] = penaltiesInRoundCache;
684-
(tokenReward, xDaiReward) = computeTokenAndXDaiRewards(_disputeID, _appeal);
689+
(tokenReward, xDaiReward) = computeTokenAndETHRewards(_disputeID, _appeal);
685690
}
686691
}
687692
}
@@ -767,7 +772,7 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
767772
emit NewPeriod(_disputeID, Period.evidence);
768773
}
769774

770-
/** @dev Called when `_owner` sends xDai to the MiniMe Token contract.
775+
/** @dev DEPRECATED. Called when `_owner` sends xDai to the Wrapped Token contract.
771776
* @param _owner The address that sent the xDai to create tokens.
772777
* @return allowed Whether the operation should be allowed or not.
773778
*/
@@ -896,7 +901,8 @@ contract xKlerosLiquid is Initializable, TokenController, Arbitrator {
896901

897902
/** If maxTotalStakeAllowed was reduced through governance,
898903
* totalStake could be greater than maxTotalStakeAllowed.
899-
* In such case allow unstaking. Always allow unstaking.
904+
* If this happens, removing stake is still allowed even if
905+
* totalStake is greater than maxTotalStakeAllowed afterwards.
900906
*/
901907
if ((totalStake - juror.stakedTokens + newTotalStake > maxTotalStakeAllowed) && (newTotalStake > juror.stakedTokens))
902908
return false; // Maximum PNK stake reached.

0 commit comments

Comments
 (0)