Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: amount param in _withdraw #232

Merged
merged 13 commits into from
Sep 13, 2024
Merged

Conversation

andreivladbrg
Copy link
Member

@andreivladbrg andreivladbrg commented Sep 9, 2024

Closes

Depends on #220

Changes

  • change time with amount in withdraw
  • remove time param in all functions and rely only on block.timestamp
  • remove balance == 0 check in withdraw
  • remove unneeded totalWithdrawAmount variable
  • update withdraw and amount calculation functions
  • dry-fy tests

Some notes:

We now can allow withdrawals for an amount less than snapshotDebt which previously not possible with time param.

Since now the withdraw amount is bounded between [1, coveredDebt], I have used unchecked for the balance subtraction, as we know for sure is not going to be greater than it.

flow/src/SablierFlow.sol

Lines 787 to 790 in c772b5b

// Check: the withdraw amount is not zero.
if (amount == 0) {
revert Errors.SablierFlow_WithdrawAmountZero(streamId);
}

and

flow/src/SablierFlow.sol

Lines 823 to 826 in c772b5b

// Check: the withdraw amount is not greater than the withdrawable amount.
if (amount > withdrawableAmount) {
revert Errors.SablierFlow_Overdraw(streamId, amount, withdrawableAmount);
}

Also, this is why I've added the equal check in else branch:

else if (amount == totalDebt) {

@smol-ninja
Copy link
Member

As a reminder to us:

@andreivladbrg andreivladbrg force-pushed the refactor/withdraw-amount branch 3 times, most recently from e12c17c to 6dd2d15 Compare September 9, 2024 13:56
@andreivladbrg andreivladbrg marked this pull request as ready for review September 9, 2024 13:56
@andreivladbrg andreivladbrg force-pushed the refactor/withdraw-amount branch 2 times, most recently from 2d2eb19 to dd917e2 Compare September 9, 2024 14:21
Copy link
Member

@smol-ninja smol-ninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @andreivladbrg. Great work on this. Here is a partial review and the rest of the review depends on the conclusion from the following comments.

package.json Outdated Show resolved Hide resolved
benchmark/Flow.Gas.t.sol Outdated Show resolved Hide resolved
benchmark/Flow.Gas.t.sol Outdated Show resolved Hide resolved
src/interfaces/ISablierFlow.sol Outdated Show resolved Hide resolved
src/SablierFlow.sol Outdated Show resolved Hide resolved
src/interfaces/ISablierFlow.sol Outdated Show resolved Hide resolved
src/libraries/Helpers.sol Outdated Show resolved Hide resolved
src/SablierFlow.sol Outdated Show resolved Hide resolved
test/integration/concrete/batch/batch.t.sol Show resolved Hide resolved
@smol-ninja smol-ninja changed the title Refactor/withdraw amount refactor: amount param in _withdraw Sep 10, 2024
@andreivladbrg
Copy link
Member Author

@smol-ninja I've pushed a commit a8b77f5 to address your feedback, lmk if it looks good

Copy link
Member

@smol-ninja smol-ninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given a full review. I must say with amount as input parameter, the code now looks a bit better.

Except https://github.com/sablier-labs/flow/actions/runs/10811580895/job/29991351943?pr=232 (which I have yet to investigate), everything looks great. Left some comments below.

src/SablierFlow.sol Outdated Show resolved Hide resolved
test/integration/fuzz/coveredDebtOf.t.sol Outdated Show resolved Hide resolved
src/SablierFlow.sol Show resolved Hide resolved
src/SablierFlow.sol Outdated Show resolved Hide resolved
test/integration/fuzz/withdrawMax.t.sol Show resolved Hide resolved
@smol-ninja
Copy link
Member

@andreivladbrg feel free to merge this PR now. And open separate PRs for other works such as related to invariant or the ones mentioned above (refactoring withdraw branches). I am convinced this is the way to go so lets gooo.

Copy link
Member

@smol-ninja smol-ninja left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work with this btw. I still look forward to some failing tests but until then, this is the winner.

@andreivladbrg
Copy link
Member Author

andreivladbrg commented Sep 13, 2024

feel free to merge this PR now

sounds good, merging now

Great work with this btw. I still look forward to some failing tests but until then, this is the winner.

thank you, great suggestions as well

@andreivladbrg andreivladbrg merged commit 40dd6a0 into main Sep 13, 2024
@andreivladbrg andreivladbrg deleted the refactor/withdraw-amount branch September 13, 2024 15:00
andreivladbrg added a commit that referenced this pull request Sep 13, 2024
* 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 <[email protected]>
Co-authored-by: gavriliumircea <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants