@oracle-agent/oracle 0.3.4 → 0.3.6

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.
Files changed (37) hide show
  1. package/README.md +33 -13
  2. package/SETUP.md +59 -1
  3. package/artifacts/specialist-packs/oracle-full-crypto.json +31 -9
  4. package/bin/oracle-data-mcp.mjs +317 -4
  5. package/bin/oracle-init.mjs +100 -27
  6. package/bin/oracle-upgrade.mjs +42 -0
  7. package/docs/profiles.md +29 -7
  8. package/package.json +4 -1
  9. package/plugins/oracle-owner-gate/__init__.py +213 -0
  10. package/plugins/oracle-owner-gate/plugin.yaml +9 -0
  11. package/profiles/_template/SOUL.md +8 -1
  12. package/profiles/oracle/SOUL.md +17 -2
  13. package/profiles/oracle/profile.json +6 -2
  14. package/profiles/protocol-builder/SOUL.md +13 -6
  15. package/profiles/protocol-builder/profile.json +3 -1
  16. package/profiles/robinhood-agent/SOUL.md +9 -3
  17. package/profiles/robinhood-agent/profile.json +1 -0
  18. package/skills/balance/SKILL.md +176 -0
  19. package/skills/oracle-action-semantics/SKILL.md +40 -0
  20. package/skills/oracle-multichain-nft-launch/SKILL.md +338 -0
  21. package/skills/oracle-multichain-token-launch/SKILL.md +300 -0
  22. package/src/action-semantics.mjs +62 -0
  23. package/src/data/catalog.mjs +27 -3
  24. package/src/data/desk-data.mjs +34 -4
  25. package/src/data/providers/magiceden-sol.mjs +21 -2
  26. package/src/data/providers/nft-gallery.mjs +163 -0
  27. package/src/data/providers/nft-portfolio.mjs +494 -0
  28. package/src/data/providers/opensea-nft.mjs +272 -0
  29. package/src/data/providers/portfolio-history.mjs +394 -0
  30. package/src/data/providers/portfolio.mjs +594 -0
  31. package/src/data/providers/satflow.mjs +1 -0
  32. package/src/exec-policy.mjs +5 -0
  33. package/src/gmx-attestation.mjs +1 -0
  34. package/src/index.mjs +9 -0
  35. package/src/profile-upgrade.mjs +277 -0
  36. package/src/scanner/chains.config.mjs +50 -1
  37. package/src/vault-attestation.mjs +1 -0
