Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: complete withdrawals #962

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 19 additions & 24 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 Expand Up @@ -581,7 +559,7 @@ contract DelegationManager is
staker: withdrawal.staker,
operator: withdrawal.delegatedTo,
strategies: withdrawal.strategies,
blockNumber: completableBlock
blockNumber: completableBlock - 1
});
}

Expand Down Expand Up @@ -959,7 +937,24 @@ contract DelegationManager is
withdrawals[i] = queuedWithdrawals[withdrawalRoots[i]];
shares[i] = new uint256[](withdrawals[i].strategies.length);

uint256[] memory slashingFactors = _getSlashingFactors(staker, operator, withdrawals[i].strategies);
uint32 completableBlock = withdrawals[i].startBlock + MIN_WITHDRAWAL_DELAY_BLOCKS;

uint256[] memory slashingFactors;
// if the completion block is in the future, simply read current slashing factors
// still possible however for the slashing factors to change before the withdrawal is completable
// and the shares withdrawn to be less
if (completableBlock > uint32(block.number)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could be a ternary (no biggie tho)

slashingFactors =
_getSlashingFactors({staker: staker, operator: operator, strategies: withdrawals[i].strategies});
// Read slashing factors at the completable block
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove these from this PR

} else {
slashingFactors = _getSlashingFactorsAtBlock({
staker: staker,
operator: operator,
strategies: withdrawals[i].strategies,
blockNumber: completableBlock - 1
});
}

for (uint256 j; j < withdrawals[i].strategies.length; ++j) {
shares[i][j] = SlashingLib.scaleForCompleteWithdrawal({
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
Loading
Loading