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