@uniswap/router-sdk 1.9.0 → 1.9.1-beta.2

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.
@@ -19,8 +19,8 @@ var solidity = require('@ethersproject/solidity');
19
19
  var MSG_SENDER = '0x0000000000000000000000000000000000000001';
20
20
  var ADDRESS_THIS = '0x0000000000000000000000000000000000000002';
21
21
  var ZERO = /*#__PURE__*/JSBI.BigInt(0);
22
- var ONE = /*#__PURE__*/JSBI.BigInt(1); // = 1 << 23 or 100000000000000000000000
23
-
22
+ var ONE = /*#__PURE__*/JSBI.BigInt(1);
23
+ // = 1 << 23 or 100000000000000000000000
24
24
  var V2_FEE_PATH_PLACEHOLDER = 8388608;
25
25
  var ZERO_PERCENT = /*#__PURE__*/new sdkCore.Percent(ZERO);
26
26
  var ONE_HUNDRED_PERCENT = /*#__PURE__*/new sdkCore.Percent(100, 100);
@@ -31,9 +31,8 @@ var ONE_HUNDRED_PERCENT = /*#__PURE__*/new sdkCore.Percent(100, 100);
31
31
  ApprovalTypes[ApprovalTypes["MAX_MINUS_ONE"] = 2] = "MAX_MINUS_ONE";
32
32
  ApprovalTypes[ApprovalTypes["ZERO_THEN_MAX"] = 3] = "ZERO_THEN_MAX";
33
33
  ApprovalTypes[ApprovalTypes["ZERO_THEN_MAX_MINUS_ONE"] = 4] = "ZERO_THEN_MAX_MINUS_ONE";
34
- })(exports.ApprovalTypes || (exports.ApprovalTypes = {})); // type guard
35
-
36
-
34
+ })(exports.ApprovalTypes || (exports.ApprovalTypes = {}));
35
+ // type guard
37
36
  function isMint(options) {
38
37
  return Object.keys(options).some(function (k) {
39
38
  return k === 'recipient';
@@ -44,27 +43,21 @@ var ApproveAndCall = /*#__PURE__*/function () {
44
43
  * Cannot be constructed.
45
44
  */
46
45
  function ApproveAndCall() {}
47
-
48
46
  ApproveAndCall.encodeApproveMax = function encodeApproveMax(token) {
49
47
  return ApproveAndCall.INTERFACE.encodeFunctionData('approveMax', [token.address]);
50
48
  };
51
-
52
49
  ApproveAndCall.encodeApproveMaxMinusOne = function encodeApproveMaxMinusOne(token) {
53
50
  return ApproveAndCall.INTERFACE.encodeFunctionData('approveMaxMinusOne', [token.address]);
54
51
  };
55
-
56
52
  ApproveAndCall.encodeApproveZeroThenMax = function encodeApproveZeroThenMax(token) {
57
53
  return ApproveAndCall.INTERFACE.encodeFunctionData('approveZeroThenMax', [token.address]);
58
54
  };
59
-
60
55
  ApproveAndCall.encodeApproveZeroThenMaxMinusOne = function encodeApproveZeroThenMaxMinusOne(token) {
61
56
  return ApproveAndCall.INTERFACE.encodeFunctionData('approveZeroThenMaxMinusOne', [token.address]);
62
57
  };
63
-
64
58
  ApproveAndCall.encodeCallPositionManager = function encodeCallPositionManager(calldatas) {
65
59
  !(calldatas.length > 0) ? invariant(false, 'NULL_CALLDATA') : void 0;
66
-
67
- if (calldatas.length == 1) {
60
+ if (calldatas.length === 1) {
68
61
  return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', calldatas);
69
62
  } else {
70
63
  var encodedMulticall = v3Sdk.NonfungiblePositionManager.INTERFACE.encodeFunctionData('multicall', [calldatas]);
@@ -77,25 +70,20 @@ var ApproveAndCall = /*#__PURE__*/function () {
77
70
  * @param minimalPosition Forcasted position with custom minimal token amounts
78
71
  * @param addLiquidityOptions Options for adding liquidity
79
72
  * @param slippageTolerance Defines maximum slippage
80
- */
81
- ;
82
-
73
+ */;
83
74
  ApproveAndCall.encodeAddLiquidity = function encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, slippageTolerance) {
84
75
  var _position$mintAmounts = position.mintAmountsWithSlippage(slippageTolerance),
85
- amount0Min = _position$mintAmounts.amount0,
86
- amount1Min = _position$mintAmounts.amount1; // position.mintAmountsWithSlippage() can create amounts not dependenable in scenarios
76
+ amount0Min = _position$mintAmounts.amount0,
77
+ amount1Min = _position$mintAmounts.amount1;
78
+ // position.mintAmountsWithSlippage() can create amounts not dependenable in scenarios
87
79
  // such as range orders. Allow the option to provide a position with custom minimum amounts
88
80
  // for these scenarios
89
-
90
-
91
81
  if (JSBI.lessThan(minimalPosition.amount0.quotient, amount0Min)) {
92
82
  amount0Min = minimalPosition.amount0.quotient;
93
83
  }
94
-
95
84
  if (JSBI.lessThan(minimalPosition.amount1.quotient, amount1Min)) {
96
85
  amount1Min = minimalPosition.amount1.quotient;
97
86
  }
98
-
99
87
  if (isMint(addLiquidityOptions)) {
100
88
  return ApproveAndCall.INTERFACE.encodeFunctionData('mint', [{
101
89
  token0: position.pool.token0.address,
@@ -117,26 +105,20 @@ var ApproveAndCall = /*#__PURE__*/function () {
117
105
  }]);
118
106
  }
119
107
  };
120
-
121
108
  ApproveAndCall.encodeApprove = function encodeApprove(token, approvalType) {
122
109
  switch (approvalType) {
123
110
  case exports.ApprovalTypes.MAX:
124
111
  return ApproveAndCall.encodeApproveMax(token.wrapped);
125
-
126
112
  case exports.ApprovalTypes.MAX_MINUS_ONE:
127
113
  return ApproveAndCall.encodeApproveMaxMinusOne(token.wrapped);
128
-
129
114
  case exports.ApprovalTypes.ZERO_THEN_MAX:
130
115
  return ApproveAndCall.encodeApproveZeroThenMax(token.wrapped);
131
-
132
116
  case exports.ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE:
133
117
  return ApproveAndCall.encodeApproveZeroThenMaxMinusOne(token.wrapped);
134
-
135
118
  default:
136
- throw 'Error: invalid ApprovalType';
119
+ throw new Error('Error: invalid ApprovalType');
137
120
  }
138
121
  };
139
-
140
122
  return ApproveAndCall;
141
123
  }();
142
124
  ApproveAndCall.INTERFACE = /*#__PURE__*/new abi.Interface(IApproveAndCall_json.abi);
@@ -145,28 +127,23 @@ function validateAndParseBytes32(bytes32) {
145
127
  if (!bytes32.match(/^0x[0-9a-fA-F]{64}$/)) {
146
128
  throw new Error(bytes32 + " is not valid bytes32.");
147
129
  }
148
-
149
130
  return bytes32.toLowerCase();
150
131
  }
151
-
152
132
  var MulticallExtended = /*#__PURE__*/function () {
153
133
  /**
154
134
  * Cannot be constructed.
155
135
  */
156
136
  function MulticallExtended() {}
157
-
158
137
  MulticallExtended.encodeMulticall = function encodeMulticall(calldatas, validation) {
159
138
  // if there's no validation, we can just fall back to regular multicall
160
139
  if (typeof validation === 'undefined') {
161
140
  return v3Sdk.Multicall.encodeMulticall(calldatas);
162
- } // if there is validation, we have to normalize calldatas
163
-
164
-
141
+ }
142
+ // if there is validation, we have to normalize calldatas
165
143
  if (!Array.isArray(calldatas)) {
166
144
  calldatas = [calldatas];
167
- } // this means the validation value should be a previousBlockhash
168
-
169
-
145
+ }
146
+ // this means the validation value should be a previousBlockhash
170
147
  if (typeof validation === 'string' && validation.startsWith('0x')) {
171
148
  var previousBlockhash = validateAndParseBytes32(validation);
172
149
  return MulticallExtended.INTERFACE.encodeFunctionData('multicall(bytes32,bytes[])', [previousBlockhash, calldatas]);
@@ -175,7 +152,6 @@ var MulticallExtended = /*#__PURE__*/function () {
175
152
  return MulticallExtended.INTERFACE.encodeFunctionData('multicall(uint256,bytes[])', [deadline, calldatas]);
176
153
  }
177
154
  };
178
-
179
155
  return MulticallExtended;
180
156
  }();
181
157
  MulticallExtended.INTERFACE = /*#__PURE__*/new abi.Interface(IMulticallExtended_json.abi);
@@ -183,19 +159,16 @@ MulticallExtended.INTERFACE = /*#__PURE__*/new abi.Interface(IMulticallExtended_
183
159
  function encodeFeeBips(fee) {
184
160
  return v3Sdk.toHex(fee.multiply(10000).quotient);
185
161
  }
186
-
187
162
  var PaymentsExtended = /*#__PURE__*/function () {
188
163
  /**
189
164
  * Cannot be constructed.
190
165
  */
191
166
  function PaymentsExtended() {}
192
-
193
167
  PaymentsExtended.encodeUnwrapWETH9 = function encodeUnwrapWETH9(amountMinimum, recipient, feeOptions) {
194
168
  // if there's a recipient, just pass it along
195
169
  if (typeof recipient === 'string') {
196
170
  return v3Sdk.Payments.encodeUnwrapWETH9(amountMinimum, recipient, feeOptions);
197
171
  }
198
-
199
172
  if (!!feeOptions) {
200
173
  var feeBips = encodeFeeBips(feeOptions.fee);
201
174
  var feeRecipient = sdkCore.validateAndParseAddress(feeOptions.recipient);
@@ -204,13 +177,11 @@ var PaymentsExtended = /*#__PURE__*/function () {
204
177
  return PaymentsExtended.INTERFACE.encodeFunctionData('unwrapWETH9(uint256)', [v3Sdk.toHex(amountMinimum)]);
205
178
  }
206
179
  };
207
-
208
180
  PaymentsExtended.encodeSweepToken = function encodeSweepToken(token, amountMinimum, recipient, feeOptions) {
209
181
  // if there's a recipient, just pass it along
210
182
  if (typeof recipient === 'string') {
211
183
  return v3Sdk.Payments.encodeSweepToken(token, amountMinimum, recipient, feeOptions);
212
184
  }
213
-
214
185
  if (!!feeOptions) {
215
186
  var feeBips = encodeFeeBips(feeOptions.fee);
216
187
  var feeRecipient = sdkCore.validateAndParseAddress(feeOptions.recipient);
@@ -219,19 +190,331 @@ var PaymentsExtended = /*#__PURE__*/function () {
219
190
  return PaymentsExtended.INTERFACE.encodeFunctionData('sweepToken(address,uint256)', [token.address, v3Sdk.toHex(amountMinimum)]);
220
191
  }
221
192
  };
222
-
223
193
  PaymentsExtended.encodePull = function encodePull(token, amount) {
224
194
  return PaymentsExtended.INTERFACE.encodeFunctionData('pull', [token.address, v3Sdk.toHex(amount)]);
225
195
  };
226
-
227
196
  PaymentsExtended.encodeWrapETH = function encodeWrapETH(amount) {
228
197
  return PaymentsExtended.INTERFACE.encodeFunctionData('wrapETH', [v3Sdk.toHex(amount)]);
229
198
  };
230
-
231
199
  return PaymentsExtended;
232
200
  }();
233
201
  PaymentsExtended.INTERFACE = /*#__PURE__*/new abi.Interface(IPeripheryPaymentsWithFeeExtended_json.abi);
234
202
 
203
+ function _regeneratorRuntime() {
204
+ _regeneratorRuntime = function () {
205
+ return e;
206
+ };
207
+ var t,
208
+ e = {},
209
+ r = Object.prototype,
210
+ n = r.hasOwnProperty,
211
+ o = Object.defineProperty || function (t, e, r) {
212
+ t[e] = r.value;
213
+ },
214
+ i = "function" == typeof Symbol ? Symbol : {},
215
+ a = i.iterator || "@@iterator",
216
+ c = i.asyncIterator || "@@asyncIterator",
217
+ u = i.toStringTag || "@@toStringTag";
218
+ function define(t, e, r) {
219
+ return Object.defineProperty(t, e, {
220
+ value: r,
221
+ enumerable: !0,
222
+ configurable: !0,
223
+ writable: !0
224
+ }), t[e];
225
+ }
226
+ try {
227
+ define({}, "");
228
+ } catch (t) {
229
+ define = function (t, e, r) {
230
+ return t[e] = r;
231
+ };
232
+ }
233
+ function wrap(t, e, r, n) {
234
+ var i = e && e.prototype instanceof Generator ? e : Generator,
235
+ a = Object.create(i.prototype),
236
+ c = new Context(n || []);
237
+ return o(a, "_invoke", {
238
+ value: makeInvokeMethod(t, r, c)
239
+ }), a;
240
+ }
241
+ function tryCatch(t, e, r) {
242
+ try {
243
+ return {
244
+ type: "normal",
245
+ arg: t.call(e, r)
246
+ };
247
+ } catch (t) {
248
+ return {
249
+ type: "throw",
250
+ arg: t
251
+ };
252
+ }
253
+ }
254
+ e.wrap = wrap;
255
+ var h = "suspendedStart",
256
+ l = "suspendedYield",
257
+ f = "executing",
258
+ s = "completed",
259
+ y = {};
260
+ function Generator() {}
261
+ function GeneratorFunction() {}
262
+ function GeneratorFunctionPrototype() {}
263
+ var p = {};
264
+ define(p, a, function () {
265
+ return this;
266
+ });
267
+ var d = Object.getPrototypeOf,
268
+ v = d && d(d(values([])));
269
+ v && v !== r && n.call(v, a) && (p = v);
270
+ var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p);
271
+ function defineIteratorMethods(t) {
272
+ ["next", "throw", "return"].forEach(function (e) {
273
+ define(t, e, function (t) {
274
+ return this._invoke(e, t);
275
+ });
276
+ });
277
+ }
278
+ function AsyncIterator(t, e) {
279
+ function invoke(r, o, i, a) {
280
+ var c = tryCatch(t[r], t, o);
281
+ if ("throw" !== c.type) {
282
+ var u = c.arg,
283
+ h = u.value;
284
+ return h && "object" == typeof h && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) {
285
+ invoke("next", t, i, a);
286
+ }, function (t) {
287
+ invoke("throw", t, i, a);
288
+ }) : e.resolve(h).then(function (t) {
289
+ u.value = t, i(u);
290
+ }, function (t) {
291
+ return invoke("throw", t, i, a);
292
+ });
293
+ }
294
+ a(c.arg);
295
+ }
296
+ var r;
297
+ o(this, "_invoke", {
298
+ value: function (t, n) {
299
+ function callInvokeWithMethodAndArg() {
300
+ return new e(function (e, r) {
301
+ invoke(t, n, e, r);
302
+ });
303
+ }
304
+ return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg();
305
+ }
306
+ });
307
+ }
308
+ function makeInvokeMethod(e, r, n) {
309
+ var o = h;
310
+ return function (i, a) {
311
+ if (o === f) throw new Error("Generator is already running");
312
+ if (o === s) {
313
+ if ("throw" === i) throw a;
314
+ return {
315
+ value: t,
316
+ done: !0
317
+ };
318
+ }
319
+ for (n.method = i, n.arg = a;;) {
320
+ var c = n.delegate;
321
+ if (c) {
322
+ var u = maybeInvokeDelegate(c, n);
323
+ if (u) {
324
+ if (u === y) continue;
325
+ return u;
326
+ }
327
+ }
328
+ if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) {
329
+ if (o === h) throw o = s, n.arg;
330
+ n.dispatchException(n.arg);
331
+ } else "return" === n.method && n.abrupt("return", n.arg);
332
+ o = f;
333
+ var p = tryCatch(e, r, n);
334
+ if ("normal" === p.type) {
335
+ if (o = n.done ? s : l, p.arg === y) continue;
336
+ return {
337
+ value: p.arg,
338
+ done: n.done
339
+ };
340
+ }
341
+ "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg);
342
+ }
343
+ };
344
+ }
345
+ function maybeInvokeDelegate(e, r) {
346
+ var n = r.method,
347
+ o = e.iterator[n];
348
+ if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y;
349
+ var i = tryCatch(o, e.iterator, r.arg);
350
+ if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y;
351
+ var a = i.arg;
352
+ return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y);
353
+ }
354
+ function pushTryEntry(t) {
355
+ var e = {
356
+ tryLoc: t[0]
357
+ };
358
+ 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e);
359
+ }
360
+ function resetTryEntry(t) {
361
+ var e = t.completion || {};
362
+ e.type = "normal", delete e.arg, t.completion = e;
363
+ }
364
+ function Context(t) {
365
+ this.tryEntries = [{
366
+ tryLoc: "root"
367
+ }], t.forEach(pushTryEntry, this), this.reset(!0);
368
+ }
369
+ function values(e) {
370
+ if (e || "" === e) {
371
+ var r = e[a];
372
+ if (r) return r.call(e);
373
+ if ("function" == typeof e.next) return e;
374
+ if (!isNaN(e.length)) {
375
+ var o = -1,
376
+ i = function next() {
377
+ for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next;
378
+ return next.value = t, next.done = !0, next;
379
+ };
380
+ return i.next = i;
381
+ }
382
+ }
383
+ throw new TypeError(typeof e + " is not iterable");
384
+ }
385
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", {
386
+ value: GeneratorFunctionPrototype,
387
+ configurable: !0
388
+ }), o(GeneratorFunctionPrototype, "constructor", {
389
+ value: GeneratorFunction,
390
+ configurable: !0
391
+ }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) {
392
+ var e = "function" == typeof t && t.constructor;
393
+ return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name));
394
+ }, e.mark = function (t) {
395
+ return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t;
396
+ }, e.awrap = function (t) {
397
+ return {
398
+ __await: t
399
+ };
400
+ }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () {
401
+ return this;
402
+ }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) {
403
+ void 0 === i && (i = Promise);
404
+ var a = new AsyncIterator(wrap(t, r, n, o), i);
405
+ return e.isGeneratorFunction(r) ? a : a.next().then(function (t) {
406
+ return t.done ? t.value : a.next();
407
+ });
408
+ }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () {
409
+ return this;
410
+ }), define(g, "toString", function () {
411
+ return "[object Generator]";
412
+ }), e.keys = function (t) {
413
+ var e = Object(t),
414
+ r = [];
415
+ for (var n in e) r.push(n);
416
+ return r.reverse(), function next() {
417
+ for (; r.length;) {
418
+ var t = r.pop();
419
+ if (t in e) return next.value = t, next.done = !1, next;
420
+ }
421
+ return next.done = !0, next;
422
+ };
423
+ }, e.values = values, Context.prototype = {
424
+ constructor: Context,
425
+ reset: function (e) {
426
+ if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t);
427
+ },
428
+ stop: function () {
429
+ this.done = !0;
430
+ var t = this.tryEntries[0].completion;
431
+ if ("throw" === t.type) throw t.arg;
432
+ return this.rval;
433
+ },
434
+ dispatchException: function (e) {
435
+ if (this.done) throw e;
436
+ var r = this;
437
+ function handle(n, o) {
438
+ return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o;
439
+ }
440
+ for (var o = this.tryEntries.length - 1; o >= 0; --o) {
441
+ var i = this.tryEntries[o],
442
+ a = i.completion;
443
+ if ("root" === i.tryLoc) return handle("end");
444
+ if (i.tryLoc <= this.prev) {
445
+ var c = n.call(i, "catchLoc"),
446
+ u = n.call(i, "finallyLoc");
447
+ if (c && u) {
448
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
449
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
450
+ } else if (c) {
451
+ if (this.prev < i.catchLoc) return handle(i.catchLoc, !0);
452
+ } else {
453
+ if (!u) throw new Error("try statement without catch or finally");
454
+ if (this.prev < i.finallyLoc) return handle(i.finallyLoc);
455
+ }
456
+ }
457
+ }
458
+ },
459
+ abrupt: function (t, e) {
460
+ for (var r = this.tryEntries.length - 1; r >= 0; --r) {
461
+ var o = this.tryEntries[r];
462
+ if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) {
463
+ var i = o;
464
+ break;
465
+ }
466
+ }
467
+ i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null);
468
+ var a = i ? i.completion : {};
469
+ return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a);
470
+ },
471
+ complete: function (t, e) {
472
+ if ("throw" === t.type) throw t.arg;
473
+ return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y;
474
+ },
475
+ finish: function (t) {
476
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
477
+ var r = this.tryEntries[e];
478
+ if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y;
479
+ }
480
+ },
481
+ catch: function (t) {
482
+ for (var e = this.tryEntries.length - 1; e >= 0; --e) {
483
+ var r = this.tryEntries[e];
484
+ if (r.tryLoc === t) {
485
+ var n = r.completion;
486
+ if ("throw" === n.type) {
487
+ var o = n.arg;
488
+ resetTryEntry(r);
489
+ }
490
+ return o;
491
+ }
492
+ }
493
+ throw new Error("illegal catch attempt");
494
+ },
495
+ delegateYield: function (e, r, n) {
496
+ return this.delegate = {
497
+ iterator: values(e),
498
+ resultName: r,
499
+ nextLoc: n
500
+ }, "next" === this.method && (this.arg = t), y;
501
+ }
502
+ }, e;
503
+ }
504
+ function _toPrimitive(t, r) {
505
+ if ("object" != typeof t || !t) return t;
506
+ var e = t[Symbol.toPrimitive];
507
+ if (void 0 !== e) {
508
+ var i = e.call(t, r || "default");
509
+ if ("object" != typeof i) return i;
510
+ throw new TypeError("@@toPrimitive must return a primitive value.");
511
+ }
512
+ return ("string" === r ? String : Number)(t);
513
+ }
514
+ function _toPropertyKey(t) {
515
+ var i = _toPrimitive(t, "string");
516
+ return "symbol" == typeof i ? i : String(i);
517
+ }
235
518
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
236
519
  try {
237
520
  var info = gen[key](arg);
@@ -240,84 +523,71 @@ function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
240
523
  reject(error);
241
524
  return;
242
525
  }
243
-
244
526
  if (info.done) {
245
527
  resolve(value);
246
528
  } else {
247
529
  Promise.resolve(value).then(_next, _throw);
248
530
  }
249
531
  }
250
-
251
532
  function _asyncToGenerator(fn) {
252
533
  return function () {
253
534
  var self = this,
254
- args = arguments;
535
+ args = arguments;
255
536
  return new Promise(function (resolve, reject) {
256
537
  var gen = fn.apply(self, args);
257
-
258
538
  function _next(value) {
259
539
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value);
260
540
  }
261
-
262
541
  function _throw(err) {
263
542
  asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err);
264
543
  }
265
-
266
544
  _next(undefined);
267
545
  });
268
546
  };
269
547
  }
270
-
271
548
  function _defineProperties(target, props) {
272
549
  for (var i = 0; i < props.length; i++) {
273
550
  var descriptor = props[i];
274
551
  descriptor.enumerable = descriptor.enumerable || false;
275
552
  descriptor.configurable = true;
276
553
  if ("value" in descriptor) descriptor.writable = true;
277
- Object.defineProperty(target, descriptor.key, descriptor);
554
+ Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
278
555
  }
279
556
  }
280
-
281
557
  function _createClass(Constructor, protoProps, staticProps) {
282
558
  if (protoProps) _defineProperties(Constructor.prototype, protoProps);
283
559
  if (staticProps) _defineProperties(Constructor, staticProps);
560
+ Object.defineProperty(Constructor, "prototype", {
561
+ writable: false
562
+ });
284
563
  return Constructor;
285
564
  }
286
-
287
565
  function _extends() {
288
- _extends = Object.assign || function (target) {
566
+ _extends = Object.assign ? Object.assign.bind() : function (target) {
289
567
  for (var i = 1; i < arguments.length; i++) {
290
568
  var source = arguments[i];
291
-
292
569
  for (var key in source) {
293
570
  if (Object.prototype.hasOwnProperty.call(source, key)) {
294
571
  target[key] = source[key];
295
572
  }
296
573
  }
297
574
  }
298
-
299
575
  return target;
300
576
  };
301
-
302
577
  return _extends.apply(this, arguments);
303
578
  }
304
-
305
579
  function _inheritsLoose(subClass, superClass) {
306
580
  subClass.prototype = Object.create(superClass.prototype);
307
581
  subClass.prototype.constructor = subClass;
308
-
309
582
  _setPrototypeOf(subClass, superClass);
310
583
  }
311
-
312
584
  function _setPrototypeOf(o, p) {
313
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
585
+ _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
314
586
  o.__proto__ = p;
315
587
  return o;
316
588
  };
317
-
318
589
  return _setPrototypeOf(o, p);
319
590
  }
320
-
321
591
  function _unsupportedIterableToArray(o, minLen) {
322
592
  if (!o) return;
323
593
  if (typeof o === "string") return _arrayLikeToArray(o, minLen);
@@ -326,19 +596,14 @@ function _unsupportedIterableToArray(o, minLen) {
326
596
  if (n === "Map" || n === "Set") return Array.from(o);
327
597
  if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
328
598
  }
329
-
330
599
  function _arrayLikeToArray(arr, len) {
331
600
  if (len == null || len > arr.length) len = arr.length;
332
-
333
601
  for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
334
-
335
602
  return arr2;
336
603
  }
337
-
338
604
  function _createForOfIteratorHelperLoose(o, allowArrayLike) {
339
605
  var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"];
340
606
  if (it) return (it = it.call(o)).next.bind(it);
341
-
342
607
  if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") {
343
608
  if (it) o = it;
344
609
  var i = 0;
@@ -352,776 +617,14 @@ function _createForOfIteratorHelperLoose(o, allowArrayLike) {
352
617
  };
353
618
  };
354
619
  }
355
-
356
620
  throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
357
621
  }
358
622
 
