@juiceswapxyz/router-sdk 3.0.0 → 3.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2250 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
6
+
7
+ var sdkCore = require('@juiceswapxyz/sdk-core');
8
+ var JSBI = _interopDefault(require('jsbi'));
9
+ var abi = require('@ethersproject/abi');
10
+ var invariant = _interopDefault(require('tiny-invariant'));
11
+ var IApproveAndCall = _interopDefault(require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json'));
12
+ var v3Sdk = require('@juiceswapxyz/v3-sdk');
13
+ var IMulticallExtended = _interopDefault(require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json'));
14
+ var IPeripheryPaymentsWithFeeExtended = _interopDefault(require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json'));
15
+ var ISwapRouter02 = _interopDefault(require('@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json'));
16
+ var v2Sdk = require('@juiceswapxyz/v2-sdk');
17
+ var v4Sdk = require('@juiceswapxyz/v4-sdk');
18
+ var solidity = require('@ethersproject/solidity');
19
+
20
+ var ADDRESS_ZERO = '0x0000000000000000000000000000000000000000';
21
+ var MSG_SENDER = '0x0000000000000000000000000000000000000001';
22
+ var ADDRESS_THIS = '0x0000000000000000000000000000000000000002';
23
+ var ZERO = /*#__PURE__*/JSBI.BigInt(0);
24
+ var ONE = /*#__PURE__*/JSBI.BigInt(1);
25
+ // = 1 << 23 or 0b0100000000000000000000000
26
+ var MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER = 1 << 23;
27
+ // = 10 << 4 or 0b00100000
28
+ var MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER = 2 << 4;
29
+ // = 11 << 20 or 0b001100000000000000000000
30
+ var MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER = 3 << 20;
31
+ // = 100 << 20 or 0b010000000000000000000000
32
+ var MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER = 4 << 20;
33
+ var ZERO_PERCENT = /*#__PURE__*/new sdkCore.Percent(ZERO);
34
+ var ONE_HUNDRED_PERCENT = /*#__PURE__*/new sdkCore.Percent(100, 100);
35
+
36
+ (function (ApprovalTypes) {
37
+ ApprovalTypes[ApprovalTypes["NOT_REQUIRED"] = 0] = "NOT_REQUIRED";
38
+ ApprovalTypes[ApprovalTypes["MAX"] = 1] = "MAX";
39
+ ApprovalTypes[ApprovalTypes["MAX_MINUS_ONE"] = 2] = "MAX_MINUS_ONE";
40
+ ApprovalTypes[ApprovalTypes["ZERO_THEN_MAX"] = 3] = "ZERO_THEN_MAX";
41
+ ApprovalTypes[ApprovalTypes["ZERO_THEN_MAX_MINUS_ONE"] = 4] = "ZERO_THEN_MAX_MINUS_ONE";
42
+ })(exports.ApprovalTypes || (exports.ApprovalTypes = {}));
43
+ // type guard
44
+ function isMint(options) {
45
+ return Object.keys(options).some(function (k) {
46
+ return k === 'recipient';
47
+ });
48
+ }
49
+ var ApproveAndCall = /*#__PURE__*/function () {
50
+ /**
51
+ * Cannot be constructed.
52
+ */
53
+ function ApproveAndCall() {}
54
+ ApproveAndCall.encodeApproveMax = function encodeApproveMax(token) {
55
+ return ApproveAndCall.INTERFACE.encodeFunctionData('approveMax', [token.address]);
56
+ };
57
+ ApproveAndCall.encodeApproveMaxMinusOne = function encodeApproveMaxMinusOne(token) {
58
+ return ApproveAndCall.INTERFACE.encodeFunctionData('approveMaxMinusOne', [token.address]);
59
+ };
60
+ ApproveAndCall.encodeApproveZeroThenMax = function encodeApproveZeroThenMax(token) {
61
+ return ApproveAndCall.INTERFACE.encodeFunctionData('approveZeroThenMax', [token.address]);
62
+ };
63
+ ApproveAndCall.encodeApproveZeroThenMaxMinusOne = function encodeApproveZeroThenMaxMinusOne(token) {
64
+ return ApproveAndCall.INTERFACE.encodeFunctionData('approveZeroThenMaxMinusOne', [token.address]);
65
+ };
66
+ ApproveAndCall.encodeCallPositionManager = function encodeCallPositionManager(calldatas) {
67
+ !(calldatas.length > 0) ? invariant(false, 'NULL_CALLDATA') : void 0;
68
+ if (calldatas.length === 1) {
69
+ return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', calldatas);
70
+ } else {
71
+ var encodedMulticall = v3Sdk.NonfungiblePositionManager.INTERFACE.encodeFunctionData('multicall', [calldatas]);
72
+ return ApproveAndCall.INTERFACE.encodeFunctionData('callPositionManager', [encodedMulticall]);
73
+ }
74
+ }
75
+ /**
76
+ * Encode adding liquidity to a position in the nft manager contract
77
+ * @param position Forcasted position with expected amount out from swap
78
+ * @param minimalPosition Forcasted position with custom minimal token amounts
79
+ * @param addLiquidityOptions Options for adding liquidity
80
+ * @param slippageTolerance Defines maximum slippage
81
+ */;
82
+ ApproveAndCall.encodeAddLiquidity = function encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, slippageTolerance) {
83
+ var _position$mintAmounts = position.mintAmountsWithSlippage(slippageTolerance),
84
+ amount0Min = _position$mintAmounts.amount0,
85
+ amount1Min = _position$mintAmounts.amount1;
86
+ // position.mintAmountsWithSlippage() can create amounts not dependenable in scenarios
87
+ // such as range orders. Allow the option to provide a position with custom minimum amounts
88
+ // for these scenarios
89
+ if (JSBI.lessThan(minimalPosition.amount0.quotient, amount0Min)) {
90
+ amount0Min = minimalPosition.amount0.quotient;
91
+ }
92
+ if (JSBI.lessThan(minimalPosition.amount1.quotient, amount1Min)) {
93
+ amount1Min = minimalPosition.amount1.quotient;
94
+ }
95
+ if (isMint(addLiquidityOptions)) {
96
+ return ApproveAndCall.INTERFACE.encodeFunctionData('mint', [{
97
+ token0: position.pool.token0.address,
98
+ token1: position.pool.token1.address,
99
+ fee: position.pool.fee,
100
+ tickLower: position.tickLower,
101
+ tickUpper: position.tickUpper,
102
+ amount0Min: v3Sdk.toHex(amount0Min),
103
+ amount1Min: v3Sdk.toHex(amount1Min),
104
+ recipient: addLiquidityOptions.recipient
105
+ }]);
106
+ } else {
107
+ return ApproveAndCall.INTERFACE.encodeFunctionData('increaseLiquidity', [{
108
+ token0: position.pool.token0.address,
109
+ token1: position.pool.token1.address,
110
+ amount0Min: v3Sdk.toHex(amount0Min),
111
+ amount1Min: v3Sdk.toHex(amount1Min),
112
+ tokenId: v3Sdk.toHex(addLiquidityOptions.tokenId)
113
+ }]);
114
+ }
115
+ };
116
+ ApproveAndCall.encodeApprove = function encodeApprove(token, approvalType) {
117
+ switch (approvalType) {
118
+ case exports.ApprovalTypes.MAX:
119
+ return ApproveAndCall.encodeApproveMax(token.wrapped);
120
+ case exports.ApprovalTypes.MAX_MINUS_ONE:
121
+ return ApproveAndCall.encodeApproveMaxMinusOne(token.wrapped);
122
+ case exports.ApprovalTypes.ZERO_THEN_MAX:
123
+ return ApproveAndCall.encodeApproveZeroThenMax(token.wrapped);
124
+ case exports.ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE:
125
+ return ApproveAndCall.encodeApproveZeroThenMaxMinusOne(token.wrapped);
126
+ default:
127
+ throw new Error('Error: invalid ApprovalType');
128
+ }
129
+ };
130
+ return ApproveAndCall;
131
+ }();
132
+ ApproveAndCall.INTERFACE = /*#__PURE__*/new abi.Interface(IApproveAndCall.abi);
133
+
134
+ function validateAndParseBytes32(bytes32) {
135
+ if (!bytes32.match(/^0x[0-9a-fA-F]{64}$/)) {
136
+ throw new Error(bytes32 + " is not valid bytes32.");
137
+ }
138
+ return bytes32.toLowerCase();
139
+ }
140
+ var MulticallExtended = /*#__PURE__*/function () {
141
+ /**
142
+ * Cannot be constructed.
143
+ */
144
+ function MulticallExtended() {}
145
+ MulticallExtended.encodeMulticall = function encodeMulticall(calldatas, validation) {
146
+ // if there's no validation, we can just fall back to regular multicall
147
+ if (typeof validation === 'undefined') {
148
+ return v3Sdk.Multicall.encodeMulticall(calldatas);
149
+ }
150
+ // if there is validation, we have to normalize calldatas
151
+ if (!Array.isArray(calldatas)) {
152
+ calldatas = [calldatas];
153
+ }
154
+ // this means the validation value should be a previousBlockhash
155
+ if (typeof validation === 'string' && validation.startsWith('0x')) {
156
+ var previousBlockhash = validateAndParseBytes32(validation);
157
+ return MulticallExtended.INTERFACE.encodeFunctionData('multicall(bytes32,bytes[])', [previousBlockhash, calldatas]);
158
+ } else {
159
+ var deadline = v3Sdk.toHex(validation);
160
+ return MulticallExtended.INTERFACE.encodeFunctionData('multicall(uint256,bytes[])', [deadline, calldatas]);
161
+ }
162
+ };
163
+ return MulticallExtended;
164
+ }();
165
+ MulticallExtended.INTERFACE = /*#__PURE__*/new abi.Interface(IMulticallExtended.abi);
166
+
167
+ function encodeFeeBips(fee) {
168
+ return v3Sdk.toHex(fee.multiply(10000).quotient);
169
+ }
170
+ var PaymentsExtended = /*#__PURE__*/function () {
171
+ /**
172
+ * Cannot be constructed.
173
+ */
174
+ function PaymentsExtended() {}
175
+ PaymentsExtended.encodeUnwrapWETH9 = function encodeUnwrapWETH9(amountMinimum, recipient, feeOptions) {
176
+ // if there's a recipient, just pass it along
177
+ if (typeof recipient === 'string') {
178
+ return v3Sdk.Payments.encodeUnwrapWETH9(amountMinimum, recipient, feeOptions);
179
+ }
180
+ if (!!feeOptions) {
181
+ var feeBips = encodeFeeBips(feeOptions.fee);
182
+ var feeRecipient = sdkCore.validateAndParseAddress(feeOptions.recipient);
183
+ return PaymentsExtended.INTERFACE.encodeFunctionData('unwrapWETH9WithFee(uint256,uint256,address)', [v3Sdk.toHex(amountMinimum), feeBips, feeRecipient]);
184
+ } else {
185
+ return PaymentsExtended.INTERFACE.encodeFunctionData('unwrapWETH9(uint256)', [v3Sdk.toHex(amountMinimum)]);
186
+ }
187
+ };
188
+ PaymentsExtended.encodeSweepToken = function encodeSweepToken(token, amountMinimum, recipient, feeOptions) {
189
+ // if there's a recipient, just pass it along
190
+ if (typeof recipient === 'string') {
191
+ return v3Sdk.Payments.encodeSweepToken(token, amountMinimum, recipient, feeOptions);
192
+ }
193
+ if (!!feeOptions) {
194
+ var feeBips = encodeFeeBips(feeOptions.fee);
195
+ var feeRecipient = sdkCore.validateAndParseAddress(feeOptions.recipient);
196
+ return PaymentsExtended.INTERFACE.encodeFunctionData('sweepTokenWithFee(address,uint256,uint256,address)', [token.address, v3Sdk.toHex(amountMinimum), feeBips, feeRecipient]);
197
+ } else {
198
+ return PaymentsExtended.INTERFACE.encodeFunctionData('sweepToken(address,uint256)', [token.address, v3Sdk.toHex(amountMinimum)]);
199
+ }
200
+ };
201
+ PaymentsExtended.encodePull = function encodePull(token, amount) {
202
+ return PaymentsExtended.INTERFACE.encodeFunctionData('pull', [token.address, v3Sdk.toHex(amount)]);
203
+ };
204
+ PaymentsExtended.encodeWrapETH = function encodeWrapETH(amount) {
205
+ return PaymentsExtended.INTERFACE.encodeFunctionData('wrapETH', [v3Sdk.toHex(amount)]);
206
+ };
207
+ return PaymentsExtended;
208
+ }();
209
+ PaymentsExtended.INTERFACE = /*#__PURE__*/new abi.Interface(IPeripheryPaymentsWithFeeExtended.abi);
210
+
211
+ function _arrayLikeToArray(r, a) {
212
+ (null == a || a > r.length) && (a = r.length);
213
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
214
+ return n;
215
+ }
216
+ function asyncGeneratorStep(n, t, e, r, o, a, c) {
217
+ try {
218
+ var i = n[a](c),
219
+ u = i.value;
220
+ } catch (n) {
221
+ return void e(n);
222
+ }
223
+ i.done ? t(u) : Promise.resolve(u).then(r, o);
224
+ }
225
+ function _asyncToGenerator(n) {
226
+ return function () {
227
+ var t = this,
228
+ e = arguments;
229
+ return new Promise(function (r, o) {
230
+ var a = n.apply(t, e);
231
+ function _next(n) {
232
+ asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
233
+ }
234
+ function _throw(n) {
235
+ asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
236
+ }
237
+ _next(void 0);
238
+ });
239
+ };
240
+ }
241
+ function _defineProperties(e, r) {
242
+ for (var t = 0; t < r.length; t++) {
243
+ var o = r[t];
244
+ o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
245
+ }
246
+ }
247
+ function _createClass(e, r, t) {
248
+ return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
249
+ writable: !1
250
+ }), e;
251
+ }
252
+ function _createForOfIteratorHelperLoose(r, e) {
253
+ var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
254
+ if (t) return (t = t.call(r)).next.bind(t);
255
+ if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) {
256
+ t && (r = t);
257
+ var o = 0;
258
+ return function () {
259
+ return o >= r.length ? {
260
+ done: !0
261
+ } : {
262
+ done: !1,
263
+ value: r[o++]
264
+ };
265
+ };
266
+ }
267
+ throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
268
+ }
269
+ function _extends() {
270
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
271
+ for (var e = 1; e < arguments.length; e++) {
272
+ var t = arguments[e];
273
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
274
+ }
275
+ return n;
276
+ }, _extends.apply(null, arguments);
277
+ }
278
+ function _inheritsLoose(t, o) {
279
+ t.prototype = Object.create(o.prototype), t.prototype.constructor = t, _setPrototypeOf(t, o);
280
+ }
281
+ function _regenerator() {
282
+ /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */
283
+ var e,
284
+ t,
285
+ r = "function" == typeof Symbol ? Symbol : {},
286
+ n = r.iterator || "@@iterator",
287
+ o = r.toStringTag || "@@toStringTag";
288
+ function i(r, n, o, i) {
289
+ var c = n && n.prototype instanceof Generator ? n : Generator,
290
+ u = Object.create(c.prototype);
291
+ return _regeneratorDefine(u, "_invoke", function (r, n, o) {
292
+ var i,
293
+ c,
294
+ u,
295
+ f = 0,
296
+ p = o || [],
297
+ y = !1,
298
+ G = {
299
+ p: 0,
300
+ n: 0,
301
+ v: e,
302
+ a: d,
303
+ f: d.bind(e, 4),
304
+ d: function (t, r) {
305
+ return i = t, c = 0, u = e, G.n = r, a;
306
+ }
307
+ };
308
+ function d(r, n) {
309
+ for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) {
310
+ var o,
311
+ i = p[t],
312
+ d = G.p,
313
+ l = i[2];
314
+ r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0));
315
+ }
316
+ if (o || r > 1) return a;
317
+ throw y = !0, n;
318
+ }
319
+ return function (o, p, l) {
320
+ if (f > 1) throw TypeError("Generator is already running");
321
+ for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) {
322
+ i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u);
323
+ try {
324
+ if (f = 2, i) {
325
+ if (c || (o = "next"), t = i[o]) {
326
+ if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object");
327
+ if (!t.done) return t;
328
+ u = t.value, c < 2 && (c = 0);
329
+ } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1);
330
+ i = e;
331
+ } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break;
332
+ } catch (t) {
333
+ i = e, c = 1, u = t;
334
+ } finally {
335
+ f = 1;
336
+ }
337
+ }
338
+ return {
339
+ value: t,
340
+ done: y
341
+ };
342
+ };
343
+ }(r, o, i), !0), u;
344
+ }
345
+ var a = {};
346
+ function Generator() {}
347
+ function GeneratorFunction() {}
348
+ function GeneratorFunctionPrototype() {}
349
+ t = Object.getPrototypeOf;
350
+ var c = [][n] ? t(t([][n]())) : (_regeneratorDefine(t = {}, n, function () {
351
+ return this;
352
+ }), t),
353
+ u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c);
354
+ function f(e) {
355
+ return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e;
356
+ }
357
+ return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine(u), _regeneratorDefine(u, o, "Generator"), _regeneratorDefine(u, n, function () {
358
+ return this;
359
+ }), _regeneratorDefine(u, "toString", function () {
360
+ return "[object Generator]";
361
+ }), (_regenerator = function () {
362
+ return {
363
+ w: i,
364
+ m: f
365
+ };
366
+ })();
367
+ }
368
+ function _regeneratorDefine(e, r, n, t) {
369
+ var i = Object.defineProperty;
370
+ try {
371
+ i({}, "", {});
372
+ } catch (e) {
373
+ i = 0;
374
+ }
375
+ _regeneratorDefine = function (e, r, n, t) {
376
+ function o(r, n) {
377
+ _regeneratorDefine(e, r, function (e) {
378
+ return this._invoke(r, n, e);
379
+ });
380
+ }
381
+ r ? i ? i(e, r, {
382
+ value: n,
383
+ enumerable: !t,
384
+ configurable: !t,
385
+ writable: !t
386
+ }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2));
387
+ }, _regeneratorDefine(e, r, n, t);
388
+ }
389
+ function _setPrototypeOf(t, e) {
390
+ return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) {
391
+ return t.__proto__ = e, t;
392
+ }, _setPrototypeOf(t, e);
393
+ }
394
+ function _toPrimitive(t, r) {
395
+ if ("object" != typeof t || !t) return t;
396
+ var e = t[Symbol.toPrimitive];
397
+ if (void 0 !== e) {
398
+ var i = e.call(t, r || "default");
399
+ if ("object" != typeof i) return i;
400
+ throw new TypeError("@@toPrimitive must return a primitive value.");
401
+ }
402
+ return ("string" === r ? String : Number)(t);
403
+ }
404
+ function _toPropertyKey(t) {
405
+ var i = _toPrimitive(t, "string");
406
+ return "symbol" == typeof i ? i : i + "";
407
+ }
408
+ function _unsupportedIterableToArray(r, a) {
409
+ if (r) {
410
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
411
+ var t = {}.toString.call(r).slice(8, -1);
412
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
413
+ }
414
+ }
415
+
416
+ function amountWithPathCurrency(amount, pool) {
417
+ return sdkCore.CurrencyAmount.fromFractionalAmount(getPathCurrency(amount.currency, pool), amount.numerator, amount.denominator);
418
+ }
419
+ function getPathCurrency(currency, pool) {
420
+ // return currency if the currency matches a currency of the pool
421
+ if (pool.involvesToken(currency)) {
422
+ return currency;
423
+ // return if currency.wrapped if pool involves wrapped currency
424
+ } else if (pool.involvesToken(currency.wrapped)) {
425
+ return currency.wrapped;
426
+ // return native currency if pool involves native version of wrapped currency (only applies to V4)
427
+ } else if (pool instanceof v4Sdk.Pool) {
428
+ if (pool.token0.wrapped.equals(currency)) {
429
+ return pool.token0;
430
+ } else if (pool.token1.wrapped.equals(currency)) {
431
+ return pool.token1;
432
+ }
433
+ // otherwise the token is invalid
434
+ } else {
435
+ throw new Error("Expected currency " + currency.symbol + " to be either " + pool.token0.symbol + " or " + pool.token1.symbol);
436
+ }
437
+ return currency; // this line needed for typescript to compile
438
+ }
439
+
440
+ /**
441
+ * Represents a list of pools or pairs through which a swap can occur
442
+ * @template TInput The input token
443
+ * @template TOutput The output token
444
+ */
445
+ var MixedRouteSDK = /*#__PURE__*/function () {
446
+ /**
447
+ * Creates an instance of route.
448
+ * @param pools An array of `TPool` objects (pools or pairs), ordered by the route the swap will take
449
+ * @param input The input token
450
+ * @param output The output token
451
+ * @param retainsFakePool Set to true to filter out a pool that has a fake eth-weth pool
452
+ */
453
+ function MixedRouteSDK(pools, input, output, retainFakePools) {
454
+ if (retainFakePools === void 0) {
455
+ retainFakePools = false;
456
+ }
457
+ this._midPrice = null;
458
+ pools = retainFakePools ? pools : pools.filter(function (pool) {
459
+ return !(pool instanceof v4Sdk.Pool && pool.tickSpacing === 0);
460
+ });
461
+ !(pools.length > 0) ? invariant(false, 'POOLS') : void 0;
462
+ // there is a pool mismatched to the path if we do not retain the fake eth-weth pools
463
+ var chainId = pools[0].chainId;
464
+ var allOnSameChain = pools.every(function (pool) {
465
+ return pool.chainId === chainId;
466
+ });
467
+ !allOnSameChain ? invariant(false, 'CHAIN_IDS') : void 0;
468
+ this.pathInput = getPathCurrency(input, pools[0]);
469
+ this.pathOutput = getPathCurrency(output, pools[pools.length - 1]);
470
+ if (!(pools[0] instanceof v4Sdk.Pool)) {
471
+ !pools[0].involvesToken(this.pathInput) ? invariant(false, 'INPUT') : void 0;
472
+ } else {
473
+ !pools[0].v4InvolvesToken(this.pathInput) ? invariant(false, 'INPUT') : void 0;
474
+ }
475
+ var lastPool = pools[pools.length - 1];
476
+ if (lastPool instanceof v4Sdk.Pool) {
477
+ !(lastPool.v4InvolvesToken(output) || lastPool.v4InvolvesToken(output.wrapped)) ? invariant(false, 'OUTPUT') : void 0;
478
+ } else {
479
+ !lastPool.involvesToken(output.wrapped) ? invariant(false, 'OUTPUT') : void 0;
480
+ }
481
+ /**
482
+ * Normalizes token0-token1 order and selects the next token/fee step to add to the path
483
+ * */
484
+ var tokenPath = [this.pathInput];
485
+ pools[0].token0.equals(this.pathInput) ? tokenPath.push(pools[0].token1) : tokenPath.push(pools[0].token0);
486
+ for (var i = 1; i < pools.length; i++) {
487
+ var pool = pools[i];
488
+ var inputToken = tokenPath[i];
489
+ var outputToken = void 0;
490
+ if (
491
+ // we hit an edge case if it's a v4 pool and neither of the tokens are in the pool OR it is not a v4 pool but the input currency is eth
492
+ pool instanceof v4Sdk.Pool && !pool.involvesToken(inputToken) || !(pool instanceof v4Sdk.Pool) && inputToken.isNative) {
493
+ // We handle the case where the inputToken =/= pool.token0 or pool.token1. There are 2 specific cases.
494
+ if (inputToken.equals(pool.token0.wrapped)) {
495
+ // 1) the inputToken is WETH and the current pool has ETH
496
+ // for example, pools: USDC-WETH, ETH-PEPE, path: USDC, WETH, PEPE
497
+ // second pool is a v4 pool, the first could be any version
498
+ outputToken = pool.token1;
499
+ } else if (inputToken.wrapped.equals(pool.token0) || inputToken.wrapped.equals(pool.token1)) {
500
+ // 2) the inputToken is ETH and the current pool has WETH
501
+ // for example, pools: USDC-ETH, WETH-PEPE, path: USDC, ETH, PEPE
502
+ // first pool is a v4 pool, the second could be any version
503
+ outputToken = inputToken.wrapped.equals(pool.token0) ? pool.token1 : pool.token0;
504
+ } else {
505
+ throw new Error("POOL_MISMATCH pool: " + JSON.stringify(pool) + " inputToken: " + JSON.stringify(inputToken));
506
+ }
507
+ } else {
508
+ // then the input token must equal either token0 or token1
509
+ !(inputToken.equals(pool.token0) || inputToken.equals(pool.token1)) ? invariant(false, "PATH pool " + JSON.stringify(pool) + " inputToken " + JSON.stringify(inputToken)) : void 0;
510
+ outputToken = inputToken.equals(pool.token0) ? pool.token1 : pool.token0;
511
+ }
512
+ tokenPath.push(outputToken);
513
+ }
514
+ this.pools = pools;
515
+ this.path = tokenPath;
516
+ this.input = input;
517
+ this.output = output != null ? output : tokenPath[tokenPath.length - 1];
518
+ }
519
+ return _createClass(MixedRouteSDK, [{
520
+ key: "chainId",
521
+ get: function get() {
522
+ return this.pools[0].chainId;
523
+ }
524
+ /**
525
+ * Returns the mid price of the route
526
+ */
527
+ }, {
528
+ key: "midPrice",
529
+ get: function get() {
530
+ if (this._midPrice !== null) return this._midPrice;
531
+ var price = this.pools.slice(1).reduce(function (_ref, pool) {
532
+ var nextInput = _ref.nextInput,
533
+ price = _ref.price;
534
+ return nextInput.equals(pool.token0) ? {
535
+ nextInput: pool.token1,
536
+ price: price.multiply(pool.token0Price.asFraction)
537
+ } : {
538
+ nextInput: pool.token0,
539
+ price: price.multiply(pool.token1Price.asFraction)
540
+ };
541
+ }, this.pools[0].token0.equals(this.pathInput) ? {
542
+ nextInput: this.pools[0].token1,
543
+ price: this.pools[0].token0Price.asFraction
544
+ } : {
545
+ nextInput: this.pools[0].token0,
546
+ price: this.pools[0].token1Price.asFraction
547
+ }).price;
548
+ return this._midPrice = new sdkCore.Price(this.input, this.output, price.denominator, price.numerator);
549
+ }
550
+ }]);
551
+ }();
552
+
553
+ /**
554
+ * Trades comparator, an extension of the input output comparator that also considers other dimensions of the trade in ranking them
555
+ * @template TInput The input token, either Ether or an ERC-20
556
+ * @template TOutput The output token, either Ether or an ERC-20
557
+ * @template TTradeType The trade type, either exact input or exact output
558
+ * @param a The first trade to compare
559
+ * @param b The second trade to compare
560
+ * @returns A sorted ordering for two neighboring elements in a trade array
561
+ */
562
+ function tradeComparator(a, b) {
563
+ // must have same input and output token for comparison
564
+ !a.inputAmount.currency.equals(b.inputAmount.currency) ? invariant(false, 'INPUT_CURRENCY') : void 0;
565
+ !a.outputAmount.currency.equals(b.outputAmount.currency) ? invariant(false, 'OUTPUT_CURRENCY') : void 0;
566
+ if (a.outputAmount.equalTo(b.outputAmount)) {
567
+ if (a.inputAmount.equalTo(b.inputAmount)) {
568
+ // consider the number of hops since each hop costs gas
569
+ var aHops = a.swaps.reduce(function (total, cur) {
570
+ return total + cur.route.path.length;
571
+ }, 0);
572
+ var bHops = b.swaps.reduce(function (total, cur) {
573
+ return total + cur.route.path.length;
574
+ }, 0);
575
+ return aHops - bHops;
576
+ }
577
+ // trade A requires less input than trade B, so A should come first
578
+ if (a.inputAmount.lessThan(b.inputAmount)) {
579
+ return -1;
580
+ } else {
581
+ return 1;
582
+ }
583
+ } else {
584
+ // tradeA has less output than trade B, so should come second
585
+ if (a.outputAmount.lessThan(b.outputAmount)) {
586
+ return 1;
587
+ } else {
588
+ return -1;
589
+ }
590
+ }
591
+ }
592
+ /**
593
+ * Represents a trade executed against a set of routes where some percentage of the input is
594
+ * split across each route.
595
+ *
596
+ * Each route has its own set of pools. Pools can not be re-used across routes.
597
+ *
598
+ * Does not account for slippage, i.e., changes in price environment that can occur between
599
+ * the time the trade is submitted and when it is executed.
600
+ * @notice This class is functionally the same as the `Trade` class in the `@juiceswapxyz/v3-sdk` package, aside from typing and some input validation.
601
+ * @template TInput The input token, either Ether or an ERC-20
602
+ * @template TOutput The output token, either Ether or an ERC-20
603
+ * @template TTradeType The trade type, either exact input or exact output
604
+ */
605
+ var MixedRouteTrade = /*#__PURE__*/function () {
606
+ /**
607
+ * Construct a trade by passing in the pre-computed property values
608
+ * @param routes The routes through which the trade occurs
609
+ * @param tradeType The type of trade, exact input or exact output
610
+ */
611
+ function MixedRouteTrade(_ref) {
612
+ var routes = _ref.routes,
613
+ tradeType = _ref.tradeType;
614
+ var inputCurrency = routes[0].inputAmount.currency;
615
+ var outputCurrency = routes[0].outputAmount.currency;
616
+ !routes.every(function (_ref2) {
617
+ var route = _ref2.route;
618
+ return inputCurrency.wrapped.equals(route.input.wrapped);
619
+ }) ? invariant(false, 'INPUT_CURRENCY_MATCH') : void 0;
620
+ !routes.every(function (_ref3) {
621
+ var route = _ref3.route;
622
+ return outputCurrency.wrapped.equals(route.output.wrapped);
623
+ }) ? invariant(false, 'OUTPUT_CURRENCY_MATCH') : void 0;
624
+ var numPools = routes.map(function (_ref4) {
625
+ var route = _ref4.route;
626
+ return route.pools.length;
627
+ }).reduce(function (total, cur) {
628
+ return total + cur;
629
+ }, 0);
630
+ var poolIdentifierSet = new Set();
631
+ for (var _iterator = _createForOfIteratorHelperLoose(routes), _step; !(_step = _iterator()).done;) {
632
+ var route = _step.value.route;
633
+ for (var _iterator2 = _createForOfIteratorHelperLoose(route.pools), _step2; !(_step2 = _iterator2()).done;) {
634
+ var pool = _step2.value;
635
+ if (pool instanceof v4Sdk.Pool) {
636
+ poolIdentifierSet.add(pool.poolId);
637
+ } else if (pool instanceof v3Sdk.Pool) {
638
+ poolIdentifierSet.add(v3Sdk.Pool.getAddress(pool.token0, pool.token1, pool.fee));
639
+ } else if (pool instanceof v2Sdk.Pair) {
640
+ var pair = pool;
641
+ poolIdentifierSet.add(v2Sdk.Pair.getAddress(pair.token0, pair.token1));
642
+ } else {
643
+ throw new Error('Unexpected pool type in route when constructing trade object');
644
+ }
645
+ }
646
+ }
647
+ !(numPools === poolIdentifierSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
648
+ !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
649
+ this.swaps = routes;
650
+ this.tradeType = tradeType;
651
+ }
652
+ /**
653
+ * @deprecated Deprecated in favor of 'swaps' property. If the trade consists of multiple routes
654
+ * this will return an error.
655
+ *
656
+ * When the trade consists of just a single route, this returns the route of the trade,
657
+ * i.e. which pools the trade goes through.
658
+ */
659
+ /**
660
+ * Constructs a trade by simulating swaps through the given route
661
+ * @template TInput The input token, either Ether or an ERC-20.
662
+ * @template TOutput The output token, either Ether or an ERC-20.
663
+ * @template TTradeType The type of the trade, either exact in or exact out.
664
+ * @param route route to swap through
665
+ * @param amount the amount specified, either input or output, depending on tradeType
666
+ * @param tradeType whether the trade is an exact input or exact output swap
667
+ * @returns The route
668
+ */
669
+ MixedRouteTrade.fromRoute =
670
+ /*#__PURE__*/
671
+ function () {
672
+ var _fromRoute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(route, amount, tradeType) {
673
+ var amounts, inputAmount, outputAmount, i, pool, _yield$pool$getOutput, _outputAmount;
674
+ return _regenerator().w(function (_context) {
675
+ while (1) switch (_context.n) {
676
+ case 0:
677
+ amounts = new Array(route.path.length);
678
+ !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
679
+ !amount.currency.equals(route.input) ? invariant(false, 'INPUT') : void 0;
680
+ amounts[0] = amountWithPathCurrency(amount, route.pools[0]);
681
+ i = 0;
682
+ case 1:
683
+ if (!(i < route.path.length - 1)) {
684
+ _context.n = 4;
685
+ break;
686
+ }
687
+ pool = route.pools[i];
688
+ _context.n = 2;
689
+ return pool.getOutputAmount(amountWithPathCurrency(amounts[i], pool));
690
+ case 2:
691
+ _yield$pool$getOutput = _context.v;
692
+ _outputAmount = _yield$pool$getOutput[0];
693
+ amounts[i + 1] = _outputAmount;
694
+ case 3:
695
+ i++;
696
+ _context.n = 1;
697
+ break;
698
+ case 4:
699
+ inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
700
+ outputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.output, amounts[amounts.length - 1].numerator, amounts[amounts.length - 1].denominator);
701
+ return _context.a(2, new MixedRouteTrade({
702
+ routes: [{
703
+ inputAmount: inputAmount,
704
+ outputAmount: outputAmount,
705
+ route: route
706
+ }],
707
+ tradeType: tradeType
708
+ }));
709
+ }
710
+ }, _callee);
711
+ }));
712
+ function fromRoute(_x, _x2, _x3) {
713
+ return _fromRoute.apply(this, arguments);
714
+ }
715
+ return fromRoute;
716
+ }()
717
+ /**
718
+ * Constructs a trade from routes by simulating swaps
719
+ *
720
+ * @template TInput The input token, either Ether or an ERC-20.
721
+ * @template TOutput The output token, either Ether or an ERC-20.
722
+ * @template TTradeType The type of the trade, either exact in or exact out.
723
+ * @param routes the routes to swap through and how much of the amount should be routed through each
724
+ * @param tradeType whether the trade is an exact input or exact output swap
725
+ * @returns The trade
726
+ */
727
+ ;
728
+ MixedRouteTrade.fromRoutes =
729
+ /*#__PURE__*/
730
+ function () {
731
+ var _fromRoutes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(routes, tradeType) {
732
+ var populatedRoutes, _iterator3, _step3, _step3$value, route, amount, amounts, inputAmount, outputAmount, i, pool, _yield$pool$getOutput2, _outputAmount2;
733
+ return _regenerator().w(function (_context2) {
734
+ while (1) switch (_context2.n) {
735
+ case 0:
736
+ populatedRoutes = [];
737
+ !(tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
738
+ _iterator3 = _createForOfIteratorHelperLoose(routes);
739
+ case 1:
740
+ if ((_step3 = _iterator3()).done) {
741
+ _context2.n = 7;
742
+ break;
743
+ }
744
+ _step3$value = _step3.value, route = _step3$value.route, amount = _step3$value.amount;
745
+ amounts = new Array(route.path.length);
746
+ inputAmount = void 0;
747
+ outputAmount = void 0;
748
+ !amount.currency.equals(route.input) ? invariant(false, 'INPUT') : void 0;
749
+ inputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator);
750
+ amounts[0] = sdkCore.CurrencyAmount.fromFractionalAmount(route.pathInput, amount.numerator, amount.denominator);
751
+ i = 0;
752
+ case 2:
753
+ if (!(i < route.path.length - 1)) {
754
+ _context2.n = 5;
755
+ break;
756
+ }
757
+ pool = route.pools[i];
758
+ _context2.n = 3;
759
+ return pool.getOutputAmount(amountWithPathCurrency(amounts[i], pool));
760
+ case 3:
761
+ _yield$pool$getOutput2 = _context2.v;
762
+ _outputAmount2 = _yield$pool$getOutput2[0];
763
+ amounts[i + 1] = _outputAmount2;
764
+ case 4:
765
+ i++;
766
+ _context2.n = 2;
767
+ break;
768
+ case 5:
769
+ outputAmount = sdkCore.CurrencyAmount.fromFractionalAmount(route.output, amounts[amounts.length - 1].numerator, amounts[amounts.length - 1].denominator);
770
+ populatedRoutes.push({
771
+ route: route,
772
+ inputAmount: inputAmount,
773
+ outputAmount: outputAmount
774
+ });
775
+ case 6:
776
+ _context2.n = 1;
777
+ break;
778
+ case 7:
779
+ return _context2.a(2, new MixedRouteTrade({
780
+ routes: populatedRoutes,
781
+ tradeType: tradeType
782
+ }));
783
+ }
784
+ }, _callee2);
785
+ }));
786
+ function fromRoutes(_x4, _x5) {
787
+ return _fromRoutes.apply(this, arguments);
788
+ }
789
+ return fromRoutes;
790
+ }()
791
+ /**
792
+ * Creates a trade without computing the result of swapping through the route. Useful when you have simulated the trade
793
+ * elsewhere and do not have any tick data
794
+ * @template TInput The input token, either Ether or an ERC-20
795
+ * @template TOutput The output token, either Ether or an ERC-20
796
+ * @template TTradeType The type of the trade, either exact in or exact out
797
+ * @param constructorArguments The arguments passed to the trade constructor
798
+ * @returns The unchecked trade
799
+ */
800
+ ;
801
+ MixedRouteTrade.createUncheckedTrade = function createUncheckedTrade(constructorArguments) {
802
+ return new MixedRouteTrade(_extends({}, constructorArguments, {
803
+ routes: [{
804
+ inputAmount: constructorArguments.inputAmount,
805
+ outputAmount: constructorArguments.outputAmount,
806
+ route: constructorArguments.route
807
+ }]
808
+ }));
809
+ }
810
+ /**
811
+ * Creates a trade without computing the result of swapping through the routes. Useful when you have simulated the trade
812
+ * elsewhere and do not have any tick data
813
+ * @template TInput The input token, either Ether or an ERC-20
814
+ * @template TOutput The output token, either Ether or an ERC-20
815
+ * @template TTradeType The type of the trade, either exact in or exact out
816
+ * @param constructorArguments The arguments passed to the trade constructor
817
+ * @returns The unchecked trade
818
+ */;
819
+ MixedRouteTrade.createUncheckedTradeWithMultipleRoutes = function createUncheckedTradeWithMultipleRoutes(constructorArguments) {
820
+ return new MixedRouteTrade(constructorArguments);
821
+ }
822
+ /**
823
+ * Get the minimum amount that must be received from this trade for the given slippage tolerance
824
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
825
+ * @returns The amount out
826
+ */;
827
+ var _proto = MixedRouteTrade.prototype;
828
+ _proto.minimumAmountOut = function minimumAmountOut(slippageTolerance, amountOut) {
829
+ if (amountOut === void 0) {
830
+ amountOut = this.outputAmount;
831
+ }
832
+ !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
833
+ /// does not support exactOutput, as enforced in the constructor
834
+ var slippageAdjustedAmountOut = new sdkCore.Fraction(ONE).add(slippageTolerance).invert().multiply(amountOut.quotient).quotient;
835
+ return sdkCore.CurrencyAmount.fromRawAmount(amountOut.currency, slippageAdjustedAmountOut);
836
+ }
837
+ /**
838
+ * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
839
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
840
+ * @returns The amount in
841
+ */;
842
+ _proto.maximumAmountIn = function maximumAmountIn(slippageTolerance, amountIn) {
843
+ if (amountIn === void 0) {
844
+ amountIn = this.inputAmount;
845
+ }
846
+ !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
847
+ return amountIn;
848
+ /// does not support exactOutput
849
+ }
850
+ /**
851
+ * Return the execution price after accounting for slippage tolerance
852
+ * @param slippageTolerance the allowed tolerated slippage
853
+ * @returns The execution price
854
+ */;
855
+ _proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) {
856
+ return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
857
+ }
858
+ /**
859
+ * Given a list of pools, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token
860
+ * amount to an output token, making at most `maxHops` hops.
861
+ * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting
862
+ * the amount in among multiple routes.
863
+ * @param pools the pools to consider in finding the best trade
864
+ * @param nextAmountIn exact amount of input currency to spend
865
+ * @param currencyOut the desired currency out
866
+ * @param maxNumResults maximum number of results to return
867
+ * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pool
868
+ * @param currentPools used in recursion; the current list of pools
869
+ * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter
870
+ * @param bestTrades used in recursion; the current list of best trades
871
+ * @returns The exact in trade
872
+ */;
873
+ MixedRouteTrade.bestTradeExactIn =
874
+ /*#__PURE__*/
875
+ function () {
876
+ var _bestTradeExactIn = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee3(pools, currencyAmountIn, currencyOut, _temp,
877
+ // used in recursion.
878
+ currentPools, nextAmountIn, bestTrades) {
879
+ var _ref5, _ref5$maxNumResults, maxNumResults, _ref5$maxHops, maxHops, amountIn, i, pool, amountInAdjusted, amountOut, _ref6, poolsExcludingThisPool, _t, _t2, _t3, _t4;
880
+ return _regenerator().w(function (_context3) {
881
+ while (1) switch (_context3.p = _context3.n) {
882
+ case 0:
883
+ _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;
884
+ if (currentPools === void 0) {
885
+ currentPools = [];
886
+ }
887
+ if (nextAmountIn === void 0) {
888
+ nextAmountIn = currencyAmountIn;
889
+ }
890
+ if (bestTrades === void 0) {
891
+ bestTrades = [];
892
+ }
893
+ !(pools.length > 0) ? invariant(false, 'POOLS') : void 0;
894
+ !(maxHops > 0) ? invariant(false, 'MAX_HOPS') : void 0;
895
+ !(currencyAmountIn === nextAmountIn || currentPools.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0;
896
+ amountIn = nextAmountIn;
897
+ i = 0;
898
+ case 1:
899
+ if (!(i < pools.length)) {
900
+ _context3.n = 15;
901
+ break;
902
+ }
903
+ pool = pools[i];
904
+ amountInAdjusted = pool instanceof v4Sdk.Pool ? amountIn : amountIn.wrapped; // pool irrelevant
905
+ if (!(!pool.token0.equals(amountInAdjusted.currency) && !pool.token1.equals(amountInAdjusted.currency))) {
906
+ _context3.n = 2;
907
+ break;
908
+ }
909
+ return _context3.a(3, 14);
910
+ case 2:
911
+ if (!(pool instanceof v2Sdk.Pair)) {
912
+ _context3.n = 3;
913
+ break;
914
+ }
915
+ if (!(pool.reserve0.equalTo(ZERO) || pool.reserve1.equalTo(ZERO))) {
916
+ _context3.n = 3;
917
+ break;
918
+ }
919
+ return _context3.a(3, 14);
920
+ case 3:
921
+ amountOut = void 0;
922
+ _context3.p = 4;
923
+ if (!(pool instanceof v4Sdk.Pool)) {
924
+ _context3.n = 6;
925
+ break;
926
+ }
927
+ _context3.n = 5;
928
+ return pool.getOutputAmount(amountInAdjusted);
929
+ case 5:
930
+ _t = _context3.v;
931
+ _context3.n = 8;
932
+ break;
933
+ case 6:
934
+ _context3.n = 7;
935
+ return pool.getOutputAmount(amountInAdjusted.wrapped);
936
+ case 7:
937
+ _t = _context3.v;
938
+ case 8:
939
+ _ref6 = _t;
940
+ amountOut = _ref6[0];
941
+ _context3.n = 11;
942
+ break;
943
+ case 9:
944
+ _context3.p = 9;
945
+ _t2 = _context3.v;
946
+ if (!_t2.isInsufficientInputAmountError) {
947
+ _context3.n = 10;
948
+ break;
949
+ }
950
+ return _context3.a(3, 14);
951
+ case 10:
952
+ throw _t2;
953
+ case 11:
954
+ if (!amountOut.currency.wrapped.equals(currencyOut.wrapped)) {
955
+ _context3.n = 13;
956
+ break;
957
+ }
958
+ _t3 = sdkCore.sortedInsert;
959
+ _t4 = bestTrades;
960
+ _context3.n = 12;
961
+ return MixedRouteTrade.fromRoute(new MixedRouteSDK([].concat(currentPools, [pool]), currencyAmountIn.currency, currencyOut), currencyAmountIn, sdkCore.TradeType.EXACT_INPUT);
962
+ case 12:
963
+ _t3(_t4, _context3.v, maxNumResults, tradeComparator);
964
+ _context3.n = 14;
965
+ break;
966
+ case 13:
967
+ if (!(maxHops > 1 && pools.length > 1)) {
968
+ _context3.n = 14;
969
+ break;
970
+ }
971
+ 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
972
+ _context3.n = 14;
973
+ return MixedRouteTrade.bestTradeExactIn(poolsExcludingThisPool, currencyAmountIn, currencyOut, {
974
+ maxNumResults: maxNumResults,
975
+ maxHops: maxHops - 1
976
+ }, [].concat(currentPools, [pool]), amountOut, bestTrades);
977
+ case 14:
978
+ i++;
979
+ _context3.n = 1;
980
+ break;
981
+ case 15:
982
+ return _context3.a(2, bestTrades);
983
+ }
984
+ }, _callee3, null, [[4, 9]]);
985
+ }));
986
+ function bestTradeExactIn(_x6, _x7, _x8, _x9, _x0, _x1, _x10) {
987
+ return _bestTradeExactIn.apply(this, arguments);
988
+ }
989
+ return bestTradeExactIn;
990
+ }();
991
+ return _createClass(MixedRouteTrade, [{
992
+ key: "route",
993
+ get: function get() {
994
+ !(this.swaps.length === 1) ? invariant(false, 'MULTIPLE_ROUTES') : void 0;
995
+ return this.swaps[0].route;
996
+ }
997
+ /**
998
+ * The input amount for the trade assuming no slippage.
999
+ */
1000
+ }, {
1001
+ key: "inputAmount",
1002
+ get: function get() {
1003
+ if (this._inputAmount) {
1004
+ return this._inputAmount;
1005
+ }
1006
+ var inputCurrency = this.swaps[0].inputAmount.currency;
1007
+ var totalInputFromRoutes = this.swaps.map(function (_ref7) {
1008
+ var inputAmount = _ref7.inputAmount;
1009
+ return inputAmount;
1010
+ }).reduce(function (total, cur) {
1011
+ return total.add(cur);
1012
+ }, sdkCore.CurrencyAmount.fromRawAmount(inputCurrency, 0));
1013
+ this._inputAmount = totalInputFromRoutes;
1014
+ return this._inputAmount;
1015
+ }
1016
+ /**
1017
+ * The output amount for the trade assuming no slippage.
1018
+ */
1019
+ }, {
1020
+ key: "outputAmount",
1021
+ get: function get() {
1022
+ if (this._outputAmount) {
1023
+ return this._outputAmount;
1024
+ }
1025
+ var outputCurrency = this.swaps[0].outputAmount.currency;
1026
+ var totalOutputFromRoutes = this.swaps.map(function (_ref8) {
1027
+ var outputAmount = _ref8.outputAmount;
1028
+ return outputAmount;
1029
+ }).reduce(function (total, cur) {
1030
+ return total.add(cur);
1031
+ }, sdkCore.CurrencyAmount.fromRawAmount(outputCurrency, 0));
1032
+ this._outputAmount = totalOutputFromRoutes;
1033
+ return this._outputAmount;
1034
+ }
1035
+ /**
1036
+ * The price expressed in terms of output amount/input amount.
1037
+ */
1038
+ }, {
1039
+ key: "executionPrice",
1040
+ get: function get() {
1041
+ var _this$_executionPrice;
1042
+ return (_this$_executionPrice = this._executionPrice) != null ? _this$_executionPrice : this._executionPrice = new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient);
1043
+ }
1044
+ /**
1045
+ * Returns the percent difference between the route's mid price and the price impact
1046
+ */
1047
+ }, {
1048
+ key: "priceImpact",
1049
+ get: function get() {
1050
+ if (this._priceImpact) {
1051
+ return this._priceImpact;
1052
+ }
1053
+ var spotOutputAmount = sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
1054
+ for (var _iterator4 = _createForOfIteratorHelperLoose(this.swaps), _step4; !(_step4 = _iterator4()).done;) {
1055
+ var _step4$value = _step4.value,
1056
+ route = _step4$value.route,
1057
+ inputAmount = _step4$value.inputAmount;
1058
+ var midPrice = route.midPrice;
1059
+ spotOutputAmount = spotOutputAmount.add(midPrice.quote(inputAmount));
1060
+ }
1061
+ var priceImpact = spotOutputAmount.subtract(this.outputAmount).divide(spotOutputAmount);
1062
+ this._priceImpact = new sdkCore.Percent(priceImpact.numerator, priceImpact.denominator);
1063
+ return this._priceImpact;
1064
+ }
1065
+ }]);
1066
+ }();
1067
+
1068
+ (function (Protocol) {
1069
+ Protocol["V2"] = "V2";
1070
+ Protocol["V3"] = "V3";
1071
+ Protocol["V4"] = "V4";
1072
+ Protocol["MIXED"] = "MIXED";
1073
+ })(exports.Protocol || (exports.Protocol = {}));
1074
+
1075
+ // Helper function to get the pathInput and pathOutput for a V2 / V3 route
1076
+ // currency could be native so we check against the wrapped version as they don't support native ETH in path
1077
+ function getPathToken(currency, pool) {
1078
+ if (pool.token0.wrapped.equals(currency.wrapped)) {
1079
+ return pool.token0;
1080
+ } else if (pool.token1.wrapped.equals(currency.wrapped)) {
1081
+ return pool.token1;
1082
+ } else {
1083
+ throw new Error("Expected token " + currency.symbol + " to be either " + pool.token0.symbol + " or " + pool.token1.symbol);
1084
+ }
1085
+ }
1086
+ // V2 route wrapper
1087
+ var RouteV2 = /*#__PURE__*/function (_V2RouteSDK) {
1088
+ function RouteV2(v2Route) {
1089
+ var _this;
1090
+ _this = _V2RouteSDK.call(this, v2Route.pairs, v2Route.input, v2Route.output) || this;
1091
+ _this.protocol = exports.Protocol.V2;
1092
+ _this.pools = _this.pairs;
1093
+ _this.pathInput = getPathToken(v2Route.input, _this.pairs[0]);
1094
+ _this.pathOutput = getPathToken(v2Route.output, _this.pairs[_this.pairs.length - 1]);
1095
+ return _this;
1096
+ }
1097
+ _inheritsLoose(RouteV2, _V2RouteSDK);
1098
+ return RouteV2;
1099
+ }(v2Sdk.Route);
1100
+ // V3 route wrapper
1101
+ var RouteV3 = /*#__PURE__*/function (_V3RouteSDK) {
1102
+ function RouteV3(v3Route) {
1103
+ var _this2;
1104
+ _this2 = _V3RouteSDK.call(this, v3Route.pools, v3Route.input, v3Route.output) || this;
1105
+ _this2.protocol = exports.Protocol.V3;
1106
+ _this2.path = v3Route.tokenPath;
1107
+ _this2.pathInput = getPathToken(v3Route.input, _this2.pools[0]);
1108
+ _this2.pathOutput = getPathToken(v3Route.output, _this2.pools[_this2.pools.length - 1]);
1109
+ return _this2;
1110
+ }
1111
+ _inheritsLoose(RouteV3, _V3RouteSDK);
1112
+ return RouteV3;
1113
+ }(v3Sdk.Route);
1114
+ // V4 route wrapper
1115
+ var RouteV4 = /*#__PURE__*/function (_V4RouteSDK) {
1116
+ function RouteV4(v4Route) {
1117
+ var _this3;
1118
+ _this3 = _V4RouteSDK.call(this, v4Route.pools, v4Route.input, v4Route.output) || this;
1119
+ _this3.protocol = exports.Protocol.V4;
1120
+ _this3.path = v4Route.currencyPath;
1121
+ return _this3;
1122
+ }
1123
+ _inheritsLoose(RouteV4, _V4RouteSDK);
1124
+ return RouteV4;
1125
+ }(v4Sdk.Route);
1126
+ // Mixed route wrapper
1127
+ var MixedRoute = /*#__PURE__*/function (_MixedRouteSDK) {
1128
+ function MixedRoute(mixedRoute) {
1129
+ var _this4;
1130
+ _this4 = _MixedRouteSDK.call(this, mixedRoute.pools, mixedRoute.input, mixedRoute.output) || this;
1131
+ _this4.protocol = exports.Protocol.MIXED;
1132
+ return _this4;
1133
+ }
1134
+ _inheritsLoose(MixedRoute, _MixedRouteSDK);
1135
+ return MixedRoute;
1136
+ }(MixedRouteSDK);
1137
+
1138
+ var Trade = /*#__PURE__*/function () {
1139
+ // construct a trade across v2 and v3 routes from pre-computed amounts
1140
+ function Trade(_ref) {
1141
+ var _ref$v2Routes = _ref.v2Routes,
1142
+ v2Routes = _ref$v2Routes === void 0 ? [] : _ref$v2Routes,
1143
+ _ref$v3Routes = _ref.v3Routes,
1144
+ v3Routes = _ref$v3Routes === void 0 ? [] : _ref$v3Routes,
1145
+ _ref$v4Routes = _ref.v4Routes,
1146
+ v4Routes = _ref$v4Routes === void 0 ? [] : _ref$v4Routes,
1147
+ _ref$mixedRoutes = _ref.mixedRoutes,
1148
+ mixedRoutes = _ref$mixedRoutes === void 0 ? [] : _ref$mixedRoutes,
1149
+ tradeType = _ref.tradeType;
1150
+ this.swaps = [];
1151
+ this.routes = [];
1152
+ // wrap v2 routes
1153
+ for (var _iterator = _createForOfIteratorHelperLoose(v2Routes), _step; !(_step = _iterator()).done;) {
1154
+ var _step$value = _step.value,
1155
+ routev2 = _step$value.routev2,
1156
+ inputAmount = _step$value.inputAmount,
1157
+ outputAmount = _step$value.outputAmount;
1158
+ var route = new RouteV2(routev2);
1159
+ this.routes.push(route);
1160
+ this.swaps.push({
1161
+ route: route,
1162
+ inputAmount: inputAmount,
1163
+ outputAmount: outputAmount
1164
+ });
1165
+ }
1166
+ // wrap v3 routes
1167
+ for (var _iterator2 = _createForOfIteratorHelperLoose(v3Routes), _step2; !(_step2 = _iterator2()).done;) {
1168
+ var _step2$value = _step2.value,
1169
+ routev3 = _step2$value.routev3,
1170
+ _inputAmount = _step2$value.inputAmount,
1171
+ _outputAmount = _step2$value.outputAmount;
1172
+ var _route = new RouteV3(routev3);
1173
+ this.routes.push(_route);
1174
+ this.swaps.push({
1175
+ route: _route,
1176
+ inputAmount: _inputAmount,
1177
+ outputAmount: _outputAmount
1178
+ });
1179
+ }
1180
+ // wrap v4 routes
1181
+ for (var _iterator3 = _createForOfIteratorHelperLoose(v4Routes), _step3; !(_step3 = _iterator3()).done;) {
1182
+ var _step3$value = _step3.value,
1183
+ routev4 = _step3$value.routev4,
1184
+ _inputAmount2 = _step3$value.inputAmount,
1185
+ _outputAmount2 = _step3$value.outputAmount;
1186
+ var _route2 = new RouteV4(routev4);
1187
+ this.routes.push(_route2);
1188
+ this.swaps.push({
1189
+ route: _route2,
1190
+ inputAmount: _inputAmount2,
1191
+ outputAmount: _outputAmount2
1192
+ });
1193
+ }
1194
+ for (var _iterator4 = _createForOfIteratorHelperLoose(mixedRoutes), _step4; !(_step4 = _iterator4()).done;) {
1195
+ var _step4$value = _step4.value,
1196
+ mixedRoute = _step4$value.mixedRoute,
1197
+ _inputAmount3 = _step4$value.inputAmount,
1198
+ _outputAmount3 = _step4$value.outputAmount;
1199
+ var _route3 = new MixedRoute(mixedRoute);
1200
+ this.routes.push(_route3);
1201
+ this.swaps.push({
1202
+ route: _route3,
1203
+ inputAmount: _inputAmount3,
1204
+ outputAmount: _outputAmount3
1205
+ });
1206
+ }
1207
+ if (this.swaps.length === 0) {
1208
+ throw new Error('No routes provided when calling Trade constructor');
1209
+ }
1210
+ this.tradeType = tradeType;
1211
+ // each route must have the same input and output currency
1212
+ var inputCurrency = this.swaps[0].inputAmount.currency;
1213
+ var outputCurrency = this.swaps[0].outputAmount.currency;
1214
+ !this.swaps.every(function (_ref2) {
1215
+ var route = _ref2.route;
1216
+ return inputCurrency.wrapped.equals(route.input.wrapped);
1217
+ }) ? invariant(false, 'INPUT_CURRENCY_MATCH') : void 0;
1218
+ !this.swaps.every(function (_ref3) {
1219
+ var route = _ref3.route;
1220
+ return outputCurrency.wrapped.equals(route.output.wrapped);
1221
+ }) ? invariant(false, 'OUTPUT_CURRENCY_MATCH') : void 0;
1222
+ // pools must be unique inter protocols
1223
+ var numPools = this.swaps.map(function (_ref4) {
1224
+ var route = _ref4.route;
1225
+ return route.pools.length;
1226
+ }).reduce(function (total, cur) {
1227
+ return total + cur;
1228
+ }, 0);
1229
+ var poolIdentifierSet = new Set();
1230
+ for (var _iterator5 = _createForOfIteratorHelperLoose(this.swaps), _step5; !(_step5 = _iterator5()).done;) {
1231
+ var _route4 = _step5.value.route;
1232
+ for (var _iterator6 = _createForOfIteratorHelperLoose(_route4.pools), _step6; !(_step6 = _iterator6()).done;) {
1233
+ var pool = _step6.value;
1234
+ if (pool instanceof v4Sdk.Pool) {
1235
+ poolIdentifierSet.add(pool.poolId);
1236
+ } else if (pool instanceof v3Sdk.Pool) {
1237
+ poolIdentifierSet.add(v3Sdk.Pool.getAddress(pool.token0, pool.token1, pool.fee));
1238
+ } else if (pool instanceof v2Sdk.Pair) {
1239
+ var pair = pool;
1240
+ poolIdentifierSet.add(v2Sdk.Pair.getAddress(pair.token0, pair.token1));
1241
+ } else {
1242
+ throw new Error('Unexpected pool type in route when constructing trade object');
1243
+ }
1244
+ }
1245
+ }
1246
+ !(numPools === poolIdentifierSet.size) ? invariant(false, 'POOLS_DUPLICATED') : void 0;
1247
+ }
1248
+ var _proto = Trade.prototype;
1249
+ _proto.isWrappedNative = function isWrappedNative(currency) {
1250
+ var chainId = currency.chainId;
1251
+ return currency.equals(sdkCore.Ether.onChain(chainId).wrapped);
1252
+ }
1253
+ /**
1254
+ * Returns the percent difference between the route's mid price and the expected execution price
1255
+ * In order to exclude token taxes from the price impact calculation, the spot price is calculated
1256
+ * using a ratio of values that go into the pools, which are the post-tax input amount and pre-tax output amount.
1257
+ */;
1258
+ /**
1259
+ * Get the minimum amount that must be received from this trade for the given slippage tolerance
1260
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
1261
+ * @returns The amount out
1262
+ */
1263
+ _proto.minimumAmountOut = function minimumAmountOut(slippageTolerance, amountOut) {
1264
+ if (amountOut === void 0) {
1265
+ amountOut = this.outputAmount;
1266
+ }
1267
+ !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
1268
+ if (this.tradeType === sdkCore.TradeType.EXACT_OUTPUT) {
1269
+ return amountOut;
1270
+ } else {
1271
+ var slippageAdjustedAmountOut = new sdkCore.Fraction(ONE).add(slippageTolerance).invert().multiply(amountOut.quotient).quotient;
1272
+ return sdkCore.CurrencyAmount.fromRawAmount(amountOut.currency, slippageAdjustedAmountOut);
1273
+ }
1274
+ }
1275
+ /**
1276
+ * Get the maximum amount in that can be spent via this trade for the given slippage tolerance
1277
+ * @param slippageTolerance The tolerance of unfavorable slippage from the execution price of this trade
1278
+ * @returns The amount in
1279
+ */;
1280
+ _proto.maximumAmountIn = function maximumAmountIn(slippageTolerance, amountIn) {
1281
+ if (amountIn === void 0) {
1282
+ amountIn = this.inputAmount;
1283
+ }
1284
+ !!slippageTolerance.lessThan(ZERO) ? invariant(false, 'SLIPPAGE_TOLERANCE') : void 0;
1285
+ if (this.tradeType === sdkCore.TradeType.EXACT_INPUT) {
1286
+ return amountIn;
1287
+ } else {
1288
+ var slippageAdjustedAmountIn = new sdkCore.Fraction(ONE).add(slippageTolerance).multiply(amountIn.quotient).quotient;
1289
+ return sdkCore.CurrencyAmount.fromRawAmount(amountIn.currency, slippageAdjustedAmountIn);
1290
+ }
1291
+ }
1292
+ /**
1293
+ * Return the execution price after accounting for slippage tolerance
1294
+ * @param slippageTolerance the allowed tolerated slippage
1295
+ * @returns The execution price
1296
+ */;
1297
+ _proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) {
1298
+ return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).quotient, this.minimumAmountOut(slippageTolerance).quotient);
1299
+ };
1300
+ Trade.fromRoutes = /*#__PURE__*/function () {
1301
+ var _fromRoutes = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(v2Routes, v3Routes, tradeType, mixedRoutes, v4Routes) {
1302
+ var populatedV2Routes, populatedV3Routes, populatedV4Routes, populatedMixedRoutes, _iterator7, _step7, _step7$value, routev2, _amount2, v2Trade, _inputAmount5, _outputAmount5, _iterator8, _step8, _step8$value, routev3, _amount3, v3Trade, _inputAmount6, _outputAmount6, _iterator9, _step9, _step9$value, routev4, amount, v4Trade, inputAmount, outputAmount, _iterator0, _step0, _step0$value, mixedRoute, _amount, mixedRouteTrade, _inputAmount4, _outputAmount4;
1303
+ return _regenerator().w(function (_context) {
1304
+ while (1) switch (_context.n) {
1305
+ case 0:
1306
+ populatedV2Routes = [];
1307
+ populatedV3Routes = [];
1308
+ populatedV4Routes = [];
1309
+ populatedMixedRoutes = [];
1310
+ for (_iterator7 = _createForOfIteratorHelperLoose(v2Routes); !(_step7 = _iterator7()).done;) {
1311
+ _step7$value = _step7.value, routev2 = _step7$value.routev2, _amount2 = _step7$value.amount;
1312
+ v2Trade = new v2Sdk.Trade(routev2, _amount2, tradeType);
1313
+ _inputAmount5 = v2Trade.inputAmount, _outputAmount5 = v2Trade.outputAmount;
1314
+ populatedV2Routes.push({
1315
+ routev2: routev2,
1316
+ inputAmount: _inputAmount5,
1317
+ outputAmount: _outputAmount5
1318
+ });
1319
+ }
1320
+ _iterator8 = _createForOfIteratorHelperLoose(v3Routes);
1321
+ case 1:
1322
+ if ((_step8 = _iterator8()).done) {
1323
+ _context.n = 4;
1324
+ break;
1325
+ }
1326
+ _step8$value = _step8.value, routev3 = _step8$value.routev3, _amount3 = _step8$value.amount;
1327
+ _context.n = 2;
1328
+ return v3Sdk.Trade.fromRoute(routev3, _amount3, tradeType);
1329
+ case 2:
1330
+ v3Trade = _context.v;
1331
+ _inputAmount6 = v3Trade.inputAmount, _outputAmount6 = v3Trade.outputAmount;
1332
+ populatedV3Routes.push({
1333
+ routev3: routev3,
1334
+ inputAmount: _inputAmount6,
1335
+ outputAmount: _outputAmount6
1336
+ });
1337
+ case 3:
1338
+ _context.n = 1;
1339
+ break;
1340
+ case 4:
1341
+ if (!v4Routes) {
1342
+ _context.n = 8;
1343
+ break;
1344
+ }
1345
+ _iterator9 = _createForOfIteratorHelperLoose(v4Routes);
1346
+ case 5:
1347
+ if ((_step9 = _iterator9()).done) {
1348
+ _context.n = 8;
1349
+ break;
1350
+ }
1351
+ _step9$value = _step9.value, routev4 = _step9$value.routev4, amount = _step9$value.amount;
1352
+ _context.n = 6;
1353
+ return v4Sdk.Trade.fromRoute(routev4, amount, tradeType);
1354
+ case 6:
1355
+ v4Trade = _context.v;
1356
+ inputAmount = v4Trade.inputAmount, outputAmount = v4Trade.outputAmount;
1357
+ populatedV4Routes.push({
1358
+ routev4: routev4,
1359
+ inputAmount: inputAmount,
1360
+ outputAmount: outputAmount
1361
+ });
1362
+ case 7:
1363
+ _context.n = 5;
1364
+ break;
1365
+ case 8:
1366
+ if (!mixedRoutes) {
1367
+ _context.n = 12;
1368
+ break;
1369
+ }
1370
+ _iterator0 = _createForOfIteratorHelperLoose(mixedRoutes);
1371
+ case 9:
1372
+ if ((_step0 = _iterator0()).done) {
1373
+ _context.n = 12;
1374
+ break;
1375
+ }
1376
+ _step0$value = _step0.value, mixedRoute = _step0$value.mixedRoute, _amount = _step0$value.amount;
1377
+ _context.n = 10;
1378
+ return MixedRouteTrade.fromRoute(mixedRoute, _amount, tradeType);
1379
+ case 10:
1380
+ mixedRouteTrade = _context.v;
1381
+ _inputAmount4 = mixedRouteTrade.inputAmount, _outputAmount4 = mixedRouteTrade.outputAmount;
1382
+ populatedMixedRoutes.push({
1383
+ mixedRoute: mixedRoute,
1384
+ inputAmount: _inputAmount4,
1385
+ outputAmount: _outputAmount4
1386
+ });
1387
+ case 11:
1388
+ _context.n = 9;
1389
+ break;
1390
+ case 12:
1391
+ return _context.a(2, new Trade({
1392
+ v2Routes: populatedV2Routes,
1393
+ v3Routes: populatedV3Routes,
1394
+ v4Routes: populatedV4Routes,
1395
+ mixedRoutes: populatedMixedRoutes,
1396
+ tradeType: tradeType
1397
+ }));
1398
+ }
1399
+ }, _callee);
1400
+ }));
1401
+ function fromRoutes(_x, _x2, _x3, _x4, _x5) {
1402
+ return _fromRoutes.apply(this, arguments);
1403
+ }
1404
+ return fromRoutes;
1405
+ }();
1406
+ Trade.fromRoute = /*#__PURE__*/function () {
1407
+ var _fromRoute = /*#__PURE__*/_asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(route, amount, tradeType) {
1408
+ var v2Routes, v3Routes, v4Routes, mixedRoutes, v2Trade, inputAmount, outputAmount, v3Trade, _inputAmount7, _outputAmount7, v4Trade, _inputAmount8, _outputAmount8, mixedRouteTrade, _inputAmount9, _outputAmount9;
1409
+ return _regenerator().w(function (_context2) {
1410
+ while (1) switch (_context2.n) {
1411
+ case 0:
1412
+ v2Routes = [];
1413
+ v3Routes = [];
1414
+ v4Routes = [];
1415
+ mixedRoutes = [];
1416
+ if (!(route instanceof v2Sdk.Route)) {
1417
+ _context2.n = 1;
1418
+ break;
1419
+ }
1420
+ v2Trade = new v2Sdk.Trade(route, amount, tradeType);
1421
+ inputAmount = v2Trade.inputAmount, outputAmount = v2Trade.outputAmount;
1422
+ v2Routes = [{
1423
+ routev2: route,
1424
+ inputAmount: inputAmount,
1425
+ outputAmount: outputAmount
1426
+ }];
1427
+ _context2.n = 8;
1428
+ break;
1429
+ case 1:
1430
+ if (!(route instanceof v3Sdk.Route)) {
1431
+ _context2.n = 3;
1432
+ break;
1433
+ }
1434
+ _context2.n = 2;
1435
+ return v3Sdk.Trade.fromRoute(route, amount, tradeType);
1436
+ case 2:
1437
+ v3Trade = _context2.v;
1438
+ _inputAmount7 = v3Trade.inputAmount, _outputAmount7 = v3Trade.outputAmount;
1439
+ v3Routes = [{
1440
+ routev3: route,
1441
+ inputAmount: _inputAmount7,
1442
+ outputAmount: _outputAmount7
1443
+ }];
1444
+ _context2.n = 8;
1445
+ break;
1446
+ case 3:
1447
+ if (!(route instanceof v4Sdk.Route)) {
1448
+ _context2.n = 5;
1449
+ break;
1450
+ }
1451
+ _context2.n = 4;
1452
+ return v4Sdk.Trade.fromRoute(route, amount, tradeType);
1453
+ case 4:
1454
+ v4Trade = _context2.v;
1455
+ _inputAmount8 = v4Trade.inputAmount, _outputAmount8 = v4Trade.outputAmount;
1456
+ v4Routes = [{
1457
+ routev4: route,
1458
+ inputAmount: _inputAmount8,
1459
+ outputAmount: _outputAmount8
1460
+ }];
1461
+ _context2.n = 8;
1462
+ break;
1463
+ case 5:
1464
+ if (!(route instanceof MixedRouteSDK)) {
1465
+ _context2.n = 7;
1466
+ break;
1467
+ }
1468
+ _context2.n = 6;
1469
+ return MixedRouteTrade.fromRoute(route, amount, tradeType);
1470
+ case 6:
1471
+ mixedRouteTrade = _context2.v;
1472
+ _inputAmount9 = mixedRouteTrade.inputAmount, _outputAmount9 = mixedRouteTrade.outputAmount;
1473
+ mixedRoutes = [{
1474
+ mixedRoute: route,
1475
+ inputAmount: _inputAmount9,
1476
+ outputAmount: _outputAmount9
1477
+ }];
1478
+ _context2.n = 8;
1479
+ break;
1480
+ case 7:
1481
+ throw new Error('Invalid route type');
1482
+ case 8:
1483
+ return _context2.a(2, new Trade({
1484
+ v2Routes: v2Routes,
1485
+ v3Routes: v3Routes,
1486
+ v4Routes: v4Routes,
1487
+ mixedRoutes: mixedRoutes,
1488
+ tradeType: tradeType
1489
+ }));
1490
+ }
1491
+ }, _callee2);
1492
+ }));
1493
+ function fromRoute(_x6, _x7, _x8) {
1494
+ return _fromRoute.apply(this, arguments);
1495
+ }
1496
+ return fromRoute;
1497
+ }();
1498
+ return _createClass(Trade, [{
1499
+ key: "inputAmount",
1500
+ get: function get() {
1501
+ if (this._inputAmount) {
1502
+ return this._inputAmount;
1503
+ }
1504
+ var inputAmountCurrency = this.swaps[0].inputAmount.currency;
1505
+ var totalInputFromRoutes = this.swaps.map(function (_ref5) {
1506
+ var routeInputAmount = _ref5.inputAmount;
1507
+ return routeInputAmount;
1508
+ }).reduce(function (total, cur) {
1509
+ return total.add(cur);
1510
+ }, sdkCore.CurrencyAmount.fromRawAmount(inputAmountCurrency, 0));
1511
+ this._inputAmount = totalInputFromRoutes;
1512
+ return this._inputAmount;
1513
+ }
1514
+ }, {
1515
+ key: "outputAmount",
1516
+ get: function get() {
1517
+ if (this._outputAmount) {
1518
+ return this._outputAmount;
1519
+ }
1520
+ var outputCurrency = this.swaps[0].outputAmount.currency;
1521
+ var totalOutputFromRoutes = this.swaps.map(function (_ref6) {
1522
+ var routeOutputAmount = _ref6.outputAmount;
1523
+ return routeOutputAmount;
1524
+ }).reduce(function (total, cur) {
1525
+ return total.add(cur);
1526
+ }, sdkCore.CurrencyAmount.fromRawAmount(outputCurrency, 0));
1527
+ this._outputAmount = totalOutputFromRoutes;
1528
+ return this._outputAmount;
1529
+ }
1530
+ /**
1531
+ * Returns the sum of all swaps within the trade
1532
+ * @returns
1533
+ * inputAmount: total input amount
1534
+ * inputAmountNative: total amount of native currency required for ETH input paths
1535
+ * - 0 if inputAmount is native but no native input paths
1536
+ * - undefined if inputAmount is not native
1537
+ * outputAmount: total output amount
1538
+ * outputAmountNative: total amount of native currency returned from ETH output paths
1539
+ * - 0 if outputAmount is native but no native output paths
1540
+ * - undefined if outputAmount is not native
1541
+ */
1542
+ }, {
1543
+ key: "amounts",
1544
+ get: function get() {
1545
+ var _this$swaps$find, _this$swaps$find2;
1546
+ // Find native currencies for reduce below
1547
+ var inputNativeCurrency = (_this$swaps$find = this.swaps.find(function (_ref7) {
1548
+ var inputAmount = _ref7.inputAmount;
1549
+ return inputAmount.currency.isNative;
1550
+ })) == null ? void 0 : _this$swaps$find.inputAmount.currency;
1551
+ var outputNativeCurrency = (_this$swaps$find2 = this.swaps.find(function (_ref8) {
1552
+ var outputAmount = _ref8.outputAmount;
1553
+ return outputAmount.currency.isNative;
1554
+ })) == null ? void 0 : _this$swaps$find2.outputAmount.currency;
1555
+ return {
1556
+ inputAmount: this.inputAmount,
1557
+ inputAmountNative: inputNativeCurrency ? this.swaps.reduce(function (total, swap) {
1558
+ return swap.route.pathInput.isNative ? total.add(swap.inputAmount) : total;
1559
+ }, sdkCore.CurrencyAmount.fromRawAmount(inputNativeCurrency, 0)) : undefined,
1560
+ outputAmount: this.outputAmount,
1561
+ outputAmountNative: outputNativeCurrency ? this.swaps.reduce(function (total, swap) {
1562
+ return swap.route.pathOutput.isNative ? total.add(swap.outputAmount) : total;
1563
+ }, sdkCore.CurrencyAmount.fromRawAmount(outputNativeCurrency, 0)) : undefined
1564
+ };
1565
+ }
1566
+ }, {
1567
+ key: "numberOfInputWraps",
1568
+ get: function get() {
1569
+ // if the trade's input is eth it may require a wrap
1570
+ if (this.inputAmount.currency.isNative) {
1571
+ return this.wethInputRoutes.length;
1572
+ } else return 0;
1573
+ }
1574
+ }, {
1575
+ key: "numberOfInputUnwraps",
1576
+ get: function get() {
1577
+ // if the trade's input is weth, it may require an unwrap
1578
+ if (this.isWrappedNative(this.inputAmount.currency)) {
1579
+ return this.nativeInputRoutes.length;
1580
+ } else return 0;
1581
+ }
1582
+ }, {
1583
+ key: "nativeInputRoutes",
1584
+ get: function get() {
1585
+ if (this._nativeInputRoutes) {
1586
+ return this._nativeInputRoutes;
1587
+ }
1588
+ this._nativeInputRoutes = this.routes.filter(function (route) {
1589
+ return route.pathInput.isNative;
1590
+ });
1591
+ return this._nativeInputRoutes;
1592
+ }
1593
+ }, {
1594
+ key: "wethInputRoutes",
1595
+ get: function get() {
1596
+ var _this = this;
1597
+ if (this._wethInputRoutes) {
1598
+ return this._wethInputRoutes;
1599
+ }
1600
+ this._wethInputRoutes = this.routes.filter(function (route) {
1601
+ return _this.isWrappedNative(route.pathInput);
1602
+ });
1603
+ return this._wethInputRoutes;
1604
+ }
1605
+ /**
1606
+ * The price expressed in terms of output amount/input amount.
1607
+ */
1608
+ }, {
1609
+ key: "executionPrice",
1610
+ get: function get() {
1611
+ var _this$_executionPrice;
1612
+ return (_this$_executionPrice = this._executionPrice) != null ? _this$_executionPrice : this._executionPrice = new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.inputAmount.quotient, this.outputAmount.quotient);
1613
+ }
1614
+ /**
1615
+ * Returns the sell tax of the input token
1616
+ */
1617
+ }, {
1618
+ key: "inputTax",
1619
+ get: function get() {
1620
+ var inputCurrency = this.inputAmount.currency;
1621
+ if (inputCurrency.isNative || !inputCurrency.wrapped.sellFeeBps) return ZERO_PERCENT;
1622
+ return new sdkCore.Percent(inputCurrency.wrapped.sellFeeBps.toNumber(), 10000);
1623
+ }
1624
+ /**
1625
+ * Returns the buy tax of the output token
1626
+ */
1627
+ }, {
1628
+ key: "outputTax",
1629
+ get: function get() {
1630
+ var outputCurrency = this.outputAmount.currency;
1631
+ if (outputCurrency.isNative || !outputCurrency.wrapped.buyFeeBps) return ZERO_PERCENT;
1632
+ return new sdkCore.Percent(outputCurrency.wrapped.buyFeeBps.toNumber(), 10000);
1633
+ }
1634
+ }, {
1635
+ key: "priceImpact",
1636
+ get: function get() {
1637
+ if (this._priceImpact) {
1638
+ return this._priceImpact;
1639
+ }
1640
+ // returns 0% price impact even though this may be inaccurate as a swap may have occured.
1641
+ // because we're unable to derive the pre-buy-tax amount, use 0% as a placeholder.
1642
+ if (this.outputTax.equalTo(ONE_HUNDRED_PERCENT)) return ZERO_PERCENT;
1643
+ var spotOutputAmount = sdkCore.CurrencyAmount.fromRawAmount(this.outputAmount.currency, 0);
1644
+ for (var _iterator1 = _createForOfIteratorHelperLoose(this.swaps), _step1; !(_step1 = _iterator1()).done;) {
1645
+ var _step1$value = _step1.value,
1646
+ route = _step1$value.route,
1647
+ inputAmount = _step1$value.inputAmount;
1648
+ var midPrice = route.midPrice;
1649
+ var postTaxInputAmount = inputAmount.multiply(new sdkCore.Fraction(ONE).subtract(this.inputTax));
1650
+ spotOutputAmount = spotOutputAmount.add(midPrice.quote(postTaxInputAmount));
1651
+ }
1652
+ // if the total output of this trade is 0, then most likely the post-tax input was also 0, and therefore this swap
1653
+ // does not move the pools' market price
1654
+ if (spotOutputAmount.equalTo(ZERO)) return ZERO_PERCENT;
1655
+ var preTaxOutputAmount = this.outputAmount.divide(new sdkCore.Fraction(ONE).subtract(this.outputTax));
1656
+ var priceImpact = spotOutputAmount.subtract(preTaxOutputAmount).divide(spotOutputAmount);
1657
+ this._priceImpact = new sdkCore.Percent(priceImpact.numerator, priceImpact.denominator);
1658
+ return this._priceImpact;
1659
+ }
1660
+ }]);
1661
+ }();
1662
+
1663
+ /**
1664
+ * Converts a route to a hex encoded path
1665
+ * @notice only supports exactIn route encodings
1666
+ * @param route the mixed path to convert to an encoded path
1667
+ * @param useMixedRouterQuoteV2 if true, uses the Mixed Quoter V2 encoding for v4 pools. By default, we do not set it. This is only used in SOR for explicit setting during onchain quoting.
1668
+ * @returns the exactIn encoded path
1669
+ */
1670
+ function encodeMixedRouteToPath(route, useMixedRouterQuoteV2) {
1671
+ var containsV4Pool = useMixedRouterQuoteV2 != null ? useMixedRouterQuoteV2 : route.pools.some(function (pool) {
1672
+ return pool instanceof v4Sdk.Pool;
1673
+ });
1674
+ var path;
1675
+ var types;
1676
+ if (containsV4Pool) {
1677
+ path = [route.pathInput.isNative ? ADDRESS_ZERO : route.pathInput.address];
1678
+ types = ['address'];
1679
+ var currencyIn = route.pathInput;
1680
+ for (var _iterator = _createForOfIteratorHelperLoose(route.pools), _step; !(_step = _iterator()).done;) {
1681
+ var pool = _step.value;
1682
+ var currencyOut = currencyIn.equals(pool.token0) ? pool.token1 : pool.token0;
1683
+ if (pool instanceof v4Sdk.Pool) {
1684
+ // a tickSpacing of 0 indicates a "fake" v4 pool where the quote actually requires a wrap or unwrap
1685
+ // the fake v4 pool will always have native as token0 and wrapped native as token1
1686
+ if (pool.tickSpacing === 0) {
1687
+ var wrapOrUnwrapEncoding = 0;
1688
+ path.push(wrapOrUnwrapEncoding, currencyOut.isNative ? ADDRESS_ZERO : currencyOut.wrapped.address);
1689
+ types.push('uint8', 'address');
1690
+ } else {
1691
+ var v4Fee = pool.fee + MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER;
1692
+ path.push(v4Fee, pool.tickSpacing, pool.hooks, currencyOut.isNative ? ADDRESS_ZERO : currencyOut.wrapped.address);
1693
+ types.push('uint24', 'uint24', 'address', 'address');
1694
+ }
1695
+ } else if (pool instanceof v3Sdk.Pool) {
1696
+ var v3Fee = pool.fee + MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER;
1697
+ path.push(v3Fee, currencyOut.wrapped.address);
1698
+ types.push('uint24', 'address');
1699
+ } else if (pool instanceof v2Sdk.Pair) {
1700
+ var v2Fee = MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER;
1701
+ path.push(v2Fee, currencyOut.wrapped.address);
1702
+ types.push('uint8', 'address');
1703
+ } else {
1704
+ throw new Error("Unsupported pool type " + JSON.stringify(pool));
1705
+ }
1706
+ currencyIn = currencyOut;
1707
+ }
1708
+ } else {
1709
+ // TODO: ROUTE-276 - delete this else block
1710
+ // We introduced this else block as a safety measure to prevent non-v4 mixed routes from potentially regressing
1711
+ // We'd like to gain more confidence in the new implementation before removing this block
1712
+ var result = route.pools.reduce(function (_ref, pool, index) {
1713
+ var inputToken = _ref.inputToken,
1714
+ path = _ref.path,
1715
+ types = _ref.types;
1716
+ var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
1717
+ if (index === 0) {
1718
+ return {
1719
+ inputToken: outputToken,
1720
+ types: ['address', 'uint24', 'address'],
1721
+ path: [inputToken.wrapped.address, pool instanceof v3Sdk.Pool ? pool.fee : MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER, outputToken.wrapped.address]
1722
+ };
1723
+ } else {
1724
+ return {
1725
+ inputToken: outputToken,
1726
+ types: [].concat(types, ['uint24', 'address']),
1727
+ path: [].concat(path, [pool instanceof v3Sdk.Pool ? pool.fee : MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER, outputToken.wrapped.address])
1728
+ };
1729
+ }
1730
+ }, {
1731
+ inputToken: route.input,
1732
+ path: [],
1733
+ types: []
1734
+ });
1735
+ path = result.path;
1736
+ types = result.types;
1737
+ }
1738
+ return solidity.pack(types, path);
1739
+ }
1740
+
1741
+ /**
1742
+ * Utility function to return each consecutive section of Pools or Pairs in a MixedRoute
1743
+ * @param route
1744
+ * @returns a nested array of Pools or Pairs in the order of the route
1745
+ */
1746
+ var partitionMixedRouteByProtocol = function partitionMixedRouteByProtocol(route) {
1747
+ var acc = [];
1748
+ var left = 0;
1749
+ var right = 0;
1750
+ while (right < route.pools.length) {
1751
+ if (route.pools[left] instanceof v4Sdk.Pool && !(route.pools[right] instanceof v4Sdk.Pool) || route.pools[left] instanceof v3Sdk.Pool && !(route.pools[right] instanceof v3Sdk.Pool) || route.pools[left] instanceof v2Sdk.Pair && !(route.pools[right] instanceof v2Sdk.Pair)) {
1752
+ acc.push(route.pools.slice(left, right));
1753
+ left = right;
1754
+ }
1755
+ // seek forward with right pointer
1756
+ right++;
1757
+ if (right === route.pools.length) {
1758
+ /// we reached the end, take the rest
1759
+ acc.push(route.pools.slice(left, right));
1760
+ }
1761
+ }
1762
+ return acc;
1763
+ };
1764
+ /**
1765
+ * Simple utility function to get the output of an array of Pools or Pairs
1766
+ * @param pools
1767
+ * @param firstInputToken
1768
+ * @returns the output token of the last pool in the array
1769
+ */
1770
+ var getOutputOfPools = function getOutputOfPools(pools, firstInputToken) {
1771
+ var _pools$reduce = pools.reduce(function (_ref, pool) {
1772
+ var inputToken = _ref.inputToken;
1773
+ if (!pool.involvesToken(inputToken)) throw new Error('PATH');
1774
+ var outputToken = pool.token0.equals(inputToken) ? pool.token1 : pool.token0;
1775
+ return {
1776
+ inputToken: outputToken
1777
+ };
1778
+ }, {
1779
+ inputToken: firstInputToken
1780
+ }),
1781
+ outputToken = _pools$reduce.inputToken;
1782
+ return outputToken;
1783
+ };
1784
+
1785
+ var ZERO$1 = /*#__PURE__*/JSBI.BigInt(0);
1786
+ var REFUND_ETH_PRICE_IMPACT_THRESHOLD = /*#__PURE__*/new sdkCore.Percent(/*#__PURE__*/JSBI.BigInt(50), /*#__PURE__*/JSBI.BigInt(100));
1787
+ /**
1788
+ * Represents the Uniswap V2 + V3 SwapRouter02, and has static methods for helping execute trades.
1789
+ */
1790
+ var SwapRouter = /*#__PURE__*/function () {
1791
+ /**
1792
+ * Cannot be constructed.
1793
+ */
1794
+ function SwapRouter() {}
1795
+ /**
1796
+ * @notice Generates the calldata for a Swap with a V2 Route.
1797
+ * @param trade The V2Trade to encode.
1798
+ * @param options SwapOptions to use for the trade.
1799
+ * @param routerMustCustody Flag for whether funds should be sent to the router
1800
+ * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check
1801
+ * @returns A string array of calldatas for the trade.
1802
+ */
1803
+ SwapRouter.encodeV2Swap = function encodeV2Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck) {
1804
+ var amountIn = v3Sdk.toHex(trade.maximumAmountIn(options.slippageTolerance).quotient);
1805
+ var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance).quotient);
1806
+ var path = trade.route.path.map(function (token) {
1807
+ return token.address;
1808
+ });
1809
+ var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : sdkCore.validateAndParseAddress(options.recipient);
1810
+ if (trade.tradeType === sdkCore.TradeType.EXACT_INPUT) {
1811
+ var exactInputParams = [amountIn, performAggregatedSlippageCheck ? 0 : amountOut, path, recipient];
1812
+ return SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams);
1813
+ } else {
1814
+ var exactOutputParams = [amountOut, amountIn, path, recipient];
1815
+ return SwapRouter.INTERFACE.encodeFunctionData('swapTokensForExactTokens', exactOutputParams);
1816
+ }
1817
+ }
1818
+ /**
1819
+ * @notice Generates the calldata for a Swap with a V3 Route.
1820
+ * @param trade The V3Trade to encode.
1821
+ * @param options SwapOptions to use for the trade.
1822
+ * @param routerMustCustody Flag for whether funds should be sent to the router
1823
+ * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check
1824
+ * @returns A string array of calldatas for the trade.
1825
+ */;
1826
+ SwapRouter.encodeV3Swap = function encodeV3Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck) {
1827
+ var calldatas = [];
1828
+ for (var _iterator = _createForOfIteratorHelperLoose(trade.swaps), _step; !(_step = _iterator()).done;) {
1829
+ var _step$value = _step.value,
1830
+ route = _step$value.route,
1831
+ inputAmount = _step$value.inputAmount,
1832
+ outputAmount = _step$value.outputAmount;
1833
+ var amountIn = v3Sdk.toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
1834
+ var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
1835
+ // flag for whether the trade is single hop or not
1836
+ var singleHop = route.pools.length === 1;
1837
+ var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : sdkCore.validateAndParseAddress(options.recipient);
1838
+ if (singleHop) {
1839
+ if (trade.tradeType === sdkCore.TradeType.EXACT_INPUT) {
1840
+ var exactInputSingleParams = {
1841
+ tokenIn: route.tokenPath[0].address,
1842
+ tokenOut: route.tokenPath[1].address,
1843
+ fee: route.pools[0].fee,
1844
+ recipient: recipient,
1845
+ amountIn: amountIn,
1846
+ amountOutMinimum: performAggregatedSlippageCheck ? 0 : amountOut,
1847
+ sqrtPriceLimitX96: 0
1848
+ };
1849
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]));
1850
+ } else {
1851
+ var exactOutputSingleParams = {
1852
+ tokenIn: route.tokenPath[0].address,
1853
+ tokenOut: route.tokenPath[1].address,
1854
+ fee: route.pools[0].fee,
1855
+ recipient: recipient,
1856
+ amountOut: amountOut,
1857
+ amountInMaximum: amountIn,
1858
+ sqrtPriceLimitX96: 0
1859
+ };
1860
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactOutputSingle', [exactOutputSingleParams]));
1861
+ }
1862
+ } else {
1863
+ var path = v3Sdk.encodeRouteToPath(route, trade.tradeType === sdkCore.TradeType.EXACT_OUTPUT);
1864
+ if (trade.tradeType === sdkCore.TradeType.EXACT_INPUT) {
1865
+ var exactInputParams = {
1866
+ path: path,
1867
+ recipient: recipient,
1868
+ amountIn: amountIn,
1869
+ amountOutMinimum: performAggregatedSlippageCheck ? 0 : amountOut
1870
+ };
1871
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [exactInputParams]));
1872
+ } else {
1873
+ var exactOutputParams = {
1874
+ path: path,
1875
+ recipient: recipient,
1876
+ amountOut: amountOut,
1877
+ amountInMaximum: amountIn
1878
+ };
1879
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactOutput', [exactOutputParams]));
1880
+ }
1881
+ }
1882
+ }
1883
+ return calldatas;
1884
+ }
1885
+ /**
1886
+ * @notice Generates the calldata for a MixedRouteSwap. Since single hop routes are not MixedRoutes, we will instead generate
1887
+ * them via the existing encodeV3Swap and encodeV2Swap methods.
1888
+ * @param trade The MixedRouteTrade to encode.
1889
+ * @param options SwapOptions to use for the trade.
1890
+ * @param routerMustCustody Flag for whether funds should be sent to the router
1891
+ * @param performAggregatedSlippageCheck Flag for whether we want to perform an aggregated slippage check
1892
+ * @returns A string array of calldatas for the trade.
1893
+ */;
1894
+ SwapRouter.encodeMixedRouteSwap = function encodeMixedRouteSwap(trade, options, routerMustCustody, performAggregatedSlippageCheck) {
1895
+ var calldatas = [];
1896
+ !(trade.tradeType === sdkCore.TradeType.EXACT_INPUT) ? invariant(false, 'TRADE_TYPE') : void 0;
1897
+ var _loop = function _loop() {
1898
+ var _step2$value = _step2.value,
1899
+ route = _step2$value.route,
1900
+ inputAmount = _step2$value.inputAmount,
1901
+ outputAmount = _step2$value.outputAmount;
1902
+ if (route.pools.some(function (pool) {
1903
+ return pool instanceof v4Sdk.Pool;
1904
+ })) throw new Error('Encoding mixed routes with V4 not supported');
1905
+ var amountIn = v3Sdk.toHex(trade.maximumAmountIn(options.slippageTolerance, inputAmount).quotient);
1906
+ var amountOut = v3Sdk.toHex(trade.minimumAmountOut(options.slippageTolerance, outputAmount).quotient);
1907
+ // flag for whether the trade is single hop or not
1908
+ var singleHop = route.pools.length === 1;
1909
+ var recipient = routerMustCustody ? ADDRESS_THIS : typeof options.recipient === 'undefined' ? MSG_SENDER : sdkCore.validateAndParseAddress(options.recipient);
1910
+ var mixedRouteIsAllV3 = function mixedRouteIsAllV3(route) {
1911
+ return route.pools.every(function (pool) {
1912
+ return pool instanceof v3Sdk.Pool;
1913
+ });
1914
+ };
1915
+ if (singleHop) {
1916
+ /// For single hop, since it isn't really a mixedRoute, we'll just mimic behavior of V3 or V2
1917
+ /// We don't use encodeV3Swap() or encodeV2Swap() because casting the trade to a V3Trade or V2Trade is overcomplex
1918
+ if (mixedRouteIsAllV3(route)) {
1919
+ var exactInputSingleParams = {
1920
+ tokenIn: route.path[0].wrapped.address,
1921
+ tokenOut: route.path[1].wrapped.address,
1922
+ fee: route.pools[0].fee,
1923
+ recipient: recipient,
1924
+ amountIn: amountIn,
1925
+ amountOutMinimum: performAggregatedSlippageCheck ? 0 : amountOut,
1926
+ sqrtPriceLimitX96: 0
1927
+ };
1928
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInputSingle', [exactInputSingleParams]));
1929
+ } else {
1930
+ var path = route.path.map(function (token) {
1931
+ return token.wrapped.address;
1932
+ });
1933
+ var exactInputParams = [amountIn, performAggregatedSlippageCheck ? 0 : amountOut, path, recipient];
1934
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', exactInputParams));
1935
+ }
1936
+ } else {
1937
+ var sections = partitionMixedRouteByProtocol(route);
1938
+ var isLastSectionInRoute = function isLastSectionInRoute(i) {
1939
+ return i === sections.length - 1;
1940
+ };
1941
+ var outputToken;
1942
+ var inputToken = route.input.wrapped;
1943
+ for (var i = 0; i < sections.length; i++) {
1944
+ var section = sections[i];
1945
+ /// Now, we get output of this section
1946
+ outputToken = getOutputOfPools(section, inputToken);
1947
+ var newRouteOriginal = new MixedRouteSDK([].concat(section), section[0].token0.equals(inputToken) ? section[0].token0 : section[0].token1, outputToken);
1948
+ var newRoute = new MixedRoute(newRouteOriginal);
1949
+ /// Previous output is now input
1950
+ inputToken = outputToken.wrapped;
1951
+ if (mixedRouteIsAllV3(newRoute)) {
1952
+ var _path = encodeMixedRouteToPath(newRoute);
1953
+ var _exactInputParams = {
1954
+ path: _path,
1955
+ // By default router holds funds until the last swap, then it is sent to the recipient
1956
+ // special case exists where we are unwrapping WETH output, in which case `routerMustCustody` is set to true
1957
+ // and router still holds the funds. That logic bundled into how the value of `recipient` is calculated
1958
+ recipient: isLastSectionInRoute(i) ? recipient : ADDRESS_THIS,
1959
+ amountIn: i === 0 ? amountIn : 0,
1960
+ amountOutMinimum: !isLastSectionInRoute(i) ? 0 : amountOut
1961
+ };
1962
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('exactInput', [_exactInputParams]));
1963
+ } else {
1964
+ var _exactInputParams2 = [i === 0 ? amountIn : 0, !isLastSectionInRoute(i) ? 0 : amountOut, newRoute.path.map(function (token) {
1965
+ return token.wrapped.address;
1966
+ }), isLastSectionInRoute(i) ? recipient : ADDRESS_THIS];
1967
+ calldatas.push(SwapRouter.INTERFACE.encodeFunctionData('swapExactTokensForTokens', _exactInputParams2));
1968
+ }
1969
+ }
1970
+ }
1971
+ };
1972
+ for (var _iterator2 = _createForOfIteratorHelperLoose(trade.swaps), _step2; !(_step2 = _iterator2()).done;) {
1973
+ _loop();
1974
+ }
1975
+ return calldatas;
1976
+ };
1977
+ SwapRouter.encodeSwaps = function encodeSwaps(trades, options, isSwapAndAdd) {
1978
+ // If dealing with an instance of the aggregated Trade object, unbundle it to individual trade objects.
1979
+ if (trades instanceof Trade) {
1980
+ !trades.swaps.every(function (swap) {
1981
+ return swap.route.protocol === exports.Protocol.V3 || swap.route.protocol === exports.Protocol.V2 || swap.route.protocol === exports.Protocol.MIXED;
1982
+ }) ? invariant(false, 'UNSUPPORTED_PROTOCOL (encoding routes with v4 not supported)') : void 0;
1983
+ var individualTrades = [];
1984
+ for (var _iterator3 = _createForOfIteratorHelperLoose(trades.swaps), _step3; !(_step3 = _iterator3()).done;) {
1985
+ var _step3$value = _step3.value,
1986
+ route = _step3$value.route,
1987
+ inputAmount = _step3$value.inputAmount,
1988
+ outputAmount = _step3$value.outputAmount;
1989
+ if (route.protocol === exports.Protocol.V2) {
1990
+ individualTrades.push(new v2Sdk.Trade(route, trades.tradeType === sdkCore.TradeType.EXACT_INPUT ? inputAmount : outputAmount, trades.tradeType));
1991
+ } else if (route.protocol === exports.Protocol.V3) {
1992
+ individualTrades.push(v3Sdk.Trade.createUncheckedTrade({
1993
+ route: route,
1994
+ inputAmount: inputAmount,
1995
+ outputAmount: outputAmount,
1996
+ tradeType: trades.tradeType
1997
+ }));
1998
+ } else if (route.protocol === exports.Protocol.MIXED) {
1999
+ individualTrades.push(
2000
+ /// we can change the naming of this function on MixedRouteTrade if needed
2001
+ MixedRouteTrade.createUncheckedTrade({
2002
+ route: route,
2003
+ inputAmount: inputAmount,
2004
+ outputAmount: outputAmount,
2005
+ tradeType: trades.tradeType
2006
+ }));
2007
+ } else {
2008
+ throw new Error('UNSUPPORTED_TRADE_PROTOCOL');
2009
+ }
2010
+ }
2011
+ trades = individualTrades;
2012
+ }
2013
+ if (!Array.isArray(trades)) {
2014
+ trades = [trades];
2015
+ }
2016
+ var numberOfTrades = trades.reduce(function (numberOfTrades, trade) {
2017
+ return numberOfTrades + (trade instanceof v3Sdk.Trade || trade instanceof MixedRouteTrade ? trade.swaps.length : 1);
2018
+ }, 0);
2019
+ var sampleTrade = trades[0];
2020
+ // All trades should have the same starting/ending currency and trade type
2021
+ !trades.every(function (trade) {
2022
+ return trade.inputAmount.currency.equals(sampleTrade.inputAmount.currency);
2023
+ }) ? invariant(false, 'TOKEN_IN_DIFF') : void 0;
2024
+ !trades.every(function (trade) {
2025
+ return trade.outputAmount.currency.equals(sampleTrade.outputAmount.currency);
2026
+ }) ? invariant(false, 'TOKEN_OUT_DIFF') : void 0;
2027
+ !trades.every(function (trade) {
2028
+ return trade.tradeType === sampleTrade.tradeType;
2029
+ }) ? invariant(false, 'TRADE_TYPE_DIFF') : void 0;
2030
+ var calldatas = [];
2031
+ var inputIsNative = sampleTrade.inputAmount.currency.isNative;
2032
+ var outputIsNative = sampleTrade.outputAmount.currency.isNative;
2033
+ // flag for whether we want to perform an aggregated slippage check
2034
+ // 1. when there are >2 exact input trades. this is only a heuristic,
2035
+ // as it's still more gas-expensive even in this case, but has benefits
2036
+ // in that the reversion probability is lower
2037
+ var performAggregatedSlippageCheck = sampleTrade.tradeType === sdkCore.TradeType.EXACT_INPUT && numberOfTrades > 2;
2038
+ // flag for whether funds should be send first to the router
2039
+ // 1. when receiving ETH (which much be unwrapped from WETH)
2040
+ // 2. when a fee on the output is being taken
2041
+ // 3. when performing swap and add
2042
+ // 4. when performing an aggregated slippage check
2043
+ var routerMustCustody = outputIsNative || !!options.fee || !!isSwapAndAdd || performAggregatedSlippageCheck;
2044
+ // encode permit if necessary
2045
+ if (options.inputTokenPermit) {
2046
+ !sampleTrade.inputAmount.currency.isToken ? invariant(false, 'NON_TOKEN_PERMIT') : void 0;
2047
+ calldatas.push(v3Sdk.SelfPermit.encodePermit(sampleTrade.inputAmount.currency, options.inputTokenPermit));
2048
+ }
2049
+ for (var _iterator4 = _createForOfIteratorHelperLoose(trades), _step4; !(_step4 = _iterator4()).done;) {
2050
+ var trade = _step4.value;
2051
+ if (trade instanceof v2Sdk.Trade) {
2052
+ calldatas.push(SwapRouter.encodeV2Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck));
2053
+ } else if (trade instanceof v3Sdk.Trade) {
2054
+ for (var _iterator5 = _createForOfIteratorHelperLoose(SwapRouter.encodeV3Swap(trade, options, routerMustCustody, performAggregatedSlippageCheck)), _step5; !(_step5 = _iterator5()).done;) {
2055
+ var calldata = _step5.value;
2056
+ calldatas.push(calldata);
2057
+ }
2058
+ } else if (trade instanceof MixedRouteTrade) {
2059
+ for (var _iterator6 = _createForOfIteratorHelperLoose(SwapRouter.encodeMixedRouteSwap(trade, options, routerMustCustody, performAggregatedSlippageCheck)), _step6; !(_step6 = _iterator6()).done;) {
2060
+ var _calldata = _step6.value;
2061
+ calldatas.push(_calldata);
2062
+ }
2063
+ } else {
2064
+ throw new Error('Unsupported trade object');
2065
+ }
2066
+ }
2067
+ var ZERO_IN = sdkCore.CurrencyAmount.fromRawAmount(sampleTrade.inputAmount.currency, 0);
2068
+ var ZERO_OUT = sdkCore.CurrencyAmount.fromRawAmount(sampleTrade.outputAmount.currency, 0);
2069
+ var minimumAmountOut = trades.reduce(function (sum, trade) {
2070
+ return sum.add(trade.minimumAmountOut(options.slippageTolerance));
2071
+ }, ZERO_OUT);
2072
+ var quoteAmountOut = trades.reduce(function (sum, trade) {
2073
+ return sum.add(trade.outputAmount);
2074
+ }, ZERO_OUT);
2075
+ var totalAmountIn = trades.reduce(function (sum, trade) {
2076
+ return sum.add(trade.maximumAmountIn(options.slippageTolerance));
2077
+ }, ZERO_IN);
2078
+ return {
2079
+ calldatas: calldatas,
2080
+ sampleTrade: sampleTrade,
2081
+ routerMustCustody: routerMustCustody,
2082
+ inputIsNative: inputIsNative,
2083
+ outputIsNative: outputIsNative,
2084
+ totalAmountIn: totalAmountIn,
2085
+ minimumAmountOut: minimumAmountOut,
2086
+ quoteAmountOut: quoteAmountOut
2087
+ };
2088
+ }
2089
+ /**
2090
+ * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
2091
+ * @param trades to produce call parameters for
2092
+ * @param options options for the call parameters
2093
+ */;
2094
+ SwapRouter.swapCallParameters = function swapCallParameters(trades, options) {
2095
+ var _SwapRouter$encodeSwa = SwapRouter.encodeSwaps(trades, options),
2096
+ calldatas = _SwapRouter$encodeSwa.calldatas,
2097
+ sampleTrade = _SwapRouter$encodeSwa.sampleTrade,
2098
+ routerMustCustody = _SwapRouter$encodeSwa.routerMustCustody,
2099
+ inputIsNative = _SwapRouter$encodeSwa.inputIsNative,
2100
+ outputIsNative = _SwapRouter$encodeSwa.outputIsNative,
2101
+ totalAmountIn = _SwapRouter$encodeSwa.totalAmountIn,
2102
+ minimumAmountOut = _SwapRouter$encodeSwa.minimumAmountOut;
2103
+ // unwrap or sweep
2104
+ if (routerMustCustody) {
2105
+ if (outputIsNative) {
2106
+ calldatas.push(PaymentsExtended.encodeUnwrapWETH9(minimumAmountOut.quotient, options.recipient, options.fee));
2107
+ } else {
2108
+ calldatas.push(PaymentsExtended.encodeSweepToken(sampleTrade.outputAmount.currency.wrapped, minimumAmountOut.quotient, options.recipient, options.fee));
2109
+ }
2110
+ }
2111
+ // must refund when paying in ETH: either with an uncertain input amount OR if there's a chance of a partial fill.
2112
+ // unlike ERC20's, the full ETH value must be sent in the transaction, so the rest must be refunded.
2113
+ if (inputIsNative && (sampleTrade.tradeType === sdkCore.TradeType.EXACT_OUTPUT || SwapRouter.riskOfPartialFill(trades))) {
2114
+ calldatas.push(v3Sdk.Payments.encodeRefundETH());
2115
+ }
2116
+ return {
2117
+ calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),
2118
+ value: v3Sdk.toHex(inputIsNative ? totalAmountIn.quotient : ZERO$1)
2119
+ };
2120
+ }
2121
+ /**
2122
+ * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.
2123
+ * @param trades to produce call parameters for
2124
+ * @param options options for the call parameters
2125
+ */;
2126
+ SwapRouter.swapAndAddCallParameters = function swapAndAddCallParameters(trades, options, position, addLiquidityOptions, tokenInApprovalType, tokenOutApprovalType) {
2127
+ var _SwapRouter$encodeSwa2 = SwapRouter.encodeSwaps(trades, options, true),
2128
+ calldatas = _SwapRouter$encodeSwa2.calldatas,
2129
+ inputIsNative = _SwapRouter$encodeSwa2.inputIsNative,
2130
+ outputIsNative = _SwapRouter$encodeSwa2.outputIsNative,
2131
+ sampleTrade = _SwapRouter$encodeSwa2.sampleTrade,
2132
+ totalAmountSwapped = _SwapRouter$encodeSwa2.totalAmountIn,
2133
+ quoteAmountOut = _SwapRouter$encodeSwa2.quoteAmountOut,
2134
+ minimumAmountOut = _SwapRouter$encodeSwa2.minimumAmountOut;
2135
+ // encode output token permit if necessary
2136
+ if (options.outputTokenPermit) {
2137
+ !quoteAmountOut.currency.isToken ? invariant(false, 'NON_TOKEN_PERMIT_OUTPUT') : void 0;
2138
+ calldatas.push(v3Sdk.SelfPermit.encodePermit(quoteAmountOut.currency, options.outputTokenPermit));
2139
+ }
2140
+ var chainId = sampleTrade.route.chainId;
2141
+ var zeroForOne = position.pool.token0.wrapped.address === totalAmountSwapped.currency.wrapped.address;
2142
+ var _SwapRouter$getPositi = SwapRouter.getPositionAmounts(position, zeroForOne),
2143
+ positionAmountIn = _SwapRouter$getPositi.positionAmountIn,
2144
+ positionAmountOut = _SwapRouter$getPositi.positionAmountOut;
2145
+ // if tokens are native they will be converted to WETH9
2146
+ var tokenIn = inputIsNative ? sdkCore.WETH9[chainId] : positionAmountIn.currency.wrapped;
2147
+ var tokenOut = outputIsNative ? sdkCore.WETH9[chainId] : positionAmountOut.currency.wrapped;
2148
+ // if swap output does not make up whole outputTokenBalanceDesired, pull in remaining tokens for adding liquidity
2149
+ var amountOutRemaining = positionAmountOut.subtract(quoteAmountOut.wrapped);
2150
+ if (amountOutRemaining.greaterThan(sdkCore.CurrencyAmount.fromRawAmount(positionAmountOut.currency, 0))) {
2151
+ // if output is native, this means the remaining portion is included as native value in the transaction
2152
+ // and must be wrapped. Otherwise, pull in remaining ERC20 token.
2153
+ outputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(amountOutRemaining.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenOut, amountOutRemaining.quotient));
2154
+ }
2155
+ // if input is native, convert to WETH9, else pull ERC20 token
2156
+ inputIsNative ? calldatas.push(PaymentsExtended.encodeWrapETH(positionAmountIn.quotient)) : calldatas.push(PaymentsExtended.encodePull(tokenIn, positionAmountIn.quotient));
2157
+ // approve token balances to NFTManager
2158
+ if (tokenInApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenIn, tokenInApprovalType));
2159
+ if (tokenOutApprovalType !== exports.ApprovalTypes.NOT_REQUIRED) calldatas.push(ApproveAndCall.encodeApprove(tokenOut, tokenOutApprovalType));
2160
+ // represents a position with token amounts resulting from a swap with maximum slippage
2161
+ // hence the minimal amount out possible.
2162
+ var minimalPosition = v3Sdk.Position.fromAmounts({
2163
+ pool: position.pool,
2164
+ tickLower: position.tickLower,
2165
+ tickUpper: position.tickUpper,
2166
+ amount0: zeroForOne ? position.amount0.quotient.toString() : minimumAmountOut.quotient.toString(),
2167
+ amount1: zeroForOne ? minimumAmountOut.quotient.toString() : position.amount1.quotient.toString(),
2168
+ useFullPrecision: false
2169
+ });
2170
+ // encode NFTManager add liquidity
2171
+ calldatas.push(ApproveAndCall.encodeAddLiquidity(position, minimalPosition, addLiquidityOptions, options.slippageTolerance));
2172
+ // sweep remaining tokens
2173
+ inputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenIn, ZERO$1));
2174
+ outputIsNative ? calldatas.push(PaymentsExtended.encodeUnwrapWETH9(ZERO$1)) : calldatas.push(PaymentsExtended.encodeSweepToken(tokenOut, ZERO$1));
2175
+ var value;
2176
+ if (inputIsNative) {
2177
+ value = totalAmountSwapped.wrapped.add(positionAmountIn.wrapped).quotient;
2178
+ } else if (outputIsNative) {
2179
+ value = amountOutRemaining.quotient;
2180
+ } else {
2181
+ value = ZERO$1;
2182
+ }
2183
+ return {
2184
+ calldata: MulticallExtended.encodeMulticall(calldatas, options.deadlineOrPreviousBlockhash),
2185
+ value: value.toString()
2186
+ };
2187
+ }
2188
+ // if price impact is very high, there's a chance of hitting max/min prices resulting in a partial fill of the swap
2189
+ ;
2190
+ SwapRouter.riskOfPartialFill = function riskOfPartialFill(trades) {
2191
+ if (Array.isArray(trades)) {
2192
+ return trades.some(function (trade) {
2193
+ return SwapRouter.v3TradeWithHighPriceImpact(trade);
2194
+ });
2195
+ } else {
2196
+ return SwapRouter.v3TradeWithHighPriceImpact(trades);
2197
+ }
2198
+ };
2199
+ SwapRouter.v3TradeWithHighPriceImpact = function v3TradeWithHighPriceImpact(trade) {
2200
+ return !(trade instanceof v2Sdk.Trade) && trade.priceImpact.greaterThan(REFUND_ETH_PRICE_IMPACT_THRESHOLD);
2201
+ };
2202
+ SwapRouter.getPositionAmounts = function getPositionAmounts(position, zeroForOne) {
2203
+ var _position$mintAmounts = position.mintAmounts,
2204
+ amount0 = _position$mintAmounts.amount0,
2205
+ amount1 = _position$mintAmounts.amount1;
2206
+ var currencyAmount0 = sdkCore.CurrencyAmount.fromRawAmount(position.pool.token0, amount0);
2207
+ var currencyAmount1 = sdkCore.CurrencyAmount.fromRawAmount(position.pool.token1, amount1);
2208
+ var _ref = zeroForOne ? [currencyAmount0, currencyAmount1] : [currencyAmount1, currencyAmount0],
2209
+ positionAmountIn = _ref[0],
2210
+ positionAmountOut = _ref[1];
2211
+ return {
2212
+ positionAmountIn: positionAmountIn,
2213
+ positionAmountOut: positionAmountOut
2214
+ };
2215
+ };
2216
+ return SwapRouter;
2217
+ }();
2218
+ SwapRouter.INTERFACE = /*#__PURE__*/new abi.Interface(ISwapRouter02.abi);
2219
+
2220
+ exports.ADDRESS_THIS = ADDRESS_THIS;
2221
+ exports.ADDRESS_ZERO = ADDRESS_ZERO;
2222
+ exports.ApproveAndCall = ApproveAndCall;
2223
+ exports.MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER = MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER;
2224
+ exports.MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER = MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER;
2225
+ exports.MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER = MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER;
2226
+ exports.MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER = MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER;
2227
+ exports.MSG_SENDER = MSG_SENDER;
2228
+ exports.MixedRoute = MixedRoute;
2229
+ exports.MixedRouteSDK = MixedRouteSDK;
2230
+ exports.MixedRouteTrade = MixedRouteTrade;
2231
+ exports.MulticallExtended = MulticallExtended;
2232
+ exports.ONE = ONE;
2233
+ exports.ONE_HUNDRED_PERCENT = ONE_HUNDRED_PERCENT;
2234
+ exports.PaymentsExtended = PaymentsExtended;
2235
+ exports.RouteV2 = RouteV2;
2236
+ exports.RouteV3 = RouteV3;
2237
+ exports.RouteV4 = RouteV4;
2238
+ exports.SwapRouter = SwapRouter;
2239
+ exports.Trade = Trade;
2240
+ exports.ZERO = ZERO;
2241
+ exports.ZERO_PERCENT = ZERO_PERCENT;
2242
+ exports.amountWithPathCurrency = amountWithPathCurrency;
2243
+ exports.encodeMixedRouteToPath = encodeMixedRouteToPath;
2244
+ exports.getOutputOfPools = getOutputOfPools;
2245
+ exports.getPathCurrency = getPathCurrency;
2246
+ exports.getPathToken = getPathToken;
2247
+ exports.isMint = isMint;
2248
+ exports.partitionMixedRouteByProtocol = partitionMixedRouteByProtocol;
2249
+ exports.tradeComparator = tradeComparator;
2250
+ //# sourceMappingURL=router-sdk.cjs.development.js.map