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/src/canonical.ts
ADDED
|
@@ -0,0 +1,447 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* canonical.ts — resolve the REAL token behind a name or ticker.
|
|
3
|
+
*
|
|
4
|
+
* ── WHY THIS FILE EXISTS ────────────────────────────────────────────────────
|
|
5
|
+
*
|
|
6
|
+
* LIQPROOF makes accusations. On 2026-12-04 we nearly shipped one of the
|
|
7
|
+
* worst kinds: our falsifiability harness labelled
|
|
8
|
+
*
|
|
9
|
+
* 6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw "CHZ copycat trap"
|
|
10
|
+
*
|
|
11
|
+
* and the very next probe proved that mint is the OFFICIAL Chiliz:
|
|
12
|
+
*
|
|
13
|
+
* • Chiliz's own documentation lists it as the Solana $CHZ contract
|
|
14
|
+
* https://docs.chiliz.com/quick-start/token-contract-addresses
|
|
15
|
+
* • CoinGecko's platform map for `chiliz` points at it
|
|
16
|
+
* • Jupiter prices it at $0.0109 — a real, live market price
|
|
17
|
+
* • its mint AND freeze authority are still active, under one custodial
|
|
18
|
+
* key (ER5dRbG8FA…) — exactly what a real project's own mint looks like
|
|
19
|
+
* • every impersonator we found has the OPPOSITE fingerprint: supply
|
|
20
|
+
* rounded to exactly 1,000,000,000, mint authority revoked, and a
|
|
21
|
+
* creator address from one shared vanity-key family
|
|
22
|
+
*
|
|
23
|
+
* One wrong accusation against a top-30 project destroys LIQPROOF's entire
|
|
24
|
+
* credibility — and, worse, a scanner that cries wolf is worthless even when
|
|
25
|
+
* it is right. So before this tool is allowed to call ANYTHING fake, it has
|
|
26
|
+
* to know who the genuine article is.
|
|
27
|
+
*
|
|
28
|
+
* ── THE RULE ────────────────────────────────────────────────────────────────
|
|
29
|
+
*
|
|
30
|
+
* A ticker is not an identity. Two mints can both be called "CHZ". Only the
|
|
31
|
+
* canonical mint identifies the project. Everything in this file exists to
|
|
32
|
+
* answer one question per mint:
|
|
33
|
+
*
|
|
34
|
+
* "is this mint the canonical one, or is it wearing its name?"
|
|
35
|
+
*
|
|
36
|
+
* and, when the answer is "wearing its name", to produce the RECEIPT for
|
|
37
|
+
* that claim: the canonical mint, who says so, and a URL a reader can open.
|
|
38
|
+
*
|
|
39
|
+
* ── WHERE THE TRUTH COMES FROM ───────────────────────────────────────────────
|
|
40
|
+
*
|
|
41
|
+
* Two tiers, both keyless and free:
|
|
42
|
+
*
|
|
43
|
+
* 1. first-party — the project's OWN documentation. Highest trust.
|
|
44
|
+
* 2. coingecko-platform — CoinGecko's coin→Solana-mint mapping, which is
|
|
45
|
+
* the industry reference and the thing every
|
|
46
|
+
* other aggregator in the room already agrees on.
|
|
47
|
+
*
|
|
48
|
+
* When the tiers disagree we do NOT guess: we report the disagreement. We
|
|
49
|
+
* also never infer canonicality from our own heuristics — that would be the
|
|
50
|
+
* tool marking its own homework.
|
|
51
|
+
*/
|
|
52
|
+
|
|
53
|
+
import { DiskCache, fetchJson } from './util.js';
|
|
54
|
+
import { coingeckoTarget } from './sources.js';
|
|
55
|
+
|
|
56
|
+
// ── first-party registry ─────────────────────────────────────────────────────
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Canonical mints confirmed against the project's OWN documentation.
|
|
60
|
+
*
|
|
61
|
+
* Each entry carries the URL we actually opened to verify it. A first-party
|
|
62
|
+
* claim is the only kind we are willing to publish as "this is the real one"
|
|
63
|
+
* without a second source agreeing.
|
|
64
|
+
*/
|
|
65
|
+
export const FIRST_PARTY_CANONICAL: CanonicalEntry[] = [
|
|
66
|
+
{
|
|
67
|
+
mint: '6eftxVbSAunVEoxUWdGhPdxg5UdsJ8Wkwy5w5YFuxouw',
|
|
68
|
+
name: 'Chiliz',
|
|
69
|
+
symbol: 'CHZ',
|
|
70
|
+
source: 'first-party',
|
|
71
|
+
proof: 'https://docs.chiliz.com/quick-start/token-contract-addresses',
|
|
72
|
+
proofLabel: "Chiliz official docs — Token Contract Addresses",
|
|
73
|
+
},
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
export type CanonicalSource = 'first-party' | 'coingecko-platform';
|
|
77
|
+
|
|
78
|
+
export interface CanonicalEntry {
|
|
79
|
+
mint: string;
|
|
80
|
+
name: string;
|
|
81
|
+
symbol: string;
|
|
82
|
+
source: CanonicalSource;
|
|
83
|
+
/** a URL a reader can open to verify the claim */
|
|
84
|
+
proof: string;
|
|
85
|
+
proofLabel: string;
|
|
86
|
+
/** CoinGecko coin id, when the entry came from CoinGecko */
|
|
87
|
+
coinId?: string;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
// ── normalisation ────────────────────────────────────────────────────────────
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Words that carry no identity when comparing a token's on-chain name to a
|
|
94
|
+
* registry name. "Basic Attention Token" and "Basic Attention" are the same
|
|
95
|
+
* project; "Chiliz" and "Chiliz Token" are the same project. Without this,
|
|
96
|
+
* the registry would miss the most obvious impersonation of all.
|
|
97
|
+
*
|
|
98
|
+
* ── WHAT IS *NOT* IN HERE, AND WHY ──────────────────────────────────────────
|
|
99
|
+
*
|
|
100
|
+
* This list is a loaded gun, and every word in it creates name collisions
|
|
101
|
+
* that are not collisions at all. We removed four words after measuring the
|
|
102
|
+
* damage on the live 9,053-mint sweep:
|
|
103
|
+
*
|
|
104
|
+
* 'swap' → "Solana Swap" became "solana", so every Solana memecoin named
|
|
105
|
+
* "Solana" looked like an impersonation of it. 14 tokens,
|
|
106
|
+
* $35 BILLION of advertised liquidity, wrongly attributed.
|
|
107
|
+
* 'x' → "Sol X" became "sol", so every token named "SOL" looked like
|
|
108
|
+
* an impersonation of it. 4 tokens, $6.1B, wrongly attributed.
|
|
109
|
+
* 'coin' → "USD Coin" became "usd", so a token named "USD Coin" matched a
|
|
110
|
+
* stablecoin literally called "USD+" instead of the real USDC.
|
|
111
|
+
* 'inu' → "Super Inu" became "super", so any token called "Super"
|
|
112
|
+
* looked like it.
|
|
113
|
+
*
|
|
114
|
+
* A word only belongs here if removing it NEVER changes which project a
|
|
115
|
+
* name refers to. "Token" does: "Chiliz Token" is Chiliz. "Coin" does not:
|
|
116
|
+
* "USD Coin" is USDC, "Useless Coin" is Useless, "a coin" is not "a".
|
|
117
|
+
*/
|
|
118
|
+
const NOISE_WORDS = new Set([
|
|
119
|
+
'token', 'network', 'protocol', 'finance', 'official', 'the', 'io',
|
|
120
|
+
]);
|
|
121
|
+
|
|
122
|
+
/** Lowercase, strip everything but letters and digits. */
|
|
123
|
+
export function normalizeName(s: string): string {
|
|
124
|
+
return (s ?? '')
|
|
125
|
+
.toLowerCase()
|
|
126
|
+
.normalize('NFKD')
|
|
127
|
+
.replace(/[^a-z0-9]+/g, ' ')
|
|
128
|
+
.trim()
|
|
129
|
+
.replace(/\s+/g, ' ');
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The "core" of a name: normalised, with identity-free words removed.
|
|
134
|
+
* Used as the registry key so "Basic Attention Token" === "Basic Attention".
|
|
135
|
+
*/
|
|
136
|
+
export function coreName(s: string): string {
|
|
137
|
+
const words = normalizeName(s).split(' ').filter(Boolean);
|
|
138
|
+
const kept = words.filter((w) => !NOISE_WORDS.has(w));
|
|
139
|
+
return (kept.length ? kept : words).join('');
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Normalised ticker. */
|
|
143
|
+
export function normalizeSymbol(s: string): string {
|
|
144
|
+
return (s ?? '').trim().toUpperCase();
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ── representations: when a registered name is not an identity ───────────────
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Words that mark a registered token as a REPRESENTATION of an asset that
|
|
151
|
+
* lives on another chain, rather than as the project's own identity.
|
|
152
|
+
*
|
|
153
|
+
* This matters because representations are legitimate and MANY. The market
|
|
154
|
+
* contains several different "Wormhole Bridged USDT" mints, several
|
|
155
|
+
* "Wrapped SOL" mints, several bridged TRX mints. If a registry entry can
|
|
156
|
+
* own a name, then every one of those honest bridge mints looks like a
|
|
157
|
+
* counterfeit of the other one — and the loudest victims are the projects
|
|
158
|
+
* whose assets are bridged the most (TRX, LUNC, HYPE, AVAX, DYDX, ZEC).
|
|
159
|
+
*
|
|
160
|
+
* So: a representation owns NOTHING. It cannot be impersonated, and it
|
|
161
|
+
* cannot be the victim of an impersonation. Its mint is still perfectly
|
|
162
|
+
* canonical when you query that mint directly — the distinction only
|
|
163
|
+
* matters for NAME and TICKER ownership.
|
|
164
|
+
*/
|
|
165
|
+
const REPRESENTATION_WORDS = new Set([
|
|
166
|
+
'wormhole', 'bridged', 'wrapped', 'portal', 'bridge', 'omnibridge',
|
|
167
|
+
'stargate', 'layerzero', 'axlr', 'renbtc', 'wombat', 'allbridge',
|
|
168
|
+
]);
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* Is this registered name a bridge/wrapper representation?
|
|
172
|
+
*
|
|
173
|
+
* "Solana Bridged TRX (Solana)", "Terra Classic (Wormhole)",
|
|
174
|
+
* "Wormhole Bridged HYPE", "OKX Wrapped BTC" — all representations.
|
|
175
|
+
*/
|
|
176
|
+
export function isRepresentationName(name: string): boolean {
|
|
177
|
+
const words = normalizeName(name).split(' ').filter(Boolean);
|
|
178
|
+
return words.some((w) => REPRESENTATION_WORDS.has(w));
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── the index ────────────────────────────────────────────────────────────────
|
|
182
|
+
|
|
183
|
+
export interface CanonicalIndex {
|
|
184
|
+
entries: CanonicalEntry[];
|
|
185
|
+
byMint: Map<string, CanonicalEntry>;
|
|
186
|
+
bySymbol: Map<string, CanonicalEntry[]>;
|
|
187
|
+
byCoreName: Map<string, CanonicalEntry[]>;
|
|
188
|
+
/** when the index was built */
|
|
189
|
+
loadedAt: string;
|
|
190
|
+
/** how many entries each source contributed */
|
|
191
|
+
counts: Record<string, number>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function push<K>(map: Map<K, CanonicalEntry[]>, key: K, entry: CanonicalEntry): void {
|
|
195
|
+
const list = map.get(key);
|
|
196
|
+
if (list) {
|
|
197
|
+
if (!list.some((e) => e.mint === entry.mint)) list.push(entry);
|
|
198
|
+
} else {
|
|
199
|
+
map.set(key, [entry]);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function indexOf(entries: CanonicalEntry[]): CanonicalIndex {
|
|
204
|
+
const byMint = new Map<string, CanonicalEntry>();
|
|
205
|
+
const bySymbol = new Map<string, CanonicalEntry[]>();
|
|
206
|
+
const byCoreName = new Map<string, CanonicalEntry[]>();
|
|
207
|
+
const counts: Record<string, number> = {};
|
|
208
|
+
|
|
209
|
+
for (const e of entries) {
|
|
210
|
+
byMint.set(e.mint, e);
|
|
211
|
+
push(bySymbol, normalizeSymbol(e.symbol), e);
|
|
212
|
+
push(byCoreName, coreName(e.name), e);
|
|
213
|
+
counts[e.source] = (counts[e.source] ?? 0) + 1;
|
|
214
|
+
}
|
|
215
|
+
return { entries, byMint, bySymbol, byCoreName, loadedAt: new Date().toISOString(), counts };
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
const indexCache = new DiskCache<CanonicalEntry[]>(6 * 60 * 60_000, '.liqproof/cache');
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* Build the canonical index.
|
|
222
|
+
*
|
|
223
|
+
* CoinGecko's `/coins/list?include_platform=true` returns every coin with
|
|
224
|
+
* its per-chain contract addresses in ONE keyless request (~21,000 coins,
|
|
225
|
+
* ~7,000 of them on Solana, ~1.7 s). That is the whole market's canonical
|
|
226
|
+
* map for the cost of nothing, so the index is always fresh enough.
|
|
227
|
+
*/
|
|
228
|
+
export async function loadCanonicalIndex(): Promise<CanonicalIndex> {
|
|
229
|
+
const key = 'canonical:index:v1';
|
|
230
|
+
const cached = indexCache.get(key);
|
|
231
|
+
if (cached) return indexOf(cached);
|
|
232
|
+
|
|
233
|
+
const entries: CanonicalEntry[] = [...FIRST_PARTY_CANONICAL];
|
|
234
|
+
const seen = new Set(entries.map((e) => e.mint));
|
|
235
|
+
|
|
236
|
+
try {
|
|
237
|
+
const cg = coingeckoTarget();
|
|
238
|
+
const list = await fetchJson<any[]>(`${cg.base}/coins/list?include_platform=true`, {
|
|
239
|
+
retries: 4,
|
|
240
|
+
timeoutMs: 60_000,
|
|
241
|
+
headers: cg.headers,
|
|
242
|
+
});
|
|
243
|
+
for (const c of list ?? []) {
|
|
244
|
+
const mint = c?.platforms?.solana;
|
|
245
|
+
if (!mint || typeof mint !== 'string') continue;
|
|
246
|
+
if (seen.has(mint)) continue;
|
|
247
|
+
seen.add(mint);
|
|
248
|
+
entries.push({
|
|
249
|
+
mint,
|
|
250
|
+
name: String(c.name ?? ''),
|
|
251
|
+
symbol: normalizeSymbol(String(c.symbol ?? '')),
|
|
252
|
+
source: 'coingecko-platform',
|
|
253
|
+
proof: `https://www.coingecko.com/en/coins/${c.id}`,
|
|
254
|
+
proofLabel: `CoinGecko — ${c.name} (${c.symbol})`,
|
|
255
|
+
coinId: String(c.id ?? ''),
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
} catch {
|
|
259
|
+
// CoinGecko is down or rate-limited. We still have the first-party tier,
|
|
260
|
+
// and the receipt will say so rather than pretending the index is whole.
|
|
261
|
+
//
|
|
262
|
+
// IMPORTANT: fall back to the LAST GOOD index. An empty index would make
|
|
263
|
+
// every canonical token look like an impostor, and a receipt that cannot
|
|
264
|
+
// tell a real project from a fake one must not issue accusations at all.
|
|
265
|
+
const stale = indexCache.getStale(key);
|
|
266
|
+
if (stale) return indexOf(stale.value);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
if (!entries.length) {
|
|
270
|
+
const stale = indexCache.getStale(key);
|
|
271
|
+
if (stale) return indexOf(stale.value);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
indexCache.set(key, entries);
|
|
275
|
+
return indexOf(entries);
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// ── resolution ───────────────────────────────────────────────────────────────
|
|
279
|
+
|
|
280
|
+
export type CanonicalStatus = 'canonical' | 'impersonator' | 'unresolved';
|
|
281
|
+
|
|
282
|
+
export interface CanonicalResolution {
|
|
283
|
+
mint: string;
|
|
284
|
+
status: CanonicalStatus;
|
|
285
|
+
/** true only when this mint IS the canonical token for its name */
|
|
286
|
+
isCanonical: boolean;
|
|
287
|
+
/** the canonical token this mint appears to be impersonating */
|
|
288
|
+
impersonates?: CanonicalEntry;
|
|
289
|
+
/** how strong the impersonation evidence is */
|
|
290
|
+
confidence: 'confirmed' | 'symbol-only' | 'unresolved';
|
|
291
|
+
/** how we got here — printed in the receipt so a reader can audit it */
|
|
292
|
+
method: string;
|
|
293
|
+
/** every canonical entry sharing this ticker (audit trail) */
|
|
294
|
+
symbolMatches: CanonicalEntry[];
|
|
295
|
+
/** every canonical entry sharing this name (audit trail) */
|
|
296
|
+
nameMatches: CanonicalEntry[];
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export interface MintIdentity {
|
|
300
|
+
name: string;
|
|
301
|
+
symbol: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Resolve a mint against the canonical index.
|
|
306
|
+
*
|
|
307
|
+
* The decision ladder, ordered so that the SAFEST answer is the default:
|
|
308
|
+
*
|
|
309
|
+
* 1. The mint is in the index → CANONICAL. Stop.
|
|
310
|
+
* 2. A canonical token already owns this NAME → IMPERSONATOR (confirmed).
|
|
311
|
+
* 3. Exactly one canonical token owns this
|
|
312
|
+
* TICKER, and the mint spells that ticker
|
|
313
|
+
* as its own on-chain NAME → IMPERSONATOR (symbol-only).
|
|
314
|
+
* 4. Otherwise → UNRESOLVED. We say nothing.
|
|
315
|
+
*
|
|
316
|
+
* ── WHY STEP 3 IS NOT STEP 2 ────────────────────────────────────────────────
|
|
317
|
+
*
|
|
318
|
+
* A ticker is not an identity. Two mints can both be called "CHZ"; 49
|
|
319
|
+
* CoinGecko coins share the ticker "USDC". A NAME collision says "this mint
|
|
320
|
+
* is wearing another project's name". A TICKER collision says only "this
|
|
321
|
+
* mint spells another project's ticker". The first is an accusation; the
|
|
322
|
+
* second is an observation, and the receipt labels it TICKER_COLLISION
|
|
323
|
+
* rather than IMPERSONATION so nobody can mistake it for the stronger
|
|
324
|
+
* claim.
|
|
325
|
+
*
|
|
326
|
+
* Two extra guards keep the ticker path honest:
|
|
327
|
+
*
|
|
328
|
+
* • The canonical entry must not be a bridge/wrapper REPRESENTATION
|
|
329
|
+
* (see REPRESENTATION_WORDS). Several honest "Wormhole Bridged USDT"
|
|
330
|
+
* mints exist; calling one of them a copycat of another is nonsense.
|
|
331
|
+
*
|
|
332
|
+
* • The ticker must be owned by exactly ONE registered token. "USDC"
|
|
333
|
+
* belongs to one; "DOG" belongs to six; "BP" to three. An ambiguous
|
|
334
|
+
* ticker proves nothing and we publish nothing.
|
|
335
|
+
*
|
|
336
|
+
* Step 4 is the important one. The cost of staying quiet is one missed
|
|
337
|
+
* headline. The cost of guessing is a false accusation against a real
|
|
338
|
+
* project, which costs the product.
|
|
339
|
+
*/
|
|
340
|
+
export function resolveCanonical(
|
|
341
|
+
mint: string,
|
|
342
|
+
identity: MintIdentity | null | undefined,
|
|
343
|
+
index: CanonicalIndex,
|
|
344
|
+
): CanonicalResolution {
|
|
345
|
+
const symbol = normalizeSymbol(identity?.symbol ?? '');
|
|
346
|
+
const name = (identity?.name ?? '').trim();
|
|
347
|
+
|
|
348
|
+
const direct = index.byMint.get(mint);
|
|
349
|
+
if (direct) {
|
|
350
|
+
return {
|
|
351
|
+
mint,
|
|
352
|
+
status: 'canonical',
|
|
353
|
+
isCanonical: true,
|
|
354
|
+
confidence: 'confirmed',
|
|
355
|
+
method: `mint is the canonical ${direct.name} (${direct.source})`,
|
|
356
|
+
symbolMatches: index.bySymbol.get(symbol) ?? [],
|
|
357
|
+
nameMatches: index.byCoreName.get(coreName(name)) ?? [],
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
const symbolMatches = index.bySymbol.get(symbol) ?? [];
|
|
362
|
+
const nameMatches = index.byCoreName.get(coreName(name)) ?? [];
|
|
363
|
+
|
|
364
|
+
// ── 2. a canonical token already owns this NAME ──────────────────────────
|
|
365
|
+
//
|
|
366
|
+
// A canonical NAME is strong evidence: two mints cannot both be "Chiliz".
|
|
367
|
+
// We require the core names to be equal, so "Chiliz" matches "Chiliz
|
|
368
|
+
// Token" but "XRP" does NOT match "XRP (Wormhole)" — two bridge
|
|
369
|
+
// representations of one asset are both legitimate, and we must never
|
|
370
|
+
// call the second one a counterfeit of the first.
|
|
371
|
+
const nameOwners = nameMatches.filter((e) => !isRepresentationName(e.name));
|
|
372
|
+
if (nameOwners.length === 1) {
|
|
373
|
+
const c = nameOwners[0];
|
|
374
|
+
return {
|
|
375
|
+
mint,
|
|
376
|
+
status: 'impersonator',
|
|
377
|
+
isCanonical: false,
|
|
378
|
+
impersonates: c,
|
|
379
|
+
confidence: 'confirmed',
|
|
380
|
+
method: `on-chain name "${name}" is the registered name of ${c.name} (${c.source}); different mint`,
|
|
381
|
+
symbolMatches,
|
|
382
|
+
nameMatches,
|
|
383
|
+
};
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// ── 3. a unique canonical token owns this TICKER ─────────────────────────
|
|
387
|
+
//
|
|
388
|
+
// We accept this only when the mint spells that ticker as its own
|
|
389
|
+
// on-chain NAME — a token that merely happens to carry the ticker in its
|
|
390
|
+
// symbol field is not claiming the name, so we say nothing. And we
|
|
391
|
+
// require the ticker to be unique among registered tokens that actually
|
|
392
|
+
// own identities (representations are excluded).
|
|
393
|
+
const tickerOwners = symbolMatches.filter((e) => !isRepresentationName(e.name));
|
|
394
|
+
if (tickerOwners.length === 1) {
|
|
395
|
+
const c = tickerOwners[0];
|
|
396
|
+
if (coreName(name) === coreName(c.symbol)) {
|
|
397
|
+
return {
|
|
398
|
+
mint,
|
|
399
|
+
status: 'impersonator',
|
|
400
|
+
isCanonical: false,
|
|
401
|
+
impersonates: c,
|
|
402
|
+
confidence: 'symbol-only',
|
|
403
|
+
method: `on-chain ticker ${symbol} is registered to ${c.name} (${c.source}); this mint spells that ticker as its own name; different mint`,
|
|
404
|
+
symbolMatches,
|
|
405
|
+
nameMatches,
|
|
406
|
+
};
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
// ── 4. say nothing ───────────────────────────────────────────────────────
|
|
411
|
+
return {
|
|
412
|
+
mint,
|
|
413
|
+
status: 'unresolved',
|
|
414
|
+
isCanonical: false,
|
|
415
|
+
confidence: 'unresolved',
|
|
416
|
+
method:
|
|
417
|
+
symbolMatches.length > 1
|
|
418
|
+
? `ticker ${symbol} is shared by ${symbolMatches.length} registered tokens — not distinguishable`
|
|
419
|
+
: nameMatches.length > 0
|
|
420
|
+
? `on-chain name "${name}" matches only a bridge/wrapper representation — not an identity claim`
|
|
421
|
+
: 'no registered token claims this name or ticker',
|
|
422
|
+
symbolMatches,
|
|
423
|
+
nameMatches,
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
/**
|
|
428
|
+
* Are two names close enough to be the same project?
|
|
429
|
+
*
|
|
430
|
+
* Used for the NAME-ownership comparison, and deliberately strict: after
|
|
431
|
+
* removing identity-free words, the two names must be EQUAL. We do NOT
|
|
432
|
+
* accept substring matches, because "XRP" is a substring of "XRP
|
|
433
|
+
* (Wormhole)" and two different bridge representations of the same asset
|
|
434
|
+
* are both legitimate. Treating a substring as a match would accuse every
|
|
435
|
+
* honest wrapped asset in the market.
|
|
436
|
+
*
|
|
437
|
+
* We also do NOT accept "the canonical's ticker is a prefix of its name"
|
|
438
|
+
* matches, because that is how "Basic Attention" would start matching
|
|
439
|
+
* "BAT" and how "Solana Swap" would start matching "Solana". Equality of
|
|
440
|
+
* the whole core name is the only rule that survived measurement.
|
|
441
|
+
*/
|
|
442
|
+
export function namesCompatible(a: string, b: string): boolean {
|
|
443
|
+
const ca = coreName(a);
|
|
444
|
+
const cb = coreName(b);
|
|
445
|
+
if (!ca || !cb) return false;
|
|
446
|
+
return ca === cb;
|
|
447
|
+
}
|