Skip to content

Commit

Permalink
feat: reorg
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewlilley committed Jun 28, 2021
1 parent f5b0d58 commit 7cfe7ad
Show file tree
Hide file tree
Showing 31 changed files with 442 additions and 108 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea/
node_modules
build/
build/
generated/
74 changes: 74 additions & 0 deletions internal/buildList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
const { version } = require("../package.json");

const mainnet = require("../tokens/mainnet.json");
const ropsten = require("../tokens/ropsten.json");
const rinkeby = require("../tokens/rinkeby.json");
const goerli = require("../tokens/goerli.json");
const kovan = require("../tokens/kovan.json");
const fantom = require("../tokens/fantom.json");
const fantomTestnet = require("../tokens/fantom-testnet.json");
const matic = require("../tokens/matic.json");
const maticTestnet = require("../tokens/matic-testnet.json");
const xdai = require("../tokens/xdai.json");
const bsc = require("../tokens/bsc.json");
const bscTestnet = require("../tokens/bsc-testnet.json");
const moonbase = require("../tokens/moonbase.json");
const avalanche = require("../tokens/avalanche.json");
const fuji = require("../tokens/fuji.json");
const heco = require("../tokens/heco.json");
const hecoTestnet = require("../tokens/heco-testnet.json");
const harmony = require("../tokens/harmony.json");
const harmonyTestnet = require("../tokens/harmony-testnet.json");
const okex = require("../tokens/okex.json");
const okexTestnet = require("../tokens/okex-testnet.json");
//const arbitrum = require("../tokens/arbitrum.json");
//const celo = require("../tokens/celo.json");

module.exports = function buildList() {
const parsed = version.split(".");
return {
name: "SushiSwap Menu",
timestamp: new Date().toISOString(),
version: {
major: +parsed[0],
minor: +parsed[1],
patch: +parsed[2],
},
tags: {},
logoURI:
"https://raw.githubusercontent.com/sushiswap/art/master/sushi/logo-256x256.png",
keywords: ["sushiswap", "default"],
tokens: [
...mainnet,
...ropsten,
...goerli,
...kovan,
...rinkeby,
...fantom,
...fantomTestnet,
...matic,
...maticTestnet,
...xdai,
...bsc,
...bscTestnet,
...moonbase,
...avalanche,
...fuji,
...heco,
...hecoTestnet,
...harmony,
...harmonyTestnet,
...okex,
...okexTestnet,
//...arbitrum,
//...celo,
]
// sort them by symbol for easy readability
.sort((t1, t2) => {
if (t1.chainId === t2.chainId) {
return t1.symbol.toLowerCase() < t2.symbol.toLowerCase() ? -1 : 1;
}
return t1.chainId < t2.chainId ? -1 : 1;
}),
};
};
93 changes: 93 additions & 0 deletions internal/sync.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const XLSX = require("xlsx");

const { Octokit } = require("@octokit/rest");

const octokit = new Octokit();

const { ChainId } = require("@sushiswap/sdk");

const fs = require("fs");

const { resolve } = require("path");

const NAME = {
[ChainId.MAINNET]: "mainnet",
[ChainId.FANTOM]: "fantom",
[ChainId.MATIC]: "matic",
[ChainId.XDAI]: "xdai",
[ChainId.BSC]: "bsc",
[ChainId.AVALANCHE]: "avalanche",
[ChainId.HECO]: "heco",
[ChainId.HARMONY]: "harmony",
[ChainId.OKEX]: "okex",
[ChainId.CELO]: "celo",
};

