@uniswap/token-list-bridge-utils 1.3.3 → 2.0.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,20 @@ 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'
23
24
 
24
25
  const web3 = new Web3()
25
26
 
26
27
  // chains we support fetching mappings for (can be different than the l2ChainIds arg for buildList)
27
- const SUPPORTED_L2_CHAINS = [
28
+ const CHAINS_WITH_MAPPING_PROVIDERS = [
28
29
  ChainId.ARBITRUM_ONE,
29
30
  ChainId.POLYGON,
30
31
  ChainId.OPTIMISM,
31
32
  ChainId.BNB,
33
+ ChainId.AVALANCHE,
32
34
  ]
33
35
 
34
36
  export async function buildList(
@@ -146,6 +148,8 @@ function getMappingProvider(chainId: ChainId, l1TokenList: TokenList) {
146
148
  return new PolygonMappingProvider()
147
149
  case ChainId.BNB:
148
150
  return new BnbMappingProvider()
151
+ case ChainId.AVALANCHE:
152
+ return new AvalancheMappingProvider()
149
153
  default:
150
154
  throw new Error(`Chain ${chainId} not supported for fetching mappings.`)
151
155
  }
@@ -159,11 +163,11 @@ async function generateTokenMappings(
159
163
  [key: number]:
160
164
  | PolygonMappedTokenData
161
165
  | GenericMappedTokenData
162
- | BnbMappedTokenData
166
+ | MappedTokenData
163
167
  } = {}
164
168
 
165
169
  for (const chainId of chainIds) {
166
- if (SUPPORTED_L2_CHAINS.includes(chainId)) {
170
+ if (CHAINS_WITH_MAPPING_PROVIDERS.includes(chainId)) {
167
171
  chainIdToMappingsMap[chainId] = await getMappingProvider(
168
172
  chainId,
169
173
  l1TokenList
@@ -182,7 +186,7 @@ async function getChildTokenDetails(
182
186
  [key: number]:
183
187
  | PolygonMappedTokenData
184
188
  | GenericMappedTokenData
185
- | BnbMappedTokenData
189
+ | MappedTokenData
186
190
  }
187
191
  ): Promise<{
188
192
  childTokenValid: boolean
@@ -192,8 +196,11 @@ async function getChildTokenDetails(
192
196
  const existingMapping: undefined | string =
193
197
  l1Token?.extensions?.bridgeInfo?.[chainId]?.tokenAddress
194
198
  // 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) {
199
+ // and the given chain is supported for fetching mappings
200
+ if (
201
+ CHAINS_WITH_MAPPING_PROVIDERS.includes(chainId) &&
202
+ existingMapping === undefined
203
+ ) {
197
204
  const childToken =
198
205
  chainIdToMappingsMap[chainId][l1Token.address.toLowerCase()]
199
206
 
@@ -207,8 +214,8 @@ async function getChildTokenDetails(
207
214
  (await hasExistingTokenContract(childTokenAddress, chainId))
208
215
  )
209
216
  const decimals =
210
- childToken && chainId === ChainId.BNB
211
- ? (childToken as BnbMappedToken).decimals
217
+ childToken && (chainId === ChainId.BNB || chainId === ChainId.AVALANCHE)
218
+ ? (childToken as MappedToken).decimals
212
219
  : undefined
213
220
 
214
221
  return {
package/src/utils.ts CHANGED
@@ -110,6 +110,8 @@ 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'
113
115
  default:
114
116
  }
115
117
  throw new Error('Unsupported ChainId')
package/src/.DS_Store DELETED
Binary file
package/src/.env DELETED
File without changes