Skip to content

Commit 1d2fdda

Browse files
committed
initial commit of json schema
0 parents  commit 1d2fdda

File tree

10 files changed

+342
-0
lines changed

10 files changed

+342
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.idea/
2+
dist/
3+
node_modules/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Uniswap
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# TSDX Bootstrap
2+
3+
This project was bootstrapped with [TSDX](https://github.com/jaredpalmer/tsdx).
4+
5+
## Local Development
6+
7+
Below is a list of commands you will probably find useful.
8+
9+
### `npm start` or `yarn start`
10+
11+
Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab.
12+
13+
<img src="https://user-images.githubusercontent.com/4060187/52168303-574d3a00-26f6-11e9-9f3b-71dbec9ebfcb.gif" width="600" />
14+
15+
Your library will be rebuilt if you make edits.
16+
17+
### `npm run build` or `yarn build`
18+
19+
Bundles the package to the `dist` folder.
20+
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).
21+
22+
<img src="https://user-images.githubusercontent.com/4060187/52168322-a98e5b00-26f6-11e9-8cf6-222d716b75ef.gif" width="600" />
23+
24+
### `npm test` or `yarn test`
25+
26+
Runs the test watcher (Jest) in an interactive mode.
27+
By default, runs tests related to files changed since the last commit.

package.json

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"name": "@uniswap/token-lists",
3+
"author": "Moody Salem",
4+
"version": "0.1.0",
5+
"license": "MIT",
6+
"main": "dist/index.js",
7+
"typings": "dist/index.d.ts",
8+
"files": [
9+
"dist",
10+
"src"
11+
],
12+
"engines": {
13+
"node": ">=10"
14+
},
15+
"scripts": {
16+
"start": "tsdx watch",
17+
"build": "tsdx build",
18+
"test": "tsdx test",
19+
"lint": "tsdx lint",
20+
"prepare": "tsdx build"
21+
},
22+
"peerDependencies": {},
23+
"husky": {
24+
"hooks": {
25+
"pre-commit": "tsdx lint"
26+
}
27+
},
28+
"prettier": {
29+
"printWidth": 80,
30+
"semi": true,
31+
"singleQuote": true,
32+
"trailingComma": "es5"
33+
},
34+
"module": "dist/token-lists.esm.js",
35+
"devDependencies": {
36+
"husky": "^4.2.5",
37+
"tsdx": "^0.13.2",
38+
"tslib": "^2.0.0",
39+
"typescript": "^3.9.5"
40+
}
41+
}

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { TokenList } from 'types';
2+
3+
export * from './types';
4+
5+
export function validateTokenList(list: unknown): list is TokenList {
6+
return typeof list === 'object';
7+
}

