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