@uniswap/router-sdk 1.22.2 → 1.22.3

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.
@@ -1,2 +1,2 @@
1
- "use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("@uniswap/sdk-core"),r=t(require("jsbi")),o=require("@ethersproject/abi"),u=t(require("tiny-invariant")),i=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json"),a=require("@uniswap/v3-sdk"),s=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json"),p=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json"),c=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json"),d=require("@uniswap/v2-sdk"),l=require("@uniswap/v4-sdk"),m=require("@ethersproject/solidity"),f="0x0000000000000000000000000000000000000000",h="0x0000000000000000000000000000000000000001",v="0x0000000000000000000000000000000000000002",A=r.BigInt(0),y=r.BigInt(1),w=new n.Percent(A),T=new n.Percent(100,100);function x(t){return Object.keys(t).some((function(t){return"recipient"===t}))}(e=exports.ApprovalTypes||(exports.ApprovalTypes={}))[e.NOT_REQUIRED=0]="NOT_REQUIRED",e[e.MAX=1]="MAX",e[e.MAX_MINUS_ONE=2]="MAX_MINUS_ONE",e[e.ZERO_THEN_MAX=3]="ZERO_THEN_MAX",e[e.ZERO_THEN_MAX_MINUS_ONE=4]="ZERO_THEN_MAX_MINUS_ONE";var E=function(){function t(){}return t.encodeApproveMax=function(e){return t.INTERFACE.encodeFunctionData("approveMax",[e.address])},t.encodeApproveMaxMinusOne=function(e){return t.INTERFACE.encodeFunctionData("approveMaxMinusOne",[e.address])},t.encodeApproveZeroThenMax=function(e){return t.INTERFACE.encodeFunctionData("approveZeroThenMax",[e.address])},t.encodeApproveZeroThenMaxMinusOne=function(e){return t.INTERFACE.encodeFunctionData("approveZeroThenMaxMinusOne",[e.address])},t.encodeCallPositionManager=function(e){if(e.length>0||u(!1),1===e.length)return t.INTERFACE.encodeFunctionData("callPositionManager",e);var n=a.NonfungiblePositionManager.INTERFACE.encodeFunctionData("multicall",[e]);return t.INTERFACE.encodeFunctionData("callPositionManager",[n])},t.encodeAddLiquidity=function(e,n,o,u){var i=e.mintAmountsWithSlippage(u),s=i.amount0,p=i.amount1;return r.lessThan(n.amount0.quotient,s)&&(s=n.amount0.quotient),r.lessThan(n.amount1.quotient,p)&&(p=n.amount1.quotient),x(o)?t.INTERFACE.encodeFunctionData("mint",[{token0:e.pool.token0.address,token1:e.pool.token1.address,fee:e.pool.fee,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0Min:a.toHex(s),amount1Min:a.toHex(p),recipient:o.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:a.toHex(s),amount1Min:a.toHex(p),tokenId:a.toHex(o.tokenId)}])},t.encodeApprove=function(e,n){switch(n){case exports.ApprovalTypes.MAX:return t.encodeApproveMax(e.wrapped);case exports.ApprovalTypes.MAX_MINUS_ONE:return t.encodeApproveMaxMinusOne(e.wrapped);case exports.ApprovalTypes.ZERO_THEN_MAX:return t.encodeApproveZeroThenMax(e.wrapped);case exports.ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE:return t.encodeApproveZeroThenMaxMinusOne(e.wrapped);default:throw new Error("Error: invalid ApprovalType")}},t}();E.INTERFACE=new o.Interface(i.abi);var k=function(){function t(){}return t.encodeMulticall=function(e,n){if(void 0===n)return a.Multicall.encodeMulticall(e);if(Array.isArray(e)||(e=[e]),"string"==typeof n&&n.startsWith("0x")){var r=function(t){if(!t.match(/^0x[0-9a-fA-F]{64}$/))throw new Error(t+" is not valid bytes32.");return t.toLowerCase()}(n);return t.INTERFACE.encodeFunctionData("multicall(bytes32,bytes[])",[r,e])}var o=a.toHex(n);return t.INTERFACE.encodeFunctionData("multicall(uint256,bytes[])",[o,e])},t}();function g(t){return a.toHex(t.multiply(1e4).quotient)}k.INTERFACE=new o.Interface(s.abi);var P=function(){function t(){}return t.encodeUnwrapWETH9=function(e,r,o){if("string"==typeof r)return a.Payments.encodeUnwrapWETH9(e,r,o);if(o){var u=g(o.fee),i=n.validateAndParseAddress(o.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee(uint256,uint256,address)",[a.toHex(e),u,i])}return t.INTERFACE.encodeFunctionData("unwrapWETH9(uint256)",[a.toHex(e)])},t.encodeSweepToken=function(e,r,o,u){if("string"==typeof o)return a.Payments.encodeSweepToken(e,r,o,u);if(u){var i=g(u.fee),s=n.validateAndParseAddress(u.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,a.toHex(r),i,s])}return t.INTERFACE.encodeFunctionData("sweepToken(address,uint256)",[e.address,a.toHex(r)])},t.encodePull=function(e,n){return t.INTERFACE.encodeFunctionData("pull",[e.address,a.toHex(n)])},t.encodeWrapETH=function(e){return t.INTERFACE.encodeFunctionData("wrapETH",[a.toHex(e)])},t}();function I(){I=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},u="function"==typeof Symbol?Symbol:{},i=u.iterator||"@@iterator",a=u.asyncIterator||"@@asyncIterator",s=u.toStringTag||"@@toStringTag";function p(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(t){p=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var u=Object.create((e&&e.prototype instanceof v?e:v).prototype),i=new O(r||[]);return o(u,"_invoke",{value:P(t,n,i)}),u}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=c;var l="suspendedStart",m="executing",f="completed",h={};function v(){}function A(){}function y(){}var w={};p(w,i,(function(){return this}));var T=Object.getPrototypeOf,x=T&&T(T(N([])));x&&x!==n&&r.call(x,i)&&(w=x);var E=y.prototype=v.prototype=Object.create(w);function k(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){function n(o,u,i,a){var s=d(t[o],t,u);if("throw"!==s.type){var p=s.arg,c=p.value;return c&&"object"==typeof c&&r.call(c,"__await")?e.resolve(c.__await).then((function(t){n("next",t,i,a)}),(function(t){n("throw",t,i,a)})):e.resolve(c).then((function(t){p.value=t,i(p)}),(function(t){return n("throw",t,i,a)}))}a(s.arg)}var u;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return u=u?u.then(o,o):o()}})}function P(e,n,r){var o=l;return function(u,i){if(o===m)throw new Error("Generator is already running");if(o===f){if("throw"===u)throw i;return{value:t,done:!0}}for(r.method=u,r.arg=i;;){var a=r.delegate;if(a){var s=b(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===l)throw o=f,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=m;var p=d(e,n,r);if("normal"===p.type){if(o=r.done?f:"suspendedYield",p.arg===h)continue;return{value:p.arg,done:r.done}}"throw"===p.type&&(o=f,r.method="throw",r.arg=p.arg)}}}function b(e,n){var r=n.method,o=e.iterator[r];if(o===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,b(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var u=d(o,e.iterator,n.arg);if("throw"===u.type)return n.method="throw",n.arg=u.arg,n.delegate=null,h;var i=u.arg;return i?i.done?(n[e.resultName]=i.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,h):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,h)}function R(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(R,this),this.reset(!0)}function N(e){if(e||""===e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,u=function n(){for(;++o<e.length;)if(r.call(e,o))return n.value=e[o],n.done=!1,n;return n.value=t,n.done=!0,n};return u.next=u}}throw new TypeError(typeof e+" is not iterable")}return A.prototype=y,o(E,"constructor",{value:y,configurable:!0}),o(y,"constructor",{value:A,configurable:!0}),A.displayName=p(y,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===A||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,p(t,s,"GeneratorFunction")),t.prototype=Object.create(E),t},e.awrap=function(t){return{__await:t}},k(g.prototype),p(g.prototype,a,(function(){return this})),e.AsyncIterator=g,e.async=function(t,n,r,o,u){void 0===u&&(u=Promise);var i=new g(c(t,n,r,o),u);return e.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},k(E),p(E,s,"Generator"),p(E,i,(function(){return this})),p(E,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},e.values=N,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(_),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function o(r,o){return a.type="throw",a.arg=e,n.next=r,o&&(n.method="next",n.arg=t),!!o}for(var u=this.tryEntries.length-1;u>=0;--u){var i=this.tryEntries[u],a=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),p=r.call(i,"finallyLoc");if(s&&p){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!p)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var u=o;break}}u&&("break"===t||"continue"===t)&&u.tryLoc<=e&&e<=u.finallyLoc&&(u=null);var i=u?u.completion:{};return i.type=t,i.arg=e,u?(this.method="next",this.next=u.finallyLoc,h):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),_(n),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;_(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:N(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),h}},e}function b(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function R(t,e,n,r,o,u,i){try{var a=t[u](i),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(r,o)}function _(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var u=t.apply(e,n);function i(t){R(u,r,o,i,a,"next",t)}function a(t){R(u,r,o,i,a,"throw",t)}i(void 0)}))}}function O(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,b(r.key),r)}}function N(t,e,n){return e&&O(t.prototype,e),n&&O(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function F(){return(F=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function q(t,e){var n,r;t.prototype=Object.create(e.prototype),t.prototype.constructor=t,n=t,r=e,(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(n,r)}function C(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function M(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return C(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?C(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function S(t,e){return n.CurrencyAmount.fromFractionalAmount(H(t.currency,e),t.numerator,t.denominator)}function H(t,e){if(e.involvesToken(t))return t;if(e.involvesToken(t.wrapped))return t.wrapped;if(!(e instanceof l.Pool))throw new Error("Expected currency "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol);return e.token0.wrapped.equals(t)?e.token0:e.token1.wrapped.equals(t)?e.token1:t}P.INTERFACE=new o.Interface(p.abi);var D=function(){function t(t,e,n,r){void 0===r&&(r=!1),this._midPrice=null,(t=r?t:t.filter((function(t){return!(t instanceof l.Pool&&0===t.tickSpacing)}))).length>0||u(!1);var o=t[0].chainId;t.every((function(t){return t.chainId===o}))||u(!1),this.pathInput=H(e,t[0]),this.pathOutput=H(n,t[t.length-1]),t[0]instanceof l.Pool?t[0].v4InvolvesToken(this.pathInput)||u(!1):t[0].involvesToken(this.pathInput)||u(!1);var i=t[t.length-1];i instanceof l.Pool?i.v4InvolvesToken(n)||i.v4InvolvesToken(n.wrapped)||u(!1):i.involvesToken(n.wrapped)||u(!1);var a=[this.pathInput];t[0].token0.equals(this.pathInput)?a.push(t[0].token1):a.push(t[0].token0);for(var s=1;s<t.length;s++){var p=t[s],c=a[s],d=void 0;if(p instanceof l.Pool&&!p.involvesToken(c)||!(p instanceof l.Pool)&&c.isNative)if(c.equals(p.token0.wrapped))d=p.token1;else{if(!c.wrapped.equals(p.token0)&&!c.wrapped.equals(p.token1))throw new Error("POOL_MISMATCH pool: "+JSON.stringify(p)+" inputToken: "+JSON.stringify(c));d=c.wrapped.equals(p.token0)?p.token1:p.token0}else c.equals(p.token0)||c.equals(p.token1)||u(!1),d=c.equals(p.token0)?p.token1:p.token0;a.push(d)}this.pools=t,this.path=a,this.input=e,this.output=null!=n?n:a[a.length-1]}return N(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,e){var n=t.price;return t.nextInput.equals(e.token0)?{nextInput:e.token1,price:n.multiply(e.token0Price.asFraction)}:{nextInput:e.token0,price:n.multiply(e.token1Price.asFraction)}}),this.pools[0].token0.equals(this.pathInput)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price.asFraction}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price.asFraction}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function U(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||u(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||u(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?t.swaps.reduce((function(t,e){return t+e.route.path.length}),0)-e.swaps.reduce((function(t,e){return t+e.route.path.length}),0):t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}var L,j=function(){function t(t){var e=t.routes,r=t.tradeType,o=e[0].inputAmount.currency,i=e[0].outputAmount.currency;e.every((function(t){return o.wrapped.equals(t.route.input.wrapped)}))||u(!1),e.every((function(t){return i.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var s,p=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,m=M(e);!(s=m()).done;)for(var f,h=M(s.value.route.pools);!(f=h()).done;){var v=f.value;if(v instanceof l.Pool)c.add(v.poolId);else if(v instanceof a.Pool)c.add(a.Pool.getAddress(v.token0,v.token1,v.fee));else{if(!(v instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");c.add(d.Pair.getAddress(v.token0,v.token1))}}p!==c.size&&u(!1),r!==n.TradeType.EXACT_INPUT&&u(!1),this.swaps=e,this.tradeType=r}t.fromRoute=function(){var e=_(I().mark((function e(r,o,i){var a,s,p,c,d;return I().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=new Array(r.path.length),i!==n.TradeType.EXACT_INPUT&&u(!1),o.currency.equals(r.input)||u(!1),a[0]=S(o,r.pools[0]),c=0;case 5:if(!(c<r.path.length-1)){e.next=15;break}return d=r.pools[c],e.next=9,d.getOutputAmount(S(a[c],d));case 9:a[c+1]=e.sent[0];case 12:c++,e.next=5;break;case 15:return s=n.CurrencyAmount.fromFractionalAmount(r.input,o.numerator,o.denominator),p=n.CurrencyAmount.fromFractionalAmount(r.output,a[a.length-1].numerator,a[a.length-1].denominator),e.abrupt("return",new t({routes:[{inputAmount:s,outputAmount:p,route:r}],tradeType:i}));case 18:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=_(I().mark((function e(r,o){var i,a,s,p,c,d,l,m,f,h,v;return I().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=[],o!==n.TradeType.EXACT_INPUT&&u(!1),a=M(r);case 3:if((s=a()).done){e.next=26;break}c=(p=s.value).route,d=p.amount,l=new Array(c.path.length),m=void 0,f=void 0,d.currency.equals(c.input)||u(!1),m=n.CurrencyAmount.fromFractionalAmount(c.input,d.numerator,d.denominator),l[0]=n.CurrencyAmount.fromFractionalAmount(c.pathInput,d.numerator,d.denominator),h=0;case 12:if(!(h<c.path.length-1)){e.next=22;break}return v=c.pools[h],e.next=16,v.getOutputAmount(S(l[h],v));case 16:l[h+1]=e.sent[0];case 19:h++,e.next=12;break;case 22:f=n.CurrencyAmount.fromFractionalAmount(c.output,l[l.length-1].numerator,l[l.length-1].denominator),i.push({route:c,inputAmount:m,outputAmount:f});case 24:e.next=3;break;case 26:return e.abrupt("return",new t({routes:i,tradeType:o}));case 27:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(F({},e,{routes:[{inputAmount:e.inputAmount,outputAmount:e.outputAmount,route:e.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(e){return new t(e)};var e=t.prototype;return e.minimumAmountOut=function(t,e){void 0===e&&(e=this.outputAmount),t.lessThan(A)&&u(!1);var r=new n.Fraction(y).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.maximumAmountIn=function(t,e){return void 0===e&&(e=this.inputAmount),t.lessThan(A)&&u(!1),e},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=_(I().mark((function e(r,o,i,a,s,p,c){var m,f,h,v,y,w,T,x,E,k,g;return I().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:h=void 0===(f=(m=void 0===a?{}:a).maxNumResults)?3:f,y=void 0===(v=m.maxHops)?3:v,void 0===s&&(s=[]),void 0===p&&(p=o),void 0===c&&(c=[]),r.length>0||u(!1),y>0||u(!1),o===p||s.length>0||u(!1),w=p,T=0;case 9:if(!(T<r.length)){e.next=56;break}if((x=r[T]).token0.equals((E=x instanceof l.Pool?w:w.wrapped).currency)||x.token1.equals(E.currency)){e.next=14;break}return e.abrupt("continue",53);case 14:if(!(x instanceof d.Pair)){e.next=17;break}if(!x.reserve0.equalTo(A)&&!x.reserve1.equalTo(A)){e.next=17;break}return e.abrupt("continue",53);case 17:if(k=void 0,e.prev=18,!(x instanceof l.Pool)){e.next=26;break}return e.next=23,x.getOutputAmount(E);case 23:e.t0=e.sent,e.next=29;break;case 26:return e.next=28,x.getOutputAmount(E.wrapped);case 28:e.t0=e.sent;case 29:k=e.t0[0],e.next=38;break;case 33:if(e.prev=33,e.t1=e.catch(18),!e.t1.isInsufficientInputAmountError){e.next=37;break}return e.abrupt("continue",53);case 37:throw e.t1;case 38:if(!k.currency.wrapped.equals(i.wrapped)){e.next=49;break}return e.t2=n.sortedInsert,e.t3=c,e.next=43,t.fromRoute(new D([].concat(s,[x]),o.currency,i),o,n.TradeType.EXACT_INPUT);case 43:e.t4=e.sent,e.t5=h,e.t6=U,(0,e.t2)(e.t3,e.t4,e.t5,e.t6),e.next=53;break;case 49:if(!(y>1&&r.length>1)){e.next=53;break}return g=r.slice(0,T).concat(r.slice(T+1,r.length)),e.next=53,t.bestTradeExactIn(g,o,i,{maxNumResults:h,maxHops:y-1},[].concat(s,[x]),k,c);case 53:T++,e.next=9;break;case 56:return e.abrupt("return",c);case 57:case"end":return e.stop()}}),e,null,[[18,33]])})));return function(t,n,r,o,u,i,a){return e.apply(this,arguments)}}(),N(t,[{key:"route",get:function(){return 1!==this.swaps.length&&u(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=M(this.swaps);!(t=r()).done;){var o=t.value;e=e.add(o.route.midPrice.quote(o.inputAmount))}var u=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new n.Percent(u.numerator,u.denominator),this._priceImpact}}]),t}();function X(t,e){if(e.token0.wrapped.equals(t.wrapped))return e.token0;if(e.token1.wrapped.equals(t.wrapped))return e.token1;throw new Error("Expected token "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol)}(L=exports.Protocol||(exports.Protocol={})).V2="V2",L.V3="V3",L.V4="V4",L.MIXED="MIXED";var V=function(t){function e(e){var n;return(n=t.call(this,e.pairs,e.input,e.output)||this).protocol=exports.Protocol.V2,n.pools=n.pairs,n.pathInput=X(e.input,n.pairs[0]),n.pathOutput=X(e.output,n.pairs[n.pairs.length-1]),n}return q(e,t),e}(d.Route),W=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.V3,n.path=e.tokenPath,n.pathInput=X(e.input,n.pools[0]),n.pathOutput=X(e.output,n.pools[n.pools.length-1]),n}return q(e,t),e}(a.Route),Z=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.V4,n.path=e.currencyPath,n}return q(e,t),e}(l.Route),B=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.MIXED,n}return q(e,t),e}(D),G=function(){function t(t){var e=t.v2Routes,n=void 0===e?[]:e,r=t.v3Routes,o=void 0===r?[]:r,i=t.v4Routes,s=void 0===i?[]:i,p=t.mixedRoutes,c=void 0===p?[]:p,m=t.tradeType;this.swaps=[],this.routes=[];for(var f,h=M(n);!(f=h()).done;){var v=f.value,A=v.inputAmount,y=v.outputAmount,w=new V(v.routev2);this.routes.push(w),this.swaps.push({route:w,inputAmount:A,outputAmount:y})}for(var T,x=M(o);!(T=x()).done;){var E=T.value,k=E.inputAmount,g=E.outputAmount,P=new W(E.routev3);this.routes.push(P),this.swaps.push({route:P,inputAmount:k,outputAmount:g})}for(var I,b=M(s);!(I=b()).done;){var R=I.value,_=R.inputAmount,O=R.outputAmount,N=new Z(R.routev4);this.routes.push(N),this.swaps.push({route:N,inputAmount:_,outputAmount:O})}for(var F,q=M(c);!(F=q()).done;){var C=F.value,S=C.inputAmount,H=C.outputAmount,D=new B(C.mixedRoute);this.routes.push(D),this.swaps.push({route:D,inputAmount:S,outputAmount:H})}if(0===this.swaps.length)throw new Error("No routes provided when calling Trade constructor");this.tradeType=m;var U=this.swaps[0].inputAmount.currency,L=this.swaps[0].outputAmount.currency;this.swaps.every((function(t){return U.wrapped.equals(t.route.input.wrapped)}))||u(!1),this.swaps.every((function(t){return L.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var j,X=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),G=new Set,Q=M(this.swaps);!(j=Q()).done;)for(var J,z=M(j.value.route.pools);!(J=z()).done;){var Y=J.value;if(Y instanceof l.Pool)G.add(Y.poolId);else if(Y instanceof a.Pool)G.add(a.Pool.getAddress(Y.token0,Y.token1,Y.fee));else{if(!(Y instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");G.add(d.Pair.getAddress(Y.token0,Y.token1))}}X!==G.size&&u(!1)}var e=t.prototype;return e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(A)&&u(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var r=new n.Fraction(y).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(A)&&u(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var r=new n.Fraction(y).add(t).multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.fromRoutes=function(){var e=_(I().mark((function e(n,r,o,u,i){var s,p,c,m,f,h,v,A,y,w,T,x,E,k,g,P,b,R,_,O,N,F,q,C,S,H,D;return I().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(s=[],p=[],c=[],m=[],f=M(n);!(h=f()).done;)y=new d.Trade(A=(v=h.value).routev2,v.amount,o),s.push({routev2:A,inputAmount:y.inputAmount,outputAmount:y.outputAmount});w=M(r);case 6:if((T=w()).done){e.next=15;break}return E=(x=T.value).routev3,k=x.amount,e.next=10,a.Trade.fromRoute(E,k,o);case 10:p.push({routev3:E,inputAmount:(g=e.sent).inputAmount,outputAmount:g.outputAmount});case 13:e.next=6;break;case 15:if(!i){e.next=26;break}P=M(i);case 17:if((b=P()).done){e.next=26;break}return _=(R=b.value).routev4,O=R.amount,e.next=21,l.Trade.fromRoute(_,O,o);case 21:c.push({routev4:_,inputAmount:(N=e.sent).inputAmount,outputAmount:N.outputAmount});case 24:e.next=17;break;case 26:if(!u){e.next=37;break}F=M(u);case 28:if((q=F()).done){e.next=37;break}return S=(C=q.value).mixedRoute,H=C.amount,e.next=32,j.fromRoute(S,H,o);case 32:m.push({mixedRoute:S,inputAmount:(D=e.sent).inputAmount,outputAmount:D.outputAmount});case 35:e.next=28;break;case 37:return e.abrupt("return",new t({v2Routes:s,v3Routes:p,v4Routes:c,mixedRoutes:m,tradeType:o}));case 38:case"end":return e.stop()}}),e)})));return function(t,n,r,o,u){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=_(I().mark((function e(n,r,o){var u,i,s,p,c,m,f,h;return I().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u=[],i=[],s=[],p=[],!(n instanceof d.Route)){e.next=10;break}c=new d.Trade(n,r,o),u=[{routev2:n,inputAmount:c.inputAmount,outputAmount:c.outputAmount}],e.next=35;break;case 10:if(!(n instanceof a.Route)){e.next=18;break}return e.next=13,a.Trade.fromRoute(n,r,o);case 13:i=[{routev3:n,inputAmount:(m=e.sent).inputAmount,outputAmount:m.outputAmount}],e.next=35;break;case 18:if(!(n instanceof l.Route)){e.next=26;break}return e.next=21,l.Trade.fromRoute(n,r,o);case 21:s=[{routev4:n,inputAmount:(f=e.sent).inputAmount,outputAmount:f.outputAmount}],e.next=35;break;case 26:if(!(n instanceof D)){e.next=34;break}return e.next=29,j.fromRoute(n,r,o);case 29:p=[{mixedRoute:n,inputAmount:(h=e.sent).inputAmount,outputAmount:h.outputAmount}],e.next=35;break;case 34:throw new Error("Invalid route type");case 35:return e.abrupt("return",new t({v2Routes:u,v3Routes:i,v4Routes:s,mixedRoutes:p,tradeType:o}));case 36:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),N(t,[{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"amounts",get:function(){var t,e,r=null==(t=this.swaps.find((function(t){return t.inputAmount.currency.isNative})))?void 0:t.inputAmount.currency,o=null==(e=this.swaps.find((function(t){return t.outputAmount.currency.isNative})))?void 0:e.outputAmount.currency;return{inputAmount:this.inputAmount,inputAmountNative:r?this.swaps.reduce((function(t,e){return e.route.pathInput.isNative?t.add(e.inputAmount):t}),n.CurrencyAmount.fromRawAmount(r,0)):void 0,outputAmount:this.outputAmount,outputAmountNative:o?this.swaps.reduce((function(t,e){return e.route.pathOutput.isNative?t.add(e.outputAmount):t}),n.CurrencyAmount.fromRawAmount(o,0)):void 0}}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"inputTax",get:function(){var t=this.inputAmount.currency;return t.isNative||!t.wrapped.sellFeeBps?w:new n.Percent(t.wrapped.sellFeeBps.toNumber(),1e4)}},{key:"outputTax",get:function(){var t=this.outputAmount.currency;return t.isNative||!t.wrapped.buyFeeBps?w:new n.Percent(t.wrapped.buyFeeBps.toNumber(),1e4)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;if(this.outputTax.equalTo(T))return w;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=M(this.swaps);!(t=r()).done;){var o=t.value,u=o.route.midPrice,i=o.inputAmount.multiply(new n.Fraction(y).subtract(this.inputTax));e=e.add(u.quote(i))}if(e.equalTo(A))return w;var a=this.outputAmount.divide(new n.Fraction(y).subtract(this.outputTax)),s=e.subtract(a).divide(e);return this._priceImpact=new n.Percent(s.numerator,s.denominator),this._priceImpact}}]),t}();function Q(t){var e,n;if(t.pools.some((function(t){return t instanceof l.Pool}))){e=[t.pathInput.isNative?f:t.pathInput.address],n=["address"];for(var r,o=t.pathInput,u=M(t.pools);!(r=u()).done;){var i=r.value,s=o.equals(i.token0)?i.token1:i.token0;if(i instanceof l.Pool)0===i.tickSpacing?(e.push(0,s.isNative?f:s.wrapped.address),n.push("uint8","address")):(e.push(i.fee+(4<<20),i.tickSpacing,i.hooks,s.isNative?f:s.wrapped.address),n.push("uint24","uint24","address","address"));else if(i instanceof a.Pool)e.push(i.fee+(3<<20),s.wrapped.address),n.push("uint24","address");else{if(!(i instanceof d.Pair))throw new Error("Unsupported pool type "+JSON.stringify(i));e.push(32,s.wrapped.address),n.push("uint8","address")}o=s}}else{var p=t.pools.reduce((function(t,e,n){var r=t.inputToken,o=t.path,u=t.types,i=e.token0.equals(r)?e.token1:e.token0;return 0===n?{inputToken:i,types:["address","uint24","address"],path:[r.wrapped.address,e instanceof a.Pool?e.fee:1<<23,i.wrapped.address]}:{inputToken:i,types:[].concat(u,["uint24","address"]),path:[].concat(o,[e instanceof a.Pool?e.fee:1<<23,i.wrapped.address])}}),{inputToken:t.input,path:[],types:[]});e=p.path,n=p.types}return m.pack(n,e)}var J=function(t){for(var e=[],n=0,r=0;r<t.pools.length;)(t.pools[n]instanceof l.Pool&&!(t.pools[r]instanceof l.Pool)||t.pools[n]instanceof a.Pool&&!(t.pools[r]instanceof a.Pool)||t.pools[n]instanceof d.Pair&&!(t.pools[r]instanceof d.Pair))&&(e.push(t.pools.slice(n,r)),n=r),++r===t.pools.length&&e.push(t.pools.slice(n,r));return e},z=function(t,e){return t.reduce((function(t,e){var n=t.inputToken;if(!e.involvesToken(n))throw new Error("PATH");return{inputToken:e.token0.equals(n)?e.token1:e.token0}}),{inputToken:e}).inputToken},Y=r.BigInt(0),$=new n.Percent(r.BigInt(50),r.BigInt(100)),K=function(){function t(){}return t.encodeV2Swap=function(e,r,o,u){var i=a.toHex(e.maximumAmountIn(r.slippageTolerance).quotient),s=a.toHex(e.minimumAmountOut(r.slippageTolerance).quotient),p=e.route.path.map((function(t){return t.address})),c=o?v:void 0===r.recipient?h:n.validateAndParseAddress(r.recipient);return e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[i,u?0:s,p,c]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[s,i,p,c])},t.encodeV3Swap=function(e,r,o,u){for(var i,s=[],p=M(e.swaps);!(i=p()).done;){var c=i.value,d=c.route,l=c.outputAmount,m=a.toHex(e.maximumAmountIn(r.slippageTolerance,c.inputAmount).quotient),f=a.toHex(e.minimumAmountOut(r.slippageTolerance,l).quotient),A=1===d.pools.length,y=o?v:void 0===r.recipient?h:n.validateAndParseAddress(r.recipient);if(A)s.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:y,amountIn:m,amountOutMinimum:u?0:f,sqrtPriceLimitX96:0}]):t.INTERFACE.encodeFunctionData("exactOutputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:y,amountOut:f,amountInMaximum:m,sqrtPriceLimitX96:0}]));else{var w=a.encodeRouteToPath(d,e.tradeType===n.TradeType.EXACT_OUTPUT);s.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:w,recipient:y,amountIn:m,amountOutMinimum:u?0:f}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:w,recipient:y,amountOut:f,amountInMaximum:m}]))}}return s},t.encodeMixedRouteSwap=function(e,r,o,i){var s=[];e.tradeType!==n.TradeType.EXACT_INPUT&&u(!1);for(var p,c=function(){var u=p.value,c=u.route,d=u.inputAmount,m=u.outputAmount;if(c.pools.some((function(t){return t instanceof l.Pool})))throw"Encoding mixed routes with V4 not supported";var f=a.toHex(e.maximumAmountIn(r.slippageTolerance,d).quotient),A=a.toHex(e.minimumAmountOut(r.slippageTolerance,m).quotient),y=1===c.pools.length,w=o?v:void 0===r.recipient?h:n.validateAndParseAddress(r.recipient),T=function(t){return t.pools.every((function(t){return t instanceof a.Pool}))};if(y)if(T(c))s.push(t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:c.path[0].wrapped.address,tokenOut:c.path[1].wrapped.address,fee:c.pools[0].fee,recipient:w,amountIn:f,amountOutMinimum:i?0:A,sqrtPriceLimitX96:0}]));else{var x=c.path.map((function(t){return t.wrapped.address}));s.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[f,i?0:A,x,w]))}else for(var E,k=J(c),g=function(t){return t===k.length-1},P=c.input.wrapped,I=0;I<k.length;I++){var b=k[I];E=z(b,P);var R=new D([].concat(b),b[0].token0.equals(P)?b[0].token0:b[0].token1,E),_=new B(R);if(P=E.wrapped,T(_)){var O={path:Q(_),recipient:g(I)?w:v,amountIn:0===I?f:0,amountOutMinimum:g(I)?A:0};s.push(t.INTERFACE.encodeFunctionData("exactInput",[O]))}else{var N=[0===I?f:0,g(I)?A:0,_.path.map((function(t){return t.wrapped.address})),g(I)?w:v];s.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",N))}}},d=M(e.swaps);!(p=d()).done;)c();return s},t.encodeSwaps=function(e,r,o){if(e instanceof G){e.swaps.every((function(t){return t.route.protocol===exports.Protocol.V3||t.route.protocol===exports.Protocol.V2||t.route.protocol===exports.Protocol.MIXED}))||u(!1);for(var i,s=[],p=M(e.swaps);!(i=p()).done;){var c=i.value,l=c.route,m=c.inputAmount,f=c.outputAmount;if(l.protocol===exports.Protocol.V2)s.push(new d.Trade(l,e.tradeType===n.TradeType.EXACT_INPUT?m:f,e.tradeType));else if(l.protocol===exports.Protocol.V3)s.push(a.Trade.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}));else{if(l.protocol!==exports.Protocol.MIXED)throw new Error("UNSUPPORTED_TRADE_PROTOCOL");s.push(j.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}))}}e=s}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof a.Trade||e instanceof j?e.swaps.length:1)}),0),v=e[0];e.every((function(t){return t.inputAmount.currency.equals(v.inputAmount.currency)}))||u(!1),e.every((function(t){return t.outputAmount.currency.equals(v.outputAmount.currency)}))||u(!1),e.every((function(t){return t.tradeType===v.tradeType}))||u(!1);var A=[],y=v.inputAmount.currency.isNative,w=v.outputAmount.currency.isNative,T=v.tradeType===n.TradeType.EXACT_INPUT&&h>2,x=w||!!r.fee||!!o||T;r.inputTokenPermit&&(v.inputAmount.currency.isToken||u(!1),A.push(a.SelfPermit.encodePermit(v.inputAmount.currency,r.inputTokenPermit)));for(var E,k=M(e);!(E=k()).done;){var g=E.value;if(g instanceof d.Trade)A.push(t.encodeV2Swap(g,r,x,T));else if(g instanceof a.Trade)for(var P,I=M(t.encodeV3Swap(g,r,x,T));!(P=I()).done;)A.push(P.value);else{if(!(g instanceof j))throw new Error("Unsupported trade object");for(var b,R=M(t.encodeMixedRouteSwap(g,r,x,T));!(b=R()).done;)A.push(b.value)}}var _=n.CurrencyAmount.fromRawAmount(v.inputAmount.currency,0),O=n.CurrencyAmount.fromRawAmount(v.outputAmount.currency,0),N=e.reduce((function(t,e){return t.add(e.minimumAmountOut(r.slippageTolerance))}),O),F=e.reduce((function(t,e){return t.add(e.outputAmount)}),O),q=e.reduce((function(t,e){return t.add(e.maximumAmountIn(r.slippageTolerance))}),_);return{calldatas:A,sampleTrade:v,routerMustCustody:x,inputIsNative:y,outputIsNative:w,totalAmountIn:q,minimumAmountOut:N,quoteAmountOut:F}},t.swapCallParameters=function(e,r){var o=t.encodeSwaps(e,r),u=o.calldatas,i=o.sampleTrade,s=o.inputIsNative,p=o.totalAmountIn,c=o.minimumAmountOut;return o.routerMustCustody&&u.push(o.outputIsNative?P.encodeUnwrapWETH9(c.quotient,r.recipient,r.fee):P.encodeSweepToken(i.outputAmount.currency.wrapped,c.quotient,r.recipient,r.fee)),s&&(i.tradeType===n.TradeType.EXACT_OUTPUT||t.riskOfPartialFill(e))&&u.push(a.Payments.encodeRefundETH()),{calldata:k.encodeMulticall(u,r.deadlineOrPreviousBlockhash),value:a.toHex(s?p.quotient:Y)}},t.swapAndAddCallParameters=function(e,r,o,i,s,p){var c=t.encodeSwaps(e,r,!0),d=c.calldatas,l=c.inputIsNative,m=c.outputIsNative,f=c.sampleTrade,h=c.totalAmountIn,v=c.quoteAmountOut,A=c.minimumAmountOut;r.outputTokenPermit&&(v.currency.isToken||u(!1),d.push(a.SelfPermit.encodePermit(v.currency,r.outputTokenPermit)));var y=f.route.chainId,w=o.pool.token0.wrapped.address===h.currency.wrapped.address,T=t.getPositionAmounts(o,w),x=T.positionAmountIn,g=T.positionAmountOut,I=l?n.WETH9[y]:x.currency.wrapped,b=m?n.WETH9[y]:g.currency.wrapped,R=g.subtract(v.wrapped);R.greaterThan(n.CurrencyAmount.fromRawAmount(g.currency,0))&&d.push(m?P.encodeWrapETH(R.quotient):P.encodePull(b,R.quotient)),d.push(l?P.encodeWrapETH(x.quotient):P.encodePull(I,x.quotient)),s!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(E.encodeApprove(I,s)),p!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(E.encodeApprove(b,p));var _,O=a.Position.fromAmounts({pool:o.pool,tickLower:o.tickLower,tickUpper:o.tickUpper,amount0:w?o.amount0.quotient.toString():A.quotient.toString(),amount1:w?A.quotient.toString():o.amount1.quotient.toString(),useFullPrecision:!1});return d.push(E.encodeAddLiquidity(o,O,i,r.slippageTolerance)),d.push(l?P.encodeUnwrapWETH9(Y):P.encodeSweepToken(I,Y)),d.push(m?P.encodeUnwrapWETH9(Y):P.encodeSweepToken(b,Y)),_=l?h.wrapped.add(x.wrapped).quotient:m?R.quotient:Y,{calldata:k.encodeMulticall(d,r.deadlineOrPreviousBlockhash),value:_.toString()}},t.riskOfPartialFill=function(e){return Array.isArray(e)?e.some((function(e){return t.v3TradeWithHighPriceImpact(e)})):t.v3TradeWithHighPriceImpact(e)},t.v3TradeWithHighPriceImpact=function(t){return!(t instanceof d.Trade)&&t.priceImpact.greaterThan($)},t.getPositionAmounts=function(t,e){var r=t.mintAmounts,o=r.amount1,u=n.CurrencyAmount.fromRawAmount(t.pool.token0,r.amount0),i=n.CurrencyAmount.fromRawAmount(t.pool.token1,o),a=e?[u,i]:[i,u];return{positionAmountIn:a[0],positionAmountOut:a[1]}},t}();K.INTERFACE=new o.Interface(c.abi),exports.ADDRESS_THIS=v,exports.ADDRESS_ZERO=f,exports.ApproveAndCall=E,exports.MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER=1<<23,exports.MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER=32,exports.MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER=3<<20,exports.MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER=4<<20,exports.MSG_SENDER=h,exports.MixedRoute=B,exports.MixedRouteSDK=D,exports.MixedRouteTrade=j,exports.MulticallExtended=k,exports.ONE=y,exports.ONE_HUNDRED_PERCENT=T,exports.PaymentsExtended=P,exports.RouteV2=V,exports.RouteV3=W,exports.RouteV4=Z,exports.SwapRouter=K,exports.Trade=G,exports.ZERO=A,exports.ZERO_PERCENT=w,exports.amountWithPathCurrency=S,exports.encodeMixedRouteToPath=Q,exports.getOutputOfPools=z,exports.getPathCurrency=H,exports.getPathToken=X,exports.isMint=x,exports.partitionMixedRouteByProtocol=J,exports.tradeComparator=U;
1
+ "use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("@uniswap/sdk-core"),r=t(require("jsbi")),o=require("@ethersproject/abi"),u=t(require("tiny-invariant")),i=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json"),a=require("@uniswap/v3-sdk"),s=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json"),p=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json"),c=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json"),d=require("@uniswap/v2-sdk"),l=require("@uniswap/v4-sdk"),m=require("@ethersproject/solidity"),f="0x0000000000000000000000000000000000000000",h="0x0000000000000000000000000000000000000001",v="0x0000000000000000000000000000000000000002",A=r.BigInt(0),y=r.BigInt(1),w=new n.Percent(A),T=new n.Percent(100,100);function x(t){return Object.keys(t).some((function(t){return"recipient"===t}))}(e=exports.ApprovalTypes||(exports.ApprovalTypes={}))[e.NOT_REQUIRED=0]="NOT_REQUIRED",e[e.MAX=1]="MAX",e[e.MAX_MINUS_ONE=2]="MAX_MINUS_ONE",e[e.ZERO_THEN_MAX=3]="ZERO_THEN_MAX",e[e.ZERO_THEN_MAX_MINUS_ONE=4]="ZERO_THEN_MAX_MINUS_ONE";var E=function(){function t(){}return t.encodeApproveMax=function(e){return t.INTERFACE.encodeFunctionData("approveMax",[e.address])},t.encodeApproveMaxMinusOne=function(e){return t.INTERFACE.encodeFunctionData("approveMaxMinusOne",[e.address])},t.encodeApproveZeroThenMax=function(e){return t.INTERFACE.encodeFunctionData("approveZeroThenMax",[e.address])},t.encodeApproveZeroThenMaxMinusOne=function(e){return t.INTERFACE.encodeFunctionData("approveZeroThenMaxMinusOne",[e.address])},t.encodeCallPositionManager=function(e){if(e.length>0||u(!1),1===e.length)return t.INTERFACE.encodeFunctionData("callPositionManager",e);var n=a.NonfungiblePositionManager.INTERFACE.encodeFunctionData("multicall",[e]);return t.INTERFACE.encodeFunctionData("callPositionManager",[n])},t.encodeAddLiquidity=function(e,n,o,u){var i=e.mintAmountsWithSlippage(u),s=i.amount0,p=i.amount1;return r.lessThan(n.amount0.quotient,s)&&(s=n.amount0.quotient),r.lessThan(n.amount1.quotient,p)&&(p=n.amount1.quotient),x(o)?t.INTERFACE.encodeFunctionData("mint",[{token0:e.pool.token0.address,token1:e.pool.token1.address,fee:e.pool.fee,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0Min:a.toHex(s),amount1Min:a.toHex(p),recipient:o.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:a.toHex(s),amount1Min:a.toHex(p),tokenId:a.toHex(o.tokenId)}])},t.encodeApprove=function(e,n){switch(n){case exports.ApprovalTypes.MAX:return t.encodeApproveMax(e.wrapped);case exports.ApprovalTypes.MAX_MINUS_ONE:return t.encodeApproveMaxMinusOne(e.wrapped);case exports.ApprovalTypes.ZERO_THEN_MAX:return t.encodeApproveZeroThenMax(e.wrapped);case exports.ApprovalTypes.ZERO_THEN_MAX_MINUS_ONE:return t.encodeApproveZeroThenMaxMinusOne(e.wrapped);default:throw new Error("Error: invalid ApprovalType")}},t}();E.INTERFACE=new o.Interface(i.abi);var k=function(){function t(){}return t.encodeMulticall=function(e,n){if(void 0===n)return a.Multicall.encodeMulticall(e);if(Array.isArray(e)||(e=[e]),"string"==typeof n&&n.startsWith("0x")){var r=function(t){if(!t.match(/^0x[0-9a-fA-F]{64}$/))throw new Error(t+" is not valid bytes32.");return t.toLowerCase()}(n);return t.INTERFACE.encodeFunctionData("multicall(bytes32,bytes[])",[r,e])}var o=a.toHex(n);return t.INTERFACE.encodeFunctionData("multicall(uint256,bytes[])",[o,e])},t}();function g(t){return a.toHex(t.multiply(1e4).quotient)}k.INTERFACE=new o.Interface(s.abi);var I=function(){function t(){}return t.encodeUnwrapWETH9=function(e,r,o){if("string"==typeof r)return a.Payments.encodeUnwrapWETH9(e,r,o);if(o){var u=g(o.fee),i=n.validateAndParseAddress(o.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee(uint256,uint256,address)",[a.toHex(e),u,i])}return t.INTERFACE.encodeFunctionData("unwrapWETH9(uint256)",[a.toHex(e)])},t.encodeSweepToken=function(e,r,o,u){if("string"==typeof o)return a.Payments.encodeSweepToken(e,r,o,u);if(u){var i=g(u.fee),s=n.validateAndParseAddress(u.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,a.toHex(r),i,s])}return t.INTERFACE.encodeFunctionData("sweepToken(address,uint256)",[e.address,a.toHex(r)])},t.encodePull=function(e,n){return t.INTERFACE.encodeFunctionData("pull",[e.address,a.toHex(n)])},t.encodeWrapETH=function(e){return t.INTERFACE.encodeFunctionData("wrapETH",[a.toHex(e)])},t}();function P(){P=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,o=Object.defineProperty||function(t,e,n){t[e]=n.value},u="function"==typeof Symbol?Symbol:{},i=u.iterator||"@@iterator",a=u.asyncIterator||"@@asyncIterator",s=u.toStringTag||"@@toStringTag";function p(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(t){p=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var u=Object.create((e&&e.prototype instanceof v?e:v).prototype),i=new O(r||[]);return o(u,"_invoke",{value:I(t,n,i)}),u}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=c;var l="suspendedStart",m="executing",f="completed",h={};function v(){}function A(){}function y(){}var w={};p(w,i,(function(){return this}));var T=Object.getPrototypeOf,x=T&&T(T(N([])));x&&x!==n&&r.call(x,i)&&(w=x);var E=y.prototype=v.prototype=Object.create(w);function k(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){function n(o,u,i,a){var s=d(t[o],t,u);if("throw"!==s.type){var p=s.arg,c=p.value;return c&&"object"==typeof c&&r.call(c,"__await")?e.resolve(c.__await).then((function(t){n("next",t,i,a)}),(function(t){n("throw",t,i,a)})):e.resolve(c).then((function(t){p.value=t,i(p)}),(function(t){return n("throw",t,i,a)}))}a(s.arg)}var u;o(this,"_invoke",{value:function(t,r){function o(){return new e((function(e,o){n(t,r,e,o)}))}return u=u?u.then(o,o):o()}})}function I(e,n,r){var o=l;return function(u,i){if(o===m)throw new Error("Generator is already running");if(o===f){if("throw"===u)throw i;return{value:t,done:!0}}for(r.method=u,r.arg=i;;){var a=r.delegate;if(a){var s=R(a,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(o===l)throw o=f,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);o=m;var p=d(e,n,r);if("normal"===p.type){if(o=r.done?f:"suspendedYield",p.arg===h)continue;return{value:p.arg,done:r.done}}"throw"===p.type&&(o=f,r.method="throw",r.arg=p.arg)}}}function R(e,n){var r=n.method,o=e.iterator[r];if(o===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,R(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var u=d(o,e.iterator,n.arg);if("throw"===u.type)return n.method="throw",n.arg=u.arg,n.delegate=null,h;var i=u.arg;return i?i.done?(n[e.resultName]=i.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,h):i:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,h)}function b(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(b,this),this.reset(!0)}function N(e){if(e||""===e){var n=e[i];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var o=-1,u=function n(){for(;++o<e.length;)if(r.call(e,o))return n.value=e[o],n.done=!1,n;return n.value=t,n.done=!0,n};return u.next=u}}throw new TypeError(typeof e+" is not iterable")}return A.prototype=y,o(E,"constructor",{value:y,configurable:!0}),o(y,"constructor",{value:A,configurable:!0}),A.displayName=p(y,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===A||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,y):(t.__proto__=y,p(t,s,"GeneratorFunction")),t.prototype=Object.create(E),t},e.awrap=function(t){return{__await:t}},k(g.prototype),p(g.prototype,a,(function(){return this})),e.AsyncIterator=g,e.async=function(t,n,r,o,u){void 0===u&&(u=Promise);var i=new g(c(t,n,r,o),u);return e.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},k(E),p(E,s,"Generator"),p(E,i,(function(){return this})),p(E,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},e.values=N,O.prototype={constructor:O,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(_),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function o(r,o){return a.type="throw",a.arg=e,n.next=r,o&&(n.method="next",n.arg=t),!!o}for(var u=this.tryEntries.length-1;u>=0;--u){var i=this.tryEntries[u],a=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var s=r.call(i,"catchLoc"),p=r.call(i,"finallyLoc");if(s&&p){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!p)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var o=this.tryEntries[n];if(o.tryLoc<=this.prev&&r.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var u=o;break}}u&&("break"===t||"continue"===t)&&u.tryLoc<=e&&e<=u.finallyLoc&&(u=null);var i=u?u.completion:{};return i.type=t,i.arg=e,u?(this.method="next",this.next=u.finallyLoc,h):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),_(n),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var o=r.arg;_(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:N(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),h}},e}function R(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:String(e)}function b(t,e,n,r,o,u,i){try{var a=t[u](i),s=a.value}catch(t){return void n(t)}a.done?e(s):Promise.resolve(s).then(r,o)}function _(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var u=t.apply(e,n);function i(t){b(u,r,o,i,a,"next",t)}function a(t){b(u,r,o,i,a,"throw",t)}i(void 0)}))}}function O(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,R(r.key),r)}}function N(t,e,n){return e&&O(t.prototype,e),n&&O(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function q(){return(q=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function F(t,e){var n,r;t.prototype=Object.create(e.prototype),t.prototype.constructor=t,n=t,r=e,(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(n,r)}function C(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function M(t,e){var n="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(n)return(n=n.call(t)).next.bind(n);if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return C(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?C(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function S(t,e){return n.CurrencyAmount.fromFractionalAmount(H(t.currency,e),t.numerator,t.denominator)}function H(t,e){if(e.involvesToken(t))return t;if(e.involvesToken(t.wrapped))return t.wrapped;if(!(e instanceof l.Pool))throw new Error("Expected currency "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol);return e.token0.wrapped.equals(t)?e.token0:e.token1.wrapped.equals(t)?e.token1:t}I.INTERFACE=new o.Interface(p.abi);var D=function(){function t(t,e,n,r){void 0===r&&(r=!1),this._midPrice=null,(t=r?t:t.filter((function(t){return!(t instanceof l.Pool&&0===t.tickSpacing)}))).length>0||u(!1);var o=t[0].chainId;t.every((function(t){return t.chainId===o}))||u(!1),this.pathInput=H(e,t[0]),this.pathOutput=H(n,t[t.length-1]),t[0]instanceof l.Pool?t[0].v4InvolvesToken(this.pathInput)||u(!1):t[0].involvesToken(this.pathInput)||u(!1);var i=t[t.length-1];i instanceof l.Pool?i.v4InvolvesToken(n)||i.v4InvolvesToken(n.wrapped)||u(!1):i.involvesToken(n.wrapped)||u(!1);var a=[this.pathInput];t[0].token0.equals(this.pathInput)?a.push(t[0].token1):a.push(t[0].token0);for(var s=1;s<t.length;s++){var p=t[s],c=a[s],d=void 0;if(p instanceof l.Pool&&!p.involvesToken(c)||!(p instanceof l.Pool)&&c.isNative)if(c.equals(p.token0.wrapped))d=p.token1;else{if(!c.wrapped.equals(p.token0)&&!c.wrapped.equals(p.token1))throw new Error("POOL_MISMATCH pool: "+JSON.stringify(p)+" inputToken: "+JSON.stringify(c));d=c.wrapped.equals(p.token0)?p.token1:p.token0}else c.equals(p.token0)||c.equals(p.token1)||u(!1),d=c.equals(p.token0)?p.token1:p.token0;a.push(d)}this.pools=t,this.path=a,this.input=e,this.output=null!=n?n:a[a.length-1]}return N(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,e){var n=t.price;return t.nextInput.equals(e.token0)?{nextInput:e.token1,price:n.multiply(e.token0Price.asFraction)}:{nextInput:e.token0,price:n.multiply(e.token1Price.asFraction)}}),this.pools[0].token0.equals(this.pathInput)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price.asFraction}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price.asFraction}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function U(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||u(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||u(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?t.swaps.reduce((function(t,e){return t+e.route.path.length}),0)-e.swaps.reduce((function(t,e){return t+e.route.path.length}),0):t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}var L,j=function(){function t(t){var e=t.routes,r=t.tradeType,o=e[0].inputAmount.currency,i=e[0].outputAmount.currency;e.every((function(t){return o.wrapped.equals(t.route.input.wrapped)}))||u(!1),e.every((function(t){return i.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var s,p=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,m=M(e);!(s=m()).done;)for(var f,h=M(s.value.route.pools);!(f=h()).done;){var v=f.value;if(v instanceof l.Pool)c.add(v.poolId);else if(v instanceof a.Pool)c.add(a.Pool.getAddress(v.token0,v.token1,v.fee));else{if(!(v instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");c.add(d.Pair.getAddress(v.token0,v.token1))}}p!==c.size&&u(!1),r!==n.TradeType.EXACT_INPUT&&u(!1),this.swaps=e,this.tradeType=r}t.fromRoute=function(){var e=_(P().mark((function e(r,o,i){var a,s,p,c,d;return P().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=new Array(r.path.length),i!==n.TradeType.EXACT_INPUT&&u(!1),o.currency.equals(r.input)||u(!1),a[0]=S(o,r.pools[0]),c=0;case 5:if(!(c<r.path.length-1)){e.next=15;break}return d=r.pools[c],e.next=9,d.getOutputAmount(S(a[c],d));case 9:a[c+1]=e.sent[0];case 12:c++,e.next=5;break;case 15:return s=n.CurrencyAmount.fromFractionalAmount(r.input,o.numerator,o.denominator),p=n.CurrencyAmount.fromFractionalAmount(r.output,a[a.length-1].numerator,a[a.length-1].denominator),e.abrupt("return",new t({routes:[{inputAmount:s,outputAmount:p,route:r}],tradeType:i}));case 18:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=_(P().mark((function e(r,o){var i,a,s,p,c,d,l,m,f,h,v;return P().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=[],o!==n.TradeType.EXACT_INPUT&&u(!1),a=M(r);case 3:if((s=a()).done){e.next=26;break}c=(p=s.value).route,d=p.amount,l=new Array(c.path.length),m=void 0,f=void 0,d.currency.equals(c.input)||u(!1),m=n.CurrencyAmount.fromFractionalAmount(c.input,d.numerator,d.denominator),l[0]=n.CurrencyAmount.fromFractionalAmount(c.pathInput,d.numerator,d.denominator),h=0;case 12:if(!(h<c.path.length-1)){e.next=22;break}return v=c.pools[h],e.next=16,v.getOutputAmount(S(l[h],v));case 16:l[h+1]=e.sent[0];case 19:h++,e.next=12;break;case 22:f=n.CurrencyAmount.fromFractionalAmount(c.output,l[l.length-1].numerator,l[l.length-1].denominator),i.push({route:c,inputAmount:m,outputAmount:f});case 24:e.next=3;break;case 26:return e.abrupt("return",new t({routes:i,tradeType:o}));case 27:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(q({},e,{routes:[{inputAmount:e.inputAmount,outputAmount:e.outputAmount,route:e.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(e){return new t(e)};var e=t.prototype;return e.minimumAmountOut=function(t,e){void 0===e&&(e=this.outputAmount),t.lessThan(A)&&u(!1);var r=new n.Fraction(y).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.maximumAmountIn=function(t,e){return void 0===e&&(e=this.inputAmount),t.lessThan(A)&&u(!1),e},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=_(P().mark((function e(r,o,i,a,s,p,c){var m,f,h,v,y,w,T,x,E,k,g;return P().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:h=void 0===(f=(m=void 0===a?{}:a).maxNumResults)?3:f,y=void 0===(v=m.maxHops)?3:v,void 0===s&&(s=[]),void 0===p&&(p=o),void 0===c&&(c=[]),r.length>0||u(!1),y>0||u(!1),o===p||s.length>0||u(!1),w=p,T=0;case 9:if(!(T<r.length)){e.next=56;break}if((x=r[T]).token0.equals((E=x instanceof l.Pool?w:w.wrapped).currency)||x.token1.equals(E.currency)){e.next=14;break}return e.abrupt("continue",53);case 14:if(!(x instanceof d.Pair)){e.next=17;break}if(!x.reserve0.equalTo(A)&&!x.reserve1.equalTo(A)){e.next=17;break}return e.abrupt("continue",53);case 17:if(k=void 0,e.prev=18,!(x instanceof l.Pool)){e.next=26;break}return e.next=23,x.getOutputAmount(E);case 23:e.t0=e.sent,e.next=29;break;case 26:return e.next=28,x.getOutputAmount(E.wrapped);case 28:e.t0=e.sent;case 29:k=e.t0[0],e.next=38;break;case 33:if(e.prev=33,e.t1=e.catch(18),!e.t1.isInsufficientInputAmountError){e.next=37;break}return e.abrupt("continue",53);case 37:throw e.t1;case 38:if(!k.currency.wrapped.equals(i.wrapped)){e.next=49;break}return e.t2=n.sortedInsert,e.t3=c,e.next=43,t.fromRoute(new D([].concat(s,[x]),o.currency,i),o,n.TradeType.EXACT_INPUT);case 43:e.t4=e.sent,e.t5=h,e.t6=U,(0,e.t2)(e.t3,e.t4,e.t5,e.t6),e.next=53;break;case 49:if(!(y>1&&r.length>1)){e.next=53;break}return g=r.slice(0,T).concat(r.slice(T+1,r.length)),e.next=53,t.bestTradeExactIn(g,o,i,{maxNumResults:h,maxHops:y-1},[].concat(s,[x]),k,c);case 53:T++,e.next=9;break;case 56:return e.abrupt("return",c);case 57:case"end":return e.stop()}}),e,null,[[18,33]])})));return function(t,n,r,o,u,i,a){return e.apply(this,arguments)}}(),N(t,[{key:"route",get:function(){return 1!==this.swaps.length&&u(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=M(this.swaps);!(t=r()).done;){var o=t.value;e=e.add(o.route.midPrice.quote(o.inputAmount))}var u=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new n.Percent(u.numerator,u.denominator),this._priceImpact}}]),t}();function X(t,e){if(e.token0.wrapped.equals(t.wrapped))return e.token0;if(e.token1.wrapped.equals(t.wrapped))return e.token1;throw new Error("Expected token "+t.symbol+" to be either "+e.token0.symbol+" or "+e.token1.symbol)}(L=exports.Protocol||(exports.Protocol={})).V2="V2",L.V3="V3",L.V4="V4",L.MIXED="MIXED";var V=function(t){function e(e){var n;return(n=t.call(this,e.pairs,e.input,e.output)||this).protocol=exports.Protocol.V2,n.pools=n.pairs,n.pathInput=X(e.input,n.pairs[0]),n.pathOutput=X(e.output,n.pairs[n.pairs.length-1]),n}return F(e,t),e}(d.Route),W=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.V3,n.path=e.tokenPath,n.pathInput=X(e.input,n.pools[0]),n.pathOutput=X(e.output,n.pools[n.pools.length-1]),n}return F(e,t),e}(a.Route),Z=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.V4,n.path=e.currencyPath,n}return F(e,t),e}(l.Route),B=function(t){function e(e){var n;return(n=t.call(this,e.pools,e.input,e.output)||this).protocol=exports.Protocol.MIXED,n}return F(e,t),e}(D),G=function(){function t(t){var e=t.v2Routes,n=void 0===e?[]:e,r=t.v3Routes,o=void 0===r?[]:r,i=t.v4Routes,s=void 0===i?[]:i,p=t.mixedRoutes,c=void 0===p?[]:p,m=t.tradeType;this.swaps=[],this.routes=[];for(var f,h=M(n);!(f=h()).done;){var v=f.value,A=v.inputAmount,y=v.outputAmount,w=new V(v.routev2);this.routes.push(w),this.swaps.push({route:w,inputAmount:A,outputAmount:y})}for(var T,x=M(o);!(T=x()).done;){var E=T.value,k=E.inputAmount,g=E.outputAmount,I=new W(E.routev3);this.routes.push(I),this.swaps.push({route:I,inputAmount:k,outputAmount:g})}for(var P,R=M(s);!(P=R()).done;){var b=P.value,_=b.inputAmount,O=b.outputAmount,N=new Z(b.routev4);this.routes.push(N),this.swaps.push({route:N,inputAmount:_,outputAmount:O})}for(var q,F=M(c);!(q=F()).done;){var C=q.value,S=C.inputAmount,H=C.outputAmount,D=new B(C.mixedRoute);this.routes.push(D),this.swaps.push({route:D,inputAmount:S,outputAmount:H})}if(0===this.swaps.length)throw new Error("No routes provided when calling Trade constructor");this.tradeType=m;var U=this.swaps[0].inputAmount.currency,L=this.swaps[0].outputAmount.currency;this.swaps.every((function(t){return U.wrapped.equals(t.route.input.wrapped)}))||u(!1),this.swaps.every((function(t){return L.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var j,X=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),G=new Set,Q=M(this.swaps);!(j=Q()).done;)for(var J,z=M(j.value.route.pools);!(J=z()).done;){var Y=J.value;if(Y instanceof l.Pool)G.add(Y.poolId);else if(Y instanceof a.Pool)G.add(a.Pool.getAddress(Y.token0,Y.token1,Y.fee));else{if(!(Y instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");G.add(d.Pair.getAddress(Y.token0,Y.token1))}}X!==G.size&&u(!1)}var e=t.prototype;return e.isWrappedNative=function(t){return t.equals(n.Ether.onChain(t.chainId).wrapped)},e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(A)&&u(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var r=new n.Fraction(y).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(A)&&u(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var r=new n.Fraction(y).add(t).multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.fromRoutes=function(){var e=_(P().mark((function e(n,r,o,u,i){var s,p,c,m,f,h,v,A,y,w,T,x,E,k,g,I,R,b,_,O,N,q,F,C,S,H,D;return P().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(s=[],p=[],c=[],m=[],f=M(n);!(h=f()).done;)y=new d.Trade(A=(v=h.value).routev2,v.amount,o),s.push({routev2:A,inputAmount:y.inputAmount,outputAmount:y.outputAmount});w=M(r);case 6:if((T=w()).done){e.next=15;break}return E=(x=T.value).routev3,k=x.amount,e.next=10,a.Trade.fromRoute(E,k,o);case 10:p.push({routev3:E,inputAmount:(g=e.sent).inputAmount,outputAmount:g.outputAmount});case 13:e.next=6;break;case 15:if(!i){e.next=26;break}I=M(i);case 17:if((R=I()).done){e.next=26;break}return _=(b=R.value).routev4,O=b.amount,e.next=21,l.Trade.fromRoute(_,O,o);case 21:c.push({routev4:_,inputAmount:(N=e.sent).inputAmount,outputAmount:N.outputAmount});case 24:e.next=17;break;case 26:if(!u){e.next=37;break}q=M(u);case 28:if((F=q()).done){e.next=37;break}return S=(C=F.value).mixedRoute,H=C.amount,e.next=32,j.fromRoute(S,H,o);case 32:m.push({mixedRoute:S,inputAmount:(D=e.sent).inputAmount,outputAmount:D.outputAmount});case 35:e.next=28;break;case 37:return e.abrupt("return",new t({v2Routes:s,v3Routes:p,v4Routes:c,mixedRoutes:m,tradeType:o}));case 38:case"end":return e.stop()}}),e)})));return function(t,n,r,o,u){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=_(P().mark((function e(n,r,o){var u,i,s,p,c,m,f,h;return P().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u=[],i=[],s=[],p=[],!(n instanceof d.Route)){e.next=10;break}c=new d.Trade(n,r,o),u=[{routev2:n,inputAmount:c.inputAmount,outputAmount:c.outputAmount}],e.next=35;break;case 10:if(!(n instanceof a.Route)){e.next=18;break}return e.next=13,a.Trade.fromRoute(n,r,o);case 13:i=[{routev3:n,inputAmount:(m=e.sent).inputAmount,outputAmount:m.outputAmount}],e.next=35;break;case 18:if(!(n instanceof l.Route)){e.next=26;break}return e.next=21,l.Trade.fromRoute(n,r,o);case 21:s=[{routev4:n,inputAmount:(f=e.sent).inputAmount,outputAmount:f.outputAmount}],e.next=35;break;case 26:if(!(n instanceof D)){e.next=34;break}return e.next=29,j.fromRoute(n,r,o);case 29:p=[{mixedRoute:n,inputAmount:(h=e.sent).inputAmount,outputAmount:h.outputAmount}],e.next=35;break;case 34:throw new Error("Invalid route type");case 35:return e.abrupt("return",new t({v2Routes:u,v3Routes:i,v4Routes:s,mixedRoutes:p,tradeType:o}));case 36:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),N(t,[{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"amounts",get:function(){var t,e,r=null==(t=this.swaps.find((function(t){return t.inputAmount.currency.isNative})))?void 0:t.inputAmount.currency,o=null==(e=this.swaps.find((function(t){return t.outputAmount.currency.isNative})))?void 0:e.outputAmount.currency;return{inputAmount:this.inputAmount,inputAmountNative:r?this.swaps.reduce((function(t,e){return e.route.pathInput.isNative?t.add(e.inputAmount):t}),n.CurrencyAmount.fromRawAmount(r,0)):void 0,outputAmount:this.outputAmount,outputAmountNative:o?this.swaps.reduce((function(t,e){return e.route.pathOutput.isNative?t.add(e.outputAmount):t}),n.CurrencyAmount.fromRawAmount(o,0)):void 0}}},{key:"numberOfInputWraps",get:function(){return this.inputAmount.currency.isNative?this.wethInputRoutes.length:0}},{key:"numberOfInputUnwraps",get:function(){return this.isWrappedNative(this.inputAmount.currency)?this.nativeInputRoutes.length:0}},{key:"nativeInputRoutes",get:function(){return this._nativeInputRoutes||(this._nativeInputRoutes=this.routes.filter((function(t){return t.pathInput.isNative}))),this._nativeInputRoutes}},{key:"wethInputRoutes",get:function(){var t=this;return this._wethInputRoutes||(this._wethInputRoutes=this.routes.filter((function(e){return t.isWrappedNative(e.pathInput)}))),this._wethInputRoutes}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"inputTax",get:function(){var t=this.inputAmount.currency;return t.isNative||!t.wrapped.sellFeeBps?w:new n.Percent(t.wrapped.sellFeeBps.toNumber(),1e4)}},{key:"outputTax",get:function(){var t=this.outputAmount.currency;return t.isNative||!t.wrapped.buyFeeBps?w:new n.Percent(t.wrapped.buyFeeBps.toNumber(),1e4)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;if(this.outputTax.equalTo(T))return w;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=M(this.swaps);!(t=r()).done;){var o=t.value,u=o.route.midPrice,i=o.inputAmount.multiply(new n.Fraction(y).subtract(this.inputTax));e=e.add(u.quote(i))}if(e.equalTo(A))return w;var a=this.outputAmount.divide(new n.Fraction(y).subtract(this.outputTax)),s=e.subtract(a).divide(e);return this._priceImpact=new n.Percent(s.numerator,s.denominator),this._priceImpact}}]),t}();function Q(t){var e,n;if(t.pools.some((function(t){return t instanceof l.Pool}))){e=[t.pathInput.isNative?f:t.pathInput.address],n=["address"];for(var r,o=t.pathInput,u=M(t.pools);!(r=u()).done;){var i=r.value,s=o.equals(i.token0)?i.token1:i.token0;if(i instanceof l.Pool)0===i.tickSpacing?(e.push(0,s.isNative?f:s.wrapped.address),n.push("uint8","address")):(e.push(i.fee+(4<<20),i.tickSpacing,i.hooks,s.isNative?f:s.wrapped.address),n.push("uint24","uint24","address","address"));else if(i instanceof a.Pool)e.push(i.fee+(3<<20),s.wrapped.address),n.push("uint24","address");else{if(!(i instanceof d.Pair))throw new Error("Unsupported pool type "+JSON.stringify(i));e.push(32,s.wrapped.address),n.push("uint8","address")}o=s}}else{var p=t.pools.reduce((function(t,e,n){var r=t.inputToken,o=t.path,u=t.types,i=e.token0.equals(r)?e.token1:e.token0;return 0===n?{inputToken:i,types:["address","uint24","address"],path:[r.wrapped.address,e instanceof a.Pool?e.fee:1<<23,i.wrapped.address]}:{inputToken:i,types:[].concat(u,["uint24","address"]),path:[].concat(o,[e instanceof a.Pool?e.fee:1<<23,i.wrapped.address])}}),{inputToken:t.input,path:[],types:[]});e=p.path,n=p.types}return m.pack(n,e)}var J=function(t){for(var e=[],n=0,r=0;r<t.pools.length;)(t.pools[n]instanceof l.Pool&&!(t.pools[r]instanceof l.Pool)||t.pools[n]instanceof a.Pool&&!(t.pools[r]instanceof a.Pool)||t.pools[n]instanceof d.Pair&&!(t.pools[r]instanceof d.Pair))&&(e.push(t.pools.slice(n,r)),n=r),++r===t.pools.length&&e.push(t.pools.slice(n,r));return e},z=function(t,e){return t.reduce((function(t,e){var n=t.inputToken;if(!e.involvesToken(n))throw new Error("PATH");return{inputToken:e.token0.equals(n)?e.token1:e.token0}}),{inputToken:e}).inputToken},Y=r.BigInt(0),$=new n.Percent(r.BigInt(50),r.BigInt(100)),K=function(){function t(){}return t.encodeV2Swap=function(e,r,o,u){var i=a.toHex(e.maximumAmountIn(r.slippageTolerance).quotient),s=a.toHex(e.minimumAmountOut(r.slippageTolerance).quotient),p=e.route.path.map((function(t){return t.address})),c=o?v:void 0===r.recipient?h:n.validateAndParseAddress(r.recipient);return e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[i,u?0:s,p,c]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[s,i,p,c])},t.encodeV3Swap=function(e,r,o,u){for(var i,s=[],p=M(e.swaps);!(i=p()).done;){var c=i.value,d=c.route,l=c.outputAmount,m=a.toHex(e.maximumAmountIn(r.slippageTolerance,c.inputAmount).quotient),f=a.toHex(e.minimumAmountOut(r.slippageTolerance,l).quotient),A=1===d.pools.length,y=o?v:void 0===r.recipient?h:n.validateAndParseAddress(r.recipient);if(A)s.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:y,amountIn:m,amountOutMinimum:u?0:f,sqrtPriceLimitX96:0}]):t.INTERFACE.encodeFunctionData("exactOutputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:y,amountOut:f,amountInMaximum:m,sqrtPriceLimitX96:0}]));else{var w=a.encodeRouteToPath(d,e.tradeType===n.TradeType.EXACT_OUTPUT);s.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:w,recipient:y,amountIn:m,amountOutMinimum:u?0:f}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:w,recipient:y,amountOut:f,amountInMaximum:m}]))}}return s},t.encodeMixedRouteSwap=function(e,r,o,i){var s=[];e.tradeType!==n.TradeType.EXACT_INPUT&&u(!1);for(var p,c=function(){var u=p.value,c=u.route,d=u.inputAmount,m=u.outputAmount;if(c.pools.some((function(t){return t instanceof l.Pool})))throw"Encoding mixed routes with V4 not supported";var f=a.toHex(e.maximumAmountIn(r.slippageTolerance,d).quotient),A=a.toHex(e.minimumAmountOut(r.slippageTolerance,m).quotient),y=1===c.pools.length,w=o?v:void 0===r.recipient?h:n.validateAndParseAddress(r.recipient),T=function(t){return t.pools.every((function(t){return t instanceof a.Pool}))};if(y)if(T(c))s.push(t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:c.path[0].wrapped.address,tokenOut:c.path[1].wrapped.address,fee:c.pools[0].fee,recipient:w,amountIn:f,amountOutMinimum:i?0:A,sqrtPriceLimitX96:0}]));else{var x=c.path.map((function(t){return t.wrapped.address}));s.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[f,i?0:A,x,w]))}else for(var E,k=J(c),g=function(t){return t===k.length-1},I=c.input.wrapped,P=0;P<k.length;P++){var R=k[P];E=z(R,I);var b=new D([].concat(R),R[0].token0.equals(I)?R[0].token0:R[0].token1,E),_=new B(b);if(I=E.wrapped,T(_)){var O={path:Q(_),recipient:g(P)?w:v,amountIn:0===P?f:0,amountOutMinimum:g(P)?A:0};s.push(t.INTERFACE.encodeFunctionData("exactInput",[O]))}else{var N=[0===P?f:0,g(P)?A:0,_.path.map((function(t){return t.wrapped.address})),g(P)?w:v];s.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",N))}}},d=M(e.swaps);!(p=d()).done;)c();return s},t.encodeSwaps=function(e,r,o){if(e instanceof G){e.swaps.every((function(t){return t.route.protocol===exports.Protocol.V3||t.route.protocol===exports.Protocol.V2||t.route.protocol===exports.Protocol.MIXED}))||u(!1);for(var i,s=[],p=M(e.swaps);!(i=p()).done;){var c=i.value,l=c.route,m=c.inputAmount,f=c.outputAmount;if(l.protocol===exports.Protocol.V2)s.push(new d.Trade(l,e.tradeType===n.TradeType.EXACT_INPUT?m:f,e.tradeType));else if(l.protocol===exports.Protocol.V3)s.push(a.Trade.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}));else{if(l.protocol!==exports.Protocol.MIXED)throw new Error("UNSUPPORTED_TRADE_PROTOCOL");s.push(j.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}))}}e=s}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof a.Trade||e instanceof j?e.swaps.length:1)}),0),v=e[0];e.every((function(t){return t.inputAmount.currency.equals(v.inputAmount.currency)}))||u(!1),e.every((function(t){return t.outputAmount.currency.equals(v.outputAmount.currency)}))||u(!1),e.every((function(t){return t.tradeType===v.tradeType}))||u(!1);var A=[],y=v.inputAmount.currency.isNative,w=v.outputAmount.currency.isNative,T=v.tradeType===n.TradeType.EXACT_INPUT&&h>2,x=w||!!r.fee||!!o||T;r.inputTokenPermit&&(v.inputAmount.currency.isToken||u(!1),A.push(a.SelfPermit.encodePermit(v.inputAmount.currency,r.inputTokenPermit)));for(var E,k=M(e);!(E=k()).done;){var g=E.value;if(g instanceof d.Trade)A.push(t.encodeV2Swap(g,r,x,T));else if(g instanceof a.Trade)for(var I,P=M(t.encodeV3Swap(g,r,x,T));!(I=P()).done;)A.push(I.value);else{if(!(g instanceof j))throw new Error("Unsupported trade object");for(var R,b=M(t.encodeMixedRouteSwap(g,r,x,T));!(R=b()).done;)A.push(R.value)}}var _=n.CurrencyAmount.fromRawAmount(v.inputAmount.currency,0),O=n.CurrencyAmount.fromRawAmount(v.outputAmount.currency,0),N=e.reduce((function(t,e){return t.add(e.minimumAmountOut(r.slippageTolerance))}),O),q=e.reduce((function(t,e){return t.add(e.outputAmount)}),O),F=e.reduce((function(t,e){return t.add(e.maximumAmountIn(r.slippageTolerance))}),_);return{calldatas:A,sampleTrade:v,routerMustCustody:x,inputIsNative:y,outputIsNative:w,totalAmountIn:F,minimumAmountOut:N,quoteAmountOut:q}},t.swapCallParameters=function(e,r){var o=t.encodeSwaps(e,r),u=o.calldatas,i=o.sampleTrade,s=o.inputIsNative,p=o.totalAmountIn,c=o.minimumAmountOut;return o.routerMustCustody&&u.push(o.outputIsNative?I.encodeUnwrapWETH9(c.quotient,r.recipient,r.fee):I.encodeSweepToken(i.outputAmount.currency.wrapped,c.quotient,r.recipient,r.fee)),s&&(i.tradeType===n.TradeType.EXACT_OUTPUT||t.riskOfPartialFill(e))&&u.push(a.Payments.encodeRefundETH()),{calldata:k.encodeMulticall(u,r.deadlineOrPreviousBlockhash),value:a.toHex(s?p.quotient:Y)}},t.swapAndAddCallParameters=function(e,r,o,i,s,p){var c=t.encodeSwaps(e,r,!0),d=c.calldatas,l=c.inputIsNative,m=c.outputIsNative,f=c.sampleTrade,h=c.totalAmountIn,v=c.quoteAmountOut,A=c.minimumAmountOut;r.outputTokenPermit&&(v.currency.isToken||u(!1),d.push(a.SelfPermit.encodePermit(v.currency,r.outputTokenPermit)));var y=f.route.chainId,w=o.pool.token0.wrapped.address===h.currency.wrapped.address,T=t.getPositionAmounts(o,w),x=T.positionAmountIn,g=T.positionAmountOut,P=l?n.WETH9[y]:x.currency.wrapped,R=m?n.WETH9[y]:g.currency.wrapped,b=g.subtract(v.wrapped);b.greaterThan(n.CurrencyAmount.fromRawAmount(g.currency,0))&&d.push(m?I.encodeWrapETH(b.quotient):I.encodePull(R,b.quotient)),d.push(l?I.encodeWrapETH(x.quotient):I.encodePull(P,x.quotient)),s!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(E.encodeApprove(P,s)),p!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(E.encodeApprove(R,p));var _,O=a.Position.fromAmounts({pool:o.pool,tickLower:o.tickLower,tickUpper:o.tickUpper,amount0:w?o.amount0.quotient.toString():A.quotient.toString(),amount1:w?A.quotient.toString():o.amount1.quotient.toString(),useFullPrecision:!1});return d.push(E.encodeAddLiquidity(o,O,i,r.slippageTolerance)),d.push(l?I.encodeUnwrapWETH9(Y):I.encodeSweepToken(P,Y)),d.push(m?I.encodeUnwrapWETH9(Y):I.encodeSweepToken(R,Y)),_=l?h.wrapped.add(x.wrapped).quotient:m?b.quotient:Y,{calldata:k.encodeMulticall(d,r.deadlineOrPreviousBlockhash),value:_.toString()}},t.riskOfPartialFill=function(e){return Array.isArray(e)?e.some((function(e){return t.v3TradeWithHighPriceImpact(e)})):t.v3TradeWithHighPriceImpact(e)},t.v3TradeWithHighPriceImpact=function(t){return!(t instanceof d.Trade)&&t.priceImpact.greaterThan($)},t.getPositionAmounts=function(t,e){var r=t.mintAmounts,o=r.amount1,u=n.CurrencyAmount.fromRawAmount(t.pool.token0,r.amount0),i=n.CurrencyAmount.fromRawAmount(t.pool.token1,o),a=e?[u,i]:[i,u];return{positionAmountIn:a[0],positionAmountOut:a[1]}},t}();K.INTERFACE=new o.Interface(c.abi),exports.ADDRESS_THIS=v,exports.ADDRESS_ZERO=f,exports.ApproveAndCall=E,exports.MIXED_QUOTER_V1_V2_FEE_PATH_PLACEHOLDER=1<<23,exports.MIXED_QUOTER_V2_V2_FEE_PATH_PLACEHOLDER=32,exports.MIXED_QUOTER_V2_V3_FEE_PATH_PLACEHOLDER=3<<20,exports.MIXED_QUOTER_V2_V4_FEE_PATH_PLACEHOLDER=4<<20,exports.MSG_SENDER=h,exports.MixedRoute=B,exports.MixedRouteSDK=D,exports.MixedRouteTrade=j,exports.MulticallExtended=k,exports.ONE=y,exports.ONE_HUNDRED_PERCENT=T,exports.PaymentsExtended=I,exports.RouteV2=V,exports.RouteV3=W,exports.RouteV4=Z,exports.SwapRouter=K,exports.Trade=G,exports.ZERO=A,exports.ZERO_PERCENT=w,exports.amountWithPathCurrency=S,exports.encodeMixedRouteToPath=Q,exports.getOutputOfPools=z,exports.getPathCurrency=H,exports.getPathToken=X,exports.isMint=x,exports.partitionMixedRouteByProtocol=J,exports.tradeComparator=U;
2
2
  //# sourceMappingURL=router-sdk.cjs.production.min.js.map