Skip to content

Commit

Permalink
feat: add feeAmount in withdraw event
Browse files Browse the repository at this point in the history
  • Loading branch information
andreivladbrg committed Nov 19, 2024
1 parent 0d594e4 commit 2cd611a
Show file tree
Hide file tree
Showing 16 changed files with 104 additions and 32 deletions.
2 changes: 1 addition & 1 deletion src/core/abstracts/SablierLockupBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,6 @@ abstract contract SablierLockupBase is
asset.safeTransfer({ to: to, value: amount });

// Log the withdrawal.
emit ISablierLockupBase.WithdrawFromLockupStream(streamId, to, asset, amount);
emit ISablierLockupBase.WithdrawFromLockupStream(streamId, to, asset, amount, msg.value);
}
}
13 changes: 8 additions & 5 deletions src/core/interfaces/ISablierLockupBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -58,18 +58,21 @@ interface ISablierLockupBase is
address indexed admin, ILockupNFTDescriptor oldNFTDescriptor, ILockupNFTDescriptor newNFTDescriptor
);

/// @notice Emitted when the sablier fee is changed.
/// @notice Emitted when the Sablier fee is changed.
/// @param admin The address of the current contract admin.
/// @param oldSablierFee The old sablier fee.
/// @param newSablierFee The new sablier fee.
/// @param oldSablierFee The old Sablier fee.
/// @param newSablierFee The new Sablier fee.
event SetSablierFee(address indexed admin, uint256 oldSablierFee, uint256 newSablierFee);

/// @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 asset The contract address of the ERC-20 asset that has been withdrawn.
/// @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);
/// @param withdrawnAmount The amount of assets withdrawn, denoted in units of the asset's decimals.
/// @param feeAmount The fee amount of ETH transferred to the contract.
event WithdrawFromLockupStream(
uint256 indexed streamId, address indexed to, IERC20 indexed asset, uint128 withdrawnAmount, uint256 feeAmount
);

/// @notice Emitted when Sablier fees are withdrawn.
/// @param admin The address of the current contract admin.
Expand Down
10 changes: 9 additions & 1 deletion test/core/fork/LockupDynamic.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ abstract contract Lockup_Dynamic_Fork_Test is Fork_Test {
uint256 initialBrokerBalance;
uint128 totalAmount;
// Withdraw vars
uint256 initialETHLockupBalance;
uint128 actualWithdrawnAmount;
uint128 expectedWithdrawnAmount;
uint128 withdrawableAmount;
Expand Down Expand Up @@ -259,14 +260,16 @@ abstract contract Lockup_Dynamic_Fork_Test is Fork_Test {
// Load the pre-withdraw asset balances.
vars.initialLockupBalance = vars.actualLockupBalance;
vars.initialRecipientBalance = FORK_ASSET.balanceOf(params.recipient);
vars.initialETHLockupBalance = address(lockup).balance;

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockup) });
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: vars.streamId,
to: params.recipient,
asset: FORK_ASSET,
amount: params.withdrawAmount
withdrawnAmount: params.withdrawAmount,
feeAmount: SABLIER_FEE
});
vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: vars.streamId });
Expand All @@ -291,6 +294,11 @@ abstract contract Lockup_Dynamic_Fork_Test is Fork_Test {
}
assertEq(vars.actualStatus, vars.expectedStatus, "post-withdraw stream status");

// Assert that the contract's balance has been updated.
assertEq(
address(lockup).balance, vars.initialETHLockupBalance + SABLIER_FEE, "post-withdraw contract balance"
);

// Assert that the withdrawn amount has been updated.
vars.actualWithdrawnAmount = lockup.getWithdrawnAmount(vars.streamId);
vars.expectedWithdrawnAmount = params.withdrawAmount;
Expand Down
11 changes: 10 additions & 1 deletion test/core/fork/LockupLinear.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ abstract contract Lockup_Linear_Fork_Test is Fork_Test {
uint256 expectedNextStreamId;
uint256 initialBrokerBalance;
// Withdraw vars
uint256 initialETHLockupBalance;
uint128 actualWithdrawnAmount;
uint128 expectedWithdrawnAmount;
uint128 withdrawableAmount;
Expand Down Expand Up @@ -300,13 +301,16 @@ abstract contract Lockup_Linear_Fork_Test is Fork_Test {
vars.initialLockupBalance = vars.actualLockupBalance;
vars.initialRecipientBalance = FORK_ASSET.balanceOf(params.recipient);

vars.initialETHLockupBalance = address(lockup).balance;

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockup) });
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: vars.streamId,
to: params.recipient,
asset: FORK_ASSET,
amount: params.withdrawAmount
withdrawnAmount: params.withdrawAmount,
feeAmount: SABLIER_FEE
});
vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: vars.streamId });
Expand All @@ -331,6 +335,11 @@ abstract contract Lockup_Linear_Fork_Test is Fork_Test {
}
assertEq(vars.actualStatus, vars.expectedStatus, "post-withdraw stream status");

// Assert that the contract's balance has been updated.
assertEq(
address(lockup).balance, vars.initialETHLockupBalance + SABLIER_FEE, "post-withdraw contract balance"
);

// Assert that the withdrawn amount has been updated.
vars.actualWithdrawnAmount = lockup.getWithdrawnAmount(vars.streamId);
vars.expectedWithdrawnAmount = params.withdrawAmount;
Expand Down
10 changes: 9 additions & 1 deletion test/core/fork/LockupTranched.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ abstract contract Lockup_Tranched_Fork_Test is Fork_Test {
uint256 initialBrokerBalance;
uint128 totalAmount;
// Withdraw vars
uint256 initialETHLockupBalance;
uint128 actualWithdrawnAmount;
uint128 expectedWithdrawnAmount;
uint128 withdrawableAmount;
Expand Down Expand Up @@ -259,14 +260,16 @@ abstract contract Lockup_Tranched_Fork_Test is Fork_Test {
// Load the pre-withdraw asset balances.
vars.initialLockupBalance = vars.actualLockupBalance;
vars.initialRecipientBalance = FORK_ASSET.balanceOf(params.recipient);
vars.initialETHLockupBalance = address(lockup).balance;

// Expect the relevant events to be emitted.
vm.expectEmit({ emitter: address(lockup) });
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: vars.streamId,
to: params.recipient,
asset: FORK_ASSET,
amount: params.withdrawAmount
withdrawnAmount: params.withdrawAmount,
feeAmount: SABLIER_FEE
});
vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: vars.streamId });
Expand All @@ -291,6 +294,11 @@ abstract contract Lockup_Tranched_Fork_Test is Fork_Test {
}
assertEq(vars.actualStatus, vars.expectedStatus, "post-withdraw stream status");

// Assert that the contract's balance has been updated.
assertEq(
address(lockup).balance, vars.initialETHLockupBalance + SABLIER_FEE, "post-withdraw contract balance"
);

// Assert that the withdrawn amount has been updated.
vars.actualWithdrawnAmount = lockup.getWithdrawnAmount(vars.streamId);
vars.expectedWithdrawnAmount = params.withdrawAmount;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,11 @@ contract WithdrawMaxAndTransfer_Integration_Concrete_Test is Integration_Test {
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: defaultStreamId,
to: users.recipient,
amount: expectedWithdrawnAmount,
asset: dai
asset: dai,
withdrawnAmount: expectedWithdrawnAmount,
feeAmount: SABLIER_FEE
});

vm.expectEmit({ emitter: address(lockup) });
emit IERC721.Transfer({ from: users.recipient, to: users.alice, tokenId: defaultStreamId });

Expand Down Expand Up @@ -158,9 +160,11 @@ contract WithdrawMaxAndTransfer_Integration_Concrete_Test is Integration_Test {
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: defaultStreamId,
to: users.recipient,
amount: expectedWithdrawnAmount,
asset: dai
asset: dai,
withdrawnAmount: expectedWithdrawnAmount,
feeAmount: SABLIER_FEE
});

vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: defaultStreamId });
vm.expectEmit({ emitter: address(lockup) });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ contract WithdrawMax_Integration_Concrete_Test is Integration_Test {
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: defaultStreamId,
to: users.recipient,
amount: defaults.DEPOSIT_AMOUNT(),
asset: dai
asset: dai,
withdrawnAmount: defaults.DEPOSIT_AMOUNT(),
feeAmount: SABLIER_FEE
});

// Make the max withdrawal.
Expand Down Expand Up @@ -66,8 +67,9 @@ contract WithdrawMax_Integration_Concrete_Test is Integration_Test {
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: defaultStreamId,
to: users.recipient,
amount: expectedWithdrawnAmount,
asset: dai
asset: dai,
withdrawnAmount: expectedWithdrawnAmount,
feeAmount: SABLIER_FEE
});

// Make the max withdrawal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,24 @@ contract WithdrawMultiple_Integration_Concrete_Test is Integration_Test {
streamId: withdrawMultipleStreamIds[0],
to: users.recipient,
asset: dai,
amount: withdrawAmounts[0]
withdrawnAmount: withdrawAmounts[0],
feeAmount: SABLIER_FEE
});
vm.expectEmit({ emitter: address(lockup) });
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: withdrawMultipleStreamIds[1],
to: users.recipient,
asset: dai,
amount: withdrawAmounts[1]
withdrawnAmount: withdrawAmounts[1],
feeAmount: SABLIER_FEE
});
vm.expectEmit({ emitter: address(lockup) });
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: withdrawMultipleStreamIds[2],
to: users.recipient,
asset: dai,
amount: withdrawAmounts[2]
withdrawnAmount: withdrawAmounts[2],
feeAmount: SABLIER_FEE
});

// Make the withdrawals.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test {
streamId: defaultStreamId,
to: users.alice,
asset: dai,
amount: withdrawAmount
withdrawnAmount: withdrawAmount,
feeAmount: SABLIER_FEE
});
vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: defaultStreamId });
Expand Down Expand Up @@ -304,7 +305,8 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test {
streamId: defaultStreamId,
to: users.recipient,
asset: dai,
amount: withdrawAmount
withdrawnAmount: withdrawAmount,
feeAmount: SABLIER_FEE
});
vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: defaultStreamId });
Expand Down Expand Up @@ -530,7 +532,8 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test {
streamId: recipientGoodStreamId,
to: address(recipientGood),
asset: dai,
amount: withdrawAmount
withdrawnAmount: withdrawAmount,
feeAmount: SABLIER_FEE
});
vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: recipientGoodStreamId });
Expand All @@ -542,6 +545,9 @@ abstract contract Withdraw_Integration_Concrete_Test is Integration_Test {
amount: withdrawAmount
});

// Assert that the contract balance has been updated.
assertEq(address(lockup).balance, SABLIER_FEE, "contract balance");

