A production-ready, Anchor-based staking program for the Solana blockchain with configurable rewards, multi-tier referral system, and flexible admin controls.
- Token Staking — Stake SPL tokens with configurable minimum amount and lock-up period
- Progressive Rewards — Monthly reward percentages that increase over time (up to 5 years)
- 3-Tier Referral System — Earn 5%, 3%, and 2% on referred users' stakes (direct, second, third referrer)
- Admin Controls — Pause staking/withdrawals, adjust parameters, manage vault liquidity
- PDAs & Security — Program Derived Addresses for vault and state isolation
┌─────────────────────────────────────────────────────────────────┐
│ Staking Contract (Anchor) │
├─────────────────────────────────────────────────────────────────┤
│ GlobalState (PDA) │ StakingState (per-user PDA) │
│ • Admin, Mint, Vault │ • Owner, stakes[], referrers │
│ • Reward params │ • 60 monthly stake entries │
│ • Stake/Withdraw toggles │ • Referral earnings │
└─────────────────────────────────────────────────────────────────┘
| Component | Technology |
|---|---|
| Framework | Anchor 0.31.1 |
| Language | Rust |
| Blockchain | Solana |
| Client | TypeScript, @coral-xyz/anchor, @solana/spl-token |
- Rust (1.75+)
- Solana CLI (1.18+)
- Anchor 0.31.1
- Node.js 18+ & Yarn
# Clone the repository
git clone https://github.com/vladmeer/staking-sc.git
cd Staking-Contract
# Install dependencies
yarn install
# Build the program
anchor buildEdit Anchor.toml to set:
| Key | Description |
|---|---|
[programs.localnet] |
Program ID for local deployment |
[provider] |
RPC URL and wallet path |
cluster |
devnet, mainnet, or local RPC |
# Build
anchor build
# Deploy to configured cluster
anchor deploy
# Run tests
anchor test
# or
yarn run ts-mocha -p ./tsconfig.json -t 1000000 tests/**/*.ts| Instruction | Description |
|---|---|
stake |
Stake tokens. Optionally pass referrer staking states for referral rewards. |
user_withdraw |
Withdraw staked tokens after the minimum lock-up period. |
refer |
Register a referred user (admin-only). Links referrer → referred user. |
| Instruction | Description |
|---|---|
initialize |
Initialize the program with mint, min stake, period, and reward params. |
change_admin |
Transfer admin authority. |
change_stake_period |
Update minimum stake period (months). |
change_min_stake_amount |
Update minimum stake amount. |
change_reward_start_month |
Month when rewards begin. |
change_reward_start_percent |
Initial reward percentage. |
change_reward_increase_percent_per_month |
Monthly reward increase. |
change_stake_status |
Enable/disable new stakes. |
change_withdraw_status |
Enable/disable withdrawals. |
admin_deposit |
Add tokens to the vault. |
admin_withdraw |
Remove tokens from the vault. |
admin— Program adminmint— Staking token minttotal_staked_amount,total_staked_numreward_start_month,reward_start_percent,reward_increase_percent_per_monthminimum_stake_amount,minimum_stake_periodstake_enabled,withdraw_status
owner— Stakerstakes[60]— Per-month stake entries (amount, stake_num)first_referrer,second_referrer,third_referrertotal_staked_amount,withdrawn_amount
- Direct referrer: 5% of referred user's stake
- Second referrer: 3% of referred user's stake
- Third referrer: 2% of referred user's stake
Referrers must have an active staking position. Referrals are registered via refer (admin) before the referred user stakes.
Staking-Contract/
├── programs/
│ └── staking-contract/
│ └── src/
│ ├── lib.rs # Program entry
│ ├── state.rs # Account structs
│ ├── constant.rs # Seeds, limits
│ ├── errors.rs # Custom errors
│ ├── utils.rs # Rewards, time helpers
│ └── instructions/ # Instruction handlers
├── tests/
│ └── staking-contract.ts
├── migrations/
│ └── deploy.ts
├── Anchor.toml
└── package.json
Tests use Mocha and Chai. Configure keys/admin.json and keys/user.json for test signers.
anchor testISC