Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

docs(x402): refresh distribution, copilot, and sniper docs to match the shipped code

nirholas782881896d69
diff --git a/docs/agent-sniper.md b/docs/agent-sniper.md
index 949fdb9c1..8faf6580e 100644
--- a/docs/agent-sniper.md
+++ b/docs/agent-sniper.md
@@ -16,8 +16,8 @@ A snipe is not one decision. It is a chain of gates, and a coin must pass every
2. **Entry scoring** (`workers/agent-sniper/scorer.js`, pure function, no I/O). The coin must be SOL-quoted, inside the strategy's market-cap band, pass creator-history checks, and carry socials if the strategy demands them. Every skip is recorded with a reason string, so you can see why a coin was passed over, not just which ones were bought.
3. **Fleet safety band.** Worker-level env clamps (`SNIPER_MIN_MC_FLOOR_USD` / `SNIPER_MAX_MC_CEIL_USD`) tighten every strategy at once. A per-strategy bound can only narrow this band, never widen it. Unknown market cap fails closed: the sniper never buys a coin it cannot price.
4. **Mayhem gate** (`workers/agent-sniper/mayhem-gate.js`). Pump.fun "Mayhem mode" tokens are excluded by owner rule. The flag is not in the firehose, so the worker reads it from the on-chain bonding curve, one cached RPC read per mint.
-5. **Trade firewall** (`api/_lib/trade-firewall.js`). Before broadcasting, the executor runs a real simulated buy-then-sell on-chain. The classification is leg-aware: only a revert on the **sell** leg has the honeypot shape (you can get in but not out) and stays a fatal block. A revert on the **buy** leg (the payer cannot fund the probe, or the curve moved past the quoted slippage) is a warning, not a honeypot verdict, because it says nothing about sellability; on the pump.fun curve the sell path is the curve program itself, and the authority audit separately catches freeze/mint rugs. The strategy's `firewall_level` decides what a verdict does: `block` aborts the buy on a block verdict or a critical unproven-safety warning, `warn` proceeds with a lowered confidence score.
-6. **Execution** (`workers/agent-sniper/executor.js`, the only file that signs). The agent's key is decrypted from its at-rest AES-256-GCM secret box, the v0 transaction is signed and broadcast with the strategy's slippage and priority-fee settings, and an idempotency lock guarantees one buy per mint per strategy.
+5. **Trade firewall** (`api/_lib/trade-firewall.js`). Before broadcasting, the executor runs a real simulated buy-then-sell on-chain. The classification is leg-aware: only a revert on the **sell** leg has the honeypot shape (you can get in but not out) and stays a fatal block. A revert on the **buy** leg (the payer cannot fund the probe, or the curve moved past the quoted slippage) is a warning, not a honeypot verdict, because it says nothing about sellability; on the pump.fun curve the sell path is the curve program itself, and the authority audit separately catches freeze/mint rugs. The probe is also sized to the payer: when the executor hands over the wallet's known balance, the round-trip quote shrinks to what that wallet can actually simulate (sellability is a property of the coin, not of the probe size), so a thin wallet reads as a thin wallet, not as a honeypot. A wallet that cannot fund even the minimum probe gets a `probe_unaffordable` warning, which counts as critical unproven safety, never a silent pass. The strategy's `firewall_level` decides what a verdict does: `block` aborts the buy on a block verdict or a critical unproven-safety warning, `warn` proceeds with a lowered confidence score.
+6. **Execution** (`workers/agent-sniper/executor.js`, the only file that signs). The agent's key is decrypted from its at-rest AES-256-GCM secret box, the v0 transaction is signed and broadcast with the strategy's slippage and priority-fee settings, and an idempotency lock guarantees one buy per mint per strategy. Sizing shrinks instead of sitting out: a buy that would overrun the arm's remaining daily budget is clamped to the day's remainder, and a wallet short of the configured size trades at what it can afford after fee headroom, but only while the wallet stays above an operational floor; below that floor the arm sits out rather than looping on simulations it cannot fund (`resolveEntrySize` in `api/_lib/agent-trade-guards.js`).
7. **The decision ledger.** Every trade appends an entry to `agent_decisions`: the inputs (trigger, firewall verdict and score, price impact, size), a plain-language rationale, a falsifiable prediction, and a mechanically computed confidence. Entries are hash-chained (`prev_hash` to `entry_hash`), so the reasoning history cannot be silently rewritten.
8. **Position management** (`workers/agent-sniper/positions.js` + `exit-logic.js`). A sweep re-quotes every open position against the bonding curve (or the AMM after graduation), updates the high-water mark, and decides exits in strict priority order: **stop-loss, then signal-flip, then trailing-stop, then take-profit, then timeout**. The laddered variant recovers initial cost at a configured multiple and lets a moon bag ride the trailing stop.
9. **Custody audit.** Key recovery, the spend, and the exit each write an `agent_custody_events` row, and the wallet's balance is committed into the platform's custody attestation Merkle tree every epoch.
@@ -74,7 +74,7 @@ Every layer of the trade above is independently checkable. You do not need our w
The case study above audits one trade. [/sniper/experiments](/sniper/experiments) is the live version of that audit for the whole fleet, updated every 30 seconds:
- **Every arm's wallet, in the open.** Each row shows its Solana address (truncated, linked to Solscan) and its real-time SOL balance — no login, no DB query, just what the chain says right now. A "Fleet SOL on hand" tile totals it across every armed wallet.
-- **The funding source too.** The fleet's dry wallets are kept above their floor by one master wallet (`SNIPER_AUTO_FUND`, `workers/agent-sniper/auto-funder.js`). Its address and live balance are published in the same view, so funding flow into the fleet is as auditable as the fleet itself.
+- **The funding source too.** The fleet's dry wallets are kept above a per-arm funding level by one master wallet (`SNIPER_AUTO_FUND`, `workers/agent-sniper/auto-funder.js`). The trigger and refill target are sized off each arm's own largest per-trade size via `api/_lib/agent-funding-policy.js` (a wallet that cannot cover its arm's trade size is not healthy, however far above a flat floor it sits), and the economy's idle-capital reclaim reads the same two functions, so refill and reclaim cannot ping-pong the same SOL. The master's address and live balance are published in the same view, so funding flow into the fleet is as auditable as the fleet itself.
- **A "ledger →" link on every arm** goes straight to that agent's full Reasoning Ledger (`/reasoning-ledger?agent=<id>&kind=snipe`, backed by `GET /api/ledger/:agentId`): the complete, tamper-evident, hash-chained history of every buy decision that agent has made — the trigger, price impact, firewall verdict, and (for LLM-judged arms) the model's thesis and confidence at the moment it decided, plus the reconciled real outcome once the position closes (win or loss, exact SOL, the sell signature). Nothing is aggregated away; a loss is exactly as visible as a win.
- **The judgment ledger** (rendered lower on the same page) scores every LLM verdict — buys AND skips — against what the coin actually did, independent of position size, so a model's calibration is measurable even before its trades close.
@@ -113,7 +113,7 @@ The hard-config sniper is the control group: its constants (band edges, stop per
**Layer 1: LLM-judged entry (`decision_mode = 'llm'`).** An arm can skip the rule shields and instead ask a model (an OpenRouter slug, via the platform's LLM failover chain) to judge each launch, returning `{ buy, confidence, thesis }`. The verdict is persisted and later scored against what the coin actually did (`sniper_evolution_log` / the judgment ledger), so a model's calls are measured independent of trade size. The deterministic rails (firewall, Mayhem exclusion, budgets, concurrency) still apply to LLM arms identically.
-**Layer 2: intra-arm optimizer (`api/cron/sniper-optimize.js` + `api/_lib/sniper-optimizer.js`).** On a cadence it reads each arm's own real trading record over a trailing window, including the exit-reason distribution, and proposes bounded adjustments to that arm's *inward* knobs: take-profit, trailing/stop percentages, hold time, entry-quality thresholds, and per-trade size. Every proposal is clamped to a hard range and to a small per-run step, so one run can never lurch an arm to an extreme. Below `MIN_SAMPLE` closed trades the rules stay quiet, with one exception: an arm with **zero wins** over `MIN_SAMPLE_WINLESS` or more real closes and net losses gets the single de-risking move (shrink per-trade size) and nothing else, so a winless arm can never bleed at full size while waiting to accumulate a "real" sample.
+**Layer 2: intra-arm optimizer (`api/cron/sniper-optimize.js` + `api/_lib/sniper-optimizer.js`).** On a cadence it reads each arm's own real trading record over a trailing window, including the exit-reason distribution, and proposes bounded adjustments to that arm's *inward* knobs: take-profit, trailing/stop percentages, hold time, entry-quality thresholds, and per-trade size. Every proposal is clamped to a hard range and to a small per-run step, so one run can never lurch an arm to an extreme, and a `per_trade_lamports` proposal is additionally capped at the arm's own daily budget, so the optimizer can never size a bet the budget cannot fund (the drift that used to leave an arm permanently armed but unable to buy). Below `MIN_SAMPLE` closed trades the rules stay quiet, with one exception: an arm with **zero wins** over `MIN_SAMPLE_WINLESS` or more real closes and net losses gets the single de-risking move (shrink per-trade size) and nothing else, so a winless arm can never bleed at full size while waiting to accumulate a "real" sample.
Two rules exist specifically to keep the loop honest about *size*, because `avgPnlPct` is an unweighted mean of percentages while real positions differ by up to 50x. **Rule S** fires when an arm's average percent is positive but its net lamports are negative: arithmetically that is only possible when the larger bets are the worse ones, so the arm's edge does not scale and the response is to shrink the position rather than tune an exit percentage. It runs *before* the scale-up rule and claims `per_trade_lamports` first. And the high-win-rate scale-up path now additionally requires `netPnl >= 0`, so an arm can never be handed a bigger position while it is losing real money just because its hit rate looks healthy. Both encode the fleet postmortem's first lesson: win rate and average percent are vanity metrics; expectancy in lamports is the thing being optimized. It runs **shadow by default** (`SNIPER_OPTIMIZER_MODE`): it persists what it *would* do to `agent_sniper_optimizer_runs` and mutates nothing, so you can watch it make tuning calls before it ever touches a live arm. In `apply` mode it enacts changes only for arms that opted in (`auto_optimize = true`), and logs each change to the agent's tamper-evident Reasoning Ledger (`kind = 'optimize'`) next to the trades it learned from. This is the layer that would have caught the first trade's missing take-profit automatically.
diff --git a/docs/trading-copilot.md b/docs/trading-copilot.md
index 0579514b5..9c5f1be46 100644
--- a/docs/trading-copilot.md
+++ b/docs/trading-copilot.md
@@ -102,8 +102,11 @@ SSE events:
| `done` | `{ reply, proposals, citations }` | final reply |
| `error` | `{ code, message }` | turn failed |
-The provider chain is free-first and OpenAI-compatible (Groq → OpenRouter → NVIDIA, with
-paid OpenAI as the backstop), so the copilot works without any paid key. A 15s heartbeat
+The provider chain is free-first and OpenAI-compatible (Groq → OpenRouter, including any
+`OPENROUTER_FALLBACK_KEYS` → NVIDIA, with paid OpenAI as the backstop), so the copilot
+works without any paid key. Whenever the GCP project is configured, a keyless,
+credits-billed **Vertex Gemini** rung is appended unconditionally as the final anchor,
+so the chain always ends on a provider that cannot be evicted by a dead key. A 15s heartbeat
keeps the stream alive across slow tool rounds; the client aborts a genuinely dead stream
and offers Retry rather than hanging.
diff --git a/docs/x402-distribution.md b/docs/x402-distribution.md
index f9976b77a..9ab9a89d1 100644
--- a/docs/x402-distribution.md
+++ b/docs/x402-distribution.md
@@ -1,6 +1,6 @@
# x402 Distribution — getting listed and ranked everywhere
-three.ws sells 70+ pay-per-call services over [x402](x402.md). Building them is
+three.ws sells 90+ pay-per-call services over [x402](x402.md). Building them is
half the job; the other half is making sure every x402 directory, crawler, and
agent marketplace can find them — and ranks us at the top. This page is the
operating playbook for that distribution: how each surface indexes providers,
@@ -58,9 +58,15 @@ search results after 30 days without a settle**.
- **Ops required (secondary priority — see Chain priority above):**
`CDP_API_KEY_ID`/`CDP_API_KEY_SECRET` on the Cloud Run
service so Base settles through the CDP facilitator, then ≥1 settled payment
- per endpoint (point one ring rotation at the CDP rail). Note the ring payer
- (`api/_lib/x402/pay.js`) is Solana-only today, so a Base settle leg would have
- to be built and funded first. Do not let that block Solana work. Verify presence via
+ per endpoint. The ring payer (`api/_lib/x402/pay.js`) is still Solana-only,
+ but the Base settle leg exists as a one-shot buyer sweep:
+ [`scripts/x402-bazaar-settle-sweep.mjs`](../scripts/x402-bazaar-settle-sweep.mjs)
+ pays one real Base USDC settle against every live endpoint that advertises a
+ Base accept, cheapest-first under a spend cap (default $3), sending each
+ endpoint's own runnable `bazaar.input` example so the settle indexes a 200.
+ It needs a funded Base buyer wallet (`X402_BUYER_PRIVATE_KEY`); all Base
+ accepts pay to the owner's wallet, so the sweep is an internal transfer.
+ Do not let any of this block Solana work. Verify presence via
`GET https://api.cdp.coinbase.com/platform/v2/x402/discovery/resources` —
do **not** trust the `EXTENSION-RESPONSES` header alone (known upstream bug:
x402-foundation/x402#2112 — it is sometimes never emitted).
@@ -198,7 +204,9 @@ script. Everything else above updates itself.
before the payment dance. Default stays `true` until the owner flips it.
- **Bazaar indexing needs the CDP facilitator.** Solana-only settles through
the self-hosted facilitator never reach the Bazaar catalog. The Base rail
- must settle via CDP at least once per endpoint.
+ must settle via CDP at least once per endpoint; that is exactly what
+ `scripts/x402-bazaar-settle-sweep.mjs` does once CDP credentials and a funded
+ Base buyer wallet are in place.
## Related