@uniswap/token-list-bridge-utils 0.1.1-beta.1 → 1.0.1

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.
Files changed (56) hide show
  1. package/README.md +102 -5
  2. package/dist/arbitrum/gateway.d.ts +2 -0
  3. package/dist/{arb-token-lists/src/lib → arbitrum}/instantiate_bridge.d.ts +3 -4
  4. package/dist/constants/types.d.ts +30 -0
  5. package/dist/fixtures/index.d.ts +9 -0
  6. package/dist/providers/ArbitrumMappingProvider.d.ts +7 -6
  7. package/dist/providers/MappingProvider.d.ts +4 -2
  8. package/dist/providers/OptimismMappingProvider.d.ts +5 -4
  9. package/dist/providers/PolygonMappingProvider.d.ts +4 -2
  10. package/dist/providers/index.d.ts +2 -4
  11. package/dist/token-list-bridge-utils.cjs.development.js +327 -906
  12. package/dist/token-list-bridge-utils.cjs.development.js.map +1 -1
  13. package/dist/token-list-bridge-utils.cjs.production.min.js +1 -1
  14. package/dist/token-list-bridge-utils.cjs.production.min.js.map +1 -1
  15. package/dist/token-list-bridge-utils.esm.js +329 -902
  16. package/dist/token-list-bridge-utils.esm.js.map +1 -1
  17. package/dist/utils.d.ts +4 -0
  18. package/package.json +7 -4
  19. package/src/.DS_Store +0 -0
  20. package/src/arbitrum/gateway.ts +25 -0
  21. package/src/{arb-token-lists/src/lib → arbitrum}/instantiate_bridge.ts +11 -15
  22. package/src/constants/types.ts +28 -0
  23. package/src/fixtures/index.ts +40 -5
  24. package/src/index.test.ts +60 -18
  25. package/src/index.ts +5 -7
  26. package/src/providers/ArbitrumMappingProvider.ts +31 -21
  27. package/src/providers/MappingProvider.ts +4 -2
  28. package/src/providers/OptimismMappingProvider.ts +21 -5
  29. package/src/providers/PolygonMappingProvider.ts +22 -114
  30. package/src/providers/index.ts +82 -2
  31. package/src/utils.ts +71 -1
  32. package/dist/arb-token-lists/server/app.d.ts +0 -1
  33. package/dist/arb-token-lists/src/lib/getClargs.d.ts +0 -8
  34. package/dist/arb-token-lists/src/lib/graph.d.ts +0 -2
  35. package/dist/arb-token-lists/src/lib/token_list_gen.d.ts +0 -23
  36. package/dist/arb-token-lists/src/lib/types.d.ts +0 -36
  37. package/dist/arb-token-lists/src/lib/utils.d.ts +0 -18
  38. package/dist/arb-token-lists/src/main.d.ts +0 -1
  39. package/src/arb-token-lists/.env.sample +0 -4
  40. package/src/arb-token-lists/.eslintrc.js +0 -43
  41. package/src/arb-token-lists/.gitignore +0 -4
  42. package/src/arb-token-lists/package.json +0 -40
  43. package/src/arb-token-lists/readme.md +0 -14
  44. package/src/arb-token-lists/server/app.ts +0 -21
  45. package/src/arb-token-lists/src/Assets/coingecko_uris.json +0 -5108
  46. package/src/arb-token-lists/src/Assets/logo_uris.json +0 -44
  47. package/src/arb-token-lists/src/WarningList/warningTokens.json +0 -290
  48. package/src/arb-token-lists/src/lib/getClargs.ts +0 -32
  49. package/src/arb-token-lists/src/lib/graph.ts +0 -116
  50. package/src/arb-token-lists/src/lib/token_list_gen.ts +0 -334
  51. package/src/arb-token-lists/src/lib/types.ts +0 -44
  52. package/src/arb-token-lists/src/lib/utils.ts +0 -285
  53. package/src/arb-token-lists/src/main.ts +0 -54
  54. package/src/arb-token-lists/tsconfig.json +0 -20
  55. package/src/arb-token-lists/update_all +0 -6
  56. package/src/arb-token-lists/yarn.lock +0 -4273
@@ -1,16 +1,10 @@
1
1
  import { cloneDeep, groupBy, merge } from 'lodash-es';
2
- import { schema, minVersionBump, nextVersion, VersionUpgrade } from '@uniswap/token-lists';
3
- import { abi, TokenBridger, MultiCaller, getL1Network, getL2Network, constants as constants$1 } from 'arb-ts';
4
- import { providers, constants, utils } from 'ethers';
5
- import { readFileSync, existsSync } from 'fs';
6
- import { gql, request } from 'graphql-request';
7
- import Ajv from 'ajv';
8
- import addFormats from 'ajv-formats';
2
+ import { providers, ethers } from 'ethers';
3
+ import { config } from 'dotenv';
4
+ import { MultiCaller, getL1Network, getL2Network } from '@arbitrum/sdk';
5
+ import { L1GatewayRouter__factory } from '@arbitrum/sdk/dist/lib/abi/factories/L1GatewayRouter__factory';
6
+ import { existsSync, readFileSync } from 'fs';
9
7
  import axios from 'axios';
10
- import betterAjvErrors from 'better-ajv-errors';
11
- import path from 'path';
12
- import yargs from 'yargs/yargs';
13
- import dotenv from 'dotenv';
14
8
 
15
9
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
16
10
  try {
@@ -66,15 +60,6 @@ function _extends() {
66
60
  return _extends.apply(this, arguments);
67
61
  }
68
62
 
69
- function _taggedTemplateLiteralLoose(strings, raw) {
70
- if (!raw) {
71
- raw = strings.slice(0);
72
- }
73
-
74
- strings.raw = raw;
75
- return strings;
76
- }
77
-
78
63
  function _unsupportedIterableToArray(o, minLen) {
79
64
  if (!o) return;
80
65
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -886,25 +871,63 @@ var ChainId;
886
871
  ChainId[ChainId["POLYGON_MUMBAI"] = 80001] = "POLYGON_MUMBAI";
887
872
  })(ChainId || (ChainId = {}));
888
873
 
889
- var coinGeckoBuff = /*#__PURE__*/readFileSync( /*#__PURE__*/path.resolve(__dirname, '../Assets/coingecko_uris.json'));
890
- var logoURIsBuff = /*#__PURE__*/readFileSync( /*#__PURE__*/path.resolve(__dirname, '../Assets/logo_uris.json'));
891
- var coingeckoURIs = /*#__PURE__*/JSON.parse( /*#__PURE__*/coinGeckoBuff.toString());
892
- var logoUris = /*#__PURE__*/JSON.parse( /*#__PURE__*/logoURIsBuff.toString());
874
+ var networkID = 42161;
875
+ config();
876
+ var getNetworkConfig = /*#__PURE__*/function () {
877
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
878
+ var l2Network, l1Network, arbProvider, ethProvider, l1MultiCaller, l2MultiCaller;
879
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
880
+ while (1) {
881
+ switch (_context.prev = _context.next) {
882
+ case 0:
883
+ _context.next = 2;
884
+ return getL2Network(networkID);
893
885
 
894
- for (var _i = 0, _Object$keys = /*#__PURE__*/Object.keys(logoUris); _i < _Object$keys.length; _i++) {
895
- var address = _Object$keys[_i];
896
- logoUris[/*#__PURE__*/address.toLowerCase()] = logoUris[address];
897
- }
898
- var listNameToArbifiedListName = function listNameToArbifiedListName(name) {
899
- var prefix = 'Arbed ';
900
- var fileName = sanitizeString(name);
886
+ case 2:
887
+ l2Network = _context.sent;
888
+ _context.next = 5;
889
+ return getL1Network(l2Network.partnerChainID);
901
890
 
902
- if (!fileName.startsWith(prefix)) {
903
- fileName = prefix + fileName;
904
- }
891
+ case 5:
892
+ l1Network = _context.sent;
893
+ arbProvider = new providers.JsonRpcProvider(l2Network.rpcURL);
894
+ ethProvider = new providers.JsonRpcProvider(l1Network.rpcURL);
895
+ _context.next = 10;
896
+ return MultiCaller.fromProvider(ethProvider);
897
+
898
+ case 10:
899
+ l1MultiCaller = _context.sent;
900
+ _context.next = 13;
901
+ return MultiCaller.fromProvider(arbProvider);
902
+
903
+ case 13:
904
+ l2MultiCaller = _context.sent;
905
+ return _context.abrupt("return", {
906
+ l1: {
907
+ network: l1Network,
908
+ provider: ethProvider,
909
+ multiCaller: l1MultiCaller
910
+ },
911
+ l2: {
912
+ network: l2Network,
913
+ provider: arbProvider,
914
+ multiCaller: l2MultiCaller
915
+ }
916
+ });
917
+
918
+ case 15:
919
+ case "end":
920
+ return _context.stop();
921
+ }
922
+ }
923
+ }, _callee);
924
+ }));
925
+
926
+ return function getNetworkConfig() {
927
+ return _ref.apply(this, arguments);
928
+ };
929
+ }();
905
930
 
906
- return fileName.split(' ').slice(0, 2).join(' ').slice(0, 20);
907
- };
908
931
  var getL2TokenAddressesFromL1 = /*#__PURE__*/function () {
909
932
  var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenAddresses, multiCaller, l1GatewayRouterAddress) {
910
933
  var iFace;
@@ -912,7 +935,7 @@ var getL2TokenAddressesFromL1 = /*#__PURE__*/function () {
912
935
  while (1) {
913
936
  switch (_context.prev = _context.next) {
914
937
  case 0:
915
- iFace = abi.L1GatewayRouter__factory.createInterface();
938
+ iFace = L1GatewayRouter__factory.createInterface();
916
939
  _context.next = 3;
917
940
  return multiCaller.multiCall(l1TokenAddresses.map(function (addr) {
918
941
  return {
@@ -941,243 +964,218 @@ var getL2TokenAddressesFromL1 = /*#__PURE__*/function () {
941
964
  return _ref.apply(this, arguments);
942
965
  };
943
966
  }();
944
- var getL2TokenAddressesFromL2 = /*#__PURE__*/function () {
945
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(l1TokenAddresses, multiCaller, l2GatewayRouterAddress) {
946
- var iFace;
947
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
948
- while (1) {
949
- switch (_context2.prev = _context2.next) {
950
- case 0:
951
- iFace = abi.L2GatewayRouter__factory.createInterface();
952
- _context2.next = 3;
953
- return multiCaller.multiCall(l1TokenAddresses.map(function (addr) {
954
- return {
955
- encoder: function encoder() {
956
- return iFace.encodeFunctionData('calculateL2TokenAddress', [addr]);
957
- },
958
- decoder: function decoder(returnData) {
959
- return iFace.decodeFunctionResult('calculateL2TokenAddress', returnData)[0];
960
- },
961
- targetAddr: l2GatewayRouterAddress
962
- };
963
- }));
964
967
 
965
- case 3:
966
- return _context2.abrupt("return", _context2.sent);
968
+ /**
969
+ * This provider provides the l1->l2(Arbitrum) address mappings using the arbitrum SDK.
970
+ */
967
971
 
968
- case 4:
969
- case "end":
970
- return _context2.stop();
971
- }
972
- }
973
- }, _callee2);
974
- }));
972
+ var ArbitrumMappingProvider = /*#__PURE__*/function () {
973
+ function ArbitrumMappingProvider(l1TokenList) {
974
+ this.l1TokenList = void 0;
975
+ this.l1TokenList = l1TokenList;
976
+ }
975
977
 
976
- return function getL2TokenAddressesFromL2(_x4, _x5, _x6) {
977
- return _ref2.apply(this, arguments);
978
- };
979
- }();
980
- var getLogoUri = /*#__PURE__*/function () {
981
- var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(l1TokenAddress) {
982
- var l1TokenAddressLCase, logoUri, coinGeckoURI, trustWalletUri, uris, _iterator, _step, uri, res;
978
+ var _proto = ArbitrumMappingProvider.prototype;
983
979
 
984
- return _regeneratorRuntime.wrap(function _callee3$(_context3) {
985
- while (1) {
986
- switch (_context3.prev = _context3.next) {
987
- case 0:
988
- l1TokenAddressLCase = l1TokenAddress.toLowerCase();
989
- logoUri = logoUris[l1TokenAddressLCase];
990
- coinGeckoURI = coingeckoURIs[l1TokenAddressLCase];
991
- trustWalletUri = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/" + l1TokenAddress + "/logo.png";
992
- uris = [logoUri, coinGeckoURI, trustWalletUri].filter(function (x) {
993
- return !!x;
994
- });
995
- _iterator = _createForOfIteratorHelperLoose(uris);
980
+ _proto.provide = /*#__PURE__*/function () {
981
+ var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
982
+ var tokens, _yield$getNetworkConf, l1, l2, tokenAddresses, l2AddressesFromL1;
996
983
 
997
- case 6:
998
- if ((_step = _iterator()).done) {
999
- _context3.next = 20;
1000
- break;
1001
- }
984
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
985
+ while (1) {
986
+ switch (_context.prev = _context.next) {
987
+ case 0:
988
+ tokens = {};
989
+ _context.next = 3;
990
+ return getNetworkConfig();
991
+
992
+ case 3:
993
+ _yield$getNetworkConf = _context.sent;
994
+ l1 = _yield$getNetworkConf.l1;
995
+ l2 = _yield$getNetworkConf.l2;
996
+ tokenAddresses = this.l1TokenList.tokens.map(function (token) {
997
+ return token.address.toLowerCase();
998
+ });
999
+ _context.next = 9;
1000
+ return getL2TokenAddressesFromL1(tokenAddresses, l1.multiCaller, l2.network.tokenBridge.l1GatewayRouter);
1002
1001
 
1003
- uri = _step.value;
1004
- _context3.prev = 8;
1005
- _context3.next = 11;
1006
- return axios.get(uri);
1002
+ case 9:
1003
+ l2AddressesFromL1 = _context.sent;
1004
+ tokens = tokenAddresses.reduce(function (obj, key, index) {
1005
+ var _extends2;
1007
1006
 
1008
- case 11:
1009
- res = _context3.sent;
1007
+ return _extends({}, obj, (_extends2 = {}, _extends2[key] = l2AddressesFromL1[index], _extends2));
1008
+ }, {});
1009
+ return _context.abrupt("return", tokens);
1010
1010
 
1011
- if (!(res.status === 200)) {
1012
- _context3.next = 14;
1013
- break;
1014
- }
1011
+ case 12:
1012
+ case "end":
1013
+ return _context.stop();
1014
+ }
1015
+ }
1016
+ }, _callee, this);
1017
+ }));
1018
+
1019
+ function provide() {
1020
+ return _provide.apply(this, arguments);
1021
+ }
1022
+
1023
+ return provide;
1024
+ }();
1025
+
1026
+ return ArbitrumMappingProvider;
1027
+ }();
1015
1028
 
1016
- return _context3.abrupt("return", uri);
1029
+ function compareTokenInfos(t1, t2) {
1030
+ if (t1.chainId === t2.chainId) {
1031
+ return t1.symbol.toLowerCase() < t2.symbol.toLowerCase() ? -1 : 1;
1032
+ }
1017
1033
 
1018
- case 14:
1019
- _context3.next = 18;
1020
- break;
1034
+ return t1.chainId < t2.chainId ? -1 : 1;
1035
+ } // ref: https://github.com/OffchainLabs/arb-token-lists/blob/master/src/lib/utils.ts
1036
+
1037
+ function getTokenList(_x) {
1038
+ return _getTokenList.apply(this, arguments);
1039
+ }
1021
1040
 
1022
- case 16:
1023
- _context3.prev = 16;
1024
- _context3.t0 = _context3["catch"](8);
1041
+ function _getTokenList() {
1042
+ _getTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(l1TokenListOrPathOrUrl) {
1043
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
1044
+ while (1) {
1045
+ switch (_context5.prev = _context5.next) {
1046
+ case 0:
1047
+ if (!(typeof l1TokenListOrPathOrUrl === 'string')) {
1048
+ _context5.next = 4;
1049
+ break;
1050
+ }
1025
1051
 
1026
- case 18:
1027
- _context3.next = 6;
1028
- break;
1052
+ return _context5.abrupt("return", getTokenListObj(l1TokenListOrPathOrUrl));
1029
1053
 
1030
- case 20:
1031
- return _context3.abrupt("return");
1054
+ case 4:
1055
+ return _context5.abrupt("return", l1TokenListOrPathOrUrl);
1032
1056
 
1033
- case 21:
1057
+ case 5:
1034
1058
  case "end":
1035
- return _context3.stop();
1059
+ return _context5.stop();
1036
1060
  }
1037
1061
  }
1038
- }, _callee3, null, [[8, 16]]);
1062
+ }, _callee5);
1039
1063
  }));
1064
+ return _getTokenList.apply(this, arguments);
1065
+ }
1040
1066
 
1041
- return function getLogoUri(_x7) {
1042
- return _ref3.apply(this, arguments);
1043
- };
1044
- }();
1045
1067
  var getTokenListObjFromUrl = /*#__PURE__*/function () {
1046
- var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(url) {
1047
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
1068
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(url) {
1069
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1048
1070
  while (1) {
1049
- switch (_context4.prev = _context4.next) {
1071
+ switch (_context.prev = _context.next) {
1050
1072
  case 0:
1051
- _context4.next = 2;
1073
+ _context.next = 2;
1052
1074
  return axios.get(url);
1053
1075
 
1054
1076
  case 2:
1055
- return _context4.abrupt("return", _context4.sent.data);
1077
+ return _context.abrupt("return", _context.sent.data);
1056
1078
 
1057
1079
  case 3:
1058
1080
  case "end":
1059
- return _context4.stop();
1081
+ return _context.stop();
1060
1082
  }
1061
1083
  }
1062
- }, _callee4);
1084
+ }, _callee);
1063
1085
  }));
1064
1086
 
1065
- return function getTokenListObjFromUrl(_x8) {
1066
- return _ref4.apply(this, arguments);
1087
+ return function getTokenListObjFromUrl(_x2) {
1088
+ return _ref.apply(this, arguments);
1067
1089
  };
1068
1090
  }();
1069
1091
  var getTokenListObjFromLocalPath = /*#__PURE__*/function () {
1070
- var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(path) {
1071
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
1092
+ var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(path) {
1093
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1072
1094
  while (1) {
1073
- switch (_context5.prev = _context5.next) {
1095
+ switch (_context2.prev = _context2.next) {
1074
1096
  case 0:
1075
- return _context5.abrupt("return", JSON.parse(readFileSync(path).toString()));
1097
+ return _context2.abrupt("return", JSON.parse(readFileSync(path).toString()));
1076
1098
 
1077
1099
  case 1:
1078
1100
  case "end":
1079
- return _context5.stop();
1101
+ return _context2.stop();
1080
1102
  }
1081
1103
  }
1082
- }, _callee5);
1104
+ }, _callee2);
1083
1105
  }));
1084
1106
 
1085
- return function getTokenListObjFromLocalPath(_x9) {
1086
- return _ref5.apply(this, arguments);
1107
+ return function getTokenListObjFromLocalPath(_x3) {
1108
+ return _ref2.apply(this, arguments);
1087
1109
  };
1088
1110
  }();
1089
- var tokenListIsValid = function tokenListIsValid(tokenList) {
1090
- var ajv = new Ajv();
1091
- addFormats(ajv);
1092
- var validate = ajv.compile(schema);
1093
- var res = validate(tokenList);
1094
-
1095
- if (validate.errors) {
1096
- var output = betterAjvErrors(schema, tokenList, validate.errors, {
1097
- indent: 2
1098
- });
1099
- console.log(output);
1100
- }
1101
-
1102
- return res;
1103
- };
1104
- var validateTokenListWithErrorThrowing = function validateTokenListWithErrorThrowing(tokenList) {
1105
- try {
1106
- var valid = tokenListIsValid(tokenList);
1107
- if (valid) return true;else throw new Error('Data does not conform to token list schema; not sure why');
1108
- } catch (e) {
1109
- console.log('Invalid token list:');
1110
- throw e;
1111
- }
1112
- };
1113
1111
  var getTokenListObj = /*#__PURE__*/function () {
1114
- var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(pathOrUrl) {
1112
+ var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(pathOrUrl) {
1115
1113
  var tokenList;
1116
- return _regeneratorRuntime.wrap(function _callee7$(_context7) {
1114
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
1117
1115
  while (1) {
1118
- switch (_context7.prev = _context7.next) {
1116
+ switch (_context4.prev = _context4.next) {
1119
1117
  case 0:
1120
- _context7.next = 2;
1118
+ _context4.next = 2;
1121
1119
  return function () {
1122
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(pathOrUrl) {
1120
+ var _ref4 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(pathOrUrl) {
1123
1121
  var localFileExists, looksLikeUrl;
1124
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
1122
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
1125
1123
  while (1) {
1126
- switch (_context6.prev = _context6.next) {
1124
+ switch (_context3.prev = _context3.next) {
1127
1125
  case 0:
1128
1126
  localFileExists = existsSync(pathOrUrl);
1129
1127
  looksLikeUrl = isValidHttpUrl(pathOrUrl);
1130
1128
 
1131
1129
  if (!localFileExists) {
1132
- _context6.next = 6;
1130
+ _context3.next = 6;
1133
1131
  break;
1134
1132
  }
1135
1133
 
1136
- return _context6.abrupt("return", getTokenListObjFromLocalPath(pathOrUrl));
1134
+ return _context3.abrupt("return", getTokenListObjFromLocalPath(pathOrUrl));
1137
1135
 
1138
1136
  case 6:
1139
1137
  if (!looksLikeUrl) {
1140
- _context6.next = 12;
1138
+ _context3.next = 12;
1141
1139
  break;
1142
1140
  }
1143
1141
 
1144
- _context6.next = 9;
1142
+ _context3.next = 9;
1145
1143
  return getTokenListObjFromUrl(pathOrUrl);
1146
1144
 
1147
1145
  case 9:
1148
- return _context6.abrupt("return", _context6.sent);
1146
+ return _context3.abrupt("return", _context3.sent);
1149
1147
 
1150
1148
  case 12:
1151
1149
  throw new Error('Could not find token list');
1152
1150
 
1153
1151
  case 13:
1154
1152
  case "end":
1155
- return _context6.stop();
1153
+ return _context3.stop();
1156
1154
  }
1157
1155
  }
1158
- }, _callee6);
1156
+ }, _callee3);
1159
1157
  }));
1160
1158
 
1161
- return function (_x11) {
1162
- return _ref7.apply(this, arguments);
1159
+ return function (_x5) {
1160
+ return _ref4.apply(this, arguments);
1163
1161
  };
1164
1162
  }()(pathOrUrl);
1165
1163
 
1166
1164
  case 2:
1167
- tokenList = _context7.sent;
1165
+ tokenList = _context4.sent;
1168
1166
  isTokenList(tokenList);
1169
- return _context7.abrupt("return", tokenList);
1167
+ return _context4.abrupt("return", tokenList);
1170
1168
 
1171
1169
  case 5:
1172
1170
  case "end":
1173
- return _context7.stop();
1171
+ return _context4.stop();
1174
1172
  }
1175
1173
  }
1176
- }, _callee7);
1174
+ }, _callee4);
1177
1175
  }));
1178
1176
 
1179
- return function getTokenListObj(_x10) {
1180
- return _ref6.apply(this, arguments);
1177
+ return function getTokenListObj(_x4) {
1178
+ return _ref3.apply(this, arguments);
1181
1179
  };
1182
1180
  }(); // https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
1183
1181
 
@@ -1193,6 +1191,7 @@ function isValidHttpUrl(urlString) {
1193
1191
  return url.protocol === 'http:' || url.protocol === 'https:';
1194
1192
  } // typeguard:
1195
1193
 
1194
+
1196
1195
  var isTokenList = function isTokenList(obj) {
1197
1196
  var expectedListKeys = ['name', 'timestamp', 'version', 'tokens'];
1198
1197
  var actualListKeys = new Set(Object.keys(obj));
@@ -1200,7 +1199,7 @@ var isTokenList = function isTokenList(obj) {
1200
1199
  if (!expectedListKeys.every(function (key) {
1201
1200
  return actualListKeys.has(key);
1202
1201
  })) {
1203
- throw new Error("tokenlist typeguard error: requried list key not included");
1202
+ throw new Error('tokenlist typeguard error: required list key not included');
1204
1203
  }
1205
1204
 
1206
1205
  var version = obj.version,
@@ -1209,7 +1208,7 @@ var isTokenList = function isTokenList(obj) {
1209
1208
  if (!['major', 'minor', 'patch'].every(function (key) {
1210
1209
  return typeof version[key] === 'number';
1211
1210
  })) {
1212
- throw new Error("tokenlist typeguard error: invalid version");
1211
+ throw new Error('tokenlist typeguard error: invalid version');
1213
1212
  }
1214
1213
 
1215
1214
  if (!tokens.every(function (token) {
@@ -1218,625 +1217,123 @@ var isTokenList = function isTokenList(obj) {
1218
1217
  return tokenKeys.has(key);
1219
1218
  });
1220
1219
  })) {
1221
- throw new Error("tokenlist typeguard error: token missing required key");
1220
+ throw new Error('tokenlist typeguard error: token missing required key');
1222
1221
  }
1223
1222
  };
1224
- var sanitizeString = function sanitizeString(str) {
1225
- return str.replace(/[^ \w.'+\-%/À-ÖØ-öø-ÿ:&\[\]\(\)]/gi, '');
1226
- };
1227
- var excludeList = /*#__PURE__*/['0x0CE51000d5244F1EAac0B313a792D5a5f96931BF', '0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f', '0xEDA6eFE5556e134Ef52f2F858aa1e81c84CDA84b', '0xe54942077Df7b8EEf8D4e6bCe2f7B58B0082b0cd', '0x282db609e787a132391eb64820ba6129fceb2695', '0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3', '0x106538cc16f938776c7c180186975bca23875287', '0xB4A3B0Faf0Ab53df58001804DdA5Bfc6a3D59008' // spera
1228
- // "0x960b236a07cf122663c4303350609a66a7b288c0", //aragon old
1229
- ].map(function (s) {
1230
- return s.toLowerCase();
1231
- });
1232
1223
 
1233
- var _templateObject, _templateObject2;
1234
- var apolloL2GatewaysRinkebyClient = 'https://api.thegraph.com/subgraphs/name/fredlacs/layer2-token-gateway-rinkeby';
1235
- var apolloL2GatewaysClient = 'https://api.thegraph.com/subgraphs/name/fredlacs/layer2-token-gateway';
1224
+ var optimismTokenListURL = 'https://raw.githubusercontent.com/' + 'ethereum-optimism/ethereum-optimism.github.io/2138386277e4156d159615d1840882cecc398437/optimism.tokenlist.json';
1225
+ /**
1226
+ * The Optimism L2 mapping (linked above) is manually maintained by the Optimism team.
1227
+ *
1228
+ * This provider provides the l1->l2(Optimism) token mappings.
1229
+ */
1236
1230
 
1237
- var chaidIdToGraphClientUrl = function chaidIdToGraphClientUrl(chainID) {
1238
- switch (chainID) {
1239
- case '42161':
1240
- return apolloL2GatewaysClient;
1231
+ var OptimismMappingProvider = /*#__PURE__*/function () {
1232
+ function OptimismMappingProvider() {}
1241
1233
 
1242
- case '421611':
1243
- return apolloL2GatewaysRinkebyClient;
1234
+ var _proto = OptimismMappingProvider.prototype;
1244
1235
 
1245
- default:
1246
- throw new Error('Unsupported chain');
1247
- }
1248
- };
1236
+ _proto.provide = /*#__PURE__*/function () {
1237
+ var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1238
+ var tokens, optimismTokens, _iterator, _step, token, _token$extensions;
1249
1239
 
1250
- var isGraphTokenResult = function isGraphTokenResult(obj) {
1251
- if (!obj) {
1252
- throw new Error("Graph result: undefined");
1253
- }
1240
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1241
+ while (1) {
1242
+ switch (_context.prev = _context.next) {
1243
+ case 0:
1244
+ tokens = {};
1245
+ _context.next = 3;
1246
+ return getTokenList(optimismTokenListURL);
1254
1247
 
1255
- var expectedKeys = ["joinTableEntry", "l1TokenAddr"];
1256
- var actualKeys = new Set(Object.keys(obj));
1248
+ case 3:
1249
+ optimismTokens = _context.sent;
1257
1250
 
1258
- if (!expectedKeys.every(function (key) {
1259
- return actualKeys.has(key);
1260
- })) {
1261
- throw new Error("Graph result: missing top level key");
1262
- }
1251
+ for (_iterator = _createForOfIteratorHelperLoose(optimismTokens.tokens); !(_step = _iterator()).done;) {
1252
+ token = _step.value;
1263
1253
 
1264
- var joinTableEntry = obj.joinTableEntry[0];
1254
+ if (token.chainId === ChainId.MAINNET) {
1255
+ tokens[token.address.toLowerCase()] = token == null ? void 0 : (_token$extensions = token.extensions) == null ? void 0 : _token$extensions.bridgeInfo[ChainId.OPTIMISM].tokenAddress;
1256
+ }
1257
+ }
1265
1258
 
1266
- if (!joinTableEntry) {
1267
- throw new Error("Graph result: no joinTableEntry");
1268
- }
1259
+ return _context.abrupt("return", tokens);
1269
1260
 
1270
- if (!joinTableEntry.gateway.gatewayAddr) {
1271
- throw new Error("Graph result: could not get gateway address");
1272
- }
1273
- };
1261
+ case 6:
1262
+ case "end":
1263
+ return _context.stop();
1264
+ }
1265
+ }
1266
+ }, _callee);
1267
+ }));
1274
1268
 
1275
- var getTokens = /*#__PURE__*/function () {
1276
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenAddresses, networkID) {
1277
- var clientUrl, allTokens, allTokenAddresses, formattedAddresses, query, _yield$request, tokens;
1269
+ function provide() {
1270
+ return _provide.apply(this, arguments);
1271
+ }
1278
1272
 
1279
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1280
- while (1) {
1281
- switch (_context.prev = _context.next) {
1282
- case 0:
1283
- clientUrl = chaidIdToGraphClientUrl(networkID); // lazy solution for big lists for now; we'll have to paginate once we have > 500 tokens registed
1273
+ return provide;
1274
+ }();
1284
1275
 
1285
- if (!(l1TokenAddresses.length > 500)) {
1286
- _context.next = 9;
1287
- break;
1288
- }
1276
+ return OptimismMappingProvider;
1277
+ }();
1289
1278
 
1290
- _context.next = 4;
1291
- return getAllTokens(networkID);
1279
+ var url = 'https://tokenmapper.api.matic.today/api/v1/mapping?';
1280
+ var params = 'map_type=[%22POS%22]&chain_id=137&limit=200&offset=';
1281
+ /**
1282
+ * The Polygon team manually maintains the mapping via user submissions at
1283
+ * https://mapper.polygon.technology.
1284
+ *
1285
+ * This provider provides the l1->l2(Polygon) token mappings.
1286
+ */
1292
1287
 
1293
- case 4:
1294
- allTokens = _context.sent;
1295
- allTokenAddresses = new Set(allTokens.map(function (token) {
1296
- return token.l1TokenAddr.toLowerCase();
1297
- }));
1298
- l1TokenAddresses = l1TokenAddresses.filter(function (addr) {
1299
- return allTokenAddresses.has(addr.toLowerCase());
1300
- });
1288
+ var PolygonMappingProvider = /*#__PURE__*/function () {
1289
+ function PolygonMappingProvider() {}
1301
1290
 
1302
- if (!(l1TokenAddresses.length > 500)) {
1303
- _context.next = 9;
1304
- break;
1305
- }
1291
+ var _proto = PolygonMappingProvider.prototype;
1306
1292
 
1307
- throw new Error("Too many tokens for graph query");
1293
+ _proto.provide = /*#__PURE__*/function () {
1294
+ var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1295
+ var offset, tokens, response, _iterator, _step, token;
1308
1296
 
1309
- case 9:
1310
- formattedAddresses = l1TokenAddresses.map(function (a) {
1311
- return ("\"" + a + "\"").toLowerCase();
1312
- }).join(',');
1313
- query = gql(_templateObject || (_templateObject = _taggedTemplateLiteralLoose(["\n {\n tokens(first: 500, skip: 0, where:{\n id_in:[", "]\n }) {\n l1TokenAddr: id\n joinTableEntry: gateway(\n first: 1\n orderBy: blockNum\n orderDirection: desc\n ) {\n id\n blockNum\n token {\n tokenAddr: id\n }\n gateway {\n gatewayAddr: id\n }\n }\n }\n }\n"])), formattedAddresses);
1314
- _context.next = 13;
1315
- return request(clientUrl, query);
1297
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1298
+ while (1) {
1299
+ switch (_context.prev = _context.next) {
1300
+ case 0:
1301
+ offset = 0;
1302
+ tokens = {};
1316
1303
 
1317
- case 13:
1318
- _yield$request = _context.sent;
1319
- tokens = _yield$request.tokens;
1320
- tokens.map(function (token) {
1321
- return isGraphTokenResult(token);
1322
- });
1323
- return _context.abrupt("return", tokens.filter(function (token) {
1324
- return !excludeList.includes(token.l1TokenAddr.toLowerCase());
1325
- }));
1304
+ case 2:
1326
1305
 
1327
- case 17:
1328
- case "end":
1329
- return _context.stop();
1330
- }
1331
- }
1332
- }, _callee);
1333
- }));
1306
+ _context.next = 5;
1307
+ return axios.get("" + url + params + offset);
1334
1308
 
1335
- return function getTokens(_x, _x2) {
1336
- return _ref.apply(this, arguments);
1337
- };
1338
- }();
1339
- var getAllTokens = /*#__PURE__*/function () {
1340
- var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(networkID) {
1341
- var clientUrl, query, _yield$request2, tokens;
1342
-
1343
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1344
- while (1) {
1345
- switch (_context2.prev = _context2.next) {
1346
- case 0:
1347
- clientUrl = chaidIdToGraphClientUrl(networkID);
1348
- query = gql(_templateObject2 || (_templateObject2 = _taggedTemplateLiteralLoose(["\n {\n tokens(first: 500, skip: 0) {\n l1TokenAddr: id\n joinTableEntry: gateway(\n first: 1\n orderBy: blockNum\n orderDirection: desc\n ) {\n id\n blockNum\n token {\n tokenAddr: id\n }\n gateway {\n gatewayAddr: id\n }\n }\n }\n }\n "])));
1349
- _context2.next = 4;
1350
- return request(clientUrl, query);
1351
-
1352
- case 4:
1353
- _yield$request2 = _context2.sent;
1354
- tokens = _yield$request2.tokens;
1355
- tokens.map(function (token) {
1356
- return isGraphTokenResult(token);
1357
- });
1358
- return _context2.abrupt("return", tokens.filter(function (token) {
1359
- return !excludeList.includes(token.l1TokenAddr.toLowerCase());
1360
- }));
1361
-
1362
- case 8:
1363
- case "end":
1364
- return _context2.stop();
1365
- }
1366
- }
1367
- }, _callee2);
1368
- }));
1369
-
1370
- return function getAllTokens(_x3) {
1371
- return _ref2.apply(this, arguments);
1372
- };
1373
- }();
1374
-
1375
- /*
1376
- * Copyright 2021, Offchain Labs, Inc.
1377
- *
1378
- * Licensed under the Apache License, Version 2.0 (the "License");
1379
- * you may not use this file except in compliance with the License.
1380
- * You may obtain a copy of the License at
1381
- *
1382
- * http://www.apache.org/licenses/LICENSE-2.0
1383
- *
1384
- * Unless required by applicable law or agreed to in writing, software
1385
- * distributed under the License is distributed on an "AS IS" BASIS,
1386
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1387
- * See the License for the specific language governing permissions and
1388
- * limitations under the License.
1389
- */
1390
- var argv = /*#__PURE__*/yargs(process.argv.slice(2)).options({
1391
- l2NetworkID: {
1392
- type: 'number'
1393
- },
1394
- tokenList: {
1395
- type: 'string'
1396
- }
1397
- }).parseSync();
1398
-
1399
- var _args$l2NetworkID;
1400
- dotenv.config();
1401
- var networkID = ((_args$l2NetworkID = argv.l2NetworkID) == null ? void 0 : /*#__PURE__*/_args$l2NetworkID.toString()) || '42161';
1402
- console.log('Using L2 networkID:', networkID);
1403
- var getNetworkConfig = /*#__PURE__*/function () {
1404
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1405
- var l2Network, l1Network, arbProvider, ethProvider, l1MultiCaller, l2MultiCaller, tokenBridger;
1406
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1407
- while (1) {
1408
- switch (_context.prev = _context.next) {
1409
- case 0:
1410
- _context.next = 2;
1411
- return getL2Network(networkID);
1412
-
1413
- case 2:
1414
- l2Network = _context.sent;
1415
- _context.next = 5;
1416
- return getL1Network(l2Network.partnerChainID);
1417
-
1418
- case 5:
1419
- l1Network = _context.sent;
1420
- arbProvider = new providers.JsonRpcProvider(l2Network.rpcURL);
1421
- ethProvider = new providers.JsonRpcProvider(l1Network.rpcURL);
1422
- _context.next = 10;
1423
- return MultiCaller.fromProvider(ethProvider);
1424
-
1425
- case 10:
1426
- l1MultiCaller = _context.sent;
1427
- _context.next = 13;
1428
- return MultiCaller.fromProvider(arbProvider);
1429
-
1430
- case 13:
1431
- l2MultiCaller = _context.sent;
1432
- tokenBridger = new TokenBridger(l2Network);
1433
- return _context.abrupt("return", {
1434
- l1: {
1435
- network: l1Network,
1436
- provider: ethProvider,
1437
- multiCaller: l1MultiCaller
1438
- },
1439
- l2: {
1440
- network: l2Network,
1441
- provider: arbProvider,
1442
- multiCaller: l2MultiCaller
1443
- },
1444
- tokenBridger: tokenBridger
1445
- });
1446
-
1447
- case 16:
1448
- case "end":
1449
- return _context.stop();
1450
- }
1451
- }
1452
- }, _callee);
1453
- }));
1454
-
1455
- return function getNetworkConfig() {
1456
- return _ref.apply(this, arguments);
1457
- };
1458
- }();
1459
-
1460
- var l2ToL1GatewayAddresses = {
1461
- // L2 ERC20 Gateway mainnet
1462
- '0x09e9222e96e7b4ae2a407b98d48e330053351eee': '0xa3A7B6F88361F48403514059F1F16C8E78d60EeC',
1463
- // L2 Arb-Custom Gateway mainnet
1464
- '0x096760f208390250649e3e8763348e783aef5562': '0xcEe284F754E854890e311e3280b767F80797180d',
1465
- // L2 weth mainnet
1466
- '0x6c411ad3e74de3e7bd422b94a27770f5b86c623b': '0xd92023E9d9911199a6711321D1277285e6d4e2db',
1467
- // L2 dai gateway mainnet
1468
- '0x467194771dae2967aef3ecbedd3bf9a310c76c65': '0xd3b5b60020504bc3489d6949d545893982ba3011',
1469
- // L2 ERC20 Gateway rinkeby
1470
- "0x195c107f3f75c4c93eba7d9a1312f19305d6375f": "0x91169Dbb45e6804743F94609De50D511C437572E",
1471
- // L2 Arb-Custom Gateway rinkeby
1472
- "0x9b014455acc2fe90c52803849d0002aeec184a06": "0x917dc9a69F65dC3082D518192cd3725E1Fa96cA2",
1473
- // L2 Weth Gateway rinkeby
1474
- "0xf94bc045c4e926cc0b34e8d1c41cd7a043304ac9": "0x81d1a19cf7071732D4313c75dE8DD5b8CF697eFD",
1475
- // old L2 weth gateway in rinkeby? we can prob remove this
1476
- "0xf90eb31045d5b924900aff29344deb42eae0b087": "0x81d1a19cf7071732D4313c75dE8DD5b8CF697eFD",
1477
- // livepeer gateway mainnet
1478
- "0x6d2457a4ad276000a615295f7a80f79e48ccd318": "0x6142f1C8bBF02E6A6bd074E8d564c9A5420a0676"
1479
- };
1480
- var generateTokenList = /*#__PURE__*/function () {
1481
- var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenList, prevArbTokenList, options) {
1482
- var name, mainLogoUri, _yield$getNetworkConf, l1, l2, tokens, l1TokenAddresses, l2AddressesFromL1, l2AddressesFromL2, tokenData, logoUris, _iterator, _step, token, uri, arbifiedTokens, arbifiedTokenList, l1ArbedTokenList, l1AddressesOfBridgedTokens, unbridgedTokens, version, arbTokenList, validationTokenList;
1483
-
1484
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1485
- while (1) {
1486
- switch (_context.prev = _context.next) {
1487
- case 0:
1488
- if (!(options != null && options.includeAllL1Tokens && options.includeUnbridgedL1Tokens)) {
1489
- _context.next = 2;
1490
- break;
1491
- }
1492
-
1493
- throw new Error("Cannot include both of AllL1Tokens and UnbridgedL1Tokens since UnbridgedL1Tokens is a subset of AllL1Tokens.");
1494
-
1495
- case 2:
1496
- name = l1TokenList.name;
1497
- mainLogoUri = l1TokenList.logoURI;
1498
- _context.next = 6;
1499
- return getNetworkConfig();
1500
-
1501
- case 6:
1502
- _yield$getNetworkConf = _context.sent;
1503
- l1 = _yield$getNetworkConf.l1;
1504
- l2 = _yield$getNetworkConf.l2;
1505
-
1506
- if (!(options && options.getAllTokensInNetwork)) {
1507
- _context.next = 15;
1508
- break;
1509
- }
1510
-
1511
- _context.next = 12;
1512
- return getAllTokens(l2.network.chainID);
1513
-
1514
- case 12:
1515
- _context.t0 = _context.sent;
1516
- _context.next = 18;
1517
- break;
1518
-
1519
- case 15:
1520
- _context.next = 17;
1521
- return getTokens(l1TokenList.tokens.map(function (token) {
1522
- return token.address.toLowerCase();
1523
- }), l2.network.chainID);
1524
-
1525
- case 17:
1526
- _context.t0 = _context.sent;
1527
-
1528
- case 18:
1529
- tokens = _context.t0;
1530
- l1TokenAddresses = tokens.map(function (token) {
1531
- return token.l1TokenAddr;
1532
- });
1533
- _context.next = 22;
1534
- return getL2TokenAddressesFromL1(l1TokenAddresses, l1.multiCaller, l2.network.tokenBridge.l1GatewayRouter);
1535
-
1536
- case 22:
1537
- l2AddressesFromL1 = _context.sent;
1538
- _context.next = 25;
1539
- return getL2TokenAddressesFromL2(l1TokenAddresses, l2.multiCaller, l2.network.tokenBridge.l2GatewayRouter);
1540
-
1541
- case 25:
1542
- l2AddressesFromL2 = _context.sent;
1543
- // if the l2 route hasn't been updated yet we remove the token from the bridged tokens
1544
- tokens = tokens.filter(function (t, i) {
1545
- return l2AddressesFromL1[i] === l2AddressesFromL2[i];
1546
- });
1547
- _context.next = 29;
1548
- return l2.multiCaller.getTokenData(l2AddressesFromL1.map(function (t) {
1549
- return t || constants.AddressZero;
1550
- }), {
1551
- name: true,
1552
- decimals: true,
1553
- symbol: true
1554
- });
1555
-
1556
- case 29:
1557
- tokenData = _context.sent;
1558
- logoUris = [];
1559
- _iterator = _createForOfIteratorHelperLoose(tokens);
1560
-
1561
- case 32:
1562
- if ((_step = _iterator()).done) {
1563
- _context.next = 40;
1564
- break;
1565
- }
1566
-
1567
- token = _step.value;
1568
- _context.next = 36;
1569
- return getLogoUri(token.l1TokenAddr);
1570
-
1571
- case 36:
1572
- uri = _context.sent;
1573
- logoUris.push(uri);
1574
-
1575
- case 38:
1576
- _context.next = 32;
1577
- break;
1578
-
1579
- case 40:
1580
- arbifiedTokens = tokens.map(function (t, i) {
1581
- return {
1582
- token: t,
1583
- l2Address: l2AddressesFromL2[i],
1584
- tokenDatum: tokenData[i]
1585
- };
1586
- }) // it's possible that even though l2AddressesFromL1[i] === l2AddressesFromL2[i] these addresses could be the zero address
1587
- // this can happen if the graphql query returns an address that hasnt been bridged
1588
- .filter(function (t) {
1589
- return t.l2Address != undefined && t.l2Address !== constants.AddressZero;
1590
- }).map(function (token, i) {
1591
- var _bridgeInfo, _bridgeInfo2;
1592
-
1593
- var l2GatewayAddress = token.token.joinTableEntry[0].gateway.gatewayAddr;
1594
- var _token$tokenDatum = token.tokenDatum,
1595
- _name = _token$tokenDatum.name,
1596
- decimals = _token$tokenDatum.decimals,
1597
- _symbol = _token$tokenDatum.symbol;
1598
- if (decimals === undefined) throw new Error("Unexpected undefined token decimals: " + JSON.stringify(token));
1599
-
1600
- _name = function () {
1601
- if (_name === undefined) throw new Error("Unexpected undefined token name: " + JSON.stringify(token)); // if token name is empty, instead set the address as the name
1602
- // we remove the initial 0x since the token list standard only allows up to 40 characters
1603
- else if (_name === "") return token.token.l1TokenAddr.substring(2); // parse null terminated bytes32 strings
1604
- else if (_name.length === 64) return utils.parseBytes32String("0x" + _name);else return _name;
1605
- }();
1606
-
1607
- _symbol = function () {
1608
- if (_symbol === undefined) throw new Error("Unexpected undefined token symbol: " + JSON.stringify(token)); // schema doesn't allow for empty symbols, and has a max length of 20
1609
- else if (_symbol === "") return _name.substring(0, Math.min(_name.length, 20)); // parse null terminated bytes32 strings
1610
- else if (_symbol.length === 64) return utils.parseBytes32String("0x" + _symbol);else return _symbol;
1611
- }();
1612
-
1613
- var name = sanitizeString(_name);
1614
- var symbol = sanitizeString(_symbol);
1615
- var arbTokenInfo = {
1616
- chainId: +l2.network.chainID,
1617
- address: token.l2Address,
1618
- name: name,
1619
- symbol: symbol,
1620
- decimals: decimals,
1621
- extensions: {
1622
- bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[l1.network.chainID] = {
1623
- tokenAddress: token.token.l1TokenAddr,
1624
- originBridgeAddress: l2GatewayAddress,
1625
- destBridgeAddress: l2ToL1GatewayAddresses[l2GatewayAddress.toLowerCase()]
1626
- }, _bridgeInfo)
1627
- }
1628
- };
1629
- var l1TokenInfo = {
1630
- chainId: +l1.network.chainID,
1631
- address: token.token.l1TokenAddr,
1632
- name: name,
1633
- symbol: symbol,
1634
- decimals: decimals,
1635
- extensions: {
1636
- bridgeInfo: (_bridgeInfo2 = {}, _bridgeInfo2[l2.network.chainID] = {
1637
- tokenAddress: token.l2Address,
1638
- originBridgeAddress: l2ToL1GatewayAddresses[l2GatewayAddress.toLowerCase()],
1639
- destBridgeAddress: l2GatewayAddress
1640
- }, _bridgeInfo2)
1641
- }
1642
- };
1309
+ case 5:
1310
+ response = _context.sent;
1643
1311
 
1644
- if (logoUris[i]) {
1645
- arbTokenInfo = _extends({}, {
1646
- logoURI: logoUris[i]
1647
- }, arbTokenInfo);
1648
- } else {
1649
- console.log('no logo uri for ', token.token.l1TokenAddr, symbol);
1312
+ if (!(response.data.message === 'success')) {
1313
+ _context.next = 11;
1314
+ break;
1650
1315
  }
1651
1316
 
1652
- return {
1653
- arbTokenInfo: arbTokenInfo,
1654
- l1TokenInfo: l1TokenInfo
1655
- };
1656
- }).filter(function (_ref2) {
1657
- var arbTokenInfo = _ref2.arbTokenInfo;
1658
- return arbTokenInfo.extensions && arbTokenInfo.extensions.bridgeInfo[l1.network.chainID].originBridgeAddress !== constants$1.DISABLED_GATEWAY;
1659
- });
1660
- arbifiedTokenList = arbifiedTokens.map(function (_ref3) {
1661
- var arbTokenInfo = _ref3.arbTokenInfo;
1662
- return arbTokenInfo;
1663
- }).sort(function (a, b) {
1664
- return a.symbol < b.symbol ? -1 : 1;
1665
- });
1666
- l1ArbedTokenList = arbifiedTokens.map(function (_ref4) {
1667
- var l1TokenInfo = _ref4.l1TokenInfo;
1668
- return l1TokenInfo;
1669
- });
1670
- console.log("List has " + arbifiedTokenList.length + " bridged tokens");
1671
-
1672
- if (options != null && options.includeAllL1Tokens) {
1673
- arbifiedTokenList = arbifiedTokenList.concat(l1ArbedTokenList);
1674
- } else if (options != null && options.includeUnbridgedL1Tokens) {
1675
- l1AddressesOfBridgedTokens = new Set(tokens.map(function (token) {
1676
- return token.l1TokenAddr.toLowerCase();
1677
- }));
1678
- unbridgedTokens = l1ArbedTokenList.filter(function (l1TokenInfo) {
1679
- return !l1AddressesOfBridgedTokens.has(l1TokenInfo.address.toLowerCase()) && l1TokenInfo.chainId === +l1.network.chainID;
1680
- }).sort(function (a, b) {
1681
- return a.symbol < b.symbol ? -1 : 1;
1682
- });
1683
- console.log("List has " + unbridgedTokens.length + " unbridged tokens");
1684
- arbifiedTokenList = arbifiedTokenList.concat(unbridgedTokens);
1685
- }
1686
-
1687
- version = function () {
1688
- if (prevArbTokenList) {
1689
- // @ts-ignore
1690
- var versionBump = minVersionBump(prevArbTokenList.tokens, arbifiedTokenList); // tmp: library doesn't nicely handle patches (for extensions object)
1691
-
1692
- if (versionBump === VersionUpgrade.PATCH) {
1693
- versionBump = VersionUpgrade.NONE;
1694
- }
1695
-
1696
- return nextVersion(prevArbTokenList.version, versionBump);
1317
+ for (_iterator = _createForOfIteratorHelperLoose(response.data.data.mapping); !(_step = _iterator()).done;) {
1318
+ token = _step.value;
1319
+ tokens[token.root_token.toLowerCase()] = token;
1697
1320
  }
1698
1321
 
1699
- return {
1700
- major: 1,
1701
- minor: 0,
1702
- patch: 0
1703
- };
1704
- }();
1705
-
1706
- arbTokenList = {
1707
- name: listNameToArbifiedListName(name),
1708
- timestamp: new Date().toISOString(),
1709
- version: version,
1710
- tokens: arbifiedTokenList,
1711
- logoURI: mainLogoUri
1712
- };
1713
- validationTokenList = _extends({}, arbTokenList, {
1714
- tokens: arbTokenList.tokens
1715
- });
1716
- validateTokenListWithErrorThrowing(validationTokenList);
1717
- console.log("Generated list with total " + arbTokenList.tokens.length + " tokens");
1718
- console.log('version:', version);
1719
- return _context.abrupt("return", arbTokenList);
1720
-
1721
- case 52:
1722
- case "end":
1723
- return _context.stop();
1724
- }
1725
- }
1726
- }, _callee);
1727
- }));
1728
-
1729
- return function generateTokenList(_x, _x2, _x3) {
1730
- return _ref.apply(this, arguments);
1731
- };
1732
- }();
1733
-
1734
- function compareTokenInfos(t1, t2) {
1735
- if (t1.chainId === t2.chainId) {
1736
- return t1.symbol.toLowerCase() < t2.symbol.toLowerCase() ? -1 : 1;
1737
- }
1738
-
1739
- return t1.chainId < t2.chainId ? -1 : 1;
1740
- }
1741
- function getTokenList(_x) {
1742
- return _getTokenList.apply(this, arguments);
1743
- }
1744
-
1745
- function _getTokenList() {
1746
- _getTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenListOrPathOrUrl) {
1747
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1748
- while (1) {
1749
- switch (_context.prev = _context.next) {
1750
- case 0:
1751
- if (!(typeof l1TokenListOrPathOrUrl === 'string')) {
1752
- _context.next = 4;
1753
- break;
1754
- }
1755
-
1756
- return _context.abrupt("return", getTokenListObj(l1TokenListOrPathOrUrl));
1757
-
1758
- case 4:
1759
- return _context.abrupt("return", l1TokenListOrPathOrUrl);
1760
-
1761
- case 5:
1762
- case "end":
1763
- return _context.stop();
1764
- }
1765
- }
1766
- }, _callee);
1767
- }));
1768
- return _getTokenList.apply(this, arguments);
1769
- }
1770
-
1771
- /**
1772
- * The Arbitrum team maintains an (unpublished) package to `arbify` an L1
1773
- * token list.
1774
- *
1775
- * The provider simply invokes this package which we host as a submodule.
1776
- */
1777
-
1778
- var ArbitrumMappingProvider = /*#__PURE__*/function () {
1779
- function ArbitrumMappingProvider() {}
1780
-
1781
- var _proto = ArbitrumMappingProvider.prototype;
1782
-
1783
- _proto.provide = /*#__PURE__*/function () {
1784
- var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenList) {
1785
- var arbedTokenList;
1786
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1787
- while (1) {
1788
- switch (_context.prev = _context.next) {
1789
- case 0:
1790
- _context.next = 2;
1791
- return generateTokenList(l1TokenList,
1792
- /*prevArbTokenList=*/
1793
- undefined, {
1794
- includeAllL1Tokens: true
1795
- });
1796
-
1797
- case 2:
1798
- arbedTokenList = _context.sent;
1799
- return _context.abrupt("return", _extends({}, arbedTokenList, {
1800
- tokens: arbedTokenList.tokens.sort(compareTokenInfos)
1801
- }));
1802
-
1803
- case 4:
1804
- case "end":
1805
- return _context.stop();
1806
- }
1807
- }
1808
- }, _callee);
1809
- }));
1322
+ if (!(response.data.data.has_next_page === true)) {
1323
+ _context.next = 11;
1324
+ break;
1325
+ }
1810
1326
 
1811
- function provide(_x) {
1812
- return _provide.apply(this, arguments);
1813
- }
1327
+ offset += 200;
1328
+ return _context.abrupt("continue", 2);
1814
1329
 
1815
- return provide;
1816
- }();
1330
+ case 11:
1331
+ return _context.abrupt("break", 14);
1817
1332
 
1818
- return ArbitrumMappingProvider;
1819
- }();
1333
+ case 14:
1334
+ return _context.abrupt("return", tokens);
1820
1335
 
1821
- /**
1822
- * The Optimism L2 mapping is manually maintained by the Optimism team.
1823
- *
1824
- * This provider mostly no-ops, i.e. grabs the list and returns it.
1825
- */
1826
- var OptimismMappingProvider = /*#__PURE__*/function () {
1827
- function OptimismMappingProvider() {}
1828
-
1829
- var _proto = OptimismMappingProvider.prototype;
1830
-
1831
- _proto.provide = /*#__PURE__*/function () {
1832
- var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenList) {
1833
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1834
- while (1) {
1835
- switch (_context.prev = _context.next) {
1836
- case 0:
1837
- return _context.abrupt("return", l1TokenList);
1838
-
1839
- case 1:
1336
+ case 15:
1840
1337
  case "end":
1841
1338
  return _context.stop();
1842
1339
  }
@@ -1844,160 +1341,92 @@ var OptimismMappingProvider = /*#__PURE__*/function () {
1844
1341
  }, _callee);
1845
1342
  }));
1846
1343
 
1847
- function provide(_x) {
1344
+ function provide() {
1848
1345
  return _provide.apply(this, arguments);
1849
1346
  }
1850
1347
 
1851
1348
  return provide;
1852
1349
  }();
1853
1350
 
1854
- return OptimismMappingProvider;
1351
+ return PolygonMappingProvider;
1855
1352
  }();
1856
1353
 
1857
- /**
1858
- * The Polygon team manually maintains the mapping via user submissions at
1859
- * https://mapper.polygon.technology.
1860
- */
1861
-
1862
- var PolygonMappingProvider = /*#__PURE__*/function () {
1863
- function PolygonMappingProvider() {}
1864
-
1865
- var _proto = PolygonMappingProvider.prototype;
1354
+ function buildList(_x, _x2) {
1355
+ return _buildList.apply(this, arguments);
1356
+ }
1866
1357
 
1867
- _proto.provide = /*#__PURE__*/function () {
1868
- var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenList) {
1869
- var polygonTokens, mappedTokens, _iterator, _step, _bridgeInfo, _bridgeInfo2, _childToken$name, _childToken$symbol, rootToken, childToken, childTokenValid, toRootExtensions, toChildExtensions, rootTokenInfo, childTokenInfo, tokenList;
1358
+ function _buildList() {
1359
+ _buildList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(chainId, l1TokenList) {
1360
+ var tokenAddressMap, mappedTokens, _iterator, _step, rootToken, childToken, childTokenValid, _bridgeInfo, _bridgeInfo2, toRootExtensions, toChildExtensions, rootTokenInfo, childTokenInfo, tokenList;
1870
1361
 
1871
- return _regeneratorRuntime.wrap(function _callee$(_context) {
1872
- while (1) {
1873
- switch (_context.prev = _context.next) {
1874
- case 0:
1875
- _context.next = 2;
1876
- return fetchPolygonMappedTokens();
1362
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1363
+ while (1) {
1364
+ switch (_context.prev = _context.next) {
1365
+ case 0:
1366
+ _context.next = 2;
1367
+ return getMappingProvider(chainId, l1TokenList).provide();
1877
1368
 
1878
- case 2:
1879
- polygonTokens = _context.sent;
1880
- mappedTokens = [];
1369
+ case 2:
1370
+ tokenAddressMap = _context.sent;
1371
+ mappedTokens = [];
1881
1372
 
1882
- for (_iterator = _createForOfIteratorHelperLoose(l1TokenList.tokens); !(_step = _iterator()).done;) {
1883
- rootToken = _step.value;
1884
- childToken = polygonTokens[rootToken.address.toLowerCase()];
1885
- childTokenValid = Boolean(childToken && !childToken.deleted); // build extension info if available
1373
+ for (_iterator = _createForOfIteratorHelperLoose(l1TokenList.tokens); !(_step = _iterator()).done;) {
1374
+ rootToken = _step.value;
1375
+ childToken = tokenAddressMap[rootToken.address.toLowerCase()];
1376
+ childTokenValid = Boolean(childToken && (typeof childToken === 'object' ? !childToken.deleted : true));
1886
1377
 
1378
+ if (rootToken.chainId === ChainId.MAINNET) {
1379
+ // build extension info if available
1887
1380
  toRootExtensions = childTokenValid ? {
1888
1381
  extensions: {
1889
1382
  bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[rootToken.chainId] = {
1890
- tokenAddress: childToken.root_token
1383
+ tokenAddress: ethers.utils.getAddress(rootToken.address)
1891
1384
  }, _bridgeInfo)
1892
1385
  }
1893
1386
  } : {};
1894
1387
  toChildExtensions = childTokenValid ? {
1895
1388
  extensions: {
1896
- bridgeInfo: (_bridgeInfo2 = {}, _bridgeInfo2[childToken.chainId] = {
1897
- tokenAddress: childToken.child_token
1389
+ bridgeInfo: (_bridgeInfo2 = {}, _bridgeInfo2[chainId] = {
1390
+ tokenAddress: ethers.utils.getAddress(typeof childToken === 'object' ? childToken.child_token : childToken)
1898
1391
  }, _bridgeInfo2)
1899
1392
  }
1900
1393
  } : {};
1901
1394
  rootTokenInfo = _extends({}, rootToken, toChildExtensions);
1902
- childTokenInfo = _extends({}, rootToken, {
1903
- chainId: childToken.chainId,
1904
- name: (_childToken$name = childToken.name) != null ? _childToken$name : rootToken.name,
1905
- symbol: (_childToken$symbol = childToken.symbol) != null ? _childToken$symbol : rootToken.symbol,
1906
- address: childToken.child_token
1907
- }, toRootExtensions);
1908
- mappedTokens.push(rootTokenInfo);
1909
- mappedTokens.push(childTokenInfo);
1910
- }
1911
-
1912
- tokenList = {
1913
- name: "Polygon " + l1TokenList.name,
1914
- timestamp: new Date().toISOString(),
1915
- version: l1TokenList.version,
1916
- tokens: mappedTokens.sort(compareTokenInfos)
1917
- };
1918
- return _context.abrupt("return", tokenList);
1919
-
1920
- case 7:
1921
- case "end":
1922
- return _context.stop();
1923
- }
1924
- }
1925
- }, _callee);
1926
- }));
1927
-
1928
- function provide(_x) {
1929
- return _provide.apply(this, arguments);
1930
- }
1931
-
1932
- return provide;
1933
- }();
1934
-
1935
- return PolygonMappingProvider;
1936
- }();
1937
- var url = 'https://tokenmapper.api.matic.today/api/v1/mapping?';
1938
- var params = 'map_type=[%22POS%22]&chain_id=137&limit=200&offset=';
1939
-
1940
- function fetchPolygonMappedTokens() {
1941
- return _fetchPolygonMappedTokens.apply(this, arguments);
1942
- }
1943
1395
 
1944
- function _fetchPolygonMappedTokens() {
1945
- _fetchPolygonMappedTokens = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
1946
- var offset, tokens, response, _iterator2, _step2, token;
1947
-
1948
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1949
- while (1) {
1950
- switch (_context2.prev = _context2.next) {
1951
- case 0:
1952
- offset = 0;
1953
- tokens = {};
1954
-
1955
- case 2:
1956
-
1957
- _context2.next = 5;
1958
- return axios.get("" + url + params + offset);
1959
-
1960
- case 5:
1961
- response = _context2.sent;
1962
-
1963
- if (!(response.data.message === 'success')) {
1964
- _context2.next = 11;
1965
- break;
1966
- }
1967
-
1968
- for (_iterator2 = _createForOfIteratorHelperLoose(response.data.data.mapping); !(_step2 = _iterator2()).done;) {
1969
- token = _step2.value;
1970
- tokens[token.root_token.toLowerCase()] = token;
1971
- }
1396
+ if (childTokenValid) {
1397
+ childTokenInfo = _extends({}, rootToken, {
1398
+ chainId: chainId,
1399
+ address: ethers.utils.getAddress(typeof childToken === 'object' ? childToken.child_token : childToken)
1400
+ }, toRootExtensions);
1401
+ mappedTokens.push(childTokenInfo);
1402
+ }
1972
1403
 
1973
- if (!(response.data.data.has_next_page === true)) {
1974
- _context2.next = 11;
1975
- break;
1404
+ mappedTokens.push(rootTokenInfo);
1405
+ }
1976
1406
  }
1977
1407
 
1978
- offset += 200;
1979
- return _context2.abrupt("continue", 2);
1980
-
1981
- case 11:
1982
- return _context2.abrupt("break", 14);
1983
-
1984
- case 14:
1985
- return _context2.abrupt("return", tokens);
1408
+ tokenList = {
1409
+ name: "(ChainId: " + chainId + ") " + l1TokenList.name,
1410
+ timestamp: new Date().toISOString(),
1411
+ version: l1TokenList.version,
1412
+ tokens: mappedTokens.sort(compareTokenInfos)
1413
+ };
1414
+ return _context.abrupt("return", tokenList);
1986
1415
 
1987
- case 15:
1416
+ case 7:
1988
1417
  case "end":
1989
- return _context2.stop();
1418
+ return _context.stop();
1990
1419
  }
1991
1420
  }
1992
- }, _callee2);
1421
+ }, _callee);
1993
1422
  }));
1994
- return _fetchPolygonMappedTokens.apply(this, arguments);
1423
+ return _buildList.apply(this, arguments);
1995
1424
  }
1996
1425
 
1997
- function getMappingProvider(chainId) {
1426
+ function getMappingProvider(chainId, l1TokenList) {
1998
1427
  switch (chainId) {
1999
1428
  case ChainId.ARBITRUM_ONE:
2000
- return new ArbitrumMappingProvider();
1429
+ return new ArbitrumMappingProvider(l1TokenList);
2001
1430
 
2002
1431
  case ChainId.OPTIMISM:
2003
1432
  return new OptimismMappingProvider();
@@ -2135,36 +1564,35 @@ function chainifyTokenList(_x2, _x3) {
2135
1564
 
2136
1565
  function _chainifyTokenList() {
2137
1566
  _chainifyTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chainId, l1TokenListOrPathOrUrl) {
2138
- var tokenList;
1567
+ var l1TokenList, tokenList;
2139
1568
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
2140
1569
  while (1) {
2141
1570
  switch (_context2.prev = _context2.next) {
2142
1571
  case 0:
2143
1572
  _context2.prev = 0;
2144
- _context2.t0 = getMappingProvider(chainId);
2145
- _context2.next = 4;
1573
+ _context2.next = 3;
2146
1574
  return getTokenList(l1TokenListOrPathOrUrl);
2147
1575
 
2148
- case 4:
2149
- _context2.t1 = _context2.sent;
2150
- _context2.next = 7;
2151
- return _context2.t0.provide.call(_context2.t0, _context2.t1);
1576
+ case 3:
1577
+ l1TokenList = _context2.sent;
1578
+ _context2.next = 6;
1579
+ return buildList(chainId, l1TokenList);
2152
1580
 
2153
- case 7:
1581
+ case 6:
2154
1582
  tokenList = _context2.sent;
2155
1583
  return _context2.abrupt("return", verifyExtensions(tokenList));
2156
1584
 
2157
- case 11:
2158
- _context2.prev = 11;
2159
- _context2.t2 = _context2["catch"](0);
2160
- throw new Error("An error occured: " + _context2.t2);
1585
+ case 10:
1586
+ _context2.prev = 10;
1587
+ _context2.t0 = _context2["catch"](0);
1588
+ throw new Error("An error occured: " + _context2.t0);
2161
1589
 
2162
- case 14:
1590
+ case 13:
2163
1591
  case "end":
2164
1592
  return _context2.stop();
2165
1593
  }
2166
1594
  }
2167
- }, _callee2, null, [[0, 11]]);
1595
+ }, _callee2, null, [[0, 10]]);
2168
1596
  }));
2169
1597
  return _chainifyTokenList.apply(this, arguments);
2170
1598
  }
@@ -2186,7 +1614,6 @@ function mergeTokenLists(primary, secondary) {
2186
1614
 
2187
1615
  if ((_merged$extensions = merged.extensions) != null && _merged$extensions.bridgeInfo) {
2188
1616
  // remove reference to self-chain from merge
2189
- // @ts-expect-error TokenList schema doesn't yet define objects
2190
1617
  delete merged.extensions.bridgeInfo[merged.chainId];
2191
1618
  }
2192
1619