Skip to content

Commit 34e14ce

Browse files
feat: add CreateBatchLockup event in BatchLockup (#1274)
* feat: emit funder in Lockup create events feat: emit event in BatchLockup create functions * refactor: rename to CreateBatchLockup --------- Co-authored-by: Paul Razvan Berg <[email protected]>
1 parent 081a298 commit 34e14ce

25 files changed

+90
-25
lines changed

src/SablierBatchLockup.sol

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,9 @@ contract SablierBatchLockup is ISablierBatchLockup {
8383
batch[i].segmentsWithDuration
8484
);
8585
}
86+
87+
// Log the creation of the batch of streams.
88+
emit ISablierBatchLockup.CreateLockupBatch({ funder: msg.sender, lockup: lockup, streamIds: streamIds });
8689
}
8790

8891
/// @inheritdoc ISablierBatchLockup
@@ -139,6 +142,9 @@ contract SablierBatchLockup is ISablierBatchLockup {
139142
batch[i].segments
140143
);
141144
}
145+
146+
// Log the creation of the batch of streams.
147+
emit ISablierBatchLockup.CreateLockupBatch({ funder: msg.sender, lockup: lockup, streamIds: streamIds });
142148
}
143149

144150
/// @inheritdoc ISablierBatchLockup
@@ -188,6 +194,9 @@ contract SablierBatchLockup is ISablierBatchLockup {
188194
batch[i].durations
189195
);
190196
}
197+
198+
// Log the creation of the batch of streams.
199+
emit ISablierBatchLockup.CreateLockupBatch({ funder: msg.sender, lockup: lockup, streamIds: streamIds });
191200
}
192201

193202
/// @inheritdoc ISablierBatchLockup
@@ -238,6 +247,9 @@ contract SablierBatchLockup is ISablierBatchLockup {
238247
batch[i].cliffTime
239248
);
240249
}
250+
251+
// Log the creation of the batch of streams.
252+
emit ISablierBatchLockup.CreateLockupBatch({ funder: msg.sender, lockup: lockup, streamIds: streamIds });
241253
}
242254

243255
/// @inheritdoc ISablierBatchLockup
@@ -286,6 +298,9 @@ contract SablierBatchLockup is ISablierBatchLockup {
286298
batch[i].tranchesWithDuration
287299
);
288300
}
301+
302+
// Log the creation of the batch of streams.
303+
emit ISablierBatchLockup.CreateLockupBatch({ funder: msg.sender, lockup: lockup, streamIds: streamIds });
289304
}
290305

291306
/// @inheritdoc ISablierBatchLockup
@@ -342,6 +357,9 @@ contract SablierBatchLockup is ISablierBatchLockup {
342357
batch[i].tranches
343358
);
344359
}
360+
361+
// Log the creation of the batch of streams.
362+
emit ISablierBatchLockup.CreateLockupBatch({ funder: msg.sender, lockup: lockup, streamIds: streamIds });
345363
}
346364

347365
/*//////////////////////////////////////////////////////////////////////////

src/abstracts/SablierLockupDynamic.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ abstract contract SablierLockupDynamic is
138138
emit ISablierLockupDynamic.CreateLockupDynamicStream({
139139
streamId: streamId,
140140
commonParams: Lockup.CreateEventCommon({
141+
funder: msg.sender,
141142
sender: sender,
142143
recipient: recipient,
143144
depositAmount: depositAmount,

src/abstracts/SablierLockupLinear.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ abstract contract SablierLockupLinear is
144144
emit ISablierLockupLinear.CreateLockupLinearStream({
145145
streamId: streamId,
146146
commonParams: Lockup.CreateEventCommon({
147+
funder: msg.sender,
147148
sender: sender,
148149
recipient: recipient,
149150
depositAmount: depositAmount,

src/abstracts/SablierLockupTranched.sol

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ abstract contract SablierLockupTranched is
138138
emit ISablierLockupTranched.CreateLockupTranchedStream({
139139
streamId: streamId,
140140
commonParams: Lockup.CreateEventCommon({
141+
funder: msg.sender,
141142
sender: sender,
142143
recipient: recipient,
143144
depositAmount: depositAmount,

src/interfaces/ISablierBatchLockup.sol

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ import { ISablierLockup } from "./ISablierLockup.sol";
99
/// @title ISablierBatchLockup
1010
/// @notice Helper to batch create Lockup streams.
1111
interface ISablierBatchLockup {
12+
/*//////////////////////////////////////////////////////////////////////////
13+
EVENTS
14+
//////////////////////////////////////////////////////////////////////////*/
15+
16+
/// @notice Emitted when a batch of Lockup streams are created.
17+
/// @param funder The address funding the streams.
18+
/// @param lockup The address of the {SablierLockup} contract used to create the streams.
19+
/// @param streamIds The ids of the newly created streams, the ones that were successfully created.
20+
event CreateLockupBatch(address indexed funder, ISablierLockup indexed lockup, uint256[] streamIds);
21+
1222
/*//////////////////////////////////////////////////////////////////////////
1323
USER-FACING STATE-CHANGING FUNCTIONS
1424
//////////////////////////////////////////////////////////////////////////*/

