@buildaureon/sdk 0.1.0 → 0.1.1
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 +353 -245
- package/dist/index.d.ts +15 -6
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/docs/architecture.md +139 -138
- package/docs/auth.md +127 -168
- package/docs/client-api.md +5 -4
- package/docs/data-contracts.md +7 -4
- package/docs/error-model.md +151 -116
- package/docs/integration-guide.md +173 -112
- package/docs/security.md +87 -41
- package/docs/transport.md +91 -77
- package/examples/e2e-policy-rebalance/main.ts +24 -36
- package/examples/e2e-policy-rebalance/underrun.ts +28 -24
- package/examples/e2e-policy-rebalance/verify-sizing.ts +29 -26
- package/examples/e2e-vault-flow/main.ts +36 -90
- package/examples/market-event/main.ts +9 -9
- package/examples/quickstart/main.ts +17 -16
- package/examples/sdk-demo-terminal/main.ts +171 -0
- package/package.json +5 -8
package/docs/transport.md
CHANGED
|
@@ -1,122 +1,120 @@
|
|
|
1
1
|
# Transport Layer Reference
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
HTTP transport for `@buildaureon/sdk` (`src/transport/http.ts`): headers, timeouts, retries, URL helpers, and logging.
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
## 1.
|
|
8
|
-
|
|
9
|
-
Every SDK client call delegates network execution to the `requestJson` helper.
|
|
7
|
+
## 1. Request lifecycle
|
|
10
8
|
|
|
11
9
|
```mermaid
|
|
12
10
|
flowchart TD
|
|
13
|
-
Call[
|
|
14
|
-
Prep --> Auth[
|
|
15
|
-
Auth --> Abort[
|
|
16
|
-
Abort --> Fetch[
|
|
17
|
-
Fetch -->
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
Map --> Retry{
|
|
21
|
-
Retry -->|Yes| Sleep[
|
|
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]
|
|
22
20
|
Sleep --> Fetch
|
|
23
|
-
Retry -->|No| Throw[Throw
|
|
21
|
+
Retry -->|No| Throw[Throw]
|
|
24
22
|
```
|
|
25
23
|
|
|
26
|
-
1.
|
|
27
|
-
2.
|
|
28
|
-
3.
|
|
29
|
-
4.
|
|
30
|
-
5.
|
|
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.
|
|
31
29
|
|
|
32
30
|
---
|
|
33
31
|
|
|
34
|
-
## 2.
|
|
32
|
+
## 2. Headers
|
|
35
33
|
|
|
36
|
-
|
|
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 |
|
|
37
42
|
|
|
38
|
-
|
|
39
|
-
|--------|----------|---------------|---------|
|
|
40
|
-
| `Accept` | Yes | `application/json` | Specifies the accepted media type. |
|
|
41
|
-
| `Content-Type` | Optional | `application/json` | Specifies the payload format (attached if a request body is present). |
|
|
42
|
-
| `X-Aureon-SDK` | Yes | `@buildaureon/sdk/0.1.0` | Identifies client package version. |
|
|
43
|
-
| `X-Aureon-Api-Key` | Optional | `api_key_abc123` | Sent if the client is configured with an API key. |
|
|
44
|
-
| `Authorization` | Optional | `Bearer token_xyz` | Session JWT, attached if a token provider is active. |
|
|
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.
|
|
45
44
|
|
|
46
45
|
---
|
|
47
46
|
|
|
48
|
-
## 3.
|
|
47
|
+
## 3. Client transport options
|
|
49
48
|
|
|
50
|
-
### 3.1 `joinUrl`
|
|
51
|
-
Normalizes base URLs and paths to prevent double slashes at joining boundaries:
|
|
52
49
|
```ts
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
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
|
+
});
|
|
58
60
|
```
|
|
59
61
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
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`.
|
|
73
78
|
|
|
74
79
|
---
|
|
75
80
|
|
|
76
|
-
##
|
|
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
|
+
---
|
|
77
92
|
|
|
78
|
-
|
|
93
|
+
## 6. Timeouts and aborts
|
|
79
94
|
|
|
80
95
|
```ts
|
|
81
96
|
const controller = new AbortController();
|
|
82
|
-
const timeoutId = setTimeout(() => controller.abort(),
|
|
83
|
-
|
|
97
|
+
const timeoutId = setTimeout(() => controller.abort(), timeoutMs);
|
|
84
98
|
try {
|
|
85
|
-
|
|
86
|
-
...init,
|
|
87
|
-
signal: controller.signal
|
|
88
|
-
});
|
|
89
|
-
return response;
|
|
99
|
+
return await fetchImpl(url, { ...init, signal: controller.signal });
|
|
90
100
|
} catch (error) {
|
|
91
101
|
if (error instanceof Error && error.name === "AbortError") {
|
|
92
|
-
throw
|
|
102
|
+
throw /* AureonTimeoutError */;
|
|
93
103
|
}
|
|
94
|
-
throw
|
|
104
|
+
throw /* AureonNetworkError */;
|
|
95
105
|
} finally {
|
|
96
106
|
clearTimeout(timeoutId);
|
|
97
107
|
}
|
|
98
108
|
```
|
|
99
109
|
|
|
100
|
-
|
|
101
|
-
* **Custom Abort Signals**: You can pass a custom `AbortSignal` in `RequestOptions` to cancel requests manually based on user actions.
|
|
102
|
-
|
|
103
|
-
---
|
|
104
|
-
|
|
105
|
-
## 5. Retry Loop and Backoff Configurations
|
|
106
|
-
|
|
107
|
-
The SDK implements a retry mechanism for transient exceptions:
|
|
108
|
-
|
|
109
|
-
* **Retryable Failures**: `NETWORK_ERROR`, `TIMEOUT`, `RATE_LIMITED` (HTTP 429), and `SERVER_ERROR` (HTTP 5xx).
|
|
110
|
-
* **Default Behavior**: `maxRetries` is 0. If you configure `maxRetries: 2` and `retryDelayMs: 500`, the client will try the request up to 3 times, waiting 500ms between attempts.
|
|
110
|
+
For agent loops that call restore + sync, prefer slightly higher `timeoutMs` under load rather than disabling timeouts.
|
|
111
111
|
|
|
112
112
|
---
|
|
113
113
|
|
|
114
|
-
##
|
|
115
|
-
|
|
116
|
-
Integrate with internal request diagnostics using the `AureonLogger` interface:
|
|
114
|
+
## 7. Logger interface
|
|
117
115
|
|
|
118
116
|
```ts
|
|
119
|
-
|
|
117
|
+
interface AureonLogger {
|
|
120
118
|
debug(message: string, context?: Record<string, unknown>): void;
|
|
121
119
|
info(message: string, context?: Record<string, unknown>): void;
|
|
122
120
|
warn(message: string, context?: Record<string, unknown>): void;
|
|
@@ -124,5 +122,21 @@ export interface AureonLogger {
|
|
|
124
122
|
}
|
|
125
123
|
```
|
|
126
124
|
|
|
127
|
-
|
|
128
|
-
|
|
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,12 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Live e2e:
|
|
2
|
+
* Live e2e: vault deposits + Automatic maintain 20% TSLA against the hosted API.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Env:
|
|
5
|
+
* AUREON_API_KEY issued developer key (required)
|
|
6
|
+
* AUREON_WALLET_PRIVATE_KEY 0x… signing key (required)
|
|
7
|
+
* AUREON_API_URL optional (default https://api.aureonlabs.network)
|
|
8
|
+
* AUREON_RPC_URL optional
|
|
9
|
+
* AUREON_CHAIN_ID optional (default 46630)
|
|
10
|
+
*
|
|
11
|
+
* pnpm --filter @buildaureon/sdk example:e2e-policy
|
|
5
12
|
*/
|
|
6
13
|
|
|
7
|
-
import { readFileSync, existsSync } from "node:fs";
|
|
8
|
-
import { dirname, join } from "node:path";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
14
|
import {
|
|
11
15
|
createPublicClient,
|
|
12
16
|
createWalletClient,
|
|
@@ -21,13 +25,10 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
21
25
|
import {
|
|
22
26
|
createAureonClient,
|
|
23
27
|
createSessionTokenProvider,
|
|
28
|
+
DEFAULT_API_BASE_URL,
|
|
24
29
|
isAureonError,
|
|
25
|
-
LOCAL_API_BASE_URL,
|
|
26
30
|
} from "../../src/index.js";
|
|
27
31
|
|
|
28
|
-
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
29
|
-
const BACKEND = join(__dirname, "../../../backend");
|
|
30
|
-
|
|
31
32
|
const VAULT_ABI = [
|
|
32
33
|
{
|
|
33
34
|
type: "function",
|
|
@@ -41,32 +42,18 @@ const VAULT_ABI = [
|
|
|
41
42
|
},
|
|
42
43
|
] as const;
|
|
43
44
|
|
|
44
|
-
function
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
const trimmed = line.trim();
|
|
49
|
-
if (!trimmed || trimmed.startsWith("#")) continue;
|
|
50
|
-
const i = trimmed.indexOf("=");
|
|
51
|
-
if (i < 0) continue;
|
|
52
|
-
out[trimmed.slice(0, i)] = trimmed.slice(i + 1).trim();
|
|
53
|
-
}
|
|
54
|
-
return out;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function firstApiKey(raw?: string): string {
|
|
58
|
-
const key = raw?.split(",")[0]?.trim();
|
|
59
|
-
if (!key) throw new Error("AUREON_API_KEYS missing");
|
|
60
|
-
return key;
|
|
45
|
+
function requireEnv(name: string): string {
|
|
46
|
+
const value = process.env[name]?.trim();
|
|
47
|
+
if (!value) throw new Error(`Set ${name}`);
|
|
48
|
+
return value;
|
|
61
49
|
}
|
|
62
50
|
|
|
63
51
|
function loadKey(): Hex {
|
|
64
|
-
|
|
65
|
-
|
|
52
|
+
const key = requireEnv("AUREON_WALLET_PRIVATE_KEY");
|
|
53
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(key)) {
|
|
54
|
+
throw new Error("AUREON_WALLET_PRIVATE_KEY must be a 0x-prefixed 32-byte hex key");
|
|
66
55
|
}
|
|
67
|
-
|
|
68
|
-
const j = JSON.parse(readFileSync(walletPath, "utf8")) as { privateKey: string };
|
|
69
|
-
return j.privateKey as Hex;
|
|
56
|
+
return key as Hex;
|
|
70
57
|
}
|
|
71
58
|
|
|
72
59
|
function log(step: string, data?: unknown) {
|
|
@@ -74,11 +61,12 @@ function log(step: string, data?: unknown) {
|
|
|
74
61
|
}
|
|
75
62
|
|
|
76
63
|
async function main() {
|
|
77
|
-
const
|
|
78
|
-
const
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
const
|
|
64
|
+
const baseUrl = process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL;
|
|
65
|
+
const rpcUrl =
|
|
66
|
+
process.env.AUREON_RPC_URL?.trim() ||
|
|
67
|
+
"https://rpc.testnet.chain.robinhood.com";
|
|
68
|
+
const chainId = Number(process.env.AUREON_CHAIN_ID ?? 46630);
|
|
69
|
+
const apiKey = requireEnv("AUREON_API_KEY");
|
|
82
70
|
|
|
83
71
|
const account = privateKeyToAccount(loadKey());
|
|
84
72
|
const publicClient = createPublicClient({ transport: http(rpcUrl) });
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Follow-up: force TSLA underweight → Auto should Sell WETH → Buy TSLA.
|
|
3
|
+
*
|
|
4
|
+
* Env:
|
|
5
|
+
* AUREON_API_KEY issued developer key
|
|
6
|
+
* AUREON_WALLET_PRIVATE_KEY 0x… signing key
|
|
7
|
+
* AUREON_API_URL optional (default https://api.aureonlabs.network)
|
|
8
|
+
* AUREON_RPC_URL optional
|
|
9
|
+
* AUREON_CHAIN_ID optional (default 46630)
|
|
3
10
|
*/
|
|
4
|
-
|
|
5
|
-
import { join, dirname } from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
7
12
|
import {
|
|
8
13
|
createPublicClient,
|
|
9
14
|
createWalletClient,
|
|
@@ -15,39 +20,39 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
15
20
|
import {
|
|
16
21
|
createAureonClient,
|
|
17
22
|
createSessionTokenProvider,
|
|
23
|
+
DEFAULT_API_BASE_URL,
|
|
18
24
|
isAureonError,
|
|
19
|
-
LOCAL_API_BASE_URL,
|
|
20
25
|
} from "../../src/index.js";
|
|
21
26
|
|
|
22
|
-
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
readFileSync(join(BACKEND, ".secrets/robinhood-testnet-wallet.json"), "utf8")
|
|
34
|
-
).privateKey as Hex;
|
|
27
|
+
function requireEnv(name: string): string {
|
|
28
|
+
const value = process.env[name]?.trim();
|
|
29
|
+
if (!value) throw new Error(`Set ${name}`);
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const key = requireEnv("AUREON_WALLET_PRIVATE_KEY") as Hex;
|
|
34
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(key)) {
|
|
35
|
+
throw new Error("AUREON_WALLET_PRIVATE_KEY must be a 0x-prefixed 32-byte hex key");
|
|
36
|
+
}
|
|
37
|
+
|
|
35
38
|
const account = privateKeyToAccount(key);
|
|
36
|
-
const rpc =
|
|
37
|
-
|
|
39
|
+
const rpc =
|
|
40
|
+
process.env.AUREON_RPC_URL?.trim() ||
|
|
41
|
+
"https://rpc.testnet.chain.robinhood.com";
|
|
42
|
+
const chainId = Number(process.env.AUREON_CHAIN_ID || 46630);
|
|
38
43
|
const publicClient = createPublicClient({ transport: http(rpc) });
|
|
39
44
|
const walletClient = createWalletClient({ account, transport: http(rpc) });
|
|
40
45
|
const chain = {
|
|
41
46
|
id: chainId,
|
|
42
|
-
name: "
|
|
47
|
+
name: "Robinhood Chain Testnet",
|
|
43
48
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
44
49
|
rpcUrls: { default: { http: [rpc] } },
|
|
45
50
|
} as const;
|
|
46
51
|
|
|
47
52
|
const session = createSessionTokenProvider(null);
|
|
48
53
|
const aureon = createAureonClient({
|
|
49
|
-
baseUrl:
|
|
50
|
-
apiKey:
|
|
54
|
+
baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
|
|
55
|
+
apiKey: requireEnv("AUREON_API_KEY"),
|
|
51
56
|
getAccessToken: session.getAccessToken,
|
|
52
57
|
});
|
|
53
58
|
|
|
@@ -100,8 +105,7 @@ for (const step of d.steps) {
|
|
|
100
105
|
}
|
|
101
106
|
|
|
102
107
|
const objs = await aureon.listObjectives();
|
|
103
|
-
const obj =
|
|
104
|
-
objs.find((o) => o.name.includes("E2E 20% TSLA")) ?? objs[0];
|
|
108
|
+
const obj = objs.find((o) => o.name.includes("E2E 20% TSLA")) ?? objs[0];
|
|
105
109
|
if (!obj) throw new Error("no objective");
|
|
106
110
|
console.log("using objective", obj.id, obj.name);
|
|
107
111
|
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Verify underweight
|
|
2
|
+
* Verify underweight Automatic sizing lands near 20% (not a blow-up fill).
|
|
3
|
+
*
|
|
4
|
+
* Env:
|
|
5
|
+
* AUREON_API_KEY issued developer key
|
|
6
|
+
* AUREON_WALLET_PRIVATE_KEY 0x… signing key
|
|
7
|
+
* AUREON_API_URL optional (default https://api.aureonlabs.network)
|
|
8
|
+
* AUREON_RPC_URL optional
|
|
9
|
+
* AUREON_CHAIN_ID optional (default 46630)
|
|
3
10
|
*/
|
|
4
|
-
|
|
5
|
-
import { join, dirname } from "node:path";
|
|
6
|
-
import { fileURLToPath } from "node:url";
|
|
11
|
+
|
|
7
12
|
import {
|
|
8
13
|
createPublicClient,
|
|
9
14
|
createWalletClient,
|
|
@@ -15,38 +20,38 @@ import { privateKeyToAccount } from "viem/accounts";
|
|
|
15
20
|
import {
|
|
16
21
|
createAureonClient,
|
|
17
22
|
createSessionTokenProvider,
|
|
18
|
-
|
|
23
|
+
DEFAULT_API_BASE_URL,
|
|
19
24
|
} from "../../src/index.js";
|
|
20
25
|
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
readFileSync(join(BACKEND, ".secrets/robinhood-testnet-wallet.json"), "utf8")
|
|
33
|
-
).privateKey as Hex;
|
|
26
|
+
function requireEnv(name: string): string {
|
|
27
|
+
const value = process.env[name]?.trim();
|
|
28
|
+
if (!value) throw new Error(`Set ${name}`);
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const key = requireEnv("AUREON_WALLET_PRIVATE_KEY") as Hex;
|
|
33
|
+
if (!/^0x[0-9a-fA-F]{64}$/.test(key)) {
|
|
34
|
+
throw new Error("AUREON_WALLET_PRIVATE_KEY must be a 0x-prefixed 32-byte hex key");
|
|
35
|
+
}
|
|
36
|
+
|
|
34
37
|
const account = privateKeyToAccount(key);
|
|
35
|
-
const rpc =
|
|
36
|
-
|
|
38
|
+
const rpc =
|
|
39
|
+
process.env.AUREON_RPC_URL?.trim() ||
|
|
40
|
+
"https://rpc.testnet.chain.robinhood.com";
|
|
41
|
+
const chainId = Number(process.env.AUREON_CHAIN_ID || 46630);
|
|
37
42
|
const publicClient = createPublicClient({ transport: http(rpc) });
|
|
38
43
|
const walletClient = createWalletClient({ account, transport: http(rpc) });
|
|
39
44
|
const chain = {
|
|
40
45
|
id: chainId,
|
|
41
|
-
name: "
|
|
46
|
+
name: "Robinhood Chain Testnet",
|
|
42
47
|
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
43
48
|
rpcUrls: { default: { http: [rpc] } },
|
|
44
49
|
} as const;
|
|
45
50
|
|
|
46
51
|
const session = createSessionTokenProvider(null);
|
|
47
52
|
const aureon = createAureonClient({
|
|
48
|
-
baseUrl:
|
|
49
|
-
apiKey:
|
|
53
|
+
baseUrl: process.env.AUREON_API_URL?.trim() || DEFAULT_API_BASE_URL,
|
|
54
|
+
apiKey: requireEnv("AUREON_API_KEY"),
|
|
50
55
|
getAccessToken: session.getAccessToken,
|
|
51
56
|
});
|
|
52
57
|
|
|
@@ -61,7 +66,6 @@ session.setToken(
|
|
|
61
66
|
).token
|
|
62
67
|
);
|
|
63
68
|
|
|
64
|
-
// Fresh Auto objective
|
|
65
69
|
const objective = await aureon.createObjective({
|
|
66
70
|
name: `SizeFix 20% TSLA ${Date.now()}`,
|
|
67
71
|
kind: "balanced_portfolio",
|
|
@@ -73,7 +77,6 @@ const objective = await aureon.createObjective({
|
|
|
73
77
|
});
|
|
74
78
|
console.log("objective", objective.id);
|
|
75
79
|
|
|
76
|
-
// Dump almost all TSLA so we're heavily underweight, keep/add WETH
|
|
77
80
|
const vault = await aureon.getVault();
|
|
78
81
|
console.log(
|
|
79
82
|
"before",
|
|
@@ -138,7 +141,7 @@ console.log("health after", {
|
|
|
138
141
|
});
|
|
139
142
|
|
|
140
143
|
const weightPct = (h2.currentMetric ?? 0) * 100;
|
|
141
|
-
const ok = weightPct >= 5 && weightPct <= 45;
|
|
144
|
+
const ok = weightPct >= 5 && weightPct <= 45;
|
|
142
145
|
console.log(
|
|
143
146
|
ok
|
|
144
147
|
? `PASS sizing : TSLA weight ~${weightPct.toFixed(1)}% (want ~20%)`
|