All projects

DeFi · Blockchain

AIChainCoin Staking

Solana staking for a token with a built-in transfer fee

Overview

A staking program on Solana for a Token-2022 token that charges a fee on every transfer. Users stake, earn rewards that accrue every second, and claim or unstake once the minimum staking period has passed.

The program is written in Rust/Anchor, with a React dApp for stakers and an admin dashboard for funding rewards and managing settings.

What it does

  • Per-second reward accrual (15% APY) on each stake
  • Configurable minimum staking period before rewards can be claimed
  • Multiple concurrent stakes per wallet, each tracked with its own timestamp
  • Claim rewards or unstake principal plus rewards in one step
  • Admin reward deposits and withdrawals from a program-owned vault
  • React dApp with a staker view and an admin dashboard

The hard parts

Staking a token that taxes itself

With a Token-2022 transfer fee, the amount a user sends is not the amount the vault receives. The program reads the mint's TransferFeeConfig, picks the older or newer fee depending on the current epoch, caps it at the configured maximum, and records only the net amount as the stake — so reward math is based on what actually arrived.

Fees on the way out, too

Every outgoing transfer — claims, unstakes, and admin withdrawals — pays the same fee, and Token-2022 rejects a transfer whose declared fee doesn't match. Each instruction computes the exact fee before calling transfer_checked_with_fee, so transfers from the program-owned vault never fail on a fee mismatch.

Concurrent stakes in fixed-size accounts

Solana accounts have a fixed size at creation, but users can open any number of stakes. I used Anchor's account reallocation to grow a wallet's stake account on each new stake, with the user paying the extra rent — no wasted space up front and no hard cap on stake count.

Tech stack

Rust / AnchorSolanaToken-2022React@solana/web3.js