agentlili 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,533 @@
1
+ # AI Agent Wallet — Solana Devnet
2
+
3
+ An autonomous AI agent wallet for Solana that manages wallets, executes DeFi operations, and interacts with on-chain protocols — all through natural language. Supports multiple independent agents, each with their own isolated keypair, security policy, and decision-making context.
4
+
5
+ Built with Vercel AI SDK, Solana Agent Kit v2, and Next.js 15.
6
+
7
+ ---
8
+
9
+ ## For Judges — Quick Navigation
10
+
11
+ | Judging Criteria | What to Look At | Command / Link |
12
+ |---|---|---|
13
+ | **C1: Functional Demo** | Autonomous DeFi agent with 93 tools, SSE activity feed, one-click demos | `pnpm dev` → click any demo card, or `SKIP_LLM=1 pnpm headless-demo` |
14
+ | **C2: Security & Key Mgmt** | FROST 2-of-3 threshold signing, PolicyParticipant, PDA vault, spending limits, HMAC audit chain | `pnpm frost-demo` (no API keys needed), Security tab in UI, [SECURITY.md](SECURITY.md) |
15
+ | **C3: Documentation** | 1,800+ line deep dive, 22 Mermaid diagrams, machine-readable SKILLS.md | [DEEP_DIVE.md](DEEP_DIVE.md) (architecture + threat model), [SKILLS.md](SKILLS.md) |
16
+ | **C4: Multi-Agent Scalability** | 12-agent stress test, fleet health dashboard, bulk provisioning | `pnpm stress-test` (12 agents, 76 ops, 0% errors) |
17
+
18
+ ### Key Differentiators
19
+ - **1,106 passing tests** (zero-mock) — run `pnpm test` to verify
20
+ - **18-tool MCP server** for Claude Desktop integration — `pnpm mcp`
21
+ - **5-layer security**: FROST threshold → PolicyParticipant → PDA vault → Kora gasless → Jito MEV protection
22
+ - **93 DeFi tools** via Solana Agent Kit v2 (vs typical 2–4)
23
+
24
+ ---
25
+
26
+ ## Architecture
27
+
28
+ ```
29
+ ┌─────────────────────────────────────────────────────────────────────────┐
30
+ │ WEB UI (Next.js) │
31
+ │ Chat Interface │ Wallet Panel │ Portfolio │ Agent Monitor │ Analytics │
32
+ │ Activity Feed │ Demo Launcher │ Strategy │ Backup │ Lifecycle │
33
+ │ Security Tab: FROST Mgmt │ Audit Log Viewer │ Fleet Health │ Spending │
34
+ └───────────────────────────────────┬─────────────────────────────────────┘
35
+ │ HTTP + SSE
36
+ ┌───────────────────────────────────▼─────────────────────────────────────┐
37
+ │ SECURITY MIDDLEWARE (every route) │
38
+ │ HMAC-SHA256 Request Signing │ Per-IP Rate Limiter │ Audit Logger │
39
+ │ Spending Limit Enforcement │ Agent Lifecycle Gate │ Input Sanit. │
40
+ └───────────────────────────────────┬─────────────────────────────────────┘
41
+
42
+ ┌───────────────────────────────────▼─────────────────────────────────────┐
43
+ │ AGENT CORE │
44
+ │ LLM Provider (Claude / GPT-4) Solana Agent Kit v2 (93 DeFi Tools) │
45
+ │ Multi-step Tool Chaining Success Detection Pipeline │
46
+ │ Strategy Presets (3 risk levels) Per-Agent SSE Event Bus │
47
+ └───────────────────────────────────┬─────────────────────────────────────┘
48
+
49
+ ┌───────────────────────────────────▼─────────────────────────────────────┐
50
+ │ WALLET LAYER │
51
+ │ WalletManager: AES-256-GCM + scrypt KDF │
52
+ │ KeypairWallet: Ed25519 signing, devnet airdrop, SPL token support │
53
+ │ Isolated per-agent state: keypair, tx log, spending ledger, lifecycle │
54
+ └──────────────────┬────────────────────────────────┬─────────────────────┘
55
+ │ direct SOL fees │ gasless (Kora)
56
+ │ │
57
+ │ ┌──────────────────────▼──────────────────┐
58
+ │ │ KORA PAYMASTER (optional) │
59
+ │ │ Fee Payer Co-signing │ Token Fee Mode │
60
+ │ │ Sponsored (free) │ Margin │ Fixed │
61
+ │ └──────────────────────┬──────────────────┘
62
+ │ │
63
+ ┌──────────────────▼────────────────────────────────▼─────────────────────┐
64
+ │ SOLANA DEVNET │
65
+ │ Jupiter │ Orca │ Raydium │ Drift │ Lulo │ Meteora │ Pyth │ deBridge │
66
+ └─────────────────────────────────────────────────────────────────────────┘
67
+ ```
68
+
69
+ ---
70
+
71
+ ## Quick Start (Under 3 Minutes)
72
+
73
+ > **No API key?** Skip to the [Headless Demo](#headless-demo-no-browser-required) below — runs the full wallet + FROST demo without any external keys.
74
+
75
+ ### Prerequisites
76
+
77
+ - Node.js 18+
78
+ - pnpm (`npm i -g pnpm`)
79
+
80
+ ### Setup
81
+
82
+ ```bash
83
+ # 1. Install dependencies
84
+ pnpm install
85
+
86
+ # 2. Copy environment config
87
+ cp .env.example .env
88
+
89
+ # 3. Generate a wallet encryption key
90
+ node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"
91
+ # → paste the output as WALLET_ENCRYPTION_KEY in .env
92
+
93
+ # 4. Add your LLM API key to .env (optional — headless demo works without it)
94
+ # ANTHROPIC_API_KEY=sk-ant-api03-{your-key-here}
95
+
96
+ # 5. Start the web app
97
+ pnpm dev
98
+ ```
99
+
100
+ Open [http://localhost:3000](http://localhost:3000).
101
+
102
+ ### First 2 Minutes
103
+
104
+ Once the app is running:
105
+
106
+ 1. Click **Create New Wallet** in the left sidebar — the agent wallet is created and auto-funded with devnet SOL
107
+ 2. In the empty chat area, click the green **DeFi Explorer** demo card
108
+ 3. Watch the **Activity Feed** (bottom of page) stream live tool calls and transaction signatures in real time
109
+ 4. Click any transaction signature → opens directly in **Solana Explorer** on devnet (every TX is a clickable link to the explorer)
110
+
111
+ ### Headless Demo (No Browser Required)
112
+
113
+ ```bash
114
+ # Wallet + airdrop + on-chain verify — NO API key needed
115
+ SKIP_LLM=1 pnpm headless-demo
116
+
117
+ # FROST threshold signing demo — NO API key needed
118
+ pnpm frost-demo
119
+
120
+ # Full 7-phase demo with autonomous LLM execution (requires ANTHROPIC_API_KEY)
121
+ pnpm headless-demo
122
+ ```
123
+
124
+ ### Gasless Transactions (Optional — Kora Paymaster)
125
+
126
+ To enable gasless transactions where agents don't need SOL for fees:
127
+
128
+ ```bash
129
+ # 1. Start the Kora paymaster server (requires Rust toolchain or Docker)
130
+ cd ../kora_server && chmod +x setup.sh && ./setup.sh
131
+
132
+ # 2. Add to .env
133
+ KORA_ENDPOINT=http://localhost:8080
134
+ KORA_FEE_MODE=sponsored
135
+ ```
136
+
137
+ See [kora_server/README.md](../kora_server/README.md) for full setup details.
138
+
139
+ ### Multi-Agent Scalability Test
140
+
141
+ ```bash
142
+ pnpm stress-test # 12 concurrent agents, 76 ops, 0% errors — empirical proof
143
+ STRESS_AGENTS=20 pnpm stress-test # Scale to 20 agents
144
+ ```
145
+
146
+ ### CLI Mode
147
+
148
+ ```bash
149
+ pnpm cli
150
+ ```
151
+
152
+ ---
153
+
154
+ ## Features
155
+
156
+ ### Autonomous Agent Wallet (C1)
157
+
158
+ - **Programmatic wallet creation** — `Keypair.generate()` with automatic devnet airdrop on creation
159
+ - **AES-256-GCM encrypted key storage** — per-wallet scrypt salt, stored at rest on disk
160
+ - **Automatic transaction signing** — no human approval required; agent signs and submits
161
+ - **93 DeFi tools** via Solana Agent Kit v2 (TokenPlugin + DefiPlugin)
162
+ - **Multi-step tool chaining** — up to 10 sequential tool calls per LLM request
163
+ - **Natural language → on-chain execution** — "swap 0.1 SOL for USDC" → Jupiter swap tx
164
+ - **Real-time SSE activity feed** — live streaming of every tool call, tx signature, and balance change as they happen
165
+ - **One-click demo mode** — 3 pre-built autonomous DeFi scenarios; spawns wallet, funds it, and executes strategy while you watch
166
+ - **Portfolio view** — aggregate SOL + SPL holdings across all agent wallets with USD values (Jupiter Price API)
167
+ - **Transaction analytics dashboard** — success/failure rates, SOL spent, tool usage charts, hourly timeline
168
+ - **Security tab** — dedicated sidebar panel with FROST wallet management, HMAC-chained audit log viewer with integrity verification, fleet health dashboard (grade distribution, agents needing attention), and per-wallet spending limits editor
169
+
170
+ ### Security & Key Management (C2)
171
+
172
+ - **AES-256-GCM encryption** — all private keys encrypted at rest; GCM auth tag detects ciphertext tampering
173
+ - **scrypt key derivation** — N=2^14 storage, N=2^17 backup; memory-hard against brute force
174
+ - **HMAC-SHA256 request signing** — every write/delete request signed with a derived key; replays blocked via 5-minute window
175
+ - **Per-IP sliding-window rate limiting** — 12 per-bucket presets; prevents API abuse and DoS
176
+ - **Spending limits** — configurable max SOL per-transaction and per-day per agent; blocks over-budget tool calls
177
+ - **HMAC-chained audit log** — append-only JSONL with each entry hashing the previous; tamper detection via `verifyAuditIntegrity()`
178
+ - **Password-protected wallet backup** — export encrypted JSON, restore from file; scrypt N=2^17 for strong backup protection
179
+ - **Agent lifecycle enforcement** — paused/terminated agents are blocked from executing at the API level (403 AGENT_NOT_ACTIVE)
180
+ - **Input sanitization** — HTML/XSS stripped from labels, wallet IDs validated by strict hex regex, JSON parse errors handled gracefully
181
+ - **FROST threshold signing (RFC 9591)** — 2-of-3 Ed25519 threshold signatures; no single key compromise can sign
182
+ - **PolicyParticipant enforcement** — 5 independent checks (program allowlist, per-tx/daily limits, intent matching, suspicious patterns, cooldown)
183
+ - **Proactive share refresh** — rotate key shares without changing on-chain address; forward secrecy
184
+ - **PDA Vault (on-chain)** — Anchor program enforces spending limits and program allowlists at the Solana runtime level
185
+ - **Jito MEV protection** — bundle submission bypasses public mempool to prevent sandwich attacks (mainnet-beta only; devnet transactions use standard RPC submission)
186
+ - **Kora gasless transactions** — optional paymaster co-signing; agents transact without holding SOL for fees. Supports sponsored (free), margin, and fixed token fee modes. See `kora_server/` for local setup.
187
+
188
+ ### Documentation & Deep Dive (C3)
189
+
190
+ - [DEEP_DIVE.md](./DEEP_DIVE.md) — 1,700+ line architecture deep dive with 22 Mermaid diagrams (17 sections):
191
+ - System overview, separation of concerns, multi-agent isolation, key management flow
192
+ - Transaction signing sequence, HMAC authentication flow, wallet backup pipeline
193
+ - Agent lifecycle state machine, real-time event architecture, threat model visualization
194
+ - Section 12: FROST threshold signing architecture | Section 13: Threat model progression
195
+ - Section 14: Why this is a spending account | Section 15: Prompt injection defense
196
+ - Section 16: Transaction lifecycle (CU simulation, commitment strategy, retry)
197
+ - **Section 17: Full system architecture — the 5-layer defense-in-depth synthesizing argument**
198
+ - [SECURITY.md](./SECURITY.md) — Full STRIDE threat model, 12 mitigated threats (T1–T12), 5 accepted risks, cryptographic inventory table, attack surface map, production hardening roadmap
199
+ - [BENCHMARK.md](./BENCHMARK.md) — Stress test results: 12 concurrent agents, 76 ops, **0% error rate**, 1.8s total, wallet isolation proof, memory profile, extrapolation to 100+ agents
200
+ - [SKILLS.md](./SKILLS.md) — Complete agent capability catalog (93 tools across 11 categories) for judges/agents to read
201
+ - [VIDEO_SCRIPT.md](./VIDEO_SCRIPT.md) — Structured 7-scene, 5-minute demo recording script
202
+ - [DEMO.md](./DEMO.md) — Judge-friendly walkthrough of all demo scripts
203
+
204
+ ### Multi-Agent Scalability (C4)
205
+
206
+ - **Independent wallet isolation** — each agent has its own keypair, RPC context, tx log, spending ledger, strategy config, and lifecycle state; cryptographically verified (see [BENCHMARK.md](./BENCHMARK.md))
207
+ - **Agent monitoring dashboard** — live view of all agents: balance, status (idle/executing/error/paused/terminated), last action, daily spending bar, success rate
208
+ - **Agent lifecycle management** — pause, resume, or terminate agents with proper cleanup; terminated is terminal; transition history persisted
209
+ - **Agent-to-agent transfers** — one agent can send SOL or SPL tokens to another agent's wallet; lifecycle and spending checks enforced
210
+ - **Strategy presets** — conservative / balanced / aggressive risk profiles; affects slippage, max position size, leverage rules, protocol selection
211
+ - **Stress test** — `pnpm stress-test` spawns 12 concurrent agents, runs 7 phases (create, airdrop, balance, transfers, lifecycle, strategy, monitoring); **76 ops / 0 failures / 1.8s** on Solana devnet; see [BENCHMARK.md](./BENCHMARK.md) for full results
212
+
213
+ ### UI/UX Polish
214
+
215
+ - **Dark/light theme toggle** — CSS variable system with localStorage persistence, FOUC-free SSR
216
+ - **Loading skeletons** — shimmer placeholders for wallet panel, portfolio, agent monitor, analytics
217
+ - **Toast notifications** — success/error/info toasts for every user action (wallet create, airdrop, strategy change, backup, transfer, lifecycle transition)
218
+ - **Copy-to-clipboard** — animated clipboard → checkmark for wallet addresses, tx signatures, mint addresses
219
+ - **Solana Explorer deep links** — every tx signature and wallet address links to Solana Explorer with correct cluster
220
+ - **Mobile responsive layout** — tested on iOS (safe area insets, `h-dvh`, 16px input zoom prevention)
221
+
222
+ ---
223
+
224
+ ## MCP Server (Model Context Protocol)
225
+
226
+ Expose all wallet and agent management tools to Claude Desktop, Cursor, or any MCP-compatible client.
227
+
228
+ ```bash
229
+ # Start the MCP server
230
+ WALLET_ENCRYPTION_KEY=<key> pnpm mcp
231
+ ```
232
+
233
+ **Claude Desktop config** (`~/.claude/claude_desktop_config.json`):
234
+ ```json
235
+ {
236
+ "mcpServers": {
237
+ "stng-defi": {
238
+ "command": "npx",
239
+ "args": ["tsx", "src/mcp/server.ts"],
240
+ "cwd": "/path/to/stng_defi_wallets",
241
+ "env": {
242
+ "WALLET_ENCRYPTION_KEY": "<your-key>",
243
+ "SOLANA_RPC_URL": "https://api.devnet.solana.com"
244
+ }
245
+ }
246
+ }
247
+ }
248
+ ```
249
+
250
+ **18 tools** across 5 categories: wallet operations, FROST threshold signing, agent lifecycle management, spending & security controls, and portfolio analytics.
251
+
252
+ **5 guided prompts**: portfolio overview, security audit, agent creation, fleet health check, and wallet investigation.
253
+
254
+ ---
255
+
256
+ ## API Reference
257
+
258
+ All write/delete endpoints verify HMAC-SHA256 signatures when `X-Signature` header is present. All endpoints are rate-limited per-IP.
259
+
260
+ **Interactive docs:** `GET /api/openapi` returns the full OpenAPI 3.0 spec. Open `/api-docs` in the browser for Swagger UI (try any endpoint with one click).
261
+
262
+ ### Infrastructure
263
+
264
+ | Method | Endpoint | Description |
265
+ |--------|----------|-------------|
266
+ | GET | `/api/health` | RPC status, wallet count, LLM provider info |
267
+ | GET | `/api/events` | SSE stream of agent events (`?walletId=` for per-wallet filter) |
268
+ | GET | `/api/auth/signing-key` | Fetch derived HMAC signing key for request authentication |
269
+ | GET | `/api/openapi` | OpenAPI 3.0 specification (JSON) — import into Postman/Insomnia |
270
+
271
+ ### Wallets
272
+
273
+ | Method | Endpoint | Description |
274
+ |--------|----------|-------------|
275
+ | GET | `/api/wallet` | List all wallets with labels |
276
+ | POST | `/api/wallet` | Create wallet. Body: `{ "label": "name" }` — auto-airdrops devnet SOL |
277
+ | GET | `/api/wallet/:id` | Wallet details: SOL balance, SPL token list |
278
+ | DELETE | `/api/wallet/:id` | Delete wallet and all associated data |
279
+ | POST | `/api/wallet/:id?action=airdrop` | Request devnet SOL. Body: `{ "amount": 1 }` |
280
+ | GET | `/api/wallet/:id/history` | Paginated transaction history |
281
+ | GET | `/api/wallet/:id/limits` | Get spending limits (maxPerTx, maxPerDay, dailySpent) |
282
+ | PUT | `/api/wallet/:id/limits` | Update spending limits. Body: `{ "maxPerTx": 0.5, "maxPerDay": 2 }` |
283
+ | GET | `/api/wallet/:id/strategy` | Get risk strategy (conservative/balanced/aggressive) |
284
+ | PUT | `/api/wallet/:id/strategy` | Set strategy. Body: `{ "strategyId": "conservative" }` |
285
+ | POST | `/api/wallet/:id/backup` | Export password-protected encrypted backup |
286
+ | PUT | `/api/wallet/:id/backup` | Restore wallet from backup file + password |
287
+ | POST | `/api/wallet/:id?action=rekey` | Re-encrypt wallet with fresh salt + IV (forward secrecy) |
288
+
289
+ ### Agents
290
+
291
+ | Method | Endpoint | Description |
292
+ |--------|----------|-------------|
293
+ | GET | `/api/agents` | List all agents with SOL balances |
294
+ | POST | `/api/agents` | Spawn agent. Body: `{ "label": "Bot Name" }` — auto-airdrops |
295
+ | POST | `/api/agents/bulk` | Batch-create up to 20 agents. Body: `{ "labels": ["Bot1", "Bot2"] }` — returns array of walletIds |
296
+ | GET | `/api/agents/monitor` | Full monitoring data. Params: `?status=active&strategy=conservative&limit=10` |
297
+ | POST | `/api/agents/transfer` | Agent-to-agent transfer. Body: `{ "fromAgent", "toAgent", "amount", "mint?" }` |
298
+ | GET | `/api/agents/:id/lifecycle` | Get lifecycle state and transition history |
299
+ | PUT | `/api/agents/:id/lifecycle` | Transition state. Body: `{ "state": "paused" \| "active" \| "terminated" }` |
300
+ | POST | `/api/agents/:id/run` | Trigger one autonomous execution cycle — no human prompt needed |
301
+ | GET | `/api/agents/health-summary` | Aggregate security health across all agents: avg score, grade distribution, attention list |
302
+
303
+ ### FROST Threshold Signing
304
+
305
+ | Method | Endpoint | Description |
306
+ |--------|----------|-------------|
307
+ | GET | `/api/frost` | List all FROST wallets (metadata only) |
308
+ | POST | `/api/frost` | Create FROST wallet. Body: `{ "threshold": 2, "totalShares": 3, "labels": [...] }` |
309
+ | GET | `/api/frost/:id` | Get FROST wallet details + security health |
310
+ | DELETE | `/api/frost/:id` | Delete FROST wallet and all encrypted shares |
311
+ | POST | `/api/frost/:id/sign` | Execute FROST signing ceremony. Body: `{ "message", "participantIds", "intent?" }` |
312
+ | POST | `/api/frost/:id/refresh` | Refresh shares (proactive key rotation) — group key unchanged |
313
+
314
+ ### Kora Gasless Transactions
315
+
316
+ | Method | Endpoint | Description |
317
+ |--------|----------|-------------|
318
+ | GET | `/api/kora/status` | Kora paymaster status: enabled/disabled, fee mode, payer address, supported tokens |
319
+ | POST | `/api/kora/estimate` | Estimate transaction fee. Body: `{ "transaction": "<base64>", "feeToken?": "<mint>" }` |
320
+ | POST | `/api/frost/:id/sign-kora` | FROST sign + Kora co-sign and submit. Body: `{ "transaction", "participantIds", "intent?", "feeToken?" }` |
321
+
322
+ ### Chat & Operations
323
+
324
+ | Method | Endpoint | Description |
325
+ |--------|----------|-------------|
326
+ | POST | `/api/chat` | Streaming chat (SSE). Body: `{ "messages": [...], "walletId": "abc" }` |
327
+ | GET | `/api/demo` | List available demo scenarios |
328
+ | POST | `/api/demo` | Launch demo. Body: `{ "scenarioId": "defi-explorer" }` |
329
+ | GET | `/api/portfolio` | Aggregate portfolio: total USD value, per-wallet holdings, allocation |
330
+ | GET | `/api/analytics` | Usage analytics. Params: `?walletId=&hours=24` |
331
+ | GET | `/api/audit` | Audit log. Params: `?action=&walletId=&verify=true&limit=50&offset=0` |
332
+
333
+ ---
334
+
335
+ ## Multi-Agent Example
336
+
337
+ ```bash
338
+ # Spawn two independent agents
339
+ curl -X POST localhost:3000/api/agents \
340
+ -H 'Content-Type: application/json' \
341
+ -d '{"label": "Trading Bot"}'
342
+ # → { "walletId": "abc123", "publicKey": "..." }
343
+
344
+ curl -X POST localhost:3000/api/agents \
345
+ -H 'Content-Type: application/json' \
346
+ -d '{"label": "LP Manager"}'
347
+ # → { "walletId": "def456", "publicKey": "..." }
348
+
349
+ # Each agent operates independently with full isolation
350
+ curl -X POST localhost:3000/api/chat \
351
+ -H 'Content-Type: application/json' \
352
+ -d '{"walletId": "abc123", "messages": [{"role":"user","content":"Check my balance and swap 0.05 SOL for USDC"}]}'
353
+
354
+ curl -X POST localhost:3000/api/chat \
355
+ -H 'Content-Type: application/json' \
356
+ -d '{"walletId": "def456", "messages": [{"role":"user","content":"Stake 0.1 SOL via Jupiter"}]}'
357
+
358
+ # Agent-to-agent transfer
359
+ curl -X POST localhost:3000/api/agents/transfer \
360
+ -H 'Content-Type: application/json' \
361
+ -d '{"fromAgent": "abc123", "toAgent": "def456", "amount": 0.01}'
362
+
363
+ # Pause a misbehaving agent
364
+ curl -X PUT localhost:3000/api/agents/abc123/lifecycle \
365
+ -H 'Content-Type: application/json' \
366
+ -d '{"state": "paused"}'
367
+
368
+ # Monitor all agents
369
+ curl localhost:3000/api/agents/monitor
370
+ ```
371
+
372
+ ---
373
+
374
+ ## Demo Mode
375
+
376
+ Three pre-built autonomous scenarios launch with one click (UI or API):
377
+
378
+ | Scenario | Strategy | Description |
379
+ |----------|----------|-------------|
380
+ | `defi-explorer` | Balanced | Check balance, fetch SOL price, swap to USDC, summarize portfolio |
381
+ | `multi-protocol` | Balanced | Diversify across staking, swaps, and liquidity provision |
382
+ | `trading-bot` | Aggressive | Market analysis, conditional trades, position reporting |
383
+
384
+ ```bash
385
+ # List scenarios
386
+ curl localhost:3000/api/demo
387
+
388
+ # Launch a scenario (creates wallet, airdrops, sets strategy, returns prompt)
389
+ curl -X POST localhost:3000/api/demo \
390
+ -H 'Content-Type: application/json' \
391
+ -d '{"scenarioId": "trading-bot"}'
392
+ ```
393
+
394
+ ---
395
+
396
+ ## Running the Demos
397
+
398
+ ```bash
399
+ # Basic demo: wallet creation + airdrop + transaction signing
400
+ pnpm demo
401
+
402
+ # DeFi demo: AI agent autonomously executes multi-step DeFi operations
403
+ pnpm demo:defi
404
+
405
+ # Multi-agent demo: 3 concurrent agents with timing + memory metrics
406
+ pnpm demo:multi
407
+
408
+ # Stress test: 12 concurrent agents across 7 phases, with isolation verification
409
+ pnpm stress-test
410
+ # Override agent count: STRESS_AGENTS=20 pnpm stress-test
411
+ ```
412
+
413
+ See [DEMO.md](./DEMO.md) for a detailed judge-friendly walkthrough.
414
+
415
+ ---
416
+
417
+ ## Test Suite
418
+
419
+ ```bash
420
+ # Unit + API tests (~4s)
421
+ pnpm test
422
+
423
+ # With V8 coverage report
424
+ pnpm test --coverage
425
+
426
+ # On-chain tests against local validator (requires solana-test-validator)
427
+ pnpm validator:start && pnpm test:localnet
428
+
429
+ # E2E tests with Playwright (16 specs — requires dev server)
430
+ pnpm test:e2e
431
+
432
+ # Integration tests against devnet (requires RUN_INTEGRATION=1)
433
+ pnpm test:integration
434
+
435
+ # Type check only
436
+ pnpm typecheck
437
+
438
+ # Production build
439
+ pnpm build
440
+ ```
441
+
442
+ **Test breakdown (1,000+ total across 4 layers, zero mocks):**
443
+
444
+ | Layer | Tests | Files | What it covers |
445
+ |-------|------:|------:|----------------|
446
+ | Unit + API (Vitest) | 743 | 44 | Core library, API routes, tool count, stress-lite — **zero mocks** |
447
+ | FROST (Vitest) | 140 | 11 | Key management, ceremony, signer, policy, nonce, vault, share refresh, SATI, refresh triggers, e2e |
448
+ | Kora (Vitest) | 19 | 4 | Config, client, transaction prep, FROST+Kora adapter, gasless on-chain SOL transfers |
449
+ | Localnet (Vitest) | 40 | 6 | Real SOL transfers, balance queries, airdrops, health, full 17-phase workflow, **12 LLM vulnerability tests** — against `solana-test-validator` |
450
+ | E2E (Playwright) | 16 | 1 | Wallet creation → airdrop → chat → on-chain verification |
451
+ | Integration (devnet) | 55+ | 1 | Airdrop, SOL transfer, multi-agent, DeFi tool invocation via Solana Agent Kit |
452
+
453
+ Run localnet tests: `pnpm test:localnet` (requires `solana-test-validator`)
454
+ Run integration tests (requires devnet RPC): `pnpm test:integration`
455
+
456
+ **CI/CD:** GitHub Actions pipeline runs lint → test → typecheck → build → E2E on every push to main.
457
+
458
+ Test categories:
459
+ - Wallet encryption/decryption (AES-256-GCM, scrypt, round-trips, tamper detection)
460
+ - Wallet CRUD and multi-agent isolation
461
+ - Rate limiter logic, per-bucket presets, memory management
462
+ - Spending limits enforcement, daily window, SOL extraction
463
+ - HMAC request signing (sign, verify, replay protection, timing-safe compare)
464
+ - Audit log integrity chain (HMAC, filtering, pagination)
465
+ - Agent lifecycle state machine (transitions, terminal state, executable gate)
466
+ - Agent-to-agent transfer validation, lifecycle + spending guards
467
+ - Agent monitor aggregation, status derivation, sorting
468
+ - Portfolio aggregation, Jupiter price integration, allocation calc
469
+ - Analytics (time series, category breakdown, top tools, wallet activity)
470
+ - Demo scenarios (data integrity, prompt quality, strategy assignments)
471
+ - SSE event bus (client management, wallet filtering, reconnect, keep-alive)
472
+ - Toast notifications, copy button, loading skeletons (jsdom)
473
+ - Theme system, mobile responsive layout (jsdom)
474
+ - Error boundaries: RPC down, empty wallet, rate limit, lifecycle block, missing env
475
+ - E2E: full wallet → airdrop → chat → on-chain verification (Playwright)
476
+
477
+ ---
478
+
479
+ ## Security
480
+
481
+ See [SECURITY.md](./SECURITY.md) for the full threat model. Key properties:
482
+
483
+ | Property | Implementation |
484
+ |----------|----------------|
485
+ | Key storage | AES-256-GCM + scrypt (N=2^14, r=8, p=1) per-wallet salt |
486
+ | Key export | Never — no API endpoint reads raw private key bytes |
487
+ | Key re-encryption | `POST /api/wallet/:id?action=rekey` rotates salt+IV; old ciphertext becomes stale |
488
+ | Backup | AES-256-GCM + scrypt (N=2^17) under user password |
489
+ | API authentication | HMAC-SHA256 + 5-minute replay window |
490
+ | Rate limiting | Per-IP sliding window, 12 per-bucket presets |
491
+ | Spending controls | Configurable per-tx + per-day SOL caps, enforced server-side |
492
+ | Audit trail | HMAC-SHA256 integrity chain, append-only JSONL |
493
+ | FROST threshold signing | 2-of-3 RFC 9591 shares — no single point of compromise |
494
+ | PolicyParticipant | Independent TX validation: program allowlist, spending limits, intent matching |
495
+ | PDA Vault | Anchor program enforces on-chain spending limits and CPI allowlist |
496
+ | Gasless transactions | Kora paymaster co-signs as fee payer; agents don't need SOL for gas |
497
+ | Prompt injection defense | PolicyParticipant validates TX semantics, not natural language (see SECURITY.md §6) |
498
+ | Agent isolation | Separate keypair, RPC context, ledger, lifecycle state per agent |
499
+ | Path traversal | Wallet IDs validated as 8-char hex by strict regex before any file I/O |
500
+ | XSS prevention | HTML stripped from all user-supplied labels |
501
+
502
+ ---
503
+
504
+ ## Tech Stack
505
+
506
+ | Layer | Technology |
507
+ |-------|-----------|
508
+ | Framework | Next.js 15 (App Router) |
509
+ | AI | Vercel AI SDK 4 (`streamText`, `useChat`, `maxSteps: 10`) |
510
+ | Solana | solana-agent-kit 2.0 — TokenPlugin (26 tools) + DefiPlugin (70 tools) |
511
+ | Encryption | Node.js `crypto` — AES-256-GCM, scrypt KDF |
512
+ | FROST | `@substrate-system/frost` v0.0.9 — RFC 9591 Ed25519 threshold signatures |
513
+ | Gasless Txs | Kora paymaster (`@solana/kora` SDK) — fee payer co-signing, token fee abstraction |
514
+ | On-chain | 2 Anchor programs — `agent_vault` (PDA policy) + `agent_sati` (on-chain identity) |
515
+ | UI | React 19, Tailwind CSS 4, pure SVG charts |
516
+ | Testing | Vitest (unit), Playwright (E2E), @vitest/coverage-v8 |
517
+ | CI/CD | GitHub Actions — lint, test, typecheck, build, E2E |
518
+ | Runtime | Node.js 22, pnpm 9 |
519
+
520
+ ---
521
+
522
+ ## Documentation
523
+
524
+ | File | Contents |
525
+ |------|----------|
526
+ | [DEMO.md](./DEMO.md) | Judge-friendly demo walkthrough (start here) |
527
+ | [DEEP_DIVE.md](./DEEP_DIVE.md) | 1,500+ line architecture deep dive with 22 Mermaid diagrams |
528
+ | [SECURITY.md](./SECURITY.md) | STRIDE threat model, cryptographic inventory, attack surface map |
529
+ | [BENCHMARK.md](./BENCHMARK.md) | Stress test: 12 agents, 76 ops, 0% errors, 1.8s, isolation proof |
530
+ | [SKILLS.md](./SKILLS.md) | Complete agent capability catalog (93 tools, for agents to read) |
531
+ | [VIDEO_SCRIPT.md](./VIDEO_SCRIPT.md) | 7-scene, 5-minute demo recording script |
532
+ | `/api/openapi` | OpenAPI 3.0 JSON spec — import into Postman/Insomnia |
533
+ | `/api-docs` | Interactive Swagger UI — try all 18 endpoints in the browser |