Skip to content

Commit

Permalink
add functions to register and exit/remove the ssv validator
Browse files Browse the repository at this point in the history
  • Loading branch information
sparrowDom committed Apr 18, 2024
1 parent 2c448bb commit 5d5e9cb
Show file tree
Hide file tree
Showing 12 changed files with 272 additions and 80 deletions.
34 changes: 34 additions & 0 deletions contracts/contracts/interfaces/IDepositContract.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

interface IDepositContract {
/// @notice A processed deposit event.
event DepositEvent(
bytes pubkey,
bytes withdrawal_credentials,
bytes amount,
bytes signature,
bytes index
);

/// @notice Submit a Phase 0 DepositData object.
/// @param pubkey A BLS12-381 public key.
/// @param withdrawal_credentials Commitment to a public key for withdrawals.
/// @param signature A BLS12-381 signature.
/// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object.
/// Used as a protection against malformed input.
function deposit(
bytes calldata pubkey,
bytes calldata withdrawal_credentials,
bytes calldata signature,
bytes32 deposit_data_root
) external payable;

/// @notice Query the current deposit root hash.
/// @return The deposit root hash.
function get_deposit_root() external view returns (bytes32);

/// @notice Query the current deposit count.
/// @return The deposit count encoded as a little endian 64-bit number.
function get_deposit_count() external view returns (bytes memory);
}
37 changes: 37 additions & 0 deletions contracts/contracts/mocks/BeaconChainDepositContractMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

contract BeaconChainDepositContractMock {
/// @notice A processed deposit event.
event DepositEvent(
bytes pubkey,
bytes withdrawal_credentials,
bytes amount,
bytes signature,
bytes index
);

/// @notice Submit a Phase 0 DepositData object.
/// @param pubkey A BLS12-381 public key.
/// @param withdrawal_credentials Commitment to a public key for withdrawals.
/// @param signature A BLS12-381 signature.
/// @param deposit_data_root The SHA-256 hash of the SSZ-encoded DepositData object.
/// Used as a protection against malformed input.
function deposit(
bytes calldata pubkey,
bytes calldata withdrawal_credentials,
bytes calldata signature,
bytes32 deposit_data_root
) external payable {
// Extended ABI length checks since dynamic types are used.
require(pubkey.length == 48, "DepositContract: invalid pubkey length");
require(withdrawal_credentials.length == 32, "DepositContract: invalid withdrawal_credentials length");
require(signature.length == 96, "DepositContract: invalid signature length");

// Check deposit amount
require(msg.value >= 1 ether, "DepositContract: deposit value too low");
require(msg.value % 1 gwei == 0, "DepositContract: deposit value not multiple of gwei");
uint deposit_amount = msg.value / 1 gwei;
require(deposit_amount <= type(uint64).max, "DepositContract: deposit value too high");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import { SafeERC20 } from "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.s

import { InitializableAbstractStrategy } from "../../utils/InitializableAbstractStrategy.sol";
import { IWETH9 } from "../../interfaces/IWETH9.sol";
import { ISSVNetwork, Cluster } from "../../interfaces/ISSVNetwork.sol";
import { FeeAccumulator } from "./FeeAccumulator.sol";
import { ValidatorAccountant } from "./ValidatorAccountant.sol";
import { Cluster } from "../../interfaces/ISSVNetwork.sol";

struct ValidatorStakeData {
bytes pubkey;
Expand All @@ -27,8 +27,6 @@ contract NativeStakingSSVStrategy is

/// @notice SSV ERC20 token that serves as a payment for operating SSV validators
address public immutable SSV_TOKEN_ADDRESS;
/// @notice SSV Network contract used to interface with
address public immutable SSV_NETWORK_ADDRESS;
/// @notice Fee collector address
/// @dev this address will receive Execution layer rewards - These are rewards earned for
/// executing transactions on the Ethereum network as part of block proposals. They include
Expand All @@ -51,18 +49,20 @@ 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 _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,
address _feeAccumulator
address _feeAccumulator,
address _beaconChainDepositContract
)
InitializableAbstractStrategy(_baseConfig)
ValidatorAccountant(_wethAddress, _baseConfig.vaultAddress)
ValidatorAccountant(_wethAddress, _baseConfig.vaultAddress, _beaconChainDepositContract, _ssvNetwork)
{
SSV_TOKEN_ADDRESS = _ssvToken;
SSV_NETWORK_ADDRESS = _ssvNetwork;
FEE_ACCUMULATOR_ADDRESS = _feeAccumulator;
}

Expand Down Expand Up @@ -270,13 +270,17 @@ contract NativeStakingSSVStrategy is
);
}

/// @dev Deposits more SSV Tokens to the SSV Network contract which is used to pay the SSV Operators
/// A SSV cluster is defined by the SSVOwnerAddress and the set of operatorIds
/// @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 fron-running can't DOS our maintenance service
/// that tries to top us SSV tokens.
function depositSSV(
uint64[] memory operatorIds,
uint256 amount,
Cluster memory cluster
) external {
)
onlyStrategist
external {
// address SSV_NETWORK_ADDRESS = lrtConfig.getContract(LRTConstants.SSV_NETWORK);
// ISSVNetwork(SSV_NETWORK_ADDRESS).deposit(address(this), operatorIds, amount, cluster);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ import { IWETH9 } from "../../interfaces/IWETH9.sol";
/// @notice This contract contains the logic to attribute the Beacon Chain swept ETH either to full
/// or partial withdrawals
/// @author Origin Protocol Inc
abstract contract ValidatorAccountant is ValidatorRegistrator, Pausable {
/// @notice The Wrapped ETH (WETH) contract address
address public immutable WETH_TOKEN_ADDRESS;
abstract contract ValidatorAccountant is ValidatorRegistrator {
address public immutable VAULT_ADDRESS;

/// @dev The WETH present on this contract will come from 2 sources:
Expand Down Expand Up @@ -92,8 +90,11 @@ abstract contract ValidatorAccountant is ValidatorRegistrator, Pausable {
}

/// @param _wethAddress Address of the Erc20 WETH Token contract
constructor(address _wethAddress, address _vaultAddress) {
WETH_TOKEN_ADDRESS = _wethAddress;
/// @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)
ValidatorRegistrator(_wethAddress, _beaconChainDepositContract, _ssvNetwork) {
VAULT_ADDRESS = _vaultAddress;
}

Expand Down Expand Up @@ -142,9 +143,10 @@ abstract contract ValidatorAccountant is ValidatorRegistrator, Pausable {
/// 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
/// for now
function doAccounting() external onlyRegistrator returns (bool) {
function doAccounting() external onlyRegistrator returns (bool accountingValid) {
uint256 ethBalance = address(this).balance;
uint256 MAX_STAKE = 32 ether;
accountingValid = true;

// send the WETH that is from fully withdrawn validators to the Vault
if (ethBalance >= MAX_STAKE) {
Expand Down Expand Up @@ -190,6 +192,7 @@ abstract contract ValidatorAccountant is ValidatorRegistrator, Pausable {
else {
// will emit a paused event
_pause();
accountingValid = false;
}
}

Expand Down
Loading

0 comments on commit 5d5e9cb

Please sign in to comment.