@uniswap/token-list-bridge-utils 1.0.5 → 1.0.8

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.
@@ -1,9 +1,10 @@
1
1
  import { cloneDeep, groupBy, merge } from 'lodash-es';
2
2
  import { config } from 'dotenv';
3
- import { providers, ethers } from 'ethers';
4
- import { L1GatewayRouter__factory } from '@arbitrum/sdk/dist/lib/abi/factories/L1GatewayRouter__factory';
5
3
  import { existsSync, readFileSync } from 'fs';
6
4
  import axios from 'axios';
5
+ import { providers, ethers } from 'ethers';
6
+ import { L1GatewayRouter__factory } from '@arbitrum/sdk/dist/lib/abi/factories/L1GatewayRouter__factory';
7
+ import Web3 from 'web3';
7
8
 
8
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
9
10
  try {
@@ -870,173 +871,6 @@ var ChainId;
870
871
  ChainId[ChainId["POLYGON_MUMBAI"] = 80001] = "POLYGON_MUMBAI";
871
872
  })(ChainId || (ChainId = {}));
872
873
 
873
- config();
874
- process.env.MAINNET_RPC = process.env.MAINNET_RPC || 'https://cloudflare-eth.com/';
875
-
876
- var networkID = 42161; // ref: https://github.com/OffchainLabs/arb-token-lists/blob/master/src/lib/instantiate_bridge.ts
877
-
878
- var getNetworkConfig = /*#__PURE__*/function () {
879
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
880
- var _yield$import, getL1Network, getL2Network, MultiCaller, l2Network, l1Network, arbProvider, ethProvider, l1MultiCaller, l2MultiCaller;
881
-
882
- return _regeneratorRuntime.wrap(function _callee$(_context) {
883
- while (1) {
884
- switch (_context.prev = _context.next) {
885
- case 0:
886
- _context.next = 2;
887
- return import('@arbitrum/sdk');
888
-
889
- case 2:
890
- _yield$import = _context.sent;
891
- getL1Network = _yield$import.getL1Network;
892
- getL2Network = _yield$import.getL2Network;
893
- MultiCaller = _yield$import.MultiCaller;
894
- _context.next = 8;
895
- return getL2Network(networkID);
896
-
897
- case 8:
898
- l2Network = _context.sent;
899
- _context.next = 11;
900
- return getL1Network(l2Network.partnerChainID);
901
-
902
- case 11:
903
- l1Network = _context.sent;
904
- arbProvider = new providers.JsonRpcProvider(l2Network.rpcURL);
905
- ethProvider = new providers.JsonRpcProvider(l1Network.rpcURL);
906
- _context.next = 16;
907
- return MultiCaller.fromProvider(ethProvider);
908
-
909
- case 16:
910
- l1MultiCaller = _context.sent;
911
- _context.next = 19;
912
- return MultiCaller.fromProvider(arbProvider);
913
-
914
- case 19:
915
- l2MultiCaller = _context.sent;
916
- return _context.abrupt("return", {
917
- l1: {
918
- network: l1Network,
919
- provider: ethProvider,
920
- multiCaller: l1MultiCaller
921
- },
922
- l2: {
923
- network: l2Network,
924
- provider: arbProvider,
925
- multiCaller: l2MultiCaller
926
- }
927
- });
928
-
929
- case 21:
930
- case "end":
931
- return _context.stop();
932
- }
933
- }
934
- }, _callee);
935
- }));
936
-
937
- return function getNetworkConfig() {
938
- return _ref.apply(this, arguments);
939
- };
940
- }();
941
-
942
- var getL2TokenAddressesFromL1 = /*#__PURE__*/function () {
943
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenAddresses, multiCaller, l1GatewayRouterAddress) {
944
- var iFace;
945
- return _regeneratorRuntime.wrap(function _callee$(_context) {
946
- while (1) {
947
- switch (_context.prev = _context.next) {
948
- case 0:
949
- iFace = L1GatewayRouter__factory.createInterface();
950
- _context.next = 3;
951
- return multiCaller.multiCall(l1TokenAddresses.map(function (addr) {
952
- return {
953
- encoder: function encoder() {
954
- return iFace.encodeFunctionData('calculateL2TokenAddress', [addr]);
955
- },
956
- decoder: function decoder(returnData) {
957
- return iFace.decodeFunctionResult('calculateL2TokenAddress', returnData)[0];
958
- },
959
- targetAddr: l1GatewayRouterAddress
960
- };
961
- }));
962
-
963
- case 3:
964
- return _context.abrupt("return", _context.sent);
965
-
966
- case 4:
967
- case "end":
968
- return _context.stop();
969
- }
970
- }
971
- }, _callee);
972
- }));
973
-
974
- return function getL2TokenAddressesFromL1(_x, _x2, _x3) {
975
- return _ref.apply(this, arguments);
976
- };
977
- }();
978
-
979
- /**
980
- * This provider provides the l1->l2(Arbitrum) address mappings using the arbitrum SDK.
981
- */
982
-
983
- var ArbitrumMappingProvider = /*#__PURE__*/function () {
984
- function ArbitrumMappingProvider(l1TokenList) {
985
- this.l1TokenList = void 0;
986
- this.l1TokenList = l1TokenList;
987
- }
988
-
989
- var _proto = ArbitrumMappingProvider.prototype;
990
-
991
- _proto.provide = /*#__PURE__*/function () {
992
- var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
993
- var tokens, _yield$getNetworkConf, l1, l2, tokenAddresses, l2AddressesFromL1;
994
-
995
- return _regeneratorRuntime.wrap(function _callee$(_context) {
996
- while (1) {
997
- switch (_context.prev = _context.next) {
998
- case 0:
999
- tokens = {};
1000
- _context.next = 3;
1001
- return getNetworkConfig();
1002
-
1003
- case 3:
1004
- _yield$getNetworkConf = _context.sent;
1005
- l1 = _yield$getNetworkConf.l1;
1006
- l2 = _yield$getNetworkConf.l2;
1007
- tokenAddresses = this.l1TokenList.tokens.map(function (token) {
1008
- return token.address.toLowerCase();
1009
- });
1010
- _context.next = 9;
1011
- return getL2TokenAddressesFromL1(tokenAddresses, l1.multiCaller, l2.network.tokenBridge.l1GatewayRouter);
1012
-
1013
- case 9:
1014
- l2AddressesFromL1 = _context.sent;
1015
- tokens = tokenAddresses.reduce(function (obj, key, index) {
1016
- var _extends2;
1017
-
1018
- return _extends({}, obj, (_extends2 = {}, _extends2[key] = l2AddressesFromL1[index], _extends2));
1019
- }, {});
1020
- return _context.abrupt("return", tokens);
1021
-
1022
- case 12:
1023
- case "end":
1024
- return _context.stop();
1025
- }
1026
- }
1027
- }, _callee, this);
1028
- }));
1029
-
1030
- function provide() {
1031
- return _provide.apply(this, arguments);
1032
- }
1033
-
1034
- return provide;
1035
- }();
1036
-
1037
- return ArbitrumMappingProvider;
1038
- }();
1039
-
1040
874
  function compareTokenInfos(t1, t2) {
1041
875
  if (t1.chainId === t2.chainId) {
1042
876
  return t1.symbol.toLowerCase() < t2.symbol.toLowerCase() ? -1 : 1;
@@ -1231,6 +1065,228 @@ var isTokenList = function isTokenList(obj) {
1231
1065
  throw new Error('tokenlist typeguard error: token missing required key');
1232
1066
  }
1233
1067
  };
1068
+ function getRpcUrl(chainId) {
1069
+ switch (chainId) {
1070
+ case ChainId.MAINNET:
1071
+ return 'https://cloudflare-eth.com/';
1072
+
1073
+ case ChainId.OPTIMISM:
1074
+ return 'https://mainnet.optimism.io';
1075
+
1076
+ case ChainId.OPTIMISTIC_KOVAN:
1077
+ return 'https://kovan.optimism.io';
1078
+
1079
+ case ChainId.ARBITRUM_ONE:
1080
+ return 'https://arb1.arbitrum.io/rpc';
1081
+
1082
+ case ChainId.ARBITRUM_RINKEBY:
1083
+ return 'https://rinkeby.arbitrum.io/rpc';
1084
+
1085
+ case ChainId.POLYGON:
1086
+ return 'https://polygon-rpc.com/';
1087
+
1088
+ case ChainId.POLYGON_MUMBAI:
1089
+ return 'https://rpc-endpoints.superfluid.dev/mumbai';
1090
+ }
1091
+
1092
+ throw new Error('Unsupported ChainId');
1093
+ }
1094
+ function getTokenSymbolFromContract(_x6) {
1095
+ return _getTokenSymbolFromContract.apply(this, arguments);
1096
+ }
1097
+
1098
+ function _getTokenSymbolFromContract() {
1099
+ _getTokenSymbolFromContract = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(tokenContract) {
1100
+ var symbol;
1101
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
1102
+ while (1) {
1103
+ switch (_context6.prev = _context6.next) {
1104
+ case 0:
1105
+ _context6.next = 2;
1106
+ return Promise.all([tokenContract.methods.symbol().call()]);
1107
+
1108
+ case 2:
1109
+ symbol = _context6.sent;
1110
+ return _context6.abrupt("return", symbol);
1111
+
1112
+ case 4:
1113
+ case "end":
1114
+ return _context6.stop();
1115
+ }
1116
+ }
1117
+ }, _callee6);
1118
+ }));
1119
+ return _getTokenSymbolFromContract.apply(this, arguments);
1120
+ }
1121
+
1122
+ var _process$env, _process$env$MAINNET_;
1123
+
1124
+ config();
1125
+ (_process$env$MAINNET_ = (_process$env = process.env).MAINNET_RPC) != null ? _process$env$MAINNET_ : _process$env.MAINNET_RPC = /*#__PURE__*/getRpcUrl(ChainId.MAINNET);
1126
+
1127
+ var networkID = 42161; // ref: https://github.com/OffchainLabs/arb-token-lists/blob/master/src/lib/instantiate_bridge.ts
1128
+
1129
+ var getNetworkConfig = /*#__PURE__*/function () {
1130
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1131
+ var _yield$import, getL1Network, getL2Network, MultiCaller, l2Network, l1Network, arbProvider, ethProvider, l1MultiCaller, l2MultiCaller;
1132
+
1133
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1134
+ while (1) {
1135
+ switch (_context.prev = _context.next) {
1136
+ case 0:
1137
+ _context.next = 2;
1138
+ return import('@arbitrum/sdk');
1139
+
1140
+ case 2:
1141
+ _yield$import = _context.sent;
1142
+ getL1Network = _yield$import.getL1Network;
1143
+ getL2Network = _yield$import.getL2Network;
1144
+ MultiCaller = _yield$import.MultiCaller;
1145
+ _context.next = 8;
1146
+ return getL2Network(networkID);
1147
+
1148
+ case 8:
1149
+ l2Network = _context.sent;
1150
+ _context.next = 11;
1151
+ return getL1Network(l2Network.partnerChainID);
1152
+
1153
+ case 11:
1154
+ l1Network = _context.sent;
1155
+ arbProvider = new providers.JsonRpcProvider(l2Network.rpcURL);
1156
+ ethProvider = new providers.JsonRpcProvider(l1Network.rpcURL);
1157
+ _context.next = 16;
1158
+ return MultiCaller.fromProvider(ethProvider);
1159
+
1160
+ case 16:
1161
+ l1MultiCaller = _context.sent;
1162
+ _context.next = 19;
1163
+ return MultiCaller.fromProvider(arbProvider);
1164
+
1165
+ case 19:
1166
+ l2MultiCaller = _context.sent;
1167
+ return _context.abrupt("return", {
1168
+ l1: {
1169
+ network: l1Network,
1170
+ provider: ethProvider,
1171
+ multiCaller: l1MultiCaller
1172
+ },
1173
+ l2: {
1174
+ network: l2Network,
1175
+ provider: arbProvider,
1176
+ multiCaller: l2MultiCaller
1177
+ }
1178
+ });
1179
+
1180
+ case 21:
1181
+ case "end":
1182
+ return _context.stop();
1183
+ }
1184
+ }
1185
+ }, _callee);
1186
+ }));
1187
+
1188
+ return function getNetworkConfig() {
1189
+ return _ref.apply(this, arguments);
1190
+ };
1191
+ }();
1192
+
1193
+ var getL2TokenAddressesFromL1 = /*#__PURE__*/function () {
1194
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenAddresses, multiCaller, l1GatewayRouterAddress) {
1195
+ var iFace;
1196
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1197
+ while (1) {
1198
+ switch (_context.prev = _context.next) {
1199
+ case 0:
1200
+ iFace = L1GatewayRouter__factory.createInterface();
1201
+ _context.next = 3;
1202
+ return multiCaller.multiCall(l1TokenAddresses.map(function (addr) {
1203
+ return {
1204
+ encoder: function encoder() {
1205
+ return iFace.encodeFunctionData('calculateL2TokenAddress', [addr]);
1206
+ },
1207
+ decoder: function decoder(returnData) {
1208
+ return iFace.decodeFunctionResult('calculateL2TokenAddress', returnData)[0];
1209
+ },
1210
+ targetAddr: l1GatewayRouterAddress
1211
+ };
1212
+ }));
1213
+
1214
+ case 3:
1215
+ return _context.abrupt("return", _context.sent);
1216
+
1217
+ case 4:
1218
+ case "end":
1219
+ return _context.stop();
1220
+ }
1221
+ }
1222
+ }, _callee);
1223
+ }));
1224
+
1225
+ return function getL2TokenAddressesFromL1(_x, _x2, _x3) {
1226
+ return _ref.apply(this, arguments);
1227
+ };
1228
+ }();
1229
+
1230
+ /**
1231
+ * This provider provides the l1->l2(Arbitrum) address mappings using the arbitrum SDK.
1232
+ */
1233
+
1234
+ var ArbitrumMappingProvider = /*#__PURE__*/function () {
1235
+ function ArbitrumMappingProvider(l1TokenList) {
1236
+ this.l1TokenList = void 0;
1237
+ this.l1TokenList = l1TokenList;
1238
+ }
1239
+
1240
+ var _proto = ArbitrumMappingProvider.prototype;
1241
+
1242
+ _proto.provide = /*#__PURE__*/function () {
1243
+ var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1244
+ var tokens, _yield$getNetworkConf, l1, l2, tokenAddresses, l2AddressesFromL1;
1245
+
1246
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1247
+ while (1) {
1248
+ switch (_context.prev = _context.next) {
1249
+ case 0:
1250
+ tokens = {};
1251
+ _context.next = 3;
1252
+ return getNetworkConfig();
1253
+
1254
+ case 3:
1255
+ _yield$getNetworkConf = _context.sent;
1256
+ l1 = _yield$getNetworkConf.l1;
1257
+ l2 = _yield$getNetworkConf.l2;
1258
+ tokenAddresses = this.l1TokenList.tokens.map(function (token) {
1259
+ return token.address.toLowerCase();
1260
+ });
1261
+ _context.next = 9;
1262
+ return getL2TokenAddressesFromL1(tokenAddresses, l1.multiCaller, l2.network.tokenBridge.l1GatewayRouter);
1263
+
1264
+ case 9:
1265
+ l2AddressesFromL1 = _context.sent;
1266
+ tokens = tokenAddresses.reduce(function (obj, key, index) {
1267
+ var _extends2;
1268
+
1269
+ return _extends({}, obj, (_extends2 = {}, _extends2[key] = l2AddressesFromL1[index], _extends2));
1270
+ }, {});
1271
+ return _context.abrupt("return", tokens);
1272
+
1273
+ case 12:
1274
+ case "end":
1275
+ return _context.stop();
1276
+ }
1277
+ }
1278
+ }, _callee, this);
1279
+ }));
1280
+
1281
+ function provide() {
1282
+ return _provide.apply(this, arguments);
1283
+ }
1284
+
1285
+ return provide;
1286
+ }();
1287
+
1288
+ return ArbitrumMappingProvider;
1289
+ }();
1234
1290
 
