Staking Pool
Token staking with configurable reward rates and compound interest
Deployed
Anchor 0.32
Program ID
E3xDfoQKgqdCNgnK1B77xgRjKYjEsBCXvPxZDGoxercH
Repository
ExpertVagabond/solana-staking-pool
Binary Size
344K
Cluster
Devnet
Instructions
IX
initialize_pool
Creates a new staking pool for a specific token mint with a configurable reward rate.
| Parameter | Type | Description |
|---|---|---|
reward_rate | u64 | Reward tokens distributed per second per staked token |
IX
stake
Stakes tokens into the pool, creating or updating the user's stake entry.
| Parameter | Type | Description |
|---|---|---|
amount | u64 | Number of tokens to stake |
IX
unstake
Withdraws staked tokens from the pool back to the owner's wallet.
| Parameter | Type | Description |
|---|---|---|
amount | u64 | Number of tokens to unstake |
IX
claim_rewards
Claims accumulated staking rewards without unstaking the principal.
| Parameter | Type | Description |
|---|---|---|
| No parameters | ||
Accounts
StakePool
| Field | Type | Description |
|---|---|---|
authority | Pubkey | Pool creator and configuration authority |
mint | Pubkey | Token mint for this staking pool |
reward_rate | u64 | Reward rate per second per staked token |
total_staked | u64 | Total tokens currently staked in the pool |
accumulated_reward | u64 | Accumulated reward per token (scaled) |
last_update | i64 | Timestamp of the last reward calculation |
bump | u8 | PDA bump seed |
StakeEntry
| Field | Type | Description |
|---|---|---|
pool | Pubkey | The staking pool this entry belongs to |
owner | Pubkey | Wallet that owns this stake |
amount | u64 | Number of tokens staked |
reward_debt | u64 | Reward debt for accurate reward calculation |
bump | u8 | PDA bump seed |
PDA Derivation
pool
seeds = [b"pool", authority, mint]
stake
seeds = [b"stake", pool, owner]
vault
seeds = [b"vault", pool]
Error Codes
InsufficientStake
Cannot unstake more tokens than currently staked
NothingToClaim
No rewards have accrued since the last claim
Overflow
Arithmetic overflow in reward calculation
Usage Example
import { Program, BN } from "@coral-xyz/anchor"; import { PublicKey } from "@solana/web3.js"; // Derive PDAs const [poolPda] = PublicKey.findProgramAddressSync( [Buffer.from("pool"), authority.publicKey.toBuffer(), mint.toBuffer()], program.programId ); const [stakePda] = PublicKey.findProgramAddressSync( [Buffer.from("stake"), poolPda.toBuffer(), staker.publicKey.toBuffer()], program.programId ); // Stake 1000 tokens await program.methods .stake(new BN(1_000_000_000)) .accounts({ pool: poolPda, stakeEntry: stakePda, owner: staker.publicKey, mint, }) .signers([staker]) .rpc();