SablierFlow
Inherits: Batch, NoDelegateCall, ISablierFlow, SablierFlowBase
See the documentation in ISablierFlow.
Functions
constructor
Emits {TransferAdmin} event.
constructor(
address initialAdmin,
IFlowNFTDescriptor initialNFTDescriptor
)
ERC721("Sablier Flow NFT", "SAB-FLOW")
SablierFlowBase(initialAdmin, initialNFTDescriptor);
Parameters
Name | Type | Description |
---|---|---|
initialAdmin | address | The address of the initial contract admin. |
initialNFTDescriptor | IFlowNFTDescriptor | The address of the initial NFT descriptor. |
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 override notNull(streamId) returns (uint128 coveredDebt);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
override
notNull(streamId)
notPaused(streamId)
returns (uint256 depletionTime);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
override
notNull(streamId)
returns (uint256 ongoingDebtScaled);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
override
notNull(streamId)
returns (uint128 refundableAmount);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The stream ID for the query. |
statusOf
Returns the stream's status.
Reverts if streamId
references a null stream.
function statusOf(uint256 streamId) external view override notNull(streamId) returns (Flow.Status status);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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 override notNull(streamId) returns (uint256 totalDebt);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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 override notNull(streamId) returns (uint256 uncoveredDebt);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
override
notNull(streamId)
returns (uint128 withdrawableAmount);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The stream ID for the query. |
Returns
Name | Type | Description |
---|---|---|
withdrawableAmount | uint128 | The 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
override
noDelegateCall
notNull(streamId)
notPaused(streamId)
onlySender(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to adjust. |
newRatePerSecond | UD21x18 | The 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
override
noDelegateCall
returns (uint256 streamId);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The address streaming the tokens, which is able to adjust and pause the stream. It doesn't have to be the same as msg.sender . |
recipient | address | The address receiving the tokens. |
ratePerSecond | UD21x18 | The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second. |
token | IERC20 | The contract address of the ERC-20 token to be streamed. |
transferable | bool | Boolean indicating if the stream NFT is transferable. |
Returns
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
override
noDelegateCall
returns (uint256 streamId);
Parameters
Name | Type | Description |
---|---|---|
sender | address | The address streaming the tokens. It doesn't have to be the same as msg.sender . |
recipient | address | The address receiving the tokens. |
ratePerSecond | UD21x18 | The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second. |
token | IERC20 | The contract address of the ERC-20 token to be streamed. |
transferable | bool | Boolean indicating if the stream NFT is transferable. |
amount | uint128 | The deposit amount, denoted in token's decimals. |
Returns
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
andrecipient
must match the stream's sender and recipient addresses.
function deposit(
uint256 streamId,
uint128 amount,
address sender,
address recipient
)
external
override
noDelegateCall
notNull(streamId)
notVoided(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to deposit to. |
amount | uint128 | The deposit amount, denoted in token's decimals. |
sender | address | The stream's sender address. |
recipient | address | The 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
override
noDelegateCall
notNull(streamId)
notPaused(streamId)
onlySender(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to deposit to, and then pause. |
amount | uint128 | The 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 thanMAX_FEE
. It can be zero.
function depositViaBroker(
uint256 streamId,
uint128 totalAmount,
address sender,
address recipient,
Broker calldata broker
)
external
override
noDelegateCall
notNull(streamId)
notVoided(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to deposit on. |
totalAmount | uint128 | The total amount, including the deposit and any broker fee, denoted in token's decimals. |
sender | address | The stream's sender address. |
recipient | address | The stream's recipient address. |
broker | Broker | Struct 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
override
noDelegateCall
notNull(streamId)
notPaused(streamId)
onlySender(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
override
noDelegateCall
notNull(streamId)
onlySender(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to refund from. |
amount | uint128 | The 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
override
noDelegateCall
notNull(streamId)
notPaused(streamId)
onlySender(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to refund from and then pause. |
amount | uint128 | The 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
override
noDelegateCall
notNull(streamId)
notVoided(streamId)
onlySender(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to restart. |
ratePerSecond | UD21x18 | The 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
override
noDelegateCall
notNull(streamId)
notVoided(streamId)
onlySender(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to restart. |
ratePerSecond | UD21x18 | The amount by which the debt is increasing every second, denoted as a fixed-point number where 1e18 is 1 token per second. |
amount | uint128 | The 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
override
noDelegateCall
notNull(streamId)
notVoided(streamId)
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
ifamount
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 ifmsg.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
override
noDelegateCall
notNull(streamId)
updateMetadata(streamId)
returns (uint128 withdrawnAmount, uint128 protocolFeeAmount);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to withdraw from. |
to | address | The address receiving the withdrawn tokens. |
amount | uint128 | The amount to withdraw, denoted in token's decimals. |
Returns
Name | Type | Description |
---|---|---|
withdrawnAmount | uint128 | The amount withdrawn to the recipient, denoted in token's decimals. This is input amount minus the protocol fee. |
protocolFeeAmount | uint128 | The 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
override
noDelegateCall
notNull(streamId)
updateMetadata(streamId)
returns (uint128 withdrawnAmount, uint128 protocolFeeAmount);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The ID of the stream to withdraw from. |
to | address | The address receiving the withdrawn tokens. |
Returns
Name | Type | Description |
---|---|---|
withdrawnAmount | uint128 | The amount withdrawn to the recipient, denoted in token's decimals. |
protocolFeeAmount | uint128 | The protocol fee amount, denoted in the token's decimals. |
_coveredDebtOf
Calculates the amount of covered debt by the stream balance.
function _coveredDebtOf(uint256 streamId) internal view returns (uint128);
_ongoingDebtScaledOf
Calculates the ongoing debt, as a 18-decimals fixed point number, accrued since last snapshot. Return 0 if the stream
is paused or block.timestamp
is less than or equal to snapshot time.
function _ongoingDebtScaledOf(uint256 streamId) internal view returns (uint256);
_refundableAmountOf
Calculates the refundable amount.
function _refundableAmountOf(uint256 streamId) internal view returns (uint128);
_totalDebtOf
The total debt is the sum of the snapshot debt and the ongoing debt descaled to token's decimal. This value is independent of the stream's balance.
function _totalDebtOf(uint256 streamId) internal view returns (uint256);
_uncoveredDebtOf
Calculates the uncovered debt.
function _uncoveredDebtOf(uint256 streamId) internal view returns (uint256);
_verifyStreamSenderRecipient
Checks whether the provided addresses matches stream's sender and recipient.
function _verifyStreamSenderRecipient(uint256 streamId, address sender, address recipient) internal view;
_adjustRatePerSecond
See the documentation for the user-facing functions that call this internal function.
function _adjustRatePerSecond(uint256 streamId, UD21x18 newRatePerSecond) internal;
_create
See the documentation for the user-facing functions that call this internal function.
function _create(
address sender,
address recipient,
UD21x18 ratePerSecond,
IERC20 token,
bool transferable
)
internal
returns (uint256 streamId);
_deposit
See the documentation for the user-facing functions that call this internal function.
function _deposit(uint256 streamId, uint128 amount) internal;
_depositViaBroker
See the documentation for the user-facing functions that call this internal function.
function _depositViaBroker(uint256 streamId, uint128 totalAmount, Broker memory broker) internal;
_pause
See the documentation for the user-facing functions that call this internal function.
function _pause(uint256 streamId) internal;
_refund
See the documentation for the user-facing functions that call this internal function.
function _refund(uint256 streamId, uint128 amount) internal;
_restart
See the documentation for the user-facing functions that call this internal function.
function _restart(uint256 streamId, UD21x18 ratePerSecond) internal;
_void
See the documentation for the user-facing functions that call this internal function.
function _void(uint256 streamId) internal;
_withdraw
See the documentation for the user-facing functions that call this internal function.
function _withdraw(
uint256 streamId,
address to,
uint128 amount
)
internal
returns (uint128 withdrawnAmount, uint128 protocolFeeAmount);