Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[OZ][N-02] Functions Are Updating the State Without Event Emissions #114

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions contracts/sfc/ConstantsManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ contract ConstantsManager is OwnableUpgradeable {
// Zero to disable validators deactivation by this metric.
uint64 public minAverageUptime;

event MinSelfStakeUpdated(uint256 v);
event MaxDelegatedRatioUpdated(uint256 v);
event ValidatorCommissionUpdated(uint256 v);
event BurntFeeShareUpdated(uint256 v);
event TreasuryFeeShareUpdated(uint256 v);
event WithdrawalPeriodEpochsUpdated(uint256 v);
event WithdrawalPeriodTimeUpdated(uint256 v);
event BaseRewardPerSecondUpdated(uint256 v);
event OfflinePenaltyThresholdBlocksNumUpdated(uint256 v);
event OfflinePenaltyThresholdTimeUpdated(uint256 v);
event TargetGasPowerPerSecondUpdated(uint256 v);
event GasPriceBalancingCounterweightUpdated(uint256 v);
event AverageUptimeEpochWindowUpdated(uint32 v);
event MinAverageUptimeUpdated(uint64 v);

/**
* @dev Given value is too small
*/
Expand All @@ -59,6 +74,7 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
minSelfStake = v;
emit MinSelfStakeUpdated(v);
}

function updateMaxDelegatedRatio(uint256 v) external virtual onlyOwner {
Expand All @@ -69,27 +85,31 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
maxDelegatedRatio = v;
emit MaxDelegatedRatioUpdated(v);
}

function updateValidatorCommission(uint256 v) external virtual onlyOwner {
if (v > Decimal.unit() / 2) {
revert ValueTooLarge();
}
validatorCommission = v;
emit ValidatorCommissionUpdated(v);
}

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

function updateTreasuryFeeShare(uint256 v) external virtual onlyOwner {
if (v > Decimal.unit() / 2) {
revert ValueTooLarge();
}
treasuryFeeShare = v;
emit TreasuryFeeShareUpdated(v);
}

function updateWithdrawalPeriodEpochs(uint256 v) external virtual onlyOwner {
Expand All @@ -100,6 +120,7 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
withdrawalPeriodEpochs = v;
emit WithdrawalPeriodEpochsUpdated(v);
}

function updateWithdrawalPeriodTime(uint256 v) external virtual onlyOwner {
Expand All @@ -110,6 +131,7 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
withdrawalPeriodTime = v;
emit WithdrawalPeriodTimeUpdated(v);
}

function updateBaseRewardPerSecond(uint256 v) external virtual onlyOwner {
Expand All @@ -120,6 +142,7 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
baseRewardPerSecond = v;
emit BaseRewardPerSecondUpdated(v);
}

function updateOfflinePenaltyThresholdTime(uint256 v) external virtual onlyOwner {
Expand All @@ -130,6 +153,7 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
offlinePenaltyThresholdTime = v;
emit OfflinePenaltyThresholdTimeUpdated(v);
}

function updateOfflinePenaltyThresholdBlocksNum(uint256 v) external virtual onlyOwner {
Expand All @@ -140,6 +164,7 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
offlinePenaltyThresholdBlocksNum = v;
emit OfflinePenaltyThresholdBlocksNumUpdated(v);
}

function updateTargetGasPowerPerSecond(uint256 v) external virtual onlyOwner {
Expand All @@ -150,6 +175,7 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
targetGasPowerPerSecond = v;
emit TargetGasPowerPerSecondUpdated(v);
}

function updateGasPriceBalancingCounterweight(uint256 v) external virtual onlyOwner {
Expand All @@ -160,6 +186,7 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
gasPriceBalancingCounterweight = v;
emit GasPriceBalancingCounterweightUpdated(v);
}

function updateAverageUptimeEpochWindow(uint32 v) external virtual onlyOwner {
Expand All @@ -171,12 +198,14 @@ contract ConstantsManager is OwnableUpgradeable {
revert ValueTooLarge();
}
averageUptimeEpochWindow = v;
emit AverageUptimeEpochWindowUpdated(v);
}

