Skip to content

Commit

Permalink
Remove magic number
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvol committed Sep 24, 2024
1 parent 0d887c3 commit c3f3214
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions packages/protocol/contracts-0.8/common/ScoreManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ contract ScoreManager is Initializable, Ownable {
event GroupScoreSet(address indexed group, uint256 score);
event ValidatorScoreSet(address indexed validator, uint256 score);

uint256 private constant FIXED1_UINT = 1e24;

mapping(address => Score) public groupScores;
mapping(address => Score) public validatorScores;

Expand All @@ -31,7 +33,7 @@ contract ScoreManager is Initializable, Ownable {
}

function setGroupScore(address group, uint256 score) external onlyOwner {
require(score <= 1e24, "Score must be less than or equal to 1e24.");
require(score <= FIXED1_UINT, "Score must be less than or equal to 1e24.");
Score storage groupScore = groupScores[group];
if (!groupScore.exists) {
groupScore.exists = true;
Expand All @@ -42,7 +44,7 @@ contract ScoreManager is Initializable, Ownable {
}

function setValidatorScore(address validator, uint256 score) external onlyOwner {
require(score <= 1e24, "Score must be less than or equal to 1e24.");
require(score <= FIXED1_UINT, "Score must be less than or equal to 1e24.");
Score storage validatorScore = validatorScores[validator];
if (!validatorScore.exists) {
validatorScore.exists = true;
Expand All @@ -55,15 +57,15 @@ contract ScoreManager is Initializable, Ownable {
function getGroupScore(address group) external view returns (uint256) {
Score storage groupScore = groupScores[group];
if (!groupScore.exists) {
return 1e24;
return FIXED1_UINT;
}
return groupScore.score;
}

function getValidatorScore(address validator) external view returns (uint256) {
Score storage validatorScore = validatorScores[validator];
if (!validatorScore.exists) {
return 1e24;
return FIXED1_UINT;
}
return validatorScore.score;
}
Expand Down

0 comments on commit c3f3214

Please sign in to comment.