@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.
- package/dist/constants/chainId.d.ts +3 -1
- package/dist/constants/tokens.d.ts +4 -0
- package/dist/constants/types.d.ts +3 -3
- package/dist/fixtures/index.d.ts +40 -0
- package/dist/providers/AvalancheMappingProvider.d.ts +5 -0
- package/dist/providers/BaseGoerliMappingProvider.d.ts +9 -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 +706 -12
- 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 +706 -12
- package/dist/token-list-bridge-utils.esm.js.map +1 -1
- package/package.json +3 -3
- package/src/constants/chainId.ts +4 -0
- package/src/constants/tokens.ts +32 -0
- package/src/constants/types.ts +2 -2
- package/src/fixtures/index.ts +82 -0
- package/src/index.test.ts +189 -0
- package/src/index.ts +11 -1
- package/src/local_mappings/avax.json +574 -0
- package/src/providers/AvalancheMappingProvider.ts +11 -0
- package/src/providers/BaseGoerliMappingProvider.ts +43 -0
- package/src/providers/BnbMappingProvider.ts +4 -4
- package/src/providers/MappingProvider.ts +2 -2
- package/src/providers/index.ts +21 -10
- package/src/utils.ts +4 -0
- package/src/.DS_Store +0 -0
- package/src/.env +0 -0
package/src/providers/index.ts
CHANGED
|
@@ -17,18 +17,22 @@ 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'
|
|
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
|
|
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
|
-
|
|
|
170
|
+
| MappedTokenData
|
|
163
171
|
} = {}
|
|
164
172
|
|
|
165
173
|
for (const chainId of chainIds) {
|
|
166
|
-
if (
|
|
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
|
-
|
|
|
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
|
|
196
|
-
if (
|
|
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
|
|
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
|