MCPcopy Index your code
hub / github.com/BabylonSocial/babylon

github.com/BabylonSocial/babylon @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
18,390 symbols 66,845 edges 3,456 files 5,121 documented · 28% 14 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

🎮 Babylon

A real-time prediction market game with autonomous NPCs, perpetual futures, and gamified social mechanics.


✅ Complete Feature Set

🎯 Prediction Markets

  • 15-20 active questions at all times
  • Auto-resolution after 1-7 days
  • AMM pricing (constant product market maker)
  • Buy YES/NO shares
  • Real-time odds display

💰 Perpetual Futures

  • 32 company tickers with live prices
  • Long/short with 1-100x leverage
  • Funding rates (paid every 8h)
  • Automatic liquidations
  • Real-time PnL tracking

📱 Question-Driven Feed

  • All posts relate to active prediction questions
  • Events generated by LLM specific to questions
  • Actor posts with real personalities
  • Time-aware clue strength (strengthens toward resolution)
  • Resolution events with definitive proof
  • Group chats discuss predictions
  • Stock prices hint at outcomes

🎮 Reply Guy Mechanics

  • Rate limiting: 1 reply/hour per NPC
  • Quality scoring: length + uniqueness + content
  • Following system: 5-80% probability
  • Group chat invites: 10-60% after being followed
  • Automatic sweeps of inactive/spammy users

💵 Virtual Wallet

  • 1,000 Points starting balance
  • Transaction logging
  • Lifetime PnL tracking
  • Real-time balance updates
  • Insufficient balance validation

🔐 Authentication

  • Privy integration
  • EVM wallet support (MetaMask, Rabby, etc.)
  • Multi-provider: Wallet, Email, Farcaster
  • Multi-chain: Ethereum, Base, Optimism, Polygon, Arbitrum
  • Profile setup wizard
  • Farcaster Mini App: Automatic login via Farcaster SDK

🤖 Agent Infrastructure (ERC-8004 + Agent0)

  • Universal Registration: All entities (game, users, agents) registered on-chain
  • Permissionless Discovery: External agents discover Babylon through Agent0 registry
  • A2A Protocol: Real-time agent-to-agent communication via WebSocket
  • MCP Server: Model Context Protocol endpoint for tool discovery
  • IPFS Metadata: Decentralized agent card storage
  • Reputation System: On-chain reputation tracking and aggregation

🚀 Quick Start

# 1. Install
bun install

# 2. Configure environment
cp .env.example .env.local
# Edit .env.local with your Privy credentials + GROQ_API_KEY

# 3. Setup database
bun run prisma:generate
bun run prisma:migrate
bun run prisma:seed

# 4. (Optional) Enable Agent0 Integration
# Add to .env.local:
# AGENT0_ENABLED=true
# BASE_SEPOLIA_RPC_URL=...
# BABYLON_GAME_PRIVATE_KEY=...
# Then register Babylon: bun run scripts/register-babylon-game.ts

# 5. Start development
bun run dev   # ← Automatically starts web + game engine!

Visit http://localhost:3000 - everything runs and generates content automatically!

Development Modes

Default Mode (Recommended):

bun run dev   # ← Web + Game Engine (both automatically!)

Runs both web server AND game daemon. Content generates every 60 seconds.

Web Only (No Content Generation):

bun run dev:web-only   # Just Next.js, no daemon

Use if you're only working on frontend and don't need live content.

Serverless Mode (Test Vercel Cron Locally):

bun run dev:cron-mode   # Web + Cron simulator (not daemon)

Tests the serverless cron endpoint instead of daemon. Good for verifying Vercel behavior.

Real-Time Updates

The application uses Server-Sent Events (SSE) for real-time updates (Vercel-compatible): - Feed updates (new posts) - Market price changes - Breaking news - Chat messages

For Production (Vercel): Optionally set up Redis for cross-instance broadcasting:

# Add to Vercel environment variables
UPSTASH_REDIS_REST_URL=https://your-redis-url.upstash.io
UPSTASH_REDIS_REST_TOKEN=your-token

📱 Farcaster Mini App Setup

Babylon is configured as a Farcaster Mini App with automatic authentication. Users opening your app from Farcaster/Warpcast are logged in automatically!

Prerequisites

  • Privy account with Farcaster enabled
  • Production deployment at https://babylon.market

Configuration Steps

1. Configure Privy Dashboard (10 min)

Visit https://dashboard.privy.io/ and configure:

Enable Farcaster: - Navigate to: User management → Authentication → Socials - Enable Farcaster

⚠️ CRITICAL: Add Allowed Domains: - Navigate to: Configuration → App settings → Domains - Add these domains: - ✅ https://babylon.market (your production domain) - ⚠️ https://farcaster.xyzREQUIRED for Mini Apps! - ✅ http://localhost:3000 (for development)

Why https://farcaster.xyz? Required for iframe-in-iframe support that Farcaster Mini Apps use.

Set Callback URL: - Add: https://babylon.market/api/auth/farcaster/callback

2. Verify Environment Variables

Ensure these are set in production:

