Skip to content

Commit 0623a47

Browse files
authored
add payable to fee accumulator (#2053)
* add payable to fee accumulator * remove zero initializers * some gas savings
1 parent 2f7a9cd commit 0623a47

File tree

11 files changed

+250
-77
lines changed

11 files changed

+250
-77
lines changed

contracts/contracts/strategies/NativeStaking/FeeAccumulator.sol

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,9 @@ contract FeeAccumulator is Governable {
3636
Address.sendValue(payable(STRATEGY), eth);
3737
}
3838
}
39+
40+
/**
41+
* @dev Accept ETH
42+
*/
43+
receive() external payable {}
3944
}

contracts/contracts/strategies/NativeStaking/NativeStakingSSVStrategy.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ contract NativeStakingSSVStrategy is
3131
/// executing transactions on the Ethereum network as part of block proposals. They include
3232
/// priority fees (fees paid by users for their transactions to be included) and MEV rewards
3333
/// (rewards for arranging transactions in a way that benefits the validator).
34-
address public immutable FEE_ACCUMULATOR_ADDRESS;
34+
address payable public immutable FEE_ACCUMULATOR_ADDRESS;
3535

3636
// For future use
3737
uint256[50] private __gap;
@@ -60,7 +60,7 @@ contract NativeStakingSSVStrategy is
6060
)
6161
{
6262
SSV_TOKEN_ADDRESS = _ssvToken;
63-
FEE_ACCUMULATOR_ADDRESS = _feeAccumulator;
63+
FEE_ACCUMULATOR_ADDRESS = payable(_feeAccumulator);
6464
}
6565

6666
/// @notice initialize function, to set up initial internal state

contracts/contracts/strategies/NativeStaking/ValidatorAccountant.sol

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
1515
uint256 public constant MAX_STAKE = 32 ether;
1616

1717
/// @notice Keeps track of the total consensus rewards swept from the beacon chain
18-
uint256 public consensusRewards = 0;
18+
uint256 public consensusRewards;
1919

2020
/// @notice start of fuse interval
21-
uint256 public fuseIntervalStart = 0;
21+
uint256 public fuseIntervalStart;
2222
/// @notice end of fuse interval
23-
uint256 public fuseIntervalEnd = 0;
23+
uint256 public fuseIntervalEnd;
2424

2525
uint256[50] private __gap;
2626

contracts/contracts/strategies/NativeStaking/ValidatorRegistrator.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,9 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
114114
// Convert required ETH from WETH
115115
IWETH9(WETH_TOKEN_ADDRESS).withdraw(requiredETH);
116116

117+
uint256 validatorsLength = validators.length;
117118
// For each validator
118-
for (uint256 i = 0; i < validators.length; ) {
119+
for (uint256 i = 0; i < validatorsLength; ) {
119120
bytes32 pubkeyHash = keccak256(validators[i].pubkey);
120121
VALIDATOR_STATE currentState = validatorsStates[pubkeyHash];
121122

@@ -143,7 +144,6 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
143144
validators[i].depositDataRoot
144145
);
145146

146-
activeDepositedValidators += 1;
147147
emit ETHStaked(
148148
validators[i].pubkey,
149149
32 ether,
@@ -156,6 +156,8 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
156156
++i;
157157
}
158158
}
159+
// save gas by changing this storage variable only once rather each time in the loop.
160+
activeDepositedValidators += validatorsLength;
159161
}
160162

161163
/// @notice Registers a new validator in the SSV Cluster.

contracts/deploy/deployActions.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -807,6 +807,32 @@ const deployFraxEthStrategy = async () => {
807807
return cFraxETHStrategy;
808808
};
809809

810+
/**
811+
* upgradeNativeStakingFeeAccumulator
812+
*/
813+
const upgradeNativeStakingFeeAccumulator = async () => {
814+
const { deployerAddr } = await getNamedAccounts();
815+
const sDeployer = await ethers.provider.getSigner(deployerAddr);
816+
817+
const strategyProxy = await ethers.getContract(
818+
"NativeStakingSSVStrategyProxy"
819+
);
820+
const feeAccumulatorProxy = await ethers.getContract(
821+
"NativeStakingFeeAccumulatorProxy"
822+
);
823+
824+
log("Deploy fee accumulator implementation");
825+
const dFeeAccumulatorImpl = await deployWithConfirmation("FeeAccumulator", [
826+
strategyProxy.address, // STRATEGY
827+
]);
828+
829+
await withConfirmation(
830+
feeAccumulatorProxy
831+
.connect(sDeployer)
832+
.upgradeTo(dFeeAccumulatorImpl.address)
833+
);
834+
};
835+
810836
/**
811837
* Upgrade NativeStakingSSVStrategy
812838
*/
@@ -1538,4 +1564,5 @@ module.exports = {
15381564
deployOETHSwapper,
15391565
deployOUSDSwapper,
15401566
upgradeNativeStakingSSVStrategy,
1567+
upgradeNativeStakingFeeAccumulator,
15411568
};
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const {
2+
upgradeNativeStakingSSVStrategy,
3+
upgradeNativeStakingFeeAccumulator,
4+
} = require("../deployActions");
5+
const { withConfirmation } = require("../../utils/deploy");
6+
7+
const mainExport = async () => {
8+
console.log("Running 007 deployment on Holesky...");
9+
10+
console.log("Upgrading native staking fee accumulator");
11+
await upgradeNativeStakingFeeAccumulator();
12+
13+
console.log("Upgrading native staking strategy");
14+
await upgradeNativeStakingSSVStrategy();
15+
16+
console.log("Running 007 deployment done");
17+
return true;
18+
};
19+
20+
mainExport.id = "007_upgrade_strategy";
21+
mainExport.tags = [];
22+
mainExport.dependencies = [];
23+
mainExport.skip = () => false;
24+
25+
module.exports = mainExport;

contracts/deployments/holesky/.migrations.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
"003_deposit_to_native_strategy": 1714307581,
55
"004_upgrade_strategy": 1714944723,
66
"005_deploy_new_harvester": 1714998707,
7-
"006_update_registrator": 1715184342
7+
"006_update_registrator": 1715184342,
8+
"007_upgrade_strategy": 1715251466
89
}

contracts/deployments/holesky/FeeAccumulator.json

Lines changed: 25 additions & 21 deletions
Large diffs are not rendered by default.

contracts/deployments/holesky/NativeStakingSSVStrategy.json

Lines changed: 47 additions & 47 deletions
Large diffs are not rendered by default.

contracts/deployments/holesky/solcInputs/94a4e2017aae119860e82f5bc90e390d.json

Lines changed: 104 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)