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.

Extend copy trading to fan out Oracle conviction live buys

nirholasd9c870ad69bf
diff --git a/api/_lib/migrations/20260616130000_oracle_copy_fanout.sql b/api/_lib/migrations/20260616130000_oracle_copy_fanout.sql
new file mode 100644
index 000000000..7875c6827
--- /dev/null
+++ b/api/_lib/migrations/20260616130000_oracle_copy_fanout.sql
@@ -0,0 +1,46 @@
+-- Migration: extend copy_executions to support Oracle conviction actions.
+-- Apply: psql "$DATABASE_URL" -f api/_lib/migrations/20260616130000_oracle_copy_fanout.sql
+-- Idempotent.
+--
+-- The copy-fanout cron previously only read from agent_sniper_positions (the sniper
+-- engine). This migration adds oracle_watch_actions as a second fanout source:
+-- when an oracle-armed agent fires a live buy, copy subscribers get the same
+-- sized, safety-checked intent they would from a sniper position.
+--
+-- Schema changes:
+-- 1. leader_position_id — made nullable (oracle fanout rows don't have one)
+-- 2. leader_oracle_action_id — new bigint FK to oracle_watch_actions.id
+-- 3. Unique constraint replaced with two partial unique indexes, one per source type,
+-- so idempotency is guaranteed for both sniper and oracle fanout paths.
+
+begin;
+
+-- 1. Make leader_position_id nullable so oracle-sourced rows can omit it.
+alter table copy_executions
+ alter column leader_position_id drop not null;
+
+-- 2. Add oracle action reference (nullable; set only for oracle-sourced intents).
+alter table copy_executions
+ add column if not exists leader_oracle_action_id bigint;
+
+-- 3. Drop old scalar unique constraint (postgres won't auto-drop when we add the partial indexes).
+alter table copy_executions
+ drop constraint if exists copy_executions_subscription_id_leader_position_id_direction_key;
+
+-- 4. Partial unique indexes — one per source type.
+-- Sniper path: idempotency on (sub, sniper_position, direction) when position is set.
+create unique index if not exists copy_executions_sniper_idem
+ on copy_executions (subscription_id, leader_position_id, direction)
+ where leader_position_id is not null;
+
+-- Oracle path: idempotency on (sub, oracle_action, direction) when action is set.
+create unique index if not exists copy_executions_oracle_idem
+ on copy_executions (subscription_id, leader_oracle_action_id, direction)
+ where leader_oracle_action_id is not null;
+
+-- 5. Lookup index for oracle action references.
+create index if not exists copy_executions_oracle_action
+ on copy_executions (leader_oracle_action_id)
+ where leader_oracle_action_id is not null;
+
+commit;
diff --git a/api/cron/copy-fanout.js b/api/cron/copy-fanout.js
index a75fbb8c6..9cce7fbce 100644
--- a/api/cron/copy-fanout.js
+++ b/api/cron/copy-fanout.js
@@ -1,18 +1,23 @@
// GET /api/cron/copy-fanout — turn leader trades into copier intents.
//
-// Polls agent_sniper_positions for recent entries (and closes) by agents that
-// have active copy subscribers, and for each (position, subscriber) generates a
-// sized, safety-checked copy INTENT via the pure copy-engine. Non-custodial: it
-// only records the intent — the copier acts from their own wallet.
+// Two fanout sources:
+// 1. agent_sniper_positions — the sniper engine's real executed positions.
+// 2. oracle_watch_actions — the Oracle conviction agent's live buys.
//
-// BUY fanout: a leader opens a position → size each subscriber's order, clamp
-// to their per-trade cap + remaining daily budget, gate on coin
-// safety, and insert a pending intent (or a transparent 'skipped'
-// row explaining why it didn't fire).
-// SELL fanout: a leader closes a position → mirror an exit intent ONLY to
-// copiers who actually acted on the matching buy.
+// For each (position/action, subscriber) the cron generates a sized,
+// safety-checked copy INTENT via the pure copy-engine. Non-custodial: it only
+// records the intent — the copier acts from their own wallet.
//
-// Idempotent via the unique (subscription_id, leader_position_id, direction).
+// BUY fanout: a leader opens/buys → size each subscriber's order, clamp to
+// their per-trade cap + remaining daily budget, gate on coin safety,
+// and insert a pending intent (or a 'skipped' row with reason).
+// SELL fanout (sniper only): a leader closes → mirror exit ONLY to copiers who
+// acted on the matching buy. Oracle sells are not modelled (there
+// is no explicit exit event — outcomes are graded after the fact).
+//
+// Idempotent via partial unique indexes:
+// (subscription_id, leader_position_id, direction) when leader_position_id is not null
+// (subscription_id, leader_oracle_action_id, direction) when leader_oracle_action_id is not null
import { error, json, method, wrap } from '../_lib/http.js';
import { env } from '../_lib/env.js';
@@ -166,6 +171,95 @@ async function fanoutSells(network, stats) {
}
}
+// ── Oracle conviction fanout ───────────────────────────────────────────────────
+// Mirrors live oracle buy actions to copy subscribers, using the same sizing
+// and safety logic as the sniper fanout. Only `mode = 'live'` actions fan out.
+
+async function fanoutOracleBuys(network, stats) {
+ // Only live fills from the last 8 minutes that have at least one active
+ // copy subscriber following the acting agent.
+ const actions = await sql`
+ select a.id, a.agent_id, a.mint, a.symbol, a.conviction, a.tier, a.size_sol, a.acted_at
+ from oracle_watch_actions a
+ where a.network = ${network}
+ and a.mode = 'live'
+ and a.status = 'filled'
+ and a.acted_at > now() - interval '8 minutes'
+ and exists (
+ select 1 from copy_subscriptions s
+ where s.leader_agent_id = a.agent_id and s.network = ${network} and s.status = 'active'
+ )
+ order by a.acted_at desc
+ limit 200
+ `;
+ if (!actions.length) return;
+
+ // Per-subscription day-spend + open-intent counts, batched once.
+ const spendRows = await sql`
+ select subscription_id, coalesce(sum(planned_sol), 0) as spent
+ from copy_executions
+ where direction = 'buy' and status in ('pending', 'acted') and created_at::date = current_date
+ group by subscription_id
+ `;
+ const openRows = await sql`
+ select subscription_id, count(*) as open
+ from copy_executions
+ where direction = 'buy' and status = 'pending'
+ group by subscription_id
+ `;
+ const spent = new Map(spendRows.map((r) => [r.subscription_id, Number(r.spent) || 0]));
+ const open = new Map(openRows.map((r) => [r.subscription_id, Number(r.open) || 0]));
+
+ for (const action of actions) {
+ const subs = await sql`
+ select * from copy_subscriptions
+ where leader_agent_id = ${action.agent_id} and network = ${network} and status = 'active'
+ `;
+ if (!subs.length) continue;
+ const coin = await coinContext(action.mint);
+ const entrySol = Number(action.size_sol) || 0;
+
+ for (const sub of subs) {
+ const decision = planCopyOrder({
+ subscription: sub,
+ position: { direction: 'buy', entry_sol: entrySol, mint: action.mint },
+ coin,
+ spentTodaySol: spent.get(sub.id) || 0,
+ openCopies: open.get(sub.id) || 0,
+ });
+ const status = decision.action === 'copy' ? 'pending' : 'skipped';
+ const planned = decision.action === 'copy' ? decision.order_sol : null;
+
+ // Note: leader_position_id is null for oracle-sourced intents.
+ // Idempotency is guaranteed by the copy_executions_oracle_idem partial unique index.
+ const [inserted] = await sql`
+ insert into copy_executions (
+ subscription_id, copier_user_id, leader_agent_id, leader_position_id, leader_oracle_action_id,
+ network, mint, symbol, direction, planned_sol, leader_entry_sol, status, skip_reason,
+ safety
+ ) values (
+ ${sub.id}, ${sub.copier_user_id}, ${action.agent_id}, null, ${action.id},
+ ${network}, ${action.mint}, ${action.symbol || null}, 'buy', ${planned}, ${entrySol},
+ ${status}, ${decision.reason && status === 'skipped' ? decision.reason : null},
+ ${coin ? JSON.stringify(coin) : null}::jsonb
+ )
+ on conflict (subscription_id, leader_oracle_action_id, direction)
+ where leader_oracle_action_id is not null
+ do nothing
+ returning id
+ `;
+ if (inserted) {
+ const key = `oracle_${status}`;
+ stats[key] = (stats[key] || 0) + 1;
+ if (status === 'pending') {
+ spent.set(sub.id, (spent.get(sub.id) || 0) + (planned || 0));
+ open.set(sub.id, (open.get(sub.id) || 0) + 1);
+ }
+ }
+ }
+ }
+}
+
export default wrap(async (req, res) => {
if (!method(req, res, ['GET', 'POST'])) return;
if (!requireCron(req, res)) return;
@@ -176,6 +270,7 @@ export default wrap(async (req, res) => {
try {
await fanoutBuys(network, stats);
await fanoutSells(network, stats);
+ await fanoutOracleBuys(network, stats);
} catch (err) {
stats[`error_${network}`] = err.message;
}
diff --git a/data/changelog.json b/data/changelog.json
index c07eb3b40..69e17060c 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,13 @@
{
"$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-06-16",
+ "title": "Oracle copy trading — conviction buys now fan out to copy subscribers",
+ "summary": "Copy subscribers now receive intents from Oracle conviction buys, not just sniper engine positions. When an oracle-armed agent fires a live buy, every active copy subscriber gets a sized, safety-checked copy intent — respecting their per-trade cap, daily budget, and minimum order size — exactly as they would for a sniper position. A new DB migration adds leader_oracle_action_id to copy_executions with partial unique indexes for idempotency. Simulated oracle actions are excluded; only mode=live fills fan out.",
+ "tags": ["feature"],
+ "link": "/trader"
+ },
{
"date": "2026-06-16",
"title": "Leaderboard: Oracle Conviction Rankings — agents ranked by conviction win rate",
diff --git a/public/changelog.json b/public/changelog.json
index 0c32c5423..41d4a3e98 100644
--- a/public/changelog.json
+++ b/public/changelog.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-06-16T05:23:03.865Z",
+ "generated_at": "2026-06-16T05:24:34.426Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json + data/changelog.json",
"site": {
"name": "three.ws",
diff --git a/public/features.json b/public/features.json
index a3ea25469..55d8b9fd7 100644
--- a/public/features.json
+++ b/public/features.json
@@ -1,5 +1,5 @@
{
- "generated_at": "2026-06-16T05:23:03.836Z",
+ "generated_at": "2026-06-16T05:24:34.402Z",
"generated_by": "scripts/build-page-index.mjs from data/pages.json",
"site": {
"name": "three.ws",
diff --git a/public/sitemap/index.html b/public/sitemap/index.html
index 372ca6a37..36f20cffc 100644
--- a/public/sitemap/index.html
+++ b/public/sitemap/index.html
@@ -56,6 +56,20 @@
.sm-brand img { width: 24px; height: 24px; border-radius: 5px; }
.sm-brand:hover { text-decoration: none; }
</style>
+
+ <meta property="og:type" content="website">
+ <meta property="og:site_name" content="three.ws">
+ <meta property="og:title" content="Sitemap · three.ws">
+ <meta property="og:description" content="Human-readable index of every page on three.ws.">
+ <meta property="og:url" content="https://three.ws/sitemap">
+ <meta property="og:image" content="https://three.ws/og-image.png">
+ <meta property="og:image:width" content="1200">
+ <meta property="og:image:height" content="630">
+ <meta name="twitter:card" content="summary_large_image">
+ <meta name="twitter:title" content="Sitemap · three.ws">
+ <meta name="twitter:description" content="Human-readable index of every page on three.ws.">
+ <meta name="twitter:image" content="https://three.ws/og-image.png">
+ <script type="application/ld+json">{"@context":"https://schema.org","@type":"WebPage","name":"Sitemap","description":"Human-readable index of every page on three.ws.","url":"https://three.ws/sitemap","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"}}</script>
</head>
<body>
<header class="sm-topbar">