Skip to content

Commit

Permalink
chore: massive renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
tamtamchik committed Feb 12, 2025
1 parent fb94485 commit 7bc6c00
Show file tree
Hide file tree
Showing 14 changed files with 188 additions and 171 deletions.
12 changes: 6 additions & 6 deletions contracts/0.8.25/vaults/Dashboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -458,23 +458,23 @@ contract Dashboard is Permissions {
* @notice Signals to node operators that specific validators should exit from the beacon chain.
* It does not directly trigger exits - node operators must monitor for these events and handle the exits manually.
* @param _pubkeys Concatenated validator public keys, each 48 bytes long.
* @dev Emits `ValidatorMarkedForExit` event for each validator public key through the StakingVault
* @dev Emits `ValidatorExitRequested` event for each validator public key through the StakingVault.
* This is a voluntary exit request - node operators can choose whether to act on it.
*/
function markValidatorsForExit(bytes calldata _pubkeys) external {
_markValidatorsForExit(_pubkeys);
function requestValidatorExit(bytes calldata _pubkeys) external {
_requestValidatorExit(_pubkeys);
}

/**
* @notice Requests validator withdrawals via EIP-7002 triggerable exit mechanism. This allows withdrawing either the full
* @notice Triggers validator withdrawals via EIP-7002 triggerable exit mechanism. This allows withdrawing either the full
* validator balance or a partial amount from each validator specified.
* @param _pubkeys The concatenated public keys of the validators to request withdrawal for. Each key must be 48 bytes.
* @param _amounts The withdrawal amounts in wei for each validator. Must match the length of _pubkeys.
* @param _refundRecipient The address that will receive any fee refunds.
* @dev Requires payment of withdrawal fee which is calculated based on the number of validators and must be paid in msg.value.
*/
function requestValidatorWithdrawals(bytes calldata _pubkeys, uint64[] calldata _amounts, address _refundRecipient) external payable {
_requestValidatorWithdrawals(_pubkeys, _amounts, _refundRecipient);
function triggerValidatorWithdrawal(bytes calldata _pubkeys, uint64[] calldata _amounts, address _refundRecipient) external payable {
_triggerValidatorWithdrawal(_pubkeys, _amounts, _refundRecipient);
}

// ==================== Role Management Functions ====================
Expand Down
16 changes: 8 additions & 8 deletions contracts/0.8.25/vaults/Permissions.sol
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ abstract contract Permissions is AccessControlVoteable {
keccak256("StakingVault.Permissions.ResumeBeaconChainDeposits");

/**
* @notice Permission for marking validators for exit from the StakingVault.
* @notice Permission for requesting validator exit from the StakingVault.
*/
bytes32 public constant MARK_VALIDATORS_FOR_EXIT_ROLE = keccak256("StakingVault.Permissions.MarkValidatorsForExit");
bytes32 public constant REQUEST_VALIDATOR_EXIT_ROLE = keccak256("StakingVault.Permissions.RequestValidatorExit");

/**
* @notice Permission for force validators exit from the StakingVault using EIP-7002 triggerable exit.
* @notice Permission for triggering validator withdrawal from the StakingVault using EIP-7002 triggerable exit.
*/
bytes32 public constant REQUEST_VALIDATOR_WITHDRAWALS_ROLE = keccak256("StakingVault.Permissions.RequestValidatorWithdrawals");
bytes32 public constant TRIGGER_VALIDATOR_WITHDRAWAL_ROLE = keccak256("StakingVault.Permissions.TriggerValidatorWithdrawal");

/**
* @notice Permission for voluntary disconnecting the StakingVault.
Expand Down Expand Up @@ -146,12 +146,12 @@ abstract contract Permissions is AccessControlVoteable {
stakingVault().resumeBeaconChainDeposits();
}

function _markValidatorsForExit(bytes calldata _pubkeys) internal onlyRole(MARK_VALIDATORS_FOR_EXIT_ROLE) {
stakingVault().markValidatorsForExit(_pubkeys);
function _requestValidatorExit(bytes calldata _pubkeys) internal onlyRole(REQUEST_VALIDATOR_EXIT_ROLE) {
stakingVault().requestValidatorExit(_pubkeys);
}

function _requestValidatorWithdrawals(bytes calldata _pubkeys, uint64[] calldata _amounts, address _refundRecipient) internal onlyRole(REQUEST_VALIDATOR_WITHDRAWALS_ROLE) {
stakingVault().requestValidatorWithdrawals{value: msg.value}(_pubkeys, _amounts, _refundRecipient);
function _triggerValidatorWithdrawal(bytes calldata _pubkeys, uint64[] calldata _amounts, address _refundRecipient) internal onlyRole(TRIGGER_VALIDATOR_WITHDRAWAL_ROLE) {
stakingVault().triggerValidatorWithdrawal{value: msg.value}(_pubkeys, _amounts, _refundRecipient);
}

function _voluntaryDisconnect() internal onlyRole(VOLUNTARY_DISCONNECT_ROLE) {
Expand Down
120 changes: 64 additions & 56 deletions contracts/0.8.25/vaults/StakingVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {IStakingVault} from "./interfaces/IStakingVault.sol";
* The StakingVault can be used as a backing for minting new stETH if the StakingVault is connected to the VaultHub.
* When minting stETH backed by the StakingVault, the VaultHub locks a portion of the StakingVault's valuation,
* which cannot be withdrawn by the owner. If the locked amount exceeds the StakingVault's valuation,
* the StakingVault enters the unhealthy state.
* the StakingVault enters the unbalanced state.
* In this state, the VaultHub can force-rebalance the StakingVault by withdrawing a portion of the locked amount
* and writing off the locked amount to restore the healthy state.
* and writing off the locked amount to restore the balanced state.
* The owner can voluntarily rebalance the StakingVault in any state or by simply
* supplying more ether to increase the valuation.
*
Expand All @@ -36,11 +36,11 @@ import {IStakingVault} from "./interfaces/IStakingVault.sol";
* - `rebalance()`
* - `pauseBeaconChainDeposits()`
* - `resumeBeaconChainDeposits()`
* - `markValidatorsForExit()`
* - `requestValidatorWithdrawals()`
* - `requestValidatorExit()`
* - `triggerValidatorWithdrawal()`
* - Operator:
* - `depositToBeaconChain()`
* - `requestValidatorWithdrawals()`
* - `triggerValidatorWithdrawal()`
* - VaultHub:
* - `lock()`
* - `report()`
Expand Down Expand Up @@ -265,7 +265,7 @@ contract StakingVault is IStakingVault, OwnableUpgradeable {
* @dev Cannot withdraw more than the unlocked amount or the balance of the contract, whichever is less.
* @dev Updates inOutDelta to track the net difference between funded and withdrawn ether
* @dev Includes a check that valuation remains greater than locked amount after withdrawal to ensure
* `StakingVault` stays healthy and prevent reentrancy attacks.
* `StakingVault` stays balanced and prevent reentrancy attacks.
*/
function withdraw(address _recipient, uint256 _ether) external onlyOwner {
if (_recipient == address(0)) revert ZeroArgument("_recipient");
Expand Down Expand Up @@ -303,7 +303,7 @@ contract StakingVault is IStakingVault, OwnableUpgradeable {

/**
* @notice Rebalances StakingVault by withdrawing ether to VaultHub
* @dev Can only be called by VaultHub if StakingVault is unhealthy,
* @dev Can only be called by VaultHub if StakingVault is unbalanced,
* or by owner at any moment
* @param _ether Amount of ether to rebalance
*/
Expand Down Expand Up @@ -394,7 +394,7 @@ contract StakingVault is IStakingVault, OwnableUpgradeable {
/**
* @notice Performs a deposit to the beacon chain deposit contract
* @param _deposits Array of deposit structs
* @dev Includes a check to ensure `StakingVault` is healthy before making deposits
* @dev Includes a check to ensure `StakingVault` is balanced before making deposits
*/
function depositToBeaconChain(Deposit[] calldata _deposits) external {
if (_deposits.length == 0) revert ZeroArgument("_deposits");
Expand Down Expand Up @@ -425,78 +425,81 @@ contract StakingVault is IStakingVault, OwnableUpgradeable {
* @notice Calculates the total withdrawal fee required for given number of validator keys
* @param _numberOfKeys Number of validators' public keys
* @return Total fee amount to pass as `msg.value` (wei)
* @dev The fee is only valid for the requests made in the same block.
* @dev The fee is only valid for the requests made in the same block
*/
function calculateValidatorWithdrawalsFee(uint256 _numberOfKeys) external view returns (uint256) {
function calculateValidatorWithdrawalFee(uint256 _numberOfKeys) external view returns (uint256) {
if (_numberOfKeys == 0) revert ZeroArgument("_numberOfKeys");

return _numberOfKeys * TriggerableWithdrawals.getWithdrawalRequestFee();
}

/**
* @notice Signals to node operators that specific validators should exit from the beacon chain.
* It does not directly trigger exits - node operators must monitor for these events and handle the exits manually.
* @param _pubkeys Concatenated validator public keys, each 48 bytes long.
* @notice Requests node operator to exit validators from the beacon chain
* It does not directly trigger exits - node operators must monitor for these events and handle the exits manually
* @param _pubkeys Concatenated validator public keys, each 48 bytes long
*/
function markValidatorsForExit(bytes calldata _pubkeys) external onlyOwner {
function requestValidatorExit(bytes calldata _pubkeys) external onlyOwner {
if (_pubkeys.length == 0) revert ZeroArgument("_pubkeys");
if (_pubkeys.length % PUBLIC_KEY_LENGTH != 0) {
revert InvalidValidatorPubkeysLength();
revert InvalidPubkeysLength();
}

uint256 keysCount = _pubkeys.length / PUBLIC_KEY_LENGTH;
for (uint256 i = 0; i < keysCount; i++) {
emit ValidatorMarkedForExit(msg.sender, bytes(_pubkeys[i * PUBLIC_KEY_LENGTH : (i + 1) * PUBLIC_KEY_LENGTH]));
emit ValidatorExitRequested(msg.sender, bytes(_pubkeys[i * PUBLIC_KEY_LENGTH : (i + 1) * PUBLIC_KEY_LENGTH]));
}
}

/**
* @notice Requests validator withdrawals from the beacon chain using EIP-7002 triggerable exit.
* @param _pubkeys Concatenated validators public keys, each 48 bytes long.
* @param _amounts Amounts of ether to exit, must match the length of _pubkeys.
* @param _refundRecipient Address to receive the fee refund.
* @dev The caller must provide sufficient fee via msg.value to cover the withdrawal request costs.
* TODO: check if the vault is unhealthy
* @notice Triggers validator withdrawals from the beacon chain using EIP-7002 triggerable exit
* @param _pubkeys Concatenated validators public keys, each 48 bytes long
* @param _amounts Amounts of ether to exit, must match the length of _pubkeys
* @param _refundRecipient Address to receive the fee refund
* @dev The caller must provide sufficient fee via msg.value to cover the withdrawal request costs
*/
function requestValidatorWithdrawals(bytes calldata _pubkeys, uint64[] calldata _amounts, address _refundRecipient) external payable {
uint256 value = msg.value; // cache msg.value to save gas
function triggerValidatorWithdrawal(bytes calldata _pubkeys, uint64[] calldata _amounts, address _refundRecipient) external payable {
uint256 value = msg.value;

if (value == 0) revert ZeroArgument("msg.value");
if (_pubkeys.length == 0) revert ZeroArgument("_pubkeys");
if (_amounts.length == 0) revert ZeroArgument("_amounts");
if (_refundRecipient == address(0)) revert ZeroArgument("_refundRecipient");
if (_pubkeys.length % PUBLIC_KEY_LENGTH != 0) revert InvalidPubkeysLength();

uint256 keysCount = _pubkeys.length / PUBLIC_KEY_LENGTH;
if (keysCount != _amounts.length) revert InvalidAmountsLength();

ERC7201Storage storage $ = _getStorage();
bool isHealthy = valuation() >= $.locked;
if (!isHealthy) {
bool isBalanced = valuation() >= $.locked;
bool isAuthorized = (
msg.sender == $.nodeOperator ||
msg.sender == owner() ||
(!isBalanced && msg.sender == address(VAULT_HUB))
);

if (!isAuthorized) revert NotAuthorized("triggerValidatorWithdrawal", msg.sender);
if (!isBalanced) {
for (uint256 i = 0; i < _amounts.length; i++) {
if (_amounts[i] > 0) revert PartialWithdrawalsForbidden();
if (_amounts[i] > 0) revert PartialWithdrawalNotAllowed();
}
}

if (msg.sender == $.nodeOperator || msg.sender == owner() || (!isHealthy && msg.sender == address(VAULT_HUB))) {
uint256 feePerRequest = TriggerableWithdrawals.getWithdrawalRequestFee();
uint256 totalFee = (feePerRequest * _pubkeys.length) / PUBLIC_KEY_LENGTH;
if (value < totalFee) {
revert InsufficientValidatorWithdrawalsFee(value, totalFee);
}

TriggerableWithdrawals.addWithdrawalRequests(_pubkeys, _amounts, feePerRequest);
uint256 feePerRequest = TriggerableWithdrawals.getWithdrawalRequestFee();
uint256 totalFee = feePerRequest * keysCount;
if (value < totalFee) revert InsufficientValidatorWithdrawalFee(value, totalFee);

uint256 excess = msg.value - totalFee;
if (excess > 0) {
(bool success,) = _refundRecipient.call{value: excess}("");
if (!success) {
revert ValidatorWithdrawalFeeRefundFailed(_refundRecipient, excess);
}
}
TriggerableWithdrawals.addWithdrawalRequests(_pubkeys, _amounts, feePerRequest);

emit ValidatorWithdrawalsRequested(msg.sender, _pubkeys, _amounts, _refundRecipient, excess);
} else {
revert NotAuthorized("requestValidatorWithdrawals", msg.sender);
uint256 excess = value - totalFee;
if (excess > 0) {
(bool success,) = _refundRecipient.call{value: excess}("");
if (!success) revert WithdrawalFeeRefundFailed(_refundRecipient, excess);
}

emit ValidatorWithdrawalRequested(msg.sender, _pubkeys, _amounts, _refundRecipient, excess);
}


/**
* @notice Computes the deposit data root for a validator deposit
* @param _pubkey Validator public key, 48 bytes
Expand Down Expand Up @@ -610,12 +613,12 @@ contract StakingVault is IStakingVault, OwnableUpgradeable {
event DepositedToBeaconChain(address indexed _sender, uint256 _deposits, uint256 _totalAmount);

/**
* @notice Emitted when a validator is marked for exit from the beacon chain
* @param _sender Address that marked the validator for exit
* @param _pubkeys Public key of the validator marked for exit
* @notice Emitted when vault owner requests node operator to exit validators from the beacon chain
* @param _sender Address that requested the exit
* @param _pubkey Public key of the validator to exit
* @dev Signals to node operators that they should exit this validator from the beacon chain
*/
event ValidatorMarkedForExit(address _sender, bytes _pubkeys);
event ValidatorExitRequested(address _sender, bytes _pubkey);

/**
* @notice Emitted when validator withdrawals are requested via EIP-7002
Expand All @@ -625,7 +628,7 @@ contract StakingVault is IStakingVault, OwnableUpgradeable {
* @param _refundRecipient Address to receive any excess withdrawal fee
* @param _excess Amount of excess fee refunded to recipient
*/
event ValidatorWithdrawalsRequested(address indexed _sender, bytes _pubkeys, uint64[] _amounts, address _refundRecipient, uint256 _excess);
event ValidatorWithdrawalRequested(address indexed _sender, bytes _pubkeys, uint64[] _amounts, address _refundRecipient, uint256 _excess);

/**
* @notice Emitted when an excess fee is refunded back to the sender.
Expand Down Expand Up @@ -713,26 +716,31 @@ contract StakingVault is IStakingVault, OwnableUpgradeable {
error BeaconChainDepositsArePaused();

/**
* @notice Thrown when the length of the validator public keys array is invalid
* @notice Thrown when the length of the validator public keys is invalid
*/
error InvalidPubkeysLength();

/**
* @notice Thrown when the length of the amounts is not equal to the length of the pubkeys
*/
error InvalidValidatorPubkeysLength();
error InvalidAmountsLength();

/**
* @notice Thrown when the validator withdrawal fee is insufficient
* @param _passed Amount of ether passed to the function
* @param _required Amount of ether required to cover the fee
*/
error InsufficientValidatorWithdrawalsFee(uint256 _passed, uint256 _required);
error InsufficientValidatorWithdrawalFee(uint256 _passed, uint256 _required);

/**
* @notice Thrown when a validator withdrawal fee refund fails
* @param _sender Address that initiated the refund
* @param _amount Amount of ether to refund
*/
error ValidatorWithdrawalFeeRefundFailed(address _sender, uint256 _amount);
error WithdrawalFeeRefundFailed(address _sender, uint256 _amount);

/**
* @notice Thrown when partial withdrawals are forbidden on an unhealthy vault
* @notice Thrown when partial withdrawals are not allowed on an unbalanced vault
*/
error PartialWithdrawalsForbidden();
error PartialWithdrawalNotAllowed();
}
8 changes: 4 additions & 4 deletions contracts/0.8.25/vaults/VaultFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ struct DelegationConfig {
address rebalancer;
address depositPauser;
address depositResumer;
address validatorExitRequester;
address validatorWithdrawalRequester;
address exitRequester;
address withdrawalTriggerer;
address disconnecter;
address curator;
address nodeOperatorManager;
Expand Down Expand Up @@ -78,8 +78,8 @@ contract VaultFactory {
delegation.grantRole(delegation.REBALANCE_ROLE(), _delegationConfig.rebalancer);
delegation.grantRole(delegation.PAUSE_BEACON_CHAIN_DEPOSITS_ROLE(), _delegationConfig.depositPauser);
delegation.grantRole(delegation.RESUME_BEACON_CHAIN_DEPOSITS_ROLE(), _delegationConfig.depositResumer);
delegation.grantRole(delegation.MARK_VALIDATORS_FOR_EXIT_ROLE(), _delegationConfig.validatorExitRequester);
delegation.grantRole(delegation.REQUEST_VALIDATOR_WITHDRAWALS_ROLE(), _delegationConfig.validatorWithdrawalRequester);
delegation.grantRole(delegation.REQUEST_VALIDATOR_EXIT_ROLE(), _delegationConfig.exitRequester);
delegation.grantRole(delegation.TRIGGER_VALIDATOR_WITHDRAWAL_ROLE(), _delegationConfig.withdrawalTriggerer);
delegation.grantRole(delegation.VOLUNTARY_DISCONNECT_ROLE(), _delegationConfig.disconnecter);
delegation.grantRole(delegation.CURATOR_ROLE(), _delegationConfig.curator);
delegation.grantRole(delegation.NODE_OPERATOR_MANAGER_ROLE(), _delegationConfig.nodeOperatorManager);
Expand Down
Loading

0 comments on commit 7bc6c00

Please sign in to comment.