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