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