Skip to content

Commit 48b8ceb

Browse files
committed
Merge branch 'main' into mike/oz-n-11
# Conflicts: # contracts/sfc/SFC.sol # contracts/test/UnitTestSFC.sol
2 parents cf70ffc + 1d0a4e1 commit 48b8ceb

File tree

13 files changed

+326
-105
lines changed

13 files changed

+326
-105
lines changed

contracts/interfaces/ISFC.sol

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@ interface ISFC {
1515
);
1616
event Delegated(address indexed delegator, uint256 indexed toValidatorID, uint256 amount);
1717
event Undelegated(address indexed delegator, uint256 indexed toValidatorID, uint256 indexed wrID, uint256 amount);
18-
event Withdrawn(address indexed delegator, uint256 indexed toValidatorID, uint256 indexed wrID, uint256 amount);
18+
event Withdrawn(
19+
address indexed delegator,
20+
uint256 indexed toValidatorID,
21+
uint256 indexed wrID,
22+
uint256 amount,
23+
uint256 penalty
24+
);
1925
event ClaimedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards);
2026
event RestakedRewards(address indexed delegator, uint256 indexed toValidatorID, uint256 rewards);
2127
event BurntFTM(uint256 amount);
@@ -121,6 +127,8 @@ interface ISFC {
121127

122128
function getEpochEndBlock(uint256 epoch) external view returns (uint256);
123129

130+
function epochEndTime(uint256 epoch) external view returns (uint256);
131+
124132
function rewardsStash(address delegator, uint256 validatorID) external view returns (uint256);
125133

126134
function createValidator(bytes calldata pubkey) external payable;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// SPDX-License-Identifier: UNLICENSED
2+
pragma solidity 0.8.27;
3+
4+
/**
5+
* @title Stake Subscriber Interface
6+
* @notice Used to recount votes from delegators in the governance contract
7+
* @custom:security-contact [email protected]
8+
*/
9+
interface IStakeSubscriber {
10+
function announceStakeChange(address delegator, address validator) external;
11+
}

contracts/sfc/ConstantsManager.sol

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity 0.8.27;
33

4-
import {OwnableUpgradeable} from "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
4+
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
55
import {Decimal} from "../common/Decimal.sol";
66

77
/**
88
* @custom:security-contact [email protected]
99
*/
10-
contract ConstantsManager is OwnableUpgradeable {
10+
contract ConstantsManager is Ownable {
1111
// Minimum amount of stake for a validator, i.e., 500000 FTM
1212
uint256 public minSelfStake;
1313
// Maximum ratio of delegations a validator can have, say, 15 times of self-stake
@@ -37,6 +37,10 @@ contract ConstantsManager is OwnableUpgradeable {
3737
// Zero to disable validators deactivation by this metric.
3838
uint64 public minAverageUptime;
3939

40+
// The address of the recipient that receives issued tokens
41+
// as a counterparty to the burnt FTM tokens
42+
address public issuedTokensRecipient;
43+
4044
/**
4145
* @dev Given value is too small
4246
*/
@@ -47,15 +51,13 @@ contract ConstantsManager is OwnableUpgradeable {
4751
*/
4852
error ValueTooLarge();
4953

50-
constructor(address owner) initializer {
51-
__Ownable_init(owner);
52-
}
54+
constructor(address owner) Ownable(owner) {}
5355

5456
function updateMinSelfStake(uint256 v) external virtual onlyOwner {
55-
if (v < 100000 * 1e18) {
57+
if (v < 100000 * Decimal.unit()) {
5658
revert ValueTooSmall();
5759
}
58-
if (v > 10000000 * 1e18) {
60+
if (v > 10000000 * Decimal.unit()) {
5961
revert ValueTooLarge();
6062
}
6163
minSelfStake = v;
@@ -113,10 +115,10 @@ contract ConstantsManager is OwnableUpgradeable {
113115
}
114116

115117
function updateBaseRewardPerSecond(uint256 v) external virtual onlyOwner {
116-
if (v < 0.5 * 1e18) {
118+
if (v < Decimal.unit() / 2) {
117119
revert ValueTooSmall();
118120
}
119-
if (v > 32 * 1e18) {
121+
if (v > 32 * Decimal.unit()) {
120122
revert ValueTooLarge();
121123
}
122124
baseRewardPerSecond = v;
@@ -179,4 +181,8 @@ contract ConstantsManager is OwnableUpgradeable {
179181
}
180182
minAverageUptime = v;
181183
}
184+
185+
function updateIssuedTokensRecipient(address v) external virtual onlyOwner {
186+
issuedTokensRecipient = v;
187+
}
182188
}

contracts/sfc/NetworkInitializer.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ contract NetworkInitializer {
2525
NodeDriverAuth(_auth).initialize(_sfc, _driver, _owner);
2626

2727
ConstantsManager consts = new ConstantsManager(address(this));
28-
consts.updateMinSelfStake(500000 * 1e18);
28+
consts.updateMinSelfStake(500000 * Decimal.unit());
2929
consts.updateMaxDelegatedRatio(16 * Decimal.unit());
3030
consts.updateValidatorCommission((15 * Decimal.unit()) / 100);
3131
consts.updateBurntFeeShare((20 * Decimal.unit()) / 100);

contracts/sfc/NodeDriver.sol

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ contract NodeDriver is OwnableUpgradeable, UUPSUpgradeable, INodeDriver {
3535
event UpdateNetworkVersion(uint256 version);
3636
event AdvanceEpochs(uint256 num);
3737

38+
/// @custom:oz-upgrades-unsafe-allow constructor
39+
constructor() {
40+
_disableInitializers();
41+
}
42+
3843
/// Initialization is called only once, after the contract deployment.
3944
/// Because the contract code is written directly into genesis, constructor cannot be used.
4045
function initialize(address _backend, address _evmWriterAddress, address _owner) external initializer {
@@ -144,4 +149,6 @@ contract NodeDriver is OwnableUpgradeable, UUPSUpgradeable, INodeDriver {
144149
function sealEpochValidators(uint256[] calldata nextValidatorIDs) external onlyNode {
145150
backend.sealEpochValidators(nextValidatorIDs);
146151
}
152+
153+
uint256[50] private __gap;
147154
}

contracts/sfc/NodeDriverAuth.sol

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ contract NodeDriverAuth is OwnableUpgradeable, UUPSUpgradeable {
2121
error DriverCodeHashMismatch();
2222
error RecipientNotSFC();
2323

24+
/// @custom:oz-upgrades-unsafe-allow constructor
25+
constructor() {
26+
_disableInitializers();
27+
}
28+
2429
// Initialize NodeDriverAuth, NodeDriver and SFC in one call to allow fewer genesis transactions
2530
function initialize(address payable _sfc, address _driver, address _owner) external initializer {
2631
__Ownable_init(_owner);
@@ -53,7 +58,6 @@ contract NodeDriverAuth is OwnableUpgradeable, UUPSUpgradeable {
5358
_transferOwnership(executable);
5459
INodeDriverExecutable(executable).execute();
5560
_transferOwnership(newOwner);
56-
//require(driver.backend() == address(this), "ownership of driver is lost");
5761
if (_getCodeHash(address(this)) != selfCodeHash) {
5862
revert SelfCodeHashMismatch();
5963
}
@@ -63,7 +67,7 @@ contract NodeDriverAuth is OwnableUpgradeable, UUPSUpgradeable {
6367
}
6468

6569
/// Execute a batch update of network configuration.
66-
/// Run given contract with a permission of the NodeDriverAuth owner.
70+
/// The executable will run with the privileges of the NodeDriverAuth owner.
6771
/// Does not allow changing NodeDriver and NodeDriverAuth code.
6872
function execute(address executable) external onlyOwner {
6973
_execute(executable, owner(), _getCodeHash(address(this)), _getCodeHash(address(driver)));
@@ -83,13 +87,10 @@ contract NodeDriverAuth is OwnableUpgradeable, UUPSUpgradeable {
8387

8488
/// Mint native token. To be used by SFC for minting validators rewards.
8589
function incBalance(address acc, uint256 diff) external onlySFC {
86-
if (acc != address(sfc)) {
87-
revert RecipientNotSFC();
88-
}
8990
driver.setBalance(acc, address(acc).balance + diff);
9091
}
9192

92-
/// Upgrade code of given contract by coping it from other deployed contract.
93+
/// Upgrade code of given contract by copying it from other deployed contract.
9394
/// Avoids setting code to an external address.
9495
function upgradeCode(address acc, address from) external onlyOwner {
9596
if (!isContract(acc) || !isContract(from)) {
@@ -98,7 +99,7 @@ contract NodeDriverAuth is OwnableUpgradeable, UUPSUpgradeable {
9899
driver.copyCode(acc, from);
99100
}
100101

101-
/// Upgrade code of given contract by coping it from other deployed contract.
102+
/// Upgrade code of given contract by copying it from other deployed contract.
102103
/// Does not avoid setting code to an external address. (DANGEROUS!)
103104
function copyCode(address acc, address from) external onlyOwner {
104105
driver.copyCode(acc, from);
@@ -171,19 +172,12 @@ contract NodeDriverAuth is OwnableUpgradeable, UUPSUpgradeable {
171172
}
172173

173174
function isContract(address account) internal view returns (bool) {
174-
uint256 size;
175-
// solhint-disable-next-line no-inline-assembly
176-
assembly {
177-
size := extcodesize(account)
178-
}
179-
return size > 0;
175+
return account.code.length > 0;
180176
}
181177

182178
function _getCodeHash(address addr) internal view returns (bytes32) {
183-
bytes32 codeHash;
184-
assembly {
185-
codeHash := extcodehash(addr)
186-
}
187-
return codeHash;
179+
return addr.codehash;
188180
}
181+
182+
uint256[50] private __gap;
189183
}

0 commit comments

Comments
 (0)