Bagsbet
Prediction markets that auto-generate from Bags.fm token launches. Bet on outcomes, win if you're right.
Install / Use
/learn @kapesgit/BagsbetREADME
The Problem
Bags.fm launches hundreds of tokens daily. Traders speculate on them but there's no structured way to put conviction behind a prediction. You either buy the token or sit on the sidelines.
The Solution
BagsMarket auto-generates prediction markets from every Bags.fm token launch. Top tokens by lifetime fees get PUMP and DUMP markets with dynamic targets based on current market cap. Anyone can bet YES or NO.
Think Polymarket, but for Bags.fm token launches on Solana.
Architecture
graph TB
subgraph User["User Flow"]
REG[Sign Up / Login]
DEP[Deposit SOL]
BET[Place YES/NO Bet]
TRADE[Buy/Sell Tokens]
WIN[Collect Winnings]
WD[Withdraw SOL/Tokens]
EXP[Export Private Key]
end
subgraph Engine["BagsMarket Engine"]
GEN["Market Generator\n(every 15 min)"]
RES["Market Resolver\n(every 1 min)"]
CLEAN["Cleanup\n(every 30 min)"]
WDPROC["Withdrawal Processor\n(every 2 min)"]
end
subgraph Sources["Token Sources"]
SDK[Bags SDK Leaderboard\n168 tokens by fees]
FEED[Bags API Feed\n100 new launches]
DEX[DexScreener Batch\nPrice + Images]
end
subgraph Oracle["4-Tier Price Oracle"]
DS[DexScreener]
BAGS[Bags.fm API]
HEL[Helius DAS]
JUP[Jupiter]
end
subgraph Data["Backend"]
API[Express API]
AUTH[JWT Auth]
CRYPT[AES-256-GCM\nWallet Encryption]
PARTNER[Partner Revenue\n25% Fee Share]
DB[(SQLite WAL)]
end
REG --> AUTH
DEP --> CRYPT
BET --> API
TRADE --> API
API --> DB
GEN -->|Top 30 by mcap| DB
SDK --> GEN
FEED --> GEN
DEX --> GEN
RES -->|Check prices| Oracle
DS -->|Primary| RES
BAGS -->|Fallback 1| RES
HEL -->|Fallback 2| RES
JUP -->|Fallback 3| RES
RES -->|Resolve + Payout| DB
DB --> WIN
WIN --> WD
EXP --> CRYPT
style REG fill:#f59e0b,color:#000
style DEP fill:#f59e0b,color:#000
style BET fill:#22c55e,color:#000
style TRADE fill:#22c55e,color:#000
style WIN fill:#22c55e,color:#000
style WD fill:#f59e0b,color:#000
style EXP fill:#ef4444,color:#fff
style SDK fill:#ff6b35,color:#fff
style FEED fill:#ff6b35,color:#fff
style DEX fill:#1a1a2e,color:#fff
style DS fill:#1a1a2e,color:#fff
style BAGS fill:#ff6b35,color:#fff
style HEL fill:#9945FF,color:#fff
style JUP fill:#9945FF,color:#fff
style API fill:#0984e3,color:#fff
style PARTNER fill:#22c55e,color:#000
style DB fill:#636e72,color:#fff
How It Works
-
Markets auto-generate -- Every 15 minutes, the engine pulls the top Bags.fm tokens by lifetime fees (SDK leaderboard, 168 tokens) plus the latest 100 from the feed. Batch price checks via DexScreener, top 30 tokens above $8K mcap get PUMP and DUMP markets with dynamic targets.
-
Users bet -- Sign up with username + password, get a custodial Solana wallet instantly. Deposit SOL, pick a market, choose YES or NO. Odds shift in real-time based on the pool. Buy and sell tokens directly via Bags swap API.
-
Oracle resolves -- When the deadline hits, a 4-tier price oracle (DexScreener > Bags API > Helius > Jupiter) checks the actual market cap. Winners split the pool (minus 2% platform fee).
-
Full wallet control -- View token balances, send tokens to any wallet, withdraw SOL, or export your private key to Phantom anytime.
Features
| Feature | Description | |---|---| | Auto-Generated Markets | PUMP/DUMP markets from Bags SDK leaderboard (168 tokens) + feed, top 30 by mcap | | 4-Tier Price Oracle | DexScreener, Bags API, Helius DAS, Jupiter -- cascading fallback | | Batch Price Engine | DexScreener batch queries (30 per call) instead of per-token, fast 15-min cycles | | Dynamic Targets | Targets scale with mcap: 5m/15m/30m/1h/4h timeframes | | Partner Revenue | 25% fee share via Bags partner key, live stats on landing page | | Custodial Wallets | No wallet connection needed. Sign up, deposit, bet | | AES-256-GCM Encryption | All private keys encrypted at rest | | Private Key Export | Export to Phantom/Backpack anytime, password-protected | | Token Balances | View all SPL tokens held in your wallet | | Token Withdrawal | Send tokens to any external Solana address | | Buy/Sell Tokens | Trade Bags tokens directly with debounced quote previews | | Sell Quote Preview | See estimated SOL return before selling | | Parimutuel Betting | Peer-to-peer pools with 2% platform fee | | Real-Time Resolution | Resolver checks every 60 seconds | | Market Sorting | Top (by mcap), New (latest), Hot (most activity) filter chips | | Leaderboard | Top predictors ranked by profit | | Portfolio | Full bet history, payouts, and P&L | | Platform Stats | Live markets, tokens, bets, SOL volume on landing page | | Glassmorphism UI | Premium dark design with warm amber palette, mobile-optimized | | Security Hardened | SSH key-only, fail2ban, UFW, 600 permissions on secrets |
Tech Stack
| Layer | Tech | |-------|------| | Frontend | React 18, Vite 5, Tailwind CSS, TypeScript | | Backend | Node.js, Express, TypeScript | | Database | SQLite (WAL mode, better-sqlite3) | | Auth | JWT (7-day expiry) + bcrypt (12 rounds) | | Encryption | AES-256-GCM (custodial wallet keys) | | Token Source | Bags SDK (leaderboard), Bags API (feed), DexScreener (batch pricing) | | Price Oracle | DexScreener, Bags API, Helius DAS, Jupiter | | Trading | Bags swap API (quote > swap > sign > send) | | Partner | Bags partner key (25% fee share), SDK claim stats | | Blockchain | Solana (web3.js, spl-token) | | Process | PM2, Nginx, Certbot SSL, fail2ban |
Quick Start
Prerequisites: Node.js 20+, a Bags.fm API key
git clone https://github.com/kapesgit/bagsbet.git
cd bagsbet
npm install
cp .env.example .env # Add your API keys
npm run dev
# Frontend (separate terminal)
cd frontend
npm install
npm run build
API
Auth
| Method | Endpoint | Description | |--------|----------|-------------| | POST | /api/auth/register | Sign up (username + password) -> JWT + custodial wallet | | POST | /api/auth/login | Log in -> JWT | | GET | /api/auth/me | Current user info |
Wallet
| Method | Endpoint | Description | |--------|----------|-------------| | GET | /api/wallet/deposit | Deposit address + on-chain balance | | POST | /api/wallet/sync | Sweep on-chain SOL to DB balance | | POST | /api/wallet/withdraw | Withdraw SOL to external address | | GET | /api/wallet/tokens | Token balances (auth required) | | POST | /api/wallet/withdraw-token | Send tokens to external wallet (auth required) | | POST | /api/wallet/export | Export private key (auth + password required) |
Markets
| Method | Endpoint | Description | |--------|----------|-------------| | GET | /api/markets | All open markets | | GET | /api/markets/:id | Single market + bet history | | GET | /api/markets/resolved | Resolved markets | | GET | /api/tokens | Tokens grouped with stats | | GET | /api/tokens/:mint/markets | All markets for a token | | GET | /api/tokens/:mint/info | Token info, creators, fees, claims |
Betting & Trading
| Method | Endpoint | Description | |--------|----------|-------------| | POST | /api/bet | Place a bet (auth required) | | GET | /api/trade/quote | Get swap quote (inputMint, outputMint, amount) | | POST | /api/trade/buy | Buy token with SOL (auth required) | | POST | /api/trade/sell | Sell token for SOL (auth required) |
Stats
| Method | Endpoint | Description | |--------|----------|-------------| | GET | /api/stats | Platform stats (markets, tokens, bets, volume) | | GET | /api/partner/stats | Partner revenue (claimed/unclaimed fees) | | GET | /api/portfolio | User bet history (auth required) | | GET | /api/leaderboard | Top predictors by profit |
Bags.fm Integration Depth
BagsMarket is deeply integrated with the Bags ecosystem:
| Integration | Status | |---|---| | Bags API feed (token launches) | Live | | Bags SDK leaderboard (top tokens by fees) | Live | | Bags SDK creators (creator cards with pfp) | Live | | Bags SDK claim events (fee claims on token pages) | Live | | Bags swap API (buy/sell tokens) | Live | | Bags partner key (25% fee revenue) | Live | | Partner claim stats (revenue tracking) | Live | | Token lifetime fees (displayed per token) | Live | | DexScreener batch pricing (market generation) | Live | | Helius DAS (image/metadata fallback) | Live |
Roadmap
- [x] Auto-generated PUMP/DUMP markets
- [x] 4-tier price oracle (DexScreener > Bags > Heli
