SolREM is a sleep-first product that:
- Ingests sleep data from devices (Garmin, CUDIS, WHOOP).
- Scores nightly sleep (Proof of REM points) using a research-backed sleep scoring engine.
- Provides prediction markets where users create and bet on sleep outcomes using SOL or USDC.
- Aggregates curated resources (articles, videos, research) to help users improve sleep.
Why SolREM
- Incentivizes better sleep with points and social wagering.
- Automates market settlement using device data.
- Bridges consumer sleep telemetry with decentralised prediction markets.
Key features
- Nightly sleep scoring and points: see
SleepScoringService.calculateSleepScoreand backend/services/sleepScoring.js. - Prediction markets (create/place/resolve/claim): client hooks in src/services/SolanaService.ts — e.g.
SolanaService.createMarket,SolanaService.placeBet,SolanaService.resolveMarket,SolanaService.claimWinnings. - Automatic market resolution service: see
MarketResolutionService.resolveMarketsand backend/services/marketResolution.js. - Mobile app screens: dashboard, markets, create market, market details — see src/screens/DashboardScreen.tsx, src/screens/MarketsScreen.tsx, src/screens/CreateMarketScreen.tsx, src/screens/MarketDetailsScreen.tsx.
- On-chain program (Anchor / Solana) that manages markets, bets and payouts: solana-program/programs/solrem-prediction-markets/src/lib.rs (functions:
create_market,place_bet,resolve_market,claim_winnings). - Hardcoded backend authority model:
resolve_marketchecks against a fixed backend pubkey in the program, so market state does not need a per-market authority snapshot. - Creator stake model:
create_marketauto-creates a creator bet on YES, addscreator_staketoyes_poolandtotal_pool, and transfers stake tokens into the market vault. - Claim flow:
claim_winningscloses thebetaccount after payout so the same bet cannot be claimed twice and the rent is returned to the claimant.
Getting started (local dev)
-
Backend
- Open backend/README.md for backend-specific setup.
- Install and run:
cd backend npm install cp .env.example .env # edit .env (MONGODB_URI, GARMIN_* keys if testing integrations) npm run dev
- Backend entry: backend/server.js.
-
Mobile app (React Native)
- Install JS dependencies at repo root or in app folder as appropriate.
- Run Metro and build for simulator/device per React Native docs.
-
UI (Next.js)
- UI v0 app lives in
UI v0/— build and preview with Next.js commands.
- UI v0 app lives in
-
Solana program (optional / local validator)
- Build & test Anchor program:
cd solana-program anchor build anchor test
- Program source: solana-program/programs/solrem-prediction-markets/src/lib.rs
- Build & test Anchor program:
API overview (important endpoints)
- GET /api/health — health check (backend/server.js)
- GET /api/sleep/user/:userId/data — user sleep and points (backend/routes/sleep.js)
- POST /api/garmin/sync-sleep/:userId — simulate Garmin sync (backend/routes/garmin.js)
- GET /api/markets/active — list markets (backend/routes/markets.js)
- POST /api/markets/create, /api/markets/bet, /api/markets/resolve — market lifecycle endpoints (backend/routes/markets.js)
Architecture (high level)
- Devices -> Backend ingestion (Garmin route / simulated) -> Sleep scoring engine (backend/services/sleepScoring.js) -> SleepRecord model -> Dashboard + Markets resolution (backend/services/marketResolution.js).
- Markets interact with Solana via front-end service src/services/SolanaService.ts and on-chain Anchor program solana-program/.../lib.rs.
- The on-chain backend authority is hardcoded, which keeps the MVP simple and avoids a bootstrap admin flow.
Development notes
-
Scoring weights and formulas live in backend/services/sleepScoring.js. Adjust weights or thresholds used in
SleepScoringService.calculateSleepScoreto tune behavior. -
Market resolution logic is in backend/services/marketResolution.js. Unit-test edge cases for timezones and missing sleep data.
-
Front-end mock Solana methods (in src/services/SolanaService.ts) emulate transactions — replace with real RPC / wallet integration for production.
-
Market creation requires the creator to hold enough tokens for
creator_stake; the stake transfer happens on-chain at creation time.
Testing
- Backend: run unit/integration tests (see backend/README.md).
- Solana program: run Anchor tests in solana-program/tests/solrem-prediction-markets.ts.
Deployment
- Backend: Node.js app (Docker or managed hosting). Ensure MONGODB_URI and Garmin keys are set.
- Frontend (Next.js): static or server rendering depending on routing — test build locally before pushing.
- Solana: deploy Anchor program to desired cluster and update program ID in services.
Resources & links
- Backend README: backend/README.md
- Sleep scoring service: backend/services/sleepScoring.js (
SleepScoringService.calculateSleepScore) - Market resolution service: backend/services/marketResolution.js (
MarketResolutionService.resolveMarkets) - Client Solana service: src/services/SolanaService.ts (
SolanaService.createMarket,SolanaService.placeBet,SolanaService.resolveMarket,SolanaService.claimWinnings) - On-chain program: solana-program/programs/solrem-prediction-markets/src/lib.rs
Contributing
- Open issues for feature requests or bugs.
- Follow existing code style and tests.
- Document scoring or market rule changes clearly.
License
- Add a LICENSE file as needed.