Skip to content

Commit

Permalink
refactor: amount param in _withdraw (#232)
Browse files Browse the repository at this point in the history
* refactor: change the time param in withdraw with an amount

test: update tests accordingly

* docs: fix

* perf: remove redudant assert

* Shub's feedback

* test: remove redundant lines in withdraw handler

test: change token symbols

* undeeded imports

* test: add getRenormalizedAmount in Utils.sol
test: assertions in withdrawMax fuzz test

* test: set lower bound for timejump to 0 in fuzz and invariant

* remove comment

* test: lower bound for rps

* refactor: remove corrected time logic (#236)

* chore: polish

* chore: polish

---------

Co-authored-by: smol-ninja <shubhamy2015@gmail.com>
Co-authored-by: gavriliumircea <48255669+gavriliumircea@users.noreply.github.com>
  • Loading branch information
3 people committed Sep 13, 2024
1 parent a0dab5b commit b67f34c
Show file tree
Hide file tree
Showing 37 changed files with 666 additions and 869 deletions.
20 changes: 12 additions & 8 deletions benchmark/Flow.Gas.t.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity >=0.8.22;

import { ud21x18 } from "@prb/math/src/UD21x18.sol";

import { Integration_Test } from "./../test/integration/Integration.t.sol";

/// @notice A contract to benchmark Flow functions.
Expand Down Expand Up @@ -33,7 +35,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 All @@ -43,7 +45,10 @@ contract Flow_Gas_Test is Integration_Test {

function testGas_Implementations() external {
// {flow.adjustRatePerSecond}
computeGas("adjustRatePerSecond", abi.encodeCall(flow.adjustRatePerSecond, (streamId, RATE_PER_SECOND + 1)));
computeGas(
"adjustRatePerSecond",
abi.encodeCall(flow.adjustRatePerSecond, (streamId, ud21x18(RATE_PER_SECOND_U128 + 1)))
);

// {flow.create}
computeGas(
Expand Down Expand Up @@ -74,19 +79,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, WITHDRAW_AMOUNT_6D))
);

// 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, WITHDRAW_AMOUNT_6D))
);

// {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` | 44069 |
| `create` | 113829 |
| `deposit` | 25068 |
| `depositViaBroker` | 21858 |
| `pause` | 9371 |
| `refund` | 11514 |
| `restart` | 6456 |
| `void` | 8543 |
| `withdraw (insolvent stream)` | 56632 |
| `withdraw (solvent stream)` | 39046 |
| `withdrawMax` | 51468 |
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`, except for `withdraw`
4. Red lines refers to the function that are doing an ERC-20 transfer

```mermaid
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"blockchain",
"crypto",
"cryptoasset-streaming",
"cryptotoken-streaming",
"ethereum",
"forge",
"foundry",
Expand Down
Loading

0 comments on commit b67f34c

Please sign in to comment.