Skip to content

Commit

Permalink
added forceWithdraw function to WithdrawalPool
Browse files Browse the repository at this point in the history
  • Loading branch information
BkChoy committed Nov 20, 2024
1 parent 4e1c698 commit 7e8d573
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions contracts/core/priorityPool/WithdrawalPool.sol
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,39 @@ contract WithdrawalPool is UUPSUpgradeable, OwnableUpgradeable {
emit Withdraw(owner, amountToWithdraw);
}

/**
* @notice Executes a group of fully finalized withdrawals
* @dev used by owner in the case that withdrawalBatchIdCutoff cannot be updated due to
* outstanding withdrawals
* @param _withdrawalIds list of withdrawal ids to execute
* @param _batchIds list of batch ids corresponding to withdrawal ids
*/
function forceWithdraw(
uint256[] calldata _withdrawalIds,
uint256[] calldata _batchIds
) external onlyOwner {
for (uint256 i = 0; i < _withdrawalIds.length; ++i) {
uint256 withdrawalId = _withdrawalIds[i];
Withdrawal memory withdrawal = queuedWithdrawals[_withdrawalIds[i]];
uint256 batchId = _batchIds[i];
WithdrawalBatch memory batch = withdrawalBatches[batchId];
address owner = withdrawalOwners[withdrawalId];

if (withdrawalId <= withdrawalBatches[batchId - 1].indexOfLastWithdrawal)
revert InvalidWithdrawalId();
if (withdrawalId > batch.indexOfLastWithdrawal) revert InvalidWithdrawalId();

uint256 amountToWithdraw = withdrawal.partiallyWithdrawableAmount +
(uint256(batch.stakePerShares) * uint256(withdrawal.sharesRemaining)) /
1e18;
delete queuedWithdrawals[withdrawalId];
delete withdrawalOwners[withdrawalId];

token.safeTransfer(owner, amountToWithdraw);
emit Withdraw(owner, amountToWithdraw);
}
}

/**
* @notice Queues a withdrawal of liquid staking tokens for an account
* @param _account address of account
Expand Down

0 comments on commit 7e8d573

Please sign in to comment.