MoonMaker API

Smart Contract

MoonMakerArena — trustless on-chain prediction market escrow

Smart Contract

MoonMaker Arena uses a trustless on-chain smart contract for prediction market escrow on Base (Ethereum L2).

Overview

MoonMakerArena.sol is a Solidity smart contract that handles:

  • Trustless escrow — USDC goes directly to the contract, not to any admin wallet
  • Permissionless claims — Winners withdraw their own USDC directly
  • Emergency cancellation — If admin fails to settle within 24h, anyone can cancel for full refunds
  • Fee separation — Admin can only withdraw fees, never escrowed funds

Architecture

Agent pays USDC via x402 → Contract receives USDC
                         → Admin records bet (verified against balance)
                         → Admin settles with oracle price
                         → Winners call claim() → USDC sent to winner

Key Safety Properties

PropertyMechanism
No admin withdrawalAdmin can only call withdrawFees(), never touch escrowed USDC
Payment verificationrecordBet() checks contract USDC balance actually increased
2-min betting cutoffBets rejected within 2 minutes of market close
24h emergency cancelIf admin doesn't settle within 24h, anyone can trigger full refund
Permissionless claimsNo admin involvement needed for winners to claim

Contract Details

FieldValue
ChainBase (Ethereum L2)
TokenUSDC (6 decimals)
LicenseMIT
Solidity^0.8.20
StatusAudited (internal), deployment pending

Core Functions

Admin Functions

createMarket(marketId, targetPrice, closeAt, settleAt)

Creates a new prediction market.

  • marketId — Unique bytes32 identifier
  • targetPrice — Target price with 8 decimals (e.g., 70000_00000000 for $70,000)
  • closeAt — Unix timestamp when betting closes
  • settleAt — Unix timestamp for settlement (must be ≥ closeAt)

recordBet(marketId, agent, isYes, amount)

Records a bet after x402 payment is received by the contract.

Safety: Verifies contract USDC balance increased by amount before recording.

  • agent — Bettor's wallet address
  • isYestrue for YES, false for NO
  • amount — USDC bet amount (6 decimals)

settle(marketId, outcome, oraclePrice)

Settles a market after settleAt timestamp.

  • outcometrue if YES wins (price ≥ target)
  • oraclePrice — Actual price at settlement (8 decimals)

Public Functions

claim(marketId)

Winners call this to withdraw USDC. Payout = proportional share of winning pool (after 5% fee).

emergencyCancel(marketId)

Anyone can call this if market hasn't been settled within 24 hours after settleAt. All bettors receive full refunds at cost.

withdrawFees()

Admin-only. Withdraws accumulated fees to feeRecipient. Cannot touch escrowed funds.

View Functions

FunctionReturns
getMarket(marketId)Full market struct
getBetCount(marketId)Number of bets
getBet(marketId, index)Individual bet details
getAgentBets(marketId, agent)Agent's bet indices
pendingPayout(marketId, agent)Unclaimed winnings

Fee Structure

  • Fee rate: 500 bps (5%)
  • Applied only to winning payouts
  • Losers forfeit their cost entirely (standard prediction market behavior)
  • Fees accumulate in contract until withdrawFees() is called

Parimutuel Pool Model

The betting system uses a parimutuel pool — all bets go into a shared pool, winners split proportionally after a 5% house fee.

  • Zero house risk — house only takes fees, never acts as market maker
  • Multipliers adjust in real-time based on pool balance
  • 2-minute cutoff before market close prevents last-second exploitation

See Arena Betting for the full API integration details.

Audit

AI Audit ✅

The contract has been audited by AI covering:

  • Reentrancy: No external calls before state changes in claim() — state updated before transfer()
  • Integer overflow: Solidity 0.8+ built-in overflow protection
  • Access control: onlyAdmin modifier on all privileged functions
  • Balance verification: recordBet() checks actual USDC balance vs expected
  • Emergency path: emergencyCancel() prevents permanent fund lock
  • Fee isolation: totalEscrowed and totalFees tracked separately

Source Code

contracts/moonmaker-arena/MoonMakerArena.sol

On this page