Skip to content

0xLeathery/solhex

Repository files navigation

HELIX Staking Protocol

A time-locked staking protocol on Solana inspired by HEX. Users stake HLX tokens for up to 5,555 days, earning T-shares that accumulate daily inflation. Longer and larger stakes earn bonus multipliers. A periodic Big Pay Day (BPD) event redistributes a pool to active stakers. Built with Anchor 0.32.1 and Token-2022.

Program ID: E9B7BsxdPS89M66CRGGbsCzQ9LkiGv6aNsra3cNBJha7


Architecture

Component Path Stack
On-chain program programs/helix-staking/ Anchor 0.32.1, Rust, Token-2022
Frontend app/web/ Next.js 14, wallet-adapter, React Query
Indexer services/indexer/ Fastify 5, Drizzle ORM, PostgreSQL (Neon)

Tokenomics

Parameter Value
Token HLX (8 decimals, Token-2022)
Annual inflation 3.69%
Min stake 0.1 HLX
Max stake duration 5,555 days (~15.2 years)
Starting share rate 1:1 (10,000 units)

Bonus System

Longer Pays Better (LPB) — up to 2× multiplier for stakes committed to 10 years (3,641 days). Bonus scales linearly with duration.

Bigger Pays Better (BPB) — tiered bonus for larger stake sizes with diminishing returns above 1.5B tokens to prevent whale dominance. Maximum 1.5× bonus.

Big Pay Day (BPD) — periodic event that distributes a bonus pool to all active stakers proportional to their T-shares. Features:

  • Batched finalization to handle large staker counts on-chain
  • 24-hour community observation window before sealing
  • 5% per-stake share cap to prevent whale capture
  • Duration loyalty multiplier (up to 50% bonus for stakes at full term)

Unstake Penalties

Scenario Penalty
Early (before end slot) 50% minimum, up to 100%
On-time (within 14-day grace) None
Late (after grace period) 0% → 100% over 351 days

Free Claim

Snapshot-based airdrop using Merkle proofs. 10,000 HLX per SOL held at snapshot. Eligible wallets must hold ≥ 0.1 SOL. Tokens vest: 10% immediate, 90% over 30 days. Speed bonuses apply: +20% in week 1, +10% in weeks 2–4. Claim window is 180 days.


Instructions

Instruction Description
initialize Deploy and configure protocol (one-time)
create_stake Stake HLX for days (1–5,555); mints T-shares
unstake Return T-shares, receive principal ± penalties
claim_rewards Collect accrued inflation + BPD bonus
crank_distribution Public crank: advance day counter, distribute inflation
admin_mint Admin mint up to protocol cap
initialize_claim_period Create Merkle-based free claim round
free_claim Claim airdrop with Merkle proof
withdraw_vested Withdraw unlocked vested tokens
trigger_big_pay_day Initiate BPD event
finalize_bpd_calculation Process stakes in batches for BPD
seal_bpd_finalize Seal BPD after 24-hour observation window
abort_bpd Admin abort of in-progress BPD
migrate_stake Migrate legacy stake account layout
transfer_authority Initiate two-step authority handoff
accept_authority Complete authority handoff
admin_set_claim_end_slot Extend/close claim window
admin_set_slots_per_day Update slot calibration

Getting Started

Prerequisites

  • Rust / Cargo (stable)
  • Anchor CLI 0.32.1
  • Node.js 20+
  • Solana CLI
  • Docker (for verifiable builds and localnet)
cargo install --git https://github.com/coral-xyz/anchor --tag v0.32.1 anchor-cli --locked

Install Dependencies

npm install
cd app/web && npm install
cd services/indexer && npm install

Build

# Standard build
anchor build

# Verifiable build — deterministic output via Docker
anchor build --verifiable

Verifiable output: target/verifiable/helix_staking.so


Test

Tests run against solana-bankrun for fast, in-process execution without a live validator.

# All bankrun tests
npx vitest run tests/bankrun

# Single test by name
npx vitest run tests/bankrun -t "admin bounds check"

# Phase-specific tests
npx vitest run tests/bankrun/phase8.1

Frontend E2E

cd app/web
npm run dev
npx playwright test

Indexer

cd services/indexer
npm run dev:worker   # Start event indexer
npm run dev:api      # Start API server
npm run db:generate  # Generate Drizzle migrations

Localnet

Run a Solana validator with the program pre-deployed via Docker. No local Solana CLI required.

anchor build
npm run localnet:up       # Validator only
npm run localnet:up:all   # Validator + PostgreSQL for indexer
npm run localnet:down
npm run localnet:logs

The container bootstraps the full protocol: initializes GlobalState and the HLX mint, funds a test wallet with 100 SOL and 10,000 HLX. RPC available at http://localhost:8899.

See docker/README.md for Apple Silicon notes and troubleshooting.


Deploy

# 1. Verifiable build
anchor build --verifiable

# 2. Deploy
anchor deploy --provider.cluster devnet
anchor deploy --provider.cluster mainnet

# 3. Verify on-chain bytecode
anchor verify E9B7BsxdPS89M66CRGGbsCzQ9LkiGv6aNsra3cNBJha7

Security

  • Admin authority: All privileged instructions require multisig via Squads v4
  • Two-step authority transfer: transfer_authority + accept_authority prevents accidental lockout
  • Integer safety: overflow-checks = true in release profile; saturating_sub used in BPD finalization
  • BPD transparency: 24-hour observation window before seal_bpd_finalize can be called
  • Anti-whale protections: 5% per-stake BPD cap; BPB diminishing returns above 1.5B tokens
  • Frontend: All transactions simulated before presenting to wallet
  • Indexer: Atomic checkpoint + event writes; no partial state
  • RPC proxy: Method whitelist + per-IP rate limiting

Audit findings and remediations: specs/001-fix-audit-findings/


Project Structure

programs/helix-staking/src/
├── lib.rs                  # Program entry points
├── constants.rs            # Protocol constants and parameters
├── error.rs                # Custom error codes
├── events.rs               # Anchor events for indexer
├── security.rs             # Security guards
├── instructions/           # One file per instruction
└── state/
    ├── global_state.rs     # Protocol-wide state PDA
    ├── stake_account.rs    # Per-user stake PDA
    ├── claim_config.rs     # BPD / free-claim configuration PDA
    ├── claim_status.rs     # Per-user claim tracking PDA
    └── pending_authority.rs

app/web/                    # Next.js frontend
services/indexer/           # Fastify event indexer + Drizzle ORM
docker/                     # Localnet validator setup
specs/                      # Audit reports and remediation plans
tests/bankrun/              # Bankrun test suite

License

[Add license here]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors