@uniswap/token-list-bridge-utils 2.2.0 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -17,6 +17,7 @@ import {
17
17
  DAI_BASE_GOERLI,
18
18
  COINBASE_WRAPPED_STAKED_ETH_OPTIMISM,
19
19
  DAI_BASE,
20
+ USDT_CELO,
20
21
  } from '../constants/tokens'
21
22
  import { compareTokenInfos } from '../utils'
22
23
 
@@ -60,6 +61,9 @@ export const Tokens: Partial<Record<ChainId, Record<string, TokenInfo>>> = {
60
61
  COINBASE_WRAPPED_STAKED_ETH_BASE_GOERLI
61
62
  ),
62
63
  },
64
+ [ChainId.CELO]: {
65
+ USDT: tokenToTokenInfo(USDT_CELO),
66
+ },
63
67
  }
64
68
 
65
69
  export const sampleL1TokenList: TokenList = {
@@ -236,6 +240,33 @@ export const bnbedSampleTokenList_2 = {
236
240
  ].sort(compareTokenInfos),
237
241
  }
238
242
 
243
+ export const celoedSampleTokenList = {
244
+ ...sampleL1TokenList_2,
245
+ name: 'Celo Sample',
246
+ tokens: [
247
+ {
248
+ ...Tokens[ChainId.CELO]!.USDT,
249
+ extensions: {
250
+ bridgeInfo: {
251
+ [ChainId.MAINNET]: {
252
+ tokenAddress: USDT.address,
253
+ },
254
+ },
255
+ },
256
+ } as unknown as TokenInfo,
257
+ {
258
+ ...(Tokens[ChainId.MAINNET]!.USDT as unknown as TokenInfo),
259
+ extensions: {
260
+ bridgeInfo: {
261
+ [ChainId.CELO]: {
262
+ tokenAddress: USDT_CELO.address,
263
+ },
264
+ },
265
+ },
266
+ } as unknown as TokenInfo,
267
+ ].sort(compareTokenInfos),
268
+ }
269
+
239
270
  export const baseGoerliSampleTokenList_3 = {
240
271
  ...sampleL1TokenList_3,
241
272
  name: 'Base Goerli Sample_3',
package/src/index.test.ts CHANGED
@@ -29,6 +29,7 @@ import {
29
29
  sampleL1TokenList_3,
30
30
  baseGoerliSampleTokenList_3,
31
31
  baseSampleTokenList_3,
32
+ celoedSampleTokenList,
32
33
  } from './fixtures'
33
34
 
34
35
  jest.setTimeout(15000)
@@ -130,6 +131,22 @@ it('outputs bnb list correctly', async () => {
130
131
  )
131
132
  })
132
133
 