@@ -0,0 +1,277 @@
1
+ import fs from "node:fs";
2
+ import path from "node:path";
3
+ import { randomBytes } from "node:crypto";
4
+ import { createRequire } from "node:module";
5
+
6
+ export const UPGRADE_VERSION = "oracle-profile-upgrade/v1";
7
+
8
+ function exists(file) {
9
+ try { fs.accessSync(file); return true; } catch { return false; }
10
+ }
11
+
12
+ function snapshot(dir) {
13
+ if (!exists(dir)) return [];
14
+ return fs.readdirSync(dir, { recursive: true, withFileTypes: true })
15
+ .filter((entry) => entry.isFile())
16
+ .map((entry) => path.join(entry.parentPath || entry.path, entry.name))
17
+ .sort()
18
+ .map((file) => [path.relative(dir, file), fs.readFileSync(file)]);
19
+ }
20
+
21
+ function desiredTree(source) {
22
+ const files = snapshot(source);
23
+ files.push([".oracle-upgrade-version", Buffer.from(`${UPGRADE_VERSION}\n`)]);
24
+ return files.sort(([a], [b]) => a.localeCompare(b));
25
+ }
26
+
27
+ function treeMatches(dest, files) {
28
+ const actual = snapshot(dest);
29
+ return actual.length === files.length && actual.every(([name, body], i) =>
30
+ name === files[i][0] && body.equals(files[i][1]));
31
+ }
32
+
33
+ function tempSibling(target) {
34
+ return `${target}.tmp-oracle-upgrade-${process.pid}-${randomBytes(6).toString("hex")}`;
35
+ }
36
+
37
+ function backupName(target) {
38
+ let candidate = `${target}.bak-oracle-upgrade`;
39
+ for (let n = 1; exists(candidate); n += 1) candidate = `${target}.bak-oracle-upgrade-${n}`;
40
+ return candidate;
41
+ }
42
+
43
+ function installTree(source, dest, apply, report) {
44
+ if (!exists(source) || !fs.statSync(source).isDirectory()) return;
45
+ const files = desiredTree(source);
46
+ if (treeMatches(dest, files)) {
47
+ report.unchanged.push(dest);
48
+ return;
49
+ }
50
+ const wasPresent = exists(dest);
51
+ (wasPresent ? report.updated : report.created).push(dest);
52
+ if (!apply) return;
53
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
54
+ const tmp = tempSibling(dest);
55
+ let backup = null;
56
+ fs.mkdirSync(tmp);
57
+ try {
58
+ for (const [name, body] of files) {
59
+ const out = path.join(tmp, name);
60
+ fs.mkdirSync(path.dirname(out), { recursive: true });
61
+ fs.writeFileSync(out, body);
62
+ }
63
+ if (wasPresent) {
64
+ backup = backupName(dest);
65
+ fs.renameSync(dest, backup);
66
+ report.backups.push({ path: backup, original: dest });
67
+ }
68
+ fs.renameSync(tmp, dest);
69
+ } catch (error) {
70
+ if (exists(tmp)) fs.rmSync(tmp, { recursive: true, force: true });
71
+ if (backup && !exists(dest) && exists(backup)) fs.renameSync(backup, dest);
72
+ throw error;
73
+ }
74
+ }
75
+
76
+ // This deliberately accepts only the ordinary block-style YAML Hermes writes.
77
+ // Unsupported constructs fail closed rather than risking a lossy rewrite.
78
+ function validateYaml(text, file) {
79
+ if (/^mcp_servers:[ \t]*(?!\{\}[ \t]*(?:#.*)?$)\S+/m.test(text)) {
80
+ throw new Error(`${file}: mcp_servers must be a block mapping`);
81
+ }
82
+ const stack = [];
83
+ const keys = new Map();
84
+ const lines = text.split(/\r?\n/);
85
+ let flow = 0;
86
+ for (let index = 0; index < lines.length; index += 1) {
87
+ const raw = lines[index];
88
+ if (/^\s*#/.test(raw)) continue;
89
+ if (/^\s*\t|^ +\t/.test(raw)) throw new Error(`${file}:${index + 1}: tabs are not supported in YAML indentation`);
90
+ const line = raw.replace(/\s+#.*$/, "");
91
+ if (!line.trim() || /^\s*(?:---|\.\.\.)\s*$/.test(line)) continue;
92
+ const quoteFree = line.replace(/'(?:[^']|'')*'|"(?:[^"\\]|\\.)*"/g, "");
93
+ for (const char of quoteFree) {
94
+ if ("[{".includes(char)) flow += 1;
95
+ if ("]}".includes(char)) flow -= 1;
96
+ if (flow < 0) throw new Error(`${file}:${index + 1}: unbalanced flow collection`);
97
+ }
98
+ if (/^\s*[^#\-][^:]*:\s*(?:.*)?$/.test(line)) {
99
+ const indent = line.match(/^ */)[0].length;
100
+ const key = line.trimStart().match(/^([^:]+):/)[1].trim();
101
+ while (stack.length && stack.at(-1).indent >= indent) stack.pop();
102
+ const parent = stack.map((item) => item.key).join("/");
103
+ const id = `${parent}|${indent}|${key}`;
104
+ if (keys.has(id)) throw new Error(`${file}:${index + 1}: duplicate mapping key ${key}`);
105
+ keys.set(id, true);
106
+ if (/^[^:]+:\s*(?:#.*)?$/.test(line.trimStart())) stack.push({ indent, key });
107
+ } else if (!/^\s*-\s+/.test(line) && flow === 0) {
108
+ throw new Error(`${file}:${index + 1}: unsupported or malformed YAML`);
109
+ }
110
+ }
111
+ if (flow !== 0) throw new Error(`${file}: unbalanced flow collection`);
112
+ if (/^\s*[^#\n]*:\s*[>|][+-]?\s*$/m.test(text)) {
113
+ // Block scalars are safe to preserve outside mcp_servers, but editing inside
114
+ // one would require a complete YAML parser.
115
+ const mcp = topLevelBlock(text, "mcp_servers");
116
+ if (mcp && /:\s*[>|][+-]?\s*$/m.test(mcp.body)) throw new Error(`${file}: block scalars inside mcp_servers are unsupported`);
117
+ }
118
+ }
119
+
120
+ function topLevelBlock(text, name) {
121
+ const re = new RegExp(`^${name}:[^\\S\\r\\n]*(?:#.*)?$`, "m");
122
+ const match = re.exec(text);
123
+ if (!match) return null;
124
+ const start = match.index;
125
+ const bodyStart = text.indexOf("\n", start) + 1;
126
+ if (!bodyStart) return { start, end: text.length, bodyStart: text.length, body: "" };
127
+ const rest = text.slice(bodyStart);
128
+ const next = /^(?=\S[^\r\n]*:)/m.exec(rest);
129
+ const end = next ? bodyStart + next.index : text.length;
130
+ return { start, bodyStart, end, body: text.slice(bodyStart, end) };
131
+ }
132
+
133
+ function scalar(value) {
134
+ return JSON.stringify(value);
135
+ }
136
+
137
+ function serverBlock(name, command) {
138
+ const words = command.command === "node" ? [command.script] : command.args;
139
+ const lines = [` ${name}:`, ` command: ${scalar(command.command)}`];
140
+ if (words?.length) lines.push(" args:", ...words.map((arg) => ` - ${scalar(arg)}`));
141
+ lines.push(" enabled: true", ` # ${UPGRADE_VERSION}`);
142
+ return `${lines.join("\n")}\n`;
143
+ }
144
+
145
+ function mergeMcp(text, desired) {
146
+ text = text.replace(
147
+ /^(mcp_servers:)\s*\{\}\s*(#.*)?$/m,
148
+ (_line, head, comment) => `${head}${comment ? ` ${comment}` : ""}`,
149
+ );
150
+ const block = topLevelBlock(text, "mcp_servers");
151
+ if (!block) {
152
+ const prefix = text.length && !text.endsWith("\n") ? "\n" : "";
153
+ return `${text}${prefix}mcp_servers:\n${[...desired].map(([n, c]) => serverBlock(n, c)).join("")}`;
154
+ }
155
+ let body = block.body;
156
+ for (const [name, command] of desired) {
157
+ const child = new RegExp(`^ ${name}:[^\\S\\r\\n]*(?:#.*)?\\r?\\n(?:^(?: {3,}|\\s*$).*\\r?\\n?)*`, "m");
158
+ const replacement = serverBlock(name, command);
159
+ body = child.test(body) ? body.replace(child, replacement) : `${body}${body && !body.endsWith("\n") ? "\n" : ""}${replacement}`;
160
+ }
161
+ return `${text.slice(0, block.bodyStart)}${body}${text.slice(block.end)}`;
162
+ }
163
+
164
+ function mergeEnabledPlugin(text, pluginId) {
165
+ text = text.replace(
166
+ /^(plugins:)\s*\{\}\s*(#.*)?$/m,
167
+ (_line, head, comment) => `${head}${comment ? ` ${comment}` : ""}`,
168
+ );
169
+ const item = ` - ${scalar(pluginId)}\n`;
170
+ const block = topLevelBlock(text, "plugins");
171
+ if (!block) {
172
+ const prefix = text.length && !text.endsWith("\n") ? "\n" : "";
173
+ return `${text}${prefix}plugins:\n enabled:\n${item}`;
174
+ }
175
+ let body = block.body;
176
+ const flow = /^ enabled:\s*\[([^\]]*)\](.*)$/m.exec(body);
177
+ if (flow) {
178
+ const values = flow[1].split(",").map((value) => value.trim().replace(/^["']|["']$/g, ""));
179
+ if (!values.includes(pluginId)) {
180
+ const joined = flow[1].trim() ? `${flow[1].trimEnd()}, ${scalar(pluginId)}` : scalar(pluginId);
181
+ body = body.replace(flow[0], ` enabled: [${joined}]${flow[2]}`);
182
+ }
183
+ } else {
184
+ const sequence = /^ enabled:\s*(?:#.*)?\r?\n((?:^ {4}-.*\r?\n?)*)/m.exec(body);
185
+ if (sequence) {
186
+ const values = sequence[1].split(/\r?\n/).map((line) => line.replace(/^\s*-\s*/, "").trim().replace(/^["']|["']$/g, ""));
187
+ if (!values.includes(pluginId)) body = body.replace(sequence[0], `${sequence[0]}${item}`);
188
+ } else {
189
+ body = `${body}${body && !body.endsWith("\n") ? "\n" : ""} enabled:\n${item}`;
190
+ }
191
+ }
192
+ return `${text.slice(0, block.bodyStart)}${body}${text.slice(block.end)}`;
193
+ }
194
+
195
+ function writeAtomic(file, body, report) {
196
+ const present = exists(file);
197
+ const old = present ? fs.readFileSync(file, "utf8") : null;
198
+ if (old === body) { report.unchanged.push(file); return; }
199
+ (present ? report.updated : report.created).push(file);
200
+ if (!report.applied) return;
201
+ fs.mkdirSync(path.dirname(file), { recursive: true });
202
+ if (present) {
203
+ const backup = backupName(file);
204
+ fs.copyFileSync(file, backup);
205
+ report.backups.push({ path: backup, original: file });
206
+ }
207
+ const tmp = tempSibling(file);
208
+ try {
209
+ fs.writeFileSync(tmp, body, { mode: present ? fs.statSync(file).mode : 0o600 });
210
+ fs.renameSync(tmp, file);
211
+ } catch (error) {
212
+ if (exists(tmp)) fs.rmSync(tmp, { force: true });
213
+ throw error;
214
+ }
215
+ }
216
+
217
+ function resolveControl(packageRoot, explicit) {
218
+ if (explicit) {
219
+ const [command, ...args] = explicit;
220
+ return { command, args };
221
+ }
222
+ const candidates = [
223
+ path.join(packageRoot, "bin", "oracle-control-mcp.mjs"),
224
+ path.join(packageRoot, "plugins", "oracle-owner-gate", "bin", "oracle-control-mcp.mjs"),
225
+ path.join(packageRoot, "plugins", "oracle-owner-gate", "oracle-control-mcp.mjs"),
226
+ // Control MCP ships with the local operator package, not the prepare-only public root.
227
+ path.join(packageRoot, "..", "@oracle-agent", "operator", "bin", "oracle-control-mcp.mjs"),
228
+ path.join(packageRoot, "..", "..", "@oracle-agent", "operator", "bin", "oracle-control-mcp.mjs"),
229
+ ];
230
+ for (const script of candidates) {
231
+ if (exists(script) && fs.statSync(script).isFile()) return { command: "node", script: path.resolve(script) };
232
+ }
233
+ try {
234
+ const require = createRequire(path.join(packageRoot, "package.json"));
235
+ const operatorPkg = path.dirname(require.resolve("@oracle-agent/operator/package.json"));
236
+ const script = path.join(operatorPkg, "bin", "oracle-control-mcp.mjs");
237
+ if (exists(script) && fs.statSync(script).isFile()) return { command: "node", script: path.resolve(script) };
238
+ } catch {}
239
+ return null;
240
+ }
241
+
242
+ export function upgradeProfiles({ hermesHome, packageRoot, only = null, apply = false, controlCommand = null }) {
243
+ const profilesRoot = path.join(hermesHome, "profiles");
244
+ const report = { ok: true, applied: apply, version: UPGRADE_VERSION, hermesHome, packageRoot, profiles: [], created: [], updated: [], unchanged: [], backups: [] };
245
+ let profiles = exists(profilesRoot) ? fs.readdirSync(profilesRoot, { withFileTypes: true }).filter((e) => e.isDirectory()).map((e) => e.name).sort() : [];
246
+ if (only) profiles = profiles.filter((name) => name === only);
247
+ if (only && profiles.length === 0) throw new Error(`profile not found: ${only}`);
248
+ report.profiles = profiles;
249
+
250
+ // Validate every selected config before planning or performing any write.
251
+ const configs = new Map();
252
+ for (const profile of profiles) {
253
+ const file = path.join(profilesRoot, profile, "config.yaml");
254
+ const text = exists(file) ? fs.readFileSync(file, "utf8") : "";
255
+ validateYaml(text, file);
256
+ configs.set(profile, text);
257
+ }
258
+
259
+ const skillSource = path.join(packageRoot, "skills", "oracle-action-semantics");
260
+ if (!exists(skillSource)) throw new Error(`required Oracle skill is missing: ${skillSource}`);
261
+ const pluginSource = path.join(packageRoot, "plugins", "oracle-owner-gate");
262
+ const control = resolveControl(packageRoot, controlCommand);
263
+ const dataScript = path.join(packageRoot, "bin", "oracle-data-mcp.mjs");
264
+ if (!exists(dataScript)) throw new Error(`oracle-data MCP command is missing: ${dataScript}`);
265
+
266
+ for (const profile of profiles) {
267
+ const root = path.join(profilesRoot, profile);
268
+ installTree(skillSource, path.join(root, "skills", "oracle-action-semantics"), apply, report);
269
+ if (exists(pluginSource)) installTree(pluginSource, path.join(root, "plugins", "oracle-owner-gate"), apply, report);
270
+ const desired = new Map([["oracle-data", { command: "node", script: dataScript }]]);
271
+ if (control) desired.set("oracle-control", control);
272
+ let config = mergeMcp(configs.get(profile), desired);
273
+ if (exists(pluginSource)) config = mergeEnabledPlugin(config, "oracle-owner-gate");
274
+ writeAtomic(path.join(root, "config.yaml"), config, report);
275
+ }
276
+ return report;
277
+ }
@@ -215,7 +215,56 @@ export const CHAIN_CONFIGS = Object.freeze([
215
215
  name: "Robinhood Chain",
216
216
  rpcEnv: ["RH_CHAIN_RPC", "ROBINHOOD_RPC_URL"],
217
217
  nativeCurrency: { symbol: "ETH", decimals: 18 },
218
- venues: [],
218
+ // DexScreener does index this chain under the slug "robinhood" (verified live
219
+ // 2026-07-31: a CASHCAT search returns pairs tagged chainId "robinhood"). Without
220
+ // the slug, resolvePools reported UNAVAILABLE on every RH token even though the
221
+ // data was there.
222
+ dexscreenerSlug: "robinhood",
223
+ venueKind: "uniswap-v3",
224
+ wrappedNative: "0x0bd7d308f8e1639fab988df18a8011f41eacad73",
225
+ venues: [
226
+ {
227
+ kind: "quoter",
228
+ address: "0x33e885ed0ec9bf04ecfb19341582aadcb4c8a9e7",
229
+ label: "Uniswap V3 QuoterV2",
230
+ verified: {
231
+ method:
232
+ "functional probe, not a codesize check: quoteExactInputSingle returned a " +
233
+ "live sane price (WETH->USDG fee 100 quoted 1866.58 USDG, and USDG->CASHCAT " +
234
+ "fee 10000 quoted a live amount). A contract that correctly prices known pairs " +
235
+ "IS a working V3 quoter",
236
+ source: "live eth_call against rpc.mainnet.chain.robinhood.com",
237
+ date: "2026-07-31",
238
+ chainId: 4663,
239
+ },
240
+ },
241
+ {
242
+ kind: "router",
243
+ address: "0xcaf681a66d020601342297493863e78c959e5cb2",
244
+ label: "Uniswap V3 SwapRouter02",
245
+ verified: {
246
+ method:
247
+ "eth_getCode returned real bytecode (24497 bytes) on this chain and the paired " +
248
+ "quoter at the same deployment passed a live functional quote",
249
+ source: "live eth_getCode against rpc.mainnet.chain.robinhood.com",
250
+ date: "2026-07-31",
251
+ chainId: 4663,
252
+ },
253
+ },
254
+ {
255
+ kind: "factory",
256
+ address: "0x1f7d7550b1b028f7571e69a784071f0205fd2efa",
257
+ label: "Uniswap V3 Factory",
258
+ verified: {
259
+ method:
260
+ "eth_getCode returned real bytecode (24535 bytes) and a PoolCreated log scan " +
261
+ "over this factory returned 76 pools in ~9000 recent blocks",
262
+ source: "live eth_getLogs against rpc.mainnet.chain.robinhood.com",
263
+ date: "2026-07-31",
264
+ chainId: 4663,
265
+ },
266
+ },
267
+ ],
219
268
  },
220
269
  {
221
270
  key: "base",
@@ -129,6 +129,7 @@ export function assertVaultAttestation(attestation, tx = {}, { chainId, nowMs =
129
129
  export function assertVaultApprovalAttestation(attestation, tx = {}, guard = {}, { chainId, nowMs = Date.now(), secret } = {}) {
130
130
  if (!attestation || attestation.mode !== "vault-attestation") throw new Error("vault attestation required");
131
131
  if (String(attestation.action) !== "deposit") throw new Error("vault approval requires deposit attestation");
132
+ assertFreshWindow(attestation, nowMs, "vault approval attestation");
132
133
  if (Number(attestation.expiresAtMs) <= Number(nowMs)) throw new Error("vault attestation expired");
133
134
  const expected = hmac(attestationSecret(secret), canonicalJson(unsigned(attestation)));
134
135
  if (!sameSignature(attestation.signature, expected)) throw new Error("vault attestation signature mismatch");