Skip to main content

ISablierFlow

Git Source

Inherits: ISablierFlowBase

Creates and manages Flow streams with linear streaming functions.

Functions

coveredDebtOf

Returns the amount of debt covered by the stream balance, denoted in token's decimals.

Reverts if streamId references a null stream.

function coveredDebtOf(uint256 streamId) external view returns (uint128 coveredDebt);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

depletionTimeOf

Returns the time at which the total debt exceeds stream balance. If the total debt is less than or equal to stream balance, it returns 0.

Reverts if streamId references a paused or a null stream.

function depletionTimeOf(uint256 streamId) external view returns (uint256 depletionTime);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

ongoingDebtScaledOf

Returns the amount of debt accrued since the snapshot time until now, denoted as a fixed-point number where 1e18 is 1 token.

Reverts if streamId references a null stream.

function ongoingDebtScaledOf(uint256 streamId) external view returns (uint256 ongoingDebtScaled);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

refundableAmountOf

Returns the amount that the sender can be refunded from the stream, denoted in token's decimals.

Reverts if streamId references a null stream.

function refundableAmountOf(uint256 streamId) external view returns (uint128 refundableAmount);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

statusOf

Returns the stream's status.

Reverts if streamId references a null stream.

function statusOf(uint256 streamId) external view returns (Flow.Status status);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

totalDebtOf

Returns the total amount owed by the sender to the recipient, denoted in token's decimals.

Reverts if streamId references a null stream.

function totalDebtOf(uint256 streamId) external view returns (uint256 totalDebt);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

uncoveredDebtOf

Returns the amount of debt not covered by the stream balance, denoted in token's decimals.

Reverts if streamId references a null stream.

function uncoveredDebtOf(uint256 streamId) external view returns (uint256 uncoveredDebt);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

withdrawableAmountOf

Calculates the amount that the recipient can withdraw from the stream, denoted in token decimals. This is an alias for coveredDebtOf.

Reverts if streamId references a null stream.

function withdrawableAmountOf(uint256 streamId) external view returns (uint128 withdrawableAmount);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

Returns

NameTypeDescription
withdrawableAmountuint128The amount that the recipient can withdraw.

adjustRatePerSecond

Changes the stream's rate per second.

Emits AdjustFlowStream and {MetadataUpdate} events. Notes:

  • Performs a debt snapshot. Requirements:
  • Must not be delegate called.
  • streamId must not reference a null or a paused stream.
  • msg.sender must be the stream's sender.
  • newRatePerSecond must not equal to the current rate per second.
function adjustRatePerSecond(uint256 streamId, UD21x18 newRatePerSecond) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to adjust.
newRatePerSecondUD21x18The new rate per second, denoted as a fixed-point number where 1e18 is 1 token per second.

create

Creates a new Flow stream by setting the snapshot time to block.timestamp and leaving the balance to zero. The stream is wrapped in an ERC-721 NFT.

Emits CreateFlowStream event. Requirements:

  • Must not be delegate called.
  • sender must not be the zero address.
  • recipient must not be the zero address.
  • The token's decimals must be less than or equal to 18.
function create(
address sender,
address recipient,
UD21x18 ratePerSecond,
IERC20 token,
bool transferable
)
external
returns (uint256 streamId);

Parameters

NameTypeDescription
senderaddressThe address streaming the tokens, which is able to adjust and pause the stream. It doesn't have to be the same as msg.sender.
recipientaddressThe address receiving the tokens.
ratePerSecondUD21x18The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second.
tokenIERC20The contract address of the ERC-20 token to be streamed.
transferableboolBoolean indicating if the stream NFT is transferable.

Returns

NameTypeDescription
streamIduint256The ID of the newly created stream.

createAndDeposit

Creates a new Flow stream by setting the snapshot time to block.timestamp and the balance to amount. The stream is wrapped in an ERC-721 NFT.

Emits {Transfer}, {CreateFlowStream}, and {DepositFlowStream} events. Notes:

  • Refer to the notes in {deposit}. Requirements:
  • Refer to the requirements in {create} and {deposit}.
function createAndDeposit(
address sender,
address recipient,
UD21x18 ratePerSecond,
IERC20 token,
bool transferable,
uint128 amount
)
external
returns (uint256 streamId);

Parameters

NameTypeDescription
senderaddressThe address streaming the tokens. It doesn't have to be the same as msg.sender.
recipientaddressThe address receiving the tokens.
ratePerSecondUD21x18The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second.
tokenIERC20The contract address of the ERC-20 token to be streamed.
transferableboolBoolean indicating if the stream NFT is transferable.
amountuint128The deposit amount, denoted in token's decimals.

Returns

NameTypeDescription
streamIduint256The ID of the newly created stream.

deposit

Makes a deposit in a stream.

Emits {Transfer} and {DepositFlowStream} events. Requirements:

  • Must not be delegate called.
  • streamId must not reference a null or a voided stream.
  • amount must be greater than zero.
  • sender and recipient must match the stream's sender and recipient addresses.
function deposit(uint256 streamId, uint128 amount, address sender, address recipient) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to deposit to.
amountuint128The deposit amount, denoted in token's decimals.
senderaddressThe stream's sender address.
recipientaddressThe stream's recipient address.

depositAndPause

Deposits tokens in a stream and pauses it.

Emits {Transfer}, {DepositFlowStream} and {PauseFlowStream} events. Notes:

  • Refer to the notes in {deposit} and {pause}. Requirements:
  • Refer to the requirements in {deposit} and {pause}.
function depositAndPause(uint256 streamId, uint128 amount) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to deposit to, and then pause.
amountuint128The deposit amount, denoted in token's decimals.

depositViaBroker

Deposits tokens in a stream.

Emits {Transfer} and {DepositFlowStream} events. Notes:

  • Refer to the notes in {deposit}. Requirements:
  • Must not be delegate called.
  • streamId must not reference a null stream.
  • totalAmount must be greater than zero. Otherwise it will revert inside {deposit}.
  • broker.account must not be 0 address.
  • broker.fee must not be greater than MAX_FEE. It can be zero.
function depositViaBroker(
uint256 streamId,
uint128 totalAmount,
address sender,
address recipient,
Broker calldata broker
)
external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to deposit on.
totalAmountuint128The total amount, including the deposit and any broker fee, denoted in token's decimals.
senderaddressThe stream's sender address.
recipientaddressThe stream's recipient address.
brokerBrokerStruct encapsulating (i) the address of the broker assisting in creating the stream, and (ii) the percentage fee paid to the broker from totalAmount, denoted as a fixed-point percentage.

pause

Pauses the stream.

Emits PauseFlowStream event. Notes:

  • It does not set the snapshot time to the current block timestamp.
  • It updates the snapshot debt by adding up ongoing debt.
  • It sets the rate per second to zero. Requirements:
  • Must not be delegate called.
  • streamId must not reference a null or an already paused stream.
  • msg.sender must be the stream's sender.
function pause(uint256 streamId) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to pause.

refund

Refunds the provided amount of tokens from the stream to the sender's address.

Emits {Transfer} and {RefundFromFlowStream} events. Requirements:

  • Must not be delegate called.
  • streamId must not reference a null stream.
  • msg.sender must be the sender.
  • amount must be greater than zero and must not exceed the refundable amount.
function refund(uint256 streamId, uint128 amount) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to refund from.
amountuint128The amount to refund, denoted in token's decimals.

refundAndPause

Refunds the provided amount of tokens from the stream to the sender's address.

Emits {Transfer}, {RefundFromFlowStream} and {PauseFlowStream} events. Notes:

  • Refer to the notes in {pause}. Requirements:
  • Refer to the requirements in {refund} and {pause}.
function refundAndPause(uint256 streamId, uint128 amount) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to refund from and then pause.
amountuint128The amount to refund, denoted in token's decimals.

