@uniswap/router-sdk 1.7.0 → 1.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +1 -0
- package/dist/router-sdk.cjs.development.js +14 -2
- 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 +14 -3
- package/dist/router-sdk.esm.js.map +1 -1
- package/package.json +1 -1
|
@@ -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"),c=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json"),s=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json"),p=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json"),d=require("@uniswap/v2-sdk"),l=require("@ethersproject/solidity"),m="0x0000000000000000000000000000000000000001",f="0x0000000000000000000000000000000000000002",h=r.BigInt(0),v=r.BigInt(1),A=new n.Percent(h);function y(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 T=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),c=i.amount0,s=i.amount1;return r.lessThan(n.amount0.quotient,c)&&(c=n.amount0.quotient),r.lessThan(n.amount1.quotient,s)&&(s=n.amount1.quotient),y(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(c),amount1Min:a.toHex(s),recipient:o.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:a.toHex(c),amount1Min:a.toHex(s),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"Error: invalid ApprovalType"}},t}();T.INTERFACE=new o.Interface(i.abi);var w=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 x(t){return a.toHex(t.multiply(1e4).quotient)}w.INTERFACE=new o.Interface(c.abi);var E=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=x(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=x(u.fee),c=n.validateAndParseAddress(u.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,a.toHex(r),i,c])}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 k(t,e,n,r,o,u,i){try{var a=t[u](i),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(r,o)}function g(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var u=t.apply(e,n);function i(t){k(u,r,o,i,a,"next",t)}function a(t){k(u,r,o,i,a,"throw",t)}i(void 0)}))}}function I(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.key,r)}}function P(t,e,n){return e&&I(t.prototype,e),n&&I(t,n),t}function R(){return(R=Object.assign||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 b(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,(Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function _(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 F(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 _(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)?_(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.")}E.INTERFACE=new o.Interface(s.abi);var N,O=(function(t){var e=function(t){var e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",u=r.asyncIterator||"@@asyncIterator",i=r.toStringTag||"@@toStringTag";function a(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var o=Object.create((e&&e.prototype instanceof d?e:d).prototype),u=new k(r||[]);return o._invoke=function(t,e,n){var r="suspendedStart";return function(o,u){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw u;return{value:void 0,done:!0}}for(n.method=o,n.arg=u;;){var i=n.delegate;if(i){var a=w(i,n);if(a){if(a===p)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=s(t,e,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(t,n,u),o}function s(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var p={};function d(){}function l(){}function m(){}var f={};a(f,o,(function(){return this}));var h=Object.getPrototypeOf,v=h&&h(h(g([])));v&&v!==e&&n.call(v,o)&&(f=v);var A=m.prototype=d.prototype=Object.create(f);function y(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function T(t,e){var r;this._invoke=function(o,u){function i(){return new e((function(r,i){!function r(o,u,i,a){var c=s(t[o],t,u);if("throw"!==c.type){var p=c.arg,d=p.value;return d&&"object"==typeof d&&n.call(d,"__await")?e.resolve(d.__await).then((function(t){r("next",t,i,a)}),(function(t){r("throw",t,i,a)})):e.resolve(d).then((function(t){p.value=t,i(p)}),(function(t){return r("throw",t,i,a)}))}a(c.arg)}(o,u,r,i)}))}return r=r?r.then(i,i):i()}}function w(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var r=s(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,p;var o=r.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function x(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 E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function k(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function g(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,u=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return u.next=u}}return{next:I}}function I(){return{value:void 0,done:!0}}return l.prototype=m,a(A,"constructor",m),a(m,"constructor",l),l.displayName=a(m,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,a(t,i,"GeneratorFunction")),t.prototype=Object.create(A),t},t.awrap=function(t){return{__await:t}},y(T.prototype),a(T.prototype,u,(function(){return this})),t.AsyncIterator=T,t.async=function(e,n,r,o,u){void 0===u&&(u=Promise);var i=new T(c(e,n,r,o),u);return t.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},y(A),a(A,i,"Generator"),a(A,o,(function(){return this})),a(A,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=g,k.prototype={constructor:k,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(n,r){return i.type="throw",i.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],i=u.completion;if("root"===u.tryLoc)return r("end");if(u.tryLoc<=this.prev){var a=n.call(u,"catchLoc"),c=n.call(u,"finallyLoc");if(a&&c){if(this.prev<u.catchLoc)return r(u.catchLoc,!0);if(this.prev<u.finallyLoc)return r(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return r(u.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return r(u.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.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,p):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),p},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),E(n),p}},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;E(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:g(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(N={exports:{}}),N.exports),q=function(){function t(t,e,n){this._midPrice=null,t.length>0||u(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||u(!1);var o=e.wrapped;t[0].involvesToken(o)||u(!1),t[t.length-1].involvesToken(n.wrapped)||u(!1);for(var i,a=[o],c=F(t.entries());!(i=c()).done;){var s=i.value,p=s[1],d=a[s[0]];d.equals(p.token0)||d.equals(p.token1)||u(!1);var l=d.equals(p.token0)?p.token1:p.token0;a.push(l)}this.pools=t,this.path=a,this.input=e,this.output=null!=n?n:a[a.length-1]}return P(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)}:{nextInput:e.token0,price:n.multiply(e.token1Price)}}),this.pools[0].token0.equals(this.input.wrapped)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function C(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 M,S=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 c,s=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),p=new Set,l=F(e);!(c=l()).done;)for(var m,f=F(c.value.route.pools);!(m=f()).done;){var h=m.value;p.add(h instanceof a.Pool?a.Pool.getAddress(h.token0,h.token1,h.fee):d.Pair.getAddress(h.token0,h.token1))}s!=p.size&&u(!1),r!==n.TradeType.EXACT_INPUT&&u(!1),this.swaps=e,this.tradeType=r}t.fromRoute=function(){var e=g(O.mark((function e(r,o,i){var a,c,s,p,d;return O.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]=o.wrapped,p=0;case 5:if(!(p<r.path.length-1)){e.next=15;break}return d=r.pools[p],e.next=9,d.getOutputAmount(a[p]);case 9:a[p+1]=e.sent[0];case 12:p++,e.next=5;break;case 15:return c=n.CurrencyAmount.fromFractionalAmount(r.input,o.numerator,o.denominator),s=n.CurrencyAmount.fromFractionalAmount(r.output,a[a.length-1].numerator,a[a.length-1].denominator),e.abrupt("return",new t({routes:[{inputAmount:c,outputAmount:s,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=g(O.mark((function e(r,o){var i,a,c,s,p,d,l,m,f,h,v;return O.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=[],o!==n.TradeType.EXACT_INPUT&&u(!1),a=F(r);case 3:if((c=a()).done){e.next=26;break}p=(s=c.value).route,d=s.amount,l=new Array(p.path.length),m=void 0,f=void 0,d.currency.equals(p.input)||u(!1),m=n.CurrencyAmount.fromFractionalAmount(p.input,d.numerator,d.denominator),l[0]=n.CurrencyAmount.fromFractionalAmount(p.input.wrapped,d.numerator,d.denominator),h=0;case 12:if(!(h<p.path.length-1)){e.next=22;break}return v=p.pools[h],e.next=16,v.getOutputAmount(l[h]);case 16:l[h+1]=e.sent[0];case 19:h++,e.next=12;break;case 22:f=n.CurrencyAmount.fromFractionalAmount(p.output,l[l.length-1].numerator,l[l.length-1].denominator),i.push({route:p,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(R({},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(h)&&u(!1);var r=new n.Fraction(v).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(h)&&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=g(O.mark((function e(r,o,i,a,c,s,p){var l,m,f,v,A,y,T,w,x,E,k;return O.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(m=(l=void 0===a?{}:a).maxNumResults)?3:m,A=void 0===(v=l.maxHops)?3:v,void 0===c&&(c=[]),void 0===s&&(s=o),void 0===p&&(p=[]),r.length>0||u(!1),A>0||u(!1),o===s||c.length>0||u(!1),y=s.wrapped,T=i.wrapped,w=0;case 10:if(!(w<r.length)){e.next=49;break}if((x=r[w]).token0.equals(y.currency)||x.token1.equals(y.currency)){e.next=14;break}return e.abrupt("continue",46);case 14:if(!(x instanceof d.Pair)){e.next=17;break}if(!x.reserve0.equalTo(h)&&!x.reserve1.equalTo(h)){e.next=17;break}return e.abrupt("continue",46);case 17:return E=void 0,e.prev=18,e.next=22,x.getOutputAmount(y);case 22:E=e.sent[0],e.next=31;break;case 26:if(e.prev=26,e.t0=e.catch(18),!e.t0.isInsufficientInputAmountError){e.next=30;break}return e.abrupt("continue",46);case 30:throw e.t0;case 31:if(!E.currency.isToken||!E.currency.equals(T)){e.next=42;break}return e.t1=n.sortedInsert,e.t2=p,e.next=36,t.fromRoute(new q([].concat(c,[x]),o.currency,i),o,n.TradeType.EXACT_INPUT);case 36:e.t3=e.sent,e.t4=f,e.t5=C,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=46;break;case 42:if(!(A>1&&r.length>1)){e.next=46;break}return k=r.slice(0,w).concat(r.slice(w+1,r.length)),e.next=46,t.bestTradeExactIn(k,o,i,{maxNumResults:f,maxHops:A-1},[].concat(c,[x]),E,p);case 46:w++,e.next=10;break;case 49:return e.abrupt("return",p);case 50:case"end":return e.stop()}}),e,null,[[18,26]])})));return function(t,n,r,o,u,i,a){return e.apply(this,arguments)}}(),P(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=F(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}();(M=exports.Protocol||(exports.Protocol={})).V2="V2",M.V3="V3",M.MIXED="MIXED";var H=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}return b(e,t),e}(d.Route),U=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}return b(e,t),e}(a.Route),D=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 b(e,t),e}(q),L=function(){function t(t){var e=t.v2Routes,n=t.v3Routes,r=t.tradeType,o=t.mixedRoutes;this.swaps=[],this.routes=[];for(var i,c=F(e);!(i=c()).done;){var s=i.value,p=s.inputAmount,l=s.outputAmount,m=new H(s.routev2);this.routes.push(m),this.swaps.push({route:m,inputAmount:p,outputAmount:l})}for(var f,h=F(n);!(f=h()).done;){var v=f.value,A=v.inputAmount,y=v.outputAmount,T=new U(v.routev3);this.routes.push(T),this.swaps.push({route:T,inputAmount:A,outputAmount:y})}if(o)for(var w,x=F(o);!(w=x()).done;){var E=w.value,k=E.inputAmount,g=E.outputAmount,I=new D(E.mixedRoute);this.routes.push(I),this.swaps.push({route:I,inputAmount:k,outputAmount:g})}this.tradeType=r;var P=this.swaps[0].inputAmount.currency,R=this.swaps[0].outputAmount.currency;this.swaps.every((function(t){return P.wrapped.equals(t.route.input.wrapped)}))||u(!1),this.swaps.every((function(t){return R.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var b,_=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),N=new Set,O=F(this.swaps);!(b=O()).done;)for(var q,C=F(b.value.route.pools);!(q=C()).done;){var M=q.value;if(M instanceof a.Pool)N.add(a.Pool.getAddress(M.token0,M.token1,M.fee));else{if(!(M instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");N.add(d.Pair.getAddress(M.token0,M.token1))}}_!=N.size&&u(!1)}var e=t.prototype;return e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(h)&&u(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var r=new n.Fraction(v).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(h)&&u(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var r=new n.Fraction(v).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=g(O.mark((function e(n,r,o,u){var i,c,s,p,l,m,f,h,v,A,y,T,w,x,E,k,g,I,P,R;return O.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=[],c=[],s=[],p=F(n);!(l=p()).done;)h=new d.Trade(f=(m=l.value).routev2,m.amount,o),i.push({routev2:f,inputAmount:h.inputAmount,outputAmount:h.outputAmount});v=F(r);case 5:if((A=v()).done){e.next=14;break}return T=(y=A.value).routev3,w=y.amount,e.next=9,a.Trade.fromRoute(T,w,o);case 9:c.push({routev3:T,inputAmount:(x=e.sent).inputAmount,outputAmount:x.outputAmount});case 12:e.next=5;break;case 14:if(!u){e.next=25;break}E=F(u);case 16:if((k=E()).done){e.next=25;break}return I=(g=k.value).mixedRoute,P=g.amount,e.next=20,S.fromRoute(I,P,o);case 20:s.push({mixedRoute:I,inputAmount:(R=e.sent).inputAmount,outputAmount:R.outputAmount});case 23:e.next=16;break;case 25:return e.abrupt("return",new t({v2Routes:i,v3Routes:c,mixedRoutes:s,tradeType:o}));case 26:case"end":return e.stop()}}),e)})));return function(t,n,r,o){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=g(O.mark((function e(n,r,o){var u,i,c,s,p,l;return O.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u=[],i=[],c=[],!(n instanceof d.Route)){e.next=9;break}s=new d.Trade(n,r,o),u=[{routev2:n,inputAmount:s.inputAmount,outputAmount:s.outputAmount}],e.next=26;break;case 9:if(!(n instanceof a.Route)){e.next=17;break}return e.next=12,a.Trade.fromRoute(n,r,o);case 12:i=[{routev3:n,inputAmount:(p=e.sent).inputAmount,outputAmount:p.outputAmount}],e.next=26;break;case 17:if(!(n instanceof q)){e.next=25;break}return e.next=20,S.fromRoute(n,r,o);case 20:c=[{mixedRoute:n,inputAmount:(l=e.sent).inputAmount,outputAmount:l.outputAmount}],e.next=26;break;case 25:throw new Error("Invalid route type");case 26:return e.abrupt("return",new t({v2Routes:u,v3Routes:i,mixedRoutes:c,tradeType:o}));case 27:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),P(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:"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?A:new n.Percent(t.wrapped.sellFeeBps.toNumber(),1e4)}},{key:"outputTax",get:function(){var t=this.outputAmount.currency;return t.isNative||!t.wrapped.buyFeeBps?A:new n.Percent(t.wrapped.buyFeeBps.toNumber(),1e4)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=F(this.swaps);!(t=r()).done;){var o=t.value,u=o.route.midPrice,i=o.inputAmount.multiply(new n.Fraction(v).subtract(this.inputTax));e=e.add(u.quote(i))}var a=this.outputAmount.divide(new n.Fraction(v).subtract(this.outputTax)),c=e.subtract(a).divide(e);return this._priceImpact=new n.Percent(c.numerator,c.denominator),this._priceImpact}}]),t}();function X(t){var e=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.address,e instanceof a.Pool?e.fee:8388608,i.address]}:{inputToken:i,types:[].concat(u,["uint24","address"]),path:[].concat(o,[e instanceof a.Pool?e.fee:8388608,i.address])}}),{inputToken:t.input.wrapped,path:[],types:[]});return l.pack(e.types,e.path)}var j=function(t){for(var e=[],n=0,r=0;r<t.pools.length;)(t.pools[n]instanceof a.Pool&&t.pools[r]instanceof d.Pair||t.pools[n]instanceof d.Pair&&t.pools[r]instanceof a.Pool)&&(e.push(t.pools.slice(n,r)),n=r),++r===t.pools.length&&e.push(t.pools.slice(n,r));return e},W=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},V=r.BigInt(0),Z=new n.Percent(r.BigInt(50),r.BigInt(100)),B=function(){function t(){}return t.encodeV2Swap=function(e,r,o,u){var i=a.toHex(e.maximumAmountIn(r.slippageTolerance).quotient),c=a.toHex(e.minimumAmountOut(r.slippageTolerance).quotient),s=e.route.path.map((function(t){return t.address})),p=o?f:void 0===r.recipient?m:n.validateAndParseAddress(r.recipient);return e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[i,u?0:c,s,p]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[c,i,s,p])},t.encodeV3Swap=function(e,r,o,u){for(var i,c=[],s=F(e.swaps);!(i=s()).done;){var p=i.value,d=p.route,l=p.outputAmount,h=a.toHex(e.maximumAmountIn(r.slippageTolerance,p.inputAmount).quotient),v=a.toHex(e.minimumAmountOut(r.slippageTolerance,l).quotient),A=1===d.pools.length,y=o?f:void 0===r.recipient?m:n.validateAndParseAddress(r.recipient);if(A)c.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:h,amountOutMinimum:u?0:v,sqrtPriceLimitX96:0}]):t.INTERFACE.encodeFunctionData("exactOutputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:y,amountOut:v,amountInMaximum:h,sqrtPriceLimitX96:0}]));else{var T=a.encodeRouteToPath(d,e.tradeType===n.TradeType.EXACT_OUTPUT);c.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:T,recipient:y,amountIn:h,amountOutMinimum:u?0:v}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:T,recipient:y,amountOut:v,amountInMaximum:h}]))}}return c},t.encodeMixedRouteSwap=function(e,r,o,i){var c=[];e.tradeType!==n.TradeType.EXACT_INPUT&&u(!1);for(var s,p=F(e.swaps);!(s=p()).done;){var d=s.value,l=d.route,h=d.outputAmount,v=a.toHex(e.maximumAmountIn(r.slippageTolerance,d.inputAmount).quotient),A=a.toHex(e.minimumAmountOut(r.slippageTolerance,h).quotient),y=1===l.pools.length,T=o?f:void 0===r.recipient?m:n.validateAndParseAddress(r.recipient),w=function(t){return t.pools.every((function(t){return t instanceof a.Pool}))};if(y)if(w(l))c.push(t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:l.path[0].address,tokenOut:l.path[1].address,fee:l.pools[0].fee,recipient:T,amountIn:v,amountOutMinimum:i?0:A,sqrtPriceLimitX96:0}]));else{var x=l.path.map((function(t){return t.address}));c.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[v,i?0:A,x,T]))}else!function(){for(var e=j(l),n=function(t){return t===e.length-1},r=void 0,o=l.input.wrapped,u=0;u<e.length;u++){var i=e[u];r=W(i,o);var a=new q([].concat(i),i[0].token0.equals(o)?i[0].token0:i[0].token1,r),s=new D(a);if(o=r,w(s)){var p={path:X(s),recipient:n(u)?T:f,amountIn:0==u?v:0,amountOutMinimum:n(u)?A:0};c.push(t.INTERFACE.encodeFunctionData("exactInput",[p]))}else{var d=[0==u?v:0,n(u)?A:0,s.path.map((function(t){return t.address})),n(u)?T:f];c.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",d))}}}()}return c},t.encodeSwaps=function(e,r,o){if(e instanceof L){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,c=[],s=F(e.swaps);!(i=s()).done;){var p=i.value,l=p.route,m=p.inputAmount,f=p.outputAmount;if(l.protocol==exports.Protocol.V2)c.push(new d.Trade(l,e.tradeType==n.TradeType.EXACT_INPUT?m:f,e.tradeType));else if(l.protocol==exports.Protocol.V3)c.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");c.push(S.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}))}}e=c}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof a.Trade||e instanceof S?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,T=v.outputAmount.currency.isNative,w=v.tradeType===n.TradeType.EXACT_INPUT&&h>2,x=T||!!r.fee||!!o||w;r.inputTokenPermit&&(v.inputAmount.currency.isToken||u(!1),A.push(a.SelfPermit.encodePermit(v.inputAmount.currency,r.inputTokenPermit)));for(var E,k=F(e);!(E=k()).done;){var g=E.value;if(g instanceof d.Trade)A.push(t.encodeV2Swap(g,r,x,w));else if(g instanceof a.Trade)for(var I,P=F(t.encodeV3Swap(g,r,x,w));!(I=P()).done;)A.push(I.value);else{if(!(g instanceof S))throw new Error("Unsupported trade object");for(var R,b=F(t.encodeMixedRouteSwap(g,r,x,w));!(R=b()).done;)A.push(R.value)}}var _=n.CurrencyAmount.fromRawAmount(v.inputAmount.currency,0),N=n.CurrencyAmount.fromRawAmount(v.outputAmount.currency,0),O=e.reduce((function(t,e){return t.add(e.minimumAmountOut(r.slippageTolerance))}),N),q=e.reduce((function(t,e){return t.add(e.outputAmount)}),N),C=e.reduce((function(t,e){return t.add(e.maximumAmountIn(r.slippageTolerance))}),_);return{calldatas:A,sampleTrade:v,routerMustCustody:x,inputIsNative:y,outputIsNative:T,totalAmountIn:C,minimumAmountOut:O,quoteAmountOut:q}},t.swapCallParameters=function(e,r){var o=t.encodeSwaps(e,r),u=o.calldatas,i=o.sampleTrade,c=o.inputIsNative,s=o.totalAmountIn,p=o.minimumAmountOut;return o.routerMustCustody&&u.push(o.outputIsNative?E.encodeUnwrapWETH9(p.quotient,r.recipient,r.fee):E.encodeSweepToken(i.outputAmount.currency.wrapped,p.quotient,r.recipient,r.fee)),c&&(i.tradeType===n.TradeType.EXACT_OUTPUT||t.riskOfPartialFill(e))&&u.push(a.Payments.encodeRefundETH()),{calldata:w.encodeMulticall(u,r.deadlineOrPreviousBlockhash),value:a.toHex(c?s.quotient:V)}},t.swapAndAddCallParameters=function(e,r,o,i,c,s){var p=t.encodeSwaps(e,r,!0),d=p.calldatas,l=p.inputIsNative,m=p.outputIsNative,f=p.sampleTrade,h=p.totalAmountIn,v=p.quoteAmountOut,A=p.minimumAmountOut;r.outputTokenPermit&&(v.currency.isToken||u(!1),d.push(a.SelfPermit.encodePermit(v.currency,r.outputTokenPermit)));var y=f.route.chainId,x=o.pool.token0.wrapped.address===h.currency.wrapped.address,k=t.getPositionAmounts(o,x),g=k.positionAmountIn,I=k.positionAmountOut,P=l?n.WETH9[y]:g.currency.wrapped,R=m?n.WETH9[y]:I.currency.wrapped,b=I.subtract(v.wrapped);b.greaterThan(n.CurrencyAmount.fromRawAmount(I.currency,0))&&d.push(m?E.encodeWrapETH(b.quotient):E.encodePull(R,b.quotient)),d.push(l?E.encodeWrapETH(g.quotient):E.encodePull(P,g.quotient)),c!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(T.encodeApprove(P,c)),s!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(T.encodeApprove(R,s));var _,F=a.Position.fromAmounts({pool:o.pool,tickLower:o.tickLower,tickUpper:o.tickUpper,amount0:x?o.amount0.quotient.toString():A.quotient.toString(),amount1:x?A.quotient.toString():o.amount1.quotient.toString(),useFullPrecision:!1});return d.push(T.encodeAddLiquidity(o,F,i,r.slippageTolerance)),d.push(l?E.encodeUnwrapWETH9(V):E.encodeSweepToken(P,V)),d.push(m?E.encodeUnwrapWETH9(V):E.encodeSweepToken(R,V)),_=l?h.wrapped.add(g.wrapped).quotient:m?b.quotient:V,{calldata:w.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(Z)},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}();B.INTERFACE=new o.Interface(p.abi),exports.ADDRESS_THIS=f,exports.ApproveAndCall=T,exports.MSG_SENDER=m,exports.MixedRoute=D,exports.MixedRouteSDK=q,exports.MixedRouteTrade=S,exports.MulticallExtended=w,exports.ONE=v,exports.PaymentsExtended=E,exports.RouteV2=H,exports.RouteV3=U,exports.SwapRouter=B,exports.Trade=L,exports.V2_FEE_PATH_PLACEHOLDER=8388608,exports.ZERO=h,exports.ZERO_PERCENT=A,exports.encodeMixedRouteToPath=X,exports.getOutputOfPools=W,exports.isMint=y,exports.partitionMixedRouteByProtocol=j,exports.tradeComparator=C;
|
|
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"),c=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json"),s=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json"),p=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json"),d=require("@uniswap/v2-sdk"),l=require("@ethersproject/solidity"),m="0x0000000000000000000000000000000000000001",f="0x0000000000000000000000000000000000000002",h=r.BigInt(0),v=r.BigInt(1),A=new n.Percent(h),y=new n.Percent(100,100);function T(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 w=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),c=i.amount0,s=i.amount1;return r.lessThan(n.amount0.quotient,c)&&(c=n.amount0.quotient),r.lessThan(n.amount1.quotient,s)&&(s=n.amount1.quotient),T(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(c),amount1Min:a.toHex(s),recipient:o.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:a.toHex(c),amount1Min:a.toHex(s),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"Error: invalid ApprovalType"}},t}();w.INTERFACE=new o.Interface(i.abi);var x=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 E(t){return a.toHex(t.multiply(1e4).quotient)}x.INTERFACE=new o.Interface(c.abi);var g=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=E(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=E(u.fee),c=n.validateAndParseAddress(u.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,a.toHex(r),i,c])}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 k(t,e,n,r,o,u,i){try{var a=t[u](i),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(r,o)}function I(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var u=t.apply(e,n);function i(t){k(u,r,o,i,a,"next",t)}function a(t){k(u,r,o,i,a,"throw",t)}i(void 0)}))}}function P(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.key,r)}}function R(t,e,n){return e&&P(t.prototype,e),n&&P(t,n),t}function b(){return(b=Object.assign||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 _(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,(Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function N(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 O(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 N(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)?N(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.")}g.INTERFACE=new o.Interface(s.abi);var F,q=(function(t){var e=function(t){var e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},o=r.iterator||"@@iterator",u=r.asyncIterator||"@@asyncIterator",i=r.toStringTag||"@@toStringTag";function a(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{a({},"")}catch(t){a=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var o=Object.create((e&&e.prototype instanceof d?e:d).prototype),u=new g(r||[]);return o._invoke=function(t,e,n){var r="suspendedStart";return function(o,u){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===o)throw u;return{value:void 0,done:!0}}for(n.method=o,n.arg=u;;){var i=n.delegate;if(i){var a=w(i,n);if(a){if(a===p)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=s(t,e,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(t,n,u),o}function s(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var p={};function d(){}function l(){}function m(){}var f={};a(f,o,(function(){return this}));var h=Object.getPrototypeOf,v=h&&h(h(k([])));v&&v!==e&&n.call(v,o)&&(f=v);var A=m.prototype=d.prototype=Object.create(f);function y(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function T(t,e){var r;this._invoke=function(o,u){function i(){return new e((function(r,i){!function r(o,u,i,a){var c=s(t[o],t,u);if("throw"!==c.type){var p=c.arg,d=p.value;return d&&"object"==typeof d&&n.call(d,"__await")?e.resolve(d.__await).then((function(t){r("next",t,i,a)}),(function(t){r("throw",t,i,a)})):e.resolve(d).then((function(t){p.value=t,i(p)}),(function(t){return r("throw",t,i,a)}))}a(c.arg)}(o,u,r,i)}))}return r=r?r.then(i,i):i()}}function w(t,e){var n=t.iterator[e.method];if(void 0===n){if(e.delegate=null,"throw"===e.method){if(t.iterator.return&&(e.method="return",e.arg=void 0,w(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var r=s(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,p;var o=r.arg;return o?o.done?(e[t.resultName]=o.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,p):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function x(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 E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function g(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function k(t){if(t){var e=t[o];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,u=function e(){for(;++r<t.length;)if(n.call(t,r))return e.value=t[r],e.done=!1,e;return e.value=void 0,e.done=!0,e};return u.next=u}}return{next:I}}function I(){return{value:void 0,done:!0}}return l.prototype=m,a(A,"constructor",m),a(m,"constructor",l),l.displayName=a(m,i,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===l||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,m):(t.__proto__=m,a(t,i,"GeneratorFunction")),t.prototype=Object.create(A),t},t.awrap=function(t){return{__await:t}},y(T.prototype),a(T.prototype,u,(function(){return this})),t.AsyncIterator=T,t.async=function(e,n,r,o,u){void 0===u&&(u=Promise);var i=new T(c(e,n,r,o),u);return t.isGeneratorFunction(n)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},y(A),a(A,i,"Generator"),a(A,o,(function(){return this})),a(A,"toString",(function(){return"[object Generator]"})),t.keys=function(t){var e=[];for(var n in t)e.push(n);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=k,g.prototype={constructor:g,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var e=this;function r(n,r){return i.type="throw",i.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],i=u.completion;if("root"===u.tryLoc)return r("end");if(u.tryLoc<=this.prev){var a=n.call(u,"catchLoc"),c=n.call(u,"finallyLoc");if(a&&c){if(this.prev<u.catchLoc)return r(u.catchLoc,!0);if(this.prev<u.finallyLoc)return r(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return r(u.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return r(u.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.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,p):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),p},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),E(n),p}},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;E(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:k(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(F={exports:{}}),F.exports),C=function(){function t(t,e,n){this._midPrice=null,t.length>0||u(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||u(!1);var o=e.wrapped;t[0].involvesToken(o)||u(!1),t[t.length-1].involvesToken(n.wrapped)||u(!1);for(var i,a=[o],c=O(t.entries());!(i=c()).done;){var s=i.value,p=s[1],d=a[s[0]];d.equals(p.token0)||d.equals(p.token1)||u(!1);var l=d.equals(p.token0)?p.token1:p.token0;a.push(l)}this.pools=t,this.path=a,this.input=e,this.output=null!=n?n:a[a.length-1]}return R(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)}:{nextInput:e.token0,price:n.multiply(e.token1Price)}}),this.pools[0].token0.equals(this.input.wrapped)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function M(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 S,H=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 c,s=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),p=new Set,l=O(e);!(c=l()).done;)for(var m,f=O(c.value.route.pools);!(m=f()).done;){var h=m.value;p.add(h instanceof a.Pool?a.Pool.getAddress(h.token0,h.token1,h.fee):d.Pair.getAddress(h.token0,h.token1))}s!=p.size&&u(!1),r!==n.TradeType.EXACT_INPUT&&u(!1),this.swaps=e,this.tradeType=r}t.fromRoute=function(){var e=I(q.mark((function e(r,o,i){var a,c,s,p,d;return q.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]=o.wrapped,p=0;case 5:if(!(p<r.path.length-1)){e.next=15;break}return d=r.pools[p],e.next=9,d.getOutputAmount(a[p]);case 9:a[p+1]=e.sent[0];case 12:p++,e.next=5;break;case 15:return c=n.CurrencyAmount.fromFractionalAmount(r.input,o.numerator,o.denominator),s=n.CurrencyAmount.fromFractionalAmount(r.output,a[a.length-1].numerator,a[a.length-1].denominator),e.abrupt("return",new t({routes:[{inputAmount:c,outputAmount:s,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(q.mark((function e(r,o){var i,a,c,s,p,d,l,m,f,h,v;return q.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=[],o!==n.TradeType.EXACT_INPUT&&u(!1),a=O(r);case 3:if((c=a()).done){e.next=26;break}p=(s=c.value).route,d=s.amount,l=new Array(p.path.length),m=void 0,f=void 0,d.currency.equals(p.input)||u(!1),m=n.CurrencyAmount.fromFractionalAmount(p.input,d.numerator,d.denominator),l[0]=n.CurrencyAmount.fromFractionalAmount(p.input.wrapped,d.numerator,d.denominator),h=0;case 12:if(!(h<p.path.length-1)){e.next=22;break}return v=p.pools[h],e.next=16,v.getOutputAmount(l[h]);case 16:l[h+1]=e.sent[0];case 19:h++,e.next=12;break;case 22:f=n.CurrencyAmount.fromFractionalAmount(p.output,l[l.length-1].numerator,l[l.length-1].denominator),i.push({route:p,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(b({},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(h)&&u(!1);var r=new n.Fraction(v).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(h)&&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(q.mark((function e(r,o,i,a,c,s,p){var l,m,f,v,A,y,T,w,x,E,g;return q.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(m=(l=void 0===a?{}:a).maxNumResults)?3:m,A=void 0===(v=l.maxHops)?3:v,void 0===c&&(c=[]),void 0===s&&(s=o),void 0===p&&(p=[]),r.length>0||u(!1),A>0||u(!1),o===s||c.length>0||u(!1),y=s.wrapped,T=i.wrapped,w=0;case 10:if(!(w<r.length)){e.next=49;break}if((x=r[w]).token0.equals(y.currency)||x.token1.equals(y.currency)){e.next=14;break}return e.abrupt("continue",46);case 14:if(!(x instanceof d.Pair)){e.next=17;break}if(!x.reserve0.equalTo(h)&&!x.reserve1.equalTo(h)){e.next=17;break}return e.abrupt("continue",46);case 17:return E=void 0,e.prev=18,e.next=22,x.getOutputAmount(y);case 22:E=e.sent[0],e.next=31;break;case 26:if(e.prev=26,e.t0=e.catch(18),!e.t0.isInsufficientInputAmountError){e.next=30;break}return e.abrupt("continue",46);case 30:throw e.t0;case 31:if(!E.currency.isToken||!E.currency.equals(T)){e.next=42;break}return e.t1=n.sortedInsert,e.t2=p,e.next=36,t.fromRoute(new C([].concat(c,[x]),o.currency,i),o,n.TradeType.EXACT_INPUT);case 36:e.t3=e.sent,e.t4=f,e.t5=M,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=46;break;case 42:if(!(A>1&&r.length>1)){e.next=46;break}return g=r.slice(0,w).concat(r.slice(w+1,r.length)),e.next=46,t.bestTradeExactIn(g,o,i,{maxNumResults:f,maxHops:A-1},[].concat(c,[x]),E,p);case 46:w++,e.next=10;break;case 49:return e.abrupt("return",p);case 50:case"end":return e.stop()}}),e,null,[[18,26]])})));return function(t,n,r,o,u,i,a){return e.apply(this,arguments)}}(),R(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=O(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}();(S=exports.Protocol||(exports.Protocol={})).V2="V2",S.V3="V3",S.MIXED="MIXED";var U=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}return _(e,t),e}(d.Route),D=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}return _(e,t),e}(a.Route),L=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 _(e,t),e}(C),X=function(){function t(t){var e=t.v2Routes,n=t.v3Routes,r=t.tradeType,o=t.mixedRoutes;this.swaps=[],this.routes=[];for(var i,c=O(e);!(i=c()).done;){var s=i.value,p=s.inputAmount,l=s.outputAmount,m=new U(s.routev2);this.routes.push(m),this.swaps.push({route:m,inputAmount:p,outputAmount:l})}for(var f,h=O(n);!(f=h()).done;){var v=f.value,A=v.inputAmount,y=v.outputAmount,T=new D(v.routev3);this.routes.push(T),this.swaps.push({route:T,inputAmount:A,outputAmount:y})}if(o)for(var w,x=O(o);!(w=x()).done;){var E=w.value,g=E.inputAmount,k=E.outputAmount,I=new L(E.mixedRoute);this.routes.push(I),this.swaps.push({route:I,inputAmount:g,outputAmount:k})}if(0===this.swaps.length)throw new Error("No routes provided when calling Trade constructor");this.tradeType=r;var P=this.swaps[0].inputAmount.currency,R=this.swaps[0].outputAmount.currency;this.swaps.every((function(t){return P.wrapped.equals(t.route.input.wrapped)}))||u(!1),this.swaps.every((function(t){return R.wrapped.equals(t.route.output.wrapped)}))||u(!1);for(var b,_=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),N=new Set,F=O(this.swaps);!(b=F()).done;)for(var q,C=O(b.value.route.pools);!(q=C()).done;){var M=q.value;if(M instanceof a.Pool)N.add(a.Pool.getAddress(M.token0,M.token1,M.fee));else{if(!(M instanceof d.Pair))throw new Error("Unexpected pool type in route when constructing trade object");N.add(d.Pair.getAddress(M.token0,M.token1))}}_!=N.size&&u(!1)}var e=t.prototype;return e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(h)&&u(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var r=new n.Fraction(v).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(h)&&u(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var r=new n.Fraction(v).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(q.mark((function e(n,r,o,u){var i,c,s,p,l,m,f,h,v,A,y,T,w,x,E,g,k,I,P,R;return q.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(i=[],c=[],s=[],p=O(n);!(l=p()).done;)h=new d.Trade(f=(m=l.value).routev2,m.amount,o),i.push({routev2:f,inputAmount:h.inputAmount,outputAmount:h.outputAmount});v=O(r);case 5:if((A=v()).done){e.next=14;break}return T=(y=A.value).routev3,w=y.amount,e.next=9,a.Trade.fromRoute(T,w,o);case 9:c.push({routev3:T,inputAmount:(x=e.sent).inputAmount,outputAmount:x.outputAmount});case 12:e.next=5;break;case 14:if(!u){e.next=25;break}E=O(u);case 16:if((g=E()).done){e.next=25;break}return I=(k=g.value).mixedRoute,P=k.amount,e.next=20,H.fromRoute(I,P,o);case 20:s.push({mixedRoute:I,inputAmount:(R=e.sent).inputAmount,outputAmount:R.outputAmount});case 23:e.next=16;break;case 25:return e.abrupt("return",new t({v2Routes:i,v3Routes:c,mixedRoutes:s,tradeType:o}));case 26:case"end":return e.stop()}}),e)})));return function(t,n,r,o){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=I(q.mark((function e(n,r,o){var u,i,c,s,p,l;return q.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u=[],i=[],c=[],!(n instanceof d.Route)){e.next=9;break}s=new d.Trade(n,r,o),u=[{routev2:n,inputAmount:s.inputAmount,outputAmount:s.outputAmount}],e.next=26;break;case 9:if(!(n instanceof a.Route)){e.next=17;break}return e.next=12,a.Trade.fromRoute(n,r,o);case 12:i=[{routev3:n,inputAmount:(p=e.sent).inputAmount,outputAmount:p.outputAmount}],e.next=26;break;case 17:if(!(n instanceof C)){e.next=25;break}return e.next=20,H.fromRoute(n,r,o);case 20:c=[{mixedRoute:n,inputAmount:(l=e.sent).inputAmount,outputAmount:l.outputAmount}],e.next=26;break;case 25:throw new Error("Invalid route type");case 26:return e.abrupt("return",new t({v2Routes:u,v3Routes:i,mixedRoutes:c,tradeType:o}));case 27:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),R(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:"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?A:new n.Percent(t.wrapped.sellFeeBps.toNumber(),1e4)}},{key:"outputTax",get:function(){var t=this.outputAmount.currency;return t.isNative||!t.wrapped.buyFeeBps?A:new n.Percent(t.wrapped.buyFeeBps.toNumber(),1e4)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;if(this.outputTax.equalTo(y))return A;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=O(this.swaps);!(t=r()).done;){var o=t.value,u=o.route.midPrice,i=o.inputAmount.multiply(new n.Fraction(v).subtract(this.inputTax));e=e.add(u.quote(i))}if(e.equalTo(h))return A;var a=this.outputAmount.divide(new n.Fraction(v).subtract(this.outputTax)),c=e.subtract(a).divide(e);return this._priceImpact=new n.Percent(c.numerator,c.denominator),this._priceImpact}}]),t}();function j(t){var e=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.address,e instanceof a.Pool?e.fee:8388608,i.address]}:{inputToken:i,types:[].concat(u,["uint24","address"]),path:[].concat(o,[e instanceof a.Pool?e.fee:8388608,i.address])}}),{inputToken:t.input.wrapped,path:[],types:[]});return l.pack(e.types,e.path)}var W=function(t){for(var e=[],n=0,r=0;r<t.pools.length;)(t.pools[n]instanceof a.Pool&&t.pools[r]instanceof d.Pair||t.pools[n]instanceof d.Pair&&t.pools[r]instanceof a.Pool)&&(e.push(t.pools.slice(n,r)),n=r),++r===t.pools.length&&e.push(t.pools.slice(n,r));return e},V=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},Z=r.BigInt(0),B=new n.Percent(r.BigInt(50),r.BigInt(100)),G=function(){function t(){}return t.encodeV2Swap=function(e,r,o,u){var i=a.toHex(e.maximumAmountIn(r.slippageTolerance).quotient),c=a.toHex(e.minimumAmountOut(r.slippageTolerance).quotient),s=e.route.path.map((function(t){return t.address})),p=o?f:void 0===r.recipient?m:n.validateAndParseAddress(r.recipient);return e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[i,u?0:c,s,p]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[c,i,s,p])},t.encodeV3Swap=function(e,r,o,u){for(var i,c=[],s=O(e.swaps);!(i=s()).done;){var p=i.value,d=p.route,l=p.outputAmount,h=a.toHex(e.maximumAmountIn(r.slippageTolerance,p.inputAmount).quotient),v=a.toHex(e.minimumAmountOut(r.slippageTolerance,l).quotient),A=1===d.pools.length,y=o?f:void 0===r.recipient?m:n.validateAndParseAddress(r.recipient);if(A)c.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:h,amountOutMinimum:u?0:v,sqrtPriceLimitX96:0}]):t.INTERFACE.encodeFunctionData("exactOutputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:y,amountOut:v,amountInMaximum:h,sqrtPriceLimitX96:0}]));else{var T=a.encodeRouteToPath(d,e.tradeType===n.TradeType.EXACT_OUTPUT);c.push(e.tradeType===n.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:T,recipient:y,amountIn:h,amountOutMinimum:u?0:v}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:T,recipient:y,amountOut:v,amountInMaximum:h}]))}}return c},t.encodeMixedRouteSwap=function(e,r,o,i){var c=[];e.tradeType!==n.TradeType.EXACT_INPUT&&u(!1);for(var s,p=O(e.swaps);!(s=p()).done;){var d=s.value,l=d.route,h=d.outputAmount,v=a.toHex(e.maximumAmountIn(r.slippageTolerance,d.inputAmount).quotient),A=a.toHex(e.minimumAmountOut(r.slippageTolerance,h).quotient),y=1===l.pools.length,T=o?f:void 0===r.recipient?m:n.validateAndParseAddress(r.recipient),w=function(t){return t.pools.every((function(t){return t instanceof a.Pool}))};if(y)if(w(l))c.push(t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:l.path[0].address,tokenOut:l.path[1].address,fee:l.pools[0].fee,recipient:T,amountIn:v,amountOutMinimum:i?0:A,sqrtPriceLimitX96:0}]));else{var x=l.path.map((function(t){return t.address}));c.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[v,i?0:A,x,T]))}else!function(){for(var e=W(l),n=function(t){return t===e.length-1},r=void 0,o=l.input.wrapped,u=0;u<e.length;u++){var i=e[u];r=V(i,o);var a=new C([].concat(i),i[0].token0.equals(o)?i[0].token0:i[0].token1,r),s=new L(a);if(o=r,w(s)){var p={path:j(s),recipient:n(u)?T:f,amountIn:0==u?v:0,amountOutMinimum:n(u)?A:0};c.push(t.INTERFACE.encodeFunctionData("exactInput",[p]))}else{var d=[0==u?v:0,n(u)?A:0,s.path.map((function(t){return t.address})),n(u)?T:f];c.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",d))}}}()}return c},t.encodeSwaps=function(e,r,o){if(e instanceof X){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,c=[],s=O(e.swaps);!(i=s()).done;){var p=i.value,l=p.route,m=p.inputAmount,f=p.outputAmount;if(l.protocol==exports.Protocol.V2)c.push(new d.Trade(l,e.tradeType==n.TradeType.EXACT_INPUT?m:f,e.tradeType));else if(l.protocol==exports.Protocol.V3)c.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");c.push(H.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}))}}e=c}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof a.Trade||e instanceof H?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,T=v.outputAmount.currency.isNative,w=v.tradeType===n.TradeType.EXACT_INPUT&&h>2,x=T||!!r.fee||!!o||w;r.inputTokenPermit&&(v.inputAmount.currency.isToken||u(!1),A.push(a.SelfPermit.encodePermit(v.inputAmount.currency,r.inputTokenPermit)));for(var E,g=O(e);!(E=g()).done;){var k=E.value;if(k instanceof d.Trade)A.push(t.encodeV2Swap(k,r,x,w));else if(k instanceof a.Trade)for(var I,P=O(t.encodeV3Swap(k,r,x,w));!(I=P()).done;)A.push(I.value);else{if(!(k instanceof H))throw new Error("Unsupported trade object");for(var R,b=O(t.encodeMixedRouteSwap(k,r,x,w));!(R=b()).done;)A.push(R.value)}}var _=n.CurrencyAmount.fromRawAmount(v.inputAmount.currency,0),N=n.CurrencyAmount.fromRawAmount(v.outputAmount.currency,0),F=e.reduce((function(t,e){return t.add(e.minimumAmountOut(r.slippageTolerance))}),N),q=e.reduce((function(t,e){return t.add(e.outputAmount)}),N),C=e.reduce((function(t,e){return t.add(e.maximumAmountIn(r.slippageTolerance))}),_);return{calldatas:A,sampleTrade:v,routerMustCustody:x,inputIsNative:y,outputIsNative:T,totalAmountIn:C,minimumAmountOut:F,quoteAmountOut:q}},t.swapCallParameters=function(e,r){var o=t.encodeSwaps(e,r),u=o.calldatas,i=o.sampleTrade,c=o.inputIsNative,s=o.totalAmountIn,p=o.minimumAmountOut;return o.routerMustCustody&&u.push(o.outputIsNative?g.encodeUnwrapWETH9(p.quotient,r.recipient,r.fee):g.encodeSweepToken(i.outputAmount.currency.wrapped,p.quotient,r.recipient,r.fee)),c&&(i.tradeType===n.TradeType.EXACT_OUTPUT||t.riskOfPartialFill(e))&&u.push(a.Payments.encodeRefundETH()),{calldata:x.encodeMulticall(u,r.deadlineOrPreviousBlockhash),value:a.toHex(c?s.quotient:Z)}},t.swapAndAddCallParameters=function(e,r,o,i,c,s){var p=t.encodeSwaps(e,r,!0),d=p.calldatas,l=p.inputIsNative,m=p.outputIsNative,f=p.sampleTrade,h=p.totalAmountIn,v=p.quoteAmountOut,A=p.minimumAmountOut;r.outputTokenPermit&&(v.currency.isToken||u(!1),d.push(a.SelfPermit.encodePermit(v.currency,r.outputTokenPermit)));var y=f.route.chainId,T=o.pool.token0.wrapped.address===h.currency.wrapped.address,E=t.getPositionAmounts(o,T),k=E.positionAmountIn,I=E.positionAmountOut,P=l?n.WETH9[y]:k.currency.wrapped,R=m?n.WETH9[y]:I.currency.wrapped,b=I.subtract(v.wrapped);b.greaterThan(n.CurrencyAmount.fromRawAmount(I.currency,0))&&d.push(m?g.encodeWrapETH(b.quotient):g.encodePull(R,b.quotient)),d.push(l?g.encodeWrapETH(k.quotient):g.encodePull(P,k.quotient)),c!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(w.encodeApprove(P,c)),s!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(w.encodeApprove(R,s));var _,N=a.Position.fromAmounts({pool:o.pool,tickLower:o.tickLower,tickUpper:o.tickUpper,amount0:T?o.amount0.quotient.toString():A.quotient.toString(),amount1:T?A.quotient.toString():o.amount1.quotient.toString(),useFullPrecision:!1});return d.push(w.encodeAddLiquidity(o,N,i,r.slippageTolerance)),d.push(l?g.encodeUnwrapWETH9(Z):g.encodeSweepToken(P,Z)),d.push(m?g.encodeUnwrapWETH9(Z):g.encodeSweepToken(R,Z)),_=l?h.wrapped.add(k.wrapped).quotient:m?b.quotient:Z,{calldata:x.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(B)},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}();G.INTERFACE=new o.Interface(p.abi),exports.ADDRESS_THIS=f,exports.ApproveAndCall=w,exports.MSG_SENDER=m,exports.MixedRoute=L,exports.MixedRouteSDK=C,exports.MixedRouteTrade=H,exports.MulticallExtended=x,exports.ONE=v,exports.ONE_HUNDRED_PERCENT=y,exports.PaymentsExtended=g,exports.RouteV2=U,exports.RouteV3=D,exports.SwapRouter=G,exports.Trade=X,exports.V2_FEE_PATH_PLACEHOLDER=8388608,exports.ZERO=h,exports.ZERO_PERCENT=A,exports.encodeMixedRouteToPath=j,exports.getOutputOfPools=V,exports.isMint=T,exports.partitionMixedRouteByProtocol=W,exports.tradeComparator=M;
|
|
2
2
|
//# sourceMappingURL=router-sdk.cjs.production.min.js.map
|