PartnerVesting
Inherits:IPARTNERVESTING, Context, Ownable2Step, ReentrancyGuard
Author: alexei@nebula-labs(dot)xyz
Manages linear token vesting for Lendefi partners
Implements a time-based linear vesting schedule with partner control and DAO cancellation capability
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
address private immutable _token;
_creator
Address that created this contract (Ecosystem contract)
address public immutable _creator;
_tokensReleased
Running total of tokens that have been released
uint256 private _tokensReleased;
Functions
onlyAuthorized
Restricts function access to the contract creator only
Used for cancellation functionality
modifier onlyAuthorized();
constructor
Creates a new vesting contract for a partner
Sets the beneficiary as the owner, initializes immutable vesting parameters
constructor(address token, address beneficiary, uint64 startTimestamp, uint64 durationSeconds) Ownable(beneficiary);
Parameters
token
address
Address of the ERC20 token to be vested
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 creator
function cancelContract() external nonReentrant onlyAuthorized returns (uint256 remainder);
Returns
remainder
uint256
The amount of tokens returned to the creator
release
Releases vested tokens to the beneficiary
Can be called by anyone but tokens are always sent to the owner (beneficiary)
function release() public virtual nonReentrant onlyOwner;
start
Returns the timestamp when vesting starts
function start() public view virtual returns (uint256);
Returns
<none>
uint256
The start timestamp of the vesting period
duration
Returns the duration of the vesting period
function duration() public view virtual returns (uint256);
Returns
<none>
uint256
The duration in seconds of the vesting period
end
Returns the timestamp when vesting ends
function end() public view virtual returns (uint256);
Returns
<none>
uint256
The end timestamp of the vesting period
released
Returns the amount of tokens already released
function released() public view virtual returns (uint256);
Returns
<none>
uint256
The amount of tokens that have been released so far
releasable
Calculates the amount of tokens that can be released now
function releasable() public view virtual returns (uint256);
Returns
<none>
uint256
The amount of tokens currently available to be released
vestedAmount
Calculates the amount of tokens that have vested by a given timestamp
Internal function used by releasable()
function vestedAmount(uint64 timestamp) internal view virtual returns (uint256);
Parameters
timestamp
uint64
The timestamp to calculate vested amount for
Returns
<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
function _vestingSchedule(uint256 totalAllocation, uint64 timestamp) internal view virtual returns (uint256);
Parameters
totalAllocation
uint256
Total token allocation (current balance + already released)
timestamp
uint64
The timestamp to calculate vested amount for
Returns
<none>
uint256
The amount of tokens vested at the specified timestamp
_checkAuthorized
Verifies the caller is authorized to perform creator-only actions
Throws Unauthorized error if caller is not the creator
function _checkAuthorized() internal view virtual;
Last updated