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

Sparrow dom/validator simulator #2098

Open
wants to merge 147 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
063d8b2
initial commit of the native staking strategy
sparrowDom Apr 4, 2024
6e8332b
fix text
sparrowDom Apr 4, 2024
b933f22
add some more functionality
sparrowDom Apr 10, 2024
0a43d14
finish up the fuse interval test, update deploy script
sparrowDom Apr 11, 2024
d31fe30
some natspec and refactoring
sparrowDom Apr 11, 2024
03c544c
add some more accounting logic
sparrowDom Apr 11, 2024
9aa0d73
finish up accounting and add tests for it
sparrowDom Apr 12, 2024
e99f86c
add some comments
sparrowDom Apr 15, 2024
52ba11e
add tests for manually fixing accounting
sparrowDom Apr 15, 2024
e656ecb
lint and prettier
sparrowDom Apr 15, 2024
fe113a5
undo file delete
sparrowDom Apr 15, 2024
71ad71f
implement the collect rewards function and add tests for it
sparrowDom Apr 16, 2024
2c448bb
implement and test checkBalance
sparrowDom Apr 16, 2024
5d5e9cb
add functions to register and exit/remove the ssv validator
sparrowDom Apr 18, 2024
121c7f7
Native staking updates (#2023)
naddison36 Apr 22, 2024
8a64dc8
Native staking changes (#2024)
naddison36 Apr 23, 2024
8419fc7
Native staking changes and unit tests (#2029)
naddison36 Apr 25, 2024
87c5254
allow for WETH to send ETH to the contract
sparrowDom Apr 26, 2024
1d66508
shorten error message
sparrowDom Apr 26, 2024
00ec878
fix depositing bug
sparrowDom Apr 27, 2024
ec4933b
Holesky deploy (#2026)
sparrowDom Apr 29, 2024
6179cb1
manuallyFixAccounting changes (#2034)
naddison36 Apr 29, 2024
da6a7b5
fix fork tests
sparrowDom Apr 29, 2024
fd17ec9
Merge branch 'master' into sparrowDom/nativeStaking
sparrowDom May 6, 2024
8f7d3d5
prettier
sparrowDom May 6, 2024
967fe49
fix unit test
sparrowDom May 6, 2024
1af324d
mainnet native staking fork tests (#2037)
naddison36 May 7, 2024
ce2ec63
fix unit tests
sparrowDom May 6, 2024
fe12d23
fix global hooks filter
sparrowDom May 7, 2024
c61c9bb
add github workflow
sparrowDom May 7, 2024
7e2e640
another workflow fix
sparrowDom May 7, 2024
af8ea03
another workflow fix
sparrowDom May 7, 2024
32480dd
fix holesky tests
sparrowDom May 7, 2024
0fb09ea
remove the .only
sparrowDom May 7, 2024
c7175bb
prettier
sparrowDom May 7, 2024
69abd8f
Sparrow dom/native staking defender action (#2051)
sparrowDom May 9, 2024
2f7a9cd
Fix fork tests (#2050)
naddison36 May 9, 2024
0623a47
add payable to fee accumulator (#2053)
sparrowDom May 9, 2024
f268742
fix linter
naddison36 May 9, 2024
20d29a1
Fix balancer fork test
naddison36 May 10, 2024
2a93df2
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 10, 2024
b898801
Fixed resolveContract for none proxied contracts
naddison36 May 10, 2024
25170aa
simplified woethCcipZapperFixture
naddison36 May 10, 2024
e1ff728
Regenerated latest contract diagrams
naddison36 May 10, 2024
c09cd46
Resolved Slither divide-before-multiply warning
naddison36 May 10, 2024
9d83e97
Native staking deployment to reduceQueueTime
naddison36 May 10, 2024
7eb135b
Fixed fork test harvesting CRV rewards
naddison36 May 10, 2024
579a93c
gas optimisation
sparrowDom May 10, 2024
4c864ca
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 10, 2024
e7b96e9
make verification automatic
sparrowDom May 10, 2024
8a53f3e
removed wethToVault from manuallyFixAccounting
naddison36 May 10, 2024
98a193a
Merge remote-tracking branch 'origin/sparrowDom/nativeStaking' into s…
naddison36 May 10, 2024
905abf9
native staking strategy redeployed
sparrowDom May 10, 2024
fc48427
adjust the comment
sparrowDom May 10, 2024
4b51655
add rate limit to calling manually fix accounting (#2057)
sparrowDom May 13, 2024
657b064
Correct deployName in Native Staking deploy script
naddison36 May 13, 2024
769018a
Fix linter
naddison36 May 13, 2024
b98e9de
Remove approveAssets on Swapper contract in 095_ogn_buyback script as…
naddison36 May 13, 2024
622a3b4
Fix Holesky fork tests
naddison36 May 13, 2024
c25745d
Fix mainnet fork tests
naddison36 May 13, 2024
4ca3136
skip deploy 095_ogn_buyback for now
naddison36 May 13, 2024
37c9d0a
fix some Slither errors
naddison36 May 13, 2024
193af2f
Fix Slither warnings
naddison36 May 13, 2024
6d5034a
Upgrade the CI to use node.js 20.x
naddison36 May 13, 2024
848d578
Fix CI
naddison36 May 13, 2024
79d5058
Fix CI
naddison36 May 13, 2024
7b7ac39
Upgrade to node.js 20
naddison36 May 13, 2024
6b2be67
Still upgrade the buyback contracts but not approveAssets on the swapper
naddison36 May 13, 2024
5f2f8f6
Upgrade actions so they don't use node.js 16
naddison36 May 13, 2024
6baed9b
attempt to fix holesky fork run
sparrowDom May 13, 2024
9ce05e1
Generated latest contract diagram
naddison36 May 13, 2024
8c052d8
fix codecov upload
naddison36 May 13, 2024
3687fbe
Fix OETH process diagram for native staking
naddison36 May 13, 2024
6df4f5f
add a withdrawal event when withdrawing WETH to vault (#2059)
sparrowDom May 13, 2024
614b11e
Regenerated latest native staking diagram
naddison36 May 13, 2024
21d5569
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 13, 2024
cfe6a81
add a util contract that is able to recalculate a valid deposit data …
sparrowDom May 16, 2024
c491131
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 22, 2024
e8c15b5
Prettier native staking test
naddison36 May 22, 2024
acad4b9
Renamed native staking deploy script
naddison36 May 22, 2024
638bf30
Fix event values (#2060)
sparrowDom May 22, 2024
b4e9c3f
Deploy latest Native Staking Strategy to Holesky (#2073)
naddison36 May 22, 2024
77d7b07
Deploy native staking Proxy via Relayer (#2066)
sparrowDom May 22, 2024
4c25093
Setup basic defender action (#2072)
sparrowDom May 22, 2024
c4456b9
Output more contract details in 097 deploy script
naddison36 May 23, 2024
4e9e24f
Fix Native Staking fork tests
naddison36 May 24, 2024
8cf9a25
Changed ssv util getClusterInfo to use the SSV API instead of the ssv…
naddison36 May 24, 2024
fc09bed
Prettier
naddison36 May 24, 2024
bb3b7e6
ValidatorRegistrator.stakeEth gas improvement when multiple validators
naddison36 May 24, 2024
e163cff
Corrected stakeEth call in OETH processes diagram
naddison36 May 24, 2024
e853081
Added fork test for registering a validator twice
naddison36 May 27, 2024
12bba64
Stake funds with confirmations for front-running protection of Beacon…
sparrowDom May 28, 2024
0a0e9da
Updated Buyback value flow for OETH
naddison36 May 28, 2024
93b3cdf
Updated Native staking process diagram
naddison36 May 29, 2024
003fcdb
Updated OETH Vault diagrams
naddison36 May 29, 2024
9295fe7
Add process for pausing the Native Staking Strategy
naddison36 May 29, 2024
8748170
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 May 29, 2024
270a3f6
Removed the redundant condition in the fuse interval check (#2082)
naddison36 Jun 2, 2024
706da2e
OZ - Native Staking - M-01 All Addresses Are Registered Validators by…
naddison36 Jun 2, 2024
71adea7
OZ - Native Staking - N-07 Lack of Indexed Event Parameters (#2083)
naddison36 Jun 2, 2024
8f8118d
Deployed new Native Staking Strategy
naddison36 Jun 2, 2024
d398042
generated latest NativeStakingSSVStrategy docs
naddison36 Jun 2, 2024
b6c2219
P2P API changes (#2084)
naddison36 Jun 2, 2024
49439ec
Hardhat tasks for Native Staking (#2085)
naddison36 Jun 3, 2024
6ecf222
Cap the validators a Native Staking Strategy can hold (#2087)
naddison36 Jun 3, 2024
c807e8d
don't format Defender Action code in dist folder
naddison36 Jun 4, 2024
7f54c94
Deployed latest NativeStakingSSVStrategy contract to Holesky
naddison36 Jun 4, 2024
8b7c866
Capitalised error messages in Native Staking Strategy
naddison36 Jun 5, 2024
7e19fbb
Fix hot deploy of Native Staking Strategy
naddison36 Jun 5, 2024
37a1d10
moved when event it emitted
naddison36 Jun 5, 2024
57f78b8
remove unchecked when calculating fullyWithdrawnValidators
naddison36 Jun 5, 2024
4c3ba23
Renamed MAX_STAKE to FULL_STAKE
naddison36 Jun 5, 2024
e4db674
Renamed withdrawal_credentials to withdrawalCredentials
naddison36 Jun 5, 2024
02fe259
Renamed WETH_TOKEN_ADDRESS to WETH
naddison36 Jun 5, 2024
f4fb309
renamed SSV_TOKEN_ADDRESS to SSV_TOKEN
naddison36 Jun 5, 2024
0231bb8
replaced 32 ether with FULL_STAKE
naddison36 Jun 5, 2024
7db25d2
Fix fork tests
naddison36 Jun 5, 2024
b685925
moved the internal function to the bottom of NativeStakingSSVStrategy
naddison36 Jun 5, 2024
1d9fa16
fixed formatting of if statements
naddison36 Jun 5, 2024
6dc40ab
Moved emits to after state changes
naddison36 Jun 5, 2024
f8879bd
Removed validatorsLength variable as we aren't dealing with a storage…
naddison36 Jun 5, 2024
670064e
removed unchecked iteration in for loop
naddison36 Jun 5, 2024
9ac93f5
consistent check of currentState
naddison36 Jun 5, 2024
e6af23a
Added new Holesky deploy script
naddison36 Jun 5, 2024
2457b37
Removed Governable from FeeAccumulator
naddison36 Jun 5, 2024
9ff8c5a
Decryption of validator key from P2P API (#2088)
naddison36 Jun 5, 2024
4b8a315
Added asset check to withdraw
naddison36 Jun 6, 2024
b581b9e
Merge remote-tracking branch 'origin/sparrowDom/nativeStaking' into s…
naddison36 Jun 6, 2024
275527a
bumped down the events in Native Staking Strategy
naddison36 Jun 6, 2024
125cad8
Replaced 32 ether with FULL_STAKE
naddison36 Jun 6, 2024
66a6f63
Using FULL_STAKE instead of 32 ether to make it easier for EIP-7251, …
naddison36 Jun 6, 2024
56d3331
Removed withdrawalCredentials from ETHStaked event
naddison36 Jun 6, 2024
563003d
fix updating depositedWethAccountedFor on withdrawal (#2091)
naddison36 Jun 6, 2024
370d70e
Merge remote-tracking branch 'origin/master' into sparrowDom/nativeSt…
naddison36 Jun 6, 2024
9acd4a7
Changed max validators to 500
naddison36 Jun 7, 2024
dfbf709
remove extra await from fork tests
naddison36 Jun 7, 2024
c29887b
Reduced the stakeETHThreshold to 512 which is 16 validators
naddison36 Jun 7, 2024
630d8d4
Natspec update to ValidatorRegistrator
naddison36 Jun 7, 2024
ccfa636
New Holesky deployment
naddison36 Jun 7, 2024
aed063a
initial contract changes
sparrowDom Jun 7, 2024
ecbab50
Merge remote-tracking branch 'origin/master' into sparrowDom/validato…
sparrowDom Jun 7, 2024
b7cf329
more progress on validator simulator
sparrowDom Jun 11, 2024
239fb70
messy commit
sparrowDom Jun 11, 2024
7f1351a
...
sparrowDom Jun 12, 2024
ec6bf35
add fuzz testing for validator beacon chain rewards and withdrawals
sparrowDom Jun 14, 2024
12d1b45
remove creep file
sparrowDom Jun 14, 2024
0ef6640
Merge remote-tracking branch 'origin/master' into sparrowDom/validato…
sparrowDom Jun 17, 2024
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
Prev Previous commit
Next Next commit
Native staking changes and unit tests (#2029)
* Fixed native staking deployment since the strategist is got from the vault

* Refactor of some Native Staking events
Refactor of Native Staking unit tests

* Renamed AccountingBeaconChainRewards to AccountingConsensusRewards
Accounting updated to handle zero ETH from the beacon chain

* fixed bug not accounting for previous consensus rewards
Blow fuse if ETH balance < previous consensus rewards

* Pause collectRewardTokens and doAccounting on accounting failure.

Validated asset on deposit to Native Staking Strategy.

Moved depositSSV from NativeStakingSSVStrategy to ValidatorRegistrator

moved onlyStrategist modified and VAULT_ADDRESS immutable from ValidatorAccountant to ValidatorRegistrator

manuallyFixAccounting changed to use whenPaused modifier

made fuseIntervalEnd inclusive

Natspec updates

refactoring of native staking unit tests
  • Loading branch information
naddison36 authored Apr 25, 2024
commit 8419fc7776a8747c12aa2623d67aadf77c846ffe
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ contract NativeStakingSSVStrategy is
}

/// @dev Convert accumulated ETH to WETH and send to the Harvester.
function _collectRewardTokens() internal override {
/// Will revert if the strategy is paused for accounting.
function _collectRewardTokens() internal override whenNotPaused {
// collect ETH from execution rewards from the fee accumulator
uint256 executionRewards = FeeAccumulator(FEE_ACCUMULATOR_ADDRESS)
.collect();
Expand Down Expand Up @@ -114,19 +115,23 @@ contract NativeStakingSSVStrategy is
}
}

/// @notice Deposit asset into the underlying platform
/// @param _asset Address of asset to deposit
/// @param _amount Amount of assets to deposit
/// @notice Unlike other strategies, this does not deposit assets into the underlying platform.
/// It just checks the asset is WETH and emits the Deposit event.
/// To deposit WETH into validators `registerSsvValidator` and `stakeEth` must be used.
/// Will NOT revert if the strategy is paused from an accounting failure.
/// @param _asset Address of asset to deposit. Has to be WETH.
/// @param _amount Amount of assets that were transferred to the strategy by the vault.
function deposit(address _asset, uint256 _amount)
external
override
onlyVault
nonReentrant
{
require(_asset == WETH_TOKEN_ADDRESS, "Unsupported asset");
_deposit(_asset, _amount);
}

/// @dev Deposit WETH to this contract to enable automated action to stake it
/// @dev Deposit WETH to this strategy so it can later be staked into a validator.
/// @param _asset Address of WETH
/// @param _amount Amount of WETH to deposit
function _deposit(address _asset, uint256 _amount) internal {
Expand All @@ -143,7 +148,10 @@ contract NativeStakingSSVStrategy is
emit Deposit(_asset, address(0), _amount);
}

/// @notice Deposit the entire balance of WETH asset in the strategy into the underlying platform
/// @notice Unlike other strategies, this does not deposit assets into the underlying platform.
/// It just emits the Deposit event.
/// To deposit WETH into validators `registerSsvValidator` and `stakeEth` must be used.
/// Will NOT revert if the strategy is paused from an accounting failure.
function depositAll() external override onlyVault nonReentrant {
uint256 wethBalance = IERC20(WETH_TOKEN_ADDRESS).balanceOf(
address(this)
Expand All @@ -157,6 +165,7 @@ contract NativeStakingSSVStrategy is
/// can happen when:
/// - the deposit was not a multiple of 32 WETH
/// - someone sent WETH directly to this contract
/// Will NOT revert if the strategy is paused from an accounting failure.
/// @param _recipient Address to receive withdrawn assets
/// @param _asset WETH to withdraw
/// @param _amount Amount of WETH to withdraw
Expand All @@ -180,7 +189,14 @@ contract NativeStakingSSVStrategy is
IERC20(_asset).safeTransfer(_recipient, _amount);
}

/// @notice Remove all supported assets from the underlying platform and send them to Vault contract.
/// @notice transfer all WETH deposits back to the vault.
/// This does not withdraw from the validators. That has to be done separately with the
/// `exitSsvValidator` and `removeSsvValidator` operations.
/// This does not withdraw any execution rewards from the FeeAccumulator or
/// consensus rewards in this strategy.
/// Any ETH in this strategy that was swept from a full validator withdrawal will not be withdrawn.
/// ETH from full validator withdrawals is sent to the Vault using `doAccounting`.
/// Will NOT revert if the strategy is paused from an accounting failure.
function withdrawAll() external override onlyVaultOrGovernor nonReentrant {
uint256 wethBalance = IERC20(WETH_TOKEN_ADDRESS).balanceOf(
address(this)
Expand Down Expand Up @@ -234,24 +250,6 @@ contract NativeStakingSSVStrategy is
);
}

/// @notice Deposits more SSV Tokens to the SSV Network contract which is used to pay the SSV Operators.
/// @dev A SSV cluster is defined by the SSVOwnerAddress and the set of operatorIds.
/// uses "onlyStrategist" modifier so continuous front-running can't DOS our maintenance service
/// that tries to top up SSV tokens.
/// @param cluster The SSV cluster details that must be derived from emitted events from the SSVNetwork contract.
function depositSSV(
uint64[] memory operatorIds,
uint256 amount,
Cluster memory cluster
) external onlyStrategist {
ISSVNetwork(SSV_NETWORK_ADDRESS).deposit(
address(this),
operatorIds,
amount,
cluster
);
}

/**
* @notice Only accept ETH from the FeeAccumulator
* @dev don't want to receive donations from anyone else as this will
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ pragma solidity ^0.8.0;

import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol";
import { ValidatorRegistrator } from "./ValidatorRegistrator.sol";
import { IVault } from "../../interfaces/IVault.sol";
import { IWETH9 } from "../../interfaces/IWETH9.sol";

/// @title Validator Accountant
Expand All @@ -15,8 +14,6 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
/// @notice The maximum amount of ETH that can be staked by a validator
/// @dev this can change in the future with EIP-7251, Increase the MAX_EFFECTIVE_BALANCE
uint256 public constant MAX_STAKE = 32 ether;
/// @notice Address of the OETH Vault proxy contract
address public immutable VAULT_ADDRESS;

/// @notice Keeps track of the total consensus rewards swept from the beacon chain
uint256 public consensusRewards = 0;
Expand All @@ -30,12 +27,7 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {

uint256[50] private __gap;

event FuseIntervalUpdated(
uint256 oldStart,
uint256 oldEnd,
uint256 start,
uint256 end
);
event FuseIntervalUpdated(uint256 start, uint256 end);
event AccountingFullyWithdrawnValidator(
uint256 noOfValidators,
uint256 remainingValidators,
Expand All @@ -45,11 +37,8 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
uint256 remainingValidators,
uint256 wethSentToVault
);
event AccountingGovernorAddressChanged(
address oldAddress,
address newAddress
);
event AccountingBeaconChainRewards(uint256 amount);
event AccountingGovernorChanged(address newAddress);
event AccountingConsensusRewards(uint256 amount);

event AccountingManuallyFixed(
uint256 oldActiveDepositedValidators,
Expand All @@ -69,15 +58,6 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
_;
}

/// @dev Throws if called by any account other than the Strategist
modifier onlyStrategist() {
require(
msg.sender == IVault(VAULT_ADDRESS).strategistAddr(),
"Caller is not the Strategist"
);
_;
}

/// @param _wethAddress Address of the Erc20 WETH Token contract
/// @param _vaultAddress Address of the Vault
/// @param _beaconChainDepositContract Address of the beacon chain deposit contract
Expand All @@ -90,15 +70,14 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
)
ValidatorRegistrator(
_wethAddress,
_vaultAddress,
_beaconChainDepositContract,
_ssvNetwork
)
{
VAULT_ADDRESS = _vaultAddress;
}
{}

function setAccountingGovernor(address _address) external onlyGovernor {
emit AccountingGovernorAddressChanged(accountingGovernor, _address);
emit AccountingGovernorChanged(_address);
accountingGovernor = _address;
}

Expand All @@ -115,12 +94,7 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
"incorrect fuse interval"
);

emit FuseIntervalUpdated(
fuseIntervalStart,
fuseIntervalEnd,
_fuseIntervalStart,
_fuseIntervalEnd
);
emit FuseIntervalUpdated(_fuseIntervalStart, _fuseIntervalEnd);

fuseIntervalStart = _fuseIntervalStart;
fuseIntervalEnd = _fuseIntervalEnd;
Expand All @@ -129,10 +103,10 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
/* solhint-disable max-line-length */
/// This notion page offers a good explanation of how the accounting functions
/// https://www.notion.so/originprotocol/Limited-simplified-native-staking-accounting-67a217c8420d40678eb943b9da0ee77d
/// In short, after dividing by 32 if the ETH remaining on the contract falls between 0 and fuseIntervalStart the accounting
/// function will treat that ETH as a Beacon Chain Reward ETH.
/// On the contrary if after dividing by 32 the ETH remaining on the contract falls between fuseIntervalEnd and 32 the
/// accounting function will treat that as a validator slashing.
/// In short, after dividing by 32, if the ETH remaining on the contract falls between 0 and fuseIntervalStart,
/// the accounting function will treat that ETH as Beacon chain consensus rewards.
/// On the contrary, if after dividing by 32, the ETH remaining on the contract falls between fuseIntervalEnd and 32,
/// the accounting function will treat that as a validator slashing.
/// @notice Perform the accounting attributing beacon chain ETH to either full or partial withdrawals. Returns true when
/// accounting is valid and fuse isn't "blown". Returns false when fuse is blown.
/// @dev This function could in theory be permission-less but lets allow only the Registrator (Defender Action) to call it
Expand All @@ -141,8 +115,15 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
function doAccounting()
external
onlyRegistrator
whenNotPaused
returns (bool accountingValid)
{
if (address(this).balance < consensusRewards) {
// pause and fail the accounting
_pause();
return false;
}

// Calculate all the new ETH that has been swept to the contract since the last accounting
uint256 newSweptETH = address(this).balance - consensusRewards;
accountingValid = true;
Expand All @@ -163,18 +144,23 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
);
}

uint256 ethRemaining = address(this).balance;
uint256 ethRemaining = address(this).balance - consensusRewards;
// should be less than a whole validator stake
require(ethRemaining < 32 ether, "unexpected accounting");

// Beacon chain rewards swept (partial validator withdrawals)
if (ethRemaining <= fuseIntervalStart) {
// If no Beacon chain consensus rewards swept
if (ethRemaining == 0) {
// do nothing
return accountingValid;
}
// Beacon chain consensus rewards swept (partial validator withdrawals)
else if (ethRemaining < fuseIntervalStart) {
// solhint-disable-next-line reentrancy
consensusRewards += ethRemaining;
emit AccountingBeaconChainRewards(ethRemaining);
emit AccountingConsensusRewards(ethRemaining);
}
// Beacon chain rewards swept but also a slashed validator fully exited
else if (ethRemaining >= fuseIntervalEnd) {
// Beacon chain consensus rewards swept but also a slashed validator fully exited
else if (ethRemaining > fuseIntervalEnd) {
IWETH9(WETH_TOKEN_ADDRESS).deposit{ value: ethRemaining }();
IWETH9(WETH_TOKEN_ADDRESS).transfer(VAULT_ADDRESS, ethRemaining);
activeDepositedValidators -= 1;
Expand Down Expand Up @@ -209,9 +195,7 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
uint256 _consensusRewards,
uint256 _ethThresholdCheck,
uint256 _wethThresholdCheck
) external onlyAccountingGovernor {
require(paused(), "not paused");

) external onlyAccountingGovernor whenPaused {
uint256 ethBalance = address(this).balance;
uint256 wethBalance = IWETH9(WETH_TOKEN_ADDRESS).balanceOf(
address(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity ^0.8.0;
import { Pausable } from "@openzeppelin/contracts/security/Pausable.sol";
import { Governable } from "../../governance/Governable.sol";
import { IDepositContract } from "../../interfaces/IDepositContract.sol";
import { IVault } from "../../interfaces/IVault.sol";
import { IWETH9 } from "../../interfaces/IWETH9.sol";
import { ISSVNetwork, Cluster } from "../../interfaces/ISSVNetwork.sol";

Expand All @@ -25,6 +26,8 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
address public immutable BEACON_CHAIN_DEPOSIT_CONTRACT;
/// @notice The address of the SSV Network contract used to interface with
address public immutable SSV_NETWORK_ADDRESS;
/// @notice Address of the OETH Vault proxy contract
address public immutable VAULT_ADDRESS;

/// @notice Address of the registrator - allowed to register, exit and remove validators
address public validatorRegistrator;
Expand All @@ -45,7 +48,7 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
EXIT_COMPLETE // validator has funds withdrawn to the EigenPod and is removed from the SSV
}

event RegistratorAddressChanged(address oldAddress, address newAddress);
event RegistratorChanged(address newAddress);
event ETHStaked(bytes pubkey, uint256 amount, bytes withdrawal_credentials);
event SSVValidatorRegistered(bytes pubkey, uint64[] operatorIds);
event SSVValidatorExitInitiated(bytes pubkey, uint64[] operatorIds);
Expand All @@ -60,22 +63,34 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
_;
}

/// @dev Throws if called by any account other than the Strategist
modifier onlyStrategist() {
require(
msg.sender == IVault(VAULT_ADDRESS).strategistAddr(),
"Caller is not the Strategist"
);
_;
}

/// @param _wethAddress Address of the Erc20 WETH Token contract
/// @param _vaultAddress Address of the Vault
/// @param _beaconChainDepositContract Address of the beacon chain deposit contract
/// @param _ssvNetwork Address of the SSV Network contract
constructor(
address _wethAddress,
address _vaultAddress,
address _beaconChainDepositContract,
address _ssvNetwork
) {
WETH_TOKEN_ADDRESS = _wethAddress;
BEACON_CHAIN_DEPOSIT_CONTRACT = _beaconChainDepositContract;
SSV_NETWORK_ADDRESS = _ssvNetwork;
VAULT_ADDRESS = _vaultAddress;
}

/// @notice Set the address of the registrator
function setRegistratorAddress(address _address) external onlyGovernor {
emit RegistratorAddressChanged(validatorRegistrator, _address);
/// @notice Set the address of the registrator which can register, exit and remove validators
function setRegistrator(address _address) external onlyGovernor {
emit RegistratorChanged(_address);
validatorRegistrator = _address;
}

Expand Down Expand Up @@ -201,4 +216,22 @@ abstract contract ValidatorRegistrator is Governable, Pausable {

validatorsStates[keccak256(publicKey)] = VALIDATOR_STATE.EXIT_COMPLETE;
}

/// @notice Deposits more SSV Tokens to the SSV Network contract which is used to pay the SSV Operators.
/// @dev A SSV cluster is defined by the SSVOwnerAddress and the set of operatorIds.
/// uses "onlyStrategist" modifier so continuous front-running can't DOS our maintenance service
/// that tries to top up SSV tokens.
/// @param cluster The SSV cluster details that must be derived from emitted events from the SSVNetwork contract.
function depositSSV(
uint64[] memory operatorIds,
uint256 amount,
Cluster memory cluster
) external onlyStrategist {
ISSVNetwork(SSV_NETWORK_ADDRESS).deposit(
address(this),
operatorIds,
amount,
cluster
);
}
}
8 changes: 1 addition & 7 deletions contracts/deploy/091_native_ssv_staking.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = deploymentWithGovernanceProposal(
// "",
},
async ({ deployWithConfirmation, ethers, getTxOpts, withConfirmation }) => {
const { deployerAddr, strategistAddr } = await getNamedAccounts();
const { deployerAddr } = await getNamedAccounts();
const sDeployer = await ethers.provider.getSigner(deployerAddr);

// Current contracts
Expand Down Expand Up @@ -159,12 +159,6 @@ module.exports = deploymentWithGovernanceProposal(
signature: "setAccountingGovernor(address)",
args: [deployerAddr], // TODO: change this to the defender action
},
// 6. configure strategist address
{
contract: cStrategy,
signature: "setStrategist(address)",
args: [strategistAddr],
},
],
};
}
Expand Down
Loading
Loading