Skip to content

Commit

Permalink
refactor: rename withdrawableRestakedExecutionLayerGwei
Browse files Browse the repository at this point in the history
* maintains old interface, only state variable is renamed
* this is to reduce line length when using this variable
  • Loading branch information
wadealexc committed Nov 15, 2024
1 parent 916a327 commit 77e28ab
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/contracts/interfaces/IEigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ interface IEigenPodErrors {

/// Withdrawing

/// @dev Thrown when amount exceeds `withdrawableRestakedExecutionLayerGwei`.
/// @dev Thrown when amount exceeds `restakedExecutionLayerGwei`.
error InsufficientWithdrawableBalance();
/// @dev Thrown when provided `amountGwei` is not a multiple of gwei.
error AmountMustBeMultipleOfGwei();
Expand Down Expand Up @@ -152,7 +152,7 @@ interface IEigenPod is IEigenPodErrors, IEigenPodEvents {
/**
* @notice Transfers `amountWei` in ether from this contract to the specified `recipient` address
* @notice Called by EigenPodManager to withdrawBeaconChainETH that has been added to the EigenPod's balance due to a withdrawal from the beacon chain.
* @dev The podOwner must have already proved sufficient withdrawals, so that this pod's `withdrawableRestakedExecutionLayerGwei` exceeds the
* @dev The podOwner must have already proved sufficient withdrawals, so that this pod's `restakedExecutionLayerGwei` exceeds the
* `amountWei` input (when converted to GWEI).
* @dev Reverts if `amountWei` is not a whole Gwei amount
*/
Expand Down
23 changes: 14 additions & 9 deletions src/contracts/pods/EigenPod.sol
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@ contract EigenPod is Initializable, ReentrancyGuardUpgradeable, EigenPodPausingC
/**
* @notice Transfers `amountWei` in ether from this contract to the specified `recipient` address
* @notice Called by EigenPodManager to withdrawBeaconChainETH that has been added to the EigenPod's balance due to a withdrawal from the beacon chain.
* @dev The podOwner must have already proved sufficient withdrawals, so that this pod's `withdrawableRestakedExecutionLayerGwei` exceeds the
* @dev The podOwner must have already proved sufficient withdrawals, so that this pod's `restakedExecutionLayerGwei` exceeds the
* `amountWei` input (when converted to GWEI).
* @dev Reverts if `amountWei` is not a whole Gwei amount
*/
function withdrawRestakedBeaconChainETH(address recipient, uint256 amountWei) external onlyEigenPodManager {
require(amountWei % GWEI_TO_WEI == 0, AmountMustBeMultipleOfGwei());
uint64 amountGwei = uint64(amountWei / GWEI_TO_WEI);
require(amountGwei <= withdrawableRestakedExecutionLayerGwei, InsufficientWithdrawableBalance());
withdrawableRestakedExecutionLayerGwei -= amountGwei;
require(amountGwei <= restakedExecutionLayerGwei, InsufficientWithdrawableBalance());
restakedExecutionLayerGwei -= amountGwei;
emit RestakedBeaconChainETHWithdrawn(recipient, amountWei);
// transfer ETH from pod to `recipient` directly
Address.sendValue(payable(recipient), amountWei);
Expand Down Expand Up @@ -587,12 +587,12 @@ contract EigenPod is Initializable, ReentrancyGuardUpgradeable, EigenPodPausingC
// previously been credited with shares. Once the checkpoint is finalized, `podBalanceGwei`
// will be added to the total validator balance delta and credited as shares.
//
// Note: On finalization, `podBalanceGwei` is added to `withdrawableRestakedExecutionLayerGwei`
// Note: On finalization, `podBalanceGwei` is added to `restakedExecutionLayerGwei`
// to denote that it has been credited with shares. Because this value is denominated in gwei,
// `podBalanceGwei` is also converted to a gwei amount here. This means that any sub-gwei amounts
// sent to the pod are not credited with shares and are therefore not withdrawable.
// This can be addressed by topping up a pod's balance to a value divisible by 1 gwei.
uint64 podBalanceGwei = uint64(address(this).balance / GWEI_TO_WEI) - withdrawableRestakedExecutionLayerGwei;
uint64 podBalanceGwei = uint64(address(this).balance / GWEI_TO_WEI) - restakedExecutionLayerGwei;

// If the caller doesn't want a "0 balance" checkpoint, revert
if (revertIfNoBalance && podBalanceGwei == 0) {
Expand Down Expand Up @@ -622,7 +622,7 @@ contract EigenPod is Initializable, ReentrancyGuardUpgradeable, EigenPodPausingC
* @dev Finish progress on a checkpoint and store it in state.
* @dev If the checkpoint has no proofs remaining, it is finalized:
* - a share delta is calculated and sent to the `EigenPodManager`
* - the checkpointed `podBalanceGwei` is added to `withdrawableRestakedExecutionLayerGwei`
* - the checkpointed `podBalanceGwei` is added to `restakedExecutionLayerGwei`
* - `lastCheckpointTimestamp` is updated
* - `_currentCheckpoint` and `currentCheckpointTimestamp` are deleted
*/
Expand All @@ -641,16 +641,16 @@ contract EigenPod is Initializable, ReentrancyGuardUpgradeable, EigenPodPausingC
// by which shares have decreased
uint256 wadSlashed = 0;
if (totalShareDeltaGwei < 0) {
uint64 totalRestakedBeforeGwei = withdrawableRestakedExecutionLayerGwei + checkpoint.prevBeaconBalanceGwei;
uint64 totalRestakedBeforeGwei = restakedExecutionLayerGwei + checkpoint.prevBeaconBalanceGwei;
uint64 totalRestakedAfterGwei = totalRestakedBeforeGwei - uint64(-totalShareDeltaGwei);

//TODO: analyze effects of rounding errors here see `test_VerifyWC_Slash_StartCP_VerifyWC_CompleteCP` for example
wadSlashed = uint256(totalRestakedAfterGwei).divWad(totalRestakedBeforeGwei);
}

// Add any native ETH in the pod to `withdrawableRestakedExecutionLayerGwei`
// Add any native ETH in the pod to `restakedExecutionLayerGwei`
// ... this amount can be withdrawn via the `DelegationManager` withdrawal queue
withdrawableRestakedExecutionLayerGwei += checkpoint.podBalanceGwei;
restakedExecutionLayerGwei += checkpoint.podBalanceGwei;

// Finalize the checkpoint
lastCheckpointTimestamp = currentCheckpointTimestamp;
Expand Down Expand Up @@ -685,6 +685,11 @@ contract EigenPod is Initializable, ReentrancyGuardUpgradeable, EigenPodPausingC
*
*/

/// @inheritdoc IEigenPod
function withdrawableRestakedExecutionLayerGwei() external view returns (uint64) {
return restakedExecutionLayerGwei;
}

/// @notice Returns the validatorInfo for a given validatorPubkeyHash
function validatorPubkeyHashToInfo(
bytes32 validatorPubkeyHash
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/pods/EigenPodStorage.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract contract EigenPodStorage is IEigenPod {
uint64 internal __deprecated_mostRecentWithdrawalTimestamp;

/// @notice the amount of execution layer ETH in this contract that is staked in EigenLayer (i.e. withdrawn from the Beacon Chain but not from EigenLayer),
uint64 public withdrawableRestakedExecutionLayerGwei;
uint64 internal restakedExecutionLayerGwei;

/// @notice DEPRECATED: previously used to track whether a pod had activated restaking
bool internal __deprecated_hasRestaked;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ contract Integration_VerifyWC_StartCP_CompleteCP is IntegrationCheckUtils {
check_StartCheckpoint_WithPodBalance_State(staker, gweiSent);

staker.completeCheckpoint();
// check that `pod.balance == withdrawableRestakedExecutionLayerGwei + remainderSent
// check that `pod.balance == restakedExecutionLayerGwei + remainderSent
assert_PodBalance_Eq(staker, (gweiSent * GWEI_TO_WEI) + remainderSent, "pod balance should equal expected");
check_CompleteCheckpoint_WithPodBalance_State(staker, gweiSent);
}
Expand Down Expand Up @@ -754,7 +754,7 @@ contract Integration_VerifyWC_StartCP_CompleteCP is IntegrationCheckUtils {
check_StartCheckpoint_WithPodBalance_State(staker, gweiSent);

staker.completeCheckpoint();
// check that `pod.balance == withdrawableRestakedExecutionLayerGwei + remainderSent
// check that `pod.balance == restakedExecutionLayerGwei + remainderSent
assert_PodBalance_Eq(staker, (gweiSent * GWEI_TO_WEI) + remainderSent, "pod balance should equal expected");
check_CompleteCheckpoint_WithPodBalance_State(staker, gweiSent);
}
Expand Down

0 comments on commit 77e28ab

Please sign in to comment.