LaunchpadVesting

Overview

The LaunchpadVesting smart contract is designed to manage token vesting schedules for launchpad participants. It ensures tokens are released according to predefined schedules, mitigating risks associated with immediate token liquidity. The contract uses Chainlink Keepers for automated token release and inherits functionalities from OpenZeppelin libraries for security and efficiency.

Table of Contents

  1. Dependencies

  2. State Variables

  3. Modifiers

  4. Constructor

  5. External Functions

  6. Public Functions

  7. Internal Functions

  8. Events

  9. Data Structures

Dependencies

The contract relies on several OpenZeppelin libraries and interfaces:

  • ReentrancyGuard

  • SafeMath

  • IERC20

  • SafeERC20

  • Ownable2Step

  • KeeperCompatibleInterface

  • ILaunchpadVesting

State Variables

  • IERC20 private _token: The ERC20 token being vested.

  • address public launchpad: Address of the launchpad contract.

  • uint256 public immutable START: Start time of the vesting schedule.

  • uint256 public immutable CLIFF: Cliff duration before tokens start to vest.

  • uint256 public immutable DURATION: Total duration of the vesting period.

  • uint256 public immutable SLICE_PERIOD_SECONDS: Time slices for vesting.

  • uint256 public immutable INITIAL_UNLOCK: Initial unlock percentage of tokens.

  • bytes32[] private vestingSchedulesIds: Array of vesting schedule IDs.

  • mapping(bytes32 => uint256) private userVestingScheduleId: Mapping of user vesting schedule IDs.

  • mapping(bytes32 => VestingSchedule) private vestingSchedules: Mapping of vesting schedules.

  • uint256 private vestingSchedulesTotalAmount: Total amount of tokens in all vesting schedules.

  • mapping(address => uint256) private holdersVestingCount: Mapping of vesting counts per holder.

  • uint256 public keeperInterval: Interval for Chainlink Keeper checks.

  • uint256 public keeperLastUpdatedTime: Last update time for Keeper.

Modifiers

  • onlyIfVestingScheduleNotRevoked(bytes32 vestingScheduleId): Ensures the vesting schedule is not revoked and is initialized.

Constructor

The constructor initializes the contract with the following parameters:

  • address token_: The address of the ERC20 token.

  • address _launchpad: The address of the launchpad contract.

  • uint256 _keeperInterval: The interval for Keeper checks.

  • address _owner: The address of the contract owner.

  • uint256[5] memory _vestingParams: Array containing vesting parameters [start, cliff duration, duration, slice period seconds, initial unlock].

External Functions

  • setLaunchpad(address _launchpad): Sets the launchpad address. Can only be called by the owner.

  • getVestingSchedulesCountByBeneficiary(address _beneficiary): Returns the number of vesting schedules for a beneficiary.

  • getVestingIdAtIndex(uint256 index): Returns the vesting schedule ID at a given index.

  • getVestingScheduleByAddressAndIndex(address holder, uint256 index): Returns vesting schedule information for a given holder and index.

  • getVestingSchedulesTotalAmount(): Returns the total amount of vesting schedules.

  • getToken(): Returns the address of the ERC20 token managed by the vesting contract.

  • setNewUpKeepTime(uint256 _newUpKeepTime): Sets a new start time for Chainlink Keeper.

  • setNewKeeperInterval(uint256 _newKeeperInterval): Sets a new interval for Keeper checks.

  • multisendToken(address[] memory recipients, uint256[] memory values): Sends tokens to multiple accounts.

  • checkUpkeep(bytes calldata checkData): Chainlink function to verify upkeep requirements.

  • performUpkeep(bytes calldata performData): Chainlink function to perform upkeep and release tokens.

  • createVestingSchedule(address _beneficiary, uint256 _amount): Creates a new vesting schedule.

  • release(bytes32 vestingScheduleId): Releases vested tokens for a given schedule ID.

  • computeNextVestingScheduleIdForHolder(address holder): Computes the next vesting schedule ID for a holder.

  • getLastVestingScheduleForHolder(address holder): Returns the last vesting schedule for a holder.

  • computeVestingScheduleIdForAddressAndIndex(address holder, uint256 index): Computes the vesting schedule ID for an address and index.

  • computeReleasableAmount(bytes32 vestingScheduleId): Computes the releasable amount of tokens for a given vesting schedule ID.

  • viewUserVestingDetailsIndex(bytes32 _vestingScheduleId): Returns the vesting schedule index for a given ID.

  • revoke(bytes32 vestingScheduleId): Revokes a vesting schedule and transfers unreleased tokens to the owner.

Public Functions

  • getVestingSchedulesCount(): Returns the total number of vesting schedules.

  • getVestingSchedule(bytes32 vestingScheduleId): Returns vesting schedule information for a given ID.

Internal Functions

  • _release(bytes32 vestingScheduleId): Internal function to release tokens for a given vesting schedule ID.

  • _computeReleasableAmount(VestingSchedule memory vestingSchedule): Internal function to compute the releasable amount of tokens for a vesting schedule.

Events

  • event Released(address indexed beneficiary, uint256 amount): Emitted when tokens are released.

  • event Revoked(address indexed beneficiary, bytes32 vestingScheduleId): Emitted when a vesting schedule is revoked.

Data Structures

VestingSchedule

  • bool initialized: Indicates if the schedule is initialized.

  • address beneficiary: The address of the beneficiary.

  • uint256 amountTotal: Total amount of tokens to be vested.

  • uint256 initialRelease: Amount of tokens to be initially released.

  • uint256 released: Amount of tokens released so far.

  • bool revoked: Indicates if the schedule is revoked.

KeeperCompatibleInterface

  • Inherited interface for Chainlink Keeper functionality.

ILaunchpadVesting

  • Inherited interface for Launchpad Vesting functionality.

Last updated