@uniswap/token-list-bridge-utils 1.3.2 → 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.
- package/README.md +1 -1
- package/dist/constants/chainId.d.ts +2 -1
- package/dist/constants/tokens.d.ts +1 -0
- package/dist/constants/types.d.ts +3 -3
- package/dist/fixtures/index.d.ts +9 -0
- package/dist/providers/AvalancheMappingProvider.d.ts +5 -0
- package/dist/providers/BnbMappingProvider.d.ts +2 -2
- package/dist/providers/MappingProvider.d.ts +2 -2
- package/dist/token-list-bridge-utils.cjs.development.js +624 -9
- 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 +624 -9
- package/dist/token-list-bridge-utils.esm.js.map +1 -1
- package/package.json +1 -1
- package/src/arbitrum/set_rpc.ts +1 -1
- package/src/constants/chainId.ts +2 -0
- package/src/constants/tokens.ts +8 -0
- package/src/constants/types.ts +2 -2
- package/src/fixtures/index.ts +31 -0
- package/src/index.test.ts +36 -0
- package/src/index.ts +1 -0
- package/src/local_mappings/avax.json +574 -0
- package/src/providers/AvalancheMappingProvider.ts +11 -0
- package/src/providers/BnbMappingProvider.ts +4 -4
- package/src/providers/MappingProvider.ts +2 -2
- package/src/providers/index.ts +17 -10
- package/src/utils.ts +3 -1
- package/src/.DS_Store +0 -0
- package/src/.env +0 -0
package/src/providers/index.ts
CHANGED
|
@@ -17,18 +17,20 @@ import Web3 from 'web3'
|
|
|
17
17
|
import {
|
|
18
18
|
GenericMappedTokenData,
|
|
19
19
|
PolygonMappedTokenData,
|
|
20
|
-
|
|
21
|
-
|
|
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
|
|
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
|
-
|
|
|
166
|
+
| MappedTokenData
|
|
163
167
|
} = {}
|
|
164
168
|
|
|
165
169
|
for (const chainId of chainIds) {
|
|
166
|
-
if (
|
|
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
|
-
|
|
|
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
|
|
196
|
-
if (
|
|
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
|
|
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
|
@@ -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://
|
|
98
|
+
return 'https://rpc.ankr.com/eth'
|
|
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:
|
|
@@ -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
|