@uniswap/token-list-bridge-utils 1.0.7 → 1.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/abis/erc20.d.ts +3 -0
- package/dist/constants/chainId.d.ts +2 -1
- package/dist/constants/types.d.ts +3 -0
- package/dist/index.d.ts +2 -2
- package/dist/providers/ArbitrumMappingProvider.d.ts +2 -3
- package/dist/providers/MappingProvider.d.ts +2 -4
- package/dist/providers/OptimismMappingProvider.d.ts +2 -3
- package/dist/providers/index.d.ts +1 -1
- package/dist/token-list-bridge-utils.cjs.development.js +673 -237
- 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 +672 -237
- package/dist/token-list-bridge-utils.esm.js.map +1 -1
- package/dist/utils.d.ts +4 -0
- package/package.json +4 -2
- package/src/abis/erc20.ts +226 -0
- package/src/arbitrum/set_rpc.ts +4 -3
- package/src/constants/chainId.ts +2 -0
- package/src/constants/types.ts +5 -1
- package/src/index.test.ts +3 -3
- package/src/index.ts +9 -15
- package/src/providers/ArbitrumMappingProvider.ts +2 -1
- package/src/providers/MappingProvider.ts +2 -2
- package/src/providers/OptimismMappingProvider.ts +2 -1
- package/src/providers/index.ts +167 -62
- package/src/utils.ts +28 -0
|
@@ -4,10 +4,11 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var lodash = require('lodash');
|
|
6
6
|
var dotenv = require('dotenv');
|
|
7
|
-
var ethers = require('ethers');
|
|
8
|
-
var L1GatewayRouter__factory = require('@arbitrum/sdk/dist/lib/abi/factories/L1GatewayRouter__factory');
|
|
9
7
|
var fs = require('fs');
|
|
10
8
|
var axios = require('axios');
|
|
9
|
+
var ethers = require('ethers');
|
|
10
|
+
var L1GatewayRouter__factory = require('@arbitrum/sdk/dist/lib/abi/factories/L1GatewayRouter__factory');
|
|
11
|
+
var Web3 = require('web3');
|
|
11
12
|
|
|
12
13
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
14
|
|
|
@@ -30,6 +31,7 @@ function _interopNamespace(e) {
|
|
|
30
31
|
}
|
|
31
32
|
|
|
32
33
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
34
|
+
var Web3__default = /*#__PURE__*/_interopDefaultLegacy(Web3);
|
|
33
35
|
|
|
34
36
|
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
|
|
35
37
|
try {
|
|
@@ -894,175 +896,9 @@ var ChainId;
|
|
|
894
896
|
ChainId[ChainId["OPTIMISTIC_KOVAN"] = 69] = "OPTIMISTIC_KOVAN";
|
|
895
897
|
ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
|
|
896
898
|
ChainId[ChainId["POLYGON_MUMBAI"] = 80001] = "POLYGON_MUMBAI";
|
|
899
|
+
ChainId[ChainId["CELO"] = 42220] = "CELO";
|
|
897
900
|
})(ChainId || (ChainId = {}));
|
|
898
901
|
|
|
899
|
-
dotenv.config();
|
|
900
|
-
process.env.MAINNET_RPC = process.env.MAINNET_RPC || 'https://cloudflare-eth.com/';
|
|
901
|
-
|
|
902
|
-
var networkID = 42161; // ref: https://github.com/OffchainLabs/arb-token-lists/blob/master/src/lib/instantiate_bridge.ts
|
|
903
|
-
|
|
904
|
-
var getNetworkConfig = /*#__PURE__*/function () {
|
|
905
|
-
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
906
|
-
var _yield$import, getL1Network, getL2Network, MultiCaller, l2Network, l1Network, arbProvider, ethProvider, l1MultiCaller, l2MultiCaller;
|
|
907
|
-
|
|
908
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
909
|
-
while (1) {
|
|
910
|
-
switch (_context.prev = _context.next) {
|
|
911
|
-
case 0:
|
|
912
|
-
_context.next = 2;
|
|
913
|
-
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@arbitrum/sdk')); });
|
|
914
|
-
|
|
915
|
-
case 2:
|
|
916
|
-
_yield$import = _context.sent;
|
|
917
|
-
getL1Network = _yield$import.getL1Network;
|
|
918
|
-
getL2Network = _yield$import.getL2Network;
|
|
919
|
-
MultiCaller = _yield$import.MultiCaller;
|
|
920
|
-
_context.next = 8;
|
|
921
|
-
return getL2Network(networkID);
|
|
922
|
-
|
|
923
|
-
case 8:
|
|
924
|
-
l2Network = _context.sent;
|
|
925
|
-
_context.next = 11;
|
|
926
|
-
return getL1Network(l2Network.partnerChainID);
|
|
927
|
-
|
|
928
|
-
case 11:
|
|
929
|
-
l1Network = _context.sent;
|
|
930
|
-
arbProvider = new ethers.providers.JsonRpcProvider(l2Network.rpcURL);
|
|
931
|
-
ethProvider = new ethers.providers.JsonRpcProvider(l1Network.rpcURL);
|
|
932
|
-
_context.next = 16;
|
|
933
|
-
return MultiCaller.fromProvider(ethProvider);
|
|
934
|
-
|
|
935
|
-
case 16:
|
|
936
|
-
l1MultiCaller = _context.sent;
|
|
937
|
-
_context.next = 19;
|
|
938
|
-
return MultiCaller.fromProvider(arbProvider);
|
|
939
|
-
|
|
940
|
-
case 19:
|
|
941
|
-
l2MultiCaller = _context.sent;
|
|
942
|
-
return _context.abrupt("return", {
|
|
943
|
-
l1: {
|
|
944
|
-
network: l1Network,
|
|
945
|
-
provider: ethProvider,
|
|
946
|
-
multiCaller: l1MultiCaller
|
|
947
|
-
},
|
|
948
|
-
l2: {
|
|
949
|
-
network: l2Network,
|
|
950
|
-
provider: arbProvider,
|
|
951
|
-
multiCaller: l2MultiCaller
|
|
952
|
-
}
|
|
953
|
-
});
|
|
954
|
-
|
|
955
|
-
case 21:
|
|
956
|
-
case "end":
|
|
957
|
-
return _context.stop();
|
|
958
|
-
}
|
|
959
|
-
}
|
|
960
|
-
}, _callee);
|
|
961
|
-
}));
|
|
962
|
-
|
|
963
|
-
return function getNetworkConfig() {
|
|
964
|
-
return _ref.apply(this, arguments);
|
|
965
|
-
};
|
|
966
|
-
}();
|
|
967
|
-
|
|
968
|
-
var getL2TokenAddressesFromL1 = /*#__PURE__*/function () {
|
|
969
|
-
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenAddresses, multiCaller, l1GatewayRouterAddress) {
|
|
970
|
-
var iFace;
|
|
971
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
972
|
-
while (1) {
|
|
973
|
-
switch (_context.prev = _context.next) {
|
|
974
|
-
case 0:
|
|
975
|
-
iFace = L1GatewayRouter__factory.L1GatewayRouter__factory.createInterface();
|
|
976
|
-
_context.next = 3;
|
|
977
|
-
return multiCaller.multiCall(l1TokenAddresses.map(function (addr) {
|
|
978
|
-
return {
|
|
979
|
-
encoder: function encoder() {
|
|
980
|
-
return iFace.encodeFunctionData('calculateL2TokenAddress', [addr]);
|
|
981
|
-
},
|
|
982
|
-
decoder: function decoder(returnData) {
|
|
983
|
-
return iFace.decodeFunctionResult('calculateL2TokenAddress', returnData)[0];
|
|
984
|
-
},
|
|
985
|
-
targetAddr: l1GatewayRouterAddress
|
|
986
|
-
};
|
|
987
|
-
}));
|
|
988
|
-
|
|
989
|
-
case 3:
|
|
990
|
-
return _context.abrupt("return", _context.sent);
|
|
991
|
-
|
|
992
|
-
case 4:
|
|
993
|
-
case "end":
|
|
994
|
-
return _context.stop();
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
}, _callee);
|
|
998
|
-
}));
|
|
999
|
-
|
|
1000
|
-
return function getL2TokenAddressesFromL1(_x, _x2, _x3) {
|
|
1001
|
-
return _ref.apply(this, arguments);
|
|
1002
|
-
};
|
|
1003
|
-
}();
|
|
1004
|
-
|
|
1005
|
-
/**
|
|
1006
|
-
* This provider provides the l1->l2(Arbitrum) address mappings using the arbitrum SDK.
|
|
1007
|
-
*/
|
|
1008
|
-
|
|
1009
|
-
var ArbitrumMappingProvider = /*#__PURE__*/function () {
|
|
1010
|
-
function ArbitrumMappingProvider(l1TokenList) {
|
|
1011
|
-
this.l1TokenList = void 0;
|
|
1012
|
-
this.l1TokenList = l1TokenList;
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
var _proto = ArbitrumMappingProvider.prototype;
|
|
1016
|
-
|
|
1017
|
-
_proto.provide = /*#__PURE__*/function () {
|
|
1018
|
-
var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
1019
|
-
var tokens, _yield$getNetworkConf, l1, l2, tokenAddresses, l2AddressesFromL1;
|
|
1020
|
-
|
|
1021
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1022
|
-
while (1) {
|
|
1023
|
-
switch (_context.prev = _context.next) {
|
|
1024
|
-
case 0:
|
|
1025
|
-
tokens = {};
|
|
1026
|
-
_context.next = 3;
|
|
1027
|
-
return getNetworkConfig();
|
|
1028
|
-
|
|
1029
|
-
case 3:
|
|
1030
|
-
_yield$getNetworkConf = _context.sent;
|
|
1031
|
-
l1 = _yield$getNetworkConf.l1;
|
|
1032
|
-
l2 = _yield$getNetworkConf.l2;
|
|
1033
|
-
tokenAddresses = this.l1TokenList.tokens.map(function (token) {
|
|
1034
|
-
return token.address.toLowerCase();
|
|
1035
|
-
});
|
|
1036
|
-
_context.next = 9;
|
|
1037
|
-
return getL2TokenAddressesFromL1(tokenAddresses, l1.multiCaller, l2.network.tokenBridge.l1GatewayRouter);
|
|
1038
|
-
|
|
1039
|
-
case 9:
|
|
1040
|
-
l2AddressesFromL1 = _context.sent;
|
|
1041
|
-
tokens = tokenAddresses.reduce(function (obj, key, index) {
|
|
1042
|
-
var _extends2;
|
|
1043
|
-
|
|
1044
|
-
return _extends({}, obj, (_extends2 = {}, _extends2[key] = l2AddressesFromL1[index], _extends2));
|
|
1045
|
-
}, {});
|
|
1046
|
-
return _context.abrupt("return", tokens);
|
|
1047
|
-
|
|
1048
|
-
case 12:
|
|
1049
|
-
case "end":
|
|
1050
|
-
return _context.stop();
|
|
1051
|
-
}
|
|
1052
|
-
}
|
|
1053
|
-
}, _callee, this);
|
|
1054
|
-
}));
|
|
1055
|
-
|
|
1056
|
-
function provide() {
|
|
1057
|
-
return _provide.apply(this, arguments);
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
return provide;
|
|
1061
|
-
}();
|
|
1062
|
-
|
|
1063
|
-
return ArbitrumMappingProvider;
|
|
1064
|
-
}();
|
|
1065
|
-
|
|
1066
902
|
function compareTokenInfos(t1, t2) {
|
|
1067
903
|
if (t1.chainId === t2.chainId) {
|
|
1068
904
|
return t1.symbol.toLowerCase() < t2.symbol.toLowerCase() ? -1 : 1;
|
|
@@ -1257,6 +1093,229 @@ var isTokenList = function isTokenList(obj) {
|
|
|
1257
1093
|
throw new Error('tokenlist typeguard error: token missing required key');
|
|
1258
1094
|
}
|
|
1259
1095
|
};
|
|
1096
|
+
function getRpcUrl(chainId) {
|
|
1097
|
+
switch (chainId) {
|
|
1098
|
+
case ChainId.MAINNET:
|
|
1099
|
+
return 'https://cloudflare-eth.com/';
|
|
1100
|
+
|
|
1101
|
+
case ChainId.OPTIMISM:
|
|
1102
|
+
return 'https://rpc.ankr.com/optimism';
|
|
1103
|
+
// seems to have higher rate limit than https://mainnet.optimism.io/
|
|
1104
|
+
|
|
1105
|
+
case ChainId.OPTIMISTIC_KOVAN:
|
|
1106
|
+
return 'https://kovan.optimism.io';
|
|
1107
|
+
|
|
1108
|
+
case ChainId.ARBITRUM_ONE:
|
|
1109
|
+
return 'https://arb1.arbitrum.io/rpc';
|
|
1110
|
+
|
|
1111
|
+
case ChainId.ARBITRUM_RINKEBY:
|
|
1112
|
+
return 'https://rinkeby.arbitrum.io/rpc';
|
|
1113
|
+
|
|
1114
|
+
case ChainId.POLYGON:
|
|
1115
|
+
return 'https://polygon-rpc.com/';
|
|
1116
|
+
|
|
1117
|
+
case ChainId.POLYGON_MUMBAI:
|
|
1118
|
+
return 'https://rpc-endpoints.superfluid.dev/mumbai';
|
|
1119
|
+
}
|
|
1120
|
+
|
|
1121
|
+
throw new Error('Unsupported ChainId');
|
|
1122
|
+
}
|
|
1123
|
+
function getTokenSymbolFromContract(_x6) {
|
|
1124
|
+
return _getTokenSymbolFromContract.apply(this, arguments);
|
|
1125
|
+
}
|
|
1126
|
+
|
|
1127
|
+
function _getTokenSymbolFromContract() {
|
|
1128
|
+
_getTokenSymbolFromContract = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(tokenContract) {
|
|
1129
|
+
var symbol;
|
|
1130
|
+
return _regeneratorRuntime.wrap(function _callee6$(_context6) {
|
|
1131
|
+
while (1) {
|
|
1132
|
+
switch (_context6.prev = _context6.next) {
|
|
1133
|
+
case 0:
|
|
1134
|
+
_context6.next = 2;
|
|
1135
|
+
return Promise.all([tokenContract.methods.symbol().call()]);
|
|
1136
|
+
|
|
1137
|
+
case 2:
|
|
1138
|
+
symbol = _context6.sent;
|
|
1139
|
+
return _context6.abrupt("return", symbol);
|
|
1140
|
+
|
|
1141
|
+
case 4:
|
|
1142
|
+
case "end":
|
|
1143
|
+
return _context6.stop();
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
}, _callee6);
|
|
1147
|
+
}));
|
|
1148
|
+
return _getTokenSymbolFromContract.apply(this, arguments);
|
|
1149
|
+
}
|
|
1150
|
+
|
|
1151
|
+
var _process$env, _process$env$MAINNET_;
|
|
1152
|
+
|
|
1153
|
+
dotenv.config();
|
|
1154
|
+
(_process$env$MAINNET_ = (_process$env = process.env).MAINNET_RPC) != null ? _process$env$MAINNET_ : _process$env.MAINNET_RPC = /*#__PURE__*/getRpcUrl(ChainId.MAINNET);
|
|
1155
|
+
|
|
1156
|
+
var networkID = 42161; // ref: https://github.com/OffchainLabs/arb-token-lists/blob/master/src/lib/instantiate_bridge.ts
|
|
1157
|
+
|
|
1158
|
+
var getNetworkConfig = /*#__PURE__*/function () {
|
|
1159
|
+
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
1160
|
+
var _yield$import, getL1Network, getL2Network, MultiCaller, l2Network, l1Network, arbProvider, ethProvider, l1MultiCaller, l2MultiCaller;
|
|
1161
|
+
|
|
1162
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1163
|
+
while (1) {
|
|
1164
|
+
switch (_context.prev = _context.next) {
|
|
1165
|
+
case 0:
|
|
1166
|
+
_context.next = 2;
|
|
1167
|
+
return Promise.resolve().then(function () { return /*#__PURE__*/_interopNamespace(require('@arbitrum/sdk')); });
|
|
1168
|
+
|
|
1169
|
+
case 2:
|
|
1170
|
+
_yield$import = _context.sent;
|
|
1171
|
+
getL1Network = _yield$import.getL1Network;
|
|
1172
|
+
getL2Network = _yield$import.getL2Network;
|
|
1173
|
+
MultiCaller = _yield$import.MultiCaller;
|
|
1174
|
+
_context.next = 8;
|
|
1175
|
+
return getL2Network(networkID);
|
|
1176
|
+
|
|
1177
|
+
case 8:
|
|
1178
|
+
l2Network = _context.sent;
|
|
1179
|
+
_context.next = 11;
|
|
1180
|
+
return getL1Network(l2Network.partnerChainID);
|
|
1181
|
+
|
|
1182
|
+
case 11:
|
|
1183
|
+
l1Network = _context.sent;
|
|
1184
|
+
arbProvider = new ethers.providers.JsonRpcProvider(l2Network.rpcURL);
|
|
1185
|
+
ethProvider = new ethers.providers.JsonRpcProvider(l1Network.rpcURL);
|
|
1186
|
+
_context.next = 16;
|
|
1187
|
+
return MultiCaller.fromProvider(ethProvider);
|
|
1188
|
+
|
|
1189
|
+
case 16:
|
|
1190
|
+
l1MultiCaller = _context.sent;
|
|
1191
|
+
_context.next = 19;
|
|
1192
|
+
return MultiCaller.fromProvider(arbProvider);
|
|
1193
|
+
|
|
1194
|
+
case 19:
|
|
1195
|
+
l2MultiCaller = _context.sent;
|
|
1196
|
+
return _context.abrupt("return", {
|
|
1197
|
+
l1: {
|
|
1198
|
+
network: l1Network,
|
|
1199
|
+
provider: ethProvider,
|
|
1200
|
+
multiCaller: l1MultiCaller
|
|
1201
|
+
},
|
|
1202
|
+
l2: {
|
|
1203
|
+
network: l2Network,
|
|
1204
|
+
provider: arbProvider,
|
|
1205
|
+
multiCaller: l2MultiCaller
|
|
1206
|
+
}
|
|
1207
|
+
});
|
|
1208
|
+
|
|
1209
|
+
case 21:
|
|
1210
|
+
case "end":
|
|
1211
|
+
return _context.stop();
|
|
1212
|
+
}
|
|
1213
|
+
}
|
|
1214
|
+
}, _callee);
|
|
1215
|
+
}));
|
|
1216
|
+
|
|
1217
|
+
return function getNetworkConfig() {
|
|
1218
|
+
return _ref.apply(this, arguments);
|
|
1219
|
+
};
|
|
1220
|
+
}();
|
|
1221
|
+
|
|
1222
|
+
var getL2TokenAddressesFromL1 = /*#__PURE__*/function () {
|
|
1223
|
+
var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenAddresses, multiCaller, l1GatewayRouterAddress) {
|
|
1224
|
+
var iFace;
|
|
1225
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1226
|
+
while (1) {
|
|
1227
|
+
switch (_context.prev = _context.next) {
|
|
1228
|
+
case 0:
|
|
1229
|
+
iFace = L1GatewayRouter__factory.L1GatewayRouter__factory.createInterface();
|
|
1230
|
+
_context.next = 3;
|
|
1231
|
+
return multiCaller.multiCall(l1TokenAddresses.map(function (addr) {
|
|
1232
|
+
return {
|
|
1233
|
+
encoder: function encoder() {
|
|
1234
|
+
return iFace.encodeFunctionData('calculateL2TokenAddress', [addr]);
|
|
1235
|
+
},
|
|
1236
|
+
decoder: function decoder(returnData) {
|
|
1237
|
+
return iFace.decodeFunctionResult('calculateL2TokenAddress', returnData)[0];
|
|
1238
|
+
},
|
|
1239
|
+
targetAddr: l1GatewayRouterAddress
|
|
1240
|
+
};
|
|
1241
|
+
}));
|
|
1242
|
+
|
|
1243
|
+
case 3:
|
|
1244
|
+
return _context.abrupt("return", _context.sent);
|
|
1245
|
+
|
|
1246
|
+
case 4:
|
|
1247
|
+
case "end":
|
|
1248
|
+
return _context.stop();
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
}, _callee);
|
|
1252
|
+
}));
|
|
1253
|
+
|
|
1254
|
+
return function getL2TokenAddressesFromL1(_x, _x2, _x3) {
|
|
1255
|
+
return _ref.apply(this, arguments);
|
|
1256
|
+
};
|
|
1257
|
+
}();
|
|
1258
|
+
|
|
1259
|
+
/**
|
|
1260
|
+
* This provider provides the l1->l2(Arbitrum) address mappings using the arbitrum SDK.
|
|
1261
|
+
*/
|
|
1262
|
+
|
|
1263
|
+
var ArbitrumMappingProvider = /*#__PURE__*/function () {
|
|
1264
|
+
function ArbitrumMappingProvider(l1TokenList) {
|
|
1265
|
+
this.l1TokenList = void 0;
|
|
1266
|
+
this.l1TokenList = l1TokenList;
|
|
1267
|
+
}
|
|
1268
|
+
|
|
1269
|
+
var _proto = ArbitrumMappingProvider.prototype;
|
|
1270
|
+
|
|
1271
|
+
_proto.provide = /*#__PURE__*/function () {
|
|
1272
|
+
var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
1273
|
+
var tokens, _yield$getNetworkConf, l1, l2, tokenAddresses, l2AddressesFromL1;
|
|
1274
|
+
|
|
1275
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1276
|
+
while (1) {
|
|
1277
|
+
switch (_context.prev = _context.next) {
|
|
1278
|
+
case 0:
|
|
1279
|
+
tokens = {};
|
|
1280
|
+
_context.next = 3;
|
|
1281
|
+
return getNetworkConfig();
|
|
1282
|
+
|
|
1283
|
+
case 3:
|
|
1284
|
+
_yield$getNetworkConf = _context.sent;
|
|
1285
|
+
l1 = _yield$getNetworkConf.l1;
|
|
1286
|
+
l2 = _yield$getNetworkConf.l2;
|
|
1287
|
+
tokenAddresses = this.l1TokenList.tokens.map(function (token) {
|
|
1288
|
+
return token.address.toLowerCase();
|
|
1289
|
+
});
|
|
1290
|
+
_context.next = 9;
|
|
1291
|
+
return getL2TokenAddressesFromL1(tokenAddresses, l1.multiCaller, l2.network.tokenBridge.l1GatewayRouter);
|
|
1292
|
+
|
|
1293
|
+
case 9:
|
|
1294
|
+
l2AddressesFromL1 = _context.sent;
|
|
1295
|
+
tokens = tokenAddresses.reduce(function (obj, key, index) {
|
|
1296
|
+
var _extends2;
|
|
1297
|
+
|
|
1298
|
+
return _extends({}, obj, (_extends2 = {}, _extends2[key] = l2AddressesFromL1[index], _extends2));
|
|
1299
|
+
}, {});
|
|
1300
|
+
return _context.abrupt("return", tokens);
|
|
1301
|
+
|
|
1302
|
+
case 12:
|
|
1303
|
+
case "end":
|
|
1304
|
+
return _context.stop();
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}, _callee, this);
|
|
1308
|
+
}));
|
|
1309
|
+
|
|
1310
|
+
function provide() {
|
|
1311
|
+
return _provide.apply(this, arguments);
|
|
1312
|
+
}
|
|
1313
|
+
|
|
1314
|
+
return provide;
|
|
1315
|
+
}();
|
|
1316
|
+
|
|
1317
|
+
return ArbitrumMappingProvider;
|
|
1318
|
+
}();
|
|
1260
1319
|
|
|
1261
1320
|
var optimismTokenListURL = 'https://raw.githubusercontent.com/' + 'ethereum-optimism/ethereum-optimism.github.io/2138386277e4156d159615d1840882cecc398437/optimism.tokenlist.json';
|
|
1262
1321
|
/**
|
|
@@ -1388,78 +1447,351 @@ var PolygonMappingProvider = /*#__PURE__*/function () {
|
|
|
1388
1447
|
return PolygonMappingProvider;
|
|
1389
1448
|
}();
|
|
1390
1449
|
|
|
1450
|
+
var abi = [{
|
|
1451
|
+
constant: true,
|
|
1452
|
+
inputs: [],
|
|
1453
|
+
name: 'name',
|
|
1454
|
+
outputs: [{
|
|
1455
|
+
name: '',
|
|
1456
|
+
type: 'string'
|
|
1457
|
+
}],
|
|
1458
|
+
payable: false,
|
|
1459
|
+
stateMutability: 'view',
|
|
1460
|
+
type: 'function'
|
|
1461
|
+
}, {
|
|
1462
|
+
constant: false,
|
|
1463
|
+
inputs: [{
|
|
1464
|
+
name: '_spender',
|
|
1465
|
+
type: 'address'
|
|
1466
|
+
}, {
|
|
1467
|
+
name: '_value',
|
|
1468
|
+
type: 'uint256'
|
|
1469
|
+
}],
|
|
1470
|
+
name: 'approve',
|
|
1471
|
+
outputs: [{
|
|
1472
|
+
name: '',
|
|
1473
|
+
type: 'bool'
|
|
1474
|
+
}],
|
|
1475
|
+
payable: false,
|
|
1476
|
+
stateMutability: 'nonpayable',
|
|
1477
|
+
type: 'function'
|
|
1478
|
+
}, {
|
|
1479
|
+
constant: true,
|
|
1480
|
+
inputs: [],
|
|
1481
|
+
name: 'totalSupply',
|
|
1482
|
+
outputs: [{
|
|
1483
|
+
name: '',
|
|
1484
|
+
type: 'uint256'
|
|
1485
|
+
}],
|
|
1486
|
+
payable: false,
|
|
1487
|
+
stateMutability: 'view',
|
|
1488
|
+
type: 'function'
|
|
1489
|
+
}, {
|
|
1490
|
+
constant: false,
|
|
1491
|
+
inputs: [{
|
|
1492
|
+
name: '_from',
|
|
1493
|
+
type: 'address'
|
|
1494
|
+
}, {
|
|
1495
|
+
name: '_to',
|
|
1496
|
+
type: 'address'
|
|
1497
|
+
}, {
|
|
1498
|
+
name: '_value',
|
|
1499
|
+
type: 'uint256'
|
|
1500
|
+
}],
|
|
1501
|
+
name: 'transferFrom',
|
|
1502
|
+
outputs: [{
|
|
1503
|
+
name: '',
|
|
1504
|
+
type: 'bool'
|
|
1505
|
+
}],
|
|
1506
|
+
payable: false,
|
|
1507
|
+
stateMutability: 'nonpayable',
|
|
1508
|
+
type: 'function'
|
|
1509
|
+
}, {
|
|
1510
|
+
constant: true,
|
|
1511
|
+
inputs: [],
|
|
1512
|
+
name: 'decimals',
|
|
1513
|
+
outputs: [{
|
|
1514
|
+
name: '',
|
|
1515
|
+
type: 'uint8'
|
|
1516
|
+
}],
|
|
1517
|
+
payable: false,
|
|
1518
|
+
stateMutability: 'view',
|
|
1519
|
+
type: 'function'
|
|
1520
|
+
}, {
|
|
1521
|
+
constant: true,
|
|
1522
|
+
inputs: [{
|
|
1523
|
+
name: '_owner',
|
|
1524
|
+
type: 'address'
|
|
1525
|
+
}],
|
|
1526
|
+
name: 'balanceOf',
|
|
1527
|
+
outputs: [{
|
|
1528
|
+
name: 'balance',
|
|
1529
|
+
type: 'uint256'
|
|
1530
|
+
}],
|
|
1531
|
+
payable: false,
|
|
1532
|
+
stateMutability: 'view',
|
|
1533
|
+
type: 'function'
|
|
1534
|
+
}, {
|
|
1535
|
+
constant: true,
|
|
1536
|
+
inputs: [],
|
|
1537
|
+
name: 'symbol',
|
|
1538
|
+
outputs: [{
|
|
1539
|
+
name: '',
|
|
1540
|
+
type: 'string'
|
|
1541
|
+
}],
|
|
1542
|
+
payable: false,
|
|
1543
|
+
stateMutability: 'view',
|
|
1544
|
+
type: 'function'
|
|
1545
|
+
}, {
|
|
1546
|
+
constant: false,
|
|
1547
|
+
inputs: [{
|
|
1548
|
+
name: '_to',
|
|
1549
|
+
type: 'address'
|
|
1550
|
+
}, {
|
|
1551
|
+
name: '_value',
|
|
1552
|
+
type: 'uint256'
|
|
1553
|
+
}],
|
|
1554
|
+
name: 'transfer',
|
|
1555
|
+
outputs: [{
|
|
1556
|
+
name: '',
|
|
1557
|
+
type: 'bool'
|
|
1558
|
+
}],
|
|
1559
|
+
payable: false,
|
|
1560
|
+
stateMutability: 'nonpayable',
|
|
1561
|
+
type: 'function'
|
|
1562
|
+
}, {
|
|
1563
|
+
constant: true,
|
|
1564
|
+
inputs: [{
|
|
1565
|
+
name: '_owner',
|
|
1566
|
+
type: 'address'
|
|
1567
|
+
}, {
|
|
1568
|
+
name: '_spender',
|
|
1569
|
+
type: 'address'
|
|
1570
|
+
}],
|
|
1571
|
+
name: 'allowance',
|
|
1572
|
+
outputs: [{
|
|
1573
|
+
name: '',
|
|
1574
|
+
type: 'uint256'
|
|
1575
|
+
}],
|
|
1576
|
+
payable: false,
|
|
1577
|
+
stateMutability: 'view',
|
|
1578
|
+
type: 'function'
|
|
1579
|
+
}, {
|
|
1580
|
+
payable: true,
|
|
1581
|
+
stateMutability: 'payable',
|
|
1582
|
+
type: 'fallback'
|
|
1583
|
+
}, {
|
|
1584
|
+
anonymous: false,
|
|
1585
|
+
inputs: [{
|
|
1586
|
+
indexed: true,
|
|
1587
|
+
name: 'owner',
|
|
1588
|
+
type: 'address'
|
|
1589
|
+
}, {
|
|
1590
|
+
indexed: true,
|
|
1591
|
+
name: 'spender',
|
|
1592
|
+
type: 'address'
|
|
1593
|
+
}, {
|
|
1594
|
+
indexed: false,
|
|
1595
|
+
name: 'value',
|
|
1596
|
+
type: 'uint256'
|
|
1597
|
+
}],
|
|
1598
|
+
name: 'Approval',
|
|
1599
|
+
type: 'event'
|
|
1600
|
+
}, {
|
|
1601
|
+
anonymous: false,
|
|
1602
|
+
inputs: [{
|
|
1603
|
+
indexed: true,
|
|
1604
|
+
name: 'from',
|
|
1605
|
+
type: 'address'
|
|
1606
|
+
}, {
|
|
1607
|
+
indexed: true,
|
|
1608
|
+
name: 'to',
|
|
1609
|
+
type: 'address'
|
|
1610
|
+
}, {
|
|
1611
|
+
indexed: false,
|
|
1612
|
+
name: 'value',
|
|
1613
|
+
type: 'uint256'
|
|
1614
|
+
}],
|
|
1615
|
+
name: 'Transfer',
|
|
1616
|
+
type: 'event'
|
|
1617
|
+
}];
|
|
1618
|
+
|
|
1619
|
+
var web3 = /*#__PURE__*/new Web3__default["default"](); // chains we support fetching mappings for (can be different than the l2ChainIds arg for buildList)
|
|
1620
|
+
|
|
1621
|
+
var SUPPORTED_L2_CHAINS = [ChainId.ARBITRUM_ONE, ChainId.POLYGON, ChainId.OPTIMISM];
|
|
1391
1622
|
function buildList(_x, _x2) {
|
|
1392
1623
|
return _buildList.apply(this, arguments);
|
|
1393
|
-
}
|
|
1624
|
+
} // using a symbol lookup contract call to check whether the token exists on the L2
|
|
1394
1625
|
|
|
1395
1626
|
function _buildList() {
|
|
1396
|
-
_buildList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function
|
|
1397
|
-
var
|
|
1627
|
+
_buildList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(l2ChainIds, l1TokenList) {
|
|
1628
|
+
var multiChainedTokens, chainIdToMappingsMap, _loop, _iterator, _step, tokenList;
|
|
1398
1629
|
|
|
1399
|
-
return _regeneratorRuntime.wrap(function
|
|
1630
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context3) {
|
|
1400
1631
|
while (1) {
|
|
1401
|
-
switch (
|
|
1632
|
+
switch (_context3.prev = _context3.next) {
|
|
1402
1633
|
case 0:
|
|
1403
|
-
|
|
1404
|
-
|
|
1634
|
+
multiChainedTokens = [];
|
|
1635
|
+
_context3.next = 3;
|
|
1636
|
+
return generateTokenMappings(l2ChainIds, l1TokenList);
|
|
1405
1637
|
|
|
1406
|
-
case
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
|
|
1426
|
-
|
|
1427
|
-
|
|
1428
|
-
|
|
1638
|
+
case 3:
|
|
1639
|
+
chainIdToMappingsMap = _context3.sent;
|
|
1640
|
+
_loop = /*#__PURE__*/_regeneratorRuntime.mark(function _loop() {
|
|
1641
|
+
var l1Token, chainIdToChildTokenDetailsMap, l2MappingExtension;
|
|
1642
|
+
return _regeneratorRuntime.wrap(function _loop$(_context2) {
|
|
1643
|
+
while (1) {
|
|
1644
|
+
switch (_context2.prev = _context2.next) {
|
|
1645
|
+
case 0:
|
|
1646
|
+
l1Token = _step.value;
|
|
1647
|
+
|
|
1648
|
+
if (!(l1Token.chainId === ChainId.MAINNET)) {
|
|
1649
|
+
_context2.next = 7;
|
|
1650
|
+
break;
|
|
1651
|
+
}
|
|
1652
|
+
|
|
1653
|
+
chainIdToChildTokenDetailsMap = {};
|
|
1654
|
+
l2MappingExtension = {
|
|
1655
|
+
extensions: {
|
|
1656
|
+
bridgeInfo: {}
|
|
1657
|
+
}
|
|
1658
|
+
}; // build out the extensions.bridgeInfo data containing mappings for each L2 chain
|
|
1659
|
+
|
|
1660
|
+
_context2.next = 6;
|
|
1661
|
+
return Promise.all(l2ChainIds.map( /*#__PURE__*/function () {
|
|
1662
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(chainId) {
|
|
1663
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1664
|
+
while (1) {
|
|
1665
|
+
switch (_context.prev = _context.next) {
|
|
1666
|
+
case 0:
|
|
1667
|
+
_context.next = 2;
|
|
1668
|
+
return getChildTokenDetails(l1Token, chainId, chainIdToMappingsMap);
|
|
1669
|
+
|
|
1670
|
+
case 2:
|
|
1671
|
+
chainIdToChildTokenDetailsMap[chainId] = _context.sent;
|
|
1672
|
+
|
|
1673
|
+
if (chainIdToChildTokenDetailsMap[chainId].childTokenValid) {
|
|
1674
|
+
l2MappingExtension.extensions.bridgeInfo[chainId] = {
|
|
1675
|
+
tokenAddress: chainIdToChildTokenDetailsMap[chainId].childTokenAddress
|
|
1676
|
+
};
|
|
1677
|
+
}
|
|
1678
|
+
|
|
1679
|
+
case 4:
|
|
1680
|
+
case "end":
|
|
1681
|
+
return _context.stop();
|
|
1682
|
+
}
|
|
1683
|
+
}
|
|
1684
|
+
}, _callee);
|
|
1685
|
+
}));
|
|
1686
|
+
|
|
1687
|
+
return function (_x10) {
|
|
1688
|
+
return _ref.apply(this, arguments);
|
|
1689
|
+
};
|
|
1690
|
+
}()));
|
|
1691
|
+
|
|
1692
|
+
case 6:
|
|
1693
|
+
// build the TokenInfo objects with bridgeInfo extension
|
|
1694
|
+
l2ChainIds.concat([ChainId.MAINNET]).forEach(function (chainId) {
|
|
1695
|
+
if (chainId === ChainId.MAINNET || chainIdToChildTokenDetailsMap[chainId].childTokenValid) {
|
|
1696
|
+
var _bridgeInfo;
|
|
1697
|
+
|
|
1698
|
+
var tokenInfo = chainId === ChainId.MAINNET ? _extends({}, l1Token, {
|
|
1699
|
+
extensions: Object.keys(l2MappingExtension.extensions.bridgeInfo).length > 0 ? {
|
|
1700
|
+
bridgeInfo: l2MappingExtension.extensions.bridgeInfo
|
|
1701
|
+
} : undefined
|
|
1702
|
+
}) : _extends({}, l1Token, {
|
|
1703
|
+
chainId: chainId,
|
|
1704
|
+
address: chainIdToChildTokenDetailsMap[chainId].childTokenAddress,
|
|
1705
|
+
extensions: {
|
|
1706
|
+
bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[ChainId.MAINNET] = {
|
|
1707
|
+
tokenAddress: ethers.ethers.utils.getAddress(l1Token.address)
|
|
1708
|
+
}, _bridgeInfo)
|
|
1709
|
+
}
|
|
1710
|
+
});
|
|
1711
|
+
multiChainedTokens.push(tokenInfo);
|
|
1712
|
+
}
|
|
1713
|
+
});
|
|
1714
|
+
|
|
1715
|
+
case 7:
|
|
1716
|
+
case "end":
|
|
1717
|
+
return _context2.stop();
|
|
1429
1718
|
}
|
|
1430
|
-
} : {};
|
|
1431
|
-
rootTokenInfo = _extends({}, rootToken, toChildExtensions);
|
|
1432
|
-
|
|
1433
|
-
if (childTokenValid) {
|
|
1434
|
-
childTokenInfo = _extends({}, rootToken, {
|
|
1435
|
-
chainId: chainId,
|
|
1436
|
-
address: ethers.ethers.utils.getAddress(typeof childToken === 'object' ? childToken.child_token : childToken)
|
|
1437
|
-
}, toRootExtensions);
|
|
1438
|
-
mappedTokens.push(childTokenInfo);
|
|
1439
1719
|
}
|
|
1720
|
+
}, _loop);
|
|
1721
|
+
});
|
|
1722
|
+
_iterator = _createForOfIteratorHelperLoose(l1TokenList.tokens);
|
|
1440
1723
|
|
|
1441
|
-
|
|
1442
|
-
|
|
1724
|
+
case 6:
|
|
1725
|
+
if ((_step = _iterator()).done) {
|
|
1726
|
+
_context3.next = 10;
|
|
1727
|
+
break;
|
|
1443
1728
|
}
|
|
1444
1729
|
|
|
1730
|
+
return _context3.delegateYield(_loop(), "t0", 8);
|
|
1731
|
+
|
|
1732
|
+
case 8:
|
|
1733
|
+
_context3.next = 6;
|
|
1734
|
+
break;
|
|
1735
|
+
|
|
1736
|
+
case 10:
|
|
1737
|
+
// build and return final chainified token list
|
|
1445
1738
|
tokenList = {
|
|
1446
|
-
name: "(
|
|
1739
|
+
name: "(ChainIds: " + l2ChainIds + ") " + l1TokenList.name,
|
|
1447
1740
|
timestamp: new Date().toISOString(),
|
|
1448
1741
|
version: l1TokenList.version,
|
|
1449
|
-
tokens:
|
|
1742
|
+
tokens: multiChainedTokens.sort(compareTokenInfos)
|
|
1450
1743
|
};
|
|
1451
|
-
return
|
|
1744
|
+
return _context3.abrupt("return", tokenList);
|
|
1452
1745
|
|
|
1453
|
-
case
|
|
1746
|
+
case 12:
|
|
1454
1747
|
case "end":
|
|
1455
|
-
return
|
|
1748
|
+
return _context3.stop();
|
|
1456
1749
|
}
|
|
1457
1750
|
}
|
|
1458
|
-
},
|
|
1751
|
+
}, _callee2);
|
|
1459
1752
|
}));
|
|
1460
1753
|
return _buildList.apply(this, arguments);
|
|
1461
1754
|
}
|
|
1462
1755
|
|
|
1756
|
+
function hasExistingTokenContract(_x3, _x4) {
|
|
1757
|
+
return _hasExistingTokenContract.apply(this, arguments);
|
|
1758
|
+
}
|
|
1759
|
+
|
|
1760
|
+
function _hasExistingTokenContract() {
|
|
1761
|
+
_hasExistingTokenContract = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(address, chainId) {
|
|
1762
|
+
var contract;
|
|
1763
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context4) {
|
|
1764
|
+
while (1) {
|
|
1765
|
+
switch (_context4.prev = _context4.next) {
|
|
1766
|
+
case 0:
|
|
1767
|
+
web3.setProvider(getRpcUrl(chainId));
|
|
1768
|
+
_context4.prev = 1;
|
|
1769
|
+
contract = new web3.eth.Contract(abi, address);
|
|
1770
|
+
_context4.next = 5;
|
|
1771
|
+
return getTokenSymbolFromContract(contract);
|
|
1772
|
+
|
|
1773
|
+
case 5:
|
|
1774
|
+
_context4.next = 10;
|
|
1775
|
+
break;
|
|
1776
|
+
|
|
1777
|
+
case 7:
|
|
1778
|
+
_context4.prev = 7;
|
|
1779
|
+
_context4.t0 = _context4["catch"](1);
|
|
1780
|
+
return _context4.abrupt("return", false);
|
|
1781
|
+
|
|
1782
|
+
case 10:
|
|
1783
|
+
return _context4.abrupt("return", true);
|
|
1784
|
+
|
|
1785
|
+
case 11:
|
|
1786
|
+
case "end":
|
|
1787
|
+
return _context4.stop();
|
|
1788
|
+
}
|
|
1789
|
+
}
|
|
1790
|
+
}, _callee3, null, [[1, 7]]);
|
|
1791
|
+
}));
|
|
1792
|
+
return _hasExistingTokenContract.apply(this, arguments);
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1463
1795
|
function getMappingProvider(chainId, l1TokenList) {
|
|
1464
1796
|
switch (chainId) {
|
|
1465
1797
|
case ChainId.ARBITRUM_ONE:
|
|
@@ -1472,10 +1804,123 @@ function getMappingProvider(chainId, l1TokenList) {
|
|
|
1472
1804
|
return new PolygonMappingProvider();
|
|
1473
1805
|
|
|
1474
1806
|
default:
|
|
1475
|
-
throw new Error("Chain " + chainId + " not supported.");
|
|
1807
|
+
throw new Error("Chain " + chainId + " not supported for fetching mappings.");
|
|
1476
1808
|
}
|
|
1477
1809
|
}
|
|
1478
1810
|
|
|
1811
|
+
function generateTokenMappings(_x5, _x6) {
|
|
1812
|
+
return _generateTokenMappings.apply(this, arguments);
|
|
1813
|
+
} // handles both string and object cases for childToken (Polygon mappings return object)
|
|
1814
|
+
|
|
1815
|
+
|
|
1816
|
+
function _generateTokenMappings() {
|
|
1817
|
+
_generateTokenMappings = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(chainIds, l1TokenList) {
|
|
1818
|
+
var chainIdToMappingsMap, _iterator2, _step2, chainId;
|
|
1819
|
+
|
|
1820
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context5) {
|
|
1821
|
+
while (1) {
|
|
1822
|
+
switch (_context5.prev = _context5.next) {
|
|
1823
|
+
case 0:
|
|
1824
|
+
chainIdToMappingsMap = {};
|
|
1825
|
+
_iterator2 = _createForOfIteratorHelperLoose(chainIds);
|
|
1826
|
+
|
|
1827
|
+
case 2:
|
|
1828
|
+
if ((_step2 = _iterator2()).done) {
|
|
1829
|
+
_context5.next = 10;
|
|
1830
|
+
break;
|
|
1831
|
+
}
|
|
1832
|
+
|
|
1833
|
+
chainId = _step2.value;
|
|
1834
|
+
|
|
1835
|
+
if (!SUPPORTED_L2_CHAINS.includes(chainId)) {
|
|
1836
|
+
_context5.next = 8;
|
|
1837
|
+
break;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1840
|
+
_context5.next = 7;
|
|
1841
|
+
return getMappingProvider(chainId, l1TokenList).provide();
|
|
1842
|
+
|
|
1843
|
+
case 7:
|
|
1844
|
+
chainIdToMappingsMap[chainId] = _context5.sent;
|
|
1845
|
+
|
|
1846
|
+
case 8:
|
|
1847
|
+
_context5.next = 2;
|
|
1848
|
+
break;
|
|
1849
|
+
|
|
1850
|
+
case 10:
|
|
1851
|
+
return _context5.abrupt("return", chainIdToMappingsMap);
|
|
1852
|
+
|
|
1853
|
+
case 11:
|
|
1854
|
+
case "end":
|
|
1855
|
+
return _context5.stop();
|
|
1856
|
+
}
|
|
1857
|
+
}
|
|
1858
|
+
}, _callee4);
|
|
1859
|
+
}));
|
|
1860
|
+
return _generateTokenMappings.apply(this, arguments);
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
function getChildTokenDetails(_x7, _x8, _x9) {
|
|
1864
|
+
return _getChildTokenDetails.apply(this, arguments);
|
|
1865
|
+
}
|
|
1866
|
+
|
|
1867
|
+
function _getChildTokenDetails() {
|
|
1868
|
+
_getChildTokenDetails = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(l1Token, chainId, chainIdToMappingsMap) {
|
|
1869
|
+
var _l1Token$extensions, _l1Token$extensions$b, _l1Token$extensions$b2;
|
|
1870
|
+
|
|
1871
|
+
var existingMapping, childToken, childTokenAddress, childTokenValid;
|
|
1872
|
+
return _regeneratorRuntime.wrap(function _callee5$(_context6) {
|
|
1873
|
+
while (1) {
|
|
1874
|
+
switch (_context6.prev = _context6.next) {
|
|
1875
|
+
case 0:
|
|
1876
|
+
existingMapping = l1Token == null ? void 0 : (_l1Token$extensions = l1Token.extensions) == null ? void 0 : (_l1Token$extensions$b = _l1Token$extensions.bridgeInfo) == null ? void 0 : (_l1Token$extensions$b2 = _l1Token$extensions$b[chainId]) == null ? void 0 : _l1Token$extensions$b2.tokenAddress; // use the externally fetched mappings if manual entry doesn't exist for the token/chain mapping
|
|
1877
|
+
// and the given L2 chain is supported for fetching mappings
|
|
1878
|
+
|
|
1879
|
+
if (!(SUPPORTED_L2_CHAINS.includes(chainId) && existingMapping === undefined)) {
|
|
1880
|
+
_context6.next = 13;
|
|
1881
|
+
break;
|
|
1882
|
+
}
|
|
1883
|
+
|
|
1884
|
+
childToken = chainIdToMappingsMap[chainId][l1Token.address.toLowerCase()];
|
|
1885
|
+
childTokenAddress = childToken ? ethers.ethers.utils.getAddress(typeof childToken === 'object' ? childToken.child_token : childToken) : undefined;
|
|
1886
|
+
_context6.t0 = Boolean;
|
|
1887
|
+
_context6.t1 = childTokenAddress && (typeof childToken === 'object' ? !childToken.deleted : true);
|
|
1888
|
+
|
|
1889
|
+
if (!_context6.t1) {
|
|
1890
|
+
_context6.next = 10;
|
|
1891
|
+
break;
|
|
1892
|
+
}
|
|
1893
|
+
|
|
1894
|
+
_context6.next = 9;
|
|
1895
|
+
return hasExistingTokenContract(childTokenAddress, chainId);
|
|
1896
|
+
|
|
1897
|
+
case 9:
|
|
1898
|
+
_context6.t1 = _context6.sent;
|
|
1899
|
+
|
|
1900
|
+
case 10:
|
|
1901
|
+
_context6.t2 = _context6.t1;
|
|
1902
|
+
childTokenValid = (0, _context6.t0)(_context6.t2);
|
|
1903
|
+
return _context6.abrupt("return", {
|
|
1904
|
+
childTokenValid: childTokenValid,
|
|
1905
|
+
childTokenAddress: childTokenAddress
|
|
1906
|
+
});
|
|
1907
|
+
|
|
1908
|
+
case 13:
|
|
1909
|
+
return _context6.abrupt("return", {
|
|
1910
|
+
childTokenValid: !!existingMapping,
|
|
1911
|
+
childTokenAddress: existingMapping
|
|
1912
|
+
});
|
|
1913
|
+
|
|
1914
|
+
case 14:
|
|
1915
|
+
case "end":
|
|
1916
|
+
return _context6.stop();
|
|
1917
|
+
}
|
|
1918
|
+
}
|
|
1919
|
+
}, _callee5);
|
|
1920
|
+
}));
|
|
1921
|
+
return _getChildTokenDetails.apply(this, arguments);
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1479
1924
|
/**
|
|
1480
1925
|
* Verifies that for each token with extensions.bridgeInfo defined, for every
|
|
1481
1926
|
* chainId there exists a token with that chainId at the root-level of the
|
|
@@ -1549,14 +1994,14 @@ function chainify(_x) {
|
|
|
1549
1994
|
}
|
|
1550
1995
|
/**
|
|
1551
1996
|
* Given a network and a TokenList, returns the TokenList with `extensions` filled.
|
|
1552
|
-
* @param
|
|
1997
|
+
* @param l2ChainIds layer 2 chainIds to operate on
|
|
1553
1998
|
* @param l1TokenListOrPathOrUrl either an L1 TokenList object or a path/url to a TokenList
|
|
1554
1999
|
* @returns L1 TokenList with `extensions` filled for the given network
|
|
1555
2000
|
*/
|
|
1556
2001
|
|
|
1557
2002
|
function _chainify() {
|
|
1558
2003
|
_chainify = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenListOrPathOrUrl) {
|
|
1559
|
-
var l1TokenList,
|
|
2004
|
+
var l1TokenList, l2Chains, chainified;
|
|
1560
2005
|
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
1561
2006
|
while (1) {
|
|
1562
2007
|
switch (_context.prev = _context.next) {
|
|
@@ -1566,25 +2011,16 @@ function _chainify() {
|
|
|
1566
2011
|
|
|
1567
2012
|
case 2:
|
|
1568
2013
|
l1TokenList = _context.sent;
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
case 5:
|
|
1573
|
-
optimisimed = _context.sent;
|
|
1574
|
-
_context.next = 8;
|
|
1575
|
-
return chainifyTokenList(ChainId.POLYGON, l1TokenListOrPathOrUrl);
|
|
2014
|
+
l2Chains = [ChainId.POLYGON, ChainId.ARBITRUM_ONE, ChainId.OPTIMISM, ChainId.CELO];
|
|
2015
|
+
_context.next = 6;
|
|
2016
|
+
return chainifyTokenList(l2Chains, l1TokenListOrPathOrUrl);
|
|
1576
2017
|
|
|
1577
|
-
case
|
|
1578
|
-
|
|
1579
|
-
_context.next = 11;
|
|
1580
|
-
return chainifyTokenList(ChainId.ARBITRUM_ONE, l1TokenListOrPathOrUrl);
|
|
1581
|
-
|
|
1582
|
-
case 11:
|
|
1583
|
-
arbified = _context.sent;
|
|
2018
|
+
case 6:
|
|
2019
|
+
chainified = _context.sent;
|
|
1584
2020
|
return _context.abrupt("return", mergeTokenLists(l1TokenList, // providing l1 first to make sure duplicated tokens resolve to this list
|
|
1585
|
-
|
|
2021
|
+
chainified));
|
|
1586
2022
|
|
|
1587
|
-
case
|
|
2023
|
+
case 8:
|
|
1588
2024
|
case "end":
|
|
1589
2025
|
return _context.stop();
|
|
1590
2026
|
}
|
|
@@ -1600,7 +2036,7 @@ function chainifyTokenList(_x2, _x3) {
|
|
|
1600
2036
|
/** Merges two token lists, resolving conflicts to primary list. */
|
|
1601
2037
|
|
|
1602
2038
|
function _chainifyTokenList() {
|
|
1603
|
-
_chainifyTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(
|
|
2039
|
+
_chainifyTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(l2ChainIds, l1TokenListOrPathOrUrl) {
|
|
1604
2040
|
var l1TokenList, tokenList;
|
|
1605
2041
|
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
1606
2042
|
while (1) {
|
|
@@ -1613,7 +2049,7 @@ function _chainifyTokenList() {
|
|
|
1613
2049
|
case 3:
|
|
1614
2050
|
l1TokenList = _context2.sent;
|
|
1615
2051
|
_context2.next = 6;
|
|
1616
|
-
return buildList(
|
|
2052
|
+
return buildList(l2ChainIds, l1TokenList);
|
|
1617
2053
|
|
|
1618
2054
|
case 6:
|
|
1619
2055
|
tokenList = _context2.sent;
|