359
- function createCommonjsModule(fn, module) {
360
- return module = { exports: {} }, fn(module, module.exports), module.exports;
361
- }
362
-
363
- var runtime_1 = createCommonjsModule(function (module) {
364
- /**
365
- * Copyright (c) 2014-present, Facebook, Inc.
366
- *
367
- * This source code is licensed under the MIT license found in the
368
- * LICENSE file in the root directory of this source tree.
369
- */
370
-
371
- var runtime = (function (exports) {
372
-
373
- var Op = Object.prototype;
374
- var hasOwn = Op.hasOwnProperty;
375
- var undefined$1; // More compressible than void 0.
376
- var $Symbol = typeof Symbol === "function" ? Symbol : {};
377
- var iteratorSymbol = $Symbol.iterator || "@@iterator";
378
- var asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator";
379
- var toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag";
380
-
381
- function define(obj, key, value) {
382
- Object.defineProperty(obj, key, {
383
- value: value,
384
- enumerable: true,
385
- configurable: true,
386
- writable: true
387
- });
388
- return obj[key];
389
- }
390
- try {
391
- // IE 8 has a broken Object.defineProperty that only works on DOM objects.
392
- define({}, "");
393
- } catch (err) {
394
- define = function(obj, key, value) {
395
- return obj[key] = value;
396
- };
397
- }
398
-
399
- function wrap(innerFn, outerFn, self, tryLocsList) {
400
- // If outerFn provided and outerFn.prototype is a Generator, then outerFn.prototype instanceof Generator.
401
- var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator;
402
- var generator = Object.create(protoGenerator.prototype);
403
- var context = new Context(tryLocsList || []);
404
-
405
- // The ._invoke method unifies the implementations of the .next,
406
- // .throw, and .return methods.
407
- generator._invoke = makeInvokeMethod(innerFn, self, context);
408
-
409
- return generator;
410
- }
411
- exports.wrap = wrap;
412
-
413
- // Try/catch helper to minimize deoptimizations. Returns a completion
414
- // record like context.tryEntries[i].completion. This interface could
415
- // have been (and was previously) designed to take a closure to be
416
- // invoked without arguments, but in all the cases we care about we
417
- // already have an existing method we want to call, so there's no need
418
- // to create a new function object. We can even get away with assuming
419
- // the method takes exactly one argument, since that happens to be true
420
- // in every case, so we don't have to touch the arguments object. The
421
- // only additional allocation required is the completion record, which
422
- // has a stable shape and so hopefully should be cheap to allocate.
423
- function tryCatch(fn, obj, arg) {
424
- try {
425
- return { type: "normal", arg: fn.call(obj, arg) };
426
- } catch (err) {
427
- return { type: "throw", arg: err };
428
- }
429
- }
430
-
431
- var GenStateSuspendedStart = "suspendedStart";
432
- var GenStateSuspendedYield = "suspendedYield";
433
- var GenStateExecuting = "executing";
434
- var GenStateCompleted = "completed";
435
-
436
- // Returning this object from the innerFn has the same effect as
437
- // breaking out of the dispatch switch statement.
438
- var ContinueSentinel = {};
439
-
440
- // Dummy constructor functions that we use as the .constructor and
441
- // .constructor.prototype properties for functions that return Generator
442
- // objects. For full spec compliance, you may wish to configure your
443
- // minifier not to mangle the names of these two functions.
444
- function Generator() {}
445
- function GeneratorFunction() {}
446
- function GeneratorFunctionPrototype() {}
447
-
448
- // This is a polyfill for %IteratorPrototype% for environments that
449
- // don't natively support it.
450
- var IteratorPrototype = {};
451
- define(IteratorPrototype, iteratorSymbol, function () {
452
- return this;
453
- });
454
-
455
- var getProto = Object.getPrototypeOf;
456
- var NativeIteratorPrototype = getProto && getProto(getProto(values([])));
457
- if (NativeIteratorPrototype &&
458
- NativeIteratorPrototype !== Op &&
459
- hasOwn.call(NativeIteratorPrototype, iteratorSymbol)) {
460
- // This environment has a native %IteratorPrototype%; use it instead
461
- // of the polyfill.
462
- IteratorPrototype = NativeIteratorPrototype;
463
- }
464
-
465
- var Gp = GeneratorFunctionPrototype.prototype =
466
- Generator.prototype = Object.create(IteratorPrototype);
467
- GeneratorFunction.prototype = GeneratorFunctionPrototype;
468
- define(Gp, "constructor", GeneratorFunctionPrototype);
469
- define(GeneratorFunctionPrototype, "constructor", GeneratorFunction);
470
- GeneratorFunction.displayName = define(
471
- GeneratorFunctionPrototype,
472
- toStringTagSymbol,
473
- "GeneratorFunction"
474
- );
475
-
476
- // Helper for defining the .next, .throw, and .return methods of the
477
- // Iterator interface in terms of a single ._invoke method.
478
- function defineIteratorMethods(prototype) {
479
- ["next", "throw", "return"].forEach(function(method) {
480
- define(prototype, method, function(arg) {
481
- return this._invoke(method, arg);
482
- });
483
- });
484
- }
485
-
486
- exports.isGeneratorFunction = function(genFun) {
487
- var ctor = typeof genFun === "function" && genFun.constructor;
488
- return ctor
489
- ? ctor === GeneratorFunction ||
490
- // For the native GeneratorFunction constructor, the best we can
491
- // do is to check its .name property.
492
- (ctor.displayName || ctor.name) === "GeneratorFunction"
493
- : false;
494
- };
495
-
496
- exports.mark = function(genFun) {
497
- if (Object.setPrototypeOf) {
498
- Object.setPrototypeOf(genFun, GeneratorFunctionPrototype);
499
- } else {
500
- genFun.__proto__ = GeneratorFunctionPrototype;
501
- define(genFun, toStringTagSymbol, "GeneratorFunction");
502
- }
503
- genFun.prototype = Object.create(Gp);
504
- return genFun;
505
- };
506
-
507
- // Within the body of any async function, `await x` is transformed to
508
- // `yield regeneratorRuntime.awrap(x)`, so that the runtime can test
509
- // `hasOwn.call(value, "__await")` to determine if the yielded value is
510
- // meant to be awaited.
511
- exports.awrap = function(arg) {
512
- return { __await: arg };
513
- };
514
-
515
- function AsyncIterator(generator, PromiseImpl) {
516
- function invoke(method, arg, resolve, reject) {
517
- var record = tryCatch(generator[method], generator, arg);
518
- if (record.type === "throw") {
519
- reject(record.arg);
520
- } else {
521
- var result = record.arg;
522
- var value = result.value;
523
- if (value &&
524
- typeof value === "object" &&
525
- hasOwn.call(value, "__await")) {
526
- return PromiseImpl.resolve(value.__await).then(function(value) {
527
- invoke("next", value, resolve, reject);
528
- }, function(err) {
529
- invoke("throw", err, resolve, reject);
530
- });
531
- }
532
-
533
- return PromiseImpl.resolve(value).then(function(unwrapped) {
534
- // When a yielded Promise is resolved, its final value becomes
535
- // the .value of the Promise<{value,done}> result for the
536
- // current iteration.
537
- result.value = unwrapped;
538
- resolve(result);
539
- }, function(error) {
540
- // If a rejected Promise was yielded, throw the rejection back
541
- // into the async generator function so it can be handled there.
542
- return invoke("throw", error, resolve, reject);
543
- });
544
- }
545
- }
546
-
547
- var previousPromise;
548
-
549
- function enqueue(method, arg) {
550
- function callInvokeWithMethodAndArg() {
551
- return new PromiseImpl(function(resolve, reject) {
552
- invoke(method, arg, resolve, reject);
553
- });
554
- }
555
-
556
- return previousPromise =
557
- // If enqueue has been called before, then we want to wait until
558
- // all previous Promises have been resolved before calling invoke,
559
- // so that results are always delivered in the correct order. If
560
- // enqueue has not been called before, then it is important to
561
- // call invoke immediately, without waiting on a callback to fire,
562
- // so that the async generator function has the opportunity to do
563
- // any necessary setup in a predictable way. This predictability
564
- // is why the Promise constructor synchronously invokes its
565
- // executor callback, and why async functions synchronously
566
- // execute code before the first await. Since we implement simple
567
- // async functions in terms of async generators, it is especially
568
- // important to get this right, even though it requires care.
569
- previousPromise ? previousPromise.then(
570
- callInvokeWithMethodAndArg,
571
- // Avoid propagating failures to Promises returned by later
572
- // invocations of the iterator.
573
- callInvokeWithMethodAndArg
574
- ) : callInvokeWithMethodAndArg();
575
- }
576
-
577
- // Define the unified helper method that is used to implement .next,
578
- // .throw, and .return (see defineIteratorMethods).
579
- this._invoke = enqueue;
580
- }
581
-
582
- defineIteratorMethods(AsyncIterator.prototype);
583
- define(AsyncIterator.prototype, asyncIteratorSymbol, function () {
584
- return this;
585
- });
586
- exports.AsyncIterator = AsyncIterator;
587
-
588
- // Note that simple async functions are implemented on top of
589
- // AsyncIterator objects; they just return a Promise for the value of
590
- // the final result produced by the iterator.
591
- exports.async = function(innerFn, outerFn, self, tryLocsList, PromiseImpl) {
592
- if (PromiseImpl === void 0) PromiseImpl = Promise;
593
-
594
- var iter = new AsyncIterator(
595
- wrap(innerFn, outerFn, self, tryLocsList),
596
- PromiseImpl
597
- );
598
-
599
- return exports.isGeneratorFunction(outerFn)
600
- ? iter // If outerFn is a generator, return the full iterator.
601
- : iter.next().then(function(result) {
602
- return result.done ? result.value : iter.next();
603
- });
604
- };
605
-
606
- function makeInvokeMethod(innerFn, self, context) {
607
- var state = GenStateSuspendedStart;
608
-
609
- return function invoke(method, arg) {
610
- if (state === GenStateExecuting) {
611
- throw new Error("Generator is already running");
612
- }
613
-
614
- if (state === GenStateCompleted) {
615
- if (method === "throw") {
616
- throw arg;
617
- }
618
-
619
- // Be forgiving, per 25.3.3.3.3 of the spec:
620
- // https://people.mozilla.org/~jorendorff/es6-draft.html#sec-generatorresume
621
- return doneResult();
622
- }
623
-
624
- context.method = method;
625
- context.arg = arg;
626
-
627
- while (true) {
628
- var delegate = context.delegate;
629
- if (delegate) {
630
- var delegateResult = maybeInvokeDelegate(delegate, context);
631
- if (delegateResult) {
632
- if (delegateResult === ContinueSentinel) continue;
633
- return delegateResult;
634
- }
635
- }
636
-
637
- if (context.method === "next") {
638
- // Setting context._sent for legacy support of Babel's
639
- // function.sent implementation.
640
- context.sent = context._sent = context.arg;
641
-
642
- } else if (context.method === "throw") {
643
- if (state === GenStateSuspendedStart) {
644
- state = GenStateCompleted;
645
- throw context.arg;
646
- }
647
-
648
- context.dispatchException(context.arg);
649
-
650
- } else if (context.method === "return") {
651
- context.abrupt("return", context.arg);
652
- }
653
-
654
- state = GenStateExecuting;
655
-
656
- var record = tryCatch(innerFn, self, context);
657
- if (record.type === "normal") {
658
- // If an exception is thrown from innerFn, we leave state ===
659
- // GenStateExecuting and loop back for another invocation.
660
- state = context.done
661
- ? GenStateCompleted
662
- : GenStateSuspendedYield;
663
-
664
- if (record.arg === ContinueSentinel) {
665
- continue;
666
- }
667
-
668
- return {
669
- value: record.arg,
670
- done: context.done
671
- };
672
-
673
- } else if (record.type === "throw") {
674
- state = GenStateCompleted;
675
- // Dispatch the exception by looping back around to the
676
- // context.dispatchException(context.arg) call above.
677
- context.method = "throw";
678
- context.arg = record.arg;
679
- }
680
- }
681
- };
682
- }
683
-
684
- // Call delegate.iterator[context.method](context.arg) and handle the
685
- // result, either by returning a { value, done } result from the
686
- // delegate iterator, or by modifying context.method and context.arg,
687
- // setting context.delegate to null, and returning the ContinueSentinel.
688
- function maybeInvokeDelegate(delegate, context) {
689
- var method = delegate.iterator[context.method];
690
- if (method === undefined$1) {
691
- // A .throw or .return when the delegate iterator has no .throw
692
- // method always terminates the yield* loop.
693
- context.delegate = null;
694
-
695
- if (context.method === "throw") {
696
- // Note: ["return"] must be used for ES3 parsing compatibility.
697
- if (delegate.iterator["return"]) {
698
- // If the delegate iterator has a return method, give it a
699
- // chance to clean up.
700
- context.method = "return";
701
- context.arg = undefined$1;
702
- maybeInvokeDelegate(delegate, context);
703
-
704
- if (context.method === "throw") {
705
- // If maybeInvokeDelegate(context) changed context.method from
706
- // "return" to "throw", let that override the TypeError below.
707
- return ContinueSentinel;
708
- }
709
- }
710
-
711
- context.method = "throw";
712
- context.arg = new TypeError(
713
- "The iterator does not provide a 'throw' method");
714
- }
715
-
716
- return ContinueSentinel;
717
- }
718
-
719
- var record = tryCatch(method, delegate.iterator, context.arg);
720
-
721
- if (record.type === "throw") {
722
- context.method = "throw";
723
- context.arg = record.arg;
724
- context.delegate = null;
725
- return ContinueSentinel;
726
- }
727
-
728
- var info = record.arg;
729
-
730
- if (! info) {
731
- context.method = "throw";
732
- context.arg = new TypeError("iterator result is not an object");
733
- context.delegate = null;
734
- return ContinueSentinel;
735
- }
736
-
737
- if (info.done) {
738
- // Assign the result of the finished delegate to the temporary
739
- // variable specified by delegate.resultName (see delegateYield).
740
- context[delegate.resultName] = info.value;
741
-
742
- // Resume execution at the desired location (see delegateYield).
743
- context.next = delegate.nextLoc;
744
-
745
- // If context.method was "throw" but the delegate handled the
746
- // exception, let the outer generator proceed normally. If
747
- // context.method was "next", forget context.arg since it has been
748
- // "consumed" by the delegate iterator. If context.method was
749
- // "return", allow the original .return call to continue in the
750
- // outer generator.
751
- if (context.method !== "return") {
752
- context.method = "next";
753
- context.arg = undefined$1;
754
- }
755
-
756
- } else {
757
- // Re-yield the result returned by the delegate method.
758
- return info;
759
- }
760
-
761
- // The delegate iterator is finished, so forget it and continue with
762
- // the outer generator.
763
- context.delegate = null;
764
- return ContinueSentinel;
765
- }
766
-
767
- // Define Generator.prototype.{next,throw,return} in terms of the
768
- // unified ._invoke helper method.
769
- defineIteratorMethods(Gp);
770
-
771
- define(Gp, toStringTagSymbol, "Generator");
772
-
773
- // A Generator should always return itself as the iterator object when the
774
- // @@iterator function is called on it. Some browsers' implementations of the
775
- // iterator prototype chain incorrectly implement this, causing the Generator
776
- // object to not be returned from this call. This ensures that doesn't happen.
777
- // See https://github.com/facebook/regenerator/issues/274 for more details.
778
- define(Gp, iteratorSymbol, function() {
779
- return this;
780
- });
781
-
782
- define(Gp, "toString", function() {
783
- return "[object Generator]";
784
- });
785
-
786
- function pushTryEntry(locs) {
787
- var entry = { tryLoc: locs[0] };
788
-
789
- if (1 in locs) {
790
- entry.catchLoc = locs[1];
791
- }
792
-
793
- if (2 in locs) {
794
- entry.finallyLoc = locs[2];
795
- entry.afterLoc = locs[3];
796
- }
797
-
798
- this.tryEntries.push(entry);
799
- }
800
-
801
- function resetTryEntry(entry) {
802
- var record = entry.completion || {};
803
- record.type = "normal";
804
- delete record.arg;
805
- entry.completion = record;
806
- }
807
-
808
- function Context(tryLocsList) {
809
- // The root entry object (effectively a try statement without a catch
810
- // or a finally block) gives us a place to store values thrown from
811
- // locations where there is no enclosing try statement.
812
- this.tryEntries = [{ tryLoc: "root" }];
813
- tryLocsList.forEach(pushTryEntry, this);
814
- this.reset(true);
815
- }
816
-
817
- exports.keys = function(object) {
818
- var keys = [];
819
- for (var key in object) {
820
- keys.push(key);
821
- }
822
- keys.reverse();
823
-
824
- // Rather than returning an object with a next method, we keep
825
- // things simple and return the next function itself.
826
- return function next() {
827
- while (keys.length) {
828
- var key = keys.pop();
829
- if (key in object) {
830
- next.value = key;
831
- next.done = false;
832
- return next;
833
- }
834
- }
835
-
836
- // To avoid creating an additional object, we just hang the .value
837
- // and .done properties off the next function object itself. This
838
- // also ensures that the minifier will not anonymize the function.
839
- next.done = true;
840
- return next;
841
- };
842
- };
843
-
844
- function values(iterable) {
845
- if (iterable) {
846
- var iteratorMethod = iterable[iteratorSymbol];
847
- if (iteratorMethod) {
848
- return iteratorMethod.call(iterable);
849
- }
850
-
851
- if (typeof iterable.next === "function") {
852
- return iterable;
853
- }
854
-
855
- if (!isNaN(iterable.length)) {
856
- var i = -1, next = function next() {
857
- while (++i < iterable.length) {
858
- if (hasOwn.call(iterable, i)) {
859
- next.value = iterable[i];
860
- next.done = false;
861
- return next;
862
- }
863
- }
864
-
865
- next.value = undefined$1;
866
- next.done = true;
867
-
868
- return next;
869
- };
870
-
871
- return next.next = next;
872
- }
873
- }
874
-
875
- // Return an iterator with no values.
876
- return { next: doneResult };
877
- }
878
- exports.values = values;
879
-
880
- function doneResult() {
881
- return { value: undefined$1, done: true };
882
- }
883
-
884
- Context.prototype = {
885
- constructor: Context,
886
-
887
- reset: function(skipTempReset) {
888
- this.prev = 0;
889
- this.next = 0;
890
- // Resetting context._sent for legacy support of Babel's
891
- // function.sent implementation.
892
- this.sent = this._sent = undefined$1;
893
- this.done = false;
894
- this.delegate = null;
895
-
896
- this.method = "next";
897
- this.arg = undefined$1;
898
-
899
- this.tryEntries.forEach(resetTryEntry);
900
-
901
- if (!skipTempReset) {
902
- for (var name in this) {
903
- // Not sure about the optimal order of these conditions:
904
- if (name.charAt(0) === "t" &&
905
- hasOwn.call(this, name) &&
906
- !isNaN(+name.slice(1))) {
907
- this[name] = undefined$1;
908
- }
909
- }
910
- }
911
- },
912
-
913
- stop: function() {
914
- this.done = true;
915
-
916
- var rootEntry = this.tryEntries[0];
917
- var rootRecord = rootEntry.completion;
918
- if (rootRecord.type === "throw") {
919
- throw rootRecord.arg;
920
- }
921
-
922
- return this.rval;
923
- },
924
-
925
- dispatchException: function(exception) {
926
- if (this.done) {
927
- throw exception;
928
- }
929
-
930
- var context = this;
931
- function handle(loc, caught) {
932
- record.type = "throw";
933
- record.arg = exception;
934
- context.next = loc;
935
-
936
- if (caught) {
937
- // If the dispatched exception was caught by a catch block,
938
- // then let that catch block handle the exception normally.
939
- context.method = "next";
940
- context.arg = undefined$1;
941
- }
942
-
943
- return !! caught;
944
- }
945
-
946
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
947
- var entry = this.tryEntries[i];
948
- var record = entry.completion;
949
-
950
- if (entry.tryLoc === "root") {
951
- // Exception thrown outside of any try block that could handle
952
- // it, so set the completion value of the entire function to
953
- // throw the exception.
954
- return handle("end");
955
- }
956
-
957
- if (entry.tryLoc <= this.prev) {
958
- var hasCatch = hasOwn.call(entry, "catchLoc");
959
- var hasFinally = hasOwn.call(entry, "finallyLoc");
960
-
961
- if (hasCatch && hasFinally) {
962
- if (this.prev < entry.catchLoc) {
963
- return handle(entry.catchLoc, true);
964
- } else if (this.prev < entry.finallyLoc) {
965
- return handle(entry.finallyLoc);
966
- }
967
-
968
- } else if (hasCatch) {
969
- if (this.prev < entry.catchLoc) {
970
- return handle(entry.catchLoc, true);
971
- }
972
-
973
- } else if (hasFinally) {
974
- if (this.prev < entry.finallyLoc) {
975
- return handle(entry.finallyLoc);
976
- }
977
-
978
- } else {
979
- throw new Error("try statement without catch or finally");
980
- }
981
- }
982
- }
983
- },
984
-
985
- abrupt: function(type, arg) {
986
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
987
- var entry = this.tryEntries[i];
988
- if (entry.tryLoc <= this.prev &&
989
- hasOwn.call(entry, "finallyLoc") &&
990
- this.prev < entry.finallyLoc) {
991
- var finallyEntry = entry;
992
- break;
993
- }
994
- }
995
-
996
- if (finallyEntry &&
997
- (type === "break" ||
998
- type === "continue") &&
999
- finallyEntry.tryLoc <= arg &&
1000
- arg <= finallyEntry.finallyLoc) {
1001
- // Ignore the finally entry if control is not jumping to a
1002
- // location outside the try/catch block.
1003
- finallyEntry = null;
1004
- }
1005
-
1006
- var record = finallyEntry ? finallyEntry.completion : {};
1007
- record.type = type;
1008
- record.arg = arg;
1009
-
1010
- if (finallyEntry) {
1011
- this.method = "next";
1012
- this.next = finallyEntry.finallyLoc;
1013
- return ContinueSentinel;
1014
- }
1015
-
1016
- return this.complete(record);
1017
- },
1018
-
1019
- complete: function(record, afterLoc) {
1020
- if (record.type === "throw") {
1021
- throw record.arg;
1022
- }
1023
-
1024
- if (record.type === "break" ||
1025
- record.type === "continue") {
1026
- this.next = record.arg;
1027
- } else if (record.type === "return") {
1028
- this.rval = this.arg = record.arg;
1029
- this.method = "return";
1030
- this.next = "end";
1031
- } else if (record.type === "normal" && afterLoc) {
1032
- this.next = afterLoc;
1033
- }
1034
-
1035
- return ContinueSentinel;
1036
- },
1037
-
1038
- finish: function(finallyLoc) {
1039
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1040
- var entry = this.tryEntries[i];
1041
- if (entry.finallyLoc === finallyLoc) {
1042
- this.complete(entry.completion, entry.afterLoc);
1043
- resetTryEntry(entry);
1044
- return ContinueSentinel;
1045
- }
1046
- }
1047
- },
1048
-
1049
- "catch": function(tryLoc) {
1050
- for (var i = this.tryEntries.length - 1; i >= 0; --i) {
1051
- var entry = this.tryEntries[i];
1052
- if (entry.tryLoc === tryLoc) {
1053
- var record = entry.completion;
1054
- if (record.type === "throw") {
1055
- var thrown = record.arg;
1056
- resetTryEntry(entry);
1057
- }
1058
- return thrown;
1059
- }
1060
- }
1061
-
1062
- // The context.catch method must only be called with a location
1063
- // argument that corresponds to a known catch block.
1064
- throw new Error("illegal catch attempt");
1065
- },
1066
-
1067
- delegateYield: function(iterable, resultName, nextLoc) {
1068
- this.delegate = {
1069
- iterator: values(iterable),
1070
- resultName: resultName,
1071
- nextLoc: nextLoc
1072
- };
1073
-
1074
- if (this.method === "next") {
1075
- // Deliberately forget the last sent value so that we don't
1076
- // accidentally pass it on to the delegate.
1077
- this.arg = undefined$1;
1078
- }
1079
-
1080
- return ContinueSentinel;
1081
- }
1082
- };
1083
-
1084
- // Regardless of whether this script is executing as a CommonJS module
1085
- // or not, return the runtime object so that we can declare the variable
1086
- // regeneratorRuntime in the outer scope, which allows this module to be
1087
- // injected easily by `bin/regenerator --include-runtime script.js`.
1088
- return exports;
1089
-
1090
- }(
1091
- // If this script is executing as a CommonJS module, use module.exports
1092
- // as the regeneratorRuntime namespace. Otherwise create a new empty
1093
- // object. Either way, the resulting object will be used to initialize
1094
- // the regeneratorRuntime variable at the top of this file.
1095
- module.exports
1096
- ));
1097
-
1098
- try {
1099
- regeneratorRuntime = runtime;
1100
- } catch (accidentalStrictMode) {
1101
- // This module should not be running in strict mode, so the above
1102
- // assignment should always work unless something is misconfigured. Just
1103
- // in case runtime.js accidentally runs in strict mode, in modern engines
1104
- // we can explicitly access globalThis. In older engines we can escape
1105
- // strict mode using a global Function call. This could conceivably fail
1106
- // if a Content Security Policy forbids using Function, but in that case
1107
- // the proper solution is to fix the accidental strict mode problem. If
1108
- // you've misconfigured your bundler to force strict mode and applied a
1109
- // CSP to forbid Function, and you're not willing to fix either of those
1110
- // problems, please detail your unique predicament in a GitHub issue.
1111
- if (typeof globalThis === "object") {
1112
- globalThis.regeneratorRuntime = runtime;
1113
- } else {
1114
- Function("r", "regeneratorRuntime = r")(runtime);
1115
- }
1116
- }
1117
- });
1118
-
1119
623
  /**
1120
624
  * Represents a list of pools or pairs through which a swap can occur
1121
625
  * @template TInput The input token
1122
626
  * @template TOutput The output token
1123
627
  */
