@@ -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 ,
0 commit comments