Skip to content

Commit 984f1bb

Browse files
refactor: update templates (#17)
* refactor: update templates * renames v2-core to lockup * andrei's feedback Co-authored-by: Andrei Vlad Birgaoanu <99738872+andreivladbrg@users.noreply.github.com> * test: remove unneeded variable chore: rename env var * chore: update keywords * fix ci * style: prettier * ci: fix * rename test function * use npm version for lockup * build: add airdrops npm package Co-authored-by: Andrei Vlad Birgaoanu <andreivladbrg@gmail.com> --------- Co-authored-by: Andrei Vlad Birgaoanu <99738872+andreivladbrg@users.noreply.github.com> Co-authored-by: Andrei Vlad Birgaoanu <andreivladbrg@gmail.com>
1 parent 0555522 commit 984f1bb

File tree

9 files changed

+44
-44
lines changed

9 files changed

+44
-44
lines changed

.env.example

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export RPC_URL_SEPOLIA="YOUR_RPC_URL_SEPOLIA"
1+
export SEPOLIA_RPC_URL="YOUR_SEPOLIA_RPC_URL"

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name: "CI"
22

33
env:
4-
RPC_URL_SEPOLIA: ${{ secrets.RPC_URL_SEPOLIA }}
4+
SEPOLIA_RPC_URL: ${{ secrets.SEPOLIA_RPC_URL }}
55
FOUNDRY_PROFILE: "ci"
66

77
on:

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
# Lockup Integration Template
22

33
This repository contains templates for building integrations with
4-
[Sablier Lockup](https://github.com/sablier-labs/v2-core).
4+
[Sablier Lockup](https://github.com/sablier-labs/lockup).
55

6-
- **LockupStreamCreator**: A template for creating a Lockup Linear stream.
6+
- **LockupStreamCreator**: A template for creating a Lockup stream using Linear model.
77

88
For more information, refer to this guide on our documentation website:
99

10-
https://docs.sablier.com/contracts/v2/guides/local-environment
10+
https://docs.sablier.com/guides/lockup/examples/local-environment
1111

1212
## License
1313

bun.lockb

342 Bytes
Binary file not shown.

foundry.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@
2323
wrap_comments = true
2424

2525
[rpc_endpoints]
26-
sepolia = "${RPC_URL_SEPOLIA}"
26+
sepolia = "${SEPOLIA_RPC_URL}"

package.json

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "lockup-integration-template",
3-
"description": "Template for making on-chain integrations with Sablier Lockup V2",
3+
"description": "Template for making on-chain integrations with Sablier Lockup",
44
"version": "1.0.0",
55
"author": {
66
"name": "Sablier Labs Ltd",
@@ -12,8 +12,8 @@
1212
"dependencies": {
1313
"@openzeppelin/contracts": "5.0.2",
1414
"@prb/math": "4.0.3",
15-
"@sablier/v2-core": "1.2.0",
16-
"@sablier/v2-periphery": "1.2.0"
15+
"@sablier/lockup": "2.0.0",
16+
"@sablier/airdrops": "1.3.0"
1717
},
1818
"devDependencies": {
1919
"forge-std": "github:foundry-rs/forge-std#v1.8.1",
@@ -26,12 +26,14 @@
2626
"blockchain",
2727
"cryptoasset-streaming",
2828
"cryptoassets",
29+
"cryptotoken-streaming",
30+
"cryptotokens",
2931
"ethereum",
3032
"foundry",
3133
"money-streaming",
3234
"real-time-finance",
3335
"sablier",
34-
"sablier-v2",
36+
"sablier-lockup",
3537
"smart-contracts",
3638
"solidity",
3739
"token-streaming"

remappings.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@openzeppelin/contracts/=node_modules/@openzeppelin/contracts/
22
@prb/math/=node_modules/@prb/math/
3-
@sablier/v2-core/=node_modules/@sablier/v2-core/
4-
@sablier/v2-periphery/=node_modules/@sablier/v2-periphery/
3+
@sablier/lockup/=node_modules/@sablier/lockup/
54
forge-std/=node_modules/forge-std/

src/LockupStreamCreator.sol

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,45 +3,50 @@ pragma solidity >=0.8.22;
33

44
import { IERC20 } from "@openzeppelin/contracts/token/ERC20/IERC20.sol";
55
import { ud60x18 } from "@prb/math/src/UD60x18.sol";
6-
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
7-
import { Broker, LockupLinear } from "@sablier/v2-core/src/types/DataTypes.sol";
6+
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";
7+
import { Broker, Lockup, LockupLinear } from "@sablier/lockup/src/types/DataTypes.sol";
88

99
/// @title LockupStreamCreator
10-
/// @dev This contract allows users to create Sablier lockup streams using the Lockup Linear contract.
10+
/// @dev This contract allows users to create Sablier lockup streams using the Lockup contract.
1111
contract LockupStreamCreator {
1212
IERC20 public constant DAI = IERC20(0x68194a729C2450ad26072b3D33ADaCbcef39D574);
13-
ISablierV2LockupLinear public immutable LOCKUP;
1413

15-
constructor(ISablierV2LockupLinear lockup) {
16-
LOCKUP = lockup;
17-
}
14+
// Get the latest deployment address from the docs: https://docs.sablier.com/guides/lockup/deployments
15+
ISablierLockup public constant LOCKUP = ISablierLockup(0xC2Da366fD67423b500cDF4712BdB41d0995b0794);
1816

1917
/// @dev Before calling this function, the user must first approve this contract to spend the tokens from the user's
2018
/// address.
21-
function createLockupLinearStream(uint256 totalAmount) external returns (uint256 streamId) {
19+
function createLinearStream(uint256 totalAmount) external returns (uint256 streamId) {
2220
// Transfer the provided amount of DAI tokens to this contract
2321
DAI.transferFrom(msg.sender, address(this), totalAmount);
2422

2523
// Approve the Lockup contract to spend DAI
2624
DAI.approve(address(LOCKUP), totalAmount);
2725

2826
// Declare the params struct
29-
LockupLinear.CreateWithDurations memory params;
27+
Lockup.CreateWithDurations memory params;
28+
29+
// Declare the umlockAmounts and durations structs
30+
LockupLinear.UnlockAmounts memory unlockAmounts = LockupLinear.UnlockAmounts({
31+
start: 1e18, // The amount to unlock at the start of the stream.
32+
cliff: 10e18 // The amount to unlock after cliff period.
33+
});
34+
LockupLinear.Durations memory durations = LockupLinear.Durations({
35+
cliff: 4 weeks, // Cliff tokens will be unlocked after 4 weeks
36+
total: 52 weeks // Setting a total duration of ~1 year
37+
});
3038

3139
// Declare the function parameters
3240
params.sender = msg.sender; // The sender will be able to cancel the stream
33-
params.recipient = address(0xcafe); // The recipient of the streamed assets
34-
params.totalAmount = uint128(totalAmount); // Total amount is the amount inclusive of all fees
35-
params.asset = DAI; // The streaming asset
41+
params.recipient = address(0xcafe); // The recipient of the streamed tokens
42+
params.totalAmount = uint128(totalAmount); // Total amount includes unlock amounts as well as the fees, if any
43+
params.token = DAI; // The streaming token
3644
params.cancelable = true; // Whether the stream will be cancelable or not
3745
params.transferable = true; // Whether the stream will be transferable or not
38-
params.durations = LockupLinear.Durations({
39-
cliff: 4 weeks, // Assets will be unlocked only after 4 weeks
40-
total: 52 weeks // Setting a total duration of ~1 year
41-
});
46+
params.shape = "cliff linear"; // Optional parameter for the shape of the stream
4247
params.broker = Broker(address(0), ud60x18(0)); // Optional parameter for charging a fee
4348

44-
// Create the lockup stream using a function that sets the start time to `block.timestamp`
45-
streamId = LOCKUP.createWithDurations(params);
49+
// Create the lockup linear stream using a function that sets the start time to `block.timestamp`
50+
streamId = LOCKUP.createWithDurationsLL(params, unlockAmounts, durations);
4651
}
4752
}

test/LockupStreamCreator.t.sol

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,27 @@
22
pragma solidity >=0.8.22;
33

44
import { Test } from "forge-std/src/Test.sol";
5-
import { ISablierV2LockupLinear } from "@sablier/v2-core/src/interfaces/ISablierV2LockupLinear.sol";
65

76
import { LockupStreamCreator } from "../src/LockupStreamCreator.sol";
87

98
contract LockupStreamCreatorTest is Test {
10-
// Get the latest deployment address from the docs: https://docs.sablier.com/contracts/v2/deployments
11-
address internal constant LOCKUP_LINEAR_ADDRESS = address(0x3E435560fd0a03ddF70694b35b673C25c65aBB6C);
12-
139
// Test contracts
1410
LockupStreamCreator internal creator;
15-
ISablierV2LockupLinear internal lockup;
1611
address internal user;
1712

1813
function setUp() public {
1914
// Fork Ethereum Mainnet
20-
vm.createSelectFork({ blockNumber: 6_239_031, urlOrAlias: "sepolia" });
21-
22-
// Load the lockup linear contract from Ethereum Sepolia
23-
lockup = ISablierV2LockupLinear(LOCKUP_LINEAR_ADDRESS);
15+
vm.createSelectFork({ blockNumber: 7_499_730, urlOrAlias: "sepolia" });
2416

2517
// Deploy the stream creator contract
26-
creator = new LockupStreamCreator(lockup);
18+
creator = new LockupStreamCreator();
2719

2820
// Create a test user
2921
user = payable(makeAddr("User"));
3022
vm.deal({ account: user, newBalance: 1 ether });
3123

32-
// Mint some DAI tokens to the test user, which will be pulled by the creator contract
24+
// Mint some DAI tokens to the test user, which will be pulled by the creator contract. Make sure its more than
25+
// `params.totalAmount`.
3326
deal({ token: address(creator.DAI()), to: user, give: 1337e18 });
3427

3528
// Make the test user the `msg.sender` in all following calls
@@ -39,9 +32,10 @@ contract LockupStreamCreatorTest is Test {
3932
creator.DAI().approve({ spender: address(creator), value: 1337e18 });
4033
}
4134

42-
function test_CreateLockupLinearStream() public {
43-
uint256 expectedStreamId = lockup.nextStreamId();
44-
uint256 actualStreamId = creator.createLockupLinearStream(1337e18);
35+
function test_CreateLinearStream() public {
36+
uint256 expectedStreamId = creator.LOCKUP().nextStreamId();
37+
// Create a linear stream. The amount provided must be more than `unlockAmounts.start + unlockAmounts.cliff`.
38+
uint256 actualStreamId = creator.createLinearStream(1337e18);
4539

4640
// Check that creating linear stream works by checking the stream id
4741
assertEq(actualStreamId, expectedStreamId);

0 commit comments

Comments
 (0)