@uniswap/token-list-bridge-utils 2.1.0 → 2.3.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 +2 -0
- package/dist/constants/tokens.d.ts +5 -0
- package/dist/fixtures/index.d.ts +24 -0
- package/dist/providers/BaseMappingProvider.d.ts +9 -0
- package/dist/providers/CeloMappingProvider.d.ts +5 -0
- package/dist/token-list-bridge-utils.cjs.development.js +184 -44
- 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 +184 -44
- package/dist/token-list-bridge-utils.esm.js.map +1 -1
- package/package.json +13 -22
- package/src/arbitrum/instantiate_bridge.ts +10 -2
- package/src/constants/chainId.ts +3 -0
- package/src/constants/tokens.ts +41 -1
- package/src/fixtures/index.ts +73 -0
- package/src/index.test.ts +90 -85
- package/src/index.ts +6 -8
- package/src/local_mappings/celo.json +19 -0
- package/src/providers/BaseGoerliMappingProvider.ts +1 -1
- package/src/providers/BaseMappingProvider.ts +42 -0
- package/src/providers/CeloMappingProvider.ts +10 -0
- package/src/providers/OptimismMappingProvider.ts +19 -6
- package/src/providers/PolygonMappingProvider.ts +2 -1
- package/src/providers/index.ts +22 -6
- package/src/utils.ts +6 -0
package/src/providers/index.ts
CHANGED
|
@@ -22,6 +22,8 @@ import {
|
|
|
22
22
|
} from '../constants/types'
|
|
23
23
|
import { AvalancheMappingProvider } from './AvalancheMappingProvider'
|
|
24
24
|
import { BaseGoerliMappingProvider } from './BaseGoerliMappingProvider'
|
|
25
|
+
import { BaseMappingProvider } from './BaseMappingProvider'
|
|
26
|
+
import { CeloMappingProvider } from './CeloMappingProvider'
|
|
25
27
|
|
|
26
28
|
const web3 = new Web3()
|
|
27
29
|
|
|
@@ -32,6 +34,8 @@ const CHAINS_WITH_MAPPING_PROVIDERS = [
|
|
|
32
34
|
ChainId.OPTIMISM,
|
|
33
35
|
ChainId.BNB,
|
|
34
36
|
ChainId.AVALANCHE,
|
|
37
|
+
ChainId.CELO,
|
|
38
|
+
ChainId.BASE,
|
|
35
39
|
ChainId.BASE_GOERLI,
|
|
36
40
|
]
|
|
37
41
|
|
|
@@ -55,7 +59,7 @@ export async function buildList(
|
|
|
55
59
|
} = {}
|
|
56
60
|
const l2MappingExtension = {
|
|
57
61
|
extensions: {
|
|
58
|
-
bridgeInfo: {},
|
|
62
|
+
bridgeInfo: {} as any,
|
|
59
63
|
},
|
|
60
64
|
}
|
|
61
65
|
// build out the extensions.bridgeInfo data containing mappings for each L2 chain
|
|
@@ -133,7 +137,7 @@ async function hasExistingTokenContract(address: string, chainId: ChainId) {
|
|
|
133
137
|
try {
|
|
134
138
|
const contract: Contract = new web3.eth.Contract(ERC20Abi, address)
|
|
135
139
|
await getTokenSymbolFromContract(contract)
|
|
136
|
-
} catch {
|
|
140
|
+
} catch (e) {
|
|
137
141
|
return false
|
|
138
142
|
}
|
|
139
143
|
|
|
@@ -152,6 +156,10 @@ function getMappingProvider(chainId: ChainId, l1TokenList: TokenList) {
|
|
|
152
156
|
return new BnbMappingProvider()
|
|
153
157
|
case ChainId.AVALANCHE:
|
|
154
158
|
return new AvalancheMappingProvider()
|
|
159
|
+
case ChainId.CELO:
|
|
160
|
+
return new CeloMappingProvider()
|
|
161
|
+
case ChainId.BASE:
|
|
162
|
+
return new BaseMappingProvider()
|
|
155
163
|
case ChainId.BASE_GOERLI:
|
|
156
164
|
return new BaseGoerliMappingProvider()
|
|
157
165
|
default:
|
|
@@ -197,8 +205,14 @@ async function getChildTokenDetails(
|
|
|
197
205
|
childTokenAddress: string | undefined
|
|
198
206
|
decimals?: number | undefined
|
|
199
207
|
}> {
|
|
200
|
-
const
|
|
201
|
-
|
|
208
|
+
const bridgeInfo = l1Token?.extensions?.bridgeInfo
|
|
209
|
+
let existingMapping: undefined | string
|
|
210
|
+
if (bridgeInfo && typeof bridgeInfo === 'object') {
|
|
211
|
+
const bridgeInfoForChain = bridgeInfo[chainId]
|
|
212
|
+
if (bridgeInfoForChain && typeof bridgeInfoForChain === 'object') {
|
|
213
|
+
existingMapping = bridgeInfoForChain.tokenAddress as string
|
|
214
|
+
}
|
|
215
|
+
}
|
|
202
216
|
// use the externally fetched mappings if manual entry doesn't exist for the token/chain mapping
|
|
203
217
|
// and the given chain is supported for fetching mappings
|
|
204
218
|
if (
|
|
@@ -218,10 +232,12 @@ async function getChildTokenDetails(
|
|
|
218
232
|
(await hasExistingTokenContract(childTokenAddress, chainId))
|
|
219
233
|
)
|
|
220
234
|
const decimals =
|
|
221
|
-
childToken &&
|
|
235
|
+
childToken &&
|
|
236
|
+
(chainId === ChainId.BNB ||
|
|
237
|
+
chainId === ChainId.AVALANCHE ||
|
|
238
|
+
chainId === ChainId.CELO)
|
|
222
239
|
? (childToken as MappedToken).decimals
|
|
223
240
|
: undefined
|
|
224
|
-
|
|
225
241
|
return {
|
|
226
242
|
childTokenValid: childTokenValid,
|
|
227
243
|
childTokenAddress: childTokenAddress,
|
package/src/utils.ts
CHANGED
|
@@ -112,6 +112,12 @@ export function getRpcUrl(chainId: ChainId): string {
|
|
|
112
112
|
return 'https://bsc-dataseed1.binance.org'
|
|
113
113
|
case ChainId.AVALANCHE:
|
|
114
114
|
return 'https://api.avax.network/ext/bc/C/rpc'
|
|
115
|
+
case ChainId.CELO:
|
|
116
|
+
return 'https://forno.celo.org/'
|
|
117
|
+
case ChainId.CELO_ALFAJORES:
|
|
118
|
+
return 'https://alfajores-forno.celo-testnet.org/'
|
|
119
|
+
case ChainId.BASE:
|
|
120
|
+
return 'https://mainnet.base.org'
|
|
115
121
|
case ChainId.BASE_GOERLI:
|
|
116
122
|
return 'https://goerli.base.org'
|
|
117
123
|
default:
|