liqproof 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.md +536 -2
- package/bugs/README.md +144 -0
- package/bugs/coin-gecko-liquidity-report.md +283 -0
- package/bugs/collect-ds-aggregate.mjs +213 -0
- package/bugs/collect-evidence.mjs +458 -0
- package/bugs/collect-gt-aggregate.mjs +215 -0
- package/bugs/collect-raw-rpc.mjs +165 -0
- package/bugs/collect-sweep-context.mjs +162 -0
- package/bugs/dexscreener-fake-liquidity-report.md +310 -0
- package/bugs/evidence/aggregator-liquidity-claims.json +648 -0
- package/bugs/evidence/aggregator-liquidity-claims.md +103 -0
- package/bugs/evidence/bat-native-pool-drained.json +136 -0
- package/bugs/evidence/bat-native-pool-drained.md +51 -0
- package/bugs/evidence/chz-impersonator-pool-drained.json +136 -0
- package/bugs/evidence/chz-impersonator-pool-drained.md +51 -0
- package/bugs/evidence/gt-stale-reserve-after-drain.json +141 -0
- package/bugs/evidence/gt-stale-reserve-after-drain.md +31 -0
- package/bugs/evidence/raw-rpc-transcript.json +683 -0
- package/bugs/evidence/raw-rpc-transcript.md +308 -0
- package/bugs/evidence/sweep-context.json +325 -0
- package/bugs/evidence/sweep-context.md +55 -0
- package/bugs/evidence/verified-aggregate.json +526 -0
- package/bugs/evidence/verified-aggregate.md +24 -0
- package/bugs/evidence/verified-ds-liquidity-usd.json +1197 -0
- package/bugs/evidence/verified-ds-liquidity-usd.md +250 -0
- package/bugs/evidence/verified-gt-reserve-in-usd.json +1002 -0
- package/bugs/evidence/verified-gt-reserve-in-usd.md +218 -0
- package/bugs/fix-bundle-titles.mjs +72 -0
- package/bugs/geckoterminal-stale-reserve-after-drain.md +137 -0
- package/data/dataset-summary.md +103 -0
- package/data/impersonators.json +12888 -0
- package/data/verified-impersonators.json +725 -0
- package/data/wallets.json +23 -0
- package/dist/base58.js +70 -0
- package/dist/base58.js.map +1 -0
- package/dist/canonical.js +372 -0
- package/dist/canonical.js.map +1 -0
- package/dist/cli.js +830 -0
- package/dist/cli.js.map +1 -0
- package/dist/curve.js +255 -0
- package/dist/curve.js.map +1 -0
- package/dist/dashboard.js +485 -0
- package/dist/dashboard.js.map +1 -0
- package/dist/keccak.js +197 -0
- package/dist/keccak.js.map +1 -0
- package/dist/mcp.js +604 -0
- package/dist/mcp.js.map +1 -0
- package/dist/operator.js +180 -0
- package/dist/operator.js.map +1 -0
- package/dist/pda.js +86 -0
- package/dist/pda.js.map +1 -0
- package/dist/receipt.js +897 -0
- package/dist/receipt.js.map +1 -0
- package/dist/render.js +335 -0
- package/dist/render.js.map +1 -0
- package/dist/rpc.js +377 -0
- package/dist/rpc.js.map +1 -0
- package/dist/sources.js +599 -0
- package/dist/sources.js.map +1 -0
- package/dist/store.js +330 -0
- package/dist/store.js.map +1 -0
- package/dist/tokenmeta.js +424 -0
- package/dist/tokenmeta.js.map +1 -0
- package/dist/util.js +273 -0
- package/dist/util.js.map +1 -0
- package/dist/vaults.js +510 -0
- package/dist/vaults.js.map +1 -0
- package/dist/wallet.js +404 -0
- package/dist/wallet.js.map +1 -0
- package/dist/warnings.js +41 -0
- package/dist/warnings.js.map +1 -0
- package/dist/worker.js +857 -0
- package/dist/worker.js.map +1 -0
- package/dist/x402.js +549 -0
- package/dist/x402.js.map +1 -0
- package/docs/HACKATHON-SUBMISSION.md +264 -0
- package/docs/liqproof-plan.md +221 -0
- package/docs/llms.txt +32 -0
- package/docs/mcp-registry.md +165 -0
- package/docs/screenshots/01-dashboard.png +0 -0
- package/docs/screenshots/02-receipt-drained.png +0 -0
- package/docs/screenshots/03-receipt-impersonator.png +0 -0
- package/docs/screenshots/04-receipt-canonical.png +0 -0
- package/docs/x402-pricing.md +171 -0
- package/docs/zero-xyz.md +250 -0
- package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.json +1171 -0
- package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.md +52 -0
- package/out/6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw.svg +25 -0
- package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.json +3975 -0
- package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.md +90 -0
- package/out/BTNiaZb6HaEFWeEtND4SXtZ7T6mgtDwSryHTAj6PuPyp.svg +25 -0
- package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.json +1446 -0
- package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.md +66 -0
- package/out/ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85.svg +25 -0
- package/out/dataset.csv +67 -0
- package/out/impersonation-table.md +156 -0
- package/out/index.html +1179 -0
- package/package.json +78 -4
- package/scripts/assert-no-canonical-accusations.mjs +193 -0
- package/scripts/backfill.mjs +1063 -0
- package/scripts/bundle-evidence.mjs +237 -0
- package/scripts/bundle-stale-claim.mjs +417 -0
- package/scripts/capture-bch-evidence.mjs +58 -0
- package/scripts/check-orientation-fix.mjs +40 -0
- package/scripts/check-wallet.mjs +54 -0
- package/scripts/daily-refresh.mjs +451 -0
- package/scripts/decode-clmm-vaults.mjs +180 -0
- package/scripts/falsifiability.mjs +263 -0
- package/scripts/impersonator-mining.mjs +156 -0
- package/scripts/inspect-matches.mjs +73 -0
- package/scripts/operator-sweep.mjs +252 -0
- package/scripts/publish-release.mjs +248 -0
- package/scripts/refresh-store.mjs +78 -0
- package/scripts/survival-miner.mjs +951 -0
- package/scripts/test-keccak.mjs +103 -0
- package/scripts/verify-bch-1p95b.mjs +124 -0
- package/scripts/verify-clmm-1p95b.mjs +127 -0
- package/scripts/verify-clmm-control.mjs +84 -0
- package/scripts/verify-impersonators.mjs +138 -0
- package/scripts/verify-raw.mjs +110 -0
- package/scripts/verify-raw2.mjs +99 -0
- package/server.json +34 -0
- package/src/base58.ts +68 -0
- package/src/canonical.ts +447 -0
- package/src/cli.ts +941 -0
- package/src/curve.ts +349 -0
- package/src/dashboard.ts +504 -0
- package/src/keccak.ts +228 -0
- package/src/mcp.ts +735 -0
- package/src/operator.ts +219 -0
- package/src/receipt.ts +1219 -0
- package/src/render.ts +396 -0
- package/src/rpc.ts +435 -0
- package/src/sources.ts +714 -0
- package/src/store.ts +428 -0
- package/src/tokenmeta.ts +460 -0
- package/src/util.ts +276 -0
- package/src/vaults.ts +574 -0
- package/src/wallet.ts +459 -0
- package/src/warnings.ts +40 -0
- package/src/worker.ts +1086 -0
- package/src/x402.ts +717 -0
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// Evidence capture for the $1.95B drained "BCH " pool.
|
|
2
|
+
//
|
|
3
|
+
// Captures the exact GeckoTerminal payload (the aggregator's live claim) and
|
|
4
|
+
// checks whether CoinGecko maps a canonical Bitcoin Cash on Solana.
|
|
5
|
+
//
|
|
6
|
+
// Read-only.
|
|
7
|
+
const POOL = 'CEvMnd2b79GFzsxSvJntvBZyjwJvrEaXbEfUURkyHg4f';
|
|
8
|
+
const FAKE = 'ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85';
|
|
9
|
+
|
|
10
|
+
console.log('═'.repeat(100));
|
|
11
|
+
console.log('GeckoTerminal /tokens/{mint}/pools — exact attributes for our pool');
|
|
12
|
+
console.log('═'.repeat(100));
|
|
13
|
+
const r = await fetch(
|
|
14
|
+
`https://api.geckoterminal.com/api/v2/networks/solana/tokens/${FAKE}/pools?page=1`,
|
|
15
|
+
{ headers: { accept: 'application/json' } },
|
|
16
|
+
);
|
|
17
|
+
const j = await r.json();
|
|
18
|
+
for (const p of j?.data ?? []) {
|
|
19
|
+
if (p?.id?.split('_')[1] !== POOL) continue;
|
|
20
|
+
const a = p.attributes;
|
|
21
|
+
console.log(JSON.stringify(a, null, 2));
|
|
22
|
+
console.log('\nrelationships:');
|
|
23
|
+
console.log(
|
|
24
|
+
JSON.stringify(
|
|
25
|
+
{
|
|
26
|
+
base: p.relationships?.base_token?.data?.attributes,
|
|
27
|
+
quote: p.relationships?.quote_token?.data?.attributes,
|
|
28
|
+
dex: p.relationships?.dex?.data,
|
|
29
|
+
},
|
|
30
|
+
null,
|
|
31
|
+
2,
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
console.log('\n' + '═'.repeat(100));
|
|
37
|
+
console.log('CoinGecko: coins named like Bitcoin Cash');
|
|
38
|
+
console.log('═'.repeat(100));
|
|
39
|
+
const cg = await (
|
|
40
|
+
await fetch('https://api.coingecko.com/api/v3/coins/list?include_platform=true')
|
|
41
|
+
).json();
|
|
42
|
+
for (const c of cg) {
|
|
43
|
+
const name = (c.name ?? '').toLowerCase();
|
|
44
|
+
if (name.includes('bitcoin cash') || (c.symbol ?? '').toLowerCase() === 'bch') {
|
|
45
|
+
console.log(
|
|
46
|
+
` ${c.name} (${c.symbol}) id=${c.id} solana=${c.platforms?.solana ?? 'NONE'} platforms=${Object.keys(c.platforms ?? {}).join(',') || 'none'}`,
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
console.log(` total coins scanned: ${cg.length}`);
|
|
51
|
+
|
|
52
|
+
console.log('\n' + '═'.repeat(100));
|
|
53
|
+
console.log('CoinGecko /coins/bitcoin-cash — full platform map');
|
|
54
|
+
console.log('═'.repeat(100));
|
|
55
|
+
const bch = await (await fetch('https://api.coingecko.com/api/v3/coins/bitcoin-cash')).json();
|
|
56
|
+
console.log(` name ${bch?.name} symbol ${bch?.symbol} id ${bch?.id}`);
|
|
57
|
+
console.log(` platforms: ${JSON.stringify(bch?.platforms ?? {})}`);
|
|
58
|
+
console.log(` links: ${JSON.stringify(bch?.links ?? {}).slice(0, 400)}`);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
// After the orientation fix: do the canonical bluechips still look broken?
|
|
2
|
+
//
|
|
3
|
+
// Before the fix, USDT / SOL / WBTC were audited on pools where they were
|
|
4
|
+
// only the QUOTE token, so they were published as holding $0.00 — the most
|
|
5
|
+
// misleading rows in the dataset. Now we prefer a base-side pool.
|
|
6
|
+
//
|
|
7
|
+
// This prints the audited pool, its orientation, and the verdict for each.
|
|
8
|
+
//
|
|
9
|
+
// Read-only.
|
|
10
|
+
import { RpcPool } from '../dist/rpc.js';
|
|
11
|
+
import { buildReceipt } from '../dist/receipt.js';
|
|
12
|
+
|
|
13
|
+
const rpc = new RpcPool({ verbose: false });
|
|
14
|
+
|
|
15
|
+
const MINT_NAMES = {
|
|
16
|
+
'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB': 'USDT',
|
|
17
|
+
'So11111111111111111111111111111111111111112': 'SOL (wrapped)',
|
|
18
|
+
'3NZ9JMVBmGAqocybic2c7LQCJScmgsAZ6vQqTDzcqmJh': 'WBTC',
|
|
19
|
+
'ENGkoidj2jNs73A7GZuseVmnkRg6EVF9tDtViwPz8o85': 'fake "BCH "',
|
|
20
|
+
'6GmAFSYs4gk3FDao5FzzySQpPZaWsa4rUJHacpMpUNgx': 'STONK',
|
|
21
|
+
'EJFaWZHaySFmDiA5uR8eribX65aTXYUoidW6FucsMmp1': 'ELON',
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
for (const [mint, label] of Object.entries(MINT_NAMES)) {
|
|
25
|
+
try {
|
|
26
|
+
const r = await buildReceipt(rpc, mint, { includeCurve: false });
|
|
27
|
+
console.log(
|
|
28
|
+
`${label.padEnd(14)} ${r.verdict.padEnd(19)} claimed=$${r.claimed.liquidityUsd.toFixed(0).padStart(15)} deposited=$${r.real.depositedUsd.toFixed(2).padStart(14)} cov=${(r.real.coverage * 100).toFixed(4).padStart(9)}%`,
|
|
29
|
+
);
|
|
30
|
+
console.log(
|
|
31
|
+
` pool ${r.audited.pool} dex=${r.audited.dexId} orientation=${r.audited.orientation} candidates=${r.audited.candidatePools} (base-side ${r.audited.baseSidePools}) flags=${r.flags.join(',')}`,
|
|
32
|
+
);
|
|
33
|
+
console.log(
|
|
34
|
+
` sources: ${r.claimed.sources.map((s) => `${s.source}=$${s.liquidityUsd.toFixed(0)}`).join(' ')}`,
|
|
35
|
+
);
|
|
36
|
+
} catch (e) {
|
|
37
|
+
console.log(`${label.padEnd(14)} ERROR ${e.message}`);
|
|
38
|
+
}
|
|
39
|
+
await new Promise((x) => setTimeout(x, 900));
|
|
40
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
// LIQPROOF — validate a receiving wallet and show what it is ready to receive.
|
|
2
|
+
//
|
|
3
|
+
// node scripts/check-wallet.mjs <address> [--network=solana|base]
|
|
4
|
+
//
|
|
5
|
+
// WHY THIS EXISTS
|
|
6
|
+
//
|
|
7
|
+
// Before we point a bounty payout, a hackathon prize or an x402 settlement at
|
|
8
|
+
// an address, that address has to be checked — because the two mistakes that
|
|
9
|
+
// cost money are both silent:
|
|
10
|
+
//
|
|
11
|
+
// 1. the wrong network (an ERC-20 USDC sent to a Solana address is gone)
|
|
12
|
+
// 2. a typo (a base58 address is valid-looking but unreachable)
|
|
13
|
+
//
|
|
14
|
+
// A Solana address is a 32-byte ed25519 public key in base58. "Valid" means
|
|
15
|
+
// it decodes to 32 bytes AND the point is on the curve. A Solana address can
|
|
16
|
+
// be off-curve and still be a legitimate account — but a typo usually
|
|
17
|
+
// produces something that is off-curve, so we report it as a warning rather
|
|
18
|
+
// than a hard failure.
|
|
19
|
+
//
|
|
20
|
+
// node scripts/check-wallet.mjs 7ZBzZ6f1i65RzzQ3iJtQWuDXxh3WNgsmT4rVWxkrtA8w
|
|
21
|
+
//
|
|
22
|
+
// This script is now a thin wrapper over `liqproof wallet`, which is the
|
|
23
|
+
// shipped product command. An earlier version of this file carried its own
|
|
24
|
+
// copy of the base58 codec and the ed25519 curve check — and because an
|
|
25
|
+
// absolute Windows path is not a valid ES module URL, the dynamic import of
|
|
26
|
+
// the compiled sources silently failed and the fallback copy was the code
|
|
27
|
+
// that actually ran. One implementation, in one place, is worth more than a
|
|
28
|
+
// second copy that might drift.
|
|
29
|
+
//
|
|
30
|
+
// ZERO DEPENDENCIES. It reuses the project's own base58 codec and its own
|
|
31
|
+
// ed25519 implementation, because `liqproof verify` asserts that
|
|
32
|
+
// package.json has no dependencies at all.
|
|
33
|
+
//
|
|
34
|
+
// READ-ONLY. It only calls public RPC and public APIs. It never signs.
|
|
35
|
+
|
|
36
|
+
import { spawnSync } from 'node:child_process';
|
|
37
|
+
import { join, dirname } from 'node:path';
|
|
38
|
+
import { fileURLToPath } from 'node:url';
|
|
39
|
+
|
|
40
|
+
const ROOT = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
41
|
+
|
|
42
|
+
const args = process.argv.slice(2);
|
|
43
|
+
if (args.length === 0) {
|
|
44
|
+
console.error('usage: node scripts/check-wallet.mjs <address> [--network=solana|base]');
|
|
45
|
+
process.exit(2);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const result = spawnSync(
|
|
49
|
+
process.execPath,
|
|
50
|
+
[join(ROOT, 'dist', 'cli.js'), 'wallet', ...args],
|
|
51
|
+
{ stdio: 'inherit' },
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
process.exit(result.status ?? 1);
|
|
@@ -0,0 +1,451 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* daily-refresh.mjs — the cron entry point.
|
|
4
|
+
*
|
|
5
|
+
* WHAT THIS DOES
|
|
6
|
+
* 1. Re-runs the LIGHT-WEIGHT part of the backfill: the universe pull and
|
|
7
|
+
* the suspicion ranking. This is free (HTTP only) and tells us what the
|
|
8
|
+
* market is claiming today.
|
|
9
|
+
* 2. Runs ONE survival-miner sweep: every tracked pool's quote-side
|
|
10
|
+
* balance is read from the chain and compared with the last reading, so
|
|
11
|
+
* a drain that happened since the last run is caught.
|
|
12
|
+
* 3. Writes a dated snapshot to `data/snapshots/YYYY-MM-DD.json`.
|
|
13
|
+
* 4. Prints a compact DELTA report against the previous snapshot:
|
|
14
|
+
* new findings, resolved findings, changed coverage numbers.
|
|
15
|
+
*
|
|
16
|
+
* WHY THE DELTA IS THE PRODUCT
|
|
17
|
+
*
|
|
18
|
+
* A scanner that finds a fake once is a tool. A scanner that finds the
|
|
19
|
+
* same fake on day 1, day 2, day 3 — and reports that it SURVIVED the
|
|
20
|
+
* whole time — is a forensic record. The thing we sell is not "this token
|
|
21
|
+
* is fake"; it is "this claim has been false for N days and the evidence
|
|
22
|
+
* is on-chain". The delta report is where that story is told, so it is
|
|
23
|
+
* printed prominently and it explicitly calls out findings that have
|
|
24
|
+
* persisted across snapshots.
|
|
25
|
+
*
|
|
26
|
+
* COST: zero. HTTP for the universe, one RPC batch per 100 tracked pools
|
|
27
|
+
* for the sweep. The expensive per-mint receipt work is NOT repeated
|
|
28
|
+
* here — that is the backfill's job, and it is rate-limited.
|
|
29
|
+
*
|
|
30
|
+
* FLAGS
|
|
31
|
+
* --top=N how many candidates to rank (default 150)
|
|
32
|
+
* --pages=N pagination for the pool feeds (default 2)
|
|
33
|
+
* --feed=NAME universe | boosts | profiles | pools | trending | all
|
|
34
|
+
* --limit=N how many pools the survival sweep watches
|
|
35
|
+
* --out=DIR snapshot directory (default data/snapshots)
|
|
36
|
+
* --db=FILE sqlite store (default .liqproof/liqproof.db)
|
|
37
|
+
* --dry-run compute everything, write nothing
|
|
38
|
+
* --no-summary skip the dataset-summary.md update
|
|
39
|
+
*/
|
|
40
|
+
import { existsSync, mkdirSync, readdirSync, readFileSync, writeFileSync } from 'node:fs';
|
|
41
|
+
import path from 'node:path';
|
|
42
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
43
|
+
|
|
44
|
+
const HERE = path.dirname(fileURLToPath(import.meta.url));
|
|
45
|
+
const ROOT = path.resolve(HERE, '..');
|
|
46
|
+
|
|
47
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
48
|
+
|
|
49
|
+
// ── CLI ──────────────────────────────────────────────────────────────────────
|
|
50
|
+
|
|
51
|
+
function parseArgs(argv) {
|
|
52
|
+
const out = {};
|
|
53
|
+
for (const a of argv) {
|
|
54
|
+
if (!a.startsWith('--')) continue;
|
|
55
|
+
const eq = a.indexOf('=');
|
|
56
|
+
if (eq === -1) out[a.slice(2)] = true;
|
|
57
|
+
else out[a.slice(2, eq)] = a.slice(eq + 1);
|
|
58
|
+
}
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const args = parseArgs(process.argv.slice(2));
|
|
63
|
+
|
|
64
|
+
const CFG = {
|
|
65
|
+
top: Number(args.top ?? 150),
|
|
66
|
+
pages: Number(args.pages ?? 2),
|
|
67
|
+
feed: String(args.feed ?? 'all'),
|
|
68
|
+
limit: args.limit ? Number(args.limit) : undefined,
|
|
69
|
+
outDir: args.out ? path.resolve(String(args.out)) : path.join(ROOT, 'data', 'snapshots'),
|
|
70
|
+
dryRun: !!args['dry-run'],
|
|
71
|
+
summary: !args['no-summary'],
|
|
72
|
+
db: args.db ? path.resolve(String(args.db)) : path.join(ROOT, '.liqproof', 'liqproof.db'),
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function usd(n) {
|
|
76
|
+
if (!Number.isFinite(n)) return 'n/a';
|
|
77
|
+
const abs = Math.abs(n);
|
|
78
|
+
if (abs >= 1_000_000_000) return `$${(n / 1_000_000_000).toFixed(2)}B`;
|
|
79
|
+
if (abs >= 1_000_000) return `$${(n / 1_000_000).toFixed(2)}M`;
|
|
80
|
+
if (abs >= 1_000) return `$${(n / 1_000).toFixed(2)}K`;
|
|
81
|
+
if (abs >= 1) return `$${n.toFixed(2)}`;
|
|
82
|
+
return `$${n.toFixed(4)}`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function pct(n) {
|
|
86
|
+
if (!Number.isFinite(n)) return 'n/a';
|
|
87
|
+
if (n === 0) return '0%';
|
|
88
|
+
if (n < 0.0001) return `${(n * 100).toPrecision(3)}%`;
|
|
89
|
+
return `${(n * 100).toFixed(2)}%`;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ── snapshot helpers ─────────────────────────────────────────────────────────
|
|
93
|
+
|
|
94
|
+
function today() {
|
|
95
|
+
return new Date().toISOString().slice(0, 10);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function listSnapshots(dir) {
|
|
99
|
+
if (!existsSync(dir)) return [];
|
|
100
|
+
return readdirSync(dir)
|
|
101
|
+
.filter((f) => /^\d{4}-\d{2}-\d{2}\.json$/.test(f))
|
|
102
|
+
.map((f) => path.join(dir, f))
|
|
103
|
+
.sort();
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** The most recent snapshot BEFORE the one we are about to write. */
|
|
107
|
+
function previousSnapshot(dir, date) {
|
|
108
|
+
const files = listSnapshots(dir).filter((f) => path.basename(f, '.json') < date);
|
|
109
|
+
if (!files.length) return null;
|
|
110
|
+
try {
|
|
111
|
+
return JSON.parse(readFileSync(files[files.length - 1], 'utf8'));
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* A finding is a mint whose current verdict is adverse.
|
|
119
|
+
*
|
|
120
|
+
* CONSISTENT and UNKNOWN are not findings: one is a clean bill of health
|
|
121
|
+
* and the other is "we could not read enough to say anything". THIN is a
|
|
122
|
+
* fact about a pool, not an accusation, so it is reported separately.
|
|
123
|
+
*/
|
|
124
|
+
const ADVERSE = new Set(['FAKE_LIQUIDITY', 'NO_DEPTH', 'DRAINED', 'UNBACKED_LIQUIDITY']);
|
|
125
|
+
|
|
126
|
+
function findingsOf(snapshot) {
|
|
127
|
+
const map = new Map();
|
|
128
|
+
for (const r of snapshot.receipts ?? []) {
|
|
129
|
+
if (ADVERSE.has(r.verdict)) map.set(r.mint, r);
|
|
130
|
+
}
|
|
131
|
+
return map;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* The current state of every mint we know about.
|
|
136
|
+
*
|
|
137
|
+
* The sqlite store is the source of truth for verdicts, but the store lives
|
|
138
|
+
* in `.liqproof/` which is NOT committed — a CI runner starts with an empty
|
|
139
|
+
* database. So we carry forward what the previous snapshot recorded for any
|
|
140
|
+
* mint the store has not seen yet, and let the store OVERRIDE the carried
|
|
141
|
+
* value whenever it does have a verdict.
|
|
142
|
+
*
|
|
143
|
+
* The result is that a finding survives across runs even when the machine
|
|
144
|
+
* that ran them was thrown away, and a mint that the store has since
|
|
145
|
+
* resolved is correctly reported as resolved.
|
|
146
|
+
*/
|
|
147
|
+
function mergeState(storeReceipts, prevSnapshot) {
|
|
148
|
+
const byMint = new Map();
|
|
149
|
+
for (const r of prevSnapshot?.receipts ?? []) byMint.set(r.mint, { ...r, carried: true });
|
|
150
|
+
for (const r of storeReceipts) byMint.set(r.mint, { ...r, carried: false });
|
|
151
|
+
return byMint;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// ── main ─────────────────────────────────────────────────────────────────────
|
|
155
|
+
|
|
156
|
+
async function main() {
|
|
157
|
+
const started = Date.now();
|
|
158
|
+
const date = today();
|
|
159
|
+
|
|
160
|
+
console.log('▸ LIQPROOF DAILY REFRESH');
|
|
161
|
+
console.log(` date ${date} · feed=${CFG.feed} top=${CFG.top} pages=${CFG.pages}`);
|
|
162
|
+
|
|
163
|
+
const { collectUniverse } = await import('./backfill.mjs');
|
|
164
|
+
const { Store } = await import('../dist/store.js');
|
|
165
|
+
|
|
166
|
+
// ── 1. universe + ranking (free) ────────────────────────────────────────
|
|
167
|
+
let universe = { candidates: [], mintsSeen: 0, stats: {} };
|
|
168
|
+
try {
|
|
169
|
+
universe = await collectUniverse({
|
|
170
|
+
feed: CFG.feed,
|
|
171
|
+
pages: CFG.pages,
|
|
172
|
+
universeLimit: 0,
|
|
173
|
+
});
|
|
174
|
+
} catch (err) {
|
|
175
|
+
console.log(` universe pull failed: ${err.message}`);
|
|
176
|
+
}
|
|
177
|
+
console.log(` universe: ${universe.mintsSeen} mints seen · ${universe.candidates.length} candidates`);
|
|
178
|
+
|
|
179
|
+
// ── 2. survival sweep (one poll) ────────────────────────────────────────
|
|
180
|
+
let sweep = { rows: [], events: [], suddenCount: 0 };
|
|
181
|
+
const timelinePath = path.join(ROOT, 'data', 'survival-timeline.json');
|
|
182
|
+
try {
|
|
183
|
+
const miner = await import('./survival-miner.mjs');
|
|
184
|
+
const timeline = miner.readTimeline(timelinePath);
|
|
185
|
+
const rpc = new miner.MinerRpc();
|
|
186
|
+
// The limit and the output path are passed explicitly: this module is
|
|
187
|
+
// imported, not spawned, so the miner's own CLI flags never apply.
|
|
188
|
+
sweep = await miner.sweep(rpc, timeline, { limit: CFG.limit, out: timelinePath });
|
|
189
|
+
console.log(
|
|
190
|
+
` survival: ${sweep.rows.length} pools polled · ${sweep.events.length} events · ${sweep.suddenCount} sudden`,
|
|
191
|
+
);
|
|
192
|
+
} catch (err) {
|
|
193
|
+
console.log(` survival sweep failed: ${err.message}`);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// ── 3. read the store for the current state ─────────────────────────────
|
|
197
|
+
const prev = previousSnapshot(CFG.outDir, date);
|
|
198
|
+
const store = new Store(CFG.db);
|
|
199
|
+
let storeReceipts = [];
|
|
200
|
+
let survivalStats = {};
|
|
201
|
+
try {
|
|
202
|
+
storeReceipts = store.latestReceipts().map((r) => {
|
|
203
|
+
let coverage = null;
|
|
204
|
+
let claimed = null;
|
|
205
|
+
let deposited = null;
|
|
206
|
+
let symbol = '';
|
|
207
|
+
try {
|
|
208
|
+
const p = JSON.parse(r.payload);
|
|
209
|
+
coverage = Number(p.real?.coverage ?? NaN);
|
|
210
|
+
claimed = Number(p.claimed?.liquidityUsd ?? NaN);
|
|
211
|
+
deposited = Number(p.real?.depositedUsd ?? NaN);
|
|
212
|
+
symbol = p.symbol ?? '';
|
|
213
|
+
} catch {
|
|
214
|
+
/* a malformed payload must not break the refresh */
|
|
215
|
+
}
|
|
216
|
+
return {
|
|
217
|
+
mint: r.mint,
|
|
218
|
+
verdict: r.verdict,
|
|
219
|
+
generatedAt: r.generated_at,
|
|
220
|
+
symbol,
|
|
221
|
+
claimedUsd: Number.isFinite(claimed) ? claimed : null,
|
|
222
|
+
depositedUsd: Number.isFinite(deposited) ? deposited : null,
|
|
223
|
+
coverage: Number.isFinite(coverage) ? coverage : null,
|
|
224
|
+
};
|
|
225
|
+
});
|
|
226
|
+
survivalStats = store.survival();
|
|
227
|
+
} finally {
|
|
228
|
+
store.close();
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
// ── 4. snapshot ─────────────────────────────────────────────────────────
|
|
232
|
+
//
|
|
233
|
+
// The store is authoritative, but it lives in `.liqproof/` which is NOT
|
|
234
|
+
// committed — a CI runner starts with an EMPTY database. So every mint the
|
|
235
|
+
// previous snapshot recorded is carried forward, and the store overrides
|
|
236
|
+
// it wherever the store has a verdict of its own. That is what makes a
|
|
237
|
+
// finding SURVIVE a machine that was thrown away.
|
|
238
|
+
const merged = mergeState(storeReceipts, prev);
|
|
239
|
+
const receipts = [...merged.values()];
|
|
240
|
+
const prevFindings = findingsOf(prev ?? {});
|
|
241
|
+
const findings = findingsOf({ receipts });
|
|
242
|
+
|
|
243
|
+
const snapshot = {
|
|
244
|
+
date,
|
|
245
|
+
generatedAt: new Date().toISOString(),
|
|
246
|
+
durationSeconds: 0,
|
|
247
|
+
universe: {
|
|
248
|
+
mintsSeen: universe.mintsSeen,
|
|
249
|
+
candidates: universe.candidates.length,
|
|
250
|
+
sources: universe.stats?.sources ?? [],
|
|
251
|
+
dexRequests: universe.stats?.dexRequests ?? 0,
|
|
252
|
+
},
|
|
253
|
+
topCandidates: universe.candidates.slice(0, CFG.top).map((c) => ({
|
|
254
|
+
mint: c.mint,
|
|
255
|
+
pool: c.pool.address,
|
|
256
|
+
symbol: c.pool.baseTokenSymbol ?? '',
|
|
257
|
+
claimedUsd: c.claimedUsd,
|
|
258
|
+
volume24hUsd: c.volume24hUsd,
|
|
259
|
+
suspicion: c.score,
|
|
260
|
+
seeded: !!c.seeded,
|
|
261
|
+
})),
|
|
262
|
+
receipts,
|
|
263
|
+
survival: {
|
|
264
|
+
...survivalStats,
|
|
265
|
+
poolsPolled: sweep.rows.length,
|
|
266
|
+
events: sweep.events,
|
|
267
|
+
suddenEvents: sweep.suddenCount,
|
|
268
|
+
timelineRows: sweep.rows.length,
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
|
|
272
|
+
if (!CFG.dryRun) {
|
|
273
|
+
mkdirSync(CFG.outDir, { recursive: true });
|
|
274
|
+
writeFileSync(path.join(CFG.outDir, `${date}.json`), JSON.stringify(snapshot, null, 2));
|
|
275
|
+
console.log(` wrote ${path.join(CFG.outDir, `${date}.json`)}`);
|
|
276
|
+
} else {
|
|
277
|
+
console.log(' dry run — no snapshot written');
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ── 5. the DELTA report ─────────────────────────────────────────────────
|
|
281
|
+
//
|
|
282
|
+
// This is the part that makes the dataset a longitudinal product rather
|
|
283
|
+
// than a list. Every number below is a DIFFERENCE against the previous
|
|
284
|
+
// snapshot, not an absolute.
|
|
285
|
+
console.log('');
|
|
286
|
+
console.log(' LIQPROOF DAILY DELTA');
|
|
287
|
+
console.log(' ' + '─'.repeat(72));
|
|
288
|
+
|
|
289
|
+
const currentMints = new Set(receipts.map((r) => r.mint));
|
|
290
|
+
const prevMints = new Set((prev?.receipts ?? []).map((r) => r.mint));
|
|
291
|
+
|
|
292
|
+
const newFindings = [...findings.values()].filter((r) => !prevFindings.has(r.mint));
|
|
293
|
+
const resolved = [...prevFindings.values()].filter((r) => !findings.has(r.mint));
|
|
294
|
+
// "Newly audited" means the STORE produced a verdict this run that the
|
|
295
|
+
// previous snapshot did not have. Carried-forward mints are not new work.
|
|
296
|
+
const newMints = storeReceipts.filter((r) => !prevMints.has(r.mint));
|
|
297
|
+
const goneMints = [...prevMints].filter((m) => !currentMints.has(m));
|
|
298
|
+
|
|
299
|
+
// Coverage changes for mints that are in BOTH snapshots.
|
|
300
|
+
const prevByMint = new Map((prev?.receipts ?? []).map((r) => [r.mint, r]));
|
|
301
|
+
const coverageChanges = [];
|
|
302
|
+
for (const r of receipts) {
|
|
303
|
+
const before = prevByMint.get(r.mint);
|
|
304
|
+
if (!before) continue;
|
|
305
|
+
const a = before.coverage ?? 0;
|
|
306
|
+
const b = r.coverage ?? 0;
|
|
307
|
+
if (!Number.isFinite(a) || !Number.isFinite(b)) continue;
|
|
308
|
+
const delta = b - a;
|
|
309
|
+
if (Math.abs(delta) < 1e-9) continue;
|
|
310
|
+
coverageChanges.push({ mint: r.mint, symbol: r.symbol, before: a, after: b, delta });
|
|
311
|
+
}
|
|
312
|
+
coverageChanges.sort((x, y) => Math.abs(y.delta) - Math.abs(x.delta));
|
|
313
|
+
|
|
314
|
+
console.log(` findings now ${findings.size}`);
|
|
315
|
+
console.log(` findings previous ${prevFindings.size}`);
|
|
316
|
+
console.log(` NEW findings ${newFindings.length}`);
|
|
317
|
+
console.log(` resolved findings ${resolved.length}`);
|
|
318
|
+
console.log(` newly audited mints ${newMints.length}`);
|
|
319
|
+
console.log(` mints no longer stored ${goneMints.length}`);
|
|
320
|
+
console.log(` coverage changes ${coverageChanges.length}`);
|
|
321
|
+
|
|
322
|
+
if (newFindings.length) {
|
|
323
|
+
console.log('');
|
|
324
|
+
console.log(' NEW FINDINGS');
|
|
325
|
+
for (const r of newFindings.slice(0, 12)) {
|
|
326
|
+
console.log(
|
|
327
|
+
` + ${r.verdict.padEnd(18)} ${(r.symbol || r.mint.slice(0, 14)).padEnd(14).slice(0, 14)} claimed ${usd(r.claimedUsd).padStart(11)} deposited ${usd(r.depositedUsd).padStart(11)}`,
|
|
328
|
+
);
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
if (resolved.length) {
|
|
333
|
+
console.log('');
|
|
334
|
+
console.log(' RESOLVED (no longer adverse)');
|
|
335
|
+
for (const r of resolved.slice(0, 12)) {
|
|
336
|
+
console.log(
|
|
337
|
+
` - ${r.verdict.padEnd(18)} ${(r.symbol || r.mint.slice(0, 14)).padEnd(14).slice(0, 14)} claimed ${usd(r.claimedUsd).padStart(11)} deposited ${usd(r.depositedUsd).padStart(11)}`,
|
|
338
|
+
);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
if (coverageChanges.length) {
|
|
343
|
+
console.log('');
|
|
344
|
+
console.log(' COVERAGE CHANGES');
|
|
345
|
+
for (const c of coverageChanges.slice(0, 12)) {
|
|
346
|
+
const dir = c.delta < 0 ? '▼' : '▲';
|
|
347
|
+
console.log(
|
|
348
|
+
` ${dir} ${(c.symbol || c.mint.slice(0, 14)).padEnd(14).slice(0, 14)} ${pct(c.before).padStart(11)} → ${pct(c.after).padStart(11)} (${c.delta >= 0 ? '+' : ''}${(c.delta * 100).toPrecision(3)} pts)`,
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
// ── 6. SURVIVAL — the longitudinal selling point ────────────────────────
|
|
354
|
+
//
|
|
355
|
+
// A finding that has been observed on N consecutive days is not a scan
|
|
356
|
+
// result; it is a record. We count how many snapshots in a row each
|
|
357
|
+
// finding has appeared in, and we say so out loud.
|
|
358
|
+
const snapshotFiles = listSnapshots(CFG.outDir);
|
|
359
|
+
const streak = new Map(); // mint -> number of consecutive snapshots
|
|
360
|
+
if (snapshotFiles.length) {
|
|
361
|
+
const ordered = snapshotFiles
|
|
362
|
+
.map((f) => {
|
|
363
|
+
try {
|
|
364
|
+
return JSON.parse(readFileSync(f, 'utf8'));
|
|
365
|
+
} catch {
|
|
366
|
+
return null;
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
.filter(Boolean);
|
|
370
|
+
// Walk backwards so a finding present in every snapshot counts them all.
|
|
371
|
+
for (const snap of ordered) {
|
|
372
|
+
for (const r of snap.receipts ?? []) {
|
|
373
|
+
if (!ADVERSE.has(r.verdict)) continue;
|
|
374
|
+
streak.set(r.mint, (streak.get(r.mint) ?? 0) + 1);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
const persistent = [...findings.values()]
|
|
379
|
+
.map((r) => ({ ...r, days: streak.get(r.mint) ?? 1 }))
|
|
380
|
+
.filter((r) => r.days > 1)
|
|
381
|
+
.sort((a, b) => b.days - a.days || (b.claimedUsd ?? 0) - (a.claimedUsd ?? 0));
|
|
382
|
+
|
|
383
|
+
console.log('');
|
|
384
|
+
console.log(' SURVIVAL — findings that persist across snapshots');
|
|
385
|
+
if (!persistent.length) {
|
|
386
|
+
console.log(' (none yet — this is the first snapshot, or every finding is new)');
|
|
387
|
+
} else {
|
|
388
|
+
const longest = persistent[0].days;
|
|
389
|
+
console.log(
|
|
390
|
+
` ${persistent.length} finding(s) observed on more than one snapshot · longest run ${longest} snapshot(s)`,
|
|
391
|
+
);
|
|
392
|
+
for (const r of persistent.slice(0, 12)) {
|
|
393
|
+
console.log(
|
|
394
|
+
` ▪ ${String(r.days).padStart(3)}× ${r.verdict.padEnd(18)} ${(r.symbol || r.mint.slice(0, 14)).padEnd(14).slice(0, 14)} claimed ${usd(r.claimedUsd).padStart(11)} deposited ${usd(r.depositedUsd).padStart(11)}`,
|
|
395
|
+
);
|
|
396
|
+
}
|
|
397
|
+
console.log(
|
|
398
|
+
` These claims have been false for ${longest} consecutive snapshot(s). The evidence is on-chain and reproducible.`,
|
|
399
|
+
);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
// ── 7. the summary file ─────────────────────────────────────────────────
|
|
403
|
+
//
|
|
404
|
+
// The daily refresh APPENDS a dated entry to `data/dataset-summary.md`;
|
|
405
|
+
// it never rewrites the backfill's section, so both scripts can run in
|
|
406
|
+
// any order, any number of times, without destroying each other's work.
|
|
407
|
+
if (CFG.summary && !CFG.dryRun) {
|
|
408
|
+
try {
|
|
409
|
+
const { appendRefreshSummary } = await import('./backfill.mjs');
|
|
410
|
+
appendRefreshSummary({
|
|
411
|
+
date,
|
|
412
|
+
findings: findings.size,
|
|
413
|
+
prevFindings: prevFindings.size,
|
|
414
|
+
newFindings: newFindings.length,
|
|
415
|
+
resolvedFindings: resolved.length,
|
|
416
|
+
newMints: newMints.length,
|
|
417
|
+
coverageChanges: coverageChanges.length,
|
|
418
|
+
poolsPolled: sweep.rows.length,
|
|
419
|
+
events: sweep.events.length,
|
|
420
|
+
sudden: sweep.suddenCount,
|
|
421
|
+
persistent: persistent.length,
|
|
422
|
+
longest: persistent[0]?.days ?? 1,
|
|
423
|
+
newFindingRows: newFindings.slice(0, 10),
|
|
424
|
+
});
|
|
425
|
+
console.log('');
|
|
426
|
+
console.log(' appended the daily entry to data/dataset-summary.md');
|
|
427
|
+
} catch (err) {
|
|
428
|
+
console.log(` summary update failed: ${err.message}`);
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
snapshot.durationSeconds = (Date.now() - started) / 1000;
|
|
433
|
+
if (!CFG.dryRun) {
|
|
434
|
+
writeFileSync(path.join(CFG.outDir, `${date}.json`), JSON.stringify(snapshot, null, 2));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
console.log('');
|
|
438
|
+
console.log(` done in ${snapshot.durationSeconds.toFixed(1)}s`);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
const invokedDirectly =
|
|
442
|
+
process.argv[1] && pathToFileURL(path.resolve(process.argv[1])).href === import.meta.url;
|
|
443
|
+
|
|
444
|
+
if (invokedDirectly) {
|
|
445
|
+
main().catch((err) => {
|
|
446
|
+
console.error(`\n fatal: ${err?.stack ?? err}`);
|
|
447
|
+
process.exit(1);
|
|
448
|
+
});
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export { main, listSnapshots, previousSnapshot, findingsOf };
|