Skip to content

Commit

Permalink
Add custom errors for ConstantsManager (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Mike-CZ authored Oct 22, 2024
1 parent 78101a8 commit 7be31ee
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 30 deletions.
122 changes: 93 additions & 29 deletions contracts/sfc/ConstantsManager.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

import "../ownership/Ownable.sol";
import "../common/Decimal.sol";
import {Ownable} from "../ownership/Ownable.sol";
import {Decimal} from "../common/Decimal.sol";

contract ConstantsManager is Ownable {
// Minimum amount of stake for a validator, i.e., 500000 FTM
Expand Down Expand Up @@ -32,94 +32,158 @@ contract ConstantsManager is Ownable {
uint256 public targetGasPowerPerSecond;
uint256 public gasPriceBalancingCounterweight;

/**
* @dev Given value is too small
*/
error ValueTooSmall();

/**
* @dev Given value is too large
*/
error ValueTooLarge();

function initialize() external initializer {
Ownable.initialize(msg.sender);
}

function updateMinSelfStake(uint256 v) external virtual onlyOwner {
require(v >= 100000 * 1e18, "too small value");
require(v <= 10000000 * 1e18, "too large value");
if (v < 100000 * 1e18) {
revert ValueTooSmall();
}
if (v > 10000000 * 1e18) {
revert ValueTooLarge();
}
minSelfStake = v;
}

function updateMaxDelegatedRatio(uint256 v) external virtual onlyOwner {
require(v >= Decimal.unit(), "too small value");
require(v <= 31 * Decimal.unit(), "too large value");
if (v < Decimal.unit()) {
revert ValueTooSmall();
}
if (v > 31 * Decimal.unit()) {
revert ValueTooLarge();
}
maxDelegatedRatio = v;
}

function updateValidatorCommission(uint256 v) external virtual onlyOwner {
require(v <= Decimal.unit() / 2, "too large value");
if (v > Decimal.unit() / 2) {
revert ValueTooLarge();
}
validatorCommission = v;
}

function updateBurntFeeShare(uint256 v) external virtual onlyOwner {
require(v <= Decimal.unit() / 2, "too large value");
if (v > Decimal.unit() / 2) {
revert ValueTooLarge();
}
burntFeeShare = v;
}

function updateTreasuryFeeShare(uint256 v) external virtual onlyOwner {
require(v <= Decimal.unit() / 2, "too large value");
if (v > Decimal.unit() / 2) {
revert ValueTooLarge();
}
treasuryFeeShare = v;
}

function updateUnlockedRewardRatio(uint256 v) external virtual onlyOwner {
require(v >= (5 * Decimal.unit()) / 100, "too small value");
require(v <= Decimal.unit() / 2, "too large value");
if (v < (5 * Decimal.unit()) / 100) {
revert ValueTooSmall();
}
if (v > Decimal.unit() / 2) {
revert ValueTooLarge();
}
unlockedRewardRatio = v;
}

function updateMinLockupDuration(uint256 v) external virtual onlyOwner {
require(v >= 86400, "too small value");
require(v <= 86400 * 30, "too large value");
if (v < 86400) {
revert ValueTooSmall();
}
if (v > 86400 * 30) {
revert ValueTooLarge();
}
minLockupDuration = v;
}

function updateMaxLockupDuration(uint256 v) external virtual onlyOwner {
require(v >= 86400 * 30, "too small value");
require(v <= 86400 * 1460, "too large value");
if (v < 86400 * 30) {
revert ValueTooSmall();
}
if (v > 86400 * 1460) {
revert ValueTooLarge();
}
maxLockupDuration = v;
}

function updateWithdrawalPeriodEpochs(uint256 v) external virtual onlyOwner {
require(v >= 2, "too small value");
require(v <= 100, "too large value");
if (v < 2) {
revert ValueTooSmall();
}
if (v > 100) {
revert ValueTooLarge();
}
withdrawalPeriodEpochs = v;
}

function updateWithdrawalPeriodTime(uint256 v) external virtual onlyOwner {
require(v >= 86400, "too small value");
require(v <= 30 * 86400, "too large value");
if (v < 86400) {
revert ValueTooSmall();
}
if (v > 30 * 86400) {
revert ValueTooLarge();
}
withdrawalPeriodTime = v;
}

function updateBaseRewardPerSecond(uint256 v) external virtual onlyOwner {
require(v >= 0.5 * 1e18, "too small value");
require(v <= 32 * 1e18, "too large value");
if (v < 0.5 * 1e18) {
revert ValueTooSmall();
}
if (v > 32 * 1e18) {
revert ValueTooLarge();
}
baseRewardPerSecond = v;
}

function updateOfflinePenaltyThresholdTime(uint256 v) external virtual onlyOwner {
require(v >= 86400, "too small value");
require(v <= 10 * 86400, "too large value");
if (v < 86400) {
revert ValueTooSmall();
}
if (v > 10 * 86400) {
revert ValueTooLarge();
}
offlinePenaltyThresholdTime = v;
}

function updateOfflinePenaltyThresholdBlocksNum(uint256 v) external virtual onlyOwner {
require(v >= 100, "too small value");
require(v <= 1000000, "too large value");
if (v < 100) {
revert ValueTooSmall();
}
if (v > 1000000) {
revert ValueTooLarge();
}
offlinePenaltyThresholdBlocksNum = v;
}

function updateTargetGasPowerPerSecond(uint256 v) external virtual onlyOwner {
require(v >= 1000000, "too small value");
require(v <= 500000000, "too large value");
if (v < 1000000) {
revert ValueTooSmall();
}
if (v > 500000000) {
revert ValueTooLarge();
}
targetGasPowerPerSecond = v;
}

function updateGasPriceBalancingCounterweight(uint256 v) external virtual onlyOwner {
require(v >= 100, "too small value");
require(v <= 10 * 86400, "too large value");
if (v < 100) {
revert ValueTooSmall();
}
if (v > 10 * 86400) {
revert ValueTooLarge();
}
gasPriceBalancingCounterweight = v;
}
}
2 changes: 1 addition & 1 deletion contracts/sfc/GasPriceConstants.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.9;

import "../common/Decimal.sol";
import {Decimal} from "../common/Decimal.sol";

library GP {
function trimGasPriceChangeRatio(uint256 x) internal pure returns (uint256) {
Expand Down

0 comments on commit 7be31ee

Please sign in to comment.