Skip to content

Commit 95f2803

Browse files
committed
refactor: consolidated ALPHA_DIVISOR and ONE_BASIS_POINTS
1 parent 3d211cc commit 95f2803

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

contracts/src/arbitration/KlerosCoreBase.sol

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,6 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
8888
// * Storage * //
8989
// ************************************* //
9090

91-
uint256 private constant ALPHA_DIVISOR = 1e4; // The number to divide `Court.alpha` by.
9291
uint256 private constant NON_PAYABLE_AMOUNT = (2 ** 256 - 2) / 2; // An amount higher than the supply of ETH.
9392

9493
address public governor; // The governor of the contract.
@@ -775,13 +774,13 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
775774
_params.feePerJurorInRound,
776775
_params.pnkAtStakePerJurorInRound
777776
);
778-
if (degreeOfCoherence > ALPHA_DIVISOR) {
777+
if (degreeOfCoherence > ONE_BASIS_POINT) {
779778
// Make sure the degree doesn't exceed 1, though it should be ensured by the dispute kit.
780-
degreeOfCoherence = ALPHA_DIVISOR;
779+
degreeOfCoherence = ONE_BASIS_POINT;
781780
}
782781

783782
// Fully coherent jurors won't be penalized.
784-
uint256 penalty = (round.pnkAtStakePerJuror * (ALPHA_DIVISOR - degreeOfCoherence)) / ALPHA_DIVISOR;
783+
uint256 penalty = (round.pnkAtStakePerJuror * (ONE_BASIS_POINT - degreeOfCoherence)) / ONE_BASIS_POINT;
785784

786785
// Unlock the PNKs affected by the penalty
787786
address account = round.drawnJurors[_params.repartition];
@@ -835,8 +834,8 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
835834
);
836835

837836
// Make sure the degree doesn't exceed 1, though it should be ensured by the dispute kit.
838-
if (degreeOfCoherence > ALPHA_DIVISOR) {
839-
degreeOfCoherence = ALPHA_DIVISOR;
837+
if (degreeOfCoherence > ONE_BASIS_POINT) {
838+
degreeOfCoherence = ONE_BASIS_POINT;
840839
}
841840

842841
address account = round.drawnJurors[_params.repartition % _params.numberOfVotesInRound];
@@ -1062,15 +1061,15 @@ abstract contract KlerosCoreBase is IArbitratorV2, Initializable, UUPSProxiable
10621061
/// @param _degreeOfCoherence The degree of coherence in basis points.
10631062
/// @return The amount after applying the degree of coherence.
10641063
function _applyCoherence(uint256 _amount, uint256 _degreeOfCoherence) internal pure returns (uint256) {
1065-
return (_amount * _degreeOfCoherence) / ALPHA_DIVISOR;
1064+
return (_amount * _degreeOfCoherence) / ONE_BASIS_POINT;
10661065
}
10671066

10681067
/// @dev Calculates PNK at stake per juror based on court parameters
10691068
/// @param _minStake The minimum stake for the court.
10701069
/// @param _alpha The alpha parameter for the court in basis points.
10711070
/// @return The amount of PNK at stake per juror.
10721071
function _calculatePnkAtStake(uint256 _minStake, uint256 _alpha) internal pure returns (uint256) {
1073-
return (_minStake * _alpha) / ALPHA_DIVISOR;
1072+
return (_minStake * _alpha) / ONE_BASIS_POINT;
10741073
}
10751074

10761075
/// @dev Toggles the dispute kit support for a given court.

contracts/src/arbitration/dispute-kits/DisputeKitClassicBase.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {KlerosCore, KlerosCoreBase, IDisputeKit, ISortitionModule} from "../Kler
66
import {Initializable} from "../../proxy/Initializable.sol";
77
import {UUPSProxiable} from "../../proxy/UUPSProxiable.sol";
88
import {SafeSend} from "../../libraries/SafeSend.sol";
9+
import {ONE_BASIS_POINT} from "../../libraries/Constants.sol";
910

1011
/// @title DisputeKitClassicBase
1112
/// Abstract Dispute kit classic implementation of the Kleros v1 features including:
@@ -57,7 +58,6 @@ abstract contract DisputeKitClassicBase is IDisputeKit, Initializable, UUPSProxi
5758
uint256 public constant WINNER_STAKE_MULTIPLIER = 10000; // Multiplier of the appeal cost that the winner has to pay as fee stake for a round in basis points. Default is 1x of appeal fee.
5859
uint256 public constant LOSER_STAKE_MULTIPLIER = 20000; // Multiplier of the appeal cost that the loser has to pay as fee stake for a round in basis points. Default is 2x of appeal fee.
5960
uint256 public constant LOSER_APPEAL_PERIOD_MULTIPLIER = 5000; // Multiplier of the appeal period for the choice that wasn't voted for in the previous round, in basis points. Default is 1/2 of original appeal period.
60-
uint256 public constant ONE_BASIS_POINT = 10000; // One basis point, for scaling.
6161

6262
address public governor; // The governor of the contract.
6363
KlerosCore public core; // The Kleros Core arbitrator

contracts/src/libraries/Constants.sol

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ uint256 constant DEFAULT_K = 6; // Default number of children per node.
2020
uint256 constant DEFAULT_NB_OF_JURORS = 3; // The default number of jurors in a dispute.
2121
IERC20 constant NATIVE_CURRENCY = IERC20(address(0)); // The native currency, such as ETH on Arbitrum, Optimism and Ethereum L1.
2222

23+
// Units
24+
uint256 constant ONE_BASIS_POINT = 10000;
25+
2326
enum OnError {
2427
Revert,
2528
Return

0 commit comments

Comments
 (0)