@@ -470,15 +470,23 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
470
470
/// @param _account The account whose stake is being set.
471
471
/// @param _courtID The ID of the court.
472
472
/// @param _newStake The new stake.
473
- /// @param _alreadyTransferred Whether the PNKs have already been transferred to the contract.
474
473
function setStakeBySortitionModule (
475
474
address _account ,
476
475
uint96 _courtID ,
477
476
uint256 _newStake ,
478
- bool _alreadyTransferred
477
+ bool /* _alreadyTransferred*/
479
478
) external {
480
479
if (msg .sender != address (sortitionModule)) revert SortitionModuleOnly ();
481
- _setStake (_account, _courtID, _newStake, _alreadyTransferred, OnError.Return);
480
+ _setStake (_account, _courtID, _newStake, false , OnError.Return); // alreadyTransferred is unused and DEPRECATED.
481
+ }
482
+
483
+ /// @dev Transfers PNK to the juror by SortitionModule.
484
+ /// @param _account The account of the juror whose PNK to transfer.
485
+ /// @param _amount The amount to transfer.
486
+ function transferBySortitionModule (address _account , uint256 _amount ) external {
487
+ if (msg .sender != address (sortitionModule)) revert SortitionModuleOnly ();
488
+ // Note eligibility is checked in SortitionModule.
489
+ pinakion.safeTransfer (_account, _amount);
482
490
}
483
491
484
492
/// @inheritdoc IArbitratorV2
@@ -772,26 +780,25 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
772
780
773
781
// Fully coherent jurors won't be penalized.
774
782
uint256 penalty = (round.pnkAtStakePerJuror * (ALPHA_DIVISOR - degreeOfCoherence)) / ALPHA_DIVISOR;
775
- _params.pnkPenaltiesInRound += penalty;
776
783
777
784
// Unlock the PNKs affected by the penalty
778
785
address account = round.drawnJurors[_params.repartition];
779
786
sortitionModule.unlockStake (account, penalty);
780
787
781
788
// Apply the penalty to the staked PNKs.
782
- sortitionModule.penalizeStake (account, penalty);
789
+ (uint256 pnkBalance , uint256 availablePenalty ) = sortitionModule.penalizeStake (account, penalty);
790
+ _params.pnkPenaltiesInRound += availablePenalty;
783
791
emit TokenAndETHShift (
784
792
account,
785
793
_params.disputeID,
786
794
_params.round,
787
795
degreeOfCoherence,
788
- - int256 (penalty ),
796
+ - int256 (availablePenalty ),
789
797
0 ,
790
798
round.feeToken
791
799
);
792
-
793
- if (! disputeKit.isVoteActive (_params.disputeID, _params.round, _params.repartition)) {
794
- // The juror is inactive, unstake them.
800
+ // Unstake the juror from all courts if he was inactive or his balance can't cover penalties anymore.
801
+ if (pnkBalance == 0 || ! disputeKit.isVoteActive (_params.disputeID, _params.round, _params.repartition)) {
795
802
sortitionModule.setJurorInactive (account);
796
803
}
797
804
if (_params.repartition == _params.numberOfVotesInRound - 1 && _params.coherentCount == 0 ) {
@@ -842,11 +849,6 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
842
849
// Release the rest of the PNKs of the juror for this round.
843
850
sortitionModule.unlockStake (account, pnkLocked);
844
851
845
- // Give back the locked PNKs in case the juror fully unstaked earlier.
846
- if (! sortitionModule.isJurorStaked (account)) {
847
- pinakion.safeTransfer (account, pnkLocked);
848
- }
849
-
850
852
// Transfer the rewards
851
853
uint256 pnkReward = ((_params.pnkPenaltiesInRound / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR;
852
854
round.sumPnkRewardPaid += pnkReward;
@@ -1072,14 +1074,13 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
1072
1074
/// @param _account The account to set the stake for.
1073
1075
/// @param _courtID The ID of the court to set the stake for.
1074
1076
/// @param _newStake The new stake.
1075
- /// @param _alreadyTransferred Whether the PNKs were already transferred to/from the staking contract.
1076
1077
/// @param _onError Whether to revert or return false on error.
1077
1078
/// @return Whether the stake was successfully set or not.
1078
1079
function _setStake (
1079
1080
address _account ,
1080
1081
uint96 _courtID ,
1081
1082
uint256 _newStake ,
1082
- bool _alreadyTransferred ,
1083
+ bool /* _alreadyTransferred*/ ,
1083
1084
OnError _onError
1084
1085
) internal returns (bool ) {
1085
1086
if (_courtID == FORKING_COURT || _courtID >= courts.length ) {
@@ -1094,7 +1095,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
1094
1095
_account,
1095
1096
_courtID,
1096
1097
_newStake,
1097
- _alreadyTransferred
1098
+ false // Unused parameter.
1098
1099
);
1099
1100
if (stakingResult != StakingResult.Successful) {
1100
1101
_stakingFailed (_onError, stakingResult);
0 commit comments