// Assert that the stream's status is still "STREAMING".
Lockup.Status actualStatus = lockup.statusOf(recipientGoodStreamId);
Lockup.Status expectedStatus = Lockup.Status.STREAMING;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,5 @@ Withdraw_Integration_Concrete_Test
├── it should make the withdrawal
├── it should update the withdrawn amount
├── it should make Sablier run the recipient hook
├── it should transfer the ETH to the lockup contract
└── it should emit {WithdrawFromLockupStream} and {MetadataUpdate} events
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ contract GenerateAccentColor_Integration_Concrete_Test is Base_Test {
// Passing a dummy contract instead of a real Lockup contract to make this test easy to maintain.
// Note: the address of `noop` depends on the order of the state variables in {Base_Test}.
string memory actualColor = nftDescriptorMock.generateAccentColor_({ sablier: address(noop), streamId: 1337 });
string memory expectedColor = "hsl(225,28%,77%)";
string memory expectedColor = "hsl(115,39%,48%)";
assertEq(actualColor, expectedColor, "accentColor");
}
}
19 changes: 17 additions & 2 deletions test/core/integration/fuzz/lockup-base/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ abstract contract Withdraw_Integration_Fuzz_Test is Integration_Test {

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

Expand Down Expand Up @@ -182,7 +188,13 @@ abstract contract Withdraw_Integration_Fuzz_Test is Integration_Test {

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

Expand All @@ -206,6 +218,9 @@ abstract contract Withdraw_Integration_Fuzz_Test is Integration_Test {
}
assertEq(actualStatus, expectedStatus);

// Assert that the contract balance has been updated.
assertEq(address(lockup).balance, SABLIER_FEE, "contract balance");

// Assert that the withdrawn amount has been updated.
uint128 actualWithdrawnAmount = lockup.getWithdrawnAmount(defaultStreamId);
uint128 expectedWithdrawnAmount = withdrawAmount;
Expand Down
6 changes: 4 additions & 2 deletions test/core/integration/fuzz/lockup-base/withdrawMax.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ contract WithdrawMax_Integration_Fuzz_Test is Integration_Test {
streamId: defaultStreamId,
to: users.recipient,
asset: dai,
amount: defaults.DEPOSIT_AMOUNT()
withdrawnAmount: defaults.DEPOSIT_AMOUNT(),
feeAmount: SABLIER_FEE
});

// Make the max withdrawal.
Expand Down Expand Up @@ -66,7 +67,8 @@ contract WithdrawMax_Integration_Fuzz_Test is Integration_Test {
streamId: defaultStreamId,
to: users.recipient,
asset: dai,
amount: withdrawAmount
withdrawnAmount: withdrawAmount,
feeAmount: SABLIER_FEE
});

// Make the max withdrawal.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ contract WithdrawMaxAndTransfer_Integration_Fuzz_Test is Integration_Test {
streamId: defaultStreamId,
to: users.recipient,
asset: dai,
amount: withdrawAmount
withdrawnAmount: withdrawAmount,
feeAmount: SABLIER_FEE
});
}

Expand Down
9 changes: 7 additions & 2 deletions test/core/integration/fuzz/lockup-dynamic/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ contract Withdraw_Lockup_Dynamic_Integration_Fuzz_Test is
emit ISablierLockupBase.WithdrawFromLockupStream({
streamId: vars.streamId,
to: params.to,
amount: vars.withdrawAmount,
asset: dai
asset: dai,
withdrawnAmount: vars.withdrawAmount,
feeAmount: SABLIER_FEE
});

vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: vars.streamId });

Expand All @@ -130,6 +132,9 @@ contract Withdraw_Lockup_Dynamic_Integration_Fuzz_Test is
}
assertEq(vars.actualStatus, vars.expectedStatus);

// Assert that the contract balance has been updated.
assertEq(address(lockup).balance, SABLIER_FEE, "contract balance");

// Assert that the withdrawn amount has been updated.
vars.actualWithdrawnAmount = lockup.getWithdrawnAmount(vars.streamId);
vars.expectedWithdrawnAmount = vars.withdrawAmount;
Expand Down
7 changes: 6 additions & 1 deletion test/core/integration/fuzz/lockup-tranched/withdraw.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,10 @@ contract Withdraw_Lockup_Tranched_Integration_Fuzz_Test is
streamId: vars.streamId,
to: params.to,
asset: dai,
amount: vars.withdrawAmount
withdrawnAmount: vars.withdrawAmount,
feeAmount: SABLIER_FEE
});

vm.expectEmit({ emitter: address(lockup) });
emit IERC4906.MetadataUpdate({ _tokenId: vars.streamId });

Expand All @@ -129,6 +131,9 @@ contract Withdraw_Lockup_Tranched_Integration_Fuzz_Test is
}
assertEq(vars.actualStatus, vars.expectedStatus);

// Assert that the contract balance has been updated.
assertEq(address(lockup).balance, SABLIER_FEE, "contract balance");

// Assert that the withdrawn amount has been updated.
vars.actualWithdrawnAmount = lockup.getWithdrawnAmount(vars.streamId);
vars.expectedWithdrawnAmount = vars.withdrawAmount;
Expand Down

0 comments on commit 2cd611a

Please sign in to comment.