solana-risk-engine 0.4.12 → 0.5.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 +3 -1
- package/package.json +1 -1
- package/src/holders.js +8 -3
- package/src/i18n/en.js +5 -0
- package/src/i18n/es.js +5 -0
- package/src/index.js +5 -1
- package/src/launch.js +11 -2
- package/src/map.js +250 -0
- package/src/risk.js +6 -1
- package/src/tokens.js +3 -2
package/README.md
CHANGED
|
@@ -28,7 +28,7 @@ for (const l of r.lights) // the four traffic lights
|
|
|
28
28
|
| **Real concentration** | Largest accounts are traced to their owners. Pools and programs are separated from people, so `w1`/`w10` measure *people*, not AMM vaults. |
|
|
29
29
|
| **Inflated liquidity** | DexScreener values both sides of a pool at the pool's price. A pool with 4B of a token against 2 USDC shows "$4,000M liquidity". The engine recomputes it from the real side (USDC/USDT/SOL). It only flags extreme gaps (real side under 5%), because concentrated-liquidity pools are lopsided by nature. |
|
|
30
30
|
| **Unlocked LP** | % of LP locked/burned via RugCheck. It only counts for markets under 90 days old, so veteran tokens don't get false positives, and never while a token is on Pump.fun's bonding curve, where there is no LP to pull. |
|
|
31
|
-
| **Serial creators** | For markets under 7 days: how many other tokens the creator launched in the last 24 h (RugCheck). 2 or more is a warning, 5 or more a red flag. `recentLaunches(client, wallet)` counts the same on chain for the wallet that *paid* a launch, which catches farms that name a fresh creator each time. When RugCheck has no report yet (it often answers 400 for tokens a few minutes old) the analysis falls back to `chainLaunches(client, mint)`: that count for the first signer of the token's creation transaction. |
|
|
31
|
+
| **Serial creators** | For markets under 7 days: how many other tokens the creator launched in the last 24 h (RugCheck). 2 or more is a warning, 5 or more a red flag. `recentLaunches(client, wallet)` counts the same on chain for the wallet that *paid* a launch, which catches farms that name a fresh creator each time. When RugCheck has no report yet (it often answers 400 for tokens a few minutes old) the analysis falls back to `chainLaunches(client, mint)`: that count for the first signer of the token's creation transaction, reported as its own signal `CTL_SERIAL_PAYER` ("the wallet that paid for this launch…", never as the creator) and skipped when the SolFlag wallet base knows that wallet as an exchange or platform. |
|
|
32
32
|
| **Impostors** | Tokens using the symbol or name of a famous token (USDC, JUP, BONK, WIF, BTC, ETH...) with a different address. |
|
|
33
33
|
| **Real brands** | About 320 real companies with no token on Solana (Spotify, Nike, Zara, Ferrari...). A token called just that is a red flag and **HIGH**; the brand as one word of a longer name is a warning. Everyday words that are also brands (Shell, Target, Puma) are left out, and markets at least 30 days old with $100k+ liquidity are not checked. |
|
|
34
34
|
| **Known issuers and official tokens** | Stablecoins from Paxos (PYUSD, USDG), Circle (USDC, EURC) and Tether (USDT), tokenized shares from xStocks (all recognised by their control keys, taken from mints the issuer lists on its own pages) and official tokens from exchanges and Socios.com (bnSOL, bbSOL, cbBTC, club fan tokens..., by mint address) are shown as dependency on the issuer. Their large holders (treasury, custodians, exchanges) are shown but do not count as concentration, a 0% transfer fee is not a warning, and a tiny Solana pool is a warning, not a red flag. A short **trusted** list (Circle, Paxos, Tether, xStocks; `trustedIssuer()`) goes further: every light green, holders not checked. |
|
|
@@ -77,6 +77,8 @@ Methods (all accept `{ onProgress(step, fraction) }`):
|
|
|
77
77
|
| `analyzeAddress(addr)` | `{ kind: "token" \| "wallet", ... }`, detected automatically |
|
|
78
78
|
| `analyzeHolders(mint)` | `{ rows, clusters, groups, hotGroups, creator, mode, ageDays, signals, ... }`. Young tokens (under 14 days) also trace busy wallets; a source over 100 tx/h counts as an exchange; a group over 10% (young) or 15% (mature) of the supply gives a `HOLD_GROUP` signal. With `{ base: true }` it also reads [SolFlag's wallet base](https://solflag.com/datos/base.json) (exchanges, launch farms, distributors and serial creators its collector has seen): known exchanges are recognised without measuring them, and rows and group sources get `known` / `knownSources`. Best with your own RPC. |
|
|
79
79
|
| `loadWalletBase([url])` | SolFlag's wallet base `{ wallets: { addr: { t, ph, n, roles } } }`, or `null` if it cannot be read. Kept 10 minutes. `knownType(base, addr)` gives a wallet's type. |
|
|
80
|
+
| `analyzeHolders(mint)` | `{ rows, clusters, groups, hotGroups, creator, mode, ageDays, signals, ... }`. Young tokens (under 14 days) also trace busy wallets; a source over 100 tx/h counts as an exchange; a group over 10% (young) or 15% (mature) of the supply gives a `HOLD_GROUP` signal. Best with your own RPC. |
|
|
81
|
+
| `connectionMap(mint, { createdAt })` | `{ mode, holders, sources, groups, nets, hub, creator, payer, signals }`: largest holders typed person / bot / exchange (over 100 tx/h) / pool, who gave each one its first SOL, groups sharing that source, RugCheck's token-transfer networks with their links. `young` (under 14 days) or `mature` decides what is traced and when it warns (`MAP_GROUP`, `MAP_SWARM` for 10+ holders from one source whatever they hold, `MAP_HUB`, `MAP_WHALE`). 20 holders, 75 with your own RPC. |
|
|
80
82
|
| `estimatePnl(wallets)` | `{ pnl: { [wallet]: { realized, unreal, total, ret, st, open } } }`. Needs Helius. |
|
|
81
83
|
| `takeSnapshots(wallets)` | Today's holdings. Store them yourself and pass them to `diffSnapshots(prev, next)`. |
|
|
82
84
|
| `confluence(wallets, { pct, withPnl, pnlFilter })` | Tokens held in common, with risk. |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solana-risk-engine",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Explainable risk analysis for Solana tokens and wallets: creator control, real holder concentration, inflated liquidity, impostor tokens, funder clusters and PnL. Zero dependencies, runs in Node and the browser.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./src/index.js",
|
package/src/holders.js
CHANGED
|
@@ -24,7 +24,7 @@ export async function holderBase(client, mint, onProgress) {
|
|
|
24
24
|
});
|
|
25
25
|
const owned = uniq(owners.filter(Boolean));
|
|
26
26
|
progress(onProgress, "kinds", 0.7);
|
|
27
|
-
const kind = await accountKinds(client, owned,
|
|
27
|
+
const kind = await accountKinds(client, owned, true); // on the curve with no account: a wallet emptied of SOL
|
|
28
28
|
return { mint: mint, info: info, pair: pair, largest: largest, owners: owners, uniq: owned, kind: kind };
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -134,9 +134,14 @@ export const YOUNG_DAYS = 14;
|
|
|
134
134
|
// A group (holders sharing the source of their first SOL) over this % of the supply warns
|
|
135
135
|
export const HOLD_GROUP_YOUNG = 10, HOLD_GROUP_MATURE = 15;
|
|
136
136
|
|
|
137
|
-
//
|
|
137
|
+
// Below this many signatures there is no rate to speak of: a fresh wallet funded and buying within the same
|
|
138
|
+
// minute (or a one-use bundler that funded ten wallets in five) would look like thousands an hour, i.e. an
|
|
139
|
+
// exchange, and drop out of the groups it belongs to. Exchanges and bots have far more than this.
|
|
140
|
+
export const RATE_MIN_SIGS = 50;
|
|
141
|
+
|
|
142
|
+
// Transactions per hour over a page of signatures (newest first); 0 under RATE_MIN_SIGS
|
|
138
143
|
export function perHour(sigs) {
|
|
139
|
-
if (!sigs || sigs.length <
|
|
144
|
+
if (!sigs || sigs.length < RATE_MIN_SIGS) return 0;
|
|
140
145
|
const span = ((sigs[0].blockTime || 0) - (sigs[sigs.length - 1].blockTime || 0)) / 3600;
|
|
141
146
|
return span > 0 ? sigs.length / span : sigs.length * 3600;
|
|
142
147
|
}
|
package/src/i18n/en.js
CHANGED
|
@@ -38,6 +38,11 @@ export default {
|
|
|
38
38
|
CTL_KNOWN_ISSUER: (d) => "Controlled by its issuer, " + d.issuer + " (see dependency)",
|
|
39
39
|
CTL_NONE: () => "No active authorities: nobody can mint more or freeze",
|
|
40
40
|
CTL_SERIAL_CREATOR: (d) => "The creator launched " + d.n + " other tokens in the last 24 h (per RugCheck): a serial launcher, who usually drops each token as soon as buyers arrive",
|
|
41
|
+
CTL_SERIAL_PAYER: (d) => "The wallet that paid for this launch launched " + d.n + " other tokens in the last 24 h (counted on chain): a serial launcher, who usually drops each token as soon as buyers arrive",
|
|
42
|
+
MAP_GROUP: (d) => d.n + " holders got their first SOL from the same wallet and together hold " + pct(d.pct) + " of the supply: most likely one person or team",
|
|
43
|
+
MAP_SWARM: (d) => d.n + " of the " + d.of + " largest holders got their first SOL from the same wallet (together " + pct(d.pct) + "): this many wallets from one source is usually the team splitting its supply",
|
|
44
|
+
MAP_HUB: (d) => "One wallet handed tokens to " + d.n + " wallets: teams often split the supply this way to look more spread out",
|
|
45
|
+
MAP_WHALE: (d) => "A single person (not an exchange or a pool) holds " + pct(d.pct) + " of the supply",
|
|
41
46
|
BRAND_COPY: (d) => "Uses the name of " + d.brand + ", a real company with no token on Solana: it is not official, almost certainly an imitation to draw buyers",
|
|
42
47
|
BRAND_NAME: (d) => "Uses the name of " + d.brand + ", a real company: it is not an official " + d.brand + " token",
|
|
43
48
|
COPYCAT: (d) => "There " + (d.n === 1 ? "is another token" : "are " + d.n + " more tokens") + " with the same name and ticker; the oldest one with a real market (" + short(d.original) + ", " + d.days + (d.days === 1 ? " day" : " days") + " old) is not this one: check you have the right address",
|
package/src/i18n/es.js
CHANGED
|
@@ -41,6 +41,11 @@ export default {
|
|
|
41
41
|
CTL_KNOWN_ISSUER: (d) => "Lo controla su emisor, " + d.issuer + " (ver dependencia)",
|
|
42
42
|
CTL_NONE: () => "Sin autoridades activas: nadie puede crear más ni congelar",
|
|
43
43
|
CTL_SERIAL_CREATOR: (d) => "El creador ha lanzado " + d.n + " tokens más en las últimas 24 h (según RugCheck): es un lanzador en serie, que suele abandonar cada token en cuanto llegan compradores",
|
|
44
|
+
CTL_SERIAL_PAYER: (d) => "La wallet que pagó este lanzamiento ha lanzado " + d.n + " tokens más en las últimas 24 h (contado en la cadena): es un lanzador en serie, que suele abandonar cada token en cuanto llegan compradores",
|
|
45
|
+
MAP_GROUP: (d) => d.n + " holders recibieron su primer SOL de la misma wallet y juntos tienen el " + pct(d.pct) + " del suministro: probablemente son la misma persona o equipo",
|
|
46
|
+
MAP_SWARM: (d) => d.n + " de los " + d.of + " mayores holders recibieron su primer SOL de la misma wallet (juntos tienen el " + pct(d.pct) + "): tantas wallets con el mismo origen suelen ser un reparto del equipo",
|
|
47
|
+
MAP_HUB: (d) => "Una wallet ha repartido tokens a " + d.n + " wallets: el equipo suele dividir el suministro así para parecer más repartido",
|
|
48
|
+
MAP_WHALE: (d) => "Una sola persona (que no es un exchange ni un pool) tiene el " + pct(d.pct) + " del suministro",
|
|
44
49
|
BRAND_COPY: (d) => "Usa el nombre de " + d.brand + ", una empresa real que no tiene token en Solana: no es oficial, casi seguro una imitación para atraer compradores",
|
|
45
50
|
BRAND_NAME: (d) => "Usa el nombre de " + d.brand + ", una empresa real: no es un token oficial de " + d.brand,
|
|
46
51
|
COPYCAT: (d) => "Hay " + (d.n === 1 ? "otro token" : d.n + " tokens más") + " con el mismo nombre y ticker; el más antiguo con mercado real (" + short(d.original) + ", de hace " + d.days + (d.days === 1 ? " día" : " días") + ") no es este: comprueba que tienes la dirección correcta",
|
package/src/index.js
CHANGED
|
@@ -6,6 +6,7 @@ import { takeSnapshots } from "./changes.js";
|
|
|
6
6
|
import { confluence, commonHolders } from "./confluence.js";
|
|
7
7
|
import { getTokens } from "./tokens.js";
|
|
8
8
|
import { loadWalletBase } from "./base.js";
|
|
9
|
+
import { connectionMap } from "./map.js";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* The easy entry point: one object with every high-level analysis bound to one network client.
|
|
@@ -24,6 +25,7 @@ export function createScanner(opts) {
|
|
|
24
25
|
analyzeWallet: (wallet, o) => analyzeWallet(client, wallet, o),
|
|
25
26
|
analyzeAddress: (addr, o) => analyzeAddress(client, addr, o),
|
|
26
27
|
analyzeHolders: (mint, o) => analyzeHolders(client, mint, o),
|
|
28
|
+
connectionMap: (mint, o) => connectionMap(client, mint, o),
|
|
27
29
|
estimatePnl: async (wallets, o) => {
|
|
28
30
|
// Current balances trim tokens the wallet moved away; read them if the caller did not pass them
|
|
29
31
|
o = o || {};
|
|
@@ -52,7 +54,9 @@ export { score, issuerOf, trustedIssuer, tokenType, buildLights, levelFrom, data
|
|
|
52
54
|
export { recentLaunches, chainLaunches } from "./launch.js";
|
|
53
55
|
export { analyzeToken, analyzeWallet, analyzeAddress, sortResults } from "./wallet.js";
|
|
54
56
|
export { holderBase, markBusy, onlyReceives, PASSIVE_SAMPLE, findFunder, findFunders, clusterByFunder, holderRows, creatorInfo, analyzeHolders,
|
|
55
|
-
perHour, sourceRates, groupList, EXCHANGE_PER_HOUR, YOUNG_DAYS, HOLD_GROUP_YOUNG, HOLD_GROUP_MATURE } from "./holders.js";
|
|
57
|
+
perHour, sourceRates, groupList, EXCHANGE_PER_HOUR, RATE_MIN_SIGS, YOUNG_DAYS, HOLD_GROUP_YOUNG, HOLD_GROUP_MATURE } from "./holders.js";
|
|
58
|
+
export { connectionMap, allHolders, transferNetworks, topHub, mapGroups, mapSignals, walletType,
|
|
59
|
+
BOT_PER_HOUR, mapType, MAP_GROUP_YOUNG, MAP_GROUP_MATURE, MAP_HUB, MAP_WHALE, MAP_SWARM, MAP_MAX_FREE, MAP_MAX_OWN } from "./map.js";
|
|
56
60
|
export { fetchSwaps, solHistory, priceSeries, parseTrades, pnlFromTrades, pnlStatus, estimatePnl } from "./pnl.js";
|
|
57
61
|
export { capSnap, chgDiff, chgAgg, takeSnapshots, diffSnapshots } from "./changes.js";
|
|
58
62
|
export { confluence, commonHolders } from "./confluence.js";
|
package/src/launch.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { PUMP_PROGRAM } from "./constants.js";
|
|
2
2
|
import { isCancel } from "./errors.js";
|
|
3
3
|
import { pool } from "./util.js";
|
|
4
|
+
import { loadWalletBase, knownType } from "./base.js";
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Pump.fun tokens a wallet launched in the last 24 h, read on chain from its latest transactions.
|
|
@@ -49,8 +50,12 @@ export async function recentLaunches(client, wallet, opts) {
|
|
|
49
50
|
* The launcher is the first signer of the token's creation transaction: the wallet that paid, as in
|
|
50
51
|
* recentLaunches (farms name a fresh creator each time but pay from one wallet). Only new tokens: past
|
|
51
52
|
* 1000 transactions the creation is too far back to find cheaply.
|
|
53
|
+
* The wallet is NOT the creator RugCheck names (farms name a fresh one each time), so it comes back as
|
|
54
|
+
* `payer` with `creator: null`, and the signal is CTL_SERIAL_PAYER with its own text. A wallet the
|
|
55
|
+
* SolFlag wallet base knows as an exchange or platform (it may pay launches for many unrelated people)
|
|
56
|
+
* is not counted; opts.base: a base object, or false to skip the check.
|
|
52
57
|
* Same shape as creatorLaunches, without the history of older launches (that needs market caps):
|
|
53
|
-
* @returns {creator, day, total, old: 0, dead: 0, best: null, chain: true, more} or null
|
|
58
|
+
* @returns {creator: null, payer, day, total, old: 0, dead: 0, best: null, chain: true, more} or null
|
|
54
59
|
*/
|
|
55
60
|
export async function chainLaunches(client, mint, opts) {
|
|
56
61
|
opts = opts || {};
|
|
@@ -62,7 +67,11 @@ export async function chainLaunches(client, mint, opts) {
|
|
|
62
67
|
const first = keys && keys.filter(function (k) { return k.signer; })[0];
|
|
63
68
|
const wallet = first && (first.pubkey || first);
|
|
64
69
|
if (!wallet || wallet === mint) return null;
|
|
70
|
+
if (opts.base !== false) {
|
|
71
|
+
const base = opts.base && typeof opts.base === "object" ? opts.base : await loadWalletBase(client);
|
|
72
|
+
if (knownType(base, wallet) === "exchange") return null;
|
|
73
|
+
}
|
|
65
74
|
const r = await recentLaunches(client, wallet, { now: opts.now, limit: opts.limit });
|
|
66
75
|
const day = r.mints.filter(function (m) { return m !== mint; }).length;
|
|
67
|
-
return { creator: wallet, day: day, total: day, old: 0, dead: 0, best: null, chain: true, more: r.more };
|
|
76
|
+
return { creator: null, payer: wallet, day: day, total: day, old: 0, dead: 0, best: null, chain: true, more: r.more };
|
|
68
77
|
}
|
package/src/map.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
import { ADDRESS_RE, TOKEN_PROGRAM, TOKEN_2022, RUGCHECK } from "./constants.js";
|
|
2
|
+
import { ScanError, isCancel } from "./errors.js";
|
|
3
|
+
import { pool, progress, uniq } from "./util.js";
|
|
4
|
+
import { holderBase, EXCHANGE_PER_HOUR, perHour, sourceRates, onlyReceives } from "./holders.js";
|
|
5
|
+
export { EXCHANGE_PER_HOUR, perHour, sourceRates };
|
|
6
|
+
import { accountKinds } from "./tokens.js";
|
|
7
|
+
import { rugcheckReport } from "./rugcheck.js";
|
|
8
|
+
|
|
9
|
+
/* ---------- connection map ----------
|
|
10
|
+
Everything around a token at once: its largest holders, what kind of wallet each one is, who gave each
|
|
11
|
+
one its first SOL (holders sharing that source are probably one owner), and the token-transfer networks
|
|
12
|
+
RugCheck keeps (one wallet handing tokens to many). Young tokens (under 14 days) are read for the team's
|
|
13
|
+
split; mature ones for what stayed hidden, with exchanges and pools set aside. */
|
|
14
|
+
|
|
15
|
+
// Same rule as markBusy: 200 transactions within 2 days is a bot or trader, not a holder sitting on tokens
|
|
16
|
+
export const BOT_PER_HOUR = 200 / 48;
|
|
17
|
+
export const YOUNG_DAYS = 14;
|
|
18
|
+
export const MAP_GROUP_YOUNG = 10, MAP_GROUP_MATURE = 15, MAP_HUB = 20, MAP_WHALE = 10;
|
|
19
|
+
// Many holders funded by one wallet warn whatever they hold together: with only the top 20 read the share
|
|
20
|
+
// is cut short (1/11, Leverhedge: 19 of the top 20 with 0.4% each from one source, 8.1% in view)
|
|
21
|
+
export const MAP_SWARM = 10;
|
|
22
|
+
export const MAP_MAX_FREE = 20, MAP_MAX_OWN = 75;
|
|
23
|
+
|
|
24
|
+
const B58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
25
|
+
function b58encode(bytes) {
|
|
26
|
+
let n = 0n;
|
|
27
|
+
for (const b of bytes) n = n * 256n + BigInt(b);
|
|
28
|
+
let s = "";
|
|
29
|
+
while (n > 0n) { s = B58[Number(n % 58n)] + s; n /= 58n; }
|
|
30
|
+
for (const b of bytes) { if (b !== 0) break; s = "1" + s; }
|
|
31
|
+
return s;
|
|
32
|
+
}
|
|
33
|
+
function b64bytes(s) {
|
|
34
|
+
if (typeof atob === "function") { const t = atob(s), out = new Uint8Array(t.length); for (let i = 0; i < t.length; i++) out[i] = t.charCodeAt(i); return out; }
|
|
35
|
+
return Uint8Array.from(Buffer.from(s, "base64"));
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
// person | bot | exchange | pool
|
|
40
|
+
export function walletType(kind, rate) {
|
|
41
|
+
if (kind === "program") return "pool";
|
|
42
|
+
if (rate > EXCHANGE_PER_HOUR) return "exchange";
|
|
43
|
+
if (rate > BOT_PER_HOUR || kind === "active") return "bot";
|
|
44
|
+
return "person";
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// walletType, but a busy wallet that signed none of the sampled transactions only RECEIVES (fee shares,
|
|
48
|
+
// airdrops, dust): it is a person who gets paid, not a bot or an exchange (same rule as markBusy, 0.4.7).
|
|
49
|
+
// Returns { type, passive }.
|
|
50
|
+
export async function mapType(client, addr, kind, rate, sigs) {
|
|
51
|
+
const type = walletType(kind, rate);
|
|
52
|
+
if ((type === "bot" || type === "exchange") && kind !== "active" && sigs && sigs.length >= 2 &&
|
|
53
|
+
await onlyReceives(client, addr, sigs)) return { type: "person", passive: true };
|
|
54
|
+
return { type: type, passive: false };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// Every token account of the mint (own RPC only), summed by owner, largest first. Reads just the owner
|
|
58
|
+
// and amount of each account. Returns null when the RPC refuses or the token is too big to list.
|
|
59
|
+
export async function allHolders(client, mint, program, max) {
|
|
60
|
+
const filters = [{ memcmp: { offset: 0, bytes: mint } }];
|
|
61
|
+
if (program === TOKEN_PROGRAM) filters.push({ dataSize: 165 });
|
|
62
|
+
let res;
|
|
63
|
+
try { res = await client.rpc("getProgramAccounts", [program, { encoding: "base64", dataSlice: { offset: 32, length: 40 }, filters: filters }]); }
|
|
64
|
+
catch (e) { if (isCancel(e)) throw e; return null; }
|
|
65
|
+
if (!Array.isArray(res)) return null;
|
|
66
|
+
const by = {};
|
|
67
|
+
res.forEach(function (a) {
|
|
68
|
+
const d = a && a.account && a.account.data;
|
|
69
|
+
const raw = d && b64bytes(Array.isArray(d) ? d[0] : d);
|
|
70
|
+
if (!raw || raw.length < 40) return;
|
|
71
|
+
const owner = b58encode(raw.slice(0, 32));
|
|
72
|
+
let amt = 0n;
|
|
73
|
+
for (let i = 39; i >= 32; i--) amt = amt * 256n + BigInt(raw[i]);
|
|
74
|
+
if (amt > 0n) by[owner] = (by[owner] || 0n) + amt;
|
|
75
|
+
});
|
|
76
|
+
return Object.keys(by).sort(function (a, b) { return by[b] > by[a] ? 1 : by[b] < by[a] ? -1 : 0; })
|
|
77
|
+
.slice(0, max).map(function (o) { return { owner: o, raw: Number(by[o]) }; });
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Up to 3 pages of signatures: the oldest one and the newest page (for the rate). first = null when the
|
|
81
|
+
// wallet has more than 3000 (its first transaction is too far back to find cheaply).
|
|
82
|
+
async function history(client, addr, pages) {
|
|
83
|
+
let before = null, first = null, top = null;
|
|
84
|
+
for (let i = 0; i < pages; i++) {
|
|
85
|
+
const page = await client.rpc("getSignaturesForAddress", [addr, before ? { limit: 1000, before: before } : { limit: 1000 }]);
|
|
86
|
+
if (!page || !page.length) break;
|
|
87
|
+
if (!top) top = page;
|
|
88
|
+
if (page.length < 1000) { first = page[page.length - 1].signature; break; }
|
|
89
|
+
before = page[page.length - 1].signature;
|
|
90
|
+
}
|
|
91
|
+
return { rate: perHour(top), n: top ? top.length : 0, first: first, top: top };
|
|
92
|
+
}
|
|
93
|
+
// Fee payer (account 0) of a transaction
|
|
94
|
+
async function payerOf(client, sig) {
|
|
95
|
+
let tx;
|
|
96
|
+
try { tx = await client.rpc("getTransaction", [sig, { maxSupportedTransactionVersion: 1, encoding: "jsonParsed" }]); }
|
|
97
|
+
catch (e) {
|
|
98
|
+
if (isCancel(e) || !/version|invalid param/i.test(e.message || "")) throw e;
|
|
99
|
+
tx = await client.rpc("getTransaction", [sig, { maxSupportedTransactionVersion: 0, encoding: "jsonParsed" }]);
|
|
100
|
+
}
|
|
101
|
+
const keys = tx && tx.transaction && tx.transaction.message && tx.transaction.message.accountKeys;
|
|
102
|
+
const k = keys && keys[0];
|
|
103
|
+
return k ? (k.pubkey !== undefined ? k.pubkey : k) : null;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
// RugCheck's token-transfer networks with their links (who handed tokens to whom)
|
|
108
|
+
export async function transferNetworks(client, mint, supply) {
|
|
109
|
+
const g = await client.softJson(RUGCHECK + mint + "/insiders/graph", 8000);
|
|
110
|
+
if (!Array.isArray(g)) return [];
|
|
111
|
+
return g.map(function (n) {
|
|
112
|
+
const nodes = (n.nodes || []).filter(function (x) { return x && ADDRESS_RE.test(x.id || ""); })
|
|
113
|
+
.map(function (x) { return { addr: x.id, pct: supply > 0 ? Number(x.holdings || 0) / supply * 100 : 0 }; });
|
|
114
|
+
const links = (n.links || []).filter(function (l) { return l && l.source && l.target; }).map(function (l) { return [l.source, l.target]; });
|
|
115
|
+
return { type: n.network_type || "transfer", nodes: nodes, links: links };
|
|
116
|
+
}).filter(function (n) { return n.nodes.length > 1; }).sort(function (a, b) { return b.nodes.length - a.nodes.length; });
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Wallet in the networks that handed tokens to the most others
|
|
120
|
+
export function topHub(nets) {
|
|
121
|
+
let best = null;
|
|
122
|
+
nets.forEach(function (n) {
|
|
123
|
+
const out = {};
|
|
124
|
+
n.links.forEach(function (l) { out[l[0]] = (out[l[0]] || 0) + 1; });
|
|
125
|
+
Object.keys(out).forEach(function (a) { if (!best || out[a] > best.out) best = { addr: a, out: out[a] }; });
|
|
126
|
+
});
|
|
127
|
+
return best;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// Groups: sources that gave the first SOL to 2+ holders and are not exchanges. In mature tokens only
|
|
131
|
+
// people count (bots there are traders who came later, not the team's split).
|
|
132
|
+
export function mapGroups(holders, sources, mode) {
|
|
133
|
+
const by = {};
|
|
134
|
+
holders.forEach(function (h) {
|
|
135
|
+
if (!h.funder) return;
|
|
136
|
+
if (mode === "mature" && h.type !== "person") return;
|
|
137
|
+
const s = sources[h.funder];
|
|
138
|
+
if (!s || s.type === "exchange") return;
|
|
139
|
+
(by[h.funder] = by[h.funder] || []).push(h);
|
|
140
|
+
});
|
|
141
|
+
const LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
142
|
+
return Object.keys(by).filter(function (f) { return by[f].length >= 2; }).map(function (f) {
|
|
143
|
+
return { funder: f, members: by[f].map(function (h) { return h.addr; }), pct: by[f].reduce(function (s, h) { return s + h.pct; }, 0), rate: sources[f].rate };
|
|
144
|
+
}).sort(function (a, b) { return b.pct - a.pct; }).map(function (g, i) { g.id = LETTERS[i] || "G" + i; return g; });
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
export function mapSignals(m) {
|
|
148
|
+
const out = [], young = m.mode === "young", big = m.groups[0];
|
|
149
|
+
const gLimit = young ? MAP_GROUP_YOUNG : MAP_GROUP_MATURE;
|
|
150
|
+
const grouped = big && big.pct > gLimit;
|
|
151
|
+
if (grouped) out.push({ code: "MAP_GROUP", s: young ? "bad" : "warn", data: { n: big.members.length, pct: big.pct, funder: big.funder } });
|
|
152
|
+
// the group with most wallets, unless it is the one MAP_GROUP already named
|
|
153
|
+
const many = m.groups.slice().sort(function (a, b) { return b.members.length - a.members.length || b.pct - a.pct; })[0];
|
|
154
|
+
if (many && many.members.length >= MAP_SWARM && !(grouped && many === big))
|
|
155
|
+
out.push({ code: "MAP_SWARM", s: young ? "bad" : "warn", data: { n: many.members.length, of: (m.holders || []).length, pct: many.pct, funder: many.funder } });
|
|
156
|
+
if (young && m.hub && m.hub.out >= MAP_HUB) out.push({ code: "MAP_HUB", s: "bad", data: { n: m.hub.out, addr: m.hub.addr } });
|
|
157
|
+
if (!young) {
|
|
158
|
+
const w = m.holders.filter(function (h) { return h.type === "person" && h.pct > MAP_WHALE; }).sort(function (a, b) { return b.pct - a.pct; })[0];
|
|
159
|
+
if (w) out.push({ code: "MAP_WHALE", s: "warn", data: { pct: w.pct, addr: w.addr } });
|
|
160
|
+
}
|
|
161
|
+
return out;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Connection map of a token.
|
|
166
|
+
* @param [opts.createdAt] ms when its market started (DexScreener pairCreatedAt); without it RugCheck's detectedAt
|
|
167
|
+
* @param [opts.max] holders to read (default 20, or 75 with your own RPC)
|
|
168
|
+
* @param [opts.now]
|
|
169
|
+
* @returns {mint, mode, ageDays, supply, holders: [{addr, pct, type, rate, funder}], sources: {addr: {rate, type, n}},
|
|
170
|
+
* groups, nets, hub, creator, payer, signals}
|
|
171
|
+
*/
|
|
172
|
+
export async function connectionMap(client, mint, opts) {
|
|
173
|
+
opts = opts || {};
|
|
174
|
+
const onProgress = opts.onProgress, now = opts.now || Date.now();
|
|
175
|
+
if (!ADDRESS_RE.test(mint || "")) throw new ScanError("INVALID_ADDRESS", "not a Solana address");
|
|
176
|
+
const own = client.ownRpc(), max = opts.max || (own ? MAP_MAX_OWN : MAP_MAX_FREE);
|
|
177
|
+
|
|
178
|
+
// 1) holders: with your own RPC, every account of the token (up to max); otherwise the RPC's top 20
|
|
179
|
+
const b = await holderBase(client, mint, onProgress);
|
|
180
|
+
const supply = Number(b.info.supply) || 0;
|
|
181
|
+
let rows = null;
|
|
182
|
+
if (own && max > 20) {
|
|
183
|
+
const prog = b.info.program === TOKEN_2022 ? TOKEN_2022 : TOKEN_PROGRAM;
|
|
184
|
+
rows = await allHolders(client, mint, prog, max);
|
|
185
|
+
}
|
|
186
|
+
let kind = b.kind;
|
|
187
|
+
if (rows && rows.length) {
|
|
188
|
+
const missing = rows.map(function (r) { return r.owner; }).filter(function (o) { return !kind[o]; });
|
|
189
|
+
if (missing.length) kind = Object.assign({}, kind, await accountKinds(client, missing, true));
|
|
190
|
+
} else {
|
|
191
|
+
const agg = {};
|
|
192
|
+
b.largest.forEach(function (a, i) { const o = b.owners[i] || a.address; agg[o] = (agg[o] || 0) + Number(a.amount); });
|
|
193
|
+
rows = Object.keys(agg).map(function (o) { return { owner: o, raw: agg[o] }; }).sort(function (x, y) { return y.raw - x.raw; });
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// 2) age and mode
|
|
197
|
+
const rc = await rugcheckReport(client, mint);
|
|
198
|
+
const created = opts.createdAt || (rc && rc.detectedAt ? Date.parse(rc.detectedAt) : null);
|
|
199
|
+
const ageDays = created ? (now - created) / 86400000 : null;
|
|
200
|
+
const mode = ageDays !== null && ageDays < YOUNG_DAYS ? "young" : "mature";
|
|
201
|
+
|
|
202
|
+
// 3) each holder: how busy it is and who paid its first transaction
|
|
203
|
+
const holders = rows.map(function (r) { return { addr: r.owner, pct: supply > 0 ? r.raw / supply * 100 : 0, kind: kind[r.owner] || "program" }; });
|
|
204
|
+
let done = 0;
|
|
205
|
+
await pool(holders, 3, async function (h) {
|
|
206
|
+
try {
|
|
207
|
+
if (h.kind !== "program") {
|
|
208
|
+
const hs = await history(client, h.addr, mode === "young" ? 3 : 1);
|
|
209
|
+
h.rate = hs.rate;
|
|
210
|
+
const t = await mapType(client, h.addr, h.kind, hs.rate, hs.top);
|
|
211
|
+
h.type = t.type; if (t.passive) h.passive = true;
|
|
212
|
+
// in mature tokens only people are traced; exchanges never (they would join strangers)
|
|
213
|
+
let first = hs.first;
|
|
214
|
+
if (!first && mode === "mature" && h.type === "person" && hs.n >= 1000) first = (await history(client, h.addr, 3)).first;
|
|
215
|
+
if (first && h.type !== "exchange" && (mode === "young" || h.type === "person")) {
|
|
216
|
+
const p = await payerOf(client, first);
|
|
217
|
+
if (p && p !== h.addr) h.funder = p;
|
|
218
|
+
}
|
|
219
|
+
} else { h.type = "pool"; h.rate = 0; }
|
|
220
|
+
} catch (e) { if (isCancel(e)) throw e; h.type = h.type || walletType(h.kind, 0); }
|
|
221
|
+
delete h.kind;
|
|
222
|
+
done++; progress(onProgress, "funders", 0.45 + 0.35 * done / holders.length, { done: done, total: holders.length });
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
// 4) the sources: exchanges or not
|
|
226
|
+
const srcList = uniq(holders.map(function (h) { return h.funder; }).filter(Boolean));
|
|
227
|
+
const rates = await sourceRates(client, srcList, function (c, n) { progress(onProgress, "exchangeSources", 0.8 + 0.08 * c / Math.max(1, n), { done: c, total: n }); });
|
|
228
|
+
const sources = {};
|
|
229
|
+
srcList.forEach(function (s) {
|
|
230
|
+
sources[s] = { rate: rates[s] || 0, type: (rates[s] || 0) > EXCHANGE_PER_HOUR ? "exchange" : "person",
|
|
231
|
+
n: holders.filter(function (h) { return h.funder === s; }).length };
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
// 5) transfer networks, creator and who paid the launch (young tokens)
|
|
235
|
+
progress(onProgress, "networks", 0.9);
|
|
236
|
+
const nets = await transferNetworks(client, mint, supply);
|
|
237
|
+
let payer = null;
|
|
238
|
+
if (mode === "young") {
|
|
239
|
+
try { const mh = await history(client, mint, 3); if (mh.first) payer = await payerOf(client, mh.first); }
|
|
240
|
+
catch (e) { if (isCancel(e)) throw e; }
|
|
241
|
+
}
|
|
242
|
+
const m = {
|
|
243
|
+
mint: mint, mode: mode, ageDays: ageDays, supply: supply, holders: holders, sources: sources,
|
|
244
|
+
groups: mapGroups(holders, sources, mode), nets: nets, hub: topHub(nets),
|
|
245
|
+
creator: (rc && rc.creator) || null, payer: payer
|
|
246
|
+
};
|
|
247
|
+
m.signals = mapSignals(m);
|
|
248
|
+
progress(onProgress, "done", 1);
|
|
249
|
+
return m;
|
|
250
|
+
}
|
package/src/risk.js
CHANGED
|
@@ -132,7 +132,12 @@ export function buildLights(info, conc, pair, value, type, rc, now, launches) {
|
|
|
132
132
|
}
|
|
133
133
|
// Launch farms put out a token every few minutes and drop each one as soon as buyers arrive: in a
|
|
134
134
|
// 100-token Pump.fun sample one wallet launched 7 copies of "GMS" in 10 minutes
|
|
135
|
-
|
|
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
|
+
}
|
|
136
141
|
// Older launches that went nowhere: farms that spread their tokens over days escape the 24 h count
|
|
137
142
|
if (launches && launches.old >= HISTORY_MIN && launches.dead / launches.old >= HISTORY_WARN) {
|
|
138
143
|
const bad = launches.old >= HISTORY_BAD_MIN && launches.dead / launches.old >= HISTORY_BAD;
|
package/src/tokens.js
CHANGED
|
@@ -48,7 +48,8 @@ export async function getMint(client, mint) {
|
|
|
48
48
|
// transfer fee in basis points (the higher of the current and the scheduled one); null when not set
|
|
49
49
|
feeBps: feeBps(state("transferFeeConfig")),
|
|
50
50
|
// every key that controls something in the extensions (delegate, hook, pause, metadata...)
|
|
51
|
-
extKeys: extKeys(exts)
|
|
51
|
+
extKeys: extKeys(exts),
|
|
52
|
+
program: r.value.owner || null
|
|
52
53
|
};
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -114,7 +115,7 @@ export async function getConc(client, mint, supply) {
|
|
|
114
115
|
return x && x.data && x.data.parsed && x.data.parsed.info && x.data.parsed.info.owner || null;
|
|
115
116
|
});
|
|
116
117
|
if (owners.some(function (o) { return !o; })) return out;
|
|
117
|
-
const kind = await accountKinds(client, uniq(owners),
|
|
118
|
+
const kind = await accountKinds(client, uniq(owners), true); // emptied wallets (0 SOL) still count
|
|
118
119
|
const agg = {};
|
|
119
120
|
owners.forEach(function (o, i) { agg[o] = (agg[o] || 0) + amts[i]; });
|
|
120
121
|
const ws = [];
|