function updateMinAverageUptime(uint64 v) external virtual onlyOwner {
if (v > ((Decimal.unit() * 9) / 10)) {
revert ValueTooLarge();
}
minAverageUptime = v;
emit MinAverageUptimeUpdated(v);
}
}
33 changes: 33 additions & 0 deletions contracts/sfc/SFC.sol
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,25 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
event ClaimedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards);
event RestakedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards);
event BurntFTM(uint256 amount);
event MintedNativeToken(uint256 amount);
event UpdatedSlashingRefundRatio(uint256 indexed validatorID, uint256 refundRatio);
event RefundedSlashedLegacyDelegation(address indexed delegator, uint256 indexed validatorID, uint256 amount);
event AnnouncedRedirection(address indexed from, address indexed to);
event RedirectionAuthorizerUpdated(address addr);
event RedirectionInitiated(address indexed from, address indexed to);
event RedirectedTo(address indexed from, address indexed to);
event ConstantsManagerUpdated(address addr);
event TreasuryAddressUpdated(address addr);
event StakeSubscriberUpdated(address addr);

event SealedEpoch(
uint256 indexed epoch,
uint256 endTime,
uint256 endBlock,
uint256 baseRewardPerSecond,
uint256 totalSupply
);
event SealedEpochValidators(uint256 indexed epoch, uint256 totalStake, uint256[] validatorIDs);

modifier onlyDriver() {
if (!isNode(msg.sender)) {
Expand Down Expand Up @@ -248,6 +264,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
revert SameRedirectionAuthorizer();
}
redirectionAuthorizer = v;
emit RedirectionAuthorizerUpdated(v);
}

/// Announce redirection of address to be called by validator whose auth key was compromised.
Expand All @@ -270,6 +287,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
revert SameAddress();
}
getRedirectionRequest[from] = to;
emit RedirectionInitiated(from, to);
}

/// Accept redirection proposal.
Expand All @@ -284,6 +302,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
}
getRedirection[from] = to;
getRedirectionRequest[from] = address(0);
emit RedirectedTo(from, to);
}

/// Seal current epoch - deactivate validators who were offline too long, create an epoch snapshot
Expand Down Expand Up @@ -314,6 +333,14 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
snapshot.endBlock = block.number;
snapshot.baseRewardPerSecond = c.baseRewardPerSecond();
snapshot.totalSupply = totalSupply;

emit SealedEpoch(
currentSealedEpoch,
snapshot.endTime,
snapshot.endBlock,
snapshot.baseRewardPerSecond,
snapshot.totalSupply
);
}

/// Finish epoch sealing - store validators of the new epoch into a snapshot.
Expand All @@ -328,6 +355,8 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
snapshot.totalStake = snapshot.totalStake + receivedStake;
}
snapshot.validatorIDs = nextValidatorIDs;

emit SealedEpochValidators(currentEpoch(), snapshot.totalStake, snapshot.validatorIDs);
}

/// Set an initial validator.
Expand Down Expand Up @@ -427,16 +456,19 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
/// Update treasury address.
function updateTreasuryAddress(address v) external onlyOwner {
treasuryAddress = v;
emit TreasuryAddressUpdated(v);
}

/// Update consts address.
function updateConstsAddress(address v) external onlyOwner {
c = ConstantsManager(v);
emit ConstantsManagerUpdated(v);
}

/// Update voteBook address.
function updateStakeSubscriberAddress(address v) external onlyOwner {
stakeSubscriberAddress = v;
emit StakeSubscriberUpdated(v);
}

/// Get consts address.
Expand Down Expand Up @@ -1043,6 +1075,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version {
// balance will be increased after the transaction is processed
node.incBalance(address(this), amount);
totalSupply = totalSupply + amount;
emit MintedNativeToken(amount);
}

/// Notify stake subscriber about staking changes.
Expand Down
Loading