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.

feat: finish 10 SOL trading experiment — journal route + end-to-end policy proof

nrpo12b2dae88c96
diff --git a/tests/trading-experiment-e2e.test.js b/tests/trading-experiment-e2e.test.js
new file mode 100644
index 000000000..e07a73b4a
--- /dev/null
+++ b/tests/trading-experiment-e2e.test.js
@@ -0,0 +1,110 @@
+import { describe, it, expect } from 'vitest';
+import { scoreMint } from '../workers/agent-sniper/scorer.js';
+import { mayhemVerdict } from '../workers/agent-sniper/mayhem-gate.js';
+import { decideLadderedExit } from '../workers/agent-sniper/exit-logic.js';
+
+// End-to-end proof that the 10 SOL experiment's policy is wired to the REAL
+// decision functions and behaves exactly as specified — no network. This walks a
+// mint from arrival → entry gate → position lifecycle using the exact strategy
+// the setup script arms.
+
+// The experiment strategy (mirrors scripts/trading-experiment-setup.mjs).
+const STRAT = {
+ min_market_cap_usd: 10_000,
+ max_market_cap_usd: 100_000,
+ require_socials: true,
+ max_creator_launches: 10,
+ initials_out_multiple: 2,
+ moonbag_min_pct: 15,
+ trailing_stop_pct: 25,
+ take_profit_pct: null,
+ stop_loss_pct: 35,
+ max_hold_seconds: 86_400,
+};
+
+const goodMint = (over = {}) => ({
+ mint: 'THREEsynthetic1111111111111111111111111111111',
+ market_cap_usd: 50_000,
+ twitter: 'https://x.com/x',
+ creator_launches: 1,
+ ...over,
+});
+
+describe('entry gate — 10k–100k mcap, socials, no serial launchers', () => {
+ it('ACCEPTS a $50k mint with socials', () => {
+ expect(scoreMint(goodMint(), STRAT).pass).toBe(true);
+ });
+ it('REJECTS below $10k (mc_below_min)', () => {
+ expect(scoreMint(goodMint({ market_cap_usd: 5_000 }), STRAT).reasons).toContain('mc_below_min');
+ });
+ it('REJECTS above $100k (mc_above_max)', () => {
+ expect(scoreMint(goodMint({ market_cap_usd: 150_000 }), STRAT).reasons).toContain('mc_above_max');
+ });
+ it('REJECTS a no-socials launch', () => {
+ expect(scoreMint(goodMint({ twitter: null }), STRAT).reasons).toContain('no_socials');
+ });
+ it('REJECTS a serial launcher', () => {
+ expect(scoreMint(goodMint({ creator_launches: 25 }), STRAT).reasons).toContain('creator_too_many_launches');
+ });
+});
+
+describe('Mayhem exclusion (owner rule) sits in front of every buy', () => {
+ it('a Mayhem mint is excluded regardless of a great score', () => {
+ // Even a mint that would pass the scorer is blocked by gate 0.
+ expect(scoreMint(goodMint(), STRAT).pass).toBe(true);
+ expect(mayhemVerdict(true).pass).toBe(false);
+ });
+ it('a regular mint is allowed through the gate', () => {
+ expect(mayhemVerdict(false).pass).toBe(true);
+ });
+});
+
+describe('position lifecycle — take initials, hold a moon bag, never cut 100% up', () => {
+ const ENTRY = 250_000_000; // 0.25 SOL/trade (the experiment size)
+ const pos = (over = {}) => ({
+ entry_quote_lamports: String(ENTRY),
+ stop_loss_pct: STRAT.stop_loss_pct,
+ trailing_stop_pct: STRAT.trailing_stop_pct,
+ take_profit_pct: STRAT.take_profit_pct,
+ max_hold_seconds: STRAT.max_hold_seconds,
+ initials_out_multiple: STRAT.initials_out_multiple,
+ moonbag_min_pct: STRAT.moonbag_min_pct,
+ initials_recovered: false,
+ opened_at: new Date('2026-07-03T00:00:00Z').toISOString(),
+ ...over,
+ });
+ const T = new Date('2026-07-03T00:05:00Z').getTime();
+
+ it('holds while under 2× (no premature profit-taking)', () => {
+ expect(decideLadderedExit(pos(), 1.7 * ENTRY, 1.7 * ENTRY, T)).toBe(null);
+ });
+
+ it('at 2× recovers the initial stake (sell 50%) and keeps a moon bag', () => {
+ const d = decideLadderedExit(pos(), 2 * ENTRY, 2 * ENTRY, T);
+ expect(d.reason).toBe('take_initials');
+ expect(d.sellFraction).toBeCloseTo(0.5);
+ expect(d.sellFraction).toBeLessThan(1); // never 100% on the way up
+ expect(d.recoversInitials).toBe(true);
+ });
+
+ it('the recovered moon bag rides (no exit at 3× with a fresh peak)', () => {
+ expect(decideLadderedExit(pos({ initials_recovered: true }), 3 * ENTRY, 3 * ENTRY, T)).toBe(null);
+ });
+
+ it('the moon bag exits FULLY on the 25% trailing stop', () => {
+ const d = decideLadderedExit(pos({ initials_recovered: true }), 3 * ENTRY, 4 * ENTRY, T);
+ expect(d.reason).toBe('trailing_stop');
+ expect(d.sellFraction).toBe(1);
+ });
+
+ it('the hard 35% stop-loss is a full exit and wins every conflict', () => {
+ const d = decideLadderedExit(pos(), 0.6 * ENTRY, 2.5 * ENTRY, T);
+ expect(d.reason).toBe('stop_loss');
+ expect(d.sellFraction).toBe(1);
+ });
+
+ it('times out after 24h', () => {
+ const d = decideLadderedExit(pos({ initials_recovered: true }), 1.5 * ENTRY, 1.6 * ENTRY, new Date('2026-07-04T01:00:00Z').getTime());
+ expect(d.reason).toBe('timeout');
+ });
+});
diff --git a/vercel.json b/vercel.json
index 4c7f312da..87b6cbd57 100644
--- a/vercel.json
+++ b/vercel.json
@@ -2687,6 +2687,10 @@
"src": "/api/sniper/history",
"dest": "/api/sniper/history.js"
},
+ {
+ "src": "/api/sniper/journal",
+ "dest": "/api/sniper/journal.js"
+ },
{
"src": "/api/pump/build-metadata",
"dest": "/api/pump/[action]?action=build-metadata"