@anywalletkit/tokens 0.0.0-stage → 0.1.1

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.
@@ -0,0 +1,136 @@
1
+ import { TokenFlag, TokenInfo, IWalletAccountReadOnly } from '@anywalletkit/core';
2
+ import { CcAsset } from '@anywalletkit/swap2-assets';
3
+
4
+ /** `danger`: the token can take or trap the user's money, or pretends to be another one. `caution`: worth knowing. */
5
+ type TokenRiskLevel = 'danger' | 'caution';
6
+ /**
7
+ * Why a token deserves a warning:
8
+ * - `unlisted`: always — the wallet's list does not include it, and anyone can deploy a token with any name and logo.
9
+ * - `impersonation`: its symbol reads as a known token's (USDC, ETH, …), look-alike letters included.
10
+ * - `odd-characters`: its symbol or name uses characters outside plain ASCII, or invisible ones.
11
+ * - `no-symbol`: it reports no symbol.
12
+ * - `zero-supply`: nothing has been minted.
13
+ * - `unusual-decimals`: more than 24 decimals.
14
+ * - a {@link TokenFlag} read from the chain (issuer powers, Token-2022 extensions).
15
+ */
16
+ type TokenRiskCode = 'unlisted' | 'impersonation' | 'odd-characters' | 'no-symbol' | 'zero-supply' | 'unusual-decimals' | TokenFlag;
17
+ /** One warning, worded for the person adding the token. */
18
+ interface TokenRisk {
19
+ code: TokenRiskCode;
20
+ level: TokenRiskLevel;
21
+ message: string;
22
+ }
23
+ /** Every warning that applies, worst first, and the worst level. A user token is never "safe": `caution` is the floor. */
24
+ interface TokenAssessment {
25
+ level: TokenRiskLevel;
26
+ risks: TokenRisk[];
27
+ }
28
+ /** A symbol folded the way a reader sees it: invisible characters gone, compatibility forms unified, look-alikes mapped, upper case. */
29
+ declare function foldSymbol(text: string): string;
30
+ /**
31
+ * Warnings for a token read with `getTokenInfo`, for a token the wallet's list does not include.
32
+ * Pure: nothing is fetched. `impersonation` when its symbol (look-alike letters folded) reads as a
33
+ * catalog token on the same `chain` — the real one would be in the list, this is another contract —
34
+ * or as a native coin or major stablecoin anywhere. A bridged token of another chain's list (JUP on
35
+ * Solana, listed on Unichain) is not flagged.
36
+ */
37
+ declare function assessToken(info: TokenInfo, chain?: string): TokenAssessment;
38
+
39
+ /** One JSON value under one key — the shape every small store needs (AsyncStorage, chrome.storage, memory). */
40
+ interface JsonStorage<T> {
41
+ /** The stored value, or `null` on first run. */
42
+ get(): Promise<T | null>;
43
+ /** Persist the value. */
44
+ set(value: T): Promise<void>;
45
+ }
46
+ /** In-memory storage for tests and smoke runs. */
47
+ declare function memoryJsonStorage<T>(initial?: T | null): JsonStorage<T> & {
48
+ value: T | null;
49
+ };
50
+ /** A token the user added. `symbol` and `name` are what the token reports: display them, never match on them. */
51
+ interface UserToken {
52
+ /** CAIP-2 chain id, the catalog's key (`solana:mainnet`, `eip155:1`). */
53
+ chain: string;
54
+ /** Contract (EVM, checksummed as read) or mint (Solana). The token's identity. */
55
+ address: string;
56
+ symbol: string;
57
+ name: string;
58
+ decimals: number;
59
+ /** `erc20`, `spl` or `spl-token-2022`. */
60
+ standard: string;
61
+ /** Facts read from the chain when it was added. */
62
+ flags: TokenFlag[];
63
+ /** When the user added it (ms since epoch). */
64
+ addedAt: number;
65
+ }
66
+ /** What {@link TokensTable} stores. */
67
+ interface TokensState {
68
+ v: 1;
69
+ tokens: UserToken[];
70
+ }
71
+ /** Codes of {@link TokensError}. */
72
+ type TokensErrorCode = 'not-loaded' | 'unsupported-chain' | 'bad-address' | 'listed' | 'bad-token' | 'full';
73
+ /** A refusal from the tokens table or {@link inspectToken}, with a machine-readable `code`. */
74
+ declare class TokensError extends Error {
75
+ readonly code: TokensErrorCode;
76
+ constructor(code: TokensErrorCode, message: string);
77
+ }
78
+ /** The result of looking a token up before adding it. */
79
+ type TokenInspection = {
80
+ listed: CcAsset;
81
+ } | {
82
+ listed?: undefined;
83
+ info: TokenInfo;
84
+ assessment: TokenAssessment;
85
+ token: UserToken;
86
+ };
87
+ /**
88
+ * Read a token from the chain through `account` (its chain decides where) and assess it. A token the
89
+ * catalog already lists comes back as `{ listed }`: nothing to add. Otherwise the token, ready for
90
+ * {@link TokensTable.add}, and the warnings to show first. Throws {@link TokensError}
91
+ * (`unsupported-chain`, `bad-address`) or the chain package's `NotATokenError`.
92
+ */
93
+ declare function inspectToken(account: Pick<IWalletAccountReadOnly, 'chain' | 'getTokenInfo'> & {
94
+ getChainId?: () => Promise<number | bigint>;
95
+ }, address: string, now?: () => number): Promise<TokenInspection>;
96
+ /**
97
+ * The swap options that name a user token as the source: its address and decimals. Pass them to an
98
+ * engine created with `allowUnlistedTokens: true`.
99
+ */
100
+ declare function swapSource(token: Pick<UserToken, 'address' | 'decimals'>): {
101
+ fromToken: string;
102
+ fromTokenDecimals: number;
103
+ };
104
+ /**
105
+ * The user's own tokens, over any JSON storage: load once at cold start, then read synchronously.
106
+ * Writes queue behind each other; a failed save leaves memory as stored. Tokens the catalog lists are
107
+ * refused (they are already there), and so are addresses that are not EVM contracts or Solana mints.
108
+ */
109
+ declare class TokensTable {
110
+ private readonly storage;
111
+ private _state;
112
+ private _loading;
113
+ private _writes;
114
+ private readonly listeners;
115
+ readonly maxTokens: number;
116
+ constructor(storage: JsonStorage<TokensState>, options?: {
117
+ maxTokens?: number;
118
+ });
119
+ /** Read the stored list. Call once before the sync reads; a failed read throws and leaves the table unloaded. */
120
+ load(): Promise<void>;
121
+ /** Called after every successful write. Returns the unsubscribe function. */
122
+ subscribe(fn: () => void): () => void;
123
+ /** The user's tokens, oldest first; only those on `chain` when given. */
124
+ list(chain?: string): UserToken[];
125
+ /** The user token at `address` on `chain`, if added. */
126
+ get(chain: string, address: string): UserToken | undefined;
127
+ /** Add (or refresh) a token — usually `inspection.token` after the user accepted the warnings. */
128
+ add(token: UserToken): Promise<UserToken>;
129
+ /** Remove a token. Returns whether it was there. */
130
+ remove(chain: string, address: string): Promise<boolean>;
131
+ private loaded;
132
+ private state;
133
+ private update;
134
+ }
135
+
136
+ export { type JsonStorage, type TokenAssessment, type TokenInspection, type TokenRisk, type TokenRiskCode, type TokenRiskLevel, TokensError, type TokensErrorCode, type TokensState, TokensTable, type UserToken, assessToken, foldSymbol, inspectToken, memoryJsonStorage, swapSource };
@@ -0,0 +1,136 @@
1
+ import { TokenFlag, TokenInfo, IWalletAccountReadOnly } from '@anywalletkit/core';
2
+ import { CcAsset } from '@anywalletkit/swap2-assets';
3
+
4
+ /** `danger`: the token can take or trap the user's money, or pretends to be another one. `caution`: worth knowing. */
5
+ type TokenRiskLevel = 'danger' | 'caution';
6
+ /**
7
+ * Why a token deserves a warning:
8
+ * - `unlisted`: always — the wallet's list does not include it, and anyone can deploy a token with any name and logo.
9
+ * - `impersonation`: its symbol reads as a known token's (USDC, ETH, …), look-alike letters included.
10
+ * - `odd-characters`: its symbol or name uses characters outside plain ASCII, or invisible ones.
11
+ * - `no-symbol`: it reports no symbol.
12
+ * - `zero-supply`: nothing has been minted.
13
+ * - `unusual-decimals`: more than 24 decimals.
14
+ * - a {@link TokenFlag} read from the chain (issuer powers, Token-2022 extensions).
15
+ */
16
+ type TokenRiskCode = 'unlisted' | 'impersonation' | 'odd-characters' | 'no-symbol' | 'zero-supply' | 'unusual-decimals' | TokenFlag;
17
+ /** One warning, worded for the person adding the token. */
18
+ interface TokenRisk {
19
+ code: TokenRiskCode;
20
+ level: TokenRiskLevel;
21
+ message: string;
22
+ }
23
+ /** Every warning that applies, worst first, and the worst level. A user token is never "safe": `caution` is the floor. */
24
+ interface TokenAssessment {
25
+ level: TokenRiskLevel;
26
+ risks: TokenRisk[];
27
+ }
28
+ /** A symbol folded the way a reader sees it: invisible characters gone, compatibility forms unified, look-alikes mapped, upper case. */
29
+ declare function foldSymbol(text: string): string;
30
+ /**
31
+ * Warnings for a token read with `getTokenInfo`, for a token the wallet's list does not include.
32
+ * Pure: nothing is fetched. `impersonation` when its symbol (look-alike letters folded) reads as a
33
+ * catalog token on the same `chain` — the real one would be in the list, this is another contract —
34
+ * or as a native coin or major stablecoin anywhere. A bridged token of another chain's list (JUP on
35
+ * Solana, listed on Unichain) is not flagged.
36
+ */
37
+ declare function assessToken(info: TokenInfo, chain?: string): TokenAssessment;
38
+
39
+ /** One JSON value under one key — the shape every small store needs (AsyncStorage, chrome.storage, memory). */
40
+ interface JsonStorage<T> {
41
+ /** The stored value, or `null` on first run. */
42
+ get(): Promise<T | null>;
43
+ /** Persist the value. */
44
+ set(value: T): Promise<void>;
45
+ }
46
+ /** In-memory storage for tests and smoke runs. */
47
+ declare function memoryJsonStorage<T>(initial?: T | null): JsonStorage<T> & {
48
+ value: T | null;
49
+ };
50
+ /** A token the user added. `symbol` and `name` are what the token reports: display them, never match on them. */
51
+ interface UserToken {
52
+ /** CAIP-2 chain id, the catalog's key (`solana:mainnet`, `eip155:1`). */
53
+ chain: string;
54
+ /** Contract (EVM, checksummed as read) or mint (Solana). The token's identity. */
55
+ address: string;
56
+ symbol: string;
57
+ name: string;
58
+ decimals: number;
59
+ /** `erc20`, `spl` or `spl-token-2022`. */
60
+ standard: string;
61
+ /** Facts read from the chain when it was added. */
62
+ flags: TokenFlag[];
63
+ /** When the user added it (ms since epoch). */
64
+ addedAt: number;
65
+ }
66
+ /** What {@link TokensTable} stores. */
67
+ interface TokensState {
68
+ v: 1;
69
+ tokens: UserToken[];
70
+ }
71
+ /** Codes of {@link TokensError}. */
72
+ type TokensErrorCode = 'not-loaded' | 'unsupported-chain' | 'bad-address' | 'listed' | 'bad-token' | 'full';
73
+ /** A refusal from the tokens table or {@link inspectToken}, with a machine-readable `code`. */
74
+ declare class TokensError extends Error {
75
+ readonly code: TokensErrorCode;
76
+ constructor(code: TokensErrorCode, message: string);
77
+ }
78
+ /** The result of looking a token up before adding it. */
79
+ type TokenInspection = {
80
+ listed: CcAsset;
81
+ } | {
82
+ listed?: undefined;
83
+ info: TokenInfo;
84
+ assessment: TokenAssessment;
85
+ token: UserToken;
86
+ };
87
+ /**
88
+ * Read a token from the chain through `account` (its chain decides where) and assess it. A token the
89
+ * catalog already lists comes back as `{ listed }`: nothing to add. Otherwise the token, ready for
90
+ * {@link TokensTable.add}, and the warnings to show first. Throws {@link TokensError}
91
+ * (`unsupported-chain`, `bad-address`) or the chain package's `NotATokenError`.
92
+ */
93
+ declare function inspectToken(account: Pick<IWalletAccountReadOnly, 'chain' | 'getTokenInfo'> & {
94
+ getChainId?: () => Promise<number | bigint>;
95
+ }, address: string, now?: () => number): Promise<TokenInspection>;
96
+ /**
97
+ * The swap options that name a user token as the source: its address and decimals. Pass them to an
98
+ * engine created with `allowUnlistedTokens: true`.
99
+ */
100
+ declare function swapSource(token: Pick<UserToken, 'address' | 'decimals'>): {
101
+ fromToken: string;
102
+ fromTokenDecimals: number;
103
+ };
104
+ /**
105
+ * The user's own tokens, over any JSON storage: load once at cold start, then read synchronously.
106
+ * Writes queue behind each other; a failed save leaves memory as stored. Tokens the catalog lists are
107
+ * refused (they are already there), and so are addresses that are not EVM contracts or Solana mints.
108
+ */
109
+ declare class TokensTable {
110
+ private readonly storage;
111
+ private _state;
112
+ private _loading;
113
+ private _writes;
114
+ private readonly listeners;
115
+ readonly maxTokens: number;
116
+ constructor(storage: JsonStorage<TokensState>, options?: {
117
+ maxTokens?: number;
118
+ });
119
+ /** Read the stored list. Call once before the sync reads; a failed read throws and leaves the table unloaded. */
120
+ load(): Promise<void>;
121
+ /** Called after every successful write. Returns the unsubscribe function. */
122
+ subscribe(fn: () => void): () => void;
123
+ /** The user's tokens, oldest first; only those on `chain` when given. */
124
+ list(chain?: string): UserToken[];
125
+ /** The user token at `address` on `chain`, if added. */
126
+ get(chain: string, address: string): UserToken | undefined;
127
+ /** Add (or refresh) a token — usually `inspection.token` after the user accepted the warnings. */
128
+ add(token: UserToken): Promise<UserToken>;
129
+ /** Remove a token. Returns whether it was there. */
130
+ remove(chain: string, address: string): Promise<boolean>;
131
+ private loaded;
132
+ private state;
133
+ private update;
134
+ }
135
+
136
+ export { type JsonStorage, type TokenAssessment, type TokenInspection, type TokenRisk, type TokenRiskCode, type TokenRiskLevel, TokensError, type TokensErrorCode, type TokensState, TokensTable, type UserToken, assessToken, foldSymbol, inspectToken, memoryJsonStorage, swapSource };
package/dist/index.js ADDED
@@ -0,0 +1,301 @@
1
+ // src/assess.ts
2
+ import { CC_SOURCE_CHAINS, catalogChainId, ccChain } from "@anywalletkit/swap2-assets";
3
+ var FLAG_RISKS = {
4
+ "upgradeable": { level: "caution", message: "The token's owner can replace its code." },
5
+ "mint-authority": { level: "caution", message: "The issuer can mint more at any time." },
6
+ "freeze-authority": { level: "caution", message: "The issuer can freeze your balance." },
7
+ "permanent-delegate": { level: "danger", message: "The issuer can move or burn the tokens in your wallet." },
8
+ "transfer-fee": { level: "caution", message: "Every transfer pays a fee to the issuer." },
9
+ "transfer-hook": { level: "danger", message: "A program of the issuer's choosing runs on every transfer: it can block selling." },
10
+ "non-transferable": { level: "danger", message: "It cannot be moved: not sent, not swapped." },
11
+ "default-frozen": { level: "caution", message: "New holders start frozen until the issuer lets them move it." },
12
+ "pausable": { level: "caution", message: "The issuer can pause every transfer." }
13
+ };
14
+ var CONFUSABLES = {
15
+ "\u0410": "A",
16
+ "\u0412": "B",
17
+ "\u0415": "E",
18
+ "\u041A": "K",
19
+ "\u041C": "M",
20
+ "\u041D": "H",
21
+ "\u041E": "O",
22
+ "\u0420": "P",
23
+ "\u0421": "C",
24
+ "\u0422": "T",
25
+ "\u0425": "X",
26
+ "\u0423": "Y",
27
+ "\u0406": "I",
28
+ "\u0408": "J",
29
+ "\u0405": "S",
30
+ "\u0500": "D",
31
+ "\u0430": "A",
32
+ "\u0432": "B",
33
+ "\u0435": "E",
34
+ "\u043A": "K",
35
+ "\u043C": "M",
36
+ "\u043D": "H",
37
+ "\u043E": "O",
38
+ "\u0440": "P",
39
+ "\u0441": "C",
40
+ "\u0442": "T",
41
+ "\u0445": "X",
42
+ "\u0443": "Y",
43
+ "\u0456": "I",
44
+ "\u0458": "J",
45
+ "\u0455": "S",
46
+ "\u0501": "D",
47
+ "\u0391": "A",
48
+ "\u0392": "B",
49
+ "\u0395": "E",
50
+ "\u0396": "Z",
51
+ "\u0397": "H",
52
+ "\u0399": "I",
53
+ "\u039A": "K",
54
+ "\u039C": "M",
55
+ "\u039D": "N",
56
+ "\u039F": "O",
57
+ "\u03A1": "P",
58
+ "\u03A4": "T",
59
+ "\u03A5": "Y",
60
+ "\u03A7": "X",
61
+ "\u03B1": "A",
62
+ "\u03B5": "E",
63
+ "\u03B9": "I",
64
+ "\u03BA": "K",
65
+ "\u03BD": "V",
66
+ "\u03BF": "O",
67
+ "\u03C1": "P",
68
+ "\u03C4": "T",
69
+ "\u03C5": "U",
70
+ "\u03C7": "X",
71
+ "$": "S",
72
+ "\u20AE": "T",
73
+ "\u20AC": "E",
74
+ "\xA2": "C",
75
+ "\u20BF": "B",
76
+ "\u039E": "E"
77
+ };
78
+ var INVISIBLE = /[­͏؜ᅟᅠ឴឵᠋-᠏​-‏‪-‮⁠-ㅤ︀-️ᅠ]/g;
79
+ function foldSymbol(text) {
80
+ let s = text.replace(INVISIBLE, "").replace(/\s+/g, "");
81
+ if (typeof s.normalize === "function") s = s.normalize("NFKC");
82
+ s = s.replace(/[\uFF01-\uFF5E]/g, (c) => String.fromCharCode(c.charCodeAt(0) - 65248));
83
+ let out = "";
84
+ for (const ch of s) out += CONFUSABLES[ch] ?? ch;
85
+ return out.toUpperCase();
86
+ }
87
+ var MAJOR_TOKENS = ["USDT", "USDC", "DAI", "USDe", "USDS", "PYUSD", "FDUSD", "USD1", "USDG", "EURC", "WETH", "WBTC", "cbBTC", "stETH", "wstETH", "WSOL"];
88
+ var majors;
89
+ function majorSymbols() {
90
+ if (majors) return majors;
91
+ const m = /* @__PURE__ */ new Map();
92
+ for (const chain of CC_SOURCE_CHAINS) for (const a of chain.assets) if (!a.contract && !m.has(foldSymbol(a.symbol))) m.set(foldSymbol(a.symbol), a.symbol);
93
+ for (const sym of MAJOR_TOKENS) if (!m.has(foldSymbol(sym))) m.set(foldSymbol(sym), sym);
94
+ majors = m;
95
+ return m;
96
+ }
97
+ function lookalikeOf(folded, chain) {
98
+ if (!folded) return void 0;
99
+ if (chain) {
100
+ const same = ccChain(catalogChainId(chain))?.assets.find((a) => foldSymbol(a.symbol) === folded);
101
+ if (same) return same.symbol;
102
+ }
103
+ return majorSymbols().get(folded);
104
+ }
105
+ var PLAIN = /^[\x20-\x7E]*$/;
106
+ function assessToken(info, chain) {
107
+ const risks = [{ code: "unlisted", level: "caution", message: "Not in the wallet's token list. Anyone can create a token with any name and logo: check the address with the project itself." }];
108
+ const folded = foldSymbol(info.symbol);
109
+ const lookalike = lookalikeOf(folded, chain);
110
+ if (lookalike) {
111
+ risks.push({ code: "impersonation", level: "danger", message: `It calls itself ${JSON.stringify(info.symbol)}, like ${lookalike}, but it is a different token at a different address.` });
112
+ }
113
+ if (!PLAIN.test(info.symbol) || !PLAIN.test(info.name) || info.symbol !== info.symbol.replace(INVISIBLE, "") || info.name !== info.name.replace(INVISIBLE, "")) {
114
+ risks.push({ code: "odd-characters", level: "caution", message: "Its symbol or name uses characters that can look like other letters, or invisible ones." });
115
+ }
116
+ if (!info.symbol.trim()) risks.push({ code: "no-symbol", level: "caution", message: "The token reports no symbol." });
117
+ if (info.totalSupply === 0n) risks.push({ code: "zero-supply", level: "caution", message: "Nothing has been minted." });
118
+ if (info.decimals > 24) risks.push({ code: "unusual-decimals", level: "caution", message: `It uses ${info.decimals} decimals; amounts may display oddly.` });
119
+ for (const flag of info.flags) {
120
+ const r = FLAG_RISKS[flag];
121
+ if (r) risks.push({ code: flag, ...r });
122
+ }
123
+ risks.sort((a, b) => a.level === b.level ? 0 : a.level === "danger" ? -1 : 1);
124
+ return { level: risks.some((r) => r.level === "danger") ? "danger" : "caution", risks };
125
+ }
126
+
127
+ // src/table.ts
128
+ import { catalogChainId as catalogChainId2, ccAssetByToken, isTokenAddress } from "@anywalletkit/swap2-assets";
129
+ function memoryJsonStorage(initial = null) {
130
+ const clone = (v) => JSON.parse(JSON.stringify(v));
131
+ const s = {
132
+ value: initial,
133
+ async get() {
134
+ return s.value === null ? null : clone(s.value);
135
+ },
136
+ async set(value) {
137
+ s.value = clone(value);
138
+ }
139
+ };
140
+ return s;
141
+ }
142
+ var TokensError = class extends Error {
143
+ code;
144
+ constructor(code, message) {
145
+ super(message);
146
+ this.name = "TokensError";
147
+ this.code = code;
148
+ }
149
+ };
150
+ var sameAddress = (chain, a, b) => chain.startsWith("eip155:") ? a.toLowerCase() === b.toLowerCase() : a === b;
151
+ var FLAGS = /* @__PURE__ */ new Set(["upgradeable", "mint-authority", "freeze-authority", "permanent-delegate", "transfer-fee", "transfer-hook", "non-transferable", "default-frozen", "pausable"]);
152
+ function validEntry(t) {
153
+ if (!t || typeof t !== "object") return null;
154
+ const e = t;
155
+ if (typeof e.chain !== "string" || typeof e.address !== "string" || !isTokenAddress(e.chain, e.address)) return null;
156
+ if (typeof e.decimals !== "number" || !Number.isInteger(e.decimals) || e.decimals < 0 || e.decimals > 77) return null;
157
+ if (typeof e.symbol !== "string" || typeof e.name !== "string" || typeof e.standard !== "string" || typeof e.addedAt !== "number") return null;
158
+ if (!Array.isArray(e.flags) || !e.flags.every((f) => typeof f === "string" && FLAGS.has(f))) return null;
159
+ return {
160
+ chain: e.chain,
161
+ address: e.address,
162
+ symbol: e.symbol.slice(0, 128),
163
+ name: e.name.slice(0, 128),
164
+ decimals: e.decimals,
165
+ standard: e.standard,
166
+ flags: [...e.flags],
167
+ addedAt: e.addedAt
168
+ };
169
+ }
170
+ async function inspectToken(account, address, now = Date.now) {
171
+ let reported = account.chain;
172
+ if (reported === "eip155:unknown") {
173
+ if (typeof account.getChainId !== "function") throw new TokensError("unsupported-chain", "The account does not know its chain id; create it with chainId.");
174
+ reported = `eip155:${String(await account.getChainId())}`;
175
+ }
176
+ const chain = catalogChainId2(reported);
177
+ if (!chain.startsWith("eip155:") && !chain.startsWith("solana:")) throw new TokensError("unsupported-chain", `Adding tokens is supported on EVM chains and Solana, not ${account.chain}.`);
178
+ const ref = address.trim();
179
+ if (!isTokenAddress(chain, ref)) throw new TokensError("bad-address", `${JSON.stringify(address)} is not a token address on ${chain}.`);
180
+ const listed = ccAssetByToken(chain, ref);
181
+ if (listed) return { listed };
182
+ if (typeof account.getTokenInfo !== "function") throw new TokensError("unsupported-chain", `This ${account.chain} account cannot read token info.`);
183
+ const info = await account.getTokenInfo(ref);
184
+ const token = {
185
+ chain,
186
+ address: info.address,
187
+ symbol: info.symbol.slice(0, 128),
188
+ name: info.name.slice(0, 128),
189
+ decimals: info.decimals,
190
+ standard: info.standard,
191
+ flags: [...info.flags],
192
+ addedAt: now()
193
+ };
194
+ return { info, assessment: assessToken(info, chain), token };
195
+ }
196
+ function swapSource(token) {
197
+ return { fromToken: token.address, fromTokenDecimals: token.decimals };
198
+ }
199
+ var TokensTable = class {
200
+ constructor(storage, options = {}) {
201
+ this.storage = storage;
202
+ this.maxTokens = options.maxTokens ?? 200;
203
+ }
204
+ storage;
205
+ _state = null;
206
+ _loading = null;
207
+ _writes = Promise.resolve();
208
+ listeners = /* @__PURE__ */ new Set();
209
+ maxTokens;
210
+ /** Read the stored list. Call once before the sync reads; a failed read throws and leaves the table unloaded. */
211
+ async load() {
212
+ await this.state();
213
+ }
214
+ /** Called after every successful write. Returns the unsubscribe function. */
215
+ subscribe(fn) {
216
+ this.listeners.add(fn);
217
+ return () => {
218
+ this.listeners.delete(fn);
219
+ };
220
+ }
221
+ /** The user's tokens, oldest first; only those on `chain` when given. */
222
+ list(chain) {
223
+ const s = this.loaded();
224
+ const want = chain === void 0 ? void 0 : catalogChainId2(chain);
225
+ return s.tokens.filter((t) => want === void 0 || t.chain === want).map((t) => ({ ...t, flags: [...t.flags] }));
226
+ }
227
+ /** The user token at `address` on `chain`, if added. */
228
+ get(chain, address) {
229
+ const c = catalogChainId2(chain);
230
+ const t = this.loaded().tokens.find((x) => x.chain === c && sameAddress(c, x.address, address));
231
+ return t ? { ...t, flags: [...t.flags] } : void 0;
232
+ }
233
+ /** Add (or refresh) a token — usually `inspection.token` after the user accepted the warnings. */
234
+ async add(token) {
235
+ const entry = validEntry({ ...token, chain: catalogChainId2(token.chain) });
236
+ if (!entry) throw new TokensError("bad-token", "Not a valid token entry (address, decimals 0\u201377, symbol, name, standard, flags).");
237
+ if (ccAssetByToken(entry.chain, entry.address)) throw new TokensError("listed", `${entry.address} is already in the wallet's token list.`);
238
+ await this.update((s) => {
239
+ const rest = s.tokens.filter((t) => !(t.chain === entry.chain && sameAddress(entry.chain, t.address, entry.address)));
240
+ if (rest.length >= this.maxTokens) throw new TokensError("full", `At most ${this.maxTokens} tokens can be added.`);
241
+ return { v: 1, tokens: [...rest, entry] };
242
+ });
243
+ return { ...entry, flags: [...entry.flags] };
244
+ }
245
+ /** Remove a token. Returns whether it was there. */
246
+ async remove(chain, address) {
247
+ const c = catalogChainId2(chain);
248
+ let removed = false;
249
+ await this.update((s) => {
250
+ const rest = s.tokens.filter((t) => !(t.chain === c && sameAddress(c, t.address, address)));
251
+ removed = rest.length !== s.tokens.length;
252
+ return { v: 1, tokens: rest };
253
+ });
254
+ return removed;
255
+ }
256
+ loaded() {
257
+ if (!this._state) throw new TokensError("not-loaded", "Call load() before reading the tokens table.");
258
+ return this._state;
259
+ }
260
+ async state() {
261
+ if (this._state) return this._state;
262
+ this._loading ??= (async () => {
263
+ let stored;
264
+ try {
265
+ stored = await this.storage.get();
266
+ } catch (e) {
267
+ this._loading = null;
268
+ throw e;
269
+ }
270
+ const tokens = stored && stored.v === 1 && Array.isArray(stored.tokens) ? stored.tokens.map(validEntry).filter((t) => t !== null) : [];
271
+ this._state = { v: 1, tokens };
272
+ return this._state;
273
+ })();
274
+ return this._loading;
275
+ }
276
+ update(change) {
277
+ const run = this._writes.then(async () => {
278
+ const next = change(await this.state());
279
+ await this.storage.set(next);
280
+ this._state = next;
281
+ for (const fn of this.listeners) {
282
+ try {
283
+ fn();
284
+ } catch {
285
+ }
286
+ }
287
+ });
288
+ this._writes = run.catch(() => void 0);
289
+ return run;
290
+ }
291
+ };
292
+ export {
293
+ TokensError,
294
+ TokensTable,
295
+ assessToken,
296
+ foldSymbol,
297
+ inspectToken,
298
+ memoryJsonStorage,
299
+ swapSource
300
+ };
301
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/assess.ts","../src/table.ts"],"sourcesContent":["import type { TokenFlag, TokenInfo } from '@anywalletkit/core'\nimport { CC_SOURCE_CHAINS, catalogChainId, ccChain } from '@anywalletkit/swap2-assets'\n\n/** `danger`: the token can take or trap the user's money, or pretends to be another one. `caution`: worth knowing. */\nexport type TokenRiskLevel = 'danger' | 'caution'\n\n/**\n * Why a token deserves a warning:\n * - `unlisted`: always — the wallet's list does not include it, and anyone can deploy a token with any name and logo.\n * - `impersonation`: its symbol reads as a known token's (USDC, ETH, …), look-alike letters included.\n * - `odd-characters`: its symbol or name uses characters outside plain ASCII, or invisible ones.\n * - `no-symbol`: it reports no symbol.\n * - `zero-supply`: nothing has been minted.\n * - `unusual-decimals`: more than 24 decimals.\n * - a {@link TokenFlag} read from the chain (issuer powers, Token-2022 extensions).\n */\nexport type TokenRiskCode = 'unlisted' | 'impersonation' | 'odd-characters' | 'no-symbol' | 'zero-supply' | 'unusual-decimals' | TokenFlag\n\n/** One warning, worded for the person adding the token. */\nexport interface TokenRisk {\n code: TokenRiskCode\n level: TokenRiskLevel\n message: string\n}\n\n/** Every warning that applies, worst first, and the worst level. A user token is never \"safe\": `caution` is the floor. */\nexport interface TokenAssessment {\n level: TokenRiskLevel\n risks: TokenRisk[]\n}\n\nconst FLAG_RISKS: Readonly<Record<TokenFlag, { level: TokenRiskLevel; message: string }>> = {\n 'upgradeable': { level: 'caution', message: \"The token's owner can replace its code.\" },\n 'mint-authority': { level: 'caution', message: 'The issuer can mint more at any time.' },\n 'freeze-authority': { level: 'caution', message: 'The issuer can freeze your balance.' },\n 'permanent-delegate': { level: 'danger', message: 'The issuer can move or burn the tokens in your wallet.' },\n 'transfer-fee': { level: 'caution', message: 'Every transfer pays a fee to the issuer.' },\n 'transfer-hook': { level: 'danger', message: \"A program of the issuer's choosing runs on every transfer: it can block selling.\" },\n 'non-transferable': { level: 'danger', message: 'It cannot be moved: not sent, not swapped.' },\n 'default-frozen': { level: 'caution', message: 'New holders start frozen until the issuer lets them move it.' },\n 'pausable': { level: 'caution', message: 'The issuer can pause every transfer.' },\n}\n\n/** Letters that render like Latin capitals (Cyrillic, Greek) and currency signs used as letters. */\nconst CONFUSABLES: Readonly<Record<string, string>> = {\n 'А': 'A', 'В': 'B', 'Е': 'E', 'К': 'K', 'М': 'M', 'Н': 'H', 'О': 'O', 'Р': 'P', 'С': 'C', 'Т': 'T', 'Х': 'X', 'У': 'Y', 'І': 'I', 'Ј': 'J', 'Ѕ': 'S', 'Ԁ': 'D',\n 'а': 'A', 'в': 'B', 'е': 'E', 'к': 'K', 'м': 'M', 'н': 'H', 'о': 'O', 'р': 'P', 'с': 'C', 'т': 'T', 'х': 'X', 'у': 'Y', 'і': 'I', 'ј': 'J', 'ѕ': 'S', 'ԁ': 'D',\n 'Α': 'A', 'Β': 'B', 'Ε': 'E', 'Ζ': 'Z', 'Η': 'H', 'Ι': 'I', 'Κ': 'K', 'Μ': 'M', 'Ν': 'N', 'Ο': 'O', 'Ρ': 'P', 'Τ': 'T', 'Υ': 'Y', 'Χ': 'X',\n 'α': 'A', 'ε': 'E', 'ι': 'I', 'κ': 'K', 'ν': 'V', 'ο': 'O', 'ρ': 'P', 'τ': 'T', 'υ': 'U', 'χ': 'X',\n '$': 'S', '₮': 'T', '€': 'E', '¢': 'C', '₿': 'B', 'Ξ': 'E',\n}\n/** Zero-width, bidi and other invisible format characters. */\nconst INVISIBLE = /[­͏؜ᅟᅠ឴឵᠋-᠏​-‏‪-‮⁠-ㅤ︀-️ᅠ]/g\n\n/** A symbol folded the way a reader sees it: invisible characters gone, compatibility forms unified, look-alikes mapped, upper case. */\nexport function foldSymbol(text: string): string {\n let s = text.replace(INVISIBLE, '').replace(/\\s+/g, '')\n if (typeof s.normalize === 'function') s = s.normalize('NFKC')\n // Fullwidth ASCII by hand too: some Hermes builds ship without String.prototype.normalize.\n s = s.replace(/[\\uFF01-\\uFF5E]/g, (c) => String.fromCharCode(c.charCodeAt(0) - 0xFEE0))\n let out = ''\n for (const ch of s) out += CONFUSABLES[ch] ?? ch\n return out.toUpperCase()\n}\n\n/** Symbols nobody should reuse on any chain: the big stablecoins and wrapped coins (natives are added from the catalog). */\nconst MAJOR_TOKENS = ['USDT', 'USDC', 'DAI', 'USDe', 'USDS', 'PYUSD', 'FDUSD', 'USD1', 'USDG', 'EURC', 'WETH', 'WBTC', 'cbBTC', 'stETH', 'wstETH', 'WSOL']\n\nlet majors: ReadonlyMap<string, string> | undefined\n/** Folded → display: every chain's native coin from the catalog, plus {@link MAJOR_TOKENS}. */\nfunction majorSymbols(): ReadonlyMap<string, string> {\n if (majors) return majors\n const m = new Map<string, string>()\n for (const chain of CC_SOURCE_CHAINS) for (const a of chain.assets) if (!a.contract && !m.has(foldSymbol(a.symbol))) m.set(foldSymbol(a.symbol), a.symbol)\n for (const sym of MAJOR_TOKENS) if (!m.has(foldSymbol(sym))) m.set(foldSymbol(sym), sym)\n majors = m\n return m\n}\n\n/** The known token a folded symbol reads as: any catalog token on the same chain, or a major one anywhere. */\nfunction lookalikeOf(folded: string, chain: string | undefined): string | undefined {\n if (!folded) return undefined\n if (chain) {\n const same = ccChain(catalogChainId(chain))?.assets.find((a) => foldSymbol(a.symbol) === folded)\n if (same) return same.symbol\n }\n return majorSymbols().get(folded)\n}\n\nconst PLAIN = /^[\\x20-\\x7E]*$/\n\n/**\n * Warnings for a token read with `getTokenInfo`, for a token the wallet's list does not include.\n * Pure: nothing is fetched. `impersonation` when its symbol (look-alike letters folded) reads as a\n * catalog token on the same `chain` — the real one would be in the list, this is another contract —\n * or as a native coin or major stablecoin anywhere. A bridged token of another chain's list (JUP on\n * Solana, listed on Unichain) is not flagged.\n */\nexport function assessToken(info: TokenInfo, chain?: string): TokenAssessment {\n const risks: TokenRisk[] = [{ code: 'unlisted', level: 'caution', message: \"Not in the wallet's token list. Anyone can create a token with any name and logo: check the address with the project itself.\" }]\n const folded = foldSymbol(info.symbol)\n const lookalike = lookalikeOf(folded, chain)\n if (lookalike) {\n risks.push({ code: 'impersonation', level: 'danger', message: `It calls itself ${JSON.stringify(info.symbol)}, like ${lookalike}, but it is a different token at a different address.` })\n }\n if (!PLAIN.test(info.symbol) || !PLAIN.test(info.name) || info.symbol !== info.symbol.replace(INVISIBLE, '') || info.name !== info.name.replace(INVISIBLE, '')) {\n risks.push({ code: 'odd-characters', level: 'caution', message: 'Its symbol or name uses characters that can look like other letters, or invisible ones.' })\n }\n if (!info.symbol.trim()) risks.push({ code: 'no-symbol', level: 'caution', message: 'The token reports no symbol.' })\n if (info.totalSupply === 0n) risks.push({ code: 'zero-supply', level: 'caution', message: 'Nothing has been minted.' })\n if (info.decimals > 24) risks.push({ code: 'unusual-decimals', level: 'caution', message: `It uses ${info.decimals} decimals; amounts may display oddly.` })\n for (const flag of info.flags) {\n const r = FLAG_RISKS[flag]\n if (r) risks.push({ code: flag, ...r })\n }\n risks.sort((a, b) => (a.level === b.level ? 0 : a.level === 'danger' ? -1 : 1))\n return { level: risks.some((r) => r.level === 'danger') ? 'danger' : 'caution', risks }\n}\n","import type { IWalletAccountReadOnly, TokenFlag, TokenInfo } from '@anywalletkit/core'\nimport { catalogChainId, ccAssetByToken, isTokenAddress, type CcAsset } from '@anywalletkit/swap2-assets'\nimport { assessToken, type TokenAssessment } from './assess.js'\n\n/** One JSON value under one key — the shape every small store needs (AsyncStorage, chrome.storage, memory). */\nexport interface JsonStorage<T> {\n /** The stored value, or `null` on first run. */\n get(): Promise<T | null>\n /** Persist the value. */\n set(value: T): Promise<void>\n}\n\n/** In-memory storage for tests and smoke runs. */\nexport function memoryJsonStorage<T>(initial: T | null = null): JsonStorage<T> & { value: T | null } {\n const clone = (v: T): T => JSON.parse(JSON.stringify(v)) as T\n const s = {\n value: initial,\n async get() { return s.value === null ? null : clone(s.value) },\n async set(value: T) { s.value = clone(value) },\n }\n return s\n}\n\n/** A token the user added. `symbol` and `name` are what the token reports: display them, never match on them. */\nexport interface UserToken {\n /** CAIP-2 chain id, the catalog's key (`solana:mainnet`, `eip155:1`). */\n chain: string\n /** Contract (EVM, checksummed as read) or mint (Solana). The token's identity. */\n address: string\n symbol: string\n name: string\n decimals: number\n /** `erc20`, `spl` or `spl-token-2022`. */\n standard: string\n /** Facts read from the chain when it was added. */\n flags: TokenFlag[]\n /** When the user added it (ms since epoch). */\n addedAt: number\n}\n\n/** What {@link TokensTable} stores. */\nexport interface TokensState {\n v: 1\n tokens: UserToken[]\n}\n\n/** Codes of {@link TokensError}. */\nexport type TokensErrorCode = 'not-loaded' | 'unsupported-chain' | 'bad-address' | 'listed' | 'bad-token' | 'full'\n\n/** A refusal from the tokens table or {@link inspectToken}, with a machine-readable `code`. */\nexport class TokensError extends Error {\n readonly code: TokensErrorCode\n constructor(code: TokensErrorCode, message: string) {\n super(message)\n this.name = 'TokensError'\n this.code = code\n }\n}\n\nconst sameAddress = (chain: string, a: string, b: string) => (chain.startsWith('eip155:') ? a.toLowerCase() === b.toLowerCase() : a === b)\nconst FLAGS: ReadonlySet<string> = new Set<TokenFlag>(['upgradeable', 'mint-authority', 'freeze-authority', 'permanent-delegate', 'transfer-fee', 'transfer-hook', 'non-transferable', 'default-frozen', 'pausable'])\n\n/** A stored entry as it must be, or null (a hand-edited or corrupted entry is dropped, never trusted). */\nfunction validEntry(t: unknown): UserToken | null {\n if (!t || typeof t !== 'object') return null\n const e = t as Record<string, unknown>\n if (typeof e.chain !== 'string' || typeof e.address !== 'string' || !isTokenAddress(e.chain, e.address)) return null\n if (typeof e.decimals !== 'number' || !Number.isInteger(e.decimals) || e.decimals < 0 || e.decimals > 77) return null\n if (typeof e.symbol !== 'string' || typeof e.name !== 'string' || typeof e.standard !== 'string' || typeof e.addedAt !== 'number') return null\n if (!Array.isArray(e.flags) || !e.flags.every((f) => typeof f === 'string' && FLAGS.has(f))) return null\n return {\n chain: e.chain, address: e.address, symbol: e.symbol.slice(0, 128), name: e.name.slice(0, 128), decimals: e.decimals,\n standard: e.standard, flags: [...e.flags] as TokenFlag[], addedAt: e.addedAt,\n }\n}\n\n/** The result of looking a token up before adding it. */\nexport type TokenInspection =\n | { listed: CcAsset }\n | { listed?: undefined; info: TokenInfo; assessment: TokenAssessment; token: UserToken }\n\n/**\n * Read a token from the chain through `account` (its chain decides where) and assess it. A token the\n * catalog already lists comes back as `{ listed }`: nothing to add. Otherwise the token, ready for\n * {@link TokensTable.add}, and the warnings to show first. Throws {@link TokensError}\n * (`unsupported-chain`, `bad-address`) or the chain package's `NotATokenError`.\n */\nexport async function inspectToken(\n account: Pick<IWalletAccountReadOnly, 'chain' | 'getTokenInfo'> & { getChainId?: () => Promise<number | bigint> },\n address: string,\n now: () => number = Date.now,\n): Promise<TokenInspection> {\n let reported = account.chain\n // An EVM account created without a chain id reports 'eip155:unknown' until it has asked its RPC:\n // ask now, or the catalog check (already listed? a look-alike of this chain's tokens?) would miss.\n if (reported === 'eip155:unknown') {\n if (typeof account.getChainId !== 'function') throw new TokensError('unsupported-chain', 'The account does not know its chain id; create it with chainId.')\n reported = `eip155:${String(await account.getChainId())}`\n }\n const chain = catalogChainId(reported)\n if (!chain.startsWith('eip155:') && !chain.startsWith('solana:')) throw new TokensError('unsupported-chain', `Adding tokens is supported on EVM chains and Solana, not ${account.chain}.`)\n const ref = address.trim()\n if (!isTokenAddress(chain, ref)) throw new TokensError('bad-address', `${JSON.stringify(address)} is not a token address on ${chain}.`)\n const listed = ccAssetByToken(chain, ref)\n if (listed) return { listed }\n if (typeof account.getTokenInfo !== 'function') throw new TokensError('unsupported-chain', `This ${account.chain} account cannot read token info.`)\n const info = await account.getTokenInfo(ref)\n const token: UserToken = {\n chain, address: info.address, symbol: info.symbol.slice(0, 128), name: info.name.slice(0, 128), decimals: info.decimals,\n standard: info.standard, flags: [...info.flags], addedAt: now(),\n }\n return { info, assessment: assessToken(info, chain), token }\n}\n\n/**\n * The swap options that name a user token as the source: its address and decimals. Pass them to an\n * engine created with `allowUnlistedTokens: true`.\n */\nexport function swapSource(token: Pick<UserToken, 'address' | 'decimals'>): { fromToken: string; fromTokenDecimals: number } {\n return { fromToken: token.address, fromTokenDecimals: token.decimals }\n}\n\n/**\n * The user's own tokens, over any JSON storage: load once at cold start, then read synchronously.\n * Writes queue behind each other; a failed save leaves memory as stored. Tokens the catalog lists are\n * refused (they are already there), and so are addresses that are not EVM contracts or Solana mints.\n */\nexport class TokensTable {\n private _state: TokensState | null = null\n private _loading: Promise<TokensState> | null = null\n private _writes: Promise<unknown> = Promise.resolve()\n private readonly listeners = new Set<() => void>()\n readonly maxTokens: number\n\n constructor(private readonly storage: JsonStorage<TokensState>, options: { maxTokens?: number } = {}) {\n this.maxTokens = options.maxTokens ?? 200\n }\n\n /** Read the stored list. Call once before the sync reads; a failed read throws and leaves the table unloaded. */\n async load(): Promise<void> {\n await this.state()\n }\n\n /** Called after every successful write. Returns the unsubscribe function. */\n subscribe(fn: () => void): () => void {\n this.listeners.add(fn)\n return () => { this.listeners.delete(fn) }\n }\n\n /** The user's tokens, oldest first; only those on `chain` when given. */\n list(chain?: string): UserToken[] {\n const s = this.loaded()\n const want = chain === undefined ? undefined : catalogChainId(chain)\n return s.tokens.filter((t) => want === undefined || t.chain === want).map((t) => ({ ...t, flags: [...t.flags] }))\n }\n\n /** The user token at `address` on `chain`, if added. */\n get(chain: string, address: string): UserToken | undefined {\n const c = catalogChainId(chain)\n const t = this.loaded().tokens.find((x) => x.chain === c && sameAddress(c, x.address, address))\n return t ? { ...t, flags: [...t.flags] } : undefined\n }\n\n /** Add (or refresh) a token — usually `inspection.token` after the user accepted the warnings. */\n async add(token: UserToken): Promise<UserToken> {\n const entry = validEntry({ ...token, chain: catalogChainId(token.chain) })\n if (!entry) throw new TokensError('bad-token', 'Not a valid token entry (address, decimals 0–77, symbol, name, standard, flags).')\n if (ccAssetByToken(entry.chain, entry.address)) throw new TokensError('listed', `${entry.address} is already in the wallet's token list.`)\n await this.update((s) => {\n const rest = s.tokens.filter((t) => !(t.chain === entry.chain && sameAddress(entry.chain, t.address, entry.address)))\n if (rest.length >= this.maxTokens) throw new TokensError('full', `At most ${this.maxTokens} tokens can be added.`)\n return { v: 1, tokens: [...rest, entry] }\n })\n return { ...entry, flags: [...entry.flags] }\n }\n\n /** Remove a token. Returns whether it was there. */\n async remove(chain: string, address: string): Promise<boolean> {\n const c = catalogChainId(chain)\n let removed = false\n await this.update((s) => {\n const rest = s.tokens.filter((t) => !(t.chain === c && sameAddress(c, t.address, address)))\n removed = rest.length !== s.tokens.length\n return { v: 1, tokens: rest }\n })\n return removed\n }\n\n private loaded(): TokensState {\n if (!this._state) throw new TokensError('not-loaded', 'Call load() before reading the tokens table.')\n return this._state\n }\n\n private async state(): Promise<TokensState> {\n if (this._state) return this._state\n this._loading ??= (async () => {\n let stored: TokensState | null\n try {\n stored = await this.storage.get()\n } catch (e) {\n // A failed read is not an empty list: the next write would erase the user's tokens.\n this._loading = null\n throw e\n }\n const tokens = stored && stored.v === 1 && Array.isArray(stored.tokens)\n ? stored.tokens.map(validEntry).filter((t): t is UserToken => t !== null)\n : []\n this._state = { v: 1, tokens }\n return this._state\n })()\n return this._loading\n }\n\n private update(change: (s: TokensState) => TokensState): Promise<void> {\n const run = this._writes.then(async () => {\n const next = change(await this.state())\n await this.storage.set(next)\n this._state = next\n for (const fn of this.listeners) {\n try { fn() } catch { /* a listener's failure is its own */ }\n }\n })\n this._writes = run.catch(() => undefined)\n return run\n }\n}\n"],"mappings":";AACA,SAAS,kBAAkB,gBAAgB,eAAe;AA8B1D,IAAM,aAAsF;AAAA,EAC1F,eAAe,EAAE,OAAO,WAAW,SAAS,0CAA0C;AAAA,EACtF,kBAAkB,EAAE,OAAO,WAAW,SAAS,wCAAwC;AAAA,EACvF,oBAAoB,EAAE,OAAO,WAAW,SAAS,sCAAsC;AAAA,EACvF,sBAAsB,EAAE,OAAO,UAAU,SAAS,yDAAyD;AAAA,EAC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