Token Vesting
Linear token vesting with cliff periods and revocable schedules
Pending
Anchor 0.32
Program ID
9e9VNYBpSGHbF2xbhGJyZDp33WGUQ6S1kpjDxoQXijbp
Repository
ExpertVagabond/solana-token-vesting
Binary Size
298K
Cluster
Devnet
Instructions
IX
create_vesting
Creates a new vesting schedule and deposits tokens into the vault. Tokens unlock linearly between cliff and end timestamps.
| Parameter | Type | Description |
|---|---|---|
total_amount | u64 | Total number of tokens to vest |
start_ts | i64 | Unix timestamp when vesting begins |
cliff_ts | i64 | Unix timestamp of the cliff (no claims before this) |
end_ts | i64 | Unix timestamp when all tokens are fully vested |
revocable | bool | Whether the authority can revoke the schedule |
IX
claim
Claims all currently vested tokens that have not yet been withdrawn by the beneficiary.
| Parameter | Type | Description |
|---|---|---|
| No parameters | ||
IX
revoke
Revokes a vesting schedule and returns unvested tokens to the authority. Only works if revocable was set to true.
| Parameter | Type | Description |
|---|---|---|
| No parameters | ||
Accounts
VestingSchedule
| Field | Type | Description |
|---|---|---|
authority | Pubkey | Wallet that created and controls the vesting schedule |
beneficiary | Pubkey | Wallet that receives the vested tokens |
mint | Pubkey | Token mint being vested |
total_amount | u64 | Total tokens in the vesting schedule |
claimed_amount | u64 | Tokens already claimed by the beneficiary |
start_ts | i64 | Vesting start timestamp |
cliff_ts | i64 | Cliff timestamp (no claims before this) |
end_ts | i64 | Timestamp when vesting is fully complete |
revocable | bool | Whether the schedule can be revoked |
revoked | bool | Whether the schedule has been revoked |
bump | u8 | PDA bump seed |
PDA Derivation
vesting
seeds = [b"vesting", authority, mint]
vault
seeds = [b"vault", vesting]
Error Codes
CliffNotReached
Cannot claim tokens before the cliff timestamp
NothingToClaim
No additional tokens have vested since the last claim
AlreadyRevoked
The vesting schedule has already been revoked
NotRevocable
This vesting schedule was created as non-revocable
InvalidSchedule
The provided timestamps are invalid (start must be before cliff, cliff before end)
Overflow
Arithmetic overflow in vested amount calculation
Usage Example
import { Program, BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; const now = Math.floor(Date.now() / 1000); // Create a 12-month vesting schedule with a 3-month cliff await program.methods .createVesting( new BN(10_000_000), // total_amount new BN(now), // start_ts new BN(now + 90 * 86400), // cliff_ts (3 months) new BN(now + 365 * 86400), // end_ts (12 months) true // revocable ) .accounts({ authority: authority.publicKey, beneficiary: beneficiary.publicKey, mint, }) .signers([authority]) .rpc();