Autonomous AI agent that pays for live oil/energy market signals via x402 micropayments on Solana mainnet, reasons about geopolitical + price data using Claude, and executes prediction market trades — governed by a spending policy.
🎯 View Hackathon Presentation ← Arrow keys to navigate
Agent Wallet: HXUP3Upm31CUYwzuB2jDvd1NYVkgpsxqiBv7ekqcB9V1 (Solana Mainnet)
Built for the Agent Wallet Hackathon (6 hours). Forked from x402-ai-Solana.
- Nexwave Platform: https://nexwave.so/
- x402 Signals API: https://nexwave.so/api/signals
- x402 Configuration: https://nexwave.so/.well-known/x402.json
- Live Demo: https://oilshock-arbitrageur.vercel.app (if deployed)
- Pays for live data — the agent wallet sends
$0.001 USDCon Solana mainnet via x402 tohttps://nexwave.so/api/signals(energy perp signals: WTI, Brent Crude, Natural Gas — mark price, 24h change, volume, OI, funding rates). - Reasons about oil markets — Claude Sonnet analyzes the signals with geopolitical context (OPEC, Iran, supply disruptions) and produces a directional call:
bullish | bearish+ confidence score. - Executes a trade — places a simulated prediction market position (DFlow/Kalshi-style) and displays a Solscan explorer link.
- Spending policy enforced — an OWS-style policy caps the agent at
$2.00 USDC/day. A demo button lets you trigger a$5.00spend attempt and watch the policy block it.
User: "Run the full trading cycle"
Agent: 🔍 Fetching premium oil signals from Nexwave x402...
💰 Paid $0.001 USDC via x402 on Solana mainnet
📊 Received: WTI $78.42 (+1.3%), Brent $81.10, NatGas $2.94
🧠 Analyzing with geopolitical context...
🚨 Decision: BULLISH (confidence: 74%) — OPEC cuts + Iran supply risk
✅ Trade executed: YES on WTI Weekly Range · $7.40 USDC notional
Browser (Next.js)
└─ POST /api/chat (AI SDK useChat)
└─ streamText (Claude Sonnet 4.6)
├─ Tool: fetch_oil_signals
│ └─ wrapFetchWithPayment(fetch, solanaSigner)
│ └─ x402 micropayment → https://nexwave.so/api/signals
├─ Tool: analyze_market
│ └─ generateText (Claude as commodities analyst)
│ └─ { direction, confidence, reason }
└─ Tool: execute_trade
└─ simulated prediction market position
Agent → GET /api/signals
Server ← 402 Payment Required (payment requirements JSON)
Agent → prepares payment header (Solana USDC transfer, signed by agent keypair)
Agent → GET /api/signals [X-PAYMENT: <signed-header>]
→ facilitator: https://facilitator.payai.network
Server ← 200 OK + signal data
{
"id": "oilshock-arbitrageur",
"name": "Restricted Agent Spending",
"rules": [
{ "type": "allowed_chains", "chain_ids": ["solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp"] },
{ "type": "spending_limits", "max_amount_usdc": "2.00", "period": "daily" }
],
"action": "deny"
}| Layer | Tech |
|---|---|
| Frontend | Next.js 15, React 19, AI SDK v5 (useChat) |
| AI | Claude Sonnet 3.7 via OpenRouter (@ai-sdk/openai) |
| Payments | x402 protocol · x402-fetch · wrapFetchWithPayment |
| Chain | Solana mainnet (solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp) |
| Asset | USDC (EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v) |
| Data | Nexwave (API) — energy + crypto perp signals |
| Facilitator | https://facilitator.payai.network |
{
"x402Version": 1,
"baseUrl": "https://nexwave.so",
"endpoints": [{
"path": "/api/signals",
"method": "GET",
"accepts": [{
"scheme": "exact",
"network": "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp",
"amount": "1000",
"asset": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
"payTo": "7RPNsA1PotVJhaAnKcBoydNgbx7YsN9kH8VBJa2g8EW9"
}]
}]
}git clone https://github.com/nexwave-so/oilshock-arbitrageur.git
cd oilshock-arbitrageur
pnpm installcp .env.example .env.localEdit .env.local:
# Solana agent wallet (base64-encoded 64-byte secret key)
SOLANA_PRIVATE_KEY=<your-base64-private-key>
# Mainnet — do not change
SOLANA_NETWORK=solana
# Helius RPC (recommended for reliability)
SOLANA_RPC_URL=https://mainnet.helius-rpc.com/?api-key=YOUR_HELIUS_API_KEY
# OpenRouter API key (Claude Sonnet via OpenRouter)
OPENROUTER_API_KEY=<your-key>The agent needs mainnet USDC to pay for signals. Each signal costs $0.001 USDC (1000 base units). A deposit of $0.10 USDC gives you ~100 signal fetches.
Generate a new keypair if needed:
node -e "
const { Keypair } = require('@solana/web3.js');
const k = Keypair.generate();
console.log('Private Key (base64):', Buffer.from(k.secretKey).toString('base64'));
console.log('Public Key:', k.publicKey.toString());
"The agent wallet also needs a small SOL balance (~0.001 SOL) for transaction fees.
pnpm dev
# → http://localhost:3000Open http://localhost:3000 and try:
- "Run Full Trading Cycle" — the main demo: x402 payment → signal fetch → Claude analysis → trade execution
- "Fetch Oil Signals Only" — just the x402 payment + raw data
- "Analyze Current Market" — fetch + analysis without trade
- "Trigger Policy Block ($5.00)" in the left sidebar — demonstrates the spending policy rejecting an over-limit transaction
src/
├── app/
│ ├── api/chat/route.ts # AI SDK streamText + 3 agent tools
│ ├── layout.tsx # Dark oil theme, OilShock header
│ ├── page.tsx # Chat UI, spending meter, policy demo
│ └── globals.css # Amber/orange dark theme CSS vars
├── lib/
│ ├── solana-accounts.ts # Keypair loading, createSolanaSigner()
│ └── env.ts # t3-env typed environment variables
└── components/
└── ai-elements/ # AI SDK UI components (from base template)
MIT