src/tokenlist.schema.json

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
{
2+
"$schema": "https://json-schema.org/draft-07/schema#",
3+
"$id": "https://uniswap.org/token-list.schema.json",
4+
"title": "Uniswap Token List",
5+
"description": "A list of tokens compatible with the Uniswap Interface",
6+
"$ref": "#/definitions/TokenList",
7+
"definitions": {
8+
"Version": {
9+
"type": "object",
10+
"description": "A version number for a piece of data, useful for change detection",
11+
"properties": {
12+
"major": {
13+
"type": "integer",
14+
"description": "The major version of the list. Recommend incrementing major version when tokens are removed.",
15+
"minimum": 1
16+
},
17+
"minor": {
18+
"type": "integer",
19+
"description": "The minor version of the list. Recommend incrementing minor version when tokens are added.",
20+
"minimum": 0
21+
},
22+
"patch": {
23+
"type": "integer",
24+
"description": "The patch version of the list. Recommend incrementing for changes to tokens.",
25+
"minimum": 0
26+
}
27+
},
28+
"required": [
29+
"major",
30+
"minor",
31+
"patch"
32+
]
33+
},
34+
"TagDefinition": {
35+
"type": "object",
36+
"description": "Tag definition",
37+
"properties": {
38+
"name": {
39+
"type": "string",
40+
"description": "The name of the tag",
41+
"pattern": "^[\\s\\w]+$",
42+
"minLength": 1,
43+
"maxLength": 10
44+
},
45+
"description": {
46+
"type": "string",
47+
"description": "The user-friendly description of the tag",
48+
"pattern": "^[\\s\\w\\.]+$",
49+
"minLength": 1,
50+
"maxLength": 200
51+
}
52+
},
53+
"required": [
54+
"name",
55+
"description"
56+
]
57+
},
58+
"TokenInfo": {
59+
"type": "object",
60+
"description": "Information about a single token",
61+
"properties": {
62+
"chainId": {
63+
"type": "integer",
64+
"description": "The chain ID of the chain where this token lives",
65+
"minimum": 1
66+
},
67+
"address": {
68+
"type": "string",
69+
"description": "The address of the token",
70+
"pattern": "^0x[a-fA-F0-9]{40}$"
71+
},
72+
"decimals": {
73+
"type": "integer",
74+
"description": "How many decimals the token has. Defaults to on-chain data",
75+
"minimum": 0,
76+
"maximum": 78
77+
},
78+
"name": {
79+
"type": "string",
80+
"description": "The name of the token. Defaults to on-chain data",
81+
"minLength": 1
82+
},
83+
"symbol": {
84+
"type": "string",
85+
"description": "The symbol for the token. Defaults to on-chain data",
86+
"pattern": "^[a-zA-Z0-9]+$",
87+
"minLength": 1,
88+
"maxLength": 20
89+
},
90+
"logoUrl": {
91+
"type": "string",
92+
"description": "A URL to the token description",
93+
"pattern": "^(https|ipfs|ipns)://.+$"
94+
}
95+
},
96+
"required": [
97+
"chainId",
98+
"address"
99+
]
100+
},
101+
"TokenList": {
102+
"type": "object",
103+
"properties": {
104+
"name": {
105+
"type": "string",
106+
"description": "The name of the token list",
107+
"minLength": 1,
108+
"maxLength": 20
109+
},
110+
"timestamp": {
111+
"type": "integer",
112+
"description": "The epoch seconds timestamp of the list version"
113+
},
114+
"version": {
115+
"$ref": "#/definitions/Version"
116+
},
117+
"tokens": {
118+
"type": "array",
119+
"description": "The list of tokens included in the list",
120+
"items": {
121+
"$ref": "#/definitions/TokenInfo"
122+
},
123+
"minLength": 1,
124+
"maxLength": 1000
125+
},
126+
"keywords": {
127+
"type": "array",
128+
"description": "Keywords associated with the contents of the list",
129+
"items": {
130+
"type": "string",
131+
"minLength": 1,
132+
"maxLength": 20,
133+
"pattern": "^[\\w]+$"
134+
},
135+
"uniqueItems": true
136+
},
137+
"tags": {
138+
"type": "object",
139+
"description": "A mapping of tag identifiers to their name and description.",
140+
"propertyNames": {
141+
"pattern": "^\\d+$"
142+
},
143+
"additionalProperties": {
144+
"$ref": "#/definitions/TagDefinition"
145+
}
146+
}
147+
},
148+
"required": [
149+
"name",
150+
"timestamp",
151+
"version",
152+
"tokens"
153+
]
154+
}
155+
}
156+
}

src/types.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export interface TokenInfo {
2+
chainId: number;
3+
address: string;
4+
name?: string;
5+
decimals?: number;
6+
symbol?: string;
7+
logoUrl?: string;
8+
tagIds?: string[];
9+
}
10+
11+
export interface Version {
12+
major: number;
13+
minor: number;
14+
patch: number;
15+
}
16+
17+
export interface Tags {
18+
[tagId: string]: {
19+
name: string;
20+
description: string;
21+
};
22+
}
23+
24+
export interface TokenList {
25+
name: string;
26+
timestamp: number;
27+
version: Version;
28+
tokens: TokenInfo[];
29+
keywords?: string[];
30+
tags?: Tags;
31+
}

test/example.tokenlist.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "My Example List",
3+
"keywords": ["abc"],
4+
"tags": {
5+
"1": {
6+
"name": "tag 1",
7+
"description": "blah blah"
8+
}
9+
},
10+
"timestamp": 100,
11+
"tokens": [
12+
{
13+
"name": "blah",
14+
"address": "0x0000000000000000000000000000000000000000",
15+
"chainId": 1,
16+
"decimals": 18,
17+
"logoUrl": "https://test",
18+
"symbol": "abc"
19+
}
20+
],
21+
"version": {
22+
"major": 1,
23+
"minor": 0,
24+
"patch": 0
25+
}
26+
}

test/validateTokenList.test.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { validateTokenList } from '../src';
2+
3+
describe('#validateTokenList', () => {
4+
it('works', () => {
5+
expect(validateTokenList(undefined)).toEqual(false);
6+
});
7+
});

tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"include": ["src", "types"],
3+
"compilerOptions": {
4+
"module": "esnext",
5+
"lib": ["dom", "esnext"],
6+
"importHelpers": true,
7+
"declaration": true,
8+
"sourceMap": true,
9+
"rootDir": "./src",
10+
"strict": true,
11+
"noUnusedLocals": true,
12+
"noUnusedParameters": true,
13+
"noImplicitReturns": true,
14+
"noFallthroughCasesInSwitch": true,
15+
"moduleResolution": "node",
16+
"baseUrl": "./",
17+
"paths": {
18+
"*": ["src/*", "node_modules/*"]
19+
},
20+
"jsx": "react",
21+
"esModuleInterop": true
22+
}
23+
}

0 commit comments

Comments
 (0)