chain-insights 0.85.2 → 0.92.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/bin/install.cjs +2 -1
- package/dist/{active-q3yViZhc.cjs → active-COPA14FA.cjs} +2 -16
- package/dist/{active-D2aabYRF.mjs → active-CyC4jFka.mjs} +2 -7
- package/dist/{active-D2aabYRF.mjs.map → active-CyC4jFka.mjs.map} +1 -1
- package/dist/address-card-C-NB03XP.cjs +218 -0
- package/dist/address-card-LYaT5yz0.mjs +190 -0
- package/dist/address-card-LYaT5yz0.mjs.map +1 -0
- package/dist/address-risk-DPuXBsvH.cjs +806 -0
- package/dist/address-risk-Da6FsfGx.mjs +653 -0
- package/dist/address-risk-Da6FsfGx.mjs.map +1 -0
- package/dist/{capabilities-Mxa4oQdd.cjs → capabilities-DkNreyv7.cjs} +1 -1
- package/dist/{capabilities-bZOr5Ads.mjs → capabilities-w5bNR7F9.mjs} +2 -2
- package/dist/{capabilities-bZOr5Ads.mjs.map → capabilities-w5bNR7F9.mjs.map} +1 -1
- package/dist/cli.cjs +138 -46
- package/dist/cli.mjs +138 -46
- package/dist/cli.mjs.map +1 -1
- package/dist/{deployer-screen-B5yrXZGo.mjs → deployer-screen-Bkw_sz94.mjs} +3 -3
- package/dist/{deployer-screen-B5yrXZGo.mjs.map → deployer-screen-Bkw_sz94.mjs.map} +1 -1
- package/dist/{deployer-screen-0SOQ_HFf.cjs → deployer-screen-CFLi7OeH.cjs} +2 -2
- package/dist/{dex-registry-BY67f4Ul.mjs → dex-registry-Bkri0--q.mjs} +10 -2
- package/dist/{dex-registry-BY67f4Ul.mjs.map → dex-registry-Bkri0--q.mjs.map} +1 -1
- package/dist/{dex-registry-BhGJUG9_.cjs → dex-registry-CyR3GyRr.cjs} +20 -0
- package/dist/{dex-tool-7BK_gD6H.mjs → dex-tool-D0K_Qx4N.mjs} +4 -4
- package/dist/dex-tool-D0K_Qx4N.mjs.map +1 -0
- package/dist/{dex-tool-Be9NAuD8.cjs → dex-tool-DQ5Eg0LO.cjs} +3 -3
- package/dist/{exchange-deposit-check-C5MseGlZ.cjs → exchange-deposit-check-BNzkwQeW.cjs} +18 -18
- package/dist/{exchange-deposit-check-CXHZCHWW.mjs → exchange-deposit-check-DIALj2sm.mjs} +19 -19
- package/dist/exchange-deposit-check-DIALj2sm.mjs.map +1 -0
- package/dist/{exchange-registry-CT0rRW__.cjs → exchange-registry-CEgkeQV1.cjs} +16 -93
- package/dist/{exchange-registry-CoLgHw6d.mjs → exchange-registry-Dr5UtcT5.mjs} +17 -94
- package/dist/exchange-registry-Dr5UtcT5.mjs.map +1 -0
- package/dist/{exchange-tool-Dc46SJ49.mjs → exchange-tool-B7E29YoQ.mjs} +4 -4
- package/dist/exchange-tool-B7E29YoQ.mjs.map +1 -0
- package/dist/{exchange-tool-B2SMeC5f.cjs → exchange-tool-CXaUBAd2.cjs} +3 -3
- package/dist/{graph-schema-CcrYPpSv.cjs → graph-schema-Bn3txQCj.cjs} +115 -12
- package/dist/{graph-schema-CRQuKya1.mjs → graph-schema-DvABR1yl.mjs} +97 -12
- package/dist/graph-schema-DvABR1yl.mjs.map +1 -0
- package/dist/{layer-routing-YDj-ynG9.cjs → layer-routing-j48SQ8Wk.cjs} +2 -2
- package/dist/{layer-routing-DCJVNN6O.mjs → layer-routing-r4IbIQSr.mjs} +3 -3
- package/dist/layer-routing-r4IbIQSr.mjs.map +1 -0
- package/dist/mcp-proxy.cjs +62 -15
- package/dist/mcp-proxy.d.cts.map +1 -1
- package/dist/mcp-proxy.d.mts.map +1 -1
- package/dist/mcp-proxy.mjs +62 -15
- package/dist/mcp-proxy.mjs.map +1 -1
- package/dist/public-file-BISyAesm.mjs +133 -0
- package/dist/public-file-BISyAesm.mjs.map +1 -0
- package/dist/public-file-DDp2CrUl.cjs +138 -0
- package/dist/{request-timeout-DxwNijQD.cjs → request-timeout-BXiIt9Jy.cjs} +0 -1
- package/dist/{request-timeout-K3ljP0pa.mjs → request-timeout-DetG2xO4.mjs} +2 -2
- package/dist/{request-timeout-K3ljP0pa.mjs.map → request-timeout-DetG2xO4.mjs.map} +1 -1
- package/dist/{token-lookup-Cf59VdGe.mjs → token-lookup-Ck0q7crJ.mjs} +2 -2
- package/dist/{token-lookup-Cf59VdGe.mjs.map → token-lookup-Ck0q7crJ.mjs.map} +1 -1
- package/dist/{token-lookup-DqjSRIxd.cjs → token-lookup-DLe4erP9.cjs} +1 -1
- package/dist/token-risk-CpMfFRoY.cjs +1004 -0
- package/dist/token-risk-DhnJc2kJ.mjs +971 -0
- package/dist/token-risk-DhnJc2kJ.mjs.map +1 -0
- package/dist/{tool-visibility-D8Up081E.cjs → tool-visibility-BCa-tmyZ.cjs} +11 -2
- package/dist/{tool-visibility-DuTds7V4.mjs → tool-visibility-BstrSl4s.mjs} +12 -3
- package/dist/tool-visibility-BstrSl4s.mjs.map +1 -0
- package/docs/contributing.md +10 -8
- package/docs/development.md +5 -5
- package/docs/evals.md +16 -1
- package/docs/graph-query-compatibility.md +15 -2
- package/docs/graph-tools.md +44 -6
- package/docs/mcp-proxy.md +189 -8
- package/docs/stability.md +4 -5
- package/docs/testing.md +76 -0
- package/package.json +1 -1
- package/registry/README.md +20 -5
- package/registry/address-card.json +680 -0
- package/skills/chain-insights-address-risk/SKILL.md +61 -0
- package/skills/chain-insights-address-risk/agents/openai.yaml +4 -0
- package/skills/chain-insights-aml-exchange/SKILL.md +9 -7
- package/skills/chain-insights-cypher/SKILL.md +79 -3
- package/skills/chain-insights-token-risk/SKILL.md +81 -0
- package/skills/chain-insights-token-risk/agents/openai.yaml +4 -0
- package/skills/chain-insights-virtuals/reference.md +1 -1
- package/dist/dex-tool-7BK_gD6H.mjs.map +0 -1
- package/dist/exchange-deposit-check-CXHZCHWW.mjs.map +0 -1
- package/dist/exchange-registry-CoLgHw6d.mjs.map +0 -1
- package/dist/exchange-tool-Dc46SJ49.mjs.map +0 -1
- package/dist/graph-schema-CRQuKya1.mjs.map +0 -1
- package/dist/layer-routing-DCJVNN6O.mjs.map +0 -1
- package/dist/public-tools-CBszU2oX.cjs +0 -1334
- package/dist/public-tools-DVhUjSDV.mjs +0 -1333
- package/dist/public-tools-DVhUjSDV.mjs.map +0 -1
- package/dist/tool-visibility-DuTds7V4.mjs.map +0 -1
|
@@ -0,0 +1,971 @@
|
|
|
1
|
+
import { t as __exportAll } from "./rolldown-runtime-BJohB4LM.mjs";
|
|
2
|
+
import { C as textOrNull, E as splitCardEntry, S as strings, T as riskWordRank, _ as isRecord, b as memberRows, c as addressPartnerQuery, d as assertReadAddress, g as addressOrNull, h as rowRisk, l as addressRiskFromMembers, m as kindOf, o as SURROUNDINGS_NODE_LIMIT, p as hubDegreeOf, s as addressNodeQuery, t as ADDRESS_INPUT, v as memberAnswered, w as utcOrNull, x as numberOrNull, y as memberRefusal } from "./address-risk-Da6FsfGx.mjs";
|
|
3
|
+
import { c as dexOfAddress, p as normalizeDexNetwork, r as DexRegistryError, s as dexManagerOf } from "./dex-registry-Bkri0--q.mjs";
|
|
4
|
+
import { c as refusalOf, s as membersOf } from "./token-lookup-Ck0q7crJ.mjs";
|
|
5
|
+
// src/mcp/pool-risk.ts
|
|
6
|
+
/** The rows a providers read lists at most; a full read means a pool's parties may miss someone. */
|
|
7
|
+
const PROVIDERS_READ_LIMIT = 200;
|
|
8
|
+
/** The pools a grouped pools read lists at most; a full read means more pools exist. */
|
|
9
|
+
const POOLS_READ_LIMIT = 500;
|
|
10
|
+
/** The pools detailed (node read, adders and removers), the biggest by tokens added first. */
|
|
11
|
+
const POOLS_DETAILED = 10;
|
|
12
|
+
/** The adders and the removers kept per pool. */
|
|
13
|
+
const POOL_PARTY_LIMIT = 5;
|
|
14
|
+
/** The first accounts that paid the founder, oldest first. */
|
|
15
|
+
const GAS_WALLET_LIMIT = 3;
|
|
16
|
+
/** The liquidity sums on a pool node with its own address. */
|
|
17
|
+
const POOL_NODE_COLUMNS = [
|
|
18
|
+
"a.liquidity_added_usd AS liquidity_added_usd",
|
|
19
|
+
"a.liquidity_removed_usd AS liquidity_removed_usd",
|
|
20
|
+
"a.liquidity_net_usd AS liquidity_net_usd",
|
|
21
|
+
"a.provider_count AS provider_count"
|
|
22
|
+
];
|
|
23
|
+
/** The card and model fields of a party read, on the node `v`. */
|
|
24
|
+
function partyColumns(v) {
|
|
25
|
+
return `labels(${v}) AS node_labels, ${v}.identity AS identity, ${v}.identity_name AS identity_name, ${v}.identities AS identities, ${v}.evidence AS evidence, ${v}.judgements AS judgements, ${v}.risk_level AS risk_level, ${v}.risk_score AS risk_score`;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The providers of a token on one side, by pool: liquidity added into a pool,
|
|
29
|
+
* or taken off one. One row per pool and provider, the biggest first; a full
|
|
30
|
+
* read (PROVIDERS_READ_LIMIT rows) means more may exist. `priced` counts the
|
|
31
|
+
* links that carry a price.
|
|
32
|
+
*/
|
|
33
|
+
function tokenProvidersQuery(token, side) {
|
|
34
|
+
assertReadAddress(token);
|
|
35
|
+
return `USE topology MATCH ${side === "added" ? `(a:Address)-[r:ADDED_LIQUIDITY {asset: "${token}"}]->(p:Address)` : `(p:Address)-[r:REMOVED_LIQUIDITY {asset: "${token}"}]->(a:Address)`} RETURN p.address AS pool, a.address AS address, sum(r.usd) AS tokens_worth_usd, count(r.usd) AS priced, sum(r.event_count) AS events, min(r.first_seen_height) AS first_seen_height, max(r.last_seen_height) AS last_seen_height, ${partyColumns("a")} ORDER BY tokens_worth_usd DESC LIMIT ${PROVIDERS_READ_LIMIT}`;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The pools of a token on one side, one row per pool address: its distinct
|
|
39
|
+
* providers (or removers), this token's USD sum, its priced links and its
|
|
40
|
+
* events. Grouped by the graph, so it counts every pool and every provider up
|
|
41
|
+
* to POOLS_READ_LIMIT pools, where the providers read stops at 200 rows.
|
|
42
|
+
*/
|
|
43
|
+
function tokenPoolsQuery(token, side) {
|
|
44
|
+
assertReadAddress(token);
|
|
45
|
+
const [match, parties] = side === "added" ? [`(a:Address)-[r:ADDED_LIQUIDITY {asset: "${token}"}]->(p:Address)`, "providers"] : [`(p:Address)-[r:REMOVED_LIQUIDITY {asset: "${token}"}]->(a:Address)`, "removers"];
|
|
46
|
+
return `USE topology MATCH ${match} RETURN p.address AS pool, count(DISTINCT a) AS ${parties}, sum(r.usd) AS ${side}_usd, count(r.usd) AS priced, sum(r.event_count) AS events ORDER BY ${side}_usd DESC LIMIT ${POOLS_READ_LIMIT}`;
|
|
47
|
+
}
|
|
48
|
+
/** The biggest adders or removers of one pool address. */
|
|
49
|
+
function poolPartiesQuery(pool, side) {
|
|
50
|
+
assertReadAddress(pool);
|
|
51
|
+
const anchor = `(p:Address {address: "${pool}"})`;
|
|
52
|
+
return `USE topology MATCH ${side === "adders" ? `(a:Address)-[r:ADDED_LIQUIDITY]->${anchor}` : `${anchor}-[r:REMOVED_LIQUIDITY]->(a:Address)`} RETURN a.address AS address, sum(r.usd) AS tokens_worth_usd, count(r.usd) AS priced, sum(r.event_count) AS events, min(r.first_seen_height) AS first_seen_height, max(r.last_seen_height) AS last_seen_height, ${partyColumns("a")} ORDER BY tokens_worth_usd DESC LIMIT ${POOL_PARTY_LIMIT}`;
|
|
53
|
+
}
|
|
54
|
+
/** The assets added into one pool: its tokens, and NATIVE for the chain's own coin. */
|
|
55
|
+
function poolAssetsQuery(pool) {
|
|
56
|
+
assertReadAddress(pool);
|
|
57
|
+
return `USE topology MATCH (a:Address)-[r:ADDED_LIQUIDITY]->(p:Address {address: "${pool}"}) RETURN collect(DISTINCT r.asset) AS assets LIMIT 1`;
|
|
58
|
+
}
|
|
59
|
+
/** The contract deployment of one address: who deployed it, from which wallet, by which factory. */
|
|
60
|
+
function deploymentQuery(address) {
|
|
61
|
+
assertReadAddress(address);
|
|
62
|
+
return `USE topology MATCH (d:Address)-[r:DEPLOYED_CONTRACT]->(t:Address {address: "${address}"}) RETURN d.address AS deployer, r.tx_origin AS tx_origin, r.factory_address AS factory_address, r.kind AS kind, r.tx_id AS tx_id, r.block_timestamp AS block_timestamp LIMIT 1`;
|
|
63
|
+
}
|
|
64
|
+
/** The first accounts that paid one wallet, oldest first, with no money floor: a first funder is small on purpose. */
|
|
65
|
+
function gasWalletsQuery(founder) {
|
|
66
|
+
assertReadAddress(founder);
|
|
67
|
+
return `USE topology MATCH (s:Account)-[f:FLOWED_TO]->(a:Address {address: "${founder}"}) RETURN s.address AS address, f.amount_usd_sum AS tokens_worth_usd, f.first_seen_timestamp AS first_seen_timestamp, ${partyColumns("s")} ORDER BY f.first_seen_timestamp ASC LIMIT ${GAS_WALLET_LIMIT}`;
|
|
68
|
+
}
|
|
69
|
+
/** A time in epoch milliseconds, or in seconds, as UTC text; null for anything else. */
|
|
70
|
+
function timeText(value) {
|
|
71
|
+
const number = numberOrNull(value);
|
|
72
|
+
if (number === null) return null;
|
|
73
|
+
return utcOrNull(number) ?? utcOrNull(number * 1e3);
|
|
74
|
+
}
|
|
75
|
+
/** A USD sum of a read, or null when no link of it carried a price. */
|
|
76
|
+
function usdOf(row, column) {
|
|
77
|
+
const sum = numberOrNull(row?.[column]);
|
|
78
|
+
const priced = numberOrNull(row?.priced);
|
|
79
|
+
if (priced !== null && priced <= 0) return null;
|
|
80
|
+
return sum;
|
|
81
|
+
}
|
|
82
|
+
/** The party of one row: its risk block by the address rule, its kind and its identity. */
|
|
83
|
+
function partyOf(role, address, row, dictionary, extra = {}) {
|
|
84
|
+
const word = textOrNull(row?.identity);
|
|
85
|
+
return {
|
|
86
|
+
role,
|
|
87
|
+
address,
|
|
88
|
+
..."tokens_worth_usd" in extra ? { tokens_worth_usd: extra.tokens_worth_usd ?? null } : {},
|
|
89
|
+
risk: {
|
|
90
|
+
...rowRisk(row, dictionary),
|
|
91
|
+
card_version: textOrNull(row?.card_version)
|
|
92
|
+
},
|
|
93
|
+
kind: kindOf(strings(row?.node_labels)),
|
|
94
|
+
identity: word ? {
|
|
95
|
+
word,
|
|
96
|
+
name: textOrNull(row?.identity_name)
|
|
97
|
+
} : null,
|
|
98
|
+
..."first_seen_utc" in extra ? { first_seen_utc: extra.first_seen_utc ?? null } : {},
|
|
99
|
+
..."events" in extra ? { events: extra.events ?? null } : {},
|
|
100
|
+
..."first_seen_height" in extra ? { first_seen_height: extra.first_seen_height ?? null } : {},
|
|
101
|
+
..."last_seen_height" in extra ? { last_seen_height: extra.last_seen_height ?? null } : {}
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/** The adders or removers of one pool read, as parties. */
|
|
105
|
+
function poolPartiesOf(role, rows, dictionary) {
|
|
106
|
+
const parties = [];
|
|
107
|
+
for (const row of rows.slice(0, POOL_PARTY_LIMIT)) {
|
|
108
|
+
const address = addressOrNull(row.address);
|
|
109
|
+
if (!address) continue;
|
|
110
|
+
parties.push(partyOf(role, address, row, dictionary, {
|
|
111
|
+
tokens_worth_usd: usdOf(row, "tokens_worth_usd"),
|
|
112
|
+
events: numberOrNull(row.events),
|
|
113
|
+
first_seen_height: numberOrNull(row.first_seen_height),
|
|
114
|
+
last_seen_height: numberOrNull(row.last_seen_height)
|
|
115
|
+
}));
|
|
116
|
+
}
|
|
117
|
+
return parties;
|
|
118
|
+
}
|
|
119
|
+
/** The sum of the priced rows' USD, or null when no row carried a price. */
|
|
120
|
+
function pricedSum(rows) {
|
|
121
|
+
let sum = null;
|
|
122
|
+
for (const row of rows) {
|
|
123
|
+
const usd = usdOf(row, "tokens_worth_usd");
|
|
124
|
+
if (usd !== null) sum = (sum ?? 0) + usd;
|
|
125
|
+
}
|
|
126
|
+
return sum;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* The pool addresses of a token from its two providers reads, the biggest by
|
|
130
|
+
* this token added first. A removed sum is 0 for a pool with no removal row
|
|
131
|
+
* in a removals read that answered with fewer than PROVIDERS_READ_LIMIT rows
|
|
132
|
+
* (nothing removed). It is null when the read did not answer (`removed` is
|
|
133
|
+
* null), when it came back full (more rows may exist), or when the pool's
|
|
134
|
+
* removal rows carry no price.
|
|
135
|
+
*/
|
|
136
|
+
function poolListingsOf(added, removed) {
|
|
137
|
+
const byPool = /* @__PURE__ */ new Map();
|
|
138
|
+
const entry = (pool) => {
|
|
139
|
+
const known = byPool.get(pool) ?? {
|
|
140
|
+
adders: [],
|
|
141
|
+
removers: []
|
|
142
|
+
};
|
|
143
|
+
byPool.set(pool, known);
|
|
144
|
+
return known;
|
|
145
|
+
};
|
|
146
|
+
for (const row of added) {
|
|
147
|
+
const pool = addressOrNull(row.pool);
|
|
148
|
+
if (pool && addressOrNull(row.address)) entry(pool).adders.push(row);
|
|
149
|
+
}
|
|
150
|
+
for (const row of removed ?? []) {
|
|
151
|
+
const pool = addressOrNull(row.pool);
|
|
152
|
+
if (pool && addressOrNull(row.address)) entry(pool).removers.push(row);
|
|
153
|
+
}
|
|
154
|
+
const listings = [...byPool].map(([pool, rows]) => ({
|
|
155
|
+
pool,
|
|
156
|
+
providers: new Set(rows.adders.map((row) => addressOrNull(row.address))).size,
|
|
157
|
+
added_usd: pricedSum(rows.adders),
|
|
158
|
+
removed_usd: removed === null ? null : rows.removers.length === 0 && removed.length < PROVIDERS_READ_LIMIT ? 0 : pricedSum(rows.removers),
|
|
159
|
+
adder_rows: rows.adders,
|
|
160
|
+
remover_rows: rows.removers
|
|
161
|
+
}));
|
|
162
|
+
const rank = (value) => value === null ? -1 : value;
|
|
163
|
+
return listings.sort((a, b) => rank(b.added_usd) - rank(a.added_usd) || a.pool.localeCompare(b.pool));
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* The pool addresses of a token from its two grouped pools reads: providers
|
|
167
|
+
* and this token's side come from the groups, the parties of each pool from
|
|
168
|
+
* the providers rows. `removedGroups` is null when the grouped removals read
|
|
169
|
+
* did not answer: every removed sum is then null. A pool with no removal group
|
|
170
|
+
* in a grouped read under POOLS_READ_LIMIT rows removed nothing (0); a group
|
|
171
|
+
* whose links carry no price is null. `addedRows` and `removedRows` are null
|
|
172
|
+
* when that providers read did not answer: the pool then has no parties.
|
|
173
|
+
*/
|
|
174
|
+
function poolListingsFromGroups(addedGroups, removedGroups, addedRows, removedRows) {
|
|
175
|
+
const removedBy = /* @__PURE__ */ new Map();
|
|
176
|
+
for (const row of removedGroups ?? []) {
|
|
177
|
+
const pool = addressOrNull(row.pool);
|
|
178
|
+
if (pool) removedBy.set(pool, row);
|
|
179
|
+
}
|
|
180
|
+
const rowsBy = (rows) => {
|
|
181
|
+
const by = /* @__PURE__ */ new Map();
|
|
182
|
+
for (const row of rows ?? []) {
|
|
183
|
+
const pool = addressOrNull(row.pool);
|
|
184
|
+
if (!pool || !addressOrNull(row.address)) continue;
|
|
185
|
+
by.set(pool, [...by.get(pool) ?? [], row]);
|
|
186
|
+
}
|
|
187
|
+
return by;
|
|
188
|
+
};
|
|
189
|
+
const adderRows = rowsBy(addedRows);
|
|
190
|
+
const removerRows = rowsBy(removedRows);
|
|
191
|
+
const removedFull = (removedGroups?.length ?? 0) >= POOLS_READ_LIMIT;
|
|
192
|
+
const listings = [];
|
|
193
|
+
const seen = /* @__PURE__ */ new Set();
|
|
194
|
+
const push = (pool, added) => {
|
|
195
|
+
if (seen.has(pool)) return;
|
|
196
|
+
seen.add(pool);
|
|
197
|
+
const removed = removedBy.get(pool);
|
|
198
|
+
listings.push({
|
|
199
|
+
pool,
|
|
200
|
+
providers: numberOrNull(added?.providers) ?? 0,
|
|
201
|
+
added_usd: added ? usdOf(added, "added_usd") : null,
|
|
202
|
+
removed_usd: removedGroups === null ? null : removed ? usdOf(removed, "removed_usd") : removedFull ? null : 0,
|
|
203
|
+
adder_rows: adderRows.get(pool) ?? [],
|
|
204
|
+
remover_rows: removerRows.get(pool) ?? []
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
for (const row of addedGroups) {
|
|
208
|
+
const pool = addressOrNull(row.pool);
|
|
209
|
+
if (pool) push(pool, row);
|
|
210
|
+
}
|
|
211
|
+
for (const pool of removedBy.keys()) push(pool, null);
|
|
212
|
+
const rank = (value) => value === null ? -1 : value;
|
|
213
|
+
return listings.sort((a, b) => rank(b.added_usd) - rank(a.added_usd) || a.pool.localeCompare(b.pool));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* The facts of one pool address. A pool with its own address takes both sides
|
|
217
|
+
* of its liquidity and its word from its node; a manager takes neither (its
|
|
218
|
+
* node is its whole book) and shows this token's side only.
|
|
219
|
+
*/
|
|
220
|
+
function poolFactsOf(input) {
|
|
221
|
+
const { node } = input;
|
|
222
|
+
const own = !input.isManager && node !== null;
|
|
223
|
+
let liquidity = null;
|
|
224
|
+
if (own) {
|
|
225
|
+
const added = numberOrNull(node.liquidity_added_usd);
|
|
226
|
+
const removed = numberOrNull(node.liquidity_removed_usd);
|
|
227
|
+
liquidity = {
|
|
228
|
+
added_usd: added,
|
|
229
|
+
removed_usd: removed,
|
|
230
|
+
net_usd: numberOrNull(node.liquidity_net_usd) ?? (added !== null && removed !== null ? added - removed : null)
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
return {
|
|
234
|
+
pool: input.pool,
|
|
235
|
+
exchange: input.exchange,
|
|
236
|
+
is_manager: input.isManager,
|
|
237
|
+
...input.isManager ? { pools_inside: null } : {},
|
|
238
|
+
detail: input.detail,
|
|
239
|
+
providers: input.providers,
|
|
240
|
+
token_side: input.tokenSide,
|
|
241
|
+
liquidity,
|
|
242
|
+
risk: own ? {
|
|
243
|
+
...rowRisk(node, input.dictionary),
|
|
244
|
+
card_version: textOrNull(node.card_version)
|
|
245
|
+
} : null,
|
|
246
|
+
adders: input.adders,
|
|
247
|
+
removers: input.removers
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
// src/mcp/token-risk.ts
|
|
251
|
+
var token_risk_exports = /* @__PURE__ */ __exportAll({
|
|
252
|
+
AML_TOKEN_RISK_DESCRIPTION: () => AML_TOKEN_RISK_DESCRIPTION,
|
|
253
|
+
AML_TOKEN_RISK_TITLE: () => AML_TOKEN_RISK_TITLE,
|
|
254
|
+
AML_TOKEN_RISK_TOOL: () => AML_TOKEN_RISK_TOOL,
|
|
255
|
+
handleAmlTokenRisk: () => handleAmlTokenRisk
|
|
256
|
+
});
|
|
257
|
+
const AML_TOKEN_RISK_TOOL = "aml_token_risk";
|
|
258
|
+
const AML_TOKEN_RISK_SCHEMA = "chain-insights.aml-token-risk.v1";
|
|
259
|
+
const AML_TOKEN_RISK_TITLE = "Token risk";
|
|
260
|
+
const AML_TOKEN_RISK_DESCRIPTION = `Answers what is known about one token contract or one pool: the token and how it was deployed, its founder (the wallet that sent the deployment, with its own risk answer and money partners), the factory or launchpad that deployed it (such as Virtuals; factory.name comes from the exchange registry, or from the token launchpad identity, and named_by says which), the first accounts that paid the founder (gas wallets), and its pools with their liquidity, their 5 biggest adders and removers. A wallet is no token: ask aml_address_risk about a wallet. A ticker is no address: call meta_token_lookup first. risk.word is the highest of the token own word, its founder word and each detailed pool own word, and raised_by says whose (raised_by_address names it); risk.own is the token own risk block. A factory or launchpad, a first funder and a liquidity provider never raise the word: each carries its own beside it. Every word is the higher of what labels prove and what the risk model predicts; unscored is not low and not safe. A pool row is one address: the pools inside one pool manager (such as Uniswap v4) are answered as one row for the manager (is_manager true), with its providers and this token side, not pool by pool; a manager row carries no word and never raises it, and a manager asked about itself lists no adders, removers or tokens (pool_tokens is empty): its parties and its tokens are answered per token, so ask the token. pools_found counts every pool address of the token (up to 500); only the 10 biggest are detailed (detail true), pools_truncated says when more exist; providers and token_side count every provider of a pool; parties_truncated says the 5 biggest adders and removers of a pool may miss a party. A part listed in not_read was not read: it is never "none found". The tool states facts and measures; you write the judgement: say which reasons and whose word you rely on, say when a word comes from the model alone (set_by model) that it is a prediction, never call a token or a pool safe, and name a part listed in not_read as not read, never as none found. USD figures are tokens worth at day prices; null is unpriced, never 0. Write every address in full, all 42 characters. A hub (more than 50,000 links, such as the zero address or a pool manager) has its counterparties not ranked: exposure.hub is true and not_read names counterparties; ask about one counterparty, or one token, instead. Pass surroundings: true for the nodes and links behind the answer, to draw.`;
|
|
261
|
+
const AML_TOKEN_RISK_ANNOTATIONS = {
|
|
262
|
+
readOnlyHint: true,
|
|
263
|
+
idempotentHint: true,
|
|
264
|
+
openWorldHint: false
|
|
265
|
+
};
|
|
266
|
+
/** A token's node read adds its facts and, for a pool, its sums. */
|
|
267
|
+
const SUBJECT_COLUMNS = [
|
|
268
|
+
"a.token_standard AS token_standard",
|
|
269
|
+
"a.contract_creation_timestamp AS contract_creation_timestamp",
|
|
270
|
+
...POOL_NODE_COLUMNS
|
|
271
|
+
];
|
|
272
|
+
/**
|
|
273
|
+
* The exchange registry key of a token's launchpad identity: the first part
|
|
274
|
+
* of a `launchpad` card value (`virtuals:CIA:graduated` gives `virtuals`),
|
|
275
|
+
* from its identity or any entry of its identities. Null when it has none.
|
|
276
|
+
*/
|
|
277
|
+
function launchpadKeyOf(row) {
|
|
278
|
+
const values = [];
|
|
279
|
+
if (textOrNull(row?.identity) === "launchpad") {
|
|
280
|
+
const name = textOrNull(row?.identity_name);
|
|
281
|
+
if (name) values.push(name);
|
|
282
|
+
}
|
|
283
|
+
for (const entry of strings(row?.identities)) {
|
|
284
|
+
const { word, value } = splitCardEntry(entry);
|
|
285
|
+
if (word === "launchpad" && value) values.push(value);
|
|
286
|
+
}
|
|
287
|
+
for (const value of values) {
|
|
288
|
+
const key = value.split(":")[0]?.trim().toLowerCase();
|
|
289
|
+
if (key) return key;
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* The name of a token's factory: its exchange registry row by address; else,
|
|
295
|
+
* a token factory with no row of its own (it creates tokens, not pools), the
|
|
296
|
+
* registry's name for the token's launchpad identity; else none.
|
|
297
|
+
*/
|
|
298
|
+
function factoryNameOf(factory, tokenRow, dexRows) {
|
|
299
|
+
const row = dexOfAddress(factory, dexRows);
|
|
300
|
+
if (row) return {
|
|
301
|
+
name: row.display,
|
|
302
|
+
named_by: "registry"
|
|
303
|
+
};
|
|
304
|
+
const key = launchpadKeyOf(tokenRow);
|
|
305
|
+
const launchpad = key ? dexRows.find((entry) => entry.dex === key) : void 0;
|
|
306
|
+
if (launchpad) return {
|
|
307
|
+
name: launchpad.display,
|
|
308
|
+
named_by: "launchpad"
|
|
309
|
+
};
|
|
310
|
+
return {
|
|
311
|
+
name: null,
|
|
312
|
+
named_by: null
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
/** What the node labels make of the subject: a launchpad pair carries Token and Pool, and Pool wins. */
|
|
316
|
+
function askedAsOf(nodeLabels) {
|
|
317
|
+
if (nodeLabels.includes("Pool")) return "pool";
|
|
318
|
+
if (nodeLabels.includes("Token")) return "token";
|
|
319
|
+
return "address";
|
|
320
|
+
}
|
|
321
|
+
function deploymentOf(row) {
|
|
322
|
+
if (!row) return null;
|
|
323
|
+
const deployer = addressOrNull(row.deployer);
|
|
324
|
+
const founder = addressOrNull(row.tx_origin) ?? deployer;
|
|
325
|
+
const kind = textOrNull(row.kind);
|
|
326
|
+
const factoryAddress = addressOrNull(row.factory_address);
|
|
327
|
+
return {
|
|
328
|
+
deployer,
|
|
329
|
+
factory_address: factoryAddress,
|
|
330
|
+
founder,
|
|
331
|
+
factory: kind?.toLowerCase() === "factory" && factoryAddress !== null && factoryAddress !== founder ? factoryAddress : null,
|
|
332
|
+
tx_id: textOrNull(row.tx_id),
|
|
333
|
+
kind,
|
|
334
|
+
created_utc: timeText(row.block_timestamp)
|
|
335
|
+
};
|
|
336
|
+
}
|
|
337
|
+
function raisedWordOf(own, candidates) {
|
|
338
|
+
let best = null;
|
|
339
|
+
for (const candidate of candidates) {
|
|
340
|
+
if (candidate.risk.word === "unscored") continue;
|
|
341
|
+
if (!best || riskWordRank(candidate.risk.word) > riskWordRank(best.risk.word)) best = candidate;
|
|
342
|
+
}
|
|
343
|
+
return {
|
|
344
|
+
word: best?.risk.word ?? "unscored",
|
|
345
|
+
set_by: best?.risk.set_by ?? "none",
|
|
346
|
+
score: own.score,
|
|
347
|
+
raised_by: best?.by ?? null,
|
|
348
|
+
raised_by_address: best?.address ?? null,
|
|
349
|
+
own
|
|
350
|
+
};
|
|
351
|
+
}
|
|
352
|
+
/** Sends one batch; a call that throws or holds no reads answers every read as not read, with why. */
|
|
353
|
+
async function sendBatch(deps, network, queries) {
|
|
354
|
+
let answer;
|
|
355
|
+
try {
|
|
356
|
+
answer = await deps.graphQueryBatch({
|
|
357
|
+
network,
|
|
358
|
+
queries
|
|
359
|
+
});
|
|
360
|
+
} catch (err) {
|
|
361
|
+
return failedMembers(queries, deps.describeFailure(err));
|
|
362
|
+
}
|
|
363
|
+
const members = membersOf(answer);
|
|
364
|
+
if (members.size > 0) return members;
|
|
365
|
+
return failedMembers(queries, answer.isError === true ? refusalOf(answer).text : "the batch answer held no reads");
|
|
366
|
+
}
|
|
367
|
+
function failedMembers(queries, error) {
|
|
368
|
+
return new Map(queries.map(({ id }) => [id, {
|
|
369
|
+
id,
|
|
370
|
+
ok: false,
|
|
371
|
+
error
|
|
372
|
+
}]));
|
|
373
|
+
}
|
|
374
|
+
const poolId = (index, part) => `pool${index}_${part}`;
|
|
375
|
+
function errorResult(text) {
|
|
376
|
+
return {
|
|
377
|
+
content: [{
|
|
378
|
+
type: "text",
|
|
379
|
+
text
|
|
380
|
+
}],
|
|
381
|
+
isError: true
|
|
382
|
+
};
|
|
383
|
+
}
|
|
384
|
+
function textResult(structured) {
|
|
385
|
+
return {
|
|
386
|
+
content: [{
|
|
387
|
+
type: "text",
|
|
388
|
+
text: JSON.stringify(structured, null, 2)
|
|
389
|
+
}],
|
|
390
|
+
structuredContent: structured,
|
|
391
|
+
isError: false
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
/** The answer's not-read entry of one member, or null when it answered. */
|
|
395
|
+
function notReadOf(part, id, members, pool) {
|
|
396
|
+
const member = members.get(id);
|
|
397
|
+
if (memberAnswered(member)) return null;
|
|
398
|
+
return {
|
|
399
|
+
part,
|
|
400
|
+
...memberRefusal(id, member),
|
|
401
|
+
...pool ? { pool } : {}
|
|
402
|
+
};
|
|
403
|
+
}
|
|
404
|
+
/** The founder party from its full address answer. */
|
|
405
|
+
function founderOf(address, answer) {
|
|
406
|
+
return {
|
|
407
|
+
role: "founder",
|
|
408
|
+
address,
|
|
409
|
+
risk: answer.risk,
|
|
410
|
+
kind: answer.kind,
|
|
411
|
+
identity: answer.identity,
|
|
412
|
+
exposure: answer.exposure,
|
|
413
|
+
exchange_ends: answer.exchange_ends
|
|
414
|
+
};
|
|
415
|
+
}
|
|
416
|
+
/** aml_token_risk, {network, address, surroundings?}. Every argument is checked before a read is sent. */
|
|
417
|
+
async function handleAmlTokenRisk(args, deps) {
|
|
418
|
+
const record = isRecord(args) ? args : {};
|
|
419
|
+
let network;
|
|
420
|
+
try {
|
|
421
|
+
network = normalizeDexNetwork(record.network);
|
|
422
|
+
} catch (err) {
|
|
423
|
+
return errorResult(err instanceof DexRegistryError ? err.message : `invalid_network: ${err.message}`);
|
|
424
|
+
}
|
|
425
|
+
const raw = typeof record.address === "string" ? record.address.trim() : "";
|
|
426
|
+
if (!ADDRESS_INPUT.test(raw)) return errorResult("invalid_address: address is required: the token contract or the pool, 0x plus 40 hex characters. A ticker or a name is not an address: call meta_token_lookup first.");
|
|
427
|
+
if (record.surroundings !== void 0 && typeof record.surroundings !== "boolean") return errorResult("invalid_surroundings: surroundings is true or false.");
|
|
428
|
+
const address = raw.toLowerCase();
|
|
429
|
+
const drawing = record.surroundings === true;
|
|
430
|
+
const unavailable = await deps.unavailable?.();
|
|
431
|
+
if (unavailable) return errorResult(`No token risk read was sent: ${unavailable} There is no answer yet, which is not "no risk": try again later.`);
|
|
432
|
+
let dictionary;
|
|
433
|
+
try {
|
|
434
|
+
const card = await deps.loadAddressCard();
|
|
435
|
+
if (!card) throw new Error("no copy of the address card dictionary is available");
|
|
436
|
+
dictionary = card.document.words;
|
|
437
|
+
} catch (err) {
|
|
438
|
+
return errorResult(`No token risk read was sent: the address card dictionary did not load (${err.message}). There is no answer yet, which is not "no risk".`);
|
|
439
|
+
}
|
|
440
|
+
let exchangeRows = [];
|
|
441
|
+
try {
|
|
442
|
+
exchangeRows = (await deps.loadExchangeRegistry(network)).document.rows;
|
|
443
|
+
} catch {}
|
|
444
|
+
let dexRows = [];
|
|
445
|
+
try {
|
|
446
|
+
dexRows = (await deps.loadDexRegistry(network)).document.rows;
|
|
447
|
+
} catch {}
|
|
448
|
+
let answer;
|
|
449
|
+
try {
|
|
450
|
+
answer = await deps.graphQueryBatch({
|
|
451
|
+
network,
|
|
452
|
+
queries: [{
|
|
453
|
+
id: "node",
|
|
454
|
+
query: addressNodeQuery(address, SUBJECT_COLUMNS)
|
|
455
|
+
}]
|
|
456
|
+
});
|
|
457
|
+
} catch (err) {
|
|
458
|
+
return errorResult(`The token risk read failed: ${deps.describeFailure(err)} This is not "no risk": send the same call again once.`);
|
|
459
|
+
}
|
|
460
|
+
const members1 = membersOf(answer);
|
|
461
|
+
if (members1.size === 0) return errorResult(`The token risk read failed: ${answer.isError === true ? refusalOf(answer).text : "the batch answer held no reads"} This is not "no risk".`);
|
|
462
|
+
const nodeMember = members1.get("node");
|
|
463
|
+
if (!memberAnswered(nodeMember)) return errorResult(`The token risk read failed: ${memberRefusal("node", nodeMember).reason} This is not "no risk": send the same call again once.`);
|
|
464
|
+
const nodeRow = memberRows(nodeMember)[0];
|
|
465
|
+
const isManager = dexManagerOf(address, dexRows) !== null;
|
|
466
|
+
const askedAs = !nodeRow ? "address" : isManager ? "pool" : askedAsOf(strings(nodeRow.node_labels));
|
|
467
|
+
if (askedAs !== "address") {
|
|
468
|
+
const rest = [
|
|
469
|
+
...hubDegreeOf(nodeRow) !== null ? [] : [{
|
|
470
|
+
id: "in",
|
|
471
|
+
query: addressPartnerQuery(address, "in")
|
|
472
|
+
}, {
|
|
473
|
+
id: "out",
|
|
474
|
+
query: addressPartnerQuery(address, "out")
|
|
475
|
+
}],
|
|
476
|
+
{
|
|
477
|
+
id: "deployment",
|
|
478
|
+
query: deploymentQuery(address)
|
|
479
|
+
},
|
|
480
|
+
...isManager ? [] : [
|
|
481
|
+
{
|
|
482
|
+
id: "adders",
|
|
483
|
+
query: poolPartiesQuery(address, "adders")
|
|
484
|
+
},
|
|
485
|
+
{
|
|
486
|
+
id: "removers",
|
|
487
|
+
query: poolPartiesQuery(address, "removers")
|
|
488
|
+
},
|
|
489
|
+
{
|
|
490
|
+
id: "assets",
|
|
491
|
+
query: poolAssetsQuery(address)
|
|
492
|
+
}
|
|
493
|
+
]
|
|
494
|
+
];
|
|
495
|
+
for (const [id, member] of await sendBatch(deps, network, rest)) members1.set(id, member);
|
|
496
|
+
}
|
|
497
|
+
const subjectBuilt = addressRiskFromMembers(network, address, members1, dictionary, exchangeRows, "", {
|
|
498
|
+
surroundings: drawing,
|
|
499
|
+
hubGuard: true
|
|
500
|
+
});
|
|
501
|
+
if ("failure" in subjectBuilt) return errorResult(`The token risk read failed: ${subjectBuilt.failure} This is not "no risk": send the same call again once.`);
|
|
502
|
+
const subject = subjectBuilt.result;
|
|
503
|
+
const notRead = subject.not_read.map((entry) => ({ ...entry }));
|
|
504
|
+
const base = {
|
|
505
|
+
schema: AML_TOKEN_RISK_SCHEMA,
|
|
506
|
+
tool: AML_TOKEN_RISK_TOOL,
|
|
507
|
+
network,
|
|
508
|
+
address,
|
|
509
|
+
asked_as: askedAs,
|
|
510
|
+
found: subject.found,
|
|
511
|
+
token: null,
|
|
512
|
+
risk: {
|
|
513
|
+
...raisedWordOf(subject.risk, []),
|
|
514
|
+
word: subject.risk.word,
|
|
515
|
+
set_by: subject.risk.set_by
|
|
516
|
+
},
|
|
517
|
+
model: subject.model,
|
|
518
|
+
founder: null,
|
|
519
|
+
factory: null,
|
|
520
|
+
deployment: null,
|
|
521
|
+
gas_wallets: [],
|
|
522
|
+
pools: [],
|
|
523
|
+
pools_found: null,
|
|
524
|
+
pools_truncated: false,
|
|
525
|
+
parties_truncated: false,
|
|
526
|
+
pool_tokens: [],
|
|
527
|
+
deployer: null,
|
|
528
|
+
exposure: null,
|
|
529
|
+
exchange_ends: [],
|
|
530
|
+
not_read: []
|
|
531
|
+
};
|
|
532
|
+
if (askedAs === "address") return textResult(base);
|
|
533
|
+
const deployment = deploymentOf(memberRows(members1.get("deployment"))[0]);
|
|
534
|
+
const deploymentMissing = notReadOf("deployment", "deployment", members1);
|
|
535
|
+
if (deploymentMissing) notRead.push(deploymentMissing);
|
|
536
|
+
const result = {
|
|
537
|
+
...base,
|
|
538
|
+
exposure: subject.exposure,
|
|
539
|
+
exchange_ends: subject.exchange_ends,
|
|
540
|
+
deployment: deployment ? {
|
|
541
|
+
tx_id: deployment.tx_id,
|
|
542
|
+
created_utc: deployment.created_utc,
|
|
543
|
+
kind: deployment.kind
|
|
544
|
+
} : null
|
|
545
|
+
};
|
|
546
|
+
const graph = new SurroundingsBuilder(drawing ? subject : null);
|
|
547
|
+
if (askedAs === "pool") await answerPool({
|
|
548
|
+
deps,
|
|
549
|
+
network,
|
|
550
|
+
address,
|
|
551
|
+
members1,
|
|
552
|
+
dictionary,
|
|
553
|
+
dexRows,
|
|
554
|
+
deployment,
|
|
555
|
+
notRead,
|
|
556
|
+
result,
|
|
557
|
+
graph,
|
|
558
|
+
subject
|
|
559
|
+
});
|
|
560
|
+
else await answerToken({
|
|
561
|
+
deps,
|
|
562
|
+
network,
|
|
563
|
+
address,
|
|
564
|
+
dictionary,
|
|
565
|
+
exchangeRows,
|
|
566
|
+
dexRows,
|
|
567
|
+
deployment,
|
|
568
|
+
notRead,
|
|
569
|
+
result,
|
|
570
|
+
graph,
|
|
571
|
+
subject,
|
|
572
|
+
nodeRow
|
|
573
|
+
});
|
|
574
|
+
result.not_read = notRead;
|
|
575
|
+
if (drawing) result.surroundings = graph.build();
|
|
576
|
+
return textResult(result);
|
|
577
|
+
}
|
|
578
|
+
/** The exchange of a pool address: the manager's exchange, else its deployer's or factory's, else null. */
|
|
579
|
+
function exchangeOf(pool, deployment, dexRows) {
|
|
580
|
+
const by = [
|
|
581
|
+
pool,
|
|
582
|
+
deployment?.deployer ?? null,
|
|
583
|
+
deployment?.factory_address ?? null
|
|
584
|
+
];
|
|
585
|
+
const manager = dexManagerOf(pool, dexRows);
|
|
586
|
+
if (manager) return manager.display;
|
|
587
|
+
for (const address of by) {
|
|
588
|
+
if (address === null) continue;
|
|
589
|
+
const row = dexOfAddress(address, dexRows);
|
|
590
|
+
if (row) return row.display;
|
|
591
|
+
}
|
|
592
|
+
return null;
|
|
593
|
+
}
|
|
594
|
+
/** A pool: its own word, its sums and parties from batch 1, its tokens and deployer from batch 2. */
|
|
595
|
+
async function answerPool(step) {
|
|
596
|
+
const { deps, network, address, members1, dictionary, dexRows, deployment, notRead, result, graph, subject } = step;
|
|
597
|
+
const isManager = dexManagerOf(address, dexRows) !== null;
|
|
598
|
+
const adders = isManager ? [] : poolPartiesOf("adder", memberRows(members1.get("adders")), dictionary);
|
|
599
|
+
const removers = isManager ? [] : poolPartiesOf("remover", memberRows(members1.get("removers")), dictionary);
|
|
600
|
+
const parts = [...isManager ? [] : [
|
|
601
|
+
["adders", "adders"],
|
|
602
|
+
["removers", "removers"],
|
|
603
|
+
["tokens", "assets"]
|
|
604
|
+
]];
|
|
605
|
+
for (const [part, id] of parts) {
|
|
606
|
+
const missing = notReadOf(part, id, members1);
|
|
607
|
+
if (missing) notRead.push(missing);
|
|
608
|
+
}
|
|
609
|
+
const nodeRow = memberRows(members1.get("node"))[0] ?? null;
|
|
610
|
+
const facts = poolFactsOf({
|
|
611
|
+
pool: address,
|
|
612
|
+
exchange: exchangeOf(address, deployment, dexRows),
|
|
613
|
+
isManager,
|
|
614
|
+
detail: true,
|
|
615
|
+
providers: numberOrNull(nodeRow?.provider_count),
|
|
616
|
+
tokenSide: null,
|
|
617
|
+
node: nodeRow,
|
|
618
|
+
adders,
|
|
619
|
+
removers,
|
|
620
|
+
dictionary
|
|
621
|
+
});
|
|
622
|
+
result.pools = [facts];
|
|
623
|
+
result.pools_found = 1;
|
|
624
|
+
result.risk = isManager ? {
|
|
625
|
+
...raisedWordOf(subject.risk, []),
|
|
626
|
+
word: subject.risk.word,
|
|
627
|
+
set_by: subject.risk.set_by
|
|
628
|
+
} : raisedWordOf(subject.risk, [{
|
|
629
|
+
by: "pool",
|
|
630
|
+
address,
|
|
631
|
+
risk: subject.risk
|
|
632
|
+
}]);
|
|
633
|
+
const tokens = strings(memberRows(members1.get("assets"))[0]?.assets).map((asset) => addressOrNull(asset)).filter((asset) => asset !== null && asset !== address).slice(0, 2);
|
|
634
|
+
const deployerAddress = deployment?.founder ?? null;
|
|
635
|
+
const second = [...tokens.map((token, index) => ({
|
|
636
|
+
id: `token${index}_node`,
|
|
637
|
+
query: addressNodeQuery(token)
|
|
638
|
+
})), ...deployerAddress ? [{
|
|
639
|
+
id: "deployer_node",
|
|
640
|
+
query: addressNodeQuery(deployerAddress)
|
|
641
|
+
}] : []];
|
|
642
|
+
if (second.length > 0) {
|
|
643
|
+
const members2 = await sendBatch(deps, network, second);
|
|
644
|
+
tokens.forEach((token, index) => {
|
|
645
|
+
const id = `token${index}_node`;
|
|
646
|
+
const missing = notReadOf("token", id, members2);
|
|
647
|
+
if (missing) notRead.push(missing);
|
|
648
|
+
else result.pool_tokens.push(partyOf("token", token, memberRows(members2.get(id))[0], dictionary));
|
|
649
|
+
});
|
|
650
|
+
if (deployerAddress) {
|
|
651
|
+
const missing = notReadOf("deployer", "deployer_node", members2);
|
|
652
|
+
if (missing) notRead.push(missing);
|
|
653
|
+
else result.deployer = partyOf("deployer", deployerAddress, memberRows(members2.get("deployer_node"))[0], dictionary);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
if (result.deployer && deployment?.deployer) graph.deployed(deployment.deployer, address, deployment.created_utc);
|
|
657
|
+
if (result.deployer) graph.party(result.deployer, "deployer");
|
|
658
|
+
graph.pool(facts);
|
|
659
|
+
}
|
|
660
|
+
/** A token: its pools, founder, factory and gas wallets in batch 2; the biggest pools in batches 3 and 4. */
|
|
661
|
+
async function answerToken(step) {
|
|
662
|
+
const { deps, network, address, dictionary, exchangeRows, dexRows, deployment, notRead, result, graph, subject, nodeRow } = step;
|
|
663
|
+
result.token = {
|
|
664
|
+
address,
|
|
665
|
+
standard: textOrNull(nodeRow.token_standard),
|
|
666
|
+
created_utc: timeText(nodeRow.contract_creation_timestamp) ?? deployment?.created_utc ?? null,
|
|
667
|
+
identity: subject.identity
|
|
668
|
+
};
|
|
669
|
+
const founder = deployment?.founder ?? null;
|
|
670
|
+
const factory = deployment?.factory ?? null;
|
|
671
|
+
const members2 = await sendBatch(deps, network, [
|
|
672
|
+
{
|
|
673
|
+
id: "pools_added",
|
|
674
|
+
query: tokenPoolsQuery(address, "added")
|
|
675
|
+
},
|
|
676
|
+
{
|
|
677
|
+
id: "pools_removed",
|
|
678
|
+
query: tokenPoolsQuery(address, "removed")
|
|
679
|
+
},
|
|
680
|
+
{
|
|
681
|
+
id: "providers_added",
|
|
682
|
+
query: tokenProvidersQuery(address, "added")
|
|
683
|
+
},
|
|
684
|
+
{
|
|
685
|
+
id: "providers_removed",
|
|
686
|
+
query: tokenProvidersQuery(address, "removed")
|
|
687
|
+
},
|
|
688
|
+
...founder ? [
|
|
689
|
+
{
|
|
690
|
+
id: "founder_node",
|
|
691
|
+
query: addressNodeQuery(founder)
|
|
692
|
+
},
|
|
693
|
+
{
|
|
694
|
+
id: "founder_in",
|
|
695
|
+
query: addressPartnerQuery(founder, "in")
|
|
696
|
+
},
|
|
697
|
+
{
|
|
698
|
+
id: "founder_out",
|
|
699
|
+
query: addressPartnerQuery(founder, "out")
|
|
700
|
+
},
|
|
701
|
+
{
|
|
702
|
+
id: "gas_wallets",
|
|
703
|
+
query: gasWalletsQuery(founder)
|
|
704
|
+
}
|
|
705
|
+
] : [],
|
|
706
|
+
...factory ? [{
|
|
707
|
+
id: "factory_node",
|
|
708
|
+
query: addressNodeQuery(factory)
|
|
709
|
+
}] : []
|
|
710
|
+
]);
|
|
711
|
+
if (founder) {
|
|
712
|
+
const built = addressRiskFromMembers(network, founder, members2, dictionary, exchangeRows, "founder_");
|
|
713
|
+
if ("failure" in built) notRead.push({
|
|
714
|
+
part: "founder",
|
|
715
|
+
...memberRefusal("founder_node", members2.get("founder_node"))
|
|
716
|
+
});
|
|
717
|
+
else {
|
|
718
|
+
result.founder = founderOf(founder, built.result);
|
|
719
|
+
for (const entry of built.result.not_read) notRead.push({
|
|
720
|
+
...entry,
|
|
721
|
+
part: entry.part === "senders" ? "founder_senders" : "founder_receivers"
|
|
722
|
+
});
|
|
723
|
+
}
|
|
724
|
+
const gasMissing = notReadOf("gas_wallets", "gas_wallets", members2);
|
|
725
|
+
if (gasMissing) notRead.push(gasMissing);
|
|
726
|
+
for (const row of memberRows(members2.get("gas_wallets"))) {
|
|
727
|
+
const wallet = addressOrNull(row.address);
|
|
728
|
+
if (!wallet) continue;
|
|
729
|
+
result.gas_wallets.push(partyOf("gas_wallet", wallet, row, dictionary, {
|
|
730
|
+
tokens_worth_usd: numberOrNull(row.tokens_worth_usd),
|
|
731
|
+
first_seen_utc: utcOrNull(row.first_seen_timestamp)
|
|
732
|
+
}));
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
if (factory) {
|
|
736
|
+
const missing = notReadOf("factory", "factory_node", members2);
|
|
737
|
+
if (missing) notRead.push(missing);
|
|
738
|
+
else result.factory = {
|
|
739
|
+
...partyOf("factory", factory, memberRows(members2.get("factory_node"))[0], dictionary),
|
|
740
|
+
...factoryNameOf(factory, nodeRow, dexRows)
|
|
741
|
+
};
|
|
742
|
+
}
|
|
743
|
+
const partiesNotRead = (id) => notReadOf("pool_parties", id, members2);
|
|
744
|
+
const rowsOf = (id) => partiesNotRead(id) ? null : memberRows(members2.get(id));
|
|
745
|
+
const addedRows = rowsOf("providers_added");
|
|
746
|
+
const removedRows = rowsOf("providers_removed");
|
|
747
|
+
for (const id of ["providers_added", "providers_removed"]) {
|
|
748
|
+
const missing = partiesNotRead(id);
|
|
749
|
+
if (missing) notRead.push(missing);
|
|
750
|
+
}
|
|
751
|
+
for (const rows of [addedRows, removedRows]) if (rows && rows.length >= PROVIDERS_READ_LIMIT && !result.parties_truncated) {
|
|
752
|
+
result.parties_truncated = true;
|
|
753
|
+
notRead.push({
|
|
754
|
+
part: "pool_parties",
|
|
755
|
+
code: "truncated",
|
|
756
|
+
reason: `a providers read came back full at ${PROVIDERS_READ_LIMIT} rows: the 5 biggest adders or removers of a pool may miss a party`
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
const groupsMissing = notReadOf("pools", "pools_added", members2);
|
|
760
|
+
let listings = [];
|
|
761
|
+
if (!groupsMissing) {
|
|
762
|
+
const removedMissing = notReadOf("pool_removals", "pools_removed", members2);
|
|
763
|
+
if (removedMissing) notRead.push(removedMissing);
|
|
764
|
+
const groups = memberRows(members2.get("pools_added"));
|
|
765
|
+
const removedGroups = removedMissing ? null : memberRows(members2.get("pools_removed"));
|
|
766
|
+
listings = poolListingsFromGroups(groups, removedGroups, addedRows, removedRows);
|
|
767
|
+
result.pools_found = listings.length;
|
|
768
|
+
if (groups.length >= POOLS_READ_LIMIT) notRead.push({
|
|
769
|
+
part: "pools",
|
|
770
|
+
code: "truncated",
|
|
771
|
+
reason: `the pools read came back full at ${POOLS_READ_LIMIT} pools: more pools exist`
|
|
772
|
+
});
|
|
773
|
+
if (removedGroups && removedGroups.length >= POOLS_READ_LIMIT) notRead.push({
|
|
774
|
+
part: "pool_removals",
|
|
775
|
+
code: "truncated",
|
|
776
|
+
reason: `the removals read came back full at ${POOLS_READ_LIMIT} pools: a pool not listed has its removed sum unknown`
|
|
777
|
+
});
|
|
778
|
+
result.pools_truncated = groups.length >= POOLS_READ_LIMIT || listings.length > POOLS_DETAILED;
|
|
779
|
+
} else {
|
|
780
|
+
notRead.push(groupsMissing);
|
|
781
|
+
if (addedRows) {
|
|
782
|
+
listings = poolListingsOf(addedRows, removedRows);
|
|
783
|
+
result.pools_found = listings.length;
|
|
784
|
+
result.pools_truncated = listings.length > POOLS_DETAILED || result.parties_truncated;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const managerOf = (pool) => dexManagerOf(pool, dexRows);
|
|
788
|
+
const detailed = listings.slice(0, POOLS_DETAILED);
|
|
789
|
+
const poolQueries = [];
|
|
790
|
+
detailed.forEach((listing, index) => {
|
|
791
|
+
if (managerOf(listing.pool)) return;
|
|
792
|
+
poolQueries.push({
|
|
793
|
+
id: poolId(index, "node"),
|
|
794
|
+
query: addressNodeQuery(listing.pool, POOL_NODE_COLUMNS)
|
|
795
|
+
});
|
|
796
|
+
poolQueries.push({
|
|
797
|
+
id: poolId(index, "deployment"),
|
|
798
|
+
query: deploymentQuery(listing.pool)
|
|
799
|
+
});
|
|
800
|
+
});
|
|
801
|
+
const poolMembers = poolQueries.length > 0 ? await sendBatch(deps, network, poolQueries) : /* @__PURE__ */ new Map();
|
|
802
|
+
const candidates = [{
|
|
803
|
+
by: "token",
|
|
804
|
+
address,
|
|
805
|
+
risk: subject.risk
|
|
806
|
+
}, ...result.founder ? [{
|
|
807
|
+
by: "founder",
|
|
808
|
+
address: result.founder.address,
|
|
809
|
+
risk: result.founder.risk
|
|
810
|
+
}] : []];
|
|
811
|
+
listings.forEach((listing, index) => {
|
|
812
|
+
const manager = managerOf(listing.pool);
|
|
813
|
+
const detail = index < POOLS_DETAILED;
|
|
814
|
+
let node = null;
|
|
815
|
+
let poolDeployment = null;
|
|
816
|
+
if (detail && !manager) {
|
|
817
|
+
const missing = notReadOf("pool", poolId(index, "node"), poolMembers, listing.pool);
|
|
818
|
+
if (missing) notRead.push(missing);
|
|
819
|
+
node = memberRows(poolMembers.get(poolId(index, "node")))[0] ?? null;
|
|
820
|
+
poolDeployment = deploymentOf(memberRows(poolMembers.get(poolId(index, "deployment")))[0]);
|
|
821
|
+
}
|
|
822
|
+
const facts = poolFactsOf({
|
|
823
|
+
pool: listing.pool,
|
|
824
|
+
exchange: manager ? manager.display : exchangeOf(listing.pool, poolDeployment, dexRows),
|
|
825
|
+
isManager: manager !== null,
|
|
826
|
+
detail,
|
|
827
|
+
providers: listing.providers,
|
|
828
|
+
tokenSide: {
|
|
829
|
+
added_usd: listing.added_usd,
|
|
830
|
+
removed_usd: listing.removed_usd
|
|
831
|
+
},
|
|
832
|
+
node,
|
|
833
|
+
adders: detail ? poolPartiesOf("adder", listing.adder_rows, dictionary) : [],
|
|
834
|
+
removers: detail ? poolPartiesOf("remover", listing.remover_rows, dictionary) : [],
|
|
835
|
+
dictionary
|
|
836
|
+
});
|
|
837
|
+
result.pools.push(facts);
|
|
838
|
+
if (facts.risk) candidates.push({
|
|
839
|
+
by: "pool",
|
|
840
|
+
address: facts.pool,
|
|
841
|
+
risk: facts.risk
|
|
842
|
+
});
|
|
843
|
+
});
|
|
844
|
+
result.risk = raisedWordOf(subject.risk, candidates);
|
|
845
|
+
if (result.founder) graph.party(result.founder, "founder");
|
|
846
|
+
if (result.factory) graph.party(result.factory, "factory");
|
|
847
|
+
if (deployment?.deployer) graph.deployed(deployment.deployer, address, deployment.created_utc);
|
|
848
|
+
for (const wallet of result.gas_wallets) {
|
|
849
|
+
graph.party(wallet, "gas_wallet");
|
|
850
|
+
if (result.founder) graph.link({
|
|
851
|
+
from_address: wallet.address,
|
|
852
|
+
to_address: result.founder.address,
|
|
853
|
+
link: "FLOWED_TO",
|
|
854
|
+
tokens_worth_usd: wallet.tokens_worth_usd ?? null,
|
|
855
|
+
first_seen_utc: wallet.first_seen_utc ?? null,
|
|
856
|
+
last_seen_utc: null
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
for (const facts of result.pools.filter((pool) => pool.detail)) graph.pool(facts);
|
|
860
|
+
}
|
|
861
|
+
const ROLE_ORDER = [
|
|
862
|
+
"subject",
|
|
863
|
+
"founder",
|
|
864
|
+
"factory",
|
|
865
|
+
"deployer",
|
|
866
|
+
"gas_wallet",
|
|
867
|
+
"pool",
|
|
868
|
+
"adder",
|
|
869
|
+
"remover",
|
|
870
|
+
"exchange_end",
|
|
871
|
+
"partner"
|
|
872
|
+
];
|
|
873
|
+
/**
|
|
874
|
+
* The nodes and links behind a token or pool answer, from the reads already
|
|
875
|
+
* made. At most 60 nodes: partners are dropped first, then removers, then
|
|
876
|
+
* adders. A link joins two listed nodes only.
|
|
877
|
+
*/
|
|
878
|
+
var SurroundingsBuilder = class {
|
|
879
|
+
nodes = /* @__PURE__ */ new Map();
|
|
880
|
+
links = [];
|
|
881
|
+
truncatedBefore;
|
|
882
|
+
constructor(subject) {
|
|
883
|
+
this.truncatedBefore = subject?.surroundings?.truncated ?? false;
|
|
884
|
+
for (const node of subject?.surroundings?.nodes ?? []) this.nodes.set(node.address, { ...node });
|
|
885
|
+
for (const link of subject?.surroundings?.links ?? []) this.links.push({ ...link });
|
|
886
|
+
}
|
|
887
|
+
add(node) {
|
|
888
|
+
const known = this.nodes.get(node.address);
|
|
889
|
+
if (!known || ROLE_ORDER.indexOf(node.role) < ROLE_ORDER.indexOf(known.role)) this.nodes.set(node.address, node);
|
|
890
|
+
}
|
|
891
|
+
party(party, role) {
|
|
892
|
+
this.add({
|
|
893
|
+
address: party.address,
|
|
894
|
+
role,
|
|
895
|
+
kind: party.kind,
|
|
896
|
+
name: party.name ?? party.identity?.name ?? null,
|
|
897
|
+
risk_word: party.risk.word,
|
|
898
|
+
model_level: party.risk.model_word
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
link(link) {
|
|
902
|
+
this.links.push(link);
|
|
903
|
+
}
|
|
904
|
+
deployed(deployer, contract, createdUtc) {
|
|
905
|
+
this.links.push({
|
|
906
|
+
from_address: deployer,
|
|
907
|
+
to_address: contract,
|
|
908
|
+
link: "DEPLOYED_CONTRACT",
|
|
909
|
+
tokens_worth_usd: null,
|
|
910
|
+
first_seen_utc: createdUtc,
|
|
911
|
+
last_seen_utc: null
|
|
912
|
+
});
|
|
913
|
+
}
|
|
914
|
+
pool(facts) {
|
|
915
|
+
const kind = facts.is_manager ? "contract" : "pool";
|
|
916
|
+
this.add({
|
|
917
|
+
address: facts.pool,
|
|
918
|
+
role: "pool",
|
|
919
|
+
kind,
|
|
920
|
+
name: facts.exchange,
|
|
921
|
+
risk_word: facts.risk?.word ?? "unscored",
|
|
922
|
+
model_level: facts.risk?.model_word ?? "not_scored"
|
|
923
|
+
});
|
|
924
|
+
for (const adder of facts.adders) {
|
|
925
|
+
this.party(adder, "adder");
|
|
926
|
+
this.links.push({
|
|
927
|
+
from_address: adder.address,
|
|
928
|
+
to_address: facts.pool,
|
|
929
|
+
link: "ADDED_LIQUIDITY",
|
|
930
|
+
tokens_worth_usd: adder.tokens_worth_usd ?? null,
|
|
931
|
+
first_seen_utc: null,
|
|
932
|
+
last_seen_utc: null
|
|
933
|
+
});
|
|
934
|
+
}
|
|
935
|
+
for (const remover of facts.removers) {
|
|
936
|
+
this.party(remover, "remover");
|
|
937
|
+
this.links.push({
|
|
938
|
+
from_address: facts.pool,
|
|
939
|
+
to_address: remover.address,
|
|
940
|
+
link: "REMOVED_LIQUIDITY",
|
|
941
|
+
tokens_worth_usd: remover.tokens_worth_usd ?? null,
|
|
942
|
+
first_seen_utc: null,
|
|
943
|
+
last_seen_utc: null
|
|
944
|
+
});
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
build() {
|
|
948
|
+
const all = [...this.nodes.values()];
|
|
949
|
+
const rank = (node) => ROLE_ORDER.indexOf(node.role);
|
|
950
|
+
const kept = [...all].map((node, at) => ({
|
|
951
|
+
node,
|
|
952
|
+
at
|
|
953
|
+
})).sort((a, b) => rank(a.node) - rank(b.node) || a.at - b.at).slice(0, SURROUNDINGS_NODE_LIMIT).sort((a, b) => a.at - b.at).map(({ node }) => node);
|
|
954
|
+
const listed = new Set(kept.map((node) => node.address));
|
|
955
|
+
const seen = /* @__PURE__ */ new Set();
|
|
956
|
+
return {
|
|
957
|
+
nodes: kept,
|
|
958
|
+
links: this.links.filter((link) => {
|
|
959
|
+
if (!listed.has(link.from_address) || !listed.has(link.to_address)) return false;
|
|
960
|
+
const key = `${link.link}|${link.from_address}|${link.to_address}`;
|
|
961
|
+
if (seen.has(key)) return false;
|
|
962
|
+
seen.add(key);
|
|
963
|
+
return true;
|
|
964
|
+
}),
|
|
965
|
+
truncated: this.truncatedBefore || kept.length < all.length
|
|
966
|
+
};
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
export { handleAmlTokenRisk as a, AML_TOKEN_RISK_TOOL as i, AML_TOKEN_RISK_DESCRIPTION as n, token_risk_exports as o, AML_TOKEN_RISK_TITLE as r, AML_TOKEN_RISK_ANNOTATIONS as t };
|
|
970
|
+
|
|
971
|
+
//# sourceMappingURL=token-risk-DhnJc2kJ.mjs.map
|