forked from MyEtherWallet/ethereum-lists
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgenerateMissingTokenListFromIcons.js
131 lines (126 loc) · 4.26 KB
/
generateMissingTokenListFromIcons.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
const ethIcons = './src/icons';
const web3 = require('web3');
const utils = web3.utils;
const fs = require('fs');
const bsc = 'https://tokens.coingecko.com/binance-smart-chain/all.json';
const matic = 'https://tokens.coingecko.com/polygon-pos/all.json';
const eth = 'https://tokens.coingecko.com/ethereum/all.json';
const fetch = require('node-fetch');
function fileProcessor(address, obj) {
const list = JSON.parse(
fs.readFileSync(
`./dist/tokens/${obj.network}/tokens-${obj.network}.json`,
'utf8'
)
);
const found = list.find(item => {
if (
address.substring(0, 2) === '0x' &&
address.length === 42 &&
utils.toChecksumAddress(item.address) === utils.toChecksumAddress(address)
) {
return item;
}
});
if (!found) {
console.log(`processed: ${address} in ${obj.network}`);
return obj;
}
}
function generateMissingToken() {
const icons = fs.readdirSync(ethIcons);
const exclusion = [
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-eth',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-bsc',
'0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-matic',
'0xef68e7c694f40c8202821edf525de3782458639f-eth',
'0x85e076361cc813a908ff672f9bad1541474402b2-eth', // TEL token migrated
'0xd4260e4Bfb354259F5e30279cb0D7F784Ea5f37A-eth', // contract getting included from icons
'0xacfc95585d80ab62f67a14c566c1b7a49fe91167-eth', // not erc tokens
'0x71850b7e9ee3f13ab46d67167341e4bdc905eef9-eth', // not erc tokens
'0x1C5b760F133220855340003B43cC9113EC494823-eth', // self destructed
'0xd4260e4Bfb354259F5e30279cb0D7F784Ea5f37A-eth', // ????
'0x1d350417d9787E000cc1b95d70E9536DcD91F373-bsc', // not in bsc
'0x5e3845a1d78db544613edbe43dc1ea497266d3b8-bsc' // not in bsc
];
const addressOnly = icons.map(icon => {
const idxOf = icon.indexOf('-0x');
const getAddr = icon.substring(idxOf + 1, icon.length);
const splitAddress = getAddr.split(/[^a-z0-9+]+/gi);
const noExtension = splitAddress[0];
const network = splitAddress[1];
// if (getAddr.length !== 42) {
// const actualAddress = getAddr.substring(getAddr.indexOf('0x'), 42);
// return { address: actualAddress, network: network };
// } else {
return {
address: noExtension,
network: network === 'png' || network === 'svg' ? null : ''
};
// }
});
const notInList = [];
addressOnly.forEach(obj => {
const addr = obj.address;
if (utils.isAddress(addr)) {
const inExclusionList = exclusion.find(item => {
const splitAddress = item.split(/[^a-z0-9+]+/gi);
return (
utils.toChecksumAddress(splitAddress[0]) ===
utils.toChecksumAddress(addr)
);
});
if (!inExclusionList) {
if (obj.network) {
const processedFile = fileProcessor(addr, obj);
if (processedFile) notInList.push(processedFile);
} else {
const attemptNetworks = ['eth', 'bsc', 'matic'];
attemptNetworks.forEach(item => {
const copyObj = Object.assign({}, obj, { network: item });
const processedFile = fileProcessor(addr, copyObj);
if (processedFile) notInList.push(processedFile);
});
}
}
} else {
console.log('errored:', obj.address);
}
});
fs.writeFileSync('notinlist.json', JSON.stringify(notInList));
fetch(bsc)
.then(res => {
return res.json();
})
.then(data => {
fs.writeFileSync('bscTokens.json', JSON.stringify(data.tokens));
console.log('Success on fetching data for bsc');
})
.catch(e => {
console.log('Error on fetching data for bsc');
});
fetch(matic)
.then(res => {
return res.json();
})
.then(data => {
fs.writeFileSync('maticTokens.json', JSON.stringify(data.tokens));
console.log('Success on fetching data for matic');
})
.catch(e => {
console.log('Error on fetching data for matic');
});
fetch(eth)
.then(res => {
return res.json();
})
.then(data => {
fs.writeFileSync('ethTokens.json', JSON.stringify(data.tokens));
console.log('Success on fetching data for eth');
})
.catch(e => {
console.log('Error on fetching data for eth');
});
}
generateMissingToken();