Skip to content

Commit

Permalink
refactor: emit event before calling hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Oct 26, 2023
1 parent 91887da commit 4c945a9
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/SablierV2LockupDynamic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,9 @@ contract SablierV2LockupDynamic is
// Interactions: refund the sender.
asset.safeTransfer({ to: sender, value: senderAmount });

// Log the cancellation.
emit ISablierV2Lockup.CancelLockupStream(streamId, sender, recipient, asset, senderAmount, recipientAmount);

// Interactions: if the recipient is a contract, try to invoke the cancel hook on the recipient without
// reverting if the hook is not implemented, and without bubbling up any potential revert.
if (recipient.code.length > 0) {
Expand All @@ -522,9 +525,6 @@ contract SablierV2LockupDynamic is
recipientAmount: recipientAmount
}) { } catch { }
}

// Log the cancellation.
emit ISablierV2Lockup.CancelLockupStream(streamId, sender, recipient, asset, senderAmount, recipientAmount);
}

/// @dev See the documentation for the user-facing functions that call this internal function.
Expand Down
6 changes: 3 additions & 3 deletions src/SablierV2LockupLinear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,9 @@ contract SablierV2LockupLinear is
// Interactions: refund the sender.
asset.safeTransfer({ to: sender, value: senderAmount });

// Log the cancellation.
emit ISablierV2Lockup.CancelLockupStream(streamId, sender, recipient, asset, senderAmount, recipientAmount);

// Interactions: if the recipient is a contract, try to invoke the cancel hook on the recipient without
// reverting if the hook is not implemented, and without bubbling up any potential revert.
if (recipient.code.length > 0) {
Expand All @@ -437,9 +440,6 @@ contract SablierV2LockupLinear is
recipientAmount: recipientAmount
}) { } catch { }
}

// Log the cancellation.
emit ISablierV2Lockup.CancelLockupStream(streamId, sender, recipient, asset, senderAmount, recipientAmount);
}

/// @dev See the documentation for the user-facing functions that call this internal function.
Expand Down
6 changes: 3 additions & 3 deletions src/abstracts/SablierV2Lockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ abstract contract SablierV2Lockup is
// Checks and Effects: renounce the stream.
_renounce(streamId);

// Log the renouncement.
emit ISablierV2Lockup.RenounceLockupStream(streamId);

// Interactions: if the recipient is a contract, try to invoke the renounce hook on the recipient without
// reverting if the hook is not implemented, and also without bubbling up any potential revert.
address recipient = _ownerOf(streamId);
if (recipient.code.length > 0) {
try ISablierV2LockupRecipient(recipient).onStreamRenounced(streamId) { } catch { }
}

// Log the renouncement.
emit ISablierV2Lockup.RenounceLockupStream(streamId);
}

/// @inheritdoc ISablierV2Lockup
Expand Down
4 changes: 2 additions & 2 deletions test/utils/Precompiles.sol

Large diffs are not rendered by default.

0 comments on commit 4c945a9

Please sign in to comment.