Skip to content

Commit

Permalink
refactor: change the time param in withdraw with an amount
Browse files Browse the repository at this point in the history
fix: return zero in ongoingDebt
test: update tests accordingly
  • Loading branch information
andreivladbrg committed Sep 9, 2024
1 parent 7f6ae6c commit ab49775
Show file tree
Hide file tree
Showing 23 changed files with 406 additions and 500 deletions.
13 changes: 6 additions & 7 deletions benchmark/Flow.Gas.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ contract Flow_Gas_Test is Integration_Test {
// Create the file if it doesn't exist, otherwise overwrite it.
vm.writeFile({
path: benchmarkResultsFile,
data: string.concat("# Benchmarks using 6-decimal asset \n\n", "| Function | Gas Usage |\n", "| --- | --- |\n")
data: string.concat("# Benchmarks using 6-decimal token \n\n", "| Function | Gas Usage |\n", "| --- | --- |\n")
});
}

Expand Down Expand Up @@ -74,19 +74,18 @@ contract Flow_Gas_Test is Integration_Test {
// {flow.void}
computeGas("void", abi.encodeCall(flow.void, (streamId)));

// {flow.withdrawAt} (on an insolvent stream) on an incremented stream ID.
// {flow.withdraw} (on an insolvent stream) on an incremented stream ID.
computeGas(
"withdrawAt (insolvent stream)",
abi.encodeCall(flow.withdrawAt, (++streamId, users.recipient, getBlockTimestamp()))
"withdraw (insolvent stream)",
abi.encodeCall(flow.withdraw, (++streamId, users.recipient, getBlockTimestamp()))
);

// Deposit amount on an incremented stream ID to make stream solvent.
deposit(++streamId, flow.uncoveredDebtOf(streamId) + DEPOSIT_AMOUNT_6D);

// {flow.withdrawAt} (on a solvent stream).
// {flow.withdraw} (on a solvent stream).
computeGas(
"withdrawAt (solvent stream)",
abi.encodeCall(flow.withdrawAt, (streamId, users.recipient, getBlockTimestamp()))
"withdraw (solvent stream)", abi.encodeCall(flow.withdraw, (streamId, users.recipient, getBlockTimestamp()))
);

// {flow.withdrawMax} on an incremented stream ID.
Expand Down
28 changes: 14 additions & 14 deletions benchmark/results/SablierFlow.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Benchmarks using 6-decimal asset
# Benchmarks using 6-decimal token

| Function | Gas Usage |
| ------------------------------- | --------- |
| `adjustRatePerSecond` | 43788 |
| `create` | 113491 |
| `deposit` | 24832 |
| `depositViaBroker` | 21529 |
| `pause` | 9089 |
| `refund` | 11136 |
| `restart` | 6513 |
| `void` | 7963 |
| `withdrawAt (insolvent stream)` | 53210 |
| `withdrawAt (solvent stream)` | 17692 |
| `withdrawMax` | 49012 |
| Function | Gas Usage |
| ----------------------------- | --------- |
| `adjustRatePerSecond` | 43788 |
| `create` | 113491 |
| `deposit` | 24832 |
| `depositViaBroker` | 21529 |
| `pause` | 9089 |
| `refund` | 11136 |
| `restart` | 6513 |
| `void` | 7963 |
| `withdraw (insolvent stream)` | 53210 |
| `withdraw (solvent stream)` | 17692 |
| `withdrawMax` | 49012 |
2 changes: 1 addition & 1 deletion diagrams.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ stateDiagram-v2

1. The arrows point to the status on which the function can be called
2. The "update" comments refer only to the internal state
3. `st` is always updated to `block.timestamp`, expect for `withdrawAt`
3. `st` is always updated to `block.timestamp`, expect for `withdraw`
4. Red lines refers to the function that are doing an ERC-20 transfer

```mermaid
Expand Down
2 changes: 1 addition & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

[profile.default.fuzz]
max_test_rejects = 1_000_000 # Number of times `vm.assume` can fail
runs = 5000
runs = 20

[profile.default.invariant]
call_override = false # Override unsafe external calls to perform reentrancy checks
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@
"LICENSE-GPL.md"
],
"keywords": [
"asset-distribution",
"asset-streaming",
"token-distribution",
"token-streaming",
"blockchain",
"crypto",
"cryptoasset-streaming",
"cryptotoken-streaming",
"ethereum",
"forge",
"foundry",
Expand Down
Loading

0 comments on commit ab49775

Please sign in to comment.