@buildaureon/sdk 0.1.1 → 0.1.7

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.
@@ -0,0 +1,127 @@
1
+ /**
2
+ * @fileoverview Update 3 demo — AI → objective → portfolio.
3
+ *
4
+ * Env:
5
+ * AUREON_API_KEY issued developer key (required)
6
+ * AUREON_API_URL optional (default https://api.aureonlabs.network)
7
+ *
8
+ * pnpm example:ai-to-objective-to-portfolio
9
+ */
10
+
11
+ import {
12
+ createAureonClient,
13
+ DEFAULT_API_BASE_URL,
14
+ formatWeight,
15
+ isAureonError,
16
+ parseFinancialIntent,
17
+ type PortfolioPositionInput,
18
+ } from "../../src/index.js";
19
+
20
+ const DEMO_POSITIONS: PortfolioPositionInput[] = [
21
+ {
22
+ symbol: "USDG",
23
+ name: "Paxos USDG",
24
+ category: "stable",
25
+ quantity: 24_000,
26
+ markPriceUsd: 1,
27
+ },
28
+ {
29
+ symbol: "NVDA",
30
+ name: "NVIDIA Stock Token",
31
+ category: "stock_token",
32
+ quantity: 45,
33
+ markPriceUsd: 920,
34
+ },
35
+ {
36
+ symbol: "AAPL",
37
+ name: "Apple Stock Token",
38
+ category: "stock_token",
39
+ quantity: 80,
40
+ markPriceUsd: 210,
41
+ },
42
+ {
43
+ symbol: "ETH",
44
+ name: "Ether",
45
+ category: "gas",
46
+ quantity: 8.5,
47
+ markPriceUsd: 3400,
48
+ },
49
+ ];
50
+
51
+ async function main(): Promise<void> {
52
+ const apiKey = process.env.AUREON_API_KEY?.trim();
53
+ if (!apiKey) {
54
+ throw new Error("Set AUREON_API_KEY to an issued developer key.");
55
+ }
56
+
57
+ const aureon = createAureonClient({
58
+ baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
59
+ apiKey,
60
+ });
61
+
62
+ const userBrief =
63
+ "I want to keep about 20% of my portfolio in stable assets.";
64
+
65
+ console.log("\n=== AUREON Update 3 — AI → objective → portfolio ===\n");
66
+ console.log("USER (simulated agent input):");
67
+ console.log(` "${userBrief}"\n`);
68
+
69
+ console.log("AI — structured intent:");
70
+ const intent = parseFinancialIntent(userBrief);
71
+ console.log(
72
+ JSON.stringify(
73
+ {
74
+ kind: intent.kind,
75
+ targetWeight: intent.targetWeight,
76
+ tolerance: intent.tolerance,
77
+ },
78
+ null,
79
+ 2
80
+ )
81
+ );
82
+
83
+ console.log("\n1. Seed capital book…");
84
+ await aureon.setPortfolio(DEMO_POSITIONS);
85
+
86
+ console.log("2. Apply financial intent → create objective…");
87
+ const flow = await aureon.applyFinancialIntent(intent);
88
+
89
+ console.log("\n--- Intent ---");
90
+ console.log(` Brief: ${flow.intent.brief}`);
91
+ console.log(` Policy: ${flow.intent.policySummary}`);
92
+
93
+ console.log("\n--- Objective ---");
94
+ console.log(` ID: ${flow.objective.id}`);
95
+ console.log(` Kind: ${flow.objective.kind}`);
96
+ console.log(` Mode: ${flow.objective.automationMode}`);
97
+ console.log(
98
+ ` Target: ${formatWeight(flow.objective.policy.targetWeight)}`
99
+ );
100
+
101
+ console.log("\n--- Portfolio ---");
102
+ console.log(
103
+ ` Book: $${flow.portfolio.totalNotionalUsd.toLocaleString()}`
104
+ );
105
+ console.log(
106
+ ` Stables: ${formatWeight(flow.portfolio.stableWeight)}`
107
+ );
108
+ if (flow.health) {
109
+ console.log(
110
+ ` Health: ${flow.health.state} — current ${formatWeight(flow.health.currentMetric)} vs target ${formatWeight(flow.health.targetMetric)}`
111
+ );
112
+ }
113
+
114
+ console.log(`\n${flow.message}`);
115
+ console.log(
116
+ "\nThe portfolio now has a reason — not just positions.\n"
117
+ );
118
+ }
119
+
120
+ main().catch((error) => {
121
+ if (isAureonError(error)) {
122
+ console.error(`${error.code}: ${error.message}`);
123
+ } else {
124
+ console.error(error);
125
+ }
126
+ process.exitCode = 1;
127
+ });
@@ -0,0 +1,53 @@
1
+ /**
2
+ * @fileoverview Phase 2 audit trail export — objective → proof.
3
+ *
4
+ * Env:
5
+ * AUREON_API_KEY issued developer key (required)
6
+ * AUREON_API_URL optional
7
+ * AUREON_OBJECTIVE_ID optional (defaults to first objective)
8
+ *
9
+ * pnpm example:audit-trail
10
+ */
11
+
12
+ import {
13
+ createAureonClient,
14
+ DEFAULT_API_BASE_URL,
15
+ formatAuditTrailLines,
16
+ isAureonError,
17
+ } from "../../src/index.js";
18
+
19
+ async function main(): Promise<void> {
20
+ const apiKey = process.env.AUREON_API_KEY?.trim();
21
+ if (!apiKey) {
22
+ throw new Error("Set AUREON_API_KEY to an issued developer key.");
23
+ }
24
+
25
+ const aureon = createAureonClient({
26
+ baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
27
+ apiKey,
28
+ });
29
+
30
+ const requested = process.env.AUREON_OBJECTIVE_ID?.trim();
31
+ const objectiveId =
32
+ requested || (await aureon.listObjectives())[0]?.id;
33
+ if (!objectiveId) {
34
+ throw new Error("No objectives on this wallet. Create one first.");
35
+ }
36
+
37
+ const trail = await aureon.getAuditTrail(objectiveId);
38
+
39
+ console.log("\n=== AUREON Phase 2 — Financial audit trail ===\n");
40
+ for (const line of formatAuditTrailLines(trail)) {
41
+ console.log(line);
42
+ }
43
+ console.log("");
44
+ }
45
+
46
+ main().catch((error) => {
47
+ if (isAureonError(error)) {
48
+ console.error(`${error.code}: ${error.message}`);
49
+ } else {
50
+ console.error(error);
51
+ }
52
+ process.exitCode = 1;
53
+ });
@@ -0,0 +1,96 @@
1
+ /**
2
+ * @fileoverview demo — drift → detection → restore.
3
+ *
4
+ * Shows the full loop: rule set, controlled drift, restore plan, receipt, health.
5
+ *
6
+ * Env:
7
+ * AUREON_API_KEY issued developer key (required)
8
+ * AUREON_API_URL optional (default https://api.aureonlabs.network)
9
+ *
10
+ * pnpm example:drift-detect-restore
11
+ */
12
+
13
+ import {
14
+ createAureonClient,
15
+ DEFAULT_API_BASE_URL,
16
+ formatWeight,
17
+ isAureonError,
18
+ type DriftRestoreFlow,
19
+ } from "../../src/index.js";
20
+
21
+ function printPhase(label: string, healthState: string, metric?: number, target?: number): void {
22
+ const metricStr =
23
+ metric !== undefined && target !== undefined
24
+ ? ` — ${formatWeight(metric)} vs ${formatWeight(target)} target`
25
+ : "";
26
+ console.log(` ${label}: ${healthState}${metricStr}`);
27
+ }
28
+
29
+ function printFlow(flow: DriftRestoreFlow): void {
30
+ console.log(`\nRule: ${flow.rule.summary}\n`);
31
+
32
+ console.log("1. Rule — aligned on policy");
33
+ printPhase(
34
+ " Health",
35
+ flow.phases.aligned.health.state,
36
+ flow.phases.aligned.health.currentMetric,
37
+ flow.phases.aligned.health.targetMetric
38
+ );
39
+
40
+ console.log("\n2. Drift — NVDA rally broke the stable sleeve");
41
+ printPhase(
42
+ " Health",
43
+ flow.phases.drift.health.state,
44
+ flow.phases.drift.health.currentMetric,
45
+ flow.phases.drift.health.targetMetric
46
+ );
47
+ if (flow.phases.drift.restorePlan) {
48
+ console.log(` Restore plan: ${flow.phases.drift.restorePlan.message}`);
49
+ }
50
+
51
+ if (flow.phases.restored) {
52
+ console.log("\n3. Restore — back within policy");
53
+ printPhase(
54
+ " Health",
55
+ flow.phases.restored.health.state,
56
+ flow.phases.restored.health.currentMetric,
57
+ flow.phases.restored.health.targetMetric
58
+ );
59
+ if (flow.phases.restored.receipt) {
60
+ console.log(
61
+ ` Receipt: ${flow.phases.restored.receipt.action} — settlement ${flow.phases.restored.receipt.settlement}`
62
+ );
63
+ }
64
+ }
65
+
66
+ console.log(`\n${flow.message}`);
67
+ console.log(
68
+ "\nWe broke the rule on purpose. AUREON detected it and restored the policy.\n"
69
+ );
70
+ }
71
+
72
+ async function main(): Promise<void> {
73
+ const apiKey = process.env.AUREON_API_KEY?.trim();
74
+ if (!apiKey) {
75
+ throw new Error("Set AUREON_API_KEY to an issued developer key.");
76
+ }
77
+
78
+ const aureon = createAureonClient({
79
+ baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
80
+ apiKey,
81
+ });
82
+
83
+ console.log("\n=== AUREON — Drift → detection → restore ===\n");
84
+
85
+ const flow = await aureon.runDriftRestoreDemo();
86
+ printFlow(flow);
87
+ }
88
+
89
+ main().catch((error) => {
90
+ if (isAureonError(error)) {
91
+ console.error(`${error.code}: ${error.message}`);
92
+ } else {
93
+ console.error(error);
94
+ }
95
+ process.exitCode = 1;
96
+ });
@@ -0,0 +1,83 @@
1
+ /**
2
+ * @fileoverview full AUREON loop (not a portfolio tracker).
3
+ *
4
+ * Env:
5
+ * AUREON_API_KEY issued developer key (required)
6
+ * AUREON_API_URL optional (default https://api.aureonlabs.network)
7
+ *
8
+ * pnpm example:full-aureon-loop
9
+ */
10
+
11
+ import {
12
+ createAureonClient,
13
+ DEFAULT_API_BASE_URL,
14
+ formatWeight,
15
+ isAureonError,
16
+ type FullAureonLoopFlow,
17
+ } from "../../src/index.js";
18
+
19
+ function printFlow(flow: FullAureonLoopFlow): void {
20
+ console.log("\n=== AUREON — Full loop (not a portfolio tracker) ===\n");
21
+
22
+ console.log(`User brief: "${flow.userBrief}"\n`);
23
+
24
+ console.log("1. Intent → objective");
25
+ console.log(` Objective: ${flow.phases.intent.objectiveName}`);
26
+ console.log(` Policy: ${flow.phases.intent.policySummary}`);
27
+ console.log(` Mode: ${flow.phases.intent.automationMode}`);
28
+ console.log(
29
+ ` Baseline: ${flow.phases.intent.health.state} — ${formatWeight(flow.phases.intent.health.currentMetric)} vs ${formatWeight(flow.phases.intent.health.targetMetric)}`
30
+ );
31
+
32
+ console.log("\n2. Plan check — green book can still fail the plan");
33
+ console.log(
34
+ ` After shock: ${flow.phases.planCheck.afterShock.health.state} — ${formatWeight(flow.phases.planCheck.afterShock.health.currentMetric)} vs ${formatWeight(flow.phases.planCheck.afterShock.health.targetMetric)}`
35
+ );
36
+ console.log(
37
+ ` Paradox: ${flow.phases.planCheck.afterShock.paradox.detected ? "yes" : "no"} — ${flow.phases.planCheck.afterShock.paradox.message}`
38
+ );
39
+
40
+ console.log("\n3. Drift → restore");
41
+ console.log(
42
+ ` Health: ${flow.phases.driftRestore.healthBefore.state} → ${flow.phases.driftRestore.healthAfter.state}`
43
+ );
44
+ console.log(
45
+ ` Receipt: ${flow.phases.driftRestore.settlement} — ${flow.phases.driftRestore.receipt.id}`
46
+ );
47
+
48
+ console.log("\n4. Receipt → verification");
49
+ console.log(
50
+ ` Valid: ${flow.phases.verification.phases.validation.valid}`
51
+ );
52
+ console.log(` Proof tier: ${flow.phases.verification.proofTier}`);
53
+ console.log(` Claim: ${flow.phases.verification.phases.claimed.result}`);
54
+
55
+ console.log(`\n${flow.message}`);
56
+ console.log(
57
+ "\nWe're not building another portfolio tracker. Intent → plan → restore → verify.\n"
58
+ );
59
+ }
60
+
61
+ async function main(): Promise<void> {
62
+ const apiKey = process.env.AUREON_API_KEY?.trim();
63
+ if (!apiKey) {
64
+ throw new Error("Set AUREON_API_KEY to an issued developer key.");
65
+ }
66
+
67
+ const aureon = createAureonClient({
68
+ baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
69
+ apiKey,
70
+ });
71
+
72
+ const flow = await aureon.runFullAureonLoopDemo();
73
+ printFlow(flow);
74
+ }
75
+
76
+ main().catch((error) => {
77
+ if (isAureonError(error)) {
78
+ console.error(`${error.code}: ${error.message}`);
79
+ } else {
80
+ console.error(error);
81
+ }
82
+ process.exitCode = 1;
83
+ });
@@ -0,0 +1,139 @@
1
+ /**
2
+ * @fileoverview Update 2 demo — green portfolio vs failing financial plan.
3
+ *
4
+ * Shows objective vs actual before and after a controlled NVDA rally with
5
+ * auto-restore disabled so the paradox stays visible.
6
+ *
7
+ * Env:
8
+ * AUREON_API_KEY issued developer key (required)
9
+ * AUREON_API_URL optional (default https://api.aureonlabs.network)
10
+ *
11
+ * pnpm example:green-vs-plan
12
+ */
13
+
14
+ import {
15
+ createAureonClient,
16
+ DEFAULT_API_BASE_URL,
17
+ formatWeight,
18
+ isAureonError,
19
+ type AllocationComparisonRow,
20
+ type PortfolioPositionInput,
21
+ } from "../../src/index.js";
22
+
23
+ const DEMO_POSITIONS: PortfolioPositionInput[] = [
24
+ {
25
+ symbol: "USDG",
26
+ name: "Paxos USDG",
27
+ category: "stable",
28
+ quantity: 24_000,
29
+ markPriceUsd: 1,
30
+ },
31
+ {
32
+ symbol: "NVDA",
33
+ name: "NVIDIA Stock Token",
34
+ category: "stock_token",
35
+ quantity: 45,
36
+ markPriceUsd: 920,
37
+ },
38
+ {
39
+ symbol: "AAPL",
40
+ name: "Apple Stock Token",
41
+ category: "stock_token",
42
+ quantity: 80,
43
+ markPriceUsd: 210,
44
+ },
45
+ {
46
+ symbol: "ETH",
47
+ name: "Ether",
48
+ category: "gas",
49
+ quantity: 8.5,
50
+ markPriceUsd: 3400,
51
+ },
52
+ ];
53
+
54
+ function printRows(rows: AllocationComparisonRow[]): void {
55
+ if (rows.length === 0) {
56
+ console.log(" (no active objectives)");
57
+ return;
58
+ }
59
+ for (const row of rows) {
60
+ const label = row.targetSymbol ?? row.name.slice(0, 20);
61
+ console.log(
62
+ ` ${label.padEnd(16)} current ${formatWeight(row.currentMetric)} target ${formatWeight(row.targetWeight)} ${row.state}`
63
+ );
64
+ }
65
+ }
66
+
67
+ async function main(): Promise<void> {
68
+ const apiKey = process.env.AUREON_API_KEY?.trim();
69
+ if (!apiKey) {
70
+ throw new Error("Set AUREON_API_KEY to an issued developer key.");
71
+ }
72
+
73
+ const aureon = createAureonClient({
74
+ baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
75
+ apiKey,
76
+ });
77
+
78
+ console.log("\n=== AUREON Update 2 — Green vs plan ===\n");
79
+
80
+ console.log("1. Seed capital book (~20% stables)…");
81
+ await aureon.setPortfolio(DEMO_POSITIONS);
82
+
83
+ console.log("2. Create stable allocation objective (20% ± 2%)…");
84
+ const objective = await aureon.createObjective({
85
+ name: "Maintain 20% Stable Assets",
86
+ kind: "stable_allocation",
87
+ targetWeight: 0.2,
88
+ tolerance: 0.02,
89
+ });
90
+
91
+ console.log("3. Baseline — objective vs actual:\n");
92
+ let snapshot = await aureon.getAllocationVsTarget();
93
+ printRows(snapshot.rows);
94
+ console.log(`\n Book: $${snapshot.overview.totalNotionalUsd.toLocaleString()}`);
95
+ console.log(` Paradox: ${snapshot.paradox.message}\n`);
96
+
97
+ console.log("4. Apply NVDA rally (+45%), autoRestore: false…");
98
+ const market = await aureon.applyMarketEvent({
99
+ name: "NVDA Stock Token Rally",
100
+ description: "Controlled mark move — Update 2 paradox demo",
101
+ symbol: "NVDA",
102
+ priceChangeRatio: 0.45,
103
+ autoRestore: false,
104
+ });
105
+
106
+ console.log("5. After shock — objective vs actual:\n");
107
+ snapshot = await aureon.getAllocationVsTarget();
108
+ printRows(snapshot.rows);
109
+
110
+ const stable = snapshot.rows.find((r) => r.objectiveId === objective.id);
111
+ const bookBefore = snapshot.overview.totalNotionalUsd;
112
+ const bookAfter = market.portfolio.totalNotionalUsd;
113
+
114
+ console.log(`\n Book before shock: $${bookBefore.toLocaleString()}`);
115
+ console.log(` Book after shock: $${bookAfter.toLocaleString()}`);
116
+ console.log(` Book moved up: ${bookAfter >= bookBefore ? "yes" : "no"}`);
117
+ if (stable) {
118
+ console.log(
119
+ ` Stable objective: ${formatWeight(stable.currentMetric)} vs ${formatWeight(stable.targetWeight)} target — ${stable.state}`
120
+ );
121
+ }
122
+ console.log(`\n Paradox detected: ${snapshot.paradox.detected}`);
123
+ console.log(` ${snapshot.paradox.message}\n`);
124
+
125
+ if (!snapshot.paradox.detected && stable && stable.state !== "healthy") {
126
+ console.log(
127
+ " Note: paradox flag needs book-up signal; objective is still off-plan.\n"
128
+ );
129
+ }
130
+ }
131
+
132
+ main().catch((error) => {
133
+ if (isAureonError(error)) {
134
+ console.error(`${error.code}: ${error.message}`);
135
+ } else {
136
+ console.error(error);
137
+ }
138
+ process.exitCode = 1;
139
+ });
@@ -1,65 +1,67 @@
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 runs restorative execution when objectives breach —
41
+ // use autoRestore: false for the green-vs-plan paradox demo (see example:green-vs-plan).
42
+ autoRestore: true,
43
+ });
44
+
45
+ console.log(
46
+ JSON.stringify(
47
+ {
48
+ objectiveId: objective.id,
49
+ eventId: result.event.id,
50
+ executions: result.executions.length,
51
+ settlement: result.executions[0]?.settlement ?? null,
52
+ health: result.health.find((h) => h.objectiveId === objective.id)?.state,
53
+ },
54
+ null,
55
+ 2
56
+ )
57
+ );
58
+ }
59
+
60
+ main().catch((error) => {
61
+ if (isAureonError(error)) {
62
+ console.error(`${error.code}: ${error.message}`);
63
+ } else {
64
+ console.error(error);
65
+ }
66
+ process.exitCode = 1;
67
+ });