chain-insights 0.77.1 → 0.78.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/dist/cli.cjs +5 -5
- package/dist/cli.mjs +5 -5
- package/dist/{dex-registry-CZQB2YhU.cjs → dex-registry-DdXOg5On.cjs} +4 -0
- package/dist/{dex-registry-D6Xxi_vr.mjs → dex-registry-sPTFuCrP.mjs} +5 -1
- package/dist/dex-registry-sPTFuCrP.mjs.map +1 -0
- package/dist/{dex-tool-DsM-pSku.cjs → dex-tool-CDmhhXfk.cjs} +3 -3
- package/dist/{dex-tool-BoAYqhZO.mjs → dex-tool-D61sIjpq.mjs} +4 -4
- package/dist/{dex-tool-BoAYqhZO.mjs.map → dex-tool-D61sIjpq.mjs.map} +1 -1
- package/dist/mcp-proxy.cjs +3 -3
- package/dist/mcp-proxy.mjs +3 -3
- package/dist/{token-lookup-BJ00JO9A.cjs → token-lookup-DvgEyqcC.cjs} +1 -1
- package/dist/{token-lookup-XnyisLQW.mjs → token-lookup-sH2DesLS.mjs} +2 -2
- package/dist/{token-lookup-XnyisLQW.mjs.map → token-lookup-sH2DesLS.mjs.map} +1 -1
- package/package.json +2 -2
- package/registry/README.md +12 -6
- package/registry/robinhood.json +187 -2
- package/registry/robinhood.md +86 -2
- package/skills/chain-insights-dex/SKILL.md +7 -1
- package/skills/chain-insights-virtuals/SKILL.md +1 -1
- package/dist/dex-registry-D6Xxi_vr.mjs.map +0 -1
package/dist/cli.cjs
CHANGED
|
@@ -647,8 +647,8 @@ program.command("mcp").description("Low-level access to the Chain Insights MCP e
|
|
|
647
647
|
}
|
|
648
648
|
}
|
|
649
649
|
console.log(formatToolsTable(visibleRemoteTools(tools)));
|
|
650
|
-
const { META_DEX_LOOKUP_DESCRIPTION, META_DEX_LOOKUP_TITLE, META_DEX_LOOKUP_TOOL } = await Promise.resolve().then(() => require("./dex-tool-
|
|
651
|
-
const { META_TOKEN_LOOKUP_DESCRIPTION, META_TOKEN_LOOKUP_TITLE, META_TOKEN_LOOKUP_TOOL } = await Promise.resolve().then(() => require("./token-lookup-
|
|
650
|
+
const { META_DEX_LOOKUP_DESCRIPTION, META_DEX_LOOKUP_TITLE, META_DEX_LOOKUP_TOOL } = await Promise.resolve().then(() => require("./dex-tool-CDmhhXfk.cjs")).then((n) => n.dex_tool_exports);
|
|
651
|
+
const { META_TOKEN_LOOKUP_DESCRIPTION, META_TOKEN_LOOKUP_TITLE, META_TOKEN_LOOKUP_TOOL } = await Promise.resolve().then(() => require("./token-lookup-DvgEyqcC.cjs")).then((n) => n.token_lookup_exports);
|
|
652
652
|
console.log("");
|
|
653
653
|
console.log(formatToolsTable([{
|
|
654
654
|
name: META_DEX_LOOKUP_TOOL,
|
|
@@ -685,8 +685,8 @@ program.command("mcp").description("Low-level access to the Chain Insights MCP e
|
|
|
685
685
|
return;
|
|
686
686
|
}
|
|
687
687
|
if (tool === "meta_dex_lookup") {
|
|
688
|
-
const { handleMetaDexLookup } = await Promise.resolve().then(() => require("./dex-tool-
|
|
689
|
-
const { loadRegistry } = await Promise.resolve().then(() => require("./dex-registry-
|
|
688
|
+
const { handleMetaDexLookup } = await Promise.resolve().then(() => require("./dex-tool-CDmhhXfk.cjs")).then((n) => n.dex_tool_exports);
|
|
689
|
+
const { loadRegistry } = await Promise.resolve().then(() => require("./dex-registry-DdXOg5On.cjs")).then((n) => n.dex_registry_exports);
|
|
690
690
|
const { metaDexLookupArgs } = await Promise.resolve().then(() => require("./call-args-DXEmPeE-.cjs"));
|
|
691
691
|
const result = await withGraphMcpClient("chain-insights-cli-dex-lookup", (client) => handleMetaDexLookup(metaDexLookupArgs(args), {
|
|
692
692
|
loadRegistry: (network) => loadRegistry(network),
|
|
@@ -701,7 +701,7 @@ program.command("mcp").description("Low-level access to the Chain Insights MCP e
|
|
|
701
701
|
return;
|
|
702
702
|
}
|
|
703
703
|
if (tool === "meta_token_lookup") {
|
|
704
|
-
const { handleMetaTokenLookup } = await Promise.resolve().then(() => require("./token-lookup-
|
|
704
|
+
const { handleMetaTokenLookup } = await Promise.resolve().then(() => require("./token-lookup-DvgEyqcC.cjs")).then((n) => n.token_lookup_exports);
|
|
705
705
|
const { metaTokenLookupArgs } = await Promise.resolve().then(() => require("./call-args-DXEmPeE-.cjs"));
|
|
706
706
|
const result = await withGraphMcpClient("chain-insights-cli-token-lookup", (client) => handleMetaTokenLookup(metaTokenLookupArgs(args), {
|
|
707
707
|
graphQuery: async (queryArgs) => await client.callTool({
|
package/dist/cli.mjs
CHANGED
|
@@ -645,8 +645,8 @@ program.command("mcp").description("Low-level access to the Chain Insights MCP e
|
|
|
645
645
|
}
|
|
646
646
|
}
|
|
647
647
|
console.log(formatToolsTable(visibleRemoteTools(tools)));
|
|
648
|
-
const { META_DEX_LOOKUP_DESCRIPTION, META_DEX_LOOKUP_TITLE, META_DEX_LOOKUP_TOOL } = await import("./dex-tool-
|
|
649
|
-
const { META_TOKEN_LOOKUP_DESCRIPTION, META_TOKEN_LOOKUP_TITLE, META_TOKEN_LOOKUP_TOOL } = await import("./token-lookup-
|
|
648
|
+
const { META_DEX_LOOKUP_DESCRIPTION, META_DEX_LOOKUP_TITLE, META_DEX_LOOKUP_TOOL } = await import("./dex-tool-D61sIjpq.mjs").then((n) => n.a);
|
|
649
|
+
const { META_TOKEN_LOOKUP_DESCRIPTION, META_TOKEN_LOOKUP_TITLE, META_TOKEN_LOOKUP_TOOL } = await import("./token-lookup-sH2DesLS.mjs").then((n) => n.s);
|
|
650
650
|
console.log("");
|
|
651
651
|
console.log(formatToolsTable([{
|
|
652
652
|
name: META_DEX_LOOKUP_TOOL,
|
|
@@ -683,8 +683,8 @@ program.command("mcp").description("Low-level access to the Chain Insights MCP e
|
|
|
683
683
|
return;
|
|
684
684
|
}
|
|
685
685
|
if (tool === "meta_dex_lookup") {
|
|
686
|
-
const { handleMetaDexLookup } = await import("./dex-tool-
|
|
687
|
-
const { loadRegistry } = await import("./dex-registry-
|
|
686
|
+
const { handleMetaDexLookup } = await import("./dex-tool-D61sIjpq.mjs").then((n) => n.a);
|
|
687
|
+
const { loadRegistry } = await import("./dex-registry-sPTFuCrP.mjs").then((n) => n.n);
|
|
688
688
|
const { metaDexLookupArgs } = await import("./call-args-CBqbYfOE.mjs");
|
|
689
689
|
const result = await withGraphMcpClient("chain-insights-cli-dex-lookup", (client) => handleMetaDexLookup(metaDexLookupArgs(args), {
|
|
690
690
|
loadRegistry: (network) => loadRegistry(network),
|
|
@@ -699,7 +699,7 @@ program.command("mcp").description("Low-level access to the Chain Insights MCP e
|
|
|
699
699
|
return;
|
|
700
700
|
}
|
|
701
701
|
if (tool === "meta_token_lookup") {
|
|
702
|
-
const { handleMetaTokenLookup } = await import("./token-lookup-
|
|
702
|
+
const { handleMetaTokenLookup } = await import("./token-lookup-sH2DesLS.mjs").then((n) => n.s);
|
|
703
703
|
const { metaTokenLookupArgs } = await import("./call-args-CBqbYfOE.mjs");
|
|
704
704
|
const result = await withGraphMcpClient("chain-insights-cli-token-lookup", (client) => handleMetaTokenLookup(metaTokenLookupArgs(args), {
|
|
705
705
|
graphQuery: async (queryArgs) => await client.callTool({
|
|
@@ -98,6 +98,10 @@ function registryFault(value, network) {
|
|
|
98
98
|
if (!ADDRESS_RE.test(address)) return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`;
|
|
99
99
|
if (!ROLES.includes(role)) return `${at} (${row.dex}) role ${String(role)} is not factory, manager or router`;
|
|
100
100
|
}
|
|
101
|
+
if (row.helpers !== void 0) {
|
|
102
|
+
if (!isStringList(row.helpers)) return `${at} (${row.dex}) helpers is not a list`;
|
|
103
|
+
for (const address of row.helpers) if (!ADDRESS_RE.test(address)) return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`;
|
|
104
|
+
}
|
|
101
105
|
for (const field of ["factories", "routers"]) {
|
|
102
106
|
const list = row[field];
|
|
103
107
|
if (!isStringList(list)) return `${at} (${row.dex}) ${field} is not a list`;
|
|
@@ -97,6 +97,10 @@ function registryFault(value, network) {
|
|
|
97
97
|
if (!ADDRESS_RE.test(address)) return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`;
|
|
98
98
|
if (!ROLES.includes(role)) return `${at} (${row.dex}) role ${String(role)} is not factory, manager or router`;
|
|
99
99
|
}
|
|
100
|
+
if (row.helpers !== void 0) {
|
|
101
|
+
if (!isStringList(row.helpers)) return `${at} (${row.dex}) helpers is not a list`;
|
|
102
|
+
for (const address of row.helpers) if (!ADDRESS_RE.test(address)) return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`;
|
|
103
|
+
}
|
|
100
104
|
for (const field of ["factories", "routers"]) {
|
|
101
105
|
const list = row[field];
|
|
102
106
|
if (!isStringList(list)) return `${at} (${row.dex}) ${field} is not a list`;
|
|
@@ -361,4 +365,4 @@ function matchDex(name, rows) {
|
|
|
361
365
|
}
|
|
362
366
|
export { normalizeDexNetwork as a, matchDex as i, dex_registry_exports as n, loadRegistry as r, DexRegistryError as t };
|
|
363
367
|
|
|
364
|
-
//# sourceMappingURL=dex-registry-
|
|
368
|
+
//# sourceMappingURL=dex-registry-sPTFuCrP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dex-registry-sPTFuCrP.mjs","names":[],"sources":["../src/mcp/dex-registry.ts"],"sourcesContent":["/**\n * The exchange registry, as the proxy tool meta_dex_lookup reads it.\n *\n * The reviewed table lives in this repository, registry/<network>.md, and its\n * served copy registry/<network>.json is checked in CI\n * (scripts/pin-dex-registry.mjs). The proxy reads the copy three ways, in this\n * order:\n *\n * cached ~/.chain-insights/cache/dex-registry-<network>.json, younger than one hour\n * fetched the copy on main, https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/<network>.json,\n * within 3 s, at most once an hour per network and never two in flight\n * packaged registry/<network>.json of the installed package, when the fetch fails and no cache exists\n *\n * A fetched file is used only when it passes the same rules the pin script\n * applies. A malformed file never replaces a good cache: the stale cache keeps\n * answering and one line names the fault. So a proxy that never reaches GitHub\n * behaves like the skill memo of its own version, and a row merged on main\n * reaches every running proxy within the hour, with no release.\n *\n * matchDex turns a name into one exchange: normalise, exact on key, display and\n * aliases, then within two letters of an alias of four or more characters. One\n * winner is matched, a tie is listed, never guessed, and no hit names every\n * covered exchange.\n */\n\nimport { existsSync, readFileSync } from 'node:fs'\nimport { mkdir, readFile, rename, writeFile } from 'node:fs/promises'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { chainInsightsHome } from './cache-location.js'\n\nexport const DEX_REGISTRY_SCHEMA = 'chain-insights.dex-registry.v1' as const\n/** How long a cached registry stays fresh. CACHE_TTL_MS (24 h) stays the lifetime of the schema caches. */\nexport const DEX_REGISTRY_TTL_MS = 60 * 60 * 1000\n/** The most a fetch of the public file may take on the call path. */\nexport const DEX_REGISTRY_FETCH_BUDGET_MS = 3_000\nexport const DEX_REGISTRY_URL_ENV = 'CHAIN_INSIGHTS_DEX_REGISTRY_URL'\nexport const DEX_REGISTRY_PUBLIC_URL =\n 'https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/{network}.json'\n\nexport const TRAIL_TYPES = ['plain', 'vault', 'gauge', 'launchpad'] as const\nexport type TrailType = (typeof TRAIL_TYPES)[number]\nexport const ROLES = ['factory', 'manager', 'router'] as const\nexport type Role = (typeof ROLES)[number]\nexport type RegistrySource = 'fetched' | 'cached' | 'packaged'\n\n/** One exchange of the served copy. */\nexport interface DexEntry {\n dex: string\n display: string\n aliases: string[]\n trail_type: TrailType\n adapters: string[]\n roles: Record<string, Role>\n /**\n * Contracts of the exchange the trail does not read: a position NFT, a staking gauge, a parts\n * deployer, a vault's swap router. A lookup by address finds them; no read is sent for them.\n */\n helpers?: string[]\n /** Its factory addresses, or the one manager of a vault. */\n factories: string[]\n /** Its routers, or the manager of a vault: a vault forwards its own swaps. */\n routers: string[]\n example_pool: string | null\n pool_floor: number | null\n since_block: number\n source: string\n}\n\nexport interface DexRegistryDocument {\n schema: typeof DEX_REGISTRY_SCHEMA\n network: string\n registry_version: number\n recorded_on: string\n rows: DexEntry[]\n}\n\nexport interface LoadedRegistry {\n document: DexRegistryDocument\n source: RegistrySource\n loaded_at_ms: number\n}\n\n/** A refusal with its own words for the caller: a network the registry does not cover. */\nexport class DexRegistryError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'DexRegistryError'\n }\n}\n\nconst ADDRESS_RE = /^0x[0-9a-f]{40}$/\n// An example pool is a pool address, or the pool id of a manager that keeps its pools by id.\nconst POOL_RE = /^0x(?:[0-9a-f]{40}|[0-9a-f]{64})$/\nconst DEX_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/\nconst NETWORK_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/\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 network as a lower-case identifier; it becomes part of a file name and a URL. */\nexport function normalizeDexNetwork(raw: unknown): string {\n const network = typeof raw === 'string' ? raw.trim().toLowerCase() : ''\n if (!network) {\n throw new DexRegistryError(\n 'invalid_network: network is required. Pass the identifier of a served network, for example robinhood.'\n )\n }\n if (!NETWORK_RE.test(network)) {\n throw new DexRegistryError(`invalid_network: \"${String(raw)}\" is not a network identifier`)\n }\n return network\n}\n\n/**\n * The fault of a registry document, or null when it is valid for the network:\n * the rules of registry/README.md, the same ones the pin script applies.\n */\nexport function registryFault(value: unknown, network: string): string | null {\n if (!isRecord(value)) return 'the file is not a JSON object'\n if (value.schema !== DEX_REGISTRY_SCHEMA) {\n return `schema is ${JSON.stringify(value.schema)}, not ${DEX_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 keys = new Set<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.dex !== 'string' || !DEX_RE.test(row.dex))\n return `${at}.dex is not a key: ${String(row.dex)}`\n if (keys.has(row.dex)) return `${at}.dex ${row.dex} is listed twice`\n keys.add(row.dex)\n if (typeof row.display !== 'string' || row.display.trim() === '')\n return `${at} (${row.dex}) has no display`\n if (!isStringList(row.aliases)) return `${at} (${row.dex}) aliases is not a list of names`\n if (!TRAIL_TYPES.includes(row.trail_type as TrailType)) {\n return `${at} (${row.dex}) trail_type ${String(row.trail_type)} is not plain, vault, gauge or launchpad`\n }\n if (!isStringList(row.adapters)) return `${at} (${row.dex}) adapters is not a list`\n if (!isRecord(row.roles)) return `${at} (${row.dex}) roles is not a map`\n for (const [address, role] of Object.entries(row.roles)) {\n if (!ADDRESS_RE.test(address))\n return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`\n if (!ROLES.includes(role as Role))\n return `${at} (${row.dex}) role ${String(role)} is not factory, manager or router`\n }\n if (row.helpers !== undefined) {\n if (!isStringList(row.helpers)) return `${at} (${row.dex}) helpers is not a list`\n for (const address of row.helpers) {\n if (!ADDRESS_RE.test(address))\n return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`\n }\n }\n for (const field of ['factories', 'routers'] as const) {\n const list = row[field]\n if (!isStringList(list)) return `${at} (${row.dex}) ${field} is not a list`\n for (const address of list) {\n if (!ADDRESS_RE.test(address))\n return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`\n if (!(address in row.roles))\n return `${at} (${row.dex}) ${field} names ${address}, which roles lacks`\n }\n }\n if ((row.factories as string[]).length === 0)\n return `${at} (${row.dex}) has no factory or manager`\n if (\n row.example_pool !== null &&\n (typeof row.example_pool !== 'string' || !POOL_RE.test(row.example_pool))\n ) {\n return `${at} (${row.dex}) example_pool ${String(row.example_pool)} is not a pool`\n }\n if (\n row.pool_floor !== null &&\n (!Number.isInteger(row.pool_floor) || (row.pool_floor as number) < 0)\n ) {\n return `${at} (${row.dex}) pool_floor is not a whole number`\n }\n if (!Number.isInteger(row.since_block) || (row.since_block as number) < 0) {\n return `${at} (${row.dex}) since_block is not a block`\n }\n if (typeof row.source !== 'string' || !row.source.startsWith('https://')) {\n return `${at} (${row.dex}) source is not an https link`\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 dexRegistryUrl(network: string, env: NodeJS.ProcessEnv = process.env): string {\n const override = env[DEX_REGISTRY_URL_ENV]?.trim()\n const template = override || DEX_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 dexRegistryCachePath(network: string): string {\n return path.join(chainInsightsHome(), 'cache', `dex-registry-${network}.json`)\n}\n\n/** The registry/ folder of the installed package: next to dist/, or the repository root when run from source. */\nexport function packagedRegistryDir(): string {\n const candidates = [\n fileURLToPath(new URL('../registry', import.meta.url)),\n fileURLToPath(new URL('../../registry', 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 is a defect: it throws. */\nexport function readPackagedRegistry(\n network: string,\n dir: string = packagedRegistryDir()\n): DexRegistryDocument | 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 = registryFault(parsed, network)\n if (fault)\n throw new Error(\n `the packaged exchange registry registry/${network}.json is malformed: ${fault}`\n )\n return parsed as DexRegistryDocument\n}\n\ninterface CacheFile {\n schema: typeof DEX_REGISTRY_SCHEMA\n network: string\n registry_version: number\n recorded_on: string\n rows: DexEntry[]\n /** When the copy was read: the fetch, or the first start with no fetch. */\n cached_at_ms: number\n /** When a fetch was last tried. The cache is fresh for an hour after it. */\n checked_at_ms: number\n source: 'fetched' | 'packaged'\n}\n\nconst documentOf = (file: CacheFile): DexRegistryDocument => ({\n schema: file.schema,\n network: file.network,\n registry_version: file.registry_version,\n recorded_on: file.recorded_on,\n rows: file.rows,\n})\n\nasync function readCache(network: string): Promise<CacheFile | null> {\n let parsed: unknown\n try {\n parsed = JSON.parse(await readFile(dexRegistryCachePath(network), 'utf8'))\n } catch {\n return null\n }\n if (!isRecord(parsed) || registryFault(parsed, network) !== null) return null\n if (typeof parsed.checked_at_ms !== 'number' || typeof parsed.cached_at_ms !== 'number')\n return null\n if (parsed.source !== 'fetched' && parsed.source !== 'packaged') return null\n return parsed as unknown as CacheFile\n}\n\nasync function writeCache(file: CacheFile): Promise<void> {\n const target = dexRegistryCachePath(file.network)\n await mkdir(path.dirname(target), { recursive: true })\n // Written beside the target and renamed, so a second proxy never reads half of it.\n const scratch = `${target}.${process.pid}.tmp`\n await writeFile(scratch, JSON.stringify(file, null, 2) + '\\n', { mode: 0o600 })\n await rename(scratch, target)\n}\n\nexport interface LoadRegistryOptions {\n fetch?: typeof fetch\n now?: () => number\n env?: NodeJS.ProcessEnv\n /** One line per fault: a failed fetch, a malformed file, a cache that cannot be written. */\n log?: (line: string) => void\n packagedDir?: string\n budgetMs?: number\n}\n\ntype FetchOutcome = { document: DexRegistryDocument } | { fault: string }\n\nasync function fetchRegistry(network: string, options: LoadRegistryOptions): Promise<FetchOutcome> {\n const url = dexRegistryUrl(network, options.env)\n const fetchImpl = options.fetch ?? fetch\n let response: Response\n try {\n response = await fetchImpl(url, {\n signal: AbortSignal.timeout(options.budgetMs ?? DEX_REGISTRY_FETCH_BUDGET_MS),\n })\n } catch (err) {\n return { fault: `${url} unreachable: ${err instanceof Error ? err.message : String(err)}` }\n }\n if (response.status !== 200) return { fault: `${url} answered HTTP ${response.status}` }\n let parsed: unknown\n try {\n parsed = JSON.parse(await response.text())\n } catch {\n return { fault: `${url} is not JSON` }\n }\n const fault = registryFault(parsed, network)\n if (fault) return { fault: `${url} is malformed: ${fault}` }\n return { document: parsed as DexRegistryDocument }\n}\n\n// Fetches in flight, by network: two calls at once share one fetch.\nconst inFlight = new Map<string, Promise<LoadedRegistry>>()\n\nconst defaultLog = (line: string): void => {\n process.stderr.write(`[chain-insights] dex-registry: ${line}\\n`)\n}\n\n/**\n * The registry of one network: the fresh cache, else the public file, else the\n * stale cache, else the packaged copy. A packaged copy with a higher registry\n * version than the cache or the public file wins, so an upgrade is never\n * answered from an older file. Never throws for a network the package covers.\n */\nexport async function loadRegistry(\n rawNetwork: unknown,\n options: LoadRegistryOptions = {}\n): Promise<LoadedRegistry> {\n const network = normalizeDexNetwork(rawNetwork)\n const now = options.now ?? Date.now\n const log = options.log ?? defaultLog\n const packaged = readPackagedRegistry(network, options.packagedDir)\n const newer = (document: DexRegistryDocument): boolean =>\n packaged !== null && packaged.registry_version > document.registry_version\n const fromPackaged = (): LoadedRegistry => ({\n document: packaged!,\n source: 'packaged',\n loaded_at_ms: now(),\n })\n\n const cache = await readCache(network)\n const age = cache ? now() - cache.checked_at_ms : Infinity\n if (cache && age >= 0 && age < DEX_REGISTRY_TTL_MS) {\n if (newer(cache)) return fromPackaged()\n return {\n document: documentOf(cache),\n source: cache.source === 'fetched' ? 'cached' : 'packaged',\n loaded_at_ms: now(),\n }\n }\n\n const running = inFlight.get(network)\n if (running) return running\n const load = (async (): Promise<LoadedRegistry> => {\n const outcome = await fetchRegistry(network, options)\n const checked = now()\n const save = async (file: CacheFile): Promise<void> => {\n try {\n await writeCache(file)\n } catch (err) {\n log(\n `the cache ${dexRegistryCachePath(network)} could not be written: ${err instanceof Error ? err.message : String(err)}`\n )\n }\n }\n if ('document' in outcome) {\n const { document } = outcome\n await save({ ...document, cached_at_ms: checked, checked_at_ms: checked, source: 'fetched' })\n if (newer(document)) return fromPackaged()\n return { document, source: 'fetched', loaded_at_ms: checked }\n }\n log(outcome.fault)\n if (cache) {\n // The stale cache keeps answering, and the next fetch waits an hour.\n await save({ ...cache, checked_at_ms: checked })\n if (newer(cache)) return fromPackaged()\n return {\n document: documentOf(cache),\n source: cache.source === 'fetched' ? 'cached' : 'packaged',\n loaded_at_ms: checked,\n }\n }\n if (!packaged) {\n throw new DexRegistryError(\n `network_not_covered: the exchange registry covers no network \"${network}\", and ${outcome.fault}`\n )\n }\n await save({ ...packaged, cached_at_ms: checked, checked_at_ms: checked, source: 'packaged' })\n return fromPackaged()\n })()\n inFlight.set(network, load)\n try {\n return await load\n } finally {\n inFlight.delete(network)\n }\n}\n\n// ─── The name match ───────────────────────────────────────────────────────────\n\n/** Lower case, with every space, \".\", \"-\" and \"_\" removed: \"Uni v4\" and \"uni-v4\" are \"univ4\". */\nexport function normaliseName(name: string): string {\n return name.toLowerCase().replace(/[\\s.\\-_]+/g, '')\n}\n\n/** The optimal string alignment distance: insertions, deletions, substitutions and swaps of two neighbours. */\nexport function damerauLevenshtein(a: string, b: string): number {\n const rows = a.length + 1\n const cols = b.length + 1\n const d: number[][] = Array.from({ length: rows }, (_, i) =>\n Array.from({ length: cols }, (_, j) => (i === 0 ? j : j === 0 ? i : 0))\n )\n for (let i = 1; i < rows; i += 1) {\n for (let j = 1; j < cols; j += 1) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1\n let best = Math.min(d[i - 1]![j]! + 1, d[i]![j - 1]! + 1, d[i - 1]![j - 1]! + cost)\n if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {\n best = Math.min(best, d[i - 2]![j - 2]! + 1)\n }\n d[i]![j] = best\n }\n }\n return d[a.length]![b.length]!\n}\n\n/** The most letters a near hit may differ by, and the shortest alias a near hit is taken from. */\nexport const NEAR_DISTANCE = 2\nexport const NEAR_MIN_ALIAS_LENGTH = 4\n\nexport interface DexCandidate {\n dex: string\n display: string\n distance: number\n}\n\nexport interface DexMatchResult {\n matched: DexEntry | null\n /** The name as typed, when the match is a near hit. */\n took_for?: string\n candidates: DexCandidate[]\n /** Every covered exchange, by display name. */\n covered: string[]\n}\n\n/**\n * One name against the registry rows:\n * one exact hit matched\n * several exact hits candidates at distance 0, matched null\n * no exact hit, one nearest exchange matched, took_for the name\n * no exact hit, a tie at the nearest candidates, matched null\n * nothing within two letters matched null, no candidates\n */\nexport function matchDex(name: string, rows: DexEntry[]): DexMatchResult {\n const covered = rows.map((row) => row.display)\n const wanted = normaliseName(name)\n if (!wanted) return { matched: null, candidates: [], covered }\n const exact = rows.filter((row) =>\n [row.dex, row.display, ...row.aliases].some((written) => normaliseName(written) === wanted)\n )\n if (exact.length === 1) return { matched: exact[0]!, candidates: [], covered }\n if (exact.length > 1) {\n return {\n matched: null,\n candidates: exact.map((row) => ({ dex: row.dex, display: row.display, distance: 0 })),\n covered,\n }\n }\n const near: Array<{ row: DexEntry; distance: number }> = []\n for (const row of rows) {\n const distances = row.aliases\n .map(normaliseName)\n .filter((alias) => alias.length >= NEAR_MIN_ALIAS_LENGTH)\n .map((alias) => damerauLevenshtein(wanted, alias))\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: [], covered }\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: [], covered }\n return {\n matched: null,\n candidates: nearest.map(({ row, distance }) => ({\n dex: row.dex,\n display: row.display,\n distance,\n })),\n covered,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,sBAAsB;;AAEnC,MAAa,sBAAsB;;AAEnC,MAAa,+BAA+B;AAC5C,MAAa,uBAAuB;AACpC,MAAa,0BACX;AAEF,MAAa,cAAc;CAAC;CAAS;CAAS;CAAS;AAAW;AAElE,MAAa,QAAQ;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AQ;CACpF,OAAO;EACL,SAAS;EACT,YAAY,QAAQ,KAAK,EAAE,KAAK,gBAAgB;GAC9C,KAAK,IAAI;GACT,SAAS,IAAI;GACb;EACF,EAAE;EACF;CACF;AACF"}
|
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
3
|
+
const require_dex_registry = require("./dex-registry-DdXOg5On.cjs");
|
|
4
4
|
// src/mcp/dex-recipes.ts
|
|
5
5
|
/** The trail-type skill of each trail, for hosts that load skills. */
|
|
6
6
|
const TRAIL_SKILLS = {
|
|
@@ -392,10 +392,10 @@ async function handleMetaDexLookup(args, deps) {
|
|
|
392
392
|
}
|
|
393
393
|
let match;
|
|
394
394
|
if (address !== null) {
|
|
395
|
-
const holder = document.rows.find((row) => address in row.roles);
|
|
395
|
+
const holder = document.rows.find((row) => address in row.roles || row.helpers?.includes(address));
|
|
396
396
|
match = {
|
|
397
397
|
matched: holder ?? null,
|
|
398
|
-
...holder ? { took_for: `${holder.roles[address]}, served` } : {},
|
|
398
|
+
...holder ? { took_for: `${holder.roles[address] ?? "helper"}, served` } : {},
|
|
399
399
|
candidates: [],
|
|
400
400
|
covered: document.rows.map((row) => row.display)
|
|
401
401
|
};
|
|
@@ -1,6 +1,6 @@
|
|
|
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 { a as normalizeDexNetwork, i as matchDex, t as DexRegistryError } from "./dex-registry-
|
|
3
|
+
import { a as normalizeDexNetwork, i as matchDex, t as DexRegistryError } from "./dex-registry-sPTFuCrP.mjs";
|
|
4
4
|
// src/mcp/dex-recipes.ts
|
|
5
5
|
/** The trail-type skill of each trail, for hosts that load skills. */
|
|
6
6
|
const TRAIL_SKILLS = {
|
|
@@ -392,10 +392,10 @@ async function handleMetaDexLookup(args, deps) {
|
|
|
392
392
|
}
|
|
393
393
|
let match;
|
|
394
394
|
if (address !== null) {
|
|
395
|
-
const holder = document.rows.find((row) => address in row.roles);
|
|
395
|
+
const holder = document.rows.find((row) => address in row.roles || row.helpers?.includes(address));
|
|
396
396
|
match = {
|
|
397
397
|
matched: holder ?? null,
|
|
398
|
-
...holder ? { took_for: `${holder.roles[address]}, served` } : {},
|
|
398
|
+
...holder ? { took_for: `${holder.roles[address] ?? "helper"}, served` } : {},
|
|
399
399
|
candidates: [],
|
|
400
400
|
covered: document.rows.map((row) => row.display)
|
|
401
401
|
};
|
|
@@ -463,4 +463,4 @@ async function handleMetaDexLookup(args, deps) {
|
|
|
463
463
|
}
|
|
464
464
|
export { dex_tool_exports as a, META_DEX_LOOKUP_TOOL as i, META_DEX_LOOKUP_DESCRIPTION as n, handleMetaDexLookup as o, META_DEX_LOOKUP_TITLE as r, META_DEX_LOOKUP_ANNOTATIONS as t };
|
|
465
465
|
|
|
466
|
-
//# sourceMappingURL=dex-tool-
|
|
466
|
+
//# sourceMappingURL=dex-tool-D61sIjpq.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dex-tool-BoAYqhZO.mjs","names":[],"sources":["../src/mcp/dex-recipes.ts","../src/mcp/dex-tool.ts"],"sourcesContent":["/**\n * The first reads of each trail type, filled with the addresses of one\n * exchange. meta_dex_lookup returns them, so a host that loads no skill\n * (Claude Desktop chat) still gets the tested reads of\n * skills/chain-insights-dex*. The shapes are the skills' own: R3 and R4 of\n * chain-insights-dex, G1, G4 and G5 of the gauge trail, V1, V3 and V4 of the\n * vault trail, L1 to L3 of the launchpad trail.\n *\n * A value the lookup cannot know (a seller, a day, a transaction) is written\n * as a placeholder in angle brackets, and the step's `why` says where it comes\n * from. Every address the lookup knows is written in full.\n */\n\nimport type { DexEntry, TrailType } from './dex-registry.js'\n\nexport interface RecipeStep {\n step: string\n why: string\n query: string\n}\n\n/** The trail-type skill of each trail, for hosts that load skills. */\nexport const TRAIL_SKILLS: Record<TrailType, string> = {\n plain: 'chain-insights-dex',\n gauge: 'chain-insights-dex-gauge',\n vault: 'chain-insights-dex-vault',\n launchpad: 'chain-insights-dex-launchpad',\n}\n\nconst SELLER = '<seller address>'\nconst DAY = '<YYYY-MM-DD>'\nconst TX = '<tx_id>'\nconst TOKEN = '<launched token address>'\n\n/** The pools one factory deployed, by lifetime volume (R3). */\nexport function poolsByFactoryQuery(factory: string, limit = 10): string {\n return (\n `USE topology MATCH (f:Address {address: \"${factory}\"})-[:DEPLOYED_CONTRACT]->(p:Pool) WHERE p.total_volume_usd IS NOT NULL ` +\n 'RETURN f.address AS from_address, p.address AS to_address, p.labels AS to_labels, p.total_volume_usd AS total_volume_usd, p.tx_total_count AS tx_total_count ' +\n `ORDER BY p.total_volume_usd DESC LIMIT ${limit}`\n )\n}\n\n/** The senders of one pool on FLOWED_TO, by lifetime volume (R4, G1). */\nfunction sellersIntoPoolQuery(pool: string): string {\n return (\n `USE topology MATCH (s:Address)-[f:FLOWED_TO]->(p:Address {address: \"${pool}\"}) WHERE NOT s:Pool ` +\n 'RETURN s.address AS from_address, p.address AS to_address, labels(s) AS from_node_labels, f.amount_usd_sum AS amount_usd_sum, f.tx_count AS tx_count, f.first_seen_timestamp AS first_seen_timestamp, f.last_seen_timestamp AS last_seen_timestamp, s.labels AS from_labels, p.labels AS to_labels, s.is_exchange AS from_is_exchange, p.is_exchange AS to_is_exchange ' +\n 'ORDER BY f.amount_usd_sum DESC LIMIT 25'\n )\n}\n\n/** The payers whose swaps name one contract as the recipient, by sold volume (V4 shape). */\nfunction sellersIntoContractQuery(contract: string): string {\n return (\n `USE topology MATCH (s:Address)-[sw:SWAPPED]->(r:Address {address: \"${contract}\"}) WHERE NOT s:Pool ` +\n 'RETURN s.address AS from_address, r.address AS to_address, labels(s) AS from_node_labels, sw.sold_asset AS sold_asset, sw.bought_asset AS bought_asset, sw.sold_usd AS sold_usd, sw.bought_usd AS bought_usd, sw.swap_count AS swap_count, sw.pools AS pools, sw.last_seen_height AS last_seen_height ' +\n 'ORDER BY sw.sold_usd DESC LIMIT 25'\n )\n}\n\n/** One seller's swaps (R5, G2, V1). */\nfunction sellerSwapsQuery(): string {\n return (\n `USE topology MATCH (s:Address {address: \"${SELLER}\"})-[sw:SWAPPED]->(r:Address) ` +\n 'RETURN s.address AS from_address, r.address AS to_address, labels(r) AS to_node_labels, sw.sold_asset AS sold_asset, sw.bought_asset AS bought_asset, sw.sold_usd AS sold_usd, sw.bought_usd AS bought_usd, sw.swap_count AS swap_count, sw.pools AS pools, sw.last_seen_height AS last_seen_height ' +\n 'ORDER BY sw.swap_count DESC LIMIT 25'\n )\n}\n\n/** The facts SWAP rows of a seller and one recipient on one day (R6, G4, V3). */\nfunction swapRowsQuery(recipient: string): string {\n return (\n `USE facts MATCH (s:Address {address: \"${SELLER}\"})-[x:SWAP]->(r:Address {address: \"${recipient}\"}) WHERE x.block_date = \"${DAY}\" ` +\n 'RETURN x.tx_id AS tx_id, x.block_timestamp AS block_timestamp, x.payer AS payer, x.recipient AS recipient, x.sold_asset_symbol AS sold_asset_symbol, x.sold_usd AS sold_usd, x.bought_asset_symbol AS bought_asset_symbol, x.bought_usd AS bought_usd LIMIT 50'\n )\n}\n\n/** The transfers one router made in one transaction (G5). */\nfunction routerPayoutQuery(router: string): string {\n return (\n `USE facts MATCH (r:Address {address: \"${router}\"})-[t:TRANSFER]->(b:Address) WHERE t.block_date = \"${DAY}\" AND t.tx_id = \"${TX}\" ` +\n 'RETURN r.address AS from_address, b.address AS to_address, t.amount_usd AS amount_usd, t.asset_symbol AS asset_symbol, t.kind AS kind, t.tx_id AS tx_id LIMIT 10'\n )\n}\n\nconst dayStep: RecipeStep = {\n step: 'The day of a swap link',\n why: 'A SWAPPED link carries heights, not times: read the block of its last_seen_height for the day the facts reads need.',\n query:\n 'USE chain MATCH (b:Block {block_height: <last_seen_height>}) RETURN b.block_date, b.block_timestamp',\n}\n\n/**\n * The pool a trail starts from: the busiest pool read, else the registry's\n * example pool, else none.\n */\nfunction startPool(entry: DexEntry, topPool: string | null): string | null {\n return topPool ?? entry.example_pool ?? null\n}\n\nfunction poolsStep(entry: DexEntry): RecipeStep | null {\n const factory = entry.factories.find((address) => entry.roles[address] === 'factory')\n if (!factory) return null\n return {\n step: 'Pools of the exchange, by factory',\n why: `The pools ${entry.display} deployed, by lifetime volume. One batch member per factory: ${entry.factories.filter((a) => entry.roles[a] === 'factory').join(', ')}.`,\n query: poolsByFactoryQuery(factory),\n }\n}\n\n/** The first reads of the exchange's trail type, with its addresses filled in. */\nexport function recipeFor(entry: DexEntry, topPool: string | null): RecipeStep[] {\n const pool = startPool(entry, topPool)\n const steps: RecipeStep[] = []\n switch (entry.trail_type) {\n case 'gauge': {\n const router = entry.routers[0]\n if (router) {\n steps.push({\n step: 'Sellers into the router',\n why: `On ${entry.display} a swap pays the router, and the router pays on. These are the payers whose swaps name the router ${router}; the router is never the buyer.`,\n query: sellersIntoContractQuery(router),\n })\n }\n if (pool) {\n steps.push({\n step: 'Sellers into the busiest pool',\n why: `The senders of ${pool} on FLOWED_TO. A sender that also adds liquidity is a liquidity provider, not a seller.`,\n query: sellersIntoPoolQuery(pool),\n })\n } else {\n const pools = poolsStep(entry)\n if (pools) steps.push(pools)\n }\n if (router) {\n steps.push(dayStep)\n steps.push({\n step: \"A seller's swaps through the router on one day\",\n why: 'Fill the seller from the first step and the day from the block read: each row gives the tx_id of one swap.',\n query: swapRowsQuery(router),\n })\n steps.push({\n step: 'Who the router paid in that transaction',\n why: 'Fill the day and the tx_id: the receiver of the bought asset is the buyer. A pool or a pool manager there is the next leg, not the buyer.',\n query: routerPayoutQuery(router),\n })\n }\n break\n }\n case 'vault': {\n const manager = entry.factories[0]!\n steps.push({\n step: 'The swaps the pool manager settles',\n why: `${entry.display} keeps every pool in one manager, ${manager}. A manager deploys nothing: its pools are the pools of the swaps it settles.`,\n query: sellersIntoContractQuery(manager),\n })\n steps.push({\n step: \"One seller's swaps\",\n why: 'Fill a seller from the first step. A recipient that is the manager is never the buyer: read the facts row past it.',\n query: sellerSwapsQuery(),\n })\n steps.push(dayStep)\n steps.push({\n step: 'The facts SWAP row past the manager',\n why: 'Fill the seller and the day: the recipient column names who the manager paid.',\n query: swapRowsQuery(manager),\n })\n break\n }\n case 'launchpad': {\n const factory = entry.factories[0]!\n steps.push({\n step: 'Launches of the launchpad, newest first',\n why: `The contracts ${factory} created, with the creator of each.`,\n query:\n `USE topology MATCH (f:Address {address: \"${factory}\"})-[d:DEPLOYED_CONTRACT]->(t:Address) ` +\n 'RETURN f.address AS from_address, t.address AS to_address, labels(t) AS to_node_labels, t.labels AS to_labels, d.tx_origin AS creator, d.tx_id AS tx_id, d.block_height AS block_height, d.block_timestamp AS created_timestamp ORDER BY d.block_height DESC LIMIT 25',\n })\n steps.push({\n step: 'Traders on the curve of one launched token',\n why: 'Fill a launched token from the first step.',\n query:\n `USE topology MATCH (t:Address {address: \"${TOKEN}\"})-[f:FLOWED_TO]-(b:Address) WHERE NOT t:Pool ` +\n 'RETURN startNode(f).address AS from_address, endNode(f).address AS to_address, labels(b) AS node_labels, f.tx_count AS tx_count, f.amount_usd_sum AS amount_usd_sum, f.first_seen_timestamp AS first_seen_timestamp, f.last_seen_timestamp AS last_seen_timestamp ORDER BY f.tx_count DESC LIMIT 25',\n })\n steps.push({\n step: 'The first pool of one launched token',\n why: 'The oldest ADDED_LIQUIDITY into a :Pool is the graduation. None means it has not graduated in the graph yet.',\n query:\n `USE topology MATCH (t:Address {address: \"${TOKEN}\"})-[l:ADDED_LIQUIDITY]->(p:Pool) ` +\n 'RETURN t.address AS from_address, p.address AS to_address, p.labels AS to_labels, l.asset AS asset, l.usd AS usd, l.first_seen_height AS first_seen_height ORDER BY l.first_seen_height ASC LIMIT 5',\n })\n break\n }\n case 'plain': {\n if (pool) {\n steps.push({\n step: 'Sellers into the busiest pool',\n why: `The senders of ${pool} on FLOWED_TO, by lifetime volume. A seller that is a contract is often an aggregator or a router: say \"a contract\".`,\n query: sellersIntoPoolQuery(pool),\n })\n } else {\n const pools = poolsStep(entry)\n if (pools) steps.push(pools)\n }\n steps.push({\n step: \"Who a seller's swaps paid\",\n why: 'Fill a seller from the first step. Keep the rows whose pools hold the pool: the recipient is the buyer.',\n query: sellerSwapsQuery(),\n })\n steps.push(dayStep)\n steps.push({\n step: 'The swaps of a seller and a recipient on one day',\n why: 'Fill the seller, the recipient and the day.',\n query: swapRowsQuery('<recipient address>'),\n })\n break\n }\n }\n return steps\n}\n","/**\n * meta_dex_lookup: an exchange's name becomes its addresses.\n *\n * A local tool of the proxy. It matches the name against the exchange registry\n * (src/mcp/dex-registry.ts) at no cost, then sends one graph_query_batch of\n * anchored reads: Head for the family lag, each factory, manager and router by\n * its address, and the pools each factory deployed. Nothing is read by name and\n * nothing is gated on a family lag: a factory deployed months ago is not stale\n * because the swap family is behind. A name that is not covered sends no read.\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 exchange skills open\n * with. tests/host-parity.test.ts holds it to the skills' trigger words.\n */\n\nimport { ANSWER_HINT } from './answer-hint.js'\nimport { recipeFor, TRAIL_SKILLS, type RecipeStep, poolsByFactoryQuery } from './dex-recipes.js'\nimport {\n DexRegistryError,\n matchDex,\n normalizeDexNetwork,\n type DexCandidate,\n type DexEntry,\n type DexMatchResult,\n type LoadedRegistry,\n type RegistrySource,\n type Role,\n type TrailType,\n} from './dex-registry.js'\n\nexport const META_DEX_LOOKUP_TOOL = 'meta_dex_lookup'\nexport const META_DEX_LOOKUP_SCHEMA = 'chain-insights.meta-dex-lookup.v1' as const\nexport const META_DEX_LOOKUP_TITLE = 'Exchange by name or address'\nexport const META_DEX_LOOKUP_DESCRIPTION =\n 'Call this first when a question names a decentralized exchange, a launchpad or a vault ' +\n '(Aero, Aerodrome, Velodrome, up., Raphael, Topaz, Uniswap, PancakeSwap, Balancer, Curve, ' +\n \"Penguin, Virtuals, ...) and gives no address. It turns the name into the exchange's \" +\n 'factories, routers or pool manager, its biggest pools, and the first reads to send, ' +\n 'with every address in full. A misspelling within two letters is taken and named in ' +\n 'took_for. When matched is null the name is not covered: say so, list covered, and send ' +\n 'no graph query for the name. Never ask the user for a pool, factory or router address. ' +\n 'When the user gives a contract address instead of a name, send it as address (0x plus 40 hex, ' +\n 'any case, with no name): the answer is the exchange whose factory, router or manager it is, ' +\n 'and took_for names the role it holds. When matched is null no exchange row holds the address: ' +\n 'send no read for it. Give a name or an address, not both.'\nexport const META_DEX_LOOKUP_ANNOTATIONS = {\n readOnlyHint: true,\n idempotentHint: true,\n openWorldHint: false,\n} as const\nexport const META_DEX_LOOKUP_ARGS = ['network', 'name', 'address', 'pools'] as const\n\n/** The pools returned per exchange, and per factory read. */\nexport const POOLS_LIMIT = 10\n/** A batch holds at most 20 members; Head and the pool reads take their share. */\nconst CONTRACT_MEMBERS_MAX = 12\n\nexport interface ContractRow {\n address: string\n role: Role\n confirmed: boolean\n confirmed_by?: string\n}\n\nexport interface PoolRow {\n address: string\n labels: string[]\n total_volume_usd: number\n tx_total_count: number\n}\n\nexport interface FamilyLag {\n behind_money: number | null\n behind_dex: number | null\n behind_transfers: number | null\n}\n\nexport interface DexMatch {\n dex: string\n display: string\n trail_type: TrailType\n /** The skill a host with skills loads next. */\n skill: string\n factories: ContractRow[]\n routers: ContractRow[]\n manager: ContractRow | null\n pools: PoolRow[]\n recipe: RecipeStep[]\n}\n\nexport interface CoveredExchange {\n dex: string\n display: string\n trail_type: TrailType\n factories: string[]\n routers: string[]\n}\n\nexport interface MetaDexLookupResult {\n schema: typeof META_DEX_LOOKUP_SCHEMA\n network: string\n registry_version: number\n registry_source: RegistrySource\n matched: DexMatch | null\n /** A near name hit: the name as typed. An address hit: the role it holds and the verification cell. */\n took_for?: string\n candidates: DexCandidate[]\n covered: string[]\n /** With no name: every covered exchange, with its key, trail type and contracts. */\n exchanges?: CoveredExchange[]\n families: FamilyLag | null\n /** What a read could not do: a lane that is not reachable, a member that was refused. */\n notes?: string[]\n hint: string\n}\n\n/** The batch reply as the remote client returns it. */\nexport type BatchAnswer = {\n content?: unknown[]\n structuredContent?: unknown\n isError?: boolean\n}\n\nexport interface DexToolDependencies {\n loadRegistry: (network: string) => Promise<LoadedRegistry>\n /** One graph_query_batch through the proxy's remote client, billed as any read. */\n graphQueryBatch: (args: {\n network: string\n queries: Array<{ id: string; query: string }>\n }) => Promise<BatchAnswer>\n /** The reason no read can be sent now, or undefined when the graph is reachable. */\n unavailable?: () => Promise<string | undefined> | string | undefined\n /** The text of a call that threw: payment required, transport. */\n describeFailure: (err: unknown) => string\n}\n\nexport type MetaDexLookupToolResult = {\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): MetaDexLookupToolResult {\n return { content: [{ type: 'text', text }], isError: true }\n}\n\ntype Member = { id?: unknown; ok?: unknown; results?: unknown; error?: unknown }\n\nfunction membersOf(answer: BatchAnswer): Map<string, Member> {\n const facts = isRecord(answer.structuredContent) ? answer.structuredContent.facts : undefined\n const queries = isRecord(facts) ? facts.queries : undefined\n const members = new Map<string, Member>()\n if (Array.isArray(queries)) {\n for (const member of queries)\n if (isRecord(member) && typeof member.id === 'string') members.set(member.id, member)\n }\n return members\n}\n\nconst rowsOf = (member: Member | undefined): Array<Record<string, unknown>> =>\n member?.ok === true && Array.isArray(member.results) ? member.results.filter(isRecord) : []\n\nconst numberOrNull = (value: unknown): number | null => {\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (typeof value === 'string' && value.trim() !== '' && Number.isFinite(Number(value)))\n return Number(value)\n return null\n}\n\nconst stringList = (value: unknown): string[] =>\n Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : []\n\n/** A column of a row, read under its alias or as the query wrote it (h.behind_dex). */\nfunction column(row: Record<string, unknown>, name: string, variable: string): unknown {\n return name in row ? row[name] : row[`${variable}.${name}`]\n}\n\nexport const HEAD_QUERY =\n 'USE chain MATCH (h:Head) RETURN h.behind_money, h.behind_dex, h.behind_transfers'\n\nexport function contractQuery(address: string): string {\n return (\n `USE topology MATCH (a:Address {address: \"${address}\"}) ` +\n 'RETURN a.address AS address, labels(a) AS node_labels, a.labels AS labels, a.is_contract AS is_contract LIMIT 1'\n )\n}\n\nexport function contractListQuery(addresses: string[]): string {\n return (\n `USE topology MATCH (a:Address) WHERE a.address IN [${addresses.map((a) => `\"${a}\"`).join(', ')}] ` +\n `RETURN a.address AS address, labels(a) AS node_labels, a.labels AS labels, a.is_contract AS is_contract LIMIT ${addresses.length}`\n )\n}\n\n/** The anchored reads of one exchange: Head, each contract, and the pools of each factory. */\nexport function lookupQueries(\n entry: DexEntry,\n pools: boolean\n): Array<{ id: string; query: string }> {\n const contracts = Object.keys(entry.roles)\n const queries: Array<{ id: string; query: string }> = [{ id: 'head', query: HEAD_QUERY }]\n if (contracts.length <= CONTRACT_MEMBERS_MAX) {\n for (const address of contracts)\n queries.push({ id: `contract:${address}`, query: contractQuery(address) })\n } else {\n queries.push({ id: 'contracts', query: contractListQuery(contracts) })\n }\n if (pools) {\n for (const factory of entry.factories.filter((address) => entry.roles[address] === 'factory')) {\n queries.push({ id: `pools:${factory}`, query: poolsByFactoryQuery(factory, POOLS_LIMIT) })\n }\n }\n return queries\n}\n\nfunction confirmation(\n row: Record<string, unknown> | undefined\n): Pick<ContractRow, 'confirmed' | 'confirmed_by'> {\n if (!row) return { confirmed: false }\n if (row.is_contract === true) return { confirmed: true, confirmed_by: 'is_contract' }\n if (stringList(row.node_labels).includes('Contract'))\n return { confirmed: true, confirmed_by: ':Contract' }\n return { confirmed: false }\n}\n\nfunction readMatch(\n entry: DexEntry,\n members: Map<string, Member>,\n read: boolean\n): {\n contracts: Map<string, ContractRow>\n pools: PoolRow[]\n families: FamilyLag | null\n notes: string[]\n} {\n const notes: string[] = []\n const contracts = new Map<string, ContractRow>()\n const listed = new Map(rowsOf(members.get('contracts')).map((row) => [String(row.address), row]))\n for (const [address, role] of Object.entries(entry.roles)) {\n const row = members.has(`contract:${address}`)\n ? rowsOf(members.get(`contract:${address}`))[0]\n : listed.get(address)\n contracts.set(address, { address, role, ...confirmation(row) })\n }\n const byAddress = new Map<string, PoolRow>()\n for (const [id, member] of members) {\n if (!id.startsWith('pools:')) continue\n for (const row of rowsOf(member)) {\n const address = typeof row.to_address === 'string' ? row.to_address : null\n const volume = numberOrNull(row.total_volume_usd)\n if (!address || volume === null || byAddress.has(address)) continue\n byAddress.set(address, {\n address,\n labels: stringList(row.to_labels),\n total_volume_usd: volume,\n tx_total_count: numberOrNull(row.tx_total_count) ?? 0,\n })\n }\n }\n const pools = [...byAddress.values()]\n .sort((a, b) => b.total_volume_usd - a.total_volume_usd)\n .slice(0, POOLS_LIMIT)\n const head = rowsOf(members.get('head'))[0]\n const families: FamilyLag | null = head\n ? {\n behind_money: numberOrNull(column(head, 'behind_money', 'h')),\n behind_dex: numberOrNull(column(head, 'behind_dex', 'h')),\n behind_transfers: numberOrNull(column(head, 'behind_transfers', 'h')),\n }\n : null\n if (read) {\n for (const [id, member] of members) {\n if (member.ok !== true)\n notes.push(\n `${id}: ${typeof member.error === 'string' ? member.error : 'the read was not served'}`\n )\n }\n }\n return { contracts, pools, families, notes }\n}\n\nconst ADDRESS_FORM = /^0x[0-9a-fA-F]{40}$/\n\nfunction hintFor(\n result: Omit<MetaDexLookupResult, 'hint'>,\n name: string | null,\n address: string | null = null\n): string {\n if (address !== null && !result.matched) {\n return `${ANSWER_HINT} No exchange row holds ${address}: it is not a registered exchange contract. Send no exchange read for it; read the graph for what the address did.`\n }\n if (address !== null && result.matched) {\n const { matched } = result\n return (\n `${ANSWER_HINT} Say in one line: \"${address} is a ${result.took_for} row of ${matched.display}.\" Ask nothing. ` +\n `Exchange ${matched.display}, trail ${matched.trail_type}: send the first reads of recipe, ` +\n `anchored on the addresses above, and load ${matched.skill} when this host has skills. ` +\n 'Read families before a SWAPPED search: it is sent when behind_dex is at most 100000. Never ask the user for an address.'\n )\n }\n if (name === null) {\n return `${ANSWER_HINT} These are the exchanges the registry covers. Call meta_dex_lookup with a name for its addresses and first reads.`\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 return (\n `${ANSWER_HINT} ${took}Exchange ${matched.display}, trail ${matched.trail_type}: send the first reads of recipe, ` +\n `anchored on the addresses above, and load ${matched.skill} when this host has skills. ` +\n 'Read families before a SWAPPED search: it is sent when behind_dex is at most 100000. Never ask the user for an address.'\n )\n }\n if (result.candidates.length > 0) {\n const names = result.candidates\n .map((candidate) => `${candidate.display} (${candidate.dex})`)\n .join(', ')\n return `${ANSWER_HINT} ${result.candidates.length} rows fit \"${name}\": ${names}. Name both or pick one: call meta_dex_lookup with each key. Never guess one, never ask the user for an address.`\n }\n return `${ANSWER_HINT} ${name} is not covered. Send no query for the name: say so in one line and list the covered exchanges by name.`\n}\n\nfunction textResult(structured: MetaDexLookupResult): MetaDexLookupToolResult {\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\n/** meta_dex_lookup, {network, name?, address?, pools?}. Every argument is checked before the registry is read. */\nexport async function handleMetaDexLookup(\n args: unknown,\n deps: DexToolDependencies\n): Promise<MetaDexLookupToolResult> {\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 = typeof rawAddress === 'string' && rawAddress.trim() !== '' ? rawAddress.trim() : null\n if (name !== null && addressText !== null) 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 const rawPools = record.pools\n if (rawPools !== undefined && rawPools !== null && typeof rawPools !== 'boolean') {\n return errorResult('invalid_pools: pools must be true or false')\n }\n const pools = rawPools !== false\n\n let loaded: LoadedRegistry\n try {\n loaded = await deps.loadRegistry(network)\n } catch (err) {\n return errorResult(\n err instanceof DexRegistryError\n ? err.message\n : `exchange registry unavailable: ${(err as Error).message}`\n )\n }\n const { document } = loaded\n const base = {\n schema: META_DEX_LOOKUP_SCHEMA,\n network,\n registry_version: document.registry_version,\n registry_source: loaded.source,\n }\n\n if (name === null && address === null) {\n const result = {\n ...base,\n matched: null,\n candidates: [],\n covered: document.rows.map((row) => row.display),\n exchanges: document.rows.map((row) => ({\n dex: row.dex,\n display: row.display,\n trail_type: row.trail_type,\n factories: row.factories,\n routers: row.routers,\n })),\n families: null,\n }\n return textResult({ ...result, hint: hintFor(result, null) })\n }\n\n let match: DexMatchResult\n if (address !== null) {\n const holder = document.rows.find((row) => address in row.roles)\n match = {\n matched: holder ?? null,\n ...(holder ? { took_for: `${holder.roles[address]}, served` } : {}),\n candidates: [],\n covered: document.rows.map((row) => row.display),\n }\n } else {\n match = matchDex(name as string, document.rows)\n }\n if (!match.matched) {\n const result = {\n ...base,\n matched: null,\n candidates: match.candidates,\n covered: match.covered,\n families: null,\n }\n return textResult({ ...result, hint: hintFor(result, name, address) })\n }\n\n const entry = match.matched\n const queries = lookupQueries(entry, pools)\n let members = new Map<string, Member>()\n const notes: string[] = []\n const unavailable = await deps.unavailable?.()\n if (unavailable) {\n notes.push(\n `No graph read was sent: ${unavailable} The contracts are the reviewed registry rows, not yet confirmed on the graph.`\n )\n } else {\n try {\n const answer = await deps.graphQueryBatch({ network, queries })\n members = membersOf(answer)\n if (answer.isError === true && members.size === 0) {\n const first = Array.isArray(answer.content) ? answer.content[0] : undefined\n notes.push(\n `The graph refused the reads: ${isRecord(first) && typeof first.text === 'string' ? first.text : 'no reason given'}`\n )\n }\n } catch (err) {\n notes.push(`The graph reads failed: ${deps.describeFailure(err)}`)\n }\n }\n const read = readMatch(entry, members, members.size > 0)\n notes.push(...read.notes)\n const contractsOf = (role: Role): ContractRow[] =>\n [...read.contracts.values()].filter((contract) => contract.role === role)\n const topPool = read.pools[0]?.address ?? null\n const matched: DexMatch = {\n dex: entry.dex,\n display: entry.display,\n trail_type: entry.trail_type,\n skill: TRAIL_SKILLS[entry.trail_type],\n factories: contractsOf('factory'),\n routers: contractsOf('router'),\n manager: contractsOf('manager')[0] ?? null,\n pools: read.pools,\n recipe: recipeFor(entry, topPool),\n }\n const result = {\n ...base,\n matched,\n ...(match.took_for ? { took_for: match.took_for } : {}),\n candidates: [],\n covered: match.covered,\n families: read.families,\n ...(notes.length > 0 ? { notes } : {}),\n }\n return textResult({ ...result, hint: hintFor(result, name, address) })\n}\n"],"mappings":";;;;;AAsBA,MAAa,eAA0C;CACrD,OAAO;CACP,OAAO;CACP,OAAO;CACP,WAAW;AACb;AAEA,MAAM,SAAS;AACf,MAAM,MAAM;AACZ,MAAM,KAAK;AACX,MAAM,QAAQ;;AAGd,SAAgB,oBAAoB,SAAiB,QAAQ,IAAY;CACvE,OACE,4CAA4C,QAAQ,8QAEV;AAE9C;;AAGA,SAAS,qBAAqB,MAAsB;CAClD,OACE,uEAAuE,KAAK;AAIhF;;AAGA,SAAS,yBAAyB,UAA0B;CAC1D,OACE,sEAAsE,SAAS;AAInF;;AAGA,SAAS,mBAA2B;CAClC,OACE,4CAA4C,OAAO;AAIvD;;AAGA,SAAS,cAAc,WAA2B;CAChD,OACE,yCAAyC,OAAO,sCAAsC,UAAU,4BA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AC;CACvD,MAAM,KAAK,GAAG,KAAK,KAAK;CACxB,MAAM,eAAe,SACnB,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,CAAC,CAAC,QAAQ,aAAa,SAAS,SAAS,IAAI;CAC1E,MAAM,UAAU,KAAK,MAAM,EAAE,EAAE,WAAW;CAC1C,MAAM,UAAoB;EACxB,KAAK,MAAM;EACX,SAAS,MAAM;EACf,YAAY,MAAM;EAClB,OAAO,aAAa,MAAM;EAC1B,WAAW,YAAY,SAAS;EAChC,SAAS,YAAY,QAAQ;EAC7B,SAAS,YAAY,SAAS,CAAC,CAAC,MAAM;EACtC,OAAO,KAAK;EACZ,QAAQ,UAAU,OAAO,OAAO;CAClC;CACA,MAAM,SAAS;EACb,GAAG;EACH;EACA,GAAI,MAAM,WAAW,EAAE,UAAU,MAAM,SAAS,IAAI,CAAC;EACrD,YAAY,CAAC;EACb,SAAS,MAAM;EACf,UAAU,KAAK;EACf,GAAI,MAAM,SAAS,IAAI,EAAE,MAAM,IAAI,CAAC;CACtC;CACA,OAAO,WAAW;EAAE,GAAG;EAAQ,MAAM,QAAQ,QAAQ,MAAM,OAAO;CAAE,CAAC;AACvE"}
|
|
1
|
+
{"version":3,"file":"dex-tool-D61sIjpq.mjs","names":[],"sources":["../src/mcp/dex-recipes.ts","../src/mcp/dex-tool.ts"],"sourcesContent":["/**\n * The first reads of each trail type, filled with the addresses of one\n * exchange. meta_dex_lookup returns them, so a host that loads no skill\n * (Claude Desktop chat) still gets the tested reads of\n * skills/chain-insights-dex*. The shapes are the skills' own: R3 and R4 of\n * chain-insights-dex, G1, G4 and G5 of the gauge trail, V1, V3 and V4 of the\n * vault trail, L1 to L3 of the launchpad trail.\n *\n * A value the lookup cannot know (a seller, a day, a transaction) is written\n * as a placeholder in angle brackets, and the step's `why` says where it comes\n * from. Every address the lookup knows is written in full.\n */\n\nimport type { DexEntry, TrailType } from './dex-registry.js'\n\nexport interface RecipeStep {\n step: string\n why: string\n query: string\n}\n\n/** The trail-type skill of each trail, for hosts that load skills. */\nexport const TRAIL_SKILLS: Record<TrailType, string> = {\n plain: 'chain-insights-dex',\n gauge: 'chain-insights-dex-gauge',\n vault: 'chain-insights-dex-vault',\n launchpad: 'chain-insights-dex-launchpad',\n}\n\nconst SELLER = '<seller address>'\nconst DAY = '<YYYY-MM-DD>'\nconst TX = '<tx_id>'\nconst TOKEN = '<launched token address>'\n\n/** The pools one factory deployed, by lifetime volume (R3). */\nexport function poolsByFactoryQuery(factory: string, limit = 10): string {\n return (\n `USE topology MATCH (f:Address {address: \"${factory}\"})-[:DEPLOYED_CONTRACT]->(p:Pool) WHERE p.total_volume_usd IS NOT NULL ` +\n 'RETURN f.address AS from_address, p.address AS to_address, p.labels AS to_labels, p.total_volume_usd AS total_volume_usd, p.tx_total_count AS tx_total_count ' +\n `ORDER BY p.total_volume_usd DESC LIMIT ${limit}`\n )\n}\n\n/** The senders of one pool on FLOWED_TO, by lifetime volume (R4, G1). */\nfunction sellersIntoPoolQuery(pool: string): string {\n return (\n `USE topology MATCH (s:Address)-[f:FLOWED_TO]->(p:Address {address: \"${pool}\"}) WHERE NOT s:Pool ` +\n 'RETURN s.address AS from_address, p.address AS to_address, labels(s) AS from_node_labels, f.amount_usd_sum AS amount_usd_sum, f.tx_count AS tx_count, f.first_seen_timestamp AS first_seen_timestamp, f.last_seen_timestamp AS last_seen_timestamp, s.labels AS from_labels, p.labels AS to_labels, s.is_exchange AS from_is_exchange, p.is_exchange AS to_is_exchange ' +\n 'ORDER BY f.amount_usd_sum DESC LIMIT 25'\n )\n}\n\n/** The payers whose swaps name one contract as the recipient, by sold volume (V4 shape). */\nfunction sellersIntoContractQuery(contract: string): string {\n return (\n `USE topology MATCH (s:Address)-[sw:SWAPPED]->(r:Address {address: \"${contract}\"}) WHERE NOT s:Pool ` +\n 'RETURN s.address AS from_address, r.address AS to_address, labels(s) AS from_node_labels, sw.sold_asset AS sold_asset, sw.bought_asset AS bought_asset, sw.sold_usd AS sold_usd, sw.bought_usd AS bought_usd, sw.swap_count AS swap_count, sw.pools AS pools, sw.last_seen_height AS last_seen_height ' +\n 'ORDER BY sw.sold_usd DESC LIMIT 25'\n )\n}\n\n/** One seller's swaps (R5, G2, V1). */\nfunction sellerSwapsQuery(): string {\n return (\n `USE topology MATCH (s:Address {address: \"${SELLER}\"})-[sw:SWAPPED]->(r:Address) ` +\n 'RETURN s.address AS from_address, r.address AS to_address, labels(r) AS to_node_labels, sw.sold_asset AS sold_asset, sw.bought_asset AS bought_asset, sw.sold_usd AS sold_usd, sw.bought_usd AS bought_usd, sw.swap_count AS swap_count, sw.pools AS pools, sw.last_seen_height AS last_seen_height ' +\n 'ORDER BY sw.swap_count DESC LIMIT 25'\n )\n}\n\n/** The facts SWAP rows of a seller and one recipient on one day (R6, G4, V3). */\nfunction swapRowsQuery(recipient: string): string {\n return (\n `USE facts MATCH (s:Address {address: \"${SELLER}\"})-[x:SWAP]->(r:Address {address: \"${recipient}\"}) WHERE x.block_date = \"${DAY}\" ` +\n 'RETURN x.tx_id AS tx_id, x.block_timestamp AS block_timestamp, x.payer AS payer, x.recipient AS recipient, x.sold_asset_symbol AS sold_asset_symbol, x.sold_usd AS sold_usd, x.bought_asset_symbol AS bought_asset_symbol, x.bought_usd AS bought_usd LIMIT 50'\n )\n}\n\n/** The transfers one router made in one transaction (G5). */\nfunction routerPayoutQuery(router: string): string {\n return (\n `USE facts MATCH (r:Address {address: \"${router}\"})-[t:TRANSFER]->(b:Address) WHERE t.block_date = \"${DAY}\" AND t.tx_id = \"${TX}\" ` +\n 'RETURN r.address AS from_address, b.address AS to_address, t.amount_usd AS amount_usd, t.asset_symbol AS asset_symbol, t.kind AS kind, t.tx_id AS tx_id LIMIT 10'\n )\n}\n\nconst dayStep: RecipeStep = {\n step: 'The day of a swap link',\n why: 'A SWAPPED link carries heights, not times: read the block of its last_seen_height for the day the facts reads need.',\n query:\n 'USE chain MATCH (b:Block {block_height: <last_seen_height>}) RETURN b.block_date, b.block_timestamp',\n}\n\n/**\n * The pool a trail starts from: the busiest pool read, else the registry's\n * example pool, else none.\n */\nfunction startPool(entry: DexEntry, topPool: string | null): string | null {\n return topPool ?? entry.example_pool ?? null\n}\n\nfunction poolsStep(entry: DexEntry): RecipeStep | null {\n const factory = entry.factories.find((address) => entry.roles[address] === 'factory')\n if (!factory) return null\n return {\n step: 'Pools of the exchange, by factory',\n why: `The pools ${entry.display} deployed, by lifetime volume. One batch member per factory: ${entry.factories.filter((a) => entry.roles[a] === 'factory').join(', ')}.`,\n query: poolsByFactoryQuery(factory),\n }\n}\n\n/** The first reads of the exchange's trail type, with its addresses filled in. */\nexport function recipeFor(entry: DexEntry, topPool: string | null): RecipeStep[] {\n const pool = startPool(entry, topPool)\n const steps: RecipeStep[] = []\n switch (entry.trail_type) {\n case 'gauge': {\n const router = entry.routers[0]\n if (router) {\n steps.push({\n step: 'Sellers into the router',\n why: `On ${entry.display} a swap pays the router, and the router pays on. These are the payers whose swaps name the router ${router}; the router is never the buyer.`,\n query: sellersIntoContractQuery(router),\n })\n }\n if (pool) {\n steps.push({\n step: 'Sellers into the busiest pool',\n why: `The senders of ${pool} on FLOWED_TO. A sender that also adds liquidity is a liquidity provider, not a seller.`,\n query: sellersIntoPoolQuery(pool),\n })\n } else {\n const pools = poolsStep(entry)\n if (pools) steps.push(pools)\n }\n if (router) {\n steps.push(dayStep)\n steps.push({\n step: \"A seller's swaps through the router on one day\",\n why: 'Fill the seller from the first step and the day from the block read: each row gives the tx_id of one swap.',\n query: swapRowsQuery(router),\n })\n steps.push({\n step: 'Who the router paid in that transaction',\n why: 'Fill the day and the tx_id: the receiver of the bought asset is the buyer. A pool or a pool manager there is the next leg, not the buyer.',\n query: routerPayoutQuery(router),\n })\n }\n break\n }\n case 'vault': {\n const manager = entry.factories[0]!\n steps.push({\n step: 'The swaps the pool manager settles',\n why: `${entry.display} keeps every pool in one manager, ${manager}. A manager deploys nothing: its pools are the pools of the swaps it settles.`,\n query: sellersIntoContractQuery(manager),\n })\n steps.push({\n step: \"One seller's swaps\",\n why: 'Fill a seller from the first step. A recipient that is the manager is never the buyer: read the facts row past it.',\n query: sellerSwapsQuery(),\n })\n steps.push(dayStep)\n steps.push({\n step: 'The facts SWAP row past the manager',\n why: 'Fill the seller and the day: the recipient column names who the manager paid.',\n query: swapRowsQuery(manager),\n })\n break\n }\n case 'launchpad': {\n const factory = entry.factories[0]!\n steps.push({\n step: 'Launches of the launchpad, newest first',\n why: `The contracts ${factory} created, with the creator of each.`,\n query:\n `USE topology MATCH (f:Address {address: \"${factory}\"})-[d:DEPLOYED_CONTRACT]->(t:Address) ` +\n 'RETURN f.address AS from_address, t.address AS to_address, labels(t) AS to_node_labels, t.labels AS to_labels, d.tx_origin AS creator, d.tx_id AS tx_id, d.block_height AS block_height, d.block_timestamp AS created_timestamp ORDER BY d.block_height DESC LIMIT 25',\n })\n steps.push({\n step: 'Traders on the curve of one launched token',\n why: 'Fill a launched token from the first step.',\n query:\n `USE topology MATCH (t:Address {address: \"${TOKEN}\"})-[f:FLOWED_TO]-(b:Address) WHERE NOT t:Pool ` +\n 'RETURN startNode(f).address AS from_address, endNode(f).address AS to_address, labels(b) AS node_labels, f.tx_count AS tx_count, f.amount_usd_sum AS amount_usd_sum, f.first_seen_timestamp AS first_seen_timestamp, f.last_seen_timestamp AS last_seen_timestamp ORDER BY f.tx_count DESC LIMIT 25',\n })\n steps.push({\n step: 'The first pool of one launched token',\n why: 'The oldest ADDED_LIQUIDITY into a :Pool is the graduation. None means it has not graduated in the graph yet.',\n query:\n `USE topology MATCH (t:Address {address: \"${TOKEN}\"})-[l:ADDED_LIQUIDITY]->(p:Pool) ` +\n 'RETURN t.address AS from_address, p.address AS to_address, p.labels AS to_labels, l.asset AS asset, l.usd AS usd, l.first_seen_height AS first_seen_height ORDER BY l.first_seen_height ASC LIMIT 5',\n })\n break\n }\n case 'plain': {\n if (pool) {\n steps.push({\n step: 'Sellers into the busiest pool',\n why: `The senders of ${pool} on FLOWED_TO, by lifetime volume. A seller that is a contract is often an aggregator or a router: say \"a contract\".`,\n query: sellersIntoPoolQuery(pool),\n })\n } else {\n const pools = poolsStep(entry)\n if (pools) steps.push(pools)\n }\n steps.push({\n step: \"Who a seller's swaps paid\",\n why: 'Fill a seller from the first step. Keep the rows whose pools hold the pool: the recipient is the buyer.',\n query: sellerSwapsQuery(),\n })\n steps.push(dayStep)\n steps.push({\n step: 'The swaps of a seller and a recipient on one day',\n why: 'Fill the seller, the recipient and the day.',\n query: swapRowsQuery('<recipient address>'),\n })\n break\n }\n }\n return steps\n}\n","/**\n * meta_dex_lookup: an exchange's name becomes its addresses.\n *\n * A local tool of the proxy. It matches the name against the exchange registry\n * (src/mcp/dex-registry.ts) at no cost, then sends one graph_query_batch of\n * anchored reads: Head for the family lag, each factory, manager and router by\n * its address, and the pools each factory deployed. Nothing is read by name and\n * nothing is gated on a family lag: a factory deployed months ago is not stale\n * because the swap family is behind. A name that is not covered sends no read.\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 exchange skills open\n * with. tests/host-parity.test.ts holds it to the skills' trigger words.\n */\n\nimport { ANSWER_HINT } from './answer-hint.js'\nimport { recipeFor, TRAIL_SKILLS, type RecipeStep, poolsByFactoryQuery } from './dex-recipes.js'\nimport {\n DexRegistryError,\n matchDex,\n normalizeDexNetwork,\n type DexCandidate,\n type DexEntry,\n type DexMatchResult,\n type LoadedRegistry,\n type RegistrySource,\n type Role,\n type TrailType,\n} from './dex-registry.js'\n\nexport const META_DEX_LOOKUP_TOOL = 'meta_dex_lookup'\nexport const META_DEX_LOOKUP_SCHEMA = 'chain-insights.meta-dex-lookup.v1' as const\nexport const META_DEX_LOOKUP_TITLE = 'Exchange by name or address'\nexport const META_DEX_LOOKUP_DESCRIPTION =\n 'Call this first when a question names a decentralized exchange, a launchpad or a vault ' +\n '(Aero, Aerodrome, Velodrome, up., Raphael, Topaz, Uniswap, PancakeSwap, Balancer, Curve, ' +\n \"Penguin, Virtuals, ...) and gives no address. It turns the name into the exchange's \" +\n 'factories, routers or pool manager, its biggest pools, and the first reads to send, ' +\n 'with every address in full. A misspelling within two letters is taken and named in ' +\n 'took_for. When matched is null the name is not covered: say so, list covered, and send ' +\n 'no graph query for the name. Never ask the user for a pool, factory or router address. ' +\n 'When the user gives a contract address instead of a name, send it as address (0x plus 40 hex, ' +\n 'any case, with no name): the answer is the exchange whose factory, router or manager it is, ' +\n 'and took_for names the role it holds. When matched is null no exchange row holds the address: ' +\n 'send no read for it. Give a name or an address, not both.'\nexport const META_DEX_LOOKUP_ANNOTATIONS = {\n readOnlyHint: true,\n idempotentHint: true,\n openWorldHint: false,\n} as const\nexport const META_DEX_LOOKUP_ARGS = ['network', 'name', 'address', 'pools'] as const\n\n/** The pools returned per exchange, and per factory read. */\nexport const POOLS_LIMIT = 10\n/** A batch holds at most 20 members; Head and the pool reads take their share. */\nconst CONTRACT_MEMBERS_MAX = 12\n\nexport interface ContractRow {\n address: string\n role: Role\n confirmed: boolean\n confirmed_by?: string\n}\n\nexport interface PoolRow {\n address: string\n labels: string[]\n total_volume_usd: number\n tx_total_count: number\n}\n\nexport interface FamilyLag {\n behind_money: number | null\n behind_dex: number | null\n behind_transfers: number | null\n}\n\nexport interface DexMatch {\n dex: string\n display: string\n trail_type: TrailType\n /** The skill a host with skills loads next. */\n skill: string\n factories: ContractRow[]\n routers: ContractRow[]\n manager: ContractRow | null\n pools: PoolRow[]\n recipe: RecipeStep[]\n}\n\nexport interface CoveredExchange {\n dex: string\n display: string\n trail_type: TrailType\n factories: string[]\n routers: string[]\n}\n\nexport interface MetaDexLookupResult {\n schema: typeof META_DEX_LOOKUP_SCHEMA\n network: string\n registry_version: number\n registry_source: RegistrySource\n matched: DexMatch | null\n /** A near name hit: the name as typed. An address hit: the role it holds and the verification cell. */\n took_for?: string\n candidates: DexCandidate[]\n covered: string[]\n /** With no name: every covered exchange, with its key, trail type and contracts. */\n exchanges?: CoveredExchange[]\n families: FamilyLag | null\n /** What a read could not do: a lane that is not reachable, a member that was refused. */\n notes?: string[]\n hint: string\n}\n\n/** The batch reply as the remote client returns it. */\nexport type BatchAnswer = {\n content?: unknown[]\n structuredContent?: unknown\n isError?: boolean\n}\n\nexport interface DexToolDependencies {\n loadRegistry: (network: string) => Promise<LoadedRegistry>\n /** One graph_query_batch through the proxy's remote client, billed as any read. */\n graphQueryBatch: (args: {\n network: string\n queries: Array<{ id: string; query: string }>\n }) => Promise<BatchAnswer>\n /** The reason no read can be sent now, or undefined when the graph is reachable. */\n unavailable?: () => Promise<string | undefined> | string | undefined\n /** The text of a call that threw: payment required, transport. */\n describeFailure: (err: unknown) => string\n}\n\nexport type MetaDexLookupToolResult = {\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): MetaDexLookupToolResult {\n return { content: [{ type: 'text', text }], isError: true }\n}\n\ntype Member = { id?: unknown; ok?: unknown; results?: unknown; error?: unknown }\n\nfunction membersOf(answer: BatchAnswer): Map<string, Member> {\n const facts = isRecord(answer.structuredContent) ? answer.structuredContent.facts : undefined\n const queries = isRecord(facts) ? facts.queries : undefined\n const members = new Map<string, Member>()\n if (Array.isArray(queries)) {\n for (const member of queries)\n if (isRecord(member) && typeof member.id === 'string') members.set(member.id, member)\n }\n return members\n}\n\nconst rowsOf = (member: Member | undefined): Array<Record<string, unknown>> =>\n member?.ok === true && Array.isArray(member.results) ? member.results.filter(isRecord) : []\n\nconst numberOrNull = (value: unknown): number | null => {\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (typeof value === 'string' && value.trim() !== '' && Number.isFinite(Number(value)))\n return Number(value)\n return null\n}\n\nconst stringList = (value: unknown): string[] =>\n Array.isArray(value) ? value.filter((entry): entry is string => typeof entry === 'string') : []\n\n/** A column of a row, read under its alias or as the query wrote it (h.behind_dex). */\nfunction column(row: Record<string, unknown>, name: string, variable: string): unknown {\n return name in row ? row[name] : row[`${variable}.${name}`]\n}\n\nexport const HEAD_QUERY =\n 'USE chain MATCH (h:Head) RETURN h.behind_money, h.behind_dex, h.behind_transfers'\n\nexport function contractQuery(address: string): string {\n return (\n `USE topology MATCH (a:Address {address: \"${address}\"}) ` +\n 'RETURN a.address AS address, labels(a) AS node_labels, a.labels AS labels, a.is_contract AS is_contract LIMIT 1'\n )\n}\n\nexport function contractListQuery(addresses: string[]): string {\n return (\n `USE topology MATCH (a:Address) WHERE a.address IN [${addresses.map((a) => `\"${a}\"`).join(', ')}] ` +\n `RETURN a.address AS address, labels(a) AS node_labels, a.labels AS labels, a.is_contract AS is_contract LIMIT ${addresses.length}`\n )\n}\n\n/** The anchored reads of one exchange: Head, each contract, and the pools of each factory. */\nexport function lookupQueries(\n entry: DexEntry,\n pools: boolean\n): Array<{ id: string; query: string }> {\n const contracts = Object.keys(entry.roles)\n const queries: Array<{ id: string; query: string }> = [{ id: 'head', query: HEAD_QUERY }]\n if (contracts.length <= CONTRACT_MEMBERS_MAX) {\n for (const address of contracts)\n queries.push({ id: `contract:${address}`, query: contractQuery(address) })\n } else {\n queries.push({ id: 'contracts', query: contractListQuery(contracts) })\n }\n if (pools) {\n for (const factory of entry.factories.filter((address) => entry.roles[address] === 'factory')) {\n queries.push({ id: `pools:${factory}`, query: poolsByFactoryQuery(factory, POOLS_LIMIT) })\n }\n }\n return queries\n}\n\nfunction confirmation(\n row: Record<string, unknown> | undefined\n): Pick<ContractRow, 'confirmed' | 'confirmed_by'> {\n if (!row) return { confirmed: false }\n if (row.is_contract === true) return { confirmed: true, confirmed_by: 'is_contract' }\n if (stringList(row.node_labels).includes('Contract'))\n return { confirmed: true, confirmed_by: ':Contract' }\n return { confirmed: false }\n}\n\nfunction readMatch(\n entry: DexEntry,\n members: Map<string, Member>,\n read: boolean\n): {\n contracts: Map<string, ContractRow>\n pools: PoolRow[]\n families: FamilyLag | null\n notes: string[]\n} {\n const notes: string[] = []\n const contracts = new Map<string, ContractRow>()\n const listed = new Map(rowsOf(members.get('contracts')).map((row) => [String(row.address), row]))\n for (const [address, role] of Object.entries(entry.roles)) {\n const row = members.has(`contract:${address}`)\n ? rowsOf(members.get(`contract:${address}`))[0]\n : listed.get(address)\n contracts.set(address, { address, role, ...confirmation(row) })\n }\n const byAddress = new Map<string, PoolRow>()\n for (const [id, member] of members) {\n if (!id.startsWith('pools:')) continue\n for (const row of rowsOf(member)) {\n const address = typeof row.to_address === 'string' ? row.to_address : null\n const volume = numberOrNull(row.total_volume_usd)\n if (!address || volume === null || byAddress.has(address)) continue\n byAddress.set(address, {\n address,\n labels: stringList(row.to_labels),\n total_volume_usd: volume,\n tx_total_count: numberOrNull(row.tx_total_count) ?? 0,\n })\n }\n }\n const pools = [...byAddress.values()]\n .sort((a, b) => b.total_volume_usd - a.total_volume_usd)\n .slice(0, POOLS_LIMIT)\n const head = rowsOf(members.get('head'))[0]\n const families: FamilyLag | null = head\n ? {\n behind_money: numberOrNull(column(head, 'behind_money', 'h')),\n behind_dex: numberOrNull(column(head, 'behind_dex', 'h')),\n behind_transfers: numberOrNull(column(head, 'behind_transfers', 'h')),\n }\n : null\n if (read) {\n for (const [id, member] of members) {\n if (member.ok !== true)\n notes.push(\n `${id}: ${typeof member.error === 'string' ? member.error : 'the read was not served'}`\n )\n }\n }\n return { contracts, pools, families, notes }\n}\n\nconst ADDRESS_FORM = /^0x[0-9a-fA-F]{40}$/\n\nfunction hintFor(\n result: Omit<MetaDexLookupResult, 'hint'>,\n name: string | null,\n address: string | null = null\n): string {\n if (address !== null && !result.matched) {\n return `${ANSWER_HINT} No exchange row holds ${address}: it is not a registered exchange contract. Send no exchange read for it; read the graph for what the address did.`\n }\n if (address !== null && result.matched) {\n const { matched } = result\n return (\n `${ANSWER_HINT} Say in one line: \"${address} is a ${result.took_for} row of ${matched.display}.\" Ask nothing. ` +\n `Exchange ${matched.display}, trail ${matched.trail_type}: send the first reads of recipe, ` +\n `anchored on the addresses above, and load ${matched.skill} when this host has skills. ` +\n 'Read families before a SWAPPED search: it is sent when behind_dex is at most 100000. Never ask the user for an address.'\n )\n }\n if (name === null) {\n return `${ANSWER_HINT} These are the exchanges the registry covers. Call meta_dex_lookup with a name for its addresses and first reads.`\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 return (\n `${ANSWER_HINT} ${took}Exchange ${matched.display}, trail ${matched.trail_type}: send the first reads of recipe, ` +\n `anchored on the addresses above, and load ${matched.skill} when this host has skills. ` +\n 'Read families before a SWAPPED search: it is sent when behind_dex is at most 100000. Never ask the user for an address.'\n )\n }\n if (result.candidates.length > 0) {\n const names = result.candidates\n .map((candidate) => `${candidate.display} (${candidate.dex})`)\n .join(', ')\n return `${ANSWER_HINT} ${result.candidates.length} rows fit \"${name}\": ${names}. Name both or pick one: call meta_dex_lookup with each key. Never guess one, never ask the user for an address.`\n }\n return `${ANSWER_HINT} ${name} is not covered. Send no query for the name: say so in one line and list the covered exchanges by name.`\n}\n\nfunction textResult(structured: MetaDexLookupResult): MetaDexLookupToolResult {\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\n/** meta_dex_lookup, {network, name?, address?, pools?}. Every argument is checked before the registry is read. */\nexport async function handleMetaDexLookup(\n args: unknown,\n deps: DexToolDependencies\n): Promise<MetaDexLookupToolResult> {\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 const rawPools = record.pools\n if (rawPools !== undefined && rawPools !== null && typeof rawPools !== 'boolean') {\n return errorResult('invalid_pools: pools must be true or false')\n }\n const pools = rawPools !== false\n\n let loaded: LoadedRegistry\n try {\n loaded = await deps.loadRegistry(network)\n } catch (err) {\n return errorResult(\n err instanceof DexRegistryError\n ? err.message\n : `exchange registry unavailable: ${(err as Error).message}`\n )\n }\n const { document } = loaded\n const base = {\n schema: META_DEX_LOOKUP_SCHEMA,\n network,\n registry_version: document.registry_version,\n registry_source: loaded.source,\n }\n\n if (name === null && address === null) {\n const result = {\n ...base,\n matched: null,\n candidates: [],\n covered: document.rows.map((row) => row.display),\n exchanges: document.rows.map((row) => ({\n dex: row.dex,\n display: row.display,\n trail_type: row.trail_type,\n factories: row.factories,\n routers: row.routers,\n })),\n families: null,\n }\n return textResult({ ...result, hint: hintFor(result, null) })\n }\n\n let match: DexMatchResult\n if (address !== null) {\n const holder = document.rows.find(\n (row) => address in row.roles || row.helpers?.includes(address)\n )\n match = {\n matched: holder ?? null,\n ...(holder ? { took_for: `${holder.roles[address] ?? 'helper'}, served` } : {}),\n candidates: [],\n covered: document.rows.map((row) => row.display),\n }\n } else {\n match = matchDex(name as string, document.rows)\n }\n if (!match.matched) {\n const result = {\n ...base,\n matched: null,\n candidates: match.candidates,\n covered: match.covered,\n families: null,\n }\n return textResult({ ...result, hint: hintFor(result, name, address) })\n }\n\n const entry = match.matched\n const queries = lookupQueries(entry, pools)\n let members = new Map<string, Member>()\n const notes: string[] = []\n const unavailable = await deps.unavailable?.()\n if (unavailable) {\n notes.push(\n `No graph read was sent: ${unavailable} The contracts are the reviewed registry rows, not yet confirmed on the graph.`\n )\n } else {\n try {\n const answer = await deps.graphQueryBatch({ network, queries })\n members = membersOf(answer)\n if (answer.isError === true && members.size === 0) {\n const first = Array.isArray(answer.content) ? answer.content[0] : undefined\n notes.push(\n `The graph refused the reads: ${isRecord(first) && typeof first.text === 'string' ? first.text : 'no reason given'}`\n )\n }\n } catch (err) {\n notes.push(`The graph reads failed: ${deps.describeFailure(err)}`)\n }\n }\n const read = readMatch(entry, members, members.size > 0)\n notes.push(...read.notes)\n const contractsOf = (role: Role): ContractRow[] =>\n [...read.contracts.values()].filter((contract) => contract.role === role)\n const topPool = read.pools[0]?.address ?? null\n const matched: DexMatch = {\n dex: entry.dex,\n display: entry.display,\n trail_type: entry.trail_type,\n skill: TRAIL_SKILLS[entry.trail_type],\n factories: contractsOf('factory'),\n routers: contractsOf('router'),\n manager: contractsOf('manager')[0] ?? null,\n pools: read.pools,\n recipe: recipeFor(entry, topPool),\n }\n const result = {\n ...base,\n matched,\n ...(match.took_for ? { took_for: match.took_for } : {}),\n candidates: [],\n covered: match.covered,\n families: read.families,\n ...(notes.length > 0 ? { notes } : {}),\n }\n return textResult({ ...result, hint: hintFor(result, name, address) })\n}\n"],"mappings":";;;;;AAsBA,MAAa,eAA0C;CACrD,OAAO;CACP,OAAO;CACP,OAAO;CACP,WAAW;AACb;AAEA,MAAM,SAAS;AACf,MAAM,MAAM;AACZ,MAAM,KAAK;AACX,MAAM,QAAQ;;AAGd,SAAgB,oBAAoB,SAAiB,QAAQ,IAAY;CACvE,OACE,4CAA4C,QAAQ,8QAEV;AAE9C;;AAGA,SAAS,qBAAqB,MAAsB;CAClD,OACE,uEAAuE,KAAK;AAIhF;;AAGA,SAAS,yBAAyB,UAA0B;CAC1D,OACE,sEAAsE,SAAS;AAInF;;AAGA,SAAS,mBAA2B;CAClC,OACE,4CAA4C,OAAO;AAIvD;;AAGA,SAAS,cAAc,WAA2B;CAChD,OACE,yCAAyC,OAAO,sCAAsC,UAAU,4BAA4B,I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AU,OAAO,SAAS,QAAQ,OAAO,CAAC;CACvD,MAAM,KAAK,GAAG,KAAK,KAAK;CACxB,MAAM,eAAe,SACnB,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,CAAC,CAAC,QAAQ,aAAa,SAAS,SAAS,IAAI;CAC1E,MAAM,UAAU,KAAK,MAAM,EAAE,EAAE,WAAW;CAC1C,MAAM,UAAoB;EACxB,KAAK,MAAM;EACX,SAAS,MAAM;EACf,YAAY,MAAM;EAClB,OAAO,aAAa,MAAM;EAC1B,WAAW,YAAY,SAAS;EAChC,SAAS,YAAY,QAAQ;EAC7B,SAAS,YAAY,SAAS,CAAC,CAAC,MAAM;EACtC,OAAO,KAAK;EACZ,QAAQ,UAAU,OAAO,OAAO;CAClC;CACA,MAAM,SAAS;EACb,GAAG;EACH;EACA,GAAI,MAAM,WAAW,EAAE,UAAU,MAAM,SAAS,IAAI,CAAC;EACrD,YAAY,CAAC;EACb,SAAS,MAAM;EACf,UAAU,KAAK;EACf,GAAI,MAAM,SAAS,IAAI,EAAE,MAAM,IAAI,CAAC;CACtC;CACA,OAAO,WAAW;EAAE,GAAG;EAAQ,MAAM,QAAQ,QAAQ,MAAM,OAAO;CAAE,CAAC;AACvE"}
|
package/dist/mcp-proxy.cjs
CHANGED
|
@@ -10,9 +10,9 @@ const require_capabilities = require("./capabilities-DalimVY2.cjs");
|
|
|
10
10
|
const require_graph_schema = require("./graph-schema-C8Pi6r7c.cjs");
|
|
11
11
|
const require_action_log = require("./action-log-WMW6xFMx.cjs");
|
|
12
12
|
const require_answer_hint = require("./answer-hint-BlYEBq_Y.cjs");
|
|
13
|
-
const require_dex_tool = require("./dex-tool-
|
|
14
|
-
const require_dex_registry = require("./dex-registry-
|
|
15
|
-
const require_token_lookup = require("./token-lookup-
|
|
13
|
+
const require_dex_tool = require("./dex-tool-CDmhhXfk.cjs");
|
|
14
|
+
const require_dex_registry = require("./dex-registry-DdXOg5On.cjs");
|
|
15
|
+
const require_token_lookup = require("./token-lookup-DvgEyqcC.cjs");
|
|
16
16
|
let node_url = require("node:url");
|
|
17
17
|
let node_path = require("node:path");
|
|
18
18
|
node_path = require_rolldown_runtime.__toESM(node_path, 1);
|
package/dist/mcp-proxy.mjs
CHANGED
|
@@ -8,9 +8,9 @@ import { r as mirrorGraphNetworkCapabilities } from "./capabilities-BRNHcabF.mjs
|
|
|
8
8
|
import { a as handleMetaSchema, c as GRAPH_EXPAND_TITLE, d as handleGraphExpand, l as GRAPH_EXPAND_TOOL, n as META_SCHEMA_DESCRIPTION, o as FLOWS_MAX_OFFSET, r as META_SCHEMA_TITLE, s as GRAPH_EXPAND_DESCRIPTION, t as GraphSchemaError, u as TRANSFERS_MAX } from "./graph-schema-D4LAefGf.mjs";
|
|
9
9
|
import { r as appendActionLog, t as actionLogSignalsFromResult } from "./action-log-Byv9Ln_6.mjs";
|
|
10
10
|
import { n as withAnswerHintResult } from "./answer-hint-vOE1O6Lf.mjs";
|
|
11
|
-
import { i as META_DEX_LOOKUP_TOOL, n as META_DEX_LOOKUP_DESCRIPTION, o as handleMetaDexLookup, r as META_DEX_LOOKUP_TITLE, t as META_DEX_LOOKUP_ANNOTATIONS } from "./dex-tool-
|
|
12
|
-
import { r as loadRegistry } from "./dex-registry-
|
|
13
|
-
import { a as SYMBOL_MAX, i as META_TOKEN_LOOKUP_TOOL, n as META_TOKEN_LOOKUP_DESCRIPTION, o as handleMetaTokenLookup, r as META_TOKEN_LOOKUP_TITLE, t as META_TOKEN_LOOKUP_ANNOTATIONS } from "./token-lookup-
|
|
11
|
+
import { i as META_DEX_LOOKUP_TOOL, n as META_DEX_LOOKUP_DESCRIPTION, o as handleMetaDexLookup, r as META_DEX_LOOKUP_TITLE, t as META_DEX_LOOKUP_ANNOTATIONS } from "./dex-tool-D61sIjpq.mjs";
|
|
12
|
+
import { r as loadRegistry } from "./dex-registry-sPTFuCrP.mjs";
|
|
13
|
+
import { a as SYMBOL_MAX, i as META_TOKEN_LOOKUP_TOOL, n as META_TOKEN_LOOKUP_DESCRIPTION, o as handleMetaTokenLookup, r as META_TOKEN_LOOKUP_TITLE, t as META_TOKEN_LOOKUP_ANNOTATIONS } from "./token-lookup-sH2DesLS.mjs";
|
|
14
14
|
import { fileURLToPath } from "node:url";
|
|
15
15
|
import path from "node:path";
|
|
16
16
|
import { readFileSync } from "node:fs";
|
|
@@ -1,6 +1,6 @@
|
|
|
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-
|
|
3
|
+
const require_dex_registry = require("./dex-registry-DdXOg5On.cjs");
|
|
4
4
|
const require_print_result = require("./print-result-BYppJlUi.cjs");
|
|
5
5
|
// src/mcp/token-lookup.ts
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
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 { a as normalizeDexNetwork, t as DexRegistryError } from "./dex-registry-
|
|
3
|
+
import { a as normalizeDexNetwork, t as DexRegistryError } from "./dex-registry-sPTFuCrP.mjs";
|
|
4
4
|
import { i as isEpochMs, o as utcText } from "./print-result-IFARsMnL.mjs";
|
|
5
5
|
// src/mcp/token-lookup.ts
|
|
6
6
|
/**
|
|
@@ -300,4 +300,4 @@ async function handleMetaTokenLookup(args, deps) {
|
|
|
300
300
|
}
|
|
301
301
|
export { SYMBOL_MAX as a, META_TOKEN_LOOKUP_TOOL as i, META_TOKEN_LOOKUP_DESCRIPTION as n, handleMetaTokenLookup as o, META_TOKEN_LOOKUP_TITLE as r, token_lookup_exports as s, META_TOKEN_LOOKUP_ANNOTATIONS as t };
|
|
302
302
|
|
|
303
|
-
//# sourceMappingURL=token-lookup-
|
|
303
|
+
//# sourceMappingURL=token-lookup-sH2DesLS.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"token-lookup-XnyisLQW.mjs","names":[],"sources":["../src/mcp/token-lookup.ts"],"sourcesContent":["/**\n * meta_token_lookup: a ticker or a token name becomes its contracts.\n *\n * A local tool of the proxy. It sends one anchored facts read of the Asset\n * lookup by symbol, the same read by name when the symbol answers nothing, and\n * then the creator and the factory of each candidate from topology, one batch\n * member per candidate. Nothing is matched here: the graph server matches the\n * symbol or the name, case-insensitively and exactly, and orders the rows\n * verified first, then oldest first. The proxy keeps that order.\n *\n * Tickers collide on purpose: clones reuse a symbol to borrow its trust. The\n * tool never picks one. The description below is the contract with every\n * host, Claude Desktop chat included, which reads no skill.\n */\n\nimport { ANSWER_HINT } from './answer-hint.js'\nimport { DexRegistryError, normalizeDexNetwork } from './dex-registry.js'\nimport { isEpochMs, utcText } from './timestamp-text.js'\n\nexport const META_TOKEN_LOOKUP_TOOL = 'meta_token_lookup'\nexport const META_TOKEN_LOOKUP_SCHEMA = 'chain-insights.meta-token-lookup.v1' as const\nexport const META_TOKEN_LOOKUP_TITLE = 'Token by ticker or name'\nexport const META_TOKEN_LOOKUP_DESCRIPTION =\n 'Call this first when a question names a token by its ticker or name and gives no contract ' +\n '(TCITY, USDG, SPCX). It returns every contract on the network that carries that symbol, ' +\n 'verified first, then oldest first. Tickers collide: never treat the first row as the token. ' +\n 'When several match, name them and ask, or pick by the evidence the user gave. Zero candidates ' +\n 'means no contract carries the symbol: say so, and do not search the web.'\nexport const META_TOKEN_LOOKUP_ANNOTATIONS = {\n readOnlyHint: true,\n idempotentHint: true,\n openWorldHint: false,\n} as const\nexport const META_TOKEN_LOOKUP_ARGS = ['network', 'symbol'] as const\n\n/** The candidates returned. The read asks for one more, so a full page says there are more. */\nexport const CANDIDATES_MAX = 25\nexport const ROWS_READ = CANDIDATES_MAX + 1\n/** The graph server admits at most 20 members in one graph_query_batch. */\nexport const CREATOR_BATCH_MAX = 20\nexport const SYMBOL_MAX = 64\n\nexport const ADDRESS_INPUT_HINT = 'an address is already an anchor: read it on USE topology'\n\nexport interface TokenCandidate {\n contract: string\n symbol: string | null\n name: string | null\n token_standard: string | null\n decimals: number | null\n verified: boolean\n verification_source: string | null\n first_seen_timestamp: number | null\n first_seen_timestamp_utc: string | null\n creator: string | null\n factory: string | null\n}\n\nexport interface MetaTokenLookupResult {\n schema: typeof META_TOKEN_LOOKUP_SCHEMA\n network: string\n query: string\n matched_on: 'symbol' | 'name' | null\n candidates: TokenCandidate[]\n /** The rows the server sent, at most 26: 26 means there are more than the 25 returned. */\n total: number\n truncated: boolean\n hint: string\n}\n\n/** One graph_query or graph_query_batch reply as the remote client returns it. */\nexport type GraphAnswer = {\n content?: unknown[]\n structuredContent?: unknown\n isError?: boolean\n}\n\nexport interface TokenToolDependencies {\n /** One graph_query through the proxy's remote client, billed as any read. */\n graphQuery: (args: { network: string; query: string }) => Promise<GraphAnswer>\n /** One graph_query_batch through the proxy's remote client, billed as any read. */\n graphQueryBatch: (args: {\n network: string\n queries: Array<{ id: string; query: string }>\n }) => Promise<GraphAnswer>\n /** The reason no read can be sent now, or undefined when the graph is reachable. */\n unavailable?: () => Promise<string | undefined> | string | undefined\n /** The text of a call that threw: payment required, transport. */\n describeFailure: (err: unknown) => string\n}\n\nexport type MetaTokenLookupToolResult = {\n content: Array<{ type: 'text'; text: string }>\n structuredContent?: Record<string, unknown>\n isError: boolean\n}\n\nconst ADDRESS_FORM = /^0x[0-9a-fA-F]{40}$/\nconst CONTRACT_FORM = /^0x[0-9a-f]{40}$/\n// A string literal of the read holds no double quote, no backslash and no\n// control character: the symbol is refused rather than escaped, so the read the\n// server receives is always the read written here.\nfunction unsafeLiteral(text: string): boolean {\n for (const char of text) {\n const code = char.codePointAt(0)!\n if (char === '\"' || char === '\\\\' || code < 0x20 || code === 0x7f) return true\n }\n return false\n}\nconst CODE_PREFIX = /^([a-z][a-z0-9_]*):\\s*/\n// Codes of a read that was stopped, not refused: the same read may answer later.\nconst TRANSIENT_CODE =\n /(timeout|memory_limit|cpu_limit|busy|_failed$|rate_limited|unavailable|too_large|node_error)/\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): MetaTokenLookupToolResult {\n return { content: [{ type: 'text', text }], isError: true }\n}\n\nfunction textResult(structured: MetaTokenLookupResult): MetaTokenLookupToolResult {\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\n/** The facts Asset read by symbol or by name, in the one shape the graph server admits. */\nexport function assetQuery(key: 'symbol' | 'name', value: string): string {\n return (\n `USE facts MATCH (t:Asset {${key}: \"${value}\"}) ` +\n 'RETURN t.asset_contract AS contract, t.asset_symbol AS symbol, t.name AS name, ' +\n 't.token_standard AS token_standard, t.decimals AS decimals, t.verified AS verified, ' +\n 't.verification_source AS verification_source, t.first_seen_timestamp AS first_seen_timestamp ' +\n `LIMIT ${ROWS_READ}`\n )\n}\n\n/** The topology read of who deployed one contract: the deploying address and the transaction's sender. */\nexport function creatorQuery(contract: string): string {\n return (\n `USE topology MATCH (f:Address)-[d:DEPLOYED_CONTRACT]->(t:Address {address: \"${contract}\"}) ` +\n 'RETURN f.address AS factory, d.tx_origin AS creator LIMIT 1'\n )\n}\n\nconst textOrNull = (value: unknown): string | null =>\n typeof value === 'string' && value.trim() !== '' ? value : null\n\nconst numberOrNull = (value: unknown): number | null => {\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (typeof value === 'string' && value.trim() !== '' && Number.isFinite(Number(value)))\n return Number(value)\n return null\n}\n\nconst addressOrNull = (value: unknown): string | null =>\n typeof value === 'string' && ADDRESS_FORM.test(value.trim()) ? value.trim().toLowerCase() : null\n\nfunction verifiedOf(value: unknown): boolean {\n if (typeof value === 'boolean') return value\n if (typeof value === 'number') return value === 1\n if (typeof value === 'string') return ['true', '1'].includes(value.trim().toLowerCase())\n return false\n}\n\nfunction answerText(answer: GraphAnswer): string {\n return (Array.isArray(answer.content) ? answer.content : [])\n .map((block) => (isRecord(block) && typeof block.text === 'string' ? block.text : ''))\n .filter(Boolean)\n .join('\\n')\n .trim()\n}\n\ntype Refusal = { code: string; text: string; transient: boolean }\n\n/** A graph_query answer that did not answer: its code, its text, and whether the same read may answer later. */\nfunction refusalOf(answer: GraphAnswer): Refusal {\n const text = answerText(answer)\n const detail = isRecord(answer.structuredContent)\n ? answer.structuredContent.error_detail\n : undefined\n const detailCode = isRecord(detail) && typeof detail.code === 'string' ? detail.code : ''\n const detailClass = isRecord(detail) && typeof detail.class === 'string' ? detail.class : ''\n const named = detailCode || CODE_PREFIX.exec(text)?.[1] || ''\n // A refusal that names no class is a stop only when its code says so; a\n // refusal in plain words (\"unknown label Asset\") is a server that lacks the read.\n const transient = detailClass ? detailClass !== 'refused' : TRANSIENT_CODE.test(named)\n const code = named || 'not_served'\n return { code, text: text || `${code}: the graph endpoint refused the read`, transient }\n}\n\n/** The result rows of a graph_query answer, or null when it holds none. */\nfunction rowsOf(answer: GraphAnswer): Array<Record<string, unknown>> | null {\n const facts = isRecord(answer.structuredContent) ? answer.structuredContent.facts : undefined\n const query = isRecord(facts) ? facts.query : undefined\n const results = isRecord(query) ? query.results : undefined\n return Array.isArray(results) ? results.filter(isRecord) : null\n}\n\ntype Member = { id?: unknown; ok?: unknown; results?: unknown; error?: unknown }\n\nfunction membersOf(answer: GraphAnswer): Map<string, Member> {\n const facts = isRecord(answer.structuredContent) ? answer.structuredContent.facts : undefined\n const queries = isRecord(facts) ? facts.queries : undefined\n const members = new Map<string, Member>()\n if (Array.isArray(queries)) {\n for (const member of queries)\n if (isRecord(member) && typeof member.id === 'string') members.set(member.id, member)\n }\n return members\n}\n\nfunction candidateOf(row: Record<string, unknown>): TokenCandidate | null {\n const contract = textOrNull(row.contract)?.trim().toLowerCase()\n if (!contract) return null\n const firstSeen = numberOrNull(row.first_seen_timestamp)\n return {\n contract,\n symbol: textOrNull(row.symbol),\n name: textOrNull(row.name),\n token_standard: textOrNull(row.token_standard),\n decimals: numberOrNull(row.decimals),\n verified: verifiedOf(row.verified),\n verification_source: textOrNull(row.verification_source),\n first_seen_timestamp: firstSeen,\n first_seen_timestamp_utc: isEpochMs(firstSeen) ? utcText(firstSeen) : null,\n creator: null,\n factory: null,\n }\n}\n\ntype Read =\n | { kind: 'rows'; rows: Array<Record<string, unknown>> }\n | { kind: 'not_served'; refusal: Refusal }\n | { kind: 'failed'; text: string }\n\nasync function readAssets(\n deps: TokenToolDependencies,\n network: string,\n key: 'symbol' | 'name',\n value: string\n): Promise<Read> {\n let answer: GraphAnswer\n try {\n answer = await deps.graphQuery({ network, query: assetQuery(key, value) })\n } catch (err) {\n return { kind: 'failed', text: deps.describeFailure(err) }\n }\n const rows = rowsOf(answer)\n if (answer.isError !== true && rows !== null) return { kind: 'rows', rows }\n const refusal = refusalOf(answer)\n if (answer.isError === true && refusal.transient) return { kind: 'failed', text: refusal.text }\n return { kind: 'not_served', refusal }\n}\n\n/**\n * The creator and the factory of each candidate, written in place. Returns why\n * some creators were not read, or null when every read answered. A read that\n * answered with no row leaves the candidate's creator empty with no note: the\n * graph holds no deployment for it.\n */\nasync function readCreators(\n deps: TokenToolDependencies,\n network: string,\n candidates: TokenCandidate[]\n): Promise<string | null> {\n const contracts = [\n ...new Set(candidates.map((c) => c.contract).filter((c) => CONTRACT_FORM.test(c))),\n ]\n const found = new Map<string, { creator: string | null; factory: string | null }>()\n const reasons: string[] = []\n let unread = candidates.length - candidates.filter((c) => CONTRACT_FORM.test(c.contract)).length\n for (let at = 0; at < contracts.length; at += CREATOR_BATCH_MAX) {\n const chunk = contracts.slice(at, at + CREATOR_BATCH_MAX)\n const queries = chunk.map((contract) => ({\n id: `creator:${contract}`,\n query: creatorQuery(contract),\n }))\n let members = new Map<string, Member>()\n try {\n const answer = await deps.graphQueryBatch({ network, queries })\n members = membersOf(answer)\n if (members.size === 0) {\n reasons.push(\n answer.isError === true ? refusalOf(answer).text : 'the batch answer held no reads'\n )\n }\n } catch (err) {\n reasons.push(deps.describeFailure(err))\n }\n for (const contract of chunk) {\n const member = members.get(`creator:${contract}`)\n if (member?.ok === true && Array.isArray(member.results)) {\n const row = member.results.find(isRecord)\n found.set(contract, {\n creator: row ? addressOrNull(row.creator) : null,\n factory: row ? addressOrNull(row.factory) : null,\n })\n continue\n }\n unread += 1\n if (member && typeof member.error === 'string' && !reasons.includes(member.error))\n reasons.push(member.error)\n }\n }\n for (const candidate of candidates) {\n const read = found.get(candidate.contract)\n if (read) Object.assign(candidate, read)\n }\n if (unread === 0) return null\n return `${unread} of ${candidates.length}${reasons.length > 0 ? `: ${reasons.join('; ')}` : ''}`\n}\n\nconst NO_WEB =\n 'Do not search the web and do not guess a contract: a web page is not a contract on this network.'\n\nfunction hintFor(\n result: Omit<MetaTokenLookupResult, 'hint'>,\n creatorsNotRead: string | null\n): string {\n const { network, query, candidates, matched_on, truncated } = result\n const parts: string[] = [ANSWER_HINT]\n if (candidates.length === 0) {\n parts.push(\n `No contract on ${network} carries the symbol or the name \"${query}\". Say so in one line. ${NO_WEB} ` +\n 'Ask the user for the contract if they have one.'\n )\n return parts.join(' ')\n }\n if (matched_on === 'name') {\n parts.push(`No contract carries \"${query}\" as its symbol; these carry it as their name.`)\n }\n if (candidates.length === 1) {\n parts.push(\n `One contract on ${network} carries \"${query}\": ${candidates[0]!.contract}. ` +\n 'Say it is the only one on this network, then read it by this full contract on USE topology.'\n )\n } else {\n parts.push(\n `${candidates.length} contracts on ${network} carry \"${query}\"` +\n `${truncated ? `, and more exist than the ${CANDIDATES_MAX} listed` : ''}. ` +\n 'Tickers collide: never treat the first row as the token. Name them, each contract in full, ' +\n 'with its creator and first seen time, and ask which one the user means, or pick one by the evidence the user gave ' +\n '(a creator, a launch date, a price move) and say why.'\n )\n }\n if (creatorsNotRead) {\n parts.push(\n `The creators were not read for ${creatorsNotRead}. creator and factory are empty there because the read failed, ` +\n 'not because the chain holds none.'\n )\n }\n parts.push('Write every contract and creator in full, 0x plus 40 hex characters.')\n return parts.join(' ')\n}\n\n/** meta_token_lookup, {network, symbol}. Every argument is checked before a read is sent. */\nexport async function handleMetaTokenLookup(\n args: unknown,\n deps: TokenToolDependencies\n): Promise<MetaTokenLookupToolResult> {\n const record = isRecord(args) ? args : {}\n let network: string\n try {\n network = normalizeDexNetwork(record.network)\n } catch (err) {\n return errorResult(\n err instanceof DexRegistryError ? err.message : `invalid_network: ${(err as Error).message}`\n )\n }\n if (typeof record.symbol !== 'string' || record.symbol.trim() === '') {\n return errorResult(\n 'invalid_symbol: symbol is required: the ticker or the name as the user wrote it, for example TCITY'\n )\n }\n const symbol = record.symbol.trim()\n if (symbol.length > SYMBOL_MAX) {\n return errorResult(`invalid_symbol: symbol holds at most ${SYMBOL_MAX} characters`)\n }\n const base = {\n schema: META_TOKEN_LOOKUP_SCHEMA,\n network,\n query: symbol,\n }\n\n if (ADDRESS_FORM.test(symbol)) {\n const address = symbol.toLowerCase()\n return textResult({\n ...base,\n matched_on: null,\n candidates: [],\n total: 0,\n truncated: false,\n hint: `${ANSWER_HINT} ${address} is a contract address, not a ticker: ${ADDRESS_INPUT_HINT}. Send no token lookup for it.`,\n })\n }\n if (unsafeLiteral(symbol)) {\n return errorResult(\n 'invalid_symbol: a symbol holds no double quote, backslash or control character. Send the ticker or the name as plain text.'\n )\n }\n\n const unavailable = await deps.unavailable?.()\n if (unavailable) {\n return errorResult(\n `No token read was sent: ${unavailable} The lookup has no answer yet, which is not \"no contract\": try again later, or ask the user for the contract. ${NO_WEB}`\n )\n }\n\n let matchedOn: 'symbol' | 'name' = 'symbol'\n let read = await readAssets(deps, network, 'symbol', symbol)\n if (read.kind === 'rows' && read.rows.length === 0) {\n matchedOn = 'name'\n read = await readAssets(deps, network, 'name', symbol)\n }\n if (read.kind === 'failed') {\n return errorResult(\n `The token read failed: ${read.text} This is not \"no contract\": send the same lookup again once, or ask the user for the contract. ${NO_WEB}`\n )\n }\n if (read.kind === 'not_served') {\n return textResult({\n ...base,\n matched_on: null,\n candidates: [],\n total: 0,\n truncated: false,\n hint:\n `${ANSWER_HINT} This Chain Insights server does not serve the token lookup yet (${read.refusal.code}). ` +\n `That is not \"no contract carries ${symbol}\": ask the user for the token's contract, 0x plus 40 hex characters. ${NO_WEB}`,\n })\n }\n\n const total = read.rows.length\n const candidates = read.rows\n .slice(0, CANDIDATES_MAX)\n .map(candidateOf)\n .filter((candidate): candidate is TokenCandidate => candidate !== null)\n const creatorsNotRead =\n candidates.length > 0 ? await readCreators(deps, network, candidates) : null\n const result = {\n ...base,\n matched_on: candidates.length > 0 ? matchedOn : null,\n candidates,\n total,\n truncated: total > CANDIDATES_MAX,\n }\n return textResult({ ...result, hint: hintFor(result, creatorsNotRead) })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,yBAAyB;AACtC,MAAa,2BAA2B;AACxC,MAAa,0BAA0B;AACvC,MAAa,gCACX;AAKF,MAAa,gCAAgC;CAC3C,cAAc;CACd,gBAAgB;CAChB,eAAe;AACjB;;AAIA,MAAa,iBAAiB;AAC9B,MAAa,YAAY;;AAEzB,MAAa,oBAAoB;AACjC,MAAa,aAAa;AAE1B,MAAa,qBAAqB;AAuDlC,MAAM,eAAe;AACrB,MAAM,gBAAgB;AAItB,SAAS,cAAc,MAAuB;CAC5C,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK,YAAY,CAAC;EAC/B,IAAI,SAAS,QAAO,SAAS,QAAQ,OAAO,MAAQ,SAAS,KAAM,OAAO;CAC5E;CACA,OAAO;AACT;AACA,MAAM,cAAc;AAEpB,MAAM,iBACJ;AAEF,SAAS,SAAS,OAAkD;CAClE,OAAO,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AACrE;AAEA,SAAS,YAAY,MAAyC;CAC5D,OAAO;EAAE,SAAS,CAAC;GAAE,MAAM;GAAQ;EAAK,CAAC;EAAG,SAAS;CAAK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,MAAM,GACtB,OAAO,YACL,4HACF;CAGF,MAAM,cAAc,MAAM,KAAK,cAAc;CAC7C,IAAI,aACF,OAAO,YACL,2BAA2B,YAAY,gHAAgH,QACzJ;CAGF,IAAI,YAA+B;CACnC,IAAI,OAAO,MAAM,WAAW,MAAM,SAAS,UAAU,MAAM;CAC3D,IAAI,KAAK,SAAS,UAAU,KAAK,KAAK,WAAW,GAAG;EAClD,YAAY;EACZ,OAAO,MAAM,WAAW,MAAM,SAAS,QAAQ,MAAM;CACvD;CACA,IAAI,KAAK,SAAS,UAChB,OAAO,YACL,0BAA0B,KAAK,KAAK,iGAAiG,QACvI;CAEF,IAAI,KAAK,SAAS,cAChB,OAAO,WAAW;EAChB,GAAG;EACH,YAAY;EACZ,YAAY,CAAC;EACb,OAAO;EACP,WAAW;EACX,MACE,GAAG,YAAY,mEAAmE,KAAK,QAAQ,KAAK,sCAChE,OAAO,uEAAuE;CACtH,CAAC;CAGH,MAAM,QAAQ,KAAK,KAAK;CACxB,MAAM,aAAa,KAAK,KACrB,MAAM,GAAG,cAAc,CAAC,CACxB,IAAI,WAAW,CAAC,CAChB,QAAQ,cAA2C,cAAc,IAAI;CACxE,MAAM,kBACJ,WAAW,SAAS,IAAI,MAAM,aAAa,MAAM,SAAS,UAAU,IAAI;CAC1E,MAAM,SAAS;EACb,GAAG;EACH,YAAY,WAAW,SAAS,IAAI,YAAY;EAChD;EACA;EACA,WAAW,QAAQ;CACrB;CACA,OAAO,WAAW;EAAE,GAAG;EAAQ,MAAM,QAAQ,QAAQ,eAAe;CAAE,CAAC;AACzE"}
|
|
1
|
+
{"version":3,"file":"token-lookup-sH2DesLS.mjs","names":[],"sources":["../src/mcp/token-lookup.ts"],"sourcesContent":["/**\n * meta_token_lookup: a ticker or a token name becomes its contracts.\n *\n * A local tool of the proxy. It sends one anchored facts read of the Asset\n * lookup by symbol, the same read by name when the symbol answers nothing, and\n * then the creator and the factory of each candidate from topology, one batch\n * member per candidate. Nothing is matched here: the graph server matches the\n * symbol or the name, case-insensitively and exactly, and orders the rows\n * verified first, then oldest first. The proxy keeps that order.\n *\n * Tickers collide on purpose: clones reuse a symbol to borrow its trust. The\n * tool never picks one. The description below is the contract with every\n * host, Claude Desktop chat included, which reads no skill.\n */\n\nimport { ANSWER_HINT } from './answer-hint.js'\nimport { DexRegistryError, normalizeDexNetwork } from './dex-registry.js'\nimport { isEpochMs, utcText } from './timestamp-text.js'\n\nexport const META_TOKEN_LOOKUP_TOOL = 'meta_token_lookup'\nexport const META_TOKEN_LOOKUP_SCHEMA = 'chain-insights.meta-token-lookup.v1' as const\nexport const META_TOKEN_LOOKUP_TITLE = 'Token by ticker or name'\nexport const META_TOKEN_LOOKUP_DESCRIPTION =\n 'Call this first when a question names a token by its ticker or name and gives no contract ' +\n '(TCITY, USDG, SPCX). It returns every contract on the network that carries that symbol, ' +\n 'verified first, then oldest first. Tickers collide: never treat the first row as the token. ' +\n 'When several match, name them and ask, or pick by the evidence the user gave. Zero candidates ' +\n 'means no contract carries the symbol: say so, and do not search the web.'\nexport const META_TOKEN_LOOKUP_ANNOTATIONS = {\n readOnlyHint: true,\n idempotentHint: true,\n openWorldHint: false,\n} as const\nexport const META_TOKEN_LOOKUP_ARGS = ['network', 'symbol'] as const\n\n/** The candidates returned. The read asks for one more, so a full page says there are more. */\nexport const CANDIDATES_MAX = 25\nexport const ROWS_READ = CANDIDATES_MAX + 1\n/** The graph server admits at most 20 members in one graph_query_batch. */\nexport const CREATOR_BATCH_MAX = 20\nexport const SYMBOL_MAX = 64\n\nexport const ADDRESS_INPUT_HINT = 'an address is already an anchor: read it on USE topology'\n\nexport interface TokenCandidate {\n contract: string\n symbol: string | null\n name: string | null\n token_standard: string | null\n decimals: number | null\n verified: boolean\n verification_source: string | null\n first_seen_timestamp: number | null\n first_seen_timestamp_utc: string | null\n creator: string | null\n factory: string | null\n}\n\nexport interface MetaTokenLookupResult {\n schema: typeof META_TOKEN_LOOKUP_SCHEMA\n network: string\n query: string\n matched_on: 'symbol' | 'name' | null\n candidates: TokenCandidate[]\n /** The rows the server sent, at most 26: 26 means there are more than the 25 returned. */\n total: number\n truncated: boolean\n hint: string\n}\n\n/** One graph_query or graph_query_batch reply as the remote client returns it. */\nexport type GraphAnswer = {\n content?: unknown[]\n structuredContent?: unknown\n isError?: boolean\n}\n\nexport interface TokenToolDependencies {\n /** One graph_query through the proxy's remote client, billed as any read. */\n graphQuery: (args: { network: string; query: string }) => Promise<GraphAnswer>\n /** One graph_query_batch through the proxy's remote client, billed as any read. */\n graphQueryBatch: (args: {\n network: string\n queries: Array<{ id: string; query: string }>\n }) => Promise<GraphAnswer>\n /** The reason no read can be sent now, or undefined when the graph is reachable. */\n unavailable?: () => Promise<string | undefined> | string | undefined\n /** The text of a call that threw: payment required, transport. */\n describeFailure: (err: unknown) => string\n}\n\nexport type MetaTokenLookupToolResult = {\n content: Array<{ type: 'text'; text: string }>\n structuredContent?: Record<string, unknown>\n isError: boolean\n}\n\nconst ADDRESS_FORM = /^0x[0-9a-fA-F]{40}$/\nconst CONTRACT_FORM = /^0x[0-9a-f]{40}$/\n// A string literal of the read holds no double quote, no backslash and no\n// control character: the symbol is refused rather than escaped, so the read the\n// server receives is always the read written here.\nfunction unsafeLiteral(text: string): boolean {\n for (const char of text) {\n const code = char.codePointAt(0)!\n if (char === '\"' || char === '\\\\' || code < 0x20 || code === 0x7f) return true\n }\n return false\n}\nconst CODE_PREFIX = /^([a-z][a-z0-9_]*):\\s*/\n// Codes of a read that was stopped, not refused: the same read may answer later.\nconst TRANSIENT_CODE =\n /(timeout|memory_limit|cpu_limit|busy|_failed$|rate_limited|unavailable|too_large|node_error)/\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): MetaTokenLookupToolResult {\n return { content: [{ type: 'text', text }], isError: true }\n}\n\nfunction textResult(structured: MetaTokenLookupResult): MetaTokenLookupToolResult {\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\n/** The facts Asset read by symbol or by name, in the one shape the graph server admits. */\nexport function assetQuery(key: 'symbol' | 'name', value: string): string {\n return (\n `USE facts MATCH (t:Asset {${key}: \"${value}\"}) ` +\n 'RETURN t.asset_contract AS contract, t.asset_symbol AS symbol, t.name AS name, ' +\n 't.token_standard AS token_standard, t.decimals AS decimals, t.verified AS verified, ' +\n 't.verification_source AS verification_source, t.first_seen_timestamp AS first_seen_timestamp ' +\n `LIMIT ${ROWS_READ}`\n )\n}\n\n/** The topology read of who deployed one contract: the deploying address and the transaction's sender. */\nexport function creatorQuery(contract: string): string {\n return (\n `USE topology MATCH (f:Address)-[d:DEPLOYED_CONTRACT]->(t:Address {address: \"${contract}\"}) ` +\n 'RETURN f.address AS factory, d.tx_origin AS creator LIMIT 1'\n )\n}\n\nconst textOrNull = (value: unknown): string | null =>\n typeof value === 'string' && value.trim() !== '' ? value : null\n\nconst numberOrNull = (value: unknown): number | null => {\n if (typeof value === 'number' && Number.isFinite(value)) return value\n if (typeof value === 'string' && value.trim() !== '' && Number.isFinite(Number(value)))\n return Number(value)\n return null\n}\n\nconst addressOrNull = (value: unknown): string | null =>\n typeof value === 'string' && ADDRESS_FORM.test(value.trim()) ? value.trim().toLowerCase() : null\n\nfunction verifiedOf(value: unknown): boolean {\n if (typeof value === 'boolean') return value\n if (typeof value === 'number') return value === 1\n if (typeof value === 'string') return ['true', '1'].includes(value.trim().toLowerCase())\n return false\n}\n\nfunction answerText(answer: GraphAnswer): string {\n return (Array.isArray(answer.content) ? answer.content : [])\n .map((block) => (isRecord(block) && typeof block.text === 'string' ? block.text : ''))\n .filter(Boolean)\n .join('\\n')\n .trim()\n}\n\ntype Refusal = { code: string; text: string; transient: boolean }\n\n/** A graph_query answer that did not answer: its code, its text, and whether the same read may answer later. */\nfunction refusalOf(answer: GraphAnswer): Refusal {\n const text = answerText(answer)\n const detail = isRecord(answer.structuredContent)\n ? answer.structuredContent.error_detail\n : undefined\n const detailCode = isRecord(detail) && typeof detail.code === 'string' ? detail.code : ''\n const detailClass = isRecord(detail) && typeof detail.class === 'string' ? detail.class : ''\n const named = detailCode || CODE_PREFIX.exec(text)?.[1] || ''\n // A refusal that names no class is a stop only when its code says so; a\n // refusal in plain words (\"unknown label Asset\") is a server that lacks the read.\n const transient = detailClass ? detailClass !== 'refused' : TRANSIENT_CODE.test(named)\n const code = named || 'not_served'\n return { code, text: text || `${code}: the graph endpoint refused the read`, transient }\n}\n\n/** The result rows of a graph_query answer, or null when it holds none. */\nfunction rowsOf(answer: GraphAnswer): Array<Record<string, unknown>> | null {\n const facts = isRecord(answer.structuredContent) ? answer.structuredContent.facts : undefined\n const query = isRecord(facts) ? facts.query : undefined\n const results = isRecord(query) ? query.results : undefined\n return Array.isArray(results) ? results.filter(isRecord) : null\n}\n\ntype Member = { id?: unknown; ok?: unknown; results?: unknown; error?: unknown }\n\nfunction membersOf(answer: GraphAnswer): Map<string, Member> {\n const facts = isRecord(answer.structuredContent) ? answer.structuredContent.facts : undefined\n const queries = isRecord(facts) ? facts.queries : undefined\n const members = new Map<string, Member>()\n if (Array.isArray(queries)) {\n for (const member of queries)\n if (isRecord(member) && typeof member.id === 'string') members.set(member.id, member)\n }\n return members\n}\n\nfunction candidateOf(row: Record<string, unknown>): TokenCandidate | null {\n const contract = textOrNull(row.contract)?.trim().toLowerCase()\n if (!contract) return null\n const firstSeen = numberOrNull(row.first_seen_timestamp)\n return {\n contract,\n symbol: textOrNull(row.symbol),\n name: textOrNull(row.name),\n token_standard: textOrNull(row.token_standard),\n decimals: numberOrNull(row.decimals),\n verified: verifiedOf(row.verified),\n verification_source: textOrNull(row.verification_source),\n first_seen_timestamp: firstSeen,\n first_seen_timestamp_utc: isEpochMs(firstSeen) ? utcText(firstSeen) : null,\n creator: null,\n factory: null,\n }\n}\n\ntype Read =\n | { kind: 'rows'; rows: Array<Record<string, unknown>> }\n | { kind: 'not_served'; refusal: Refusal }\n | { kind: 'failed'; text: string }\n\nasync function readAssets(\n deps: TokenToolDependencies,\n network: string,\n key: 'symbol' | 'name',\n value: string\n): Promise<Read> {\n let answer: GraphAnswer\n try {\n answer = await deps.graphQuery({ network, query: assetQuery(key, value) })\n } catch (err) {\n return { kind: 'failed', text: deps.describeFailure(err) }\n }\n const rows = rowsOf(answer)\n if (answer.isError !== true && rows !== null) return { kind: 'rows', rows }\n const refusal = refusalOf(answer)\n if (answer.isError === true && refusal.transient) return { kind: 'failed', text: refusal.text }\n return { kind: 'not_served', refusal }\n}\n\n/**\n * The creator and the factory of each candidate, written in place. Returns why\n * some creators were not read, or null when every read answered. A read that\n * answered with no row leaves the candidate's creator empty with no note: the\n * graph holds no deployment for it.\n */\nasync function readCreators(\n deps: TokenToolDependencies,\n network: string,\n candidates: TokenCandidate[]\n): Promise<string | null> {\n const contracts = [\n ...new Set(candidates.map((c) => c.contract).filter((c) => CONTRACT_FORM.test(c))),\n ]\n const found = new Map<string, { creator: string | null; factory: string | null }>()\n const reasons: string[] = []\n let unread = candidates.length - candidates.filter((c) => CONTRACT_FORM.test(c.contract)).length\n for (let at = 0; at < contracts.length; at += CREATOR_BATCH_MAX) {\n const chunk = contracts.slice(at, at + CREATOR_BATCH_MAX)\n const queries = chunk.map((contract) => ({\n id: `creator:${contract}`,\n query: creatorQuery(contract),\n }))\n let members = new Map<string, Member>()\n try {\n const answer = await deps.graphQueryBatch({ network, queries })\n members = membersOf(answer)\n if (members.size === 0) {\n reasons.push(\n answer.isError === true ? refusalOf(answer).text : 'the batch answer held no reads'\n )\n }\n } catch (err) {\n reasons.push(deps.describeFailure(err))\n }\n for (const contract of chunk) {\n const member = members.get(`creator:${contract}`)\n if (member?.ok === true && Array.isArray(member.results)) {\n const row = member.results.find(isRecord)\n found.set(contract, {\n creator: row ? addressOrNull(row.creator) : null,\n factory: row ? addressOrNull(row.factory) : null,\n })\n continue\n }\n unread += 1\n if (member && typeof member.error === 'string' && !reasons.includes(member.error))\n reasons.push(member.error)\n }\n }\n for (const candidate of candidates) {\n const read = found.get(candidate.contract)\n if (read) Object.assign(candidate, read)\n }\n if (unread === 0) return null\n return `${unread} of ${candidates.length}${reasons.length > 0 ? `: ${reasons.join('; ')}` : ''}`\n}\n\nconst NO_WEB =\n 'Do not search the web and do not guess a contract: a web page is not a contract on this network.'\n\nfunction hintFor(\n result: Omit<MetaTokenLookupResult, 'hint'>,\n creatorsNotRead: string | null\n): string {\n const { network, query, candidates, matched_on, truncated } = result\n const parts: string[] = [ANSWER_HINT]\n if (candidates.length === 0) {\n parts.push(\n `No contract on ${network} carries the symbol or the name \"${query}\". Say so in one line. ${NO_WEB} ` +\n 'Ask the user for the contract if they have one.'\n )\n return parts.join(' ')\n }\n if (matched_on === 'name') {\n parts.push(`No contract carries \"${query}\" as its symbol; these carry it as their name.`)\n }\n if (candidates.length === 1) {\n parts.push(\n `One contract on ${network} carries \"${query}\": ${candidates[0]!.contract}. ` +\n 'Say it is the only one on this network, then read it by this full contract on USE topology.'\n )\n } else {\n parts.push(\n `${candidates.length} contracts on ${network} carry \"${query}\"` +\n `${truncated ? `, and more exist than the ${CANDIDATES_MAX} listed` : ''}. ` +\n 'Tickers collide: never treat the first row as the token. Name them, each contract in full, ' +\n 'with its creator and first seen time, and ask which one the user means, or pick one by the evidence the user gave ' +\n '(a creator, a launch date, a price move) and say why.'\n )\n }\n if (creatorsNotRead) {\n parts.push(\n `The creators were not read for ${creatorsNotRead}. creator and factory are empty there because the read failed, ` +\n 'not because the chain holds none.'\n )\n }\n parts.push('Write every contract and creator in full, 0x plus 40 hex characters.')\n return parts.join(' ')\n}\n\n/** meta_token_lookup, {network, symbol}. Every argument is checked before a read is sent. */\nexport async function handleMetaTokenLookup(\n args: unknown,\n deps: TokenToolDependencies\n): Promise<MetaTokenLookupToolResult> {\n const record = isRecord(args) ? args : {}\n let network: string\n try {\n network = normalizeDexNetwork(record.network)\n } catch (err) {\n return errorResult(\n err instanceof DexRegistryError ? err.message : `invalid_network: ${(err as Error).message}`\n )\n }\n if (typeof record.symbol !== 'string' || record.symbol.trim() === '') {\n return errorResult(\n 'invalid_symbol: symbol is required: the ticker or the name as the user wrote it, for example TCITY'\n )\n }\n const symbol = record.symbol.trim()\n if (symbol.length > SYMBOL_MAX) {\n return errorResult(`invalid_symbol: symbol holds at most ${SYMBOL_MAX} characters`)\n }\n const base = {\n schema: META_TOKEN_LOOKUP_SCHEMA,\n network,\n query: symbol,\n }\n\n if (ADDRESS_FORM.test(symbol)) {\n const address = symbol.toLowerCase()\n return textResult({\n ...base,\n matched_on: null,\n candidates: [],\n total: 0,\n truncated: false,\n hint: `${ANSWER_HINT} ${address} is a contract address, not a ticker: ${ADDRESS_INPUT_HINT}. Send no token lookup for it.`,\n })\n }\n if (unsafeLiteral(symbol)) {\n return errorResult(\n 'invalid_symbol: a symbol holds no double quote, backslash or control character. Send the ticker or the name as plain text.'\n )\n }\n\n const unavailable = await deps.unavailable?.()\n if (unavailable) {\n return errorResult(\n `No token read was sent: ${unavailable} The lookup has no answer yet, which is not \"no contract\": try again later, or ask the user for the contract. ${NO_WEB}`\n )\n }\n\n let matchedOn: 'symbol' | 'name' = 'symbol'\n let read = await readAssets(deps, network, 'symbol', symbol)\n if (read.kind === 'rows' && read.rows.length === 0) {\n matchedOn = 'name'\n read = await readAssets(deps, network, 'name', symbol)\n }\n if (read.kind === 'failed') {\n return errorResult(\n `The token read failed: ${read.text} This is not \"no contract\": send the same lookup again once, or ask the user for the contract. ${NO_WEB}`\n )\n }\n if (read.kind === 'not_served') {\n return textResult({\n ...base,\n matched_on: null,\n candidates: [],\n total: 0,\n truncated: false,\n hint:\n `${ANSWER_HINT} This Chain Insights server does not serve the token lookup yet (${read.refusal.code}). ` +\n `That is not \"no contract carries ${symbol}\": ask the user for the token's contract, 0x plus 40 hex characters. ${NO_WEB}`,\n })\n }\n\n const total = read.rows.length\n const candidates = read.rows\n .slice(0, CANDIDATES_MAX)\n .map(candidateOf)\n .filter((candidate): candidate is TokenCandidate => candidate !== null)\n const creatorsNotRead =\n candidates.length > 0 ? await readCreators(deps, network, candidates) : null\n const result = {\n ...base,\n matched_on: candidates.length > 0 ? matchedOn : null,\n candidates,\n total,\n truncated: total > CANDIDATES_MAX,\n }\n return textResult({ ...result, hint: hintFor(result, creatorsNotRead) })\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAmBA,MAAa,yBAAyB;AACtC,MAAa,2BAA2B;AACxC,MAAa,0BAA0B;AACvC,MAAa,gCACX;AAKF,MAAa,gCAAgC;CAC3C,cAAc;CACd,gBAAgB;CAChB,eAAe;AACjB;;AAIA,MAAa,iBAAiB;AAC9B,MAAa,YAAY;;AAEzB,MAAa,oBAAoB;AACjC,MAAa,aAAa;AAE1B,MAAa,qBAAqB;AAuDlC,MAAM,eAAe;AACrB,MAAM,gBAAgB;AAItB,SAAS,cAAc,MAAuB;CAC5C,KAAK,MAAM,QAAQ,MAAM;EACvB,MAAM,OAAO,KAAK,YAAY,CAAC;EAC/B,IAAI,SAAS,QAAO,SAAS,QAAQ,OAAO,MAAQ,SAAS,KAAM,OAAO;CAC5E;CACA,OAAO;AACT;AACA,MAAM,cAAc;AAEpB,MAAM,iBACJ;AAEF,SAAS,SAAS,OAAkD;CAClE,OAAO,CAAC,CAAC,SAAS,OAAO,UAAU,YAAY,CAAC,MAAM,QAAQ,KAAK;AACrE;AAEA,SAAS,YAAY,MAAyC;CAC5D,OAAO;EAAE,SAAS,CAAC;GAAE,MAAM;GAAQ;EAAK,CAAC;EAAG,SAAS;CAAK;AAC5D;AAEA,SAAS,WAAW,YAA8D;CAChF,OAAO;EACL,SAAS,CAAC;GAAE,MAAM;GAAQ,MAAM,KAAK,UAAU,YAAY,MAAM,CAAC;EAAE,CAAC;EACrE,mBAAmB;EACnB,SAAS;CACX;AACF;;AAGA,SAAgB,WAAW,KAAwB,OAAuB;CACxE,OACE,6BAA6B,IAAI,KAAK,MAAM,4QAInC;AAEb;;AAGA,SAAgB,a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ACZ,OAAO,MAAM,WAAW,MAAM,SAAS,QAAQ,MAAM;CACvD;CACA,IAAI,KAAK,SAAS,UAChB,OAAO,YACL,0BAA0B,KAAK,KAAK,iGAAiG,QACvI;CAEF,IAAI,KAAK,SAAS,cAChB,OAAO,WAAW;EAChB,GAAG;EACH,YAAY;EACZ,YAAY,CAAC;EACb,OAAO;EACP,WAAW;EACX,MACE,GAAG,YAAY,mEAAmE,KAAK,QAAQ,KAAK,sCAChE,OAAO,uEAAuE;CACtH,CAAC;CAGH,MAAM,QAAQ,KAAK,KAAK;CACxB,MAAM,aAAa,KAAK,KACrB,MAAM,GAAG,cAAc,CAAC,CACxB,IAAI,WAAW,CAAC,CAChB,QAAQ,cAA2C,cAAc,IAAI;CACxE,MAAM,kBACJ,WAAW,SAAS,IAAI,MAAM,aAAa,MAAM,SAAS,UAAU,IAAI;CAC1E,MAAM,SAAS;EACb,GAAG;EACH,YAAY,WAAW,SAAS,IAAI,YAAY;EAChD;EACA;EACA,WAAW,QAAQ;CACrB;CACA,OAAO,WAAW;EAAE,GAAG;EAAQ,MAAM,QAAQ,QAAQ,eAAe;CAAE,CAAC;AACzE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "chain-insights",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.78.0",
|
|
4
4
|
"description": "AML investigation CLI and MCP proxy for blockchain risk screening and Chain Insights Graph access",
|
|
5
5
|
"homepage": "https://chain-insights.ai",
|
|
6
6
|
"repository": {
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"vitest": "^5.0.3"
|
|
94
94
|
},
|
|
95
95
|
"chainInsights": {
|
|
96
|
-
"dexRegistryVersion":
|
|
96
|
+
"dexRegistryVersion": 6
|
|
97
97
|
},
|
|
98
98
|
"overrides": {
|
|
99
99
|
"ws": "8.21.0",
|
package/registry/README.md
CHANGED
|
@@ -22,8 +22,8 @@ flowchart LR
|
|
|
22
22
|
|
|
23
23
|
| File | Rows served | Why |
|
|
24
24
|
|---|---|---|
|
|
25
|
-
| [robinhood.md](robinhood.md) |
|
|
26
|
-
| [robinhood.json](robinhood.json) |
|
|
25
|
+
| [robinhood.md](robinhood.md) | 83 | registry version 6, recorded 2026-11-05; the `dyor` row and the Ekubo positions row are not served |
|
|
26
|
+
| [robinhood.json](robinhood.json) | 40 exchanges | the served copy of `robinhood.md`, never edited by hand |
|
|
27
27
|
|
|
28
28
|
A change to the rows merged on `main` reaches every running proxy within one
|
|
29
29
|
hour. No release is needed for a data change.
|
|
@@ -36,7 +36,11 @@ hour. No release is needed for a data change.
|
|
|
36
36
|
data shows the address does what its role says:
|
|
37
37
|
- `factory`: a contract that created pools;
|
|
38
38
|
- `manager`: a contract that holds pools;
|
|
39
|
-
- `router`: a contract that forwards swaps
|
|
39
|
+
- `router`: a contract that forwards swaps;
|
|
40
|
+
- `helper`: a contract of the exchange that the trail does not read: a
|
|
41
|
+
position NFT, a staking gauge, a parts deployer, or a swap router of a
|
|
42
|
+
vault, where the manager stays the contract past the swap. The chain or
|
|
43
|
+
its verified source must tie it to the exchange.
|
|
40
44
|
Write the check into the file's `## Verification` section.
|
|
41
45
|
3. **An unchecked row stays in the table.** Its verification cell says
|
|
42
46
|
`not served:` and the reason. It is served later, when a check passes.
|
|
@@ -60,7 +64,7 @@ The `## Rows` table has twelve columns, in this order.
|
|
|
60
64
|
| aliases | the names a user types, comma separated, on one row of the exchange or spread over several |
|
|
61
65
|
| trail type | how money is traced through the exchange: `plain`, `vault`, `gauge` or `launchpad`. Every row of an exchange carries the same trail type |
|
|
62
66
|
| adapter | the adapter id of the DEX indexer that reads the row's pools: `cl-gauge-v1`, `uniswap-v4` |
|
|
63
|
-
| role | `factory` creates pools, `manager` holds pools, `router` forwards swaps |
|
|
67
|
+
| role | `factory` creates pools, `manager` holds pools, `router` forwards swaps, `helper` is a contract of the exchange that the trail does not read. A lookup by address finds a helper; the reads of the exchange follow, none for the helper itself |
|
|
64
68
|
| address | lowercase `0x` hex in backticks |
|
|
65
69
|
| valid from block | the first block the row holds from, `0` when it is not known yet |
|
|
66
70
|
| example pool | optional: one pool of the exchange, read live by the release suite. Empty or `-` when not given |
|
|
@@ -80,14 +84,14 @@ A row is refused for one of these reasons:
|
|
|
80
84
|
| `duplicate row` | the same key, role and address twice |
|
|
81
85
|
| `bad dex key` | the key is not lowercase letters, digits, `.`, `_` or `-` |
|
|
82
86
|
| `bad address` | the address is not lowercase `0x` and 40 hex digits |
|
|
83
|
-
| `unknown role` | the role is not `factory`, `manager` or `
|
|
87
|
+
| `unknown role` | the role is not `factory`, `manager`, `router` or `helper` |
|
|
84
88
|
| `unknown trail type` | the trail type is not `plain`, `vault`, `gauge` or `launchpad` |
|
|
85
89
|
| `bad adapter` | the adapter is empty or not an id |
|
|
86
90
|
| `no source link` | the source link is not `[text](https://…)` |
|
|
87
91
|
| `bad block`, `bad example pool`, `bad pool floor` | the cell is not a number or a pool |
|
|
88
92
|
| `too long` | a value does not fit its column |
|
|
89
93
|
| `dex rows disagree` | two rows of one exchange give a different display, trail type, example pool or pool floor |
|
|
90
|
-
| `no factory or manager row for the dex` | the exchange has router rows only |
|
|
94
|
+
| `no factory or manager row for the dex` | the exchange has router or helper rows only |
|
|
91
95
|
|
|
92
96
|
## The check
|
|
93
97
|
|
|
@@ -120,6 +124,8 @@ node scripts/render-dex-registry.mjs --check # exit 1 when a memo table differ
|
|
|
120
124
|
`registry/<network>.json` has the schema `chain-insights.dex-registry.v1`:
|
|
121
125
|
|
|
122
126
|
- one entry per exchange, in the order the file first names it;
|
|
127
|
+
- `helpers` lists its `helper` addresses, when it has any. An older proxy
|
|
128
|
+
ignores the field;
|
|
123
129
|
- `factories` lists its `factory` and `manager` addresses, `routers` its
|
|
124
130
|
`router` addresses; an exchange with no router row lists its manager there,
|
|
125
131
|
because a vault forwards its own swaps;
|
package/registry/robinhood.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"schema": "chain-insights.dex-registry.v1",
|
|
3
3
|
"network": "robinhood",
|
|
4
|
-
"registry_version":
|
|
5
|
-
"recorded_on": "2026-11-
|
|
4
|
+
"registry_version": 6,
|
|
5
|
+
"recorded_on": "2026-11-05",
|
|
6
6
|
"rows": [
|
|
7
7
|
{
|
|
8
8
|
"dex": "aero",
|
|
@@ -24,6 +24,16 @@
|
|
|
24
24
|
"0x0fef9e88a7b76bcdbf451780c6774fe32965ee98": "router",
|
|
25
25
|
"0x9ee35bf1bd69a03c6f0393582030fce8bb93d418": "router"
|
|
26
26
|
},
|
|
27
|
+
"helpers": [
|
|
28
|
+
"0x4857db576ee0e45f10525ec59527bfd10beec60b",
|
|
29
|
+
"0xf437f62053acb121665b8fdbfea8f214fb8e589d",
|
|
30
|
+
"0x220d17d3260f130a4f91a1ba2d21f8f75f624942",
|
|
31
|
+
"0xe033f4bd3d7ccf537a2f954ecdc8eb1218e3b7a6",
|
|
32
|
+
"0x750a4e760873c863daf22890b8db55f4c71f1114",
|
|
33
|
+
"0x045ccb9d8a98cb748b39253005be2d6d5b955c14",
|
|
34
|
+
"0x5874f5b8728776993de4c90c61473d76eeab90db",
|
|
35
|
+
"0xe5b468c4e13b45ec10a1d22ace7e2c0fc0671da0"
|
|
36
|
+
],
|
|
27
37
|
"factories": [
|
|
28
38
|
"0xc63d7338c178e805c544b8f897066bd3bbcbe136"
|
|
29
39
|
],
|
|
@@ -309,6 +319,33 @@
|
|
|
309
319
|
"since_block": 0,
|
|
310
320
|
"source": "https://developers.uniswap.org/docs/protocols/v3/deployments/v3-robinhood-chain-deployments"
|
|
311
321
|
},
|
|
322
|
+
{
|
|
323
|
+
"dex": "eth-usdg-router",
|
|
324
|
+
"display": "unnamed ETH/USDG swap router (routes into Uniswap v3 and v4)",
|
|
325
|
+
"aliases": [
|
|
326
|
+
"ETH/USDG router",
|
|
327
|
+
"ETH/USDG swap router",
|
|
328
|
+
"USDG swap router"
|
|
329
|
+
],
|
|
330
|
+
"trail_type": "plain",
|
|
331
|
+
"adapters": [
|
|
332
|
+
"uniswap-v3"
|
|
333
|
+
],
|
|
334
|
+
"roles": {
|
|
335
|
+
"0x1f7d7550b1b028f7571e69a784071f0205fd2efa": "factory",
|
|
336
|
+
"0x7a39b98d31f84152bc724bc5ddb41dbcb338f2a5": "router"
|
|
337
|
+
},
|
|
338
|
+
"factories": [
|
|
339
|
+
"0x1f7d7550b1b028f7571e69a784071f0205fd2efa"
|
|
340
|
+
],
|
|
341
|
+
"routers": [
|
|
342
|
+
"0x7a39b98d31f84152bc724bc5ddb41dbcb338f2a5"
|
|
343
|
+
],
|
|
344
|
+
"example_pool": "0x52e65b17fb6e5ba00ed806f37afcd2daa50271ca",
|
|
345
|
+
"pool_floor": null,
|
|
346
|
+
"since_block": 105000018,
|
|
347
|
+
"source": "https://github.com/chainswarm/scout-agent/issues/164"
|
|
348
|
+
},
|
|
312
349
|
{
|
|
313
350
|
"dex": "uniswap-v4",
|
|
314
351
|
"display": "Uniswap v4",
|
|
@@ -326,6 +363,10 @@
|
|
|
326
363
|
"roles": {
|
|
327
364
|
"0x8366a39cc670b4001a1121b8f6a443a643e40951": "manager"
|
|
328
365
|
},
|
|
366
|
+
"helpers": [
|
|
367
|
+
"0x204faca1764b154221e35c0d20abb3c525710498",
|
|
368
|
+
"0x8876789976decbfcbbbe364623c63652db8c0904"
|
|
369
|
+
],
|
|
329
370
|
"factories": [
|
|
330
371
|
"0x8366a39cc670b4001a1121b8f6a443a643e40951"
|
|
331
372
|
],
|
|
@@ -897,6 +938,150 @@
|
|
|
897
938
|
"pool_floor": null,
|
|
898
939
|
"since_block": 0,
|
|
899
940
|
"source": "https://github.com/chainswarm/AP1000/blob/main/openspec/changes/archive/2026-10-16-silent-factory-discovery-and-labels/design.md"
|
|
941
|
+
},
|
|
942
|
+
{
|
|
943
|
+
"dex": "weth-unwrap-helper",
|
|
944
|
+
"display": "unnamed WETH-unwrap helper of Uniswap sell routes",
|
|
945
|
+
"aliases": [
|
|
946
|
+
"WETH-unwrap helper"
|
|
947
|
+
],
|
|
948
|
+
"trail_type": "plain",
|
|
949
|
+
"adapters": [
|
|
950
|
+
"uniswap-v3"
|
|
951
|
+
],
|
|
952
|
+
"roles": {
|
|
953
|
+
"0x1f7d7550b1b028f7571e69a784071f0205fd2efa": "factory",
|
|
954
|
+
"0x0849c295bc609da9fde347834f92a75c2c4eb178": "router"
|
|
955
|
+
},
|
|
956
|
+
"factories": [
|
|
957
|
+
"0x1f7d7550b1b028f7571e69a784071f0205fd2efa"
|
|
958
|
+
],
|
|
959
|
+
"routers": [
|
|
960
|
+
"0x0849c295bc609da9fde347834f92a75c2c4eb178"
|
|
961
|
+
],
|
|
962
|
+
"example_pool": null,
|
|
963
|
+
"pool_floor": null,
|
|
964
|
+
"since_block": 103295248,
|
|
965
|
+
"source": "https://github.com/chainswarm/scout-agent/issues/162"
|
|
966
|
+
},
|
|
967
|
+
{
|
|
968
|
+
"dex": "realm-etf",
|
|
969
|
+
"display": "Realm ETF launchpad",
|
|
970
|
+
"aliases": [
|
|
971
|
+
"Realm",
|
|
972
|
+
"Realm ETF",
|
|
973
|
+
"RealmEtf"
|
|
974
|
+
],
|
|
975
|
+
"trail_type": "launchpad",
|
|
976
|
+
"adapters": [
|
|
977
|
+
"uniswap-v4"
|
|
978
|
+
],
|
|
979
|
+
"roles": {
|
|
980
|
+
"0x124ad86c732b16366ed26445e3943adef635f123": "factory",
|
|
981
|
+
"0x74dd0a05540f7c1ae419c18f8d55ff220076e8c8": "router"
|
|
982
|
+
},
|
|
983
|
+
"factories": [
|
|
984
|
+
"0x124ad86c732b16366ed26445e3943adef635f123"
|
|
985
|
+
],
|
|
986
|
+
"routers": [
|
|
987
|
+
"0x74dd0a05540f7c1ae419c18f8d55ff220076e8c8"
|
|
988
|
+
],
|
|
989
|
+
"example_pool": null,
|
|
990
|
+
"pool_floor": null,
|
|
991
|
+
"since_block": 101031051,
|
|
992
|
+
"source": "https://sourcify.dev/server/v2/contract/4663/0x74dd0a05540f7c1ae419c18f8d55ff220076e8c8"
|
|
993
|
+
},
|
|
994
|
+
{
|
|
995
|
+
"dex": "pangea",
|
|
996
|
+
"display": "Pangea launch factory",
|
|
997
|
+
"aliases": [
|
|
998
|
+
"Pangea",
|
|
999
|
+
"Pangea launch"
|
|
1000
|
+
],
|
|
1001
|
+
"trail_type": "launchpad",
|
|
1002
|
+
"adapters": [
|
|
1003
|
+
"uniswap-v4"
|
|
1004
|
+
],
|
|
1005
|
+
"roles": {
|
|
1006
|
+
"0xadf9c12eaf14da2f7780c0587cc06034f1edf8d3": "factory"
|
|
1007
|
+
},
|
|
1008
|
+
"helpers": [
|
|
1009
|
+
"0x6ea418b883571af6155145d5604187f92b2d7b92"
|
|
1010
|
+
],
|
|
1011
|
+
"factories": [
|
|
1012
|
+
"0xadf9c12eaf14da2f7780c0587cc06034f1edf8d3"
|
|
1013
|
+
],
|
|
1014
|
+
"routers": [],
|
|
1015
|
+
"example_pool": null,
|
|
1016
|
+
"pool_floor": null,
|
|
1017
|
+
"since_block": 96290239,
|
|
1018
|
+
"source": "https://sourcify.dev/server/v2/contract/4663/0xadf9c12eaf14da2f7780c0587cc06034f1edf8d3"
|
|
1019
|
+
},
|
|
1020
|
+
{
|
|
1021
|
+
"dex": "icecreamswap",
|
|
1022
|
+
"display": "IceCreamSwap aggregator",
|
|
1023
|
+
"aliases": [
|
|
1024
|
+
"IceCreamSwap",
|
|
1025
|
+
"IceCream",
|
|
1026
|
+
"Ice Cream Swap"
|
|
1027
|
+
],
|
|
1028
|
+
"trail_type": "plain",
|
|
1029
|
+
"adapters": [
|
|
1030
|
+
"uniswap-v3"
|
|
1031
|
+
],
|
|
1032
|
+
"roles": {
|
|
1033
|
+
"0x1f7d7550b1b028f7571e69a784071f0205fd2efa": "factory",
|
|
1034
|
+
"0x603206d6105217dd972e4ab30676a220ca393346": "router",
|
|
1035
|
+
"0x2ca37ff95caf25366ef16fc2e655b78a165d125f": "router",
|
|
1036
|
+
"0xec9aa0a6c2372131a0502aba6188269ab52cacb5": "router",
|
|
1037
|
+
"0xe6eeda550918638529c6cf2ea14f9ea0572d6f88": "router"
|
|
1038
|
+
},
|
|
1039
|
+
"factories": [
|
|
1040
|
+
"0x1f7d7550b1b028f7571e69a784071f0205fd2efa"
|
|
1041
|
+
],
|
|
1042
|
+
"routers": [
|
|
1043
|
+
"0x603206d6105217dd972e4ab30676a220ca393346",
|
|
1044
|
+
"0x2ca37ff95caf25366ef16fc2e655b78a165d125f",
|
|
1045
|
+
"0xec9aa0a6c2372131a0502aba6188269ab52cacb5",
|
|
1046
|
+
"0xe6eeda550918638529c6cf2ea14f9ea0572d6f88"
|
|
1047
|
+
],
|
|
1048
|
+
"example_pool": null,
|
|
1049
|
+
"pool_floor": null,
|
|
1050
|
+
"since_block": 3087983,
|
|
1051
|
+
"source": "https://sourcify.dev/server/v2/contract/4663/0x603206d6105217dd972e4ab30676a220ca393346"
|
|
1052
|
+
},
|
|
1053
|
+
{
|
|
1054
|
+
"dex": "per-launch-v4-router",
|
|
1055
|
+
"display": "unnamed per-launch Uniswap v4 swap routers",
|
|
1056
|
+
"aliases": [
|
|
1057
|
+
"per-launch router",
|
|
1058
|
+
"per-launch v4 router"
|
|
1059
|
+
],
|
|
1060
|
+
"trail_type": "vault",
|
|
1061
|
+
"adapters": [
|
|
1062
|
+
"uniswap-v4"
|
|
1063
|
+
],
|
|
1064
|
+
"roles": {
|
|
1065
|
+
"0x8366a39cc670b4001a1121b8f6a443a643e40951": "manager"
|
|
1066
|
+
},
|
|
1067
|
+
"helpers": [
|
|
1068
|
+
"0xe672754903b2be414abbec68ee1a6d7884ba993b",
|
|
1069
|
+
"0x0c388f9d803e17addc439a50a9c9b9e3937221f5",
|
|
1070
|
+
"0x3201074c2a813d9827c563395c16a86560f57437",
|
|
1071
|
+
"0x80d49714825e23d4801549a765cb88cf917f2f02",
|
|
1072
|
+
"0xf5b7cba51da2cef7fb334aa34c83203efa1f083e",
|
|
1073
|
+
"0xff4b110e9e3b70de24490bef682f18a2342b55a9"
|
|
1074
|
+
],
|
|
1075
|
+
"factories": [
|
|
1076
|
+
"0x8366a39cc670b4001a1121b8f6a443a643e40951"
|
|
1077
|
+
],
|
|
1078
|
+
"routers": [
|
|
1079
|
+
"0x8366a39cc670b4001a1121b8f6a443a643e40951"
|
|
1080
|
+
],
|
|
1081
|
+
"example_pool": null,
|
|
1082
|
+
"pool_floor": null,
|
|
1083
|
+
"since_block": 90471772,
|
|
1084
|
+
"source": "https://github.com/chainswarm/scout-agent/issues/134"
|
|
900
1085
|
}
|
|
901
1086
|
]
|
|
902
1087
|
}
|
package/registry/robinhood.md
CHANGED
|
@@ -6,9 +6,9 @@ columns and the check are in the [README](README.md). The served copy is
|
|
|
6
6
|
[robinhood.json](robinhood.json), written by
|
|
7
7
|
`node scripts/pin-dex-registry.mjs registry/robinhood.md`.
|
|
8
8
|
|
|
9
|
-
Registry version:
|
|
9
|
+
Registry version: 6.
|
|
10
10
|
|
|
11
|
-
Recorded on: 2026-11-
|
|
11
|
+
Recorded on: 2026-11-05.
|
|
12
12
|
|
|
13
13
|
## Rows
|
|
14
14
|
|
|
@@ -18,6 +18,14 @@ Recorded on: 2026-11-02.
|
|
|
18
18
|
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | router | `0x72e46c9edf828002fdbfdd0952419790576c0f18` | 94021838 | - | - | [census 2026-10-23](https://github.com/chainswarm/AP1000/blob/main/docs/evidence/2026-10-23-dex-protocol-skills.md) | served |
|
|
19
19
|
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | router | `0x0fef9e88a7b76bcdbf451780c6774fe32965ee98` | 0 | - | - | [Dromos metarouter ledger](https://github.com/dromos-labs/metadex-slipstream-public/blob/main/deployment-addresses/cl-robinhood.json) | served |
|
|
20
20
|
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | router | `0x9ee35bf1bd69a03c6f0393582030fce8bb93d418` | 0 | - | - | [Dromos CL ledger](https://github.com/dromos-labs/metadex-slipstream-public/blob/main/deployment-addresses/cl-robinhood.json) | served |
|
|
21
|
+
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | helper | `0x4857db576ee0e45f10525ec59527bfd10beec60b` | 93974253 | - | - | [position NFT named by the verified gauge](https://sourcify.dev/server/v2/contract/4663/0x89e91a960154b1ed6c093039a8f0725ab67d14e0) | served |
|
|
22
|
+
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | helper | `0xf437f62053acb121665b8fdbfea8f214fb8e589d` | 93974455 | - | - | [gauge factory of the verified gauge](https://sourcify.dev/server/v2/contract/4663/0x89e91a960154b1ed6c093039a8f0725ab67d14e0) | served |
|
|
23
|
+
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | helper | `0x220d17d3260f130a4f91a1ba2d21f8f75f624942` | 94581179 | - | - | [clone of the verified ArbCLGauge](https://sourcify.dev/server/v2/contract/4663/0x89e91a960154b1ed6c093039a8f0725ab67d14e0) | served |
|
|
24
|
+
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | helper | `0xe033f4bd3d7ccf537a2f954ecdc8eb1218e3b7a6` | 94581067 | - | - | [clone of the verified ArbCLGauge](https://sourcify.dev/server/v2/contract/4663/0x89e91a960154b1ed6c093039a8f0725ab67d14e0) | served |
|
|
25
|
+
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | helper | `0x750a4e760873c863daf22890b8db55f4c71f1114` | 94581160 | - | - | [clone of the verified ArbCLGauge](https://sourcify.dev/server/v2/contract/4663/0x89e91a960154b1ed6c093039a8f0725ab67d14e0) | served |
|
|
26
|
+
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | helper | `0x045ccb9d8a98cb748b39253005be2d6d5b955c14` | 94581169 | - | - | [clone of the verified ArbCLGauge](https://sourcify.dev/server/v2/contract/4663/0x89e91a960154b1ed6c093039a8f0725ab67d14e0) | served |
|
|
27
|
+
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | helper | `0x5874f5b8728776993de4c90c61473d76eeab90db` | 94581072 | - | - | [clone of the verified ArbCLGauge](https://sourcify.dev/server/v2/contract/4663/0x89e91a960154b1ed6c093039a8f0725ab67d14e0) | served |
|
|
28
|
+
| aero | Aero (Aerodrome and Velodrome, merged) | | gauge | cl-gauge-v1 | helper | `0xe5b468c4e13b45ec10a1d22ace7e2c0fc0671da0` | 94581094 | - | - | [clone of the verified ArbCLGauge](https://sourcify.dev/server/v2/contract/4663/0x89e91a960154b1ed6c093039a8f0725ab67d14e0) | served |
|
|
21
29
|
| up | up. | up., up, UP, up33, UP33, up.finance | gauge | cl-gauge-v1 | factory | `0x1ac9db4a2608ba45d6127b1737949b51bb54b7f3` | 6184096 | 0x4e8649be40ae67ebbcff99c291b92ee03015917b | 800 | [DefiLlama up-v3](https://github.com/DefiLlama/dimension-adapters/blob/master/dexs/up-v3/index.ts) | served |
|
|
22
30
|
| up | up. | | gauge | solidly-v2 | factory | `0xfa5429aeba338bea2bfcc1b9a889862ee395bc28` | 6180950 | - | - | [DefiLlama up-v2](https://github.com/DefiLlama/dimension-adapters/blob/master/dexs/up-v2/index.ts) | served |
|
|
23
31
|
| up | up. | | gauge | cl-gauge-v1 | router | `0xc062b870e813fca720f1e002c234369ab3ab9415` | 0 | - | - | [lp-terminal contract map](https://github.com/lp-terminal/contracts/blob/main/robinhood.json) | served |
|
|
@@ -38,7 +46,11 @@ Recorded on: 2026-11-02.
|
|
|
38
46
|
| swaphood | SwapHood | | gauge | solidly-v2 | router | `0x8f8056fec03159ebcc4aee1b8ea5a61d8fe405fc` | 0 | - | - | [SwapHood contract addresses](https://swaphood-finance.gitbook.io/swaphood-finance-docs/contract-addresses.md) | served |
|
|
39
47
|
| uniswap-v2 | Uniswap v2 | Uniswap v2, Uni v2 | plain | uniswap-v2 | factory | `0x8bceaa40b9acdfaedf85adf4ff01f5ad6517937f` | 0 | 0x4a6a85252a6f6b383a5f747259ee157e65ff1307 | 10000 | [Uniswap v2 deployments](https://developers.uniswap.org/docs/protocols/v2/deployments) | served |
|
|
40
48
|
| uniswap-v3 | Uniswap v3 | Uniswap v3, Uni v3 | plain | uniswap-v3 | factory | `0x1f7d7550b1b028f7571e69a784071f0205fd2efa` | 0 | 0x10cc6bd38112cac182db90b6a71d8bb5939526ba | 200000 | [Uniswap v3 Robinhood deployment](https://developers.uniswap.org/docs/protocols/v3/deployments/v3-robinhood-chain-deployments) | served |
|
|
49
|
+
| eth-usdg-router | unnamed ETH/USDG swap router (routes into Uniswap v3 and v4) | ETH/USDG router, ETH/USDG swap router, USDG swap router | plain | uniswap-v3 | factory | `0x1f7d7550b1b028f7571e69a784071f0205fd2efa` | 105000018 | 0x52e65b17fb6e5ba00ed806f37afcd2daa50271ca | - | [scout-agent finding 164](https://github.com/chainswarm/scout-agent/issues/164) | served |
|
|
50
|
+
| eth-usdg-router | unnamed ETH/USDG swap router (routes into Uniswap v3 and v4) | | plain | uniswap-v3 | router | `0x7a39b98d31f84152bc724bc5ddb41dbcb338f2a5` | 105000018 | 0x52e65b17fb6e5ba00ed806f37afcd2daa50271ca | - | [scout-agent finding 164](https://github.com/chainswarm/scout-agent/issues/164) | served |
|
|
41
51
|
| uniswap-v4 | Uniswap v4 | Uniswap, UNI, Uniswap v4, Uni v4, PoolManager | vault | uniswap-v4 | manager | `0x8366a39cc670b4001a1121b8f6a443a643e40951` | 0 | - | - | [Uniswap v4 deployments](https://developers.uniswap.org/docs/protocols/v4/deployments) | served |
|
|
52
|
+
| uniswap-v4 | Uniswap v4 | | vault | uniswap-v4 | helper | `0x204faca1764b154221e35c0d20abb3c525710498` | 65727895 | - | - | [Uniswap v4 deployments](https://developers.uniswap.org/docs/protocols/v4/deployments) | served |
|
|
53
|
+
| uniswap-v4 | Uniswap v4 | | vault | uniswap-v4 | helper | `0x8876789976decbfcbbbe364623c63652db8c0904` | 18127 | - | - | [Uniswap v4 deployments](https://developers.uniswap.org/docs/protocols/v4/deployments) | served |
|
|
42
54
|
| pancakeswap | PancakeSwap Infinity | PancakeSwap, Pancake, CAKE, PancakeSwap Infinity | vault | pancake-infinity-cl | manager | `0xee04c68742e6bf434be8039580d2e89bbe55bc6f` | 0 | - | - | [PancakeSwap infinity config](https://github.com/pancakeswap/infinity-periphery/blob/main/script/config/robinhood-mainnet.json) | served |
|
|
43
55
|
| pancakeswap-v2 | PancakeSwap v2 | PancakeSwap v2, Pancake v2 | plain | uniswap-v2 | factory | `0x02a84c1b3bbd7401a5f7fa98a384ebc70bb5749e` | 0 | - | 40 | [PancakeSwap infinity config](https://github.com/pancakeswap/infinity-periphery/blob/main/script/config/robinhood-mainnet.json) | served |
|
|
44
56
|
| pancakeswap-v3 | PancakeSwap v3 | PancakeSwap v3, Pancake v3 | plain | uniswap-v3 | factory | `0x0bfbcf9fa4f9c56b0f40a671ad40e0805a091865` | 0 | - | - | [PancakeSwap config](https://github.com/pancakeswap/infinity-periphery/blob/main/script/config/robinhood-mainnet.json) | served |
|
|
@@ -69,6 +81,24 @@ Recorded on: 2026-11-02.
|
|
|
69
81
|
| single-router-launchpad | unnamed single-router bonding-curve launchpad | single-router bonding-curve launchpad, single-router launchpad | launchpad | mob-launch-curve | factory | `0x006fee8a9a5482dd7cdf7f21b4d78fa6e246ca4c` | 99903488 | - | - | [scout-agent finding 131](https://github.com/chainswarm/scout-agent/issues/131) | served |
|
|
70
82
|
| single-router-launchpad | unnamed single-router bonding-curve launchpad | | launchpad | mob-launch-curve | manager | `0x4ed0f046d97d508df86d6b7b058e763dbfb0027f` | 99903488 | - | - | [devops registry v29](https://github.com/chainswarm/devops/blob/e270ee1a3c8a2afc52e9d5549be5dbb8b98f0914/charts/chainswarm-indexer-evm-dex/registry/robinhood-v29.json) | served |
|
|
71
83
|
| virtuals | Virtuals Protocol | Virtuals, VIRTUAL, Virtuals Protocol | launchpad | uniswap-v2 | factory | `0xfc2e4da3edb2e18100473339c763705d263d20a9` | 0 | - | - | [change silent-factory-discovery-and-labels](https://github.com/chainswarm/AP1000/blob/main/openspec/changes/archive/2026-10-16-silent-factory-discovery-and-labels/design.md) | served |
|
|
84
|
+
| weth-unwrap-helper | unnamed WETH-unwrap helper of Uniswap sell routes | WETH-unwrap helper | plain | uniswap-v3 | factory | `0x1f7d7550b1b028f7571e69a784071f0205fd2efa` | 103295248 | - | - | [scout-agent finding 162](https://github.com/chainswarm/scout-agent/issues/162) | served |
|
|
85
|
+
| weth-unwrap-helper | unnamed WETH-unwrap helper of Uniswap sell routes | | plain | uniswap-v3 | router | `0x0849c295bc609da9fde347834f92a75c2c4eb178` | 103295248 | - | - | [scout-agent finding 162](https://github.com/chainswarm/scout-agent/issues/162) | served |
|
|
86
|
+
| realm-etf | Realm ETF launchpad | Realm, Realm ETF, RealmEtf | launchpad | uniswap-v4 | factory | `0x124ad86c732b16366ed26445e3943adef635f123` | 101031051 | - | - | [Sourcify RealmEtfHook](https://sourcify.dev/server/v2/contract/4663/0x74dd0a05540f7c1ae419c18f8d55ff220076e8c8) | served |
|
|
87
|
+
| realm-etf | Realm ETF launchpad | | launchpad | uniswap-v4 | router | `0x74dd0a05540f7c1ae419c18f8d55ff220076e8c8` | 101031057 | - | - | [Sourcify RealmEtfHook](https://sourcify.dev/server/v2/contract/4663/0x74dd0a05540f7c1ae419c18f8d55ff220076e8c8) | served |
|
|
88
|
+
| pangea | Pangea launch factory | Pangea, Pangea launch | launchpad | uniswap-v4 | factory | `0xadf9c12eaf14da2f7780c0587cc06034f1edf8d3` | 96290239 | - | - | [Sourcify UniswapLaunchFactoryV2](https://sourcify.dev/server/v2/contract/4663/0xadf9c12eaf14da2f7780c0587cc06034f1edf8d3) | served |
|
|
89
|
+
| pangea | Pangea launch factory | | launchpad | uniswap-v4 | helper | `0x6ea418b883571af6155145d5604187f92b2d7b92` | 96283385 | - | - | [Sourcify PartsDeployerV2](https://sourcify.dev/server/v2/contract/4663/0x6ea418b883571af6155145d5604187f92b2d7b92) | served |
|
|
90
|
+
| icecreamswap | IceCreamSwap aggregator | IceCreamSwap, IceCream, Ice Cream Swap | plain | uniswap-v3 | factory | `0x1f7d7550b1b028f7571e69a784071f0205fd2efa` | 3087983 | - | - | [Sourcify AggregatorGuard](https://sourcify.dev/server/v2/contract/4663/0x603206d6105217dd972e4ab30676a220ca393346) | served |
|
|
91
|
+
| icecreamswap | IceCreamSwap aggregator | | plain | uniswap-v3 | router | `0x603206d6105217dd972e4ab30676a220ca393346` | 3087983 | - | - | [Sourcify AggregatorGuard](https://sourcify.dev/server/v2/contract/4663/0x603206d6105217dd972e4ab30676a220ca393346) | served |
|
|
92
|
+
| icecreamswap | IceCreamSwap aggregator | | plain | uniswap-v3 | router | `0x2ca37ff95caf25366ef16fc2e655b78a165d125f` | 3094087 | - | - | [Sourcify AggregatorGuard](https://sourcify.dev/server/v2/contract/4663/0x603206d6105217dd972e4ab30676a220ca393346) | served |
|
|
93
|
+
| icecreamswap | IceCreamSwap aggregator | | plain | uniswap-v3 | router | `0xec9aa0a6c2372131a0502aba6188269ab52cacb5` | 72179539 | - | - | [Sourcify AggregatorGuard](https://sourcify.dev/server/v2/contract/4663/0x603206d6105217dd972e4ab30676a220ca393346) | served |
|
|
94
|
+
| icecreamswap | IceCreamSwap aggregator | | plain | uniswap-v3 | router | `0xe6eeda550918638529c6cf2ea14f9ea0572d6f88` | 92800751 | - | - | [Sourcify AggregatorGuard](https://sourcify.dev/server/v2/contract/4663/0x603206d6105217dd972e4ab30676a220ca393346) | served |
|
|
95
|
+
| per-launch-v4-router | unnamed per-launch Uniswap v4 swap routers | per-launch router, per-launch v4 router | vault | uniswap-v4 | manager | `0x8366a39cc670b4001a1121b8f6a443a643e40951` | 90471772 | - | - | [scout-agent finding 134](https://github.com/chainswarm/scout-agent/issues/134) | served |
|
|
96
|
+
| per-launch-v4-router | unnamed per-launch Uniswap v4 swap routers | | vault | uniswap-v4 | helper | `0xe672754903b2be414abbec68ee1a6d7884ba993b` | 100454866 | - | - | [scout-agent finding 134](https://github.com/chainswarm/scout-agent/issues/134) | served |
|
|
97
|
+
| per-launch-v4-router | unnamed per-launch Uniswap v4 swap routers | | vault | uniswap-v4 | helper | `0x0c388f9d803e17addc439a50a9c9b9e3937221f5` | 100437079 | - | - | [scout-agent finding 134](https://github.com/chainswarm/scout-agent/issues/134) | served |
|
|
98
|
+
| per-launch-v4-router | unnamed per-launch Uniswap v4 swap routers | | vault | uniswap-v4 | helper | `0x3201074c2a813d9827c563395c16a86560f57437` | 100215518 | - | - | [scout-agent finding 134](https://github.com/chainswarm/scout-agent/issues/134) | served |
|
|
99
|
+
| per-launch-v4-router | unnamed per-launch Uniswap v4 swap routers | | vault | uniswap-v4 | helper | `0x80d49714825e23d4801549a765cb88cf917f2f02` | 99533593 | - | - | [scout-agent finding 134](https://github.com/chainswarm/scout-agent/issues/134) | served |
|
|
100
|
+
| per-launch-v4-router | unnamed per-launch Uniswap v4 swap routers | | vault | uniswap-v4 | helper | `0xf5b7cba51da2cef7fb334aa34c83203efa1f083e` | 99416107 | - | - | [scout-agent finding 134](https://github.com/chainswarm/scout-agent/issues/134) | served |
|
|
101
|
+
| per-launch-v4-router | unnamed per-launch Uniswap v4 swap routers | | vault | uniswap-v4 | helper | `0xff4b110e9e3b70de24490bef682f18a2342b55a9` | 90471772 | - | - | [scout-agent finding 134](https://github.com/chainswarm/scout-agent/issues/134) | served |
|
|
72
102
|
|
|
73
103
|
## Verification
|
|
74
104
|
|
|
@@ -106,6 +136,7 @@ swaps it forwarded.
|
|
|
106
136
|
| `0x006fee8a9a5482dd7cdf7f21b4d78fa6e246ca4c` | factory | the token factory of the single-router launchpad: it created all 14 launched tokens on lane B, from Mob `0xe0165a1b3d8f9e276b0746adcb9c7094cbd05785` at block 99,903,488 to block 100,030,381. Created at block 99,884,248 by `0x9cd48fc444f80e6c79d90c4bcb9d045603747390`, the deployer of the router below. A launched token is not a pool: its curve is kept inside the router, so the row's factory serves the launches read, and the router holds the pools |
|
|
107
137
|
| `0x4ed0f046d97d508df86d6b7b058e763dbfb0027f` | manager | one router holds every curve, each keyed by the launched token: 13 `mob-launch-curve` pools on lane B on 2026-11-02, from block 99,903,488 to 100,025,977, and 780 swap rows since 2026-10-28. The first, `0x331d64719b7a01f59ef03311e4f0c10f00b7271d1cef0dcdeb6321ae480efcd7` at block 99,903,517, is a buy the router refunded in part. Created at block 99,884,296 by `0x9cd48fc444f80e6c79d90c4bcb9d045603747390`; no source is verified and no project names it. The token Mob is a launch, never the launchpad's name |
|
|
108
138
|
| `0x2f4579ca81717d3d61bf8b6f06571877bbe54a07` | manager | the one reserve holder of 105 market contracts that log `Swapped` and move no token themselves; the indexer names the first, `0x95e4a408590e5ace8aab498ab0f9f4236f5162e5` (the AMD market), and 104 more, all created by `0x8dbf0d37cad30b2510d5c74e0f87a210cb298086`. The holder takes the sold token and pays the bought one in every trade. Read on lane B's StarRocks on 2026-11-02: 52 `swapped-custody` pairs from block 461,784, each a pool of the holder keyed by its two tokens, and 225,885 swap rows from 2026-10-26 to 2026-11-02. On 2026-11-01 its trades were stock tokens (SNDK, SKHY, MU, MSTR, AMD, SPCX, USO, RDDT, DJT) against USDG, and some WETH and ETH; the first that day, `0x4e625db12c0affff1ab5634d587da84a0da4c474ab110d174b6c0cd6cd64887c` at block 102,958,054. Created at block 223,587 by `0xb97c121f7bf12bc21ed22b9739f3695bd2ab23a8`; no source is verified and no project names it. The market contracts have no row: each is one token's door, not a pool and not a router |
|
|
139
|
+
| `0x7a39b98d31f84152bc724bc5ddb41dbcb338f2a5` | router | read on the production graph through the Chain Insights proxy on 2026-11-05 by scout-agent (finding 164): a contract with no label, created at block 105,000,018 (2026-11-03) by `0xf90e3e4f5b23b2ba5a53e7c72ccac139e0ff1c1b` in `0x3561086bf317b231da030bff5367f6213afdeb01724f990c1d4dc2bbed06d982`, below the DEX head 106,440,927. About 500 wallets call it directly with ETH and USDG `0x5fc5360d0400a0fd4f2af552add042d716f1d168`: 500 senders, 495 receivers, 19,962 transactions in and 21,858 out. It wraps and unwraps WETH `0x0bd7d308f8e1639fab988df18a8011f41eacad73` and swaps in the Uniswap v3 WETH/USDG pool `0x52e65b17fb6e5ba00ed806f37afcd2daa50271ca` (7,041 transactions) and, for some trades, the Uniswap v4 PoolManager `0x8366a39cc670b4001a1121b8f6a443a643e40951`. Its `SWAPPED` links reach its callers through the pool, so the caller stays the trader. Sample call `0x4e675f9318bfced710a7c2072662701beb4662a6b61fcf57a608ac84fdbeae18` (block 106,301,475) from `0x7b6830c4f01d976d9a344febdf3588d99a23dfd0`, ETH value, 12 logs. No source is verified and no project names it |
|
|
109
140
|
|
|
110
141
|
`0x0d1ebb179cdbca88d74c923c4255cb2b17474afd` created 254,650 `uniswap-v2`
|
|
111
142
|
pairs with 38 USD of volume in all: the Flap launchpad's pair factory per
|
|
@@ -136,3 +167,56 @@ one reserve holder (`swapped-custody`). The adapter ids keep the indexer's
|
|
|
136
167
|
words: the indexer named `hoodclub` and `mob` after token symbols, and
|
|
137
168
|
neither is a cited exchange name. Only the native-ETH launchpad carries a pool floor; its count is the
|
|
138
169
|
lowest proven, one pool.
|
|
170
|
+
|
|
171
|
+
Registry version 5 (2026-11-05) serves the swap router of scout-agent
|
|
172
|
+
finding 164: an unnamed ETH/USDG router, `eth-usdg-router`, that about 500
|
|
173
|
+
wallets call directly and that swaps in Uniswap v3 and Uniswap v4 pools. No
|
|
174
|
+
source names its operator, so it is served under a plain description. The
|
|
175
|
+
review rule refuses an exchange with router rows only, so the key also
|
|
176
|
+
carries a factory row for the Uniswap v3 factory
|
|
177
|
+
`0x1f7d7550b1b028f7571e69a784071f0205fd2efa`, valid from the router's
|
|
178
|
+
creation block. The example pool is the pool the router swaps in, the
|
|
179
|
+
Uniswap v3 WETH/USDG pool `0x52e65b17fb6e5ba00ed806f37afcd2daa50271ca`.
|
|
180
|
+
That factory stays Uniswap v3's: a lookup of its address still answers
|
|
181
|
+
Uniswap v3, the first exchange that names it.
|
|
182
|
+
|
|
183
|
+
Registry version 6 (2026-11-05) serves the rows of six scout-agent findings
|
|
184
|
+
and adds the role `helper`: a contract of an exchange that the trail does not
|
|
185
|
+
read. That is a position NFT, a gauge, a parts deployer, or a swap router of a
|
|
186
|
+
vault, where the manager stays the contract past the swap.
|
|
187
|
+
|
|
188
|
+
- Finding 162: the Uniswap Universal Routers
|
|
189
|
+
`0x204faca1764b154221e35c0d20abb3c525710498` and
|
|
190
|
+
`0x8876789976decbfcbbbe364623c63652db8c0904`, both on Uniswap's own
|
|
191
|
+
Robinhood Chain list, and the WETH-unwrap contract
|
|
192
|
+
`0x0849c295bc609da9fde347834f92a75c2c4eb178`. Its code holds WETH, and the
|
|
193
|
+
graph shows 7,431 transfers from it to the first router. It has no verified
|
|
194
|
+
source and no known operator, so it has a plain description and its own key.
|
|
195
|
+
- Finding 146: the Realm ETF launchpad. Sourcify verifies `RealmEtfHook`
|
|
196
|
+
`0x74dd0a05540f7c1ae419c18f8d55ff220076e8c8`, and its code holds its factory
|
|
197
|
+
`0x124ad86c732b16366ed26445e3943adef635f123` as an immutable.
|
|
198
|
+
- Finding 134: six single-launch v4 routers with one code shape, each holding
|
|
199
|
+
the PoolManager in its code. No source names them. Later launches of the
|
|
200
|
+
series need a row each.
|
|
201
|
+
- Finding 107: the Aero Slipstream staking contracts. Sourcify verifies the
|
|
202
|
+
implementation `ArbCLGauge` `0x89e91a960154b1ed6c093039a8f0725ab67d14e0`. Both
|
|
203
|
+
gauges read on 2026-11-05 answer `nft()` with the position NFT
|
|
204
|
+
`0x4857db576ee0e45f10525ec59527bfd10beec60b` ("Slipstream V3 Deposit",
|
|
205
|
+
AERO-CL) and `voter()` with `0x382409fad8503fbcdbb27a4211551fa03e884078`.
|
|
206
|
+
`0xe033f4bd3d7ccf537a2f954ecdc8eb1218e3b7a6` answers `pool()` with the Aero
|
|
207
|
+
pool `0x7615926023bb149f36095645c2a81dc367d39750`. Only the six gauges the
|
|
208
|
+
finding names are listed, out of more than 50.
|
|
209
|
+
- Finding 100: the Pangea launch factory. Sourcify verifies
|
|
210
|
+
`UniswapLaunchFactoryV2` `0xadf9c12eaf14da2f7780c0587cc06034f1edf8d3`, whose
|
|
211
|
+
title names Pangea. Its code holds `PartsDeployerV2`
|
|
212
|
+
`0x6ea418b883571af6155145d5604187f92b2d7b92`, and its `platform()` answers
|
|
213
|
+
the 20 percent fee wallet `0xe8e219cccff046b8e6666f9803414f442e333940`.
|
|
214
|
+
- Finding 50: the IceCreamSwap aggregator. Sourcify verifies `AggregatorGuard`
|
|
215
|
+
`0x603206d6105217dd972e4ab30676a220ca393346`, whose one entry function is
|
|
216
|
+
named `IceCreamSwap`. The name rests on that function alone. The three
|
|
217
|
+
executors are its routers.
|
|
218
|
+
|
|
219
|
+
Each new key that has no factory of its own names the factory or manager it
|
|
220
|
+
swaps through, valid from its own first block, as `eth-usdg-router` does. A
|
|
221
|
+
lookup of that factory or manager still answers Uniswap, the first exchange
|
|
222
|
+
that names it.
|
|
@@ -85,7 +85,7 @@ hand. When the tool and the memo differ, follow the tool: it reads the
|
|
|
85
85
|
newest file.
|
|
86
86
|
|
|
87
87
|
<!-- dex-registry:start -->
|
|
88
|
-
Memo of the exchange registry, version
|
|
88
|
+
Memo of the exchange registry, version 6, robinhood, recorded 2026-11-05.
|
|
89
89
|
|
|
90
90
|
| Exchange | Key | Also written | Trail | Factories, or the manager | Router |
|
|
91
91
|
|---|---|---|---|---|---|
|
|
@@ -100,6 +100,7 @@ Memo of the exchange registry, version 4, robinhood, recorded 2026-11-02.
|
|
|
100
100
|
| SwapHood | `swaphood` | SwapHood, SwapHood Finance, SWT, swaphood.finance | gauge | `0xe7206ecac3a51afe7e6179182ad4130a26068dd1` | `0x8f8056fec03159ebcc4aee1b8ea5a61d8fe405fc` |
|
|
101
101
|
| Uniswap v2 | `uniswap-v2` | Uniswap v2, Uni v2 | plain | `0x8bceaa40b9acdfaedf85adf4ff01f5ad6517937f` | none |
|
|
102
102
|
| Uniswap v3 | `uniswap-v3` | Uniswap v3, Uni v3 | plain | `0x1f7d7550b1b028f7571e69a784071f0205fd2efa` | none |
|
|
103
|
+
| unnamed ETH/USDG swap router (routes into Uniswap v3 and v4) | `eth-usdg-router` | ETH/USDG router, ETH/USDG swap router, USDG swap router | plain | `0x1f7d7550b1b028f7571e69a784071f0205fd2efa` | `0x7a39b98d31f84152bc724bc5ddb41dbcb338f2a5` |
|
|
103
104
|
| Uniswap v4 | `uniswap-v4` | Uniswap, UNI, Uniswap v4, Uni v4, PoolManager | vault | manager `0x8366a39cc670b4001a1121b8f6a443a643e40951` | the manager |
|
|
104
105
|
| PancakeSwap Infinity | `pancakeswap` | PancakeSwap, Pancake, CAKE, PancakeSwap Infinity | vault | manager `0xee04c68742e6bf434be8039580d2e89bbe55bc6f` | the manager |
|
|
105
106
|
| PancakeSwap v2 | `pancakeswap-v2` | PancakeSwap v2, Pancake v2 | plain | `0x02a84c1b3bbd7401a5f7fa98a384ebc70bb5749e` | none |
|
|
@@ -123,6 +124,11 @@ Memo of the exchange registry, version 4, robinhood, recorded 2026-11-02.
|
|
|
123
124
|
| unnamed native-ETH bonding-curve launchpad | `eth-curve-launchpad` | native-ETH bonding-curve launchpad, ETH bonding-curve launchpad | launchpad | `0xc4210279fb1e1de24a87d6f5cc597c9422aef899` | none |
|
|
124
125
|
| unnamed single-router bonding-curve launchpad | `single-router-launchpad` | single-router bonding-curve launchpad, single-router launchpad | launchpad | `0x006fee8a9a5482dd7cdf7f21b4d78fa6e246ca4c`, `0x4ed0f046d97d508df86d6b7b058e763dbfb0027f` | `0x4ed0f046d97d508df86d6b7b058e763dbfb0027f` |
|
|
125
126
|
| Virtuals Protocol | `virtuals` | Virtuals, VIRTUAL, Virtuals Protocol | launchpad | `0xfc2e4da3edb2e18100473339c763705d263d20a9` | none |
|
|
127
|
+
| unnamed WETH-unwrap helper of Uniswap sell routes | `weth-unwrap-helper` | WETH-unwrap helper | plain | `0x1f7d7550b1b028f7571e69a784071f0205fd2efa` | `0x0849c295bc609da9fde347834f92a75c2c4eb178` |
|
|
128
|
+
| Realm ETF launchpad | `realm-etf` | Realm, Realm ETF, RealmEtf | launchpad | `0x124ad86c732b16366ed26445e3943adef635f123` | `0x74dd0a05540f7c1ae419c18f8d55ff220076e8c8` |
|
|
129
|
+
| Pangea launch factory | `pangea` | Pangea, Pangea launch | launchpad | `0xadf9c12eaf14da2f7780c0587cc06034f1edf8d3` | none |
|
|
130
|
+
| IceCreamSwap aggregator | `icecreamswap` | IceCreamSwap, IceCream, Ice Cream Swap | plain | `0x1f7d7550b1b028f7571e69a784071f0205fd2efa` | `0x603206d6105217dd972e4ab30676a220ca393346`, `0x2ca37ff95caf25366ef16fc2e655b78a165d125f`, `0xec9aa0a6c2372131a0502aba6188269ab52cacb5`, `0xe6eeda550918638529c6cf2ea14f9ea0572d6f88` |
|
|
131
|
+
| unnamed per-launch Uniswap v4 swap routers | `per-launch-v4-router` | per-launch router, per-launch v4 router | vault | manager `0x8366a39cc670b4001a1121b8f6a443a643e40951` | the manager |
|
|
126
132
|
<!-- dex-registry:end -->
|
|
127
133
|
|
|
128
134
|
## Find the pools of an exchange
|
|
@@ -69,7 +69,7 @@ agent is created on Uniswap's own v2 factory
|
|
|
69
69
|
most of that factory's pairs are Virtuals agents.
|
|
70
70
|
|
|
71
71
|
<!-- dex-registry:start -->
|
|
72
|
-
The factories of the exchange registry, version
|
|
72
|
+
The factories of the exchange registry, version 6, row `virtuals`:
|
|
73
73
|
|
|
74
74
|
| Factory | Address |
|
|
75
75
|
|---|---|
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dex-registry-D6Xxi_vr.mjs","names":[],"sources":["../src/mcp/dex-registry.ts"],"sourcesContent":["/**\n * The exchange registry, as the proxy tool meta_dex_lookup reads it.\n *\n * The reviewed table lives in this repository, registry/<network>.md, and its\n * served copy registry/<network>.json is checked in CI\n * (scripts/pin-dex-registry.mjs). The proxy reads the copy three ways, in this\n * order:\n *\n * cached ~/.chain-insights/cache/dex-registry-<network>.json, younger than one hour\n * fetched the copy on main, https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/<network>.json,\n * within 3 s, at most once an hour per network and never two in flight\n * packaged registry/<network>.json of the installed package, when the fetch fails and no cache exists\n *\n * A fetched file is used only when it passes the same rules the pin script\n * applies. A malformed file never replaces a good cache: the stale cache keeps\n * answering and one line names the fault. So a proxy that never reaches GitHub\n * behaves like the skill memo of its own version, and a row merged on main\n * reaches every running proxy within the hour, with no release.\n *\n * matchDex turns a name into one exchange: normalise, exact on key, display and\n * aliases, then within two letters of an alias of four or more characters. One\n * winner is matched, a tie is listed, never guessed, and no hit names every\n * covered exchange.\n */\n\nimport { existsSync, readFileSync } from 'node:fs'\nimport { mkdir, readFile, rename, writeFile } from 'node:fs/promises'\nimport path from 'node:path'\nimport { fileURLToPath } from 'node:url'\nimport { chainInsightsHome } from './cache-location.js'\n\nexport const DEX_REGISTRY_SCHEMA = 'chain-insights.dex-registry.v1' as const\n/** How long a cached registry stays fresh. CACHE_TTL_MS (24 h) stays the lifetime of the schema caches. */\nexport const DEX_REGISTRY_TTL_MS = 60 * 60 * 1000\n/** The most a fetch of the public file may take on the call path. */\nexport const DEX_REGISTRY_FETCH_BUDGET_MS = 3_000\nexport const DEX_REGISTRY_URL_ENV = 'CHAIN_INSIGHTS_DEX_REGISTRY_URL'\nexport const DEX_REGISTRY_PUBLIC_URL =\n 'https://raw.githubusercontent.com/chainswarm/chain-insights/main/registry/{network}.json'\n\nexport const TRAIL_TYPES = ['plain', 'vault', 'gauge', 'launchpad'] as const\nexport type TrailType = (typeof TRAIL_TYPES)[number]\nexport const ROLES = ['factory', 'manager', 'router'] as const\nexport type Role = (typeof ROLES)[number]\nexport type RegistrySource = 'fetched' | 'cached' | 'packaged'\n\n/** One exchange of the served copy. */\nexport interface DexEntry {\n dex: string\n display: string\n aliases: string[]\n trail_type: TrailType\n adapters: string[]\n roles: Record<string, Role>\n /** Its factory addresses, or the one manager of a vault. */\n factories: string[]\n /** Its routers, or the manager of a vault: a vault forwards its own swaps. */\n routers: string[]\n example_pool: string | null\n pool_floor: number | null\n since_block: number\n source: string\n}\n\nexport interface DexRegistryDocument {\n schema: typeof DEX_REGISTRY_SCHEMA\n network: string\n registry_version: number\n recorded_on: string\n rows: DexEntry[]\n}\n\nexport interface LoadedRegistry {\n document: DexRegistryDocument\n source: RegistrySource\n loaded_at_ms: number\n}\n\n/** A refusal with its own words for the caller: a network the registry does not cover. */\nexport class DexRegistryError extends Error {\n constructor(message: string) {\n super(message)\n this.name = 'DexRegistryError'\n }\n}\n\nconst ADDRESS_RE = /^0x[0-9a-f]{40}$/\n// An example pool is a pool address, or the pool id of a manager that keeps its pools by id.\nconst POOL_RE = /^0x(?:[0-9a-f]{40}|[0-9a-f]{64})$/\nconst DEX_RE = /^[a-z0-9][a-z0-9._-]{0,31}$/\nconst NETWORK_RE = /^[a-z0-9][a-z0-9_-]{0,63}$/\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 network as a lower-case identifier; it becomes part of a file name and a URL. */\nexport function normalizeDexNetwork(raw: unknown): string {\n const network = typeof raw === 'string' ? raw.trim().toLowerCase() : ''\n if (!network) {\n throw new DexRegistryError(\n 'invalid_network: network is required. Pass the identifier of a served network, for example robinhood.'\n )\n }\n if (!NETWORK_RE.test(network)) {\n throw new DexRegistryError(`invalid_network: \"${String(raw)}\" is not a network identifier`)\n }\n return network\n}\n\n/**\n * The fault of a registry document, or null when it is valid for the network:\n * the rules of registry/README.md, the same ones the pin script applies.\n */\nexport function registryFault(value: unknown, network: string): string | null {\n if (!isRecord(value)) return 'the file is not a JSON object'\n if (value.schema !== DEX_REGISTRY_SCHEMA) {\n return `schema is ${JSON.stringify(value.schema)}, not ${DEX_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 keys = new Set<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.dex !== 'string' || !DEX_RE.test(row.dex))\n return `${at}.dex is not a key: ${String(row.dex)}`\n if (keys.has(row.dex)) return `${at}.dex ${row.dex} is listed twice`\n keys.add(row.dex)\n if (typeof row.display !== 'string' || row.display.trim() === '')\n return `${at} (${row.dex}) has no display`\n if (!isStringList(row.aliases)) return `${at} (${row.dex}) aliases is not a list of names`\n if (!TRAIL_TYPES.includes(row.trail_type as TrailType)) {\n return `${at} (${row.dex}) trail_type ${String(row.trail_type)} is not plain, vault, gauge or launchpad`\n }\n if (!isStringList(row.adapters)) return `${at} (${row.dex}) adapters is not a list`\n if (!isRecord(row.roles)) return `${at} (${row.dex}) roles is not a map`\n for (const [address, role] of Object.entries(row.roles)) {\n if (!ADDRESS_RE.test(address))\n return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`\n if (!ROLES.includes(role as Role))\n return `${at} (${row.dex}) role ${String(role)} is not factory, manager or router`\n }\n for (const field of ['factories', 'routers'] as const) {\n const list = row[field]\n if (!isStringList(list)) return `${at} (${row.dex}) ${field} is not a list`\n for (const address of list) {\n if (!ADDRESS_RE.test(address))\n return `${at} (${row.dex}) address ${address} is not lowercase 0x plus 40 hex characters`\n if (!(address in row.roles))\n return `${at} (${row.dex}) ${field} names ${address}, which roles lacks`\n }\n }\n if ((row.factories as string[]).length === 0)\n return `${at} (${row.dex}) has no factory or manager`\n if (\n row.example_pool !== null &&\n (typeof row.example_pool !== 'string' || !POOL_RE.test(row.example_pool))\n ) {\n return `${at} (${row.dex}) example_pool ${String(row.example_pool)} is not a pool`\n }\n if (\n row.pool_floor !== null &&\n (!Number.isInteger(row.pool_floor) || (row.pool_floor as number) < 0)\n ) {\n return `${at} (${row.dex}) pool_floor is not a whole number`\n }\n if (!Number.isInteger(row.since_block) || (row.since_block as number) < 0) {\n return `${at} (${row.dex}) since_block is not a block`\n }\n if (typeof row.source !== 'string' || !row.source.startsWith('https://')) {\n return `${at} (${row.dex}) source is not an https link`\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 dexRegistryUrl(network: string, env: NodeJS.ProcessEnv = process.env): string {\n const override = env[DEX_REGISTRY_URL_ENV]?.trim()\n const template = override || DEX_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 dexRegistryCachePath(network: string): string {\n return path.join(chainInsightsHome(), 'cache', `dex-registry-${network}.json`)\n}\n\n/** The registry/ folder of the installed package: next to dist/, or the repository root when run from source. */\nexport function packagedRegistryDir(): string {\n const candidates = [\n fileURLToPath(new URL('../registry', import.meta.url)),\n fileURLToPath(new URL('../../registry', 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 is a defect: it throws. */\nexport function readPackagedRegistry(\n network: string,\n dir: string = packagedRegistryDir()\n): DexRegistryDocument | 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 = registryFault(parsed, network)\n if (fault)\n throw new Error(\n `the packaged exchange registry registry/${network}.json is malformed: ${fault}`\n )\n return parsed as DexRegistryDocument\n}\n\ninterface CacheFile {\n schema: typeof DEX_REGISTRY_SCHEMA\n network: string\n registry_version: number\n recorded_on: string\n rows: DexEntry[]\n /** When the copy was read: the fetch, or the first start with no fetch. */\n cached_at_ms: number\n /** When a fetch was last tried. The cache is fresh for an hour after it. */\n checked_at_ms: number\n source: 'fetched' | 'packaged'\n}\n\nconst documentOf = (file: CacheFile): DexRegistryDocument => ({\n schema: file.schema,\n network: file.network,\n registry_version: file.registry_version,\n recorded_on: file.recorded_on,\n rows: file.rows,\n})\n\nasync function readCache(network: string): Promise<CacheFile | null> {\n let parsed: unknown\n try {\n parsed = JSON.parse(await readFile(dexRegistryCachePath(network), 'utf8'))\n } catch {\n return null\n }\n if (!isRecord(parsed) || registryFault(parsed, network) !== null) return null\n if (typeof parsed.checked_at_ms !== 'number' || typeof parsed.cached_at_ms !== 'number')\n return null\n if (parsed.source !== 'fetched' && parsed.source !== 'packaged') return null\n return parsed as unknown as CacheFile\n}\n\nasync function writeCache(file: CacheFile): Promise<void> {\n const target = dexRegistryCachePath(file.network)\n await mkdir(path.dirname(target), { recursive: true })\n // Written beside the target and renamed, so a second proxy never reads half of it.\n const scratch = `${target}.${process.pid}.tmp`\n await writeFile(scratch, JSON.stringify(file, null, 2) + '\\n', { mode: 0o600 })\n await rename(scratch, target)\n}\n\nexport interface LoadRegistryOptions {\n fetch?: typeof fetch\n now?: () => number\n env?: NodeJS.ProcessEnv\n /** One line per fault: a failed fetch, a malformed file, a cache that cannot be written. */\n log?: (line: string) => void\n packagedDir?: string\n budgetMs?: number\n}\n\ntype FetchOutcome = { document: DexRegistryDocument } | { fault: string }\n\nasync function fetchRegistry(network: string, options: LoadRegistryOptions): Promise<FetchOutcome> {\n const url = dexRegistryUrl(network, options.env)\n const fetchImpl = options.fetch ?? fetch\n let response: Response\n try {\n response = await fetchImpl(url, {\n signal: AbortSignal.timeout(options.budgetMs ?? DEX_REGISTRY_FETCH_BUDGET_MS),\n })\n } catch (err) {\n return { fault: `${url} unreachable: ${err instanceof Error ? err.message : String(err)}` }\n }\n if (response.status !== 200) return { fault: `${url} answered HTTP ${response.status}` }\n let parsed: unknown\n try {\n parsed = JSON.parse(await response.text())\n } catch {\n return { fault: `${url} is not JSON` }\n }\n const fault = registryFault(parsed, network)\n if (fault) return { fault: `${url} is malformed: ${fault}` }\n return { document: parsed as DexRegistryDocument }\n}\n\n// Fetches in flight, by network: two calls at once share one fetch.\nconst inFlight = new Map<string, Promise<LoadedRegistry>>()\n\nconst defaultLog = (line: string): void => {\n process.stderr.write(`[chain-insights] dex-registry: ${line}\\n`)\n}\n\n/**\n * The registry of one network: the fresh cache, else the public file, else the\n * stale cache, else the packaged copy. A packaged copy with a higher registry\n * version than the cache or the public file wins, so an upgrade is never\n * answered from an older file. Never throws for a network the package covers.\n */\nexport async function loadRegistry(\n rawNetwork: unknown,\n options: LoadRegistryOptions = {}\n): Promise<LoadedRegistry> {\n const network = normalizeDexNetwork(rawNetwork)\n const now = options.now ?? Date.now\n const log = options.log ?? defaultLog\n const packaged = readPackagedRegistry(network, options.packagedDir)\n const newer = (document: DexRegistryDocument): boolean =>\n packaged !== null && packaged.registry_version > document.registry_version\n const fromPackaged = (): LoadedRegistry => ({\n document: packaged!,\n source: 'packaged',\n loaded_at_ms: now(),\n })\n\n const cache = await readCache(network)\n const age = cache ? now() - cache.checked_at_ms : Infinity\n if (cache && age >= 0 && age < DEX_REGISTRY_TTL_MS) {\n if (newer(cache)) return fromPackaged()\n return {\n document: documentOf(cache),\n source: cache.source === 'fetched' ? 'cached' : 'packaged',\n loaded_at_ms: now(),\n }\n }\n\n const running = inFlight.get(network)\n if (running) return running\n const load = (async (): Promise<LoadedRegistry> => {\n const outcome = await fetchRegistry(network, options)\n const checked = now()\n const save = async (file: CacheFile): Promise<void> => {\n try {\n await writeCache(file)\n } catch (err) {\n log(\n `the cache ${dexRegistryCachePath(network)} could not be written: ${err instanceof Error ? err.message : String(err)}`\n )\n }\n }\n if ('document' in outcome) {\n const { document } = outcome\n await save({ ...document, cached_at_ms: checked, checked_at_ms: checked, source: 'fetched' })\n if (newer(document)) return fromPackaged()\n return { document, source: 'fetched', loaded_at_ms: checked }\n }\n log(outcome.fault)\n if (cache) {\n // The stale cache keeps answering, and the next fetch waits an hour.\n await save({ ...cache, checked_at_ms: checked })\n if (newer(cache)) return fromPackaged()\n return {\n document: documentOf(cache),\n source: cache.source === 'fetched' ? 'cached' : 'packaged',\n loaded_at_ms: checked,\n }\n }\n if (!packaged) {\n throw new DexRegistryError(\n `network_not_covered: the exchange registry covers no network \"${network}\", and ${outcome.fault}`\n )\n }\n await save({ ...packaged, cached_at_ms: checked, checked_at_ms: checked, source: 'packaged' })\n return fromPackaged()\n })()\n inFlight.set(network, load)\n try {\n return await load\n } finally {\n inFlight.delete(network)\n }\n}\n\n// ─── The name match ───────────────────────────────────────────────────────────\n\n/** Lower case, with every space, \".\", \"-\" and \"_\" removed: \"Uni v4\" and \"uni-v4\" are \"univ4\". */\nexport function normaliseName(name: string): string {\n return name.toLowerCase().replace(/[\\s.\\-_]+/g, '')\n}\n\n/** The optimal string alignment distance: insertions, deletions, substitutions and swaps of two neighbours. */\nexport function damerauLevenshtein(a: string, b: string): number {\n const rows = a.length + 1\n const cols = b.length + 1\n const d: number[][] = Array.from({ length: rows }, (_, i) =>\n Array.from({ length: cols }, (_, j) => (i === 0 ? j : j === 0 ? i : 0))\n )\n for (let i = 1; i < rows; i += 1) {\n for (let j = 1; j < cols; j += 1) {\n const cost = a[i - 1] === b[j - 1] ? 0 : 1\n let best = Math.min(d[i - 1]![j]! + 1, d[i]![j - 1]! + 1, d[i - 1]![j - 1]! + cost)\n if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) {\n best = Math.min(best, d[i - 2]![j - 2]! + 1)\n }\n d[i]![j] = best\n }\n }\n return d[a.length]![b.length]!\n}\n\n/** The most letters a near hit may differ by, and the shortest alias a near hit is taken from. */\nexport const NEAR_DISTANCE = 2\nexport const NEAR_MIN_ALIAS_LENGTH = 4\n\nexport interface DexCandidate {\n dex: string\n display: string\n distance: number\n}\n\nexport interface DexMatchResult {\n matched: DexEntry | null\n /** The name as typed, when the match is a near hit. */\n took_for?: string\n candidates: DexCandidate[]\n /** Every covered exchange, by display name. */\n covered: string[]\n}\n\n/**\n * One name against the registry rows:\n * one exact hit matched\n * several exact hits candidates at distance 0, matched null\n * no exact hit, one nearest exchange matched, took_for the name\n * no exact hit, a tie at the nearest candidates, matched null\n * nothing within two letters matched null, no candidates\n */\nexport function matchDex(name: string, rows: DexEntry[]): DexMatchResult {\n const covered = rows.map((row) => row.display)\n const wanted = normaliseName(name)\n if (!wanted) return { matched: null, candidates: [], covered }\n const exact = rows.filter((row) =>\n [row.dex, row.display, ...row.aliases].some((written) => normaliseName(written) === wanted)\n )\n if (exact.length === 1) return { matched: exact[0]!, candidates: [], covered }\n if (exact.length > 1) {\n return {\n matched: null,\n candidates: exact.map((row) => ({ dex: row.dex, display: row.display, distance: 0 })),\n covered,\n }\n }\n const near: Array<{ row: DexEntry; distance: number }> = []\n for (const row of rows) {\n const distances = row.aliases\n .map(normaliseName)\n .filter((alias) => alias.length >= NEAR_MIN_ALIAS_LENGTH)\n .map((alias) => damerauLevenshtein(wanted, alias))\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: [], covered }\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: [], covered }\n return {\n matched: null,\n candidates: nearest.map(({ row, distance }) => ({\n dex: row.dex,\n display: row.display,\n distance,\n })),\n covered,\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+BA,MAAa,sBAAsB;;AAEnC,MAAa,sBAAsB;;AAEnC,MAAa,+BAA+B;AAC5C,MAAa,uBAAuB;AACpC,MAAa,0BACX;AAEF,MAAa,cAAc;CAAC;CAAS;CAAS;CAAS;AAAW;AAElE,MAAa,QAAQ;CAAC;CAAW;CAAW;AAAQ;;AAqCpD,I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