Skip to content

Commit

Permalink
fix: remove numtocomplete interface (#966)
Browse files Browse the repository at this point in the history
  • Loading branch information
8sunyuan authored and ypatil12 committed Jan 3, 2025
1 parent fab4096 commit 8ae524a
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 121 deletions.
22 changes: 0 additions & 22 deletions src/contracts/core/DelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 0 additions & 14 deletions src/contracts/interfaces/IDelegationManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
88 changes: 3 additions & 85 deletions src/test/unit/DelegationUnit.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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");
Expand Down

0 comments on commit 8ae524a

Please sign in to comment.