@buildaureon/sdk 0.1.1 → 0.1.2

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/docs/security.md CHANGED
@@ -1,120 +1,120 @@
1
- # Security Model and Practices
2
-
3
- Security architecture for `@buildaureon/sdk`: trust boundaries, credentials, vault signing, and production checklist.
4
-
5
- **Automation note:** SDK agents should run **Automatic** objectives only. Manual Approve flows are utility concerns, not SDK security surface.
6
-
7
- ---
8
-
9
- ## 1. Gateway trust boundaries
10
-
11
- AUREON is non-custodial. The API is a policy engine, price indexer, and coordinator. It does not hold private keys and does not broadcast owner withdrawals for you.
12
-
13
- ```mermaid
14
- flowchart TD
15
- Host[Host_application] -->|1_request_calldata| Gateway[Aureon_API]
16
- Gateway -->|2_unsigned_steps| Host
17
- Host -->|3_sign_locally| Wallet[Private_key_or_KMS]
18
- Wallet -->|4_broadcast| Chain[Robinhood_Chain_RPC]
19
-
20
- subgraph OnChain [Smart_contract_controls]
21
- Vault[Smart_Vault]
22
- DX[Allowlisted_DEX_routes]
23
- Vault -->|keeper_swaps_only| DX
24
- end
25
- Wallet -.->|owner_deposit_withdraw| Vault
26
- ```
27
-
28
- ### 1.1 Private key isolation
29
-
30
- The SDK never loads, stores, or transmits private keys or mnemonics. Signing stays in the host (viem, ethers, HSM, KMS). A gateway breach cannot drain vaults by itself.
31
-
32
- ### 1.2 Issued API keys are wallet credentials
33
-
34
- An **issued** developer key identifies the bound wallet for control-plane operations (sync, objectives, health, restore, prepare). Treat it like a password:
35
-
36
- - Create in utility **Developers**
37
- - Store in env / secret manager
38
- - Pause or revoke on leak
39
- - Prefer one key per agent host
40
-
41
- Env bootstrap keys on the server unlock product access only. They do **not** identify a wallet and must not be used as agent identity.
42
-
43
- ### 1.3 Unsigned calldata
44
-
45
- `prepareVaultDeposit` / `prepareVaultWithdraw` return structured steps. Decode against published ABIs before signing. Broadcast is always host-side.
46
-
47
- ---
48
-
49
- ## 2. What a compromised API key can and cannot do
50
-
51
- | Can | Cannot |
52
- | --- | --- |
53
- | Read portfolio, vault, health, timeline | Sign owner deposit/withdraw txs |
54
- | Create / update / pause Auto objectives | Withdraw vault funds to arbitrary addresses |
55
- | Request restore plans and trigger Automatic restore coordination | Bypass vault keeper allowlists |
56
- | Create additional developer keys under the same wallet | Recover a private key |
57
-
58
- Keeper-driven Automatic restores execute allowlisted vault swaps. Keepers cannot send vault assets to arbitrary third parties.
59
-
60
- ---
61
-
62
- ## 3. Smart vault access control
63
-
64
- - **Owner path:** deposits and withdrawals require owner-signed txs from prepare steps.
65
- - **Keeper path:** Automatic restores use registered keepers on allowlisted routes only.
66
- - **Slippage / limits:** vault and planner enforce execution bounds to reduce bad fills.
67
-
68
- ---
69
-
70
- ## 4. Settlement honesty
71
-
72
- Every execution receipt includes `settlement`:
73
-
74
- | Value | Meaning | UI rule |
75
- | --- | --- | --- |
76
- | `vault` | On-chain vault / keeper settlement with verifiable hash | May show as on-chain |
77
- | `staged` | Ledger-local / rehearsal — not a chain settlement | Must **not** be labeled as on-chain |
78
-
79
- Never collapse staged into “confirmed on Robinhood Chain.”
80
-
81
- ---
82
-
83
- ## 5. Transport and logging hygiene
84
-
85
- - Prefer HTTPS production base URL `https://api.aureonlabs.network`.
86
- - Do not log raw `Authorization` or `X-Aureon-Api-Key`.
87
- - Redact prepare step calldata in public logs if it includes sensitive amounts in your threat model.
88
- - Set `timeoutMs` / `maxRetries` deliberately for agent loops (see [transport.md](./transport.md)).
89
-
90
- ---
91
-
92
- ## 6. Frontend vs agent hosts
93
-
94
- | Host | Guidance |
95
- | --- | --- |
96
- | Server agent / cron | Issued API key in secret store; private key in KMS if broadcasting deposits |
97
- | Browser SPA | Do **not** embed issued API keys in public bundles; proxy through your backend |
98
- | Operator utility | Wallet Bearer only — separate from SDK agent auth |
99
-
100
- ---
101
-
102
- ## 7. Production checklist
103
-
104
- - [ ] Issued developer key (not a shared env bootstrap key) in secrets
105
- - [ ] Private keys isolated from the API key and never logged
106
- - [ ] Deposit/withdraw broadcast path reviewed and ABI-checked
107
- - [ ] Automatic objectives only in SDK loops
108
- - [ ] UI / agent summaries honor `settlement: vault | staged`
109
- - [ ] Gas reserve on the signing wallet for owner txs
110
- - [ ] Key rotation plan (pause/revoke in Developers)
111
- - [ ] Error handling branches on `error.code` (see [error-model.md](./error-model.md))
112
-
113
- ---
114
-
115
- ## 8. Related docs
116
-
117
- - [Auth](./auth.md)
118
- - [Architecture](./architecture.md)
119
- - [Integration guide](./integration-guide.md)
120
- - [Error model](./error-model.md)
1
+ # Security Model and Practices
2
+
3
+ Security architecture for `@buildaureon/sdk`: trust boundaries, credentials, vault signing, and production checklist.
4
+
5
+ **Automation note:** SDK agents should run **Automatic** objectives only. Manual Approve flows are utility concerns, not SDK security surface.
6
+
7
+ ---
8
+
9
+ ## 1. Gateway trust boundaries
10
+
11
+ AUREON is non-custodial. The API is a policy engine, price indexer, and coordinator. It does not hold private keys and does not broadcast owner withdrawals for you.
12
+
13
+ ```mermaid
14
+ flowchart TD
15
+ Host[Host_application] -->|1_request_calldata| Gateway[Aureon_API]
16
+ Gateway -->|2_unsigned_steps| Host
17
+ Host -->|3_sign_locally| Wallet[Private_key_or_KMS]
18
+ Wallet -->|4_broadcast| Chain[Robinhood_Chain_RPC]
19
+
20
+ subgraph OnChain [Smart_contract_controls]
21
+ Vault[Smart_Vault]
22
+ DX[Allowlisted_DEX_routes]
23
+ Vault -->|keeper_swaps_only| DX
24
+ end
25
+ Wallet -.->|owner_deposit_withdraw| Vault
26
+ ```
27
+
28
+ ### 1.1 Private key isolation
29
+
30
+ The SDK never loads, stores, or transmits private keys or mnemonics. Signing stays in the host (viem, ethers, HSM, KMS). A gateway breach cannot drain vaults by itself.
31
+
32
+ ### 1.2 Issued API keys are wallet credentials
33
+
34
+ An **issued** developer key identifies the bound wallet for control-plane operations (sync, objectives, health, restore, prepare). Treat it like a password:
35
+
36
+ - Create in utility **Developers**
37
+ - Store in env / secret manager
38
+ - Pause or revoke on leak
39
+ - Prefer one key per agent host
40
+
41
+ Env bootstrap keys on the server unlock product access only. They do **not** identify a wallet and must not be used as agent identity.
42
+
43
+ ### 1.3 Unsigned calldata
44
+
45
+ `prepareVaultDeposit` / `prepareVaultWithdraw` return structured steps. Decode against published ABIs before signing. Broadcast is always host-side.
46
+
47
+ ---
48
+
49
+ ## 2. What a compromised API key can and cannot do
50
+
51
+ | Can | Cannot |
52
+ | --- | --- |
53
+ | Read portfolio, vault, health, timeline | Sign owner deposit/withdraw txs |
54
+ | Create / update / pause Auto objectives | Withdraw vault funds to arbitrary addresses |
55
+ | Request restore plans and trigger Automatic restore coordination | Bypass vault keeper allowlists |
56
+ | Create additional developer keys under the same wallet | Recover a private key |
57
+
58
+ Keeper-driven Automatic restores execute allowlisted vault swaps. Keepers cannot send vault assets to arbitrary third parties.
59
+
60
+ ---
61
+
62
+ ## 3. Smart vault access control
63
+
64
+ - **Owner path:** deposits and withdrawals require owner-signed txs from prepare steps.
65
+ - **Keeper path:** Automatic restores use registered keepers on allowlisted routes only.
66
+ - **Slippage / limits:** vault and planner enforce execution bounds to reduce bad fills.
67
+
68
+ ---
69
+
70
+ ## 4. Settlement honesty
71
+
72
+ Every execution receipt includes `settlement`:
73
+
74
+ | Value | Meaning | UI rule |
75
+ | --- | --- | --- |
76
+ | `vault` | On-chain vault / keeper settlement with verifiable hash | May show as on-chain |
77
+ | `staged` | Ledger-local / rehearsal — not a chain settlement | Must **not** be labeled as on-chain |
78
+
79
+ Never collapse staged into “confirmed on Robinhood Chain.”
80
+
81
+ ---
82
+
83
+ ## 5. Transport and logging hygiene
84
+
85
+ - Prefer HTTPS production base URL `https://api.aureonlabs.network`.
86
+ - Do not log raw `Authorization` or `X-Aureon-Api-Key`.
87
+ - Redact prepare step calldata in public logs if it includes sensitive amounts in your threat model.
88
+ - Set `timeoutMs` / `maxRetries` deliberately for agent loops (see [transport.md](./transport.md)).
89
+
90
+ ---
91
+
92
+ ## 6. Frontend vs agent hosts
93
+
94
+ | Host | Guidance |
95
+ | --- | --- |
96
+ | Server agent / cron | Issued API key in secret store; private key in KMS if broadcasting deposits |
97
+ | Browser SPA | Do **not** embed issued API keys in public bundles; proxy through your backend |
98
+ | Operator utility | Wallet Bearer only — separate from SDK agent auth |
99
+
100
+ ---
101
+
102
+ ## 7. Production checklist
103
+
104
+ - [ ] Issued developer key (not a shared env bootstrap key) in secrets
105
+ - [ ] Private keys isolated from the API key and never logged
106
+ - [ ] Deposit/withdraw broadcast path reviewed and ABI-checked
107
+ - [ ] Automatic objectives only in SDK loops
108
+ - [ ] UI / agent summaries honor `settlement: vault | staged`
109
+ - [ ] Gas reserve on the signing wallet for owner txs
110
+ - [ ] Key rotation plan (pause/revoke in Developers)
111
+ - [ ] Error handling branches on `error.code` (see [error-model.md](./error-model.md))
112
+
113
+ ---
114
+
115
+ ## 8. Related docs
116
+
117
+ - [Auth](./auth.md)
118
+ - [Architecture](./architecture.md)
119
+ - [Integration guide](./integration-guide.md)
120
+ - [Error model](./error-model.md)
package/docs/transport.md CHANGED
@@ -1,142 +1,142 @@
1
- # Transport Layer Reference
2
-
3
- HTTP transport for `@buildaureon/sdk` (`src/transport/http.ts`): headers, timeouts, retries, URL helpers, and logging.
4
-
5
- ---
6
-
7
- ## 1. Request lifecycle
8
-
9
- ```mermaid
10
- flowchart TD
11
- Call[Client_method] --> Prep[Join_URL_and_headers]
12
- Prep --> Auth[Resolve_API_key_and_Bearer]
13
- Auth --> Abort[AbortController_timeout]
14
- Abort --> Fetch[fetch_implementation]
15
- Fetch --> Ok{HTTP_OK?}
16
- Ok -->|Yes| Parse[Parse_JSON]
17
- Ok -->|No| Map[Map_to_AureonError]
18
- Map --> Retry{Retryable_and_budget?}
19
- Retry -->|Yes| Sleep[retryDelayMs]
20
- Sleep --> Fetch
21
- Retry -->|No| Throw[Throw]
22
- ```
23
-
24
- 1. Join `baseUrl` + path; attach query string when needed.
25
- 2. Resolve `X-Aureon-Api-Key` from `apiKey` / `getApiKey`.
26
- 3. Resolve `Authorization: Bearer …` from `getAccessToken` / `authToken` (optional).
27
- 4. Apply timeout via `AbortController` (default 30s).
28
- 5. On failure, map status → typed error; retry only if configured and retryable.
29
-
30
- ---
31
-
32
- ## 2. Headers
33
-
34
- | Header | When | Purpose |
35
- | --- | --- | --- |
36
- | `Accept` | Always | `application/json` |
37
- | `Content-Type` | Body present | `application/json` |
38
- | `X-Aureon-SDK` | Always | Package identity / version |
39
- | `X-Aureon-Api-Key` | Key configured | Product access + issued-key identity |
40
- | `Authorization` | Token configured | Optional Bearer session |
41
- | Custom `headers` | If set on client | Merged into every request |
42
-
43
- Issued developer keys in `X-Aureon-Api-Key` are enough for control-plane identity on the live API. Bearer is optional and wins when both are present.
44
-
45
- ---
46
-
47
- ## 3. Client transport options
48
-
49
- ```ts
50
- createAureonClient({
51
- baseUrl: "https://api.aureonlabs.network",
52
- apiKey: process.env.AUREON_API_KEY!,
53
- timeoutMs: 30_000, // per attempt
54
- maxRetries: 2, // extra attempts after first failure
55
- retryDelayMs: 500, // fixed delay between attempts
56
- fetch: customFetch, // optional
57
- headers: { "X-Debug": "1" },
58
- logger: myLogger,
59
- });
60
- ```
61
-
62
- | Option | Default | Notes |
63
- | --- | --- | --- |
64
- | `timeoutMs` | `30000` | Must be positive finite |
65
- | `maxRetries` | `0` | Extra tries after the first failure |
66
- | `retryDelayMs` | `250` | Fixed sleep between tries |
67
- | `fetch` | `globalThis.fetch` | Inject for tests / unusual runtimes |
68
-
69
- ---
70
-
71
- ## 4. Retry policy
72
-
73
- **Retryable:** network failures, timeouts, HTTP 429, HTTP 5xx (when mapped as retryable).
74
-
75
- **Not retryable:** 400 validation, 401/403 auth, 404, most 409 conflicts (operator must change state).
76
-
77
- Total attempts = `1 + maxRetries`.
78
-
79
- ---
80
-
81
- ## 5. URL helpers
82
-
83
- ### `joinUrl`
84
-
85
- Prevents double slashes when combining base + path.
86
-
87
- ### `withQuery`
88
-
89
- Serializes defined query params with `encodeURIComponent`. Omits `null` / `undefined`.
90
-
91
- ---
92
-
93
- ## 6. Timeouts and aborts
94
-
95
- ```ts
96
- const controller = new AbortController();
97
- const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
98
- try {
99
- return await fetchImpl(url, { ...init, signal: controller.signal });
100
- } catch (error) {
101
- if (error instanceof Error && error.name === "AbortError") {
102
- throw /* AureonTimeoutError */;
103
- }
104
- throw /* AureonNetworkError */;
105
- } finally {
106
- clearTimeout(timeoutId);
107
- }
108
- ```
109
-
110
- For agent loops that call restore + sync, prefer slightly higher `timeoutMs` under load rather than disabling timeouts.
111
-
112
- ---
113
-
114
- ## 7. Logger interface
115
-
116
- ```ts
117
- interface AureonLogger {
118
- debug(message: string, context?: Record<string, unknown>): void;
119
- info(message: string, context?: Record<string, unknown>): void;
120
- warn(message: string, context?: Record<string, unknown>): void;
121
- error(message: string, context?: Record<string, unknown>): void;
122
- }
123
- ```
124
-
125
- Helpers may include console / silent adapters depending on package exports. Never log secrets from context.
126
-
127
- ---
128
-
129
- ## 8. Testing transport
130
-
131
- - Inject a fake `fetch` that returns controlled status/body.
132
- - Assert header presence of `X-Aureon-Api-Key` for SDK clients.
133
- - Assert retries by counting fetch invocations with `maxRetries > 0` and 503 responses.
134
-
135
- ---
136
-
137
- ## 9. Related docs
138
-
139
- - [Error model](./error-model.md)
140
- - [Auth](./auth.md)
141
- - [Client API](./client-api.md)
142
- - [Security](./security.md)
1
+ # Transport Layer Reference
2
+
3
+ HTTP transport for `@buildaureon/sdk` (`src/transport/http.ts`): headers, timeouts, retries, URL helpers, and logging.
4
+
5
+ ---
6
+
7
+ ## 1. Request lifecycle
8
+
9
+ ```mermaid
10
+ flowchart TD
11
+ Call[Client_method] --> Prep[Join_URL_and_headers]
12
+ Prep --> Auth[Resolve_API_key_and_Bearer]
13
+ Auth --> Abort[AbortController_timeout]
14
+ Abort --> Fetch[fetch_implementation]
15
+ Fetch --> Ok{HTTP_OK?}
16
+ Ok -->|Yes| Parse[Parse_JSON]
17
+ Ok -->|No| Map[Map_to_AureonError]
18
+ Map --> Retry{Retryable_and_budget?}
19
+ Retry -->|Yes| Sleep[retryDelayMs]
20
+ Sleep --> Fetch
21
+ Retry -->|No| Throw[Throw]
22
+ ```
23
+
24
+ 1. Join `baseUrl` + path; attach query string when needed.
25
+ 2. Resolve `X-Aureon-Api-Key` from `apiKey` / `getApiKey`.
26
+ 3. Resolve `Authorization: Bearer …` from `getAccessToken` / `authToken` (optional).
27
+ 4. Apply timeout via `AbortController` (default 30s).
28
+ 5. On failure, map status → typed error; retry only if configured and retryable.
29
+
30
+ ---
31
+
32
+ ## 2. Headers
33
+
34
+ | Header | When | Purpose |
35
+ | --- | --- | --- |
36
+ | `Accept` | Always | `application/json` |
37
+ | `Content-Type` | Body present | `application/json` |
38
+ | `X-Aureon-SDK` | Always | Package identity / version |
39
+ | `X-Aureon-Api-Key` | Key configured | Product access + issued-key identity |
40
+ | `Authorization` | Token configured | Optional Bearer session |
41
+ | Custom `headers` | If set on client | Merged into every request |
42
+
43
+ Issued developer keys in `X-Aureon-Api-Key` are enough for control-plane identity on the live API. Bearer is optional and wins when both are present.
44
+
45
+ ---
46
+
47
+ ## 3. Client transport options
48
+
49
+ ```ts
50
+ createAureonClient({
51
+ baseUrl: "https://api.aureonlabs.network",
52
+ apiKey: process.env.AUREON_API_KEY!,
53
+ timeoutMs: 30_000, // per attempt
54
+ maxRetries: 2, // extra attempts after first failure
55
+ retryDelayMs: 500, // fixed delay between attempts
56
+ fetch: customFetch, // optional
57
+ headers: { "X-Debug": "1" },
58
+ logger: myLogger,
59
+ });
60
+ ```
61
+
62
+ | Option | Default | Notes |
63
+ | --- | --- | --- |
64
+ | `timeoutMs` | `30000` | Must be positive finite |
65
+ | `maxRetries` | `0` | Extra tries after the first failure |
66
+ | `retryDelayMs` | `250` | Fixed sleep between tries |
67
+ | `fetch` | `globalThis.fetch` | Inject for tests / unusual runtimes |
68
+
69
+ ---
70
+
71
+ ## 4. Retry policy
72
+
73
+ **Retryable:** network failures, timeouts, HTTP 429, HTTP 5xx (when mapped as retryable).
74
+
75
+ **Not retryable:** 400 validation, 401/403 auth, 404, most 409 conflicts (operator must change state).
76
+
77
+ Total attempts = `1 + maxRetries`.
78
+
79
+ ---
80
+
81
+ ## 5. URL helpers
82
+
83
+ ### `joinUrl`
84
+
85
+ Prevents double slashes when combining base + path.
86
+
87
+ ### `withQuery`
88
+
89
+ Serializes defined query params with `encodeURIComponent`. Omits `null` / `undefined`.
90
+
91
+ ---
92
+
93
+ ## 6. Timeouts and aborts
94
+
95
+ ```ts
96
+ const controller = new AbortController();
97
+ const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
98
+ try {
99
+ return await fetchImpl(url, { ...init, signal: controller.signal });
100
+ } catch (error) {
101
+ if (error instanceof Error && error.name === "AbortError") {
102
+ throw /* AureonTimeoutError */;
103
+ }
104
+ throw /* AureonNetworkError */;
105
+ } finally {
106
+ clearTimeout(timeoutId);
107
+ }
108
+ ```
109
+
110
+ For agent loops that call restore + sync, prefer slightly higher `timeoutMs` under load rather than disabling timeouts.
111
+
112
+ ---
113
+
114
+ ## 7. Logger interface
115
+
116
+ ```ts
117
+ interface AureonLogger {
118
+ debug(message: string, context?: Record<string, unknown>): void;
119
+ info(message: string, context?: Record<string, unknown>): void;
120
+ warn(message: string, context?: Record<string, unknown>): void;
121
+ error(message: string, context?: Record<string, unknown>): void;
122
+ }
123
+ ```
124
+
125
+ Helpers may include console / silent adapters depending on package exports. Never log secrets from context.
126
+
127
+ ---
128
+
129
+ ## 8. Testing transport
130
+
131
+ - Inject a fake `fetch` that returns controlled status/body.
132
+ - Assert header presence of `X-Aureon-Api-Key` for SDK clients.
133
+ - Assert retries by counting fetch invocations with `maxRetries > 0` and 503 responses.
134
+
135
+ ---
136
+
137
+ ## 9. Related docs
138
+
139
+ - [Error model](./error-model.md)
140
+ - [Auth](./auth.md)
141
+ - [Client API](./client-api.md)
142
+ - [Security](./security.md)
@@ -1,65 +1,65 @@
1
- /**
2
- * @fileoverview Controlled market-event rehearsal against the live AUREON API.
3
- *
4
- * Env:
5
- * AUREON_API_KEY issued developer key (required)
6
- * AUREON_API_URL optional (default https://api.aureonlabs.network)
7
- *
8
- * pnpm --filter @buildaureon/sdk example:market
9
- */
10
-
11
- import {
12
- createAureonClient,
13
- DEFAULT_API_BASE_URL,
14
- isAureonError,
15
- } from "../../src/index.js";
16
-
17
- async function main(): Promise<void> {
18
- const apiKey = process.env.AUREON_API_KEY?.trim();
19
- if (!apiKey) {
20
- throw new Error("Set AUREON_API_KEY to an issued developer key.");
21
- }
22
-
23
- const aureon = createAureonClient({
24
- baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
25
- apiKey,
26
- });
27
-
28
- const objective = await aureon.createObjective({
29
- name: "Maintain 20% Stable Assets",
30
- kind: "stable_allocation",
31
- targetWeight: 0.2,
32
- tolerance: 0.02,
33
- });
34
-
35
- const result = await aureon.applyMarketEvent({
36
- name: "NVDA Stock Token Rally",
37
- description: "Controlled mark appreciation on NVIDIA Stock Token",
38
- symbol: "NVDA",
39
- priceChangeRatio: 0.45,
40
- autoRestore: true,
41
- });
42
-
43
- console.log(
44
- JSON.stringify(
45
- {
46
- objectiveId: objective.id,
47
- eventId: result.event.id,
48
- executions: result.executions.length,
49
- settlement: result.executions[0]?.settlement ?? null,
50
- health: result.health.find((h) => h.objectiveId === objective.id)?.state,
51
- },
52
- null,
53
- 2
54
- )
55
- );
56
- }
57
-
58
- main().catch((error) => {
59
- if (isAureonError(error)) {
60
- console.error(`${error.code}: ${error.message}`);
61
- } else {
62
- console.error(error);
63
- }
64
- process.exitCode = 1;
65
- });
1
+ /**
2
+ * @fileoverview Controlled market-event rehearsal against the live AUREON API.
3
+ *
4
+ * Env:
5
+ * AUREON_API_KEY issued developer key (required)
6
+ * AUREON_API_URL optional (default https://api.aureonlabs.network)
7
+ *
8
+ * pnpm --filter @buildaureon/sdk example:market
9
+ */
10
+
11
+ import {
12
+ createAureonClient,
13
+ DEFAULT_API_BASE_URL,
14
+ isAureonError,
15
+ } from "../../src/index.js";
16
+
17
+ async function main(): Promise<void> {
18
+ const apiKey = process.env.AUREON_API_KEY?.trim();
19
+ if (!apiKey) {
20
+ throw new Error("Set AUREON_API_KEY to an issued developer key.");
21
+ }
22
+
23
+ const aureon = createAureonClient({
24
+ baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
25
+ apiKey,
26
+ });
27
+
28
+ const objective = await aureon.createObjective({
29
+ name: "Maintain 20% Stable Assets",
30
+ kind: "stable_allocation",
31
+ targetWeight: 0.2,
32
+ tolerance: 0.02,
33
+ });
34
+
35
+ const result = await aureon.applyMarketEvent({
36
+ name: "NVDA Stock Token Rally",
37
+ description: "Controlled mark appreciation on NVIDIA Stock Token",
38
+ symbol: "NVDA",
39
+ priceChangeRatio: 0.45,
40
+ autoRestore: true,
41
+ });
42
+
43
+ console.log(
44
+ JSON.stringify(
45
+ {
46
+ objectiveId: objective.id,
47
+ eventId: result.event.id,
48
+ executions: result.executions.length,
49
+ settlement: result.executions[0]?.settlement ?? null,
50
+ health: result.health.find((h) => h.objectiveId === objective.id)?.state,
51
+ },
52
+ null,
53
+ 2
54
+ )
55
+ );
56
+ }
57
+
58
+ main().catch((error) => {
59
+ if (isAureonError(error)) {
60
+ console.error(`${error.code}: ${error.message}`);
61
+ } else {
62
+ console.error(error);
63
+ }
64
+ process.exitCode = 1;
65
+ });