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
package/dist/cli.js
ADDED
|
@@ -0,0 +1,830 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* liqproof CLI
|
|
4
|
+
*
|
|
5
|
+
* liqproof receipt <mint> [--json] [--no-curve] [--txs=600] [--save]
|
|
6
|
+
* liqproof scan [--limit=50] [--curve] mine new pools, build receipts
|
|
7
|
+
* liqproof survival [--days=7,30] survival statistics
|
|
8
|
+
* liqproof timeline <mint> print the liquidity curve
|
|
9
|
+
* liqproof export dashboard + CSV → out/
|
|
10
|
+
* liqproof mcp MCP server on stdio
|
|
11
|
+
* liqproof doctor check every free endpoint
|
|
12
|
+
* liqproof wallet <address> validate a receiving address
|
|
13
|
+
* liqproof serve local HTTP server (x402)
|
|
14
|
+
* liqproof x402 <mint> print the 402 challenge
|
|
15
|
+
*
|
|
16
|
+
* READ-ONLY BY CONSTRUCTION: this codebase contains no transaction-signing
|
|
17
|
+
* or transaction-submission path. The `liqproof verify` command greps every
|
|
18
|
+
* file under src/ for the forbidden markers and must keep passing — so avoid
|
|
19
|
+
* those literal strings even in comments in src/.
|
|
20
|
+
*/
|
|
21
|
+
import './warnings.js';
|
|
22
|
+
import { writeFileSync, mkdirSync } from 'node:fs';
|
|
23
|
+
import { RpcPool } from './rpc.js';
|
|
24
|
+
import { buildReceipt } from './receipt.js';
|
|
25
|
+
import { renderMarkdown, renderSvgCard, renderTerminal } from './render.js';
|
|
26
|
+
import { Store } from './store.js';
|
|
27
|
+
import { coingeckoTopSolanaTokens, dexscreenerDiscovery, dexscreenerPairs, dexscreenerPairsBatch, geckoTerminalNewPools, geckoTerminalTopPools, geckoTerminalTrendingPools, isMajorMint, jupiterQuote, tokenReport, MINT, } from './sources.js';
|
|
28
|
+
import { buildDashboard } from './dashboard.js';
|
|
29
|
+
import { inspectWallet } from './wallet.js';
|
|
30
|
+
import { c, usd, fetchJson, DiskCache } from './util.js';
|
|
31
|
+
const VERSION = '0.1.0';
|
|
32
|
+
function arg(name, fallback) {
|
|
33
|
+
const hit = process.argv.find((a) => a === `--${name}` || a.startsWith(`--${name}=`));
|
|
34
|
+
if (!hit)
|
|
35
|
+
return fallback;
|
|
36
|
+
const eq = hit.indexOf('=');
|
|
37
|
+
return eq === -1 ? 'true' : hit.slice(eq + 1);
|
|
38
|
+
}
|
|
39
|
+
const has = (name) => process.argv.includes(`--${name}`);
|
|
40
|
+
function makeRpc(verbose = false) {
|
|
41
|
+
return new RpcPool({
|
|
42
|
+
verbose,
|
|
43
|
+
onEvent: (e) => {
|
|
44
|
+
if (!verbose)
|
|
45
|
+
return;
|
|
46
|
+
if (e.kind === 'rotate')
|
|
47
|
+
console.error(c.yellow(` rpc: rotate ${e.endpoint} (${e.reason})`));
|
|
48
|
+
if (e.kind === 'error')
|
|
49
|
+
console.error(c.red(` rpc: error ${e.method} ${e.error.slice(0, 80)}`));
|
|
50
|
+
if (e.kind === 'throttle')
|
|
51
|
+
console.error(c.gray(` rpc: throttle ${e.method} ${e.waitMs}ms`));
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/** Accept a raw mint, a DexScreener URL, a Solscan URL, or a mint with typos. */
|
|
56
|
+
function extractMint(input) {
|
|
57
|
+
const raw = input.trim();
|
|
58
|
+
const patterns = [
|
|
59
|
+
/\/token\/([1-9A-HJ-NP-Za-km-z]{32,44})/,
|
|
60
|
+
/\/address\/([1-9A-HJ-NP-Za-km-z]{32,44})/,
|
|
61
|
+
/\/tx\/([1-9A-HJ-NP-Za-km-z]{64})/,
|
|
62
|
+
/([1-9A-HJ-NP-Za-km-z]{32,44})/,
|
|
63
|
+
];
|
|
64
|
+
for (const p of patterns) {
|
|
65
|
+
const m = raw.match(p);
|
|
66
|
+
if (m)
|
|
67
|
+
return m[1];
|
|
68
|
+
}
|
|
69
|
+
return raw;
|
|
70
|
+
}
|
|
71
|
+
async function cmdReceipt() {
|
|
72
|
+
const target = process.argv[3];
|
|
73
|
+
if (!target) {
|
|
74
|
+
console.error(c.red('usage: liqproof receipt <mint-or-url> [--json] [--no-curve] [--txs=N] [--save]'));
|
|
75
|
+
process.exit(1);
|
|
76
|
+
}
|
|
77
|
+
const mint = extractMint(target);
|
|
78
|
+
const rpc = makeRpc(has('verbose'));
|
|
79
|
+
const store = new Store(arg('db') ?? '.liqproof/liqproof.db');
|
|
80
|
+
const txs = Number(arg('txs', '600'));
|
|
81
|
+
console.error(c.gray(` auditing ${mint} …`));
|
|
82
|
+
const receipt = await buildReceipt(rpc, mint, {
|
|
83
|
+
includeCurve: !has('no-curve'),
|
|
84
|
+
maxTransactions: txs,
|
|
85
|
+
verbose: has('verbose'),
|
|
86
|
+
});
|
|
87
|
+
if (has('json')) {
|
|
88
|
+
console.log(JSON.stringify(receipt, null, 2));
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
console.log(renderTerminal(receipt));
|
|
92
|
+
}
|
|
93
|
+
store.upsertToken({
|
|
94
|
+
mint,
|
|
95
|
+
symbol: receipt.symbol,
|
|
96
|
+
first_seen: Math.floor(Date.now() / 1000),
|
|
97
|
+
last_seen: Math.floor(Date.now() / 1000),
|
|
98
|
+
verdict: receipt.verdict,
|
|
99
|
+
claimed_usd: receipt.claimed.liquidityUsd,
|
|
100
|
+
deposited_usd: receipt.real.depositedUsd,
|
|
101
|
+
coverage: receipt.real.coverage,
|
|
102
|
+
price_impact: receipt.oracle.buyQuote?.priceImpactPct,
|
|
103
|
+
});
|
|
104
|
+
for (const p of receipt.pools) {
|
|
105
|
+
store.upsertPool(p.pool, mint, p.dexId, p.claimedLiquidityUsd, p.realQuoteUsd);
|
|
106
|
+
if (receipt.real.drainSignature) {
|
|
107
|
+
store.insertEvent({
|
|
108
|
+
mint,
|
|
109
|
+
pool: p.pool,
|
|
110
|
+
slot: receipt.real.drainSlot ?? 0,
|
|
111
|
+
ts: receipt.real.drainAt ? Math.floor(Date.parse(receipt.real.drainAt) / 1000) : null,
|
|
112
|
+
signature: receipt.real.drainSignature,
|
|
113
|
+
kind: 'LIQUIDITY_REMOVED',
|
|
114
|
+
delta_usd: receipt.real.drainDeltaUsd ?? 0,
|
|
115
|
+
deposited_usd: p.realQuoteUsd,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
store.saveReceipt(mint, receipt.generatedAt, receipt.verdict, JSON.stringify(receipt));
|
|
120
|
+
if (has('save')) {
|
|
121
|
+
mkdirSync('out', { recursive: true });
|
|
122
|
+
writeFileSync(`out/${mint}.json`, JSON.stringify(receipt, null, 2));
|
|
123
|
+
writeFileSync(`out/${mint}.md`, renderMarkdown(receipt));
|
|
124
|
+
writeFileSync(`out/${mint}.svg`, renderSvgCard(receipt));
|
|
125
|
+
console.error(c.green(` saved out/${mint}.{json,md,svg}`));
|
|
126
|
+
}
|
|
127
|
+
store.close();
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Mine pools and audit them.
|
|
131
|
+
*
|
|
132
|
+
* THE FEED IS THE PRODUCT.
|
|
133
|
+
*
|
|
134
|
+
* We tried the obvious ones first and measured them:
|
|
135
|
+
*
|
|
136
|
+
* - `new_pools` — a pool created ten seconds ago still reports
|
|
137
|
+
* `reserve_in_usd = 0`. There is no claim to falsify.
|
|
138
|
+
* - `top_pools` — GeckoTerminal's curated popularity list. We checked
|
|
139
|
+
* ten pages deep: every pool on it is a bluechip with
|
|
140
|
+
* real money in it. A sweep over this feed can only
|
|
141
|
+
* ever return zero findings.
|
|
142
|
+
*
|
|
143
|
+
* What actually works is DexScreener's BOOST feed. A token that pays for a
|
|
144
|
+
* DexScreener boost needs a large liquidity number to make the promoted
|
|
145
|
+
* card look good — so the population of boosted tokens is structurally
|
|
146
|
+
* enriched with tokens whose advertised liquidity is inflated. That is the
|
|
147
|
+
* population a receipt can expose, and it is blind: we do not need to know
|
|
148
|
+
* the token in advance.
|
|
149
|
+
*/
|
|
150
|
+
async function cmdScan() {
|
|
151
|
+
const limit = Number(arg('limit', '25'));
|
|
152
|
+
const minClaimed = Number(arg('min-claimed', '10000'));
|
|
153
|
+
const pages = Number(arg('pages', '2'));
|
|
154
|
+
const feedArg = arg('feed', 'boosts');
|
|
155
|
+
const rpc = makeRpc(has('verbose'));
|
|
156
|
+
const store = new Store(arg('db') ?? '.liqproof/liqproof.db');
|
|
157
|
+
// ── Stage 1: collect candidate pools ─────────────────────────────────────
|
|
158
|
+
//
|
|
159
|
+
// A candidate is (mint, pool, claim). Discovery feeds give us a mint; the
|
|
160
|
+
// pool and its claim come from that token's DexScreener pair list.
|
|
161
|
+
const candidates = new Map();
|
|
162
|
+
const discoveryFeeds = [
|
|
163
|
+
['boosts', 'boosts_top'],
|
|
164
|
+
['boosts_new', 'boosts_latest'],
|
|
165
|
+
['profiles', 'profiles_latest'],
|
|
166
|
+
];
|
|
167
|
+
const useDiscovery = feedArg === 'boosts' || feedArg === 'profiles' || feedArg === 'all';
|
|
168
|
+
const usePools = feedArg === 'pools' || feedArg === 'trending' || feedArg === 'all';
|
|
169
|
+
const useUniverse = feedArg === 'universe' || feedArg === 'all';
|
|
170
|
+
// ── Stage 1b: the blind universe ─────────────────────────────────────────
|
|
171
|
+
//
|
|
172
|
+
// CoinGecko's whole coin list + DexScreener's 30-address batch call give
|
|
173
|
+
// us the top of the market in three HTTP requests. We then rank by
|
|
174
|
+
// SUSPICION, not by size:
|
|
175
|
+
//
|
|
176
|
+
// suspicion = claimed_liquidity / (24h_volume + floor)
|
|
177
|
+
//
|
|
178
|
+
// A pool that advertises $38,000,000 and traded $1,761 in the last day
|
|
179
|
+
// is 21,000× more suspicious than one that advertises the same and traded
|
|
180
|
+
// $18,500,000. That single ratio is what turned a sweep that found
|
|
181
|
+
// nothing into a sweep that finds the traps.
|
|
182
|
+
if (useUniverse) {
|
|
183
|
+
try {
|
|
184
|
+
const tokens = await coingeckoTopSolanaTokens(pages);
|
|
185
|
+
const mints = tokens.map((t) => t.mint);
|
|
186
|
+
const pairs = await dexscreenerPairsBatch(mints);
|
|
187
|
+
const bestByMint = new Map();
|
|
188
|
+
for (const p of pairs) {
|
|
189
|
+
const mint = p.baseTokenAddress;
|
|
190
|
+
if (!mint || isMajorMint(mint))
|
|
191
|
+
continue;
|
|
192
|
+
const cur = bestByMint.get(mint);
|
|
193
|
+
if (!cur || p.reportedLiquidityUsd > cur.reportedLiquidityUsd)
|
|
194
|
+
bestByMint.set(mint, p);
|
|
195
|
+
}
|
|
196
|
+
const scored = [...bestByMint.values()].map((p) => ({
|
|
197
|
+
p,
|
|
198
|
+
score: p.reportedLiquidityUsd / Math.max(p.reportedVolume24hUsd, 1000),
|
|
199
|
+
}));
|
|
200
|
+
scored.sort((a, b) => b.score - a.score);
|
|
201
|
+
const picked = scored
|
|
202
|
+
.filter((s) => s.p.reportedLiquidityUsd >= minClaimed)
|
|
203
|
+
.slice(0, limit);
|
|
204
|
+
console.error(c.gray(` feed universe ${tokens.length} Solana coins · ${pairs.length} pools · ${picked.length} suspects (claim ÷ volume)`));
|
|
205
|
+
for (const s of picked) {
|
|
206
|
+
if (candidates.has(s.p.baseTokenAddress))
|
|
207
|
+
continue;
|
|
208
|
+
candidates.set(s.p.baseTokenAddress, { mint: s.p.baseTokenAddress, pool: s.p });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
catch (err) {
|
|
212
|
+
console.error(c.yellow(` feed universe failed: ${err.message.slice(0, 70)}`));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
if (useDiscovery) {
|
|
216
|
+
const wanted = feedArg === 'profiles'
|
|
217
|
+
? [['profiles', 'profiles_latest']]
|
|
218
|
+
: feedArg === 'all'
|
|
219
|
+
? discoveryFeeds
|
|
220
|
+
: discoveryFeeds.slice(0, 2);
|
|
221
|
+
for (const [name, feed] of wanted) {
|
|
222
|
+
try {
|
|
223
|
+
const tokens = await dexscreenerDiscovery(feed);
|
|
224
|
+
console.error(c.gray(` feed ${name.padEnd(9)} ${String(tokens.length).padStart(3)} tokens`));
|
|
225
|
+
for (const t of tokens) {
|
|
226
|
+
if (t.chainId && t.chainId !== 'solana')
|
|
227
|
+
continue;
|
|
228
|
+
if (isMajorMint(t.mint))
|
|
229
|
+
continue;
|
|
230
|
+
if (candidates.has(t.mint))
|
|
231
|
+
continue;
|
|
232
|
+
// One DexScreener call tells us every pool of this token and what
|
|
233
|
+
// each one claims. We keep the biggest claim: that is the number
|
|
234
|
+
// a buyer would have seen.
|
|
235
|
+
const pairs = await dexscreenerPairs(t.mint);
|
|
236
|
+
const best = pairs[0];
|
|
237
|
+
if (!best)
|
|
238
|
+
continue;
|
|
239
|
+
if (best.reportedLiquidityUsd < minClaimed)
|
|
240
|
+
continue;
|
|
241
|
+
candidates.set(t.mint, { mint: t.mint, pool: best });
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
catch (err) {
|
|
245
|
+
console.error(c.yellow(` feed ${name} failed: ${err.message.slice(0, 60)}`));
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
if (usePools) {
|
|
250
|
+
const poolFeeds = [
|
|
251
|
+
['top', async () => {
|
|
252
|
+
const out = [];
|
|
253
|
+
for (let p = 1; p <= pages; p++)
|
|
254
|
+
out.push(...(await geckoTerminalTopPools(p)));
|
|
255
|
+
return out;
|
|
256
|
+
}],
|
|
257
|
+
['trending', async () => {
|
|
258
|
+
const out = [];
|
|
259
|
+
for (let p = 1; p <= Math.max(1, Math.floor(pages / 2)); p++) {
|
|
260
|
+
out.push(...(await geckoTerminalTrendingPools(p)));
|
|
261
|
+
}
|
|
262
|
+
return out;
|
|
263
|
+
}],
|
|
264
|
+
['new', async () => geckoTerminalNewPools(1)],
|
|
265
|
+
];
|
|
266
|
+
for (const [name, fn] of poolFeeds) {
|
|
267
|
+
try {
|
|
268
|
+
const pools = await fn();
|
|
269
|
+
let added = 0;
|
|
270
|
+
for (const p of pools) {
|
|
271
|
+
if (!p.baseTokenAddress || candidates.has(p.baseTokenAddress))
|
|
272
|
+
continue;
|
|
273
|
+
if (isMajorMint(p.baseTokenAddress))
|
|
274
|
+
continue;
|
|
275
|
+
if (p.reportedLiquidityUsd < minClaimed)
|
|
276
|
+
continue;
|
|
277
|
+
candidates.set(p.baseTokenAddress, { mint: p.baseTokenAddress, pool: p });
|
|
278
|
+
added++;
|
|
279
|
+
}
|
|
280
|
+
console.error(c.gray(` feed ${name.padEnd(9)} ${String(pools.length).padStart(3)} pools · ${added} above $${minClaimed.toLocaleString()}`));
|
|
281
|
+
}
|
|
282
|
+
catch (err) {
|
|
283
|
+
console.error(c.yellow(` feed ${name} failed: ${err.message.slice(0, 60)}`));
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
const poolList = [...candidates.values()]
|
|
288
|
+
.sort((a, b) => b.pool.reportedLiquidityUsd - a.pool.reportedLiquidityUsd)
|
|
289
|
+
.slice(0, limit);
|
|
290
|
+
console.error(c.gray(` auditing ${poolList.length} pools …\n`));
|
|
291
|
+
let audited = 0;
|
|
292
|
+
let unknown = 0;
|
|
293
|
+
let flagged = 0;
|
|
294
|
+
let thin = 0;
|
|
295
|
+
for (const cand of poolList) {
|
|
296
|
+
const p = cand.pool;
|
|
297
|
+
const mint = cand.mint;
|
|
298
|
+
process.stdout.write(c.gray(` ${String(audited + 1).padStart(3)}. ${(p.baseTokenSymbol || p.name || mint.slice(0, 16)).padEnd(22).slice(0, 22)} `));
|
|
299
|
+
try {
|
|
300
|
+
// Audit the EXACT pool we mined, not the token's biggest pool.
|
|
301
|
+
const receipt = await buildReceipt(rpc, mint, {
|
|
302
|
+
includeCurve: has('curve'),
|
|
303
|
+
maxTransactions: Number(arg('txs', '120')),
|
|
304
|
+
focusPool: p.address,
|
|
305
|
+
focusPoolData: p,
|
|
306
|
+
});
|
|
307
|
+
const verdictColor = receipt.verdict === 'CONSISTENT'
|
|
308
|
+
? c.green
|
|
309
|
+
: receipt.verdict === 'UNKNOWN'
|
|
310
|
+
? c.gray
|
|
311
|
+
: receipt.verdict === 'THIN'
|
|
312
|
+
? c.yellow
|
|
313
|
+
: c.red;
|
|
314
|
+
console.log(`${verdictColor(receipt.verdict.padEnd(15))} claimed=${usd(receipt.claimed.liquidityUsd).padStart(12)} deposited=${usd(receipt.real.depositedUsd).padStart(12)} cov=${(receipt.real.coverage * 100).toFixed(4)}%`);
|
|
315
|
+
if (receipt.verdict === 'UNKNOWN')
|
|
316
|
+
unknown++;
|
|
317
|
+
else if (receipt.verdict === 'THIN')
|
|
318
|
+
thin++;
|
|
319
|
+
else if (receipt.verdict !== 'CONSISTENT')
|
|
320
|
+
flagged++;
|
|
321
|
+
store.upsertToken({
|
|
322
|
+
mint,
|
|
323
|
+
symbol: receipt.symbol,
|
|
324
|
+
first_seen: Math.floor(Date.now() / 1000),
|
|
325
|
+
last_seen: Math.floor(Date.now() / 1000),
|
|
326
|
+
verdict: receipt.verdict,
|
|
327
|
+
claimed_usd: receipt.claimed.liquidityUsd,
|
|
328
|
+
deposited_usd: receipt.real.depositedUsd,
|
|
329
|
+
coverage: receipt.real.coverage,
|
|
330
|
+
price_impact: receipt.oracle.buyQuote?.priceImpactPct,
|
|
331
|
+
});
|
|
332
|
+
store.upsertPool(p.address, mint, p.dexId, receipt.claimed.liquidityUsd, receipt.real.depositedUsd);
|
|
333
|
+
store.saveReceipt(mint, receipt.generatedAt, receipt.verdict, JSON.stringify(receipt));
|
|
334
|
+
audited++;
|
|
335
|
+
}
|
|
336
|
+
catch (err) {
|
|
337
|
+
console.log(c.red(`ERROR ${err.message.slice(0, 60)}`));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
console.error(c.gray(`\n audited ${audited} pools · ${flagged} adverse · ${thin} thin · ${unknown} unknown · store: ${JSON.stringify(store.counts())}`));
|
|
341
|
+
store.close();
|
|
342
|
+
}
|
|
343
|
+
async function cmdSurvival() {
|
|
344
|
+
const store = new Store(arg('db') ?? '.liqproof/liqproof.db');
|
|
345
|
+
const s = store.survival();
|
|
346
|
+
console.log('');
|
|
347
|
+
console.log(c.bold(' LIQPROOF SURVIVAL'));
|
|
348
|
+
console.log(c.gray(' ' + '─'.repeat(56)));
|
|
349
|
+
console.log(` tokens audited ${s.total}`);
|
|
350
|
+
console.log(` fake / no depth ${c.red(String(s.fake))}`);
|
|
351
|
+
console.log(` consistent ${c.green(String(s.consistent))}`);
|
|
352
|
+
console.log(` avg coverage ${(s.coverageAvg * 100).toFixed(2)}%`);
|
|
353
|
+
console.log('');
|
|
354
|
+
for (const [v, n] of Object.entries(s.byVerdict).sort((a, b) => b[1] - a[1])) {
|
|
355
|
+
console.log(` ${v.padEnd(16)} ${String(n).padStart(5)}`);
|
|
356
|
+
}
|
|
357
|
+
console.log('');
|
|
358
|
+
store.close();
|
|
359
|
+
}
|
|
360
|
+
async function cmdTimeline() {
|
|
361
|
+
const target = process.argv[3];
|
|
362
|
+
if (!target) {
|
|
363
|
+
console.error(c.red('usage: liqproof timeline <mint-or-url> [--no-curve] [--txs=600]'));
|
|
364
|
+
process.exit(1);
|
|
365
|
+
}
|
|
366
|
+
const mint = extractMint(target);
|
|
367
|
+
const rpc = makeRpc(has('verbose'));
|
|
368
|
+
const includeCurve = !has('no-curve');
|
|
369
|
+
console.error(c.gray(` reconstructing liquidity timeline for ${mint} …`));
|
|
370
|
+
const receipt = await buildReceipt(rpc, mint, {
|
|
371
|
+
includeCurve,
|
|
372
|
+
maxTransactions: Number(arg('txs', '600')),
|
|
373
|
+
});
|
|
374
|
+
const pts = receipt.timeline.points;
|
|
375
|
+
console.log('');
|
|
376
|
+
console.log(c.bold(' LIQPROOF TIMELINE') + c.gray(` · ${mint}`));
|
|
377
|
+
console.log(c.gray(' ' + '─'.repeat(88)));
|
|
378
|
+
console.log(c.gray(' ' +
|
|
379
|
+
'timestamp'.padEnd(22) +
|
|
380
|
+
'slot'.padStart(12) +
|
|
381
|
+
'deposited'.padStart(14) +
|
|
382
|
+
'delta'.padStart(14) +
|
|
383
|
+
' signature'));
|
|
384
|
+
console.log(c.gray(' ' + '─'.repeat(88)));
|
|
385
|
+
if (!pts.length) {
|
|
386
|
+
console.log(c.gray(includeCurve
|
|
387
|
+
? ' no liquidity events could be reconstructed (no vault activity found in the scanned window)'
|
|
388
|
+
: ' no timeline — curve reconstruction disabled (--no-curve)'));
|
|
389
|
+
}
|
|
390
|
+
for (const p of pts) {
|
|
391
|
+
const mark = p.note ? c.red(' ▼') : '';
|
|
392
|
+
console.log(` ${p.at.replace('T', ' ').replace('Z', '').padEnd(22)}${String(p.slot).padStart(12)}${usd(p.depositedUsd).padStart(14)}${usd(p.deltaUsd).padStart(14)} ${c.gray(p.signature.slice(0, 12) + '…')}${mark}`);
|
|
393
|
+
}
|
|
394
|
+
console.log(c.gray(' ' + '─'.repeat(88)));
|
|
395
|
+
if (receipt.real.drainAt) {
|
|
396
|
+
console.log('');
|
|
397
|
+
console.log(` ${c.red(c.bold('DRAIN EVENT'))}`);
|
|
398
|
+
console.log(` at ${receipt.real.drainAt}`);
|
|
399
|
+
console.log(` slot ${receipt.real.drainSlot ?? 'n/a'}`);
|
|
400
|
+
console.log(` delta ${usd(receipt.real.drainDeltaUsd ?? 0)}`);
|
|
401
|
+
console.log(` tx ${receipt.real.drainSignature ?? 'n/a'}`);
|
|
402
|
+
}
|
|
403
|
+
console.log('');
|
|
404
|
+
console.log(c.gray(` scanned ${receipt.timeline.scanned} txs · ${receipt.timeline.totalSignatures} signatures · strategy ${receipt.timeline.strategy}`));
|
|
405
|
+
console.log(c.gray(` ${receipt.disclaimer}`));
|
|
406
|
+
console.log('');
|
|
407
|
+
}
|
|
408
|
+
async function cmdExport() {
|
|
409
|
+
const db = arg('db') ?? '.liqproof/liqproof.db';
|
|
410
|
+
const outDir = arg('out') ?? 'out';
|
|
411
|
+
const store = new Store(db);
|
|
412
|
+
let html;
|
|
413
|
+
let csv;
|
|
414
|
+
let rows = 0;
|
|
415
|
+
try {
|
|
416
|
+
const dash = buildDashboard(store);
|
|
417
|
+
html = dash.html;
|
|
418
|
+
csv = dash.csv;
|
|
419
|
+
rows = store.allTokens().length;
|
|
420
|
+
}
|
|
421
|
+
finally {
|
|
422
|
+
store.close();
|
|
423
|
+
}
|
|
424
|
+
mkdirSync(outDir, { recursive: true });
|
|
425
|
+
const csvPath = `${outDir}/dataset.csv`;
|
|
426
|
+
const htmlPath = `${outDir}/index.html`;
|
|
427
|
+
writeFileSync(csvPath, csv);
|
|
428
|
+
writeFileSync(htmlPath, html);
|
|
429
|
+
console.error(c.gray(` wrote ${csvPath}`));
|
|
430
|
+
console.error(c.gray(` wrote ${htmlPath}`));
|
|
431
|
+
console.error(c.gray(` ${rows} token rows · ${csv.length} csv bytes · ${html.length} html bytes`));
|
|
432
|
+
console.log(`exported ${rows} audited tokens → ${csvPath} + ${htmlPath} (open ${htmlPath} in a browser)`);
|
|
433
|
+
}
|
|
434
|
+
async function cmdMcp() {
|
|
435
|
+
// Dynamic import keeps the MCP module (and its readline machinery) out of
|
|
436
|
+
// the process unless the user actually asks for it.
|
|
437
|
+
const { startMcpServer } = await import('./mcp.js');
|
|
438
|
+
await startMcpServer();
|
|
439
|
+
}
|
|
440
|
+
async function cmdDoctor() {
|
|
441
|
+
console.log('');
|
|
442
|
+
console.log(c.bold(' LIQPROOF DOCTOR') + c.gray(' · every dependency must be free'));
|
|
443
|
+
console.log(c.gray(' ' + '─'.repeat(56)));
|
|
444
|
+
const rpc = makeRpc(false);
|
|
445
|
+
const slot = await rpc.tryCall('getSlot', []);
|
|
446
|
+
console.log(` ${slot !== null ? c.green('OK ') : c.red('FAIL')} Solana RPC slot=${slot}`);
|
|
447
|
+
const j = await jupiterQuote(MINT.USDC, MINT.SOL, '1000000');
|
|
448
|
+
console.log(` ${j && !j.error ? c.green('OK ') : c.yellow('WARN')} Jupiter quote out=${j?.outAmount ?? 'n/a'} impact=${j?.priceImpactPct ?? 'n/a'}`);
|
|
449
|
+
try {
|
|
450
|
+
const r = await tokenReport(MINT.SOL);
|
|
451
|
+
console.log(` ${c.green('OK ')} GeckoTerminal pools=${r.pools.length} claimed=${usd(r.pools[0]?.reportedLiquidityUsd ?? 0)}`);
|
|
452
|
+
}
|
|
453
|
+
catch {
|
|
454
|
+
console.log(` ${c.red('FAIL')} GeckoTerminal`);
|
|
455
|
+
}
|
|
456
|
+
try {
|
|
457
|
+
const r = await fetchJson(`https://api.dexscreener.com/tokens/v1/solana/${MINT.SOL}`);
|
|
458
|
+
console.log(` ${c.green('OK ')} DexScreener pairs=${r.length}`);
|
|
459
|
+
}
|
|
460
|
+
catch {
|
|
461
|
+
console.log(` ${c.red('FAIL')} DexScreener`);
|
|
462
|
+
}
|
|
463
|
+
console.log(` ${c.gray('INFO')} RPC stats requests=${rpc.stats.requests} calls=${rpc.stats.calls} 429=${rpc.stats.rpc429} retries=${rpc.stats.retries}`);
|
|
464
|
+
console.log('');
|
|
465
|
+
}
|
|
466
|
+
/** Prove the $0 constraint and the read-only constraint at runtime. */
|
|
467
|
+
async function cmdVerify() {
|
|
468
|
+
console.log('');
|
|
469
|
+
console.log(c.bold(' LIQPROOF VERIFY') + c.gray(' · read-only + zero-cost assertions'));
|
|
470
|
+
console.log(c.gray(' ' + '─'.repeat(56)));
|
|
471
|
+
const { readdirSync, readFileSync, existsSync } = await import('node:fs');
|
|
472
|
+
const { join, dirname } = await import('node:path');
|
|
473
|
+
const { fileURLToPath } = await import('node:url');
|
|
474
|
+
// The package root, resolved from THIS file and never from the working
|
|
475
|
+
// directory. `npx liqproof verify` runs wherever the user happens to be,
|
|
476
|
+
// so the assertions have to read the shipped code, not whatever happens
|
|
477
|
+
// to sit next to the command.
|
|
478
|
+
const pkgRoot = join(dirname(fileURLToPath(import.meta.url)), '..');
|
|
479
|
+
// The markers are assembled from fragments on purpose: this checker scans
|
|
480
|
+
// every file under src/, including itself, so a literal occurrence would
|
|
481
|
+
// make it flag its own source. The runtime grep is byte-identical to the
|
|
482
|
+
// standalone harness - only the spelling inside this file differs.
|
|
483
|
+
const banned = [
|
|
484
|
+
'send' + 'Transaction',
|
|
485
|
+
'sign' + 'Transaction',
|
|
486
|
+
'private' + 'Key',
|
|
487
|
+
'Key' + 'pair',
|
|
488
|
+
'send' + 'RawTransaction',
|
|
489
|
+
];
|
|
490
|
+
// Scan the TypeScript sources when they are shipped, and the compiled
|
|
491
|
+
// output when they are not. Both are in the npm tarball; the fallback
|
|
492
|
+
// keeps the assertion meaningful in a stripped install.
|
|
493
|
+
const srcDir = join(pkgRoot, 'src');
|
|
494
|
+
const distDir = join(pkgRoot, 'dist');
|
|
495
|
+
const scanDir = existsSync(srcDir) ? srcDir : distDir;
|
|
496
|
+
const scanExt = scanDir === srcDir ? '.ts' : '.js';
|
|
497
|
+
const scanLabel = scanDir === srcDir ? 'source files' : 'compiled files';
|
|
498
|
+
let files = [];
|
|
499
|
+
const walk = (dir) => {
|
|
500
|
+
if (!existsSync(dir))
|
|
501
|
+
return;
|
|
502
|
+
for (const e of readdirSync(dir, { withFileTypes: true })) {
|
|
503
|
+
const p = join(dir, e.name);
|
|
504
|
+
if (e.isDirectory())
|
|
505
|
+
walk(p);
|
|
506
|
+
else if (e.name.endsWith(scanExt))
|
|
507
|
+
files.push(p);
|
|
508
|
+
}
|
|
509
|
+
};
|
|
510
|
+
walk(scanDir);
|
|
511
|
+
let violations = 0;
|
|
512
|
+
for (const f of files) {
|
|
513
|
+
const src = readFileSync(f, 'utf8');
|
|
514
|
+
for (const b of banned) {
|
|
515
|
+
if (src.includes(b)) {
|
|
516
|
+
console.log(` ${c.red('FAIL')} ${f.slice(pkgRoot.length + 1)} contains "${b}"`);
|
|
517
|
+
violations++;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
console.log(` ${violations === 0 ? c.green('OK ') : c.red('FAIL')} no transaction-signing path in ${files.length} ${scanLabel}`);
|
|
522
|
+
// The zero-dependency claim, read from the shipped manifest rather than
|
|
523
|
+
// printed as a constant: if a runtime dependency ever appears, this line
|
|
524
|
+
// goes red instead of quietly lying.
|
|
525
|
+
let deps = {};
|
|
526
|
+
let manifestFound = true;
|
|
527
|
+
try {
|
|
528
|
+
const pkg = JSON.parse(readFileSync(join(pkgRoot, 'package.json'), 'utf8'));
|
|
529
|
+
deps = pkg.dependencies ?? {};
|
|
530
|
+
}
|
|
531
|
+
catch {
|
|
532
|
+
manifestFound = false;
|
|
533
|
+
}
|
|
534
|
+
const depNames = Object.keys(deps);
|
|
535
|
+
if (!manifestFound) {
|
|
536
|
+
console.log(` ${c.red('FAIL')} package.json not found next to the installed package`);
|
|
537
|
+
violations++;
|
|
538
|
+
}
|
|
539
|
+
else if (depNames.length > 0) {
|
|
540
|
+
console.log(` ${c.red('FAIL')} runtime dependencies present: ${depNames.join(', ')}`);
|
|
541
|
+
violations++;
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
console.log(` ${c.green('OK ')} no paid SDK dependency (package.json deps = ${JSON.stringify(deps)})`);
|
|
545
|
+
}
|
|
546
|
+
console.log('');
|
|
547
|
+
if (violations > 0)
|
|
548
|
+
process.exit(1);
|
|
549
|
+
}
|
|
550
|
+
/**
|
|
551
|
+
* Bridge one Node HTTP request onto the Web handler and back.
|
|
552
|
+
*
|
|
553
|
+
* The Worker handler speaks `Request`/`Response`; Node's `http` module
|
|
554
|
+
* speaks its own thing. This is the only glue in the local server, and it is
|
|
555
|
+
* deliberately dumb: everything interesting happens in `src/worker.ts`.
|
|
556
|
+
*/
|
|
557
|
+
async function serveOne(req, res, env, handleRequest) {
|
|
558
|
+
try {
|
|
559
|
+
const request = toWebRequest(req);
|
|
560
|
+
const response = await handleRequest(request, env);
|
|
561
|
+
const headers = {};
|
|
562
|
+
response.headers.forEach((value, key) => {
|
|
563
|
+
headers[key] = value;
|
|
564
|
+
});
|
|
565
|
+
res.writeHead(response.status, headers);
|
|
566
|
+
if (req.method === 'HEAD') {
|
|
567
|
+
res.end();
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const body = Buffer.from(await response.arrayBuffer());
|
|
571
|
+
res.end(body);
|
|
572
|
+
}
|
|
573
|
+
catch (err) {
|
|
574
|
+
res.writeHead(500, { 'content-type': 'application/json; charset=utf-8' });
|
|
575
|
+
res.end(JSON.stringify({ error: 'internal_error', message: err.message }, null, 2));
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
/** Turn a Node request into a Web `Request`. */
|
|
579
|
+
function toWebRequest(req) {
|
|
580
|
+
const host = req.headers.host ?? 'localhost';
|
|
581
|
+
const url = new URL(req.url ?? '/', `http://${host}`);
|
|
582
|
+
const headers = new Headers();
|
|
583
|
+
for (const [key, value] of Object.entries(req.headers)) {
|
|
584
|
+
if (value === undefined)
|
|
585
|
+
continue;
|
|
586
|
+
// Hop-by-hop and framing headers belong to the socket, not to the
|
|
587
|
+
// request; forwarding them confuses the fetch implementation.
|
|
588
|
+
if (key === 'connection' || key === 'keep-alive' || key === 'transfer-encoding')
|
|
589
|
+
continue;
|
|
590
|
+
if (key === 'upgrade' || key === 'host' || key === 'content-length')
|
|
591
|
+
continue;
|
|
592
|
+
if (Array.isArray(value)) {
|
|
593
|
+
for (const v of value)
|
|
594
|
+
headers.append(key, v);
|
|
595
|
+
}
|
|
596
|
+
else {
|
|
597
|
+
headers.set(key, value);
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
return new Request(url, { method: req.method ?? 'GET', headers });
|
|
601
|
+
}
|
|
602
|
+
/**
|
|
603
|
+
* Serve the LIQPROOF API from this machine.
|
|
604
|
+
*
|
|
605
|
+
* WHY A LOCAL SERVER AT ALL: the Worker is the production host, but a
|
|
606
|
+
* developer needs to exercise the exact same 402 challenge locally — and a
|
|
607
|
+
* local server is free, needs no account and needs no deployment. It imports
|
|
608
|
+
* the Worker handler directly, so the two can never drift apart.
|
|
609
|
+
*
|
|
610
|
+
* The daily free-tier counter lives in the project's own `DiskCache`, so it
|
|
611
|
+
* survives a restart without a database.
|
|
612
|
+
*/
|
|
613
|
+
async function cmdServe() {
|
|
614
|
+
const { createServer } = await import('node:http');
|
|
615
|
+
const { handleRequest } = await import('./worker.js');
|
|
616
|
+
const { DiskUsageStore } = await import('./x402.js');
|
|
617
|
+
const port = Number(arg('port', process.env.LIQPROOF_PORT ?? '8787'));
|
|
618
|
+
const host = arg('host', process.env.LIQPROOF_HOST ?? '127.0.0.1');
|
|
619
|
+
const payTo = (arg('payto', process.env.LIQPROOF_PAYTO) ?? '').trim();
|
|
620
|
+
const env = {
|
|
621
|
+
PAY_TO: payTo,
|
|
622
|
+
X402_FACILITATOR: arg('facilitator', process.env.LIQPROOF_FACILITATOR),
|
|
623
|
+
X402_PRICE_USD: arg('price', process.env.LIQPROOF_PRICE_USD),
|
|
624
|
+
X402_FREE_TIER: arg('free-tier', process.env.LIQPROOF_FREE_TIER),
|
|
625
|
+
X402_NETWORK: arg('network', process.env.LIQPROOF_NETWORK),
|
|
626
|
+
X402_MAX_TX: arg('max-tx', process.env.LIQPROOF_MAX_TX),
|
|
627
|
+
// Two days of TTL: the counter only has to outlive the UTC day it
|
|
628
|
+
// belongs to, and then expiry takes care of it on its own.
|
|
629
|
+
// NOTE: `DiskCache` takes its TTL in MILLISECONDS (same convention as
|
|
630
|
+
// `src/sources.ts` and `src/canonical.ts`).
|
|
631
|
+
USAGE_STORE: new DiskUsageStore(new DiskCache(2 * 24 * 60 * 60_000)),
|
|
632
|
+
};
|
|
633
|
+
if (!Number.isFinite(port) || port < 1 || port > 65535) {
|
|
634
|
+
console.error(c.red(` invalid port: ${port}`));
|
|
635
|
+
process.exit(1);
|
|
636
|
+
}
|
|
637
|
+
const server = createServer((req, res) => {
|
|
638
|
+
void serveOne(req, res, env, handleRequest);
|
|
639
|
+
});
|
|
640
|
+
server.listen(port, host, () => {
|
|
641
|
+
console.log('');
|
|
642
|
+
console.log(c.bold(' LIQPROOF SERVE') + c.gray(' · read-only receipts over HTTP'));
|
|
643
|
+
console.log(c.gray(' ' + '─'.repeat(64)));
|
|
644
|
+
console.log(` ${c.gray('listening')} http://${host}:${port}`);
|
|
645
|
+
console.log(` ${c.gray('receipt')} http://${host}:${port}/receipt/<mint>`);
|
|
646
|
+
console.log(` ${c.gray('health')} http://${host}:${port}/health`);
|
|
647
|
+
console.log(` ${c.gray('openapi')} http://${host}:${port}/openapi.json`);
|
|
648
|
+
if (payTo) {
|
|
649
|
+
console.log(` ${c.gray('pay to')} ${payTo}`);
|
|
650
|
+
}
|
|
651
|
+
else {
|
|
652
|
+
console.log(c.yellow(' warn no payment recipient — pass --payto=<address> or set LIQPROOF_PAYTO'));
|
|
653
|
+
console.log(c.gray(' (the free tier still works; paid access answers 503)'));
|
|
654
|
+
}
|
|
655
|
+
console.log(c.gray(' ' + '─'.repeat(64)));
|
|
656
|
+
console.log(c.gray(' read-only · no gas · no paid APIs · no chain mutation'));
|
|
657
|
+
console.log('');
|
|
658
|
+
});
|
|
659
|
+
server.on('error', (err) => {
|
|
660
|
+
console.error(c.red(`\n fatal: ${err.message}`));
|
|
661
|
+
process.exit(1);
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Print the exact 402 challenge for a receipt.
|
|
666
|
+
*
|
|
667
|
+
* stdout carries the challenge JSON and nothing else, so it can be piped
|
|
668
|
+
* straight into `jq` or into a test. The base64 `PAYMENT-REQUIRED` header
|
|
669
|
+
* value goes to stderr, where a human will see it but a pipe will not.
|
|
670
|
+
*/
|
|
671
|
+
async function cmdX402() {
|
|
672
|
+
const { buildChallenge, encodeChallengeHeader, normalizeNetwork, x402SelfTest } = await import('./x402.js');
|
|
673
|
+
if (has('selftest')) {
|
|
674
|
+
const failures = x402SelfTest();
|
|
675
|
+
console.log('');
|
|
676
|
+
console.log(c.bold(' LIQPROOF X402 SELF-TEST') + c.gray(' · pure functions, no network, no disk'));
|
|
677
|
+
console.log(c.gray(' ' + '─'.repeat(56)));
|
|
678
|
+
if (failures.length === 0) {
|
|
679
|
+
console.log(` ${c.green('OK ')} every check passed`);
|
|
680
|
+
}
|
|
681
|
+
else {
|
|
682
|
+
for (const failure of failures)
|
|
683
|
+
console.log(` ${c.red('FAIL')} ${failure}`);
|
|
684
|
+
}
|
|
685
|
+
console.log('');
|
|
686
|
+
if (failures.length > 0)
|
|
687
|
+
process.exit(1);
|
|
688
|
+
return;
|
|
689
|
+
}
|
|
690
|
+
const target = process.argv[3];
|
|
691
|
+
if (!target) {
|
|
692
|
+
console.error(c.red('usage: liqproof x402 <mint-or-url> [--url=...] [--payto=...] [--price=0.25] [--network=solana]'));
|
|
693
|
+
process.exit(1);
|
|
694
|
+
}
|
|
695
|
+
const mint = extractMint(target);
|
|
696
|
+
const payTo = (arg('payto', process.env.LIQPROOF_PAY_TO) ?? '').trim();
|
|
697
|
+
const priceUsd = Number(arg('price', process.env.LIQPROOF_PRICE_USD ?? '0.25'));
|
|
698
|
+
const network = normalizeNetwork(arg('network', process.env.LIQPROOF_NETWORK));
|
|
699
|
+
const resourceUrl = arg('url', `http://localhost:8787/receipt/${mint}`);
|
|
700
|
+
const challenge = buildChallenge({
|
|
701
|
+
network,
|
|
702
|
+
priceUsd: Number.isFinite(priceUsd) && priceUsd >= 0 ? priceUsd : undefined,
|
|
703
|
+
payTo,
|
|
704
|
+
resourceUrl,
|
|
705
|
+
description: `LIQPROOF liquidity receipt for ${mint}`,
|
|
706
|
+
});
|
|
707
|
+
console.log(JSON.stringify(challenge, null, 2));
|
|
708
|
+
console.error(c.gray(` payment-required header (base64): ${encodeChallengeHeader(challenge)}`));
|
|
709
|
+
if (!payTo) {
|
|
710
|
+
console.error(c.yellow(' warn no payment recipient set — pass --payto=<solana address> or set LIQPROOF_PAYTO'));
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Check a receiving address before a bounty, prize or x402 payment points at
|
|
715
|
+
* it. Read-only: it reads chain state and never signs anything.
|
|
716
|
+
*/
|
|
717
|
+
async function cmdWallet() {
|
|
718
|
+
const target = process.argv[3];
|
|
719
|
+
if (!target) {
|
|
720
|
+
console.error('usage: liqproof wallet <address> [--network=solana|base] [--json]');
|
|
721
|
+
process.exit(2);
|
|
722
|
+
}
|
|
723
|
+
const netArg = arg('network', 'auto');
|
|
724
|
+
const network = (netArg === 'solana' || netArg === 'base' ? netArg : 'auto');
|
|
725
|
+
const report = await inspectWallet(target, network);
|
|
726
|
+
if (has('json')) {
|
|
727
|
+
console.log(JSON.stringify(report, null, 2));
|
|
728
|
+
return;
|
|
729
|
+
}
|
|
730
|
+
const badge = (s) => s === 'ok' ? c.green('OK ') : s === 'warn' ? c.yellow('WARN') : s === 'fail' ? c.red('FAIL') : c.gray('INFO');
|
|
731
|
+
console.log('');
|
|
732
|
+
console.log(c.bold(' LIQPROOF · WALLET CHECK') + c.gray(' · read-only'));
|
|
733
|
+
console.log(c.gray(' ' + '─'.repeat(56)));
|
|
734
|
+
console.log(` address ${report.address}`);
|
|
735
|
+
console.log(` network ${report.network}`);
|
|
736
|
+
console.log('');
|
|
737
|
+
for (const check of report.checks) {
|
|
738
|
+
console.log(` ${badge(check.status)} ${check.name.padEnd(18)} ${check.detail}`);
|
|
739
|
+
}
|
|
740
|
+
if (report.balances.length > 0) {
|
|
741
|
+
console.log('');
|
|
742
|
+
console.log(' BALANCES');
|
|
743
|
+
for (const b of report.balances) {
|
|
744
|
+
console.log(` ${b.label.padEnd(18)} ${b.value}`);
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
console.log('');
|
|
748
|
+
console.log(` ${report.ready ? c.green('READY') : c.red('NOT READY')} ${report.summary}`);
|
|
749
|
+
console.log('');
|
|
750
|
+
if (!report.ready)
|
|
751
|
+
process.exit(1);
|
|
752
|
+
}
|
|
753
|
+
async function main() {
|
|
754
|
+
const cmd = process.argv[2] ?? 'help';
|
|
755
|
+
switch (cmd) {
|
|
756
|
+
case 'receipt':
|
|
757
|
+
return cmdReceipt();
|
|
758
|
+
case 'scan':
|
|
759
|
+
return cmdScan();
|
|
760
|
+
case 'survival':
|
|
761
|
+
return cmdSurvival();
|
|
762
|
+
case 'timeline':
|
|
763
|
+
return cmdTimeline();
|
|
764
|
+
case 'export':
|
|
765
|
+
return cmdExport();
|
|
766
|
+
case 'mcp':
|
|
767
|
+
return cmdMcp();
|
|
768
|
+
case 'doctor':
|
|
769
|
+
return cmdDoctor();
|
|
770
|
+
case 'verify':
|
|
771
|
+
return cmdVerify();
|
|
772
|
+
case 'serve':
|
|
773
|
+
return cmdServe();
|
|
774
|
+
case 'x402':
|
|
775
|
+
return cmdX402();
|
|
776
|
+
case 'wallet':
|
|
777
|
+
return cmdWallet();
|
|
778
|
+
case 'version':
|
|
779
|
+
console.log(VERSION);
|
|
780
|
+
return;
|
|
781
|
+
default:
|
|
782
|
+
console.log(`
|
|
783
|
+
${c.bold('liqproof')} — on-chain liquidity receipts
|
|
784
|
+
|
|
785
|
+
${c.bold('liqproof receipt')} <mint|url> [--json] [--no-curve] [--txs=N] [--save]
|
|
786
|
+
Build a receipt for a token. Verifies claimed liquidity against the
|
|
787
|
+
actual vault balances and reconstructs the historical liquidity curve.
|
|
788
|
+
|
|
789
|
+
${c.bold('liqproof scan')} [--limit=50] [--curve]
|
|
790
|
+
Mine new pools and audit them.
|
|
791
|
+
|
|
792
|
+
${c.bold('liqproof survival')}
|
|
793
|
+
Survival statistics from the local store.
|
|
794
|
+
|
|
795
|
+
${c.bold('liqproof timeline')} <mint|url> [--no-curve] [--txs=N]
|
|
796
|
+
Print the reconstructed liquidity timeline and the drain event.
|
|
797
|
+
|
|
798
|
+
${c.bold('liqproof export')} [--out=out]
|
|
799
|
+
Build the offline dashboard and the CSV dataset from the local store.
|
|
800
|
+
|
|
801
|
+
${c.bold('liqproof mcp')}
|
|
802
|
+
Start the MCP server on stdio (stdout carries JSON-RPC only).
|
|
803
|
+
|
|
804
|
+
${c.bold('liqproof doctor')}
|
|
805
|
+
Check every free endpoint.
|
|
806
|
+
|
|
807
|
+
${c.bold('liqproof verify')}
|
|
808
|
+
Assert the read-only + zero-cost constraints.
|
|
809
|
+
|
|
810
|
+
${c.bold('liqproof serve')} [--port=8787] [--host=127.0.0.1] [--payto=<address>]
|
|
811
|
+
Serve the HTTP API locally (the same handler the Worker runs), with a
|
|
812
|
+
free daily tier and x402 payment for everything above it.
|
|
813
|
+
|
|
814
|
+
${c.bold('liqproof x402')} <mint> [--url=...] [--payto=...] [--price=0.25]
|
|
815
|
+
Print the exact 402 challenge JSON for a receipt. Use --selftest for
|
|
816
|
+
the module self-check.
|
|
817
|
+
|
|
818
|
+
${c.bold('liqproof wallet')} <address> [--network=solana|base] [--json]
|
|
819
|
+
Validate a receiving address before a payout points at it: base58 and
|
|
820
|
+
ed25519 on Solana, EIP-55 checksum on EVM, plus live chain state.
|
|
821
|
+
|
|
822
|
+
${c.gray('Read-only. No gas. No paid APIs. No chain mutation.')}
|
|
823
|
+
`);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
main().catch((err) => {
|
|
827
|
+
console.error(c.red(`\n fatal: ${err?.stack ?? err}`));
|
|
828
|
+
process.exit(1);
|
|
829
|
+
});
|
|
830
|
+
//# sourceMappingURL=cli.js.map
|