-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
98 lines (84 loc) · 2.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
const axios = require("axios");
const { writeFileSync, existsSync, mkdirSync, readFileSync } = require("fs");
const path = require("path");
const { exec } = require("child_process");
const { LCDClient } = require("@terra-money/terra.js");
const { readDenom, isDenomTerra } = require("@terra.kitchen/utils");
const blacklist = JSON.parse(
readFileSync(path.join(__dirname, "output", "delisted-token.json"), {
encoding: "utf8",
flag: "r",
})
);
const configs = JSON.parse(
readFileSync(path.join(__dirname, "output", "chain.json"), {
encoding: "utf8",
flag: "r",
})
);
function main() {
const init = async (config) => {
console.log("Init");
const terraAssetList = await getTerraAsset(config.name);
const mergedTokens = terraAssetList.sort(compareVerified);
const fileName = `${config.name}-token.json`;
const outdir = path.join(__dirname, "output");
const filePath = path.join(outdir, fileName);
if (!existsSync(outdir)) {
mkdirSync(outdir);
}
writeFileSync(filePath, "");
const whitelists = mergedTokens.filter((v) => {
return (
!blacklist.includes(v.token) &&
!blacklist.includes(v.contract_addr) &&
v.name != "TEST DONOT BUY" &&
v.name != "Token test dont buy" &&
v.name != "test dont buy 100" &&
v.verified
);
});
writeFileSync(filePath, JSON.stringify(whitelists));
return true;
};
const commit = () => {
console.log("Add file");
exec("git add .", () => {
console.log("Commit");
exec('git commit -m "Commit token list"', () => {
console.log("push");
exec("git push origin main", () => {
console.log("done");
});
});
});
};
return {
init,
commit,
};
}
function compareVerified(a, b) {
if (a.symbol < b.symbol) {
return -1;
}
if (a.symbol > b.symbol) {
return 1;
}
return 0;
}
async function getTerraAsset() {
const terraAssetListUrl = "https://api.terraswap.io/tokens";
const terraAssetList = await axios.default.get(terraAssetListUrl);
const tokens = terraAssetList.data;
return tokens;
}
const run = async () => {
const _main = main();
for (let index = 0; index < configs.length; index++) {
const config = configs[index];
await _main.init(config);
}
_main.commit();
};
run();