134
+ it('outputs celo list correctly', async () => {
135
+ const tokenList = await chainifyTokenList([ChainId.CELO], sampleL1TokenList_2)
136
+ expect(tokenList).toBeDefined()
137
+ expect(tokenList?.version).toEqual(celoedSampleTokenList.version)
138
+ expect(
139
+ tokenList?.tokens.map((t) => [t.address, t.chainId, t.extensions])
140
+ ).toEqual(
141
+ // ignores other metadata
142
+ celoedSampleTokenList.tokens.map((t) => [
143
+ t.address,
144
+ t.chainId,
145
+ t.extensions,
146
+ ])
147
+ )
148
+ })
149
+
133
150
  it('outputs bnb list correctly with different decimals', async () => {
134
151
  const tokenList = await chainifyTokenList([ChainId.BNB], sampleL1TokenList_2)
135
152
  expect(tokenList).toBeDefined()
@@ -0,0 +1,19 @@
1
+ {
2
+ "0xdac17f958d2ee523a2206206994597c13d831ec7": {
3
+ "childToken": "0x617f3112bf5397D0467D315cC709EF968D9ba546",
4
+ "decimals": 18
5
+ },
6
+ "0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599": {
7
+ "childToken": "0xd71Ffd0940c920786eC4DbB5A12306669b5b81EF",
8
+ "decimals": 18
9
+ },
10
+ "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2": {
11
+ "childToken": "0xb829b68f57CC546dA7E5806A929e53bE32a4625D",
12
+ "decimals": 18
13
+ },
14
+ "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48": {
15
+ "childToken": "0x37f750B7cC259A2f741AF45294f6a16572CF5cAd",
16
+ "decimals": 6
17
+ }
18
+ }
19
+
@@ -0,0 +1,10 @@
1
+ import { MappingProvider } from './MappingProvider'
2
+ import { MappedTokenData } from '../constants/types'
3
+ import celoMappings from '../local_mappings/celo.json'
4
+
5
+ // barring a better external source, we use a local source of mappings for celo
6
+ export class CeloMappingProvider implements MappingProvider {
7
+ async provide(): Promise<MappedTokenData> {
8
+ return celoMappings as MappedTokenData
9
+ }
10
+ }
@@ -3,7 +3,8 @@ import { MappingProvider } from './MappingProvider'
3
3
  import { PolygonMappedTokenData } from '../constants/types'
4
4
 
5
5
  // called from https://mapper.polygon.technology
6
- const url = 'https://open-api.polygon.technology/api/v1/info/all-mappings'
6
+ const url =
7
+ 'https://api-polygon-tokens.polygon.technology/api/v1/info/all-mappings'
7
8
  const access_token = '504afd90-3228-4df9-9d88-9b4d70646101'
8
9
 
9
10
  /**
@@ -23,6 +23,7 @@ import {
23
23
  import { AvalancheMappingProvider } from './AvalancheMappingProvider'
24
24
  import { BaseGoerliMappingProvider } from './BaseGoerliMappingProvider'
25
25
  import { BaseMappingProvider } from './BaseMappingProvider'
26
+ import { CeloMappingProvider } from './CeloMappingProvider'
26
27
 
27
28
  const web3 = new Web3()
28
29
 
@@ -33,6 +34,7 @@ const CHAINS_WITH_MAPPING_PROVIDERS = [
33
34
  ChainId.OPTIMISM,
34
35
  ChainId.BNB,
35
36
  ChainId.AVALANCHE,
37
+ ChainId.CELO,
36
38
  ChainId.BASE,
37
39
  ChainId.BASE_GOERLI,
38
40
  ]
@@ -154,6 +156,8 @@ function getMappingProvider(chainId: ChainId, l1TokenList: TokenList) {
154
156
  return new BnbMappingProvider()
155
157
  case ChainId.AVALANCHE:
156
158
  return new AvalancheMappingProvider()
159
+ case ChainId.CELO:
160
+ return new CeloMappingProvider()
157
161
  case ChainId.BASE:
158
162
  return new BaseMappingProvider()
159
163
  case ChainId.BASE_GOERLI:
@@ -228,7 +232,10 @@ async function getChildTokenDetails(
228
232
  (await hasExistingTokenContract(childTokenAddress, chainId))
229
233
  )
230
234
  const decimals =
231
- childToken && (chainId === ChainId.BNB || chainId === ChainId.AVALANCHE)
235
+ childToken &&
236
+ (chainId === ChainId.BNB ||
237
+ chainId === ChainId.AVALANCHE ||
238
+ chainId === ChainId.CELO)
232
239
  ? (childToken as MappedToken).decimals
233
240
  : undefined
234
241
  return {
package/src/utils.ts CHANGED
@@ -95,7 +95,7 @@ export const isTokenList = (obj: any) => {
95
95
  export function getRpcUrl(chainId: ChainId): string {
96
96
  switch (chainId) {
97
97
  case ChainId.MAINNET:
98
- return 'https://rpc.ankr.com/eth'
98
+ return 'https://ethereum-rpc.publicnode.com'
99
99
  case ChainId.OPTIMISM:
100
100
  return 'https://rpc.ankr.com/optimism' // seems to have higher rate limit than https://mainnet.optimism.io/
101
101
  case ChainId.OPTIMISTIC_KOVAN:
@@ -112,6 +112,10 @@ export function getRpcUrl(chainId: ChainId): string {
112
112
  return 'https://bsc-dataseed1.binance.org'
113
113
  case ChainId.AVALANCHE:
114
114
  return 'https://api.avax.network/ext/bc/C/rpc'
115
+ case ChainId.CELO:
116
+ return 'https://forno.celo.org/'
117
+ case ChainId.CELO_ALFAJORES:
118
+ return 'https://alfajores-forno.celo-testnet.org/'
115
119
  case ChainId.BASE:
116
120
  return 'https://mainnet.base.org'
117
121
  case ChainId.BASE_GOERLI: