Skip to main content

SablierV2Lockup

Git Source

Inherits: NoDelegateCall, Adminable, ISablierV2Lockup, ERC721

See the documentation in ISablierV2Lockup.

State Variables

MAX_BROKER_FEE

Retrieves the maximum broker fee that can be charged by the broker, denoted as a fixed-point number where 1e18 is 100%.

This value is hard coded as a constant.

UD60x18 public constant override MAX_BROKER_FEE = UD60x18.wrap(0.1e18);

nextStreamId

Counter for stream IDs, used in the create functions.

uint256 public override nextStreamId;

nftDescriptor

Contract that generates the non-fungible token URI.

ISablierV2NFTDescriptor public override nftDescriptor;

_allowedToHook

Mapping of contracts allowed to hook to Sablier when a stream is canceled or when assets are withdrawn.

mapping(address recipient => bool allowed) internal _allowedToHook;

_streams

Sablier V2 Lockup streams mapped by unsigned integers.

mapping(uint256 id => Lockup.Stream stream) internal _streams;

Functions

constructor

Emits a {TransferAdmin} event.

constructor(address initialAdmin, ISablierV2NFTDescriptor initialNFTDescriptor);

Parameters

NameTypeDescription
initialAdminaddressThe address of the initial contract admin.
initialNFTDescriptorISablierV2NFTDescriptorThe address of the initial NFT descriptor.

notNull

Checks that streamId does not reference a null stream.

modifier notNull(uint256 streamId);

getAsset

Retrieves the address of the ERC-20 asset to be distributed.

Reverts if streamId references a null stream.

function getAsset(uint256 streamId) external view override notNull(streamId) returns (IERC20 asset);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

getDepositedAmount

Retrieves the amount deposited in the stream, denoted in units of the asset's decimals.

Reverts if streamId references a null stream.

function getDepositedAmount(uint256 streamId)
external
view
override
notNull(streamId)
returns (uint128 depositedAmount);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

getEndTime

Retrieves the stream's end time, which is a Unix timestamp.

Reverts if streamId references a null stream.

function getEndTime(uint256 streamId) external view override notNull(streamId) returns (uint40 endTime);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

getRecipient

Retrieves the stream's recipient.

Reverts if the NFT has been burned.

function getRecipient(uint256 streamId) external view override returns (address recipient);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

getRefundedAmount

Retrieves the amount refunded to the sender after a cancellation, denoted in units of the asset's decimals. This amount is always zero unless the stream was canceled.

Reverts if streamId references a null stream.

function getRefundedAmount(uint256 streamId)
external
view
override
notNull(streamId)
returns (uint128 refundedAmount);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

getSender

Retrieves the stream's sender.

Reverts if streamId references a null stream.

function getSender(uint256 streamId) external view override notNull(streamId) returns (address sender);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

getStartTime

Retrieves the stream's start time, which is a Unix timestamp.

Reverts if streamId references a null stream.

function getStartTime(uint256 streamId) external view override notNull(streamId) returns (uint40 startTime);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

getWithdrawnAmount

Retrieves the amount withdrawn from the stream, denoted in units of the asset's decimals.

Reverts if streamId references a null stream.

function getWithdrawnAmount(uint256 streamId)
external
view
override
notNull(streamId)
returns (uint128 withdrawnAmount);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

isAllowedToHook

Retrieves a flag indicating whether the provided address is a contract allowed to hook to Sablier when a stream is canceled or when assets are withdrawn.

See ISablierLockupRecipient for more information.

function isAllowedToHook(address recipient) external view returns (bool result);

isCancelable

Retrieves a flag indicating whether the stream can be canceled. When the stream is cold, this flag is always false.

Reverts if streamId references a null stream.

function isCancelable(uint256 streamId) external view override notNull(streamId) returns (bool result);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

isCold

Retrieves a flag indicating whether the stream is cold, i.e. settled, canceled, or depleted.

Reverts if streamId references a null stream.

function isCold(uint256 streamId) external view override notNull(streamId) returns (bool result);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

isDepleted

Retrieves a flag indicating whether the stream is depleted.

Reverts if streamId references a null stream.

function isDepleted(uint256 streamId) external view override notNull(streamId) returns (bool result);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

isStream

Retrieves a flag indicating whether the stream exists.

Does not revert if streamId references a null stream.

function isStream(uint256 streamId) external view override returns (bool result);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

isTransferable

Retrieves a flag indicating whether the stream NFT can be transferred.

Reverts if streamId references a null stream.

function isTransferable(uint256 streamId) external view override notNull(streamId) returns (bool result);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

isWarm

Retrieves a flag indicating whether the stream is warm, i.e. either pending or streaming.

