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.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
feat: refactor volume cap logic and introduce ring constants for better configuration management
nrpo9492ba623bca
diff --git a/api/_lib/x402/pipelines/volume-shared.js b/api/_lib/x402/pipelines/volume-shared.jsindex 5fced9f5d..a8ac0d674 100644--- a/api/_lib/x402/pipelines/volume-shared.js+++ b/api/_lib/x402/pipelines/volume-shared.js@@ -13,22 +13,19 @@import { USDC_MINT } from '../pay.js';import { rotationPlan } from '../ring-catalog.js';+import { volumePerRunCapAtomic } from '../ring-constants.js';export const ASSET = USDC_MINT || 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v';// Self-imposed per-run USDC budget (atomics, 6dp) for the 5-minute volume loop.// Bounds a single tick on top of the loop's daily cap so one run can't drain the-// day. Raised from the original $0.05 to ACCOMMODATE the ring-settle price this-// catalog rotates ($1.00 default, X402_PRICE_RING_SETTLE) — at $0.05 the-// flagship ring-settle call was silently skipped every cycle (cap_would_exceed).-// The pair is documented in .env.example; validateRingConfig() flags a+// day. The default ($1.10) accommodates the ring-settle price this catalog+// rotates ($1.00 default, X402_PRICE_RING_SETTLE) — at the old $0.05 the flagship+// ring-settle call was silently skipped every cycle (cap_would_exceed). The value+// and its env override live in ring-constants.js (the single source of truth that+// ring-config.js's price>cap check also reads); validateRingConfig() flags a// price > cap contradiction, and payX402 warns loudly if one is ever hit.-// Default $1.10 = 1_100_000 (ring-settle $1.00 + headroom for the cheap calls a-// window sweeps alongside it). The loop's daily cap still bounds total spend.-export const VOLUME_PER_RUN_CAP_ATOMIC = Math.max(- 0,- Number(process.env.X402_VOLUME_PER_RUN_CAP_ATOMIC || 1_100_000),-);+export const VOLUME_PER_RUN_CAP_ATOMIC = volumePerRunCapAtomic();// How many endpoints the 5-minute volume loop sweeps per run (cursor advances by// this each tick). With the catalog below a batch of 4 covers the full set indiff --git a/api/_lib/x402/ring-config.js b/api/_lib/x402/ring-config.jsindex f5d394bac..fe4da6f1d 100644--- a/api/_lib/x402/ring-config.js+++ b/api/_lib/x402/ring-config.js@@ -28,26 +28,12 @@import { env } from '../env.js';import { priceFor } from '../x402-prices.js';+import { RING_SETTLE_DEFAULT_PRICE_ATOMICS, volumePerRunCapAtomic } from './ring-constants.js';// External default when the self-facilitator is off and no URL is set.// Mirrors the default baked into env.js X402_FACILITATOR_URL_SOLANA.export const EXTERNAL_FACILITATOR_URL_DEFAULT = 'https://facilitator.payai.network';-// Mirrors DEFAULT_PRICE_ATOMICS in api/x402/ring-settle.js ($1.00) — kept as a-// local constant because importing the endpoint module would drag the whole-// paid-endpoint wiring into this pure config module.-const RING_SETTLE_DEFAULT_PRICE_ATOMICS = '1000000';--// Mirrors VOLUME_PER_RUN_CAP_ATOMIC in x402/pipelines/volume-shared.js-// ($1.10 default) — same env var, same default, read here without importing the-// pipeline (it pulls db/pay/web3 at module load). The default was raised from-// $0.05 to $1.10 (task 04) precisely so it accommodates the ring-settle price it-// rotates ($1.00); keep this mirror in lockstep or the price>cap finding below-// false-positives on stock config.-function volumePerRunCapAtomic() {- return Math.max(0, Number(process.env.X402_VOLUME_PER_RUN_CAP_ATOMIC || 1_100_000));-}-export function selfFacilitatorEnabled() {return String(process.env.X402_SELF_FACILITATOR_ENABLED || '').toLowerCase() === 'true';}diff --git a/api/_lib/x402/ring-constants.js b/api/_lib/x402/ring-constants.jsnew file mode 100644index 000000000..c1a9d42d2--- /dev/null+++ b/api/_lib/x402/ring-constants.js@@ -0,0 +1,25 @@+// Single source of truth for the x402 ring's price/cap constants.+//+// These numbers are consumed in three places that must agree or the config+// validator's `ring_price_exceeds_run_cap` check false-positives (or, worse,+// misses a real contradiction): the ring-settle endpoint's default price, the+// volume loop's per-run cap, and the pure `ring-config.js` validator. Before+// this module each kept its own hand-copied literal. Import from here instead —+// this file is dependency-free (no db/pay/web3), so even the pure config module+// can import it without dragging the pipeline's load-time deps in.++/** ring-settle default price in USDC atomic units ($1.00). */+export const RING_SETTLE_DEFAULT_PRICE_ATOMICS = '1000000';++/**+ * Volume-loop per-run cap default in USDC atomic units ($1.10). Raised from the+ * old $0.05 so it accommodates the $1.00 ring-settle price it rotates — keep it+ * ≥ RING_SETTLE_DEFAULT_PRICE_ATOMICS. Env `X402_VOLUME_PER_RUN_CAP_ATOMIC`+ * overrides it.+ */+export const VOLUME_PER_RUN_CAP_ATOMIC_DEFAULT = 1_100_000;++/** Resolve the per-run cap, honoring the env override. */+export function volumePerRunCapAtomic() {+ return Math.max(0, Number(process.env.X402_VOLUME_PER_RUN_CAP_ATOMIC || VOLUME_PER_RUN_CAP_ATOMIC_DEFAULT));+}diff --git a/api/x402/ring-settle.js b/api/x402/ring-settle.jsindex ddd5daa01..79eef2ec8 100644--- a/api/x402/ring-settle.js+++ b/api/x402/ring-settle.js@@ -27,6 +27,7 @@ import crypto from 'node:crypto';import { paidEndpoint } from '../_lib/x402-paid-endpoint.js';import { buildBazaarSchema } from '../_lib/x402-spec.js';import { priceFor } from '../_lib/x402-prices.js';+import { RING_SETTLE_DEFAULT_PRICE_ATOMICS } from '../_lib/x402/ring-constants.js';const ROUTE = '/api/x402/ring-settle';diff --git a/data/changelog.json b/data/changelog.jsonindex 3c17e0f94..432626102 100644--- a/data/changelog.json+++ b/data/changelog.json@@ -1,6 +1,24 @@{"$comment": "Curated changelog entries for three.ws — the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.","entries": [+ {+ "date": "2026-07-03",+ "title": "Status page now shows internal dependency health, not just uptime",+ "summary": "The public status page and the platform health API now report the health of the systems behind the surfaces — cache, database, Solana RPC, the x402 payment ring, and the world service — not only whether each page returns. A surface can answer normally while a dependency is quietly running on a fallback (cache on memory, RPC throttled, the payment ring half-configured); those states are now visible with a plain-language explanation and the exact fix, instead of being buried in server logs. The monitor also re-alerts on a degradation that persists rather than going silent after the first notice, and posts a recovery note when it clears.",+ "tags": [+ "improvement"+ ],+ "link": "/status"+ },+ {+ "date": "2026-07-03",+ "title": "Payment audit writes now batch instead of hammering the database",+ "summary": "The ledger that records every x402 payment used to write one row to the database per paid request. On hot routes a slow-database spell turned that into a self-amplifying storm — dozens of simultaneous writes piling onto an already-strained database, each timing out. Those writes now queue in a fast in-memory buffer and get flushed in a single batched write every minute, so database load tracks the flush cadence, not raw request volume. Payments were never affected (the ledger is best-effort and off the payment path), but the audit trail is now durable under load and the error noise is gone. A retention sweep also keeps the ledger trimmed so dashboard reports stay fast. Health checks now expose whether the autonomous spend loop is live, and operators get a clean pause switch that stops spending without tripping the tamper alarm.",+ "tags": [+ "fix",+ "infra"+ ]+ },{"date": "2026-07-03","title": "Agents no longer buy pump.fun mayhem-mode coins",diff --git a/docs/ops/production-log-triage.md b/docs/ops/production-log-triage.mdindex 66d793756..23a9d0eed 100644--- a/docs/ops/production-log-triage.md+++ b/docs/ops/production-log-triage.md@@ -14,6 +14,16 @@ Silencing any of them in code would hide a real production signal, so don't.Severity legend: 🔴 owner decision (money / security / billing) · 🟡 set an envvar or add quota · 🟢 self-healing, no action needed.+> **You no longer need a log export to see most of this.** The platform now+> self-reports internal-dependency health: **[/status](https://three.ws/status)**+> renders it with a plain-language fix for each degradation, and+> **`/api/healthz`** carries a machine-readable `subsystems` block (cache, database,+> Helius RPC, x402 ring, world, x402 config). The uptime cron+> ([api/cron/uptime-check.js](../../api/cron/uptime-check.js)) parks a snapshot+> each tick and re-pages a degradation that persists. Source of the roll-up:+> [api/_lib/ops/subsystem-health.js](../../api/_lib/ops/subsystem-health.js). This+> table remains the deep reference for what each state means and how to clear it.+---## 🔴 `[ring-invariants] SPEND PATH DISABLED in x402-autonomous-loop`diff --git a/src/theater-feed.js b/src/theater-feed.jsindex 362bfac7a..d52e8d68c 100644--- a/src/theater-feed.js+++ b/src/theater-feed.js@@ -64,6 +64,10 @@ export function normalizeEvent(e) {return { ...base, kind: 'pay', title: 'Payment', usd: Number.isFinite(Number(e.usdcAtomic)) ? Number(e.usdcAtomic) / 1e6 : null, sub: fmtUsdc(e.usdcAtomic) || e.recipientLabel || base.actor, href: e.explorerUrl || null };case 'jackpot':return { ...base, kind: 'win', title: 'Jackpot', sub: e.reward ? `${e.reward}` : base.actor, href: null };+ case 'agent-guard':+ // A safety refusal — an agent declined a bad buy. Shown in the tape (not+ // as a performance) so watchers see the platform's guardrails working.+ return { ...base, kind: 'guard', agentId: e.agentId || null, title: `${base.actor || 'Agent'} ${e.label || 'skipped an unsafe buy'}`, sub: e.mint ? shortMint(e.mint) : (e.reason || 'safety'), href: e.agentId ? `/agent/${e.agentId}` : (e.mint ? solscanToken(e.mint, e.network) : null) };case 'agora-registered':return { ...base, kind: 'launch', title: 'Agora citizen joined', sub: base.actor, href: e.citizenId ? `/agora?citizen=${e.citizenId}` : '/agora' };case 'agora-task-claimed':diff --git a/src/theater.css b/src/theater.cssindex f07d03faf..3a6e62dab 100644--- a/src/theater.css+++ b/src/theater.css@@ -425,6 +425,8 @@.th-tick-buy .th-tick-dot, .th-tick-win .th-tick-dot { background: var(--success, #4ade80); }.th-tick-loss .th-tick-dot { background: var(--danger, #f87171); }.th-tick-launch .th-tick-dot, .th-tick-verify .th-tick-dot, .th-tick-pay .th-tick-dot { background: var(--th-accent); }+.th-tick-guard .th-tick-dot { background: var(--warn, #fbbf24); box-shadow: 0 0 0 3px rgba(251, 191, 36, 0.14); }+.th-tick-guard .th-tick-title { text-transform: none; color: var(--warn, #fbbf24); font-weight: var(--weight-medium, 500); }.th-tick-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }.th-tick-title { font-size: var(--text-sm, 0.78rem); font-weight: var(--weight-semibold, 600); color: var(--ink-bright, #fff); text-transform: capitalize; }.th-tick-sub { font-family: var(--font-mono, monospace); font-size: var(--text-2xs, 0.69rem); color: var(--ink-dim, #888); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }diff --git a/tests/sniper-autofund-consent.test.js b/tests/sniper-autofund-consent.test.jsnew file mode 100644index 000000000..1dee337a4--- /dev/null+++ b/tests/sniper-autofund-consent.test.js@@ -0,0 +1,60 @@+import { describe, it, expect } from 'vitest';+import { optedInAgentIds } from '../workers/agent-sniper/auto-funder.js';++// The auto-funder may only move SOL to agents whose strategy has EXPLICITLY+// opted in (auto_fund_enabled === true). Arming a strategy must never, on its+// own, make the launcher master push funds — that implicit trigger was the+// documented footgun. These tests pin the fail-safe default.++describe('optedInAgentIds — explicit auto-fund consent', () => {+ it('excludes an enabled strategy that did NOT opt in (the footgun case)', () => {+ const strategies = [+ { agent_id: 'a1', network: 'mainnet', enabled: true, auto_fund_enabled: false },+ ];+ expect(optedInAgentIds(strategies, 'mainnet')).toEqual([]);+ });++ it('includes only strategies that explicitly opted in', () => {+ const strategies = [+ { agent_id: 'a1', network: 'mainnet', auto_fund_enabled: true },+ { agent_id: 'a2', network: 'mainnet', auto_fund_enabled: false },+ { agent_id: 'a3', network: 'mainnet' }, // flag absent → treated as no+ ];+ expect(optedInAgentIds(strategies, 'mainnet')).toEqual(['a1']);+ });++ it('treats a missing flag as no-consent (fail-safe mid-migration)', () => {+ const strategies = [{ agent_id: 'a1', network: 'mainnet', auto_fund_enabled: undefined }];+ expect(optedInAgentIds(strategies, 'mainnet')).toEqual([]);+ });++ it('never treats a truthy-but-not-true value as consent', () => {+ // Guards against a stringy DB value ('t', 1, 'true') silently authorizing funds.+ const strategies = [+ { agent_id: 'a1', network: 'mainnet', auto_fund_enabled: 'true' },+ { agent_id: 'a2', network: 'mainnet', auto_fund_enabled: 1 },+ ];+ expect(optedInAgentIds(strategies, 'mainnet')).toEqual([]);+ });++ it('scopes to the requested network', () => {+ const strategies = [+ { agent_id: 'a1', network: 'mainnet', auto_fund_enabled: true },+ { agent_id: 'a2', network: 'devnet', auto_fund_enabled: true },+ ];+ expect(optedInAgentIds(strategies, 'devnet')).toEqual(['a2']);+ });++ it('dedupes an agent that has multiple opted-in strategies', () => {+ const strategies = [+ { agent_id: 'a1', network: 'mainnet', auto_fund_enabled: true },+ { agent_id: 'a1', network: 'mainnet', auto_fund_enabled: true },+ ];+ expect(optedInAgentIds(strategies, 'mainnet')).toEqual(['a1']);+ });++ it('handles empty/nullish input', () => {+ expect(optedInAgentIds(undefined, 'mainnet')).toEqual([]);+ expect(optedInAgentIds([], 'mainnet')).toEqual([]);+ });+});diff --git a/workers/agent-sniper/README.md b/workers/agent-sniper/README.mdindex 57080f270..a901e017f 100644--- a/workers/agent-sniper/README.md+++ b/workers/agent-sniper/README.md@@ -62,11 +62,22 @@ Enforced in `executeBuy`, short-circuiting before any transaction:5. **Mandatory stop-loss** — DB `CHECK (stop_loss_pct > 0)` + runtime filter.6. **Price-impact circuit breaker** — `max_price_impact_pct` checked against a fresh `quoteForBuy`.7. **Idempotency** — `INSERT … ON CONFLICT (agent_id, mint, network) DO NOTHING` claims the slot before the tx; one shot per mint per agent.+8. **Mayhem exclusion (owner rule)** — the first gate: never buy pump.fun "Mayhem"-mode tokens, only regular launches. Reads `isMayhemMode` off the on-chain bonding curve (cached per mint) via `mayhem-gate.js`. Applies to **every** trigger path, since it lives in the `executeBuy` chokepoint. `SNIPER_MAYHEM_FILTER=0` disables; `SNIPER_MAYHEM_STRICT=1` also skips when the curve can't be read.+9. **Agent scoping** — `SNIPER_AGENT_IDS` restricts the worker to a specific set of agents, so a bounded run against the shared DB can't act on every other armed strategy.++> **Wallet/funds pre-check.** An agent with no wallet or too little SOL is skipped+> *before* the idempotency claim, so it leaves no `failed` position row — those+> aborts used to dominate the feed. Only post-broadcast failures persist a row.> **Single-worker assumption.** Budget/concurrency races are prevented by an> in-process per-agent lock. Run exactly ONE instance. Scaling out requires an> atomic DB spend reservation instead.+> **Master funding cap.** Set `LAUNCHER_MASTER_DAILY_CAP_SOL` to bound how much SOL+> can leave the launcher master wallet per UTC day across *all* automated funders+> (`api/_lib/launcher-funding.js`). This is a hard backstop that a loose per-call+> cap can't bypass — recommended whenever armed strategies auto-fund from the master.+## Environment| Var | Required | Default | Notes |@@ -79,6 +90,10 @@ Enforced in `executeBuy`, short-circuiting before any transaction:| `SNIPER_GLOBAL_KILL` | | `0` | `1` halts new buys. || `SNIPER_POLL_MS` | | `5000` | Position re-quote cadence. || `SNIPER_MAX_GLOBAL_BUYS_PER_MIN` | | `10` | Platform-wide buy throttle backstop. |+| `SNIPER_MAYHEM_FILTER` | | `1` | Enforce the no-Mayhem rule (skip pump.fun Mayhem-mode tokens). `0` disables. |+| `SNIPER_MAYHEM_STRICT` | | `0` | `1` = skip a buy when the bonding curve can't be read (default allows-on-unknown, logged). |+| `SNIPER_AGENT_IDS` | | — | Comma/space-separated agent UUID allowlist. Unset = all agents for the network. |+| `LAUNCHER_MASTER_DAILY_CAP_SOL` | | — | Hard per-UTC-day ceiling on total master-wallet outflow across automated funders. Unset = no cap. || `SNIPER_CONFIRM_TIMEOUT_MS` | | `60000` | Per-trade confirmation wait. || `SNIPER_CLAIM_POLL_MS` | | `30000` | First-claim trigger: fee-claim poll cadence. || `SNIPER_CLAIM_LOOKBACK_S` | | `600` | First-claim trigger: window scanned each poll (must exceed the poll interval). |