src/types/Lockup.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ library Lockup {
2020
}
2121

2222
/// @notice Struct encapsulating the common parameters emitted in the stream creation events.
23+
/// @param funder The address funding the stream.
2324
/// @param sender The address distributing the tokens, which is able to cancel the stream.
2425
/// @param recipient The address receiving the tokens, as well as the NFT owner.
2526
/// @param depositAmount The deposit amount, denoted in units of the token's decimals.
@@ -30,6 +31,7 @@ library Lockup {
3031
/// @param shape An optional parameter to specify the shape of the distribution function. This helps differentiate
3132
/// streams in the UI.
3233
struct CreateEventCommon {
34+
address funder;
3335
address sender;
3436
address recipient;
3537
uint128 depositAmount;

tests/fork/LockupDynamic.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ abstract contract Lockup_Dynamic_Fork_Test is Lockup_Fork_Test {
5959
vm.expectEmit({ emitter: address(lockup) });
6060
emit ISablierLockupDynamic.CreateLockupDynamicStream({
6161
streamId: vars.streamId,
62-
commonParams: defaults.lockupCreateEvent({ params: params.create, token_: FORK_TOKEN }),
62+
commonParams: defaults.lockupCreateEvent({ caller: forkTokenHolder, params: params.create, token_: FORK_TOKEN }),
6363
segments: params.segments
6464
});
6565

tests/fork/LockupLinear.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ abstract contract Lockup_Linear_Fork_Test is Lockup_Fork_Test {
6060
vm.expectEmit({ emitter: address(lockup) });
6161
emit ISablierLockupLinear.CreateLockupLinearStream({
6262
streamId: vars.streamId,
63-
commonParams: defaults.lockupCreateEvent({ params: params.create, token_: FORK_TOKEN }),
63+
commonParams: defaults.lockupCreateEvent({ caller: forkTokenHolder, params: params.create, token_: FORK_TOKEN }),
6464
cliffTime: params.cliffTime,
6565
unlockAmounts: params.unlockAmounts
6666
});

tests/fork/LockupTranched.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ abstract contract Lockup_Tranched_Fork_Test is Lockup_Fork_Test {
6060
vm.expectEmit({ emitter: address(lockup) });
6161
emit ISablierLockupTranched.CreateLockupTranchedStream({
6262
streamId: vars.streamId,
63-
commonParams: defaults.lockupCreateEvent({ params: params.create, token_: FORK_TOKEN }),
63+
commonParams: defaults.lockupCreateEvent({ caller: forkTokenHolder, params: params.create, token_: FORK_TOKEN }),
6464
tranches: params.tranches
6565
});
6666

tests/integration/concrete/batch-lockup/create-with-durations-ld/createWithDurationsLD.t.sol

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// SPDX-License-Identifier: UNLICENSED
22
pragma solidity >=0.8.22 <0.9.0;
33

4+
import { ISablierBatchLockup } from "src/interfaces/ISablierBatchLockup.sol";
45
import { Errors } from "src/libraries/Errors.sol";
56
import { BatchLockup } from "src/types/BatchLockup.sol";
67

@@ -14,6 +15,8 @@ contract CreateWithDurationsLD_Integration_Test is Integration_Test {
1415
}
1516

1617
function test_WhenBatchSizeNotZero() external {
18+
uint256[] memory expectedStreamIds = defaults.incrementalStreamIds({ firstStreamId: lockup.nextStreamId() });
19+
1720
// Token flow: Sender → batchLockup → SablierLockup
1821
// Expect transfers from Alice to the batchLockup, and then from the batchLockup to the Lockup contract.
1922
expectCallToTransferFrom({
@@ -34,12 +37,13 @@ contract CreateWithDurationsLD_Integration_Test is Integration_Test {
3437
value: defaults.DEPOSIT_AMOUNT()
3538
});
3639

37-
uint256 firstStreamId = lockup.nextStreamId();
40+
// It should emit a {CreateLockupBatch} event.
41+
vm.expectEmit({ emitter: address(batchLockup) });
42+
emit ISablierBatchLockup.CreateLockupBatch({ funder: users.sender, lockup: lockup, streamIds: expectedStreamIds });
3843

3944
// Assert that the batch of streams has been created successfully.
4045
uint256[] memory actualStreamIds =
4146
batchLockup.createWithDurationsLD(lockup, dai, defaults.batchCreateWithDurationsLD());
42-
uint256[] memory expectedStreamIds = defaults.incrementalStreamIds({ firstStreamId: firstStreamId });
4347
assertEq(actualStreamIds, expectedStreamIds, "stream ids mismatch");
4448
}
4549
}

0 commit comments

Comments
 (0)