-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathgenerate-multichain-uniswap-standard-list.js
65 lines (57 loc) · 1.83 KB
/
generate-multichain-uniswap-standard-list.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
const fs = require('fs');
const path = require('path');
const contractMap = require('./buildindex.js');
const timestamp = new Date().toISOString();
function createUniswapTokenList() {
const tokens = Object.entries(contractMap)
.filter(([key]) => key.startsWith('eip155:'))
.map(([key, data]) => {
// Parse the CAIP-19 ID to extract chain and address information
// Expected format: eip155:1/erc20:0xAddress
const [chainPart, addressPart] = key.split('/');
const chainId = parseInt(chainPart.split(':')[1], 10);
const address = addressPart.split(':')[1];
let logoURI = '';
if (data.logo) {
const logoFileName = data.logo.split('/').pop();
logoURI = `https://raw.githubusercontent.com/MetaMask/contract-metadata/master/icons/${chainPart}/${addressPart}.${logoFileName.split('.').pop()}`;
}
return {
chainId,
address,
name: data.name || '',
symbol: data.symbol || '',
decimals: data.decimals || 18,
logoURI
};
});
// Create the token list structure according to Uniswap standard
const tokenList = {
name: "MetaMask Token List",
logoURI: "https://images.ctfassets.net/clixtyxoaeas/1ezuBGezqfIeifWdVtwU4c/d970d4cdf13b163efddddd5709164d2e/MetaMask-icon-Fox.svg",
keywords: [
"metamask",
],
timestamp,
tokens,
version: {
major: 1,
minor: 0,
patch: 0
}
};
return tokenList;
}
const tokenList = createUniswapTokenList();
const outputPath = path.join(__dirname, 'metamask-uniswap-tokenlist.json');
try {
fs.writeFileSync(
outputPath,
JSON.stringify(tokenList, null, 2),
'utf8'
);
console.log(`Successfully wrote MetaMask Uniswap token list to ${outputPath}`);
} catch (error) {
console.error('Error writing Uniswap token list:', error);
process.exit(1);
}