@@ -538,7 +538,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
538538 : convertEthToTokenAmount (_feeToken, court.feeForJuror);
539539 round.nbVotes = _feeAmount / feeForJuror;
540540 round.disputeKitID = disputeKitID;
541- round.pnkAtStakePerJuror = (court.minStake * court.alpha) / ALPHA_DIVISOR ;
541+ round.pnkAtStakePerJuror = _calculatePnkAtStake (court.minStake, court.alpha);
542542 round.totalFeesForJurors = _feeAmount;
543543 round.feeToken = IERC20 (_feeToken);
544544
@@ -668,7 +668,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
668668
669669 Court storage court = courts[newCourtID];
670670 extraRound.nbVotes = msg .value / court.feeForJuror; // As many votes that can be afforded by the provided funds.
671- extraRound.pnkAtStakePerJuror = (court.minStake * court.alpha) / ALPHA_DIVISOR ;
671+ extraRound.pnkAtStakePerJuror = _calculatePnkAtStake (court.minStake, court.alpha);
672672 extraRound.totalFeesForJurors = msg .value ;
673673 extraRound.disputeKitID = newDisputeKitID;
674674
@@ -805,13 +805,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
805805 }
806806 if (_params.repartition == _params.numberOfVotesInRound - 1 && _params.coherentCount == 0 ) {
807807 // No one was coherent, send the rewards to the governor.
808- if (round.feeToken == NATIVE_CURRENCY) {
809- // The dispute fees were paid in ETH
810- payable (governor).safeSend (round.totalFeesForJurors, wNative);
811- } else {
812- // The dispute fees were paid in ERC20
813- round.feeToken.safeTransfer (governor, round.totalFeesForJurors);
814- }
808+ _transferFeeToken (round.feeToken, payable (governor), round.totalFeesForJurors);
815809 pinakion.safeTransfer (governor, _params.pnkPenaltiesInRound);
816810 emit LeftoverRewardSent (
817811 _params.disputeID,
@@ -846,24 +840,18 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
846840 }
847841
848842 address account = round.drawnJurors[_params.repartition % _params.numberOfVotesInRound];
849- uint256 pnkLocked = (round.pnkAtStakePerJuror * degreeOfCoherence) / ALPHA_DIVISOR ;
843+ uint256 pnkLocked = _applyCoherence (round.pnkAtStakePerJuror, degreeOfCoherence);
850844
851845 // Release the rest of the PNKs of the juror for this round.
852846 sortitionModule.unlockStake (account, pnkLocked);
853847
854848 // Transfer the rewards
855- uint256 pnkReward = (( _params.pnkPenaltiesInRound / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR ;
849+ uint256 pnkReward = _applyCoherence ( _params.pnkPenaltiesInRound / _params.coherentCount, degreeOfCoherence);
856850 round.sumPnkRewardPaid += pnkReward;
857- uint256 feeReward = (( round.totalFeesForJurors / _params.coherentCount) * degreeOfCoherence) / ALPHA_DIVISOR ;
851+ uint256 feeReward = _applyCoherence ( round.totalFeesForJurors / _params.coherentCount, degreeOfCoherence);
858852 round.sumFeeRewardPaid += feeReward;
859853 pinakion.safeTransfer (account, pnkReward);
860- if (round.feeToken == NATIVE_CURRENCY) {
861- // The dispute fees were paid in ETH
862- payable (account).safeSend (feeReward, wNative);
863- } else {
864- // The dispute fees were paid in ERC20
865- round.feeToken.safeTransfer (account, feeReward);
866- }
854+ _transferFeeToken (round.feeToken, payable (account), feeReward);
867855 emit TokenAndETHShift (
868856 account,
869857 _params.disputeID,
@@ -883,13 +871,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
883871 pinakion.safeTransfer (governor, leftoverPnkReward);
884872 }
885873 if (leftoverFeeReward != 0 ) {
886- if (round.feeToken == NATIVE_CURRENCY) {
887- // The dispute fees were paid in ETH
888- payable (governor).safeSend (leftoverFeeReward, wNative);
889- } else {
890- // The dispute fees were paid in ERC20
891- round.feeToken.safeTransfer (governor, leftoverFeeReward);
892- }
874+ _transferFeeToken (round.feeToken, payable (governor), leftoverFeeReward);
893875 }
894876 emit LeftoverRewardSent (
895877 _params.disputeID,
@@ -962,7 +944,7 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
962944 /// @param _disputeID The ID of the dispute.
963945 /// @return start The start of the appeal period.
964946 /// @return end The end of the appeal period.
965- function appealPeriod (uint256 _disputeID ) public view returns (uint256 start , uint256 end ) {
947+ function appealPeriod (uint256 _disputeID ) external view returns (uint256 start , uint256 end ) {
966948 Dispute storage dispute = disputes[_disputeID];
967949 if (dispute.period == Period.appeal) {
968950 start = dispute.lastPeriodChange;
@@ -1063,6 +1045,34 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
10631045 // * Internal * //
10641046 // ************************************* //
10651047
1048+ /// @dev Internal function to transfer fee tokens (ETH or ERC20)
1049+ /// @param _feeToken The token to transfer (NATIVE_CURRENCY for ETH).
1050+ /// @param _recipient The recipient address.
1051+ /// @param _amount The amount to transfer.
1052+ function _transferFeeToken (IERC20 _feeToken , address payable _recipient , uint256 _amount ) internal {
1053+ if (_feeToken == NATIVE_CURRENCY) {
1054+ _recipient.safeSend (_amount, wNative);
1055+ } else {
1056+ _feeToken.safeTransfer (_recipient, _amount);
1057+ }
1058+ }
1059+
1060+ /// @dev Applies degree of coherence to an amount
1061+ /// @param _amount The base amount to apply coherence to.
1062+ /// @param _degreeOfCoherence The degree of coherence in basis points.
1063+ /// @return The amount after applying the degree of coherence.
1064+ function _applyCoherence (uint256 _amount , uint256 _degreeOfCoherence ) internal pure returns (uint256 ) {
1065+ return (_amount * _degreeOfCoherence) / ALPHA_DIVISOR;
1066+ }
1067+
1068+ /// @dev Calculates PNK at stake per juror based on court parameters
1069+ /// @param _minStake The minimum stake for the court.
1070+ /// @param _alpha The alpha parameter for the court in basis points.
1071+ /// @return The amount of PNK at stake per juror.
1072+ function _calculatePnkAtStake (uint256 _minStake , uint256 _alpha ) internal pure returns (uint256 ) {
1073+ return (_minStake * _alpha) / ALPHA_DIVISOR;
1074+ }
1075+
10661076 /// @dev Toggles the dispute kit support for a given court.
10671077 /// @param _courtID The ID of the court to toggle the support for.
10681078 /// @param _disputeKitID The ID of the dispute kit to toggle the support for.
0 commit comments