Skip to content

Commit 49c6087

Browse files
committed
Make default list compatible with tokenlists.org
1 parent 5783022 commit 49c6087

2 files changed

Lines changed: 34 additions & 21 deletions

File tree

server/src/handlers/setup.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,17 @@ export async function setupDefaultTokens(c: Context) {
1818
const chains = await db.selectFrom('chains').select('id').execute()
1919

2020
const tokensOnChains = defaultTokens.filter((t) =>
21-
chains.some((c) => c.id === t.chain)
21+
chains.some((c) => c.id === t.chainId)
2222
)
2323

2424
await db
2525
.insertInto('tokens')
26-
.values(tokensOnChains)
26+
.values(
27+
tokensOnChains.map((t) => ({
28+
...t,
29+
chain: t.chainId,
30+
}))
31+
)
2732
.onConflict((oc) => oc.doNothing())
2833
.execute()
2934

server/src/tokens.ts

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,121 +1,129 @@
1-
import type { Insertable } from 'kysely'
1+
import type { Address } from 'viem'
22

33
import { defaultChains } from './chains'
4-
import type { Tables } from './db'
54

6-
export const defaultTokens: Insertable<Tables['tokens']>[] = [
5+
// Compatible with tokenlists.org so we can build an easy importing feature later
6+
type TokenlistToken = {
7+
chainId: number
8+
address: Address
9+
name: string
10+
symbol: string
11+
decimals: number
12+
}
13+
14+
export const defaultTokens: TokenlistToken[] = [
715
// Native ETH on all default chains
816
...defaultChains.map(
917
(chain) =>
1018
({
1119
address: '0x0000000000000000000000000000000000000000',
12-
chain: chain.id,
20+
chainId: chain.id,
1321
name: 'Ether',
1422
symbol: 'ETH',
1523
decimals: 18,
1624
}) as const
1725
),
1826
{
1927
address: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
20-
chain: 1,
28+
chainId: 1,
2129
name: 'Wrapped Ether',
2230
symbol: 'WETH',
2331
decimals: 18,
2432
},
2533
{
2634
address: '0x4200000000000000000000000000000000000006',
27-
chain: 8453,
35+
chainId: 8453,
2836
name: 'Wrapped Ether',
2937
symbol: 'WETH',
3038
decimals: 18,
3139
},
3240
{
3341
address: '0x4200000000000000000000000000000000000006',
34-
chain: 10,
42+
chainId: 10,
3543
name: 'Wrapped Ether',
3644
symbol: 'WETH',
3745
decimals: 18,
3846
},
3947
{
4048
address: '0x82aF49447D8a07e3bd95BD0d56f35241523fBab1',
41-
chain: 42161,
49+
chainId: 42161,
4250
name: 'Wrapped Ether',
4351
symbol: 'WETH',
4452
decimals: 18,
4553
},
4654
{
4755
address: '0xdAC17F958D2ee523a2206206994597C13D831ec7',
48-
chain: 1,
56+
chainId: 1,
4957
name: 'Tether',
5058
symbol: 'USDT',
5159
decimals: 18,
5260
},
5361
{
5462
address: '0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48',
55-
chain: 1,
63+
chainId: 1,
5664
name: 'USDC',
5765
symbol: 'USDC',
5866
decimals: 6,
5967
},
6068
{
6169
address: '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913',
62-
chain: 8453,
70+
chainId: 8453,
6371
name: 'USDC',
6472
symbol: 'USDC',
6573
decimals: 6,
6674
},
6775
{
6876
address: '0x514910771AF9Ca656af840dff83E8264EcF986CA',
69-
chain: 1,
77+
chainId: 1,
7078
name: 'Chainlink',
7179
symbol: 'LINK',
7280
decimals: 18,
7381
},
7482
{
7583
address: '0x6B175474E89094C44Da98b954EedeAC495271d0F',
76-
chain: 1,
84+
chainId: 1,
7785
name: 'Dai',
7886
symbol: 'DAI',
7987
decimals: 18,
8088
},
8189
{
8290
address: '0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984',
83-
chain: 1,
91+
chainId: 1,
8492
name: 'Uniswap',
8593
symbol: 'UNI',
8694
decimals: 18,
8795
},
8896
{
8997
address: '0x7Fc66500c84A76Ad7e9c93437bFc5Ac33E2DDaE9',
90-
chain: 1,
98+
chainId: 1,
9199
name: 'Aave',
92100
symbol: 'AAVE',
93101
decimals: 18,
94102
},
95103
{
96104
address: '0x912CE59144191C1204E64559FE8253a0e49E6548',
97-
chain: 42161,
105+
chainId: 42161,
98106
name: 'Arbitrum',
99107
symbol: 'ARB',
100108
decimals: 18,
101109
},
102110
{
103111
address: '0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2',
104-
chain: 1,
112+
chainId: 1,
105113
name: 'Maker',
106114
symbol: 'MKR',
107115
decimals: 18,
108116
},
109117
{
110118
address: '0x4200000000000000000000000000000000000042',
111-
chain: 10,
119+
chainId: 10,
112120
name: 'Optimism',
113121
symbol: 'OP',
114122
decimals: 18,
115123
},
116124
{
117125
address: '0xC18360217D8F7Ab5e7c516566761Ea12Ce7F9D72',
118-
chain: 1,
126+
chainId: 1,
119127
name: 'Ethereum Name Service',
120128
symbol: 'ENS',
121129
decimals: 18,

0 commit comments

Comments
 (0)