Skip to content

Commit

Permalink
refactor: add "recipient" in cancel event
Browse files Browse the repository at this point in the history
docs: refine explanatory comments
refactor: reorder parameters in events
  • Loading branch information
PaulRBerg committed Oct 18, 2023
1 parent 927cedd commit b69d326
Show file tree
Hide file tree
Showing 16 changed files with 57 additions and 46 deletions.
10 changes: 5 additions & 5 deletions src/SablierV2LockupDynamic.sol
Original file line number Diff line number Diff line change
Expand Up @@ -506,14 +506,14 @@ contract SablierV2LockupDynamic is
address sender = _streams[streamId].sender;
address recipient = _ownerOf(streamId);

// Retrieve the ERC-20 asset from storage.
IERC20 asset = _streams[streamId].asset;

// Interactions: refund the sender.
asset.safeTransfer({ to: sender, value: senderAmount });

// 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.
// 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) {
try ISablierV2LockupRecipient(recipient).onStreamCanceled({
streamId: streamId,
Expand All @@ -524,7 +524,7 @@ contract SablierV2LockupDynamic is
}

// Log the cancellation.
emit ISablierV2Lockup.CancelLockupStream(streamId, sender, asset, senderAmount, recipientAmount);
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 Expand Up @@ -642,6 +642,6 @@ contract SablierV2LockupDynamic is
asset.safeTransfer({ to: to, value: amount });

// Log the withdrawal.
emit ISablierV2Lockup.WithdrawFromLockupStream(streamId, to, amount, asset);
emit ISablierV2Lockup.WithdrawFromLockupStream(streamId, to, asset, amount);
}
}
10 changes: 5 additions & 5 deletions src/SablierV2LockupLinear.sol
Original file line number Diff line number Diff line change
Expand Up @@ -421,14 +421,14 @@ contract SablierV2LockupLinear is
address sender = _streams[streamId].sender;
address recipient = _ownerOf(streamId);

// Retrieve the ERC-20 asset from storage.
IERC20 asset = _streams[streamId].asset;

// Interactions: refund the sender.
asset.safeTransfer({ to: sender, value: senderAmount });

// 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.
// 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) {
try ISablierV2LockupRecipient(recipient).onStreamCanceled({
streamId: streamId,
Expand All @@ -439,7 +439,7 @@ contract SablierV2LockupLinear is
}

// Log the cancellation.
emit ISablierV2Lockup.CancelLockupStream(streamId, sender, asset, senderAmount, recipientAmount);
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 Expand Up @@ -548,6 +548,6 @@ contract SablierV2LockupLinear is
asset.safeTransfer({ to: to, value: amount });

// Log the withdrawal.
emit ISablierV2Lockup.WithdrawFromLockupStream(streamId, to, amount, asset);
emit ISablierV2Lockup.WithdrawFromLockupStream(streamId, to, asset, amount);
}
}
8 changes: 5 additions & 3 deletions src/interfaces/ISablierV2Lockup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,16 @@ interface ISablierV2Lockup is
/// @notice Emitted when a stream is canceled.
/// @param streamId The id of the stream.
/// @param sender The address of the stream's sender.
/// @param recipient The address of the stream's recipient.
/// @param asset The contract address of the ERC-20 asset used for streaming.
/// @param senderAmount The amount of assets refunded to the stream's sender, denoted in units of the asset's
/// decimals.
/// @param recipientAmount The amount of assets left for the stream's recipient to withdraw, denoted in units of the
/// asset's decimals.
event CancelLockupStream(
uint256 indexed streamId,
uint256 streamId,
address indexed sender,
address indexed recipient,
IERC20 indexed asset,
uint128 senderAmount,
uint128 recipientAmount
Expand All @@ -49,9 +51,9 @@ interface ISablierV2Lockup is
/// @notice Emitted when assets are withdrawn from a stream.
/// @param streamId The id of the stream.
/// @param to The address that has received the withdrawn assets.
/// @param amount The amount of assets withdrawn, denoted in units of the asset's decimals.
/// @param asset The contract address of the ERC-20 asset used for streaming.
event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, uint128 amount, IERC20 indexed asset);
/// @param amount The amount of assets withdrawn, denoted in units of the asset's decimals.
event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, IERC20 indexed asset, uint128 amount);

