@buildaureon/sdk 0.1.8 → 0.1.9

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 CHANGED
@@ -1,658 +1,673 @@
1
- <div align="center">
2
-
3
- # Aureon
4
-
5
- **Financial Intelligence Layer for Onchain AI Agents**
6
-
7
- The official TypeScript HTTP client for the AUREON API.
8
- Financial Compass, capital health, and verified restore plans: one typed integration surface.
9
-
10
- **Contract Address (CA):** `0xd293291060334d42e5dbea6fb854c231af527777`
11
-
12
- [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
13
- [![ESM](https://img.shields.io/badge/Module-ESM-f7df1e?style=flat-square)](#requirements)
14
- [![Version](https://img.shields.io/badge/version-0.1.8-a8e00d?style=flat-square)](https://github.com/buildaureon)
15
- [![License: MIT](https://img.shields.io/badge/license-MIT-0b0e0d?style=flat-square)](LICENSE)
16
- [![Node](https://img.shields.io/badge/node-%3E%3D20-339933?style=flat-square&logo=nodejs&logoColor=white)](#requirements)
17
-
18
- <br />
19
-
20
- ```bash
21
- pnpm add @buildaureon/sdk
22
- ```
23
-
24
- [Quickstart](#quickstart) · [Authentication](#authentication) · [API Surface](#api-surface) · [Docs](#documentation)
25
-
26
- </div>
27
-
28
- ---
29
-
30
- ## Table of contents
31
-
32
- 1. [Overview](#overview)
33
- 2. [What is AUREON?](#what-is-aureon)
34
- 3. [What this SDK is](#what-this-sdk-is)
35
- 4. [Ecosystem](#ecosystem)
36
- 5. [Full system architecture](#full-system-architecture)
37
- 6. [End-to-end flows](#end-to-end-flows)
38
- 7. [Requirements & installation](#requirements--installation)
39
- 8. [Quick start](#quick-start)
40
- 9. [Authentication](#detailed-authentication-guide)
41
- 10. [API surface reference](#api-surface-reference--code-walkthroughs)
42
- 11. [Client configuration](#client-configuration--transport-engine)
43
- 12. [Error model](#error-model-and-code-handling)
44
- 13. [CLI](#cli-command-line-guide)
45
- 14. [Design principles](#design-principles--settlement-honesty)
46
- 15. [Documentation registry](#documentation-registry)
47
- 16. [Community](#community--resources)
48
-
49
- ---
50
-
51
- ## Overview
52
-
53
- **AUREON** is the financial intelligence layer for onchain AI agents on **Robinhood Chain**. Agents and operators do not live on one-off swaps. They need continuous policy: keep a stable sleeve near a target weight, hold exposure bands on equity tokens, and restore capital when markets move. AUREON turns those rules into first-class **Financial Compass Objectives** — registered policies the system monitors, scores for health, and restores with explicit settlement receipts.
54
-
55
- Traditional web3 tooling is transactional. An operator submits a deposit or a swap, the chain settles once, and the broader intent disappears. Markets then move. Allocations drift. The agent either wakes up late or fires uncontrolled rebalances with no shared memory of why capital was supposed to look a certain way. AUREON closes that gap with a hosted policy and health engine, a non-custodial vault path on Robinhood Chain, and a typed TypeScript client so integrators never hand-roll the trust boundary between monitoring and signing.
56
-
57
- **`@buildaureon/sdk`** is the official TypeScript HTTP client in this repository. It is how agent runtimes, operator scripts, and product surfaces talk to the AUREON API: wallet session handshake, Capital Book sync, objective CRUD, health and timeline queries, vault deposit and withdraw step preparation, restore plan execution, and controlled market-event rehearsal for integration tests. Private keys stay with the host application. The API never holds custody. Receipts are honest about whether settlement was **vault** (on-chain) or **staged** (ledger-local, labeled for UI transparency).
58
-
59
- The broader product stack includes the hosted AUREON API and Health Watchdog, the operator utility at [app.aureonlabs.network](https://app.aureonlabs.network), Smart Vault contracts on Robinhood Chain, and the public site at [aureonlabs.network](https://www.aureonlabs.network/). This README is the integrator front door — dense enough to understand the system, practical enough to ship a first session, and linked into the long-form docs under `docs/`.
60
-
61
- ---
62
-
63
- ## What is AUREON?
64
-
65
- AUREON treats capital as a living policy surface rather than a sequence of forgotten transactions. Developers register continuous financial rules — for example, “maintain a stablecoin buffer at 25% of total portfolio value with a three-point tolerance.” The system then:
66
-
67
- - Monitors holdings across active addresses and smart vault contracts.
68
- - Marks portfolio value with public market data.
69
- - Detects allocation breaches against registered objective bands.
70
- - Produces recovery instructions (wrap or unwrap paths, keeper-driven vault swaps).
71
- - Appends an auditable timeline of compliance events and restore receipts.
72
-
73
- ### The concept: persistent objectives, honest settlement
74
-
75
- Unlike a one-shot rebalancer bot that fires and forgets, AUREON keeps the objective as the primitive. Health state, timeline events, and restore plans all hang off that policy object. When drift exceeds tolerance, the watchdog records a violation, a restore plan is available, and execution returns a receipt whose `settlement` field tells the truth about where capital actually moved.
76
-
77
- ```mermaid
78
- flowchart LR
79
- subgraph intent["Intent"]
80
- FCO[Financial Compass Objective]
81
- end
82
- subgraph engine["Policy engine"]
83
- Health[Health + Watchdog]
84
- Plan[Restore planner]
85
- end
86
- subgraph settle["Settlement"]
87
- Staged[staged receipt]
88
- Vault[vault / on-chain]
89
- end
90
- FCO --> Health --> Plan
91
- Plan --> Staged
92
- Plan --> Vault
93
- ```
94
-
95
- ### What AUREON is not
96
-
97
- - Not a custodian. Private keys never leave the client.
98
- - Not a silent black-box trader. Restores are plan-driven and receipted.
99
- - Not a claim that every restore is on-chain. `settlement: "staged"` means ledger-local and must be labeled as such in product UI.
100
-
101
- ---
102
-
103
- ## What this SDK is
104
-
105
- **`@buildaureon/sdk`** is the npm-facing TypeScript package for application developers and agent authors.
106
-
107
- | You can | Through |
108
- | --- | --- |
109
- | Authenticate with an issued API key (wallet identity) | `apiKey` on `createAureonClient` |
110
- | Authenticate a wallet session (optional nonce sign) | `getAuthNonce`, `verifyWallet`, `createSessionTokenProvider` |
111
- | Sync and manage the Capital Book | `syncPortfolio`, `setPortfolio`, `clearPortfolio` |
112
- | Create and query Financial Compass objectives | `createObjective`, `listObjectives`, `getObjective` |
113
- | Read health, timeline, and overview | `getHealth`, `getTimeline`, `getOverview`, `refreshWatchdog` |
114
- | Prepare non-custodial vault deposit / withdraw steps | `prepareVaultDeposit`, related vault helpers |
115
- | Fetch and execute restore plans | `getRestorePlan`, `restoreObjective` |
116
- | Apply controlled market events for integration rehearsal | `applyMarketEvent` |
117
- | Register agent intent as objective + portfolio flow | `applyFinancialIntent`, `getObjectivePortfolioFlow` |
118
- | Compare objective vs actual allocation | `getAllocationVsTarget` |
119
- | Manage developer API keys | `createApiKey`, `listApiKeys`, `toggleApiKey`, `revokeApiKey` |
120
-
121
- **This package alone does not:**
122
-
123
- - Hold or rotate private keys.
124
- - Broadcast transactions (your viem / wallet client does).
125
- - Deploy Smart Vault contracts.
126
- - Replace the hosted Health Watchdog — it calls it.
127
-
128
- ---
129
-
130
- ## Ecosystem
131
-
132
- ```mermaid
133
- flowchart TB
134
- subgraph clients["Integrators"]
135
- Agent[AI agent / operator script]
136
- Utility[Operator utility]
137
- end
138
- subgraph npm_pkg["npm: @buildaureon/sdk"]
139
- SDK[TypeScript client + CLI]
140
- end
141
- subgraph hosted["AUREON hosted layer"]
142
- API[API gateway]
143
- Watchdog[Health Watchdog]
144
- Ledger[(Ledger store)]
145
- end
146
- subgraph chain["Robinhood Chain L2"]
147
- Vault[Smart Vault]
148
- Keeper[Keeper rebalance path]
149
- end
150
- Agent --> SDK
151
- Utility --> SDK
152
- SDK -->|HTTPS + API key + JWT| API
153
- API --> Watchdog
154
- API --> Ledger
155
- Watchdog --> Keeper
156
- Agent -->|sign + broadcast steps| Vault
157
- Keeper --> Vault
158
- ```
159
-
160
- | Component | Surface | Role |
161
- | --- | --- | --- |
162
- | **@buildaureon/sdk** (this repo) | TypeScript / CLI | Typed client, session helpers, vault step prep |
163
- | **AUREON API** | Hosted HTTPS | Objectives, health, timeline, restore coordination |
164
- | **Operator utility** | [app.aureonlabs.network](https://app.aureonlabs.network) | Human console for keys, capital, and policy |
165
- | **Smart Vaults** | Robinhood Chain | Non-custodial on-chain capital path |
166
- | **Website** | [aureonlabs.network](https://www.aureonlabs.network/) | Product narrative and entry points |
167
-
168
- ---
169
-
170
- ## Full system architecture
171
-
172
- Complete AUREON topology: SDK client, hosted policy engines, ledger, vault settlement, and local signing.
173
-
174
- ```mermaid
175
- flowchart TB
176
- subgraph CLIENT["CLIENT LAYER — Operator / Agent"]
177
- direction TB
178
- APP["Host application"]
179
- SDK["@buildaureon/sdk"]
180
- SESSION["Session token provider"]
181
- SIGNER["Wallet signer · Viem"]
182
- APP --> SDK
183
- APP --> SESSION
184
- APP --> SIGNER
185
- end
186
-
187
- subgraph CLOUD["HOSTED INGRESS AUREON API"]
188
- direction TB
189
- API["API gateway"]
190
- DB[("Ledger store")]
191
- ORACLE["Public price marks"]
192
- HEALTH["Health evaluation"]
193
- WATCH["Watchdog heartbeat"]
194
- PLANNER["Restore planner"]
195
- API --> DB
196
- API --> HEALTH
197
- API --> WATCH
198
- ORACLE --> HEALTH
199
- WATCH --> PLANNER
200
- end
201
-
202
- subgraph EVM["ROBINHOOD CHAIN L2"]
203
- direction TB
204
- VAULT["AUREON Smart Vault"]
205
- KEEPER["Keeper rebalance adapter"]
206
- KEEPER --> VAULT
207
- end
208
-
209
- SDK -->|"1 HTTPS · API key · JWT"| API
210
- API -->|"2 health / plans / steps"| SDK
211
- SIGNER -->|"3 sign + broadcast"| VAULT
212
- WATCH -->|"4 violation → plan"| PLANNER
213
- PLANNER -->|"5 vault_swap path"| KEEPER
214
-
215
- style CLIENT fill:#f9faf3,stroke:#0b0e0d,color:#0b0e0d
216
- style CLOUD fill:#f9faf3,stroke:#a8e00d,color:#0b0e0d
217
- style EVM fill:#f9faf3,stroke:#0b0e0d,color:#0b0e0d
218
- ```
219
-
220
- ### Architecture at a glance
221
-
222
- | Layer | Components | Trust boundary |
223
- | --- | --- | --- |
224
- | **Client** | Host app, `@buildaureon/sdk`, session provider, local signer | Keys and broadcast stay here |
225
- | **Hosted** | API, ledger, oracles, health, watchdog, planner | Policy, pricing, coordination — no private keys |
226
- | **Chain** | Smart Vault, keeper path | Settlement when `settlement: "vault"` |
227
-
228
- Deep dive: [docs/architecture.md](docs/architecture.md) · [docs/security.md](docs/security.md) · [docs/integration-guide.md](docs/integration-guide.md)
229
-
230
- ---
231
-
232
- ## End-to-end flows
233
-
234
- ### Client–API trust boundary
235
-
236
- To protect user funds, AUREON splits responsibility. The hosted API monitors capital, marks prices, evaluates objectives, and coordinates restore plans. The host application alone stores keys and signs transactions. The SDK sits on that boundary: it validates inputs, transports requests, prepares unsigned vault calldata, and never asks for a private key.
237
-
238
- | Layer | Responsibility |
239
- | --- | --- |
240
- | **SDK** | Transport, validation, retries, EIP-712 helpers, vault step construction |
241
- | **AUREON API** | Ledger sync, objective logic, price marks, timeline, staged or vault restore coordination |
242
- | **Host application** | Key storage, wallet UX, signing, broadcasting |
243
-
244
- ### Session authentication flow
245
-
246
- Authentication is a challenge–response handshake that binds a wallet address to a temporary JWT.
247
-
248
- ```mermaid
249
- sequenceDiagram
250
- autonumber
251
- participant App as Client Operator
252
- participant SDK as SDK Client
253
- participant API as AUREON API Gateway
254
-
255
- App->>SDK: aureon.getAuthNonce(address)
256
- SDK->>API: GET /auth/nonce?address=0x...
257
- API-->>SDK: { message, nonce, expiresAt }
258
- SDK-->>App: { message, nonce }
259
- Note over App: Operator signs message<br/>using private key
260
- App->>SDK: aureon.verifyWallet({ address, message, signature })
261
- SDK->>API: POST /auth/verify { address, message, signature }
262
- API->>API: Verify EIP-191 Signature
263
- API-->>SDK: { token, expiresAt, sessionId }
264
- SDK-->>App: Return JWT Token
265
- ```
266
-
267
- ### Watchdog and restore flow
268
-
269
- When portfolio weights drift past tolerance, health flips to violation and a restore plan becomes available.
270
-
271
- ```mermaid
272
- sequenceDiagram
273
- autonumber
274
- participant Client as Client Application
275
- participant API as AUREON API Gateway
276
- participant DB as Ledger Store
277
- participant Engine as Health Engine
278
- participant Keeper as Keeper Service
279
-
280
- Client->>API: aureon.refreshWatchdog()
281
- API->>DB: Pull price marks and positions
282
- API->>Engine: Recompute objective deviations
283
- alt Drift exceeds tolerance
284
- Engine->>DB: Write health state: violation
285
- Engine->>DB: Write event: violation_detected
286
- Engine->>Keeper: Request restoration plan
287
- Keeper-->>API: Return plan (e.g. vault_swap)
288
- else Within bands
289
- Engine->>DB: Write health state: healthy
290
- end
291
- API-->>Client: Watchdog status and breach reports
292
- ```
293
-
294
- Typical operator loop in prose:
295
-
296
- 1. **Define capital** sync the Capital Book from chain or seed an explicit book for rehearsal.
297
- 2. **Register policy** — create a Financial Compass objective with target weight and tolerance.
298
- 3. **Observe** poll health and timeline; refresh the watchdog after market moves.
299
- 4. **Restore** fetch the plan, execute restore, read `settlement` on the receipt.
300
- 5. **Verify** confirm health returns to healthy and the timeline shows the restore event.
301
-
302
- ---
303
-
304
- ## Requirements & installation
305
-
306
- ### Requirements
307
-
308
- - **Node.js** 20 or higher (ESM).
309
- - **Viem** 2.x when you sign and broadcast vault steps.
310
-
311
- ### Installation
312
-
313
- ```bash
314
- pnpm add @buildaureon/sdk
315
- # or
316
- npm install @buildaureon/sdk
317
- # or
318
- yarn add @buildaureon/sdk
319
- ```
320
-
321
- ---
322
-
323
- ## Quick start
324
-
325
- Initialize the client with an **issued** developer API key (Developers page in the utility).
326
- That key identifies your wallet for control-plane calls — sync, objectives, health, restore plans.
327
- A private key is only needed later to **broadcast** on-chain deposit/withdraw txs.
328
-
329
- **SDK supports Automatic objectives only** (`automationMode: "auto"`, the default). Manual Approve workflows stay in the operator utility.
330
-
331
- ```ts
332
- import { createAureonClient } from "@buildaureon/sdk";
333
-
334
- async function run() {
335
- const aureon = createAureonClient({
336
- apiKey: process.env.AUREON_API_KEY!, // issued key from Developers console
337
- });
338
- // Default network is mainnet (4663 / http://127.0.0.1:8788).
339
- // Opt in to testnet: createAureonClient({ network: "testnet", apiKey })
340
- // Public api.aureonlabs.network is still chain 46630.
341
-
342
- const me = await aureon.me();
343
- console.log("wallet", me.walletAddress);
344
-
345
- const synced = await aureon.syncPortfolio();
346
- console.log("Portfolio Value USD:", synced.portfolio.totalNotionalUsd);
347
- }
348
- ```
349
-
350
- Optional wallet Bearer (nonce → sign → `verifyWallet`) still works and **wins** when both
351
- are sent. Env bootstrap keys (`AUREON_API_KEYS` on the server) unlock product access only —
352
- they do not identify a wallet; use an issued key or a Bearer session with those.
353
-
354
- From here, create an objective, read health, and restore when the watchdog reports a violation.
355
- Full walkthroughs live in [docs/integration-guide.md](docs/integration-guide.md).
356
-
357
- ---
358
-
359
- ## Detailed authentication guide
360
-
361
- ### Issued API keys (recommended for SDK / agents)
362
-
363
- Create a key in the operator utility **Developers** console. The plaintext secret is shown once.
364
- Send it as `X-Aureon-Api-Key`. The gateway resolves the bound wallet and scopes ledger operations
365
- to that address. Treat issued keys like passwords: pause, revoke, rotate; never commit them.
366
-
367
- ### Private key / on-chain signing
368
-
369
- `prepareVaultDeposit` / `prepareVaultWithdraw` return **unsigned** calldata. Broadcasting those
370
- transactions (and any other signed chain steps) requires the wallet private key or a browser
371
- wallet — not the API key.
372
-
373
- ### Wallet bearer handshake (optional)
374
-
375
- Bearer sessions also scope ledger operations to a wallet. The SDK fetches a nonce message, the
376
- host signs it with an EVM signer, and `/auth/verify` returns a session token for `getAccessToken`.
377
- Use this for the browser utility, or when you only have an env bootstrap key (no issued key).
378
-
379
- ### Token provider lifecycle
380
-
381
- ```ts
382
- import { createSessionTokenProvider } from "@buildaureon/sdk";
383
-
384
- const session = createSessionTokenProvider(process.env.AUREON_TOKEN ?? null);
385
-
386
- await aureon.logout();
387
- session.clear();
388
- ```
389
-
390
- `createSessionTokenProvider` is a small stateful container: set after verify, clear on logout,
391
- inject via `getAccessToken` so the client stays free of global mutable auth state.
392
-
393
- ---
394
-
395
- ## API surface reference & code walkthroughs
396
-
397
- ### Connection smoke tests
398
-
399
- ```ts
400
- const ping = await aureon.ping();
401
- console.log(`Connected. Backend version: ${ping.version}`);
402
- ```
403
-
404
- ### Managing the Capital Book
405
-
406
- The Capital Book is the set of positions AUREON tracks for weight and health math. Sync from Robinhood Chain and vaults, or set an explicit book for controlled rehearsal environments.
407
-
408
- ```ts
409
- const syncResult = await aureon.syncPortfolio();
410
- console.log("Current stable coin weight:", syncResult.portfolio.stableWeight);
411
-
412
- const updatedBook = await aureon.setPortfolio([
413
- { symbol: "WETH", quantity: 2.5, category: "gas" },
414
- { symbol: "USDG", quantity: 2500, category: "stable" },
415
- ]);
416
-
417
- await aureon.clearPortfolio();
418
- ```
419
-
420
- ### Defining and querying objectives
421
-
422
- Objectives are the Financial Compass primitives: target weights, tolerance bands, and priority. SDK-created objectives participate in automatic restore coordination when health enters violation.
423
-
424
- ```ts
425
- const stableObj = await aureon.createObjective({
426
- name: "Stable Core Reserve",
427
- kind: "stable_allocation",
428
- targetWeight: 0.3,
429
- tolerance: 0.03,
430
- priority: "high",
431
- });
432
-
433
- const stockObj = await aureon.createObjective({
434
- name: "Tesla Sleeve Allocation",
435
- kind: "balanced_portfolio",
436
- targetSymbol: "TSLA",
437
- targetWeight: 0.2,
438
- tolerance: 0.05,
439
- });
440
-
441
- const objectives = await aureon.listObjectives();
442
- ```
443
-
444
- ### Health, timeline, and overview
445
-
446
- ```ts
447
- const healthRecords = await aureon.getHealth();
448
- for (const health of healthRecords) {
449
- console.log(`Objective ${health.objectiveId}: State: ${health.state}`);
450
- }
451
-
452
- const timeline = await aureon.getTimeline();
453
- timeline.forEach((event) => console.log(`[${event.type}]: ${event.message}`));
454
-
455
- const overview = await aureon.getOverview();
456
- console.log("Global health score:", overview.globalHealthScore);
457
- ```
458
-
459
- ### Non-custodial vault operations
460
-
461
- Vault helpers prepare unsigned steps. The host signs and broadcasts; AUREON never receives the private key.
462
-
463
- ```ts
464
- import type { Hex } from "viem";
465
-
466
- const depositData = await aureon.prepareVaultDeposit({
467
- symbol: "ETH",
468
- amount: "0.5",
469
- });
470
-
471
- for (const step of depositData.steps) {
472
- const hash = await walletClient.sendTransaction({
473
- account,
474
- to: step.to as `0x${string}`,
475
- data: step.data as Hex,
476
- value: BigInt(step.value),
477
- });
478
- await publicClient.waitForTransactionReceipt({ hash });
479
- }
480
- ```
481
-
482
- ### Restore plans and rebalances
483
-
484
- When health is in violation, fetch the plan and execute. Always read `settlement` on the receipt.
485
-
486
- ```ts
487
- const plan = await aureon.getRestorePlan(objective.id);
488
- console.log(`Plan requires action: ${plan.kind} for ${plan.amountHuman} tokens.`);
489
-
490
- if (plan.kind === "vault_swap") {
491
- const receipt = await aureon.restoreObjective(objective.id);
492
- console.log("Rebalance transaction hash:", receipt.transactionHash);
493
- console.log("Settlement environment:", receipt.settlement); // "vault" | "staged"
494
- } else {
495
- console.warn("Execute wrap_eth or unwrap_weth with your wallet provider.");
496
- }
497
- ```
498
-
499
- ### Controlled market events
500
-
501
- Apply a deterministic price mark change to rehearse breach and restore paths in integration environments. This is a controlled market event against the ledger marks — not a claim of live exchange execution.
502
-
503
- ```ts
504
- const shockResult = await aureon.applyMarketEvent({
505
- symbol: "NVDA",
506
- priceChangeRatio: -0.15,
507
- autoRestore: true,
508
- });
509
- ```
510
-
511
- ### Developer API key management
512
-
513
- ```ts
514
- const newKey = await aureon.createApiKey("Secondary Bot Ingress");
515
- console.log(`Plaintext secret: ${newKey.secret}`);
516
-
517
- const keys = await aureon.listApiKeys();
518
- await aureon.toggleApiKey(newKey.id);
519
- await aureon.revokeApiKey(newKey.id);
520
- ```
521
-
522
- ---
523
-
524
- ## Client configuration & transport engine
525
-
526
- ### Configuration reference
527
-
528
- | Parameter | Type | Default | Description |
529
- | --- | --- | --- | --- |
530
- | `network` | `"mainnet" \| "testnet"` | `"mainnet"` | Bundles chain + API. Mainnet is 4663 / local 8788. Testnet is optional (public host, still 46630). |
531
- | `baseUrl` | `string` | mainnet `http://127.0.0.1:8788` | Explicit URL still wins. Must not disagree with `network`. |
532
- | `apiKey` | `string` | `undefined` | Sent as `X-Aureon-Api-Key` |
533
- | `authToken` | `string` | `undefined` | Static JWT bearer |
534
- | `getAccessToken` | `() => string \| null` | `undefined` | Dynamic bearer resolver |
535
- | `timeoutMs` | `number` | `30000` | Per-call abort threshold |
536
- | `maxRetries` | `number` | `0` | Transient failure retries |
537
- | `retryDelayMs` | `number` | `250` | Delay between retries |
538
- | `headers` | `Record<string, string>` | `{}` | Extra headers |
539
- | `fetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch override |
540
-
541
- ### Retries and failover
542
-
543
- When `maxRetries` is greater than zero, the client retries timeouts and selected transient HTTP failures with a fixed `retryDelayMs`. Prefer raising retries for long-running agent loops; keep them low for interactive UI paths where fail-fast is better.
544
-
545
- ---
546
-
547
- ## Error model and code handling
548
-
549
- ### Error code reference
550
-
551
- | Code | HTTP | Description |
552
- | --- | --- | --- |
553
- | `UNAUTHORIZED` | 401 | Missing or invalid API key or bearer |
554
- | `VALIDATION_ERROR` | 400 | Payload failed validation |
555
- | `NOT_FOUND` | 404 | Objective, key, or resource missing |
556
- | `CONFLICT` | 409 | Request conflicts with current ledger state |
557
- | `RATE_LIMITED` | 429 | Request volume exceeded |
558
- | `SERVER_ERROR` | 500 / 503 | Hosted execution failure |
559
- | `TIMEOUT` | — | Exceeded `timeoutMs` |
560
- | `NETWORK_ERROR` | — | Endpoint unreachable |
561
-
562
- ### Narrowing errors in practice
563
-
564
- ```ts
565
- import { isAureonError } from "@buildaureon/sdk";
566
-
567
- try {
568
- await aureon.getObjective("missing_id");
569
- } catch (error) {
570
- if (isAureonError(error)) {
571
- switch (error.code) {
572
- case "NOT_FOUND":
573
- console.error("The specified objective does not exist.");
574
- break;
575
- case "UNAUTHORIZED":
576
- console.error("Check API key and wallet session configuration.");
577
- break;
578
- default:
579
- console.error(`Aureon error: ${error.message}`);
580
- }
581
- } else {
582
- console.error("Generic execution failure:", error);
583
- }
584
- }
585
- ```
586
-
587
- Full matrix: [docs/error-model.md](docs/error-model.md).
588
-
589
- ---
590
-
591
- ## CLI command-line guide
592
-
593
- The package ships a developer CLI. Configure credentials via environment variables:
594
-
595
- ```bash
596
- # Issued developer key (recommended) — identifies wallet;
597
- export AUREON_API_KEY=aureon_....
598
-
599
- pnpm --filter @buildaureon/sdk cli ping
600
- pnpm --filter @buildaureon/sdk cli me
601
- pnpm --filter @buildaureon/sdk cli sync
602
- pnpm --filter @buildaureon/sdk cli portfolio
603
- pnpm --filter @buildaureon/sdk cli objectives
604
- ```
605
-
606
- ### Runnable examples (live API)
607
-
608
- Requires `AUREON_API_KEY`:
609
-
610
- ```bash
611
- pnpm example:ai-to-objective-to-portfolio
612
- pnpm example:drift-detect-restore
613
- pnpm example:receipt-verification
614
- pnpm example:portfolio-watch
615
- pnpm example:full-aureon-loop
616
- pnpm example:green-vs-plan
617
- ```
618
-
619
- ---
620
-
621
- ## Design principles & settlement honesty
622
-
623
- 1. **Non-custodial by construction.** Private keys never leave the client. The API verifies signatures and returns unsigned steps; it does not sign for you.
624
- 2. **Settlement transparency.** Every execution receipt includes `settlement`: `"vault"` means Robinhood Chain settlement; `"staged"` means ledger-local and must be labeled clearly in any user-facing surface.
625
- 3. **Seeded capital, not invented capital.** Positions come from chain sync or explicit operator input. The SDK does not invent balances to make demos look healthy.
626
- 4. **Objectives as primitives.** Health, timeline, and restores hang off Financial Compass objectives so agents can reason about policy, not only about the last transaction hash.
627
-
628
- ---
629
-
630
- ## Documentation registry
631
-
632
- Long-form technical docs live under `docs/`:
633
-
634
- | Document | Focus |
635
- | --- | --- |
636
- | [docs/architecture.md](docs/architecture.md) | Client vs API boundary, system maps |
637
- | [docs/auth.md](docs/auth.md) | Wallet handshake and JWT lifecycle |
638
- | [docs/client-api.md](docs/client-api.md) | Method and parameter index |
639
- | [docs/data-contracts.md](docs/data-contracts.md) | Types aligned to hosted JSON |
640
- | [docs/error-model.md](docs/error-model.md) | Full error code mapping |
641
- | [docs/integration-guide.md](docs/integration-guide.md) | End-to-end integrator walkthrough |
642
- | [docs/security.md](docs/security.md) | API key and token guidance |
643
- | [docs/transport.md](docs/transport.md) | Retries, headers, transport edge cases |
644
-
645
- ---
646
-
647
- ## Community & resources
648
-
649
- - **Website:** [aureonlabs.network](https://www.aureonlabs.network/)
650
- - **Operator utility:** [app.aureonlabs.network](https://app.aureonlabs.network)
651
- - **X:** [@buildaureon](https://x.com/buildaureon)
652
- - **GitHub:** [github.com/buildaureon](https://github.com/buildaureon)
653
-
654
- ---
655
-
656
- ## License
657
-
658
- MIT — see [LICENSE](LICENSE).
1
+ <div align="center">
2
+
3
+ # Aureon
4
+
5
+ **Financial Intelligence Layer for Onchain AI Agents**
6
+
7
+ The official TypeScript HTTP client for the AUREON API.
8
+ Financial Compass, capital health, and verified restore plans: one typed integration surface.
9
+
10
+ Default network is **Robinhood Chain mainnet** (chain 4663). Confirm live vault and token addresses from the API you actually call.
11
+
12
+ [![TypeScript](https://img.shields.io/badge/TypeScript-5.x-3178C6?style=flat-square&logo=typescript&logoColor=white)](https://www.typescriptlang.org/)
13
+ [![ESM](https://img.shields.io/badge/Module-ESM-f7df1e?style=flat-square)](#requirements)
14
+ [![Version](https://img.shields.io/badge/version-0.1.9-a8e00d?style=flat-square)](https://github.com/buildaureon)
15
+ [![License: MIT](https://img.shields.io/badge/license-MIT-0b0e0d?style=flat-square)](LICENSE)
16
+ [![Node](https://img.shields.io/badge/node-%3E%3D20-339933?style=flat-square&logo=nodejs&logoColor=white)](#requirements)
17
+
18
+ <br />
19
+
20
+ ```bash
21
+ pnpm add @buildaureon/sdk
22
+ ```
23
+
24
+ [Quickstart](#quickstart) · [Authentication](#authentication) · [API Surface](#api-surface) · [Docs](#documentation)
25
+
26
+ </div>
27
+
28
+ ---
29
+
30
+ ## Table of contents
31
+
32
+ 1. [Overview](#overview)
33
+ 2. [What is AUREON?](#what-is-aureon)
34
+ 3. [What this SDK is](#what-this-sdk-is)
35
+ 4. [Ecosystem](#ecosystem)
36
+ 5. [Networks](#networks)
37
+ 6. [Full system architecture](#full-system-architecture)
38
+ 7. [End-to-end flows](#end-to-end-flows)
39
+ 8. [Requirements & installation](#requirements--installation)
40
+ 9. [Quick start](#quick-start)
41
+ 10. [Authentication](#detailed-authentication-guide)
42
+ 11. [API surface reference](#api-surface-reference--code-walkthroughs)
43
+ 12. [Client configuration](#client-configuration--transport-engine)
44
+ 13. [Error model](#error-model-and-code-handling)
45
+ 14. [CLI](#cli-command-line-guide)
46
+ 15. [Design principles](#design-principles--settlement-honesty)
47
+ 16. [Documentation registry](#documentation-registry)
48
+ 17. [Community](#community--resources)
49
+
50
+ ---
51
+
52
+ ## Overview
53
+
54
+ **AUREON** is the financial intelligence layer for onchain AI agents on **Robinhood Chain**. Agents and operators do not live on one-off swaps. They need continuous policy: keep a stable sleeve near a target weight, hold exposure bands on equity tokens, and restore capital when markets move. AUREON turns those rules into first-class **Financial Compass Objectives** — registered policies the system monitors, scores for health, and restores with explicit settlement receipts.
55
+
56
+ Traditional web3 tooling is transactional. An operator submits a deposit or a swap, the chain settles once, and the broader intent disappears. Markets then move. Allocations drift. The agent either wakes up late or fires uncontrolled rebalances with no shared memory of why capital was supposed to look a certain way. AUREON closes that gap with a hosted policy and health engine, a non-custodial vault path on Robinhood Chain, and a typed TypeScript client so integrators never hand-roll the trust boundary between monitoring and signing.
57
+
58
+ **`@buildaureon/sdk`** is the official TypeScript HTTP client in this repository. It is how agent runtimes, operator scripts, and product surfaces talk to the AUREON API: wallet session handshake, Capital Book sync, objective CRUD, health and timeline queries, vault deposit and withdraw step preparation, restore plan execution, and controlled market-event rehearsal for integration tests. Private keys stay with the host application. The API never holds custody. Receipts are honest about whether settlement was **vault** (on-chain) or **staged** (ledger-local, labeled for UI transparency).
59
+
60
+ The broader product stack includes the hosted AUREON API and Health Watchdog, the operator utility at [app.aureonlabs.network](https://app.aureonlabs.network), Smart Vault contracts on Robinhood Chain, and the public site at [aureonlabs.network](https://www.aureonlabs.network/). This README is the integrator front door — dense enough to understand the system, practical enough to ship a first session, and linked into the long-form docs under `docs/`.
61
+
62
+ ---
63
+
64
+ ## What is AUREON?
65
+
66
+ AUREON treats capital as a living policy surface rather than a sequence of forgotten transactions. Developers register continuous financial rules — for example, “maintain a stablecoin buffer at 25% of total portfolio value with a three-point tolerance.” The system then:
67
+
68
+ - Monitors holdings across active addresses and smart vault contracts.
69
+ - Marks portfolio value with public market data.
70
+ - Detects allocation breaches against registered objective bands.
71
+ - Produces recovery instructions (wrap or unwrap paths, keeper-driven vault swaps).
72
+ - Appends an auditable timeline of compliance events and restore receipts.
73
+
74
+ ### The concept: persistent objectives, honest settlement
75
+
76
+ Unlike a one-shot rebalancer bot that fires and forgets, AUREON keeps the objective as the primitive. Health state, timeline events, and restore plans all hang off that policy object. When drift exceeds tolerance, the watchdog records a violation, a restore plan is available, and execution returns a receipt whose `settlement` field tells the truth about where capital actually moved.
77
+
78
+ ```mermaid
79
+ flowchart LR
80
+ subgraph intent["Intent"]
81
+ FCO[Financial Compass Objective]
82
+ end
83
+ subgraph engine["Policy engine"]
84
+ Health[Health + Watchdog]
85
+ Plan[Restore planner]
86
+ end
87
+ subgraph settle["Settlement"]
88
+ Staged[staged receipt]
89
+ Vault[vault / on-chain]
90
+ end
91
+ FCO --> Health --> Plan
92
+ Plan --> Staged
93
+ Plan --> Vault
94
+ ```
95
+
96
+ ### What AUREON is not
97
+
98
+ - Not a custodian. Private keys never leave the client.
99
+ - Not a silent black-box trader. Restores are plan-driven and receipted.
100
+ - Not a claim that every restore is on-chain. `settlement: "staged"` means ledger-local and must be labeled as such in product UI.
101
+
102
+ ---
103
+
104
+ ## What this SDK is
105
+
106
+ **`@buildaureon/sdk`** is the npm-facing TypeScript package for application developers and agent authors.
107
+
108
+ | You can | Through |
109
+ | --- | --- |
110
+ | Authenticate with an issued API key (wallet identity) | `apiKey` on `createAureonClient` |
111
+ | Authenticate a wallet session (optional nonce → sign) | `getAuthNonce`, `verifyWallet`, `createSessionTokenProvider` |
112
+ | Sync and manage the Capital Book | `syncPortfolio`, `setPortfolio`, `clearPortfolio` |
113
+ | Create and query Financial Compass objectives | `createObjective`, `listObjectives`, `getObjective` |
114
+ | Read health, timeline, and overview | `getHealth`, `getTimeline`, `getOverview`, `refreshWatchdog` |
115
+ | Prepare non-custodial vault deposit / withdraw steps | `prepareVaultDeposit`, related vault helpers |
116
+ | Fetch and execute restore plans | `getRestorePlan`, `restoreObjective` |
117
+ | Apply controlled market events for integration rehearsal | `applyMarketEvent` |
118
+ | Register agent intent as objective + portfolio flow | `applyFinancialIntent`, `getObjectivePortfolioFlow` |
119
+ | Compare objective vs actual allocation | `getAllocationVsTarget` |
120
+ | Manage developer API keys | `createApiKey`, `listApiKeys`, `toggleApiKey`, `revokeApiKey` |
121
+
122
+ **This package alone does not:**
123
+
124
+ - Hold or rotate private keys.
125
+ - Broadcast transactions (your viem / wallet client does).
126
+ - Deploy Smart Vault contracts.
127
+ - Replace the hosted Health Watchdog — it calls it.
128
+
129
+ ---
130
+
131
+ ## Ecosystem
132
+
133
+ ```mermaid
134
+ flowchart TB
135
+ subgraph clients["Integrators"]
136
+ Agent[AI agent / operator script]
137
+ Utility[Operator utility]
138
+ end
139
+ subgraph npm_pkg["npm: @buildaureon/sdk"]
140
+ SDK[TypeScript client + CLI]
141
+ end
142
+ subgraph hosted["AUREON hosted layer"]
143
+ API[API gateway]
144
+ Watchdog[Health Watchdog]
145
+ Ledger[(Ledger store)]
146
+ end
147
+ subgraph chain["Robinhood Chain L2"]
148
+ Vault[Smart Vault]
149
+ Keeper[Keeper rebalance path]
150
+ end
151
+ Agent --> SDK
152
+ Utility --> SDK
153
+ SDK -->|HTTPS + API key + JWT| API
154
+ API --> Watchdog
155
+ API --> Ledger
156
+ Watchdog --> Keeper
157
+ Agent -->|sign + broadcast steps| Vault
158
+ Keeper --> Vault
159
+ ```
160
+
161
+ | Component | Surface | Role |
162
+ | --- | --- | --- |
163
+ | **@buildaureon/sdk** (this repo) | TypeScript / CLI | Typed client, session helpers, vault step prep |
164
+ | **AUREON API** | Hosted HTTPS | Objectives, health, timeline, restore coordination |
165
+ | **Operator utility** | [app.aureonlabs.network](https://app.aureonlabs.network) | Human console for keys, capital, and policy |
166
+ | **Smart Vaults** | Robinhood Chain | Non-custodial on-chain capital path |
167
+ | **Website** | [aureonlabs.network](https://www.aureonlabs.network/) | Product narrative and entry points |
168
+
169
+ ---
170
+
171
+ ## Networks
172
+
173
+ Omitted `network` / omitted `baseUrl` uses the official API `https://api.aureonlabs.network` on Robinhood Chain **testnet 46630**. Pass `network: "mainnet"` (or `AUREON_NETWORK=mainnet`) to select chain **4663** on the same official host. Set `baseUrl` / `AUREON_API_URL` only to override that host.
174
+
175
+ The official host still serves chain **46630** until that deployment is cut over to 4663. Issue developer keys at [app.aureonlabs.network](https://app.aureonlabs.network). First use: an empty vault Automatic restore returns **409**; `prepareVaultDeposit` returns unsigned steps; the host wallet or MetaMask broadcasts; this SDK and MCP agents never broadcast deposits.
176
+
177
+ | | Testnet (default) | Mainnet (`network: "mainnet"`) |
178
+ | --- | --- | --- |
179
+ | Chain ID | 46630 | 4663 |
180
+ | API | `https://api.aureonlabs.network` | `https://api.aureonlabs.network` |
181
+ | Utility | [app.aureonlabs.network](https://app.aureonlabs.network) | [app.aureonlabs.network](https://app.aureonlabs.network) |
182
+
183
+ ---
184
+
185
+ ## Full system architecture
186
+
187
+ Complete AUREON topology: SDK client, hosted policy engines, ledger, vault settlement, and local signing.
188
+
189
+ ```mermaid
190
+ flowchart TB
191
+ subgraph CLIENT["CLIENT LAYER — Operator / Agent"]
192
+ direction TB
193
+ APP["Host application"]
194
+ SDK["@buildaureon/sdk"]
195
+ SESSION["Session token provider"]
196
+ SIGNER["Wallet signer · Viem"]
197
+ APP --> SDK
198
+ APP --> SESSION
199
+ APP --> SIGNER
200
+ end
201
+
202
+ subgraph CLOUD["HOSTED INGRESS — AUREON API"]
203
+ direction TB
204
+ API["API gateway"]
205
+ DB[("Ledger store")]
206
+ ORACLE["Public price marks"]
207
+ HEALTH["Health evaluation"]
208
+ WATCH["Watchdog heartbeat"]
209
+ PLANNER["Restore planner"]
210
+ API --> DB
211
+ API --> HEALTH
212
+ API --> WATCH
213
+ ORACLE --> HEALTH
214
+ WATCH --> PLANNER
215
+ end
216
+
217
+ subgraph EVM["ROBINHOOD CHAIN L2"]
218
+ direction TB
219
+ VAULT["AUREON Smart Vault"]
220
+ KEEPER["Keeper rebalance adapter"]
221
+ KEEPER --> VAULT
222
+ end
223
+
224
+ SDK -->|"1 HTTPS · API key · JWT"| API
225
+ API -->|"2 health / plans / steps"| SDK
226
+ SIGNER -->|"3 sign + broadcast"| VAULT
227
+ WATCH -->|"4 violation → plan"| PLANNER
228
+ PLANNER -->|"5 vault_swap path"| KEEPER
229
+
230
+ style CLIENT fill:#f9faf3,stroke:#0b0e0d,color:#0b0e0d
231
+ style CLOUD fill:#f9faf3,stroke:#a8e00d,color:#0b0e0d
232
+ style EVM fill:#f9faf3,stroke:#0b0e0d,color:#0b0e0d
233
+ ```
234
+
235
+ ### Architecture at a glance
236
+
237
+ | Layer | Components | Trust boundary |
238
+ | --- | --- | --- |
239
+ | **Client** | Host app, `@buildaureon/sdk`, session provider, local signer | Keys and broadcast stay here |
240
+ | **Hosted** | API, ledger, oracles, health, watchdog, planner | Policy, pricing, coordination — no private keys |
241
+ | **Chain** | Smart Vault, keeper path | Settlement when `settlement: "vault"` |
242
+
243
+ Deep dive: [docs/architecture.md](docs/architecture.md) · [docs/security.md](docs/security.md) · [docs/integration-guide.md](docs/integration-guide.md)
244
+
245
+ ---
246
+
247
+ ## End-to-end flows
248
+
249
+ ### Client–API trust boundary
250
+
251
+ To protect user funds, AUREON splits responsibility. The hosted API monitors capital, marks prices, evaluates objectives, and coordinates restore plans. The host application alone stores keys and signs transactions. The SDK sits on that boundary: it validates inputs, transports requests, prepares unsigned vault calldata, and never asks for a private key.
252
+
253
+ | Layer | Responsibility |
254
+ | --- | --- |
255
+ | **SDK** | Transport, validation, retries, EIP-712 helpers, vault step construction |
256
+ | **AUREON API** | Ledger sync, objective logic, price marks, timeline, staged or vault restore coordination |
257
+ | **Host application** | Key storage, wallet UX, signing, broadcasting |
258
+
259
+ ### Session authentication flow
260
+
261
+ Authentication is a challenge–response handshake that binds a wallet address to a temporary JWT.
262
+
263
+ ```mermaid
264
+ sequenceDiagram
265
+ autonumber
266
+ participant App as Client Operator
267
+ participant SDK as SDK Client
268
+ participant API as AUREON API Gateway
269
+
270
+ App->>SDK: aureon.getAuthNonce(address)
271
+ SDK->>API: GET /auth/nonce?address=0x...
272
+ API-->>SDK: { message, nonce, expiresAt }
273
+ SDK-->>App: { message, nonce }
274
+ Note over App: Operator signs message<br/>using private key
275
+ App->>SDK: aureon.verifyWallet({ address, message, signature })
276
+ SDK->>API: POST /auth/verify { address, message, signature }
277
+ API->>API: Verify EIP-191 Signature
278
+ API-->>SDK: { token, expiresAt, sessionId }
279
+ SDK-->>App: Return JWT Token
280
+ ```
281
+
282
+ ### Watchdog and restore flow
283
+
284
+ When portfolio weights drift past tolerance, health flips to violation and a restore plan becomes available.
285
+
286
+ ```mermaid
287
+ sequenceDiagram
288
+ autonumber
289
+ participant Client as Client Application
290
+ participant API as AUREON API Gateway
291
+ participant DB as Ledger Store
292
+ participant Engine as Health Engine
293
+ participant Keeper as Keeper Service
294
+
295
+ Client->>API: aureon.refreshWatchdog()
296
+ API->>DB: Pull price marks and positions
297
+ API->>Engine: Recompute objective deviations
298
+ alt Drift exceeds tolerance
299
+ Engine->>DB: Write health state: violation
300
+ Engine->>DB: Write event: violation_detected
301
+ Engine->>Keeper: Request restoration plan
302
+ Keeper-->>API: Return plan (e.g. vault_swap)
303
+ else Within bands
304
+ Engine->>DB: Write health state: healthy
305
+ end
306
+ API-->>Client: Watchdog status and breach reports
307
+ ```
308
+
309
+ Typical operator loop in prose:
310
+
311
+ 1. **Define capital** — sync the Capital Book from chain or seed an explicit book for rehearsal.
312
+ 2. **Register policy** — create a Financial Compass objective with target weight and tolerance.
313
+ 3. **Observe** — poll health and timeline; refresh the watchdog after market moves.
314
+ 4. **Restore** — fetch the plan, execute restore, read `settlement` on the receipt.
315
+ 5. **Verify** — confirm health returns to healthy and the timeline shows the restore event.
316
+
317
+ ---
318
+
319
+ ## Requirements & installation
320
+
321
+ ### Requirements
322
+
323
+ - **Node.js** 20 or higher (ESM).
324
+ - **Viem** 2.x when you sign and broadcast vault steps.
325
+
326
+ ### Installation
327
+
328
+ ```bash
329
+ pnpm add @buildaureon/sdk
330
+ # or
331
+ npm install @buildaureon/sdk
332
+ # or
333
+ yarn add @buildaureon/sdk
334
+ ```
335
+
336
+ ---
337
+
338
+ ## Quick start
339
+
340
+ Initialize the client with an **issued** developer API key (Developers page in the utility).
341
+ That key identifies your wallet for control-plane calls — sync, objectives, health, restore plans.
342
+ A private key is only needed later to **broadcast** on-chain deposit/withdraw txs.
343
+
344
+ **SDK supports Automatic objectives only** (`automationMode: "auto"`, the default). Manual Approve workflows stay in the operator utility.
345
+
346
+ ```ts
347
+ import { createAureonClient } from "@buildaureon/sdk";
348
+
349
+ async function run() {
350
+ const aureon = createAureonClient({
351
+ apiKey: process.env.AUREON_API_KEY!, // issued key from Developers console
352
+ });
353
+ // Default: official API https://api.aureonlabs.network (testnet 46630).
354
+ // Chain 4663: createAureonClient({ network: "mainnet", apiKey })
355
+
356
+ const me = await aureon.me();
357
+ console.log("wallet", me.walletAddress);
358
+
359
+ const synced = await aureon.syncPortfolio();
360
+ console.log("Portfolio Value USD:", synced.portfolio.totalNotionalUsd);
361
+ }
362
+ ```
363
+
364
+ Optional wallet Bearer (nonce sign `verifyWallet`) still works and **wins** when both
365
+ are sent. Env bootstrap keys (`AUREON_API_KEYS` on the server) unlock product access only —
366
+ they do not identify a wallet; use an issued key or a Bearer session with those.
367
+
368
+ From here, create an objective, read health, and restore when the watchdog reports a violation.
369
+ Full walkthroughs live in [docs/integration-guide.md](docs/integration-guide.md).
370
+
371
+ ---
372
+
373
+ ## Detailed authentication guide
374
+
375
+ ### Issued API keys (recommended for SDK / agents)
376
+
377
+ Create a key in the operator utility **Developers** console. The plaintext secret is shown once.
378
+ Send it as `X-Aureon-Api-Key`. The gateway resolves the bound wallet and scopes ledger operations
379
+ to that address. Treat issued keys like passwords: pause, revoke, rotate; never commit them.
380
+
381
+ ### Private key / on-chain signing
382
+
383
+ `prepareVaultDeposit` / `prepareVaultWithdraw` return **unsigned** calldata. Broadcasting those
384
+ transactions (and any other signed chain steps) requires the wallet private key or a browser
385
+ wallet — not the API key.
386
+
387
+ ### Wallet bearer handshake (optional)
388
+
389
+ Bearer sessions also scope ledger operations to a wallet. The SDK fetches a nonce message, the
390
+ host signs it with an EVM signer, and `/auth/verify` returns a session token for `getAccessToken`.
391
+ Use this for the browser utility, or when you only have an env bootstrap key (no issued key).
392
+
393
+ ### Token provider lifecycle
394
+
395
+ ```ts
396
+ import { createSessionTokenProvider } from "@buildaureon/sdk";
397
+
398
+ const session = createSessionTokenProvider(process.env.AUREON_TOKEN ?? null);
399
+
400
+ await aureon.logout();
401
+ session.clear();
402
+ ```
403
+
404
+ `createSessionTokenProvider` is a small stateful container: set after verify, clear on logout,
405
+ inject via `getAccessToken` so the client stays free of global mutable auth state.
406
+
407
+ ---
408
+
409
+ ## API surface reference & code walkthroughs
410
+
411
+ ### Connection smoke tests
412
+
413
+ ```ts
414
+ const ping = await aureon.ping();
415
+ console.log(`Connected. Backend version: ${ping.version}`);
416
+ ```
417
+
418
+ ### Managing the Capital Book
419
+
420
+ The Capital Book is the set of positions AUREON tracks for weight and health math. Sync from Robinhood Chain and vaults, or set an explicit book for controlled rehearsal environments.
421
+
422
+ ```ts
423
+ const syncResult = await aureon.syncPortfolio();
424
+ console.log("Current stable coin weight:", syncResult.portfolio.stableWeight);
425
+
426
+ const updatedBook = await aureon.setPortfolio([
427
+ { symbol: "WETH", quantity: 2.5, category: "gas" },
428
+ { symbol: "USDG", quantity: 2500, category: "stable" },
429
+ ]);
430
+
431
+ await aureon.clearPortfolio();
432
+ ```
433
+
434
+ ### Defining and querying objectives
435
+
436
+ Objectives are the Financial Compass primitives: target weights, tolerance bands, and priority. SDK-created objectives participate in automatic restore coordination when health enters violation.
437
+
438
+ ```ts
439
+ const stableObj = await aureon.createObjective({
440
+ name: "Stable Core Reserve",
441
+ kind: "stable_allocation",
442
+ targetWeight: 0.3,
443
+ tolerance: 0.03,
444
+ priority: "high",
445
+ });
446
+
447
+ const stockObj = await aureon.createObjective({
448
+ name: "Tesla Sleeve Allocation",
449
+ kind: "balanced_portfolio",
450
+ targetSymbol: "TSLA",
451
+ targetWeight: 0.2,
452
+ tolerance: 0.05,
453
+ });
454
+
455
+ const objectives = await aureon.listObjectives();
456
+ ```
457
+
458
+ ### Health, timeline, and overview
459
+
460
+ ```ts
461
+ const healthRecords = await aureon.getHealth();
462
+ for (const health of healthRecords) {
463
+ console.log(`Objective ${health.objectiveId}: State: ${health.state}`);
464
+ }
465
+
466
+ const timeline = await aureon.getTimeline();
467
+ timeline.forEach((event) => console.log(`[${event.type}]: ${event.message}`));
468
+
469
+ const overview = await aureon.getOverview();
470
+ console.log("Global health score:", overview.globalHealthScore);
471
+ ```
472
+
473
+ ### Non-custodial vault operations
474
+
475
+ Vault helpers prepare unsigned steps. The host signs and broadcasts; AUREON never receives the private key.
476
+
477
+ ```ts
478
+ import type { Hex } from "viem";
479
+
480
+ const depositData = await aureon.prepareVaultDeposit({
481
+ symbol: "ETH",
482
+ amount: "0.5",
483
+ });
484
+
485
+ for (const step of depositData.steps) {
486
+ const hash = await walletClient.sendTransaction({
487
+ account,
488
+ to: step.to as `0x${string}`,
489
+ data: step.data as Hex,
490
+ value: BigInt(step.value),
491
+ });
492
+ await publicClient.waitForTransactionReceipt({ hash });
493
+ }
494
+ ```
495
+
496
+ ### Restore plans and rebalances
497
+
498
+ When health is in violation, fetch the plan and execute. Always read `settlement` on the receipt. On **first use** the vault is empty: `restoreObjective` returns HTTP **409**. Call `prepareVaultDeposit`, return the unsigned steps, and wait for the user or host wallet to broadcast. Do not fund the vault from an agent or script. After a deposit, Automatic restore can settle on-chain; `verifiedOnChain` is true only after a vault rebalance for that wallet.
499
+
500
+ ```ts
501
+ const plan = await aureon.getRestorePlan(objective.id);
502
+ console.log(`Plan requires action: ${plan.kind} for ${plan.amountHuman} tokens.`);
503
+
504
+ if (plan.kind === "vault_swap") {
505
+ const receipt = await aureon.restoreObjective(objective.id);
506
+ console.log("Rebalance transaction hash:", receipt.transactionHash);
507
+ console.log("Settlement environment:", receipt.settlement); // "vault" | "staged"
508
+ } else {
509
+ console.warn("Execute wrap_eth or unwrap_weth with your wallet provider.");
510
+ }
511
+ ```
512
+
513
+ ### Controlled market events
514
+
515
+ Apply a deterministic price mark change to rehearse breach and restore paths in integration environments. This is a controlled market event against the ledger marks — not a claim of live exchange execution.
516
+
517
+ ```ts
518
+ const shockResult = await aureon.applyMarketEvent({
519
+ symbol: "NVDA",
520
+ priceChangeRatio: -0.15,
521
+ autoRestore: true,
522
+ });
523
+ ```
524
+
525
+ ### Developer API key management
526
+
527
+ ```ts
528
+ const newKey = await aureon.createApiKey("Secondary Bot Ingress");
529
+ console.log(`Plaintext secret: ${newKey.secret}`);
530
+
531
+ const keys = await aureon.listApiKeys();
532
+ await aureon.toggleApiKey(newKey.id);
533
+ await aureon.revokeApiKey(newKey.id);
534
+ ```
535
+
536
+ ---
537
+
538
+ ## Client configuration & transport engine
539
+
540
+ ### Configuration reference
541
+
542
+ | Parameter | Type | Default | Description |
543
+ | --- | --- | --- | --- |
544
+ | `network` | `"mainnet" \| "testnet"` | `"testnet"` | Chain selector on the official API. Omit for 46630. Pass `"mainnet"` for 4663. |
545
+ | `baseUrl` | `string` | `https://api.aureonlabs.network` | Leave unset. Override only if you must point at another host. |
546
+ | `apiKey` | `string` | `undefined` | Sent as `X-Aureon-Api-Key` |
547
+ | `authToken` | `string` | `undefined` | Static JWT bearer |
548
+ | `getAccessToken` | `() => string \| null` | `undefined` | Dynamic bearer resolver |
549
+ | `timeoutMs` | `number` | `30000` | Per-call abort threshold |
550
+ | `maxRetries` | `number` | `0` | Transient failure retries |
551
+ | `retryDelayMs` | `number` | `250` | Delay between retries |
552
+ | `headers` | `Record<string, string>` | `{}` | Extra headers |
553
+ | `fetch` | `typeof fetch` | `globalThis.fetch` | Custom fetch override |
554
+
555
+ ### Retries and failover
556
+
557
+ When `maxRetries` is greater than zero, the client retries timeouts and selected transient HTTP failures with a fixed `retryDelayMs`. Prefer raising retries for long-running agent loops; keep them low for interactive UI paths where fail-fast is better.
558
+
559
+ ---
560
+
561
+ ## Error model and code handling
562
+
563
+ ### Error code reference
564
+
565
+ | Code | HTTP | Description |
566
+ | --- | --- | --- |
567
+ | `UNAUTHORIZED` | 401 | Missing or invalid API key or bearer |
568
+ | `VALIDATION_ERROR` | 400 | Payload failed validation |
569
+ | `NOT_FOUND` | 404 | Objective, key, or resource missing |
570
+ | `CONFLICT` | 409 | Request conflicts with current ledger state |
571
+ | `RATE_LIMITED` | 429 | Request volume exceeded |
572
+ | `SERVER_ERROR` | 500 / 503 | Hosted execution failure |
573
+ | `TIMEOUT` | | Exceeded `timeoutMs` |
574
+ | `NETWORK_ERROR` | — | Endpoint unreachable |
575
+
576
+ ### Narrowing errors in practice
577
+
578
+ ```ts
579
+ import { isAureonError } from "@buildaureon/sdk";
580
+
581
+ try {
582
+ await aureon.getObjective("missing_id");
583
+ } catch (error) {
584
+ if (isAureonError(error)) {
585
+ switch (error.code) {
586
+ case "NOT_FOUND":
587
+ console.error("The specified objective does not exist.");
588
+ break;
589
+ case "UNAUTHORIZED":
590
+ console.error("Check API key and wallet session configuration.");
591
+ break;
592
+ default:
593
+ console.error(`Aureon error: ${error.message}`);
594
+ }
595
+ } else {
596
+ console.error("Generic execution failure:", error);
597
+ }
598
+ }
599
+ ```
600
+
601
+ Full matrix: [docs/error-model.md](docs/error-model.md).
602
+
603
+ ---
604
+
605
+ ## CLI command-line guide
606
+
607
+ The package ships a developer CLI. Configure credentials via environment variables:
608
+
609
+ ```bash
610
+ # Issued developer key (recommended) — identifies wallet;
611
+ export AUREON_API_KEY=aureon_....
612
+
613
+ pnpm --filter @buildaureon/sdk cli ping
614
+ pnpm --filter @buildaureon/sdk cli me
615
+ pnpm --filter @buildaureon/sdk cli sync
616
+ pnpm --filter @buildaureon/sdk cli portfolio
617
+ pnpm --filter @buildaureon/sdk cli objectives
618
+ ```
619
+
620
+ ### Runnable examples (live API)
621
+
622
+ Requires `AUREON_API_KEY`:
623
+
624
+ ```bash
625
+ pnpm example:ai-to-objective-to-portfolio
626
+ pnpm example:drift-detect-restore
627
+ pnpm example:receipt-verification
628
+ pnpm example:portfolio-watch
629
+ pnpm example:full-aureon-loop
630
+ pnpm example:green-vs-plan
631
+ ```
632
+
633
+ ---
634
+
635
+ ## Design principles & settlement honesty
636
+
637
+ 1. **Non-custodial by construction.** Private keys never leave the client. The API verifies signatures and returns unsigned steps; it does not sign for you.
638
+ 2. **Settlement transparency.** Every execution receipt includes `settlement`: `"vault"` means Robinhood Chain settlement; `"staged"` means ledger-local and must be labeled clearly in any user-facing surface.
639
+ 3. **Seeded capital, not invented capital.** Positions come from chain sync or explicit operator input. The SDK does not invent balances to make demos look healthy.
640
+ 4. **Objectives as primitives.** Health, timeline, and restores hang off Financial Compass objectives so agents can reason about policy, not only about the last transaction hash.
641
+
642
+ ---
643
+
644
+ ## Documentation registry
645
+
646
+ Long-form technical docs live under `docs/`:
647
+
648
+ | Document | Focus |
649
+ | --- | --- |
650
+ | [docs/architecture.md](docs/architecture.md) | Client vs API boundary, system maps |
651
+ | [docs/auth.md](docs/auth.md) | Wallet handshake and JWT lifecycle |
652
+ | [docs/client-api.md](docs/client-api.md) | Method and parameter index |
653
+ | [docs/data-contracts.md](docs/data-contracts.md) | Types aligned to hosted JSON |
654
+ | [docs/error-model.md](docs/error-model.md) | Full error code mapping |
655
+ | [docs/integration-guide.md](docs/integration-guide.md) | End-to-end integrator walkthrough |
656
+ | [docs/security.md](docs/security.md) | API key and token guidance |
657
+ | [docs/transport.md](docs/transport.md) | Retries, headers, transport edge cases |
658
+ | [CHANGELOG.md](CHANGELOG.md) | Published versions, including 0.1.9 official API and network header |
659
+
660
+ ---
661
+
662
+ ## Community & resources
663
+
664
+ - **Website:** [aureonlabs.network](https://www.aureonlabs.network/)
665
+ - **Operator utility:** [app.aureonlabs.network](https://app.aureonlabs.network)
666
+ - **X:** [@buildaureon](https://x.com/buildaureon)
667
+ - **GitHub:** [github.com/buildaureon](https://github.com/buildaureon)
668
+
669
+ ---
670
+
671
+ ## License
672
+
673
+ MIT — see [LICENSE](LICENSE).