@@ -470,15 +470,23 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
470470 /// @param _account The account whose stake is being set.
471471 /// @param _courtID The ID of the court.
472472 /// @param _newStake The new stake.
473- /// @param _alreadyTransferred Whether the PNKs have already been transferred to the contract.
474473 function setStakeBySortitionModule (
475474 address _account ,
476475 uint96 _courtID ,
477476 uint256 _newStake ,
478- bool _alreadyTransferred
477+ bool /* _alreadyTransferred*/
479478 ) external {
480479 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);
482490 }
483491
484492 /// @inheritdoc IArbitratorV2
@@ -774,26 +782,25 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
774782
775783 // Fully coherent jurors won't be penalized.
776784 uint256 penalty = (round.pnkAtStakePerJuror * (ALPHA_DIVISOR - degreeOfCoherence)) / ALPHA_DIVISOR;
777- _params.pnkPenaltiesInRound += penalty;
778785
779786 // Unlock the PNKs affected by the penalty
780787 address account = round.drawnJurors[_params.repartition];
781788 sortitionModule.unlockStake (account, penalty);
782789
783790 // 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;
785793 emit TokenAndETHShift (
786794 account,
787795 _params.disputeID,
788796 _params.round,
789797 degreeOfCoherence,
790- - int256 (penalty ),
798+ - int256 (availablePenalty ),
791799 0 ,
792800 round.feeToken
793801 );
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)) {
797804 sortitionModule.setJurorInactive (account);
798805 }
799806 if (_params.repartition == _params.numberOfVotesInRound - 1 && _params.coherentCount == 0 ) {
@@ -844,11 +851,6 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
844851 // Release the rest of the PNKs of the juror for this round.
845852 sortitionModule.unlockStake (account, pnkLocked);
846853
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-
852854 // Transfer the rewards
853855 uint256 pnkReward = ((_params.pnkPenaltiesInRound / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR;
854856 round.sumPnkRewardPaid += pnkReward;
@@ -1074,14 +1076,13 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
10741076 /// @param _account The account to set the stake for.
10751077 /// @param _courtID The ID of the court to set the stake for.
10761078 /// @param _newStake The new stake.
1077- /// @param _alreadyTransferred Whether the PNKs were already transferred to/from the staking contract.
10781079 /// @param _onError Whether to revert or return false on error.
10791080 /// @return Whether the stake was successfully set or not.
10801081 function _setStake (
10811082 address _account ,
10821083 uint96 _courtID ,
10831084 uint256 _newStake ,
1084- bool _alreadyTransferred ,
1085+ bool /* _alreadyTransferred*/ ,
10851086 OnError _onError
10861087 ) internal returns (bool ) {
10871088 if (_courtID == FORKING_COURT || _courtID >= courts.length ) {
@@ -1096,7 +1097,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
10961097 _account,
10971098 _courtID,
10981099 _newStake,
1099- _alreadyTransferred
1100+ false // Unused parameter.
11001101 );
11011102 if (stakingResult != StakingResult.Successful) {
11021103 _stakingFailed (_onError, stakingResult);
0 commit comments