From 336190dd04e83dd0139f65e78f0819ffc418ccd8 Mon Sep 17 00:00:00 2001 From: Michael Sun Date: Tue, 17 Dec 2024 20:08:32 -0500 Subject: [PATCH] fix: remove numtocomplete interface --- src/contracts/core/DelegationManager.sol | 22 ----- .../interfaces/IDelegationManager.sol | 14 --- src/test/unit/DelegationUnit.t.sol | 88 +------------------ 3 files changed, 3 insertions(+), 121 deletions(-) diff --git a/src/contracts/core/DelegationManager.sol b/src/contracts/core/DelegationManager.sol index 5b827ebb5..481335aa6 100644 --- a/src/contracts/core/DelegationManager.sol +++ b/src/contracts/core/DelegationManager.sol @@ -241,28 +241,6 @@ contract DelegationManager is } } - /// @inheritdoc IDelegationManager - function completeQueuedWithdrawals( - IERC20[][] calldata tokens, - bool[] calldata receiveAsTokens, - uint256 numToComplete - ) external onlyWhenNotPaused(PAUSED_EXIT_WITHDRAWAL_QUEUE) nonReentrant { - EnumerableSet.Bytes32Set storage withdrawalRoots = _stakerQueuedWithdrawalRoots[msg.sender]; - uint256 length = withdrawalRoots.length(); - numToComplete = numToComplete > length ? length : numToComplete; - - // Read withdrawals to complete. We use 2 seperate loops here because the second - // loop will remove elements by index from `withdrawalRoots`. - Withdrawal[] memory withdrawals = new Withdrawal[](numToComplete); - for (uint256 i; i < withdrawals.length; ++i) { - withdrawals[i] = queuedWithdrawals[withdrawalRoots.at(i)]; - } - - for (uint256 i; i < withdrawals.length; ++i) { - _completeQueuedWithdrawal(withdrawals[i], tokens[i], receiveAsTokens[i]); - } - } - /// @inheritdoc IDelegationManager function increaseDelegatedShares( address staker, diff --git a/src/contracts/interfaces/IDelegationManager.sol b/src/contracts/interfaces/IDelegationManager.sol index 806f06adf..86bee3452 100644 --- a/src/contracts/interfaces/IDelegationManager.sol +++ b/src/contracts/interfaces/IDelegationManager.sol @@ -288,20 +288,6 @@ interface IDelegationManager is ISignatureUtils, IDelegationManagerErrors, IDele QueuedWithdrawalParams[] calldata params ) external returns (bytes32[] memory); - /** - * @notice Used to complete the all queued withdrawals. - * Used to complete the specified `withdrawals`. The function caller must match `withdrawals[...].withdrawer` - * @param tokens Array of tokens for each Withdrawal. See `completeQueuedWithdrawal` for the usage of a single array. - * @param receiveAsTokens Whether or not to complete each withdrawal as tokens. See `completeQueuedWithdrawal` for the usage of a single boolean. - * @param numToComplete The number of withdrawals to complete. This must be less than or equal to the number of queued withdrawals. - * @dev See `completeQueuedWithdrawal` for relevant dev tags - */ - function completeQueuedWithdrawals( - IERC20[][] calldata tokens, - bool[] calldata receiveAsTokens, - uint256 numToComplete - ) external; - /** * @notice Used to complete the lastest queued withdrawal. * @param withdrawal The withdrawal to complete. diff --git a/src/test/unit/DelegationUnit.t.sol b/src/test/unit/DelegationUnit.t.sol index 386fe0b18..d4204f104 100644 --- a/src/test/unit/DelegationUnit.t.sol +++ b/src/test/unit/DelegationUnit.t.sol @@ -5887,10 +5887,6 @@ contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManage // multiple Withdrawal interface cheats.expectRevert(IPausable.CurrentlyPaused.selector); delegationManager.completeQueuedWithdrawals(withdrawals, tokensArray, receiveAsTokens); - - // numToComplete interface - cheats.expectRevert(IPausable.CurrentlyPaused.selector); - delegationManager.completeQueuedWithdrawals(tokensArray, receiveAsTokens, 1); } function test_Revert_WhenInputArrayLengthMismatch() public { @@ -5918,16 +5914,6 @@ contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManage cheats.expectRevert(InputArrayLengthMismatch.selector); delegationManager.completeQueuedWithdrawal(withdrawal, newTokens, false); - IERC20[][] memory tokensArray = new IERC20[][](1); - tokensArray[0] = newTokens; - - bool[] memory receiveAsTokens = new bool[](1); - receiveAsTokens[0] = true; - - cheats.prank(defaultStaker); - cheats.expectRevert(InputArrayLengthMismatch.selector); - delegationManager.completeQueuedWithdrawals(tokensArray, receiveAsTokens, 1); - // check that the withdrawal completes otherwise cheats.prank(defaultStaker); delegationManager.completeQueuedWithdrawal(withdrawal, tokens, true); @@ -6012,16 +5998,6 @@ contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManage cheats.expectRevert(WithdrawalDelayNotElapsed.selector); cheats.prank(defaultStaker); delegationManager.completeQueuedWithdrawal(withdrawal, tokens, receiveAsTokens); - - IERC20[][] memory tokensArray = new IERC20[][](1); - tokensArray[0] = tokens; - - bool[] memory receiveAsTokensArray = new bool[](1); - receiveAsTokensArray[0] = false; - - cheats.expectRevert(WithdrawalDelayNotElapsed.selector); - cheats.prank(defaultStaker); - delegationManager.completeQueuedWithdrawals(tokensArray, receiveAsTokensArray, 1); } /** @@ -6108,63 +6084,6 @@ contract DelegationManagerUnitTests_completeQueuedWithdrawal is DelegationManage ); } - /** - * Test completing multiple queued withdrawals for a single strategy without passing in the withdrawals - */ - function test_completeQueuedWithdrawals_NumToComplete(Randomness r) public rand(r) { - address staker = r.Address(); - uint256 depositAmount = r.Uint256(1, MAX_STRATEGY_SHARES); - uint256 numWithdrawals = r.Uint256(2, 20); - uint256 numToComplete = r.Uint256(2, numWithdrawals); - - ( - Withdrawal[] memory withdrawals, - IERC20[][] memory tokens, - bytes32[] memory withdrawalRoots - ) = _setUpCompleteQueuedWithdrawalsSingleStrat({ - staker: staker, - withdrawer: staker, - depositAmount: depositAmount, - numWithdrawals: numWithdrawals - }); - - _registerOperatorWithBaseDetails(defaultOperator); - _delegateToOperatorWhoAcceptsAllStakers(staker, defaultOperator); - uint256 operatorSharesBefore = delegationManager.operatorShares(defaultOperator, withdrawals[0].strategies[0]); - - for (uint i = 0; i < withdrawalRoots.length; i++) { - assertTrue(delegationManager.pendingWithdrawals(withdrawalRoots[i]), "withdrawalRoots should be pending"); - } - - bool[] memory receiveAsTokens = new bool[](withdrawals.length); - for (uint i = 0; i < withdrawals.length; i++) { - receiveAsTokens[i] = true; - } - - // completeQueuedWithdrawal - cheats.roll(withdrawals[0].startBlock + delegationManager.minWithdrawalDelayBlocks()); - _completeQueuedWithdrawals_expectEmit( - CompleteQueuedWithdrawalsEmitStruct({ - withdrawals: withdrawals, - tokens: tokens, - receiveAsTokens: receiveAsTokens - }) - ); - cheats.prank(staker); - delegationManager.completeQueuedWithdrawals(tokens, receiveAsTokens, numToComplete); - - uint256 operatorSharesAfter = delegationManager.operatorShares(defaultOperator, withdrawals[0].strategies[0]); - assertEq(operatorSharesAfter, operatorSharesBefore, "operator shares should be unchanged"); - - for (uint i = 0; i < numToComplete; i++) { - assertFalse(delegationManager.pendingWithdrawals(withdrawalRoots[i]), "withdrawalRoot should be completed and marked false now"); - } - - for (uint i = numToComplete; i < numWithdrawals; i++) { - assertTrue(delegationManager.pendingWithdrawals(withdrawalRoots[i]), "withdrawalRoot should still be pending"); - } - } - /** * @notice Verifies that `DelegationManager.completeQueuedWithdrawal` properly completes a queued withdrawal for the `withdrawer` * for a single strategy. @@ -8263,10 +8182,9 @@ contract DelegationManagerUnitTests_Lifecycle is DelegationManagerUnitTests { assertEq(stakerWithdrawableShares[0], 0, "staker withdrawable shares not calculated correctly"); assertEq(depositShares[0], 0, "staker deposit shares not reset correctly"); - bool[] memory receiveAsTokens = new bool[](1); - receiveAsTokens[0] = false; - IERC20[][] memory tokens = new IERC20[][](1); - delegationManager.completeQueuedWithdrawals(tokens, receiveAsTokens, 1); + cheats.roll(withdrawal.startBlock + delegationManager.minWithdrawalDelayBlocks() + 1); + cheats.prank(defaultStaker); + delegationManager.completeQueuedWithdrawal(withdrawal, tokenMock.toArray(), false); (stakerWithdrawableShares, depositShares) = delegationManager.getWithdrawableShares(defaultStaker, strategyArray); assertEq(stakerWithdrawableShares[0], 0, "staker withdrawable shares not calculated correctly");