Skip to content

Commit

Permalink
Refactor/cancel to pause (#113)
Browse files Browse the repository at this point in the history
* refactor: rename cancel function to pause

refactor: don't refund in pause function
feat: keep track of debt after pausing

* test: update tests accordingly

* test: update deposit, refundableAmountOf and withdrawMax tests

* test: update invariant tests

* docs: update README with new invariants

* test: order alphabetically the invariant tests

* docs: update pause natspec

* perf: slightly optimize streamDebtOf function

refactor: remove pauseMultiple function

* docs: natspec

* refactor: say "recipientAmount" instead of sum in _withdrawableAmountOf function

test: be more precise for caller test branches
test: remove unneeded test for pause function
docs: correct invariants

* test: update invariant tests

* docs: improve remainingAmount natspec

---------

Co-authored-by: smol-ninja <[email protected]>
  • Loading branch information
andreivladbrg and smol-ninja authored May 24, 2024
1 parent b5f70b6 commit ef8b7ce
Show file tree
Hide file tree
Showing 40 changed files with 798 additions and 831 deletions.
34 changes: 24 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,20 @@ The withdrawable amount is actually the streamed amount when there is no debt or

The refundable amount is calculated by subtracting the streamed amount from the balance.

#### Abbreviation table

| Full Name | Abbreviation |
| ------------------ | ------------ |
| lastTimeUpdate | ltu |
| block.timestamp | now |
| balance | bal |
| ratePerSecond | rps |
| remainingAmount | ra |
| streamedAmount | sa |
| debt | debt |
| withdrawableAmount | wa |
| refundableAmount | rfa |

### Issues:

Due to the lack of a fixed duration and a fixed deposit amount, the rate per second (rps) introduces a precision problem
Expand Down Expand Up @@ -129,32 +143,32 @@ Sender address **must** be checked because there is no `ERC20` transfer in `_cre

### Invariants:

_withdrawable amount = min(balance, streamed amount) + remaining amount_
_wa ≀ bal_

_balance = withdrawable amount + refundable amount - remaining amount_
_if(debt = 0) then wa = sa + ra_

_balance = sum of deposits - sum of withdrawals_
_if(debt = 0 && isPaused = true) then wa = ra_

_withdrawable amount - remaining amount ≀ streamed amount_
_if(debt > 0) then wa = bal_

_sumΒ of withdrawn amounts ≀ sum of deposits_
_bal = sum of deposits - sum of withdrawals_

_sumΒ of withdrawn amounts ≀ sum of deposits_

_sum of stream balances normilized to asset decimals ≀ asset.balanceOf(SablierV2OpenEnded)_
_sum of stream balances normalized to asset decimals ≀ asset.balanceOf(SablierV2OpenEnded)_

_lastTimeUpdate ≀ block.timestamp;_
_ltu ≀ now_

_if(isCanceled = true) then balance = 0 && ratePerSecond = 0 && withdrawable amount = remaining amount_
_if(isPaused = true) then rps = 0_

### Actions Access Control:

| Action | Sender | Recipient | Operator(s) | Unkown User |
| Action | Sender | Recipient | Operator(s) | Unknown User |
| ------------------- | :----: | :-------: | :---------: | :--------------------: |
| AdjustRatePerSecond | βœ… | ❌ | ❌ | ❌ |
| Cancel | βœ… | ❌ | ❌ | ❌ |
| Deposit | βœ… | βœ… | βœ… | βœ… |
| RefundFromStream | βœ… | ❌ | ❌ | ❌ |
| RestartStream | βœ… | ❌ | ❌ | ❌ |
| Pause | βœ… | ❌ | ❌ | ❌ |
| Transfer NFT | ❌ | βœ… | βœ… | ❌ |
| Withdraw | βœ… | βœ… | βœ… | βœ… (only to Recipient) |
Loading

0 comments on commit ef8b7ce

Please sign in to comment.