Skip to main content

ISablierV2LockupDynamic

Git Source

Inherits: ISablierV2Lockup

Creates and manages lockup streams with dynamic streaming functions.

Functions

MAX_SEGMENT_COUNT

The maximum number of segments allowed in a stream.

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

function MAX_SEGMENT_COUNT() external view returns (uint256);

getRange

Retrieves the stream's range, a struct containing (i) the stream's start time and (ii) end time, both as Unix timestamps.

Reverts if streamId references a null stream.

function getRange(uint256 streamId) external view returns (LockupDynamic.Range memory range);

Parameters

NameTypeDescription
streamIduint256The stream id for the query.

getSegments

Retrieves the segments the protocol uses to compose the custom streaming curve.

Reverts if streamId references a null stream.

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

Parameters

NameTypeDescription
streamIduint256The stream id for the query.

getStream

Retrieves the stream entity.

Reverts if streamId references a null stream.

function getStream(uint256 streamId) external view returns (LockupDynamic.Stream memory stream);

Parameters

NameTypeDescription
streamIduint256The stream id for the query.

streamedAmountOf

Calculates the amount streamed to the recipient, denoted in units of the asset's decimals. When the stream is warm, the streaming function is:

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

Where:

  • xx is the elapsed time divided by the total time in the current segment.
  • expexp is the current segment exponent.
  • csacsa is the current segment amount.
  • Σ(esa)\Sigma(esa) is the sum of all elapsed segments' amounts. 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.

Reverts if streamId references a null stream.

function streamedAmountOf(uint256 streamId) external view returns (uint128 streamedAmount);

Parameters

NameTypeDescription
streamIduint256The stream id for the query.

createWithDeltas

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 deltas. The segment milestones are derived from these deltas. The stream is funded by msg.sender and is wrapped in an ERC-721 NFT.

Emits a {CreateLockupDynamicStream} and a {Transfer} event. Requirements:

  • All requirements in {createWithMilestones} must be met for the calculated parameters.
function createWithDeltas(LockupDynamic.CreateWithDeltas calldata params) external returns (uint256 streamId);

Parameters

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

Returns

NameTypeDescription
streamIduint256The id of the newly created stream.

createWithMilestones

Creates a stream with the provided segment milestones, implying the end time from the last milestone. The stream is funded by msg.sender and is wrapped in an ERC-721 NFT.

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

  • As long as the segment milestones 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_FEE.
  • params.segments must have at least one segment, but not more than MAX_SEGMENT_COUNT.
  • params.startTime must be less than the first segment's milestone.
  • The segment milestones must be arranged in ascending order.
  • The last segment milestone (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 createWithMilestones(LockupDynamic.CreateWithMilestones calldata params) external returns (uint256 streamId);

Parameters

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

Returns

NameTypeDescription
streamIduint256The id of the newly created stream.

Events

CreateLockupDynamicStream

Emitted when a stream is created.

event CreateLockupDynamicStream(
uint256 streamId,
address indexed funder,
address indexed sender,
address indexed recipient,
Lockup.CreateAmounts amounts,
IERC20 asset,
bool cancelable,
LockupDynamic.Segment[] segments,
LockupDynamic.Range range,
address broker
);