From 268e7169ca50a2994b0af0148c7864c51389f6c3 Mon Sep 17 00:00:00 2001 From: mike Date: Fri, 13 Dec 2024 11:45:53 +0100 Subject: [PATCH] Add event emissions --- contracts/sfc/ConstantsManager.sol | 29 ++++++++++++++++++++++++++ contracts/sfc/SFC.sol | 33 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/contracts/sfc/ConstantsManager.sol b/contracts/sfc/ConstantsManager.sol index 1c41030..91fe2b9 100644 --- a/contracts/sfc/ConstantsManager.sol +++ b/contracts/sfc/ConstantsManager.sol @@ -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 */ @@ -59,6 +74,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } minSelfStake = v; + emit MinSelfStakeUpdated(v); } function updateMaxDelegatedRatio(uint256 v) external virtual onlyOwner { @@ -69,6 +85,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } maxDelegatedRatio = v; + emit MaxDelegatedRatioUpdated(v); } function updateValidatorCommission(uint256 v) external virtual onlyOwner { @@ -76,6 +93,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } validatorCommission = v; + emit ValidatorCommissionUpdated(v); } function updateBurntFeeShare(uint256 v) external virtual onlyOwner { @@ -83,6 +101,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } burntFeeShare = v; + emit BurntFeeShareUpdated(v); } function updateTreasuryFeeShare(uint256 v) external virtual onlyOwner { @@ -90,6 +109,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } treasuryFeeShare = v; + emit TreasuryFeeShareUpdated(v); } function updateWithdrawalPeriodEpochs(uint256 v) external virtual onlyOwner { @@ -100,6 +120,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } withdrawalPeriodEpochs = v; + emit WithdrawalPeriodEpochsUpdated(v); } function updateWithdrawalPeriodTime(uint256 v) external virtual onlyOwner { @@ -110,6 +131,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } withdrawalPeriodTime = v; + emit WithdrawalPeriodTimeUpdated(v); } function updateBaseRewardPerSecond(uint256 v) external virtual onlyOwner { @@ -120,6 +142,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } baseRewardPerSecond = v; + emit BaseRewardPerSecondUpdated(v); } function updateOfflinePenaltyThresholdTime(uint256 v) external virtual onlyOwner { @@ -130,6 +153,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } offlinePenaltyThresholdTime = v; + emit OfflinePenaltyThresholdTimeUpdated(v); } function updateOfflinePenaltyThresholdBlocksNum(uint256 v) external virtual onlyOwner { @@ -140,6 +164,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } offlinePenaltyThresholdBlocksNum = v; + emit OfflinePenaltyThresholdBlocksNumUpdated(v); } function updateTargetGasPowerPerSecond(uint256 v) external virtual onlyOwner { @@ -150,6 +175,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } targetGasPowerPerSecond = v; + emit TargetGasPowerPerSecondUpdated(v); } function updateGasPriceBalancingCounterweight(uint256 v) external virtual onlyOwner { @@ -160,6 +186,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } gasPriceBalancingCounterweight = v; + emit GasPriceBalancingCounterweightUpdated(v); } function updateAverageUptimeEpochWindow(uint32 v) external virtual onlyOwner { @@ -171,6 +198,7 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } averageUptimeEpochWindow = v; + emit AverageUptimeEpochWindowUpdated(v); } function updateMinAverageUptime(uint64 v) external virtual onlyOwner { @@ -178,5 +206,6 @@ contract ConstantsManager is OwnableUpgradeable { revert ValueTooLarge(); } minAverageUptime = v; + emit MinAverageUptimeUpdated(v); } } diff --git a/contracts/sfc/SFC.sol b/contracts/sfc/SFC.sol index 5b97ec3..cf8f670 100644 --- a/contracts/sfc/SFC.sol +++ b/contracts/sfc/SFC.sol @@ -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)) { @@ -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. @@ -270,6 +287,7 @@ contract SFC is OwnableUpgradeable, UUPSUpgradeable, Version { revert SameAddress(); } getRedirectionRequest[from] = to; + emit RedirectionInitiated(from, to); } /// Accept redirection proposal. @@ -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 @@ -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. @@ -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. @@ -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. @@ -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.