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

Feat/status #180

Merged
merged 16 commits into from
Jun 25, 2024
Merged

Feat/status #180

merged 16 commits into from
Jun 25, 2024

Conversation

andreivladbrg
Copy link
Member

@andreivladbrg andreivladbrg commented Jun 12, 2024

Linked issues

Changes

  • Add an enum and implement a status function
  • Add a mermaid diagrams
  • Be more consistent in how to update the contract storage
Diagrams

Statuses

Types

Type Statuses Description
Active Streaming Insolvent, StreamingSolvent The amount owed to the recipient is increasing over time.
Paused PauseSolvent, PausedInsolvent The amount owed to the recipient is not increasing over time.
Status Description
Streaming Solvent Active stream when there is no debt.
Streaming Insolvent Active stream when there is debt.
Paused Solvent Paused stream when there is no debt.
Paused Insolvent Paused stream when there is debt.

Statuses diagram

The transition between statuses is done by specific functions, which can be seen in the text on the edges or by the
time.


image


Function calls

Notes:

  1. The "update" comments refer only to the internal state
  2. ltu is always updated to block.timestamp
  3. Red lines refers to the function that are doing an ERC20 transfer
flowchart LR
    subgraph Statuses
        NULL((NULL)):::grey
        ACV((ACTIVE)):::green
        INACV((INACTIVE)):::yellow
    end


    subgraph Functions
        CR([CREATE])
        ADJRPS([ADJUST_RPS])
        DP([DEPOSIT])
        WTD([WITHDRAW])
        RFD([REFUND])
        RST([RESTART])
        PS([PAUSE])
        VD([VOID])
    end

    BOTH((  )):::black

    classDef grey fill:#b0b0b0,stroke:#333,stroke-width:2px;
    classDef green fill:#32cd32,stroke:#333,stroke-width:2px;
    classDef yellow fill:#ffff99,stroke:#333,stroke-width:2px;
    classDef black fill:#000000,stroke:#333,stroke-width:2px;

    CR -- "update rps\nupdate ltu" --> NULL
    ADJRPS -- "update ra (+rca)\nupdate rps\nupdate ltu" -->  ACV

    DP -- "update bal (+)" --> BOTH

    RFD -- "update bal (-)" --> BOTH

    VD -- "update ra (bal)\nupdate rps (0)" --> BOTH

    WTD -- "update ra (-) \nupdate ltu\nupdate bal (-)" --> BOTH

    PS -- "update ra (+rca)\nupdate rps (0)" --> ACV

    BOTH --> ACV & INACV

    RST -- "update rps \nupdate ltu" --> INACV

    linkStyle 2,3,5 stroke:#ff0000,stroke-width:2px
Loading

The words chosen for the statuses are meant to best express their correct status, but they might be debatable. Feel free to suggest better terminology. While reading the code, it's advise to also real the diagrams.md file.

I’ve decided to add the diagrams here until we have a field in our docs because it is easier to maintain them here instead of having them in github discussions or as gists.

@andreivladbrg andreivladbrg marked this pull request as draft June 12, 2024 17:26
@andreivladbrg andreivladbrg requested a review from smol-ninja June 13, 2024 14:08
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.

@andreivladbrg really great work on the diagrams. On the statuses of the stream, I have left my comments below. I'd love to know your thoughts on it.

src/types/DataTypes.sol Outdated Show resolved Hide resolved
src/types/DataTypes.sol Outdated Show resolved Hide resolved
src/types/DataTypes.sol Outdated Show resolved Hide resolved
@andreivladbrg andreivladbrg force-pushed the feat/status branch 2 times, most recently from 3e3ce32 to 3021580 Compare June 15, 2024 18:42
@andreivladbrg
Copy link
Member Author

andreivladbrg commented Jun 15, 2024