1235
1291
  var optimismTokenListURL = 'https://raw.githubusercontent.com/' + 'ethereum-optimism/ethereum-optimism.github.io/2138386277e4156d159615d1840882cecc398437/optimism.tokenlist.json';
1236
1292
  /**
@@ -1362,60 +1418,258 @@ var PolygonMappingProvider = /*#__PURE__*/function () {
1362
1418
  return PolygonMappingProvider;
1363
1419
  }();
1364
1420
 
1421
+ var abi = [{
1422
+ constant: true,
1423
+ inputs: [],
1424
+ name: 'name',
1425
+ outputs: [{
1426
+ name: '',
1427
+ type: 'string'
1428
+ }],
1429
+ payable: false,
1430
+ stateMutability: 'view',
1431
+ type: 'function'
1432
+ }, {
1433
+ constant: false,
1434
+ inputs: [{
1435
+ name: '_spender',
1436
+ type: 'address'
1437
+ }, {
1438
+ name: '_value',
1439
+ type: 'uint256'
1440
+ }],
1441
+ name: 'approve',
1442
+ outputs: [{
1443
+ name: '',
1444
+ type: 'bool'
1445
+ }],
1446
+ payable: false,
1447
+ stateMutability: 'nonpayable',
1448
+ type: 'function'
1449
+ }, {
1450
+ constant: true,
1451
+ inputs: [],
1452
+ name: 'totalSupply',
1453
+ outputs: [{
1454
+ name: '',
1455
+ type: 'uint256'
1456
+ }],
1457
+ payable: false,
1458
+ stateMutability: 'view',
1459
+ type: 'function'
1460
+ }, {
1461
+ constant: false,
1462
+ inputs: [{
1463
+ name: '_from',
1464
+ type: 'address'
1465
+ }, {
1466
+ name: '_to',
1467
+ type: 'address'
1468
+ }, {
1469
+ name: '_value',
1470
+ type: 'uint256'
1471
+ }],
1472
+ name: 'transferFrom',
1473
+ outputs: [{
1474
+ name: '',
1475
+ type: 'bool'
1476
+ }],
1477
+ payable: false,
1478
+ stateMutability: 'nonpayable',
1479
+ type: 'function'
1480
+ }, {
1481
+ constant: true,
1482
+ inputs: [],
1483
+ name: 'decimals',
1484
+ outputs: [{
1485
+ name: '',
1486
+ type: 'uint8'
1487
+ }],
1488
+ payable: false,
1489
+ stateMutability: 'view',
1490
+ type: 'function'
1491
+ }, {
1492
+ constant: true,
1493
+ inputs: [{
1494
+ name: '_owner',
1495
+ type: 'address'
1496
+ }],
1497
+ name: 'balanceOf',
1498
+ outputs: [{
1499
+ name: 'balance',
1500
+ type: 'uint256'
1501
+ }],
1502
+ payable: false,
1503
+ stateMutability: 'view',
1504
+ type: 'function'
1505
+ }, {
1506
+ constant: true,
1507
+ inputs: [],
1508
+ name: 'symbol',
1509
+ outputs: [{
1510
+ name: '',
1511
+ type: 'string'
1512
+ }],
1513
+ payable: false,
1514
+ stateMutability: 'view',
1515
+ type: 'function'
1516
+ }, {
1517
+ constant: false,
1518
+ inputs: [{
1519
+ name: '_to',
1520
+ type: 'address'
1521
+ }, {
1522
+ name: '_value',
1523
+ type: 'uint256'
1524
+ }],
1525
+ name: 'transfer',
1526
+ outputs: [{
1527
+ name: '',
1528
+ type: 'bool'
1529
+ }],
1530
+ payable: false,
1531
+ stateMutability: 'nonpayable',
1532
+ type: 'function'
1533
+ }, {
1534
+ constant: true,
1535
+ inputs: [{
1536
+ name: '_owner',
1537
+ type: 'address'
1538
+ }, {
1539
+ name: '_spender',
1540
+ type: 'address'
1541
+ }],
1542
+ name: 'allowance',
1543
+ outputs: [{
1544
+ name: '',
1545
+ type: 'uint256'
1546
+ }],
1547
+ payable: false,
1548
+ stateMutability: 'view',
1549
+ type: 'function'
1550
+ }, {
1551
+ payable: true,
1552
+ stateMutability: 'payable',
1553
+ type: 'fallback'
1554
+ }, {
1555
+ anonymous: false,
1556
+ inputs: [{
1557
+ indexed: true,
1558
+ name: 'owner',
1559
+ type: 'address'
1560
+ }, {
1561
+ indexed: true,
1562
+ name: 'spender',
1563
+ type: 'address'
1564
+ }, {
1565
+ indexed: false,
1566
+ name: 'value',
1567
+ type: 'uint256'
1568
+ }],
1569
+ name: 'Approval',
1570
+ type: 'event'
1571
+ }, {
1572
+ anonymous: false,
1573
+ inputs: [{
1574
+ indexed: true,
1575
+ name: 'from',
1576
+ type: 'address'
1577
+ }, {
1578
+ indexed: true,
1579
+ name: 'to',
1580
+ type: 'address'
1581
+ }, {
1582
+ indexed: false,
1583
+ name: 'value',
1584
+ type: 'uint256'
1585
+ }],
1586
+ name: 'Transfer',
1587
+ type: 'event'
1588
+ }];
1589
+
1590
+ var web3 = /*#__PURE__*/new Web3();
1365
1591
  function buildList(_x, _x2) {
1366
1592
  return _buildList.apply(this, arguments);
1367
- }
1593
+ } // using a symbol lookup contract call to check whether the token exists on the L2
1368
1594
 
1369
1595
  function _buildList() {
1370
1596
  _buildList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(chainId, l1TokenList) {
1371
- var tokenAddressMap, mappedTokens, _iterator, _step, rootToken, childToken, childTokenValid, _bridgeInfo, _bridgeInfo2, toRootExtensions, toChildExtensions, rootTokenInfo, childTokenInfo, tokenList;
1597
+ var tokenAddressMap, mappedTokens, _iterator, _step, rootToken, childToken, childTokenAddress, childTokenValid, _bridgeInfo, _bridgeInfo2, toRootExtensions, toChildExtensions, rootTokenInfo, childTokenInfo, tokenList;
1372
1598
 
1373
1599
  return _regeneratorRuntime.wrap(function _callee$(_context) {
1374
1600
  while (1) {
1375
1601
  switch (_context.prev = _context.next) {
1376
1602
  case 0:
1377
- _context.next = 2;
1603
+ web3.setProvider(getRpcUrl(chainId));
1604
+ _context.next = 3;
1378
1605
  return getMappingProvider(chainId, l1TokenList).provide();
1379
1606
 
1380
- case 2:
1607
+ case 3:
1381
1608
  tokenAddressMap = _context.sent;
1382
1609
  mappedTokens = [];
1610
+ _iterator = _createForOfIteratorHelperLoose(l1TokenList.tokens);
1383
1611
 
1384
- for (_iterator = _createForOfIteratorHelperLoose(l1TokenList.tokens); !(_step = _iterator()).done;) {
1385
- rootToken = _step.value;
1386
- childToken = tokenAddressMap[rootToken.address.toLowerCase()];
1387
- childTokenValid = Boolean(childToken && (typeof childToken === 'object' ? !childToken.deleted : true));
1388
-
1389
- if (rootToken.chainId === ChainId.MAINNET) {
1390
- // build extension info if available
1391
- toRootExtensions = childTokenValid ? {
1392
- extensions: {
1393
- bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[rootToken.chainId] = {
1394
- tokenAddress: ethers.utils.getAddress(rootToken.address)
1395
- }, _bridgeInfo)
1396
- }
1397
- } : {};
1398
- toChildExtensions = childTokenValid ? {
1399
- extensions: {
1400
- bridgeInfo: (_bridgeInfo2 = {}, _bridgeInfo2[chainId] = {
1401
- tokenAddress: ethers.utils.getAddress(typeof childToken === 'object' ? childToken.child_token : childToken)
1402
- }, _bridgeInfo2)
1403
- }
1404
- } : {};
1405
- rootTokenInfo = _extends({}, rootToken, toChildExtensions);
1406
-
1407
- if (childTokenValid) {
1408
- childTokenInfo = _extends({}, rootToken, {
1409
- chainId: chainId,
1410
- address: ethers.utils.getAddress(typeof childToken === 'object' ? childToken.child_token : childToken)
1411
- }, toRootExtensions);
1412
- mappedTokens.push(childTokenInfo);
1413
- }
1612
+ case 6:
1613
+ if ((_step = _iterator()).done) {
1614
+ _context.next = 21;
1615
+ break;
1616
+ }
1617
+
1618
+ rootToken = _step.value;
1619
+ childToken = tokenAddressMap[rootToken.address.toLowerCase()];
1620
+ childTokenAddress = childToken ? ethers.utils.getAddress(typeof childToken === 'object' ? childToken.child_token : childToken) : undefined;
1621
+ _context.t0 = Boolean;
1622
+ _context.t1 = childTokenAddress && (typeof childToken === 'object' ? !childToken.deleted : true);
1623
+
1624
+ if (!_context.t1) {
1625
+ _context.next = 16;
1626
+ break;
1627
+ }
1414
1628
 
1415
- mappedTokens.push(rootTokenInfo);
1629
+ _context.next = 15;
1630
+ return hasExistingTokenContract(childTokenAddress, chainId);
1631
+
1632
+ case 15:
1633
+ _context.t1 = _context.sent;
1634
+
1635
+ case 16:
1636
+ _context.t2 = _context.t1;
1637
+ childTokenValid = (0, _context.t0)(_context.t2);
1638
+
1639
+ if (rootToken.chainId === ChainId.MAINNET) {
1640
+ // build extension info if available
1641
+ toRootExtensions = childTokenValid ? {
1642
+ extensions: {
1643
+ bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[rootToken.chainId] = {
1644
+ tokenAddress: ethers.utils.getAddress(rootToken.address)
1645
+ }, _bridgeInfo)
1646
+ }
1647
+ } : {};
1648
+ toChildExtensions = childTokenValid ? {
1649
+ extensions: {
1650
+ bridgeInfo: (_bridgeInfo2 = {}, _bridgeInfo2[chainId] = {
1651
+ tokenAddress: childTokenAddress
1652
+ }, _bridgeInfo2)
1653
+ }
1654
+ } : {};
1655
+ rootTokenInfo = _extends({}, rootToken, toChildExtensions);
1656
+
1657
+ if (childTokenValid) {
1658
+ childTokenInfo = _extends({}, rootToken, {
1659
+ chainId: chainId,
1660
+ address: childTokenAddress
1661
+ }, toRootExtensions);
1662
+ mappedTokens.push(childTokenInfo);
1416
1663
  }
1664
+
1665
+ mappedTokens.push(rootTokenInfo);
1417
1666
  }
1418
1667
 
1668
+ case 19:
1669
+ _context.next = 6;
1670
+ break;
1671
+
1672
+ case 21:
1419
1673
  tokenList = {
1420
1674
  name: "(ChainId: " + chainId + ") " + l1TokenList.name,
1421
1675
  timestamp: new Date().toISOString(),
@@ -1424,7 +1678,7 @@ function _buildList() {
1424
1678
  };
1425
1679
  return _context.abrupt("return", tokenList);
1426
1680
 
1427
- case 7:
1681
+ case 23:
1428
1682
  case "end":
1429
1683
  return _context.stop();
1430
1684
  }
@@ -1434,6 +1688,44 @@ function _buildList() {
1434
1688
  return _buildList.apply(this, arguments);
1435
1689
  }
1436
1690
 
1691
+ function hasExistingTokenContract(_x3, _x4) {
1692
+ return _hasExistingTokenContract.apply(this, arguments);
1693
+ }
1694
+
1695
+ function _hasExistingTokenContract() {
1696
+ _hasExistingTokenContract = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(address, chainId) {
1697
+ var contract;
1698
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1699
+ while (1) {
1700
+ switch (_context2.prev = _context2.next) {
1701
+ case 0:
1702
+ _context2.prev = 0;
1703
+ contract = new web3.eth.Contract(abi, address);
1704
+ _context2.next = 4;
1705
+ return getTokenSymbolFromContract(contract);
1706
+
1707
+ case 4:
1708
+ _context2.next = 9;
1709
+ break;
1710
+
1711
+ case 6:
1712
+ _context2.prev = 6;
1713
+ _context2.t0 = _context2["catch"](0);
1714
+ return _context2.abrupt("return", false);
1715
+
1716
+ case 9:
1717
+ return _context2.abrupt("return", true);
1718
+
1719
+ case 10:
1720
+ case "end":
1721
+ return _context2.stop();
1722
+ }
1723
+ }
1724
+ }, _callee2, null, [[0, 6]]);
1725
+ }));
1726
+ return _hasExistingTokenContract.apply(this, arguments);
1727
+ }
1728
+
1437
1729
  function getMappingProvider(chainId, l1TokenList) {
1438
1730
  switch (chainId) {
1439
1731
  case ChainId.ARBITRUM_ONE: