Skip to content

Commit 1ec4e02

Browse files
docs: natspec update
1 parent 79a458c commit 1ec4e02

File tree

8 files changed

+209
-101
lines changed

8 files changed

+209
-101
lines changed

contracts/src/arbitration/KlerosCore.sol

Lines changed: 109 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
5252
Period period; // The current period of the dispute.
5353
bool ruled; // True if the ruling has been executed, false otherwise.
5454
uint256 lastPeriodChange; // The last time the period was changed.
55-
Round[] rounds;
55+
Round[] rounds; // Rounds of the dispute.
5656
}
5757

5858
struct Round {
@@ -83,9 +83,9 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
8383
}
8484

8585
struct CurrencyRate {
86-
bool feePaymentAccepted;
87-
uint64 rateInEth;
88-
uint8 rateDecimals;
86+
bool feePaymentAccepted; // True if this token is supported as payment method.
87+
uint64 rateInEth; // Rate of the fee token in ETH.
88+
uint8 rateDecimals; // Decimals of the fee token rate.
8989
}
9090

9191
// ************************************* //
@@ -113,10 +113,38 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
113113
// * Events * //
114114
// ************************************* //
115115

116+
/// @dev Emitted when period is passed.
117+
/// @param _disputeID ID of the related dispute.
118+
/// @param _period The new period.
116119
event NewPeriod(uint256 indexed _disputeID, Period _period);
120+
121+
/// @dev Emitted when appeal period starts.
122+
/// @param _disputeID ID of the related dispute.
123+
/// @param _arbitrable The arbitrable contract.
117124
event AppealPossible(uint256 indexed _disputeID, IArbitrableV2 indexed _arbitrable);
125+
126+
/// @dev Emitted when the dispute is successfully appealed.
127+
/// @param _disputeID ID of the related dispute.
128+
/// @param _arbitrable The arbitrable contract.
118129
event AppealDecision(uint256 indexed _disputeID, IArbitrableV2 indexed _arbitrable);
130+
131+
/// @dev Emitted when an address is successfully drawn.
132+
/// @param _address The drawn address.
133+
/// @param _disputeID ID of the related dispute.
134+
/// @param _roundID ID of the related round.
135+
/// @param _voteID ID of the vote given to the drawn juror.
119136
event Draw(address indexed _address, uint256 indexed _disputeID, uint256 _roundID, uint256 _voteID);
137+
138+
/// @dev Emitted when a new court is created.
139+
/// @param _courtID ID of the new court.
140+
/// @param _parent ID of the parent court.
141+
/// @param _hiddenVotes Whether the court has hidden votes or not.
142+
/// @param _minStake The `minStake` property value of the court.
143+
/// @param _alpha The `alpha` property value of the court.
144+
/// @param _feeForJuror The `feeForJuror` property value of the court.
145+
/// @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the court.
146+
/// @param _timesPerPeriod The `timesPerPeriod` property value of the court.
147+
/// @param _supportedDisputeKits Indexes of dispute kits that this court will support.
120148
event CourtCreated(
121149
uint96 indexed _courtID,
122150
uint96 indexed _parent,
@@ -128,6 +156,15 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
128156
uint256[4] _timesPerPeriod,
129157
uint256[] _supportedDisputeKits
130158
);
159+
160+
/// @dev Emitted when court's parameters are changed.
161+
/// @param _courtID ID of the court.
162+
/// @param _hiddenVotes Whether the court has hidden votes or not.
163+
/// @param _minStake The `minStake` property value of the court.
164+
/// @param _alpha The `alpha` property value of the court.
165+
/// @param _feeForJuror The `feeForJuror` property value of the court.
166+
/// @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the court.
167+
/// @param _timesPerPeriod The `timesPerPeriod` property value of the court.
131168
event CourtModified(
132169
uint96 indexed _courtID,
133170
bool _hiddenVotes,
@@ -137,20 +174,50 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
137174
uint256 _jurorsForCourtJump,
138175
uint256[4] _timesPerPeriod
139176
);
177+
178+
/// @dev Emitted when a dispute kit is created.
179+
/// @param _disputeKitID ID of the new dispute kit.
180+
/// @param _disputeKitAddress Address of the new dispute kit.
140181
event DisputeKitCreated(uint256 indexed _disputeKitID, IDisputeKit indexed _disputeKitAddress);
182+
183+
/// @dev Emitted when a dispute kit is enabled/disabled in a court.
184+
/// @param _courtID ID of the related court.
185+
/// @param _disputeKitID ID of the dispute kit.
186+
/// @param _enable Whether the dispute kit has been enabled or disabled.
141187
event DisputeKitEnabled(uint96 indexed _courtID, uint256 indexed _disputeKitID, bool indexed _enable);
188+
189+
/// @dev Emitted when a dispute jumps to a new court.
190+
/// @param _disputeID ID of the dispute.
191+
/// @param _roundID ID of the round.
192+
/// @param _fromCourtID ID of the previous court.
193+
/// @param _toCourtID ID of the new court.
142194
event CourtJump(
143195
uint256 indexed _disputeID,
144196
uint256 indexed _roundID,
145197
uint96 indexed _fromCourtID,
146198
uint96 _toCourtID
147199
);
200+
201+
/// @dev Emitted when a dispute jumps to a new dispute kit.
202+
/// @param _disputeID ID of the dispute.
203+
/// @param _roundID ID of the round.
204+
/// @param _fromDisputeKitID ID of the previous dispute kit.
205+
/// @param _toDisputeKitID ID of the new dispute kit.
148206
event DisputeKitJump(
149207
uint256 indexed _disputeID,
150208
uint256 indexed _roundID,
151209
uint256 indexed _fromDisputeKitID,
152210
uint256 _toDisputeKitID
153211
);
212+
213+
/// @dev Emitted when juror's balance shifts after penalties/rewards has been processed.
214+
/// @param _account Juror's address.
215+
/// @param _disputeID ID of the dispute.
216+
/// @param _roundID ID of the round.
217+
/// @param _degreeOfCoherency Juror's degree of coherency in this round.
218+
/// @param _pnkAmount Amount of PNK shifted.
219+
/// @param _feeAmount Amount of fee shifted.
220+
/// @param _feeToken Address of the fee token.
154221
event TokenAndETHShift(
155222
address indexed _account,
156223
uint256 indexed _disputeID,
@@ -160,14 +227,25 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
160227
int256 _feeAmount,
161228
IERC20 _feeToken
162229
);
230+
231+
/// @dev Emitted when leftover reward sent to owner.
232+
/// @param _disputeID ID of the dispute.
233+
/// @param _roundID ID of the round.
234+
/// @param _pnkAmount Amount of PNK sent.
235+
/// @param _feeAmount Amount of fee sent.
236+
/// @param _feeToken Address of the fee token.
163237
event LeftoverRewardSent(
164238
uint256 indexed _disputeID,
165239
uint256 indexed _roundID,
166240
uint256 _pnkAmount,
167241
uint256 _feeAmount,
168242
IERC20 _feeToken
169243
);
244+
245+
/// @dev Emitted when this contract is paused.
170246
event Paused();
247+
248+
/// @dev Emitted when this contract is unpaused.
171249
event Unpaused();
172250