@PaulRBerg @razgraf tagging you to request your opinions on the naming of statuses (also, you can see the diagrams in the PR's OP - or diagrams.md file for all diagrams):

    /// @notice Enum representing the different statuses of a stream.
    /// @dev There are two types of streams:
    /// - ACTIVE: when the amount owed to the recipient is increasing over time.
    /// - INACTIVE: when the amount owed to the recipient is not increasing over time.
    /// @custom:value0 STREAMING_SOLVENT Active stream when there is no debt.
    /// @custom:value1 STREAMING_INSOLVENT Active stream when there is debt.
    /// @custom:value2 PAUSED_SOLVENT Paused stream when there is no debt.
    /// @custom:value3 PAUSED_INSOLVENT Paused stream when there is debt.
    enum Status {
        // ACTIVE:
        STREAMING_SOLVENT,
        STREAMING_INSOLVENT,
        // INACTIVE:
        PAUSED_SOLVENT,
        PAUSED_INSOLVENT
    }

@andreivladbrg andreivladbrg marked this pull request as ready for review June 22, 2024 15:10
@andreivladbrg
Copy link
Member Author

@smol-ninja since we softly agreed on the statuses names, the PR is ready to be reviewed

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.

@andreivladbrg I loved the diagrams. Fantastic work on it.

Q: Why not replace INACTIVE keyword with PAUSE and ACTIVE with STREAMING?

src/SablierFlow.sol Outdated Show resolved Hide resolved
diagrams.md Outdated Show resolved Hide resolved
diagrams.md Outdated Show resolved Hide resolved
diagrams.md Outdated Show resolved Hide resolved
diagrams.md Outdated Show resolved Hide resolved
diagrams.md Outdated Show resolved Hide resolved
src/SablierFlow.sol Show resolved Hide resolved
src/types/DataTypes.sol Show resolved Hide resolved
@andreivladbrg

This comment was marked as resolved.

@smol-ninja

This comment was marked as resolved.

@andreivladbrg

This comment was marked as resolved.

@smol-ninja
Copy link
Member

Yes kind of. I changed it a bit to show you what I was thinking.

stateDiagram-v2
    direction LR

    state Streaming {
        STREAMING_SOLVENT
        STREAMING_INSOLVENT --> STREAMING_SOLVENT : deposit
        STREAMING_SOLVENT --> STREAMING_INSOLVENT : time
    }

    state Paused {
        # direction BT
        PAUSED_SOLVENT
        PAUSED_INSOLVENT
         PAUSED_INSOLVENT --> PAUSED_SOLVENT : deposit || void
    }

    STREAMING_SOLVENT --> PAUSED_SOLVENT : pause
    STREAMING_INSOLVENT --> PAUSED_INSOLVENT : pause
    STREAMING_INSOLVENT --> PAUSED_SOLVENT : void
    PAUSED_SOLVENT --> STREAMING_SOLVENT : restart
    PAUSED_INSOLVENT --> STREAMING_INSOLVENT : restart

    NULL --> STREAMING_SOLVENT : create

    NULL:::grey
    Streaming:::lightGreen
    Paused:::lightYellow
    STREAMING_SOLVENT:::intenseGreen
    STREAMING_INSOLVENT:::intenseGreen
    PAUSED_INSOLVENT:::intenseYellow
    PAUSED_SOLVENT:::intenseYellow

    classDef grey fill:#b0b0b0,stroke:#333,stroke-width:2px,color:#000,font-weight:bold;
    classDef lightGreen fill:#98FB98,color:#000,font-weight:bold;
    classDef intenseGreen fill:#32cd32,stroke:#333,stroke-width:2px,color:#000,font-weight:bold;
    classDef lightYellow fill:#ffff99,color:#000,font-weight:bold;
    classDef intenseYellow fill:#ffd700,color:#000,font-weight:bold;
Loading

And then replace "Active" and "Inactive" with "Streaming" and "Paused" in the Datatypes.sol and other parts in the code.

@andreivladbrg

This comment was marked as resolved.

@smol-ninja

This comment was marked as resolved.

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.

LGTM except one small change.

diagrams.md Outdated Show resolved Hide resolved
@andreivladbrg andreivladbrg merged commit b2063ad into main Jun 25, 2024
6 checks passed
@andreivladbrg andreivladbrg deleted the feat/status branch June 25, 2024 13:56
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.

Implement a Status
3 participants