forked from solflare-wallet/token-list
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerate.task.js
107 lines (95 loc) · 2.82 KB
/
generate.task.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
const {
Generator,
ProviderCoinGecko,
ProviderLegacyToken,
Tag,
ChainId,
} = require('@solflare-wallet/utl-aggregator')
const { CronJob } = require('cron')
const fs = require('fs')
async function handle(fileName = null) {
console.log(`${name} | start | ${new Date().toISOString()}`)
const coinGeckoApiKey = process.env.COINGECKO_API_KEY ?? null
const rpcUrlMainnet = process.env.RPC_URL_MAINNET
const rpcUrlDevnet = process.env.RPC_URL_DEVNET
const baseTokenListCdnUrl = process.env.TOKEN_LIST_CDN_URL
// Can be used to clear cache
// ProviderLegacyToken.clearCache(ChainId.MAINNET)
// ProviderLegacyToken.clearCache(ChainId.DEVNET)
const generator = new Generator([
new ProviderCoinGecko(coinGeckoApiKey, rpcUrlMainnet, {
throttle: 200,
throttleCoinGecko: 65 * 1000,
batchAccountsInfo: 200, // 1000
batchCoinGecko: 2, // 400
}),
new ProviderLegacyToken(
baseTokenListCdnUrl,
rpcUrlMainnet,
{
throttle: 2000,
batchAccountsInfo: 200, // 1000
batchSignatures: 200, // 250
batchTokenHolders: 1, // 4
},
[Tag.LP_TOKEN],
ChainId.MAINNET
),
new ProviderLegacyToken(
baseTokenListCdnUrl,
rpcUrlDevnet,
{
throttle: 2000,
batchAccountsInfo: 1000, // 1000
batchSignatures: 250, // 250
batchTokenHolders: 1, // 4
},
[Tag.LP_TOKEN],
ChainId.DEVNET,
60,
20
),
])
const tokenMap = await generator.generateTokenList()
console.log(`${name} | generated | ${new Date().toISOString()}`)
if (fileName) {
fs.writeFile(
`./${fileName}`,
JSON.stringify(tokenMap),
'utf8',
function (err) {
if (err) {
return console.log(`${name} | file errored`, err)
}
console.log(`${name} | file saved`)
}
)
} else {
console.log(`${name} | returned`)
return tokenMap
}
}
/* istanbul ignore next */
const cronJob = () =>
new CronJob(
process.env.CRON_TIME ?? '0 0 */4 * * *',
async () => {
if (inProgress) {
return
}
inProgress = true
try {
await handle('solana-tokenlist.json')
} catch (err) {
console.log(`${name} | errored`, err)
} finally {
inProgress = false
}
},
null,
true,
'UTC'
)
const name = 'generate-utl'
let inProgress = false
module.exports = { handle, cronJob }