LockupMath
Provides functions for calculating the streamed amounts in Lockup streams. Note that 'streamed' is synonymous with 'vested'.
Functions
calculateStreamedAmountLD
Calculates the streamed amount of LD streams.
*The LD streaming model uses the following distribution function:
Where:
- is the elapsed time divided by the total duration of the current segment.
- is the current segment exponent.
- is the current segment amount.
- is the sum of all streamed segments' amounts. Notes:
- Normalization to 18 decimals is not needed because there is no mix of amounts with different decimals.
- The stream's start time must be in the past so that the calculations below do not overflow.
- 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. Assumptions:
- The sum of all segment amounts does not overflow uint128 and equals the deposited amount.
- The first segment's timestamp is greater than the start time.
- The last segment's timestamp equals the end time.
- The segment timestamps are arranged in ascending order.*
function calculateStreamedAmountLD(
uint128 depositedAmount,
uint40 endTime,
LockupDynamic.Segment[] calldata segments,
uint40 startTime,
uint128 withdrawnAmount
)
external
view
returns (uint128);
calculateStreamedAmountLL
Calculates the streamed amount of LL streams.
*The LL streaming model uses the following distribution function:
Where:
- is the elapsed time in the streamable range divided by the total streamable range.
- is the streamable amount, i.e. deposited amount minus unlock amounts' sum.
- is the start unlock amount.
- is the cliff unlock amount. Assumptions:
- The sum of the unlock amounts (start and cliff) does not overflow uint128 and is less than or equal to the deposit amount.
- The start time is before the end time.
- If the cliff time is not zero, it is after the start time and before the end time.*
function calculateStreamedAmountLL(
uint40 cliffTime,
uint128 depositedAmount,
uint40 endTime,
uint40 startTime,
LockupLinear.UnlockAmounts calldata unlockAmounts,
uint128 withdrawnAmount
)
external
view
returns (uint128);
calculateStreamedAmountLT
Calculates the streamed amount of LT streams.
*The LT streaming model uses the following distribution function:
Where:
- is the sum of all streamed tranches' amounts. Assumptions:
- The sum of all tranche amounts does not overflow uint128, and equals the deposited amount.
- The first tranche's timestamp is greater than the start time.
- The last tranche's timestamp equals the end time.
- The tranche timestamps are arranged in ascending order.*
function calculateStreamedAmountLT(
uint128 depositedAmount,
uint40 endTime,
uint40 startTime,
LockupTranched.Tranche[] calldata tranches
)
external
view
returns (uint128);