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: flow examples #37

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
Open

feat: flow examples #37

wants to merge 10 commits into from

Conversation

andreivladbrg
Copy link
Member

@andreivladbrg andreivladbrg commented Oct 2, 2024

Closes #36

Note: this PR merge must be synchronized with docs reference changes due to v2 rename to lockup (e.g. this one). Will work on that once you finish with your refactor @smol-ninja.


The flow example contracts are represented by these 4:

  1. FlowBatchable
    • different functions (adjustRatePerSecondAndDeposit, createMultiple, createAndDepositViaBroker etc.) to declare the calldata as bytes for multiple function calls into a single tx
  2. FlowManager
    • Manager contract that calls function to manage streams (basically mirror functions)
  3. FlowStreamCreator
    • Contract for creating 2 streams with different rates
  4. FlowUtilities
    • A library (used in the stream creator contract) with a series of utility functions for calculating the rps using a desired amount and duration.

@sablier-labs/solidity lmk if you have anything else in mind, or if the current ones should suffice

build: update PRBMath
build: add flow/lockup foundry profiles
feat: implement a FlowUtilities library
feat: implement flow creator contract
refactor: rename v2 to lockup
chore: add scripts in package json for the new profiles
@andreivladbrg andreivladbrg marked this pull request as draft October 2, 2024 21:41
@andreivladbrg andreivladbrg changed the title Feat/flow feat: flow examples Oct 2, 2024
build: install flow repo via package.json
test: add tests for FlowStreamCreator
test: add tests for FlowBatchable
@smol-ninja
Copy link
Member

@andreivladbrg this might need some refactor with the deposit function

@andreivladbrg
Copy link
Member Author

andreivladbrg commented Oct 22, 2024

@andreivladbrg this might need some refactor with the deposit function

indeed it needs, will updated it

also, since the repo is public now, it can be removed via package.json file so the gitmodules can be removed

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.

Nice work on Flow examples especially FlowUtilities library. I have an idea for an example:

  • An example to salaries to multiple people through a single contract.

Let me know what you think if it would be useful or an overkill for this repo? I was thinking of examples from the use case point of view. And this may be a useful for users.

package.json Outdated
@@ -16,7 +16,8 @@
},
"dependencies": {
"@openzeppelin/contracts": "5.0.2",
"@prb/math": "4.0.3",
"@prb/math": "4.1.0",
"@sablier/flow": "github:sablier-labs/flow#main",
Copy link
Member

Choose a reason for hiding this comment

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

main is by default.

Copy link
Member

Choose a reason for hiding this comment

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


import { ISablierFlow } from "@sablier/flow/src/interfaces/ISablierFlow.sol";

contract FlowManager {
Copy link
Member

Choose a reason for hiding this comment

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

Lets add create as well. Without it, all the txns would revert since this contract may not be the msg.sender.

IIUC, is the objective to introduce a manager that acts on behalf of the users?

}

// Create a stream that sends 1000 USDC per month
function createStream_1T_PerMonth() external returns (uint256 streamId) {
Copy link
Member

Choose a reason for hiding this comment

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

should be createStream_1K_PerMonth. T is best suited to represent Trillions.

Copy link
Member

Choose a reason for hiding this comment

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

// Calculate the duration.
uint40 duration = end - start;

if (decimals < 18) {
Copy link
Member

Choose a reason for hiding this comment

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

Should be ==

Copy link
Member

Choose a reason for hiding this comment

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

@smol-ninja
Copy link
Member

Adding a note that after merging this PR, the links should be updated in sablier-labs/docs#186

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.

Include flow examples
2 participants