Technology Stack
App Router Structure
0G Chain Configuration (wagmi + viem)
The chain configuration lives infrontendV2/src/lib/wagmi.ts:
Key Hooks
useMarkets
Reads all markets from ProphetFactory and enriches with AMM state:useMarketDetail
Reads full state for a single market:useOracleReasoning
Fetches oracle reasoning from 0G Storage via the API proxy:useLiquidityPool
Reads LiquidityPool balance and market allocations:The Trade Panel (trade-panel.tsx)
The main trading component atfrontendV2/src/app/_components/trade-panel.tsx handles:
- Mode switching: Buy / Sell tabs
- Share type selection: YES / NO toggle
- Amount input: USDT input for buy, shares input for sell
- Quote fetching: Calls
getBuyAmountorgetSellAmounton MarketContract - Slippage calculation: Applies user’s tolerance to minSharesOut / minCollateralOut
- USDT approval: Checks allowance, requests approval if needed (one-time)
- Transaction submission:
buySharesorsellShares - Position commit: After buy, encrypts position and calls
PositionVault.commitPosition - State refresh: Refetches AMM state after transaction confirms
API Routes
/api/validate-question
Method: POSTBody:
{ question: string }Returns:
{ valid: boolean, reason: string, suggestedSources: string[] }
Calls 0G Compute via @0glabs/0g-serving-broker to validate whether the question is a valid binary prediction market question. This is server-side only — the provider address and compute credentials are not exposed to the browser.
/api/store-metadata
Method: POSTBody:
MarketMetadata objectReturns:
{ rootHash: string }
Uploads market metadata to 0G Storage using the turbo indexer. Returns the root hash which should be stored in the contract’s metadataHash field.
/api/og-storage
Method: GETQuery:
?hash=0x...Returns: Parsed JSON object stored at that root hash Proxies 0G Storage reads from the browser. Handles CORS, caches responses, and implements retry logic. The turbo indexer URL is kept server-side.
/api/faucet
Method: POSTBody:
{ address: string }Returns:
{ txHash: string }
Mints 1000 mock USDT to the specified address. Server-side only — uses a funded wallet private key to call the mock USDT contract’s mint() function.
/api/prices
Method: GETQuery:
?market=0x...Returns:
{ yesPrice: string, noPrice: string, lastUpdated: string }
Returns cached price data pushed by the market-maker agent. Falls back to reading from the contract directly if cache is stale.
0G Storage — Server-Side Client
The server-side storage client atfrontendV2/src/lib/server/og-storage.ts is used only in API routes (never in client components):
ABI Management
Contract ABIs are stored as JSON files infrontendV2/src/lib/abis/. After deploying new contracts, regenerate them:
npm run type-check to catch any function signature mismatches.
Market Status Utilities
frontendV2/src/lib/market-status.ts contains helpers for interpreting market status: