A comprehensive staking platform built on the Solana blockchain, enabling users to stake SOL tokens, earn rewards, and manage staking positions through a modern web interface.
This project is a complete staking ecosystem consisting of three main components:
- Smart Contracts - Rust/Anchor programs that manage on-chain staking logic
- Indexer - A reliable off-chain service that synchronizes blockchain state with a PostgreSQL database
- Web Client - A Next.js frontend for users to interact with staking pools and manage positions
- Multiple Staking Pools - Support for different staking pools with varying APY rates and terms
- Real-time Data - Indexed blockchain state for instant data queries
- Position Management - Track and manage active staking positions
- Reward Tracking - Monitor pending and claimed rewards
- Responsive UI - Desktop and mobile optimized interface
- Wallet Integration - Support for popular Solana wallets (Phantom, Solflare, etc.)
- Exactly-Once Processing - Guaranteed reliable transaction ingestion with recovery mechanisms
- Framework: Next.js 16+ with React 19+
- UI Components: Radix UI
- Styling: TailwindCSS with PostCSS
- Web3: Coral-xyz Anchor SDK, Solana Web3.js
- Wallet Adapter: Solana Wallet Adapter React
- Language: TypeScript with Node.js
- Runtime: tsx for development
- Database: PostgreSQL with Prisma ORM
- Blockchain Interaction: Coral-xyz Anchor, Solana Web3.js
- Logging: Pino logger
- Architecture: Background job-based with RPC failover and retry mechanisms
- Language: Rust
- Framework: Anchor (Solana program development framework)
- SPL Tokens: Solana Program Library for token operations
- Compilation: Solana BPF (sBPF)
- Package Manager: Yarn/pnpm
- Rust Toolchain: Managed via
rust-toolchain.toml - Testing: Mocha + TypeScript, ts-mocha
- Code Quality: Prettier for formatting
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Solana Blockchain β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Staking Smart Contracts (Anchor Program) β β
β β - Pool creation & management β β
β β - Stake deposits & withdrawals β β
β β - Reward calculations & distributions β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β² β
β RPC Calls β On-chain Events
β βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Indexer Service (Node.js/TS) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Components: β β
β β - Account Sync Job β β
β β - Instruction Ingestion β β
β β - Gap Filler β β
β β - Finalization & Reconciliation β β
β β - RPC Failover & Retry Logic β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Prisma ORM
βΌ
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PostgreSQL Database β
β - Pool data & state β
β - User positions & balances β
β - Transaction history β
β - Account information β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β² SQL Queries
β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Web Client (Next.js + React) β
β ββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Pages: β β
β β - Dashboard (overview & balance) β β
β β - Pools (discover & browse) β β
β β - Positions (manage stakes) β β
β β - Fund Rewards (admin interface) β β
β β - Transaction History β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββ β
β ββββββββββββββββββββββββββββββββββββββββββββββββββ β
β β Features: β β
β β - Wallet connection & signing β β
β β - Real-time data updates β β
β β - State management & hooks β β
β β - Responsive UI components β β
β ββββββββββββββββββββββββββββββββββββββββββββββββββ β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
The indexer implements several reliability mechanisms:
- Exactly-Once Processing: Claim-first commit protocol with PostgreSQL unique constraints
- Crash Recovery: Timeout-based recovery with automatic lock resets
- RPC Failover: Rotating fallbacks with exponential backoff for 429 and 5xx errors
- Component-Based Jobs: Modular architecture with separate jobs for different sync tasks
.
βββ programs/staking/ # Smart contracts
β βββ Cargo.toml # Rust package configuration
β βββ src/ # Contract source code
β
βββ indexer/ # Off-chain data indexer
β βββ package.json # Node.js dependencies
β βββ prisma/
β β βββ schema.prisma # Database schema
β β βββ migrations/ # Database migrations
β βββ src/
β β βββ index.ts # Entry point
β β βββ logger.ts # Logging setup
β β βββ alerts/ # Alert mechanisms
β β βββ ingestion/ # Data ingestion jobs
β β βββ jobs/ # Background jobs
β β βββ program/ # Program interaction logic
β β βββ rpc/ # RPC client & failover
β βββ README.md # Indexer-specific docs
β
βββ staking_client/ # Next.js web frontend
β βββ package.json # React dependencies
β βββ tsconfig.json # TypeScript config
β βββ next.config.mjs # Next.js configuration
β βββ app/ # Next.js App Router
β β βββ layout.tsx # Root layout
β β βββ page.tsx # Home page
β β βββ api/ # API routes
β β βββ pools/ # Pools page & routes
β β βββ create_pool/ # Pool creation
β β βββ fund-rewards/ # Reward funding
β βββ components/ # Reusable React components
β β βββ common/ # Common components
β β βββ dashboard/ # Dashboard components
β β βββ ui/ # UI primitives
β β βββ providers/ # Context providers
β β βββ actions/ # Server actions
β βββ hooks/ # Custom React hooks
β β βββ usePools.ts # Pool data fetching
β β βββ useUserPositions.ts # User positions
β β βββ useWalletActivity.ts # Activity tracking
β β βββ use-mobile.ts # Responsive design
β βββ lib/ # Utility functions
β β βββ anchor.ts # Anchor setup
β β βββ types.ts # TypeScript types
β β βββ utils.ts # Helpers
β β βββ instructions/ # Transaction builders
β β βββ adapters/ # Data adapters
β β βββ hooks/ # Library hooks
β βββ prisma/
β β βββ schema.prisma # Client-side database schema
β βββ public/ # Static assets
β βββ styles/ # Global styles
β βββ README.md # Client-specific docs
β
βββ tests/ # Integration tests
β βββ staking.ts # Main staking tests
β βββ create_pool.ts # Pool creation tests
β
βββ trident-tests/ # Fuzz testing with Trident
β βββ Cargo.toml
β βββ Trident.toml
β βββ fuzz_0/ # Fuzz test programs
β
βββ migrations/ # Migration scripts
β βββ deploy.ts # Deployment utilities
β
βββ scripts/ # Utility scripts
β βββ global-config.ts # Global configuration
β
βββ target/ # Build artifacts
β βββ debug/ # Debug builds
β βββ release/ # Release builds
β βββ idl/ # Interface Definition Language files
β βββ types/ # Generated TypeScript types
β βββ sbpf-solana-solana/ # Solana BPF compilation
β
βββ test-ledger/ # Local validator data (gitignored)
β βββ faucet-keypair.json
β βββ validator-keypair.json
β βββ accounts/ # Validator account data
β βββ rocksdb/ # Local ledger state
β βββ snapshots/ # State snapshots
β
βββ Cargo.toml # Workspace root
βββ Anchor.toml # Anchor configuration
βββ package.json # Root package config
βββ tsconfig.json # TypeScript configuration
βββ rust-toolchain.toml # Rust version
βββ README.md # This file
User connects wallet
β
Browse available staking pools
β
Stake SOL tokens in a pool
β
Staking program processes transaction
β
Indexer captures on-chain event
β
Database updates with new position
β
Dashboard reflects updated balance & rewards
β
User can view activity history & claim rewards
- Transaction Submission: User connects wallet and submits a staking transaction (deposit, withdraw, claim)
- On-Chain Execution: Anchor smart contract validates and executes the transaction
- Event Emission: Program emits events containing transaction details
- Indexer Ingestion: Indexer service captures events via RPC calls
- Database Sync: Prisma ORM stores/updates data in PostgreSQL
- Frontend Query: Next.js app queries database via API routes or direct DB connection
- UI Update: React components display updated staking positions and rewards
Smart Contracts (programs/staking/)
- Define pool structure and rules
- Validate stake/unstake operations
- Calculate and distribute rewards
- Maintain global state
Indexer (indexer/)
- Continuously polls blockchain for new transactions
- Extracts transaction data and account information
- Handles network interruptions and recovery
- Maintains exactly-once processing guarantee
- Provides fast query API for frontend
Web Client (staking_client/)
- User-friendly interface for staking operations
- Real-time dashboard with balance and rewards
- Pool discovery and comparison
- Transaction history and status tracking
- Node.js 18+ (for indexer and client)
- Rust 1.70+ (for smart contracts)
- Solana CLI tools
- PostgreSQL 13+ (for indexer)
- A Solana wallet with devnet SOL (for testing)
-
Clone the repository
cd /path/to/staking -
Install root dependencies
yarn install
-
Setup Smart Contracts
cd programs/staking cargo build -
Setup Indexer
cd indexer npm install npm run db:migrate npm run dev -
Setup Web Client
cd staking_client npm install npm run dev
- Anchor.toml: Specifies program IDs, RPC endpoints, and wallet location
- indexer/.env: Database connection string and RPC endpoints
- staking_client/.env.local: API endpoints and feature flags
yarn buildyarn test # Run all tests
yarn test tests/staking.ts # Run specific testTerminal 1 - Local Validator
anchor localnetTerminal 2 - Indexer
cd indexer
npm run devTerminal 3 - Web Client
cd staking_client
npm run dev- Devnet:
anchor deploy --provider.cluster devnet - Production: Follow deployment guides in respective component directories
The indexer uses Prisma to manage a PostgreSQL database with tables for:
- Staking pools and their configurations
- User staking positions and balances
- Transaction history and events
- Account state and metadata
See indexer/prisma/schema.prisma for the complete schema.
- Smart contracts use Anchor framework's built-in security checks
- Indexer implements exactly-once processing to prevent data corruption
- Private keys are managed via Solana CLI
- All transactions require wallet signatures
ISC
For more detailed information, refer to the README files in individual component directories: