SablierV2Lockup
Inherits: IERC4906, SablierV2Base, ISablierV2Lockup, ERC721
See the documentation in ISablierV2Lockup.
State Variables
nextStreamId
Counter for stream ids, used in the create functions.
uint256 public override nextStreamId;
_nftDescriptor
Contract that generates the non-fungible token URI.
ISablierV2NFTDescriptor internal _nftDescriptor;
Functions
constructor
constructor(
address initialAdmin,
ISablierV2Comptroller initialComptroller,
ISablierV2NFTDescriptor initialNFTDescriptor
)
SablierV2Base(initialAdmin, initialComptroller);
Parameters
Name | Type | Description |
---|---|---|
initialAdmin | address | The address of the initial contract admin. |
initialComptroller | ISablierV2Comptroller | The address of the initial comptroller. |
initialNFTDescriptor | ISablierV2NFTDescriptor | The address of the initial NFT descriptor. |
notNull
Checks that streamId
does not reference a null stream.
modifier notNull(uint256 streamId);
updateMetadata
Emits an ERC-4906 event to trigger an update of the NFT metadata.
modifier updateMetadata(uint256 streamId);
getRecipient
Retrieves the stream's recipient.
Reverts if the NFT has been burned.
function getRecipient(uint256 streamId) external view override returns (address recipient);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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) public view virtual override returns (bool result);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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) public view virtual override returns (bool result);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
Name | Type | Description |
---|---|---|
streamId | uint256 | The stream id for the query. |
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) public view virtual override returns (bool result);
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 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
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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) public view virtual returns (bool);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The stream id for the query. |
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;
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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;
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
Name | Type | Description |
---|---|---|
streamIds | uint256[] | 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.
- This function attempts to invoke a hook on the stream's recipient, provided that the recipient is a contract. 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) updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The 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
Name | Type | Description |
---|---|---|
newNFTDescriptor | ISablierV2NFTDescriptor | The 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 invoke a hook on the stream's recipient, provided that the recipient is a contract and
msg.sender
is either the sender or an approved operator. Requirements: - Must not be delegate called.
streamId
must not reference a null or depleted stream.msg.sender
must be the stream's sender, the stream's recipient or an approved third party.to
must be the recipient ifmsg.sender
is the stream's sender.to
must not be the zero address.amount
must be greater than zero and must not exceed the withdrawable amount.
function withdraw(
uint256 streamId,
address to,
uint128 amount
)
public
override
noDelegateCall
updateMetadata(streamId);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The id of the stream to withdraw from. |
to | address | The address receiving the withdrawn assets. |
amount | uint128 | The 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;
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The id of the stream to withdraw from. |
to | address | The address receiving the withdrawn assets. |
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);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The id of the stream NFT to transfer. |
newRecipient | address | The address of the new owner of the stream NFT. |
withdrawMultiple
Withdraws assets from streams to the provided address to
.
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: - All requirements from {withdraw} must be met for each stream.
- There must be an equal number of
streamIds
andamounts
.
function withdrawMultiple(
uint256[] calldata streamIds,
address to,
uint128[] calldata amounts
)
external
override
noDelegateCall;
Parameters
Name | Type | Description |
---|---|---|
streamIds | uint256[] | The ids of the streams to withdraw from. |
to | address | The address receiving the withdrawn assets. |
amounts | uint128[] | The amounts to withdraw, denoted in units of the asset's decimals. |
_afterTokenTransfer
Overrides the internal ERC-721 transfer function to emit an ERC-4906 event upon transfer. The goal is to refresh the NFT metadata on external platforms.
This event is also emitted when the NFT is minted or burned.
function _afterTokenTransfer(address, address, uint256 streamId, uint256) internal override updateMetadata(streamId);
_beforeTokenTransfer
Overrides the internal ERC-721 transfer function to check that the stream is transferable.
There are two cases when the transferable flag is ignored:
- If
from
is 0, then the transfer is a mint and is allowed. - If
to
is 0, then the transfer is a burn and is also allowed.
function _beforeTokenTransfer(address from, address to, uint256 streamId, uint256) internal view override;
_isCallerStreamRecipientOrApproved
Checks whether msg.sender
is the stream's recipient or an approved third party.
function _isCallerStreamRecipientOrApproved(uint256 streamId) internal view returns (bool);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The stream id for the query. |
_isCallerStreamSender
Checks whether msg.sender
is the stream's sender.
function _isCallerStreamSender(uint256 streamId) internal view virtual returns (bool);
Parameters
Name | Type | Description |
---|---|---|
streamId | uint256 | The stream id for the query. |
_statusOf
Retrieves the stream's status without performing a null check.
function _statusOf(uint256 streamId) internal view virtual returns (Lockup.Status);
_withdrawableAmountOf
See the documentation for the user-facing functions that call this internal function.
function _withdrawableAmountOf(uint256 streamId) internal view virtual returns (uint128);
_cancel
See the documentation for the user-facing functions that call this internal function.
function _cancel(uint256 tokenId) internal virtual;
_renounce
See the documentation for the user-facing functions that call this internal function.
function _renounce(uint256 streamId) internal virtual;
_withdraw
See the documentation for the user-facing functions that call this internal function.
function _withdraw(uint256 streamId, address to, uint128 amount) internal virtual;