@uniswap/token-list-bridge-utils 2.3.0 → 2.6.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.
@@ -3,7 +3,7 @@ import { ChainId } from '../constants/chainId'
3
3
  import { getTokenList } from '../utils'
4
4
  import { GenericMappedTokenData } from '../constants/types'
5
5
 
6
- const baseGoerliTokenListURL =
6
+ const baseTokenListURL =
7
7
  'https://raw.githubusercontent.com/' +
8
8
  'ethereum-optimism/ethereum-optimism.github.io/master/optimism.tokenlist.json'
9
9
 
@@ -15,7 +15,7 @@ export class BaseMappingProvider implements MappingProvider {
15
15
  async provide(): Promise<GenericMappedTokenData> {
16
16
  const tokens: { [key: string]: string | undefined } = {}
17
17
 
18
- let allTokens = await getTokenList(baseGoerliTokenListURL)
18
+ let allTokens = await getTokenList(baseTokenListURL)
19
19
 
20
20
  let opTokenId_baseAddressMap: Record<string, string> = {}
21
21
  allTokens.tokens.forEach((token) => {
@@ -1,28 +1,36 @@
1
1
  import axios from 'axios'
2
2
  import { MappingProvider } from './MappingProvider'
3
- import { PolygonMappedTokenData } from '../constants/types'
3
+ import {
4
+ PolygonMappedTokenData,
5
+ PolygonTokenListResponse,
6
+ PolygonWrappedToken,
7
+ } from '../constants/types'
4
8
 
5
- // called from https://mapper.polygon.technology
6
9
  const url =
7
- 'https://api-polygon-tokens.polygon.technology/api/v1/info/all-mappings'
8
- const access_token = '504afd90-3228-4df9-9d88-9b4d70646101'
10
+ 'https://api-polygon-tokens.polygon.technology/tokenlists/mapped.tokenlist.json'
11
+
12
+ const POS_BRIDGE_TAG = 'pos'
9
13
 
10
14
  /**
11
- * The Polygon team manually maintains the mapping via user submissions at
12
- * https://mapper.polygon.technology.
13
15
  *
14
16
  * This provider provides the l1->l2(Polygon) token mappings.
15
17
  */
16
18
  export class PolygonMappingProvider implements MappingProvider {
17
19
  async provide(): Promise<PolygonMappedTokenData> {
18
- const response = await axios.get(url, {
19
- headers: { 'x-access-token': access_token },
20
- })
20
+ const response = await axios.get<PolygonTokenListResponse>(url)
21
21
  const tokens: PolygonMappedTokenData = {}
22
22
 
23
- for (const token of response.data) {
24
- if (token.isPos) {
25
- tokens[token.rootToken.toLowerCase()] = token
23
+ for (const token of response.data.tokens) {
24
+ const posToken = token.wrappedTokens.find(
25
+ (wrapped: PolygonWrappedToken) => wrapped.tags.includes(POS_BRIDGE_TAG)
26
+ )
27
+
28
+ if (posToken) {
29
+ tokens[token.originTokenAddress.toLowerCase()] = {
30
+ rootToken: token.originTokenAddress,
31
+ childToken: posToken.wrappedTokenAddress,
32
+ isPos: true,
33
+ }
26
34
  }
27
35
  }
28
36
  return tokens
@@ -0,0 +1,11 @@
1
+ import { MappingProvider } from './MappingProvider'
2
+ import { MappedTokenData } from '../constants/types'
3
+ import unichainMappings from '../local_mappings/unichain.json'
4
+
5
+ // we use a local source of mappings for unichain
6
+ export class UnichainMappingProvider implements MappingProvider {
7
+ async provide(): Promise<MappedTokenData> {
8
+ const tokens = unichainMappings as MappedTokenData
9
+ return tokens
10
+ }
11
+ }
@@ -4,6 +4,7 @@ import { ArbitrumMappingProvider } from './ArbitrumMappingProvider'
4
4
  import { OptimismMappingProvider } from './OptimismMappingProvider'
5
5
  import { PolygonMappingProvider } from './PolygonMappingProvider'
6
6
  import { BnbMappingProvider } from './BnbMappingProvider'
7
+ import { UnichainMappingProvider } from './UnichainMappingProvider'
7
8
  import { TokenInfo, TokenList } from '@uniswap/token-lists'
8
9
  import { ethers } from 'ethers'
9
10
  import {
@@ -21,7 +22,6 @@ import {
21
22
  MappedToken,
22
23
  } from '../constants/types'
23
24
  import { AvalancheMappingProvider } from './AvalancheMappingProvider'
24
- import { BaseGoerliMappingProvider } from './BaseGoerliMappingProvider'
25
25
  import { BaseMappingProvider } from './BaseMappingProvider'
26
26
  import { CeloMappingProvider } from './CeloMappingProvider'
27
27
 
@@ -36,7 +36,7 @@ const CHAINS_WITH_MAPPING_PROVIDERS = [
36
36
  ChainId.AVALANCHE,
37
37
  ChainId.CELO,
38
38
  ChainId.BASE,
39
- ChainId.BASE_GOERLI,
39
+ ChainId.UNICHAIN,
40
40
  ]
41
41
 
42
42
  export async function buildList(
@@ -160,8 +160,8 @@ function getMappingProvider(chainId: ChainId, l1TokenList: TokenList) {
160
160
  return new CeloMappingProvider()
161
161
  case ChainId.BASE:
162
162
  return new BaseMappingProvider()
163
- case ChainId.BASE_GOERLI:
164
- return new BaseGoerliMappingProvider()
163
+ case ChainId.UNICHAIN:
164
+ return new UnichainMappingProvider()
165
165
  default:
166
166
  throw new Error(`Chain ${chainId} not supported for fetching mappings.`)
167
167
  }
@@ -229,7 +229,9 @@ async function getChildTokenDetails(
229
229
  : undefined
230
230
  const childTokenValid = Boolean(
231
231
  childTokenAddress &&
232
- (await hasExistingTokenContract(childTokenAddress, chainId))
232
+ (chainId === ChainId.UNICHAIN // barring a unichain rpc url, we skip the contract call. Since we're using a manually curated list of tokens, we can assume they exist.
233
+ ? true
234
+ : await hasExistingTokenContract(childTokenAddress, chainId))
233
235
  )
234
236
  const decimals =
235
237
  childToken &&
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:
@@ -118,8 +118,6 @@ export function getRpcUrl(chainId: ChainId): string {
118
118
  return 'https://alfajores-forno.celo-testnet.org/'
119
119
  case ChainId.BASE:
120
120
  return 'https://mainnet.base.org'
121
- case ChainId.BASE_GOERLI:
122
- return 'https://goerli.base.org'
123
121
  default:
124
122
  }
125
123
  throw new Error('Unsupported ChainId')
@@ -1,9 +0,0 @@
1
- import { MappingProvider } from './MappingProvider';
2
- import { GenericMappedTokenData } from '../constants/types';
3
- /**
4
- * The Base Goerli mapping (linked above) is manually maintained by the Coinbase team
5
- * in this repository: https://github.com/ethereum-optimism/ethereum-optimism.github.io.
6
- */
7
- export declare class BaseGoerliMappingProvider implements MappingProvider {
8
- provide(): Promise<GenericMappedTokenData>;
9
- }
@@ -1,43 +0,0 @@
1
- import { MappingProvider } from './MappingProvider'
2
- import { ChainId } from '../constants/chainId'
3
- import { getTokenList } from '../utils'
4
- import { GenericMappedTokenData } from '../constants/types'
5
-
6
- const baseGoerliTokenListURL =
7
- 'https://raw.githubusercontent.com/' +
8
- 'ethereum-optimism/ethereum-optimism.github.io/master/optimism.tokenlist.json'
9
-
10
- /**
11
- * The Base Goerli mapping (linked above) is manually maintained by the Coinbase team
12
- * in this repository: https://github.com/ethereum-optimism/ethereum-optimism.github.io.
13
- */
14
- export class BaseGoerliMappingProvider implements MappingProvider {
15
- async provide(): Promise<GenericMappedTokenData> {
16
- const tokens: { [key: string]: string | undefined } = {}
17
-
18
- let allTokens = await getTokenList(baseGoerliTokenListURL)
19
-
20
- let opTokenId_baseGoerliAddressMap: Record<string, string> = {}
21
- allTokens.tokens.forEach((token) => {
22
- if (token.chainId === ChainId.BASE_GOERLI) {
23
- if (typeof token.extensions?.opTokenId === 'string') {
24
- opTokenId_baseGoerliAddressMap[token.extensions.opTokenId] =
25
- token.address
26
- }
27
- }
28
- })
29
-
30
- allTokens.tokens.forEach((token) => {
31
- if (
32
- token.chainId === ChainId.MAINNET &&
33
- typeof token.extensions?.opTokenId === 'string' &&
34
- token.extensions!.opTokenId in opTokenId_baseGoerliAddressMap
35
- ) {
36
- tokens[token.address.toLowerCase()] =
37
- opTokenId_baseGoerliAddressMap[token.extensions!.opTokenId]
38
- }
39
- })
40
-
41
- return tokens
42
- }
43
- }