Skip to main content

Technology Stack


App Router Structure


0G Chain Configuration (wagmi + viem)

The chain configuration lives in frontendV2/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 at frontendV2/src/app/_components/trade-panel.tsx handles:
  1. Mode switching: Buy / Sell tabs
  2. Share type selection: YES / NO toggle
  3. Amount input: USDT input for buy, shares input for sell
  4. Quote fetching: Calls getBuyAmount or getSellAmount on MarketContract
  5. Slippage calculation: Applies user’s tolerance to minSharesOut / minCollateralOut
  6. USDT approval: Checks allowance, requests approval if needed (one-time)
  7. Transaction submission: buyShares or sellShares
  8. Position commit: After buy, encrypts position and calls PositionVault.commitPosition
  9. State refresh: Refetches AMM state after transaction confirms

API Routes

/api/validate-question

Method: POST
Body: { 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: POST
Body: MarketMetadata object
Returns: { 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: GET
Query: ?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: POST
Body: { 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: GET
Query: ?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 at frontendV2/src/lib/server/og-storage.ts is used only in API routes (never in client components):
Never import og-storage.ts from client components. It uses the Node.js Buffer API and server-only env vars. Always use the /api/og-storage route from the browser.

ABI Management

Contract ABIs are stored as JSON files in frontendV2/src/lib/abis/. After deploying new contracts, regenerate them:
ABIs are imported in hooks and components:
After updating ABIs, run 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:

Development Commands