Skip to content

Commit 8b53bbe

Browse files
committed
feat: script'n'test
1 parent d353e03 commit 8b53bbe

File tree

8 files changed

+108
-175
lines changed

8 files changed

+108
-175
lines changed

.github/pull_request_template.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@ Please review the following token assets:
33
## 📑 Description
44

55
<!-- Some basic information about the token you want to add -->
6-
- Token Name: ...
7-
- Project Website: https://... <!-- ⚠️ Your website MUST contain of the token address or the PR will be rejected -->
8-
- Explorer URI: https://...
96

7+
- Token Name: ...
8+
- Project Website: https://... <!-- ⚠️ Your website MUST contain of the token address or the PR will be rejected -->
9+
- Explorer URI: https://...
1010

1111
---
1212

1313
## ✅ Checks
1414

1515
<!-- Make sure your pr passes the CI checks and do check the following fields as needed - -->
16-
- [ ] I created a new folder with the token address, **all in lowercase**
17-
- [ ] I added the token's logo as a `32x32` PNG file, named `logo-32.png`
18-
- [ ] I added the token's logo as a `128x128` PNG file, named `logo-128.png`
19-
- [ ] I added the token's logo as a SVG file, named `logo.svg`
20-
- [ ] My SVG logo is a proper SVG and not some base64 stuff
21-
- [ ] My documentation/website clearly display the token address somewhere
16+
17+
- [ ] I created a new folder with the token address, **all in lowercase**
18+
- [ ] I added the token's logo as a `32x32` PNG file, named `logo-32.png`
19+
- [ ] I added the token's logo as a `128x128` PNG file, named `logo-128.png`
20+
- [ ] I added the token's logo as a SVG file, named `logo.svg`
21+
- [ ] My SVG logo is a proper SVG and not some base64 stuff
22+
- [ ] My documentation/website clearly display the token address somewhere

.github/scripts/generate-lists.mjs

+23-21
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,35 @@
1-
import fs from "fs-extra";
2-
import path from "path";
3-
import createKeccakHash from 'keccak'
1+
import fs from 'fs-extra';
2+
import path from 'path';
3+
import createKeccakHash from 'keccak';
44

5-
const DataDirectory = "./tokens";
6-
const IndexName = "list.json";
5+
const DataDirectory = './tokens';
6+
const IndexName = 'list.json';
77

88
function toChecksumAddress(address) {
9-
address = address.toLowerCase().replace('0x', '')
10-
var hash = createKeccakHash('keccak256').update(address).digest('hex')
11-
var ret = '0x'
9+
address = address.toLowerCase().replace('0x', '');
10+
var hash = createKeccakHash('keccak256').update(address).digest('hex');
11+
var ret = '0x';
1212

1313
for (var i = 0; i < address.length; i++) {
1414
if (parseInt(hash[i], 16) >= 8) {
15-
ret += address[i].toUpperCase()
15+
ret += address[i].toUpperCase();
1616
} else {
17-
ret += address[i]
17+
ret += address[i];
1818
}
1919
}
2020

21-
return ret
21+
return ret;
2222
}
2323

