Use batch withdrawals for gas savings
When the Lido withdrawal queue is called to claim withdrawals, claimWithdrawal
is called in a loop:
function _claimWithdrawals(address user, uint256[] memory requestIds) internal returns (uint256) {
uint256 beforeBalance = address(this).balance;
// Claim Ether for the burned stETH positions
// this will fail if the request is not finalized
for (uint i = 0; i < requestIds.length; i++) {
lidoWithdrawalQueue.claimWithdrawal(requestIds[i]);
}
uint256 withdrawnAmount = address(this).balance - beforeBalance;
require(withdrawnAmount > 0, "IWA");
emit WithdrawalClaimed(withdrawnAmount, requestIds, user);
return withdrawnAmount;
}
However, according to the Lido documentation↗, if a caller wishes to claim multiple withdrawals, the recommended way to do this is to call claimWithdrawals(uint256[] _requestIDs, uint256[] _hints)
.
This saves gas by not having to emit multiple external calls. The hints can be passed from the caller all the way into this function after having been computed off chain.