Reverts if streamId references a null stream.

function isWarm(uint256 streamId) external view override notNull(streamId) returns (bool result);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

refundableAmountOf

Calculates the amount that the sender would be refunded if the stream were canceled, denoted in units of the asset's decimals.

Reverts if streamId references a null stream.

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

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

statusOf

Retrieves the stream's status.

Reverts if streamId references a null stream.

function statusOf(uint256 streamId) external view override notNull(streamId) returns (Lockup.Status status);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

streamedAmountOf

Calculates the amount streamed to the recipient, denoted in units of the asset's decimals.

Reverts if streamId references a null stream. Notes:

  • Upon cancellation of the stream, the amount streamed is calculated as the difference between the deposited amount and the refunded amount. Ultimately, when the stream becomes depleted, the streamed amount is equivalent to the total amount withdrawn.
function streamedAmountOf(uint256 streamId) public view override notNull(streamId) returns (uint128 streamedAmount);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

supportsInterface

See {IERC165-supportsInterface}.

function supportsInterface(bytes4 interfaceId) public view override(IERC165, ERC721) returns (bool);

tokenURI

See {IERC721Metadata-tokenURI}.

function tokenURI(uint256 streamId) public view override(IERC721Metadata, ERC721) returns (string memory uri);

wasCanceled

Retrieves a flag indicating whether the stream was canceled.

Reverts if streamId references a null stream.

function wasCanceled(uint256 streamId) external view override notNull(streamId) returns (bool result);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

withdrawableAmountOf

Calculates the amount that the recipient can withdraw from the stream, denoted in units of the asset's decimals.

Reverts if streamId references a null stream.

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

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

allowToHook

Allows a recipient contract to hook to Sablier when a stream is canceled or when assets are withdrawn. Useful for implementing contracts that hold streams on behalf of users, such as vaults or staking contracts.

Emits an {AllowToHook} event. Notes:

function allowToHook(address recipient) external override onlyAdmin;

Parameters

NameTypeDescription
recipientaddressThe address of the contract to allow for hooks.

burn

Burns the NFT associated with the stream.

Emits a {Transfer} event. Requirements:

  • Must not be delegate called.
  • streamId must reference a depleted stream.
  • The NFT must exist.
  • msg.sender must be either the NFT owner or an approved third party.
function burn(uint256 streamId) external override noDelegateCall notNull(streamId);

Parameters

NameTypeDescription
streamIduint256The ID of the stream NFT to burn.

cancel

Cancels the stream and refunds any remaining assets to the sender.

Emits a {Transfer}, {CancelLockupStream}, and {MetadataUpdate} event. Notes:

  • If there any assets left for the recipient to withdraw, the stream is marked as canceled. Otherwise, the stream is marked as depleted.
  • This function attempts to invoke a hook on the recipient, if the resolved address is a contract. Requirements:
  • Must not be delegate called.
  • The stream must be warm and cancelable.
  • msg.sender must be the stream's sender.
function cancel(uint256 streamId) public override noDelegateCall notNull(streamId);

Parameters

NameTypeDescription
streamIduint256The ID of the stream to cancel.

cancelMultiple

Cancels multiple streams and refunds any remaining assets to the sender.

Emits multiple {Transfer}, {CancelLockupStream}, and {MetadataUpdate} events. Notes:

  • Refer to the notes in {cancel}. Requirements:
  • All requirements from {cancel} must be met for each stream.
function cancelMultiple(uint256[] calldata streamIds) external override noDelegateCall;

Parameters

NameTypeDescription
streamIdsuint256[]The IDs of the streams to cancel.

renounce

Removes the right of the stream's sender to cancel the stream.

Emits a {RenounceLockupStream} and {MetadataUpdate} event. Notes:

  • This is an irreversible operation. Requirements:
  • Must not be delegate called.
  • streamId must reference a warm stream.
  • msg.sender must be the stream's sender.
  • The stream must be cancelable.
function renounce(uint256 streamId) external override noDelegateCall notNull(streamId);

Parameters

NameTypeDescription
streamIduint256The ID of the stream to renounce.

setNFTDescriptor

Sets a new NFT descriptor contract, which produces the URI describing the Sablier stream NFTs.

Emits a {SetNFTDescriptor} and {BatchMetadataUpdate} event. Notes:

  • Does not revert if the NFT descriptor is the same. Requirements:
  • msg.sender must be the contract admin.
function setNFTDescriptor(ISablierV2NFTDescriptor newNFTDescriptor) external override onlyAdmin;

Parameters

NameTypeDescription
newNFTDescriptorISablierV2NFTDescriptorThe address of the new NFT descriptor contract.

withdraw

