@pancakeswap/token-lists 0.0.13 → 0.0.15

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/dist/react.mjs CHANGED
@@ -1,5 +1,4 @@
1
- import { getVersionUpgrade } from './chunk-COROHIJN.mjs';
2
- import { __spreadProps, __spreadValues, __async } from './chunk-2L3ZO4UM.mjs';
1
+ import { __async, __spreadProps, __spreadValues, getVersionUpgrade } from './chunk-DC45HQOL.mjs';
3
2
  import { createAction, createReducer, nanoid } from '@reduxjs/toolkit';
4
3
  import { atom, useAtom, useAtomValue } from 'jotai';
5
4
  import { atomWithStorage, loadable } from 'jotai/utils';
@@ -19,7 +18,516 @@ var acceptListUpdate = createAction("lists/acceptListUpdate");
19
18
  var rejectVersionUpdate = createAction("lists/rejectVersionUpdate");
20
19
  var updateListVersion = createAction("lists/updateListVersion");
21
20
 
22
- // react/reducer.ts
21
+ // ../utils/uriToHttp.ts
22
+ function uriToHttp(uri) {
23
+ var _a, _b;
24
+ const protocol = uri.split(":")[0].toLowerCase();
25
+ switch (protocol) {
26
+ case "https":
27
+ return [uri];
28
+ case "http":
29
+ return [`https${uri.substring(4)}`, uri];
30
+ case "ipfs":
31
+ const hash = (_a = uri.match(/^ipfs:(\/\/)?(.*)$/i)) == null ? void 0 : _a[2];
32
+ return [`https://cloudflare-ipfs.com/ipfs/${hash}/`, `https://ipfs.io/ipfs/${hash}/`];
33
+ case "ipns":
34
+ const name = (_b = uri.match(/^ipns:(\/\/)?(.*)$/i)) == null ? void 0 : _b[2];
35
+ return [`https://cloudflare-ipfs.com/ipns/${name}/`, `https://ipfs.io/ipns/${name}/`];
36
+ default:
37
+ return [];
38
+ }
39
+ }
40
+
41
+ // schema/pancakeswap.json
42
+ var pancakeswap_default = {
43
+ $schema: "http://json-schema.org/draft-07/schema#",
44
+ $id: "pancakeswap",
45
+ title: "PancakeSwap Token List",
46
+ description: "Schema for lists of tokens compatible with the PancakeSwap Interface, including Uniswap standard and PancakeSwap Aptos",
47
+ definitions: {
48
+ Version: {
49
+ type: "object",
50
+ description: "The version of the list, used in change detection",
51
+ examples: [
52
+ {
53
+ major: 1,
54
+ minor: 0,
55
+ patch: 0
56
+ }
57
+ ],
58
+ additionalProperties: false,
59
+ properties: {
60
+ major: {
61
+ type: "integer",
62
+ description: "The major version of the list. Must be incremented when tokens are removed from the list or token addresses are changed.",
63
+ minimum: 0,
64
+ examples: [1, 2]
65
+ },
66
+ minor: {
67
+ type: "integer",
68
+ description: "The minor version of the list. Must be incremented when tokens are added to the list.",
69
+ minimum: 0,
70
+ examples: [0, 1]
71
+ },
72
+ patch: {
73
+ type: "integer",
74
+ description: "The patch version of the list. Must be incremented for any changes to the list.",
75
+ minimum: 0,
76
+ examples: [0, 1]
77
+ }
78
+ },
79
+ required: ["major", "minor", "patch"]
80
+ },
81
+ TagIdentifier: {
82
+ type: "string",
83
+ description: "The unique identifier of a tag",
84
+ minLength: 1,
85
+ maxLength: 10,
86
+ pattern: "^[\\w]+$",
87
+ examples: ["compound", "stablecoin"]
88
+ },
89
+ ExtensionIdentifier: {
90
+ type: "string",
91
+ description: "The name of a token extension property",
92
+ minLength: 1,
93
+ maxLength: 40,
94
+ pattern: "^[\\w]+$",
95
+ examples: ["color", "is_fee_on_transfer", "aliases"]
96
+ },
97
+ ExtensionMap: {
98
+ type: "object",
99
+ description: "An object containing any arbitrary or vendor-specific token metadata",
100
+ maxProperties: 10,
101
+ propertyNames: {
102
+ $ref: "#/definitions/ExtensionIdentifier"
103
+ },
104
+ additionalProperties: {
105
+ $ref: "#/definitions/ExtensionValue"
106
+ },
107
+ examples: [
108
+ {
109
+ color: "#000000",
110
+ is_verified_by_me: true
111
+ },
112
+ {
113
+ "x-bridged-addresses-by-chain": {
114
+ "1": {
115
+ bridgeAddress: "0x4200000000000000000000000000000000000010",
116
+ tokenAddress: "0x4200000000000000000000000000000000000010"
117
+ }
118
+ }
119
+ }
120
+ ]
121
+ },
122
+ ExtensionPrimitiveValue: {
123
+ anyOf: [
124
+ {
125
+ type: "string",
126
+ minLength: 1,
127
+ maxLength: 42,
128
+ examples: ["#00000"]
129
+ },
130
+ {
131
+ type: "boolean",
132
+ examples: [true]
133
+ },
134
+ {
135
+ type: "number",
136
+ examples: [15]
137
+ },
138
+ {
139
+ type: "null"
140
+ }
141
+ ]
142
+ },
143
+ ExtensionValue: {
144
+ anyOf: [
145
+ {
146
+ $ref: "#/definitions/ExtensionPrimitiveValue"
147
+ },
148
+ {
149
+ type: "object",
150
+ maxProperties: 10,
151
+ propertyNames: {
152
+ $ref: "#/definitions/ExtensionIdentifier"
153
+ },
154
+ additionalProperties: {
155
+ $ref: "#/definitions/ExtensionValueInner0"
156
+ }
157
+ }
158
+ ]
159
+ },
160
+ ExtensionValueInner0: {
161
+ anyOf: [
162
+ {
163
+ $ref: "#/definitions/ExtensionPrimitiveValue"
164
+ },
165
+ {
166
+ type: "object",
167
+ maxProperties: 10,
168
+ propertyNames: {
169
+ $ref: "#/definitions/ExtensionIdentifier"
170
+ },
171
+ additionalProperties: {
172
+ $ref: "#/definitions/ExtensionValueInner1"
173
+ }
174
+ }
175
+ ]
176
+ },
177
+ ExtensionValueInner1: {
178
+ anyOf: [
179
+ {
180
+ $ref: "#/definitions/ExtensionPrimitiveValue"
181
+ }
182
+ ]
183
+ },
184
+ TagDefinition: {
185
+ type: "object",
186
+ description: "Definition of a tag that can be associated with a token via its identifier",
187
+ additionalProperties: false,
188
+ properties: {
189
+ name: {
190
+ type: "string",
191
+ description: "The name of the tag",
192
+ pattern: "^[ \\w]+$",
193
+ minLength: 1,
194
+ maxLength: 20
195
+ },
196
+ description: {
197
+ type: "string",
198
+ description: "A user-friendly description of the tag",
199
+ pattern: "^[ \\w\\.,:]+$",
200
+ minLength: 1,
201
+ maxLength: 200
202
+ }
203
+ },
204
+ required: ["name", "description"],
205
+ examples: [
206
+ {
207
+ name: "Stablecoin",
208
+ description: "A token with value pegged to another asset"
209
+ }
210
+ ]
211
+ },
212
+ TokenInfo: {
213
+ type: "object",
214
+ description: "Metadata for a single token in a token list",
215
+ additionalProperties: false,
216
+ properties: {
217
+ chainId: {
218
+ type: "integer",
219
+ description: "The chain ID of the Ethereum network where this token is deployed",
220
+ minimum: 1,
221
+ examples: [1, 42]
222
+ },
223
+ address: {
224
+ type: "string",
225
+ description: "The checksummed address of the token on the specified chain ID",
226
+ pattern: "^0x[a-fA-F0-9]{40}$",
227
+ examples: ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]
228
+ },
229
+ decimals: {
230
+ type: "integer",
231
+ description: "The number of decimals for the token balance",
232
+ minimum: 0,
233
+ maximum: 255,
234
+ examples: [18]
235
+ },
236
+ name: {
237
+ type: "string",
238
+ description: "The name of the token",
239
+ minLength: 1,
240
+ maxLength: 40,
241
+ pattern: "^[ \\w.'+\\-%/\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
242
+ examples: ["USD Coin"]
243
+ },
244
+ symbol: {
245
+ type: "string",
246
+ description: "The symbol for the token; must be alphanumeric",
247
+ pattern: "^[a-zA-Z0-9+\\-%/$.\\s]+$",
248
+ minLength: 1,
249
+ maxLength: 20,
250
+ examples: ["USDC"]
251
+ },
252
+ logoURI: {
253
+ type: "string",
254
+ 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",
255
+ format: "uri",
256
+ examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
257
+ },
258
+ tags: {
259
+ type: "array",
260
+ description: "An array of tag identifiers associated with the token; tags are defined at the list level",
261
+ items: {
262
+ $ref: "#/definitions/TagIdentifier"
263
+ },
264
+ maxItems: 10,
265
+ examples: ["stablecoin", "compound"]
266
+ },
267
+ extensions: {
268
+ $ref: "#/definitions/ExtensionMap"
269
+ }
270
+ },
271
+ required: ["chainId", "address", "decimals", "name", "symbol"]
272
+ },
273
+ AptosTokenInfo: {
274
+ type: "object",
275
+ description: "Metadata for a single token in a token list",
276
+ additionalProperties: false,
277
+ properties: {
278
+ chainId: {
279
+ type: "integer",
280
+ description: "The chain ID of the Aptos network where this token is deployed, 0 is devent",
281
+ minimum: 0,
282
+ examples: [1, 42]
283
+ },
284
+ address: {
285
+ type: "string",
286
+ description: "The address of the coin on the specified chain ID",
287
+ examples: ["0x1::aptos_coin::AptosCoin"]
288
+ },
289
+ decimals: {
290
+ type: "integer",
291
+ description: "The number of decimals for the token balance",
292
+ minimum: 0,
293
+ maximum: 255,
294
+ examples: [18]
295
+ },
296
+ name: {
297
+ type: "string",
298
+ description: "The name of the token",
299
+ minLength: 1,
300
+ maxLength: 40,
301
+ pattern: "^[ \\w.'+\\-%/\xC0-\xD6\xD8-\xF6\xF8-\xFF:&\\[\\]\\(\\)]+$",
302
+ examples: ["USD Coin"]
303
+ },
304
+ symbol: {
305
+ type: "string",
306
+ description: "The symbol for the token; must be alphanumeric",
307
+ pattern: "^[a-zA-Z0-9+\\-%/$.]+$",
308
+ minLength: 1,
309
+ maxLength: 20,
310
+ examples: ["USDC"]
311
+ },
312
+ logoURI: {
313
+ type: "string",
314
+ 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",
315
+ format: "uri",
316
+ examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
317
+ },
318
+ tags: {
319
+ type: "array",
320
+ description: "An array of tag identifiers associated with the token; tags are defined at the list level",
321
+ items: {
322
+ $ref: "#/definitions/TagIdentifier"
323
+ },
324
+ maxItems: 10,
325
+ examples: ["stablecoin", "compound"]
326
+ },
327
+ extensions: {
328
+ $ref: "#/definitions/ExtensionMap"
329
+ }
330
+ },
331
+ required: ["chainId", "address", "decimals", "name", "symbol"]
332
+ }
333
+ },
334
+ type: "object",
335
+ additionalProperties: false,
336
+ properties: {
337
+ name: {
338
+ type: "string",
339
+ description: "The name of the token list",
340
+ minLength: 1,
341
+ maxLength: 30,
342
+ pattern: "^[\\w ]+$",
343
+ examples: ["My Token List"]
344
+ },
345
+ timestamp: {
346
+ type: "string",
347
+ format: "date-time",
348
+ description: "The timestamp of this list version; i.e. when this immutable version of the list was created"
349
+ },
350
+ schema: {
351
+ type: "string"
352
+ },
353
+ version: {
354
+ $ref: "#/definitions/Version"
355
+ },
356
+ tokens: {
357
+ type: "array",
358
+ description: "The list of tokens included in the list",
359
+ minItems: 1,
360
+ maxItems: 1e4
361
+ },
362
+ keywords: {
363
+ type: "array",
364
+ description: "Keywords associated with the contents of the list; may be used in list discoverability",
365
+ items: {
366
+ type: "string",
367
+ description: "A keyword to describe the contents of the list",
368
+ minLength: 1,
369
+ maxLength: 20,
370
+ pattern: "^[\\w ]+$",
371
+ examples: ["compound", "lending", "personal tokens"]
372
+ },
373
+ maxItems: 20,
374
+ uniqueItems: true
375
+ },
376
+ tags: {
377
+ type: "object",
378
+ description: "A mapping of tag identifiers to their name and description",
379
+ propertyNames: {
380
+ $ref: "#/definitions/TagIdentifier"
381
+ },
382
+ additionalProperties: {
383
+ $ref: "#/definitions/TagDefinition"
384
+ },
385
+ maxProperties: 20,
386
+ examples: [
387
+ {
388
+ stablecoin: {
389
+ name: "Stablecoin",
390
+ description: "A token with value pegged to another asset"
391
+ }
392
+ }
393
+ ]
394
+ },
395
+ logoURI: {
396
+ type: "string",
397
+ description: "A URI for the logo of the token list; prefer SVG or PNG of size 256x256",
398
+ format: "uri",
399
+ examples: ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
400
+ }
401
+ },
402
+ if: {
403
+ properties: { schema: { const: "aptos" } },
404
+ required: ["name", "timestamp", "version", "tokens", "schema"]
405
+ },
406
+ then: {
407
+ properties: {
408
+ tokens: {
409
+ items: {
410
+ $ref: "#/definitions/AptosTokenInfo"
411
+ },
412
+ type: "array",
413
+ description: "The list of tokens included in the list",
414
+ minItems: 1,
415
+ maxItems: 1e4
416
+ }
417
+ }
418
+ },
419
+ else: {
420
+ properties: {
421
+ tokens: {
422
+ items: {
423
+ $ref: "#/definitions/TokenInfo"
424
+ },
425
+ type: "array",
426
+ description: "The list of tokens included in the list",
427
+ minItems: 1,
428
+ maxItems: 1e4
429
+ }
430
+ }
431
+ },
432
+ required: ["name", "timestamp", "version", "tokens"]
433
+ };
434
+
435
+ // react/getTokenList.ts
436
+ function getTokenList(listUrl) {
437
+ return __async(this, null, function* () {
438
+ const urls = uriToHttp(listUrl);
439
+ const { default: Ajv } = yield import('ajv');
440
+ const validator = new Ajv({ allErrors: true }).compile(pancakeswap_default);
441
+ for (const [i, url] of urls.entries()) {
442
+ try {
443
+ const json = yield fetchJson(url);
444
+ if (!validator(json)) {
445
+ const preFilterErrors = validator.errors;
446
+ json.tokens = json.tokens.filter((token) => validator(__spreadProps(__spreadValues({}, json), { tokens: [token] })));
447
+ if (!validator(json)) {
448
+ const errors = validator.errors;
449
+ throw new Error(`Validation failed after filtering: ${JSON.stringify(errors)}`);
450
+ }
451
+ console.warn(`Pre-filter validation errors: ${JSON.stringify(preFilterErrors)}`);
452
+ }
453
+ return json;
454
+ } catch (error) {
455
+ if (i === urls.length - 1) {
456
+ throw new Error(`Failed to download list ${listUrl}`);
457
+ }
458
+ }
459
+ }
460
+ throw new Error("Unrecognized list URL protocol.");
461
+ });
462
+ }
463
+ function fetchJson(url) {
464
+ return __async(this, null, function* () {
465
+ const res = yield fetch(url);
466
+ if (!res.ok)
467
+ throw new Error(`Failed to fetch: ${url}`);
468
+ return res.json();
469
+ });
470
+ }
471
+ function noop() {
472
+ }
473
+ var noopStorage = {
474
+ getItem: () => Promise.resolve(noop()),
475
+ setItem: () => Promise.resolve(noop()),
476
+ removeItem: () => Promise.resolve(noop())
477
+ };
478
+ var EMPTY = Symbol();
479
+ var createListsAtom = (storeName, reducer, initialState) => {
480
+ function IndexedDBStorage(dbName) {
481
+ if (typeof window !== "undefined") {
482
+ const db = localForage.createInstance({
483
+ name: dbName,
484
+ storeName
485
+ });
486
+ return {
487
+ getItem: (key) => __async(this, null, function* () {
488
+ const value = yield db.getItem(key);
489
+ if (value) {
490
+ return value;
491
+ }
492
+ return initialState;
493
+ }),
494
+ setItem: (k, v) => __async(this, null, function* () {
495
+ if (v === EMPTY)
496
+ return;
497
+ yield db.setItem(k, v);
498
+ }),
499
+ removeItem: db.removeItem
500
+ };
501
+ }
502
+ return noopStorage;
503
+ }
504
+ const listsStorageAtom = atomWithStorage("lists", EMPTY, IndexedDBStorage("lists"));
505
+ const defaultStateAtom = atom(
506
+ (get) => {
507
+ const value = get(loadable(listsStorageAtom));
508
+ if (value.state === "hasData" && value.data !== EMPTY) {
509
+ return value.data;
510
+ }
511
+ return initialState;
512
+ },
513
+ (get, set, action) => __async(void 0, null, function* () {
514
+ set(listsStorageAtom, reducer(yield get(defaultStateAtom), action));
515
+ })
516
+ );
517
+ const isReadyAtom = loadable(listsStorageAtom);
518
+ function useListState() {
519
+ return useAtom(defaultStateAtom);
520
+ }
521
+ function useListStateReady() {
522
+ const value = useAtomValue(isReadyAtom);
523
+ return value.state === "hasData" && value.data !== EMPTY;
524
+ }
525
+ return {
526
+ listsAtom: defaultStateAtom,
527
+ useListStateReady,
528
+ useListState
529
+ };
530
+ };
23
531
  var NEW_LIST_STATE = {
24
532
  error: null,
25
533
  current: null,
@@ -143,66 +651,6 @@ var createTokenListReducer = (initialState, DEFAULT_LIST_OF_LISTS, DEFAULT_ACTIV
143
651
  }
144
652
  })
