Skip to content

Commit

Permalink
test: don't run tests on all distribution model
Browse files Browse the repository at this point in the history
test: test only cancel withdraw renounce and calculation functions for all distribution models
test: add getters common test file and run them only for dynamic
test: add and use expectRevert function in Integration_Test
test: remove shared dir from integration
test: remove "multiple" fuzz tests
test: remove getWithdrawnAmount fuzz tests
test: rename create dirs to contain the model
test: add revert test for unique getters
test: dry fy create with timestamps test with a common file in lockup-base
test: dry fy tests by adding lockupModel variable in Integration_Test
test: use only createDefaultStream function where possible
test: other dry fy and code improvements
  • Loading branch information
andreivladbrg committed Nov 12, 2024
1 parent 0828db8 commit d919d60
Show file tree
Hide file tree
Showing 172 changed files with 2,455 additions and 4,656 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,10 @@ This is just a glimpse of Sablier Lockup. For more guides and examples, see the
[documentation](https://docs.sablier.com).

```solidity
import { ISablierLockupLinear } from "@sablier/lockup/src/interfaces/ISablierLockupLinear.sol";
import { ISablierLockup } from "@sablier/lockup/src/interfaces/ISablierLockup.sol";
contract MyContract {
ISablierLockupLinear lockup;
ISablierLockup lockup;
function buildSomethingWithSablier() external {
// ...
Expand All @@ -84,9 +84,9 @@ contract MyContract {

## Architecture

Lockup uses a singleton-style architecture, where all streams are managed in the `LockupLinear`, `LockupDynamic` and
`LockupTranched` contracts. That is, Sablier does not deploy a new contract for each stream. It bundles all streams into
a single contract, which is more gas-efficient and easier to maintain.
Lockup uses a singleton-style architecture, where all streams are managed in the `SablierLockup` contract. That is,
Sablier does not deploy a new contract for each distribution model or stream. It bundles all streams into a single
contract, which is more gas-efficient and easier to maintain.

For more information, see the [Technical Overview](https://docs.sablier.com/contracts/v2/reference/overview) in our
docs, as well as these [diagrams](https://docs.sablier.com/contracts/v2/reference/diagrams).
Expand Down
10 changes: 5 additions & 5 deletions benchmark/BatchLockup.Gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
function gasCreateWithTimestampsLD(uint256 batchSize, uint256 segmentsCount) internal {
Lockup.CreateWithTimestamps memory createParams = defaults.createWithTimestampsBrokerNull();
LockupDynamic.Segment[] memory segments = _generateSegments(segmentsCount);
createParams.startTime = getBlockTimestamp();
createParams.endTime = segments[segments.length - 1].timestamp;
createParams.timestamps.start = getBlockTimestamp();
createParams.timestamps.end = segments[segments.length - 1].timestamp;
createParams.totalAmount = uint128(AMOUNT_PER_ITEM * segmentsCount);
BatchLockup.CreateWithTimestampsLD[] memory params =
BatchLockupBuilder.fillBatch(createParams, segments, batchSize);
Expand Down Expand Up @@ -131,7 +131,7 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
function gasCreateWithTimestampsLL(uint256 batchSize) internal {
BatchLockup.CreateWithTimestampsLL[] memory params = BatchLockupBuilder.fillBatch({
params: defaults.createWithTimestampsBrokerNull(),
cliff: defaults.CLIFF_TIME(),
cliffTime: defaults.CLIFF_TIME(),
batchSize: batchSize
});

Expand Down Expand Up @@ -175,8 +175,8 @@ contract BatchLockup_Gas_Test is Benchmark_Test {
function gasCreateWithTimestampsLT(uint256 batchSize, uint256 tranchesCount) internal {
Lockup.CreateWithTimestamps memory createParams = defaults.createWithTimestampsBrokerNull();
LockupTranched.Tranche[] memory tranches = _generateTranches(tranchesCount);
createParams.startTime = getBlockTimestamp();
createParams.endTime = tranches[tranches.length - 1].timestamp;
createParams.timestamps.start = getBlockTimestamp();
createParams.timestamps.end = tranches[tranches.length - 1].timestamp;
createParams.totalAmount = uint128(AMOUNT_PER_ITEM * tranchesCount);
BatchLockup.CreateWithTimestampsLT[] memory params =
BatchLockupBuilder.fillBatch(createParams, tranches, batchSize);
Expand Down
27 changes: 0 additions & 27 deletions benchmark/EstimateMaxCount.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { console2 } from "forge-std/src/console2.sol";
import { Test } from "forge-std/src/Test.sol";

import { Lockup_Dynamic_Gas_Test } from "./LockupDynamic.Gas.t.sol";
import { Lockup_Tranched_Gas_Test } from "./LockupTranched.Gas.t.sol";

/// @notice Structure to group the block gas limit and chain id.
struct ChainInfo {
Expand Down Expand Up @@ -62,30 +61,4 @@ contract EstimateMaxCount is Test {
console2.log("count: %d and gasUsed: %d and chainId: %d", count, lastGasConsumed, chains[i].chainId);
}
}

/// @notice Estimate the maximum number of tranches allowed in LockupTranched.
function test_EstimateTranches() public {
Lockup_Tranched_Gas_Test lockupTranchedGasTest = new Lockup_Tranched_Gas_Test();
lockupTranchedGasTest.setUp();

for (uint256 i = 0; i < chains.length; ++i) {
uint128 count = INITIAL_GUESS;

// Subtract `BUFFER_GAS` from `blockGasLimit` as an additional precaution to account for the dynamic gas for
// ether transfer on different chains.
uint256 blockGasLimit = chains[i].blockGasLimit - BUFFER_GAS;

uint256 gasConsumed = 0;
uint256 lastGasConsumed = 0;
while (blockGasLimit > gasConsumed) {
count += 10;
lastGasConsumed = gasConsumed;

// Estimate the gas consumed by adding 10 tranches.
gasConsumed = lockupTranchedGasTest.computeGas_CreateWithDurationsLT(count + 10);
}

console2.log("count: %d and gasUsed: %d and chainId: %d", count, lastGasConsumed, chains[i].chainId);
}
}
}
6 changes: 3 additions & 3 deletions benchmark/LockupDynamic.Gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ contract Lockup_Dynamic_Gas_Test is Benchmark_Test {
vm.writeFile({
path: benchmarkResultsFile,
data: string.concat(
"# Benchmarks for Lockup Dynamic\n\n", "| Implementation | Gas Usage |\n", "| --- | --- |\n"
"# Benchmarks for Lockup Dynamic Model\n\n", "| Implementation | Gas Usage |\n", "| --- | --- |\n"
)
});

Expand Down Expand Up @@ -224,8 +224,8 @@ contract Lockup_Dynamic_Gas_Test is Benchmark_Test {

params = defaults.createWithTimestamps();
params.totalAmount = _calculateTotalAmount(depositAmount, brokerFee);
params.startTime = getBlockTimestamp();
params.endTime = segments_[totalSegments - 1].timestamp;
params.timestamps.start = getBlockTimestamp();
params.timestamps.end = segments_[totalSegments - 1].timestamp;
params.broker.fee = brokerFee;
return (params, segments_);
}
Expand Down
4 changes: 3 additions & 1 deletion benchmark/LockupLinear.Gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ contract Lockup_Linear_Gas_Test is Benchmark_Test {
// Create the file if it doesn't exist, otherwise overwrite it.
vm.writeFile({
path: benchmarkResultsFile,
data: string.concat("# Benchmarks for Lockup Linear\n\n", "| Implementation | Gas Usage |\n", "| --- | --- |\n")
data: string.concat(
"# Benchmarks for Lockup Linear Model\n\n", "| Implementation | Gas Usage |\n", "| --- | --- |\n"
)
});

vm.warp({ newTimestamp: defaults.END_TIME() });
Expand Down
6 changes: 3 additions & 3 deletions benchmark/LockupTranched.Gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ contract Lockup_Tranched_Gas_Test is Benchmark_Test {
vm.writeFile({
path: benchmarkResultsFile,
data: string.concat(
"# Benchmarks for Lockup Tranched\n\n", "| Implementation | Gas Usage |\n", "| --- | --- |\n"
"# Benchmarks for Lockup Tranched Model\n\n", "| Implementation | Gas Usage |\n", "| --- | --- |\n"
)
});

Expand Down Expand Up @@ -207,8 +207,8 @@ contract Lockup_Tranched_Gas_Test is Benchmark_Test {

params = defaults.createWithTimestamps();
params.broker.fee = brokerFee;
params.startTime = getBlockTimestamp();
params.endTime = tranches_[totalTranches - 1].timestamp;
params.timestamps.start = getBlockTimestamp();
params.timestamps.end = tranches_[totalTranches - 1].timestamp;
params.totalAmount = _calculateTotalAmount(depositAmount, brokerFee);
return (params, tranches_);
}
Expand Down
60 changes: 30 additions & 30 deletions benchmark/results/SablierBatchLockup.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,33 @@

| Function | Lockup Type | Segments/Tranches | Batch Size | Gas Usage |
| ------------------------ | --------------- | ----------------- | ---------- | --------- |
| `createWithDurationsLL` | Lockup Linear | N/A | 5 | 779252 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 5 | 737531 |
| `createWithDurationsLD` | Lockup Dynamic | 24 | 5 | 4119940 |
| `createWithTimestampsLD` | Lockup Dynamic | 24 | 5 | 3888761 |
| `createWithDurationsLT` | Lockup Tranched | 24 | 5 | 3995338 |
| `createWithTimestampsLT` | Lockup Tranched | 24 | 5 | 3804250 |
| `createWithDurationsLL` | Lockup Linear | N/A | 10 | 1425098 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 10 | 1424116 |
| `createWithDurationsLD` | Lockup Dynamic | 24 | 10 | 8190322 |
| `createWithTimestampsLD` | Lockup Dynamic | 24 | 10 | 7728484 |
| `createWithDurationsLT` | Lockup Tranched | 24 | 10 | 7938702 |
| `createWithTimestampsLT` | Lockup Tranched | 24 | 10 | 7559817 |
| `createWithDurationsLL` | Lockup Linear | N/A | 20 | 2799677 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 20 | 2798898 |
| `createWithDurationsLD` | Lockup Dynamic | 24 | 20 | 16351825 |
| `createWithTimestampsLD` | Lockup Dynamic | 24 | 20 | 15412578 |
| `createWithDurationsLT` | Lockup Tranched | 24 | 20 | 15824057 |
| `createWithTimestampsLT` | Lockup Tranched | 24 | 20 | 15075556 |
| `createWithDurationsLL` | Lockup Linear | N/A | 30 | 4168931 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 30 | 4177876 |
| `createWithDurationsLD` | Lockup Dynamic | 24 | 30 | 24550618 |
| `createWithTimestampsLD` | Lockup Dynamic | 24 | 30 | 23110560 |
| `createWithDurationsLT` | Lockup Tranched | 24 | 30 | 23709058 |
| `createWithTimestampsLT` | Lockup Tranched | 24 | 30 | 22605337 |
| `createWithDurationsLL` | Lockup Linear | N/A | 50 | 6914041 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 50 | 6941746 |
| `createWithDurationsLD` | Lockup Dynamic | 12 | 50 | 24037239 |
| `createWithTimestampsLD` | Lockup Dynamic | 12 | 50 | 22827992 |
| `createWithDurationsLT` | Lockup Tranched | 12 | 50 | 23314745 |
| `createWithTimestampsLT` | Lockup Tranched | 12 | 50 | 22415432 |
| `createWithDurationsLL` | Lockup Linear | N/A | 5 | 778232 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 5 | 738090 |
| `createWithDurationsLD` | Lockup Dynamic | 24 | 5 | 4117172 |
| `createWithTimestampsLD` | Lockup Dynamic | 24 | 5 | 3887412 |
| `createWithDurationsLT` | Lockup Tranched | 24 | 5 | 3993178 |
| `createWithTimestampsLT` | Lockup Tranched | 24 | 5 | 3806069 |
| `createWithDurationsLL` | Lockup Linear | N/A | 10 | 1423058 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 10 | 1425240 |
| `createWithDurationsLD` | Lockup Dynamic | 24 | 10 | 8189792 |
| `createWithTimestampsLD` | Lockup Dynamic | 24 | 10 | 7725792 |
| `createWithDurationsLT` | Lockup Tranched | 24 | 10 | 7934383 |
| `createWithTimestampsLT` | Lockup Tranched | 24 | 10 | 7563478 |
| `createWithDurationsLL` | Lockup Linear | N/A | 20 | 2795598 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 20 | 2801161 |
| `createWithDurationsLD` | Lockup Dynamic | 24 | 20 | 16350772 |
| `createWithTimestampsLD` | Lockup Dynamic | 24 | 20 | 15407205 |
| `createWithDurationsLT` | Lockup Tranched | 24 | 20 | 15815419 |
| `createWithTimestampsLT` | Lockup Tranched | 24 | 20 | 15082887 |
| `createWithDurationsLL` | Lockup Linear | N/A | 30 | 4162811 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 30 | 4181289 |
| `createWithDurationsLD` | Lockup Dynamic | 24 | 30 | 24549048 |
| `createWithTimestampsLD` | Lockup Dynamic | 24 | 30 | 23102525 |
| `createWithDurationsLT` | Lockup Tranched | 24 | 30 | 23696100 |
| `createWithTimestampsLT` | Lockup Tranched | 24 | 30 | 22616357 |
| `createWithDurationsLL` | Lockup Linear | N/A | 50 | 6903841 |
| `createWithTimestampsLL` | Lockup Linear | N/A | 50 | 6947495 |
| `createWithDurationsLD` | Lockup Dynamic | 12 | 50 | 24028066 |
| `createWithTimestampsLD` | Lockup Dynamic | 12 | 50 | 22808040 |
| `createWithDurationsLT` | Lockup Tranched | 12 | 50 | 23292554 |
| `createWithTimestampsLT` | Lockup Tranched | 12 | 50 | 22433243 |
56 changes: 28 additions & 28 deletions benchmark/results/SablierLockup_Dynamic.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# Benchmarks for Lockup Dynamic
# Benchmarks for Lockup Dynamic Model

| Implementation | Gas Usage |
| ------------------------------------------------------------ | --------- |
| `burn` | 15737 |
| `cancel` | 69877 |
| `renounce` | 37913 |
| `createWithDurationsLD` (2 segments) (Broker fee set) | 211048 |
| `createWithDurationsLD` (2 segments) (Broker fee not set) | 194992 |
| `createWithTimestampsLD` (2 segments) (Broker fee set) | 191907 |
| `createWithTimestampsLD` (2 segments) (Broker fee not set) | 187158 |
| `withdraw` (2 segments) (After End Time) (by Recipient) | 19081 |
| `withdraw` (2 segments) (Before End Time) (by Recipient) | 28414 |
| `withdraw` (2 segments) (After End Time) (by Anyone) | 14337 |
| `withdraw` (2 segments) (Before End Time) (by Anyone) | 28470 |
| `createWithDurationsLD` (10 segments) (Broker fee set) | 418495 |
| `createWithDurationsLD` (10 segments) (Broker fee not set) | 413754 |
| `createWithTimestampsLD` (10 segments) (Broker fee set) | 398397 |
| `createWithTimestampsLD` (10 segments) (Broker fee not set) | 393659 |
| `withdraw` (10 segments) (After End Time) (by Recipient) | 14268 |
| `withdraw` (10 segments) (Before End Time) (by Recipient) | 35941 |
| `withdraw` (10 segments) (After End Time) (by Anyone) | 14345 |
| `withdraw` (10 segments) (Before End Time) (by Anyone) | 35997 |
| `createWithDurationsLD` (100 segments) (Broker fee set) | 2917762 |
| `createWithDurationsLD` (100 segments) (Broker fee not set) | 2914004 |
| `createWithTimestampsLD` (100 segments) (Broker fee set) | 2725623 |
| `createWithTimestampsLD` (100 segments) (Broker fee not set) | 2721888 |
| `withdraw` (100 segments) (After End Time) (by Recipient) | 14268 |
| `withdraw` (100 segments) (Before End Time) (by Recipient) | 121045 |
| `withdraw` (100 segments) (After End Time) (by Anyone) | 14324 |
| `withdraw` (100 segments) (Before End Time) (by Anyone) | 121101 |
| `burn` | 15759 |
| `cancel` | 68674 |
| `renounce` | 37726 |
| `createWithDurationsLD` (2 segments) (Broker fee set) | 210925 |
| `createWithDurationsLD` (2 segments) (Broker fee not set) | 194672 |
| `createWithTimestampsLD` (2 segments) (Broker fee set) | 191434 |
| `createWithTimestampsLD` (2 segments) (Broker fee not set) | 186483 |
| `withdraw` (2 segments) (After End Time) (by Recipient) | 19035 |
| `withdraw` (2 segments) (Before End Time) (by Recipient) | 28249 |
| `withdraw` (2 segments) (After End Time) (by Anyone) | 14291 |
| `withdraw` (2 segments) (Before End Time) (by Anyone) | 28305 |
| `createWithDurationsLD` (10 segments) (Broker fee set) | 418459 |
| `createWithDurationsLD` (10 segments) (Broker fee not set) | 413521 |
| `createWithTimestampsLD` (10 segments) (Broker fee set) | 398011 |
| `createWithTimestampsLD` (10 segments) (Broker fee not set) | 393076 |
| `withdraw` (10 segments) (After End Time) (by Recipient) | 14222 |
| `withdraw` (10 segments) (Before End Time) (by Recipient) | 35552 |
| `withdraw` (10 segments) (After End Time) (by Anyone) | 14299 |
| `withdraw` (10 segments) (Before End Time) (by Anyone) | 35608 |
| `createWithDurationsLD` (100 segments) (Broker fee set) | 2918719 |
| `createWithDurationsLD` (100 segments) (Broker fee not set) | 2914766 |
| `createWithTimestampsLD` (100 segments) (Broker fee set) | 2726237 |
| `createWithTimestampsLD` (100 segments) (Broker fee not set) | 2722308 |
| `withdraw` (100 segments) (After End Time) (by Recipient) | 14222 |
| `withdraw` (100 segments) (Before End Time) (by Recipient) | 118136 |
| `withdraw` (100 segments) (After End Time) (by Anyone) | 14278 |
| `withdraw` (100 segments) (Before End Time) (by Anyone) | 118192 |
Loading

0 comments on commit d919d60

Please sign in to comment.