SablierLockup
Inherits: ISablierLockup, SablierLockupBase
See the documentation in ISablierLockup.
State Variables
MAX_COUNT
The maximum number of segments and tranches allowed in Dynamic and Tranched streams respectively.
This is initialized at construction time and cannot be changed later.
uint256 public immutable override MAX_COUNT;
_cliffs
Cliff timestamp mapped by stream IDs. This is used in Lockup Linear models.
mapping(uint256 streamId => uint40 cliffTime) internal _cliffs;
_segments
Stream segments mapped by stream IDs. This is used in Lockup Dynamic models.
mapping(uint256 streamId => LockupDynamic.Segment[] segments) internal _segments;
_tranches
Stream tranches mapped by stream IDs. This is used in Lockup Tranched models.
mapping(uint256 streamId => LockupTranched.Tranche[] tranches) internal _tranches;
_unlockAmounts
Unlock amounts mapped by stream IDs. This is used in Lockup Linear models.
mapping(uint256 streamId => LockupLinear.UnlockAmounts unlockAmounts) internal _unlockAmounts;
Functions
constructor
constructor(
address initialAdmin,
ILockupNFTDescriptor initialNFTDescriptor,
uint256 maxCount
)
ERC721("Sablier Lockup NFT", "SAB-LOCKUP")
SablierLockupBase(initialAdmin, initialNFTDescriptor);
Parameters
| Name | Type | Description |
|---|---|---|
initialAdmin | address | The address of the initial contract admin. |
initialNFTDescriptor | ILockupNFTDescriptor | The address of the NFT descriptor contract. |
maxCount | uint256 | The maximum number of segments and tranched allowed in Lockup Dynamic and Lockup Tranched models, respectively. |
getCliffTime
Retrieves the stream's cliff time, which is a Unix timestamp. A value of zero means there is no cliff.
Reverts if streamId references a null stream or a non Lockup Linear stream.
function getCliffTime(uint256 streamId) external view override notNull(streamId) returns (uint40 cliffTime);
Parameters
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The stream ID for the query. |
getSegments
Retrieves the segments used to compose the dynamic distribution function.
Reverts if streamId references a null stream or a non Lockup Dynamic stream.
function getSegments(uint256 streamId)
external
view
override
notNull(streamId)
returns (LockupDynamic.Segment[] memory segments);
Parameters
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The stream ID for the query. |
Returns
| Name | Type | Description |
|---|---|---|
segments | LockupDynamic.Segment[] | See the documentation in {DataTypes}. |
getTranches
Retrieves the tranches used to compose the tranched distribution function.
Reverts if streamId references a null stream or a non Lockup Tranched stream.
function getTranches(uint256 streamId)
external
view
override
notNull(streamId)
returns (LockupTranched.Tranche[] memory tranches);
Parameters
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The stream ID for the query. |
Returns
| Name | Type | Description |
|---|---|---|
tranches | LockupTranched.Tranche[] | See the documentation in {DataTypes}. |
getUnlockAmounts
Retrieves the unlock amounts used to compose the linear distribution function.
Reverts if streamId references a null stream or a non Lockup Linear stream.
function getUnlockAmounts(uint256 streamId)
external
view
override
notNull(streamId)
returns (LockupLinear.UnlockAmounts memory unlockAmounts);
Parameters
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The stream ID for the query. |
Returns
| Name | Type | Description |
|---|---|---|
unlockAmounts | LockupLinear.UnlockAmounts | See the documentation in {DataTypes}. |
createWithDurationsLD
Creates a stream by setting the start time to block.timestamp, and the end time to the sum of block.timestamp and
all specified time durations. The segment timestamps are derived from these durations. The stream is funded by
msg.sender and is wrapped in an ERC-721 NFT.
Emits a {Transfer}, {CreateLockupDynamicStream} and {MetadataUpdate} event. Requirements:
- All requirements in {createWithTimestampsLD} must be met for the calculated parameters.
function createWithDurationsLD(
Lockup.CreateWithDurations calldata params,
LockupDynamic.SegmentWithDuration[] calldata segmentsWithDuration
)
external
payable
override
noDelegateCall
returns (uint256 streamId);
Parameters
| Name | Type | Description |
|---|---|---|
params | Lockup.CreateWithDurations | Struct encapsulating the function parameters, which are documented in {DataTypes}. |
segmentsWithDuration | LockupDynamic.SegmentWithDuration[] | Segments with durations used to compose the dynamic distribution function. Timestamps are calculated by starting from block.timestamp and adding each duration to the previous timestamp. |
Returns
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The ID of the newly created stream. |
createWithDurationsLL
Creates a stream by setting the start time to block.timestamp, and the end time to the sum of block.timestamp and
durations.total. The stream is funded by msg.sender and is wrapped in an ERC-721 NFT.
Emits a {Transfer}, {CreateLockupLinearStream} and {MetadataUpdate} event. Requirements:
- All requirements in {createWithTimestampsLL} must be met for the calculated parameters.
function createWithDurationsLL(
Lockup.CreateWithDurations calldata params,
LockupLinear.UnlockAmounts calldata unlockAmounts,
LockupLinear.Durations calldata durations
)
external
payable
override
noDelegateCall
returns (uint256 streamId);
Parameters
| Name | Type | Description |
|---|---|---|
params | Lockup.CreateWithDurations | Struct encapsulating the function parameters, which are documented in {DataTypes}. |
unlockAmounts | LockupLinear.UnlockAmounts | Struct encapsulating (i) the amount to unlock at the start time and (ii) the amount to unlock at the cliff time. |
durations | LockupLinear.Durations | Struct encapsulating (i) cliff period duration and (ii) total stream duration, both in seconds. |
Returns
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The ID of the newly created stream. |
createWithDurationsLT
Creates a stream by setting the start time to block.timestamp, and the end time to the sum of block.timestamp and
all specified time durations. The tranche timestamps are derived from these durations. The stream is funded by
msg.sender and is wrapped in an ERC-721 NFT.
Emits a {Transfer}, {CreateLockupTrancheStream} and {MetadataUpdate} event. Requirements:
- All requirements in {createWithTimestampsLT} must be met for the calculated parameters.
function createWithDurationsLT(
Lockup.CreateWithDurations calldata params,
LockupTranched.TrancheWithDuration[] calldata tranchesWithDuration
)
external
payable
override
noDelegateCall
returns (uint256 streamId);
Parameters
| Name | Type | Description |
|---|---|---|
params | Lockup.CreateWithDurations | Struct encapsulating the function parameters, which are documented in {DataTypes}. |
tranchesWithDuration | LockupTranched.TrancheWithDuration[] | Tranches with durations used to compose the tranched distribution function. Timestamps are calculated by starting from block.timestamp and adding each duration to the previous timestamp. |
Returns
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The ID of the newly created stream. |
createWithTimestampsLD
Creates a stream with the provided segment timestamps, implying the end time from the last timestamp. The stream is
funded by msg.sender and is wrapped in an ERC-721 NFT.
Emits a {Transfer}, {CreateLockupDynamicStream} and {MetadataUpdate} event. Notes:
- As long as the segment timestamps are arranged in ascending order, it is not an error for some of them to be in the past. Requirements:
- Must not be delegate called.
params.totalAmountmust be greater than zero.- If set,
params.broker.feemust not be greater thanMAX_BROKER_FEE. params.timestamps.startmust be greater than zero and less than the first segment's timestamp.segmentsmust have at least one segment, but not more thanMAX_COUNT.- The segment timestamps must be arranged in ascending order.
params.timestamps.endmust be equal to the last segment's timestamp.- The sum of the segment amounts must equal the deposit amount.
params.recipientmust not be the zero address.params.sendermust not be the zero address.msg.sendermust have allowed this contract to spend at leastparams.totalAmounttokens.params.shape.lengthmust not be greater than 32 characters.
function createWithTimestampsLD(
Lockup.CreateWithTimestamps calldata params,
LockupDynamic.Segment[] calldata segments
)
external
payable
override
noDelegateCall
returns (uint256 streamId);
Parameters
| Name | Type | Description |
|---|---|---|
params | Lockup.CreateWithTimestamps | Struct encapsulating the function parameters, which are documented in {DataTypes}. |
segments | LockupDynamic.Segment[] | Segments used to compose the dynamic distribution function. |
Returns
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The ID of the newly created stream. |
createWithTimestampsLL
Creates a stream with the provided start time and end time. The stream is funded by msg.sender and is wrapped in an
ERC-721 NFT.
Emits a {Transfer}, {CreateLockupLinearStream} and {MetadataUpdate} event. Notes:
- A cliff time of zero means there is no cliff.
- As long as the times are ordered, it is not an error for the start or the cliff time to be in the past. Requirements:
- Must not be delegate called.
params.totalAmountmust be greater than zero.- If set,
params.broker.feemust not be greater thanMAX_BROKER_FEE. params.timestamps.startmust be greater than zero and less thanparams.timestamps.end.- If set,
cliffTimemust be greater thanparams.timestamps.startand less thanparams.timestamps.end. params.recipientmust not be the zero address.params.sendermust not be the zero address.- The sum of
params.unlockAmounts.startandparams.unlockAmounts.cliffmust be less than or equal to deposit amount. - If
params.timestamps.cliffnot set, theparams.unlockAmounts.cliffmust be zero. msg.sendermust have allowed this contract to spend at leastparams.totalAmounttokens.params.shape.lengthmust not be greater than 32 characters.
function createWithTimestampsLL(
Lockup.CreateWithTimestamps calldata params,
LockupLinear.UnlockAmounts calldata unlockAmounts,
uint40 cliffTime
)
external
payable
override
noDelegateCall
returns (uint256 streamId);
Parameters
| Name | Type | Description |
|---|---|---|
params | Lockup.CreateWithTimestamps | Struct encapsulating the function parameters, which are documented in {DataTypes}. |
unlockAmounts | LockupLinear.UnlockAmounts | Struct encapsulating (i) the amount to unlock at the start time and (ii) the amount to unlock at the cliff time. |
cliffTime | uint40 | The Unix timestamp for the cliff period's end. A value of zero means there is no cliff. |
Returns
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The ID of the newly created stream. |
createWithTimestampsLT
Creates a stream with the provided tranche timestamps, implying the end time from the last timestamp. The stream is
funded by msg.sender and is wrapped in an ERC-721 NFT.
Emits a {Transfer}, {CreateLockupTrancheStream} and {MetadataUpdate} event. Notes:
- As long as the tranche timestamps are arranged in ascending order, it is not an error for some of them to be in the past. Requirements:
- Must not be delegate called.
params.totalAmountmust be greater than zero.- If set,
params.broker.feemust not be greater thanMAX_BROKER_FEE. params.timestamps.startmust be greater than zero and less than the first tranche's timestamp.tranchesmust have at least one tranche, but not more thanMAX_COUNT.- The tranche timestamps must be arranged in ascending order.
params.timestamps.endmust be equal to the last tranche's timestamp.- The sum of the tranche amounts must equal the deposit amount.
params.recipientmust not be the zero address.params.sendermust not be the zero address.msg.sendermust have allowed this contract to spend at leastparams.totalAmounttokens.params.shape.lengthmust not be greater than 32 characters.
function createWithTimestampsLT(
Lockup.CreateWithTimestamps calldata params,
LockupTranched.Tranche[] calldata tranches
)
external
payable
override
noDelegateCall
returns (uint256 streamId);
Parameters
| Name | Type | Description |
|---|---|---|
params | Lockup.CreateWithTimestamps | Struct encapsulating the function parameters, which are documented in {DataTypes}. |
tranches | LockupTranched.Tranche[] | Tranches used to compose the tranched distribution function. |
Returns
| Name | Type | Description |
|---|---|---|
streamId | uint256 | The ID of the newly created stream. |
_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 override returns (uint128);
_create
Common logic for creating a stream.
function _create(
uint256 streamId,
Lockup.CreateWithTimestamps memory params,
Lockup.CreateAmounts memory createAmounts,
Lockup.Model lockupModel
)
internal
returns (Lockup.CreateEventCommon memory);
Returns
| Name | Type | Description |
|---|---|---|
<none> | Lockup.CreateEventCommon | The common parameters emitted in the create event between all Lockup models. |
_createLD
See the documentation for the user-facing functions that call this internal function.
function _createLD(
Lockup.CreateWithTimestamps memory params,
LockupDynamic.Segment[] memory segments
)
internal
returns (uint256 streamId);
_createLL
See the documentation for the user-facing functions that call this internal function.
function _createLL(
Lockup.CreateWithTimestamps memory params,
LockupLinear.UnlockAmounts memory unlockAmounts,
uint40 cliffTime
)
internal
returns (uint256 streamId);
_createLT
See the documentation for the user-facing functions that call this internal function.
function _createLT(
Lockup.CreateWithTimestamps memory params,
LockupTranched.Tranche[] memory tranches
)
internal
returns (uint256 streamId);