Crates.io | vestinglib |
lib.rs | vestinglib |
version | 0.1.4 |
source | src |
created_at | 2022-10-25 23:40:46.92682 |
updated_at | 2022-11-06 16:37:54.346434 |
description | A library used to compute the vesting math needed for a Solana program |
homepage | |
repository | |
max_upload_size | |
id | 697395 |
size | 16,643 |
VestingLib is a tiny library for computing a vesting schedule for a beneficiary. Developers can initialize a Vesting object by passing in the configuration parameters and compute the total amount of tokens that can be released for the beneficiary.
I'm doing a begineer's workshop on Anchor programmin at Solana Breakpoint 2022. I'll be covering basic Solana concepts by going through a practical example: creating a token vesting contract. I want the class to focus on the Solana concepts and less on the math/business logic - so I created this library to abstract the core vesting calculation away from the students.
Students can import this library and focus more on developing the Solana program.
Below is some sample code of how the library is to be used:
use std::time::{SystemTime, UNIX_EPOCH};
use vestinglib::{Vesting, CanInitialize, VestingInitParams, GetReleasableAmountParams };
// Initialize a vesting instance based on the vesting parameters
let vesting_schedule = Vesting::from_init_params(&VestingInitParams {
cliff_seconds: 31560000, // One year in seconds
duration_seconds: 126240000, // Four years in seconds
seconds_per_slice: 2592000, // One month in seconds,
start_unix: 1585181904, // Grant start time
already_issued_token_amount: 0, // No tokens were already issued
grant_token_amount: 100, // Grant is 100 tokens
revoked: false, // If true, marks grant as revoked
})?;
// Get the current time
let current_time_unix = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs();
// Returns the amount releasable by the owner of the grant.
let releasable_amount = vesting_schedule.get_releasable_amount(&GetReleasableAmountParams{
current_time_unix,
})?;