(async () => {
try {
const book = XLSX.utils.book_new();

for (const key of Object.keys(ChainId)) {
const path = resolve(__dirname, `../tokens/${NAME[key]}.json`);

if (!fs.existsSync(path)) {
continue;
}

const tokens = require(path);

// Grab file file names of the sushiswap/icons repo at the token path
// we can use this to see if our default list is missing icons
const { data } = await octokit.rest.repos.getContent({
owner: "sushiswap",
repo: "icons",
path: "token",
});

const icons = data.map((data) => data.name.replace(".jpg", ""));

const json = [];

for (const token of tokens) {
const listIcon = icons.find(
(icon) => icon === token.symbol.toLowerCase()
);

// TODO: Check Figma and get icon if available
const figmaIcon = undefined;

const icon = listIcon || figmaIcon;

if ((!token.logoURI && !icon) || !icon) {
json.push({
network: NAME[key],
address: token.address,
name: token.name,
symbol: token.symbol,
logoURI: token?.logoURI || "",
});
console.log("Add to list to send to chester");
continue;
}

// Check if logoURI has correct path
if (!token.logoURI.includes("sushiswap/icons")) {
// TODO: Automate this part...
const logoURI = `https://raw.githubusercontent.com/sushiswap/icons/master/token/${icon}.jpg`;

console.log(`Update Logo URI for ${token.symbol} with ${logoURI}`);
} else {
console.log(`Logo URI for ${token.symbol} is correct`);
}
}

const sheet = XLSX.utils.json_to_sheet(json);

XLSX.utils.book_append_sheet(book, sheet, NAME[key]);
}

XLSX.writeFile(book, resolve(__dirname, `../generated/missing-icons.xlsx`));
} catch (error) {
console.error(error);
}
})();
2 changes: 2 additions & 0 deletions internal/write.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
const buildList = require("./buildList");
console.log(JSON.stringify(buildList(), null, 2));
11 changes: 8 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
"main": "build/sushiswap-default.tokenlist.json",
"scripts": {
"test": "mocha",
"build": "rimraf build && mkdir -p build && node src/write.js > build/sushiswap-default.tokenlist.json",
"prepublishOnly": "npm test && npm run build"
"build": "rimraf build && mkdir -p build && node internal/write.js > build/sushiswap-default.tokenlist.json",
"prepublishOnly": "npm test && npm run build",
"sync": "node internal/sync.js"
},
"files": [
"build/sushiswap-default.tokenlist.json"
Expand All @@ -29,11 +30,15 @@
"homepage": "https://github.com/sushiswap/default-token-list#readme",
"devDependencies": {
"@ethersproject/address": "^5.0.2",
"@ethersproject/solidity": "^5.3.0",
"@octokit/rest": "^18.6.2",
"@sushiswap/sdk": "^5.0.0-canary.22",
"@uniswap/token-lists": "^1.0.0-beta.19",
"ajv": "^6.12.3",
"chai": "^4.2.0",
"lodash": "^4.17.21",
"mocha": "^8.0.1",
"rimraf": "^3.0.2"
"rimraf": "^3.0.2",
"xlsx": "^0.17.0"
}
}
73 changes: 0 additions & 73 deletions src/buildList.js

This file was deleted.

2 changes: 0 additions & 2 deletions src/write.js

This file was deleted.

58 changes: 30 additions & 28 deletions test/sushiswap-default.test.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,60 @@
const packageJson = require('../package.json');
const schema = require('@uniswap/token-lists/src/tokenlist.schema.json');
const { expect } = require('chai');
const { getAddress } = require('@ethersproject/address');
const Ajv = require('ajv');
const buildList = require('../src/buildList');

const ajv = new Ajv({ allErrors: true, format: 'full' });
const packageJson = require("../package.json");
const schema = require("@uniswap/token-lists/src/tokenlist.schema.json");
const { expect } = require("chai");
const { getAddress } = require("@ethersproject/address");
const Ajv = require("ajv");
const buildList = require("../internal/buildList");

const ajv = new Ajv({ allErrors: true, format: "full" });
const validator = ajv.compile(schema);

describe('buildList', () => {
describe("buildList", () => {
const defaultTokenList = buildList();

it('validates', () => {
it("validates", () => {
expect(validator(defaultTokenList)).to.equal(true);
});

it('contains no duplicate addresses', () => {
it("contains no duplicate addresses", () => {
const map = {};
for (let token of defaultTokenList.tokens) {
const key = `${token.chainId}-${token.address}`;
expect(typeof map[ key ])
.to.equal('undefined');
map[ key ] = true;
expect(typeof map[key]).to.equal("undefined");
map[key] = true;
}
});

it('contains no duplicate symbols', () => {
it("contains no duplicate symbols", () => {
const map = {};
for (let token of defaultTokenList.tokens) {
const key = `${token.chainId}-${token.symbol.toLowerCase()}`;
expect(typeof map[ key ])
.to.equal('undefined');
map[ key ] = true;
expect(typeof map[key]).to.equal("undefined");
map[key] = true;
}
})
});

it('contains no duplicate names', () => {
it("contains no duplicate names", () => {
const map = {};
for (let token of defaultTokenList.tokens) {
const key = `${token.chainId}-${token.name.toLowerCase()}`;
expect(typeof map[ key ])
.to.equal('undefined', `duplicate name: ${token.name}`);
map[ key ] = true;
expect(typeof map[key]).to.equal(
"undefined",
`duplicate name: ${token.name}`
);
map[key] = true;
}
})
});

it('all addresses are valid and checksummed', () => {
it("all addresses are valid and checksummed", () => {
for (let token of defaultTokenList.tokens) {
expect(getAddress(token.address)).to.eq(token.address);
}
});

it('version matches package.json', () => {
it("version matches package.json", () => {
expect(packageJson.version).to.match(/^\d+\.\d+\.\d+$/);
expect(packageJson.version).to.equal(`${defaultTokenList.version.major}.${defaultTokenList.version.minor}.${defaultTokenList.version.patch}`);
expect(packageJson.version).to.equal(
`${defaultTokenList.version.major}.${defaultTokenList.version.minor}.${defaultTokenList.version.patch}`
);
});
});
});
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 7cfe7ad

Please sign in to comment.