/**
* @dev Withdraws a VotingEscrow token back to the depositor after the vesting period. The function restores the
* remaining vesting duration and transfers the token back to the depositor.
*
* @param receiver The address to receive the withdrawn VotingEscrow token.
* @param tokenId The identifier of the VotingEscrow token to be withdrawn.
*/
function withdraw(address receiver, uint256 tokenId) external nonReentrant {
if (depositors[tokenId] != msg.sender) {
revert NotAuthorized(msg.sender);
}
VestingSchedule storage tokenSchedule = vestingSchedules[tokenId];
uint256 endTime = tokenSchedule.endTime;
uint256 remainingTime;
if (endTime > block.timestamp) {
unchecked {
remainingTime = endTime - block.timestamp;
}
}
_removeTokenFromDepositorEnumeration(msg.sender, tokenId);
delete vestingSchedules[tokenId];
votingEscrow.updateVestingDuration(tokenId, remainingTime);
votingEscrow.transferFrom(address(this), receiver, tokenId);
}
Recommendation:
We advise an if conditional to wrap the function invocation, ensuring that it is performed solely when it needs to and thereby optimizing the gas cost of the VotingEscrowVesting::withdraw function.
VEV-05C: Unconditional Configuration of Vesting Duration
Description:
The
VotingEscrowVesting::withdraw
function will perform a redundant call toRWAVotingEscrow::updateVestingDuration
when theremainingTime
is0
.Example:
Recommendation:
We advise an
if
conditional to wrap the function invocation, ensuring that it is performed solely when it needs to and thereby optimizing the gas cost of theVotingEscrowVesting::withdraw
function.