@uniswap/token-list-bridge-utils 0.1.1-beta.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 (61) hide show
  1. package/LICENSE +674 -0
  2. package/README.md +17 -0
  3. package/dist/arb-token-lists/server/app.d.ts +1 -0
  4. package/dist/arb-token-lists/src/lib/getClargs.d.ts +8 -0
  5. package/dist/arb-token-lists/src/lib/graph.d.ts +2 -0
  6. package/dist/arb-token-lists/src/lib/instantiate_bridge.d.ts +15 -0
  7. package/dist/arb-token-lists/src/lib/token_list_gen.d.ts +23 -0
  8. package/dist/arb-token-lists/src/lib/types.d.ts +36 -0
  9. package/dist/arb-token-lists/src/lib/utils.d.ts +18 -0
  10. package/dist/arb-token-lists/src/main.d.ts +1 -0
  11. package/dist/constants/chainId.d.ts +10 -0
  12. package/dist/constants/tokens.d.ts +5 -0
  13. package/dist/fixtures/index.d.ts +24 -0
  14. package/dist/index.d.ts +18 -0
  15. package/dist/index.js +8 -0
  16. package/dist/providers/ArbitrumMappingProvider.d.ts +11 -0
  17. package/dist/providers/MappingProvider.d.ts +4 -0
  18. package/dist/providers/OptimismMappingProvider.d.ts +10 -0
  19. package/dist/providers/PolygonMappingProvider.d.ts +9 -0
  20. package/dist/providers/index.d.ts +5 -0
  21. package/dist/token-list-bridge-utils.cjs.development.js +2217 -0
  22. package/dist/token-list-bridge-utils.cjs.development.js.map +1 -0
  23. package/dist/token-list-bridge-utils.cjs.production.min.js +2 -0
  24. package/dist/token-list-bridge-utils.cjs.production.min.js.map +1 -0
  25. package/dist/token-list-bridge-utils.esm.js +2201 -0
  26. package/dist/token-list-bridge-utils.esm.js.map +1 -0
  27. package/dist/utils.d.ts +4 -0
  28. package/dist/verify.d.ts +9 -0
  29. package/package.json +68 -0
  30. package/src/arb-token-lists/.env.sample +4 -0
  31. package/src/arb-token-lists/.eslintrc.js +43 -0
  32. package/src/arb-token-lists/.gitignore +4 -0
  33. package/src/arb-token-lists/package.json +40 -0
  34. package/src/arb-token-lists/readme.md +14 -0
  35. package/src/arb-token-lists/server/app.ts +21 -0
  36. package/src/arb-token-lists/src/Assets/coingecko_uris.json +5108 -0
  37. package/src/arb-token-lists/src/Assets/logo_uris.json +44 -0
  38. package/src/arb-token-lists/src/WarningList/warningTokens.json +290 -0
  39. package/src/arb-token-lists/src/lib/getClargs.ts +32 -0
  40. package/src/arb-token-lists/src/lib/graph.ts +116 -0
  41. package/src/arb-token-lists/src/lib/instantiate_bridge.ts +35 -0
  42. package/src/arb-token-lists/src/lib/token_list_gen.ts +334 -0
  43. package/src/arb-token-lists/src/lib/types.ts +44 -0
  44. package/src/arb-token-lists/src/lib/utils.ts +285 -0
  45. package/src/arb-token-lists/src/main.ts +54 -0
  46. package/src/arb-token-lists/tsconfig.json +20 -0
  47. package/src/arb-token-lists/update_all +6 -0
  48. package/src/arb-token-lists/yarn.lock +4273 -0
  49. package/src/constants/chainId.ts +13 -0
  50. package/src/constants/tokens.ts +31 -0
  51. package/src/fixtures/index.ts +104 -0
  52. package/src/index.test.ts +211 -0
  53. package/src/index.ts +92 -0
  54. package/src/providers/ArbitrumMappingProvider.ts +28 -0
  55. package/src/providers/MappingProvider.ts +5 -0
  56. package/src/providers/OptimismMappingProvider.ts +13 -0
  57. package/src/providers/PolygonMappingProvider.ts +127 -0
  58. package/src/providers/index.ts +17 -0
  59. package/src/utils.ts +21 -0
  60. package/src/verify.test.ts +19 -0
  61. package/src/verify.ts +60 -0
