@@ -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
@@ -774,26 +782,25 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
774
782
775
783
// Fully coherent jurors won't be penalized.
776
784
uint256 penalty = (round.pnkAtStakePerJuror * (ALPHA_DIVISOR - degreeOfCoherence)) / ALPHA_DIVISOR;
777
- _params.pnkPenaltiesInRound += penalty;
778
785
779
786
// Unlock the PNKs affected by the penalty
780
787
address account = round.drawnJurors[_params.repartition];
781
788
sortitionModule.unlockStake (account, penalty);
782
789
783
790
// Apply the penalty to the staked PNKs.
784
- sortitionModule.penalizeStake (account, penalty);
791
+ (uint256 pnkBalance , uint256 availablePenalty ) = sortitionModule.penalizeStake (account, penalty);
792
+ _params.pnkPenaltiesInRound += availablePenalty;
785
793
emit TokenAndETHShift (
786
794
account,
787
795
_params.disputeID,
788
796
_params.round,
789
797
degreeOfCoherence,
790
- - int256 (penalty ),
798
+ - int256 (availablePenalty ),
791
799
0 ,
792
800
round.feeToken
793
801
);
794
-
795
- if (! disputeKit.isVoteActive (_params.disputeID, _params.round, _params.repartition)) {
796
- // The juror is inactive, unstake them.
802
+ // Unstake the juror from all courts if he was inactive or his balance can't cover penalties anymore.
803
+ if (pnkBalance == 0 || ! disputeKit.isVoteActive (_params.disputeID, _params.round, _params.repartition)) {
797
804
sortitionModule.setJurorInactive (account);
798
805
}
799
806
if (_params.repartition == _params.numberOfVotesInRound - 1 && _params.coherentCount == 0 ) {
@@ -844,11 +851,6 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
844
851
// Release the rest of the PNKs of the juror for this round.
845
852
sortitionModule.unlockStake (account, pnkLocked);
846
853
847
- // Give back the locked PNKs in case the juror fully unstaked earlier.
848
- if (! sortitionModule.isJurorStaked (account)) {
849
- pinakion.safeTransfer (account, pnkLocked);
850
- }
851
-
852
854
// Transfer the rewards
853
855
uint256 pnkReward = ((_params.pnkPenaltiesInRound / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR;
854
856
round.sumPnkRewardPaid += pnkReward;
@@ -1074,14 +1076,13 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
1074
1076
/// @param _account The account to set the stake for.
1075
1077
/// @param _courtID The ID of the court to set the stake for.
1076
1078
/// @param _newStake The new stake.
1077
- /// @param _alreadyTransferred Whether the PNKs were already transferred to/from the staking contract.
1078
1079
/// @param _onError Whether to revert or return false on error.
1079
1080
/// @return Whether the stake was successfully set or not.
1080
1081
function _setStake (
1081
1082
address _account ,
1082
1083
uint96 _courtID ,
1083
1084
uint256 _newStake ,
1084
- bool _alreadyTransferred ,
1085
+ bool /* _alreadyTransferred*/ ,
1085
1086
OnError _onError
1086
1087
) internal returns (bool ) {
1087
1088
if (_courtID == FORKING_COURT || _courtID >= courts.length ) {
@@ -1096,7 +1097,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
1096
1097
_account,
1097
1098
_courtID,
1098
1099
_newStake,
1099
- _alreadyTransferred
1100
+ false // Unused parameter.
1100
1101
);
1101
1102
if (stakingResult != StakingResult.Successful) {
1102
1103
_stakingFailed (_onError, stakingResult);
0 commit comments