Skip to content

Commit

Permalink
refactor: make setup easy to new list (#227)
Browse files Browse the repository at this point in the history
* refactor

* fix test

* remove base

* polish

* doc

* workflow

* update lock

* lock version

* unlock

* use node

* fix coingecko
  • Loading branch information
0xjojoex authored Aug 25, 2023
1 parent 610b787 commit d6f02c0
Show file tree
Hide file tree
Showing 36 changed files with 1,041 additions and 8,051 deletions.
2 changes: 1 addition & 1 deletion .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
# the repo. Unless a later match takes precedence,
# @global-owner1 and @global-owner2 will be requested for
# review when someone opens a pull request.
* @chef-jojo @chefjackson @chefilip @ChefMomota @Chef-Yogi
* @chef-jojo @chefjackson @ChefMomota @Chef-Yogi
12 changes: 6 additions & 6 deletions .github/workflows/fetchCMC.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
node-version: 14.x
bun-version: latest

- name: Install dependencies
run: yarn install --frozen-lockfile
run: bun install

- name: Fetch CMC
run: yarn fetch:cmc
run: bun fetch cmc

- name: Makelist
run: yarn makelist:cmc
run: bun makelist cmc

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/fetchCoingecko.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ jobs:
- name: Checkout code
uses: actions/checkout@v2

- name: Setup Node
uses: actions/setup-node@v2
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
node-version: 14.x
bun-version: latest

- name: Install dependencies
run: yarn install --frozen-lockfile
run: bun install

- name: Fetch coingecko
run: yarn fetch:coingecko
run: bun fetch coingecko

- name: Makelist
run: yarn makelist:coingecko
run: bun makelist coingecko

- name: Create Pull Request
uses: peter-evans/create-pull-request@v3
Expand Down
11 changes: 6 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ jobs:
name: Unit Tests
steps:
- uses: actions/checkout@v2
- name: Setup node
uses: actions/setup-node@v1
- name: Setup Bun
uses: oven-sh/setup-bun@v1
with:
node-version: 14.x
- run: yarn install --frozen-lockfile
- run: yarn test
bun-version: latest
- run: bun install
- run: bun test
- run: bun ci-check
28 changes: 19 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# PancakeSwap Token Lists

## Install
use [Bun](https://bun.sh/)
```sh
curl -fsSL https://bun.sh/install | bash
```

```sh
bun install
```

This repo contains main PancakeSwap token list and tools to validate it.

## How to add external lists
Expand All @@ -9,41 +19,41 @@ URLs to external lists are stored in `token-lists.json`, if you want your list t
## How to add new lists within this repository

- Add an array of tokens under `src/tokens`
- Add `checksum:newlistname`, `generate:newlistname`, `makelist:newlistname` command to `package.json` analogous to PancakeSwap default and extended list scripts.
- Add `checksum newlistname`, `generate newlistname`, `makelist newlistname` command to `package.json` analogous to PancakeSwap default and extended list scripts.
- Modify `checksum.ts`, `buildList.ts`, `ci-check.ts`, and `default.test.ts` to handle new list

## How to add new tokens to PancakeSwap (extended) token list

Note - this is not something we expect pull requests for.
Note - this is not something we expect pull requests for.
Unless you've been specifically asked by someone from PCS team please do no submit PRs to be listed on default PCS list. You can still trade your tokens on PCS exchange by pasting your address into the token field.

- Add new tokens to `src/tokens/pancakeswap-extended.json` file
- Run `yarn makelist:pcs-extended`
- Run `bun makelist pancakeswap-extended`
- By default new list will have patch version number bumped by 1 (e.g. `2.0.1` -> `2.0.2`).
- If you want to bump minor version add `minor` after makelist command `yarn makelist:pcs-extended minor`
- If you want to bump major version add `major` after makelist command `yarn makelist:pcs-extended major`
- If you want to bump minor version add `minor` after makelist command `bun makelist pancakeswap-extended minor`
- If you want to bump major version add `major` after makelist command `bun makelist pancakeswap-extended major`
- If tests pass - new token list will be created under `lists` directory

For list to be considered valid it need to satisfy the following criteria:

- It passes [token list schema](https://github.com/Uniswap/token-lists/blob/master/src/tokenlist.schema.json) validation (schema is [slightly modified](src/schema.ts))
- There are no duplicate addresses, symbols or token names in the list
- All addresses are valid and checksummed (`yarn checksum:pcs` automatically converts addresses to checksummed versions, it is also part of `yarn makelist:pcs`)
- All addresses are valid and checksummed (`bun checksum listName` automatically converts addresses to checksummed versions, it is also part of `bun makelist listName`)

## How to update Top100 Token list

Note - this is not something we expect pull requests for.

```shell script
# Fetch the Top100 Tokens on PancakeSwap v2, and update list.
$ yarn fetch:pcs-top-100
$ bun fetch pancakeswap-top-100

# Build token list (pancakeswap-top-100.json)
$ yarn makelist:pcs-top-100
$ bun makelist pancakeswap-top-100
```

## Deploying

Token lists will be auto-deployed via netlify when PR is merged to master. Be sure to build the list with `yarn makelist:list-name` before submitting/merging the PR since it doesn't make much sense building lists within Netlify (because most errors are related to wrong token information and should be fixed prior to landing into master)
Token lists will be auto-deployed via netlify when PR is merged to master. Be sure to build the list with `bun makelist list-name` before submitting/merging the PR since it doesn't make much sense building lists within Netlify (because most errors are related to wrong token information and should be fixed prior to landing into master)

Netlify simply takes the json files under `lists` directory and hosts them on `tokens.pancakeswap.finance/list-name.json`
Binary file added bun.lockb
Binary file not shown.
54 changes: 54 additions & 0 deletions index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { buildList, saveList, VersionBump } from "./src/buildList.js";
import checksumAddresses from "./src/checksum.js";
import ciCheck from "./src/ci-check.js";
import topTokens from "./src/top-100.js";
import fetchThirdPartyList from "./src/fetchThirdPartyList.js";
import { LISTS } from "./src/constants.js";
import { exec } from "child_process";

const command = process.argv[2];
const listName = process.argv[3];
const versionBump = process.argv[4];

function checkListName() {
if (LISTS[listName as keyof typeof LISTS] === undefined) {
throw new Error(`Unknown list: ${listName}. Please check src/constants.ts`);
}
}

switch (command) {
case "checksum":
checkListName();
await checksumAddresses(listName);
break;
case "generate":
checkListName();
await saveList(await buildList(listName, versionBump as VersionBump), listName);
break;
case "makelist":
checkListName();
await checksumAddresses(listName);
await saveList(await buildList(listName, versionBump as VersionBump), listName);
const proc = Bun.spawn({
cmd: ["bun", "test", "-t", `${listName}`],
});

await proc.exited;
if (proc.exitCode !== 0) {
throw new Error(`Failed to generate list ${listName}`);
}
break;
case "fetch":
checkListName();
if (listName === "pcs-top-100") {
await topTokens();
}
await fetchThirdPartyList(listName);
break;
case "ci-check":
await ciCheck();
break;
default:
console.info("Unknown command");
break;
}
6 changes: 3 additions & 3 deletions lists/coingecko.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "CoinGecko",
"timestamp": "2023-08-23T08:50:25.260Z",
"timestamp": "2023-08-25T07:56:40.722Z",
"version": {
"major": 1,
"minor": 0,
"patch": 30
"patch": 31
},
"logoURI": "https://www.coingecko.com/assets/thumbnail-007177f3eca19695592f0b8b0eabbdae282b54154e1be912285c9034ea6cbaf2.png",
"logoURI": "https://tokens.pancakeswap.finance/images/projects/coingecko.png",
"keywords": [
"defi"
],
Expand Down
Binary file added lists/images/projects/coingecko.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions lists/pancakeswap-default.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "PancakeSwap Default",
"timestamp": "2022-03-01T08:37:04.410Z",
"timestamp": "2023-08-25T04:51:17.474Z",
"version": {
"major": 2,
"minor": 16,
"patch": 5
"patch": 7
},
"logoURI": "https://pancakeswap.finance/logo.png",
"keywords": [
Expand Down
12 changes: 2 additions & 10 deletions lists/pancakeswap-onramp.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "PancakeSwap Onramp",
"timestamp": "2023-08-14T05:08:36.025Z",
"timestamp": "2023-08-25T06:42:04.375Z",
"version": {
"major": 0,
"minor": 0,
"patch": 3
"patch": 6
},
"logoURI": "https://pancakeswap.finance/logo.png",
"keywords": [
Expand Down Expand Up @@ -44,14 +44,6 @@
"chainId": 56,
"logoURI": "https://tokens.pancakeswap.finance/images/symbol/busd.png"
},
{
"name": "DAI StableCoin",
"address": "0x6B175474E89094C44Da98b954EedeAC495271d0F",
"symbol": "DAI",
"decimals": 18,
"chainId": 324,
"logoURI": "https://tokens.pancakeswap.finance/images/symbol/dai.png"
},
{
"name": "USD ",
"symbol": "USDC",
Expand Down
67 changes: 9 additions & 58 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,65 +7,13 @@
"private": true,
"scripts": {
"build": "rm -rf ./dist && rollup -c",
"generate:pcs-aptos": "yarn build && node ./dist generate pancakeswap-aptos",
"makelist:pcs-aptos": "yarn test --list=pancakeswap-aptos && yarn generate:pcs-aptos",
"checksum:pcs-default": "yarn build && node ./dist checksum pancakeswap-default",
"generate:pcs-default": "yarn test --list=pancakeswap-default && yarn build && node ./dist generate pancakeswap-default",
"makelist:pcs-default": "yarn checksum:pcs-default && yarn generate:pcs-default",
"checksum:pcs-eth-default": "yarn build && node ./dist checksum pancakeswap-eth-default",
"generate:pcs-eth-default": "yarn test --list=pancakeswap-eth-default && yarn build && node ./dist generate pancakeswap-eth-default",
"makelist:pcs-eth-default": "yarn checksum:pcs-eth-default && yarn generate:pcs-eth-default",
"checksum:pcs-zksync-default": "yarn build && node ./dist checksum pancakeswap-zksync-default",
"generate:pcs-zksync-default": "yarn test --list=pancakeswap-zksync-default && yarn build && node ./dist generate pancakeswap-zksync-default",
"makelist:pcs-zksync-default": "yarn checksum:pcs-zksync-default && yarn generate:pcs-zksync-default",
"checksum:pcs-polygon-zkevm-default": "yarn build && node ./dist checksum pancakeswap-polygon-zkevm-default",
"generate:pcs-polygon-zkevm-default": "yarn test --list=pancakeswap-polygon-zkevm-default && yarn build && node ./dist generate pancakeswap-polygon-zkevm-default",
"makelist:pcs-polygon-zkevm-default": "yarn checksum:pcs-polygon-zkevm-default && yarn generate:pcs-polygon-zkevm-default",
"checksum:pcs-arbitrum-default": "yarn build && node ./dist checksum pancakeswap-arbitrum-default",
"generate:pcs-arbitrum-default": "yarn test --list=pancakeswap-arbitrum-default && yarn build && node ./dist generate pancakeswap-arbitrum-default",
"makelist:pcs-arbitrum-default": "yarn checksum:pcs-arbitrum-default && yarn generate:pcs-arbitrum-default",
"checksum:pcs-linea-default": "yarn build && node ./dist checksum pancakeswap-linea-default",
"generate:pcs-linea-default": "yarn test --list=pancakeswap-linea-default && yarn build && node ./dist generate pancakeswap-linea-default",
"makelist:pcs-linea-default": "yarn checksum:pcs-linea-default && yarn generate:pcs-linea-default",
"checksum:pcs-eth-mm": "yarn build && node ./dist checksum pancakeswap-eth-mm",
"generate:pcs-eth-mm": "yarn test --list=pancakeswap-eth-mm && yarn build && node ./dist generate pancakeswap-eth-mm",
"makelist:pcs-eth-mm": "yarn checksum:pcs-eth-mm && yarn generate:pcs-eth-mm",
"checksum:pcs-bnb-mm": "yarn build && node ./dist checksum pancakeswap-bnb-mm",
"generate:pcs-bnb-mm": "yarn test --list=pancakeswap-bnb-mm && yarn build && node ./dist generate pancakeswap-bnb-mm",
"makelist:pcs-bnb-mm": "yarn checksum:pcs-bnb-mm && yarn generate:pcs-bnb-mm",
"checksum:pcs-extended": "yarn build && node ./dist checksum pancakeswap-extended",
"generate:pcs-extended": "yarn test --list=pancakeswap-extended && yarn build && node ./dist generate pancakeswap-extended",
"makelist:pcs-extended": "yarn checksum:pcs-extended && yarn generate:pcs-extended",
"checksum:pcs-top-100": "yarn build && node ./dist checksum pancakeswap-top-100",
"generate:pcs-top-100": "yarn test && yarn build && node ./dist generate pancakeswap-top-100",
"makelist:pcs-top-100": "yarn checksum:pcs-top-100 && yarn generate:pcs-top-100",
"checksum:pcs-top-15": "yarn build && node ./dist checksum pancakeswap-top-15",
"generate:pcs-top-15": "yarn test && yarn build && node ./dist generate pancakeswap-top-15",
"makelist:pcs-top-15": "yarn checksum:pcs-top-15 && yarn generate:pcs-top-15",
"checksum:coingecko": "yarn build && node ./dist checksum coingecko",
"generate:coingecko": "yarn test --list=coingecko && yarn build && node ./dist generate coingecko",
"makelist:coingecko": "yarn checksum:coingecko && yarn generate:coingecko",
"checksum:cmc": "yarn build && node ./dist checksum cmc",
"generate:cmc": "yarn test --list=cmc && yarn build && node ./dist generate cmc",
"makelist:cmc": "yarn checksum:cmc && yarn generate:cmc",
"checksum:pcs-mini": "yarn build && node ./dist checksum pancakeswap-mini",
"generate:pcs-mini": "yarn test --list=pancakeswap-mini && yarn build && node ./dist generate pancakeswap-mini",
"makelist:pcs-mini": "yarn checksum:pcs-mini && yarn generate:pcs-mini",
"checksum:pcs-mini-extended": "yarn build && node ./dist checksum pancakeswap-mini-extended",
"generate:pcs-mini-extended": "yarn test --list=pancakeswap-mini-extended && yarn build && node ./dist generate pancakeswap-mini-extended",
"makelist:pcs-mini-extended": "yarn checksum:pcs-mini-extended && yarn generate:pcs-mini-extended",
"from-addresses:pcs-mini-extended": "yarn build && node ./dist get-list-from-addresses",
"checksum:pcs-onramp": "yarn build && node ./dist checksum pancakeswap-onramp",
"generate:pcs-onramp": "yarn test --list=pancakeswap-onramp && yarn build && node ./dist generate pancakeswap-onramp",
"makelist:pcs-onramp": "yarn checksum:pcs-onramp && yarn generate:pcs-onramp",
"checksum": "bun run index.ts checksum",
"generate": "bun run index.ts generate",
"makelist": "bun run index.ts makelist",
"lint": "eslint 'src/**/*.{js,jsx,ts,tsx}'",
"fetch:pcs-top-100": "yarn build && node ./dist fetch pcs-top-100",
"fetch:coingecko": "yarn build && node ./dist fetch coingecko",
"fetch:cmc": "yarn build && node ./dist fetch cmc",
"fetch": "bun run index.ts fetch",
"test": "jest",
"ci-check": "yarn build && node ./dist ci-check",
"postinstall": "yarn run typechain",
"typechain": "typechain --out-dir src/utils/abi/types --target=ethers-v5 \"src/utils/abi/*.json\""
"ci-check": "bun run index.ts ci-check"
},
"dependencies": {
"@ethersproject/address": "^5.1.0",
Expand All @@ -75,13 +23,15 @@
"ajv": "6.12.2",
"aptos": "^1.3.16",
"axios": "^0.26.0",
"bun": "^0.8.0",
"ethers": "^5.5.4",
"graphql": "^15.5.0",
"graphql-request": "^3.4.0",
"lodash": "^4.17.21",
"slugify": "^1.6.0",
"tslib": "^2.4.0",
"typechain": "^7.0.0"
"typechain": "^7.0.0",
"viem": "^1.7.0"
},
"devDependencies": {
"@babel/preset-env": "^7.14.1",
Expand All @@ -92,6 +42,7 @@
"@types/lodash": "^4.14.182",
"@types/node": "^15.0.2",
"babel-jest": "^26.6.3",
"bun-types": "^0.8.0",
"jest": "^26.6.3",
"rollup": "^2.47.0",
"ts-jest": "^26.5.6",
Expand Down
Loading

0 comments on commit d6f02c0

Please sign in to comment.