Withdraws the provided amount of assets from the stream to the to address.

Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event. Notes:

  • This function attempts to call a hook on the recipient of the stream, unless msg.sender is the recipient. Requirements:
  • Must not be delegate called.
  • streamId must not reference a null or depleted stream.
  • to must not be the zero address.
  • amount must be greater than zero and must not exceed the withdrawable amount.
  • to must be the recipient if msg.sender is not the stream's recipient or an approved third party.
function withdraw(uint256 streamId, address to, uint128 amount) public override noDelegateCall notNull(streamId);

Parameters

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

withdrawMax

Withdraws the maximum withdrawable amount from the stream to the provided address to.

Emits a {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} event. Notes:

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

Parameters

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

Returns

NameTypeDescription
withdrawnAmountuint128The amount withdrawn, denoted in units of the asset's decimals.

withdrawMaxAndTransfer

Withdraws the maximum withdrawable amount from the stream to the current recipient, and transfers the NFT to newRecipient.

Emits a {WithdrawFromLockupStream} and a {Transfer} event. Notes:

  • If the withdrawable amount is zero, the withdrawal is skipped.
  • Refer to the notes in {withdraw}. Requirements:
  • msg.sender must be the stream's recipient.
  • Refer to the requirements in {withdraw}.
  • Refer to the requirements in {IERC721.transferFrom}.
function withdrawMaxAndTransfer(
uint256 streamId,
address newRecipient
)
external
override
noDelegateCall
notNull(streamId)
returns (uint128 withdrawnAmount);

Parameters

NameTypeDescription
streamIduint256The ID of the stream NFT to transfer.
newRecipientaddressThe address of the new owner of the stream NFT.

Returns

NameTypeDescription
withdrawnAmountuint128The amount withdrawn, denoted in units of the asset's decimals.

withdrawMultiple

Withdraws assets from streams to the recipient of each stream.

Emits multiple {Transfer}, {WithdrawFromLockupStream}, and {MetadataUpdate} events. Notes:

  • This function attempts to call a hook on the recipient of each stream, unless msg.sender is the recipient. Requirements:
  • Must not be delegate called.
  • There must be an equal number of streamIds and amounts.
  • Each stream ID in the array must not reference a null or depleted stream.
  • Each amount in the array must be greater than zero and must not exceed the withdrawable amount.
function withdrawMultiple(uint256[] calldata streamIds, uint128[] calldata amounts) external override noDelegateCall;

Parameters

NameTypeDescription
streamIdsuint256[]The IDs of the streams to withdraw from.
amountsuint128[]The amounts to withdraw, denoted in units of the asset's decimals.

_calculateStreamedAmount

Calculates the streamed amount of the stream without looking up the stream's status.

This function is implemented by child contracts, so the logic varies depending on the model.

function _calculateStreamedAmount(uint256 streamId) internal view virtual returns (uint128);

_isCallerStreamRecipientOrApproved

Checks whether msg.sender is the stream's recipient or an approved third party.

function _isCallerStreamRecipientOrApproved(uint256 streamId) internal view returns (bool);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

_isCallerStreamSender

Checks whether msg.sender is the stream's sender.

function _isCallerStreamSender(uint256 streamId) internal view returns (bool);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

_statusOf

Retrieves the stream's status without performing a null check.

function _statusOf(uint256 streamId) internal view returns (Lockup.Status);

_streamedAmountOf

See the documentation for the user-facing functions that call this internal function.

function _streamedAmountOf(uint256 streamId) internal view returns (uint128);

_withdrawableAmountOf

See the documentation for the user-facing functions that call this internal function.

function _withdrawableAmountOf(uint256 streamId) internal view returns (uint128);

_cancel

See the documentation for the user-facing functions that call this internal function.

function _cancel(uint256 streamId) internal;

_renounce

See the documentation for the user-facing functions that call this internal function.

function _renounce(uint256 streamId) internal;

_update

Overrides the {ERC-721._update} function to check that the stream is transferable, and emits an ERC-4906 event.

There are two cases when the transferable flag is ignored:

  • If the current owner is 0, then the update is a mint and is allowed.
  • If to is 0, then the update is a burn and is also allowed.
function _update(address to, uint256 streamId, address auth) internal override returns (address);

Parameters

NameTypeDescription
toaddressThe address of the new recipient of the stream.
streamIduint256ID of the stream to update.
authaddressOptional parameter. If the value is not zero, the overridden implementation will check that auth is either the recipient of the stream, or an approved third party.

Returns

NameTypeDescription
<none>addressThe original recipient of the streamId before the update.

_withdraw

See the documentation for the user-facing functions that call this internal function.

function _withdraw(uint256 streamId, address to, uint128 amount) internal;