VestingMath
Library with functions needed to calculate vested amount across lockup streams.
Functions
calculateLockupDynamicStreamedAmount
Calculates the streamed amount for a Lockup dynamic stream.
Lockup dynamic 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 vested 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 calculateLockupDynamicStreamedAmount(
uint128 depositedAmount,
LockupDynamic.Segment[] memory segments,
uint40 blockTimestamp,
Lockup.Timestamps memory timestamps,
uint128 withdrawnAmount
)
public
pure
returns (uint128);
calculateLockupLinearStreamedAmount
Calculates the streamed amount for a Lockup linear stream.
Lockup linear 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 calculateLockupLinearStreamedAmount(
uint128 depositedAmount,
uint40 blockTimestamp,
Lockup.Timestamps memory timestamps,
uint40 cliffTime,
LockupLinear.UnlockAmounts memory unlockAmounts,
uint128 withdrawnAmount
)
public
pure
returns (uint128);
calculateLockupTranchedStreamedAmount
Calculates the streamed amount for a Lockup tranched stream.
Lockup tranched model uses the following distribution function:
Where:
- is the sum of all vested 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 calculateLockupTranchedStreamedAmount(
uint128 depositedAmount,
uint40 blockTimestamp,
Lockup.Timestamps memory timestamps,
LockupTranched.Tranche[] memory tranches
)
public
pure
returns (uint128);