@uniswap/token-list-bridge-utils 1.3.3 → 2.1.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,18 +17,22 @@ import Web3 from 'web3'
17
17
  import {
18
18
  GenericMappedTokenData,
19
19
  PolygonMappedTokenData,
20
- BnbMappedTokenData,
21
- BnbMappedToken,
20
+ MappedTokenData,
21
+ MappedToken,
22
22
  } from '../constants/types'
23
+ import { AvalancheMappingProvider } from './AvalancheMappingProvider'
24
+ import { BaseGoerliMappingProvider } from './BaseGoerliMappingProvider'
23
25
 
24
26
  const web3 = new Web3()
25
27
 
26
28
  // chains we support fetching mappings for (can be different than the l2ChainIds arg for buildList)
27
- const SUPPORTED_L2_CHAINS = [
29
+ const CHAINS_WITH_MAPPING_PROVIDERS = [
28
30
  ChainId.ARBITRUM_ONE,
29
31
  ChainId.POLYGON,
30
32
  ChainId.OPTIMISM,
31
33
  ChainId.BNB,
34
+ ChainId.AVALANCHE,
35
+ ChainId.BASE_GOERLI,
32
36
  ]
33
37
 
34
38
  export async function buildList(
@@ -146,6 +150,10 @@ function getMappingProvider(chainId: ChainId, l1TokenList: TokenList) {
146
150
  return new PolygonMappingProvider()
147
151
  case ChainId.BNB:
148
152
  return new BnbMappingProvider()
153
+ case ChainId.AVALANCHE:
154
+ return new AvalancheMappingProvider()
155
+ case ChainId.BASE_GOERLI:
156
+ return new BaseGoerliMappingProvider()
149
157
  default:
150
158
  throw new Error(`Chain ${chainId} not supported for fetching mappings.`)
151
159
  }
@@ -159,11 +167,11 @@ async function generateTokenMappings(
159
167
  [key: number]:
160
168
  | PolygonMappedTokenData
161
169
  | GenericMappedTokenData
162
- | BnbMappedTokenData
170
+ | MappedTokenData
163
171
  } = {}
164
172
 
165
173
  for (const chainId of chainIds) {
166
- if (SUPPORTED_L2_CHAINS.includes(chainId)) {
174
+ if (CHAINS_WITH_MAPPING_PROVIDERS.includes(chainId)) {
167
175
  chainIdToMappingsMap[chainId] = await getMappingProvider(
168
176
  chainId,
169
177
  l1TokenList
@@ -182,7 +190,7 @@ async function getChildTokenDetails(
182
190
  [key: number]:
183
191
  | PolygonMappedTokenData
184
192
  | GenericMappedTokenData
185
- | BnbMappedTokenData
193
+ | MappedTokenData
186
194
  }
187
195
  ): Promise<{
188
196
  childTokenValid: boolean
@@ -192,8 +200,11 @@ async function getChildTokenDetails(
192
200
  const existingMapping: undefined | string =
193
201
  l1Token?.extensions?.bridgeInfo?.[chainId]?.tokenAddress
194
202
  // use the externally fetched mappings if manual entry doesn't exist for the token/chain mapping
195
- // and the given L2 chain is supported for fetching mappings
196
- if (SUPPORTED_L2_CHAINS.includes(chainId) && existingMapping === undefined) {
203
+ // and the given chain is supported for fetching mappings
204
+ if (
205
+ CHAINS_WITH_MAPPING_PROVIDERS.includes(chainId) &&
206
+ existingMapping === undefined
207
+ ) {
197
208
  const childToken =
198
209
  chainIdToMappingsMap[chainId][l1Token.address.toLowerCase()]
199
210
 
@@ -207,8 +218,8 @@ async function getChildTokenDetails(
207
218
  (await hasExistingTokenContract(childTokenAddress, chainId))
208
219
  )
209
220
  const decimals =
210
- childToken && chainId === ChainId.BNB
211
- ? (childToken as BnbMappedToken).decimals
221
+ childToken && (chainId === ChainId.BNB || chainId === ChainId.AVALANCHE)
222
+ ? (childToken as MappedToken).decimals
212
223
  : undefined
213
224
 
214
225
  return {
package/src/utils.ts CHANGED
@@ -110,6 +110,10 @@ export function getRpcUrl(chainId: ChainId): string {
110
110
  return 'https://rpc-endpoints.superfluid.dev/mumbai'
111
111
  case ChainId.BNB:
112
112
  return 'https://bsc-dataseed1.binance.org'
113
+ case ChainId.AVALANCHE:
114
+ return 'https://api.avax.network/ext/bc/C/rpc'
115
+ case ChainId.BASE_GOERLI:
116
+ return 'https://goerli.base.org'
113
117
  default:
114
118
  }
115
119
  throw new Error('Unsupported ChainId')
package/src/.DS_Store DELETED
Binary file
package/src/.env DELETED
File without changes