TeamVesting

Git Source

Inherits:ITEAMVESTING, Context, Ownable2Step, ReentrancyGuard

Cancellable Vesting contract

Offers flexible withdrawal schedule (gas efficient)

Implements secure linear vesting for the DAO team

Note: security-contact: security@nebula-labs.xyz

State Variables

_start

Start timestamp of the vesting period

uint64 private immutable _start;

_duration

Duration of the vesting period in seconds

uint64 private immutable _duration;

_token

Address of the token being vested

_timelock

Address of the timelock controller that can cancel vesting

_tokensReleased

Running total of tokens that have been released

Functions

onlyTimelock

Restricts function access to the timelock controller only

Used for cancellation functionality

constructor

Creates a new vesting contract for a team member

Sets the beneficiary as the owner, initializes immutable vesting parameters

Parameters

Name
Type
Description

token

address

Address of the ERC20 token to be vested

timelock

address

Address of the timelock controller

beneficiary

address

Address that will receive the vested tokens

startTimestamp

uint64

UNIX timestamp when vesting begins

durationSeconds

uint64

Duration of vesting period in seconds

cancelContract

Cancels the vesting contract, releasing vested tokens and returning unvested tokens

First releases any vested tokens to the beneficiary, then returns remaining tokens to timelock

Returns

Name
Type
Description

remainder

uint256

The amount of unvested tokens returned to the timelock

release

Releases vested tokens to the beneficiary

Can be called by anyone but tokens are always sent to the owner (beneficiary)

start

Returns the timestamp when vesting starts

This value is immutable and set during contract creation

Returns

Name
Type
Description

<none>

uint256

The start timestamp of the vesting period

duration

Returns the duration of the vesting period

This value is immutable and set during contract creation

Returns

Name
Type
Description

<none>

uint256

The duration in seconds of the vesting period

end

Returns the timestamp when vesting ends

Calculated as start() + duration()

Returns

Name
Type
Description

<none>

uint256

The end timestamp of the vesting period

released

Returns the amount of tokens already released

Used in vesting calculations to determine how many more tokens can be released

Returns

Name
Type
Description

<none>

uint256

The amount of tokens that have been released so far

releasable

Calculates the amount of tokens that can be released now

Subtracts already released tokens from the total vested amount

Returns

Name
Type
Description

<none>

uint256

The amount of tokens currently available to be released

_checkTimelock

Verifies the caller is the timelock controller

Throws Unauthorized error if caller is not the timelock

vestedAmount

Calculates the amount of tokens that have vested by a given timestamp

Internal function used by releasable()

Parameters

Name
Type
Description

timestamp

uint64

The timestamp to calculate vested amount for

Returns

Name
Type
Description

<none>

uint256

The total amount of tokens vested at the specified timestamp

_vestingSchedule

Calculates vested tokens according to the linear vesting schedule

Implements the core vesting calculation logic

Parameters

Name
Type
Description

totalAllocation

uint256

Total token allocation (current balance + already released)

timestamp

uint64

The timestamp to calculate vested amount for

Returns

Name
Type
Description

<none>

uint256

The amount of tokens vested at the specified timestamp

Last updated