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;

_streams

Sablier V2 Lockup Dynamic streams mapped by unsigned integer ids.

mapping(uint256 id => LockupDynamic.Stream stream) private _streams;

Functions

constructor

Emits a {TransferAdmin} event.

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

Parameters

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

getAsset

Retrieves the address of the ERC-20 asset used for streaming.

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.

getRange

Retrieves the stream's range, which is 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
override
notNull(streamId)
returns (LockupDynamic.Range memory range);

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.

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
override
notNull(streamId)
returns (LockupDynamic.Segment[] memory segments);

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.

getStream

Retrieves the stream entity.

Reverts if streamId references a null stream.

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

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.

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.

isTransferable

function isTransferable(uint256 streamId)
public
view
override(ISablierV2Lockup, SablierV2Lockup)
notNull(streamId)
returns (bool result);

isDepleted

Retrieves a flag indicating whether the stream is depleted.

Reverts if streamId references a null stream.

function isDepleted(uint256 streamId)
public
view
override(ISablierV2Lockup, SablierV2Lockup)
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) public view override(ISablierV2Lockup, SablierV2Lockup) 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.

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. 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)
public
view
override(ISablierV2Lockup, ISablierV2LockupDynamic)
notNull(streamId)
returns (uint128 streamedAmount);

Parameters

NameTypeDescription
streamIduint256The stream id for the query.

wasCanceled

Retrieves a flag indicating whether the stream was canceled.

Reverts if streamId references a null stream.

function wasCanceled(uint256 streamId)
public
view
override(ISablierV2Lockup, SablierV2Lockup)
notNull(streamId)
returns (bool result);

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

  • All requirements in {createWithMilestones} must be met for the calculated parameters.
function createWithDeltas(LockupDynamic.CreateWithDeltas calldata params)
external
override
noDelegateCall
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 {Transfer} and {CreateLockupDynamicStream} 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
override
noDelegateCall
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.

_calculateStreamedAmount

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

function _calculateStreamedAmount(uint256 streamId) internal view 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 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);

_isCallerStreamSender

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

function _isCallerStreamSender(uint256 streamId) internal view override 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 override 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 override returns (uint128);

_cancel

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

function _cancel(uint256 streamId) internal override;

_createWithMilestones

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

function _createWithMilestones(LockupDynamic.CreateWithMilestones memory params) internal returns (uint256 streamId);

_renounce

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

function _renounce(uint256 streamId) internal override;

_withdraw

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

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