Skip to content

Commit

Permalink
Cap the validators a Native Staking Strategy can hold (#2087)
Browse files Browse the repository at this point in the history
* Added max validators check to Native Staking Strategy
  • Loading branch information
naddison36 committed Jun 3, 2024
1 parent 49439ec commit 6ecf222
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,15 @@ contract NativeStakingSSVStrategy is
/// @param _wethAddress Address of the Erc20 WETH Token contract
/// @param _ssvToken Address of the Erc20 SSV Token contract
/// @param _ssvNetwork Address of the SSV Network contract
/// @param _maxValidators Maximum number of validators that can be registered in the strategy
/// @param _feeAccumulator Address of the fee accumulator receiving execution layer validator rewards
/// @param _beaconChainDepositContract Address of the beacon chain deposit contract
constructor(
BaseStrategyConfig memory _baseConfig,
address _wethAddress,
address _ssvToken,
address _ssvNetwork,
uint256 _maxValidators,
address _feeAccumulator,
address _beaconChainDepositContract
)
Expand All @@ -89,7 +91,8 @@ contract NativeStakingSSVStrategy is
_wethAddress,
_baseConfig.vaultAddress,
_beaconChainDepositContract,
_ssvNetwork
_ssvNetwork,
_maxValidators
)
{
SSV_TOKEN_ADDRESS = _ssvToken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,20 @@ abstract contract ValidatorAccountant is ValidatorRegistrator {
/// @param _vaultAddress Address of the Vault
/// @param _beaconChainDepositContract Address of the beacon chain deposit contract
/// @param _ssvNetwork Address of the SSV Network contract
/// @param _maxValidators Maximum number of validators that can be registered in the strategy
constructor(
address _wethAddress,
address _vaultAddress,
address _beaconChainDepositContract,
address _ssvNetwork
address _ssvNetwork,
uint256 _maxValidators
)
ValidatorRegistrator(
_wethAddress,
_vaultAddress,
_beaconChainDepositContract,
_ssvNetwork
_ssvNetwork,
_maxValidators
)
{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
address public immutable SSV_NETWORK_ADDRESS;
/// @notice Address of the OETH Vault proxy contract
address public immutable VAULT_ADDRESS;
/// @notice Maximum number of validators that can be registered in this strategy
uint256 public immutable MAX_VALIDATORS;

/// @notice Address of the registrator - allowed to register, exit and remove validators
address public validatorRegistrator;
Expand Down Expand Up @@ -109,16 +111,19 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
/// @param _vaultAddress Address of the Vault
/// @param _beaconChainDepositContract Address of the beacon chain deposit contract
/// @param _ssvNetwork Address of the SSV Network contract
/// @param _maxValidators Maximum number of validators that can be registered in the strategy
constructor(
address _wethAddress,
address _vaultAddress,
address _beaconChainDepositContract,
address _ssvNetwork
address _ssvNetwork,
uint256 _maxValidators
) {
WETH_TOKEN_ADDRESS = _wethAddress;
BEACON_CHAIN_DEPOSIT_CONTRACT = _beaconChainDepositContract;
SSV_NETWORK_ADDRESS = _ssvNetwork;
VAULT_ADDRESS = _vaultAddress;
MAX_VALIDATORS = _maxValidators;
}

/// @notice Set the address of the registrator which can register, exit and remove validators
Expand Down Expand Up @@ -163,6 +168,10 @@ abstract contract ValidatorRegistrator is Governable, Pausable {
requiredETH <= IWETH9(WETH_TOKEN_ADDRESS).balanceOf(address(this)),
"insufficient WETH"
);
require(
activeDepositedValidators + validators.length <= MAX_VALIDATORS,
"Max validators reached"
);

require(
stakeETHTally + requiredETH <= stakeETHThreshold,
Expand Down
2 changes: 2 additions & 0 deletions contracts/deploy/deployActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,7 @@ const upgradeNativeStakingSSVStrategy = async () => {
assetAddresses.WETH, // wethAddress
assetAddresses.SSV, // ssvToken
assetAddresses.SSVNetwork, // ssvNetwork
600, // maxValidators
cFeeAccumulatorProxy.address, // feeAccumulator
assetAddresses.beaconChainDepositContract, // depositContractMock
]
Expand Down Expand Up @@ -900,6 +901,7 @@ const deployNativeStakingSSVStrategy = async () => {
assetAddresses.WETH, // wethAddress
assetAddresses.SSV, // ssvToken
assetAddresses.SSVNetwork, // ssvNetwork
600, // maxValidators
dFeeAccumulatorProxy.address, // feeAccumulator
assetAddresses.beaconChainDepositContract, // depositContractMock
]
Expand Down
18 changes: 18 additions & 0 deletions contracts/deploy/holesky/012_upgrade_strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const { upgradeNativeStakingSSVStrategy } = require("../deployActions");

const mainExport = async () => {
console.log("Running 012 deployment on Holesky...");

console.log("Upgrading native staking strategy");
await upgradeNativeStakingSSVStrategy();

console.log("Running 012 deployment done");
return true;
};

mainExport.id = "012_upgrade_strategy";
mainExport.tags = [];
mainExport.dependencies = [];
mainExport.skip = () => false;

module.exports = mainExport;
1 change: 1 addition & 0 deletions contracts/deploy/mainnet/097_native_ssv_staking.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = deploymentWithGovernanceProposal(
addresses.mainnet.WETH, // wethAddress
addresses.mainnet.SSV, // ssvToken
addresses.mainnet.SSVNetwork, // ssvNetwork
600, // maxValidators
dFeeAccumulatorProxy.address, // feeAccumulator
addresses.mainnet.beaconChainDepositContract, // beacon chain deposit contract
]
Expand Down

0 comments on commit 6ecf222

Please sign in to comment.