PartnerVesting
Overview
The PartnerVesting contract implements a linear token vesting mechanism designed for partner allocations within the Lendefi DAO ecosystem. It provides controlled token distribution with cancellation capabilities, allowing the parent Ecosystem contract to reclaim unvested tokens if a partnership ends.
Architecture & Design
Design Pattern
The contract employs a hub-and-spoke architecture where:
The Ecosystem contract acts as a central hub, creating and managing individual vesting instances
Each PartnerVesting contract serves as a spoke, handling vesting for a single partner
Inheritance
Ownable2Step: Provides two-step ownership transfer for enhanced security
ReentrancyGuard: Protects against reentrancy attacks
Context: Provides execution context information
Storage Design
The contract optimizes gas usage with:
Immutable Variables: All core parameters are immutable, saving gas and preventing modifications
Minimal State: Only tracks released tokens as mutable state
Type-Appropriate Storage: Uses uint64 for timestamps to optimize storage
Token Vesting Mechanism
Implementation Approach
The vesting follows a simple linear model:
Tokens vest continuously from start time to end time
No cliff period (vesting begins immediately at start)
Vested amount calculation:
totalAllocation * (currentTime - startTime) / duration
Vesting Calculation
The implementation correctly handles edge cases:
Before start: 0 tokens vested
After end: 100% tokens vested
During vesting: Linear proportion based on elapsed time
Already released tokens are properly accounted for
Inherits: IPARTNERVESTING, Context, Ownable2Step, ReentrancyGuard
State Variables
_start
start timestamp
_duration
duration seconds
_token
token address
_timelock
timelock address
_creator
creator address (Ecosystem)
_tokensReleased
amount of tokens released
Functions
onlyAuthorized
Throws if called by any account other than the timelock or creator.
constructor
Sets the owner to partner address (beneficiary), the start timestamp and the vesting duration of the vesting contract.
cancelContract
Allows the DAO to cancel the contract in case the partnership ends. First releases any vested tokens to the beneficiary, then returns the remaining unvested tokens to the creator (Ecosystem contract).
Returns
<none>
uint256
remainder The amount of tokens returned to the creator Can only be called by the creator (Ecosystem contract).
_checkAuthorized
Throws if the sender is not authorized to cancel.
release
start
duration
end
released
releasable
vestedAmount
_vestingSchedule
Events
VestingInitialized
Contract initialization event
Errors
Unauthorized
Custom errors
ZeroAddress
Last updated