-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerateTokenList.js
More file actions
100 lines (86 loc) · 3.04 KB
/
Copy pathgenerateTokenList.js
File metadata and controls
100 lines (86 loc) · 3.04 KB
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
const fs = require('fs');
const axios = require('axios');
const path = require('path');
const { getFewTokenFromOriginalToken } = require("few-v2-sdk-multiple-network-9");
const { Token, ChainId } = require("few-sdk-core-multiple-network-6");
const { ethers } = require('ethers');
const dotenv = require("dotenv");
dotenv.config();
const SUPPORTED_CHAINS = [ChainId.MAINNET, ChainId.BASE, ChainId.BLAST];
const SUPPORTED_CHAINS_TOKENLIST_NAME = {
[ChainId.MAINNET]: 'uniswap',
// [ChainId.MAINNET]: 'ethereum',
[ChainId.BASE]: 'base',
[ChainId.BLAST]: 'blast',
}
const TOKENLIST_API_BASE = "https://tokens.coingecko.com";
function getTokenListUrl(tokenlistName) {
return `${TOKENLIST_API_BASE}/${tokenlistName}/all.json`;
}
// set API URL and local path
function getTokenListPath(tokenlistName) {
return path.join(__dirname, 'all', `${tokenlistName}.tokenlist.json`);
}
async function main() {
try {
// 1. get API data
for (const CHAIN_ID of SUPPORTED_CHAINS) {
const tokenlistName = SUPPORTED_CHAINS_TOKENLIST_NAME[CHAIN_ID];
const API_URL = getTokenListUrl(tokenlistName);
const TOKENLIST_PATH = getTokenListPath(tokenlistName);
const response = await axios.get(API_URL);
const allTokens = response.data || [];
// 2.filter chainId and logoURI
const tokens = allTokens.tokens.filter(token =>
token.chainId === CHAIN_ID &&
token.logoURI &&
token.logoURI.trim() !== ''
);
// 3. generate newTokens:in swapnetTokens but not in ringxTokens
const newTokens = tokens.map(t => {
const checksummedAddress = ethers.utils.getAddress(t.address);
const originalToken = new Token(
t.chainId,
checksummedAddress,
t.decimals,
t.symbol,
t.name
);
const fewToken = getFewTokenFromOriginalToken(originalToken, t.chainId);
return {
chainId: t.chainId,
address: checksummedAddress,
name: t.name,
symbol: t.symbol,
decimals: t.decimals,
logoURI: t.logoURI,
extensions: {
fewWrappedAddress: fewToken.address,
fewName: `Few Wrapped ${t.name}`.length > 42
? `Few Wrapped ${t.name}`.substring(0, 42)
: `Few Wrapped ${t.name}`,
fewSymbol: `fw${t.symbol}`
}
};
});
// print result
const result = {
name: allTokens.name,
logoURI: allTokens.logoURI,
keywords: allTokens.keywords,
timestamp: allTokens.timestamp,
version: allTokens.version,
tokens: newTokens,
};
console.log(`ChainId: ${CHAIN_ID}`);
console.log(JSON.stringify(result, null, 2));
// write file
fs.writeFileSync(TOKENLIST_PATH, JSON.stringify(result, null, 2));
console.log(`✅ Wrote ${result.tokens.length} new tokens to newTokens.${tokenlistName}.json`);
}
console.log('✅ All token lists processed successfully.');
} catch (error) {
console.error('❌ Error:', error.message);
}
}
main();