solana-risk-engine 0.5.1 → 0.5.2

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/src/risk.js CHANGED
@@ -1,338 +1,339 @@
1
- import { EXT_POINTS, RANKS, PUMP_CURVE_DEXES, CL_POOL_LABELS, ISSUERS, OFFICIAL_TOKENS, FAMOUS } from "./constants.js";
2
- import { isCancel } from "./errors.js";
3
- import { short, sleep } from "./util.js";
4
- import { getMint, getAuthKinds, getConc } from "./tokens.js";
5
- import { impostorOf, brandOf, copiesOf, fakeLiquidity } from "./markets.js";
6
- import { rugcheckSummary, creatorLaunches } from "./rugcheck.js";
7
- import { chainLaunches } from "./launch.js";
8
-
9
- // Every finding is a "signal": {code, s, data}. `s` is ok | na | warn | bad, `data` holds the numbers
10
- // behind it. Turning signals into sentences is i18n's job (describe / explainLight), never the engine's.
11
- function sig(code, s, data) {
12
- const o = { code: code, s: s };
13
- if (data) o.data = data;
14
- return o;
15
- }
16
-
17
- const DAY = 86400000;
18
- // Other tokens launched by the same creator in the last 24 h that make it a serial launcher
19
- export const SERIAL_WARN = 2, SERIAL_BAD = 5;
20
- // Creator track record: at least HISTORY_MIN older tokens and this share of them never took off. Red needs
21
- // 95%: 86% of all new tokens never reach $10k (149-token sample, 28/10), so one launch that took off out of
22
- // ten is already better than chance and must not raise the verdict
23
- export const HISTORY_MIN = 3, HISTORY_WARN = 0.8, HISTORY_BAD_MIN = 10, HISTORY_BAD = 0.95;
24
-
25
- /* ---------- old point score: only for tokens without a market, to spot spam ---------- */
26
- export function score(info) {
27
- let pts = 0;
28
- const why = [];
29
- if (!info) return { pts: 30, why: [sig("NO_INFO", "warn")] };
30
- const ak = info.authKind || {};
31
- if (info.mintAuth) {
32
- if (ak[info.mintAuth] === "program") { pts += 10; why.push(sig("MINT_BY_PROGRAM", "warn")); }
33
- else { pts += 25; why.push(sig("MINT_ACTIVE", "bad", { byWallet: ak[info.mintAuth] === "wallet" })); }
34
- }
35
- if (info.freezeAuth) {
36
- if (ak[info.freezeAuth] === "program") { pts += 8; why.push(sig("FREEZE_BY_PROGRAM", "warn")); }
37
- else { pts += 20; why.push(sig("FREEZE_ACTIVE", "warn", { byWallet: ak[info.freezeAuth] === "wallet" })); }
38
- }
39
- info.ext.forEach(function (e) { if (EXT_POINTS[e]) { pts += EXT_POINTS[e]; why.push(sig("EXTENSION", "warn", { ext: e })); } });
40
- why.push(sig("NO_MARKET", "na"));
41
- return { pts: pts, why: why };
42
- }
43
-
44
- /* ---------- token type ---------- */
45
- export function tokenType(info, pair, now) {
46
- if (!info) return null;
47
- now = now || Date.now();
48
- const ak = info.authKind || {};
49
- const sym = ((pair && pair.baseToken && pair.baseToken.symbol) || "") + " " + ((pair && pair.baseToken && pair.baseToken.name) || "");
50
- const price = Number((pair && pair.priceUsd) || 0);
51
- const liq = (pair && pair.liquidity && pair.liquidity.usd) || 0;
52
- const ageDays = (pair && pair.pairCreatedAt) ? (now - pair.pairCreatedAt) / DAY : 0;
53
- // Being called "USD something" is not enough to be judged more leniently than a normal token:
54
- // it needs a stable price, real liquidity and some time trading (otherwise a scammer only has to
55
- // name the token "USDX" and keep the price near $1 for a while)
56
- if (/USD|DOLLAR/i.test(sym) && price > 0.97 && price < 1.03 && liq >= 200000 && ageDays >= 30) return "STABLE";
57
- // a verified issuer's dollar or euro token is a stablecoin whatever pair DexScreener found (USDC showed
58
- // "bridged" because its pair as base token is recent)
59
- if (/USD|DOLLAR|EUR/i.test(sym) && issuerOf(info, pair && pair.baseToken && pair.baseToken.address)) return "STABLE";
60
- if (info.ext.indexOf("permanentDelegate") >= 0) return "TOKENIZED";
61
- const walletAuth = (info.mintAuth && ak[info.mintAuth] !== "program") || (info.freezeAuth && ak[info.freezeAuth] !== "program");
62
- if (walletAuth) return "CREATOR";
63
- if (info.mintAuth || info.freezeAuth) return "BRIDGED";
64
- return "OPEN";
65
- }
66
-
67
- /* ---------- known issuers ---------- */
68
- // Name of the known issuer that holds every control key of this mint, or null. Needs the extension keys
69
- // read by getMint (extKeys): without them a permanent delegate or a hook could belong to anyone
70
- export function issuerOf(info, mint) {
71
- if (mint && OFFICIAL_TOKENS[mint]) return OFFICIAL_TOKENS[mint];
72
- if (!info || !info.extKeys) return null;
73
- const keys = [info.mintAuth, info.freezeAuth].concat(info.extKeys).filter(Boolean);
74
- if (!keys.length) return null;
75
- const found = ISSUERS.find(function (i) { return keys.every(function (k) { return i.keys.indexOf(k) >= 0; }); });
76
- return found ? found.name : null;
77
- }
78
-
79
- // Name of the issuer when it is on SolFlag's short trusted list, or null
80
- export function trustedIssuer(info, mint) {
81
- const name = issuerOf(info, mint);
82
- return name && ISSUERS.some(function (i) { return i.trusted && i.name === name; }) ? name : null;
83
- }
84
-
85
- // Extensions that only matter as they are set: a hook with no program and nobody able to add one does
86
- // nothing, and new accounts are only born frozen when the default state says "frozen". Mint info without
87
- // those details (older callers) keeps the old behaviour: the extension alone is enough
88
- function hookActive(info) { return !info.hook || !!(info.hook.program || info.hook.auth); }
89
- function bornFrozen(info) { return !info.defaultState || info.defaultState === "frozen"; }
90
-
91
- /* ---------- the four traffic lights ---------- */
92
- function mkLight(k, items, okSignal) {
93
- if (!items.length) return { k: k, s: "ok", items: [okSignal] };
94
- let st = "ok";
95
- items.forEach(function (x) { if (RANKS[x.s] > RANKS[st]) st = x.s; });
96
- // na ranks like ok for "worst of", but an unchecked light must stay na so levelFrom can cap it
97
- if (st === "ok" && items.some(function (x) { return x.s === "na"; })) st = "na";
98
- return { k: k, s: st, items: items };
99
- }
100
-
101
- /**
102
- * @param info mint info from getMint (+ authKind) or null if it could not be read
103
- * @param conc concentration from getConc, {skip:true}, or null if the RPC did not answer
104
- * @param pair best DexScreener pair (required: lights are only built for tokens with a market)
105
- * @param value USD value the analysed wallet holds (0 when checking a token alone)
106
- * @param type tokenType(info, pair)
107
- * @param rc RugCheck summary or null
108
- * @param launches creatorLaunches result or null: what else the creator launched (last 24 h, and how older ones did)
109
- * @returns [control, concentration, market, dependency]
110
- */
111
- export function buildLights(info, conc, pair, value, type, rc, now, launches) {
112
- now = now || Date.now();
113
- const ak = (info && info.authKind) || {};
114
- const issuer = issuerOf(info, pair && pair.baseToken && pair.baseToken.address);
115
- const trusted = issuer && trustedIssuer(info, pair && pair.baseToken && pair.baseToken.address);
116
- let it;
117
-
118
- // 1) creator control
119
- it = [];
120
- if (!info) it.push(sig("NO_INFO", "warn"));
121
- else {
122
- // a known issuer's mint, freeze, hook and pause are how the product works (see dependency)
123
- if (!issuer) {
124
- if (info.mintAuth && ak[info.mintAuth] !== "program") it.push(sig("CTL_MINT_ACTIVE", "bad"));
125
- if (info.freezeAuth && ak[info.freezeAuth] !== "program") it.push(sig("CTL_FREEZE_ACTIVE", "warn"));
126
- if (info.ext.indexOf("transferHook") >= 0 && hookActive(info)) it.push(sig("CTL_TRANSFER_HOOK", "warn"));
127
- if (info.ext.indexOf("defaultAccountState") >= 0 && bornFrozen(info)) it.push(sig("CTL_DEFAULT_FROZEN", "warn"));
128
- }
129
- // PYUSD and USDG carry the fee extension at 0%: under a known issuer that is how the product is built
130
- if (info.ext.indexOf("transferFeeConfig") >= 0 && !(issuer && info.feeBps === 0)) it.push(sig("CTL_TRANSFER_FEE", "warn"));
131
- if (info.ext.indexOf("nonTransferable") >= 0) it.push(sig("CTL_NON_TRANSFERABLE", "warn"));
132
- }
133
- // Launch farms put out a token every few minutes and drop each one as soon as buyers arrive: in a
134
- // 100-token Pump.fun sample one wallet launched 7 copies of "GMS" in 10 minutes
135
- // counted on chain (RugCheck had no report): it is the wallet that paid the launch, not the named creator
136
- if (launches && launches.day >= SERIAL_WARN) {
137
- const lv = launches.day >= SERIAL_BAD ? "bad" : "warn";
138
- it.push(launches.chain ? sig("CTL_SERIAL_PAYER", lv, { n: launches.day, payer: launches.payer })
139
- : sig("CTL_SERIAL_CREATOR", lv, { n: launches.day, creator: launches.creator }));
140
- }
141
- // Older launches that went nowhere: farms that spread their tokens over days escape the 24 h count
142
- if (launches && launches.old >= HISTORY_MIN && launches.dead / launches.old >= HISTORY_WARN) {
143
- const bad = launches.old >= HISTORY_BAD_MIN && launches.dead / launches.old >= HISTORY_BAD;
144
- it.push(sig("CTL_CREATOR_HISTORY", bad ? "bad" : "warn", { old: launches.old, dead: launches.dead, best: launches.best, creator: launches.creator }));
145
- }
146
- const control = mkLight("control", it, issuer ? sig("CTL_KNOWN_ISSUER", "ok", { issuer: issuer })
147
- : sig((info && (info.mintAuth || info.freezeAuth)) ? "CTL_ONLY_PROGRAMS" : "CTL_NONE", "ok"));
148
-
149
- // 2) concentration in people (pools and programs do not count)
150
- let concentration;
151
- const soft = (type === "STABLE" || type === "TOKENIZED" || type === "BRIDGED");
152
- if (trusted) concentration = mkLight("concentration", [sig("CON_TRUSTED", "ok", { issuer: issuer })]);
153
- else if (conc && conc.skip) concentration = mkLight("concentration", [sig("CON_SKIPPED", "na")]);
154
- else if (!conc) concentration = mkLight("concentration", [sig("CON_UNAVAILABLE", "na")]);
155
- else if (conc.ok) {
156
- let st = "ok";
157
- if (conc.w1 > 30 || conc.w10 > 70) st = "bad"; else if (conc.w1 > 15 || conc.w10 > 50) st = "warn";
158
- if (soft && st === "bad") st = "warn";
159
- const data = { w1: conc.w1, w10: conc.w10, prog: conc.prog, wallets: conc.nW }; // prog >= 20 is worth mentioning
160
- if (conc.ex) { data.ex = conc.ex; data.exn = conc.exn; } // named exchanges, shown but not counted
161
- let code = !conc.nW ? (conc.ex ? "CON_EXCHANGES" : "CON_ALL_POOLS") : (st === "ok" ? "CON_OK" : "CON_HIGH");
162
- // under a verified issuer the big holders are its treasury, custodians, exchanges and lending
163
- // protocols, not someone about to dump: shown, not counted (PYUSD 56% in one wallet, 1/11)
164
- if (issuer && code === "CON_HIGH") { code = "CON_ISSUER"; st = "ok"; }
165
- concentration = mkLight("concentration", [sig(code, st, data)]);
166
- } else {
167
- concentration = mkLight("concentration", [sig("CON_UNSPLIT", (conc.top1 > 30 || conc.top10 > 70) ? "warn" : "ok", { top1: conc.top1, top10: conc.top10 })]);
168
- }
169
-
170
- // 3) market and exit
171
- const liq = (pair.liquidity && pair.liquidity.usd) || 0, vol = (pair.volume && pair.volume.h24) || 0;
172
- it = [];
173
- // a verified issuer's token with little real liquidity on Solana trades elsewhere: not a trap
174
- if (pair.liqRaw && issuer) it.push(sig(liq < 10000 ? "MKT_LIQ_VERY_LOW" : "MKT_LIQ_LOW", "warn", { liq: liq, offSolana: true }));
175
- else if (pair.liqRaw) it.push(sig("MKT_LIQ_INFLATED", "bad", { reported: pair.liqRaw, real: liq }));
176
- else if (liq < 10000) it.push(sig("MKT_LIQ_VERY_LOW", "bad", { liq: liq }));
177
- else if (liq < 50000) it.push(sig("MKT_LIQ_LOW", "warn", { liq: liq }));
178
- if (vol < 1000) it.push(sig("MKT_VOLUME_LOW", "warn", { vol: vol }));
179
- if (pair.pairCreatedAt) {
180
- const d = (now - pair.pairCreatedAt) / DAY;
181
- if (d < 7) it.push(sig("MKT_NEW", "warn", { days: Math.floor(d) }));
182
- }
183
- if (value > 0 && liq > 0 && value / liq >= 0.1) it.push(sig("MKT_POSITION_HEAVY", "warn", { pct: value / liq * 100 }));
184
- // Dollars in the pool do not say who can take them out: if the LP tokens are neither locked nor
185
- // burned, the creator can pull the liquidity at any time whatever the rest says. Only for markets
186
- // under 90 days: that is when the creator alone provides liquidity and rug pulls are typical. In
187
- // veteran tokens (JUP, WIF...) many market makers provide it and unlocked LP is not a signal: applying
188
- // it there gave false positives (JUP scored worse than a new memecoin)
189
- const young = !pair.pairCreatedAt || (now - pair.pairCreatedAt) / DAY < 90;
190
- // On Pump.fun's bonding curve there is no LP at all: the curve program holds the liquidity and nobody
191
- // can pull it (RugCheck reports 0% locked, which flagged 49 of 75 curve tokens in a 100-token sample)
192
- const onCurve = PUMP_CURVE_DEXES.indexOf(pair.dexId) >= 0;
193
- // Same in concentrated-liquidity pools: no LP token, RugCheck reports ~0% locked (STONK on Meteora DLMM,
194
- // $2.4M liquidity in 27 pairs, showed a red flag, 1/11)
195
- const clPool = (pair.labels || []).some(function (l) { return CL_POOL_LABELS.indexOf(l) >= 0; });
196
- if (rc && !soft && young && !onCurve && !clPool && liq > 0 && typeof rc.lpLockedPct === "number" && isFinite(rc.lpLockedPct)) {
197
- if (rc.lpLockedPct < 20) it.push(sig("MKT_LP_UNLOCKED", "bad", { pct: rc.lpLockedPct }));
198
- else if (rc.lpLockedPct < 60) it.push(sig("MKT_LP_PARTLY_LOCKED", "warn", { pct: rc.lpLockedPct }));
199
- }
200
- if (type === "BRIDGED" && liq < 50000 && it.length) it[0] = Object.assign({}, it[0], { data: Object.assign({}, it[0].data, { offSolana: true }) });
201
- // an official token from an exchange or Socios trades mostly there: little liquidity on Solana is a
202
- // warning (hard to sell here), not a sign of a token built to trap buyers
203
- if (issuer && OFFICIAL_TOKENS[pair.baseToken && pair.baseToken.address]) it = it.map(function (x) {
204
- return x.code === "MKT_LIQ_VERY_LOW" ? sig(x.code, "warn", Object.assign({}, x.data, { offSolana: true })) : x;
205
- });
206
- const market = mkLight("market", it, sig("MKT_OK", "ok", { liq: liq, vol: vol }));
207
-
208
- // 4) dependency on an issuer or a bridge
209
- it = [];
210
- if (trusted) it.push(sig("DEP_TRUSTED_ISSUER", "ok", { issuer: issuer }));
211
- else if (issuer) it.push(sig("DEP_KNOWN_ISSUER", "warn", { issuer: issuer }));
212
- else if (info) {
213
- if ((info.mintAuth && ak[info.mintAuth] === "program") || (info.freezeAuth && ak[info.freezeAuth] === "program"))
214
- it.push(sig("DEP_PROGRAM_AUTHORITY", "warn"));
215
- if (info.ext.indexOf("permanentDelegate") >= 0) it.push(sig("DEP_PERMANENT_DELEGATE", "warn"));
216
- }
217
- if (type === "STABLE" && !trusted) it.push(sig("DEP_STABLE_ISSUER", "warn"));
218
- const dependency = mkLight("dependency", it, sig("DEP_NONE", "ok"));
219
-
220
- return [control, concentration, market, dependency];
221
- }
222
-
223
- export function levelFrom(lights) {
224
- let b = 0, w = 0, na = 0;
225
- lights.forEach(function (l) { if (l.s === "bad") b++; else if (l.s === "warn") w++; else if (l.s === "na") na++; });
226
- let lvl = (b >= 2 || (b === 1 && w >= 1)) ? "HIGH" : ((b === 1 || w >= 2) ? "MEDIUM" : "LOW");
227
- // What could not be checked does not count as "fine": with a check missing, at best it is medium risk
228
- if (lvl === "LOW" && na > 0) lvl = "MEDIUM";
229
- // A market under 7 days old has no track record: it is never "low risk", even with nothing else wrong.
230
- // Other single warnings stay low: on established tokens they are normal for their type (a staking pool's
231
- // program-controlled mint, a transfer hook...); measured on 62 real tokens, this rule moved 9 brand-new
232
- // tokens from low to medium and no established one
233
- if (lvl === "LOW" && lights.some(function (l) { return (l.items || []).some(function (x) { return x.code === "MKT_NEW"; }); })) lvl = "MEDIUM";
234
- return { lvl: lvl, sev: 3 * b + w + (na && !b && !w ? 1 : 0) };
235
- }
236
-
237
- // "Medium" with no concrete signal at all: only because some check could not run (e.g. holders without
238
- // your own RPC). Callers should say so explicitly so the scanner does not look like it marks everything the same
239
- export function dataOnly(r) {
240
- return r.lvl === "MEDIUM" && !!r.lights && !r.lights.some(function (l) { return l.s === "bad" || l.s === "warn"; }) && r.lights.some(function (l) { return l.s === "na"; });
241
- }
242
-
243
- // The signals worth showing as "why": everything not ok, in light order
244
- export function reasonsFrom(lights) {
245
- const out = [];
246
- lights.forEach(function (l) { if (l.s !== "ok") l.items.forEach(function (x) { if (x.s !== "ok") out.push(Object.assign({ k: l.k }, x)); }); });
247
- return out;
248
- }
249
-
250
- /**
251
- * Full risk assessment of one token.
252
- *
253
- * @param client
254
- * @param mint
255
- * @param pair best DexScreener pair or null (no market)
256
- * @param [opts.value] USD the analysed wallet holds of it (for the "heavy position" check)
257
- * @param [opts.marketUnknown] the DexScreener batch for this mint failed: no data, not "no market"
258
- * @param [opts.skipConcentration]
259
- * @param [opts.skipCreator] do not ask RugCheck what else the creator launched (markets under 7 days only)
260
- * @returns null for NFTs, otherwise {mint, sym, name, lvl, sev, pts, type, lights, reasons, impostor, value, pair, img}
261
- */
262
- export async function assess(client, mint, pair, opts) {
263
- opts = opts || {};
264
- const value = opts.value || 0;
265
- if (opts.marketUnknown) {
266
- return {
267
- mint: mint, sym: short(mint), name: "", pts: 0, sev: 0, lvl: "NO_DATA",
268
- reasons: [sig("MARKET_UNCHECKED", "na")], lights: null, type: null, impostor: null, value: value, pair: null, img: null
269
- };
270
- }
271
- const rcPromise = pair ? rugcheckSummary(client, mint) : Promise.resolve(null); // in parallel with the RPC calls below
272
- // Serial launching only matters while a token is new; RugCheck's full report is small (~10 KB) then
273
- const fresh = pair && !opts.skipCreator && (!pair.pairCreatedAt || Date.now() - pair.pairCreatedAt < 7 * DAY);
274
- // when RugCheck does not know the creator (new tokens often get a 400) the launches are counted on chain
275
- const launchPromise = fresh ? creatorLaunches(client, mint).then(function (r) {
276
- return r || chainLaunches(client, mint).catch(function (e) { if (isCancel(e)) throw e; return null; });
277
- }) : Promise.resolve(null);
278
- // Copies of the same name and ticker: one search per token, so only when asked (a single token, not a wallet)
279
- const copiesPromise = pair && opts.copies && !OFFICIAL_TOKENS[mint] ? copiesOf(client, mint, pair).catch(function (e) { if (isCancel(e)) throw e; return null; }) : Promise.resolve(null);
280
- let info = null, conc = null;
281
- try { info = await getMint(client, mint); } catch (e) { if (isCancel(e)) throw e; }
282
- if (info && info.decimals === 0 && info.supply === 1) return null; // NFT
283
- // Without a market concentration is not checked: saves half the requests
284
- if (info && pair && (info.mintAuth || info.freezeAuth)) {
285
- try { info.authKind = await getAuthKinds(client, info); } catch (e) { if (isCancel(e)) throw e; }
286
- }
287
- // a trusted issuer's holders are not checked (its treasury and exchanges; from the browser the public RPC
288
- // often cannot list USDC's holders, which left it "unchecked" and medium)
289
- if (info && pair && (opts.skipConcentration || trustedIssuer(info, mint))) conc = { skip: true };
290
- else if (info && pair) {
291
- // In tokens with millions of holders (BONK) getTokenLargestAccounts sometimes times out: a second try usually works
292
- for (let tryC = 0; tryC < 2 && !conc; tryC++) {
293
- try { conc = await getConc(client, mint, info.supply); }
294
- catch (e) { if (isCancel(e)) throw e; conc = null; if (!tryC) await sleep(client.retryDelayMs === undefined ? 1500 : client.retryDelayMs); }
295
- }
296
- }
297
- const rc = await rcPromise, launches = await launchPromise, copies = await copiesPromise;
298
- const base = (pair && pair.baseToken) || {};
299
- let lvl, sev = 0, reasons = [], lights = null, type = null, pts = 0, imp = null;
300
- if (pair) {
301
- type = tokenType(info, pair);
302
- lights = buildLights(info, conc, pair, value, type, rc, null, launches);
303
- imp = impostorOf(mint, pair);
304
- const official = !!OFFICIAL_TOKENS[mint];
305
- const brand = imp || official ? null : brandOf(pair, type);
306
- // copying a famous token, a real company or an older token with the same name and ticker
307
- const front = [];
308
- if (imp) front.push(sig("IMPOSTOR", "bad", { symbol: imp.sym, real: imp.real }));
309
- if (brand) front.push(sig(brand.exact ? "BRAND_COPY" : "BRAND_NAME", brand.exact ? "bad" : "warn", { brand: brand.brand }));
310
- // the real USDC/USDT is rarely the base token of a DexScreener pair, so the search found an older
311
- // "USDC" and called the real one the copy (USDC and USDT showed HIGH, 1/11)
312
- const canon = Object.keys(FAMOUS).some(function (k) { return FAMOUS[k] === mint; }) || !!issuerOf(info, mint);
313
- if (copies && !imp && !official && !canon) {
314
- const strong = copies.origLiq >= 50000 && copies.origLiq >= 10 * Math.max(copies.liq, 1);
315
- front.push(sig("COPYCAT", strong ? "bad" : "warn", copies));
316
- }
317
- if (front.length) {
318
- const prev = lights[0], st = front.some(function (x) { return x.s === "bad"; }) ? "bad" : (prev.s === "bad" ? "bad" : "warn");
319
- lights[0] = { k: "control", s: st, items: front.concat(prev.s !== "ok" ? prev.items : []) };
320
- }
321
- const lf = levelFrom(lights); lvl = lf.lvl; sev = lf.sev; reasons = reasonsFrom(lights);
322
- // a copy of a famous token or a real company, or liquidity faked 100 times over, is high risk even
323
- // when everything else looks normal: it is built to look like something it is not
324
- if (imp || (brand && brand.exact) || (fakeLiquidity(pair) && !issuerOf(info, mint))) { if (lvl !== "HIGH") sev += 5; lvl = "HIGH"; }
325
- } else {
326
- const s = score(info);
327
- pts = s.pts; reasons = s.why; lvl = pts >= 25 ? "SPAM" : "NO_MARKET";
328
- // an official token with no Solana pool (bgSOL trades on Bitget) is not spam: its issuer mints it
329
- if (OFFICIAL_TOKENS[mint]) { pts = 0; lvl = "NO_MARKET"; reasons = [sig("DEP_KNOWN_ISSUER", "warn", { issuer: OFFICIAL_TOKENS[mint] }), sig("NO_MARKET", "na")]; }
330
- }
331
- return {
332
- mint: mint, sym: base.symbol || short(mint), name: base.name || "", pts: pts, sev: sev,
333
- lvl: lvl, type: type, lights: lights, reasons: reasons, impostor: imp, copies: copies, value: value, pair: pair,
334
- rugcheck: rc ? { lpLockedPct: rc.lpLockedPct, score: rc.score_normalised !== undefined ? rc.score_normalised : rc.score } : null,
335
- creator: launches,
336
- img: (pair && pair.info && pair.info.imageUrl) || null
337
- };
338
- }
1
+ import { EXT_POINTS, RANKS, PUMP_CURVE_DEXES, CL_POOL_LABELS, ISSUERS, OFFICIAL_TOKENS, FAMOUS } from "./constants.js";
2
+ import { isCancel } from "./errors.js";
3
+ import { short, sleep } from "./util.js";
4
+ import { getMint, getAuthKinds, getConc } from "./tokens.js";
5
+ import { impostorOf, brandOf, copiesOf, fakeLiquidity } from "./markets.js";
6
+ import { rugcheckSummary, creatorLaunches } from "./rugcheck.js";
7
+ import { chainLaunches } from "./launch.js";
8
+
9
+ // Every finding is a "signal": {code, s, data}. `s` is ok | na | warn | bad, `data` holds the numbers
10
+ // behind it. Turning signals into sentences is i18n's job (describe / explainLight), never the engine's.
11
+ function sig(code, s, data) {
12
+ const o = { code: code, s: s };
13
+ if (data) o.data = data;
14
+ return o;
15
+ }
16
+
17
+ const DAY = 86400000;
18
+ // Other tokens launched by the same creator in the last 24 h that make it a serial launcher
19
+ export const SERIAL_WARN = 2, SERIAL_BAD = 5;
20
+ // Creator track record: at least HISTORY_MIN older tokens and this share of them never took off. Red needs
21
+ // 95%: 86% of all new tokens never reach $10k (149-token sample, 28/10), so one launch that took off out of
22
+ // ten is already better than chance and must not raise the verdict
23
+ export const HISTORY_MIN = 3, HISTORY_WARN = 0.8, HISTORY_BAD_MIN = 10, HISTORY_BAD = 0.95;
24
+
25
+ /* ---------- old point score: only for tokens without a market, to spot spam ---------- */
26
+ export function score(info) {
27
+ let pts = 0;
28
+ const why = [];
29
+ if (!info) return { pts: 30, why: [sig("NO_INFO", "warn")] };
30
+ const ak = info.authKind || {};
31
+ if (info.mintAuth) {
32
+ if (ak[info.mintAuth] === "program") { pts += 10; why.push(sig("MINT_BY_PROGRAM", "warn")); }
33
+ else { pts += 25; why.push(sig("MINT_ACTIVE", "bad", { byWallet: ak[info.mintAuth] === "wallet" })); }
34
+ }
35
+ if (info.freezeAuth) {
36
+ if (ak[info.freezeAuth] === "program") { pts += 8; why.push(sig("FREEZE_BY_PROGRAM", "warn")); }
37
+ else { pts += 20; why.push(sig("FREEZE_ACTIVE", "warn", { byWallet: ak[info.freezeAuth] === "wallet" })); }
38
+ }
39
+ info.ext.forEach(function (e) { if (EXT_POINTS[e]) { pts += EXT_POINTS[e]; why.push(sig("EXTENSION", "warn", { ext: e })); } });
40
+ why.push(sig("NO_MARKET", "na"));
41
+ return { pts: pts, why: why };
42
+ }
43
+
44
+ /* ---------- token type ---------- */
45
+ export function tokenType(info, pair, now) {
46
+ if (!info) return null;
47
+ now = now || Date.now();
48
+ const ak = info.authKind || {};
49
+ const sym = ((pair && pair.baseToken && pair.baseToken.symbol) || "") + " " + ((pair && pair.baseToken && pair.baseToken.name) || "");
50
+ const price = Number((pair && pair.priceUsd) || 0);
51
+ const liq = (pair && pair.liquidity && pair.liquidity.usd) || 0;
52
+ const ageDays = (pair && pair.pairCreatedAt) ? (now - pair.pairCreatedAt) / DAY : 0;
53
+ // Being called "USD something" is not enough to be judged more leniently than a normal token:
54
+ // it needs a stable price, real liquidity and some time trading (otherwise a scammer only has to
55
+ // name the token "USDX" and keep the price near $1 for a while)
56
+ if (/USD|DOLLAR/i.test(sym) && price > 0.97 && price < 1.03 && liq >= 200000 && ageDays >= 30) return "STABLE";
57
+ // a verified issuer's dollar or euro token is a stablecoin whatever pair DexScreener found (USDC showed
58
+ // "bridged" because its pair as base token is recent)
59
+ if (/USD|DOLLAR|EUR/i.test(sym) && issuerOf(info, pair && pair.baseToken && pair.baseToken.address)) return "STABLE";
60
+ if (info.ext.indexOf("permanentDelegate") >= 0) return "TOKENIZED";
61
+ const walletAuth = (info.mintAuth && ak[info.mintAuth] !== "program") || (info.freezeAuth && ak[info.freezeAuth] !== "program");
62
+ if (walletAuth) return "CREATOR";
63
+ if (info.mintAuth || info.freezeAuth) return "BRIDGED";
64
+ return "OPEN";
65
+ }
66
+
67
+ /* ---------- known issuers ---------- */
68
+ // Name of the known issuer that holds every control key of this mint, or null. Needs the extension keys
69
+ // read by getMint (extKeys): without them a permanent delegate or a hook could belong to anyone
70
+ export function issuerOf(info, mint) {
71
+ if (mint && OFFICIAL_TOKENS[mint]) return OFFICIAL_TOKENS[mint];
72
+ if (!info || !info.extKeys) return null;
73
+ const keys = [info.mintAuth, info.freezeAuth].concat(info.extKeys).filter(Boolean);
74
+ if (!keys.length) return null;
75
+ const found = ISSUERS.find(function (i) { return keys.every(function (k) { return i.keys.indexOf(k) >= 0; }); });
76
+ return found ? found.name : null;
77
+ }
78
+
79
+ // Name of the issuer when it is on SolFlag's short trusted list, or null
80
+ export function trustedIssuer(info, mint) {
81
+ const name = issuerOf(info, mint);
82
+ return name && ISSUERS.some(function (i) { return i.trusted && i.name === name; }) ? name : null;
83
+ }
84
+
85
+ // Extensions that only matter as they are set: a hook with no program and nobody able to add one does
86
+ // nothing, and new accounts are only born frozen when the default state says "frozen". Mint info without
87
+ // those details (older callers) keeps the old behaviour: the extension alone is enough
88
+ function hookActive(info) { return !info.hook || !!(info.hook.program || info.hook.auth); }
89
+ function bornFrozen(info) { return !info.defaultState || info.defaultState === "frozen"; }
90
+
91
+ /* ---------- the four traffic lights ---------- */
92
+ function mkLight(k, items, okSignal) {
93
+ if (!items.length) return { k: k, s: "ok", items: [okSignal] };
94
+ let st = "ok";
95
+ items.forEach(function (x) { if (RANKS[x.s] > RANKS[st]) st = x.s; });
96
+ // na ranks like ok for "worst of", but an unchecked light must stay na so levelFrom can cap it
97
+ if (st === "ok" && items.some(function (x) { return x.s === "na"; })) st = "na";
98
+ return { k: k, s: st, items: items };
99
+ }
100
+
101
+ /**
102
+ * @param info mint info from getMint (+ authKind) or null if it could not be read
103
+ * @param conc concentration from getConc, {skip:true}, or null if the RPC did not answer
104
+ * @param pair best DexScreener pair (required: lights are only built for tokens with a market)
105
+ * @param value USD value the analysed wallet holds (0 when checking a token alone)
106
+ * @param type tokenType(info, pair)
107
+ * @param rc RugCheck summary or null
108
+ * @param launches creatorLaunches result or null: what else the creator launched (last 24 h, and how older ones did)
109
+ * @returns [control, concentration, market, dependency]
110
+ */
111
+ export function buildLights(info, conc, pair, value, type, rc, now, launches) {
112
+ now = now || Date.now();
113
+ const ak = (info && info.authKind) || {};
114
+ const issuer = issuerOf(info, pair && pair.baseToken && pair.baseToken.address);
115
+ const trusted = issuer && trustedIssuer(info, pair && pair.baseToken && pair.baseToken.address);
116
+ let it;
117
+
118
+ // 1) creator control
119
+ it = [];
120
+ if (!info) it.push(sig("NO_INFO", "warn"));
121
+ else {
122
+ // a known issuer's mint, freeze, hook and pause are how the product works (see dependency)
123
+ if (!issuer) {
124
+ if (info.mintAuth && ak[info.mintAuth] !== "program") it.push(sig("CTL_MINT_ACTIVE", "bad"));
125
+ if (info.freezeAuth && ak[info.freezeAuth] !== "program") it.push(sig("CTL_FREEZE_ACTIVE", "warn"));
126
+ if (info.ext.indexOf("transferHook") >= 0 && hookActive(info)) it.push(sig("CTL_TRANSFER_HOOK", "warn"));
127
+ if (info.ext.indexOf("defaultAccountState") >= 0 && bornFrozen(info)) it.push(sig("CTL_DEFAULT_FROZEN", "warn"));
128
+ }
129
+ // PYUSD and USDG carry the fee extension at 0%: under a known issuer that is how the product is built
130
+ if (info.ext.indexOf("transferFeeConfig") >= 0 && !(issuer && info.feeBps === 0)) it.push(sig("CTL_TRANSFER_FEE", "warn"));
131
+ if (info.ext.indexOf("nonTransferable") >= 0) it.push(sig("CTL_NON_TRANSFERABLE", "warn"));
132
+ }
133
+ // Launch farms put out a token every few minutes and drop each one as soon as buyers arrive: in a
134
+ // 100-token Pump.fun sample one wallet launched 7 copies of "GMS" in 10 minutes
135
+ // counted on chain (RugCheck had no report): it is the wallet that paid the launch, not the named creator
136
+ if (launches && launches.day >= SERIAL_WARN) {
137
+ const lv = launches.day >= SERIAL_BAD ? "bad" : "warn";
138
+ it.push(launches.chain ? sig("CTL_SERIAL_PAYER", lv, { n: launches.day, payer: launches.payer })
139
+ : sig("CTL_SERIAL_CREATOR", lv, { n: launches.day, creator: launches.creator }));
140
+ }
141
+ // Older launches that went nowhere: farms that spread their tokens over days escape the 24 h count
142
+ if (launches && launches.old >= HISTORY_MIN && launches.dead / launches.old >= HISTORY_WARN) {
143
+ const bad = launches.old >= HISTORY_BAD_MIN && launches.dead / launches.old >= HISTORY_BAD;
144
+ it.push(sig("CTL_CREATOR_HISTORY", bad ? "bad" : "warn", { old: launches.old, dead: launches.dead, best: launches.best, creator: launches.creator }));
145
+ }
146
+ const control = mkLight("control", it, issuer ? sig("CTL_KNOWN_ISSUER", "ok", { issuer: issuer })
147
+ : sig((info && (info.mintAuth || info.freezeAuth)) ? "CTL_ONLY_PROGRAMS" : "CTL_NONE", "ok"));
148
+
149
+ // 2) concentration in people (pools and programs do not count)
150
+ let concentration;
151
+ const soft = (type === "STABLE" || type === "TOKENIZED" || type === "BRIDGED");
152
+ if (trusted) concentration = mkLight("concentration", [sig("CON_TRUSTED", "ok", { issuer: issuer })]);
153
+ else if (conc && conc.skip) concentration = mkLight("concentration", [sig("CON_SKIPPED", "na")]);
154
+ else if (!conc) concentration = mkLight("concentration", [sig("CON_UNAVAILABLE", "na")]);
155
+ else if (conc.ok) {
156
+ let st = "ok";
157
+ if (conc.w1 > 30 || conc.w10 > 70) st = "bad"; else if (conc.w1 > 15 || conc.w10 > 50) st = "warn";
158
+ if (soft && st === "bad") st = "warn";
159
+ const data = { w1: conc.w1, w10: conc.w10, prog: conc.prog, wallets: conc.nW }; // prog >= 20 is worth mentioning
160
+ if (conc.ex) { data.ex = conc.ex; data.exn = conc.exn; } // named exchanges, shown but not counted
161
+ if (conc.mm) { data.mm = conc.mm; data.mmn = conc.mmn; } // named market makers, shown and counted
162
+ let code = !conc.nW ? (conc.ex ? "CON_EXCHANGES" : "CON_ALL_POOLS") : (st === "ok" ? "CON_OK" : "CON_HIGH");
163
+ // under a verified issuer the big holders are its treasury, custodians, exchanges and lending
164
+ // protocols, not someone about to dump: shown, not counted (PYUSD 56% in one wallet, 1/11)
165
+ if (issuer && code === "CON_HIGH") { code = "CON_ISSUER"; st = "ok"; }
166
+ concentration = mkLight("concentration", [sig(code, st, data)]);
167
+ } else {
168
+ concentration = mkLight("concentration", [sig("CON_UNSPLIT", (conc.top1 > 30 || conc.top10 > 70) ? "warn" : "ok", { top1: conc.top1, top10: conc.top10 })]);
169
+ }
170
+
171
+ // 3) market and exit
172
+ const liq = (pair.liquidity && pair.liquidity.usd) || 0, vol = (pair.volume && pair.volume.h24) || 0;
173
+ it = [];
174
+ // a verified issuer's token with little real liquidity on Solana trades elsewhere: not a trap
175
+ if (pair.liqRaw && issuer) it.push(sig(liq < 10000 ? "MKT_LIQ_VERY_LOW" : "MKT_LIQ_LOW", "warn", { liq: liq, offSolana: true }));
176
+ else if (pair.liqRaw) it.push(sig("MKT_LIQ_INFLATED", "bad", { reported: pair.liqRaw, real: liq }));
177
+ else if (liq < 10000) it.push(sig("MKT_LIQ_VERY_LOW", "bad", { liq: liq }));
178
+ else if (liq < 50000) it.push(sig("MKT_LIQ_LOW", "warn", { liq: liq }));
179
+ if (vol < 1000) it.push(sig("MKT_VOLUME_LOW", "warn", { vol: vol }));
180
+ if (pair.pairCreatedAt) {
181
+ const d = (now - pair.pairCreatedAt) / DAY;
182
+ if (d < 7) it.push(sig("MKT_NEW", "warn", { days: Math.floor(d) }));
183
+ }
184
+ if (value > 0 && liq > 0 && value / liq >= 0.1) it.push(sig("MKT_POSITION_HEAVY", "warn", { pct: value / liq * 100 }));
185
+ // Dollars in the pool do not say who can take them out: if the LP tokens are neither locked nor
186
+ // burned, the creator can pull the liquidity at any time whatever the rest says. Only for markets
187
+ // under 90 days: that is when the creator alone provides liquidity and rug pulls are typical. In
188
+ // veteran tokens (JUP, WIF...) many market makers provide it and unlocked LP is not a signal: applying
189
+ // it there gave false positives (JUP scored worse than a new memecoin)
190
+ const young = !pair.pairCreatedAt || (now - pair.pairCreatedAt) / DAY < 90;
191
+ // On Pump.fun's bonding curve there is no LP at all: the curve program holds the liquidity and nobody
192
+ // can pull it (RugCheck reports 0% locked, which flagged 49 of 75 curve tokens in a 100-token sample)
193
+ const onCurve = PUMP_CURVE_DEXES.indexOf(pair.dexId) >= 0;
194
+ // Same in concentrated-liquidity pools: no LP token, RugCheck reports ~0% locked (STONK on Meteora DLMM,
195
+ // $2.4M liquidity in 27 pairs, showed a red flag, 1/11)
196
+ const clPool = (pair.labels || []).some(function (l) { return CL_POOL_LABELS.indexOf(l) >= 0; });
197
+ if (rc && !soft && young && !onCurve && !clPool && liq > 0 && typeof rc.lpLockedPct === "number" && isFinite(rc.lpLockedPct)) {
198
+ if (rc.lpLockedPct < 20) it.push(sig("MKT_LP_UNLOCKED", "bad", { pct: rc.lpLockedPct }));
199
+ else if (rc.lpLockedPct < 60) it.push(sig("MKT_LP_PARTLY_LOCKED", "warn", { pct: rc.lpLockedPct }));
200
+ }
201
+ if (type === "BRIDGED" && liq < 50000 && it.length) it[0] = Object.assign({}, it[0], { data: Object.assign({}, it[0].data, { offSolana: true }) });
202
+ // an official token from an exchange or Socios trades mostly there: little liquidity on Solana is a
203
+ // warning (hard to sell here), not a sign of a token built to trap buyers
204
+ if (issuer && OFFICIAL_TOKENS[pair.baseToken && pair.baseToken.address]) it = it.map(function (x) {
205
+ return x.code === "MKT_LIQ_VERY_LOW" ? sig(x.code, "warn", Object.assign({}, x.data, { offSolana: true })) : x;
206
+ });
207
+ const market = mkLight("market", it, sig("MKT_OK", "ok", { liq: liq, vol: vol }));
208
+
209
+ // 4) dependency on an issuer or a bridge
210
+ it = [];
211
+ if (trusted) it.push(sig("DEP_TRUSTED_ISSUER", "ok", { issuer: issuer }));
212
+ else if (issuer) it.push(sig("DEP_KNOWN_ISSUER", "warn", { issuer: issuer }));
213
+ else if (info) {
214
+ if ((info.mintAuth && ak[info.mintAuth] === "program") || (info.freezeAuth && ak[info.freezeAuth] === "program"))
215
+ it.push(sig("DEP_PROGRAM_AUTHORITY", "warn"));
216
+ if (info.ext.indexOf("permanentDelegate") >= 0) it.push(sig("DEP_PERMANENT_DELEGATE", "warn"));
217
+ }
218
+ if (type === "STABLE" && !trusted) it.push(sig("DEP_STABLE_ISSUER", "warn"));
219
+ const dependency = mkLight("dependency", it, sig("DEP_NONE", "ok"));
220
+
221
+ return [control, concentration, market, dependency];
222
+ }
223
+
224
+ export function levelFrom(lights) {
225
+ let b = 0, w = 0, na = 0;
226
+ lights.forEach(function (l) { if (l.s === "bad") b++; else if (l.s === "warn") w++; else if (l.s === "na") na++; });
227
+ let lvl = (b >= 2 || (b === 1 && w >= 1)) ? "HIGH" : ((b === 1 || w >= 2) ? "MEDIUM" : "LOW");
228
+ // What could not be checked does not count as "fine": with a check missing, at best it is medium risk
229
+ if (lvl === "LOW" && na > 0) lvl = "MEDIUM";
230
+ // A market under 7 days old has no track record: it is never "low risk", even with nothing else wrong.
231
+ // Other single warnings stay low: on established tokens they are normal for their type (a staking pool's
232
+ // program-controlled mint, a transfer hook...); measured on 62 real tokens, this rule moved 9 brand-new
233
+ // tokens from low to medium and no established one
234
+ if (lvl === "LOW" && lights.some(function (l) { return (l.items || []).some(function (x) { return x.code === "MKT_NEW"; }); })) lvl = "MEDIUM";
235
+ return { lvl: lvl, sev: 3 * b + w + (na && !b && !w ? 1 : 0) };
236
+ }
237
+
238
+ // "Medium" with no concrete signal at all: only because some check could not run (e.g. holders without
239
+ // your own RPC). Callers should say so explicitly so the scanner does not look like it marks everything the same
240
+ export function dataOnly(r) {
241
+ return r.lvl === "MEDIUM" && !!r.lights && !r.lights.some(function (l) { return l.s === "bad" || l.s === "warn"; }) && r.lights.some(function (l) { return l.s === "na"; });
242
+ }
243
+
244
+ // The signals worth showing as "why": everything not ok, in light order
245
+ export function reasonsFrom(lights) {
246
+ const out = [];
247
+ lights.forEach(function (l) { if (l.s !== "ok") l.items.forEach(function (x) { if (x.s !== "ok") out.push(Object.assign({ k: l.k }, x)); }); });
248
+ return out;
249
+ }
250
+
251
+ /**
252
+ * Full risk assessment of one token.
253
+ *
254
+ * @param client
255
+ * @param mint
256
+ * @param pair best DexScreener pair or null (no market)
257
+ * @param [opts.value] USD the analysed wallet holds of it (for the "heavy position" check)
258
+ * @param [opts.marketUnknown] the DexScreener batch for this mint failed: no data, not "no market"
259
+ * @param [opts.skipConcentration]
260
+ * @param [opts.skipCreator] do not ask RugCheck what else the creator launched (markets under 7 days only)
261
+ * @returns null for NFTs, otherwise {mint, sym, name, lvl, sev, pts, type, lights, reasons, impostor, value, pair, img}
262
+ */
263
+ export async function assess(client, mint, pair, opts) {
264
+ opts = opts || {};
265
+ const value = opts.value || 0;
266
+ if (opts.marketUnknown) {
267
+ return {
268
+ mint: mint, sym: short(mint), name: "", pts: 0, sev: 0, lvl: "NO_DATA",
269
+ reasons: [sig("MARKET_UNCHECKED", "na")], lights: null, type: null, impostor: null, value: value, pair: null, img: null
270
+ };
271
+ }
272
+ const rcPromise = pair ? rugcheckSummary(client, mint) : Promise.resolve(null); // in parallel with the RPC calls below
273
+ // Serial launching only matters while a token is new; RugCheck's full report is small (~10 KB) then
274
+ const fresh = pair && !opts.skipCreator && (!pair.pairCreatedAt || Date.now() - pair.pairCreatedAt < 7 * DAY);
275
+ // when RugCheck does not know the creator (new tokens often get a 400) the launches are counted on chain
276
+ const launchPromise = fresh ? creatorLaunches(client, mint).then(function (r) {
277
+ return r || chainLaunches(client, mint).catch(function (e) { if (isCancel(e)) throw e; return null; });
278
+ }) : Promise.resolve(null);
279
+ // Copies of the same name and ticker: one search per token, so only when asked (a single token, not a wallet)
280
+ const copiesPromise = pair && opts.copies && !OFFICIAL_TOKENS[mint] ? copiesOf(client, mint, pair).catch(function (e) { if (isCancel(e)) throw e; return null; }) : Promise.resolve(null);
281
+ let info = null, conc = null;
282
+ try { info = await getMint(client, mint); } catch (e) { if (isCancel(e)) throw e; }
283
+ if (info && info.decimals === 0 && info.supply === 1) return null; // NFT
284
+ // Without a market concentration is not checked: saves half the requests
285
+ if (info && pair && (info.mintAuth || info.freezeAuth)) {
286
+ try { info.authKind = await getAuthKinds(client, info); } catch (e) { if (isCancel(e)) throw e; }
287
+ }
288
+ // a trusted issuer's holders are not checked (its treasury and exchanges; from the browser the public RPC
289
+ // often cannot list USDC's holders, which left it "unchecked" and medium)
290
+ if (info && pair && (opts.skipConcentration || trustedIssuer(info, mint))) conc = { skip: true };
291
+ else if (info && pair) {
292
+ // In tokens with millions of holders (BONK) getTokenLargestAccounts sometimes times out: a second try usually works
293
+ for (let tryC = 0; tryC < 2 && !conc; tryC++) {
294
+ try { conc = await getConc(client, mint, info.supply); }
295
+ catch (e) { if (isCancel(e)) throw e; conc = null; if (!tryC) await sleep(client.retryDelayMs === undefined ? 1500 : client.retryDelayMs); }
296
+ }
297
+ }
298
+ const rc = await rcPromise, launches = await launchPromise, copies = await copiesPromise;
299
+ const base = (pair && pair.baseToken) || {};
300
+ let lvl, sev = 0, reasons = [], lights = null, type = null, pts = 0, imp = null;
301
+ if (pair) {
302
+ type = tokenType(info, pair);
303
+ lights = buildLights(info, conc, pair, value, type, rc, null, launches);
304
+ imp = impostorOf(mint, pair);
305
+ const official = !!OFFICIAL_TOKENS[mint];
306
+ const brand = imp || official ? null : brandOf(pair, type);
307
+ // copying a famous token, a real company or an older token with the same name and ticker
308
+ const front = [];
309
+ if (imp) front.push(sig("IMPOSTOR", "bad", { symbol: imp.sym, real: imp.real }));
310
+ if (brand) front.push(sig(brand.exact ? "BRAND_COPY" : "BRAND_NAME", brand.exact ? "bad" : "warn", { brand: brand.brand }));
311
+ // the real USDC/USDT is rarely the base token of a DexScreener pair, so the search found an older
312
+ // "USDC" and called the real one the copy (USDC and USDT showed HIGH, 1/11)
313
+ const canon = Object.keys(FAMOUS).some(function (k) { return FAMOUS[k] === mint; }) || !!issuerOf(info, mint);
314
+ if (copies && !imp && !official && !canon) {
315
+ const strong = copies.origLiq >= 50000 && copies.origLiq >= 10 * Math.max(copies.liq, 1);
316
+ front.push(sig("COPYCAT", strong ? "bad" : "warn", copies));
317
+ }
318
+ if (front.length) {
319
+ const prev = lights[0], st = front.some(function (x) { return x.s === "bad"; }) ? "bad" : (prev.s === "bad" ? "bad" : "warn");
320
+ lights[0] = { k: "control", s: st, items: front.concat(prev.s !== "ok" ? prev.items : []) };
321
+ }
322
+ const lf = levelFrom(lights); lvl = lf.lvl; sev = lf.sev; reasons = reasonsFrom(lights);
323
+ // a copy of a famous token or a real company, or liquidity faked 100 times over, is high risk even
324
+ // when everything else looks normal: it is built to look like something it is not
325
+ if (imp || (brand && brand.exact) || (fakeLiquidity(pair) && !issuerOf(info, mint))) { if (lvl !== "HIGH") sev += 5; lvl = "HIGH"; }
326
+ } else {
327
+ const s = score(info);
328
+ pts = s.pts; reasons = s.why; lvl = pts >= 25 ? "SPAM" : "NO_MARKET";
329
+ // an official token with no Solana pool (bgSOL trades on Bitget) is not spam: its issuer mints it
330
+ if (OFFICIAL_TOKENS[mint]) { pts = 0; lvl = "NO_MARKET"; reasons = [sig("DEP_KNOWN_ISSUER", "warn", { issuer: OFFICIAL_TOKENS[mint] }), sig("NO_MARKET", "na")]; }
331
+ }
332
+ return {
333
+ mint: mint, sym: base.symbol || short(mint), name: base.name || "", pts: pts, sev: sev,
334
+ lvl: lvl, type: type, lights: lights, reasons: reasons, impostor: imp, copies: copies, value: value, pair: pair,
335
+ rugcheck: rc ? { lpLockedPct: rc.lpLockedPct, score: rc.score_normalised !== undefined ? rc.score_normalised : rc.score } : null,
336
+ creator: launches,
337
+ img: (pair && pair.info && pair.info.imageUrl) || null
338
+ };
339
+ }