Managing a Stream
This section will guide you through the different functions of Flow and how to interact with them. Before diving in, please note the following:
- We assume you are already familiar with creating Flow streams.
- We also assume that the stream management contract is authorized to invoke each respective function. To learn more about access control in Flow, see the Access Control guide.
caution
The code in this guide is not production-ready, and is implemented in a simplistic manner for the purpose of learning.
Set up your contract
Declare the Solidity version used to compile the contract:
// SPDX-License-Identifier: GPL-3.0-or-later
pragma solidity >=0.8.22;
Import the relevant symbols from @sablier/flow
and @prb/math
:
import { ud21x18 } from "@prb/math/src/UD21x18.sol";
import { ud60x18 } from "@prb/math/src/UD60x18.sol";
import { Broker, ISablierFlow } from "@sablier/flow/src/interfaces/ISablierFlow.sol";
Declare the contract and add the Flow address as a constant:
contract FlowStreamManager {
ISablierFlow public constant FLOW = ISablierFlow(0x52ab22e769E31564E17D524b683264B65662A014);
}
Also, these addresses are deployed on Sepolia. If you need to work with a different chain, Flow addresses can be obtained from the Flow Deployments page.
Deposit
Depositing into streams means adding tokens to the stream, which will then be distributed to the recipient based on the value of rate per second.
info
A deposit is also referred to as a top-up.
There are three deposit functions:
deposit
: deposits an amount of tokens.depositAndPause
: deposits an amount of tokens and then pauses the stream.depositViaBroker
: deposits an amount of tokens and transfers a fee to the broker specified.
function deposit(uint256 streamId, uint256 amount) external {
FLOW.deposit(streamId, amount);
}
function depositAndPause(uint256 streamId) external {
FLOW.depositAndPause(streamId, 3.14159e18);
}
function depositViaBroker(uint256 streamId) external {
Broker memory broker = Broker({ account: address(0xDEAD), fee: ud60x18(0.0001e18) });
FLOW.depositViaBroker({
streamId: streamId,
totalAmount: 3.14159e18,
sender: msg.sender,
recipient: address(0xCAFE),
broker: broker
});
}