Skip to content

Commit

Permalink
Merge branch 'main' into mike/oz-n-11
Browse files Browse the repository at this point in the history
# Conflicts:
#	contracts/sfc/ConstantsManager.sol
  • Loading branch information
Mike-CZ committed Jan 31, 2025
2 parents cba9a84 + 23beff7 commit d6467ca
Show file tree
Hide file tree
Showing 7 changed files with 350 additions and 49 deletions.
31 changes: 3 additions & 28 deletions contracts/sfc/ConstantsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ contract ConstantsManager is Ownable {
uint256 public baseRewardPerSecond;
uint256 public offlinePenaltyThresholdBlocksNum;
uint256 public offlinePenaltyThresholdTime;
uint256 public targetGasPowerPerSecond;
uint256 public gasPriceBalancingCounterweight;

// The number of epochs to calculate the average uptime ratio from, acceptable bound [10, 87600].
// Is also the minimum number of epochs necessary for deactivation of offline validators.
Expand Down Expand Up @@ -81,14 +79,14 @@ contract ConstantsManager is Ownable {
}

function updateBurntFeeShare(uint256 v) external onlyOwner {
if (v > Decimal.unit() / 2) {
if (v + treasuryFeeShare > Decimal.unit()) {
revert ValueTooLarge();
}
burntFeeShare = v;
}

function updateTreasuryFeeShare(uint256 v) external onlyOwner {
if (v > Decimal.unit() / 2) {
if (v + burntFeeShare > Decimal.unit()) {
revert ValueTooLarge();
}
treasuryFeeShare = v;
Expand All @@ -115,9 +113,6 @@ contract ConstantsManager is Ownable {
}

function updateBaseRewardPerSecond(uint256 v) external virtual onlyOwner {
if (v < Decimal.unit() / 2) {
revert ValueTooSmall();
}
if (v > 32 * Decimal.unit()) {
revert ValueTooLarge();
}
Expand All @@ -144,27 +139,7 @@ contract ConstantsManager is Ownable {
offlinePenaltyThresholdBlocksNum = v;
}

function updateTargetGasPowerPerSecond(uint256 v) external virtual onlyOwner {
if (v < 1000000) {
revert ValueTooSmall();
}
if (v > 500000000) {
revert ValueTooLarge();
}
targetGasPowerPerSecond = v;
}

function updateGasPriceBalancingCounterweight(uint256 v) external virtual onlyOwner {
if (v < 100) {
revert ValueTooSmall();
}
if (v > 10 * 86400) {
revert ValueTooLarge();
}
gasPriceBalancingCounterweight = v;
}

function updateAverageUptimeEpochWindow(uint32 v) external onlyOwner {
function updateAverageUptimeEpochWindow(uint32 v) external virtual onlyOwner {
if (v < 10) {
// needs to be long enough to allow permissible downtime for validators maintenance
revert ValueTooSmall();
Expand Down
12 changes: 5 additions & 7 deletions contracts/sfc/NetworkInitializer.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,16 @@ contract NetworkInitializer {
NodeDriverAuth(_auth).initialize(_sfc, _driver, _owner);

ConstantsManager consts = new ConstantsManager(address(this));
consts.updateMinSelfStake(500000 * Decimal.unit());
consts.updateMinSelfStake(500_000 * Decimal.unit());
consts.updateMaxDelegatedRatio(16 * Decimal.unit());
consts.updateValidatorCommission((15 * Decimal.unit()) / 100);
consts.updateBurntFeeShare((20 * Decimal.unit()) / 100);
consts.updateTreasuryFeeShare((10 * Decimal.unit()) / 100);
consts.updateBurntFeeShare(0);
consts.updateTreasuryFeeShare((90 * Decimal.unit()) / 100);
consts.updateWithdrawalPeriodEpochs(3);
consts.updateWithdrawalPeriodTime(60 * 60 * 24 * 7);
consts.updateBaseRewardPerSecond(2668658453701531600);
consts.updateBaseRewardPerSecond(1_000);
consts.updateOfflinePenaltyThresholdTime(5 days);
consts.updateOfflinePenaltyThresholdBlocksNum(1000);
consts.updateTargetGasPowerPerSecond(2000000);
consts.updateGasPriceBalancingCounterweight(3600);
consts.updateOfflinePenaltyThresholdBlocksNum(1_000);
consts.updateAverageUptimeEpochWindow(100);
consts.updateMinAverageUptime(0); // check disabled by default
consts.transferOwnership(_owner);
Expand Down
2 changes: 1 addition & 1 deletion contracts/sfc/NodeDriverAuth.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ contract NodeDriverAuth is OwnableUpgradeable, UUPSUpgradeable {

/// Mint native token. To be used by SFC for minting validators rewards.
function incBalance(address acc, uint256 diff) external onlySFC {
driver.setBalance(acc, address(acc).balance + diff);
driver.setBalance(acc, acc.balance + diff);
}

/// Upgrade code of given contract by copying it from other deployed contract.
Expand Down
9 changes: 6 additions & 3 deletions contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -830,7 +830,10 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
revert ValueTooLarge();
}
totalSupply -= amount;
payable(address(0)).transfer(amount);
(bool sent, ) = payable(address(0)).call{value: amount}("");
if (!sent) {
revert TransferFailed();
}
emit BurntNativeTokens(amount);
}
}
Expand All @@ -840,9 +843,9 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
function _receiverOf(address addr) internal view returns (address payable) {
address to = getRedirection[addr];
if (to == address(0)) {
return payable(address(uint160(addr)));
return payable(addr);
}
return payable(address(uint160(to)));
return payable(to);
}

/// Seal epoch - sync validators.
Expand Down
8 changes: 0 additions & 8 deletions contracts/test/UnitTestConstantsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,7 @@ contract UnitTestConstantsManager is ConstantsManager {
baseRewardPerSecond = v;
}

function updateGasPriceBalancingCounterweight(uint256 v) external override onlyOwner {
gasPriceBalancingCounterweight = v;
}

function updateOfflinePenaltyThresholdTime(uint256 v) external override onlyOwner {
offlinePenaltyThresholdTime = v;
}

function updateTargetGasPowerPerSecond(uint256 v) external override onlyOwner {
targetGasPowerPerSecond = v;
}
}
2 changes: 0 additions & 2 deletions contracts/test/UnitTestSFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ contract UnitTestNetworkInitializer {
consts.updateBaseRewardPerSecond(6183414351851851852);
consts.updateOfflinePenaltyThresholdTime(3 days);
consts.updateOfflinePenaltyThresholdBlocksNum(1000);
consts.updateTargetGasPowerPerSecond(2000000);
consts.updateGasPriceBalancingCounterweight(6 * 60 * 60);
consts.updateAverageUptimeEpochWindow(10);
consts.updateMinAverageUptime(0); // check disabled by default
consts.transferOwnership(_owner);
Expand Down
Loading

0 comments on commit d6467ca

Please sign in to comment.