2424
const perChain = {};
2525
function generate(directory) {
2626
for (let name of fs.readdirSync(directory)) {
27-
if (name.startsWith(".") || name === IndexName || name === 'node_modules') continue;
27+
if (name.startsWith('.') || name === IndexName || name === 'node_modules') continue;
2828
const file = path.join(directory, name);
2929
const stat = fs.lstatSync(file);
3030
if (stat.isDirectory()) {
31-
if (name.startsWith("0x")) {
32-
const currentChain = Number(directory.split("/").pop());
31+
if (name.startsWith('0x')) {
32+
const currentChain = Number(directory.split('/').pop());
3333
if (perChain[currentChain] === undefined) {
3434
perChain[currentChain] = [];
3535
}
@@ -41,21 +41,23 @@ function generate(directory) {
4141
}
4242

4343
const cwd = process.cwd();
44-
if (!fs.existsSync(path.join(cwd, ".git"))) {
45-
console.error("Error: script should be run in the root of the repo.");
44+
if (!fs.existsSync(path.join(cwd, '.git'))) {
45+
console.error('Error: script should be run in the root of the repo.');
4646
process.exit(1);
4747
}
4848

4949
try {
5050
generate(DataDirectory);
5151
for (const chain in perChain) {
5252
//load the existing list
53-
const previousLists = fs.existsSync(path.join(DataDirectory, chain, IndexName)) ? JSON.parse(fs.readFileSync(path.join(DataDirectory, chain, IndexName))) : {};
53+
const previousLists = fs.existsSync(path.join(DataDirectory, chain, IndexName))
54+
? JSON.parse(fs.readFileSync(path.join(DataDirectory, chain, IndexName)))
55+
: {};
5456
if (!previousLists.version) {
5557
previousLists.version = {
56-
'major': 0,
57-
'minor': 0,
58-
'patch': 0
58+
major: 0,
59+
minor: 0,
60+
patch: 0
5961
};
6062
}
6163
if (!previousLists.tokens) {
@@ -64,7 +66,7 @@ try {
6466
const newList = {
6567
version: previousLists.version,
6668
tokens: perChain[chain]
67-
}
69+
};
6870
//compare the new list with the old one
6971
if (JSON.stringify(previousLists.tokens) === JSON.stringify(newList.tokens)) {
7072
console.log(`No changes detected for chain ${chain}`);

.github/scripts/verify-chains.mjs

+21-17
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
1-
import fs from "fs-extra";
2-
import path from "path";
1+
import fs from 'fs-extra';
2+
import path from 'path';
33

4-
const DataDirectory = "./chains";
5-
const IndexName = "index.json";
4+
const DataDirectory = './chains';
5+
const IndexName = 'index.json';
66

77
function validate(directory) {
88
let allValid = true;
99
for (let name of fs.readdirSync(directory)) {
10-
if (name.startsWith(".") || name === IndexName || name === 'node_modules') continue;
10+
if (name.startsWith('.') || name === IndexName || name === 'node_modules') continue;
1111
const file = path.join(directory, name);
1212
const stat = fs.lstatSync(file);
1313
if (stat.isDirectory()) {
14-
if (name.startsWith("_")) {
15-
continue
14+
if (name.startsWith('_')) {
15+
continue;
1616
}
1717
if (name.match(/^[0-9]+$/) != null) {
18-
if (!fs.existsSync(path.join(file, "logo-128.png"))) {
18+
if (!fs.existsSync(path.join(file, 'logo-128.png'))) {
1919
console.error(`Error: "${file}" is missing logo-128.png`);
2020
allValid = false;
2121
}
22-
if (!fs.existsSync(path.join(file, "logo-32.png"))) {
22+
if (!fs.existsSync(path.join(file, 'logo-32.png'))) {
2323
console.error(`Error: "${file}" is missing logo-32.png`);
2424
allValid = false;
2525
}
26-
if (!fs.existsSync(path.join(file, "logo.svg"))) {
26+
if (!fs.existsSync(path.join(file, 'logo.svg'))) {
2727
console.error(`Error: "${file}" is missing logo.svg`);
2828
allValid = false;
2929
} else {
30-
const svgValue = fs.readFileSync(path.join(file, "logo.svg"));
31-
if (svgValue.includes(`data:image/png;base64`) || svgValue.includes(`data:img/png;base64`) || svgValue.includes(`data:image/jpeg;base64`) || svgValue.includes(`data:img/jpeg;base64`)) {
30+
const svgValue = fs.readFileSync(path.join(file, 'logo.svg'));
31+
if (
32+
svgValue.includes(`data:image/png;base64`) ||
33+
svgValue.includes(`data:img/png;base64`) ||
34+
svgValue.includes(`data:image/jpeg;base64`) ||
35+
svgValue.includes(`data:img/jpeg;base64`)
36+
) {
3237
console.error(`Error: "${file}" logo.svg contains base64 encoded image.`);
3338
allValid = false;
3439
}
@@ -42,19 +47,18 @@ function validate(directory) {
4247

4348
function verify(dataDir) {
4449
const valid = validate(dataDir);
45-
if (!valid)
46-
process.exit(1);
50+
if (!valid) process.exit(1);
4751
}
4852

4953
const cwd = process.cwd();
50-
if (!fs.existsSync(path.join(cwd, ".git"))) {
51-
console.error("Error: script should be run in the root of the repo.");
54+
if (!fs.existsSync(path.join(cwd, '.git'))) {
55+
console.error('Error: script should be run in the root of the repo.');
5256
process.exit(1);
5357
}
5458

5559
try {
5660
verify(DataDirectory);
57-
console.log("Ok: all files match schema definitions!");
61+
console.log('Ok: all files match schema definitions!');
5862
} catch (error) {
5963
console.error(error);
6064
process.exit(1);

.github/scripts/verify-tokens.mjs

+36-20
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,65 @@
1-
import fs from "fs-extra";
2-
import path from "path";
1+
import fs from 'fs-extra';
2+
import path from 'path';
33

4-
const DataDirectory = "./tokens";
5-
const IndexName = "index.json";
4+
const DataDirectory = './tokens';
5+
const IndexName = 'index.json';
6+
7+
function getFilesizeInBytes(filename) {
8+
var stats = fs.statSync(filename);
9+
var fileSizeInBytes = stats.size;
10+
return fileSizeInBytes;
11+
}
612

713
function validate(directory) {
814
let allValid = true;
915
for (let name of fs.readdirSync(directory)) {
10-
if (name.startsWith(".") || name === IndexName || name === 'node_modules') continue;
16+
if (name.startsWith('.') || name === IndexName || name === 'node_modules') continue;
1117
const file = path.join(directory, name);
1218
const stat = fs.lstatSync(file);
1319
if (stat.isDirectory()) {
14-
if (name.startsWith("0x")) {
20+
if (name.startsWith('0x')) {
1521
try {
1622
if (name.toLowerCase() !== name) {
1723
console.error(`Error: "${name}" is not lowercased. Should be "${name.toLowerCase()}".`);
1824
allValid = false;
1925
}
20-
} catch(error) {
26+
} catch (error) {
2127
console.error(`Error: "${name}" is not lowercased. Should be "${name.toLowerCase()}".`);
2228
allValid = false;
2329
}
2430
}
25-
if (name.startsWith("_")) {
26-
continue
31+
if (name.startsWith('_')) {
32+
continue;
2733
}
28-
if (name.startsWith("0x")) {
29-
if (!fs.existsSync(path.join(file, "logo-128.png"))) {
34+
if (name.startsWith('0x')) {
35+
if (!fs.existsSync(path.join(file, 'logo-128.png'))) {
3036
console.error(`Error: "${file}" is missing logo-128.png`);
3137
allValid = false;
3238
}
33-
if (!fs.existsSync(path.join(file, "logo-32.png"))) {
39+
if (!fs.existsSync(path.join(file, 'logo-32.png'))) {
3440
console.error(`Error: "${file}" is missing logo-32.png`);
3541
allValid = false;
3642
}
37-
if (!fs.existsSync(path.join(file, "logo.svg"))) {
43+
if (!fs.existsSync(path.join(file, 'logo.svg'))) {
3844
console.error(`Error: "${file}" is missing logo.svg`);
3945
allValid = false;
4046
} else {
41-
const svgValue = fs.readFileSync(path.join(file, "logo.svg"));
42-
if (svgValue.includes(`data:image/png;base64`) || svgValue.includes(`data:img/png;base64`) || svgValue.includes(`data:image/jpeg;base64`) || svgValue.includes(`data:img/jpeg;base64`)) {
47+
const svgValue = fs.readFileSync(path.join(file, 'logo.svg'));
48+
if (
49+
svgValue.includes(`data:image/png;base64`) ||
50+
svgValue.includes(`data:img/png;base64`) ||
51+
svgValue.includes(`data:image/jpeg;base64`) ||
52+
svgValue.includes(`data:img/jpeg;base64`)
53+
) {
4354
console.error(`Error: "${file}" logo.svg contains base64 encoded image.`);
4455
allValid = false;
4556
}
57+
// const fileSize = getFilesizeInBytes(path.join(file, 'logo.svg')) / 1000000;
58+
// if (fileSize > 0.15) {
59+
// console.error(`Error: "${file}" logo.svg is larger than 0.15mb.`);
60+
// allValid = false;
61+
// }
62+
4663
}
4764
}
4865
allValid &= validate(file);
@@ -53,19 +70,18 @@ function validate(directory) {
5370

5471
function verify(dataDir) {
5572
const valid = validate(dataDir);
56-
if (!valid)
57-
process.exit(1);
73+
if (!valid) process.exit(1);
5874
}
5975

6076
const cwd = process.cwd();
61-
if (!fs.existsSync(path.join(cwd, ".git"))) {
62-
console.error("Error: script should be run in the root of the repo.");
77+
if (!fs.existsSync(path.join(cwd, '.git'))) {
78+
console.error('Error: script should be run in the root of the repo.');
6379
process.exit(1);
6480
}
6581

6682
try {
6783
verify(DataDirectory);
68-
console.log("Ok: all files match schema definitions!");
84+
console.log('Ok: all files match schema definitions!');
6985
} catch (error) {
7086
console.error(error);
7187
process.exit(1);

.prettierrc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"singleQuote": true,
3+
"semi": true,
4+
"useTabs": true,
5+
"tabWidth": 4,
6+
"trailingComma": "none",
7+
"bracketSpacing": false,
8+
"arrowParens": "avoid",
9+
"bracketSameLine": true,
10+
"singleAttributePerLine": true,
11+
"printWidth": 120
12+
}

0 commit comments

Comments
 (0)