173251
// ************************************* //
@@ -413,6 +491,14 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
413491
);
414492
}
415493

494+
/// @dev Changes the parameters of the court.
495+
/// @param _courtID ID of the court.
496+
/// @param _hiddenVotes The `hiddenVotes` property value of the court.
497+
/// @param _minStake The `minStake` property value of the court.
498+
/// @param _alpha The `alpha` property value of the court.
499+
/// @param _feeForJuror The `feeForJuror` property value of the court.
500+
/// @param _jurorsForCourtJump The `jurorsForCourtJump` property value of the court.
501+
/// @param _timesPerPeriod The `timesPerPeriod` property value of the court.
416502
function changeCourtParameters(
417503
uint96 _courtID,
418504
bool _hiddenVotes,
@@ -795,7 +881,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
795881
}
796882
}
797883
if (round.pnkPenalties != pnkPenaltiesInRound) {
798-
round.pnkPenalties = pnkPenaltiesInRound; // Reentrancy risk: breaks Check-Effect-Interact
884+
round.pnkPenalties = pnkPenaltiesInRound; // Note: Check-Effect-Interaction pattern is compromised here, but in the current state it doesn't cause any issues.
799885
}
800886
}
801887

@@ -816,7 +902,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
816902
_params.pnkAtStakePerJurorInRound
817903
);
818904