@@ -0,0 +1,2217 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var lodash = require('lodash');
6
+ var tokenLists = require('@uniswap/token-lists');
7
+ var arbTs = require('arb-ts');
8
+ var ethers = require('ethers');
9
+ var fs = require('fs');
10
+ var graphqlRequest = require('graphql-request');
11
+ var Ajv = require('ajv');
12
+ var addFormats = require('ajv-formats');
13
+ var axios = require('axios');
14
+ var betterAjvErrors = require('better-ajv-errors');
15
+ var path = require('path');
16
+ var yargs = require('yargs/yargs');
17
+ var dotenv = require('dotenv');
18
+
19
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
+
21
+ var Ajv__default = /*#__PURE__*/_interopDefaultLegacy(Ajv);
22
+ var addFormats__default = /*#__PURE__*/_interopDefaultLegacy(addFormats);
23
+ var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
24
+ var betterAjvErrors__default = /*#__PURE__*/_interopDefaultLegacy(betterAjvErrors);
25
+ var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
26
+ var yargs__default = /*#__PURE__*/_interopDefaultLegacy(yargs);
27
+ var dotenv__default = /*#__PURE__*/_interopDefaultLegacy(dotenv);
28
+
29
+ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
30
+ try {
31
+ var info = gen[key](arg);
32
+ var value = info.value;
33
+ } catch (error) {
34
+ reject(error);
35
+ return;
36
+ }
37
+
38
+ if (info.done) {
39
+ resolve(value);
40
+ } else {
41
+ Promise.resolve(value).then(_next, _throw);
42
+ }
43
+ }
44
+
45
+ function _asyncToGenerator(fn) {
46
+ return function () {
47
+ var self = this,
48
+ args = arguments;
49
+ return new Promise(function (resolve, reject) {
50
+ var gen = fn.apply(self, args);
51
+
52
+ function _next(value) {
53
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
54
+ }
55
+
56
+ function _throw(err) {
57
+ asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
58
+ }
59
+
60
+ _next(undefined);
61
+ });
62
+ };
63
+ }
64
+
65
+ function _extends() {
66
+ _extends = Object.assign || function (target) {
67
+ for (var i = 1; i < arguments.length; i++) {
68
+ var source = arguments[i];
69
+
70
+ for (var key in source) {
71
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
72
+ target[key] = source[key];
73
+ }
74
+ }
75
+ }
76
+
77
+ return target;
78
+ };
79
+
80
+ return _extends.apply(this, arguments);
81
+ }
82
+
83
+ function _taggedTemplateLiteralLoose(strings, raw) {
84
+ if (!raw) {
85
+ raw = strings.slice(0);
86
+ }
87
+
88
+ strings.raw = raw;
89
+ return strings;
90
+ }
91
+
92
+ function _unsupportedIterableToArray(o, minLen) {
93
+ if (!o) return;
94
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
95
+ var n = Object.prototype.toString.call(o).slice(8, -1);
96
+ if (n === "Object" && o.constructor) n = o.constructor.name;
97
+ if (n === "Map" || n === "Set") return Array.from(o);
98
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
99
+ }
100
+
101
+ function _arrayLikeToArray(arr, len) {
102
+ if (len == null || len > arr.length) len = arr.length;
103
+
104
+ for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
105
+
106
+ return arr2;
107
+ }
108
+
109
+ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
110
+ var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
111
+ if (it) return (it = it.call(o)).next.bind(it);
112
+
113
+ if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
114
+ if (it) o = it;
115
+ var i = 0;
116
+ return function () {
117
+ if (i >= o.length) return {
118
+ done: true
119
+ };
120
+ return {
121
+ done: false,
122
+ value: o[i++]
123
+ };
124
+ };
125
+ }
126
+
127
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
128
+ }
129
+
130
+ var runtime = {exports: {}};
131
+
132
+ /**
133
+ * Copyright (c) 2014-present, Facebook, Inc.
134
+ *
135
+ * This source code is licensed under the MIT license found in the
136
+ * LICENSE file in the root directory of this source tree.
137
+ */
138
+
139
+ (function (module) {
140
+ var runtime = (function (exports) {
141
+
142
+ var Op = Object.prototype;
143
+ var hasOwn = Op.hasOwnProperty;
144
+ var undefined$1; // More compressible than void 0.
145
+ var $Symbol = typeof Symbol === "function" ? Symbol : {};
146
+ var iteratorSymbol = $Symbol.iterator || "@@iterator";
147
+ var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
148
+ var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
149
+
150
+ function define(obj, key, value) {
151
+ Object.defineProperty(obj, key, {
152
+ value: value,
153
+ enumerable: true,
154
+ configurable: true,
155
+ writable: true
156
+ });
157
+ return obj[key];
158
+ }
159
+ try {
160
+ // IE 8 has a broken Object.defineProperty that only works on DOM objects.
161
+ define({}, "");
162
+ } catch (err) {
163
+ define = function(obj, key, value) {
164
+ return obj[key] = value;
165
+ };
166
+ }
167
+
168
+ function wrap(innerFn, outerFn, self, tryLocsList) {
169
+ // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
170
+ var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
171
+ var generator = Object.create(protoGenerator.prototype);
172
+ var context = new Context(tryLocsList || []);
173
+
174
+ // The ._invoke method unifies the implementations of the .next,
175
+ // .throw, and .return methods.
176
+ generator._invoke = makeInvokeMethod(innerFn, self, context);
177
+
178
+ return generator;
179
+ }
180
+ exports.wrap = wrap;
181
+
182
+ // Try/catch helper to minimize deoptimizations. Returns a completion
183
+ // record like context.tryEntries[i].completion. This interface could
184
+ // have been (and was previously) designed to take a closure to be
185
+ // invoked without arguments, but in all the cases we care about we
186
+ // already have an existing method we want to call, so there's no need
187
+ // to create a new function object. We can even get away with assuming
188
+ // the method takes exactly one argument, since that happens to be true
189
+ // in every case, so we don't have to touch the arguments object. The
190
+ // only additional allocation required is the completion record, which
191
+ // has a stable shape and so hopefully should be cheap to allocate.
192
+ function tryCatch(fn, obj, arg) {
193
+ try {
194
+ return { type: "normal", arg: fn.call(obj, arg) };
195
+ } catch (err) {
196
+ return { type: "throw", arg: err };
197
+ }
198
+ }
199
+
200
+ var GenStateSuspendedStart = "suspendedStart";
201
+ var GenStateSuspendedYield = "suspendedYield";
202
+ var GenStateExecuting = "executing";
203
+ var GenStateCompleted = "completed";
204
+
205
+ // Returning this object from the innerFn has the same effect as
206
+ // breaking out of the dispatch switch statement.
207
+ var ContinueSentinel = {};
208
+
209
+ // Dummy constructor functions that we use as the .constructor and
210
+ // .constructor.prototype properties for functions that return Generator
211
+ // objects. For full spec compliance, you may wish to configure your
212
+ // minifier not to mangle the names of these two functions.
213
+ function Generator() {}
214
+ function GeneratorFunction() {}
215
+ function GeneratorFunctionPrototype() {}
216
+
217
+ // This is a polyfill for %IteratorPrototype% for environments that
218
+ // don't natively support it.
219
+ var IteratorPrototype = {};
220
+ define(IteratorPrototype, iteratorSymbol, function () {
221
+ return this;
222
+ });
223
+
224
+ var getProto = Object.getPrototypeOf;
225
+ var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
226
+ if (NativeIteratorPrototype &&
227
+ NativeIteratorPrototype !== Op &&
228
+ hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
229
+ // This environment has a native %IteratorPrototype%; use it instead
230
+ // of the polyfill.
231
+ IteratorPrototype = NativeIteratorPrototype;
232
+ }
233
+
234
+ var Gp = GeneratorFunctionPrototype.prototype =
235
+ Generator.prototype = Object.create(IteratorPrototype);
236
+ GeneratorFunction.prototype = GeneratorFunctionPrototype;
237
+ define(Gp, "constructor", GeneratorFunctionPrototype);
238
+ define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
239
+ GeneratorFunction.displayName = define(
240
+ GeneratorFunctionPrototype,
241
+ toStringTagSymbol,
242
+ "GeneratorFunction"
243
+ );
244
+
245
+ // Helper for defining the .next, .throw, and .return methods of the
246
+ // Iterator interface in terms of a single ._invoke method.
247
+ function defineIteratorMethods(prototype) {
248
+ ["next", "throw", "return"].forEach(function(method) {
249
+ define(prototype, method, function(arg) {
250
+ return this._invoke(method, arg);
251
+ });
252
+ });
253
+ }
254
+
255
+ exports.isGeneratorFunction = function(genFun) {
256
+ var ctor = typeof genFun === "function" && genFun.constructor;
257
+ return ctor
258
+ ? ctor === GeneratorFunction ||
259
+ // For the native GeneratorFunction constructor, the best we can
260
+ // do is to check its .name property.
261
+ (ctor.displayName || ctor.name) === "GeneratorFunction"
262
+ : false;
263
+ };
264
+
265
+ exports.mark = function(genFun) {
266
+ if (Object.setPrototypeOf) {
267
+ Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
268
+ } else {
269
+ genFun.__proto__ = GeneratorFunctionPrototype;
270
+ define(genFun, toStringTagSymbol, "GeneratorFunction");
271
+ }
272
+ genFun.prototype = Object.create(Gp);
273
+ return genFun;
274
+ };
275
+
276
+ // Within the body of any async function, `await x` is transformed to
277
+ // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
278
+ // `hasOwn.call(value, "__await")` to determine if the yielded value is
279
+ // meant to be awaited.
280
+ exports.awrap = function(arg) {
281
+ return { __await: arg };
282
+ };
283
+
284
+ function AsyncIterator(generator, PromiseImpl) {
285
+ function invoke(method, arg, resolve, reject) {
286
+ var record = tryCatch(generator[method], generator, arg);
287
+ if (record.type === "throw") {
288
+ reject(record.arg);
289
+ } else {
290
+ var result = record.arg;
291
+ var value = result.value;
292
+ if (value &&
293
+ typeof value === "object" &&
294
+ hasOwn.call(value, "__await")) {
295
+ return PromiseImpl.resolve(value.__await).then(function(value) {
296
+ invoke("next", value, resolve, reject);
297
+ }, function(err) {
298
+ invoke("throw", err, resolve, reject);
299
+ });
300
+ }
301
+
302
+ return PromiseImpl.resolve(value).then(function(unwrapped) {
303
+ // When a yielded Promise is resolved, its final value becomes
304
+ // the .value of the Promise<{value,done}> result for the
305
+ // current iteration.
306
+ result.value = unwrapped;
307
+ resolve(result);
308
+ }, function(error) {
309
+ // If a rejected Promise was yielded, throw the rejection back
310
+ // into the async generator function so it can be handled there.
311
+ return invoke("throw", error, resolve, reject);
312
+ });
313
+ }
314
+ }
315
+
316
+ var previousPromise;
317
+
318
+ function enqueue(method, arg) {
319
+ function callInvokeWithMethodAndArg() {
320
+ return new PromiseImpl(function(resolve, reject) {
321
+ invoke(method, arg, resolve, reject);
322
+ });
323
+ }
324
+
325
+ return previousPromise =
326
+ // If enqueue has been called before, then we want to wait until
327
+ // all previous Promises have been resolved before calling invoke,
328
+ // so that results are always delivered in the correct order. If
329
+ // enqueue has not been called before, then it is important to
330
+ // call invoke immediately, without waiting on a callback to fire,
331
+ // so that the async generator function has the opportunity to do
332
+ // any necessary setup in a predictable way. This predictability
333
+ // is why the Promise constructor synchronously invokes its
334
+ // executor callback, and why async functions synchronously
335
+ // execute code before the first await. Since we implement simple
336
+ // async functions in terms of async generators, it is especially
337
+ // important to get this right, even though it requires care.
338
+ previousPromise ? previousPromise.then(
339
+ callInvokeWithMethodAndArg,
340
+ // Avoid propagating failures to Promises returned by later
341
+ // invocations of the iterator.
342
+ callInvokeWithMethodAndArg
343
+ ) : callInvokeWithMethodAndArg();
344
+ }
345
+
346
+ // Define the unified helper method that is used to implement .next,
347
+ // .throw, and .return (see defineIteratorMethods).
348
+ this._invoke = enqueue;
349
+ }
350
+
351
+ defineIteratorMethods(AsyncIterator.prototype);
352
+ define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
353
+ return this;
354
+ });
355
+ exports.AsyncIterator = AsyncIterator;
356
+
357
+ // Note that simple async functions are implemented on top of
358
+ // AsyncIterator objects; they just return a Promise for the value of
359
+ // the final result produced by the iterator.
360
+ exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
361
+ if (PromiseImpl === void 0) PromiseImpl = Promise;
362
+
363
+ var iter = new AsyncIterator(
364
+ wrap(innerFn, outerFn, self, tryLocsList),
365
+ PromiseImpl
366
+ );
367
+
368
+ return exports.isGeneratorFunction(outerFn)
369
+ ? iter // If outerFn is a generator, return the full iterator.
370
+ : iter.next().then(function(result) {
371
+ return result.done ? result.value : iter.next();
372
+ });
373
+ };
374
+
375
+ function makeInvokeMethod(innerFn, self, context) {
376
+ var state = GenStateSuspendedStart;
377
+
378
+ return function invoke(method, arg) {
379
+ if (state === GenStateExecuting) {
380
+ throw new Error("Generator is already running");
381
+ }
382
+
383
+ if (state === GenStateCompleted) {
384
+ if (method === "throw") {
385
+ throw arg;
386
+ }
387
+
388
+ // Be forgiving, per 25.3.3.3.3 of the spec:
389
+ // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
390
+ return doneResult();
391
+ }
392
+
393
+ context.method = method;
394
+ context.arg = arg;
395
+
396
+ while (true) {
397
+ var delegate = context.delegate;
398
+ if (delegate) {
399
+ var delegateResult = maybeInvokeDelegate(delegate, context);
400
+ if (delegateResult) {
401
+ if (delegateResult === ContinueSentinel) continue;
402
+ return delegateResult;
403
+ }
404
+ }
405
+
406
+ if (context.method === "next") {
407
+ // Setting context._sent for legacy support of Babel's
408
+ // function.sent implementation.
409
+ context.sent = context._sent = context.arg;
410
+
411
+ } else if (context.method === "throw") {
412
+ if (state === GenStateSuspendedStart) {
413
+ state = GenStateCompleted;
414
+ throw context.arg;
415
+ }
416
+
417
+ context.dispatchException(context.arg);
418
+
419
+ } else if (context.method === "return") {
420
+ context.abrupt("return", context.arg);
421
+ }
422
+
423
+ state = GenStateExecuting;
424
+
425
+ var record = tryCatch(innerFn, self, context);
426
+ if (record.type === "normal") {
427
+ // If an exception is thrown from innerFn, we leave state ===
428
+ // GenStateExecuting and loop back for another invocation.
429
+ state = context.done
430
+ ? GenStateCompleted
431
+ : GenStateSuspendedYield;
432
+
433
+ if (record.arg === ContinueSentinel) {
434
+ continue;
435
+ }
436
+
437
+ return {
438
+ value: record.arg,
439
+ done: context.done
440
+ };
441
+
442
+ } else if (record.type === "throw") {
443
+ state = GenStateCompleted;
444
+ // Dispatch the exception by looping back around to the
445
+ // context.dispatchException(context.arg) call above.
446
+ context.method = "throw";
447
+ context.arg = record.arg;
448
+ }
449
+ }
450
+ };
451
+ }
452
+
453
+ // Call delegate.iterator[context.method](context.arg) and handle the
454
+ // result, either by returning a { value, done } result from the
455
+ // delegate iterator, or by modifying context.method and context.arg,
456
+ // setting context.delegate to null, and returning the ContinueSentinel.
457
+ function maybeInvokeDelegate(delegate, context) {
458
+ var method = delegate.iterator[context.method];
459
+ if (method === undefined$1) {
460
+ // A .throw or .return when the delegate iterator has no .throw
461
+ // method always terminates the yield* loop.
462
+ context.delegate = null;
463
+
464
+ if (context.method === "throw") {
465
+ // Note: ["return"] must be used for ES3 parsing compatibility.
466
+ if (delegate.iterator["return"]) {
467
+ // If the delegate iterator has a return method, give it a
468
+ // chance to clean up.
469
+ context.method = "return";
470
+ context.arg = undefined$1;
471
+ maybeInvokeDelegate(delegate, context);
472
+
473
+ if (context.method === "throw") {
474
+ // If maybeInvokeDelegate(context) changed context.method from
475
+ // "return" to "throw", let that override the TypeError below.
476
+ return ContinueSentinel;
477
+ }
478
+ }
479
+
480
+ context.method = "throw";
481
+ context.arg = new TypeError(
482
+ "The iterator does not provide a 'throw' method");
483
+ }
484
+
485
+ return ContinueSentinel;
486
+ }
487
+
488
+ var record = tryCatch(method, delegate.iterator, context.arg);
489
+
490
+ if (record.type === "throw") {
491
+ context.method = "throw";
492
+ context.arg = record.arg;
493
+ context.delegate = null;
494
+ return ContinueSentinel;
495
+ }
496
+
497
+ var info = record.arg;
498
+
499
+ if (! info) {
500
+ context.method = "throw";
501
+ context.arg = new TypeError("iterator result is not an object");
502
+ context.delegate = null;
503
+ return ContinueSentinel;
504
+ }
505
+
506
+ if (info.done) {
507
+ // Assign the result of the finished delegate to the temporary
508
+ // variable specified by delegate.resultName (see delegateYield).
509
+ context[delegate.resultName] = info.value;
510
+
511
+ // Resume execution at the desired location (see delegateYield).
512
+ context.next = delegate.nextLoc;
513
+
514
+ // If context.method was "throw" but the delegate handled the
515
+ // exception, let the outer generator proceed normally. If
516
+ // context.method was "next", forget context.arg since it has been
517
+ // "consumed" by the delegate iterator. If context.method was
518
+ // "return", allow the original .return call to continue in the
519
+ // outer generator.
520
+ if (context.method !== "return") {
521
+ context.method = "next";
522
+ context.arg = undefined$1;
523
+ }
524
+
525
+ } else {
526
+ // Re-yield the result returned by the delegate method.
527
+ return info;
528
+ }
529
+
530
+ // The delegate iterator is finished, so forget it and continue with
531
+ // the outer generator.
532
+ context.delegate = null;
533
+ return ContinueSentinel;
534
+ }
535
+
536
+ // Define Generator.prototype.{next,throw,return} in terms of the
537
+ // unified ._invoke helper method.
538
+ defineIteratorMethods(Gp);
539
+
540
+ define(Gp, toStringTagSymbol, "Generator");
541
+
542
+ // A Generator should always return itself as the iterator object when the
543
+ // @@iterator function is called on it. Some browsers' implementations of the
544
+ // iterator prototype chain incorrectly implement this, causing the Generator
545
+ // object to not be returned from this call. This ensures that doesn't happen.
546
+ // See https://github.com/facebook/regenerator/issues/274 for more details.
547
+ define(Gp, iteratorSymbol, function() {
548
+ return this;
549
+ });
550
+
551
+ define(Gp, "toString", function() {
552
+ return "[object Generator]";
553
+ });
554
+
555
+ function pushTryEntry(locs) {
556
+ var entry = { tryLoc: locs[0] };
557
+
558
+ if (1 in locs) {
559
+ entry.catchLoc = locs[1];
560
+ }
561
+
562
+ if (2 in locs) {
563
+ entry.finallyLoc = locs[2];
564
+ entry.afterLoc = locs[3];
565
+ }
566
+
567
+ this.tryEntries.push(entry);
568
+ }
569
+
570
+ function resetTryEntry(entry) {
571
+ var record = entry.completion || {};
572
+ record.type = "normal";
573
+ delete record.arg;
574
+ entry.completion = record;
575
+ }
576
+
577
+ function Context(tryLocsList) {
578
+ // The root entry object (effectively a try statement without a catch
579
+ // or a finally block) gives us a place to store values thrown from
580
+ // locations where there is no enclosing try statement.
581
+ this.tryEntries = [{ tryLoc: "root" }];
582
+ tryLocsList.forEach(pushTryEntry, this);
583
+ this.reset(true);
584
+ }
585
+
586
+ exports.keys = function(object) {
587
+ var keys = [];
588
+ for (var key in object) {
589
+ keys.push(key);
590
+ }
591
+ keys.reverse();
592
+
593
+ // Rather than returning an object with a next method, we keep
594
+ // things simple and return the next function itself.
595
+ return function next() {
596
+ while (keys.length) {
597
+ var key = keys.pop();
598
+ if (key in object) {
599
+ next.value = key;
600
+ next.done = false;
601
+ return next;
602
+ }
603
+ }
604
+
605
+ // To avoid creating an additional object, we just hang the .value
606
+ // and .done properties off the next function object itself. This
607
+ // also ensures that the minifier will not anonymize the function.
608
+ next.done = true;
609
+ return next;
610
+ };
611
+ };
612
+
613
+ function values(iterable) {
614
+ if (iterable) {
615
+ var iteratorMethod = iterable[iteratorSymbol];
616
+ if (iteratorMethod) {
617
+ return iteratorMethod.call(iterable);
618
+ }
619
+
620
+ if (typeof iterable.next === "function") {
621
+ return iterable;
622
+ }
623
+
624
+ if (!isNaN(iterable.length)) {
625
+ var i = -1, next = function next() {
626
+ while (++i < iterable.length) {
627
+ if (hasOwn.call(iterable, i)) {
628
+ next.value = iterable[i];
629
+ next.done = false;
630
+ return next;
631
+ }
632
+ }
633
+
634
+ next.value = undefined$1;
635
+ next.done = true;
636
+
637
+ return next;
638
+ };
639
+
640
+ return next.next = next;
641
+ }
642
+ }
643
+
644
+ // Return an iterator with no values.
645
+ return { next: doneResult };
646
+ }
647
+ exports.values = values;
648
+
649
+ function doneResult() {
650
+ return { value: undefined$1, done: true };
651
+ }
652
+
653
+ Context.prototype = {
654
+ constructor: Context,
655
+
656
+ reset: function(skipTempReset) {
657
+ this.prev = 0;
658
+ this.next = 0;
659
+ // Resetting context._sent for legacy support of Babel's
660
+ // function.sent implementation.
661
+ this.sent = this._sent = undefined$1;
662
+ this.done = false;
663
+ this.delegate = null;
664
+
665
+ this.method = "next";
666
+ this.arg = undefined$1;
667
+
668
+ this.tryEntries.forEach(resetTryEntry);
669
+
670
+ if (!skipTempReset) {
671
+ for (var name in this) {
672
+ // Not sure about the optimal order of these conditions:
673
+ if (name.charAt(0) === "t" &&
674
+ hasOwn.call(this, name) &&
675
+ !isNaN(+name.slice(1))) {
676
+ this[name] = undefined$1;
677
+ }
678
+ }
679
+ }
680
+ },
681
+
682
+ stop: function() {
683
+ this.done = true;
684
+
685
+ var rootEntry = this.tryEntries[0];
686
+ var rootRecord = rootEntry.completion;
687
+ if (rootRecord.type === "throw") {
688
+ throw rootRecord.arg;
689
+ }
690
+
691
+ return this.rval;
692
+ },
693
+
694
+ dispatchException: function(exception) {
695
+ if (this.done) {
696
+ throw exception;
697
+ }
698
+
699
+ var context = this;
700
+ function handle(loc, caught) {
701
+ record.type = "throw";
702
+ record.arg = exception;
703
+ context.next = loc;
704
+
705
+ if (caught) {
706
+ // If the dispatched exception was caught by a catch block,
707
+ // then let that catch block handle the exception normally.
708
+ context.method = "next";
709
+ context.arg = undefined$1;
710
+ }
711
+
712
+ return !! caught;
713
+ }
714
+
715
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
716
+ var entry = this.tryEntries[i];
717
+ var record = entry.completion;
718
+
719
+ if (entry.tryLoc === "root") {
720
+ // Exception thrown outside of any try block that could handle
721
+ // it, so set the completion value of the entire function to
722
+ // throw the exception.
723
+ return handle("end");
724
+ }
725
+
726
+ if (entry.tryLoc <= this.prev) {
727
+ var hasCatch = hasOwn.call(entry, "catchLoc");
728
+ var hasFinally = hasOwn.call(entry, "finallyLoc");
729
+
730
+ if (hasCatch && hasFinally) {
731
+ if (this.prev < entry.catchLoc) {
732
+ return handle(entry.catchLoc, true);
733
+ } else if (this.prev < entry.finallyLoc) {
734
+ return handle(entry.finallyLoc);
735
+ }
736
+
737
+ } else if (hasCatch) {
738
+ if (this.prev < entry.catchLoc) {
739
+ return handle(entry.catchLoc, true);
740
+ }
741
+
742
+ } else if (hasFinally) {
743
+ if (this.prev < entry.finallyLoc) {
744
+ return handle(entry.finallyLoc);
745
+ }
746
+
747
+ } else {
748
+ throw new Error("try statement without catch or finally");
749
+ }
750
+ }
751
+ }
752
+ },
753
+
754
+ abrupt: function(type, arg) {
755
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
756
+ var entry = this.tryEntries[i];
757
+ if (entry.tryLoc <= this.prev &&
758
+ hasOwn.call(entry, "finallyLoc") &&
759
+ this.prev < entry.finallyLoc) {
760
+ var finallyEntry = entry;
761
+ break;
762
+ }
763
+ }
764
+
765
+ if (finallyEntry &&
766
+ (type === "break" ||
767
+ type === "continue") &&
768
+ finallyEntry.tryLoc <= arg &&
769
+ arg <= finallyEntry.finallyLoc) {
770
+ // Ignore the finally entry if control is not jumping to a
771
+ // location outside the try/catch block.
772
+ finallyEntry = null;
773
+ }
774
+
775
+ var record = finallyEntry ? finallyEntry.completion : {};
776
+ record.type = type;
777
+ record.arg = arg;
778
+
779
+ if (finallyEntry) {
780
+ this.method = "next";
781
+ this.next = finallyEntry.finallyLoc;
782
+ return ContinueSentinel;
783
+ }
784
+
785
+ return this.complete(record);
786
+ },
787
+
788
+ complete: function(record, afterLoc) {
789
+ if (record.type === "throw") {
790
+ throw record.arg;
791
+ }
792
+
793
+ if (record.type === "break" ||
794
+ record.type === "continue") {
795
+ this.next = record.arg;
796
+ } else if (record.type === "return") {
797
+ this.rval = this.arg = record.arg;
798
+ this.method = "return";
799
+ this.next = "end";
800
+ } else if (record.type === "normal" && afterLoc) {
801
+ this.next = afterLoc;
802
+ }
803
+
804
+ return ContinueSentinel;
805
+ },
806
+
807
+ finish: function(finallyLoc) {
808
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
809
+ var entry = this.tryEntries[i];
810
+ if (entry.finallyLoc === finallyLoc) {
811
+ this.complete(entry.completion, entry.afterLoc);
812
+ resetTryEntry(entry);
813
+ return ContinueSentinel;
814
+ }
815
+ }
816
+ },
817
+
818
+ "catch": function(tryLoc) {
819
+ for (var i = this.tryEntries.length - 1; i >= 0; --i) {
820
+ var entry = this.tryEntries[i];
821
+ if (entry.tryLoc === tryLoc) {
822
+ var record = entry.completion;
823
+ if (record.type === "throw") {
824
+ var thrown = record.arg;
825
+ resetTryEntry(entry);
826
+ }
827
+ return thrown;
828
+ }
829
+ }
830
+
831
+ // The context.catch method must only be called with a location
832
+ // argument that corresponds to a known catch block.
833
+ throw new Error("illegal catch attempt");
834
+ },
835
+
836
+ delegateYield: function(iterable, resultName, nextLoc) {
837
+ this.delegate = {
838
+ iterator: values(iterable),
839
+ resultName: resultName,
840
+ nextLoc: nextLoc
841
+ };
842
+
843
+ if (this.method === "next") {
844
+ // Deliberately forget the last sent value so that we don't
845
+ // accidentally pass it on to the delegate.
846
+ this.arg = undefined$1;
847
+ }
848
+
849
+ return ContinueSentinel;
850
+ }
851
+ };
852
+
853
+ // Regardless of whether this script is executing as a CommonJS module
854
+ // or not, return the runtime object so that we can declare the variable
855
+ // regeneratorRuntime in the outer scope, which allows this module to be
856
+ // injected easily by `bin/regenerator --include-runtime script.js`.
857
+ return exports;
858
+
859
+ }(
860
+ // If this script is executing as a CommonJS module, use module.exports
861
+ // as the regeneratorRuntime namespace. Otherwise create a new empty
862
+ // object. Either way, the resulting object will be used to initialize
863
+ // the regeneratorRuntime variable at the top of this file.
864
+ module.exports
865
+ ));
866
+
867
+ try {
868
+ regeneratorRuntime = runtime;
869
+ } catch (accidentalStrictMode) {
870
+ // This module should not be running in strict mode, so the above
871
+ // assignment should always work unless something is misconfigured. Just
872
+ // in case runtime.js accidentally runs in strict mode, in modern engines
873
+ // we can explicitly access globalThis. In older engines we can escape
874
+ // strict mode using a global Function call. This could conceivably fail
875
+ // if a Content Security Policy forbids using Function, but in that case
876
+ // the proper solution is to fix the accidental strict mode problem. If
877
+ // you've misconfigured your bundler to force strict mode and applied a
878
+ // CSP to forbid Function, and you're not willing to fix either of those
879
+ // problems, please detail your unique predicament in a GitHub issue.
880
+ if (typeof globalThis === "object") {
881
+ globalThis.regeneratorRuntime = runtime;
882
+ } else {
883
+ Function("r", "regeneratorRuntime = r")(runtime);
884
+ }
885
+ }
886
+ }(runtime));
887
+
888
+ var _regeneratorRuntime = runtime.exports;
889
+
890
+ var ChainId;
891
+
892
+ (function (ChainId) {
893
+ ChainId[ChainId["MAINNET"] = 1] = "MAINNET";
894
+ ChainId[ChainId["RINKEBY"] = 4] = "RINKEBY";
895
+ ChainId[ChainId["ARBITRUM_ONE"] = 42161] = "ARBITRUM_ONE";
896
+ ChainId[ChainId["ARBITRUM_RINKEBY"] = 421611] = "ARBITRUM_RINKEBY";
897
+ ChainId[ChainId["OPTIMISM"] = 10] = "OPTIMISM";
898
+ ChainId[ChainId["OPTIMISTIC_KOVAN"] = 69] = "OPTIMISTIC_KOVAN";
899
+ ChainId[ChainId["POLYGON"] = 137] = "POLYGON";
900
+ ChainId[ChainId["POLYGON_MUMBAI"] = 80001] = "POLYGON_MUMBAI";
901
+ })(ChainId || (ChainId = {}));
902
+
903
+ var coinGeckoBuff = /*#__PURE__*/fs.readFileSync( /*#__PURE__*/path__default["default"].resolve(__dirname, '../Assets/coingecko_uris.json'));
904
+ var logoURIsBuff = /*#__PURE__*/fs.readFileSync( /*#__PURE__*/path__default["default"].resolve(__dirname, '../Assets/logo_uris.json'));
905
+ var coingeckoURIs = /*#__PURE__*/JSON.parse( /*#__PURE__*/coinGeckoBuff.toString());
906
+ var logoUris = /*#__PURE__*/JSON.parse( /*#__PURE__*/logoURIsBuff.toString());
907
+
908
+ for (var _i = 0, _Object$keys = /*#__PURE__*/Object.keys(logoUris); _i < _Object$keys.length; _i++) {
909
+ var address = _Object$keys[_i];
910
+ logoUris[/*#__PURE__*/address.toLowerCase()] = logoUris[address];
911
+ }
912
+ var listNameToArbifiedListName = function listNameToArbifiedListName(name) {
913
+ var prefix = 'Arbed ';
914
+ var fileName = sanitizeString(name);
915
+
916
+ if (!fileName.startsWith(prefix)) {
917
+ fileName = prefix + fileName;
918
+ }
919
+
920
+ return fileName.split(' ').slice(0, 2).join(' ').slice(0, 20);
921
+ };
922
+ var getL2TokenAddressesFromL1 = /*#__PURE__*/function () {
923
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenAddresses, multiCaller, l1GatewayRouterAddress) {
924
+ var iFace;
925
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
926
+ while (1) {
927
+ switch (_context.prev = _context.next) {
928
+ case 0:
929
+ iFace = arbTs.abi.L1GatewayRouter__factory.createInterface();
930
+ _context.next = 3;
931
+ return multiCaller.multiCall(l1TokenAddresses.map(function (addr) {
932
+ return {
933
+ encoder: function encoder() {
934
+ return iFace.encodeFunctionData('calculateL2TokenAddress', [addr]);
935
+ },
936
+ decoder: function decoder(returnData) {
937
+ return iFace.decodeFunctionResult('calculateL2TokenAddress', returnData)[0];
938
+ },
939
+ targetAddr: l1GatewayRouterAddress
940
+ };
941
+ }));
942
+
943
+ case 3:
944
+ return _context.abrupt("return", _context.sent);
945
+
946
+ case 4:
947
+ case "end":
948
+ return _context.stop();
949
+ }
950
+ }
951
+ }, _callee);
952
+ }));
953
+
954
+ return function getL2TokenAddressesFromL1(_x, _x2, _x3) {
955
+ return _ref.apply(this, arguments);
956
+ };
957
+ }();
958
+ var getL2TokenAddressesFromL2 = /*#__PURE__*/function () {
959
+ var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(l1TokenAddresses, multiCaller, l2GatewayRouterAddress) {
960
+ var iFace;
961
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
962
+ while (1) {
963
+ switch (_context2.prev = _context2.next) {
964
+ case 0:
965
+ iFace = arbTs.abi.L2GatewayRouter__factory.createInterface();
966
+ _context2.next = 3;
967
+ return multiCaller.multiCall(l1TokenAddresses.map(function (addr) {
968
+ return {
969
+ encoder: function encoder() {
970
+ return iFace.encodeFunctionData('calculateL2TokenAddress', [addr]);
971
+ },
972
+ decoder: function decoder(returnData) {
973
+ return iFace.decodeFunctionResult('calculateL2TokenAddress', returnData)[0];
974
+ },
975
+ targetAddr: l2GatewayRouterAddress
976
+ };
977
+ }));
978
+
979
+ case 3:
980
+ return _context2.abrupt("return", _context2.sent);
981
+
982
+ case 4:
983
+ case "end":
984
+ return _context2.stop();
985
+ }
986
+ }
987
+ }, _callee2);
988
+ }));
989
+
990
+ return function getL2TokenAddressesFromL2(_x4, _x5, _x6) {
991
+ return _ref2.apply(this, arguments);
992
+ };
993
+ }();
994
+ var getLogoUri = /*#__PURE__*/function () {
995
+ var _ref3 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(l1TokenAddress) {
996
+ var l1TokenAddressLCase, logoUri, coinGeckoURI, trustWalletUri, uris, _iterator, _step, uri, res;
997
+
998
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
999
+ while (1) {
1000
+ switch (_context3.prev = _context3.next) {
1001
+ case 0:
1002
+ l1TokenAddressLCase = l1TokenAddress.toLowerCase();
1003
+ logoUri = logoUris[l1TokenAddressLCase];
1004
+ coinGeckoURI = coingeckoURIs[l1TokenAddressLCase];
1005
+ trustWalletUri = "https://raw.githubusercontent.com/trustwallet/assets/master/blockchains/ethereum/assets/" + l1TokenAddress + "/logo.png";
1006
+ uris = [logoUri, coinGeckoURI, trustWalletUri].filter(function (x) {
1007
+ return !!x;
1008
+ });
1009
+ _iterator = _createForOfIteratorHelperLoose(uris);
1010
+
1011
+ case 6:
1012
+ if ((_step = _iterator()).done) {
1013
+ _context3.next = 20;
1014
+ break;
1015
+ }
1016
+
1017
+ uri = _step.value;
1018
+ _context3.prev = 8;
1019
+ _context3.next = 11;
1020
+ return axios__default["default"].get(uri);
1021
+
1022
+ case 11:
1023
+ res = _context3.sent;
1024
+
1025
+ if (!(res.status === 200)) {
1026
+ _context3.next = 14;
1027
+ break;
1028
+ }
1029
+
1030
+ return _context3.abrupt("return", uri);
1031
+
1032
+ case 14:
1033
+ _context3.next = 18;
1034
+ break;
1035
+
1036
+ case 16:
1037
+ _context3.prev = 16;
1038
+ _context3.t0 = _context3["catch"](8);
1039
+
1040
+ case 18:
1041
+ _context3.next = 6;
1042
+ break;
1043
+
1044
+ case 20:
1045
+ return _context3.abrupt("return");
1046
+
1047
+ case 21:
1048
+ case "end":
1049
+ return _context3.stop();
1050
+ }
1051
+ }
1052
+ }, _callee3, null, [[8, 16]]);
1053
+ }));
1054
+
1055
+ return function getLogoUri(_x7) {
1056
+ return _ref3.apply(this, arguments);
1057
+ };
1058
+ }();
1059
+ var getTokenListObjFromUrl = /*#__PURE__*/function () {
1060
+ var _ref4 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(url) {
1061
+ return _regeneratorRuntime.wrap(function _callee4$(_context4) {
1062
+ while (1) {
1063
+ switch (_context4.prev = _context4.next) {
1064
+ case 0:
1065
+ _context4.next = 2;
1066
+ return axios__default["default"].get(url);
1067
+
1068
+ case 2:
1069
+ return _context4.abrupt("return", _context4.sent.data);
1070
+
1071
+ case 3:
1072
+ case "end":
1073
+ return _context4.stop();
1074
+ }
1075
+ }
1076
+ }, _callee4);
1077
+ }));
1078
+
1079
+ return function getTokenListObjFromUrl(_x8) {
1080
+ return _ref4.apply(this, arguments);
1081
+ };
1082
+ }();
1083
+ var getTokenListObjFromLocalPath = /*#__PURE__*/function () {
1084
+ var _ref5 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5(path) {
1085
+ return _regeneratorRuntime.wrap(function _callee5$(_context5) {
1086
+ while (1) {
1087
+ switch (_context5.prev = _context5.next) {
1088
+ case 0:
1089
+ return _context5.abrupt("return", JSON.parse(fs.readFileSync(path).toString()));
1090
+
1091
+ case 1:
1092
+ case "end":
1093
+ return _context5.stop();
1094
+ }
1095
+ }
1096
+ }, _callee5);
1097
+ }));
1098
+
1099
+ return function getTokenListObjFromLocalPath(_x9) {
1100
+ return _ref5.apply(this, arguments);
1101
+ };
1102
+ }();
1103
+ var tokenListIsValid = function tokenListIsValid(tokenList) {
1104
+ var ajv = new Ajv__default["default"]();
1105
+ addFormats__default["default"](ajv);
1106
+ var validate = ajv.compile(tokenLists.schema);
1107
+ var res = validate(tokenList);
1108
+
1109
+ if (validate.errors) {
1110
+ var output = betterAjvErrors__default["default"](tokenLists.schema, tokenList, validate.errors, {
1111
+ indent: 2
1112
+ });
1113
+ console.log(output);
1114
+ }
1115
+
1116
+ return res;
1117
+ };
1118
+ var validateTokenListWithErrorThrowing = function validateTokenListWithErrorThrowing(tokenList) {
1119
+ try {
1120
+ var valid = tokenListIsValid(tokenList);
1121
+ if (valid) return true;else throw new Error('Data does not conform to token list schema; not sure why');
1122
+ } catch (e) {
1123
+ console.log('Invalid token list:');
1124
+ throw e;
1125
+ }
1126
+ };
1127
+ var getTokenListObj = /*#__PURE__*/function () {
1128
+ var _ref6 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee7(pathOrUrl) {
1129
+ var tokenList;
1130
+ return _regeneratorRuntime.wrap(function _callee7$(_context7) {
1131
+ while (1) {
1132
+ switch (_context7.prev = _context7.next) {
1133
+ case 0:
1134
+ _context7.next = 2;
1135
+ return function () {
1136
+ var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(pathOrUrl) {
1137
+ var localFileExists, looksLikeUrl;
1138
+ return _regeneratorRuntime.wrap(function _callee6$(_context6) {
1139
+ while (1) {
1140
+ switch (_context6.prev = _context6.next) {
1141
+ case 0:
1142
+ localFileExists = fs.existsSync(pathOrUrl);
1143
+ looksLikeUrl = isValidHttpUrl(pathOrUrl);
1144
+
1145
+ if (!localFileExists) {
1146
+ _context6.next = 6;
1147
+ break;
1148
+ }
1149
+
1150
+ return _context6.abrupt("return", getTokenListObjFromLocalPath(pathOrUrl));
1151
+
1152
+ case 6:
1153
+ if (!looksLikeUrl) {
1154
+ _context6.next = 12;
1155
+ break;
1156
+ }
1157
+
1158
+ _context6.next = 9;
1159
+ return getTokenListObjFromUrl(pathOrUrl);
1160
+
1161
+ case 9:
1162
+ return _context6.abrupt("return", _context6.sent);
1163
+
1164
+ case 12:
1165
+ throw new Error('Could not find token list');
1166
+
1167
+ case 13:
1168
+ case "end":
1169
+ return _context6.stop();
1170
+ }
1171
+ }
1172
+ }, _callee6);
1173
+ }));
1174
+
1175
+ return function (_x11) {
1176
+ return _ref7.apply(this, arguments);
1177
+ };
1178
+ }()(pathOrUrl);
1179
+
1180
+ case 2:
1181
+ tokenList = _context7.sent;
1182
+ isTokenList(tokenList);
1183
+ return _context7.abrupt("return", tokenList);
1184
+
1185
+ case 5:
1186
+ case "end":
1187
+ return _context7.stop();
1188
+ }
1189
+ }
1190
+ }, _callee7);
1191
+ }));
1192
+
1193
+ return function getTokenListObj(_x10) {
1194
+ return _ref6.apply(this, arguments);
1195
+ };
1196
+ }(); // https://stackoverflow.com/questions/5717093/check-if-a-javascript-string-is-a-url
1197
+
1198
+ function isValidHttpUrl(urlString) {
1199
+ var url;
1200
+
1201
+ try {
1202
+ url = new URL(urlString);
1203
+ } catch (_) {
1204
+ return false;
1205
+ }
1206
+
1207
+ return url.protocol === 'http:' || url.protocol === 'https:';
1208
+ } // typeguard:
1209
+
1210
+ var isTokenList = function isTokenList(obj) {
1211
+ var expectedListKeys = ['name', 'timestamp', 'version', 'tokens'];
1212
+ var actualListKeys = new Set(Object.keys(obj));
1213
+
1214
+ if (!expectedListKeys.every(function (key) {
1215
+ return actualListKeys.has(key);
1216
+ })) {
1217
+ throw new Error("tokenlist typeguard error: requried list key not included");
1218
+ }
1219
+
1220
+ var version = obj.version,
1221
+ tokens = obj.tokens;
1222
+
1223
+ if (!['major', 'minor', 'patch'].every(function (key) {
1224
+ return typeof version[key] === 'number';
1225
+ })) {
1226
+ throw new Error("tokenlist typeguard error: invalid version");
1227
+ }
1228
+
1229
+ if (!tokens.every(function (token) {
1230
+ var tokenKeys = new Set(Object.keys(token));
1231
+ return ['chainId', 'address', 'name', 'decimals', 'symbol'].every(function (key) {
1232
+ return tokenKeys.has(key);
1233
+ });
1234
+ })) {
1235
+ throw new Error("tokenlist typeguard error: token missing required key");
1236
+ }
1237
+ };
1238
+ var sanitizeString = function sanitizeString(str) {
1239
+ return str.replace(/[^ \w.'+\-%/À-ÖØ-öø-ÿ:&\[\]\(\)]/gi, '');
1240
+ };
1241
+ var excludeList = /*#__PURE__*/['0x0CE51000d5244F1EAac0B313a792D5a5f96931BF', '0x4Dbd4fc535Ac27206064B68FfCf827b0A60BAB3f', '0xEDA6eFE5556e134Ef52f2F858aa1e81c84CDA84b', '0xe54942077Df7b8EEf8D4e6bCe2f7B58B0082b0cd', '0x282db609e787a132391eb64820ba6129fceb2695', '0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3', '0x106538cc16f938776c7c180186975bca23875287', '0xB4A3B0Faf0Ab53df58001804DdA5Bfc6a3D59008' // spera
1242
+ // "0x960b236a07cf122663c4303350609a66a7b288c0", //aragon old
1243
+ ].map(function (s) {
1244
+ return s.toLowerCase();
1245
+ });
1246
+
1247
+ var _templateObject, _templateObject2;
1248
+ var apolloL2GatewaysRinkebyClient = 'https://api.thegraph.com/subgraphs/name/fredlacs/layer2-token-gateway-rinkeby';
1249
+ var apolloL2GatewaysClient = 'https://api.thegraph.com/subgraphs/name/fredlacs/layer2-token-gateway';
1250
+
1251
+ var chaidIdToGraphClientUrl = function chaidIdToGraphClientUrl(chainID) {
1252
+ switch (chainID) {
1253
+ case '42161':
1254
+ return apolloL2GatewaysClient;
1255
+
1256
+ case '421611':
1257
+ return apolloL2GatewaysRinkebyClient;
1258
+
1259
+ default:
1260
+ throw new Error('Unsupported chain');
1261
+ }
1262
+ };
1263
+
1264
+ var isGraphTokenResult = function isGraphTokenResult(obj) {
1265
+ if (!obj) {
1266
+ throw new Error("Graph result: undefined");
1267
+ }
1268
+
1269
+ var expectedKeys = ["joinTableEntry", "l1TokenAddr"];
1270
+ var actualKeys = new Set(Object.keys(obj));
1271
+
1272
+ if (!expectedKeys.every(function (key) {
1273
+ return actualKeys.has(key);
1274
+ })) {
1275
+ throw new Error("Graph result: missing top level key");
1276
+ }
1277
+
1278
+ var joinTableEntry = obj.joinTableEntry[0];
1279
+
1280
+ if (!joinTableEntry) {
1281
+ throw new Error("Graph result: no joinTableEntry");
1282
+ }
1283
+
1284
+ if (!joinTableEntry.gateway.gatewayAddr) {
1285
+ throw new Error("Graph result: could not get gateway address");
1286
+ }
1287
+ };
1288
+
1289
+ var getTokens = /*#__PURE__*/function () {
1290
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenAddresses, networkID) {
1291
+ var clientUrl, allTokens, allTokenAddresses, formattedAddresses, query, _yield$request, tokens;
1292
+
1293
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1294
+ while (1) {
1295
+ switch (_context.prev = _context.next) {
1296
+ case 0:
1297
+ clientUrl = chaidIdToGraphClientUrl(networkID); // lazy solution for big lists for now; we'll have to paginate once we have > 500 tokens registed
1298
+
1299
+ if (!(l1TokenAddresses.length > 500)) {
1300
+ _context.next = 9;
1301
+ break;
1302
+ }
1303
+
1304
+ _context.next = 4;
1305
+ return getAllTokens(networkID);
1306
+
1307
+ case 4:
1308
+ allTokens = _context.sent;
1309
+ allTokenAddresses = new Set(allTokens.map(function (token) {
1310
+ return token.l1TokenAddr.toLowerCase();
1311
+ }));
1312
+ l1TokenAddresses = l1TokenAddresses.filter(function (addr) {
1313
+ return allTokenAddresses.has(addr.toLowerCase());
1314
+ });
1315
+
1316
+ if (!(l1TokenAddresses.length > 500)) {
1317
+ _context.next = 9;
1318
+ break;
1319
+ }
1320
+
1321
+ throw new Error("Too many tokens for graph query");
1322
+
1323
+ case 9:
1324
+ formattedAddresses = l1TokenAddresses.map(function (a) {
1325
+ return ("\"" + a + "\"").toLowerCase();
1326
+ }).join(',');
1327
+ query = graphqlRequest.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);
1328
+ _context.next = 13;
1329
+ return graphqlRequest.request(clientUrl, query);
1330
+
1331
+ case 13:
1332
+ _yield$request = _context.sent;
1333
+ tokens = _yield$request.tokens;
1334
+ tokens.map(function (token) {
1335
+ return isGraphTokenResult(token);
1336
+ });
1337
+ return _context.abrupt("return", tokens.filter(function (token) {
1338
+ return !excludeList.includes(token.l1TokenAddr.toLowerCase());
1339
+ }));
1340
+
1341
+ case 17:
1342
+ case "end":
1343
+ return _context.stop();
1344
+ }
1345
+ }
1346
+ }, _callee);
1347
+ }));
1348
+
1349
+ return function getTokens(_x, _x2) {
1350
+ return _ref.apply(this, arguments);
1351
+ };
1352
+ }();
1353
+ var getAllTokens = /*#__PURE__*/function () {
1354
+ var _ref2 = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(networkID) {
1355
+ var clientUrl, query, _yield$request2, tokens;
1356
+
1357
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1358
+ while (1) {
1359
+ switch (_context2.prev = _context2.next) {
1360
+ case 0:
1361
+ clientUrl = chaidIdToGraphClientUrl(networkID);
1362
+ query = graphqlRequest.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 "])));
1363
+ _context2.next = 4;
1364
+ return graphqlRequest.request(clientUrl, query);
1365
+
1366
+ case 4:
1367
+ _yield$request2 = _context2.sent;
1368
+ tokens = _yield$request2.tokens;
1369
+ tokens.map(function (token) {
1370
+ return isGraphTokenResult(token);
1371
+ });
1372
+ return _context2.abrupt("return", tokens.filter(function (token) {
1373
+ return !excludeList.includes(token.l1TokenAddr.toLowerCase());
1374
+ }));
1375
+
1376
+ case 8:
1377
+ case "end":
1378
+ return _context2.stop();
1379
+ }
1380
+ }
1381
+ }, _callee2);
1382
+ }));
1383
+
1384
+ return function getAllTokens(_x3) {
1385
+ return _ref2.apply(this, arguments);
1386
+ };
1387
+ }();
1388
+
1389
+ /*
1390
+ * Copyright 2021, Offchain Labs, Inc.
1391
+ *
1392
+ * Licensed under the Apache License, Version 2.0 (the "License");
1393
+ * you may not use this file except in compliance with the License.
1394
+ * You may obtain a copy of the License at
1395
+ *
1396
+ * http://www.apache.org/licenses/LICENSE-2.0
1397
+ *
1398
+ * Unless required by applicable law or agreed to in writing, software
1399
+ * distributed under the License is distributed on an "AS IS" BASIS,
1400
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1401
+ * See the License for the specific language governing permissions and
1402
+ * limitations under the License.
1403
+ */
1404
+ var argv = /*#__PURE__*/yargs__default["default"](process.argv.slice(2)).options({
1405
+ l2NetworkID: {
1406
+ type: 'number'
1407
+ },
1408
+ tokenList: {
1409
+ type: 'string'
1410
+ }
1411
+ }).parseSync();
1412
+
1413
+ var _args$l2NetworkID;
1414
+ dotenv__default["default"].config();
1415
+ var networkID = ((_args$l2NetworkID = argv.l2NetworkID) == null ? void 0 : /*#__PURE__*/_args$l2NetworkID.toString()) || '42161';
1416
+ console.log('Using L2 networkID:', networkID);
1417
+ var getNetworkConfig = /*#__PURE__*/function () {
1418
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
1419
+ var l2Network, l1Network, arbProvider, ethProvider, l1MultiCaller, l2MultiCaller, tokenBridger;
1420
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1421
+ while (1) {
1422
+ switch (_context.prev = _context.next) {
1423
+ case 0:
1424
+ _context.next = 2;
1425
+ return arbTs.getL2Network(networkID);
1426
+
1427
+ case 2:
1428
+ l2Network = _context.sent;
1429
+ _context.next = 5;
1430
+ return arbTs.getL1Network(l2Network.partnerChainID);
1431
+
1432
+ case 5:
1433
+ l1Network = _context.sent;
1434
+ arbProvider = new ethers.providers.JsonRpcProvider(l2Network.rpcURL);
1435
+ ethProvider = new ethers.providers.JsonRpcProvider(l1Network.rpcURL);
1436
+ _context.next = 10;
1437
+ return arbTs.MultiCaller.fromProvider(ethProvider);
1438
+
1439
+ case 10:
1440
+ l1MultiCaller = _context.sent;
1441
+ _context.next = 13;
1442
+ return arbTs.MultiCaller.fromProvider(arbProvider);
1443
+
1444
+ case 13:
1445
+ l2MultiCaller = _context.sent;
1446
+ tokenBridger = new arbTs.TokenBridger(l2Network);
1447
+ return _context.abrupt("return", {
1448
+ l1: {
1449
+ network: l1Network,
1450
+ provider: ethProvider,
1451
+ multiCaller: l1MultiCaller
1452
+ },
1453
+ l2: {
1454
+ network: l2Network,
1455
+ provider: arbProvider,
1456
+ multiCaller: l2MultiCaller
1457
+ },
1458
+ tokenBridger: tokenBridger
1459
+ });
1460
+
1461
+ case 16:
1462
+ case "end":
1463
+ return _context.stop();
1464
+ }
1465
+ }
1466
+ }, _callee);
1467
+ }));
1468
+
1469
+ return function getNetworkConfig() {
1470
+ return _ref.apply(this, arguments);
1471
+ };
1472
+ }();
1473
+
1474
+ var l2ToL1GatewayAddresses = {
1475
+ // L2 ERC20 Gateway mainnet
1476
+ '0x09e9222e96e7b4ae2a407b98d48e330053351eee': '0xa3A7B6F88361F48403514059F1F16C8E78d60EeC',
1477
+ // L2 Arb-Custom Gateway mainnet
1478
+ '0x096760f208390250649e3e8763348e783aef5562': '0xcEe284F754E854890e311e3280b767F80797180d',
1479
+ // L2 weth mainnet
1480
+ '0x6c411ad3e74de3e7bd422b94a27770f5b86c623b': '0xd92023E9d9911199a6711321D1277285e6d4e2db',
1481
+ // L2 dai gateway mainnet
1482
+ '0x467194771dae2967aef3ecbedd3bf9a310c76c65': '0xd3b5b60020504bc3489d6949d545893982ba3011',
1483
+ // L2 ERC20 Gateway rinkeby
1484
+ "0x195c107f3f75c4c93eba7d9a1312f19305d6375f": "0x91169Dbb45e6804743F94609De50D511C437572E",
1485
+ // L2 Arb-Custom Gateway rinkeby
1486
+ "0x9b014455acc2fe90c52803849d0002aeec184a06": "0x917dc9a69F65dC3082D518192cd3725E1Fa96cA2",
1487
+ // L2 Weth Gateway rinkeby
1488
+ "0xf94bc045c4e926cc0b34e8d1c41cd7a043304ac9": "0x81d1a19cf7071732D4313c75dE8DD5b8CF697eFD",
1489
+ // old L2 weth gateway in rinkeby? we can prob remove this
1490
+ "0xf90eb31045d5b924900aff29344deb42eae0b087": "0x81d1a19cf7071732D4313c75dE8DD5b8CF697eFD",
1491
+ // livepeer gateway mainnet
1492
+ "0x6d2457a4ad276000a615295f7a80f79e48ccd318": "0x6142f1C8bBF02E6A6bd074E8d564c9A5420a0676"
1493
+ };
1494
+ var generateTokenList = /*#__PURE__*/function () {
1495
+ var _ref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenList, prevArbTokenList, options) {
1496
+ 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;
1497
+
1498
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1499
+ while (1) {
1500
+ switch (_context.prev = _context.next) {
1501
+ case 0:
1502
+ if (!(options != null && options.includeAllL1Tokens && options.includeUnbridgedL1Tokens)) {
1503
+ _context.next = 2;
1504
+ break;
1505
+ }
1506
+
1507
+ throw new Error("Cannot include both of AllL1Tokens and UnbridgedL1Tokens since UnbridgedL1Tokens is a subset of AllL1Tokens.");
1508
+
1509
+ case 2:
1510
+ name = l1TokenList.name;
1511
+ mainLogoUri = l1TokenList.logoURI;
1512
+ _context.next = 6;
1513
+ return getNetworkConfig();
1514
+
1515
+ case 6:
1516
+ _yield$getNetworkConf = _context.sent;
1517
+ l1 = _yield$getNetworkConf.l1;
1518
+ l2 = _yield$getNetworkConf.l2;
1519
+
1520
+ if (!(options && options.getAllTokensInNetwork)) {
1521
+ _context.next = 15;
1522
+ break;
1523
+ }
1524
+
1525
+ _context.next = 12;
1526
+ return getAllTokens(l2.network.chainID);
1527
+
1528
+ case 12:
1529
+ _context.t0 = _context.sent;
1530
+ _context.next = 18;
1531
+ break;
1532
+
1533
+ case 15:
1534
+ _context.next = 17;
1535
+ return getTokens(l1TokenList.tokens.map(function (token) {
1536
+ return token.address.toLowerCase();
1537
+ }), l2.network.chainID);
1538
+
1539
+ case 17:
1540
+ _context.t0 = _context.sent;
1541
+
1542
+ case 18:
1543
+ tokens = _context.t0;
1544
+ l1TokenAddresses = tokens.map(function (token) {
1545
+ return token.l1TokenAddr;
1546
+ });
1547
+ _context.next = 22;
1548
+ return getL2TokenAddressesFromL1(l1TokenAddresses, l1.multiCaller, l2.network.tokenBridge.l1GatewayRouter);
1549
+
1550
+ case 22:
1551
+ l2AddressesFromL1 = _context.sent;
1552
+ _context.next = 25;
1553
+ return getL2TokenAddressesFromL2(l1TokenAddresses, l2.multiCaller, l2.network.tokenBridge.l2GatewayRouter);
1554
+
1555
+ case 25:
1556
+ l2AddressesFromL2 = _context.sent;
1557
+ // if the l2 route hasn't been updated yet we remove the token from the bridged tokens
1558
+ tokens = tokens.filter(function (t, i) {
1559
+ return l2AddressesFromL1[i] === l2AddressesFromL2[i];
1560
+ });
1561
+ _context.next = 29;
1562
+ return l2.multiCaller.getTokenData(l2AddressesFromL1.map(function (t) {
1563
+ return t || ethers.constants.AddressZero;
1564
+ }), {
1565
+ name: true,
1566
+ decimals: true,
1567
+ symbol: true
1568
+ });
1569
+
1570
+ case 29:
1571
+ tokenData = _context.sent;
1572
+ logoUris = [];
1573
+ _iterator = _createForOfIteratorHelperLoose(tokens);
1574
+
1575
+ case 32:
1576
+ if ((_step = _iterator()).done) {
1577
+ _context.next = 40;
1578
+ break;
1579
+ }
1580
+
1581
+ token = _step.value;
1582
+ _context.next = 36;
1583
+ return getLogoUri(token.l1TokenAddr);
1584
+
1585
+ case 36:
1586
+ uri = _context.sent;
1587
+ logoUris.push(uri);
1588
+
1589
+ case 38:
1590
+ _context.next = 32;
1591
+ break;
1592
+
1593
+ case 40:
1594
+ arbifiedTokens = tokens.map(function (t, i) {
1595
+ return {
1596
+ token: t,
1597
+ l2Address: l2AddressesFromL2[i],
1598
+ tokenDatum: tokenData[i]
1599
+ };
1600
+ }) // it's possible that even though l2AddressesFromL1[i] === l2AddressesFromL2[i] these addresses could be the zero address
1601
+ // this can happen if the graphql query returns an address that hasnt been bridged
1602
+ .filter(function (t) {
1603
+ return t.l2Address != undefined && t.l2Address !== ethers.constants.AddressZero;
1604
+ }).map(function (token, i) {
1605
+ var _bridgeInfo, _bridgeInfo2;
1606
+
1607
+ var l2GatewayAddress = token.token.joinTableEntry[0].gateway.gatewayAddr;
1608
+ var _token$tokenDatum = token.tokenDatum,
1609
+ _name = _token$tokenDatum.name,
1610
+ decimals = _token$tokenDatum.decimals,
1611
+ _symbol = _token$tokenDatum.symbol;
1612
+ if (decimals === undefined) throw new Error("Unexpected undefined token decimals: " + JSON.stringify(token));
1613
+
1614
+ _name = function () {
1615
+ 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
1616
+ // we remove the initial 0x since the token list standard only allows up to 40 characters
1617
+ else if (_name === "") return token.token.l1TokenAddr.substring(2); // parse null terminated bytes32 strings
1618
+ else if (_name.length === 64) return ethers.utils.parseBytes32String("0x" + _name);else return _name;
1619
+ }();
1620
+
1621
+ _symbol = function () {
1622
+ 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
1623
+ else if (_symbol === "") return _name.substring(0, Math.min(_name.length, 20)); // parse null terminated bytes32 strings
1624
+ else if (_symbol.length === 64) return ethers.utils.parseBytes32String("0x" + _symbol);else return _symbol;
1625
+ }();
1626
+
1627
+ var name = sanitizeString(_name);
1628
+ var symbol = sanitizeString(_symbol);
1629
+ var arbTokenInfo = {
1630
+ chainId: +l2.network.chainID,
1631
+ address: token.l2Address,
1632
+ name: name,
1633
+ symbol: symbol,
1634
+ decimals: decimals,
1635
+ extensions: {
1636
+ bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[l1.network.chainID] = {
1637
+ tokenAddress: token.token.l1TokenAddr,
1638
+ originBridgeAddress: l2GatewayAddress,
1639
+ destBridgeAddress: l2ToL1GatewayAddresses[l2GatewayAddress.toLowerCase()]
1640
+ }, _bridgeInfo)
1641
+ }
1642
+ };
1643
+ var l1TokenInfo = {
1644
+ chainId: +l1.network.chainID,
1645
+ address: token.token.l1TokenAddr,
1646
+ name: name,
1647
+ symbol: symbol,
1648
+ decimals: decimals,
1649
+ extensions: {
1650
+ bridgeInfo: (_bridgeInfo2 = {}, _bridgeInfo2[l2.network.chainID] = {
1651
+ tokenAddress: token.l2Address,
1652
+ originBridgeAddress: l2ToL1GatewayAddresses[l2GatewayAddress.toLowerCase()],
1653
+ destBridgeAddress: l2GatewayAddress
1654
+ }, _bridgeInfo2)
1655
+ }
1656
+ };
1657
+
1658
+ if (logoUris[i]) {
1659
+ arbTokenInfo = _extends({}, {
1660
+ logoURI: logoUris[i]
1661
+ }, arbTokenInfo);
1662
+ } else {
1663
+ console.log('no logo uri for ', token.token.l1TokenAddr, symbol);
1664
+ }
1665
+
1666
+ return {
1667
+ arbTokenInfo: arbTokenInfo,
1668
+ l1TokenInfo: l1TokenInfo
1669
+ };
1670
+ }).filter(function (_ref2) {
1671
+ var arbTokenInfo = _ref2.arbTokenInfo;
1672
+ return arbTokenInfo.extensions && arbTokenInfo.extensions.bridgeInfo[l1.network.chainID].originBridgeAddress !== arbTs.constants.DISABLED_GATEWAY;
1673
+ });
1674
+ arbifiedTokenList = arbifiedTokens.map(function (_ref3) {
1675
+ var arbTokenInfo = _ref3.arbTokenInfo;
1676
+ return arbTokenInfo;
1677
+ }).sort(function (a, b) {
1678
+ return a.symbol < b.symbol ? -1 : 1;
1679
+ });
1680
+ l1ArbedTokenList = arbifiedTokens.map(function (_ref4) {
1681
+ var l1TokenInfo = _ref4.l1TokenInfo;
1682
+ return l1TokenInfo;
1683
+ });
1684
+ console.log("List has " + arbifiedTokenList.length + " bridged tokens");
1685
+
1686
+ if (options != null && options.includeAllL1Tokens) {
1687
+ arbifiedTokenList = arbifiedTokenList.concat(l1ArbedTokenList);
1688
+ } else if (options != null && options.includeUnbridgedL1Tokens) {
1689
+ l1AddressesOfBridgedTokens = new Set(tokens.map(function (token) {
1690
+ return token.l1TokenAddr.toLowerCase();
1691
+ }));
1692
+ unbridgedTokens = l1ArbedTokenList.filter(function (l1TokenInfo) {
1693
+ return !l1AddressesOfBridgedTokens.has(l1TokenInfo.address.toLowerCase()) && l1TokenInfo.chainId === +l1.network.chainID;
1694
+ }).sort(function (a, b) {
1695
+ return a.symbol < b.symbol ? -1 : 1;
1696
+ });
1697
+ console.log("List has " + unbridgedTokens.length + " unbridged tokens");
1698
+ arbifiedTokenList = arbifiedTokenList.concat(unbridgedTokens);
1699
+ }
1700
+
1701
+ version = function () {
1702
+ if (prevArbTokenList) {
1703
+ // @ts-ignore
1704
+ var versionBump = tokenLists.minVersionBump(prevArbTokenList.tokens, arbifiedTokenList); // tmp: library doesn't nicely handle patches (for extensions object)
1705
+
1706
+ if (versionBump === tokenLists.VersionUpgrade.PATCH) {
1707
+ versionBump = tokenLists.VersionUpgrade.NONE;
1708
+ }
1709
+
1710
+ return tokenLists.nextVersion(prevArbTokenList.version, versionBump);
1711
+ }
1712
+
1713
+ return {
1714
+ major: 1,
1715
+ minor: 0,
1716
+ patch: 0
1717
+ };
1718
+ }();
1719
+
1720
+ arbTokenList = {
1721
+ name: listNameToArbifiedListName(name),
1722
+ timestamp: new Date().toISOString(),
1723
+ version: version,
1724
+ tokens: arbifiedTokenList,
1725
+ logoURI: mainLogoUri
1726
+ };
1727
+ validationTokenList = _extends({}, arbTokenList, {
1728
+ tokens: arbTokenList.tokens
1729
+ });
1730
+ validateTokenListWithErrorThrowing(validationTokenList);
1731
+ console.log("Generated list with total " + arbTokenList.tokens.length + " tokens");
1732
+ console.log('version:', version);
1733
+ return _context.abrupt("return", arbTokenList);
1734
+
1735
+ case 52:
1736
+ case "end":
1737
+ return _context.stop();
1738
+ }
1739
+ }
1740
+ }, _callee);
1741
+ }));
1742
+
1743
+ return function generateTokenList(_x, _x2, _x3) {
1744
+ return _ref.apply(this, arguments);
1745
+ };
1746
+ }();
1747
+
1748
+ function compareTokenInfos(t1, t2) {
1749
+ if (t1.chainId === t2.chainId) {
1750
+ return t1.symbol.toLowerCase() < t2.symbol.toLowerCase() ? -1 : 1;
1751
+ }
1752
+
1753
+ return t1.chainId < t2.chainId ? -1 : 1;
1754
+ }
1755
+ function getTokenList(_x) {
1756
+ return _getTokenList.apply(this, arguments);
1757
+ }
1758
+
1759
+ function _getTokenList() {
1760
+ _getTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenListOrPathOrUrl) {
1761
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1762
+ while (1) {
1763
+ switch (_context.prev = _context.next) {
1764
+ case 0:
1765
+ if (!(typeof l1TokenListOrPathOrUrl === 'string')) {
1766
+ _context.next = 4;
1767
+ break;
1768
+ }
1769
+
1770
+ return _context.abrupt("return", getTokenListObj(l1TokenListOrPathOrUrl));
1771
+
1772
+ case 4:
1773
+ return _context.abrupt("return", l1TokenListOrPathOrUrl);
1774
+
1775
+ case 5:
1776
+ case "end":
1777
+ return _context.stop();
1778
+ }
1779
+ }
1780
+ }, _callee);
1781
+ }));
1782
+ return _getTokenList.apply(this, arguments);
1783
+ }
1784
+
1785
+ /**
1786
+ * The Arbitrum team maintains an (unpublished) package to `arbify` an L1
1787
+ * token list.
1788
+ *
1789
+ * The provider simply invokes this package which we host as a submodule.
1790
+ */
1791
+
1792
+ var ArbitrumMappingProvider = /*#__PURE__*/function () {
1793
+ function ArbitrumMappingProvider() {}
1794
+
1795
+ var _proto = ArbitrumMappingProvider.prototype;
1796
+
1797
+ _proto.provide = /*#__PURE__*/function () {
1798
+ var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenList) {
1799
+ var arbedTokenList;
1800
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1801
+ while (1) {
1802
+ switch (_context.prev = _context.next) {
1803
+ case 0:
1804
+ _context.next = 2;
1805
+ return generateTokenList(l1TokenList,
1806
+ /*prevArbTokenList=*/
1807
+ undefined, {
1808
+ includeAllL1Tokens: true
1809
+ });
1810
+
1811
+ case 2:
1812
+ arbedTokenList = _context.sent;
1813
+ return _context.abrupt("return", _extends({}, arbedTokenList, {
1814
+ tokens: arbedTokenList.tokens.sort(compareTokenInfos)
1815
+ }));
1816
+
1817
+ case 4:
1818
+ case "end":
1819
+ return _context.stop();
1820
+ }
1821
+ }
1822
+ }, _callee);
1823
+ }));
1824
+
1825
+ function provide(_x) {
1826
+ return _provide.apply(this, arguments);
1827
+ }
1828
+
1829
+ return provide;
1830
+ }();
1831
+
1832
+ return ArbitrumMappingProvider;
1833
+ }();
1834
+
1835
+ /**
1836
+ * The Optimism L2 mapping is manually maintained by the Optimism team.
1837
+ *
1838
+ * This provider mostly no-ops, i.e. grabs the list and returns it.
1839
+ */
1840
+ var OptimismMappingProvider = /*#__PURE__*/function () {
1841
+ function OptimismMappingProvider() {}
1842
+
1843
+ var _proto = OptimismMappingProvider.prototype;
1844
+
1845
+ _proto.provide = /*#__PURE__*/function () {
1846
+ var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenList) {
1847
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1848
+ while (1) {
1849
+ switch (_context.prev = _context.next) {
1850
+ case 0:
1851
+ return _context.abrupt("return", l1TokenList);
1852
+
1853
+ case 1:
1854
+ case "end":
1855
+ return _context.stop();
1856
+ }
1857
+ }
1858
+ }, _callee);
1859
+ }));
1860
+
1861
+ function provide(_x) {
1862
+ return _provide.apply(this, arguments);
1863
+ }
1864
+
1865
+ return provide;
1866
+ }();
1867
+
1868
+ return OptimismMappingProvider;
1869
+ }();
1870
+
1871
+ /**
1872
+ * The Polygon team manually maintains the mapping via user submissions at
1873
+ * https://mapper.polygon.technology.
1874
+ */
1875
+
1876
+ var PolygonMappingProvider = /*#__PURE__*/function () {
1877
+ function PolygonMappingProvider() {}
1878
+
1879
+ var _proto = PolygonMappingProvider.prototype;
1880
+
1881
+ _proto.provide = /*#__PURE__*/function () {
1882
+ var _provide = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenList) {
1883
+ var polygonTokens, mappedTokens, _iterator, _step, _bridgeInfo, _bridgeInfo2, _childToken$name, _childToken$symbol, rootToken, childToken, childTokenValid, toRootExtensions, toChildExtensions, rootTokenInfo, childTokenInfo, tokenList;
1884
+
1885
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
1886
+ while (1) {
1887
+ switch (_context.prev = _context.next) {
1888
+ case 0:
1889
+ _context.next = 2;
1890
+ return fetchPolygonMappedTokens();
1891
+
1892
+ case 2:
1893
+ polygonTokens = _context.sent;
1894
+ mappedTokens = [];
1895
+
1896
+ for (_iterator = _createForOfIteratorHelperLoose(l1TokenList.tokens); !(_step = _iterator()).done;) {
1897
+ rootToken = _step.value;
1898
+ childToken = polygonTokens[rootToken.address.toLowerCase()];
1899
+ childTokenValid = Boolean(childToken && !childToken.deleted); // build extension info if available
1900
+
1901
+ toRootExtensions = childTokenValid ? {
1902
+ extensions: {
1903
+ bridgeInfo: (_bridgeInfo = {}, _bridgeInfo[rootToken.chainId] = {
1904
+ tokenAddress: childToken.root_token
1905
+ }, _bridgeInfo)
1906
+ }
1907
+ } : {};
1908
+ toChildExtensions = childTokenValid ? {
1909
+ extensions: {
1910
+ bridgeInfo: (_bridgeInfo2 = {}, _bridgeInfo2[childToken.chainId] = {
1911
+ tokenAddress: childToken.child_token
1912
+ }, _bridgeInfo2)
1913
+ }
1914
+ } : {};
1915
+ rootTokenInfo = _extends({}, rootToken, toChildExtensions);
1916
+ childTokenInfo = _extends({}, rootToken, {
1917
+ chainId: childToken.chainId,
1918
+ name: (_childToken$name = childToken.name) != null ? _childToken$name : rootToken.name,
1919
+ symbol: (_childToken$symbol = childToken.symbol) != null ? _childToken$symbol : rootToken.symbol,
1920
+ address: childToken.child_token
1921
+ }, toRootExtensions);
1922
+ mappedTokens.push(rootTokenInfo);
1923
+ mappedTokens.push(childTokenInfo);
1924
+ }
1925
+
1926
+ tokenList = {
1927
+ name: "Polygon " + l1TokenList.name,
1928
+ timestamp: new Date().toISOString(),
1929
+ version: l1TokenList.version,
1930
+ tokens: mappedTokens.sort(compareTokenInfos)
1931
+ };
1932
+ return _context.abrupt("return", tokenList);
1933
+
1934
+ case 7:
1935
+ case "end":
1936
+ return _context.stop();
1937
+ }
1938
+ }
1939
+ }, _callee);
1940
+ }));
1941
+
1942
+ function provide(_x) {
1943
+ return _provide.apply(this, arguments);
1944
+ }
1945
+
1946
+ return provide;
1947
+ }();
1948
+
1949
+ return PolygonMappingProvider;
1950
+ }();
1951
+ var url = 'https://tokenmapper.api.matic.today/api/v1/mapping?';
1952
+ var params = 'map_type=[%22POS%22]&chain_id=137&limit=200&offset=';
1953
+
1954
+ function fetchPolygonMappedTokens() {
1955
+ return _fetchPolygonMappedTokens.apply(this, arguments);
1956
+ }
1957
+
1958
+ function _fetchPolygonMappedTokens() {
1959
+ _fetchPolygonMappedTokens = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
1960
+ var offset, tokens, response, _iterator2, _step2, token;
1961
+
1962
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
1963
+ while (1) {
1964
+ switch (_context2.prev = _context2.next) {
1965
+ case 0:
1966
+ offset = 0;
1967
+ tokens = {};
1968
+
1969
+ case 2:
1970
+
1971
+ _context2.next = 5;
1972
+ return axios__default["default"].get("" + url + params + offset);
1973
+
1974
+ case 5:
1975
+ response = _context2.sent;
1976
+
1977
+ if (!(response.data.message === 'success')) {
1978
+ _context2.next = 11;
1979
+ break;
1980
+ }
1981
+
1982
+ for (_iterator2 = _createForOfIteratorHelperLoose(response.data.data.mapping); !(_step2 = _iterator2()).done;) {
1983
+ token = _step2.value;
1984
+ tokens[token.root_token.toLowerCase()] = token;
1985
+ }
1986
+
1987
+ if (!(response.data.data.has_next_page === true)) {
1988
+ _context2.next = 11;
1989
+ break;
1990
+ }
1991
+
1992
+ offset += 200;
1993
+ return _context2.abrupt("continue", 2);
1994
+
1995
+ case 11:
1996
+ return _context2.abrupt("break", 14);
1997
+
1998
+ case 14:
1999
+ return _context2.abrupt("return", tokens);
2000
+
2001
+ case 15:
2002
+ case "end":
2003
+ return _context2.stop();
2004
+ }
2005
+ }
2006
+ }, _callee2);
2007
+ }));
2008
+ return _fetchPolygonMappedTokens.apply(this, arguments);
2009
+ }
2010
+
2011
+ function getMappingProvider(chainId) {
2012
+ switch (chainId) {
2013
+ case ChainId.ARBITRUM_ONE:
2014
+ return new ArbitrumMappingProvider();
2015
+
2016
+ case ChainId.OPTIMISM:
2017
+ return new OptimismMappingProvider();
2018
+
2019
+ case ChainId.POLYGON:
2020
+ return new PolygonMappingProvider();
2021
+
2022
+ default:
2023
+ throw new Error("Chain " + chainId + " not supported.");
2024
+ }
2025
+ }
2026
+
2027
+ /**
2028
+ * Verifies that for each token with extensions.bridgeInfo defined, for every
2029
+ * chainId there exists a token with that chainId at the root-level of the
2030
+ * token list.
2031
+ *
2032
+ * @returns input TokenList if valid, throws otherwise
2033
+ */
2034
+ function verifyExtensions(tokenList) {
2035
+ var _loop = function _loop() {
2036
+ var _token$extensions;
2037
+
2038
+ var token = _step.value;
2039
+ if (!((_token$extensions = token.extensions) != null && _token$extensions.bridgeInfo)) return "continue"; // if has extension, make sure that:
2040
+ // 1/ other token has root-level entry
2041
+ // 2/ other root entry has extension pointing to it
2042
+
2043
+ var _loop2 = function _loop2() {
2044
+ var _destToken$extensions;
2045
+
2046
+ var destChainId = _Object$keys[_i];
2047
+ var destTokens = tokenList.tokens.filter(function (t) {
2048
+ return t.chainId === Number(destChainId) && t.address === // @ts-expect-error TokenList schema does not allow bridgeInfo objetcs yet
2049
+ token.extensions.bridgeInfo[destChainId].tokenAddress;
2050
+ });
2051
+
2052
+ if (destTokens.length > 1) {
2053
+ throw new Error("TokenList has duplicate root-level tokens for " + token.symbol + " " + token.chainId);
2054
+ }
2055
+
2056
+ var destToken = destTokens[0];
2057
+
2058
+ if (!destToken) {
2059
+ throw new Error("TokenList is missing root-level TokenInfo for " + token.symbol + " " + token.chainId);
2060
+ } // ensure destToken has an extension pointing back to this
2061
+
2062
+
2063
+ var srcToken = // @ts-expect-error TokenList schema does not allow bridgeInfo objects yet
2064
+ (_destToken$extensions = destToken.extensions) == null ? void 0 : _destToken$extensions.bridgeInfo[token.chainId];
2065
+
2066
+ if (!srcToken) {
2067
+ throw new Error("TokenList is missing root-level TokenInfo.extensions.bridgeInfo for " + token.symbol + " " + token.chainId);
2068
+ }
2069
+
2070
+ if (srcToken.tokenAddress !== token.address) {
2071
+ throw new Error("TokenList has invalid root-level TokenInfo.extensions.bridgeInfo for " + token.symbol + " " + token.chainId + ". Expected " + token.address + " but got " + srcToken.tokenAddress);
2072
+ }
2073
+ };
2074
+
2075
+ for (var _i = 0, _Object$keys = Object.keys(token.extensions.bridgeInfo); _i < _Object$keys.length; _i++) {
2076
+ _loop2();
2077
+ }
2078
+ };
2079
+
2080
+ for (var _iterator = _createForOfIteratorHelperLoose(tokenList.tokens), _step; !(_step = _iterator()).done;) {
2081
+ var _ret = _loop();
2082
+
2083
+ if (_ret === "continue") continue;
2084
+ }
2085
+
2086
+ return tokenList;
2087
+ }
2088
+
2089
+ /**
2090
+ * Adds bridgeInfo to the given token list for Optimism, Polygon and Arbitrum.
2091
+ * @param l1TokenListOrPathOrUrl
2092
+ * @returns TokenList with l2 bridgeInfo filled
2093
+ */
2094
+
2095
+ function chainify(_x) {
2096
+ return _chainify.apply(this, arguments);
2097
+ }
2098
+ /**
2099
+ * Given a network and a TokenList, returns the TokenList with `extensions` filled.
2100
+ * @param chainId chainId to operate on
2101
+ * @param l1TokenListOrPathOrUrl either an L1 TokenList object or a path/url to a TokenList
2102
+ * @returns L1 TokenList with `extensions` filled for the given network
2103
+ */
2104
+
2105
+ function _chainify() {
2106
+ _chainify = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(l1TokenListOrPathOrUrl) {
2107
+ var l1TokenList, optimisimed, polygoned, arbified;
2108
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
2109
+ while (1) {
2110
+ switch (_context.prev = _context.next) {
2111
+ case 0:
2112
+ _context.next = 2;
2113
+ return getTokenList(l1TokenListOrPathOrUrl);
2114
+
2115
+ case 2:
2116
+ l1TokenList = _context.sent;
2117
+ _context.next = 5;
2118
+ return chainifyTokenList(ChainId.OPTIMISM, l1TokenListOrPathOrUrl);
2119
+
2120
+ case 5:
2121
+ optimisimed = _context.sent;
2122
+ _context.next = 8;
2123
+ return chainifyTokenList(ChainId.POLYGON, l1TokenListOrPathOrUrl);
2124
+
2125
+ case 8:
2126
+ polygoned = _context.sent;
2127
+ _context.next = 11;
2128
+ return chainifyTokenList(ChainId.ARBITRUM_ONE, l1TokenListOrPathOrUrl);
2129
+
2130
+ case 11:
2131
+ arbified = _context.sent;
2132
+ return _context.abrupt("return", mergeTokenLists(l1TokenList, // providing l1 first to make sure duplicated tokens resolve to this list
2133
+ mergeTokenLists(mergeTokenLists(arbified, optimisimed), polygoned)));
2134
+
2135
+ case 13:
2136
+ case "end":
2137
+ return _context.stop();
2138
+ }
2139
+ }
2140
+ }, _callee);
2141
+ }));
2142
+ return _chainify.apply(this, arguments);
2143
+ }
2144
+
2145
+ function chainifyTokenList(_x2, _x3) {
2146
+ return _chainifyTokenList.apply(this, arguments);
2147
+ }
2148
+ /** Merges two token lists, resolving conflicts to primary list. */
2149
+
2150
+ function _chainifyTokenList() {
2151
+ _chainifyTokenList = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(chainId, l1TokenListOrPathOrUrl) {
2152
+ var tokenList;
2153
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
2154
+ while (1) {
2155
+ switch (_context2.prev = _context2.next) {
2156
+ case 0:
2157
+ _context2.prev = 0;
2158
+ _context2.t0 = getMappingProvider(chainId);
2159
+ _context2.next = 4;
2160
+ return getTokenList(l1TokenListOrPathOrUrl);
2161
+
2162
+ case 4:
2163
+ _context2.t1 = _context2.sent;
2164
+ _context2.next = 7;
2165
+ return _context2.t0.provide.call(_context2.t0, _context2.t1);
2166
+
2167
+ case 7:
2168
+ tokenList = _context2.sent;
2169
+ return _context2.abrupt("return", verifyExtensions(tokenList));
2170
+
2171
+ case 11:
2172
+ _context2.prev = 11;
2173
+ _context2.t2 = _context2["catch"](0);
2174
+ throw new Error("An error occured: " + _context2.t2);
2175
+
2176
+ case 14:
2177
+ case "end":
2178
+ return _context2.stop();
2179
+ }
2180
+ }
2181
+ }, _callee2, null, [[0, 11]]);
2182
+ }));
2183
+ return _chainifyTokenList.apply(this, arguments);
2184
+ }
2185
+
2186
+ function mergeTokenLists(primary, secondary) {
2187
+ primary = lodash.cloneDeep(primary);
2188
+ secondary = lodash.cloneDeep(secondary);
2189
+ var grouped = lodash.groupBy([].concat(secondary.tokens, primary.tokens), function (t) {
2190
+ return t.chainId + "-" + t.address.toLowerCase();
2191
+ });
2192
+ var merged = Object.values(grouped).map(function (group) {
2193
+ var _merged$extensions;
2194
+
2195
+ if (group.length === 1) {
2196
+ return group[0];
2197
+ }
2198
+
2199
+ var merged = lodash.merge(group[0], group[1]);
2200
+
2201
+ if ((_merged$extensions = merged.extensions) != null && _merged$extensions.bridgeInfo) {
2202
+ // remove reference to self-chain from merge
2203
+ // @ts-expect-error TokenList schema doesn't yet define objects
2204
+ delete merged.extensions.bridgeInfo[merged.chainId];
2205
+ }
2206
+
2207
+ return merged;
2208
+ });
2209
+ return lodash.cloneDeep(_extends({}, primary, {
2210
+ tokens: merged.sort(compareTokenInfos)
2211
+ }));
2212
+ }
2213
+
2214
+ exports.chainify = chainify;
2215
+ exports.chainifyTokenList = chainifyTokenList;
2216
+ exports.mergeTokenLists = mergeTokenLists;
2217
+ //# sourceMappingURL=token-list-bridge-utils.cjs.development.js.map