@pancakeswap/token-lists 0.0.6 → 0.0.8

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,45 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __defProps = Object.defineProperties;
5
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
10
+ var __spreadValues = (a, b) => {
11
+ for (var prop in b || (b = {}))
12
+ if (__hasOwnProp.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ if (__getOwnPropSymbols)
15
+ for (var prop of __getOwnPropSymbols(b)) {
16
+ if (__propIsEnum.call(b, prop))
17
+ __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
+ };
21
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
+ var __async = (__this, __arguments, generator) => {
23
+ return new Promise((resolve, reject) => {
24
+ var fulfilled = (value) => {
25
+ try {
26
+ step(generator.next(value));
27
+ } catch (e) {
28
+ reject(e);
29
+ }
30
+ };
31
+ var rejected = (value) => {
32
+ try {
33
+ step(generator.throw(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
39
+ step((generator = generator.apply(__this, __arguments)).next());
40
+ });
41
+ };
42
+
43
+ exports.__async = __async;
44
+ exports.__spreadProps = __spreadProps;
45
+ exports.__spreadValues = __spreadValues;
@@ -1,5 +1,6 @@
1
+ import { Token } from '@pancakeswap/swap-sdk-core';
2
+
1
3
  // src/wrappedTokenInfo.ts
2
- import { Token } from "@pancakeswap/swap-sdk-core";
3
4
  var WrappedTokenInfo = class extends Token {
4
5
  constructor(tokenInfo) {
5
6
  super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name);
@@ -62,9 +63,24 @@ function getVersionUpgrade(base, update) {
62
63
  return update.patch > base.patch ? 1 /* PATCH */ : 0 /* NONE */;
63
64
  }
64
65
 
65
- export {
66
- WrappedTokenInfo,
67
- deserializeToken,
68
- VersionUpgrade,
69
- getVersionUpgrade
70
- };
66
+ // src/filtering.ts
67
+ function createFilterToken(search, isAddress) {
68
+ if (isAddress(search)) {
69
+ const address = search.toLowerCase();
70
+ return (t) => "address" in t && address === t.address.toLowerCase();
71
+ }
72
+ const lowerSearchParts = search.toLowerCase().split(/\s+/).filter((s) => s.length > 0);
73
+ if (lowerSearchParts.length === 0) {
74
+ return () => true;
75
+ }
76
+ const matchesSearch = (s) => {
77
+ const sParts = s.toLowerCase().split(/\s+/).filter((s_) => s_.length > 0);
78
+ return lowerSearchParts.every((p) => p.length === 0 || sParts.some((sp) => sp.startsWith(p) || sp.endsWith(p)));
79
+ };
80
+ return (token) => {
81
+ const { symbol, name } = token;
82
+ return Boolean(symbol && matchesSearch(symbol) || name && matchesSearch(name));
83
+ };
84
+ }
85
+
86
+ export { VersionUpgrade, WrappedTokenInfo, createFilterToken, deserializeToken, getVersionUpgrade };
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ var swapSdkCore = require('@pancakeswap/swap-sdk-core');
4
+
5
+ // src/wrappedTokenInfo.ts
6
+ var WrappedTokenInfo = class extends swapSdkCore.Token {
7
+ constructor(tokenInfo) {
8
+ super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name);
9
+ this.logoURI = tokenInfo.logoURI;
10
+ }
11
+ get serialize() {
12
+ return {
13
+ address: this.address,
14
+ chainId: this.chainId,
15
+ decimals: this.decimals,
16
+ symbol: this.symbol,
17
+ name: this.name,
18
+ projectLink: this.projectLink,
19
+ logoURI: this.logoURI
20
+ };
21
+ }
22
+ };
23
+ function deserializeToken(serializedToken) {
24
+ if (serializedToken.logoURI) {
25
+ return new WrappedTokenInfo({
26
+ chainId: serializedToken.chainId,
27
+ address: serializedToken.address,
28
+ decimals: serializedToken.decimals,
29
+ symbol: serializedToken.symbol || "Unknown",
30
+ name: serializedToken.name || "Unknown",
31
+ logoURI: serializedToken.logoURI
32
+ });
33
+ }
34
+ return new swapSdkCore.Token(
35
+ serializedToken.chainId,
36
+ serializedToken.address,
37
+ serializedToken.decimals,
38
+ serializedToken.symbol,
39
+ serializedToken.name,
40
+ serializedToken.projectLink
41
+ );
42
+ }
43
+
44
+ // src/getVersionUpgrade.ts
45
+ var VersionUpgrade = /* @__PURE__ */ ((VersionUpgrade2) => {
46
+ VersionUpgrade2[VersionUpgrade2["NONE"] = 0] = "NONE";
47
+ VersionUpgrade2[VersionUpgrade2["PATCH"] = 1] = "PATCH";
48
+ VersionUpgrade2[VersionUpgrade2["MINOR"] = 2] = "MINOR";
49
+ VersionUpgrade2[VersionUpgrade2["MAJOR"] = 3] = "MAJOR";
50
+ return VersionUpgrade2;
51
+ })(VersionUpgrade || {});
52
+ function getVersionUpgrade(base, update) {
53
+ if (update.major > base.major) {
54
+ return 3 /* MAJOR */;
55
+ }
56
+ if (update.major < base.major) {
57
+ return 0 /* NONE */;
58
+ }
59
+ if (update.minor > base.minor) {
60
+ return 2 /* MINOR */;
61
+ }
62
+ if (update.minor < base.minor) {
63
+ return 0 /* NONE */;
64
+ }
65
+ return update.patch > base.patch ? 1 /* PATCH */ : 0 /* NONE */;
66
+ }
67
+
68
+ // src/filtering.ts
69
+ function createFilterToken(search, isAddress) {
70
+ if (isAddress(search)) {
71
+ const address = search.toLowerCase();
72
+ return (t) => "address" in t && address === t.address.toLowerCase();
73
+ }
74
+ const lowerSearchParts = search.toLowerCase().split(/\s+/).filter((s) => s.length > 0);
75
+ if (lowerSearchParts.length === 0) {
76
+ return () => true;
77
+ }
78
+ const matchesSearch = (s) => {
79
+ const sParts = s.toLowerCase().split(/\s+/).filter((s_) => s_.length > 0);
80
+ return lowerSearchParts.every((p) => p.length === 0 || sParts.some((sp) => sp.startsWith(p) || sp.endsWith(p)));
81
+ };
82
+ return (token) => {
83
+ const { symbol, name } = token;
84
+ return Boolean(symbol && matchesSearch(symbol) || name && matchesSearch(name));
85
+ };
86
+ }
87
+
88
+ exports.VersionUpgrade = VersionUpgrade;
89
+ exports.WrappedTokenInfo = WrappedTokenInfo;
90
+ exports.createFilterToken = createFilterToken;
91
+ exports.deserializeToken = deserializeToken;
92
+ exports.getVersionUpgrade = getVersionUpgrade;
@@ -1,6 +1,6 @@
1
- import {
2
- __async
3
- } from "./chunk-2L3ZO4UM.mjs";
1
+ import { __async } from './chunk-2L3ZO4UM.mjs';
2
+ import remove from 'lodash/remove';
3
+ import Ajv from 'ajv';
4
4
 
5
5
  // ../utils/uriToHttp.ts
6
6
  function uriToHttp(uri) {
@@ -22,10 +22,6 @@ function uriToHttp(uri) {
22
22
  }
23
23
  }
24
24
 
25
- // react/getTokenList.ts
26
- import remove from "lodash/remove";
27
- import Ajv from "ajv";
28
-
29
25
  // schema/pancakeswap.json
30
26
  var pancakeswap_default = {
31
27
  $schema: "http://json-schema.org/draft-07/schema#",
@@ -462,7 +458,5 @@ function getTokenList(listUrl) {
462
458
  throw new Error("Unrecognized list URL protocol.");
463
459
  });
464
460
  }
465
- export {
466
- getTokenList as default,
467
- tokenListValidator
468
- };
461
+
462
+ export { getTokenList as default, tokenListValidator };
@@ -0,0 +1,472 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var chunk4TPCCB4K_js = require('./chunk-4TPCCB4K.js');
6
+ var remove = require('lodash/remove');
7
+ var Ajv = require('ajv');
8
+
9
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
10
+
11
+ var remove__default = /*#__PURE__*/_interopDefault(remove);
12
+ var Ajv__default = /*#__PURE__*/_interopDefault(Ajv);
13
+
14
+ // ../utils/uriToHttp.ts
15
+ function uriToHttp(uri) {
16
+ var _a, _b;
17
+ const protocol = uri.split(":")[0].toLowerCase();
18
+ switch (protocol) {
19
+ case "https":
20
+ return [uri];
21
+ case "http":
22
+ return [`https${uri.substring(4)}`, uri];
23
+ case "ipfs":
24
+ const hash = (_a = uri.match(/^ipfs:(\/\/)?(.*)$/i)) == null ? void 0 : _a[2];
25
+ return [`https://cloudflare-ipfs.com/ipfs/${hash}/`, `https://ipfs.io/ipfs/${hash}/`];
26
+ case "ipns":
27
+ const name = (_b = uri.match(/^ipns:(\/\/)?(.*)$/i)) == null ? void 0 : _b[2];
28
+ return [`https://cloudflare-ipfs.com/ipns/${name}/`, `https://ipfs.io/ipns/${name}/`];
29
+ default:
30
+ return [];
31
+ }
32
+ }
33
+
34
+ // schema/pancakeswap.json
35
+ var pancakeswap_default = {
36
+ $schema: "http://json-schema.org/draft-07/schema#",
37
+ $id: "pancakeswap",
38
+ title: "PancakeSwap Token List",
39
+ description: "Schema for lists of tokens compatible with the PancakeSwap Interface, including Uniswap standard and PancakeSwap Aptos",
40
+ definitions: {
41
+ Version: {
42
+ type: "object",
43
+ description: "The version of the list, used in change detection",
44
+ examples: [
45
+ {
46
+ major: 1,
47
+ minor: 0,
48
+ patch: 0
49
+ }
50
+ ],
51
+ additionalProperties: false,
52
+ properties: {
53
+ major: {
54
+ type: "integer",
55
+ description: "The major version of the list. Must be incremented when tokens are removed from the list or token addresses are changed.",
56
+ minimum: 0,
57
+ examples: [1, 2]
58
+ },
59
+ minor: {
60
+ type: "integer",
61
+ description: "The minor version of the list. Must be incremented when tokens are added to the list.",
62
+ minimum: 0,
63
+ examples: [0, 1]
64
+ },
65
+ patch: {
66
+ type: "integer",
67
+ description: "The patch version of the list. Must be incremented for any changes to the list.",
68
+ minimum: 0,
69
+ examples: [0, 1]
70
+ }
71
+ },
72
+ required: ["major", "minor", "patch"]
73
+ },
74
+ TagIdentifier: {
75
+ type: "string",
76
+ description: "The unique identifier of a tag",
77
+ minLength: 1,
78
+ maxLength: 10,
79
+ pattern: "^[\\w]+$",
80
+ examples: ["compound", "stablecoin"]
81
+ },
82
+ ExtensionIdentifier: {
83
+ type: "string",
84
+ description: "The name of a token extension property",
85
+ minLength: 1,
86
+ maxLength: 40,
87
+ pattern: "^[\\w]+$",
88
+ examples: ["color", "is_fee_on_transfer", "aliases"]
89
+ },
90
+ ExtensionMap: {
91
+ type: "object",
92
+ description: "An object containing any arbitrary or vendor-specific token metadata",
93
+ maxProperties: 10,
94
+ propertyNames: {
95
+ $ref: "#/definitions/ExtensionIdentifier"
96
+ },
97
+ additionalProperties: {
98
+ $ref: "#/definitions/ExtensionValue"
99
+ },
100
+ examples: [
101
+ {
102
+ color: "#000000",
103
+ is_verified_by_me: true
104
+ },
105
+ {
106
+ "x-bridged-addresses-by-chain": {
107
+ "1": {
108
+ bridgeAddress: "0x4200000000000000000000000000000000000010",
109
+ tokenAddress: "0x4200000000000000000000000000000000000010"
110
+ }
111
+ }
112
+ }
113
+ ]
114
+ },
115
+ ExtensionPrimitiveValue: {
116
+ anyOf: [
117
+ {
118
+ type: "string",
119
+ minLength: 1,
120
+ maxLength: 42,
121
+ examples: ["#00000"]
122
+ },
123
+ {
124
+ type: "boolean",
125
+ examples: [true]
126
+ },
127
+ {
128
+ type: "number",
129
+ examples: [15]
130
+ },
131
+ {
132
+ type: "null"
133
+ }
134
+ ]
135
+ },
136
+ ExtensionValue: {
137
+ anyOf: [
138
+ {
139
+ $ref: "#/definitions/ExtensionPrimitiveValue"
140
+ },
141
+ {
142
+ type: "object",
143
+ maxProperties: 10,
144
+ propertyNames: {
145
+ $ref: "#/definitions/ExtensionIdentifier"
146
+ },
147
+ additionalProperties: {
148
+ $ref: "#/definitions/ExtensionValueInner0"
149
+ }
150
+ }
151
+ ]
152
+ },
153
+ ExtensionValueInner0: {
154
+ anyOf: [
155
+ {
156
+ $ref: "#/definitions/ExtensionPrimitiveValue"
157
+ },
158
+ {
159
+ type: "object",
160
+ maxProperties: 10,
161
+ propertyNames: {
162
+ $ref: "#/definitions/ExtensionIdentifier"
163
+ },
164
+ additionalProperties: {
165
+ $ref: "#/definitions/ExtensionValueInner1"
166
+ }
167
+ }
168
+ ]
169
+ },
170
+ ExtensionValueInner1: {
171
+ anyOf: [
172
+ {
173
+ $ref: "#/definitions/ExtensionPrimitiveValue"
174
+ }
175
+ ]
176
+ },
177
+ TagDefinition: {
178
+ type: "object",
179
+ description: "Definition of a tag that can be associated with a token via its identifier",
180
+ additionalProperties: false,
181
+ properties: {
182
+ name: {
183
+ type: "string",
184
+ description: "The name of the tag",
185
+ pattern: "^[ \\w]+$",
186
+ minLength: 1,
187
+ maxLength: 20
188
+ },
189
+ description: {
190
+ type: "string",
191
+ description: "A user-friendly description of the tag",
192
+ pattern: "^[ \\w\\.,:]+$",
193
+ minLength: 1,
194
+ maxLength: 200
195
+ }
196
+ },
197
+ required: ["name", "description"],
198
+ examples: [
199
+ {
200
+ name: "Stablecoin",
201
+ description: "A token with value pegged to another asset"
202
+ }
203
+ ]
204
+ },
205
+ TokenInfo: {
206
+ type: "object",
207
+ description: "Metadata for a single token in a token list",
208
+ additionalProperties: false,
209
+ properties: {
210
+ chainId: {
211
+ type: "integer",
212
+ description: "The chain ID of the Ethereum network where this token is deployed",
213
+ minimum: 1,
214
+ examples: [1, 42]
215
+ },
216
+ address: {
217
+ type: "string",
218
+ description: "The checksummed address of the token on the specified chain ID",
219
+ pattern: "^0x[a-fA-F0-9]{40}$",
220
+ examples: ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]
221
+ },
222
+ decimals: {
223
+ type: "integer",
224
+ description: "The number of decimals for the token balance",
225
+ minimum: 0,
226
+ maximum: 255,
227
+ examples: [18]
228
+ },
229
+ name: {
230
+ type: "string",
231
+ description: "The name of the token",
232
+ minLength: 1,
233
+ maxLength: 40,
234
+ pattern: "^[ \\w.'+\\-%/\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
235
+ examples: ["USD Coin"]
236
+ },
237
+ symbol: {
238
+ type: "string",
239
+ description: "The symbol for the token; must be alphanumeric",
240
+ pattern: "^[a-zA-Z0-9+\\-%/$.]+$",
241
+ minLength: 1,
242
+ maxLength: 20,
243
+ examples: ["USDC"]
244
+ },
245
+ logoURI: {
246
+ type: "string",
247
+ description: "A URI to the token logo asset; if not set, interface will attempt to find a logo based on the token address; suggest SVG or PNG of size 64x64",
248
+ format: "uri",
249
+ examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
250
+ },
251
+ tags: {
252
+ type: "array",
253
+ description: "An array of tag identifiers associated with the token; tags are defined at the list level",
254
+ items: {
255
+ $ref: "#/definitions/TagIdentifier"
256
+ },
257
+ maxItems: 10,
258
+ examples: ["stablecoin", "compound"]
259
+ },
260
+ extensions: {
261
+ $ref: "#/definitions/ExtensionMap"
262
+ }
263
+ },
264
+ required: ["chainId", "address", "decimals", "name", "symbol"]
265
+ },
266
+ AptosTokenInfo: {
267
+ type: "object",
268
+ description: "Metadata for a single token in a token list",
269
+ additionalProperties: false,
270
+ properties: {
271
+ chainId: {
272
+ type: "integer",
273
+ description: "The chain ID of the Aptos network where this token is deployed, 0 is devent",
274
+ minimum: 0,
275
+ examples: [1, 42]
276
+ },
277
+ address: {
278
+ type: "string",
279
+ description: "The address of the coin on the specified chain ID",
280
+ examples: ["0x1::aptos_coin::AptosCoin"]
281
+ },
282
+ decimals: {
283
+ type: "integer",
284
+ description: "The number of decimals for the token balance",
285
+ minimum: 0,
286
+ maximum: 255,
287
+ examples: [18]
288
+ },
289
+ name: {
290
+ type: "string",
291
+ description: "The name of the token",
292
+ minLength: 1,
293
+ maxLength: 40,
294
+ pattern: "^[ \\w.'+\\-%/\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
295
+ examples: ["USD Coin"]
296
+ },
297
+ symbol: {
298
+ type: "string",
299
+ description: "The symbol for the token; must be alphanumeric",
300
+ pattern: "^[a-zA-Z0-9+\\-%/$.]+$",
301
+ minLength: 1,
302
+ maxLength: 20,
303
+ examples: ["USDC"]
304
+ },
305
+ logoURI: {
306
+ type: "string",
307
+ description: "A URI to the token logo asset; if not set, interface will attempt to find a logo based on the token address; suggest SVG or PNG of size 64x64",
308
+ format: "uri",
309
+ examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
310
+ },
311
+ tags: {
312
+ type: "array",
313
+ description: "An array of tag identifiers associated with the token; tags are defined at the list level",
314
+ items: {
315
+ $ref: "#/definitions/TagIdentifier"
316
+ },
317
+ maxItems: 10,
318
+ examples: ["stablecoin", "compound"]
319
+ },
320
+ extensions: {
321
+ $ref: "#/definitions/ExtensionMap"
322
+ }
323
+ },
324
+ required: ["chainId", "address", "decimals", "name", "symbol"]
325
+ }
326
+ },
327
+ type: "object",
328
+ additionalProperties: false,
329
+ properties: {
330
+ name: {
331
+ type: "string",
332
+ description: "The name of the token list",
333
+ minLength: 1,
334
+ maxLength: 30,
335
+ pattern: "^[\\w ]+$",
336
+ examples: ["My Token List"]
337
+ },
338
+ timestamp: {
339
+ type: "string",
340
+ format: "date-time",
341
+ description: "The timestamp of this list version; i.e. when this immutable version of the list was created"
342
+ },
343
+ schema: {
344
+ type: "string"
345
+ },
346
+ version: {
347
+ $ref: "#/definitions/Version"
348
+ },
349
+ tokens: {
350
+ type: "array",
351
+ description: "The list of tokens included in the list",
352
+ minItems: 1,
353
+ maxItems: 1e4
354
+ },
355
+ keywords: {
356
+ type: "array",
357
+ description: "Keywords associated with the contents of the list; may be used in list discoverability",
358
+ items: {
359
+ type: "string",
360
+ description: "A keyword to describe the contents of the list",
361
+ minLength: 1,
362
+ maxLength: 20,
363
+ pattern: "^[\\w ]+$",
364
+ examples: ["compound", "lending", "personal tokens"]
365
+ },
366
+ maxItems: 20,
367
+ uniqueItems: true
368
+ },
369
+ tags: {
370
+ type: "object",
371
+ description: "A mapping of tag identifiers to their name and description",
372
+ propertyNames: {
373
+ $ref: "#/definitions/TagIdentifier"
374
+ },
375
+ additionalProperties: {
376
+ $ref: "#/definitions/TagDefinition"
377
+ },
378
+ maxProperties: 20,
379
+ examples: [
380
+ {
381
+ stablecoin: {
382
+ name: "Stablecoin",
383
+ description: "A token with value pegged to another asset"
384
+ }
385
+ }
386
+ ]
387
+ },
388
+ logoURI: {
389
+ type: "string",
390
+ description: "A URI for the logo of the token list; prefer SVG or PNG of size 256x256",
391
+ format: "uri",
392
+ examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
393
+ }
394
+ },
395
+ if: {
396
+ properties: { schema: { const: "aptos" } },
397
+ required: ["name", "timestamp", "version", "tokens", "schema"]
398
+ },
399
+ then: {
400
+ properties: {
401
+ tokens: {
402
+ items: {
403
+ $ref: "#/definitions/AptosTokenInfo"
404
+ },
405
+ type: "array",
406
+ description: "The list of tokens included in the list",
407
+ minItems: 1,
408
+ maxItems: 1e4
409
+ }
410
+ }
411
+ },
412
+ else: {
413
+ properties: {
414
+ tokens: {
415
+ items: {
416
+ $ref: "#/definitions/TokenInfo"
417
+ },
418
+ type: "array",
419
+ description: "The list of tokens included in the list",
420
+ minItems: 1,
421
+ maxItems: 1e4
422
+ }
423
+ }
424
+ },
425
+ required: ["name", "timestamp", "version", "tokens"]
426
+ };
427
+
428
+ // react/getTokenList.ts
429
+ var tokenListValidator = new Ajv__default.default({ allErrors: true }).compile(pancakeswap_default);
430
+ function getTokenList(listUrl) {
431
+ return chunk4TPCCB4K_js.__async(this, null, function* () {
432
+ var _a, _b;
433
+ const urls = uriToHttp(listUrl);
434
+ for (let i = 0; i < urls.length; i++) {
435
+ const url = urls[i];
436
+ const isLast = i === urls.length - 1;
437
+ let response;
438
+ try {
439
+ response = yield fetch(url);
440
+ } catch (error) {
441
+ console.error("Failed to fetch list", listUrl, error);
442
+ if (isLast)
443
+ throw new Error(`Failed to download list ${listUrl}`);
444
+ continue;
445
+ }
446
+ if (!response.ok) {
447
+ if (isLast)
448
+ throw new Error(`Failed to download list ${listUrl}`);
449
+ continue;
450
+ }
451
+ const json = yield response.json();
452
+ if (json.tokens) {
453
+ remove__default.default(json.tokens, (token) => {
454
+ return token.symbol ? token.symbol.length === 0 : true;
455
+ });
456
+ }
457
+ if (!tokenListValidator(json)) {
458
+ const validationErrors = (_b = (_a = tokenListValidator.errors) == null ? void 0 : _a.reduce((memo, error) => {
459
+ var _a2;
460
+ const add = `${error.dataPath} ${(_a2 = error.message) != null ? _a2 : ""}`;
461
+ return memo.length > 0 ? `${memo}; ${add}` : `${add}`;
462
+ }, "")) != null ? _b : "unknown error";
463
+ throw new Error(`Token list failed validation: ${validationErrors}`);
464
+ }
465
+ return json;
466
+ }
467
+ throw new Error("Unrecognized list URL protocol.");
468
+ });
469
+ }
470
+
471
+ exports.default = getTokenList;
472
+ exports.tokenListValidator = tokenListValidator;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
1
  import { SerializedToken, Token } from '@pancakeswap/swap-sdk-core';
2
- import { T as TokenInfo, a as TokenList, V as Version } from './types-d752b62d.js';
3
- export { b as Tags } from './types-d752b62d.js';
2
+ import { T as TokenInfo, a as TokenList, V as Version } from './types-d6730d17.js';
3
+ export { b as Tags } from './types-d6730d17.js';
4
4
 
5
5
  interface SerializedWrappedToken extends SerializedToken {
6
6
  chainId: number;
7
- address: string;
7
+ address: `0x${string}`;
8
8
  decimals: number;
9
9
  symbol: string;
10
10
  name?: string;
@@ -47,4 +47,6 @@ declare enum VersionUpgrade {
47
47
  */
48
48
  declare function getVersionUpgrade(base: Version, update: Version): VersionUpgrade;
49
49
 
50
- export { SerializedWrappedToken, TokenAddressMap, TokenInfo, TokenList, Version, VersionUpgrade, WrappedTokenInfo, deserializeToken, getVersionUpgrade };
50
+ declare function createFilterToken<T extends TokenInfo | Token>(search: string, isAddress: (address: string) => boolean): (token: T) => boolean;
51
+
52
+ export { SerializedWrappedToken, TokenAddressMap, TokenInfo, TokenList, Version, VersionUpgrade, WrappedTokenInfo, createFilterToken, deserializeToken, getVersionUpgrade };