@@ -218,30 +218,13 @@ contract SortitionModule is ISortitionModule, UUPSProxiable, Initializable {
218
218
delayedStakeReadIndex = newDelayedStakeReadIndex;
219
219
}
220
220
221
- /// @dev Checks if there is already a delayed stake. In this case consider it irrelevant and remove it.
222
- /// @param _courtID ID of the court.
223
- /// @param _juror Juror whose stake to check.
224
- function deleteDelayedStake (uint96 _courtID , address _juror ) external override onlyByCore {
225
- uint256 latestIndex = latestDelayedStakeIndex[_juror][_courtID];
226
- if (latestIndex != 0 ) {
227
- DelayedStake storage delayedStake = delayedStakes[latestIndex];
228
- if (delayedStake.alreadyTransferred) {
229
- bytes32 stakePathID = _accountAndCourtIDToStakePathID (_juror, _courtID);
230
- // Sortition stake represents the stake value that was last updated during Staking phase.
231
- uint256 sortitionStake = stakeOf (bytes32 (uint256 (_courtID)), stakePathID);
232
- // Withdraw the tokens that were added with the latest delayed stake.
233
- core.withdrawPartiallyDelayedStake (_courtID, _juror, delayedStake.stake - sortitionStake);
234
- }
235
- delete delayedStakes[latestIndex];
236
- delete latestDelayedStakeIndex[_juror][_courtID];
237
- }
238
- }
239
-
240
221
function preStakeHook (
241
222
address _account ,
242
223
uint96 _courtID ,
243
224
uint256 _stake
244
225
) external override onlyByCore returns (PreStakeHookResult) {
226
+ _deleteDelayedStake (_courtID, _account);
227
+
245
228
(, , uint256 currentStake , uint256 nbCourts ) = core.getJurorBalance (_account, _courtID);
246
229
if (currentStake == 0 && nbCourts >= MAX_STAKE_PATHS) {
247
230
// Prevent staking beyond MAX_STAKE_PATHS but unstaking is always allowed.
@@ -268,6 +251,25 @@ contract SortitionModule is ISortitionModule, UUPSProxiable, Initializable {
268
251
return PreStakeHookResult.ok;
269
252
}
270
253
254
+ /// @dev Checks if there is already a delayed stake. In this case consider it irrelevant and remove it.
255
+ /// @param _courtID ID of the court.
256
+ /// @param _juror Juror whose stake to check.
257
+ function _deleteDelayedStake (uint96 _courtID , address _juror ) internal {
258
+ uint256 latestIndex = latestDelayedStakeIndex[_juror][_courtID];
259
+ if (latestIndex != 0 ) {
260
+ DelayedStake storage delayedStake = delayedStakes[latestIndex];
261
+ if (delayedStake.alreadyTransferred) {
262
+ bytes32 stakePathID = _accountAndCourtIDToStakePathID (_juror, _courtID);
263
+ // Sortition stake represents the stake value that was last updated during Staking phase.
264
+ uint256 sortitionStake = stakeOf (bytes32 (uint256 (_courtID)), stakePathID);
265
+ // Withdraw the tokens that were added with the latest delayed stake.
266
+ core.withdrawPartiallyDelayedStake (_courtID, _juror, delayedStake.stake - sortitionStake);
267
+ }
268
+ delete delayedStakes[latestIndex];
269
+ delete latestDelayedStakeIndex[_juror][_courtID];
270
+ }
271
+ }
272
+
271
273
function createDisputeHook (uint256 /*_disputeID*/ , uint256 /*_roundID*/ ) external override onlyByCore {
272
274
disputesWithoutJurors++ ;
273
275
}
0 commit comments