@pancakeswap/token-lists 0.0.2

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,302 @@
1
+ {
2
+ "$schema": "http://json-schema.org/draft-07/schema#",
3
+ "$id": "https://uniswap.org/tokenlist.schema.json",
4
+ "title": "Uniswap Token List",
5
+ "description": "Schema for lists of tokens compatible with the Uniswap Interface",
6
+ "definitions": {
7
+ "Version": {
8
+ "type": "object",
9
+ "description": "The version of the list, used in change detection",
10
+ "examples": [
11
+ {
12
+ "major": 1,
13
+ "minor": 0,
14
+ "patch": 0
15
+ }
16
+ ],
17
+ "additionalProperties": false,
18
+ "properties": {
19
+ "major": {
20
+ "type": "integer",
21
+ "description": "The major version of the list. Must be incremented when tokens are removed from the list or token addresses are changed.",
22
+ "minimum": 0,
23
+ "examples": [1, 2]
24
+ },
25
+ "minor": {
26
+ "type": "integer",
27
+ "description": "The minor version of the list. Must be incremented when tokens are added to the list.",
28
+ "minimum": 0,
29
+ "examples": [0, 1]
30
+ },
31
+ "patch": {
32
+ "type": "integer",
33
+ "description": "The patch version of the list. Must be incremented for any changes to the list.",
34
+ "minimum": 0,
35
+ "examples": [0, 1]
36
+ }
37
+ },
38
+ "required": ["major", "minor", "patch"]
39
+ },
40
+ "TagIdentifier": {
41
+ "type": "string",
42
+ "description": "The unique identifier of a tag",
43
+ "minLength": 1,
44
+ "maxLength": 10,
45
+ "pattern": "^[\\w]+$",
46
+ "examples": ["compound", "stablecoin"]
47
+ },
48
+ "ExtensionIdentifier": {
49
+ "type": "string",
50
+ "description": "The name of a token extension property",
51
+ "minLength": 1,
52
+ "maxLength": 40,
53
+ "pattern": "^[\\w]+$",
54
+ "examples": ["color", "is_fee_on_transfer", "aliases"]
55
+ },
56
+ "ExtensionMap": {
57
+ "type": "object",
58
+ "description": "An object containing any arbitrary or vendor-specific token metadata",
59
+ "maxProperties": 10,
60
+ "propertyNames": {
61
+ "$ref": "#/definitions/ExtensionIdentifier"
62
+ },
63
+ "additionalProperties": {
64
+ "$ref": "#/definitions/ExtensionValue"
65
+ },
66
+ "examples": [
67
+ {
68
+ "color": "#000000",
69
+ "is_verified_by_me": true
70
+ },
71
+ {
72
+ "x-bridged-addresses-by-chain": {
73
+ "1": {
74
+ "bridgeAddress": "0x4200000000000000000000000000000000000010",
75
+ "tokenAddress": "0x4200000000000000000000000000000000000010"
76
+ }
77
+ }
78
+ }
79
+ ]
80
+ },
81
+ "ExtensionPrimitiveValue": {
82
+ "anyOf": [
83
+ {
84
+ "type": "string",
85
+ "minLength": 1,
86
+ "maxLength": 42,
87
+ "examples": ["#00000"]
88
+ },
89
+ {
90
+ "type": "boolean",
91
+ "examples": [true]
92
+ },
93
+ {
94
+ "type": "number",
95
+ "examples": [15]
96
+ },
97
+ {
98
+ "type": "null"
99
+ }
100
+ ]
101
+ },
102
+ "ExtensionValue": {
103
+ "anyOf": [
104
+ {
105
+ "$ref": "#/definitions/ExtensionPrimitiveValue"
106
+ },
107
+ {
108
+ "type": "object",
109
+ "maxProperties": 10,
110
+ "propertyNames": {
111
+ "$ref": "#/definitions/ExtensionIdentifier"
112
+ },
113
+ "additionalProperties": {
114
+ "$ref": "#/definitions/ExtensionValueInner0"
115
+ }
116
+ }
117
+ ]
118
+ },
119
+ "ExtensionValueInner0": {
120
+ "anyOf": [
121
+ {
122
+ "$ref": "#/definitions/ExtensionPrimitiveValue"
123
+ },
124
+ {
125
+ "type": "object",
126
+ "maxProperties": 10,
127
+ "propertyNames": {
128
+ "$ref": "#/definitions/ExtensionIdentifier"
129
+ },
130
+ "additionalProperties": {
131
+ "$ref": "#/definitions/ExtensionValueInner1"
132
+ }
133
+ }
134
+ ]
135
+ },
136
+ "ExtensionValueInner1": {
137
+ "anyOf": [
138
+ {
139
+ "$ref": "#/definitions/ExtensionPrimitiveValue"
140
+ }
141
+ ]
142
+ },
143
+ "TagDefinition": {
144
+ "type": "object",
145
+ "description": "Definition of a tag that can be associated with a token via its identifier",
146
+ "additionalProperties": false,
147
+ "properties": {
148
+ "name": {
149
+ "type": "string",
150
+ "description": "The name of the tag",
151
+ "pattern": "^[ \\w]+$",
152
+ "minLength": 1,
153
+ "maxLength": 20
154
+ },
155
+ "description": {
156
+ "type": "string",
157
+ "description": "A user-friendly description of the tag",
158
+ "pattern": "^[ \\w\\.,:]+$",
159
+ "minLength": 1,
160
+ "maxLength": 200
161
+ }
162
+ },
163
+ "required": ["name", "description"],
164
+ "examples": [
165
+ {
166
+ "name": "Stablecoin",
167
+ "description": "A token with value pegged to another asset"
168
+ }
169
+ ]
170
+ },
171
+ "TokenInfo": {
172
+ "type": "object",
173
+ "description": "Metadata for a single token in a token list",
174
+ "additionalProperties": false,
175
+ "properties": {
176
+ "chainId": {
177
+ "type": "integer",
178
+ "description": "The chain ID of the Ethereum network where this token is deployed",
179
+ "minimum": 1,
180
+ "examples": [1, 42]
181
+ },
182
+ "address": {
183
+ "type": "string",
184
+ "description": "The checksummed address of the token on the specified chain ID",
185
+ "pattern": "^0x[a-fA-F0-9]{40}$",
186
+ "examples": ["0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"]
187
+ },
188
+ "decimals": {
189
+ "type": "integer",
190
+ "description": "The number of decimals for the token balance",
191
+ "minimum": 0,
192
+ "maximum": 255,
193
+ "examples": [18]
194
+ },
195
+ "name": {
196
+ "type": "string",
197
+ "description": "The name of the token",
198
+ "minLength": 1,
199
+ "maxLength": 40,
200
+ "pattern": "^[ \\w.'+\\-%/À-ÖØ-öø-ÿ:&\\[\\]\\(\\)]+$",
201
+ "examples": ["USD Coin"]
202
+ },
203
+ "symbol": {
204
+ "type": "string",
205
+ "description": "The symbol for the token; must be alphanumeric",
206
+ "pattern": "^[a-zA-Z0-9+\\-%/$.]+$",
207
+ "minLength": 1,
208
+ "maxLength": 20,
209
+ "examples": ["USDC"]
210
+ },
211
+ "logoURI": {
212
+ "type": "string",
213
+ "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",
214
+ "format": "uri",
215
+ "examples": ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
216
+ },
217
+ "tags": {
218
+ "type": "array",
219
+ "description": "An array of tag identifiers associated with the token; tags are defined at the list level",
220
+ "items": {
221
+ "$ref": "#/definitions/TagIdentifier"
222
+ },
223
+ "maxItems": 10,
224
+ "examples": ["stablecoin", "compound"]
225
+ },
226
+ "extensions": {
227
+ "$ref": "#/definitions/ExtensionMap"
228
+ }
229
+ },
230
+ "required": ["chainId", "address", "decimals", "name", "symbol"]
231
+ }
232
+ },
233
+ "type": "object",
234
+ "additionalProperties": false,
235
+ "properties": {
236
+ "name": {
237
+ "type": "string",
238
+ "description": "The name of the token list",
239
+ "minLength": 1,
240
+ "maxLength": 30,
241
+ "pattern": "^[\\w ]+$",
242
+ "examples": ["My Token List"]
243
+ },
244
+ "timestamp": {
245
+ "type": "string",
246
+ "format": "date-time",
247
+ "description": "The timestamp of this list version; i.e. when this immutable version of the list was created"
248
+ },
249
+ "version": {
250
+ "$ref": "#/definitions/Version"
251
+ },
252
+ "tokens": {
253
+ "type": "array",
254
+ "description": "The list of tokens included in the list",
255
+ "items": {
256
+ "$ref": "#/definitions/TokenInfo"
257
+ },
258
+ "minItems": 1,
259
+ "maxItems": 10000
260
+ },
261
+ "keywords": {
262
+ "type": "array",
263
+ "description": "Keywords associated with the contents of the list; may be used in list discoverability",
264
+ "items": {
265
+ "type": "string",
266
+ "description": "A keyword to describe the contents of the list",
267
+ "minLength": 1,
268
+ "maxLength": 20,
269
+ "pattern": "^[\\w ]+$",
270
+ "examples": ["compound", "lending", "personal tokens"]
271
+ },
272
+ "maxItems": 20,
273
+ "uniqueItems": true
274
+ },
275
+ "tags": {
276
+ "type": "object",
277
+ "description": "A mapping of tag identifiers to their name and description",
278
+ "propertyNames": {
279
+ "$ref": "#/definitions/TagIdentifier"
280
+ },
281
+ "additionalProperties": {
282
+ "$ref": "#/definitions/TagDefinition"
283
+ },
284
+ "maxProperties": 20,
285
+ "examples": [
286
+ {
287
+ "stablecoin": {
288
+ "name": "Stablecoin",
289
+ "description": "A token with value pegged to another asset"
290
+ }
291
+ }
292
+ ]
293
+ },
294
+ "logoURI": {
295
+ "type": "string",
296
+ "description": "A URI for the logo of the token list; prefer SVG or PNG of size 256x256",
297
+ "format": "uri",
298
+ "examples": ["ipfs://QmXfzKRvjZz3u5JRgC4v5mGVbm9ahrUiB4DgzHBsnWbTMM"]
299
+ }
300
+ },
301
+ "required": ["name", "timestamp", "version", "tokens"]
302
+ }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Enum describing types of version differences
3
+ */
4
+ import { Version } from './types'
5
+
6
+ export enum VersionUpgrade {
7
+ NONE,
8
+ PATCH,
9
+ MINOR,
10
+ MAJOR,
11
+ }
12
+
13
+ /**
14
+ * Return the upgrade type from the base version to the update version.
15
+ * Note that downgrades and equivalent versions are both treated as `NONE`.
16
+ * @param base base list
17
+ * @param update update to the list
18
+ */
19
+ export function getVersionUpgrade(base: Version, update: Version): VersionUpgrade {
20
+ if (update.major > base.major) {
21
+ return VersionUpgrade.MAJOR
22
+ }
23
+ if (update.major < base.major) {
24
+ return VersionUpgrade.NONE
25
+ }
26
+ if (update.minor > base.minor) {
27
+ return VersionUpgrade.MINOR
28
+ }
29
+ if (update.minor < base.minor) {
30
+ return VersionUpgrade.NONE
31
+ }
32
+ return update.patch > base.patch ? VersionUpgrade.PATCH : VersionUpgrade.NONE
33
+ }
package/src/index.ts ADDED
@@ -0,0 +1,3 @@
1
+ export * from './wrappedTokenInfo'
2
+ export * from './types'
3
+ export * from './getVersionUpgrade'
package/src/types.ts ADDED
@@ -0,0 +1,45 @@
1
+ type ExtensionValue = string | number | boolean | null | undefined
2
+
3
+ export interface TokenInfo {
4
+ readonly chainId: number
5
+ readonly address: string
6
+ readonly name: string
7
+ readonly decimals: number
8
+ readonly symbol: string
9
+ readonly logoURI?: string
10
+ readonly tags?: string[]
11
+ readonly extensions?: {
12
+ readonly [key: string]:
13
+ | {
14
+ [key: string]:
15
+ | {
16
+ [key: string]: ExtensionValue
17
+ }
18
+ | ExtensionValue
19
+ }
20
+ | ExtensionValue
21
+ }
22
+ }
23
+
24
+ export interface Version {
25
+ readonly major: number
26
+ readonly minor: number
27
+ readonly patch: number
28
+ }
29
+
30
+ export interface Tags {
31
+ readonly [tagId: string]: {
32
+ readonly name: string
33
+ readonly description: string
34
+ }
35
+ }
36
+
37
+ export interface TokenList {
38
+ readonly name: string
39
+ readonly timestamp: string
40
+ readonly version: Version
41
+ readonly tokens: TokenInfo[]
42
+ readonly keywords?: string[]
43
+ readonly tags?: Tags
44
+ readonly logoURI?: string
45
+ }
@@ -0,0 +1,4 @@
1
+ import Ajv from 'ajv'
2
+ import schema from './schema/pancakeswap.json'
3
+
4
+ export const tokenListValidator = new Ajv({ allErrors: true }).compile(schema)
@@ -0,0 +1,63 @@
1
+ import { SerializedToken, Token } from '@pancakeswap/swap-sdk-core'
2
+ import { TokenInfo, TokenList } from './types'
3
+
4
+ export interface SerializedWrappedToken extends SerializedToken {
5
+ chainId: number
6
+ address: string
7
+ decimals: number
8
+ symbol: string
9
+ name?: string
10
+ projectLink?: string
11
+ logoURI?: string
12
+ }
13
+
14
+ /**
15
+ * Token instances created from token info.
16
+ */
17
+ export class WrappedTokenInfo extends Token {
18
+ public readonly logoURI: string | undefined
19
+
20
+ constructor(tokenInfo: TokenInfo) {
21
+ super(tokenInfo.chainId, tokenInfo.address, tokenInfo.decimals, tokenInfo.symbol, tokenInfo.name)
22
+ this.logoURI = tokenInfo.logoURI
23
+ }
24
+
25
+ public get serialize(): SerializedWrappedToken {
26
+ return {
27
+ address: this.address,
28
+ chainId: this.chainId,
29
+ decimals: this.decimals,
30
+ symbol: this.symbol,
31
+ name: this.name,
32
+ projectLink: this.projectLink,
33
+ logoURI: this.logoURI,
34
+ }
35
+ }
36
+ }
37
+
38
+ export type TokenAddressMap<TChainId extends number> = Readonly<{
39
+ [chainId in TChainId]: Readonly<{
40
+ [tokenAddress: string]: { token: WrappedTokenInfo; list: TokenList }
41
+ }>
42
+ }>
43
+
44
+ export function deserializeToken(serializedToken: SerializedWrappedToken): Token {
45
+ if (serializedToken.logoURI) {
46
+ return new WrappedTokenInfo({
47
+ chainId: serializedToken.chainId,
48
+ address: serializedToken.address,
49
+ decimals: serializedToken.decimals,
50
+ symbol: serializedToken.symbol || 'Unknown',
51
+ name: serializedToken.name || 'Unknown',
52
+ logoURI: serializedToken.logoURI,
53
+ })
54
+ }
55
+ return new Token(
56
+ serializedToken.chainId,
57
+ serializedToken.address,
58
+ serializedToken.decimals,
59
+ serializedToken.symbol,
60
+ serializedToken.name,
61
+ serializedToken.projectLink,
62
+ )
63
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,9 @@
1
+ {
2
+ "extends": "tsconfig/react-library",
3
+ "compilerOptions": {
4
+ "esModuleInterop": true,
5
+ "resolveJsonModule": true,
6
+ "isolatedModules": true,
7
+ "skipLibCheck": true
8
+ }
9
+ }
package/tsup.config.ts ADDED
@@ -0,0 +1,10 @@
1
+ import { defineConfig } from 'tsup'
2
+
3
+ export default defineConfig({
4
+ entry: {
5
+ index: './src/index.ts',
6
+ react: './react/index.ts',
7
+ },
8
+ format: ['esm', 'cjs'],
9
+ dts: true,
10
+ })