Skip to content

Commit

Permalink
Merge pull request #705 from sablier-labs/perf/optimize-withdraw
Browse files Browse the repository at this point in the history
perf: optimize withdraw function
  • Loading branch information
PaulRBerg authored Oct 18, 2023
2 parents 6189bbc + 9c73c2f commit b07ba8f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/abstracts/SablierV2Lockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -246,13 +246,18 @@ abstract contract SablierV2Lockup is
revert Errors.SablierV2Lockup_StreamDepleted(streamId);
}

bool isCallerStreamSender = _isCallerStreamSender(streamId);

// Checks: `msg.sender` is the stream's sender, the stream's recipient, or an approved third party.
if (!_isCallerStreamSender(streamId) && !_isCallerStreamRecipientOrApproved(streamId)) {
if (!isCallerStreamSender && !_isCallerStreamRecipientOrApproved(streamId)) {
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 && to != recipient) {
revert Errors.SablierV2Lockup_InvalidSenderWithdrawal(streamId, msg.sender, to);
}

Expand All @@ -275,9 +280,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 b07ba8f

Please sign in to comment.