forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 0
/
createTokens.js
94 lines (89 loc) · 2.17 KB
/
createTokens.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
const fs = require('fs');
const Web3 = require('web3');
const { timer, print } = require('./utils');
const utils = Web3.utils;
const notInListPath = './notinlist.json';
const notInList = JSON.parse(fs.readFileSync(notInListPath));
const networks = {
eth: 'ethTokens.json',
matic: 'maticTokens.json',
bsc: 'bscTokens.json'
};
const cache = {};
let tokenCount = 0;
function createToken(obj) {
if (!cache.eth) {
console.log('Caching tokens');
let nets = ['eth', 'matic', 'bsc'];
nets.forEach(network => {
const tokens = JSON.parse(fs.readFileSync(networks[network]));
tokens.forEach(token => {
const address = utils.toChecksumAddress(token.address);
cache[network] = {
[address]: token,
...cache[network]
};
});
console.log('%s cashed', network);
});
}
const address = utils.toChecksumAddress(obj.address);
const token = cache[obj.network][address];
if (token) {
const tokenTemp = {
symbol: '',
name: '',
type: 'ERC20',
address: '',
ens_address: '',
decimals: 0,
website: '',
logo: {
src: '',
width: '',
height: '',
ipfs_hash: ''
},
support: {
email: '',
url: ''
},
social: {
blog: '',
chat: '',
discord: '',
facebook: '',
forum: '',
github: '',
gitter: '',
instagram: '',
linkedin: '',
reddit: '',
slack: '',
telegram: '',
twitter: '',
youtube: ''
}
};
const newTokenCopy = Object.assign({}, tokenTemp, {
symbol: token.symbol,
name: token.name,
address: utils.toChecksumAddress(obj.address),
decimals: token.decimals
});
fs.writeFileSync(
`./src/tokens/${obj.network}/${utils.toChecksumAddress(
obj.address
)}.json`,
print(newTokenCopy),
{ encoding: 'utf-8' }
);
console.log(`Successfully created: ${obj.address} in ${obj.network}`);
tokenCount++;
}
}
function parseTokens() {
notInList.forEach(i => createToken(i));
console.log('%s tokens processed', tokenCount);
}
timer(parseTokens);