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
Actors
Phase 1 · Agent creation
- 1You write a thesis
/app/create · one sentence of conviction. The ThesisInput component posts it to /api/thesis/parse
components/create/thesis-input.tsx - 2Groq 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 - 3You 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 - 4Client 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 - 5Phantom 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 - 6Server 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
Phase 2 · Trading loop
- 1Tick 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 - 2Candidate 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 - 3Groq 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 - 4Worker 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 - 5State 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
Phase 3 · Market resolution
- 1Deadline 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 - 2Live 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 - 3Admin 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 - 4Positions 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 - 5PnL 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
Phase 4 · Copy trading
- 1Copier 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 - 2Copier 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 - 3Mirror 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 - 4Royalty 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
Right now on your system
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