Skip to content

Commit

Permalink
initial commit of json schema
Browse files Browse the repository at this point in the history
  • Loading branch information
moodysalem committed Jun 10, 2020
0 parents commit 1d2fdda
Show file tree
Hide file tree
Showing 10 changed files with 342 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.idea/

This comment has been minimized.

Copy link
@Keyfo7272

Keyfo7272 Jan 26, 2022

1

This comment has been minimized.

Copy link
@Keyfo7272

Keyfo7272 Jan 26, 2022

E

dist/
node_modules/
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Uniswap

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# TSDX Bootstrap

This project was bootstrapped with [TSDX](https://github.com/jaredpalmer/tsdx).

## Local Development

Below is a list of commands you will probably find useful.

### `npm start` or `yarn start`

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.

<img src="https://user-images.githubusercontent.com/4060187/52168303-574d3a00-26f6-11e9-9f3b-71dbec9ebfcb.gif" width="600" />

Your library will be rebuilt if you make edits.

### `npm run build` or `yarn build`

Bundles the package to the `dist` folder.
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).

<img src="https://user-images.githubusercontent.com/4060187/52168322-a98e5b00-26f6-11e9-8cf6-222d716b75ef.gif" width="600" />

### `npm test` or `yarn test`

Runs the test watcher (Jest) in an interactive mode.
By default, runs tests related to files changed since the last commit.
41 changes: 41 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "@uniswap/token-lists",
"author": "Moody Salem",
"version": "0.1.0",
"license": "MIT",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"files": [
"dist",
"src"
],
"engines": {
"node": ">=10"
},
"scripts": {
"start": "tsdx watch",
"build": "tsdx build",
"test": "tsdx test",
"lint": "tsdx lint",
"prepare": "tsdx build"
},
"peerDependencies": {},
"husky": {
"hooks": {
"pre-commit": "tsdx lint"
}
},
"prettier": {
"printWidth": 80,
"semi": true,
"singleQuote": true,
"trailingComma": "es5"
},
"module": "dist/token-lists.esm.js",
"devDependencies": {
"husky": "^4.2.5",
"tsdx": "^0.13.2",
"tslib": "^2.0.0",
"typescript": "^3.9.5"
}
}
7 changes: 7 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { TokenList } from 'types';

export * from './types';

export function validateTokenList(list: unknown): list is TokenList {
return typeof list === 'object';
}
156 changes: 156 additions & 0 deletions src/tokenlist.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
{
"$schema": "https://json-schema.org/draft-07/schema#",
"$id": "https://uniswap.org/token-list.schema.json",
"title": "Uniswap Token List",
"description": "A list of tokens compatible with the Uniswap Interface",
"$ref": "#/definitions/TokenList",
"definitions": {
"Version": {
"type": "object",
"description": "A version number for a piece of data, useful for change detection",
"properties": {
"major": {
"type": "integer",
"description": "The major version of the list. Recommend incrementing major version when tokens are removed.",
"minimum": 1
},
"minor": {
"type": "integer",
"description": "The minor version of the list. Recommend incrementing minor version when tokens are added.",
"minimum": 0
},
"patch": {
"type": "integer",
"description": "The patch version of the list. Recommend incrementing for changes to tokens.",
"minimum": 0
}
},
"required": [
"major",
"minor",
"patch"
]
},
"TagDefinition": {
"type": "object",
"description": "Tag definition",
"properties": {
"name": {
"type": "string",
"description": "The name of the tag",
"pattern": "^[\\s\\w]+$",
"minLength": 1,
"maxLength": 10
},
"description": {
"type": "string",
"description": "The user-friendly description of the tag",
"pattern": "^[\\s\\w\\.]+$",
"minLength": 1,
"maxLength": 200
}
},
"required": [
"name",
"description"
]
},
"TokenInfo": {
"type": "object",
"description": "Information about a single token",
"properties": {
"chainId": {
"type": "integer",
"description": "The chain ID of the chain where this token lives",
"minimum": 1
},
"address": {
"type": "string",
"description": "The address of the token",
"pattern": "^0x[a-fA-F0-9]{40}$"
},
"decimals": {
"type": "integer",
"description": "How many decimals the token has. Defaults to on-chain data",
"minimum": 0,
"maximum": 78
},
"name": {
"type": "string",
"description": "The name of the token. Defaults to on-chain data",
"minLength": 1
},
"symbol": {
"type": "string",
"description": "The symbol for the token. Defaults to on-chain data",
"pattern": "^[a-zA-Z0-9]+$",
"minLength": 1,
"maxLength": 20
},
"logoUrl": {
"type": "string",
"description": "A URL to the token description",
"pattern": "^(https|ipfs|ipns)://.+$"
}
},
"required": [
"chainId",
"address"
]
},
"TokenList": {
"type": "object",
"properties": {
"name": {
"type": "string",
"description": "The name of the token list",
"minLength": 1,
"maxLength": 20
},
"timestamp": {
"type": "integer",
"description": "The epoch seconds timestamp of the list version"
},
"version": {
"$ref": "#/definitions/Version"
},
"tokens": {
"type": "array",
"description": "The list of tokens included in the list",
"items": {
"$ref": "#/definitions/TokenInfo"
},
"minLength": 1,
"maxLength": 1000
},
"keywords": {
"type": "array",
"description": "Keywords associated with the contents of the list",
"items": {
"type": "string",
"minLength": 1,
"maxLength": 20,
"pattern": "^[\\w]+$"
},
"uniqueItems": true
},
"tags": {
"type": "object",
"description": "A mapping of tag identifiers to their name and description.",
"propertyNames": {
"pattern": "^\\d+$"
},
"additionalProperties": {
"$ref": "#/definitions/TagDefinition"
}
}
},
"required": [
"name",
"timestamp",
"version",
"tokens"
]
}
}
}
31 changes: 31 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
export interface TokenInfo {
chainId: number;
address: string;
name?: string;
decimals?: number;
symbol?: string;
logoUrl?: string;
tagIds?: string[];
}

export interface Version {
major: number;
minor: number;
patch: number;
}

export interface Tags {
[tagId: string]: {
name: string;
description: string;
};
}

export interface TokenList {
name: string;
timestamp: number;
version: Version;
tokens: TokenInfo[];
keywords?: string[];
tags?: Tags;
}
26 changes: 26 additions & 0 deletions test/example.tokenlist.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "My Example List",
"keywords": ["abc"],
"tags": {
"1": {
"name": "tag 1",
"description": "blah blah"
}
},
"timestamp": 100,
"tokens": [
{
"name": "blah",
"address": "0x0000000000000000000000000000000000000000",
"chainId": 1,
"decimals": 18,
"logoUrl": "https://test",
"symbol": "abc"
}
],
"version": {
"major": 1,
"minor": 0,
"patch": 0
}
}
7 changes: 7 additions & 0 deletions test/validateTokenList.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { validateTokenList } from '../src';

describe('#validateTokenList', () => {
it('works', () => {
expect(validateTokenList(undefined)).toEqual(false);
});
});
23 changes: 23 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"include": ["src", "types"],
"compilerOptions": {
"module": "esnext",
"lib": ["dom", "esnext"],
"importHelpers": true,
"declaration": true,
"sourceMap": true,
"rootDir": "./src",
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"moduleResolution": "node",
"baseUrl": "./",
"paths": {
"*": ["src/*", "node_modules/*"]
},
"jsx": "react",
"esModuleInterop": true
}
}

0 comments on commit 1d2fdda

Please sign in to comment.