145
653
  );
146
- function noop() {
147
- }
148
- var noopStorage = {
149
- getItem: () => Promise.resolve(noop()),
150
- setItem: () => Promise.resolve(noop()),
151
- removeItem: () => Promise.resolve(noop())
152
- };
153
- var EMPTY = Symbol();
154
- var createListsAtom = (storeName, reducer, initialState) => {
155
- function IndexedDBStorage(dbName) {
156
- if (typeof window !== "undefined") {
157
- const db = localForage.createInstance({
158
- name: dbName,
159
- storeName
160
- });
161
- return {
162
- getItem: (key) => __async(this, null, function* () {
163
- const value = yield db.getItem(key);
164
- if (value) {
165
- return value;
166
- }
167
- return initialState;
168
- }),
169
- setItem: (k, v) => __async(this, null, function* () {
170
- if (v === EMPTY)
171
- return;
172
- yield db.setItem(k, v);
173
- }),
174
- removeItem: db.removeItem
175
- };
176
- }
177
- return noopStorage;
178
- }
179
- const listsStorageAtom = atomWithStorage("lists", EMPTY, IndexedDBStorage("lists"));
180
- const defaultStateAtom = atom(
181
- (get) => {
182
- const value = get(loadable(listsStorageAtom));
183
- if (value.state === "hasData" && value.data !== EMPTY) {
184
- return value.data;
185
- }
186
- return initialState;
187
- },
188
- (get, set, action) => __async(void 0, null, function* () {
189
- set(listsStorageAtom, reducer(yield get(defaultStateAtom), action));
190
- })
191
- );
192
- const isReadyAtom = loadable(listsStorageAtom);
193
- function useListState() {
194
- return useAtom(defaultStateAtom);
195
- }
196
- function useListStateReady() {
197
- const value = useAtomValue(isReadyAtom);
198
- return value.state === "hasData" && value.data !== EMPTY;
199
- }
200
- return {
201
- listsAtom: defaultStateAtom,
202
- useListStateReady,
203
- useListState
204
- };
205
- };
206
654
  function useFetchListCallback(dispatch) {
207
655
  return useCallback(
208
656
  (listUrl, sendDispatch = true) => __async(this, null, function* () {
@@ -210,7 +658,6 @@ function useFetchListCallback(dispatch) {
210
658
  if (sendDispatch) {
211
659
  dispatch(fetchTokenList.pending({ requestId, url: listUrl }));
212
660
  }
213
- const getTokenList = (yield import('./getTokenList-PEH2JP67.mjs')).default;
214
661
  return getTokenList(listUrl).then((tokenList) => {
215
662
  if (sendDispatch) {
216
663
  dispatch(fetchTokenList.fulfilled({ url: listUrl, tokenList, requestId }));
@@ -229,4 +676,4 @@ function useFetchListCallback(dispatch) {
229
676
  }
230
677
  var useFetchListCallback_default = useFetchListCallback;
231
678
 
232
- export { NEW_LIST_STATE, acceptListUpdate, addList, createListsAtom, createTokenListReducer, disableList, enableList, fetchTokenList, rejectVersionUpdate, removeList, updateListVersion, useFetchListCallback_default as useFetchListCallback };
679
+ export { NEW_LIST_STATE, acceptListUpdate, addList, createListsAtom, createTokenListReducer, disableList, enableList, fetchTokenList, getTokenList, rejectVersionUpdate, removeList, updateListVersion, useFetchListCallback_default as useFetchListCallback };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@pancakeswap/token-lists",
3
- "version": "0.0.13",
3
+ "version": "0.0.15",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",
7
7
  "dependencies": {
8
8
  "ajv": "^6.12.3",
9
9
  "lodash": "^4.17.21",
10
- "@pancakeswap/swap-sdk-core": "1.2.0"
10
+ "@pancakeswap/swap-sdk-core": "1.4.0"
11
11
  },
12
12
  "peerDependencies": {
13
13
  "@reduxjs/toolkit": "^1.9.1",
@@ -22,7 +22,7 @@
22
22
  "localforage": "^1.10.0",
23
23
  "react": "^18.2.0",
24
24
  "tsup": "^6.7.0",
25
- "@pancakeswap/utils": "6.0.9"
25
+ "@pancakeswap/utils": "6.1.0"
26
26
  },
27
27
  "exports": {
28
28
  ".": {