Pulse is a Solana-based prediction-market platform combining institutional-grade market discovery, TradingView Lightweight Charts price terminals, real-time Pyth Network Hermes v2 oracle feeds, deterministic server-authoritative settlement, and an Anchor Rust smart contract suite built for Solana Devnet.
┌────────────────────────────────────────────────────────────────────────────┐
│ Frontend SPA (apps/web · Vite + React) │
│ • Tailwind CSS + shadcn/ui dark-first trading interface │
│ • TradingView Lightweight Charts (spot & reference price lines) │
│ • Recharts (cumulative P&L & asset exposure analytics) │
│ • Solana Wallet Adapter (Phantom / Solflare) + Ed25519 signature sign-in │
└───────────────┬───────────────────────────────┬────────────────────────────┘
│ REST (/api/*) │ WebSocket (/ws)
▼ ▼
┌────────────────────────────────────────────────────────────────────────────┐
│ Backend Server (server.ts + apps/api · Port 3000) │
│ • Express REST API + Zod validation + Rate Limiting + Helmet │
│ • Ed25519 Challenge/Nonce Auth & HMAC Bearer Sessions (in-memory) │
│ • Deterministic Market Engine (CREATED→OPEN→LOCKED→RESOLVING→RESOLVED) │
│ • Live Pyth Hermes v2 Poller (SOL, BTC, ETH, JUP) + Stale Feed Guard │
│ • WebSocket Hub (live prices, countdown sync, pool deltas, activity) │
└───────────────────────────────────────────────┬────────────────────────────┘
│ Shared Contracts
▼
┌────────────────────────────────────────────────────────────────────────────┐
│ Shared Domain Package (packages/shared) │
│ • Market, Position, UserProfile, ActivityEvent, WSServerEvent types │
│ • Deterministic pool-share payout math & lifecycle transition guard │
└────────────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────────────┐
│ Solana Anchor Program (programs/pulse) │
│ • PlatformConfig PDA · Market PDA · UserParticipation PDA · Vault PDA │
│ • ResolutionRecord PDA + Pyth PriceUpdateV2 freshness & confidence checks │
└────────────────────────────────────────────────────────────────────────────┘
packages/shared(@pulse/shared): Strict TypeScript domain models, Zod request schemas, Pyth feed registry, lifecycle state machine transitions, and deterministic pool-share math.apps/api(@pulse/api): Express API, WebSocket hub, Pyth Hermes v2 oracle poller, Ed25519 authentication service, deterministic market engine, and in-memory store seeded with historical and live rounds.apps/web(@pulse/web): React + Vite + Tailwind CSS + shadcn/ui web application featuring Dashboard, Market Discovery, Market Detail, Portfolio, Activity, and Profile pages.programs/pulse: Anchor Rust smart contract (lib.rs,state.rs,errors.rs) and TypeScript integration test suite (tests/pulse.ts).server.ts: Unified Node.js entry point binding Express, WebSockets, and Vite middleware (or production static bundle) on0.0.0.0:3000.
-
Install dependencies:
npm install
-
Configure environment variables: Copy
.env.exampleto.envif customizing RPC or oracle settings:cp .env.example .env
-
Start the full-stack server (port 3000):
npm run dev
Open
http://localhost:3000in your browser. -
Run TypeScript checks, build, and automated tests:
npm run lint npm run build npm test
Markets enforce strict state transitions:
CREATED → OPEN → LOCKED → RESOLVING → RESOLVED
Supporting safety states: CANCELLED, DISPUTED, REFUNDED.
- No Post-Closure Participation: Submissions after
closesAtor outsideOPENreturn400. - Idempotency Protection: Every participation requires a unique
idempotencyKey, preventing accidental double submissions. - Single-Execution Settlement: Markets carry a per-market lock and
settledflag so payouts or refunds execute at most once. - Stale Oracle Guard: Pyth updates older than
ORACLE_MAX_AGE_SECONDS(default30s) or exceedingORACLE_MAX_CONFIDENCE_BPS(default150 bps) pause settlement (DISPUTED) rather than resolving on stale data. - Deterministic Tie & Cancellation Refunds: Exact price ties (
closePrice === openPrice) or cancelled markets transition toREFUNDED, returning 100% of participant principal.
The Anchor program under programs/pulse implements on-chain PDAs for PlatformConfig, Market, UserParticipation, MarketVault, and ResolutionRecord, validating Pyth PriceUpdateV2 accounts via pyth-solana-receiver-sdk::get_price_no_older_than.
- Rust & Cargo (
rustup) - Solana CLI (
solana --version) configured for Devnet (solana config set --url devnet) - Anchor CLI (
0.31.1)
cd programs/pulse
anchor build
anchor test
solana airdrop 2 --url devnet
anchor deploy --provider.cluster devnetAfter deploying:
- Copy the deployed Program ID into
programs/pulse/Anchor.toml,declare_id!(...)inprograms/pulse/programs/pulse/src/lib.rs, andVITE_PULSE_PROGRAM_IDin.env. - Initialize
PlatformConfigviainitialize_platform(oracle_max_age_secs, max_confidence_bps, protocol_fee_bps).
- No Server Private Keys: User wallets sign authentication challenges client-side via Phantom, Solflare, or an in-browser ephemeral Devnet keypair; no private keys are transmitted or stored on the server.
- In-Memory Session Tokens: Verified Ed25519 challenge logins issue HMAC-SHA256 Bearer tokens held exclusively in client JS memory (never
localStorageorsessionStorage). - Rate Limiting & Input Sanitization: Authentication, faucet, market creation, and participation routes enforce Express rate limits and strict Zod schema validation.
- Authorization Checks: Market resolution and cancellation require verified
ADMINauthority (403 Forbiddenotherwise).