restart

Restarts the stream with the provided rate per second.

Emits RestartFlowStream event.

  • This function updates stream's snapshotTime to the current block timestamp. Notes:
  • It sets the snapshot time to the current block timestamp. Requirements:
  • Must not be delegate called.
  • streamId must not reference a null, or a voided stream.
  • msg.sender must be the stream's sender.
  • ratePerSecond must be greater than zero.
function restart(uint256 streamId, UD21x18 ratePerSecond) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to restart.
ratePerSecondUD21x18The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second.

restartAndDeposit

Restarts the stream with the provided rate per second, and makes a deposit.

Emits RestartFlowStream, {Transfer}, and {DepositFlowStream} events. Notes:

  • Refer to the notes in {restart} and {deposit}. Requirements:
  • amount must be greater than zero.
  • Refer to the requirements in {restart}.
function restartAndDeposit(uint256 streamId, UD21x18 ratePerSecond, uint128 amount) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to restart.
ratePerSecondUD21x18The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second.
amountuint128The deposit amount, denoted in token's decimals.

void

Voids a stream.

Emits VoidFlowStream event. Notes:

  • It sets snapshot time to the block.timestamp
  • Voiding an insolvent stream sets the snapshot debt to the stream's balance making the uncovered debt to become zero.
  • Voiding a solvent stream updates the snapshot debt by adding up ongoing debt.
  • It sets the rate per second to zero.
  • A voided stream cannot be restarted. Requirements:
  • Must not be delegate called.
  • streamId must not reference a null or a voided stream.
  • msg.sender must either be the stream's sender, recipient or an approved third party.
function void(uint256 streamId) external;

Parameters

NameTypeDescription
streamIduint256The ID of the stream to void.

withdraw

Withdraws the provided amount minus the protocol fee to the provided to address.

Emits {Transfer} and {WithdrawFromFlowStream} events. Notes:

  • It sets the snapshot time to the block.timestamp if amount is greater than snapshot debt.
  • A protocol fee may be charged on the withdrawn amount if the protocol fee is enabled for the streaming token. Requirements:
  • Must not be delegate called.
  • streamId must not reference a null stream.
  • to must not be the zero address.
  • to must be the recipient if msg.sender is not the stream's recipient.
  • amount must be greater than zero and must not exceed the withdrawable amount.
function withdraw(
uint256 streamId,
address to,
uint128 amount
)
external
returns (uint128 withdrawnAmount, uint128 protocolFeeAmount);

Parameters

NameTypeDescription
streamIduint256The ID of the stream to withdraw from.
toaddressThe address receiving the withdrawn tokens.
amountuint128The amount to withdraw, denoted in token's decimals.

Returns

NameTypeDescription
withdrawnAmountuint128The amount withdrawn to the recipient, denoted in token's decimals. This is input amount minus the protocol fee.
protocolFeeAmountuint128The protocol fee amount, denoted in the token's decimals.

withdrawMax

Withdraws the entire withdrawable amount minus the protocol fee to the provided to address.

Emits {Transfer} and {WithdrawFromFlowStream} events. Notes:

  • Refer to the notes in {withdraw}. Requirements:
  • Refer to the requirements in {withdraw}.
function withdrawMax(
uint256 streamId,
address to
)
external
returns (uint128 withdrawnAmount, uint128 protocolFeeAmount);

Parameters

NameTypeDescription
streamIduint256The ID of the stream to withdraw from.
toaddressThe address receiving the withdrawn tokens.

Returns

NameTypeDescription
withdrawnAmountuint128The amount withdrawn to the recipient, denoted in token's decimals.
protocolFeeAmountuint128The protocol fee amount, denoted in the token's decimals.

Events

AdjustFlowStream

Emitted when the rate per second is updated by the sender.

event AdjustFlowStream(uint256 indexed streamId, uint256 totalDebt, UD21x18 oldRatePerSecond, UD21x18 newRatePerSecond);

Parameters

NameTypeDescription
streamIduint256The ID of the stream.
totalDebtuint256The total debt at the time of the update, denoted in token's decimals.
oldRatePerSecondUD21x18The old rate per second, denoted as a fixed-point number where 1e18 is 1 token per second.
newRatePerSecondUD21x18The new rate per second, denoted as a fixed-point number where 1e18 is 1 token per second.

CreateFlowStream

Emitted when a Flow stream is created.

event CreateFlowStream(
uint256 streamId,
address indexed sender,
address indexed recipient,
UD21x18 ratePerSecond,
IERC20 indexed token,
bool transferable
);

Parameters

NameTypeDescription
streamIduint256The ID of the newly created stream.
senderaddressThe address streaming the tokens, which is able to adjust and pause the stream.
recipientaddressThe address receiving the tokens, as well as the NFT owner.
ratePerSecondUD21x18The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second.
tokenIERC20The contract address of the ERC-20 token to be streamed.
transferableboolBoolean indicating whether the stream NFT is transferable or not.

DepositFlowStream

Emitted when a stream is funded.

event DepositFlowStream(uint256 indexed streamId, address indexed funder, uint128 amount);

Parameters

NameTypeDescription
streamIduint256The ID of the stream.
funderaddressThe address that made the deposit.
amountuint128The amount of tokens deposited into the stream, denoted in token's decimals.

PauseFlowStream

Emitted when a stream is paused by the sender.

event PauseFlowStream(uint256 indexed streamId, address indexed sender, address indexed recipient, uint256 totalDebt);

Parameters

NameTypeDescription
streamIduint256The ID of the stream.
senderaddressThe stream's sender address.
recipientaddressThe stream's recipient address.
totalDebtuint256The amount of tokens owed by the sender to the recipient, denoted in token's decimals.

RefundFromFlowStream

Emitted when a sender is refunded from a stream.

event RefundFromFlowStream(uint256 indexed streamId, address indexed sender, uint128 amount);

Parameters

NameTypeDescription
streamIduint256The ID of the stream.
senderaddressThe stream's sender address.
amountuint128The amount of tokens refunded to the sender, denoted in token's decimals.

RestartFlowStream

Emitted when a stream is restarted by the sender.

event RestartFlowStream(uint256 indexed streamId, address indexed sender, UD21x18 ratePerSecond);

Parameters

NameTypeDescription
streamIduint256The ID of the stream.
senderaddressThe stream's sender address.
ratePerSecondUD21x18The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second.

VoidFlowStream

Emitted when a stream is voided by the sender, recipient or an approved operator.

event VoidFlowStream(
uint256 indexed streamId,
address indexed sender,
address indexed recipient,
address caller,
uint256 newTotalDebt,
uint256 writtenOffDebt
);

Parameters

NameTypeDescription
streamIduint256The ID of the stream.
senderaddressThe stream's sender address.
recipientaddressThe stream's recipient address.
calleraddressThe address that performed the void, which can be the sender, recipient or an approved operator.
newTotalDebtuint256The new total debt, denoted in token's decimals.
writtenOffDebtuint256The amount of debt written off by the caller, denoted in token's decimals.

WithdrawFromFlowStream

Emitted when tokens are withdrawn from a stream by a recipient or an approved operator.

event WithdrawFromFlowStream(
uint256 indexed streamId,
address indexed to,
IERC20 indexed token,
address caller,
uint128 withdrawAmount,
uint128 protocolFeeAmount
);

Parameters

NameTypeDescription
streamIduint256The ID of the stream.
toaddressThe address that received the withdrawn tokens.
tokenIERC20The contract address of the ERC-20 token that was withdrawn.
calleraddressThe address that performed the withdrawal, which can be the recipient or an approved operator.
withdrawAmountuint128The amount withdrawn to the recipient after subtracting the protocol fee, denoted in token's decimals.
protocolFeeAmountuint128The amount of protocol fee deducted from the withdrawn amount, denoted in token's decimals.