forked from llamafolio/llamafolio-tokens
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
94 lines (85 loc) · 2.26 KB
/
index.ts
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
import arbitrum from './arbitrum/tokenlist.json'
import arbitrumNova from './arbitrum-nova/tokenlist.json'
import avalanche from './avalanche/tokenlist.json'
import bsc from './bsc/tokenlist.json'
import base from './base/tokenlist.json'
import celo from './celo/tokenlist.json'
import ethereum from './ethereum/tokenlist.json'
import fantom from './fantom/tokenlist.json'
import gnosis from './gnosis/tokenlist.json'
import harmony from './harmony/tokenlist.json'
import linea from './linea/tokenlist.json'
import moonbeam from './moonbeam/tokenlist.json'
import opbnb from './opbnb/tokenlist.json'
import optimism from './optimism/tokenlist.json'
import polygon from './polygon/tokenlist.json'
import polygonZkevm from './polygon-zkevm/tokenlist.json'
import zksyncEra from './zksync-era/tokenlist.json'
export interface Token {
address: string
name: string
symbol: string
decimals: number
stable: boolean
}
export interface ChainToken extends Token {
chain: string
}
export type ChainTokenRegistry = { [key: string]: ChainToken }
export const chainNames = [
'arbitrum',
'arbitrum-nova',
'avalanche',
'bsc',
'base',
'celo',
'ethereum',
'fantom',
'gnosis',
'harmony',
'linea',
'moonbeam',
'opbnb',
'optimism',
'polygon',
'polygon-zkevm',
'zksync-era'
] as const
export type Chain = (typeof chainNames)[number]
export const chains: { [chain in Chain]: Token[] } = {
arbitrum,
'arbitrum-nova': arbitrumNova,
avalanche,
bsc,
base,
celo,
ethereum,
fantom,
gnosis,
harmony,
linea,
moonbeam,
opbnb,
optimism,
polygon,
'polygon-zkevm': polygonZkevm,
'zksync-era': zksyncEra
}
const registries: { [chain: string]: ChainTokenRegistry } = {}
for (const chain in chains) {
const registry: ChainTokenRegistry = (registries[chain] = {})
for (const token of chains[chain as Chain]) {
registry[token.address] = { ...token, chain }
}
}
/**
* @param {Chain} chain name. ex: "ethereum"
* @param {string} address lowercase hex string. ex: "0x0000000000000000000000000000000000000000"
*/
export function getToken(chain: Chain, address: string = '0x0000000000000000000000000000000000000000') {
if (!registries[chain]) {
console.error(`Chain '${chain}' not supported yet`)
return
}
return registries[chain][address]
}