@@ -115,8 +115,13 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
115115 // ************************************* //
116116
117117 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+ );
120125 event NewPeriod (uint256 indexed _disputeID , Period _period );
121126 event AppealPossible (uint256 indexed _disputeID , IArbitrableV2 indexed _arbitrable );
122127 event AppealDecision (uint256 indexed _disputeID , IArbitrableV2 indexed _arbitrable );
@@ -171,7 +176,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
171176 uint256 _feeAmount ,
172177 IERC20 _feeToken
173178 );
174- event PartiallyDelayedStakeWithdrawn (uint96 indexed _courtID , address indexed _account , uint256 _withdrawnAmount );
175179
176180 // ************************************* //
177181 // * Function Modifiers * //
@@ -460,18 +464,26 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
460464 /// @param _newStake The new stake.
461465 /// Note that the existing delayed stake will be nullified as non-relevant.
462466 function setStake (uint96 _courtID , uint256 _newStake ) external {
463- removeDelayedStake (_courtID);
467+ _deleteDelayedStake (_courtID);
464468 if (! _setStakeForAccount (msg .sender , _courtID, _newStake, false )) revert StakingFailed ();
465469 }
466470
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);
471483 }
472484
473485 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 ();
475487 uint256 actualAmount = _amountToWithdraw;
476488 Juror storage juror = jurors[_juror];
477489 if (juror.stakedPnk <= actualAmount) {
@@ -481,7 +493,7 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
481493 // StakePnk can become lower because of penalty, thus we adjust the amount for it. stakedPnkByCourt can't be penalized so subtract the default amount.
482494 juror.stakedPnk -= actualAmount;
483495 juror.stakedPnkByCourt[_courtID] -= _amountToWithdraw;
484- emit PartiallyDelayedStakeWithdrawn (_courtID, _juror, _amountToWithdraw);
496+ emit StakeDelayedAlreadyTransferredWithdrawn (_courtID, _juror, _amountToWithdraw);
485497 // Note that if we don't delete court here it'll be duplicated after staking.
486498 if (juror.stakedPnkByCourt[_courtID] == 0 ) {
487499 for (uint256 i = juror.courtIDs.length ; i > 0 ; i-- ) {
@@ -494,20 +506,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
494506 }
495507 }
496508
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-
511509 /// @inheritdoc IArbitratorV2
512510 function createDispute (
513511 uint256 _numberOfChoices ,
@@ -1063,6 +1061,12 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
10631061 emit DisputeKitEnabled (_courtID, _disputeKitID, _enable);
10641062 }
10651063
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+
10661070 /// @dev Sets the specified juror's stake in a court.
10671071 /// `O(n + p * log_k(j))` where
10681072 /// `n` is the number of courts the juror has staked in,
@@ -1091,11 +1095,11 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
10911095 return false ;
10921096 }
10931097
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) {
10961100 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);
10991103 return true ;
11001104 }
11011105
@@ -1153,8 +1157,8 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
11531157 }
11541158
11551159 // 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);
11581162 return true ;
11591163 }
11601164
@@ -1201,6 +1205,8 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
12011205 // ************************************* //
12021206
12031207 error GovernorOnly ();
1208+ error DisputeKitOnly ();
1209+ error SortitionModuleOnly ();
12041210 error UnsuccessfulCall ();
12051211 error InvalidDisputKitParent ();
12061212 error DepthLevelMax ();
@@ -1211,7 +1217,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
12111217 error CannotDisableClassicDK ();
12121218 error ArraysLengthMismatch ();
12131219 error StakingFailed ();
1214- error WrongCaller ();
12151220 error ArbitrationFeesNotEnough ();
12161221 error DisputeKitNotSupportedByCourt ();
12171222 error MustSupportDisputeKitClassic ();
@@ -1224,7 +1229,6 @@ contract KlerosCore is IArbitratorV2, UUPSProxiable, Initializable {
12241229 error NotEvidencePeriod ();
12251230 error AppealFeesNotEnough ();
12261231 error DisputeNotAppealable ();
1227- error DisputeKitOnly ();
12281232 error NotExecutionPeriod ();
12291233 error RulingAlreadyExecuted ();
12301234 error DisputePeriodIsFinal ();
0 commit comments