chain-insights 0.85.2 → 0.92.0
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 +2 -0
- package/bin/install.cjs +2 -1
- package/dist/{active-q3yViZhc.cjs → active-COPA14FA.cjs} +2 -16
- package/dist/{active-D2aabYRF.mjs → active-CyC4jFka.mjs} +2 -7
- package/dist/{active-D2aabYRF.mjs.map → active-CyC4jFka.mjs.map} +1 -1
- package/dist/address-card-C-NB03XP.cjs +218 -0
- package/dist/address-card-LYaT5yz0.mjs +190 -0
- package/dist/address-card-LYaT5yz0.mjs.map +1 -0
- package/dist/address-risk-DPuXBsvH.cjs +806 -0
- package/dist/address-risk-Da6FsfGx.mjs +653 -0
- package/dist/address-risk-Da6FsfGx.mjs.map +1 -0
- package/dist/{capabilities-Mxa4oQdd.cjs → capabilities-DkNreyv7.cjs} +1 -1
- package/dist/{capabilities-bZOr5Ads.mjs → capabilities-w5bNR7F9.mjs} +2 -2
- package/dist/{capabilities-bZOr5Ads.mjs.map → capabilities-w5bNR7F9.mjs.map} +1 -1
- package/dist/cli.cjs +138 -46
- package/dist/cli.mjs +138 -46
- package/dist/cli.mjs.map +1 -1
- package/dist/{deployer-screen-B5yrXZGo.mjs → deployer-screen-Bkw_sz94.mjs} +3 -3
- package/dist/{deployer-screen-B5yrXZGo.mjs.map → deployer-screen-Bkw_sz94.mjs.map} +1 -1
- package/dist/{deployer-screen-0SOQ_HFf.cjs → deployer-screen-CFLi7OeH.cjs} +2 -2
- package/dist/{dex-registry-BY67f4Ul.mjs → dex-registry-Bkri0--q.mjs} +10 -2
- package/dist/{dex-registry-BY67f4Ul.mjs.map → dex-registry-Bkri0--q.mjs.map} +1 -1
- package/dist/{dex-registry-BhGJUG9_.cjs → dex-registry-CyR3GyRr.cjs} +20 -0
- package/dist/{dex-tool-7BK_gD6H.mjs → dex-tool-D0K_Qx4N.mjs} +4 -4
- package/dist/dex-tool-D0K_Qx4N.mjs.map +1 -0
- package/dist/{dex-tool-Be9NAuD8.cjs → dex-tool-DQ5Eg0LO.cjs} +3 -3
- package/dist/{exchange-deposit-check-C5MseGlZ.cjs → exchange-deposit-check-BNzkwQeW.cjs} +18 -18
- package/dist/{exchange-deposit-check-CXHZCHWW.mjs → exchange-deposit-check-DIALj2sm.mjs} +19 -19
- package/dist/exchange-deposit-check-DIALj2sm.mjs.map +1 -0
- package/dist/{exchange-registry-CT0rRW__.cjs → exchange-registry-CEgkeQV1.cjs} +16 -93
- package/dist/{exchange-registry-CoLgHw6d.mjs → exchange-registry-Dr5UtcT5.mjs} +17 -94
- package/dist/exchange-registry-Dr5UtcT5.mjs.map +1 -0
- package/dist/{exchange-tool-Dc46SJ49.mjs → exchange-tool-B7E29YoQ.mjs} +4 -4
- package/dist/exchange-tool-B7E29YoQ.mjs.map +1 -0
- package/dist/{exchange-tool-B2SMeC5f.cjs → exchange-tool-CXaUBAd2.cjs} +3 -3
- package/dist/{graph-schema-CcrYPpSv.cjs → graph-schema-Bn3txQCj.cjs} +115 -12
- package/dist/{graph-schema-CRQuKya1.mjs → graph-schema-DvABR1yl.mjs} +97 -12
- package/dist/graph-schema-DvABR1yl.mjs.map +1 -0
- package/dist/{layer-routing-YDj-ynG9.cjs → layer-routing-j48SQ8Wk.cjs} +2 -2
- package/dist/{layer-routing-DCJVNN6O.mjs → layer-routing-r4IbIQSr.mjs} +3 -3
- package/dist/layer-routing-r4IbIQSr.mjs.map +1 -0
- package/dist/mcp-proxy.cjs +62 -15
- package/dist/mcp-proxy.d.cts.map +1 -1
- package/dist/mcp-proxy.d.mts.map +1 -1
- package/dist/mcp-proxy.mjs +62 -15
- package/dist/mcp-proxy.mjs.map +1 -1
- package/dist/public-file-BISyAesm.mjs +133 -0
- package/dist/public-file-BISyAesm.mjs.map +1 -0
- package/dist/public-file-DDp2CrUl.cjs +138 -0
- package/dist/{request-timeout-DxwNijQD.cjs → request-timeout-BXiIt9Jy.cjs} +0 -1
- package/dist/{request-timeout-K3ljP0pa.mjs → request-timeout-DetG2xO4.mjs} +2 -2
- package/dist/{request-timeout-K3ljP0pa.mjs.map → request-timeout-DetG2xO4.mjs.map} +1 -1
- package/dist/{token-lookup-Cf59VdGe.mjs → token-lookup-Ck0q7crJ.mjs} +2 -2
- package/dist/{token-lookup-Cf59VdGe.mjs.map → token-lookup-Ck0q7crJ.mjs.map} +1 -1
- package/dist/{token-lookup-DqjSRIxd.cjs → token-lookup-DLe4erP9.cjs} +1 -1
- package/dist/token-risk-CpMfFRoY.cjs +1004 -0
- package/dist/token-risk-DhnJc2kJ.mjs +971 -0
- package/dist/token-risk-DhnJc2kJ.mjs.map +1 -0
- package/dist/{tool-visibility-D8Up081E.cjs → tool-visibility-BCa-tmyZ.cjs} +11 -2
- package/dist/{tool-visibility-DuTds7V4.mjs → tool-visibility-BstrSl4s.mjs} +12 -3
- package/dist/tool-visibility-BstrSl4s.mjs.map +1 -0
- package/docs/contributing.md +10 -8
- package/docs/development.md +5 -5
- package/docs/evals.md +16 -1
- package/docs/graph-query-compatibility.md +15 -2
- package/docs/graph-tools.md +44 -6
- package/docs/mcp-proxy.md +189 -8
- package/docs/stability.md +4 -5
- package/docs/testing.md +76 -0
- package/package.json +1 -1
- package/registry/README.md +20 -5
- package/registry/address-card.json +680 -0
- package/skills/chain-insights-address-risk/SKILL.md +61 -0
- package/skills/chain-insights-address-risk/agents/openai.yaml +4 -0
- package/skills/chain-insights-aml-exchange/SKILL.md +9 -7
- package/skills/chain-insights-cypher/SKILL.md +79 -3
- package/skills/chain-insights-token-risk/SKILL.md +81 -0
- package/skills/chain-insights-token-risk/agents/openai.yaml +4 -0
- package/skills/chain-insights-virtuals/reference.md +1 -1
- package/dist/dex-tool-7BK_gD6H.mjs.map +0 -1
- package/dist/exchange-deposit-check-CXHZCHWW.mjs.map +0 -1
- package/dist/exchange-registry-CoLgHw6d.mjs.map +0 -1
- package/dist/exchange-tool-Dc46SJ49.mjs.map +0 -1
- package/dist/graph-schema-CRQuKya1.mjs.map +0 -1
- package/dist/layer-routing-DCJVNN6O.mjs.map +0 -1
- package/dist/public-tools-CBszU2oX.cjs +0 -1334
- package/dist/public-tools-DVhUjSDV.mjs +0 -1333
- package/dist/public-tools-DVhUjSDV.mjs.map +0 -1
- package/dist/tool-visibility-DuTds7V4.mjs.map +0 -1
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.mjs";
|
|
2
2
|
import { n as chainInsightsHome } from "./cache-location-DxTTqBwk.mjs";
|
|
3
|
-
import { a as NEAR_MIN_ALIAS_LENGTH,
|
|
3
|
+
import { a as NEAR_MIN_ALIAS_LENGTH, f as normaliseName, i as NEAR_DISTANCE, o as damerauLevenshtein, p as normalizeDexNetwork } from "./dex-registry-Bkri0--q.mjs";
|
|
4
|
+
import { t as loadPublicFile } from "./public-file-BISyAesm.mjs";
|
|
4
5
|
import { fileURLToPath } from "node:url";
|
|
5
6
|
import path from "node:path";
|
|
6
7
|
import { existsSync, readFileSync } from "node:fs";
|
|
7
|
-
import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
8
8
|
// src/mcp/exchange-registry.ts
|
|
9
9
|
/**
|
|
10
10
|
* The centralized exchange lookup, as meta_exchange_lookup and
|
|
@@ -23,7 +23,8 @@ import { mkdir, readFile, rename, writeFile } from "node:fs/promises";
|
|
|
23
23
|
* written by scripts/pin-exchange-registry.mjs and held to the rules below by
|
|
24
24
|
* tests/exchange-registry.test.ts.
|
|
25
25
|
*
|
|
26
|
-
* The proxy reads the file
|
|
26
|
+
* The proxy reads the file through the shared public file loader
|
|
27
|
+
* (src/mcp/public-file.ts), as it reads the address card dictionary:
|
|
27
28
|
*
|
|
28
29
|
* cached ~/.chain-insights/cache/exchange-registry-<network>.json, younger than one hour
|
|
29
30
|
* fetched the copy on main, https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/exchanges/<network>.json,
|
|
@@ -108,42 +109,6 @@ function readPackagedExchangeRegistry(network, dir = packagedExchangeRegistryDir
|
|
|
108
109
|
if (fault) throw new Error(`the packaged exchange lookup registry/exchanges/${network}.json is malformed: ${fault}`);
|
|
109
110
|
return parsed;
|
|
110
111
|
}
|
|
111
|
-
async function readCache(network) {
|
|
112
|
-
try {
|
|
113
|
-
const parsed = JSON.parse(await readFile(exchangeRegistryCachePath(network), "utf8"));
|
|
114
|
-
if (!isRecord(parsed) || typeof parsed.checked_at_ms !== "number") return null;
|
|
115
|
-
if (parsed.source !== "fetched" && parsed.source !== "packaged") return null;
|
|
116
|
-
if (exchangeRegistryFault(parsed.document, network) !== null) return null;
|
|
117
|
-
return parsed;
|
|
118
|
-
} catch {
|
|
119
|
-
return null;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
async function writeCache(network, file) {
|
|
123
|
-
const target = exchangeRegistryCachePath(network);
|
|
124
|
-
await mkdir(path.dirname(target), { recursive: true });
|
|
125
|
-
const scratch = `${target}.${process.pid}.tmp`;
|
|
126
|
-
await writeFile(scratch, JSON.stringify(file, null, 2) + "\n", { mode: 384 });
|
|
127
|
-
await rename(scratch, target);
|
|
128
|
-
}
|
|
129
|
-
async function fetchDocument(network, options) {
|
|
130
|
-
const url = exchangeRegistryUrl(network, options.env);
|
|
131
|
-
let response;
|
|
132
|
-
try {
|
|
133
|
-
response = await (options.fetch ?? fetch)(url, { signal: AbortSignal.timeout(options.budgetMs ?? DEX_REGISTRY_FETCH_BUDGET_MS) });
|
|
134
|
-
} catch (err) {
|
|
135
|
-
return { fault: `${url} unreachable: ${err instanceof Error ? err.message : String(err)}` };
|
|
136
|
-
}
|
|
137
|
-
if (response.status !== 200) return { fault: `${url} answered HTTP ${response.status}` };
|
|
138
|
-
let parsed;
|
|
139
|
-
try {
|
|
140
|
-
parsed = JSON.parse(await response.text());
|
|
141
|
-
} catch {
|
|
142
|
-
return { fault: `${url} is not JSON` };
|
|
143
|
-
}
|
|
144
|
-
const fault = exchangeRegistryFault(parsed, network);
|
|
145
|
-
return fault ? { fault: `${url} is malformed: ${fault}` } : { document: parsed };
|
|
146
|
-
}
|
|
147
112
|
/** A network with no file: no rows, so every lookup on it answers with an empty list. */
|
|
148
113
|
function emptyDocument(network) {
|
|
149
114
|
return {
|
|
@@ -159,63 +124,21 @@ const defaultLog = (line) => {
|
|
|
159
124
|
};
|
|
160
125
|
/**
|
|
161
126
|
* The lookup file of one network: the fresh cache, else the public file, else
|
|
162
|
-
* the stale cache, else the packaged copy. A packaged
|
|
163
|
-
* version than the cache or the public file wins. A network
|
|
164
|
-
* anywhere answers with no rows; it never throws for a
|
|
127
|
+
* the stale cache, else the packaged copy (src/mcp/public-file.ts). A packaged
|
|
128
|
+
* copy with a higher version than the cache or the public file wins. A network
|
|
129
|
+
* with no file anywhere answers with no rows; it never throws for a
|
|
130
|
+
* well-formed network.
|
|
165
131
|
*/
|
|
166
132
|
async function loadExchangeRegistry(rawNetwork, options = {}) {
|
|
167
133
|
const network = normalizeDexNetwork(rawNetwork);
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
source
|
|
177
|
-
};
|
|
178
|
-
const cache = await readCache(network);
|
|
179
|
-
const age = cache ? now() - cache.checked_at_ms : Infinity;
|
|
180
|
-
if (cache && age >= 0 && age < DEX_REGISTRY_TTL_MS) return pick(cache.document, cache.source === "fetched" ? "cached" : "packaged");
|
|
181
|
-
const save = async (file) => {
|
|
182
|
-
try {
|
|
183
|
-
await writeCache(network, file);
|
|
184
|
-
} catch (err) {
|
|
185
|
-
log(`the cache ${exchangeRegistryCachePath(network)} could not be written: ${err instanceof Error ? err.message : String(err)}`);
|
|
186
|
-
}
|
|
187
|
-
};
|
|
188
|
-
const outcome = await fetchDocument(network, options);
|
|
189
|
-
const checked = now();
|
|
190
|
-
if ("document" in outcome) {
|
|
191
|
-
await save({
|
|
192
|
-
document: outcome.document,
|
|
193
|
-
checked_at_ms: checked,
|
|
194
|
-
source: "fetched"
|
|
195
|
-
});
|
|
196
|
-
return pick(outcome.document, "fetched");
|
|
197
|
-
}
|
|
198
|
-
if (cache) {
|
|
199
|
-
log(outcome.fault);
|
|
200
|
-
await save({
|
|
201
|
-
...cache,
|
|
202
|
-
checked_at_ms: checked
|
|
203
|
-
});
|
|
204
|
-
return pick(cache.document, cache.source === "fetched" ? "cached" : "packaged");
|
|
205
|
-
}
|
|
206
|
-
if (packaged) {
|
|
207
|
-
log(outcome.fault);
|
|
208
|
-
await save({
|
|
209
|
-
document: packaged,
|
|
210
|
-
checked_at_ms: checked,
|
|
211
|
-
source: "packaged"
|
|
212
|
-
});
|
|
213
|
-
return {
|
|
214
|
-
document: packaged,
|
|
215
|
-
source: "packaged"
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
return {
|
|
134
|
+
return await loadPublicFile({
|
|
135
|
+
url: exchangeRegistryUrl(network, options.env),
|
|
136
|
+
cachePath: exchangeRegistryCachePath(network),
|
|
137
|
+
fault: (value) => exchangeRegistryFault(value, network),
|
|
138
|
+
packaged: readPackagedExchangeRegistry(network, options.packagedDir),
|
|
139
|
+
version: (document) => document.registry_version,
|
|
140
|
+
log: options.log ?? defaultLog
|
|
141
|
+
}, options) ?? {
|
|
219
142
|
document: emptyDocument(network),
|
|
220
143
|
source: "none"
|
|
221
144
|
};
|
|
@@ -316,4 +239,4 @@ function exchangeOfLabels(labels, rows) {
|
|
|
316
239
|
}
|
|
317
240
|
export { matchExchange as a, loadExchangeRegistry as i, exchangeOfWallet as n, exchange_registry_exports as r, exchangeOfLabels as t };
|
|
318
241
|
|
|
319
|
-
//# sourceMappingURL=exchange-registry-
|
|
242
|
+
//# sourceMappingURL=exchange-registry-Dr5UtcT5.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exchange-registry-Dr5UtcT5.mjs","names":[],"sources":["../src/mcp/exchange-registry.ts"],"sourcesContent":["/**\n * The centralized exchange lookup, as meta_exchange_lookup and\n * aml_exchange_deposit_check read it.\n *\n * registry/exchanges/<network>.json lists every centralized exchange the\n * indexer-evm-cex registry of the network names, with its id, its display name\n * and its aliases, and under each only the wallets proven on that network's\n * own data: hot wallets that receive the sweeps of its deposits, gas wallets\n * that top deposits up, and spenders that pull approved deposits. Each wallet\n * carries the payer proof and the block it was proven at, always above 0. An\n * exchange tag, or a wallet of another network at the same address, never\n * enters the file: it stays in the indexer's registry and reaches the graph.\n * So an exchange may list no wallet; its deposits, its SWEPT links and its\n * hot wallets are read from the graph (aml_exchange_deposit_check). It is\n * written by scripts/pin-exchange-registry.mjs and held to the rules below by\n * tests/exchange-registry.test.ts.\n *\n * The proxy reads the file through the shared public file loader\n * (src/mcp/public-file.ts), as it reads the address card dictionary:\n *\n * cached ~/.chain-insights/cache/exchange-registry-<network>.json, younger than one hour\n * fetched the copy on main, https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/exchanges/<network>.json,\n * within 3 s, at most once an hour per network\n * packaged registry/exchanges/<network>.json of the installed package\n *\n * A fetched file is used only when it passes the rules. A row merged on main\n * reaches every running proxy within the hour, with no release. A lookup is a\n * proxy tool and never a table or a graph property.\n */\n\nimport { existsSync, readFileSync } from 'node:fs'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { chainInsightsHome } from './cache-location.js'\nimport {\n NEAR_DISTANCE,\n NEAR_MIN_ALIAS_LENGTH,\n damerauLevenshtein,\n normalizeDexNetwork,\n normaliseName,\n} from './dex-registry.js'\nimport { loadPublicFile, type PublicFileOptions } from './public-file.js'\n\nexport const EXCHANGE_REGISTRY_SCHEMA = 'chain-insights.exchange-registry.v1' as const\nexport const EXCHANGE_REGISTRY_URL_ENV = 'CHAIN_INSIGHTS_EXCHANGE_REGISTRY_URL'\nexport const EXCHANGE_REGISTRY_PUBLIC_URL =\n 'https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/exchanges/{network}.json'\n\nexport const WALLET_ROLES = ['hot_wallet', 'gas_wallet', 'spender'] as const\nexport type WalletRole = (typeof WALLET_ROLES)[number]\nexport type ExchangeRegistrySource = 'fetched' | 'cached' | 'packaged' | 'none'\n\n/** One wallet of an exchange, with its evidence. */\nexport interface ExchangeWallet {\n address: string\n role: WalletRole\n /** What the chain showed: payers, the sample that pays only this exchange, the window. */\n evidence: string\n /** The block the payer proof is pinned at, always above 0. */\n proven_at_block: number\n}\n\n/** One exchange of the lookup file. */\nexport interface ExchangeEntry {\n /** The stable lower-case id, the word the graph's labels carry. */\n exchange: string\n display: string\n aliases: string[]\n wallets: ExchangeWallet[]\n}\n\nexport interface ExchangeRegistryDocument {\n schema: typeof EXCHANGE_REGISTRY_SCHEMA\n network: string\n registry_version: number\n recorded_on: string\n rows: ExchangeEntry[]\n}\n\nexport interface LoadedExchangeRegistry {\n document: ExchangeRegistryDocument\n source: ExchangeRegistrySource\n}\n\nconst ADDRESS_RE = /^0x[0-9a-f]{40}$/\nconst EXCHANGE_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object' && !Array.isArray(value)\n}\n\nconst isStringList = (value: unknown): value is string[] =>\n Array.isArray(value) && value.every((entry) => typeof entry === 'string')\n\n/** The fault of a lookup file, or null when it is valid for the network. */\nexport function exchangeRegistryFault(value: unknown, network: string): string | null {\n if (!isRecord(value)) return 'the file is not a JSON object'\n if (value.schema !== EXCHANGE_REGISTRY_SCHEMA) {\n return `schema is ${JSON.stringify(value.schema)}, not ${EXCHANGE_REGISTRY_SCHEMA}`\n }\n if (value.network !== network)\n return `network is ${JSON.stringify(value.network)}, not ${network}`\n if (!Number.isInteger(value.registry_version) || (value.registry_version as number) < 0) {\n return 'registry_version is not a whole number'\n }\n if (typeof value.recorded_on !== 'string' || !/^\\d{4}-\\d{2}-\\d{2}$/.test(value.recorded_on)) {\n return 'recorded_on is not a YYYY-MM-DD day'\n }\n if (!Array.isArray(value.rows) || value.rows.length === 0) return 'rows is empty'\n const ids = new Set<string>()\n const owners = new Map<string, string>()\n for (const [index, row] of value.rows.entries()) {\n const at = `rows[${index}]`\n if (!isRecord(row)) return `${at} is not an object`\n if (typeof row.exchange !== 'string' || !EXCHANGE_RE.test(row.exchange))\n return `${at}.exchange is not an id: ${String(row.exchange)}`\n if (ids.has(row.exchange)) return `${at}.exchange ${row.exchange} is listed twice`\n ids.add(row.exchange)\n if (typeof row.display !== 'string' || row.display.trim() === '')\n return `${at} (${row.exchange}) has no display`\n if (!isStringList(row.aliases)) return `${at} (${row.exchange}) aliases is not a list of names`\n if (!Array.isArray(row.wallets)) return `${at} (${row.exchange}) wallets is not a list`\n for (const wallet of row.wallets) {\n if (!isRecord(wallet)) return `${at} (${row.exchange}) has a wallet that is not an object`\n const address = wallet.address\n if (typeof address !== 'string' || !ADDRESS_RE.test(address))\n return `${at} (${row.exchange}) address ${String(address)} is not lowercase 0x plus 40 hex characters`\n if (!WALLET_ROLES.includes(wallet.role as WalletRole))\n return `${at} (${row.exchange}) role ${String(wallet.role)} is not hot_wallet, gas_wallet or spender`\n if (typeof wallet.evidence !== 'string' || wallet.evidence.trim() === '')\n return `${at} (${row.exchange}) ${address} has no evidence`\n if (!Number.isInteger(wallet.proven_at_block) || (wallet.proven_at_block as number) <= 0)\n return `${at} (${row.exchange}) ${address} proven_at_block is not a block above 0: only a wallet proven on this chain is listed`\n const owner = owners.get(address)\n if (owner !== undefined)\n return `${at} (${row.exchange}) ${address} is also a wallet of ${owner}`\n owners.set(address, row.exchange)\n }\n }\n return null\n}\n\n/** The URL of the served copy: the public file on main, or the override with {network} filled in. */\nexport function exchangeRegistryUrl(network: string, env: NodeJS.ProcessEnv = process.env): string {\n const override = env[EXCHANGE_REGISTRY_URL_ENV]?.trim()\n const template = override || EXCHANGE_REGISTRY_PUBLIC_URL\n if (template.includes('{network}')) return template.replaceAll('{network}', network)\n return template.endsWith('/') ? `${template}${network}.json` : template\n}\n\nexport function exchangeRegistryCachePath(network: string): string {\n return path.join(chainInsightsHome(), 'cache', `exchange-registry-${network}.json`)\n}\n\n/** registry/exchanges of the installed package: next to dist/, or the repository root when run from source. */\nexport function packagedExchangeRegistryDir(): string {\n const candidates = [\n fileURLToPath(new URL('../registry/exchanges', import.meta.url)),\n fileURLToPath(new URL('../../registry/exchanges', import.meta.url)),\n ]\n return (\n candidates.find((candidate) => existsSync(path.join(candidate, 'robinhood.json'))) ??\n candidates[0]!\n )\n}\n\n/** The packaged copy of a network, or null when the package carries none. A packaged copy that fails the rules throws. */\nexport function readPackagedExchangeRegistry(\n network: string,\n dir: string = packagedExchangeRegistryDir()\n): ExchangeRegistryDocument | null {\n let parsed: unknown\n try {\n parsed = JSON.parse(readFileSync(path.join(dir, `${network}.json`), 'utf8'))\n } catch {\n return null\n }\n const fault = exchangeRegistryFault(parsed, network)\n if (fault)\n throw new Error(\n `the packaged exchange lookup registry/exchanges/${network}.json is malformed: ${fault}`\n )\n return parsed as ExchangeRegistryDocument\n}\n\nexport interface LoadExchangeRegistryOptions extends PublicFileOptions {\n env?: NodeJS.ProcessEnv\n log?: (line: string) => void\n packagedDir?: string\n}\n\n/** A network with no file: no rows, so every lookup on it answers with an empty list. */\nfunction emptyDocument(network: string): ExchangeRegistryDocument {\n return {\n schema: EXCHANGE_REGISTRY_SCHEMA,\n network,\n registry_version: 0,\n recorded_on: '1970-01-01',\n rows: [],\n }\n}\n\nconst defaultLog = (line: string): void => {\n process.stderr.write(`[chain-insights] exchange-registry: ${line}\\n`)\n}\n\n/**\n * The lookup file of one network: the fresh cache, else the public file, else\n * the stale cache, else the packaged copy (src/mcp/public-file.ts). A packaged\n * copy with a higher version than the cache or the public file wins. A network\n * with no file anywhere answers with no rows; it never throws for a\n * well-formed network.\n */\nexport async function loadExchangeRegistry(\n rawNetwork: unknown,\n options: LoadExchangeRegistryOptions = {}\n): Promise<LoadedExchangeRegistry> {\n const network = normalizeDexNetwork(rawNetwork)\n const loaded = await loadPublicFile<ExchangeRegistryDocument>(\n {\n url: exchangeRegistryUrl(network, options.env),\n cachePath: exchangeRegistryCachePath(network),\n fault: (value) => exchangeRegistryFault(value, network),\n packaged: readPackagedExchangeRegistry(network, options.packagedDir),\n version: (document) => document.registry_version,\n log: options.log ?? defaultLog,\n },\n options\n )\n return loaded ?? { document: emptyDocument(network), source: 'none' }\n}\n\n// ─── The name and the address match ───────────────────────────────────────────\n\nexport interface ExchangeCandidate {\n exchange: string\n display: string\n distance: number\n}\n\nexport interface ExchangeMatchResult {\n matched: ExchangeEntry | null\n /** The name as typed, when the match is a near hit. */\n took_for?: string\n candidates: ExchangeCandidate[]\n /** Every exchange the file lists for the network, by display name. */\n listed: string[]\n}\n\n/**\n * One name against the rows, as matchDex does for a DEX: exact on the id, the\n * display and the aliases; then within two letters of an alias of four or more\n * characters. A tie is listed, never guessed.\n */\nexport function matchExchange(name: string, rows: ExchangeEntry[]): ExchangeMatchResult {\n const listed = rows.map((row) => row.display)\n const wanted = normaliseName(name)\n if (!wanted) return { matched: null, candidates: [], listed }\n const exact = rows.filter((row) =>\n [row.exchange, row.display, ...row.aliases].some((written) => normaliseName(written) === wanted)\n )\n if (exact.length === 1) return { matched: exact[0]!, candidates: [], listed }\n if (exact.length > 1) {\n return {\n matched: null,\n candidates: exact.map((row) => ({\n exchange: row.exchange,\n display: row.display,\n distance: 0,\n })),\n listed,\n }\n }\n const near: Array<{ row: ExchangeEntry; distance: number }> = []\n for (const row of rows) {\n const distances = [row.exchange, row.display, ...row.aliases]\n .map(normaliseName)\n .filter((alias) => alias.length >= NEAR_MIN_ALIAS_LENGTH)\n .map((alias) => damerauLevenshtein(wanted, alias))\n if (distances.length === 0) continue\n const distance = Math.min(...distances)\n if (distance <= NEAR_DISTANCE) near.push({ row, distance })\n }\n if (near.length === 0) return { matched: null, candidates: [], listed }\n const least = Math.min(...near.map((hit) => hit.distance))\n const nearest = near.filter((hit) => hit.distance === least)\n if (nearest.length === 1)\n return { matched: nearest[0]!.row, took_for: name.trim(), candidates: [], listed }\n return {\n matched: null,\n candidates: nearest.map(({ row, distance }) => ({\n exchange: row.exchange,\n display: row.display,\n distance,\n })),\n listed,\n }\n}\n\n/** The exchange and the wallet a lowercase address is, or null when no row lists it. */\nexport function exchangeOfWallet(\n address: string,\n rows: ExchangeEntry[]\n): { entry: ExchangeEntry; wallet: ExchangeWallet } | null {\n for (const entry of rows) {\n const wallet = entry.wallets.find((candidate) => candidate.address === address)\n if (wallet) return { entry, wallet }\n }\n return null\n}\n\n/** The exchange a list of graph label words names, or null: the first word that is an id, a display name or an alias. */\nexport function exchangeOfLabels(\n labels: readonly string[],\n rows: ExchangeEntry[]\n): ExchangeEntry | null {\n for (const word of labels) {\n const wanted = normaliseName(word)\n if (!wanted) continue\n const row = rows.find((entry) =>\n [entry.exchange, entry.display, ...entry.aliases].some(\n (name) => normaliseName(name) === wanted\n )\n )\n if (row) return row\n }\n return null\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,MAAa,2BAA2B;AACxC,MAAa,4BAA4B;AACzC,MAAa,+BACX;AAEF,MAAa,eAAe;CAAC;CAAc;CAAc;AAAS;AAoClE,MAAM,aAAa;AACnB,MAAM,cAAc;AAEpB,SAAS,SAAS,OAAkD;CAClE,OAAO,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AACrE;AAEA,MAAM,gBAAgB,UACpB,MAAM,QAAQ,KAAK,KAAK,MAAM,OAAO,UAAU,OAAO,UAAU,QAAQ;;AAG1E,SAAgB,sBAAsB,OAAgB,SAAgC;CACpF,IAAI,CAAC,SAAS,KAAK,GAAG,OAAO;CAC7B,IAAI,MAAM,WAAW,0BACnB,OAAO,aAAa,KAAK,UAAU,MAAM,MAAM,EAAE,QAAQ;CAE3D,IAAI,MAAM,YAAY,SACpB,OAAO,cAAc,KAAK,UAAU,MAAM,OAAO,EAAE,QAAQ;CAC7D,IAAI,CAAC,OAAO,UAAU,MAAM,gBAAgB,KAAM,MAAM,mBAA8B,GACpF,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CAAC,MAC/C,SAAS,cAAc,IAAI,MAAM,MACpC,CACF;EACA,IAAI,KAAK,OAAO;CAClB;CACA,OAAO;AACT"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.mjs";
|
|
2
2
|
import { t as ANSWER_HINT } from "./answer-hint-vOE1O6Lf.mjs";
|
|
3
|
-
import {
|
|
4
|
-
import { a as matchExchange, n as exchangeOfWallet } from "./exchange-registry-
|
|
3
|
+
import { p as normalizeDexNetwork, r as DexRegistryError } from "./dex-registry-Bkri0--q.mjs";
|
|
4
|
+
import { a as matchExchange, n as exchangeOfWallet } from "./exchange-registry-Dr5UtcT5.mjs";
|
|
5
5
|
// src/mcp/exchange-tool.ts
|
|
6
6
|
/**
|
|
7
7
|
* meta_exchange_lookup: a centralized exchange's name becomes its wallets.
|
|
@@ -81,7 +81,7 @@ const ROLE_WORDS = {
|
|
|
81
81
|
};
|
|
82
82
|
function hintFor(result, name, address) {
|
|
83
83
|
const { network } = result;
|
|
84
|
-
if (address !== null && !result.matched) return `${ANSWER_HINT} ${address} is no wallet the exchange lookup lists for ${network}: the file lists only wallets proven on this chain. The graph marks deposits and hot wallets of every exchange: call aml_exchange_deposit_check {network: "${network}", address: "${address}"} to read its
|
|
84
|
+
if (address !== null && !result.matched) return `${ANSWER_HINT} ${address} is no wallet the exchange lookup lists for ${network}: the file lists only wallets proven on this chain. The graph marks deposits and hot wallets of every exchange: call aml_exchange_deposit_check {network: "${network}", address: "${address}"} to read its exchange_role, its exchange and its SWEPT links.`;
|
|
85
85
|
if (address !== null && result.matched) return `${ANSWER_HINT} Say in one line: "${address} is ${result.took_for} of ${result.matched.display} on ${network}." A trail that reaches it has entered the exchange: end the trail there. Never walk on past a hot wallet.`;
|
|
86
86
|
if (name === null) return `${ANSWER_HINT} These are the exchanges the lookup lists for ${network}. Call meta_exchange_lookup with a name for its wallets.`;
|
|
87
87
|
if (result.matched) {
|
|
@@ -176,4 +176,4 @@ async function handleMetaExchangeLookup(args, deps) {
|
|
|
176
176
|
}
|
|
177
177
|
export { META_EXCHANGE_LOOKUP_TOOL as a, META_EXCHANGE_LOOKUP_TITLE as i, META_EXCHANGE_LOOKUP_ANNOTATIONS as n, exchange_tool_exports as o, META_EXCHANGE_LOOKUP_DESCRIPTION as r, handleMetaExchangeLookup as s, EXCHANGE_OPENING_RULE as t };
|
|
178
178
|
|
|
179
|
-
//# sourceMappingURL=exchange-tool-
|
|
179
|
+
//# sourceMappingURL=exchange-tool-B7E29YoQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"exchange-tool-B7E29YoQ.mjs","names":[],"sources":["../src/mcp/exchange-tool.ts"],"sourcesContent":["/**\n * meta_exchange_lookup: a centralized exchange's name becomes its wallets.\n *\n * A local tool of the proxy. It matches the name against the exchange lookup\n * file (src/mcp/exchange-registry.ts) and answers from it alone: no graph read,\n * no cost. The file lists every exchange, and only the wallets proven on that\n * network's own data, each with its payer proof and the block it was proven\n * at. An address instead of a name says whose wallet the address is. Whether\n * an address is a deposit, and which hot wallet it swept into, is read from\n * the graph by aml_exchange_deposit_check.\n *\n * The description below is the contract with every host, Claude Desktop chat\n * included, which reads no skill: it carries the rule the skill\n * chain-insights-aml-exchange opens with. tests/host-parity.test.ts holds it to\n * the skill's trigger words.\n */\n\nimport { ANSWER_HINT } from './answer-hint.js'\nimport { DexRegistryError, normalizeDexNetwork } from './dex-registry.js'\nimport {\n exchangeOfWallet,\n matchExchange,\n type ExchangeCandidate,\n type ExchangeEntry,\n type ExchangeRegistrySource,\n type ExchangeWallet,\n type LoadedExchangeRegistry,\n} from './exchange-registry.js'\n\n/**\n * The rule the exchange skill opens with, carried by both of its doors: where a\n * trail ends, and where an exchange's wallets come from.\n */\nexport const EXCHANGE_OPENING_RULE =\n 'Money that reaches an exchange deposit with a SWEPT link entered that exchange there: the trail ends at the deposit, and never walks on past a hot wallet. ' +\n \"Take an exchange's wallets from meta_exchange_lookup, never from a guess or a graph search by name.\"\n\nexport const META_EXCHANGE_LOOKUP_TOOL = 'meta_exchange_lookup' as const\nexport const META_EXCHANGE_LOOKUP_SCHEMA = 'chain-insights.meta-exchange-lookup.v1' as const\nexport const META_EXCHANGE_LOOKUP_TITLE = 'Centralized exchange by name or address'\nexport const META_EXCHANGE_LOOKUP_DESCRIPTION =\n 'Call this first when a question names a centralized exchange (Binance, Bitget, Bybit, Coinbase, Gate, KuCoin, MEXC, OKX, ...) ' +\n 'and gives no address, or asks which exchange a wallet belongs to. It turns the name into the hot wallets of that exchange on the network, ' +\n \"The file lists only wallets proven on that chain's own data, each with its payer proof and the block it was proven at, and its gas wallets; \" +\n 'an exchange may list none, and its deposits and hot wallets are still marked in the graph. ' +\n 'A misspelling within two letters is taken and named in took_for. Send address instead (0x plus 40 hex, any case) to learn whose hot wallet ' +\n 'or gas wallet it is. It reads no graph and costs nothing. ' +\n `${EXCHANGE_OPENING_RULE} Give a name or an address, not both.`\nexport const META_EXCHANGE_LOOKUP_ANNOTATIONS = {\n readOnlyHint: true,\n idempotentHint: true,\n openWorldHint: false,\n} as const\nexport const META_EXCHANGE_LOOKUP_ARGS = ['network', 'name', 'address'] as const\n\nexport type WalletRow = Omit<ExchangeWallet, 'role'>\n\nexport interface ExchangeMatch {\n exchange: string\n display: string\n hot_wallets: WalletRow[]\n gas_wallets: WalletRow[]\n spenders: WalletRow[]\n}\n\nexport interface ListedExchange {\n exchange: string\n display: string\n hot_wallets: number\n}\n\nexport interface MetaExchangeLookupResult {\n schema: typeof META_EXCHANGE_LOOKUP_SCHEMA\n network: string\n registry_version: number\n registry_source: ExchangeRegistrySource\n recorded_on: string\n matched: ExchangeMatch | null\n /** A near name hit: the name as typed. An address hit: the role the address holds. */\n took_for?: string\n candidates: ExchangeCandidate[]\n /** Every exchange the lookup lists for the network, by display name. */\n listed: string[]\n /** With no name and no address: every listed exchange, with its id and its hot wallet count. */\n exchanges?: ListedExchange[]\n hint: string\n}\n\nexport interface ExchangeToolDependencies {\n loadExchangeRegistry: (network: string) => Promise<LoadedExchangeRegistry>\n}\n\nexport type MetaExchangeLookupToolResult = {\n content: Array<{ type: 'text'; text: string }>\n structuredContent?: Record<string, unknown>\n isError: boolean\n}\n\nfunction isRecord(value: unknown): value is Record<string, unknown> {\n return !!value && typeof value === 'object' && !Array.isArray(value)\n}\n\nfunction errorResult(text: string): MetaExchangeLookupToolResult {\n return { content: [{ type: 'text', text }], isError: true }\n}\n\nfunction textResult(structured: MetaExchangeLookupResult): MetaExchangeLookupToolResult {\n return {\n content: [{ type: 'text', text: JSON.stringify(structured, null, 2) }],\n structuredContent: structured as unknown as Record<string, unknown>,\n isError: false,\n }\n}\n\nconst ADDRESS_FORM = /^0x[0-9a-fA-F]{40}$/\n\nfunction walletsOf(entry: ExchangeEntry, role: ExchangeWallet['role']): WalletRow[] {\n return entry.wallets\n .filter((wallet) => wallet.role === role)\n .map(({ address, evidence, proven_at_block }) => ({ address, evidence, proven_at_block }))\n}\n\n/** One row of the lookup as the tool returns it. */\nexport function exchangeMatchOf(entry: ExchangeEntry): ExchangeMatch {\n return {\n exchange: entry.exchange,\n display: entry.display,\n hot_wallets: walletsOf(entry, 'hot_wallet'),\n gas_wallets: walletsOf(entry, 'gas_wallet'),\n spenders: walletsOf(entry, 'spender'),\n }\n}\n\nconst ROLE_WORDS: Record<ExchangeWallet['role'], string> = {\n hot_wallet: 'a hot wallet',\n gas_wallet: 'a gas wallet',\n spender: 'a spender',\n}\n\nconst NO_SEARCH_BY_NAME = 'Send no graph search by name.'\n\nfunction hintFor(\n result: Omit<MetaExchangeLookupResult, 'hint'>,\n name: string | null,\n address: string | null\n): string {\n const { network } = result\n if (address !== null && !result.matched) {\n return (\n `${ANSWER_HINT} ${address} is no wallet the exchange lookup lists for ${network}: the file lists only wallets proven on this chain. ` +\n `The graph marks deposits and hot wallets of every exchange: call aml_exchange_deposit_check {network: \"${network}\", address: \"${address}\"} ` +\n 'to read its exchange_role, its exchange and its SWEPT links.'\n )\n }\n if (address !== null && result.matched) {\n return (\n `${ANSWER_HINT} Say in one line: \"${address} is ${result.took_for} of ${result.matched.display} on ${network}.\" ` +\n 'A trail that reaches it has entered the exchange: end the trail there. Never walk on past a hot wallet.'\n )\n }\n if (name === null) {\n return `${ANSWER_HINT} These are the exchanges the lookup lists for ${network}. Call meta_exchange_lookup with a name for its wallets.`\n }\n if (result.matched) {\n const { matched } = result\n const took = result.took_for\n ? `Say in one line: \"I took ${matched.display} for ${result.took_for}.\" Ask nothing. `\n : ''\n const count = matched.hot_wallets.length\n const wallets =\n count === 0\n ? `${matched.display} on ${network}: the lookup lists no wallet of it proven on this chain yet; the graph marks its deposits and hot wallets. `\n : `${matched.display} on ${network}: ${count} hot wallet${count === 1 ? '' : 's'} proven on this chain. `\n return (\n `${ANSWER_HINT} ${took}${wallets}` +\n 'A deposit of this exchange has a SWEPT link into its hot wallet. Read SWEPT anchored on the address the trail reached, never on a hot wallet: ' +\n 'a hot wallet links to many thousands of deposits. To check one address, call aml_exchange_deposit_check. ' +\n `${EXCHANGE_OPENING_RULE}`\n )\n }\n if (result.candidates.length > 0) {\n const names = result.candidates\n .map((candidate) => `${candidate.display} (${candidate.exchange})`)\n .join(', ')\n return `${ANSWER_HINT} ${result.candidates.length} exchanges fit \"${name}\": ${names}. Name both or pick one: call meta_exchange_lookup with each id. Never guess one.`\n }\n return (\n `${ANSWER_HINT} The exchange lookup holds no wallet of \"${name}\" for ${network}` +\n (result.listed.length > 0 ? `; it lists ${result.listed.join(', ')}. ` : '. ') +\n 'If the user knows one address of that exchange (a deposit address, or a wallet it paid them from), call aml_exchange_deposit_check with it. ' +\n NO_SEARCH_BY_NAME\n )\n}\n\n/** meta_exchange_lookup, {network, name?, address?}. Every argument is checked before the lookup is read. */\nexport async function handleMetaExchangeLookup(\n args: unknown,\n deps: ExchangeToolDependencies\n): Promise<MetaExchangeLookupToolResult> {\n const record = isRecord(args) ? args : {}\n let network: string\n try {\n network = normalizeDexNetwork(record.network)\n } catch (err) {\n return errorResult((err as Error).message)\n }\n const rawName = record.name\n if (rawName !== undefined && rawName !== null && typeof rawName !== 'string') {\n return errorResult('invalid_name: name must be the exchange name as text')\n }\n const name = typeof rawName === 'string' && rawName.trim() !== '' ? rawName.trim() : null\n const rawAddress = record.address\n if (rawAddress !== undefined && rawAddress !== null && typeof rawAddress !== 'string') {\n return errorResult('invalid_address: address must be 0x plus 40 hex characters')\n }\n const addressText =\n typeof rawAddress === 'string' && rawAddress.trim() !== '' ? rawAddress.trim() : null\n if (name !== null && addressText !== null)\n return errorResult('Give a name or an address, not both.')\n if (addressText !== null && !ADDRESS_FORM.test(addressText)) {\n return errorResult('invalid_address: address must be 0x plus 40 hex characters')\n }\n const address = addressText === null ? null : addressText.toLowerCase()\n\n let loaded: LoadedExchangeRegistry\n try {\n loaded = await deps.loadExchangeRegistry(network)\n } catch (err) {\n return errorResult(\n err instanceof DexRegistryError\n ? err.message\n : `exchange lookup unavailable: ${(err as Error).message}`\n )\n }\n const { document } = loaded\n const listed = document.rows.map((row) => row.display)\n const base = {\n schema: META_EXCHANGE_LOOKUP_SCHEMA,\n network,\n registry_version: document.registry_version,\n registry_source: loaded.source,\n recorded_on: document.recorded_on,\n }\n\n if (name === null && address === null) {\n const result = {\n ...base,\n matched: null,\n candidates: [],\n listed,\n exchanges: document.rows.map((row) => ({\n exchange: row.exchange,\n display: row.display,\n hot_wallets: row.wallets.filter((wallet) => wallet.role === 'hot_wallet').length,\n })),\n }\n return textResult({ ...result, hint: hintFor(result, null, null) })\n }\n\n if (address !== null) {\n const owner = exchangeOfWallet(address, document.rows)\n const result = {\n ...base,\n matched: owner ? exchangeMatchOf(owner.entry) : null,\n ...(owner ? { took_for: ROLE_WORDS[owner.wallet.role] } : {}),\n candidates: [],\n listed,\n }\n return textResult({ ...result, hint: hintFor(result, null, address) })\n }\n\n const match = matchExchange(name as string, document.rows)\n const result = {\n ...base,\n matched: match.matched ? exchangeMatchOf(match.matched) : null,\n ...(match.took_for ? { took_for: match.took_for } : {}),\n candidates: match.candidates,\n listed,\n }\n return textResult({ ...result, hint: hintFor(result, name, null) })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,MAAa,wBACX;AAGF,MAAa,4BAA4B;AACzC,MAAa,8BAA8B;AAC3C,MAAa,6BAA6B;AAC1C,MAAa,mCACX,urBAMG,sBAAsB;AAC3B,MAAa,mCAAmC;CAC9C,cAAc;CACd,gBAAgB;CAChB,eAAe;AACjB;AA8CA,SAAS,SAAS,OAAkD;CAClE,OAAO,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AACrE;AAEA,SAAS,YAAY,MAA4C;CAC/D,OAAO;EAAE,SAAS,CAAC;GAAE,MAAM;GAAQ;EAAK,CAAC;EAAG,SAAS;CAAK;AAC5D;AAEA,SAAS,WAAW,YAAoE;CACtF,OAAO;EACL,SAAS,CAAC;GAAE,MAAM;GAAQ,MAAM,KAAK,UAAU,YAAY,MAAM,CAAC;EAAE,CAAC;EACrE,mBAAmB;EACnB,SAAS;CACX;AACF;AAEA,MAAM,eAAe;AAErB,SAAS,UAAU,OAAsB,MAA2C;CAClF,OAAO,MAAM,QACV,QAAQ,WAAW,OAAO,SAAS,IAAI,CAAC,CACxC,KAAK,EAAE,SAAS,UAAU,uBAAuB;EAAE;EAAS;EAAU;CAAgB,EAAE;AAC7F;;AAGA,SAAgB,gBAAgB,OAAqC;CACnE,OAAO;EACL,UAAU,MAAM;EAChB,SAAS,MAAM;EACf,aAAa,UAAU,OAAO,YAAY;EAC1C,aAAa,UAAU,OAAO,YAAY;EAC1C,UAAU,UAAU,OAAO,SAAS;CACtC;AACF;AAEA,MAAM,aAAqD;CACzD,YAAY;CACZ,YAAY;CACZ,SAAS;AACX;AAIA,SAAS,QACP,QACA,MACA,SACQ;CACR,MAAM,EAAE,YAAY;CACpB,IAAI,YAAY,QAAQ,CAAC,OAAO,SAC9B,OACE,GAAG,YAAY,GAAG,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AS;GACb,GAAG;GACH,SAAS,QAAQ,gBAAgB,MAAM,KAAK,IAAI;GAChD,GAAI,QAAQ,EAAE,UAAU,WAAW,MAAM,OAAO,MAAM,IAAI,CAAC;GAC3D,YAAY,CAAC;GACb;EACF;EACA,OAAO,WAAW;GAAE,GAAG;GAAQ,MAAM,QAAQ,QAAQ,MAAM,OAAO;EAAE,CAAC;CACvE;CAEA,MAAM,QAAQ,cAAc,MAAgB,SAAS,IAAI;CACzD,MAAM,SAAS;EACb,GAAG;EACH,SAAS,MAAM,UAAU,gBAAgB,MAAM,OAAO,IAAI;EAC1D,GAAI,MAAM,WAAW,EAAE,UAAU,MAAM,SAAS,IAAI,CAAC;EACrD,YAAY,MAAM;EAClB;CACF;CACA,OAAO,WAAW;EAAE,GAAG;EAAQ,MAAM,QAAQ,QAAQ,MAAM,IAAI;CAAE,CAAC;AACpE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-BW-eSwOZ.cjs");
|
|
2
2
|
const require_answer_hint = require("./answer-hint-BlYEBq_Y.cjs");
|
|
3
|
-
const require_dex_registry = require("./dex-registry-
|
|
4
|
-
const require_exchange_registry = require("./exchange-registry-
|
|
3
|
+
const require_dex_registry = require("./dex-registry-CyR3GyRr.cjs");
|
|
4
|
+
const require_exchange_registry = require("./exchange-registry-CEgkeQV1.cjs");
|
|
5
5
|
// src/mcp/exchange-tool.ts
|
|
6
6
|
/**
|
|
7
7
|
* meta_exchange_lookup: a centralized exchange's name becomes its wallets.
|
|
@@ -81,7 +81,7 @@ const ROLE_WORDS = {
|
|
|
81
81
|
};
|
|
82
82
|
function hintFor(result, name, address) {
|
|
83
83
|
const { network } = result;
|
|
84
|
-
if (address !== null && !result.matched) return `${require_answer_hint.ANSWER_HINT} ${address} is no wallet the exchange lookup lists for ${network}: the file lists only wallets proven on this chain. The graph marks deposits and hot wallets of every exchange: call aml_exchange_deposit_check {network: "${network}", address: "${address}"} to read its
|
|
84
|
+
if (address !== null && !result.matched) return `${require_answer_hint.ANSWER_HINT} ${address} is no wallet the exchange lookup lists for ${network}: the file lists only wallets proven on this chain. The graph marks deposits and hot wallets of every exchange: call aml_exchange_deposit_check {network: "${network}", address: "${address}"} to read its exchange_role, its exchange and its SWEPT links.`;
|
|
85
85
|
if (address !== null && result.matched) return `${require_answer_hint.ANSWER_HINT} Say in one line: "${address} is ${result.took_for} of ${result.matched.display} on ${network}." A trail that reaches it has entered the exchange: end the trail there. Never walk on past a hot wallet.`;
|
|
86
86
|
if (name === null) return `${require_answer_hint.ANSWER_HINT} These are the exchanges the lookup lists for ${network}. Call meta_exchange_lookup with a name for its wallets.`;
|
|
87
87
|
if (result.matched) {
|
|
@@ -1,12 +1,64 @@
|
|
|
1
1
|
const require_rolldown_runtime = require("./rolldown-runtime-BW-eSwOZ.cjs");
|
|
2
|
-
const require_capabilities = require("./capabilities-
|
|
2
|
+
const require_capabilities = require("./capabilities-DkNreyv7.cjs");
|
|
3
|
+
const require_address_card = require("./address-card-C-NB03XP.cjs");
|
|
3
4
|
const require_client = require("./client-Ddk4X9Ko.cjs");
|
|
4
5
|
const require_cache_location = require("./cache-location-C09AE55j.cjs");
|
|
5
|
-
const require_layer_routing = require("./layer-routing-
|
|
6
|
+
const require_layer_routing = require("./layer-routing-j48SQ8Wk.cjs");
|
|
6
7
|
let node_path = require("node:path");
|
|
7
8
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
|
8
9
|
let node_fs_promises = require("node:fs/promises");
|
|
9
10
|
let node_crypto = require("node:crypto");
|
|
11
|
+
// src/mcp/behaviour-kinds.ts
|
|
12
|
+
const BEHAVIOUR_KINDS = Object.freeze([
|
|
13
|
+
{
|
|
14
|
+
value: "SWAP_BOT_FARM_WALLET",
|
|
15
|
+
plain: "one wallet of a swap-bot farm: takes funds from hundreds of brand-new wallets, swaps through a router, pays hundreds of other brand-new wallets"
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
value: "DEX_TRADER_BOT",
|
|
19
|
+
plain: "an automated trader: most of its transfers touch pools or routers and it swaps hundreds of times a week"
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
value: "VOLUME_RING_HUB",
|
|
23
|
+
plain: "the hub of a volume ring: pays a standing set of its own wallets, which pay it back"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
value: "WALLET_FARM_CONTROLLER",
|
|
27
|
+
plain: "funds hundreds of brand-new wallets in a burst and sweeps them back"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
value: "FIXED_AMOUNT_DISTRIBUTOR",
|
|
31
|
+
plain: "pays one fixed amount to hundreds of wallets that never pay back"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
value: "MIXER_LOOP_HUB",
|
|
35
|
+
plain: "collects from wallets that withdrew from a mixer and pays wallets that deposit into one"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
value: "PAYOUT_DESK",
|
|
39
|
+
plain: "payers and receivers are different people, active almost every hour of the week: the shape of a payment desk"
|
|
40
|
+
}
|
|
41
|
+
]);
|
|
42
|
+
/** The rule every host follows, word for word in the graph_query description and in the skill. */
|
|
43
|
+
const BEHAVIOUR_RULE = "A behaviour kind describes automation or volume, it is not a risk signal by itself; say so, and never present it as an accusation.";
|
|
44
|
+
function kindGloss() {
|
|
45
|
+
return BEHAVIOUR_KINDS.map((kind) => `${kind.value} (${kind.plain})`).join("; ");
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* The one paragraph of the graph_query description: what the two properties
|
|
49
|
+
* hold, each kind in plain words, how to read them and how to say them.
|
|
50
|
+
*/
|
|
51
|
+
const GRAPH_QUERY_BEHAVIOUR_SENTENCE = [
|
|
52
|
+
"behaviour_kind on an :Address says how a busy account behaves: a rule over one week of its own on-chain counts, for an account with 200 or more payers plus receivers in the week that no other label names. It is absent on every other address and goes when the account goes quiet. It is a counted fact, not a model's guess: never call it inferred.",
|
|
53
|
+
`Its values: ${kindGloss()}.`,
|
|
54
|
+
"behaviour_group is <behaviour_kind>:<first payer address>: 3 or more accounts of one kind whose first ever payer is that address, one operator's wallets. It is absent when the account is in no group. When that first payer is an exchange wallet, a :Pool or a :Protocol contract, the group is the accounts it funded first, not one operator: say that.",
|
|
55
|
+
"Neither is a mark or a word in labels, so read them anchored on the full address: USE topology MATCH (a:Address {address: $addr}) RETURN a.address AS address, a.behaviour_kind AS behaviour_kind, a.behaviour_group AS behaviour_group LIMIT 1. Read the members of a group anchored on its first payer, never with a WHERE on behaviour_kind or behaviour_group alone.",
|
|
56
|
+
`${BEHAVIOUR_RULE} MIXER_LOOP_HUB is a pattern of payments around a mixer, not proof of laundering. Say the kind in its plain words, never the constant alone.`
|
|
57
|
+
].join(" ");
|
|
58
|
+
/** The served hint line (the server instructions of hosts that read them). */
|
|
59
|
+
const BEHAVIOUR_HINT = `- ${GRAPH_QUERY_BEHAVIOUR_SENTENCE}`;
|
|
60
|
+
/** The note meta_schema adds when the lane serves behaviour_kind. */
|
|
61
|
+
const BEHAVIOUR_SCHEMA_NOTE = `behaviour_kind on an :Address is how a busy account behaves, counted by a rule over one week: ${BEHAVIOUR_KINDS.map((kind) => kind.value).join(", ")}. behaviour_group is <behaviour_kind>:<first payer address>, 3 or more accounts of one kind with the same first payer. Read both anchored on an address. ${BEHAVIOUR_RULE}`;
|
|
10
62
|
// src/mcp/contract-read.ts
|
|
11
63
|
/**
|
|
12
64
|
* The Contract read of the facts layer: what one contract is, and what its
|
|
@@ -943,12 +995,13 @@ async function saveGraphSchemaCache(network, document, endpoint, complete, now)
|
|
|
943
995
|
*/
|
|
944
996
|
var graph_schema_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({
|
|
945
997
|
formatGraphSchemaText: () => formatGraphSchemaText,
|
|
946
|
-
getGraphSchema: () => getGraphSchema
|
|
998
|
+
getGraphSchema: () => getGraphSchema,
|
|
999
|
+
withAddressCard: () => withAddressCard
|
|
947
1000
|
});
|
|
948
1001
|
const GRAPH_SCHEMA_ID = "chain-insights.graph-schema.v1";
|
|
949
1002
|
const GRAPH_SCHEMA_SOURCE = "live catalog";
|
|
950
1003
|
const META_SCHEMA_TITLE = "Graph schema";
|
|
951
|
-
const META_SCHEMA_DESCRIPTION =
|
|
1004
|
+
const META_SCHEMA_DESCRIPTION = `Return the live graph schema of one network: the labels, the link types, the field names of an address and of each main link, the indexes, the USE facts relationships with the TRANSFER columns and the properties of the Contract read, and the USE chain lookups. Call it first when you need field names. It is cached for 24 hours; pass refresh=true to rebuild it. It also lists the address card on every address, each property with its question and its values. ${require_address_card.ADDRESS_CARD_RULE}`;
|
|
952
1005
|
/** Fields of an address come from this many sampled nodes, and of a link from this many sampled links. */
|
|
953
1006
|
const ADDRESS_SAMPLE_LIMIT = 20;
|
|
954
1007
|
const LINK_SAMPLE_LIMIT = 5;
|
|
@@ -965,19 +1018,28 @@ const SAMPLED_LINK_TYPES = [
|
|
|
965
1018
|
"SWEPT"
|
|
966
1019
|
];
|
|
967
1020
|
/**
|
|
968
|
-
* The values of `
|
|
1021
|
+
* The values of `exchange_role` on an `:Exchange` address: which wallet of its
|
|
969
1022
|
* exchange the address is. The labels layer sets it from the exchange label's
|
|
970
1023
|
* subtype; `SWEPT` (layer `cex_sweeps`) runs from a `deposit` to the
|
|
971
1024
|
* `hot_wallet` it swept into.
|
|
972
1025
|
*/
|
|
973
|
-
const
|
|
1026
|
+
const EXCHANGE_ROLES = [
|
|
974
1027
|
"deposit",
|
|
975
1028
|
"hot_wallet",
|
|
976
1029
|
"cold_wallet",
|
|
977
1030
|
"withdrawal"
|
|
978
1031
|
];
|
|
979
|
-
/** The
|
|
980
|
-
const
|
|
1032
|
+
/** The node property keys that carry the exchange role, new name first. */
|
|
1033
|
+
const EXCHANGE_ROLE_KEYS = ["exchange_role", "cex_role"];
|
|
1034
|
+
/**
|
|
1035
|
+
* The Cypher expression that reads the exchange role of the node `variable` on
|
|
1036
|
+
* both lanes: `coalesce(<v>.exchange_role, <v>.cex_role)`.
|
|
1037
|
+
*/
|
|
1038
|
+
function exchangeRoleRead(variable) {
|
|
1039
|
+
return `coalesce(${variable}.exchange_role, ${variable}.cex_role)`;
|
|
1040
|
+
}
|
|
1041
|
+
/** The note a schema carries when the graph serves `SWEPT` or `exchange_role`. */
|
|
1042
|
+
const EXCHANGE_SCHEMA_NOTE = `exchange_role on an :Exchange address says which wallet of its exchange it is: ${EXCHANGE_ROLES.join(", ")}. A lane not yet re-indexed still carries it as cex_role; read ${exchangeRoleRead("a")}. SWEPT runs from an exchange deposit to the hot wallet it swept into; a trail that reaches it ends there. inferred_exchange_role (deposit or hot_wallet) is the exchange model's guess, with its ml:exchange-roles:<model>:<basis> entry in inferred_sources: never a label, never a SWEPT link, and always said as inferred by that model.`;
|
|
981
1043
|
const FACTS_TRANSFER_COLUMNS = [
|
|
982
1044
|
"tx_id",
|
|
983
1045
|
"block_date",
|
|
@@ -1214,7 +1276,8 @@ async function buildGraphSchema(options) {
|
|
|
1214
1276
|
}
|
|
1215
1277
|
const words = [...topology.property_keys, ...Object.values(topology.samples).flat()];
|
|
1216
1278
|
if (words.includes("synced_through_height") || words.includes("pair_key")) remarks.push("synced_through_height and pair_key are sync bookkeeping: never filter or sort on them.");
|
|
1217
|
-
if (topology.link_types.includes("SWEPT") || topology.property_keys.includes(
|
|
1279
|
+
if (topology.link_types.includes("SWEPT") || EXCHANGE_ROLE_KEYS.some((key) => topology.property_keys.includes(key))) remarks.push(EXCHANGE_SCHEMA_NOTE);
|
|
1280
|
+
if (topology.property_keys.includes("behaviour_kind")) remarks.push(BEHAVIOUR_SCHEMA_NOTE);
|
|
1218
1281
|
const levels = require_layer_routing.swapLinkShape(capability?.graph_progress?.families) === "levels" || topology.link_types.includes("ROUTED_TO");
|
|
1219
1282
|
if (levels) remarks.push(require_layer_routing.levelLines().join(" "));
|
|
1220
1283
|
remarks.push("Fields come from a sample of the live graph. A rare field may be missing.");
|
|
@@ -1295,9 +1358,30 @@ function formatGraphSchemaText(document) {
|
|
|
1295
1358
|
lines.push(sampled.length > 0 ? "Fields, from a sample:" : "Fields, from a sample: none read");
|
|
1296
1359
|
for (const [kind, fields] of sampled) lines.push(`- ${kind}: ${fields.join(", ")}`);
|
|
1297
1360
|
lines.push("", "USE facts", listLine("Relationships", facts.relationships), listLine("TRANSFER columns", facts.transfer_columns), ...facts.contract_properties?.length ? [listLine("Contract properties, one contract by its address", facts.contract_properties)] : [], "", "USE chain", listLine("Lookups", chain.lookups));
|
|
1361
|
+
if (document.address_card) lines.push("", ...require_address_card.formatAddressCardLines(document.address_card));
|
|
1298
1362
|
if (document.notes.length > 0) lines.push("", "Notes:", ...document.notes.map((note) => `- ${note}`));
|
|
1299
1363
|
return lines.join("\n");
|
|
1300
1364
|
}
|
|
1365
|
+
/**
|
|
1366
|
+
* The schema with the address card dictionary beside it. The card is read on
|
|
1367
|
+
* every answer through its own cache; a card that cannot be read leaves a note
|
|
1368
|
+
* and never fails the schema.
|
|
1369
|
+
*/
|
|
1370
|
+
async function withAddressCard(document, load) {
|
|
1371
|
+
try {
|
|
1372
|
+
const loaded = await load();
|
|
1373
|
+
if (!loaded) return document;
|
|
1374
|
+
return {
|
|
1375
|
+
...document,
|
|
1376
|
+
address_card: require_address_card.addressCardSection(loaded)
|
|
1377
|
+
};
|
|
1378
|
+
} catch (err) {
|
|
1379
|
+
return {
|
|
1380
|
+
...document,
|
|
1381
|
+
notes: [...document.notes, `The address card dictionary could not be read: ${err instanceof Error ? err.message : String(err)}`]
|
|
1382
|
+
};
|
|
1383
|
+
}
|
|
1384
|
+
}
|
|
1301
1385
|
function errorResult(text) {
|
|
1302
1386
|
return {
|
|
1303
1387
|
content: [{
|
|
@@ -1313,7 +1397,7 @@ async function handleMetaSchema(args, deps) {
|
|
|
1313
1397
|
const refresh = record.refresh;
|
|
1314
1398
|
if (refresh !== void 0 && refresh !== null && typeof refresh !== "boolean") return errorResult("invalid_refresh: refresh must be true or false");
|
|
1315
1399
|
try {
|
|
1316
|
-
const
|
|
1400
|
+
const schema = await getGraphSchema({
|
|
1317
1401
|
network: record.network,
|
|
1318
1402
|
refresh: refresh === true,
|
|
1319
1403
|
endpoint: deps.endpoint,
|
|
@@ -1322,6 +1406,7 @@ async function handleMetaSchema(args, deps) {
|
|
|
1322
1406
|
...deps.pauseMs === void 0 ? {} : { pauseMs: deps.pauseMs },
|
|
1323
1407
|
...deps.sleep ? { sleep: deps.sleep } : {}
|
|
1324
1408
|
});
|
|
1409
|
+
const document = deps.loadAddressCard ? await withAddressCard(schema, deps.loadAddressCard) : schema;
|
|
1325
1410
|
return {
|
|
1326
1411
|
content: [{
|
|
1327
1412
|
type: "text",
|
|
@@ -1334,10 +1419,10 @@ async function handleMetaSchema(args, deps) {
|
|
|
1334
1419
|
return errorResult(err instanceof GraphSchemaError ? err.message : deps.describeFailure(err));
|
|
1335
1420
|
}
|
|
1336
1421
|
}
|
|
1337
|
-
Object.defineProperty(exports, "
|
|
1422
|
+
Object.defineProperty(exports, "BEHAVIOUR_HINT", {
|
|
1338
1423
|
enumerable: true,
|
|
1339
1424
|
get: function() {
|
|
1340
|
-
return
|
|
1425
|
+
return BEHAVIOUR_HINT;
|
|
1341
1426
|
}
|
|
1342
1427
|
});
|
|
1343
1428
|
Object.defineProperty(exports, "CONTRACT_READ_HINT", {
|
|
@@ -1346,6 +1431,12 @@ Object.defineProperty(exports, "CONTRACT_READ_HINT", {
|
|
|
1346
1431
|
return CONTRACT_READ_HINT;
|
|
1347
1432
|
}
|
|
1348
1433
|
});
|
|
1434
|
+
Object.defineProperty(exports, "EXCHANGE_ROLES", {
|
|
1435
|
+
enumerable: true,
|
|
1436
|
+
get: function() {
|
|
1437
|
+
return EXCHANGE_ROLES;
|
|
1438
|
+
}
|
|
1439
|
+
});
|
|
1349
1440
|
Object.defineProperty(exports, "FLOWS_MAX_OFFSET", {
|
|
1350
1441
|
enumerable: true,
|
|
1351
1442
|
get: function() {
|
|
@@ -1370,6 +1461,12 @@ Object.defineProperty(exports, "GRAPH_EXPAND_TOOL", {
|
|
|
1370
1461
|
return GRAPH_EXPAND_TOOL;
|
|
1371
1462
|
}
|
|
1372
1463
|
});
|
|
1464
|
+
Object.defineProperty(exports, "GRAPH_QUERY_BEHAVIOUR_SENTENCE", {
|
|
1465
|
+
enumerable: true,
|
|
1466
|
+
get: function() {
|
|
1467
|
+
return GRAPH_QUERY_BEHAVIOUR_SENTENCE;
|
|
1468
|
+
}
|
|
1469
|
+
});
|
|
1373
1470
|
Object.defineProperty(exports, "GRAPH_QUERY_CONTRACT_READ_SENTENCE", {
|
|
1374
1471
|
enumerable: true,
|
|
1375
1472
|
get: function() {
|
|
@@ -1400,6 +1497,12 @@ Object.defineProperty(exports, "TRANSFERS_MAX", {
|
|
|
1400
1497
|
return TRANSFERS_MAX;
|
|
1401
1498
|
}
|
|
1402
1499
|
});
|
|
1500
|
+
Object.defineProperty(exports, "exchangeRoleRead", {
|
|
1501
|
+
enumerable: true,
|
|
1502
|
+
get: function() {
|
|
1503
|
+
return exchangeRoleRead;
|
|
1504
|
+
}
|
|
1505
|
+
});
|
|
1403
1506
|
Object.defineProperty(exports, "graph_schema_exports", {
|
|
1404
1507
|
enumerable: true,
|
|
1405
1508
|
get: function() {
|