/*//////////////////////////////////////////////////////////////////////////
CONSTANT FUNCTIONS
Expand Down
8 changes: 5 additions & 3 deletions test/fork/LockupDynamic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,8 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
emit WithdrawFromLockupStream({
streamId: vars.streamId,
to: params.recipient,
amount: params.withdrawAmount,
asset: ASSET
asset: ASSET,
amount: params.withdrawAmount
});
vm.expectEmit({ emitter: address(lockupDynamic) });
emit MetadataUpdate({ _tokenId: vars.streamId });
Expand Down Expand Up @@ -351,7 +351,9 @@ abstract contract LockupDynamic_Fork_Test is Fork_Test {
vm.expectEmit({ emitter: address(lockupDynamic) });
vars.senderAmount = lockupDynamic.refundableAmountOf(vars.streamId);
vars.recipientAmount = lockupDynamic.withdrawableAmountOf(vars.streamId);
emit CancelLockupStream(vars.streamId, params.sender, ASSET, vars.senderAmount, vars.recipientAmount);
emit CancelLockupStream(
vars.streamId, params.sender, params.recipient, ASSET, vars.senderAmount, vars.recipientAmount
);
vm.expectEmit({ emitter: address(lockupDynamic) });
emit MetadataUpdate({ _tokenId: vars.streamId });

Expand Down
8 changes: 5 additions & 3 deletions test/fork/LockupLinear.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
emit WithdrawFromLockupStream({
streamId: vars.streamId,
to: params.recipient,
amount: params.withdrawAmount,
asset: ASSET
asset: ASSET,
amount: params.withdrawAmount
});
vm.expectEmit({ emitter: address(lockupLinear) });
emit MetadataUpdate({ _tokenId: vars.streamId });
Expand Down Expand Up @@ -335,7 +335,9 @@ abstract contract LockupLinear_Fork_Test is Fork_Test {
vm.expectEmit({ emitter: address(lockupLinear) });
vars.senderAmount = lockupLinear.refundableAmountOf(vars.streamId);
vars.recipientAmount = lockupLinear.withdrawableAmountOf(vars.streamId);
emit CancelLockupStream(vars.streamId, params.sender, ASSET, vars.senderAmount, vars.recipientAmount);
emit CancelLockupStream(
vars.streamId, params.sender, params.recipient, ASSET, vars.senderAmount, vars.recipientAmount
);
vm.expectEmit({ emitter: address(lockupLinear) });
emit MetadataUpdate({ _tokenId: vars.streamId });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ abstract contract CancelMultiple_Integration_Concrete_Test is
givenAllStreamsWarm
whenCallerUnauthorized
{
// Make the recipient the caller in this test.
// Make the Recipient the caller in this test.
changePrank({ msgSender: users.recipient });

// Run the test.
Expand Down Expand Up @@ -119,7 +119,7 @@ abstract contract CancelMultiple_Integration_Concrete_Test is
givenAllStreamsWarm
whenCallerUnauthorized
{
// Make the recipient the caller in this test.
// Make the Recipient the caller in this test.
changePrank({ msgSender: users.recipient });

// Run the test.
Expand Down Expand Up @@ -181,6 +181,7 @@ abstract contract CancelMultiple_Integration_Concrete_Test is
emit CancelLockupStream({
streamId: testStreamIds[0],
sender: users.sender,
recipient: users.recipient,
asset: dai,
senderAmount: senderAmount0,
recipientAmount: defaults.DEPOSIT_AMOUNT() - senderAmount0
Expand All @@ -189,6 +190,7 @@ abstract contract CancelMultiple_Integration_Concrete_Test is
emit CancelLockupStream({
streamId: testStreamIds[1],
sender: users.sender,
recipient: users.recipient,
asset: dai,
senderAmount: senderAmount1,
recipientAmount: defaults.DEPOSIT_AMOUNT() - senderAmount1
Expand Down
4 changes: 2 additions & 2 deletions test/integration/concrete/lockup/cancel/cancel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ abstract contract Cancel_Integration_Concrete_Test is Integration_Test, Cancel_I
givenStreamWarm
whenCallerUnauthorized
{
// Make recipient the caller in this test.
// Make the Recipient the caller in this test.
changePrank({ msgSender: users.recipient });

// Run the test.
Expand Down Expand Up @@ -255,7 +255,7 @@ abstract contract Cancel_Integration_Concrete_Test is Integration_Test, Cancel_I

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockup) });
emit CancelLockupStream(streamId, users.sender, dai, senderAmount, recipientAmount);
emit CancelLockupStream(streamId, users.sender, address(goodRecipient), dai, senderAmount, recipientAmount);
vm.expectEmit({ emitter: address(lockup) });
emit MetadataUpdate({ _tokenId: streamId });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -310,22 +310,22 @@ abstract contract WithdrawMultiple_Integration_Concrete_Test is
emit WithdrawFromLockupStream({
streamId: testStreamIds[0],
to: users.recipient,
amount: testAmounts[0],
asset: dai
asset: dai,
amount: testAmounts[0]
});
vm.expectEmit({ emitter: address(lockup) });
emit WithdrawFromLockupStream({
streamId: testStreamIds[1],
to: users.recipient,
amount: testAmounts[1],
asset: dai
asset: dai,
amount: testAmounts[1]
});
vm.expectEmit({ emitter: address(lockup) });
emit WithdrawFromLockupStream({
streamId: testStreamIds[2],
to: users.recipient,
amount: testAmounts[2],
asset: dai
asset: dai,
amount: testAmounts[2]
});

// Make the withdrawals.
Expand Down
8 changes: 4 additions & 4 deletions test/integration/concrete/lockup/withdraw/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -299,8 +299,8 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
emit WithdrawFromLockupStream({
streamId: defaultStreamId,
to: users.recipient,
amount: withdrawAmount,
asset: dai
asset: dai,
amount: withdrawAmount
});

// Make the withdrawal.
Expand Down Expand Up @@ -499,8 +499,8 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test, Withdr
emit WithdrawFromLockupStream({
streamId: streamId,
to: address(goodRecipient),
amount: withdrawAmount,
asset: dai
asset: dai,
amount: withdrawAmount
});
vm.expectEmit({ emitter: address(lockup) });
emit MetadataUpdate({ _tokenId: streamId });
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fuzz/lockup/cancel.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ abstract contract Cancel_Integration_Fuzz_Test is Integration_Test, Cancel_Integ
// Expect the relevant events to be emitted.
uint128 recipientAmount = lockup.withdrawableAmountOf(streamId);
vm.expectEmit({ emitter: address(lockup) });
emit CancelLockupStream(streamId, users.sender, dai, senderAmount, recipientAmount);
emit CancelLockupStream(streamId, users.sender, address(goodRecipient), dai, senderAmount, recipientAmount);
vm.expectEmit({ emitter: address(lockup) });
emit MetadataUpdate({ _tokenId: streamId });

Expand Down
2 changes: 2 additions & 0 deletions test/integration/fuzz/lockup/cancelMultiple.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ abstract contract CancelMultiple_Integration_Fuzz_Test is Integration_Test, Canc
emit CancelLockupStream({
streamId: streamIds[0],
sender: users.sender,
recipient: users.recipient,
asset: dai,
senderAmount: senderAmount0,
recipientAmount: defaults.DEPOSIT_AMOUNT() - senderAmount0
Expand All @@ -55,6 +56,7 @@ abstract contract CancelMultiple_Integration_Fuzz_Test is Integration_Test, Canc
emit CancelLockupStream({
streamId: streamIds[1],
sender: users.sender,
recipient: users.recipient,
asset: dai,
senderAmount: senderAmount1,
recipientAmount: defaults.DEPOSIT_AMOUNT() - senderAmount1
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fuzz/lockup/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ abstract contract Withdraw_Integration_Fuzz_Test is Integration_Test, Withdraw_I

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockup) });
emit WithdrawFromLockupStream(defaultStreamId, to, withdrawAmount, dai);
emit WithdrawFromLockupStream(defaultStreamId, to, dai, withdrawAmount);
vm.expectEmit({ emitter: address(lockup) });
emit MetadataUpdate({ _tokenId: defaultStreamId });

Expand Down Expand Up @@ -152,7 +152,7 @@ abstract contract Withdraw_Integration_Fuzz_Test is Integration_Test, Withdraw_I

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockup) });
emit WithdrawFromLockupStream(defaultStreamId, to, withdrawAmount, dai);
emit WithdrawFromLockupStream(defaultStreamId, to, dai, withdrawAmount);
vm.expectEmit({ emitter: address(lockup) });
emit MetadataUpdate({ _tokenId: defaultStreamId });

Expand Down
8 changes: 4 additions & 4 deletions test/integration/fuzz/lockup/withdrawMax.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ abstract contract WithdrawMax_Integration_Fuzz_Test is Integration_Test, Withdra
emit WithdrawFromLockupStream({
streamId: defaultStreamId,
to: users.recipient,
amount: defaults.DEPOSIT_AMOUNT(),
asset: dai
asset: dai,
amount: defaults.DEPOSIT_AMOUNT()
});

// Make the max withdrawal.
Expand Down Expand Up @@ -69,8 +69,8 @@ abstract contract WithdrawMax_Integration_Fuzz_Test is Integration_Test, Withdra
emit WithdrawFromLockupStream({
streamId: defaultStreamId,
to: users.recipient,
amount: withdrawAmount,
asset: dai
asset: dai,
amount: withdrawAmount
});

// Make the max withdrawal.
Expand Down
4 changes: 2 additions & 2 deletions test/integration/fuzz/lockup/withdrawMaxAndTransfer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ abstract contract WithdrawMaxAndTransfer_Integration_Fuzz_Test is
emit WithdrawFromLockupStream({
streamId: defaultStreamId,
to: users.recipient,
amount: withdrawAmount,
asset: dai
asset: dai,
amount: withdrawAmount
});
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/fuzz/lockup/withdrawMultiple.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ abstract contract WithdrawMultiple_Integration_Fuzz_Test is

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockup) });
emit WithdrawFromLockupStream({ streamId: ongoingStreamId, to: to, amount: ongoingWithdrawAmount, asset: dai });
emit WithdrawFromLockupStream({ streamId: ongoingStreamId, to: to, asset: dai, amount: ongoingWithdrawAmount });
vm.expectEmit({ emitter: address(lockup) });
emit WithdrawFromLockupStream({ streamId: settledStreamId, to: to, amount: settledWithdrawAmount, asset: dai });
emit WithdrawFromLockupStream({ streamId: settledStreamId, to: to, asset: dai, amount: settledWithdrawAmount });

// Make the withdrawals.
uint256[] memory streamIds = Solarray.uint256s(ongoingStreamId, settledStreamId);
Expand Down
5 changes: 3 additions & 2 deletions test/utils/Events.sol
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,9 @@ abstract contract Events {
//////////////////////////////////////////////////////////////////////////*/

event CancelLockupStream(
uint256 indexed streamId,
uint256 streamId,
address indexed sender,
address indexed recipient,
IERC20 indexed asset,
uint128 senderAmount,
uint128 recipientAmount
Expand All @@ -82,7 +83,7 @@ abstract contract Events {
address indexed admin, ISablierV2NFTDescriptor oldNFTDescriptor, ISablierV2NFTDescriptor newNFTDescriptor
);

event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, uint128 amount, IERC20 indexed asset);
event WithdrawFromLockupStream(uint256 indexed streamId, address indexed to, IERC20 indexed asset, uint128 amount);

/*//////////////////////////////////////////////////////////////////////////
SABLIER-V2-LOCKUP-DYNAMIC
Expand Down

0 comments on commit b69d326

Please sign in to comment.