NEXT_PUBLIC_PRIVY_APP_ID=your_privy_app_id
PRIVY_APP_SECRET=your_privy_app_secret

3. Deploy

vercel --prod

4. Test in Farcaster

Create a cast in Warpcast:

Check out Babylon! 🏛️

https://babylon.market

Click to launch → Users are automatically logged in! ✨

How It Works

  1. Mini App SDK detects Farcaster context
  2. Auto-login triggers via Privy + @farcaster/miniapp-sdk
  3. User approves once
  4. Instant authentication - no forms or passwords!

Using Mini App Context in Code

import { useFarcasterMiniApp } from '@/components/providers/FarcasterFrameProvider'

function MyComponent() {
  const { isMiniApp, fid, username } = useFarcasterMiniApp()

  if (isMiniApp) {
    return 

Welcome from Farcaster, {username}!


  }

  return 

Welcome to Babylon!


}

Key Resources

  • Farcaster Mini Apps: https://miniapps.farcaster.xyz/
  • Privy Recipe: https://docs.privy.io/recipes/farcaster/mini-apps
  • Mini Apps SDK: https://github.com/farcaster/miniapp-sdk

---

🧪 Testing - Complete E2E Coverage

Complete Synpress testing implementation covering every page, button, and feature!

Quick Verification

# Verify tests work NOW (no setup):
bun test tests/unit/
# ✅ 19/19 PASS

Your Tested Features

All your requirements are tested in tests/synpress/00-critical-path.spec.ts:

✅ Load feed
✅ Comment on feed
✅ Post to feed
✅ Like feed items
✅ Visit markets
✅ Buy/sell all market types
✅ Leaderboard + ALL buttons
✅ Rewards + ALL actions

Complete Coverage

  • 21+ pages tested (every page in app)
  • Every button tested (automatic discovery)
  • All features tested (50+ features)
  • Bulletproof error detection (any error = crash)

Test Commands

bun run test:critical   # Your requirements (5 min)
bun run test:complete   # All pages + buttons (15 min)
bun run test           # Everything (40 min)

See START_TESTING_NOW.md for quick start!


Extension points exported contracts — how you extend this code

WalletPort (Interface)
(no doc) [7 implementers]
packages/core/markets/shared/common.ts
TrainableAgent (Interface)
(no doc) [6 implementers]
packages/examples/harness/src/types.ts
NpcTradeRateLimitProvider (Interface)
(no doc) [5 implementers]
packages/engine/src/services/npc-trade-rate-limiter.ts
TypedServiceContainer (Interface)
Typed overloads when BabylonServices has been augmented. [1 implementers]
packages/sim/core/types.ts
WalletMethods (Interface)
Wallet methods provided by Chroma's wallets fixture
tools/chroma/specs/helpers/privy-auth.ts
LLMCall (Interface)
* LLM Call structure in trajectory steps
packages/training/src/utils/synthetic-detector.ts
TokenBucket (Interface)
* A2A Rate Limiter * Token bucket algorithm for rate limiting agent messages
packages/a2a/src/utils/rate-limiter.ts
ExecuteWithRetryOptions (Interface)
* Options for executeWithRetry function.
packages/mcp/src/handlers/tool-handlers.ts

Core symbols most depended-on inside this repo

get
called by 5323
packages/sim/core/types.ts
log
called by 2883
packages/shared/src/utils/logger.ts
info
called by 2468
packages/shared/src/utils/logger.ts
now
called by 1827
packages/core/markets/shared/common.ts
error
called by 1010
packages/shared/src/utils/logger.ts
warn
called by 1006
packages/shared/src/utils/logger.ts
set
called by 954
packages/sim/core/types.ts
cn
called by 824
packages/shared/src/utils/ui.ts

Shape

Function 7,862
Method 6,213
Interface 2,747
Class 1,545
Enum 17
Route 6

Languages

TypeScript69%
Python31%

Modules by API surface

packages/mcp/src/types/mcp.ts178 symbols
packages/training/python/tests/test_enhanced_rewards_extended.py138 symbols
packages/training/python/tests/test_rewards_comprehensive.py137 symbols
packages/core/storage/adapters/postgres/postgres-storage-provider.ts122 symbols
packages/a2a/src/executors/babylon-executor.ts111 symbols
packages/training/python/tests/test_train_local_script.py106 symbols
packages/training/python/tests/test_run_full_pipeline.py102 symbols
packages/training/python/tests/test_scam_defense_local_pipeline.py100 symbols
packages/agents/src/plugins/babylon/integration-a2a-sdk.ts97 symbols
packages/mcp/src/handlers/tool-handlers.ts95 symbols
packages/training/python/tests/test_social_rewards.py91 symbols
packages/training/python/tests/test_archetype_scoring.py91 symbols

Datastores touched

babylonDatabase · 1 repos
babylon_testDatabase · 1 repos
dbDatabase · 1 repos
postgresDatabase · 1 repos
stewardDatabase · 1 repos
babylon_stagingDatabase · 1 repos
dbnameDatabase · 1 repos
mockDatabase · 1 repos

For agents

$ claude mcp add babylon \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact