Skip to content
DashboardPROPHIT · architecture
Architecture

How a single sentence becomes onchain trades

Every PROPHIT agent follows this exact path. It runs end-to-end on Solana devnet right now — no mocks, no intermediaries

the cast

Actors

You
Phantom wallet owner
signs create_agent, pause, retire, copy
Phantom
browser extension
signs versioned transactions
Next.js web app
apps/web
UI + API routes + SSE feed
Neon Postgres
Drizzle ORM
mirrors onchain state for fast queries
Anchor program
6nHV3BW…1AngV
source of truth for every trade
Groq · Llama 3.3 70B
llama-3.3-70b-versatile
decides which market + side to trade
Executor key
DdXHh2i5…tXYg
worker-held keypair that signs trades
Worker
apps/worker · 60s tick
loops: resolve → decide → execute
60 seconds

Phase 1 · Agent creation

  1. 1
    You write a thesis

    /app/create · one sentence of conviction. The ThesisInput component posts it to /api/thesis/parse

    components/create/thesis-input.tsx
  2. 2
    Groq extracts a structured belief

    Server calls llama-3.3-70b-versatile via the OpenAI-compatible tool-calling REST with a strict JSON schema: domain, primary_asset, condition (operator/target/deadline), confidence

    app/api/thesis/parse/route.ts · packages/shared/src/groq.ts
  3. 3
    You set bankroll, risk, drawdown

    Dollar input, risk profile chip (conservative/balanced/aggressive), 30% default drawdown. Min $1 to deploy, max $2,000.

    components/create/bankroll-step.tsx
  4. 4
    Client builds a real Solana transaction

    program-client.ts composes the create_agent instruction using our hand-rolled SDK (no Anchor IDL needed). Derives Agent PDA, Vault PDA, your USDC ATA. Wraps in a VersionedTransaction so Phantom can simulate it

    lib/program-client.ts · packages/sdk/src/instructions.ts
  5. 5
    Phantom signs, we send

    wallet.signTransaction → connection.sendRawTransaction → we wait for devnet confirmation. Your USDC moves from your ATA into the agent's Vault PDA atomically

    lib/program-client.ts
  6. 6
    Server verifies + persists

    POST /api/agents receives the tx signature. Server fetches the tx from the RPC, verifies the signer matches your session and the expected Agent PDA is in the accounts list, then inserts a row into Neon

    app/api/agents/route.ts
every 60s forever

Phase 2 · Trading loop

  1. 1
    Tick starts

    Worker wakes up. First it calls resolveExpiredMarkets (Phase 3) to settle anything whose deadline passed. Then it pulls every active agent from Neon

    apps/worker/src/index.ts
  2. 2
    Candidate markets filtered

    For each agent, fetch open markets from Neon, exclude any market the agent has already traded. Skip agents with open_positions ≥ 8 or bankroll < $0.05

    apps/worker/src/index.ts
  3. 3
    Groq picks market + side + voice

    decide.ts pre-loads the Polymarket/Manifold reference price per candidate, passes the full context to Groq. The tool-call returns {market_id, side, confidence_bps, reasoning, voice}. Heuristic fallback if Groq 429s / times out.

    apps/worker/src/decide.ts
  4. 4
    Worker signs execute_trade

    Builds the instruction, signs with the executor keypair (separate from your wallet — never has access to your USDC directly), submits to devnet. Program enforces: 10% position cap, 2% slippage, 5% market share cap, drawdown auto-pause, TVL ceiling

    apps/worker/src/execute.ts · programs/prophit/src/instructions/trade.rs
  5. 5
    State propagates

    DB gets a new Trade row. Agent bankroll decreases. Market's YES or NO pool increases. Alpha Feed SSE picks it up within 4s and broadcasts. Every connected client sees it

    app/api/events/route.ts
when the clock hits zero

Phase 3 · Market resolution

  1. 1
    Deadline passes

    Short-term BTC markets expire at 5/15/60 min. Worker scans Neon for markets where resolution_deadline < now() and resolved = false

    apps/worker/src/resolve.ts
  2. 2
    Live price oracle

    Worker calls CoinGecko's public BTC price endpoint. Parses the strike out of the market question text. Compares: outcome = YES if btc > strike else NO

    apps/worker/src/resolve.ts
  3. 3
    Admin signs resolve_market

    Instruction includes the original evidence_reveal bytes whose sha256 must equal the commit stored at market creation. Program verifies the hash matches before accepting the outcome

    programs/prophit/src/instructions/market.rs
  4. 4
    Positions settled

    getProgramAccounts finds every onchain Position in this market. For each, executor signs close_position with payout = min(shares, winning_pool) for winners, 0 for losers. USDC moves from market_vault back to agent_vault

    apps/worker/src/resolve.ts · programs/prophit/src/instructions/trade.rs
  5. 5
    PnL realized

    DB updates: Trade row with action=close, realized_pnl filled in. Agent bankroll_current bumps. total_trades + wins increment. Alpha Feed + dashboard + agent detail all live-update

    apps/worker/src/resolve.ts
the moat

Phase 4 · Copy trading

  1. 1
    Copier hits Copy on an agent card

    UI calls copyAgentOnchain. A new Agent PDA is derived with the copier as owner but creator stays the original agent's creator (royalty routes back)

    lib/program-client.ts · packages/sdk/src/instructions.ts · copy_agent
  2. 2
    Copier signs copy_agent

    Instruction clones the parent's thesis_hash and domain, takes the copier's capital + risk, deploys a fresh Vault PDA

    programs/prophit/src/instructions/agent.rs
  3. 3
    Mirror trades land

    Worker sees the new agent, runs the same decision flow, opens its own positions. Parent's creator_royalty counter increments

    apps/worker/src/index.ts
  4. 4
    Royalty on profitable close

    When the clone's close_position pays out > cost_basis, pay_royalty CPI fires atomically: 10% of profit to the parent's creator wallet, the rest to the copier

    programs/prophit/src/instructions/trade.rs · pay_royalty
live state

Right now on your system

Program
6nHV3BW…1AngV
devnet · upgrade authority on your keypair
Platform PDA
5d7qYpe…HxH5
initialised · paused=false
Executor
DdXHh2i…tXYg
0.5 SOL · signs every worker trade
Markets onchain
35+
20 seeded + 3 short-term + 16 imported from Polymarket/Manifold
Decision engine
Groq · Llama 3.3 70B
tool-calling + heuristic fallback on 429/timeout
Oracles
CoinGecko + Polymarket + Manifold
BTC resolution + external-price reference signal
repo tour

Where every piece lives

  • programs/prophit/src/Anchor program · the only source of truth
  • packages/sdk/src/instructions.tsHand-rolled TS builders for every instruction
  • packages/sdk/src/seeds.tsPDA derivations (agent / vault / market / position / trade)
  • packages/shared/src/groq.tsIsomorphic Groq REST helper (OpenAI-compatible tool calls)
  • apps/web/app/api/agents/route.tsPOST verifies tx onchain before persisting
  • apps/web/app/api/events/route.tsAlpha Feed SSE (4s poll, stale-while-revalidate)
  • apps/web/lib/program-client.tsBrowser-side tx builder + Phantom signer
  • apps/web/lib/memcache.tsIn-memory TTL cache for hot API routes
  • apps/worker/src/index.ts60s tick: resolve → polymarket+manifold sync → snapshots → decide → trade → house
  • apps/worker/src/decide.tsGroq decision with external-reference context + heuristic fallback
  • apps/worker/src/execute.tsSigns + sends execute_trade with the executor key
  • apps/worker/src/resolve.tsAuto-resolve + settle on deadline (CoinGecko oracle)
  • apps/worker/src/polymarket.tsGamma CLOB sync + keyword linking to PROPHIT markets
  • apps/worker/src/manifold.tsManifold search-markets sync + richer /v0/market fidelity
  • apps/worker/src/house-agent.tsHouse counter-agent: takes imbalanced side
  • apps/worker/src/snapshots.tsTime-series snapshot writer (for price charts)
  • scripts/setup-platform.tsOne-time platform init onchain
  • scripts/seed-markets.tsAdmin seeds the canonical 20 markets
  • scripts/import-external-markets.tsMints top Polymarket+Manifold markets as PROPHIT-native mirrors
  • scripts/seed-demo.tsOne-shot demo seed: house agent + 3 example agents + market activity