Skip to content

Commit 403e0a1

Browse files
eigenmikemMichael
authored andcommitted
fix: fixing 0 withdrawal issues (#1019)
* fix: fixing 0 withdrawal issues * style: white space * docs: changing description for test --------- Co-authored-by: Michael <[email protected]>
1 parent 5e626b5 commit 403e0a1

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

src/contracts/core/DelegationManager.sol

+5
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,11 @@ contract DelegationManager is
562562
slashingFactor: prevSlashingFactors[i]
563563
});
564564

565+
//Do nothing if 0 shares to withdraw
566+
if (sharesToWithdraw == 0) {
567+
continue;
568+
}
569+
565570
if (receiveAsTokens) {
566571
// Withdraws `shares` in `strategy` to `withdrawer`. If the shares are virtual beaconChainETH shares,
567572
// then a call is ultimately forwarded to the `staker`s EigenPod; otherwise a call is ultimately forwarded

src/test/unit/DelegationUnit.t.sol

+21-15
Original file line numberDiff line numberDiff line change
@@ -5946,8 +5946,8 @@ contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManage
59465946
delegationManager.completeQueuedWithdrawal(withdrawal, tokens, receiveAsTokens);
59475947
}
59485948

5949-
/// @notice Verifies that when we complete a withdrawal as shares after a full slash, we revert
5950-
function test_revert_fullySlashed() public {
5949+
/// @notice Verifies that when we complete a withdrawal as shares after a full slash, we clear the withdrawal
5950+
function test_clearWithdrawal_fullySlashed() public {
59515951
// Register operator
59525952
_registerOperatorWithBaseDetails(defaultOperator);
59535953
_setOperatorMagnitude(defaultOperator, strategyMock, WAD);
@@ -5978,12 +5978,22 @@ contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManage
59785978
cheats.prank(address(allocationManagerMock));
59795979
delegationManager.slashOperatorShares(defaultOperator, strategyMock, WAD, 0);
59805980

5981-
// Complete withdrawal as shares and assert that operator has no shares increased
5981+
// Complete withdrawal as shares and check that withdrawal was cleared
59825982
cheats.roll(block.number + 1);
59835983
IERC20[] memory tokens = strategyMock.underlyingToken().toArray();
5984-
cheats.expectRevert(FullySlashed.selector);
5984+
5985+
bytes32 withdrawalRoot = delegationManager.calculateWithdrawalRoot(withdrawal);
5986+
assertTrue(delegationManager.pendingWithdrawals(withdrawalRoot), "withdrawal should be pending before completion");
5987+
59855988
cheats.prank(defaultStaker);
59865989
delegationManager.completeQueuedWithdrawal(withdrawal, tokens, false);
5990+
5991+
assertFalse(delegationManager.pendingWithdrawals(withdrawalRoot), "withdrawal should be cleared after completion");
5992+
5993+
// Assert that no shares were added back
5994+
assertEq(delegationManager.operatorShares(defaultOperator, strategyMock), 0, "operator shares should remain 0");
5995+
(uint256[] memory withdrawableShares, ) = delegationManager.getWithdrawableShares(defaultStaker, strategyMock.toArray());
5996+
assertEq(withdrawableShares[0], 0, "withdrawable shares should be 0");
59875997
}
59885998

59895999
/**
@@ -6631,22 +6641,18 @@ contract DelegationManagerUnitTests_slashingShares is DelegationManagerUnitTests
66316641

66326642
uint256 slashableSharesInQueueAfter = delegationManager.getSlashableSharesInQueue(defaultOperator, strategyMock);
66336643

6634-
// Complete withdrawal as tokens and assert that nothing is returned
6644+
// Complete withdrawal as tokens and assert that nothing is returned and withdrawal is cleared
66356645
cheats.roll(block.number + 1);
66366646
IERC20[] memory tokens = strategyMock.underlyingToken().toArray();
6637-
cheats.expectCall(
6638-
address(strategyManagerMock),
6639-
abi.encodeWithSelector(
6640-
IShareManager.withdrawSharesAsTokens.selector,
6641-
defaultStaker,
6642-
strategyMock,
6643-
strategyMock.underlyingToken(),
6644-
0
6645-
)
6646-
);
6647+
6648+
bytes32 withdrawalRoot = delegationManager.calculateWithdrawalRoot(withdrawal);
6649+
assertTrue(delegationManager.pendingWithdrawals(withdrawalRoot), "withdrawal should be pending before completion");
6650+
66476651
cheats.prank(defaultStaker);
66486652
delegationManager.completeQueuedWithdrawal(withdrawal, tokens, true);
66496653

6654+
assertFalse(delegationManager.pendingWithdrawals(withdrawalRoot), "withdrawal should be cleared after completion");
6655+
66506656
assertEq(
66516657
slashableSharesInQueue,
66526658
depositAmount,

0 commit comments

Comments
 (0)