@uniswap/router-sdk 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/router-sdk.cjs.development.js +244 -454
- package/dist/router-sdk.cjs.development.js.map +1 -1
- package/dist/router-sdk.cjs.production.min.js +1 -1
- package/dist/router-sdk.cjs.production.min.js.map +1 -1
- package/dist/router-sdk.esm.js +244 -454
- package/dist/router-sdk.esm.js.map +1 -1
- package/dist/utils/encodeMixedRouteToPath.d.ts +2 -1
- package/package.json +5 -5
|
@@ -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=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json")),a=require("@uniswap/v3-sdk"),s=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json")),p=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json")),c=t(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(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}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 b(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 _(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,M(r.key),r)}}function O(t,e,n){return e&&_(t.prototype,e),n&&_(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function N(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 P(t,e);var n={}.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)?P(t,e):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 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)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(null,arguments)}function F(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,function(t,e){(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}(t,e)}function C(){C=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 _(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(O([])));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 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=P(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 P(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,P(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 b(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(R,this),this.reset(!0)}function O(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=O,_.prototype={constructor:_,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(b),!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 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),b(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;b(n)}return o}}throw Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:O(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),h}},e}function M(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:e+""}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(){return O((function(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]}),[{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)}}])}();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,X=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=N(e);!(s=m()).done;)for(var f,h=N(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=b(C().mark((function e(r,o,i){var a,s,p,c,d;return C().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=b(C().mark((function e(r,o){var i,a,s,p,c,d,l,m,f,h,v;return C().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=[],o!==n.TradeType.EXACT_INPUT&&u(!1),a=N(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=b(C().mark((function e(r,o,i,a,s,p,c){var m,f,h,v,y,w,T,x,E,k,g;return C().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)}}(),O(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=N(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}}])}();function j(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=j(e.input,n.pairs[0]),n.pathOutput=j(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=j(e.input,n.pools[0]),n.pathOutput=j(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=N(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=N(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=N(s);!(P=R()).done;){var b=P.value,_=b.inputAmount,O=b.outputAmount,q=new Z(b.routev4);this.routes.push(q),this.swaps.push({route:q,inputAmount:_,outputAmount:O})}for(var F,C=N(c);!(F=C()).done;){var M=F.value,S=M.inputAmount,H=M.outputAmount,D=new B(M.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 X,j=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),G=new Set,Q=N(this.swaps);!(X=Q()).done;)for(var J,z=N(X.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))}}j!==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=b(C().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,P,R,b,_,O,q,F,M,S,H,D;return C().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(s=[],p=[],c=[],m=[],f=N(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=N(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=N(i);case 17:if((P=I()).done){e.next=26;break}return b=(R=P.value).routev4,_=R.amount,e.next=21,l.Trade.fromRoute(b,_,o);case 21:c.push({routev4:b,inputAmount:(O=e.sent).inputAmount,outputAmount:O.outputAmount});case 24:e.next=17;break;case 26:if(!u){e.next=37;break}q=N(u);case 28:if((F=q()).done){e.next=37;break}return S=(M=F.value).mixedRoute,H=M.amount,e.next=32,X.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=b(C().mark((function e(n,r,o){var u,i,s,p,c,m,f,h;return C().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,X.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)}}(),O(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=N(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}}])}();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=N(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=N(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 new Error("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=N(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=N(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(X.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 X?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=N(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=N(t.encodeV3Swap(g,r,x,T));!(I=P()).done;)A.push(I.value);else{if(!(g instanceof X))throw new Error("Unsupported trade object");for(var R,b=N(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),q=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),C=e.reduce((function(t,e){return t.add(e.maximumAmountIn(r.slippageTolerance))}),_);return{calldatas:A,sampleTrade:v,routerMustCustody:x,inputIsNative:y,outputIsNative:w,totalAmountIn:C,minimumAmountOut:q,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?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=X,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=j,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"),o=t(require("jsbi")),r=require("@ethersproject/abi"),u=t(require("tiny-invariant")),i=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json")),a=require("@uniswap/v3-sdk"),p=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json")),s=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json")),c=t(require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json")),d=require("@uniswap/v2-sdk"),m=require("@uniswap/v4-sdk"),l=require("@ethersproject/solidity"),f="0x0000000000000000000000000000000000000000",h="0x0000000000000000000000000000000000000001",A="0x0000000000000000000000000000000000000002",v=o.BigInt(0),y=o.BigInt(1),T=new n.Percent(v),w=new n.Percent(100,100);function k(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,r,u){var i=e.mintAmountsWithSlippage(u),p=i.amount0,s=i.amount1;return o.lessThan(n.amount0.quotient,p)&&(p=n.amount0.quotient),o.lessThan(n.amount1.quotient,s)&&(s=n.amount1.quotient),k(r)?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(p),amount1Min:a.toHex(s),recipient:r.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:a.toHex(p),amount1Min:a.toHex(s),tokenId:a.toHex(r.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 r.Interface(i.abi);var I=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 o=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[])",[o,e])}var r=a.toHex(n);return t.INTERFACE.encodeFunctionData("multicall(uint256,bytes[])",[r,e])},t}();function P(t){return a.toHex(t.multiply(1e4).quotient)}I.INTERFACE=new r.Interface(p.abi);var x=function(){function t(){}return t.encodeUnwrapWETH9=function(e,o,r){if("string"==typeof o)return a.Payments.encodeUnwrapWETH9(e,o,r);if(r){var u=P(r.fee),i=n.validateAndParseAddress(r.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,o,r,u){if("string"==typeof r)return a.Payments.encodeSweepToken(e,o,r,u);if(u){var i=P(u.fee),p=n.validateAndParseAddress(u.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,a.toHex(o),i,p])}return t.INTERFACE.encodeFunctionData("sweepToken(address,uint256)",[e.address,a.toHex(o)])},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 R(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,o=Array(e);n<e;n++)o[n]=t[n];return o}function g(t,e,n,o,r,u,i){try{var a=t[u](i),p=a.value}catch(t){return void n(t)}a.done?e(p):Promise.resolve(p).then(o,r)}function _(t){return function(){var e=this,n=arguments;return new Promise((function(o,r){var u=t.apply(e,n);function i(t){g(u,o,r,i,a,"next",t)}function a(t){g(u,o,r,i,a,"throw",t)}i(void 0)}))}}function b(t,e){for(var n=0;n<e.length;n++){var o=e[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(t,S(o.key),o)}}function O(t,e,n){return e&&b(t.prototype,e),n&&b(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function N(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 R(t,e);var n={}.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)?R(t,e):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var o=0;return function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}}}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 q(){return(q=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var o in n)({}).hasOwnProperty.call(n,o)&&(t[o]=n[o])}return t}).apply(null,arguments)}function F(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,function(t,e){(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}(t,e)}function C(){var t,e,n="function"==typeof Symbol?Symbol:{},o=n.iterator||"@@iterator",r=n.toStringTag||"@@toStringTag";function u(n,o,r,u){var p=Object.create((o&&o.prototype instanceof a?o:a).prototype);return M(p,"_invoke",function(n,o,r){var u,a,p,s=0,c=r||[],d=!1,m={p:0,n:0,v:t,a:l,f:l.bind(t,4),d:function(e,n){return u=e,a=0,p=t,m.n=n,i}};function l(n,o){for(a=n,p=o,e=0;!d&&s&&!r&&e<c.length;e++){var r,u=c[e],l=m.p,f=u[2];n>3?(r=f===o)&&(p=u[(a=u[4])?5:(a=3,3)],u[4]=u[5]=t):u[0]<=l&&((r=n<2&&l<u[1])?(a=0,m.v=o,m.n=u[1]):l<f&&(r=n<3||u[0]>o||o>f)&&(u[4]=n,u[5]=o,m.n=f,a=0))}if(r||n>1)return i;throw d=!0,o}return function(r,c,f){if(s>1)throw TypeError("Generator is already running");for(d&&1===c&&l(c,f),a=c,p=f;(e=a<2?t:p)||!d;){u||(a?a<3?(a>1&&(m.n=-1),l(a,p)):m.n=p:m.v=p);try{if(s=2,u){if(a||(r="next"),e=u[r]){if(!(e=e.call(u,p)))throw TypeError("iterator result is not an object");if(!e.done)return e;p=e.value,a<2&&(a=0)}else 1===a&&(e=u.return)&&e.call(u),a<2&&(p=TypeError("The iterator does not provide a '"+r+"' method"),a=1);u=t}else if((e=(d=m.n<0)?p:n.call(o,m))!==i)break}catch(e){u=t,a=1,p=e}finally{s=1}}return{value:e,done:d}}}(n,r,u),!0),p}var i={};function a(){}function p(){}function s(){}e=Object.getPrototypeOf;var c=[][o]?e(e([][o]())):(M(e={},o,(function(){return this})),e),d=s.prototype=a.prototype=Object.create(c);function m(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,s):(t.__proto__=s,M(t,r,"GeneratorFunction")),t.prototype=Object.create(d),t}return p.prototype=s,M(d,"constructor",s),M(s,"constructor",p),p.displayName="GeneratorFunction",M(s,r,"GeneratorFunction"),M(d),M(d,r,"Generator"),M(d,o,(function(){return this})),M(d,"toString",(function(){return"[object Generator]"})),(C=function(){return{w:u,m:m}})()}function M(t,e,n,o){var r=Object.defineProperty;try{r({},"",{})}catch(t){r=0}(M=function(t,e,n,o){function u(e,n){M(t,e,(function(t){return this._invoke(e,n,t)}))}e?r?r(t,e,{value:n,enumerable:!o,configurable:!o,writable:!o}):t[e]=n:(u("next",0),u("throw",1),u("return",2))})(t,e,n,o)}function S(t){var e=function(t,e){if("object"!=typeof t||!t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var o=n.call(t,"string");if("object"!=typeof o)return o;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof e?e:e+""}function H(t,e){return n.CurrencyAmount.fromFractionalAmount(D(t.currency,e),t.numerator,t.denominator)}function D(t,e){if(e.involvesToken(t))return t;if(e.involvesToken(t.wrapped))return t.wrapped;if(!(e instanceof m.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}x.INTERFACE=new r.Interface(s.abi);var U=function(){return O((function(t,e,n,o){void 0===o&&(o=!1),this._midPrice=null,(t=o?t:t.filter((function(t){return!(t instanceof m.Pool&&0===t.tickSpacing)}))).length>0||u(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||u(!1),this.pathInput=D(e,t[0]),this.pathOutput=D(n,t[t.length-1]),t[0]instanceof m.Pool?t[0].v4InvolvesToken(this.pathInput)||u(!1):t[0].involvesToken(this.pathInput)||u(!1);var i=t[t.length-1];i instanceof m.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 p=1;p<t.length;p++){var s=t[p],c=a[p],d=void 0;if(s instanceof m.Pool&&!s.involvesToken(c)||!(s instanceof m.Pool)&&c.isNative)if(c.equals(s.token0.wrapped))d=s.token1;else{if(!c.wrapped.equals(s.token0)&&!c.wrapped.equals(s.token1))throw new Error("POOL_MISMATCH pool: "+JSON.stringify(s)+" inputToken: "+JSON.stringify(c));d=c.wrapped.equals(s.token0)?s.token1:s.token0}else c.equals(s.token0)||c.equals(s.token1)||u(!1),d=c.equals(s.token0)?s.token1:s.token0;a.push(d)}this.pools=t,this.path=a,this.input=e,this.output=null!=n?n:a[a.length-1]}),[{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)}}])}();function X(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 j,V=function(){function t(t){var e=t.routes,o=t.tradeType,r=e[0].inputAmount.currency,i=e[0].outputAmount.currency;e.every((function(t){return r.wrapped.equals(t.route.input.wrapped)}))||u(!1),e.every((function(t){return i.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var p,s=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,l=N(e);!(p=l()).done;)for(var f,h=N(p.value.route.pools);!(f=h()).done;){var A=f.value;if(A instanceof m.Pool)c.add(A.poolId);else if(A instanceof a.Pool)c.add(a.Pool.getAddress(A.token0,A.token1,A.fee));else{if(!(A instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");c.add(d.Pair.getAddress(A.token0,A.token1))}}s!==c.size&&u(!1),o!==n.TradeType.EXACT_INPUT&&u(!1),this.swaps=e,this.tradeType=o}t.fromRoute=function(){var e=_(C().m((function e(o,r,i){var a,p,s,c,d;return C().w((function(e){for(;;)switch(e.n){case 0:a=new Array(o.path.length),i!==n.TradeType.EXACT_INPUT&&u(!1),r.currency.equals(o.input)||u(!1),a[0]=H(r,o.pools[0]),c=0;case 1:if(!(c<o.path.length-1)){e.n=4;break}return d=o.pools[c],e.n=2,d.getOutputAmount(H(a[c],d));case 2:a[c+1]=e.v[0];case 3:c++,e.n=1;break;case 4:return p=n.CurrencyAmount.fromFractionalAmount(o.input,r.numerator,r.denominator),s=n.CurrencyAmount.fromFractionalAmount(o.output,a[a.length-1].numerator,a[a.length-1].denominator),e.a(2,new t({routes:[{inputAmount:p,outputAmount:s,route:o}],tradeType:i}))}}),e)})));return function(t,n,o){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=_(C().m((function e(o,r){var i,a,p,s,c,d,m,l,f,h,A;return C().w((function(e){for(;;)switch(e.n){case 0:i=[],r!==n.TradeType.EXACT_INPUT&&u(!1),a=N(o);case 1:if((p=a()).done){e.n=7;break}c=(s=p.value).route,d=s.amount,m=new Array(c.path.length),l=void 0,f=void 0,d.currency.equals(c.input)||u(!1),l=n.CurrencyAmount.fromFractionalAmount(c.input,d.numerator,d.denominator),m[0]=n.CurrencyAmount.fromFractionalAmount(c.pathInput,d.numerator,d.denominator),h=0;case 2:if(!(h<c.path.length-1)){e.n=5;break}return A=c.pools[h],e.n=3,A.getOutputAmount(H(m[h],A));case 3:m[h+1]=e.v[0];case 4:h++,e.n=2;break;case 5:f=n.CurrencyAmount.fromFractionalAmount(c.output,m[m.length-1].numerator,m[m.length-1].denominator),i.push({route:c,inputAmount:l,outputAmount:f});case 6:e.n=1;break;case 7:return e.a(2,new t({routes:i,tradeType:r}))}}),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(v)&&u(!1);var o=new n.Fraction(y).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},e.maximumAmountIn=function(t,e){return void 0===e&&(e=this.inputAmount),t.lessThan(v)&&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=_(C().m((function e(o,r,i,a,p,s,c){var l,f,h,A,y,T,w,k,E,I,P,x,R,g,_;return C().w((function(e){for(;;)switch(e.p=e.n){case 0:h=void 0===(f=(l=void 0===a?{}:a).maxNumResults)?3:f,y=void 0===(A=l.maxHops)?3:A,void 0===p&&(p=[]),void 0===s&&(s=r),void 0===c&&(c=[]),o.length>0||u(!1),y>0||u(!1),r===s||p.length>0||u(!1),T=s,w=0;case 1:if(!(w<o.length)){e.n=15;break}if((k=o[w]).token0.equals((E=k instanceof m.Pool?T:T.wrapped).currency)||k.token1.equals(E.currency)){e.n=2;break}return e.a(3,14);case 2:if(!(k instanceof d.Pair)){e.n=3;break}if(!k.reserve0.equalTo(v)&&!k.reserve1.equalTo(v)){e.n=3;break}return e.a(3,14);case 3:if(I=void 0,e.p=4,!(k instanceof m.Pool)){e.n=6;break}return e.n=5,k.getOutputAmount(E);case 5:x=e.v,e.n=8;break;case 6:return e.n=7,k.getOutputAmount(E.wrapped);case 7:x=e.v;case 8:I=x[0],e.n=11;break;case 9:if(e.p=9,!(R=e.v).isInsufficientInputAmountError){e.n=10;break}return e.a(3,14);case 10:throw R;case 11:if(!I.currency.wrapped.equals(i.wrapped)){e.n=13;break}return g=n.sortedInsert,_=c,e.n=12,t.fromRoute(new U([].concat(p,[k]),r.currency,i),r,n.TradeType.EXACT_INPUT);case 12:g(_,e.v,h,X),e.n=14;break;case 13:if(!(y>1&&o.length>1)){e.n=14;break}return P=o.slice(0,w).concat(o.slice(w+1,o.length)),e.n=14,t.bestTradeExactIn(P,r,i,{maxNumResults:h,maxHops:y-1},[].concat(p,[k]),I,c);case 14:w++,e.n=1;break;case 15:return e.a(2,c)}}),e,null,[[4,9]])})));return function(t,n,o,r,u,i,a){return e.apply(this,arguments)}}(),O(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),o=N(this.swaps);!(t=o()).done;){var r=t.value;e=e.add(r.route.midPrice.quote(r.inputAmount))}var u=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new n.Percent(u.numerator,u.denominator),this._priceImpact}}])}();function W(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)}(j=exports.Protocol||(exports.Protocol={})).V2="V2",j.V3="V3",j.V4="V4",j.MIXED="MIXED";var L=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=W(e.input,n.pairs[0]),n.pathOutput=W(e.output,n.pairs[n.pairs.length-1]),n}return F(e,t),e}(d.Route),Z=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=W(e.input,n.pools[0]),n.pathOutput=W(e.output,n.pools[n.pools.length-1]),n}return F(e,t),e}(a.Route),B=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}(m.Route),Q=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}(U),G=function(){function t(t){var e=t.v2Routes,n=void 0===e?[]:e,o=t.v3Routes,r=void 0===o?[]:o,i=t.v4Routes,p=void 0===i?[]:i,s=t.mixedRoutes,c=void 0===s?[]:s,l=t.tradeType;this.swaps=[],this.routes=[];for(var f,h=N(n);!(f=h()).done;){var A=f.value,v=A.inputAmount,y=A.outputAmount,T=new L(A.routev2);this.routes.push(T),this.swaps.push({route:T,inputAmount:v,outputAmount:y})}for(var w,k=N(r);!(w=k()).done;){var E=w.value,I=E.inputAmount,P=E.outputAmount,x=new Z(E.routev3);this.routes.push(x),this.swaps.push({route:x,inputAmount:I,outputAmount:P})}for(var R,g=N(p);!(R=g()).done;){var _=R.value,b=_.inputAmount,O=_.outputAmount,q=new B(_.routev4);this.routes.push(q),this.swaps.push({route:q,inputAmount:b,outputAmount:O})}for(var F,C=N(c);!(F=C()).done;){var M=F.value,S=M.inputAmount,H=M.outputAmount,D=new Q(M.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=l;var U=this.swaps[0].inputAmount.currency,X=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 X.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var j,V=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),W=new Set,G=N(this.swaps);!(j=G()).done;)for(var J,z=N(j.value.route.pools);!(J=z()).done;){var $=J.value;if($ instanceof m.Pool)W.add($.poolId);else if($ instanceof a.Pool)W.add(a.Pool.getAddress($.token0,$.token1,$.fee));else{if(!($ instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");W.add(d.Pair.getAddress($.token0,$.token1))}}V!==W.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(v)&&u(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var o=new n.Fraction(y).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(v)&&u(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var o=new n.Fraction(y).add(t).multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,o)},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=_(C().m((function e(n,o,r,u,i){var p,s,c,l,f,h,A,v,y,T,w,k,E,I,P,x,R,g,_,b,O,q,F,M,S,H,D;return C().w((function(e){for(;;)switch(e.n){case 0:for(p=[],s=[],c=[],l=[],f=N(n);!(h=f()).done;)y=new d.Trade(v=(A=h.value).routev2,A.amount,r),p.push({routev2:v,inputAmount:y.inputAmount,outputAmount:y.outputAmount});T=N(o);case 1:if((w=T()).done){e.n=4;break}return E=(k=w.value).routev3,I=k.amount,e.n=2,a.Trade.fromRoute(E,I,r);case 2:s.push({routev3:E,inputAmount:(P=e.v).inputAmount,outputAmount:P.outputAmount});case 3:e.n=1;break;case 4:if(!i){e.n=8;break}x=N(i);case 5:if((R=x()).done){e.n=8;break}return _=(g=R.value).routev4,b=g.amount,e.n=6,m.Trade.fromRoute(_,b,r);case 6:c.push({routev4:_,inputAmount:(O=e.v).inputAmount,outputAmount:O.outputAmount});case 7:e.n=5;break;case 8:if(!u){e.n=12;break}q=N(u);case 9:if((F=q()).done){e.n=12;break}return S=(M=F.value).mixedRoute,H=M.amount,e.n=10,V.fromRoute(S,H,r);case 10:l.push({mixedRoute:S,inputAmount:(D=e.v).inputAmount,outputAmount:D.outputAmount});case 11:e.n=9;break;case 12:return e.a(2,new t({v2Routes:p,v3Routes:s,v4Routes:c,mixedRoutes:l,tradeType:r}))}}),e)})));return function(t,n,o,r,u){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=_(C().m((function e(n,o,r){var u,i,p,s,c,l,f,h;return C().w((function(e){for(;;)switch(e.n){case 0:if(u=[],i=[],p=[],s=[],!(n instanceof d.Route)){e.n=1;break}c=new d.Trade(n,o,r),u=[{routev2:n,inputAmount:c.inputAmount,outputAmount:c.outputAmount}],e.n=8;break;case 1:if(!(n instanceof a.Route)){e.n=3;break}return e.n=2,a.Trade.fromRoute(n,o,r);case 2:i=[{routev3:n,inputAmount:(l=e.v).inputAmount,outputAmount:l.outputAmount}],e.n=8;break;case 3:if(!(n instanceof m.Route)){e.n=5;break}return e.n=4,m.Trade.fromRoute(n,o,r);case 4:p=[{routev4:n,inputAmount:(f=e.v).inputAmount,outputAmount:f.outputAmount}],e.n=8;break;case 5:if(!(n instanceof U)){e.n=7;break}return e.n=6,V.fromRoute(n,o,r);case 6:s=[{mixedRoute:n,inputAmount:(h=e.v).inputAmount,outputAmount:h.outputAmount}],e.n=8;break;case 7:throw new Error("Invalid route type");case 8:return e.a(2,new t({v2Routes:u,v3Routes:i,v4Routes:p,mixedRoutes:s,tradeType:r}))}}),e)})));return function(t,n,o){return e.apply(this,arguments)}}(),O(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,o=null==(t=this.swaps.find((function(t){return t.inputAmount.currency.isNative})))?void 0:t.inputAmount.currency,r=null==(e=this.swaps.find((function(t){return t.outputAmount.currency.isNative})))?void 0:e.outputAmount.currency;return{inputAmount:this.inputAmount,inputAmountNative:o?this.swaps.reduce((function(t,e){return e.route.pathInput.isNative?t.add(e.inputAmount):t}),n.CurrencyAmount.fromRawAmount(o,0)):void 0,outputAmount:this.outputAmount,outputAmountNative:r?this.swaps.reduce((function(t,e){return e.route.pathOutput.isNative?t.add(e.outputAmount):t}),n.CurrencyAmount.fromRawAmount(r,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?T:new n.Percent(t.wrapped.sellFeeBps.toNumber(),1e4)}},{key:"outputTax",get:function(){var t=this.outputAmount.currency;return t.isNative||!t.wrapped.buyFeeBps?T:new n.Percent(t.wrapped.buyFeeBps.toNumber(),1e4)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;if(this.outputTax.equalTo(w))return T;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),o=N(this.swaps);!(t=o()).done;){var r=t.value,u=r.route.midPrice,i=r.inputAmount.multiply(new n.Fraction(y).subtract(this.inputTax));e=e.add(u.quote(i))}if(e.equalTo(v))return T;var a=this.outputAmount.divide(new n.Fraction(y).subtract(this.outputTax)),p=e.subtract(a).divide(e);return this._priceImpact=new n.Percent(p.numerator,p.denominator),this._priceImpact}}])}();function J(t,e){var n,o;if(null!=e?e:t.pools.some((function(t){return t instanceof m.Pool}))){n=[t.pathInput.isNative?f:t.pathInput.address],o=["address"];for(var r,u=t.pathInput,i=N(t.pools);!(r=i()).done;){var p=r.value,s=u.equals(p.token0)?p.token1:p.token0;if(p instanceof m.Pool)0===p.tickSpacing?(n.push(0,s.isNative?f:s.wrapped.address),o.push("uint8","address")):(n.push(p.fee+(4<<20),p.tickSpacing,p.hooks,s.isNative?f:s.wrapped.address),o.push("uint24","uint24","address","address"));else if(p instanceof a.Pool)n.push(p.fee+(3<<20),s.wrapped.address),o.push("uint24","address");else{if(!(p instanceof d.Pair))throw new Error("Unsupported pool type "+JSON.stringify(p));n.push(32,s.wrapped.address),o.push("uint8","address")}u=s}}else{var c=t.pools.reduce((function(t,e,n){var o=t.inputToken,r=t.path,u=t.types,i=e.token0.equals(o)?e.token1:e.token0;return 0===n?{inputToken:i,types:["address","uint24","address"],path:[o.wrapped.address,e instanceof a.Pool?e.fee:1<<23,i.wrapped.address]}:{inputToken:i,types:[].concat(u,["uint24","address"]),path:[].concat(r,[e instanceof a.Pool?e.fee:1<<23,i.wrapped.address])}}),{inputToken:t.input,path:[],types:[]});n=c.path,o=c.types}return l.pack(o,n)}var z=function(t){for(var e=[],n=0,o=0;o<t.pools.length;)(t.pools[n]instanceof m.Pool&&!(t.pools[o]instanceof m.Pool)||t.pools[n]instanceof a.Pool&&!(t.pools[o]instanceof a.Pool)||t.pools[n]instanceof d.Pair&&!(t.pools[o]instanceof d.Pair))&&(e.push(t.pools.slice(n,o)),n=o),++o===t.pools.length&&e.push(t.pools.slice(n,o));return e},$=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},K=o.BigInt(0),Y=new n.Percent(o.BigInt(50),o.BigInt(100)),tt=function(){function t(){}return t.encodeV2Swap=function(e,o,r,u){var i=a.toHex(e.maximumAmountIn(o.slippageTolerance).quotient),p=a.toHex(e.minimumAmountOut(o.slippageTolerance).quotient),s=e.route.path.map((function(t){return t.address})),c=r?A:void 0===o.recipient?h:n.validateAndParseAddress(o.recipient);return e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[i,u?0:p,s,c]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[p,i,s,c])},t.encodeV3Swap=function(e,o,r,u){for(var i,p=[],s=N(e.swaps);!(i=s()).done;){var c=i.value,d=c.route,m=c.outputAmount,l=a.toHex(e.maximumAmountIn(o.slippageTolerance,c.inputAmount).quotient),f=a.toHex(e.minimumAmountOut(o.slippageTolerance,m).quotient),v=1===d.pools.length,y=r?A:void 0===o.recipient?h:n.validateAndParseAddress(o.recipient);if(v)p.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:l,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:l,sqrtPriceLimitX96:0}]));else{var T=a.encodeRouteToPath(d,e.tradeType===n.TradeType.EXACT_OUTPUT);p.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:T,recipient:y,amountIn:l,amountOutMinimum:u?0:f}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:T,recipient:y,amountOut:f,amountInMaximum:l}]))}}return p},t.encodeMixedRouteSwap=function(e,o,r,i){var p=[];e.tradeType!==n.TradeType.EXACT_INPUT&&u(!1);for(var s,c=function(){var u=s.value,c=u.route,d=u.inputAmount,l=u.outputAmount;if(c.pools.some((function(t){return t instanceof m.Pool})))throw new Error("Encoding mixed routes with V4 not supported");var f=a.toHex(e.maximumAmountIn(o.slippageTolerance,d).quotient),v=a.toHex(e.minimumAmountOut(o.slippageTolerance,l).quotient),y=1===c.pools.length,T=r?A:void 0===o.recipient?h:n.validateAndParseAddress(o.recipient),w=function(t){return t.pools.every((function(t){return t instanceof a.Pool}))};if(y)if(w(c))p.push(t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:c.path[0].wrapped.address,tokenOut:c.path[1].wrapped.address,fee:c.pools[0].fee,recipient:T,amountIn:f,amountOutMinimum:i?0:v,sqrtPriceLimitX96:0}]));else{var k=c.path.map((function(t){return t.wrapped.address}));p.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[f,i?0:v,k,T]))}else for(var E,I=z(c),P=function(t){return t===I.length-1},x=c.input.wrapped,R=0;R<I.length;R++){var g=I[R];E=$(g,x);var _=new U([].concat(g),g[0].token0.equals(x)?g[0].token0:g[0].token1,E),b=new Q(_);if(x=E.wrapped,w(b)){var O={path:J(b),recipient:P(R)?T:A,amountIn:0===R?f:0,amountOutMinimum:P(R)?v:0};p.push(t.INTERFACE.encodeFunctionData("exactInput",[O]))}else{var N=[0===R?f:0,P(R)?v:0,b.path.map((function(t){return t.wrapped.address})),P(R)?T:A];p.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",N))}}},d=N(e.swaps);!(s=d()).done;)c();return p},t.encodeSwaps=function(e,o,r){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,p=[],s=N(e.swaps);!(i=s()).done;){var c=i.value,m=c.route,l=c.inputAmount,f=c.outputAmount;if(m.protocol===exports.Protocol.V2)p.push(new d.Trade(m,e.tradeType===n.TradeType.EXACT_INPUT?l:f,e.tradeType));else if(m.protocol===exports.Protocol.V3)p.push(a.Trade.createUncheckedTrade({route:m,inputAmount:l,outputAmount:f,tradeType:e.tradeType}));else{if(m.protocol!==exports.Protocol.MIXED)throw new Error("UNSUPPORTED_TRADE_PROTOCOL");p.push(V.createUncheckedTrade({route:m,inputAmount:l,outputAmount:f,tradeType:e.tradeType}))}}e=p}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof a.Trade||e instanceof V?e.swaps.length:1)}),0),A=e[0];e.every((function(t){return t.inputAmount.currency.equals(A.inputAmount.currency)}))||u(!1),e.every((function(t){return t.outputAmount.currency.equals(A.outputAmount.currency)}))||u(!1),e.every((function(t){return t.tradeType===A.tradeType}))||u(!1);var v=[],y=A.inputAmount.currency.isNative,T=A.outputAmount.currency.isNative,w=A.tradeType===n.TradeType.EXACT_INPUT&&h>2,k=T||!!o.fee||!!r||w;o.inputTokenPermit&&(A.inputAmount.currency.isToken||u(!1),v.push(a.SelfPermit.encodePermit(A.inputAmount.currency,o.inputTokenPermit)));for(var E,I=N(e);!(E=I()).done;){var P=E.value;if(P instanceof d.Trade)v.push(t.encodeV2Swap(P,o,k,w));else if(P instanceof a.Trade)for(var x,R=N(t.encodeV3Swap(P,o,k,w));!(x=R()).done;)v.push(x.value);else{if(!(P instanceof V))throw new Error("Unsupported trade object");for(var g,_=N(t.encodeMixedRouteSwap(P,o,k,w));!(g=_()).done;)v.push(g.value)}}var b=n.CurrencyAmount.fromRawAmount(A.inputAmount.currency,0),O=n.CurrencyAmount.fromRawAmount(A.outputAmount.currency,0),q=e.reduce((function(t,e){return t.add(e.minimumAmountOut(o.slippageTolerance))}),O),F=e.reduce((function(t,e){return t.add(e.outputAmount)}),O),C=e.reduce((function(t,e){return t.add(e.maximumAmountIn(o.slippageTolerance))}),b);return{calldatas:v,sampleTrade:A,routerMustCustody:k,inputIsNative:y,outputIsNative:T,totalAmountIn:C,minimumAmountOut:q,quoteAmountOut:F}},t.swapCallParameters=function(e,o){var r=t.encodeSwaps(e,o),u=r.calldatas,i=r.sampleTrade,p=r.inputIsNative,s=r.totalAmountIn,c=r.minimumAmountOut;return r.routerMustCustody&&u.push(r.outputIsNative?x.encodeUnwrapWETH9(c.quotient,o.recipient,o.fee):x.encodeSweepToken(i.outputAmount.currency.wrapped,c.quotient,o.recipient,o.fee)),p&&(i.tradeType===n.TradeType.EXACT_OUTPUT||t.riskOfPartialFill(e))&&u.push(a.Payments.encodeRefundETH()),{calldata:I.encodeMulticall(u,o.deadlineOrPreviousBlockhash),value:a.toHex(p?s.quotient:K)}},t.swapAndAddCallParameters=function(e,o,r,i,p,s){var c=t.encodeSwaps(e,o,!0),d=c.calldatas,m=c.inputIsNative,l=c.outputIsNative,f=c.sampleTrade,h=c.totalAmountIn,A=c.quoteAmountOut,v=c.minimumAmountOut;o.outputTokenPermit&&(A.currency.isToken||u(!1),d.push(a.SelfPermit.encodePermit(A.currency,o.outputTokenPermit)));var y=f.route.chainId,T=r.pool.token0.wrapped.address===h.currency.wrapped.address,w=t.getPositionAmounts(r,T),k=w.positionAmountIn,P=w.positionAmountOut,R=m?n.WETH9[y]:k.currency.wrapped,g=l?n.WETH9[y]:P.currency.wrapped,_=P.subtract(A.wrapped);_.greaterThan(n.CurrencyAmount.fromRawAmount(P.currency,0))&&d.push(l?x.encodeWrapETH(_.quotient):x.encodePull(g,_.quotient)),d.push(m?x.encodeWrapETH(k.quotient):x.encodePull(R,k.quotient)),p!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(E.encodeApprove(R,p)),s!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(E.encodeApprove(g,s));var b,O=a.Position.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:T?r.amount0.quotient.toString():v.quotient.toString(),amount1:T?v.quotient.toString():r.amount1.quotient.toString(),useFullPrecision:!1});return d.push(E.encodeAddLiquidity(r,O,i,o.slippageTolerance)),d.push(m?x.encodeUnwrapWETH9(K):x.encodeSweepToken(R,K)),d.push(l?x.encodeUnwrapWETH9(K):x.encodeSweepToken(g,K)),b=m?h.wrapped.add(k.wrapped).quotient:l?_.quotient:K,{calldata:I.encodeMulticall(d,o.deadlineOrPreviousBlockhash),value:b.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(Y)},t.getPositionAmounts=function(t,e){var o=t.mintAmounts,r=o.amount1,u=n.CurrencyAmount.fromRawAmount(t.pool.token0,o.amount0),i=n.CurrencyAmount.fromRawAmount(t.pool.token1,r),a=e?[u,i]:[i,u];return{positionAmountIn:a[0],positionAmountOut:a[1]}},t}();tt.INTERFACE=new r.Interface(c.abi),exports.ADDRESS_THIS=A,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=Q,exports.MixedRouteSDK=U,exports.MixedRouteTrade=V,exports.MulticallExtended=I,exports.ONE=y,exports.ONE_HUNDRED_PERCENT=w,exports.PaymentsExtended=x,exports.RouteV2=L,exports.RouteV3=Z,exports.RouteV4=B,exports.SwapRouter=tt,exports.Trade=G,exports.ZERO=v,exports.ZERO_PERCENT=T,exports.amountWithPathCurrency=H,exports.encodeMixedRouteToPath=J,exports.getOutputOfPools=$,exports.getPathCurrency=D,exports.getPathToken=W,exports.isMint=k,exports.partitionMixedRouteByProtocol=z,exports.tradeComparator=X;
|
|
2
2
|
//# sourceMappingURL=router-sdk.cjs.production.min.js.map
|