Skip to content

Commit

Permalink
perf: optimize withdraw function
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Oct 14, 2023
1 parent 6189bbc commit f291f6e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 deletions src/abstracts/SablierV2Lockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,11 @@ abstract contract SablierV2Lockup is
revert Errors.SablierV2Lockup_Unauthorized(streamId, msg.sender);
}

// Retrieve the recipient from storage.
address recipient = _ownerOf(streamId);

// Checks: if `msg.sender` is the stream's sender, the withdrawal address must be the recipient.
if (_isCallerStreamSender(streamId) && to != _ownerOf(streamId)) {
if (_isCallerStreamSender(streamId) && to != recipient) {
revert Errors.SablierV2Lockup_InvalidSenderWithdrawal(streamId, msg.sender, to);
}

Expand All @@ -275,9 +278,6 @@ abstract contract SablierV2Lockup is
// Effects and Interactions: make the withdrawal.
_withdraw(streamId, to, amount);

// Retrieve the recipient from storage.
address recipient = _ownerOf(streamId);

// Interactions: if `msg.sender` is not the recipient and the recipient is a contract, try to invoke the
// withdraw hook on it without reverting if the hook is not implemented, and also without bubbling up
// any potential revert.
Expand Down
Loading

0 comments on commit f291f6e

Please sign in to comment.