@@ -115,8 +115,13 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
115
115
// ************************************* //
116
116
117
117
event StakeSet (address indexed _address , uint256 _courtID , uint256 _amount );
118
- event StakeDelayed (address indexed _address , uint256 _courtID , uint256 _amount );
119
- event StakePartiallyDelayed (address indexed _address , uint256 _courtID , uint256 _amount );
118
+ event StakeDelayedNotTransferred (address indexed _address , uint256 _courtID , uint256 _amount );
119
+ event StakeDelayedAlreadyTransferred (address indexed _address , uint256 _courtID , uint256 _amount );
120
+ event StakeDelayedAlreadyTransferredWithdrawn (
121
+ uint96 indexed _courtID ,
122
+ address indexed _account ,
123
+ uint256 _withdrawnAmount
124
+ );
120
125
event NewPeriod (uint256 indexed _disputeID , Period _period );
121
126
event AppealPossible (uint256 indexed _disputeID , IArbitrableV2 indexed _arbitrable );
122
127
event AppealDecision (uint256 indexed _disputeID , IArbitrableV2 indexed _arbitrable );
@@ -171,7 +176,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
171
176
uint256 _feeAmount ,
172
177
IERC20 _feeToken
173
178
);
174
- event PartiallyDelayedStakeWithdrawn (uint96 indexed _courtID , address indexed _account , uint256 _withdrawnAmount );
175
179
176
180
// ************************************* //
177
181
// * Function Modifiers * //
@@ -460,18 +464,26 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
460
464
/// @param _newStake The new stake.
461
465
/// Note that the existing delayed stake will be nullified as non-relevant.
462
466
function setStake (uint96 _courtID , uint256 _newStake ) external {
463
- removeDelayedStake (_courtID);
467
+ _deleteDelayedStake (_courtID);
464
468
if (! _setStakeForAccount (msg .sender , _courtID, _newStake, false )) revert StakingFailed ();
465
469
}
466
470
467
- /// @dev Removes the latest delayed stake if there is any.
468
- /// @param _courtID The ID of the court.
469
- function removeDelayedStake (uint96 _courtID ) public {
470
- sortitionModule.checkExistingDelayedStake (_courtID, msg .sender );
471
+ function setStakeBySortitionModule (
472
+ address _account ,
473
+ uint96 _courtID ,
474
+ uint256 _newStake ,
475
+ bool _alreadyTransferred
476
+ ) external {
477
+ if (msg .sender != address (sortitionModule)) revert SortitionModuleOnly ();
478
+ // Always nullify the latest delayed stake before setting a new value.
479
+ // Note that we check the delayed stake here too because the check in `setStake` can be bypassed
480
+ // if the stake was updated automatically during `execute` (e.g. when unstaking inactive juror).
481
+ _deleteDelayedStake (_courtID);
482
+ _setStakeForAccount (_account, _courtID, _newStake, _alreadyTransferred);
471
483
}
472
484
473
485
function withdrawPartiallyDelayedStake (uint96 _courtID , address _juror , uint256 _amountToWithdraw ) external {
474
- if (msg .sender != address (sortitionModule)) revert WrongCaller ();
486
+ if (msg .sender != address (sortitionModule)) revert SortitionModuleOnly ();
475
487
uint256 actualAmount = _amountToWithdraw;
476
488
Juror storage juror = jurors[_juror];
477
489
if (juror.stakedPnk <= actualAmount) {
@@ -481,7 +493,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
481
493
// StakePnk can become lower because of penalty, thus we adjust the amount for it. stakedPnkByCourt can't be penalized so subtract the default amount.
482
494
juror.stakedPnk -= actualAmount;
483
495
juror.stakedPnkByCourt[_courtID] -= _amountToWithdraw;
484
- emit PartiallyDelayedStakeWithdrawn (_courtID, _juror, _amountToWithdraw);
496
+ emit StakeDelayedAlreadyTransferredWithdrawn (_courtID, _juror, _amountToWithdraw);
485
497
// Note that if we don't delete court here it'll be duplicated after staking.
486
498
if (juror.stakedPnkByCourt[_courtID] == 0 ) {
487
499
for (uint256 i = juror.courtIDs.length ; i > 0 ; i-- ) {
@@ -494,20 +506,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
494
506
}
495
507
}
496
508
497
- function setStakeBySortitionModule (
498
- address _account ,
499
- uint96 _courtID ,
500
- uint256 _newStake ,
501
- bool _alreadyTransferred
502
- ) external {
503
- if (msg .sender != address (sortitionModule)) revert WrongCaller ();
504
- // Always nullify the latest delayed stake before setting a new value.
505
- // Note that we check the delayed stake here too because the check in `setStake` can be bypassed
506
- // if the stake was updated automatically during `execute` (e.g. when unstaking inactive juror).
507
- removeDelayedStake (_courtID);
508
- _setStakeForAccount (_account, _courtID, _newStake, _alreadyTransferred);
509
- }
510
-
511
509
/// @inheritdoc IArbitratorV2
512
510
function createDispute (
513
511
uint256 _numberOfChoices ,
@@ -1063,6 +1061,12 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
1063
1061
emit DisputeKitEnabled (_courtID, _disputeKitID, _enable);
1064
1062
}
1065
1063
1064
+ /// @dev Removes the latest delayed stake if there is any.
1065
+ /// @param _courtID The ID of the court.
1066
+ function _deleteDelayedStake (uint96 _courtID ) private {
1067
+ sortitionModule.deleteDelayedStake (_courtID, msg .sender );
1068
+ }
1069
+
1066
1070
/// @dev Sets the specified juror's stake in a court.
1067
1071
/// `O(n + p * log_k(j))` where
1068
1072
/// `n` is the number of courts the juror has staked in,
@@ -1091,11 +1095,11 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
1091
1095
return false ;
1092
1096
}
1093
1097
1094
- ISortitionModule.preStakeHookResult result = sortitionModule.preStakeHook (_account, _courtID, _newStake);
1095
- if (result == ISortitionModule.preStakeHookResult .failed) {
1098
+ ISortitionModule.PreStakeHookResult result = sortitionModule.preStakeHook (_account, _courtID, _newStake);
1099
+ if (result == ISortitionModule.PreStakeHookResult .failed) {
1096
1100
return false ;
1097
- } else if (result == ISortitionModule.preStakeHookResult.delayed ) {
1098
- emit StakeDelayed (_account, _courtID, _newStake);
1101
+ } else if (result == ISortitionModule.PreStakeHookResult.stakeDelayedNotTransferred ) {
1102
+ emit StakeDelayedNotTransferred (_account, _courtID, _newStake);
1099
1103
return true ;
1100
1104
}
1101
1105
@@ -1153,8 +1157,8 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
1153
1157
}
1154
1158
1155
1159
// Transfer the tokens but don't update sortition module.
1156
- if (result == ISortitionModule.preStakeHookResult.partiallyDelayed ) {
1157
- emit StakePartiallyDelayed (_account, _courtID, _newStake);
1160
+ if (result == ISortitionModule.PreStakeHookResult.stakeDelayedAlreadyTransferred ) {
1161
+ emit StakeDelayedAlreadyTransferred (_account, _courtID, _newStake);
1158
1162
return true ;
1159
1163
}
1160
1164
@@ -1201,6 +1205,8 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
1201
1205
// ************************************* //
1202
1206
1203
1207
error GovernorOnly ();
1208
+ error DisputeKitOnly ();
1209
+ error SortitionModuleOnly ();
1204
1210
error UnsuccessfulCall ();
1205
1211
error InvalidDisputKitParent ();
1206
1212
error DepthLevelMax ();
@@ -1211,7 +1217,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
1211
1217
error CannotDisableClassicDK ();
1212
1218
error ArraysLengthMismatch ();
1213
1219
error StakingFailed ();
1214
- error WrongCaller ();
1215
1220
error ArbitrationFeesNotEnough ();
1216
1221
error DisputeKitNotSupportedByCourt ();
1217
1222
error MustSupportDisputeKitClassic ();
@@ -1224,7 +1229,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
1224
1229
error NotEvidencePeriod ();
1225
1230
error AppealFeesNotEnough ();
1226
1231
error DisputeNotAppealable ();
1227
- error DisputeKitOnly ();
1228
1232
error NotExecutionPeriod ();
1229
1233
error RulingAlreadyExecuted ();
1230
1234
error DisputePeriodIsFinal ();
0 commit comments