@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.
- package/dist/constants/chainId.d.ts +1 -1
- package/dist/constants/tokens.d.ts +2 -2
- package/dist/constants/types.d.ts +30 -0
- package/dist/fixtures/index.d.ts +0 -12
- package/dist/providers/PolygonMappingProvider.d.ts +0 -2
- package/dist/providers/UnichainMappingProvider.d.ts +5 -0
- package/dist/token-list-bridge-utils.cjs.development.js +1511 -332
- package/dist/token-list-bridge-utils.cjs.development.js.map +1 -1
- package/dist/token-list-bridge-utils.cjs.production.min.js +1 -1
- package/dist/token-list-bridge-utils.cjs.production.min.js.map +1 -1
- package/dist/token-list-bridge-utils.esm.js +1511 -332
- package/dist/token-list-bridge-utils.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/constants/chainId.ts +2 -1
- package/src/constants/tokens.ts +11 -11
- package/src/constants/types.ts +30 -0
- package/src/fixtures/index.ts +8 -36
- package/src/index.test.ts +21 -40
- package/src/index.ts +1 -1
- package/src/local_mappings/unichain.json +1194 -0
- package/src/providers/BaseMappingProvider.ts +2 -2
- package/src/providers/PolygonMappingProvider.ts +20 -12
- package/src/providers/UnichainMappingProvider.ts +11 -0
- package/src/providers/index.ts +7 -5
- package/src/utils.ts +1 -3
- package/dist/providers/BaseGoerliMappingProvider.d.ts +0 -9
- package/src/providers/BaseGoerliMappingProvider.ts +0 -43
|
@@ -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
|
|
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(
|
|
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 {
|
|
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/
|
|
8
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
+
}
|
package/src/providers/index.ts
CHANGED
|
@@ -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.
|
|
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.
|
|
164
|
-
return new
|
|
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
|
-
(
|
|
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.
|
|
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
|
-
}
|