1124
-
1125
628
  var MixedRouteSDK = /*#__PURE__*/function () {
1126
629
  /**
1127
630
  * Creates an instance of route.
@@ -1143,25 +646,21 @@ var MixedRouteSDK = /*#__PURE__*/function () {
1143
646
  /**
1144
647
  * Normalizes token0-token1 order and selects the next token/fee step to add to the path
1145
648
  * */
1146
-
1147
649
  var tokenPath = [wrappedInput];
1148
-
1149
650
  for (var _iterator = _createForOfIteratorHelperLoose(pools.entries()), _step; !(_step = _iterator()).done;) {
1150
651
  var _step$value = _step.value,
1151
- i = _step$value[0],
1152
- pool = _step$value[1];
652
+ i = _step$value[0],
653
+ pool = _step$value[1];
1153
654
  var currentInputToken = tokenPath[i];
1154
655
  !(currentInputToken.equals(pool.token0) || currentInputToken.equals(pool.token1)) ? invariant(false, 'PATH') : void 0;
1155
656
  var nextToken = currentInputToken.equals(pool.token0) ? pool.token1 : pool.token0;
1156
657
  tokenPath.push(nextToken);
1157
658
  }
1158
-
1159
659
  this.pools = pools;
1160
660
  this.path = tokenPath;
1161
661
  this.input = input;
1162
662
  this.output = output != null ? output : tokenPath[tokenPath.length - 1];
1163
663
  }
1164
-
1165
664
  _createClass(MixedRouteSDK, [{
1166
665
  key: "chainId",
1167
666
  get: function get() {
@@ -1170,14 +669,13 @@ var MixedRouteSDK = /*#__PURE__*/function () {
1170
669
  /**
1171
670
  * Returns the mid price of the route
1172
671
  */
1173
-
1174
672
  }, {
1175
673
  key: "midPrice",
1176
674
  get: function get() {
1177
675
  if (this._midPrice !== null) return this._midPrice;
1178
676
  var price = this.pools.slice(1).reduce(function (_ref, pool) {
1179
677
  var nextInput = _ref.nextInput,
1180
- price = _ref.price;
678
+ price = _ref.price;
1181
679
  return nextInput.equals(pool.token0) ? {
1182
680
  nextInput: pool.token1,
1183
681
  price: price.multiply(pool.token0Price)
@@ -1195,7 +693,6 @@ var MixedRouteSDK = /*#__PURE__*/function () {
1195
693
  return this._midPrice = new sdkCore.Price(this.input, this.output, price.denominator, price.numerator);
1196
694
  }
1197
695
  }]);
1198
-
1199
696
  return MixedRouteSDK;
1200
697
  }();
1201
698
 
@@ -1208,12 +705,10 @@ var MixedRouteSDK = /*#__PURE__*/function () {
1208
705
  * @param b The second trade to compare
1209
706
  * @returns A sorted ordering for two neighboring elements in a trade array
1210
707
  */
1211
-
1212
708
  function tradeComparator(a, b) {
1213
709
  // must have same input and output token for comparison
1214
710
  !a.inputAmount.currency.equals(b.inputAmount.currency) ? invariant(false, 'INPUT_CURRENCY') : void 0;
1215
711
  !a.outputAmount.currency.equals(b.outputAmount.currency) ? invariant(false, 'OUTPUT_CURRENCY') : void 0;
1216
-
1217
712
  if (a.outputAmount.equalTo(b.outputAmount)) {
1218
713
  if (a.inputAmount.equalTo(b.inputAmount)) {
1219
714
  // consider the number of hops since each hop costs gas
@@ -1224,9 +719,8 @@ function tradeComparator(a, b) {
1224
719
  return total + cur.route.path.length;
1225
720
  }, 0);
1226
721
  return aHops - bHops;
1227
- } // trade A requires less input than trade B, so A should come first
1228
-
1229
-
722
+ }
723
+ // trade A requires less input than trade B, so A should come first
1230
724
  if (a.inputAmount.lessThan(b.inputAmount)) {
1231
725
  return -1;
1232
726
  } else {
@@ -1254,7 +748,6 @@ function tradeComparator(a, b) {
1254
748
  * @template TOutput The output token, either Ether or an ERC-20
1255
749
  * @template TTradeType The trade type, either exact input or exact output
1256
750
  */
1257
-
1258
751
  var MixedRouteTrade = /*#__PURE__*/function () {
1259
752
  /**
1260
753
  * Construct a trade by passing in the pre-computed property values
@@ -1263,7 +756,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1263
756
  */
1264
757
  function MixedRouteTrade(_ref) {
1265
758
  var routes = _ref.routes,
1266
- tradeType = _ref.tradeType;
759
+ tradeType = _ref.tradeType;
1267
760
  var inputCurrency = routes[0].inputAmount.currency;
1268
761
  var outputCurrency = routes[0].outputAmount.currency;
1269
762
  !routes.every(function (_ref2) {
@@ -1281,17 +774,14 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1281
774
  return total + cur;
1282
775
  }, 0);
1283
776
  var poolAddressSet = new Set();
1284
-
1285
777
  for (var _iterator = _createForOfIteratorHelperLoose(routes), _step; !(_step = _iterator()).done;) {
1286
778
  var route = _step.value.route;
1287
-
1288
779
  for (var _iterator2 = _createForOfIteratorHelperLoose(route.pools), _step2; !(_step2 = _iterator2()).done;) {
1289
780
  var pool = _step2.value;
1290
781
  pool instanceof v3Sdk.Pool ? poolAddressSet.add(v3Sdk.Pool.getAddress(pool.token0, pool.token1, pool.fee)) : poolAddressSet.add(v2Sdk.Pair.getAddress(pool.token0, pool.token1));
1291
782
  }
1292
783
  }
1293
-
1294
- !(numPools == poolAddressSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
784
+ !(numPools === poolAddressSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
1295
785
  !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
1296
786
  this.swaps = routes;
1297
787
  this.tradeType = tradeType;
@@ -1303,8 +793,6 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1303
793
  * When the trade consists of just a single route, this returns the route of the trade,
1304
794
  * i.e. which pools the trade goes through.
1305
795
  */
1306
-
1307
-
1308
796
  /**
1309
797
  * Constructs a trade by simulating swaps through the given route
1310
798
  * @template TInput The input token, either Ether or an ERC-20.
@@ -1318,63 +806,52 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1318
806
  MixedRouteTrade.fromRoute =
1319
807
  /*#__PURE__*/
1320
808
  function () {
1321
- var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(route, amount, tradeType) {
809
+ var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(route, amount, tradeType) {
1322
810
  var amounts, inputAmount, outputAmount, i, pool, _yield$pool$getOutput, _outputAmount;
1323
-
1324
- return runtime_1.wrap(function _callee$(_context) {
1325
- while (1) {
1326
- switch (_context.prev = _context.next) {
1327
- case 0:
1328
- amounts = new Array(route.path.length);
1329
- !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
1330
- !amount.currency.equals(route.input) ? invariant(false, 'INPUT') : void 0;
1331
- amounts[0] = amount.wrapped;
1332
- i = 0;
1333
-
1334
- case 5:
1335
- if (!(i < route.path.length - 1)) {
1336
- _context.next = 15;
1337
- break;
1338
- }
1339
-
1340
- pool = route.pools[i];
1341
- _context.next = 9;
1342
- return pool.getOutputAmount(amounts[i]);
1343
-
1344
- case 9:
1345
- _yield$pool$getOutput = _context.sent;
1346
- _outputAmount = _yield$pool$getOutput[0];
1347
- amounts[i + 1] = _outputAmount;
1348
-
1349
- case 12:
1350
- i++;
1351
- _context.next = 5;
811
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
812
+ while (1) switch (_context.prev = _context.next) {
813
+ case 0:
814
+ amounts = new Array(route.path.length);
815
+ !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
816
+ !amount.currency.equals(route.input) ? invariant(false, 'INPUT') : void 0;
817
+ amounts[0] = amount.wrapped;
818
+ i = 0;
819
+ case 5:
820
+ if (!(i < route.path.length - 1)) {
821
+ _context.next = 15;
1352
822
  break;
1353
-
1354
- case 15:
1355
- inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
1356
- outputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.output, amounts[amounts.length - 1].numerator, amounts[amounts.length - 1].denominator);
1357
- return _context.abrupt("return", new MixedRouteTrade({
1358
- routes: [{
1359
- inputAmount: inputAmount,
1360
- outputAmount: outputAmount,
1361
- route: route
1362
- }],
1363
- tradeType: tradeType
1364
- }));
1365
-
1366
- case 18:
1367
- case "end":
1368
- return _context.stop();
1369
- }
823
+ }
824
+ pool = route.pools[i];
825
+ _context.next = 9;
826
+ return pool.getOutputAmount(amounts[i]);
827
+ case 9:
828
+ _yield$pool$getOutput = _context.sent;
829
+ _outputAmount = _yield$pool$getOutput[0];
830
+ amounts[i + 1] = _outputAmount;
831
+ case 12:
832
+ i++;
833
+ _context.next = 5;
834
+ break;
835
+ case 15:
836
+ inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
837
+ outputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.output, amounts[amounts.length - 1].numerator, amounts[amounts.length - 1].denominator);
838
+ return _context.abrupt("return", new MixedRouteTrade({
839
+ routes: [{
840
+ inputAmount: inputAmount,
841
+ outputAmount: outputAmount,
842
+ route: route
843
+ }],
844
+ tradeType: tradeType
845
+ }));
846
+ case 18:
847
+ case "end":
848
+ return _context.stop();
1370
849
  }
1371
850
  }, _callee);
1372
851
  }));
1373
-
1374
852
  function fromRoute(_x, _x2, _x3) {
1375
853
  return _fromRoute.apply(this, arguments);
1376
854
  }
1377
-
1378
855
  return fromRoute;
1379
856
  }()
1380
857
  /**
@@ -1388,86 +865,70 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1388
865
  * @returns The trade
1389
866
  */
1390
867
  ;
1391
-
1392
868
  MixedRouteTrade.fromRoutes =
1393
869
  /*#__PURE__*/
1394
870
  function () {
1395
- var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(routes, tradeType) {
871
+ var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(routes, tradeType) {
1396
872
  var populatedRoutes, _iterator3, _step3, _step3$value, route, amount, amounts, inputAmount, outputAmount, i, pool, _yield$pool$getOutput2, _outputAmount2;
1397
-
1398
- return runtime_1.wrap(function _callee2$(_context2) {
1399
- while (1) {
1400
- switch (_context2.prev = _context2.next) {
1401
- case 0:
1402
- populatedRoutes = [];
1403
- !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
1404
- _iterator3 = _createForOfIteratorHelperLoose(routes);
1405
-
1406
- case 3:
1407
- if ((_step3 = _iterator3()).done) {
1408
- _context2.next = 26;
1409
- break;
1410
- }
1411
-
1412
- _step3$value = _step3.value, route = _step3$value.route, amount = _step3$value.amount;
1413
- amounts = new Array(route.path.length);
1414
- inputAmount = void 0;
1415
- outputAmount = void 0;
1416
- !amount.currency.equals(route.input) ? invariant(false, 'INPUT') : void 0;
1417
- inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
1418
- amounts[0] = sdkCore.CurrencyAmount.fromFractionalAmount(route.input.wrapped, amount.numerator, amount.denominator);
1419
- i = 0;
1420
-
1421
- case 12:
1422
- if (!(i < route.path.length - 1)) {
1423
- _context2.next = 22;
1424
- break;
1425
- }
1426
-
1427
- pool = route.pools[i];
1428
- _context2.next = 16;
1429
- return pool.getOutputAmount(amounts[i]);
1430
-
1431
- case 16:
1432
- _yield$pool$getOutput2 = _context2.sent;
1433
- _outputAmount2 = _yield$pool$getOutput2[0];
1434
- amounts[i + 1] = _outputAmount2;
1435
-
1436
- case 19:
1437
- i++;
1438
- _context2.next = 12;
873
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
874
+ while (1) switch (_context2.prev = _context2.next) {
875
+ case 0:
876
+ populatedRoutes = [];
877
+ !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
878
+ _iterator3 = _createForOfIteratorHelperLoose(routes);
879
+ case 3:
880
+ if ((_step3 = _iterator3()).done) {
881
+ _context2.next = 26;
1439
882
  break;
1440
-
1441
- case 22:
1442
- outputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.output, amounts[amounts.length - 1].numerator, amounts[amounts.length - 1].denominator);
1443
- populatedRoutes.push({
1444
- route: route,
1445
- inputAmount: inputAmount,
1446
- outputAmount: outputAmount
1447
- });
1448
-
1449
- case 24:
1450
- _context2.next = 3;
883
+ }
884
+ _step3$value = _step3.value, route = _step3$value.route, amount = _step3$value.amount;
885
+ amounts = new Array(route.path.length);
886
+ inputAmount = void 0;
887
+ outputAmount = void 0;
888
+ !amount.currency.equals(route.input) ? invariant(false, 'INPUT') : void 0;
889
+ inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
890
+ amounts[0] = sdkCore.CurrencyAmount.fromFractionalAmount(route.input.wrapped, amount.numerator, amount.denominator);
891
+ i = 0;
892
+ case 12:
893
+ if (!(i < route.path.length - 1)) {
894
+ _context2.next = 22;
1451
895
  break;
1452
-
1453
- case 26:
1454
- return _context2.abrupt("return", new MixedRouteTrade({
1455
- routes: populatedRoutes,
1456
- tradeType: tradeType
1457
- }));
1458
-
1459
- case 27:
1460
- case "end":
1461
- return _context2.stop();
1462
- }
896
+ }
897
+ pool = route.pools[i];
898
+ _context2.next = 16;
899
+ return pool.getOutputAmount(amounts[i]);
900
+ case 16:
901
+ _yield$pool$getOutput2 = _context2.sent;
902
+ _outputAmount2 = _yield$pool$getOutput2[0];
903
+ amounts[i + 1] = _outputAmount2;
904
+ case 19:
905
+ i++;
906
+ _context2.next = 12;
907
+ break;
908
+ case 22:
909
+ outputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.output, amounts[amounts.length - 1].numerator, amounts[amounts.length - 1].denominator);
910
+ populatedRoutes.push({
911
+ route: route,
912
+ inputAmount: inputAmount,
913
+ outputAmount: outputAmount
914
+ });
915
+ case 24:
916
+ _context2.next = 3;
917
+ break;
918
+ case 26:
919
+ return _context2.abrupt("return", new MixedRouteTrade({
920
+ routes: populatedRoutes,
921
+ tradeType: tradeType
922
+ }));
923
+ case 27:
924
+ case "end":
925
+ return _context2.stop();
1463
926
  }
1464
927
  }, _callee2);
1465
928
  }));
1466
-
1467
929
  function fromRoutes(_x4, _x5) {
1468
930
  return _fromRoutes.apply(this, arguments);
1469
931
  }
1470
-
1471
932
  return fromRoutes;
1472
933
  }()
1473
934
  /**
@@ -1480,7 +941,6 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1480
941
  * @returns The unchecked trade
1481
942
  */
1482
943
  ;
1483
-
1484
944
  MixedRouteTrade.createUncheckedTrade = function createUncheckedTrade(constructorArguments) {
1485
945
  return new MixedRouteTrade(_extends({}, constructorArguments, {
1486
946
  routes: [{
@@ -1498,9 +958,7 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1498
958
  * @template TTradeType The type of the trade, either exact in or exact out
1499
959
  * @param constructorArguments The arguments passed to the trade constructor
1500
960
  * @returns The unchecked trade
1501
- */
1502
- ;
1503
-
961
+ */;
1504
962
  MixedRouteTrade.createUncheckedTradeWithMultipleRoutes = function createUncheckedTradeWithMultipleRoutes(constructorArguments) {
1505
963
  return new MixedRouteTrade(constructorArguments);
1506
964
  }
@@ -1508,18 +966,14 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1508
966
  * Get the minimum amount that must be received from this trade for the given slippage tolerance
1509
967
  * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
1510
968
  * @returns The amount out
1511
- */
1512
- ;
1513
-
969
+ */;
1514
970
  var _proto = MixedRouteTrade.prototype;
1515
-
1516
971
  _proto.minimumAmountOut = function minimumAmountOut(slippageTolerance, amountOut) {
1517
972
  if (amountOut === void 0) {
1518
973
  amountOut = this.outputAmount;
1519
974
  }
1520
-
1521
- !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0; /// does not support exactOutput, as enforced in the constructor
1522
-
975
+ !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
976
+ /// does not support exactOutput, as enforced in the constructor
1523
977
  var slippageAdjustedAmountOut = new sdkCore.Fraction(ONE).add(slippageTolerance).invert().multiply(amountOut.quotient).quotient;
1524
978
  return sdkCore.CurrencyAmount.fromRawAmount(amountOut.currency, slippageAdjustedAmountOut);
1525
979
  }
@@ -1527,24 +981,20 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1527
981
  * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
1528
982
  * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
1529
983
  * @returns The amount in
1530
- */
1531
- ;
1532
-
984
+ */;
1533
985
  _proto.maximumAmountIn = function maximumAmountIn(slippageTolerance, amountIn) {
1534
986
  if (amountIn === void 0) {
1535
987
  amountIn = this.inputAmount;
1536
988
  }
1537
-
1538
989
  !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
1539
- return amountIn; /// does not support exactOutput
990
+ return amountIn;
991
+ /// does not support exactOutput
1540
992
  }
1541
993
  /**
1542
994
  * Return the execution price after accounting for slippage tolerance
1543
995
  * @param slippageTolerance the allowed tolerated slippage
1544
996
  * @returns The execution price
1545
- */
1546
- ;
1547
-
997
+ */;
1548
998
  _proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) {
1549
999
  return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
1550
1000
  }
@@ -1562,168 +1012,133 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1562
1012
  * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
1563
1013
  * @param bestTrades used in recursion; the current list of best trades
1564
1014
  * @returns The exact in trade
1565
- */
1566
- ;
1567
-
1015
+ */;
1568
1016
  MixedRouteTrade.bestTradeExactIn =
1569
1017
  /*#__PURE__*/
1570
1018
  function () {
1571
- var _bestTradeExactIn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee3(pools, currencyAmountIn, currencyOut, _temp, // used in recursion.
1019
+ var _bestTradeExactIn = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(pools, currencyAmountIn, currencyOut, _temp,
1020
+ // used in recursion.
1572
1021
  currentPools, nextAmountIn, bestTrades) {
1573
1022
  var _ref5, _ref5$maxNumResults, maxNumResults, _ref5$maxHops, maxHops, amountIn, tokenOut, i, pool, amountOut, _yield$pool$getOutput3, poolsExcludingThisPool;
1574
-
1575
- return runtime_1.wrap(function _callee3$(_context3) {
1576
- while (1) {
1577
- switch (_context3.prev = _context3.next) {
1578
- case 0:
1579
- _ref5 = _temp === void 0 ? {} : _temp, _ref5$maxNumResults = _ref5.maxNumResults, maxNumResults = _ref5$maxNumResults === void 0 ? 3 : _ref5$maxNumResults, _ref5$maxHops = _ref5.maxHops, maxHops = _ref5$maxHops === void 0 ? 3 : _ref5$maxHops;
1580
-
1581
- if (currentPools === void 0) {
1582
- currentPools = [];
1583
- }
1584
-
1585
- if (nextAmountIn === void 0) {
1586
- nextAmountIn = currencyAmountIn;
1587
- }
1588
-
1589
- if (bestTrades === void 0) {
1590
- bestTrades = [];
1591
- }
1592
-
1593
- !(pools.length > 0) ? invariant(false, 'POOLS') : void 0;
1594
- !(maxHops > 0) ? invariant(false, 'MAX_HOPS') : void 0;
1595
- !(currencyAmountIn === nextAmountIn || currentPools.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0;
1596
- amountIn = nextAmountIn.wrapped;
1597
- tokenOut = currencyOut.wrapped;
1598
- i = 0;
1599
-
1600
- case 10:
1601
- if (!(i < pools.length)) {
1602
- _context3.next = 49;
1603
- break;
1604
- }
1605
-
1606
- pool = pools[i]; // pool irrelevant
1607
-
1608
- if (!(!pool.token0.equals(amountIn.currency) && !pool.token1.equals(amountIn.currency))) {
1609
- _context3.next = 14;
1610
- break;
1611
- }
1612
-
1613
- return _context3.abrupt("continue", 46);
1614
-
1615
- case 14:
1616
- if (!(pool instanceof v2Sdk.Pair)) {
1617
- _context3.next = 17;
1618
- break;
1619
- }
1620
-
1621
- if (!(pool.reserve0.equalTo(ZERO) || pool.reserve1.equalTo(ZERO))) {
1622
- _context3.next = 17;
1623
- break;
1624
- }
1625
-
1626
- return _context3.abrupt("continue", 46);
1627
-
1628
- case 17:
1629
- amountOut = void 0;
1630
- _context3.prev = 18;
1631
- _context3.next = 22;
1632
- return pool.getOutputAmount(amountIn);
1633
-
1634
- case 22:
1635
- _yield$pool$getOutput3 = _context3.sent;
1636
- amountOut = _yield$pool$getOutput3[0];
1637
- _context3.next = 31;
1023
+ return _regeneratorRuntime().wrap(function _callee3$(_context3) {
1024
+ while (1) switch (_context3.prev = _context3.next) {
1025
+ case 0:
1026
+ _ref5 = _temp === void 0 ? {} : _temp, _ref5$maxNumResults = _ref5.maxNumResults, maxNumResults = _ref5$maxNumResults === void 0 ? 3 : _ref5$maxNumResults, _ref5$maxHops = _ref5.maxHops, maxHops = _ref5$maxHops === void 0 ? 3 : _ref5$maxHops;
1027
+ if (currentPools === void 0) {
1028
+ currentPools = [];
1029
+ }
1030
+ if (nextAmountIn === void 0) {
1031
+ nextAmountIn = currencyAmountIn;
1032
+ }
1033
+ if (bestTrades === void 0) {
1034
+ bestTrades = [];
1035
+ }
1036
+ !(pools.length > 0) ? invariant(false, 'POOLS') : void 0;
1037
+ !(maxHops > 0) ? invariant(false, 'MAX_HOPS') : void 0;
1038
+ !(currencyAmountIn === nextAmountIn || currentPools.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0;
1039
+ amountIn = nextAmountIn.wrapped;
1040
+ tokenOut = currencyOut.wrapped;
1041
+ i = 0;
1042
+ case 10:
1043
+ if (!(i < pools.length)) {
1044
+ _context3.next = 49;
1045
+ break;
1046
+ }
1047
+ pool = pools[i]; // pool irrelevant
1048
+ if (!(!pool.token0.equals(amountIn.currency) && !pool.token1.equals(amountIn.currency))) {
1049
+ _context3.next = 14;
1050
+ break;
1051
+ }
1052
+ return _context3.abrupt("continue", 46);
1053
+ case 14:
1054
+ if (!(pool instanceof v2Sdk.Pair)) {
1055
+ _context3.next = 17;
1056
+ break;
1057
+ }
1058
+ if (!(pool.reserve0.equalTo(ZERO) || pool.reserve1.equalTo(ZERO))) {
1059
+ _context3.next = 17;
1060
+ break;
1061
+ }
1062
+ return _context3.abrupt("continue", 46);
1063
+ case 17:
1064
+ amountOut = void 0;
1065
+ _context3.prev = 18;
1066
+ _context3.next = 22;
1067
+ return pool.getOutputAmount(amountIn);
1068
+ case 22:
1069
+ _yield$pool$getOutput3 = _context3.sent;
1070
+ amountOut = _yield$pool$getOutput3[0];
1071
+ _context3.next = 31;
1072
+ break;
1073
+ case 26:
1074
+ _context3.prev = 26;
1075
+ _context3.t0 = _context3["catch"](18);
1076
+ if (!_context3.t0.isInsufficientInputAmountError) {
1077
+ _context3.next = 30;
1638
1078
  break;
1639
-
1640
- case 26:
1641
- _context3.prev = 26;
1642
- _context3.t0 = _context3["catch"](18);
1643
-
1644
- if (!_context3.t0.isInsufficientInputAmountError) {
1645
- _context3.next = 30;
1646
- break;
1647
- }
1648
-
1649
- return _context3.abrupt("continue", 46);
1650
-
1651
- case 30:
1652
- throw _context3.t0;
1653
-
1654
- case 31:
1655
- if (!(amountOut.currency.isToken && amountOut.currency.equals(tokenOut))) {
1656
- _context3.next = 42;
1657
- break;
1658
- }
1659
-
1660
- _context3.t1 = sdkCore.sortedInsert;
1661
- _context3.t2 = bestTrades;
1662
- _context3.next = 36;
1663
- return MixedRouteTrade.fromRoute(new MixedRouteSDK([].concat(currentPools, [pool]), currencyAmountIn.currency, currencyOut), currencyAmountIn, sdkCore.TradeType.EXACT_INPUT);
1664
-
1665
- case 36:
1666
- _context3.t3 = _context3.sent;
1667
- _context3.t4 = maxNumResults;
1668
- _context3.t5 = tradeComparator;
1669
- (0, _context3.t1)(_context3.t2, _context3.t3, _context3.t4, _context3.t5);
1670
- _context3.next = 46;
1079
+ }
1080
+ return _context3.abrupt("continue", 46);
1081
+ case 30:
1082
+ throw _context3.t0;
1083
+ case 31:
1084
+ if (!(amountOut.currency.isToken && amountOut.currency.equals(tokenOut))) {
1085
+ _context3.next = 42;
1671
1086
  break;
1672
-
1673
- case 42:
1674
- if (!(maxHops > 1 && pools.length > 1)) {
1675
- _context3.next = 46;
1676
- break;
1677
- }
1678
-
1679
- poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length)); // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops
1680
-
1087
+ }
1088
+ _context3.t1 = sdkCore.sortedInsert;
1089
+ _context3.t2 = bestTrades;
1090
+ _context3.next = 36;
1091
+ return MixedRouteTrade.fromRoute(new MixedRouteSDK([].concat(currentPools, [pool]), currencyAmountIn.currency, currencyOut), currencyAmountIn, sdkCore.TradeType.EXACT_INPUT);
1092
+ case 36:
1093
+ _context3.t3 = _context3.sent;
1094
+ _context3.t4 = maxNumResults;
1095
+ _context3.t5 = tradeComparator;
1096
+ (0, _context3.t1)(_context3.t2, _context3.t3, _context3.t4, _context3.t5);
1097
+ _context3.next = 46;
1098
+ break;
1099
+ case 42:
1100
+ if (!(maxHops > 1 && pools.length > 1)) {
1681
1101
  _context3.next = 46;
1682
- return MixedRouteTrade.bestTradeExactIn(poolsExcludingThisPool, currencyAmountIn, currencyOut, {
1683
- maxNumResults: maxNumResults,
1684
- maxHops: maxHops - 1
1685
- }, [].concat(currentPools, [pool]), amountOut, bestTrades);
1686
-
1687
- case 46:
1688
- i++;
1689
- _context3.next = 10;
1690
1102
  break;
1691
-
1692
- case 49:
1693
- return _context3.abrupt("return", bestTrades);
1694
-
1695
- case 50:
1696
- case "end":
1697
- return _context3.stop();
1698
- }
1103
+ }
1104
+ poolsExcludingThisPool = pools.slice(0, i).concat(pools.slice(i + 1, pools.length)); // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops
1105
+ _context3.next = 46;
1106
+ return MixedRouteTrade.bestTradeExactIn(poolsExcludingThisPool, currencyAmountIn, currencyOut, {
1107
+ maxNumResults: maxNumResults,
1108
+ maxHops: maxHops - 1
1109
+ }, [].concat(currentPools, [pool]), amountOut, bestTrades);
1110
+ case 46:
1111
+ i++;
1112
+ _context3.next = 10;
1113
+ break;
1114
+ case 49:
1115
+ return _context3.abrupt("return", bestTrades);
1116
+ case 50:
1117
+ case "end":
1118
+ return _context3.stop();
1699
1119
  }
1700
1120
  }, _callee3, null, [[18, 26]]);
1701
1121
  }));
1702
-
1703
1122
  function bestTradeExactIn(_x6, _x7, _x8, _x9, _x10, _x11, _x12) {
1704
1123
  return _bestTradeExactIn.apply(this, arguments);
1705
1124
  }
1706
-
1707
1125
  return bestTradeExactIn;
1708
1126
  }();
1709
-
1710
1127
  _createClass(MixedRouteTrade, [{
1711
1128
  key: "route",
1712
1129
  get: function get() {
1713
- !(this.swaps.length == 1) ? invariant(false, 'MULTIPLE_ROUTES') : void 0;
1130
+ !(this.swaps.length === 1) ? invariant(false, 'MULTIPLE_ROUTES') : void 0;
1714
1131
  return this.swaps[0].route;
1715
1132
  }
1716
1133
  /**
1717
1134
  * The input amount for the trade assuming no slippage.
1718
1135
  */
1719
-
1720
1136
  }, {
1721
1137
  key: "inputAmount",
1722
1138
  get: function get() {
1723
1139
  if (this._inputAmount) {
1724
1140
  return this._inputAmount;
1725
1141
  }
1726
-
1727
1142
  var inputCurrency = this.swaps[0].inputAmount.currency;
1728
1143
  var totalInputFromRoutes = this.swaps.map(function (_ref6) {
1729
1144
  var inputAmount = _ref6.inputAmount;
@@ -1737,14 +1152,12 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1737
1152
  /**
1738
1153
  * The output amount for the trade assuming no slippage.
1739
1154
  */
1740
-
1741
1155
  }, {
1742
1156
  key: "outputAmount",
1743
1157
  get: function get() {
1744
1158
  if (this._outputAmount) {
1745
1159
  return this._outputAmount;
1746
1160
  }
1747
-
1748
1161
  var outputCurrency = this.swaps[0].outputAmount.currency;
1749
1162
  var totalOutputFromRoutes = this.swaps.map(function (_ref7) {
1750
1163
  var outputAmount = _ref7.outputAmount;
@@ -1758,41 +1171,34 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1758
1171
  /**
1759
1172
  * The price expressed in terms of output amount/input amount.
1760
1173
  */
1761
-
1762
1174
  }, {
1763
1175
  key: "executionPrice",
1764
1176
  get: function get() {
1765
1177
  var _this$_executionPrice;
1766
-
1767
1178
  return (_this$_executionPrice = this._executionPrice) != null ? _this$_executionPrice : this._executionPrice = new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient);
1768
1179
  }
1769
1180
  /**
1770
1181
  * Returns the percent difference between the route's mid price and the price impact
1771
1182
  */
1772
-
1773
1183
  }, {
1774
1184
  key: "priceImpact",
1775
1185
  get: function get() {
1776
1186
  if (this._priceImpact) {
1777
1187
  return this._priceImpact;
1778
1188
  }
1779
-
1780
1189
  var spotOutputAmount = sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
1781
-
1782
1190
  for (var _iterator4 = _createForOfIteratorHelperLoose(this.swaps), _step4; !(_step4 = _iterator4()).done;) {
1783
1191
  var _step4$value = _step4.value,
1784
- route = _step4$value.route,
1785
- inputAmount = _step4$value.inputAmount;
1192
+ route = _step4$value.route,
1193
+ inputAmount = _step4$value.inputAmount;
1786
1194
  var midPrice = route.midPrice;
1787
1195
  spotOutputAmount = spotOutputAmount.add(midPrice.quote(inputAmount));
1788
1196
  }
1789
-
1790
1197
  var priceImpact = spotOutputAmount.subtract(this.outputAmount).divide(spotOutputAmount);
1791
1198
  this._priceImpact = new sdkCore.Percent(priceImpact.numerator, priceImpact.denominator);
1792
1199
  return this._priceImpact;
1793
1200
  }
1794
1201
  }]);
1795
-
1796
1202
  return MixedRouteTrade;
1797
1203
  }();
1798
1204
 
@@ -1802,47 +1208,39 @@ var MixedRouteTrade = /*#__PURE__*/function () {
1802
1208
  Protocol["MIXED"] = "MIXED";
1803
1209
  })(exports.Protocol || (exports.Protocol = {}));
1804
1210
 
1211
+ // V2 route wrapper
1805
1212
  var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
1806
1213
  _inheritsLoose(RouteV2, _V2RouteSDK);
1807
-
1808
1214
  function RouteV2(v2Route) {
1809
1215
  var _this;
1810
-
1811
1216
  _this = _V2RouteSDK.call(this, v2Route.pairs, v2Route.input, v2Route.output) || this;
1812
1217
  _this.protocol = exports.Protocol.V2;
1813
1218
  _this.pools = _this.pairs;
1814
1219
  return _this;
1815
1220
  }
1816
-
1817
1221
  return RouteV2;
1818
- }(v2Sdk.Route); // V3 route wrapper
1819
-
1222
+ }(v2Sdk.Route);
1223
+ // V3 route wrapper
1820
1224
  var RouteV3 = /*#__PURE__*/function (_V3RouteSDK) {
1821
1225
  _inheritsLoose(RouteV3, _V3RouteSDK);
1822
-
1823
1226
  function RouteV3(v3Route) {
1824
1227
  var _this2;
1825
-
1826
1228
  _this2 = _V3RouteSDK.call(this, v3Route.pools, v3Route.input, v3Route.output) || this;
1827
1229
  _this2.protocol = exports.Protocol.V3;
1828
1230
  _this2.path = v3Route.tokenPath;
1829
1231
  return _this2;
1830
1232
  }
1831
-
1832
1233
  return RouteV3;
1833
- }(v3Sdk.Route); // Mixed route wrapper
1834
-
1234
+ }(v3Sdk.Route);
1235
+ // Mixed route wrapper
1835
1236
  var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
1836
1237
  _inheritsLoose(MixedRoute, _MixedRouteSDK);
1837
-
1838
1238
  function MixedRoute(mixedRoute) {
1839
1239
  var _this3;
1840
-
1841
1240
  _this3 = _MixedRouteSDK.call(this, mixedRoute.pools, mixedRoute.input, mixedRoute.output) || this;
1842
1241
  _this3.protocol = exports.Protocol.MIXED;
1843
1242
  return _this3;
1844
1243
  }
1845
-
1846
1244
  return MixedRoute;
1847
1245
  }(MixedRouteSDK);
1848
1246
 
@@ -1850,52 +1248,46 @@ var Trade = /*#__PURE__*/function () {
1850
1248
  // construct a trade across v2 and v3 routes from pre-computed amounts
1851
1249
  function Trade(_ref) {
1852
1250
  var v2Routes = _ref.v2Routes,
1853
- v3Routes = _ref.v3Routes,
1854
- tradeType = _ref.tradeType,
1855
- mixedRoutes = _ref.mixedRoutes;
1251
+ v3Routes = _ref.v3Routes,
1252
+ tradeType = _ref.tradeType,
1253
+ mixedRoutes = _ref.mixedRoutes;
1856
1254
  this.swaps = [];
1857
- this.routes = []; // wrap v2 routes
1858
-
1255
+ this.routes = [];
1256
+ // wrap v2 routes
1859
1257
  for (var _iterator = _createForOfIteratorHelperLoose(v2Routes), _step; !(_step = _iterator()).done;) {
1860
1258
  var _step$value = _step.value,
1861
- routev2 = _step$value.routev2,
1862
- _inputAmount = _step$value.inputAmount,
1863
- _outputAmount = _step$value.outputAmount;
1864
-
1259
+ routev2 = _step$value.routev2,
1260
+ _inputAmount = _step$value.inputAmount,
1261
+ _outputAmount = _step$value.outputAmount;
1865
1262
  var _route = new RouteV2(routev2);
1866
-
1867
1263
  this.routes.push(_route);
1868
1264
  this.swaps.push({
1869
1265
  route: _route,
1870
1266
  inputAmount: _inputAmount,
1871
1267
  outputAmount: _outputAmount
1872
1268
  });
1873
- } // wrap v3 routes
1874
-
1875
-
1269
+ }
1270
+ // wrap v3 routes
1876
1271
  for (var _iterator2 = _createForOfIteratorHelperLoose(v3Routes), _step2; !(_step2 = _iterator2()).done;) {
1877
1272
  var _step2$value = _step2.value,
1878
- routev3 = _step2$value.routev3,
1879
- _inputAmount2 = _step2$value.inputAmount,
1880
- _outputAmount2 = _step2$value.outputAmount;
1881
-
1273
+ routev3 = _step2$value.routev3,
1274
+ _inputAmount2 = _step2$value.inputAmount,
1275
+ _outputAmount2 = _step2$value.outputAmount;
1882
1276
  var _route2 = new RouteV3(routev3);
1883
-
1884
1277
  this.routes.push(_route2);
1885
1278
  this.swaps.push({
1886
1279
  route: _route2,
1887
1280
  inputAmount: _inputAmount2,
1888
1281
  outputAmount: _outputAmount2
1889
1282
  });
1890
- } // wrap mixedRoutes
1891
-
1892
-
1283
+ }
1284
+ // wrap mixedRoutes
1893
1285
  if (mixedRoutes) {
1894
1286
  for (var _iterator3 = _createForOfIteratorHelperLoose(mixedRoutes), _step3; !(_step3 = _iterator3()).done;) {
1895
1287
  var _step3$value = _step3.value,
1896
- mixedRoute = _step3$value.mixedRoute,
1897
- inputAmount = _step3$value.inputAmount,
1898
- outputAmount = _step3$value.outputAmount;
1288
+ mixedRoute = _step3$value.mixedRoute,
1289
+ inputAmount = _step3$value.inputAmount,
1290
+ outputAmount = _step3$value.outputAmount;
1899
1291
  var route = new MixedRoute(mixedRoute);
1900
1292
  this.routes.push(route);
1901
1293
  this.swaps.push({
@@ -1905,13 +1297,11 @@ var Trade = /*#__PURE__*/function () {
1905
1297
  });
1906
1298
  }
1907
1299
  }
1908
-
1909
1300
  if (this.swaps.length === 0) {
1910
1301
  throw new Error('No routes provided when calling Trade constructor');
1911
1302
  }
1912
-
1913
- this.tradeType = tradeType; // each route must have the same input and output currency
1914
-
1303
+ this.tradeType = tradeType;
1304
+ // each route must have the same input and output currency
1915
1305
  var inputCurrency = this.swaps[0].inputAmount.currency;
1916
1306
  var outputCurrency = this.swaps[0].outputAmount.currency;
1917
1307
  !this.swaps.every(function (_ref2) {
@@ -1921,8 +1311,8 @@ var Trade = /*#__PURE__*/function () {
1921
1311
  !this.swaps.every(function (_ref3) {
1922
1312
  var route = _ref3.route;
1923
1313
  return outputCurrency.wrapped.equals(route.output.wrapped);
1924
- }) ? invariant(false, 'OUTPUT_CURRENCY_MATCH') : void 0; // pools must be unique inter protocols
1925
-
1314
+ }) ? invariant(false, 'OUTPUT_CURRENCY_MATCH') : void 0;
1315
+ // pools must be unique inter protocols
1926
1316
  var numPools = this.swaps.map(function (_ref4) {
1927
1317
  var route = _ref4.route;
1928
1318
  return route.pools.length;
@@ -1930,13 +1320,10 @@ var Trade = /*#__PURE__*/function () {
1930
1320
  return total + cur;
1931
1321
  }, 0);
1932
1322
  var poolAddressSet = new Set();
1933
-
1934
1323
  for (var _iterator4 = _createForOfIteratorHelperLoose(this.swaps), _step4; !(_step4 = _iterator4()).done;) {
1935
1324
  var _route3 = _step4.value.route;
1936
-
1937
1325
  for (var _iterator5 = _createForOfIteratorHelperLoose(_route3.pools), _step5; !(_step5 = _iterator5()).done;) {
1938
1326
  var pool = _step5.value;
1939
-
1940
1327
  if (pool instanceof v3Sdk.Pool) {
1941
1328
  poolAddressSet.add(v3Sdk.Pool.getAddress(pool.token0, pool.token1, pool.fee));
1942
1329
  } else if (pool instanceof v2Sdk.Pair) {
@@ -1947,12 +1334,9 @@ var Trade = /*#__PURE__*/function () {
1947
1334
  }
1948
1335
  }
1949
1336
  }
1950
-
1951
- !(numPools == poolAddressSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
1337
+ !(numPools === poolAddressSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
1952
1338
  }
1953
-
1954
1339
  var _proto = Trade.prototype;
1955
-
1956
1340
  /**
1957
1341
  * Get the minimum amount that must be received from this trade for the given slippage tolerance
1958
1342
  * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
@@ -1962,9 +1346,7 @@ var Trade = /*#__PURE__*/function () {
1962
1346
  if (amountOut === void 0) {
1963
1347
  amountOut = this.outputAmount;
1964
1348
  }
1965
-
1966
1349
  !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
1967
-
1968
1350
  if (this.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
1969
1351
  return amountOut;
1970
1352
  } else {
@@ -1976,16 +1358,12 @@ var Trade = /*#__PURE__*/function () {
1976
1358
  * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
1977
1359
  * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
1978
1360
  * @returns The amount in
1979
- */
1980
- ;
1981
-
1361
+ */;
1982
1362
  _proto.maximumAmountIn = function maximumAmountIn(slippageTolerance, amountIn) {
1983
1363
  if (amountIn === void 0) {
1984
1364
  amountIn = this.inputAmount;
1985
1365
  }
1986
-
1987
1366
  !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
1988
-
1989
1367
  if (this.tradeType === sdkCore.TradeType.EXACT_INPUT) {
1990
1368
  return amountIn;
1991
1369
  } else {
@@ -1997,215 +1375,174 @@ var Trade = /*#__PURE__*/function () {
1997
1375
  * Return the execution price after accounting for slippage tolerance
1998
1376
  * @param slippageTolerance the allowed tolerated slippage
1999
1377
  * @returns The execution price
2000
- */
2001
- ;
2002
-
1378
+ */;
2003
1379
  _proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) {
2004
1380
  return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
2005
1381
  };
2006
-
2007
1382
  Trade.fromRoutes = /*#__PURE__*/function () {
2008
- var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes) {
1383
+ var _fromRoutes = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes) {
2009
1384
  var populatedV2Routes, populatedV3Routes, populatedMixedRoutes, _iterator6, _step6, _step6$value, routev2, _amount, v2Trade, _inputAmount3, _outputAmount3, _iterator7, _step7, _step7$value, routev3, _amount2, v3Trade, _inputAmount4, _outputAmount4, _iterator8, _step8, _step8$value, mixedRoute, amount, mixedRouteTrade, inputAmount, outputAmount;
2010
-
2011
- return runtime_1.wrap(function _callee$(_context) {
2012
- while (1) {
2013
- switch (_context.prev = _context.next) {
2014
- case 0:
2015
- populatedV2Routes = [];
2016
- populatedV3Routes = [];
2017
- populatedMixedRoutes = [];
2018
-
2019
- for (_iterator6 = _createForOfIteratorHelperLoose(v2Routes); !(_step6 = _iterator6()).done;) {
2020
- _step6$value = _step6.value, routev2 = _step6$value.routev2, _amount = _step6$value.amount;
2021
- v2Trade = new v2Sdk.Trade(routev2, _amount, tradeType);
2022
- _inputAmount3 = v2Trade.inputAmount, _outputAmount3 = v2Trade.outputAmount;
2023
- populatedV2Routes.push({
2024
- routev2: routev2,
2025
- inputAmount: _inputAmount3,
2026
- outputAmount: _outputAmount3
2027
- });
2028
- }
2029
-
2030
- _iterator7 = _createForOfIteratorHelperLoose(v3Routes);
2031
-
2032
- case 5:
2033
- if ((_step7 = _iterator7()).done) {
2034
- _context.next = 14;
2035
- break;
2036
- }
2037
-
2038
- _step7$value = _step7.value, routev3 = _step7$value.routev3, _amount2 = _step7$value.amount;
2039
- _context.next = 9;
2040
- return v3Sdk.Trade.fromRoute(routev3, _amount2, tradeType);
2041
-
2042
- case 9:
2043
- v3Trade = _context.sent;
2044
- _inputAmount4 = v3Trade.inputAmount, _outputAmount4 = v3Trade.outputAmount;
2045
- populatedV3Routes.push({
2046
- routev3: routev3,
2047
- inputAmount: _inputAmount4,
2048
- outputAmount: _outputAmount4
1385
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
1386
+ while (1) switch (_context.prev = _context.next) {
1387
+ case 0:
1388
+ populatedV2Routes = [];
1389
+ populatedV3Routes = [];
1390
+ populatedMixedRoutes = [];
1391
+ for (_iterator6 = _createForOfIteratorHelperLoose(v2Routes); !(_step6 = _iterator6()).done;) {
1392
+ _step6$value = _step6.value, routev2 = _step6$value.routev2, _amount = _step6$value.amount;
1393
+ v2Trade = new v2Sdk.Trade(routev2, _amount, tradeType);
1394
+ _inputAmount3 = v2Trade.inputAmount, _outputAmount3 = v2Trade.outputAmount;
1395
+ populatedV2Routes.push({
1396
+ routev2: routev2,
1397
+ inputAmount: _inputAmount3,
1398
+ outputAmount: _outputAmount3
2049
1399
  });
2050
-
2051
- case 12:
2052
- _context.next = 5;
1400
+ }
1401
+ _iterator7 = _createForOfIteratorHelperLoose(v3Routes);
1402
+ case 5:
1403
+ if ((_step7 = _iterator7()).done) {
1404
+ _context.next = 14;
2053
1405
  break;
2054
-
2055
- case 14:
2056
- if (!mixedRoutes) {
2057
- _context.next = 25;
2058
- break;
2059
- }
2060
-
2061
- _iterator8 = _createForOfIteratorHelperLoose(mixedRoutes);
2062
-
2063
- case 16:
2064
- if ((_step8 = _iterator8()).done) {
2065
- _context.next = 25;
2066
- break;
2067
- }
2068
-
2069
- _step8$value = _step8.value, mixedRoute = _step8$value.mixedRoute, amount = _step8$value.amount;
2070
- _context.next = 20;
2071
- return MixedRouteTrade.fromRoute(mixedRoute, amount, tradeType);
2072
-
2073
- case 20:
2074
- mixedRouteTrade = _context.sent;
2075
- inputAmount = mixedRouteTrade.inputAmount, outputAmount = mixedRouteTrade.outputAmount;
2076
- populatedMixedRoutes.push({
2077
- mixedRoute: mixedRoute,
2078
- inputAmount: inputAmount,
2079
- outputAmount: outputAmount
2080
- });
2081
-
2082
- case 23:
2083
- _context.next = 16;
1406
+ }
1407
+ _step7$value = _step7.value, routev3 = _step7$value.routev3, _amount2 = _step7$value.amount;
1408
+ _context.next = 9;
1409
+ return v3Sdk.Trade.fromRoute(routev3, _amount2, tradeType);
1410
+ case 9:
1411
+ v3Trade = _context.sent;
1412
+ _inputAmount4 = v3Trade.inputAmount, _outputAmount4 = v3Trade.outputAmount;
1413
+ populatedV3Routes.push({
1414
+ routev3: routev3,
1415
+ inputAmount: _inputAmount4,
1416
+ outputAmount: _outputAmount4
1417
+ });
1418
+ case 12:
1419
+ _context.next = 5;
1420
+ break;
1421
+ case 14:
1422
+ if (!mixedRoutes) {
1423
+ _context.next = 25;
2084
1424
  break;
2085
-
2086
- case 25:
2087
- return _context.abrupt("return", new Trade({
2088
- v2Routes: populatedV2Routes,
2089
- v3Routes: populatedV3Routes,
2090
- mixedRoutes: populatedMixedRoutes,
2091
- tradeType: tradeType
2092
- }));
2093
-
2094
- case 26:
2095
- case "end":
2096
- return _context.stop();
2097
- }
1425
+ }
1426
+ _iterator8 = _createForOfIteratorHelperLoose(mixedRoutes);
1427
+ case 16:
1428
+ if ((_step8 = _iterator8()).done) {
1429
+ _context.next = 25;
1430
+ break;
1431
+ }
1432
+ _step8$value = _step8.value, mixedRoute = _step8$value.mixedRoute, amount = _step8$value.amount;
1433
+ _context.next = 20;
1434
+ return MixedRouteTrade.fromRoute(mixedRoute, amount, tradeType);
1435
+ case 20:
1436
+ mixedRouteTrade = _context.sent;
1437
+ inputAmount = mixedRouteTrade.inputAmount, outputAmount = mixedRouteTrade.outputAmount;
1438
+ populatedMixedRoutes.push({
1439
+ mixedRoute: mixedRoute,
1440
+ inputAmount: inputAmount,
1441
+ outputAmount: outputAmount
1442
+ });
1443
+ case 23:
1444
+ _context.next = 16;
1445
+ break;
1446
+ case 25:
1447
+ return _context.abrupt("return", new Trade({
1448
+ v2Routes: populatedV2Routes,
1449
+ v3Routes: populatedV3Routes,
1450
+ mixedRoutes: populatedMixedRoutes,
1451
+ tradeType: tradeType
1452
+ }));
1453
+ case 26:
1454
+ case "end":
1455
+ return _context.stop();
2098
1456
  }
2099
1457
  }, _callee);
2100
1458
  }));
2101
-
2102
1459
  function fromRoutes(_x, _x2, _x3, _x4) {
2103
1460
  return _fromRoutes.apply(this, arguments);
2104
1461
  }
2105
-
2106
1462
  return fromRoutes;
2107
1463
  }();
2108
-
2109
1464
  Trade.fromRoute = /*#__PURE__*/function () {
2110
- var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/runtime_1.mark(function _callee2(route, amount, tradeType) {
1465
+ var _fromRoute = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(route, amount, tradeType) {
2111
1466
  var v2Routes, v3Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade, _inputAmount5, _outputAmount5, mixedRouteTrade, _inputAmount6, _outputAmount6;
2112
-
2113
- return runtime_1.wrap(function _callee2$(_context2) {
2114
- while (1) {
2115
- switch (_context2.prev = _context2.next) {
2116
- case 0:
2117
- v2Routes = [];
2118
- v3Routes = [];
2119
- mixedRoutes = [];
2120
-
2121
- if (!(route instanceof v2Sdk.Route)) {
2122
- _context2.next = 9;
2123
- break;
2124
- }
2125
-
2126
- v2Trade = new v2Sdk.Trade(route, amount, tradeType);
2127
- inputAmount = v2Trade.inputAmount, outputAmount = v2Trade.outputAmount;
2128
- v2Routes = [{
2129
- routev2: route,
2130
- inputAmount: inputAmount,
2131
- outputAmount: outputAmount
2132
- }];
2133
- _context2.next = 26;
1467
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
1468
+ while (1) switch (_context2.prev = _context2.next) {
1469
+ case 0:
1470
+ v2Routes = [];
1471
+ v3Routes = [];
1472
+ mixedRoutes = [];
1473
+ if (!(route instanceof v2Sdk.Route)) {
1474
+ _context2.next = 9;
2134
1475
  break;
2135
-
2136
- case 9:
2137
- if (!(route instanceof v3Sdk.Route)) {
2138
- _context2.next = 17;
2139
- break;
2140
- }
2141
-
2142
- _context2.next = 12;
2143
- return v3Sdk.Trade.fromRoute(route, amount, tradeType);
2144
-
2145
- case 12:
2146
- v3Trade = _context2.sent;
2147
- _inputAmount5 = v3Trade.inputAmount, _outputAmount5 = v3Trade.outputAmount;
2148
- v3Routes = [{
2149
- routev3: route,
2150
- inputAmount: _inputAmount5,
2151
- outputAmount: _outputAmount5
2152
- }];
2153
- _context2.next = 26;
1476
+ }
1477
+ v2Trade = new v2Sdk.Trade(route, amount, tradeType);
1478
+ inputAmount = v2Trade.inputAmount, outputAmount = v2Trade.outputAmount;
1479
+ v2Routes = [{
1480
+ routev2: route,
1481
+ inputAmount: inputAmount,
1482
+ outputAmount: outputAmount
1483
+ }];
1484
+ _context2.next = 26;
1485
+ break;
1486
+ case 9:
1487
+ if (!(route instanceof v3Sdk.Route)) {
1488
+ _context2.next = 17;
2154
1489
  break;
2155
-
2156
- case 17:
2157
- if (!(route instanceof MixedRouteSDK)) {
2158
- _context2.next = 25;
2159
- break;
2160
- }
2161
-
2162
- _context2.next = 20;
2163
- return MixedRouteTrade.fromRoute(route, amount, tradeType);
2164
-
2165
- case 20:
2166
- mixedRouteTrade = _context2.sent;
2167
- _inputAmount6 = mixedRouteTrade.inputAmount, _outputAmount6 = mixedRouteTrade.outputAmount;
2168
- mixedRoutes = [{
2169
- mixedRoute: route,
2170
- inputAmount: _inputAmount6,
2171
- outputAmount: _outputAmount6
2172
- }];
2173
- _context2.next = 26;
1490
+ }
1491
+ _context2.next = 12;
1492
+ return v3Sdk.Trade.fromRoute(route, amount, tradeType);
1493
+ case 12:
1494
+ v3Trade = _context2.sent;
1495
+ _inputAmount5 = v3Trade.inputAmount, _outputAmount5 = v3Trade.outputAmount;
1496
+ v3Routes = [{
1497
+ routev3: route,
1498
+ inputAmount: _inputAmount5,
1499
+ outputAmount: _outputAmount5
1500
+ }];
1501
+ _context2.next = 26;
1502
+ break;
1503
+ case 17:
1504
+ if (!(route instanceof MixedRouteSDK)) {
1505
+ _context2.next = 25;
2174
1506
  break;
2175
-
2176
- case 25:
2177
- throw new Error('Invalid route type');
2178
-
2179
- case 26:
2180
- return _context2.abrupt("return", new Trade({
2181
- v2Routes: v2Routes,
2182
- v3Routes: v3Routes,
2183
- mixedRoutes: mixedRoutes,
2184
- tradeType: tradeType
2185
- }));
2186
-
2187
- case 27:
2188
- case "end":
2189
- return _context2.stop();
2190
- }
1507
+ }
1508
+ _context2.next = 20;
1509
+ return MixedRouteTrade.fromRoute(route, amount, tradeType);
1510
+ case 20:
1511
+ mixedRouteTrade = _context2.sent;
1512
+ _inputAmount6 = mixedRouteTrade.inputAmount, _outputAmount6 = mixedRouteTrade.outputAmount;
1513
+ mixedRoutes = [{
1514
+ mixedRoute: route,
1515
+ inputAmount: _inputAmount6,
1516
+ outputAmount: _outputAmount6
1517
+ }];
1518
+ _context2.next = 26;
1519
+ break;
1520
+ case 25:
1521
+ throw new Error('Invalid route type');
1522
+ case 26:
1523
+ return _context2.abrupt("return", new Trade({
1524
+ v2Routes: v2Routes,
1525
+ v3Routes: v3Routes,
1526
+ mixedRoutes: mixedRoutes,
1527
+ tradeType: tradeType
1528
+ }));
1529
+ case 27:
1530
+ case "end":
1531
+ return _context2.stop();
2191
1532
  }
2192
1533
  }, _callee2);
2193
1534
  }));
2194
-
2195
1535
  function fromRoute(_x5, _x6, _x7) {
2196
1536
  return _fromRoute.apply(this, arguments);
2197
1537
  }
2198
-
2199
1538
  return fromRoute;
2200
1539
  }();
2201
-
2202
1540
  _createClass(Trade, [{
2203
1541
  key: "inputAmount",
2204
1542
  get: function get() {
2205
1543
  if (this._inputAmount) {
2206
1544
  return this._inputAmount;
2207
1545
  }
2208
-
2209
1546
  var inputCurrency = this.swaps[0].inputAmount.currency;
2210
1547
  var totalInputFromRoutes = this.swaps.map(function (_ref5) {
2211
1548
  var inputAmount = _ref5.inputAmount;
@@ -2222,7 +1559,6 @@ var Trade = /*#__PURE__*/function () {
2222
1559
  if (this._outputAmount) {
2223
1560
  return this._outputAmount;
2224
1561
  }
2225
-
2226
1562
  var outputCurrency = this.swaps[0].outputAmount.currency;
2227
1563
  var totalOutputFromRoutes = this.swaps.map(function (_ref6) {
2228
1564
  var outputAmount = _ref6.outputAmount;
@@ -2236,18 +1572,15 @@ var Trade = /*#__PURE__*/function () {
2236
1572
  /**
2237
1573
  * The price expressed in terms of output amount/input amount.
2238
1574
  */
2239
-
2240
1575
  }, {
2241
1576
  key: "executionPrice",
2242
1577
  get: function get() {
2243
1578
  var _this$_executionPrice;
2244
-
2245
1579
  return (_this$_executionPrice = this._executionPrice) != null ? _this$_executionPrice : this._executionPrice = new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient);
2246
1580
  }
2247
1581
  /**
2248
1582
  * Returns the sell tax of the input token
2249
1583
  */
2250
-
2251
1584
  }, {
2252
1585
  key: "inputTax",
2253
1586
  get: function get() {
@@ -2258,7 +1591,6 @@ var Trade = /*#__PURE__*/function () {
2258
1591
  /**
2259
1592
  * Returns the buy tax of the output token
2260
1593
  */
2261
-
2262
1594
  }, {
2263
1595
  key: "outputTax",
2264
1596
  get: function get() {
@@ -2271,30 +1603,26 @@ var Trade = /*#__PURE__*/function () {
2271
1603
  * In order to exclude token taxes from the price impact calculation, the spot price is calculated
2272
1604
  * using a ratio of values that go into the pools, which are the post-tax input amount and pre-tax output amount.
2273
1605
  */
2274
-
2275
1606
  }, {
2276
1607
  key: "priceImpact",
2277
1608
  get: function get() {
2278
1609
  if (this._priceImpact) {
2279
1610
  return this._priceImpact;
2280
- } // returns 0% price impact even though this may be inaccurate as a swap may have occured.
1611
+ }
1612
+ // returns 0% price impact even though this may be inaccurate as a swap may have occured.
2281
1613
  // because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.
2282
-
2283
-
2284
1614
  if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
2285
1615
  var spotOutputAmount = sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
2286
-
2287
1616
  for (var _iterator9 = _createForOfIteratorHelperLoose(this.swaps), _step9; !(_step9 = _iterator9()).done;) {
2288
1617
  var _step9$value = _step9.value,
2289
- route = _step9$value.route,
2290
- inputAmount = _step9$value.inputAmount;
1618
+ route = _step9$value.route,
1619
+ inputAmount = _step9$value.inputAmount;
2291
1620
  var midPrice = route.midPrice;
2292
1621
  var postTaxInputAmount = inputAmount.multiply(new sdkCore.Fraction(ONE).subtract(this.inputTax));
2293
1622
  spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
2294
- } // if the total output of this trade is 0, then most likely the post-tax input was also 0, and therefore this swap
1623
+ }
1624
+ // if the total output of this trade is 0, then most likely the post-tax input was also 0, and therefore this swap
2295
1625
  // does not move the pools' market price
2296
-
2297
-
2298
1626
  if (spotOutputAmount.equalTo(ZERO)) return ZERO_PERCENT;
2299
1627
  var preTaxOutputAmount = this.outputAmount.divide(new sdkCore.Fraction(ONE).subtract(this.outputTax));
2300
1628
  var priceImpact = spotOutputAmount.subtract(preTaxOutputAmount).divide(spotOutputAmount);
@@ -2302,7 +1630,6 @@ var Trade = /*#__PURE__*/function () {
2302
1630
  return this._priceImpact;
2303
1631
  }
2304
1632
  }]);
2305
-
2306
1633
  return Trade;
2307
1634
  }();
2308
1635
 
@@ -2312,37 +1639,33 @@ var Trade = /*#__PURE__*/function () {
2312
1639
  * @param route the mixed path to convert to an encoded path
2313
1640
  * @returns the exactIn encoded path
2314
1641
  */
2315
-
2316
1642
  function encodeMixedRouteToPath(route) {
2317
1643
  var firstInputToken = route.input.wrapped;
2318
-
2319
1644
  var _route$pools$reduce = route.pools.reduce(function (_ref, pool, index) {
2320
- var inputToken = _ref.inputToken,
1645
+ var inputToken = _ref.inputToken,
2321
1646
  path = _ref.path,
2322
1647
  types = _ref.types;
2323
- var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
2324
-
2325
- if (index === 0) {
2326
- return {
2327
- inputToken: outputToken,
2328
- types: ['address', 'uint24', 'address'],
2329
- path: [inputToken.address, pool instanceof v3Sdk.Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address]
2330
- };
2331
- } else {
2332
- return {
2333
- inputToken: outputToken,
2334
- types: [].concat(types, ['uint24', 'address']),
2335
- path: [].concat(path, [pool instanceof v3Sdk.Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address])
2336
- };
2337
- }
2338
- }, {
2339
- inputToken: firstInputToken,
2340
- path: [],
2341
- types: []
2342
- }),
2343
- path = _route$pools$reduce.path,
2344
- types = _route$pools$reduce.types;
2345
-
1648
+ var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
1649
+ if (index === 0) {
1650
+ return {
1651
+ inputToken: outputToken,
1652
+ types: ['address', 'uint24', 'address'],
1653
+ path: [inputToken.address, pool instanceof v3Sdk.Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address]
1654
+ };
1655
+ } else {
1656
+ return {
1657
+ inputToken: outputToken,
1658
+ types: [].concat(types, ['uint24', 'address']),
1659
+ path: [].concat(path, [pool instanceof v3Sdk.Pool ? pool.fee : V2_FEE_PATH_PLACEHOLDER, outputToken.address])
1660
+ };
1661
+ }
1662
+ }, {
1663
+ inputToken: firstInputToken,
1664
+ path: [],
1665
+ types: []
1666
+ }),
1667
+ path = _route$pools$reduce.path,
1668
+ types = _route$pools$reduce.types;
2346
1669
  return solidity.pack(types, path);
2347
1670
  }
2348
1671
 
@@ -2351,27 +1674,22 @@ function encodeMixedRouteToPath(route) {
2351
1674
  * @param route
2352
1675
  * @returns a nested array of Pools or Pairs in the order of the route
2353
1676
  */
2354
-
2355
1677
  var partitionMixedRouteByProtocol = function partitionMixedRouteByProtocol(route) {
2356
1678
  var acc = [];
2357
1679
  var left = 0;
2358
1680
  var right = 0;
2359
-
2360
1681
  while (right < route.pools.length) {
2361
1682
  if (route.pools[left] instanceof v3Sdk.Pool && route.pools[right] instanceof v2Sdk.Pair || route.pools[left] instanceof v2Sdk.Pair && route.pools[right] instanceof v3Sdk.Pool) {
2362
1683
  acc.push(route.pools.slice(left, right));
2363
1684
  left = right;
2364
- } // seek forward with right pointer
2365
-
2366
-
1685
+ }
1686
+ // seek forward with right pointer
2367
1687
  right++;
2368
-
2369
1688
  if (right === route.pools.length) {
2370
1689
  /// we reached the end, take the rest
2371
1690
  acc.push(route.pools.slice(left, right));
2372
1691
  }
2373
1692
  }
2374
-
2375
1693
  return acc;
2376
1694
  };
2377
1695
  /**
@@ -2380,20 +1698,18 @@ var partitionMixedRouteByProtocol = function partitionMixedRouteByProtocol(route
2380
1698
  * @param firstInputToken
2381
1699
  * @returns the output token of the last pool in the array
2382
1700
  */
2383
-
2384
1701
  var getOutputOfPools = function getOutputOfPools(pools, firstInputToken) {
2385
1702
  var _pools$reduce = pools.reduce(function (_ref, pool) {
2386
- var inputToken = _ref.inputToken;
2387
- if (!pool.involvesToken(inputToken)) throw new Error('PATH');
2388
- var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
2389
- return {
2390
- inputToken: outputToken
2391
- };
2392
- }, {
2393
- inputToken: firstInputToken
2394
- }),
2395
- outputToken = _pools$reduce.inputToken;
2396
-
1703
+ var inputToken = _ref.inputToken;
1704
+ if (!pool.involvesToken(inputToken)) throw new Error('PATH');
1705
+ var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
1706
+ return {
1707
+ inputToken: outputToken
1708
+ };
1709
+ }, {
1710
+ inputToken: firstInputToken
1711
+ }),
1712
+ outputToken = _pools$reduce.inputToken;
2397
1713
  return outputToken;
2398
1714
  };
2399
1715
 
@@ -2402,7 +1718,6 @@ var REFUND_ETH_PRICE_IMPACT_THRESHOLD = /*#__PURE__*/new sdkCore.Percent( /*#__P
2402
1718
  /**
2403
1719
  * Represents the Uniswap V2 + V3 SwapRouter02, and has static methods for helping execute trades.
2404
1720
  */
2405
-
2406
1721
  var SwapRouter = /*#__PURE__*/function () {
2407
1722
  /**
2408
1723
  * Cannot be constructed.
@@ -2416,8 +1731,6 @@ var SwapRouter = /*#__PURE__*/function () {
2416
1731
  * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check
2417
1732
  * @returns A string array of calldatas for the trade.
2418
1733
  */
2419
-
2420
-
2421
1734
  SwapRouter.encodeV2Swap = function encodeV2Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck) {
2422
1735
  var amountIn = v3Sdk.toHex(trade.maximumAmountIn(options.slippageTolerance).quotient);
2423
1736
  var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance).quotient);
@@ -2425,7 +1738,6 @@ var SwapRouter = /*#__PURE__*/function () {
2425
1738
  return token.address;
2426
1739
  });
2427
1740
  var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : sdkCore.validateAndParseAddress(options.recipient);
2428
-
2429
1741
  if (trade.tradeType === sdkCore.TradeType.EXACT_INPUT) {
2430
1742
  var exactInputParams = [amountIn, performAggregatedSlippageCheck ? 0 : amountOut, path, recipient];
2431
1743
  return SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams);
@@ -2441,23 +1753,19 @@ var SwapRouter = /*#__PURE__*/function () {
2441
1753
  * @param routerMustCustody Flag for whether funds should be sent to the router
2442
1754
  * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check
2443
1755
  * @returns A string array of calldatas for the trade.
2444
- */
2445
- ;
2446
-
1756
+ */;
2447
1757
  SwapRouter.encodeV3Swap = function encodeV3Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck) {
2448
1758
  var calldatas = [];
2449
-
2450
1759
  for (var _iterator = _createForOfIteratorHelperLoose(trade.swaps), _step; !(_step = _iterator()).done;) {
2451
1760
  var _step$value = _step.value,
2452
- route = _step$value.route,
2453
- inputAmount = _step$value.inputAmount,
2454
- outputAmount = _step$value.outputAmount;
1761
+ route = _step$value.route,
1762
+ inputAmount = _step$value.inputAmount,
1763
+ outputAmount = _step$value.outputAmount;
2455
1764
  var amountIn = v3Sdk.toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
2456
- var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient); // flag for whether the trade is single hop or not
2457
-
1765
+ var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
1766
+ // flag for whether the trade is single hop or not
2458
1767
  var singleHop = route.pools.length === 1;
2459
1768
  var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : sdkCore.validateAndParseAddress(options.recipient);
2460
-
2461
1769
  if (singleHop) {
2462
1770
  if (trade.tradeType === sdkCore.TradeType.EXACT_INPUT) {
2463
1771
  var exactInputSingleParams = {
@@ -2484,7 +1792,6 @@ var SwapRouter = /*#__PURE__*/function () {
2484
1792
  }
2485
1793
  } else {
2486
1794
  var path = v3Sdk.encodeRouteToPath(route, trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT);
2487
-
2488
1795
  if (trade.tradeType === sdkCore.TradeType.EXACT_INPUT) {
2489
1796
  var exactInputParams = {
2490
1797
  path: path,
@@ -2504,7 +1811,6 @@ var SwapRouter = /*#__PURE__*/function () {
2504
1811
  }
2505
1812
  }
2506
1813
  }
2507
-
2508
1814
  return calldatas;
2509
1815
  }
2510
1816
  /**
@@ -2515,30 +1821,25 @@ var SwapRouter = /*#__PURE__*/function () {
2515
1821
  * @param routerMustCustody Flag for whether funds should be sent to the router
2516
1822
  * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check
2517
1823
  * @returns A string array of calldatas for the trade.
2518
- */
2519
- ;
2520
-
1824
+ */;
2521
1825
  SwapRouter.encodeMixedRouteSwap = function encodeMixedRouteSwap(trade, options, routerMustCustody, performAggregatedSlippageCheck) {
2522
1826
  var calldatas = [];
2523
1827
  !(trade.tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
2524
-
2525
- for (var _iterator2 = _createForOfIteratorHelperLoose(trade.swaps), _step2; !(_step2 = _iterator2()).done;) {
1828
+ var _loop = function _loop() {
2526
1829
  var _step2$value = _step2.value,
2527
- route = _step2$value.route,
2528
- inputAmount = _step2$value.inputAmount,
2529
- outputAmount = _step2$value.outputAmount;
1830
+ route = _step2$value.route,
1831
+ inputAmount = _step2$value.inputAmount,
1832
+ outputAmount = _step2$value.outputAmount;
2530
1833
  var amountIn = v3Sdk.toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
2531
- var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient); // flag for whether the trade is single hop or not
2532
-
1834
+ var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
1835
+ // flag for whether the trade is single hop or not
2533
1836
  var singleHop = route.pools.length === 1;
2534
1837
  var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : sdkCore.validateAndParseAddress(options.recipient);
2535
-
2536
1838
  var mixedRouteIsAllV3 = function mixedRouteIsAllV3(route) {
2537
1839
  return route.pools.every(function (pool) {
2538
1840
  return pool instanceof v3Sdk.Pool;
2539
1841
  });
2540
1842
  };
2541
-
2542
1843
  if (singleHop) {
2543
1844
  /// For single hop, since it isn't really a mixedRoute, we'll just mimic behavior of V3 or V2
2544
1845
  /// We don't use encodeV3Swap() or encodeV2Swap() because casting the trade to a V3Trade or V2Trade is overcomplex
@@ -2561,77 +1862,70 @@ var SwapRouter = /*#__PURE__*/function () {
2561
1862
  calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams));
2562
1863
  }
2563
1864
  } else {
2564
- (function () {
2565
- var sections = partitionMixedRouteByProtocol(route);
2566
-
2567
- var isLastSectionInRoute = function isLastSectionInRoute(i) {
2568
- return i === sections.length - 1;
2569
- };
2570
-
2571
- var outputToken = void 0;
2572
- var inputToken = route.input.wrapped;
2573
-
2574
- for (var i = 0; i < sections.length; i++) {
2575
- var section = sections[i]; /// Now, we get output of this section
2576
-
2577
- outputToken = getOutputOfPools(section, inputToken);
2578
- var newRouteOriginal = new MixedRouteSDK([].concat(section), section[0].token0.equals(inputToken) ? section[0].token0 : section[0].token1, outputToken);
2579
- var newRoute = new MixedRoute(newRouteOriginal); /// Previous output is now input
2580
-
2581
- inputToken = outputToken;
2582
-
2583
- if (mixedRouteIsAllV3(newRoute)) {
2584
- var _path = encodeMixedRouteToPath(newRoute);
2585
-
2586
- var _exactInputParams = {
2587
- path: _path,
2588
- // By default router holds funds until the last swap, then it is sent to the recipient
2589
- // special case exists where we are unwrapping WETH output, in which case `routerMustCustody` is set to true
2590
- // and router still holds the funds. That logic bundled into how the value of `recipient` is calculated
2591
- recipient: isLastSectionInRoute(i) ? recipient : ADDRESS_THIS,
2592
- amountIn: i == 0 ? amountIn : 0,
2593
- amountOutMinimum: !isLastSectionInRoute(i) ? 0 : amountOut
2594
- };
2595
- calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [_exactInputParams]));
2596
- } else {
2597
- var _exactInputParams2 = [i == 0 ? amountIn : 0, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (token) {
2598
- return token.address;
2599
- }), isLastSectionInRoute(i) ? recipient : ADDRESS_THIS];
2600
- calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', _exactInputParams2));
2601
- }
1865
+ var sections = partitionMixedRouteByProtocol(route);
1866
+ var isLastSectionInRoute = function isLastSectionInRoute(i) {
1867
+ return i === sections.length - 1;
1868
+ };
1869
+ var outputToken;
1870
+ var inputToken = route.input.wrapped;
1871
+ for (var i = 0; i < sections.length; i++) {
1872
+ var section = sections[i];
1873
+ /// Now, we get output of this section
1874
+ outputToken = getOutputOfPools(section, inputToken);
1875
+ var newRouteOriginal = new MixedRouteSDK([].concat(section), section[0].token0.equals(inputToken) ? section[0].token0 : section[0].token1, outputToken);
1876
+ var newRoute = new MixedRoute(newRouteOriginal);
1877
+ /// Previous output is now input
1878
+ inputToken = outputToken;
1879
+ if (mixedRouteIsAllV3(newRoute)) {
1880
+ var _path = encodeMixedRouteToPath(newRoute);
1881
+ var _exactInputParams = {
1882
+ path: _path,
1883
+ // By default router holds funds until the last swap, then it is sent to the recipient
1884
+ // special case exists where we are unwrapping WETH output, in which case `routerMustCustody` is set to true
1885
+ // and router still holds the funds. That logic bundled into how the value of `recipient` is calculated
1886
+ recipient: isLastSectionInRoute(i) ? recipient : ADDRESS_THIS,
1887
+ amountIn: i === 0 ? amountIn : 0,
1888
+ amountOutMinimum: !isLastSectionInRoute(i) ? 0 : amountOut
1889
+ };
1890
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [_exactInputParams]));
1891
+ } else {
1892
+ var _exactInputParams2 = [i === 0 ? amountIn : 0, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (token) {
1893
+ return token.address;
1894
+ }), isLastSectionInRoute(i) ? recipient : ADDRESS_THIS];
1895
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', _exactInputParams2));
2602
1896
  }
2603
- })();
1897
+ }
2604
1898
  }
1899
+ };
1900
+ for (var _iterator2 = _createForOfIteratorHelperLoose(trade.swaps), _step2; !(_step2 = _iterator2()).done;) {
1901
+ _loop();
2605
1902
  }
2606
-
2607
1903
  return calldatas;
2608
1904
  };
2609
-
2610
1905
  SwapRouter.encodeSwaps = function encodeSwaps(trades, options, isSwapAndAdd) {
2611
1906
  // If dealing with an instance of the aggregated Trade object, unbundle it to individual trade objects.
2612
1907
  if (trades instanceof Trade) {
2613
1908
  !trades.swaps.every(function (swap) {
2614
- return swap.route.protocol == exports.Protocol.V3 || swap.route.protocol == exports.Protocol.V2 || swap.route.protocol == exports.Protocol.MIXED;
1909
+ return swap.route.protocol === exports.Protocol.V3 || swap.route.protocol === exports.Protocol.V2 || swap.route.protocol === exports.Protocol.MIXED;
2615
1910
  }) ? invariant(false, 'UNSUPPORTED_PROTOCOL') : void 0;
2616
1911
  var individualTrades = [];
2617
-
2618
1912
  for (var _iterator3 = _createForOfIteratorHelperLoose(trades.swaps), _step3; !(_step3 = _iterator3()).done;) {
2619
1913
  var _step3$value = _step3.value,
2620
- route = _step3$value.route,
2621
- inputAmount = _step3$value.inputAmount,
2622
- outputAmount = _step3$value.outputAmount;
2623
-
2624
- if (route.protocol == exports.Protocol.V2) {
2625
- individualTrades.push(new v2Sdk.Trade(route, trades.tradeType == sdkCore.TradeType.EXACT_INPUT ? inputAmount : outputAmount, trades.tradeType));
2626
- } else if (route.protocol == exports.Protocol.V3) {
1914
+ route = _step3$value.route,
1915
+ inputAmount = _step3$value.inputAmount,
1916
+ outputAmount = _step3$value.outputAmount;
1917
+ if (route.protocol === exports.Protocol.V2) {
1918
+ individualTrades.push(new v2Sdk.Trade(route, trades.tradeType === sdkCore.TradeType.EXACT_INPUT ? inputAmount : outputAmount, trades.tradeType));
1919
+ } else if (route.protocol === exports.Protocol.V3) {
2627
1920
  individualTrades.push(v3Sdk.Trade.createUncheckedTrade({
2628
1921
  route: route,
2629
1922
  inputAmount: inputAmount,
2630
1923
  outputAmount: outputAmount,
2631
1924
  tradeType: trades.tradeType
2632
1925
  }));
2633
- } else if (route.protocol == exports.Protocol.MIXED) {
2634
- individualTrades.push( /// we can change the naming of this function on MixedRouteTrade if needed
1926
+ } else if (route.protocol === exports.Protocol.MIXED) {
1927
+ individualTrades.push(
1928
+ /// we can change the naming of this function on MixedRouteTrade if needed
2635
1929
  MixedRouteTrade.createUncheckedTrade({
2636
1930
  route: route,
2637
1931
  inputAmount: inputAmount,
@@ -2642,19 +1936,16 @@ var SwapRouter = /*#__PURE__*/function () {
2642
1936
  throw new Error('UNSUPPORTED_TRADE_PROTOCOL');
2643
1937
  }
2644
1938
  }
2645
-
2646
1939
  trades = individualTrades;
2647
1940
  }
2648
-
2649
1941
  if (!Array.isArray(trades)) {
2650
1942
  trades = [trades];
2651
1943
  }
2652
-
2653
1944
  var numberOfTrades = trades.reduce(function (numberOfTrades, trade) {
2654
1945
  return numberOfTrades + (trade instanceof v3Sdk.Trade || trade instanceof MixedRouteTrade ? trade.swaps.length : 1);
2655
1946
  }, 0);
2656
- var sampleTrade = trades[0]; // All trades should have the same starting/ending currency and trade type
2657
-
1947
+ var sampleTrade = trades[0];
1948
+ // All trades should have the same starting/ending currency and trade type
2658
1949
  !trades.every(function (trade) {
2659
1950
  return trade.inputAmount.currency.equals(sampleTrade.inputAmount.currency);
2660
1951
  }) ? invariant(false, 'TOKEN_IN_DIFF') : void 0;
@@ -2666,27 +1957,25 @@ var SwapRouter = /*#__PURE__*/function () {
2666
1957
  }) ? invariant(false, 'TRADE_TYPE_DIFF') : void 0;
2667
1958
  var calldatas = [];
2668
1959
  var inputIsNative = sampleTrade.inputAmount.currency.isNative;
2669
- var outputIsNative = sampleTrade.outputAmount.currency.isNative; // flag for whether we want to perform an aggregated slippage check
1960
+ var outputIsNative = sampleTrade.outputAmount.currency.isNative;
1961
+ // flag for whether we want to perform an aggregated slippage check
2670
1962
  // 1. when there are >2 exact input trades. this is only a heuristic,
2671
1963
  // as it's still more gas-expensive even in this case, but has benefits
2672
1964
  // in that the reversion probability is lower
2673
-
2674
- var performAggregatedSlippageCheck = sampleTrade.tradeType === sdkCore.TradeType.EXACT_INPUT && numberOfTrades > 2; // flag for whether funds should be send first to the router
1965
+ var performAggregatedSlippageCheck = sampleTrade.tradeType === sdkCore.TradeType.EXACT_INPUT && numberOfTrades > 2;
1966
+ // flag for whether funds should be send first to the router
2675
1967
  // 1. when receiving ETH (which much be unwrapped from WETH)
2676
1968
  // 2. when a fee on the output is being taken
2677
1969
  // 3. when performing swap and add
2678
1970
  // 4. when performing an aggregated slippage check
2679
-
2680
- var routerMustCustody = outputIsNative || !!options.fee || !!isSwapAndAdd || performAggregatedSlippageCheck; // encode permit if necessary
2681
-
1971
+ var routerMustCustody = outputIsNative || !!options.fee || !!isSwapAndAdd || performAggregatedSlippageCheck;
1972
+ // encode permit if necessary
2682
1973
  if (options.inputTokenPermit) {
2683
1974
  !sampleTrade.inputAmount.currency.isToken ? invariant(false, 'NON_TOKEN_PERMIT') : void 0;
2684
1975
  calldatas.push(v3Sdk.SelfPermit.encodePermit(sampleTrade.inputAmount.currency, options.inputTokenPermit));
2685
1976
  }
2686
-
2687
1977
  for (var _iterator4 = _createForOfIteratorHelperLoose(trades), _step4; !(_step4 = _iterator4()).done;) {
2688
1978
  var trade = _step4.value;
2689
-
2690
1979
  if (trade instanceof v2Sdk.Trade) {
2691
1980
  calldatas.push(SwapRouter.encodeV2Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck));
2692
1981
  } else if (trade instanceof v3Sdk.Trade) {
@@ -2703,7 +1992,6 @@ var SwapRouter = /*#__PURE__*/function () {
2703
1992
  throw new Error('Unsupported trade object');
2704
1993
  }
2705
1994
  }
2706
-
2707
1995
  var ZERO_IN = sdkCore.CurrencyAmount.fromRawAmount(sampleTrade.inputAmount.currency, 0);
2708
1996
  var ZERO_OUT = sdkCore.CurrencyAmount.fromRawAmount(sampleTrade.outputAmount.currency, 0);
2709
1997
  var minimumAmountOut = trades.reduce(function (sum, trade) {
@@ -2730,34 +2018,29 @@ var SwapRouter = /*#__PURE__*/function () {
2730
2018
  * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
2731
2019
  * @param trades to produce call parameters for
2732
2020
  * @param options options for the call parameters
2733
- */
2734
- ;
2735
-
2021
+ */;
2736
2022
  SwapRouter.swapCallParameters = function swapCallParameters(trades, options) {
2737
2023
  var _SwapRouter$encodeSwa = SwapRouter.encodeSwaps(trades, options),
2738
- calldatas = _SwapRouter$encodeSwa.calldatas,
2739
- sampleTrade = _SwapRouter$encodeSwa.sampleTrade,
2740
- routerMustCustody = _SwapRouter$encodeSwa.routerMustCustody,
2741
- inputIsNative = _SwapRouter$encodeSwa.inputIsNative,
2742
- outputIsNative = _SwapRouter$encodeSwa.outputIsNative,
2743
- totalAmountIn = _SwapRouter$encodeSwa.totalAmountIn,
2744
- minimumAmountOut = _SwapRouter$encodeSwa.minimumAmountOut; // unwrap or sweep
2745
-
2746
-
2024
+ calldatas = _SwapRouter$encodeSwa.calldatas,
2025
+ sampleTrade = _SwapRouter$encodeSwa.sampleTrade,
2026
+ routerMustCustody = _SwapRouter$encodeSwa.routerMustCustody,
2027
+ inputIsNative = _SwapRouter$encodeSwa.inputIsNative,
2028
+ outputIsNative = _SwapRouter$encodeSwa.outputIsNative,
2029
+ totalAmountIn = _SwapRouter$encodeSwa.totalAmountIn,
2030
+ minimumAmountOut = _SwapRouter$encodeSwa.minimumAmountOut;
2031
+ // unwrap or sweep
2747
2032
  if (routerMustCustody) {
2748
2033
  if (outputIsNative) {
2749
2034
  calldatas.push(PaymentsExtended.encodeUnwrapWETH9(minimumAmountOut.quotient, options.recipient, options.fee));
2750
2035
  } else {
2751
2036
  calldatas.push(PaymentsExtended.encodeSweepToken(sampleTrade.outputAmount.currency.wrapped, minimumAmountOut.quotient, options.recipient, options.fee));
2752
2037
  }
2753
- } // must refund when paying in ETH: either with an uncertain input amount OR if there's a chance of a partial fill.
2038
+ }
2039
+ // must refund when paying in ETH: either with an uncertain input amount OR if there's a chance of a partial fill.
2754
2040
  // unlike ERC20's, the full ETH value must be sent in the transaction, so the rest must be refunded.
2755
-
2756
-
2757
2041
  if (inputIsNative && (sampleTrade.tradeType === sdkCore.TradeType.EXACT_OUTPUT || SwapRouter.riskOfPartialFill(trades))) {
2758
2042
  calldatas.push(v3Sdk.Payments.encodeRefundETH());
2759
2043
  }
2760
-
2761
2044
  return {
2762
2045
  calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),
2763
2046
  value: v3Sdk.toHex(inputIsNative ? totalAmountIn.quotient : ZERO$1)
@@ -2767,51 +2050,43 @@ var SwapRouter = /*#__PURE__*/function () {
2767
2050
  * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
2768
2051
  * @param trades to produce call parameters for
2769
2052
  * @param options options for the call parameters
2770
- */
2771
- ;
2772
-
2053
+ */;
2773
2054
  SwapRouter.swapAndAddCallParameters = function swapAndAddCallParameters(trades, options, position, addLiquidityOptions, tokenInApprovalType, tokenOutApprovalType) {
2774
2055
  var _SwapRouter$encodeSwa2 = SwapRouter.encodeSwaps(trades, options, true),
2775
- calldatas = _SwapRouter$encodeSwa2.calldatas,
2776
- inputIsNative = _SwapRouter$encodeSwa2.inputIsNative,
2777
- outputIsNative = _SwapRouter$encodeSwa2.outputIsNative,
2778
- sampleTrade = _SwapRouter$encodeSwa2.sampleTrade,
2779
- totalAmountSwapped = _SwapRouter$encodeSwa2.totalAmountIn,
2780
- quoteAmountOut = _SwapRouter$encodeSwa2.quoteAmountOut,
2781
- minimumAmountOut = _SwapRouter$encodeSwa2.minimumAmountOut; // encode output token permit if necessary
2782
-
2783
-
2056
+ calldatas = _SwapRouter$encodeSwa2.calldatas,
2057
+ inputIsNative = _SwapRouter$encodeSwa2.inputIsNative,
2058
+ outputIsNative = _SwapRouter$encodeSwa2.outputIsNative,
2059
+ sampleTrade = _SwapRouter$encodeSwa2.sampleTrade,
2060
+ totalAmountSwapped = _SwapRouter$encodeSwa2.totalAmountIn,
2061
+ quoteAmountOut = _SwapRouter$encodeSwa2.quoteAmountOut,
2062
+ minimumAmountOut = _SwapRouter$encodeSwa2.minimumAmountOut;
2063
+ // encode output token permit if necessary
2784
2064
  if (options.outputTokenPermit) {
2785
2065
  !quoteAmountOut.currency.isToken ? invariant(false, 'NON_TOKEN_PERMIT_OUTPUT') : void 0;
2786
2066
  calldatas.push(v3Sdk.SelfPermit.encodePermit(quoteAmountOut.currency, options.outputTokenPermit));
2787
2067
  }
2788
-
2789
2068
  var chainId = sampleTrade.route.chainId;
2790
2069
  var zeroForOne = position.pool.token0.wrapped.address === totalAmountSwapped.currency.wrapped.address;
2791
-
2792
2070
  var _SwapRouter$getPositi = SwapRouter.getPositionAmounts(position, zeroForOne),
2793
- positionAmountIn = _SwapRouter$getPositi.positionAmountIn,
2794
- positionAmountOut = _SwapRouter$getPositi.positionAmountOut; // if tokens are native they will be converted to WETH9
2795
-
2796
-
2071
+ positionAmountIn = _SwapRouter$getPositi.positionAmountIn,
2072
+ positionAmountOut = _SwapRouter$getPositi.positionAmountOut;
2073
+ // if tokens are native they will be converted to WETH9
2797
2074
  var tokenIn = inputIsNative ? sdkCore.WETH9[chainId] : positionAmountIn.currency.wrapped;
2798
- var tokenOut = outputIsNative ? sdkCore.WETH9[chainId] : positionAmountOut.currency.wrapped; // if swap output does not make up whole outputTokenBalanceDesired, pull in remaining tokens for adding liquidity
2799
-
2075
+ var tokenOut = outputIsNative ? sdkCore.WETH9[chainId] : positionAmountOut.currency.wrapped;
2076
+ // if swap output does not make up whole outputTokenBalanceDesired, pull in remaining tokens for adding liquidity
2800
2077
  var amountOutRemaining = positionAmountOut.subtract(quoteAmountOut.wrapped);
2801
-
2802
2078
  if (amountOutRemaining.greaterThan(sdkCore.CurrencyAmount.fromRawAmount(positionAmountOut.currency, 0))) {
2803
2079
  // if output is native, this means the remaining portion is included as native value in the transaction
2804
2080
  // and must be wrapped. Otherwise, pull in remaining ERC20 token.
2805
2081
  outputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(amountOutRemaining.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenOut, amountOutRemaining.quotient));
2806
- } // if input is native, convert to WETH9, else pull ERC20 token
2807
-
2808
-
2809
- inputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(positionAmountIn.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenIn, positionAmountIn.quotient)); // approve token balances to NFTManager
2810
-
2082
+ }
2083
+ // if input is native, convert to WETH9, else pull ERC20 token
2084
+ inputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(positionAmountIn.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenIn, positionAmountIn.quotient));
2085
+ // approve token balances to NFTManager
2811
2086
  if (tokenInApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenIn, tokenInApprovalType));
2812
- if (tokenOutApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType)); // represents a position with token amounts resulting from a swap with maximum slippage
2087
+ if (tokenOutApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType));
2088
+ // represents a position with token amounts resulting from a swap with maximum slippage
2813
2089
  // hence the minimal amount out possible.
2814
-
2815
2090
  var minimalPosition = v3Sdk.Position.fromAmounts({
2816
2091
  pool: position.pool,
2817
2092
  tickLower: position.tickLower,
@@ -2819,14 +2094,13 @@ var SwapRouter = /*#__PURE__*/function () {
2819
2094
  amount0: zeroForOne ? position.amount0.quotient.toString() : minimumAmountOut.quotient.toString(),
2820
2095
  amount1: zeroForOne ? minimumAmountOut.quotient.toString() : position.amount1.quotient.toString(),
2821
2096
  useFullPrecision: false
2822
- }); // encode NFTManager add liquidity
2823
-
2824
- calldatas.push(ApproveAndCall.encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, options.slippageTolerance)); // sweep remaining tokens
2825
-
2097
+ });
2098
+ // encode NFTManager add liquidity
2099
+ calldatas.push(ApproveAndCall.encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, options.slippageTolerance));
2100
+ // sweep remaining tokens
2826
2101
  inputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenIn, ZERO$1));
2827
2102
  outputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenOut, ZERO$1));
2828
2103
  var value;
2829
-
2830
2104
  if (inputIsNative) {
2831
2105
  value = totalAmountSwapped.wrapped.add(positionAmountIn.wrapped).quotient;
2832
2106
  } else if (outputIsNative) {
@@ -2834,14 +2108,13 @@ var SwapRouter = /*#__PURE__*/function () {
2834
2108
  } else {
2835
2109
  value = ZERO$1;
2836
2110
  }
2837
-
2838
2111
  return {
2839
2112
  calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),
2840
2113
  value: value.toString()
2841
2114
  };
2842
- } // if price impact is very high, there's a chance of hitting max/min prices resulting in a partial fill of the swap
2115
+ }
2116
+ // if price impact is very high, there's a chance of hitting max/min prices resulting in a partial fill of the swap
2843
2117
  ;
2844
-
2845
2118
  SwapRouter.riskOfPartialFill = function riskOfPartialFill(trades) {
2846
2119
  if (Array.isArray(trades)) {
2847
2120
  return trades.some(function (trade) {
@@ -2851,28 +2124,23 @@ var SwapRouter = /*#__PURE__*/function () {
2851
2124
  return SwapRouter.v3TradeWithHighPriceImpact(trades);
2852
2125
  }
2853
2126
  };
2854
-
2855
2127
  SwapRouter.v3TradeWithHighPriceImpact = function v3TradeWithHighPriceImpact(trade) {
2856
2128
  return !(trade instanceof v2Sdk.Trade) && trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
2857
2129
  };
2858
-
2859
2130
  SwapRouter.getPositionAmounts = function getPositionAmounts(position, zeroForOne) {
2860
2131
  var _position$mintAmounts = position.mintAmounts,
2861
- amount0 = _position$mintAmounts.amount0,
2862
- amount1 = _position$mintAmounts.amount1;
2132
+ amount0 = _position$mintAmounts.amount0,
2133
+ amount1 = _position$mintAmounts.amount1;
2863
2134
  var currencyAmount0 = sdkCore.CurrencyAmount.fromRawAmount(position.pool.token0, amount0);
2864
2135
  var currencyAmount1 = sdkCore.CurrencyAmount.fromRawAmount(position.pool.token1, amount1);
2865
-
2866
2136
  var _ref = zeroForOne ? [currencyAmount0, currencyAmount1] : [currencyAmount1, currencyAmount0],
2867
- positionAmountIn = _ref[0],
2868
- positionAmountOut = _ref[1];
2869
-
2137
+ positionAmountIn = _ref[0],
2138
+ positionAmountOut = _ref[1];
2870
2139
  return {
2871
2140
  positionAmountIn: positionAmountIn,
2872
2141
  positionAmountOut: positionAmountOut
2873
2142
  };
2874
2143
  };
2875
-
2876
2144
  return SwapRouter;
2877
2145
  }();
2878
2146
  SwapRouter.INTERFACE = /*#__PURE__*/new abi.Interface(ISwapRouter02_json.abi);