-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.ts
67 lines (58 loc) · 1.57 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
import arbitrum from './arbitrum/tokenlist.json'
import avalanche from './avalanche/tokenlist.json'
import bsc from './bsc/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 optimism from './optimism/tokenlist.json'
import polygon from './polygon/tokenlist.json'
export interface Token {
address: string
name: string
symbol: string
decimals: number
coingeckoId: string | null
wallet: boolean
stable: boolean
native?: boolean
}
export interface ChainToken extends Token {
chain: string
}
export type ChainTokenRegistry = { [key: string]: ChainToken }
export const chains = {
arbitrum,
avalanche,
bsc,
celo,
ethereum,
fantom,
gnosis,
harmony,
optimism,
polygon
} satisfies { [chain: string]: Token[] }
export type Chain = keyof typeof chains
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
* @param address lowercase hex string. ex: "0x0000000000000000000000000000000000000000"
*/
export function getToken(
chain: string,
address: string = '0x0000000000000000000000000000000000000000'
) {
if (!registries[chain]) {
console.error(`Chain '${chain}' not supported yet`)
return
}
return registries[chain][address]
}