819-
// Guard against degree exceeding 1, though it should be ensured by the dispute kit.
905+
// Extra check to guard against degree exceeding 1, though it should be ensured by the dispute kit.
820906
if (coherence > ONE_BASIS_POINT) {
821907
coherence = ONE_BASIS_POINT;
822908
}
@@ -885,7 +971,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
885971
_params.pnkAtStakePerJurorInRound
886972
);
887973

888-
// Guard against degree exceeding 1, though it should be ensured by the dispute kit.
974+
// Extra check to guard against degree exceeding 1, though it should be ensured by the dispute kit.
889975
if (pnkCoherence > ONE_BASIS_POINT) {
890976
pnkCoherence = ONE_BASIS_POINT;
891977
}
@@ -908,7 +994,7 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
908994
// Transfer the fee reward
909995
_transferFeeToken(round.feeToken, payable(account), feeReward);
910996

911-
// Stake the PNK reward if possible, by-passes delayed stakes and other checks usually done by validateStake()
997+
// Stake the PNK reward if possible, bypasses delayed stakes and other checks done by validateStake()
912998
if (!sortitionModule.setStakeReward(account, dispute.courtID, pnkReward)) {
913999
pinakion.safeTransfer(account, pnkReward);
9141000
}
@@ -1102,10 +1188,16 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
11021188
return !courts[court.parent].supportedDisputeKits[round.disputeKitID];
11031189
}
11041190

1191+
/// @dev Returns the length of disputeKits array.
1192+
/// @return disputeKits length.
11051193
function getDisputeKitsLength() external view returns (uint256) {
11061194
return disputeKits.length;
11071195
}
11081196

1197+
/// @dev Converts ETH into tokens.
1198+
/// @param _toToken The token to convert ETH into.
1199+
/// @param _amountInEth ETH amount.
1200+
/// @return Amount of tokens.
11091201
function convertEthToTokenAmount(IERC20 _toToken, uint256 _amountInEth) public view returns (uint256) {
11101202
return (_amountInEth * 10 ** currencyRates[_toToken].rateDecimals) / currencyRates[_toToken].rateInEth;
11111203
}
@@ -1127,6 +1219,15 @@ contract KlerosCore is IArbitratorV2, Initializable, UUPSProxiable {
11271219
disputeKits[_round.disputeKitID].earlyCourtJump(_disputeID) || _round.nbVotes >= _court.jurorsForCourtJump;
11281220
}
11291221

1222+
/// @dev Checks whether a dispute will jump to new court/DK, and returns new court and DK.
1223+
/// @param _dispute Dispute data.
1224+
/// @param _round Round ID.
1225+
/// @param _court Current court ID.
1226+
/// @param _disputeID Dispute ID.
1227+
/// @return newCourtID Court ID after jump.
1228+
/// @return newDisputeKitID Dispute kit ID after jump.
1229+
/// @return courtJump Whether the dispute jumps to a new court or not.
1230+
/// @return disputeKitJump Whether the dispute jumps to a new dispute kit or not.
11301231
function _getCourtAndDisputeKitJumps(
11311232
Dispute storage _dispute,
11321233
Round storage _round,

contracts/src/arbitration/SortitionModule.sol

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,9 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
5353
mapping(TreeKey key => SortitionTrees.Tree) sortitionSumTrees; // The mapping of sortition trees by keys.
5454
mapping(address account => Juror) public jurors; // The jurors.
5555
mapping(uint256 => DelayedStake) public delayedStakes; // Stores the stakes that were changed during Drawing phase, to update them when the phase is switched to Staking.
56-
uint256 public maxStakePerJuror;
57-
uint256 public maxTotalStaked;
58-
uint256 public totalStaked;
56+
uint256 public maxStakePerJuror; // The maximum amount of PNK a juror can stake in a court.
57+
uint256 public maxTotalStaked; // The maximum amount of PNK that can be staked in all courts.
58+
uint256 public totalStaked; // The amount that is currently staked in all courts.
5959

6060
// ************************************* //
6161
// * Events * //
@@ -178,10 +178,14 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
178178
}
179179
}
180180

