solana-risk-engine 0.7.1 → 0.7.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/package.json +1 -1
- package/src/markets.js +44 -16
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "solana-risk-engine",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
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/markets.js
CHANGED
|
@@ -83,27 +83,55 @@ export async function copiesOf(client, mint, pair, now) {
|
|
|
83
83
|
return { n: others.length, original: oldest.addr, days: Math.floor(((now || Date.now()) - oldest.at) / 86400000), origLiq: oldest.liq, liq: mine.liq };
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
-
//
|
|
86
|
+
// Up to this many tokens, each one gets its own request for all its pools (token-pairs/v1, 4 at a time).
|
|
87
|
+
// The batch request (tokens/v1) returns a single pool per token, not always the deepest: measured
|
|
88
|
+
// 22/11/2026 on 99 tokens, 15 came out with a much smaller pool (RUSH $0.6M instead of $42M).
|
|
89
|
+
// Bigger lists (a wallet with hundreds of tokens) stay on the batch request to respect DexScreener's limits.
|
|
90
|
+
export const PAIRS_MAX = 30;
|
|
91
|
+
|
|
92
|
+
// Best (most liquid) DexScreener pair per mint.
|
|
87
93
|
// `failed` lists mints whose batch failed: unknown, which is not the same as "no market".
|
|
88
94
|
export async function getMarkets(client, mints, onStep) {
|
|
89
95
|
const best = {};
|
|
90
96
|
let failed = [];
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
const
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
97
|
+
const keep = function (m, p) {
|
|
98
|
+
realLiq(p);
|
|
99
|
+
const liq = (p.liquidity && p.liquidity.usd) || 0;
|
|
100
|
+
const cur = best[m] && best[m].liquidity && best[m].liquidity.usd || 0;
|
|
101
|
+
if (!best[m] || liq > cur) best[m] = p;
|
|
102
|
+
};
|
|
103
|
+
if (mints.length <= PAIRS_MAX) {
|
|
104
|
+
let next = 0, done = 0;
|
|
105
|
+
const worker = async function () {
|
|
106
|
+
while (next < mints.length) {
|
|
107
|
+
const m = mints[next++];
|
|
108
|
+
try {
|
|
109
|
+
const pares = await client.jfetch(DEX_PAIRS + m);
|
|
110
|
+
if (Array.isArray(pares)) pares.forEach(function (p) {
|
|
111
|
+
if (p && p.baseToken && p.baseToken.address === m && (!p.chainId || p.chainId === "solana")) keep(m, p);
|
|
112
|
+
});
|
|
113
|
+
} catch (e) { if (isCancel(e)) throw e; }
|
|
114
|
+
done++;
|
|
115
|
+
if (onStep && done < mints.length) onStep(done, mints.length);
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
await Promise.all([worker(), worker(), worker(), worker()].slice(0, Math.min(4, mints.length)));
|
|
119
|
+
// what got no answer (or no market) goes once more through the batch request
|
|
120
|
+
const rest = mints.filter(function (m) { return !best[m]; });
|
|
121
|
+
if (!rest.length) { if (onStep && mints.length) onStep(mints.length, mints.length); return { data: best, failed: failed }; }
|
|
122
|
+
const again = await batchMarkets(client, rest);
|
|
123
|
+
Object.keys(again.data).forEach(function (m) { best[m] = again.data[m]; });
|
|
124
|
+
if (onStep) onStep(mints.length, mints.length);
|
|
125
|
+
return { data: best, failed: again.failed };
|
|
106
126
|
}
|
|
127
|
+
const r = await batchMarkets(client, mints, onStep);
|
|
128
|
+
return r;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
// 30 mints per request (tokens/v1)
|
|
132
|
+
async function batchMarkets(client, mints, onStep) {
|
|
133
|
+
const best = {};
|
|
134
|
+
let failed = [];
|
|
107
135
|
for (let i = 0; i < mints.length; i += 30) {
|
|
108
136
|
const lote = mints.slice(i, i + 30);
|
|
109
137
|
try {
|