Skip to content

About

Pulse is a Solana-powered prediction market platform where users can explore crypto price predictions, participate in UP/DOWN markets using simulated credits, track real-time market data, and connect their Solana wallets. Built with React, TypeScript, Express, WebSockets, and Pyth Oracle integration.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

Pulse — Solana Prediction Market Platform

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.


Architecture Overview

┌────────────────────────────────────────────────────────────────────────────┐
│                     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 │
└────────────────────────────────────────────────────────────────────────────┘

Monorepo Workspaces

  • 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) on 0.0.0.0:3000.

Installation & Local Development

  1. Install dependencies:

    npm install
  2. Configure environment variables: Copy .env.example to .env if customizing RPC or oracle settings:

    cp .env.example .env
  3. Start the full-stack server (port 3000):

    npm run dev

    Open http://localhost:3000 in your browser.

  4. Run TypeScript checks, build, and automated tests:

    npm run lint
    npm run build
    npm test

Market Engine & Lifecycle Rules

Markets enforce strict state transitions:

CREATED → OPEN → LOCKED → RESOLVING → RESOLVED

Supporting safety states: CANCELLED, DISPUTED, REFUNDED.

  • No Post-Closure Participation: Submissions after closesAt or outside OPEN return 400.
  • Idempotency Protection: Every participation requires a unique idempotencyKey, preventing accidental double submissions.
  • Single-Execution Settlement: Markets carry a per-market lock and settled flag so payouts or refunds execute at most once.
  • Stale Oracle Guard: Pyth updates older than ORACLE_MAX_AGE_SECONDS (default 30s) or exceeding ORACLE_MAX_CONFIDENCE_BPS (default 150 bps) pause settlement (DISPUTED) rather than resolving on stale data.
  • Deterministic Tie & Cancellation Refunds: Exact price ties (closePrice === openPrice) or cancelled markets transition to REFUNDED, returning 100% of participant principal.

Solana Anchor Program & Devnet Deployment

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.

Prerequisites (Local Machine / CI with Solana Toolchain)

  • Rust & Cargo (rustup)
  • Solana CLI (solana --version) configured for Devnet (solana config set --url devnet)
  • Anchor CLI (0.31.1)

Build, Test & Deploy to Devnet

cd programs/pulse
anchor build
anchor test
solana airdrop 2 --url devnet
anchor deploy --provider.cluster devnet

After deploying:

  1. Copy the deployed Program ID into programs/pulse/Anchor.toml, declare_id!(...) in programs/pulse/programs/pulse/src/lib.rs, and VITE_PULSE_PROGRAM_ID in .env.
  2. Initialize PlatformConfig via initialize_platform(oracle_max_age_secs, max_confidence_bps, protocol_fee_bps).

Security Considerations

  • 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 localStorage or sessionStorage).
  • 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 ADMIN authority (403 Forbidden otherwise).

About

Pulse is a Solana-powered prediction market platform where users can explore crypto price predictions, participate in UP/DOWN markets using simulated credits, track real-time market data, and connect their Solana wallets. Built with React, TypeScript, Express, WebSockets, and Pyth Oracle integration.

Resources

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages