Skip to main content

SablierV2LockupDynamic

Git Source

Inherits: ISablierV2LockupDynamic, SablierV2Lockup

See the documentation in ISablierV2LockupDynamic.

State Variables

MAX_SEGMENT_COUNT

The maximum number of segments allowed in a stream.

This is initialized at construction time and cannot be changed later.

uint256 public immutable override MAX_SEGMENT_COUNT;

_segments

Stream segments mapped by stream IDs. This complements the _streams mapping in SablierV2Lockup.

mapping(uint256 id => LockupDynamic.Segment[] segments) internal _segments;

Functions

constructor

Emits a {TransferAdmin} event.

constructor(
address initialAdmin,
ISablierV2NFTDescriptor initialNFTDescriptor,
uint256 maxSegmentCount
)
ERC721("Sablier V2 Lockup Dynamic NFT", "SAB-V2-LOCKUP-DYN")
SablierV2Lockup(initialAdmin, initialNFTDescriptor);

Parameters

NameTypeDescription
initialAdminaddressThe address of the initial contract admin.
initialNFTDescriptorISablierV2NFTDescriptorThe address of the NFT descriptor contract.
maxSegmentCountuint256The maximum number of segments allowed in a stream.

getSegments

Retrieves the segments used to compose the dynamic distribution function.

Reverts if streamId references a null stream.

function getSegments(uint256 streamId)
external
view
override
notNull(streamId)
returns (LockupDynamic.Segment[] memory segments);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

getStream

Retrieves the full stream details.

Reverts if streamId references a null stream.

function getStream(uint256 streamId)
external
view
override
notNull(streamId)
returns (LockupDynamic.StreamLD memory stream);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

Returns

NameTypeDescription
streamLockupDynamic.StreamLDSee the documentation in {DataTypes}.

getTimestamps

Retrieves the stream's start and end timestamps.

Reverts if streamId references a null stream.

function getTimestamps(uint256 streamId)
external
view
override
notNull(streamId)
returns (LockupDynamic.Timestamps memory timestamps);

Parameters

NameTypeDescription
streamIduint256The stream ID for the query.

Returns

NameTypeDescription
timestampsLockupDynamic.TimestampsSee the documentation in {DataTypes}.

createWithDurations

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} and {CreateLockupDynamicStream} event. Requirements:

  • All requirements in {createWithTimestamps} must be met for the calculated parameters.
function createWithDurations(LockupDynamic.CreateWithDurations calldata params)
external
override
noDelegateCall
returns (uint256 streamId);

Parameters

NameTypeDescription
paramsLockupDynamic.CreateWithDurationsStruct encapsulating the function parameters, which are documented in {DataTypes}.

Returns

NameTypeDescription
streamIduint256The ID of the newly created stream.

createWithTimestamps

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} and {CreateLockupDynamicStream} 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.totalAmount must be greater than zero.
  • If set, params.broker.fee must not be greater than MAX_BROKER_FEE.
  • params.startTime must be greater than zero and less than the first segment's timestamp.
  • params.segments must have at least one segment, but not more than MAX_SEGMENT_COUNT.
  • The segment timestamps must be arranged in ascending order.
  • The last segment timestamp (i.e. the stream's end time) must be in the future.
  • The sum of the segment amounts must equal the deposit amount.
  • params.recipient must not be the zero address.
  • msg.sender must have allowed this contract to spend at least params.totalAmount assets.
function createWithTimestamps(LockupDynamic.CreateWithTimestamps calldata params)
external
override
noDelegateCall
returns (uint256 streamId);

Parameters

NameTypeDescription
paramsLockupDynamic.CreateWithTimestampsStruct encapsulating the function parameters, which are documented in {DataTypes}.

Returns

NameTypeDescription
streamIduint256The ID of the newly created stream.

_calculateStreamedAmount

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

The distribution function is:

f(x)=xexpcsa+Σ(esa)f(x) = x^{exp} * csa + \Sigma(esa)

Where:

  • xx is the elapsed time divided by the total duration of the current segment.
  • expexp is the current segment exponent.
  • csacsa is the current segment amount.
  • Σ(esa)\Sigma(esa) is the sum of all vested segments' amounts.
function _calculateStreamedAmount(uint256 streamId) internal view override returns (uint128);

_calculateStreamedAmountForMultipleSegments

Calculates the streamed amount for a stream with multiple segments. Notes:

  1. Normalization to 18 decimals is not needed because there is no mix of amounts with different decimals.
  2. The stream's start time must be in the past so that the calculations below do not overflow.
  3. The stream's end time must be in the future so that the loop below does not panic with an "index out of bounds" error.
function _calculateStreamedAmountForMultipleSegments(uint256 streamId) internal view returns (uint128);

_calculateStreamedAmountForOneSegment

Calculates the streamed amount for a stream with one segment. Normalization to 18 decimals is not needed because there is no mix of amounts with different decimals.

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

_create

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

function _create(LockupDynamic.CreateWithTimestamps memory params) internal returns (uint256 streamId);