181+
/// @dev Changes the `maxStakePerJuror` storage variable.
182+
/// @param _maxStakePerJuror The new `maxStakePerJuror` storage variable.
181183
function changeMaxStakePerJuror(uint256 _maxStakePerJuror) external onlyByOwner {
182184
maxStakePerJuror = _maxStakePerJuror;
183185
}
184186

187+
/// @dev Changes the `maxTotalStaked` storage variable.
188+
/// @param _maxTotalStaked The new `maxTotalStaked` storage variable.
185189
function changeMaxTotalStaked(uint256 _maxTotalStaked) external onlyByOwner {
186190
maxTotalStaked = _maxTotalStaked;
187191
}
@@ -190,6 +194,7 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
190194
// * State Modifiers * //
191195
// ************************************* //
192196

197+
/// @dev Passes the phase.
193198
function passPhase() external {
194199
if (phase == Phase.staking) {
195200
if (block.timestamp - lastPhaseChange < minStakingTime) revert MinStakingTimeNotPassed();
@@ -239,10 +244,12 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
239244
delayedStakeReadIndex = newDelayedStakeReadIndex;
240245
}
241246

247+
/// @dev Triggers the state changes after dispute creation.
242248
function createDisputeHook(uint256 /*_disputeID*/, uint256 /*_roundID*/) external override onlyByCore {
243249
disputesWithoutJurors++;
244250
}
245251

252+
/// @dev Triggers the state changes after drawing.
246253
function postDrawHook(uint256 /*_disputeID*/, uint256 /*_roundID*/) external override onlyByCore {
247254
disputesWithoutJurors--;
248255
}
@@ -452,11 +459,17 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
452459
emit StakeSet(_account, _courtID, _newStake, juror.stakedPnk);
453460
}
454461

462+
/// @dev Locks the tokens of the drawn juror.
463+
/// @param _account The address of the juror.
464+
/// @param _relativeAmount The amount to lock.
455465
function lockStake(address _account, uint256 _relativeAmount) external override onlyByCore {
456466
jurors[_account].lockedPnk += _relativeAmount;
457467
emit StakeLocked(_account, _relativeAmount, false);
458468
}
459469

470+
/// @dev Unlocks the tokens of the drawn juror.
471+
/// @param _account The address of the juror.
472+
/// @param _relativeAmount The amount to unlock.
460473
function unlockStake(address _account, uint256 _relativeAmount) external override onlyByCore {
461474
Juror storage juror = jurors[_account];
462475
juror.lockedPnk -= _relativeAmount;
@@ -573,10 +586,16 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
573586
return jurors[_juror].courtIDs;
574587
}
575588

589+
/// @dev Checks if the juror is staked in any court.
590+
/// @param _juror The address of the juror.
591+
/// @return Whether the juror is staked or not.
576592
function isJurorStaked(address _juror) external view override returns (bool) {
577593
return jurors[_juror].stakedPnk > 0;
578594
}
579595

596+
/// @dev Checks if the juror has any leftover PNK in the contract.
597+
/// @param _juror The address of the juror.
598+
/// @return Whether the juror has leftover PNK.
580599
function getJurorLeftoverPNK(address _juror) public view override returns (uint256) {
581600
Juror storage juror = jurors[_juror];
582601
if (juror.courtIDs.length == 0 && juror.lockedPnk == 0) {
@@ -590,6 +609,9 @@ contract SortitionModule is ISortitionModule, Initializable, UUPSProxiable {
590609
// * Internal * //
591610
// ************************************* //
592611

612+
/// @dev Converts sortition extradata into K value of sortition tree.
613+
/// @param _extraData Sortition extra data.
614+
/// @return K The value of K.
593615
function _extraDataToTreeK(bytes memory _extraData) internal pure returns (uint256 K) {
594616
if (_extraData.length >= 32) {
595617
assembly {

0 commit comments

Comments
 (0)