@uniswap/router-sdk 1.0.6 → 1.3.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/constants.d.ts +1 -0
- package/dist/entities/mixedRoute/route.d.ts +29 -0
- package/dist/entities/mixedRoute/trade.d.ts +183 -0
- package/dist/entities/protocol.d.ts +2 -1
- package/dist/entities/route.d.ts +5 -0
- package/dist/entities/trade.d.ts +12 -3
- package/dist/index.d.ts +3 -0
- package/dist/router-sdk.cjs.development.js +1139 -87
- 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 +1137 -91
- package/dist/router-sdk.esm.js.map +1 -1
- package/dist/swapRouter.d.ts +35 -4
- package/dist/utils/encodeMixedRouteToPath.d.ts +9 -0
- package/dist/utils/index.d.ts +17 -0
- 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=t(require("jsbi")),r=require("@ethersproject/abi"),o=t(require("tiny-invariant")),u=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json"),i=require("@uniswap/v3-sdk"),a=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json"),c=require("@uniswap/sdk-core"),p=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IPeripheryPaymentsWithFeeExtended.sol/IPeripheryPaymentsWithFeeExtended.json"),s=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/ISwapRouter02.sol/ISwapRouter02.json"),d=require("@uniswap/v2-sdk"),l="0x0000000000000000000000000000000000000001",m="0x0000000000000000000000000000000000000002",f=n.BigInt(0),h=n.BigInt(1);function v(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 y=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||o(!1),1==e.length)return t.INTERFACE.encodeFunctionData("callPositionManager",e);var n=i.NonfungiblePositionManager.INTERFACE.encodeFunctionData("multicall",[e]);return t.INTERFACE.encodeFunctionData("callPositionManager",[n])},t.encodeAddLiquidity=function(e,r,o,u){var a=e.mintAmountsWithSlippage(u),c=a.amount0,p=a.amount1;return n.lessThan(r.amount0.quotient,c)&&(c=r.amount0.quotient),n.lessThan(r.amount1.quotient,p)&&(p=r.amount1.quotient),v(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:i.toHex(c),amount1Min:i.toHex(p),recipient:o.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:i.toHex(c),amount1Min:i.toHex(p),tokenId:i.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}();y.INTERFACE=new r.Interface(u.abi);var A=function(){function t(){}return t.encodeMulticall=function(e,n){if(void 0===n)return i.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=i.toHex(n);return t.INTERFACE.encodeFunctionData("multicall(uint256,bytes[])",[o,e])},t}();function T(t){return i.toHex(t.multiply(1e4).quotient)}A.INTERFACE=new r.Interface(a.abi);var w=function(){function t(){}return t.encodeUnwrapWETH9=function(e,n,r){if("string"==typeof n)return i.Payments.encodeUnwrapWETH9(e,n,r);if(r){var o=T(r.fee),u=c.validateAndParseAddress(r.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee(uint256,uint256,address)",[i.toHex(e),o,u])}return t.INTERFACE.encodeFunctionData("unwrapWETH9(uint256)",[i.toHex(e)])},t.encodeSweepToken=function(e,n,r,o){if("string"==typeof r)return i.Payments.encodeSweepToken(e,n,r,o);if(o){var u=T(o.fee),a=c.validateAndParseAddress(o.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,i.toHex(n),u,a])}return t.INTERFACE.encodeFunctionData("sweepToken(address,uint256)",[e.address,i.toHex(n)])},t.encodePull=function(e,n){return t.INTERFACE.encodeFunctionData("pull",[e.address,i.toHex(n)])},t.encodeWrapETH=function(e){return t.INTERFACE.encodeFunctionData("wrapETH",[i.toHex(e)])},t}();function E(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 x(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var u=t.apply(e,n);function i(t){E(u,r,o,i,a,"next",t)}function a(t){E(u,r,o,i,a,"throw",t)}i(void 0)}))}}function g(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 I(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 P(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 I(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)?I(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.")}w.INTERFACE=new r.Interface(p.abi);var k,R,N=(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===s)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=p(t,e,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===s)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 p(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}t.wrap=c;var s={};function d(){}function l(){}function m(){}var f={};a(f,o,(function(){return this}));var h=Object.getPrototypeOf,v=h&&h(h(I([])));v&&v!==e&&n.call(v,o)&&(f=v);var y=m.prototype=d.prototype=Object.create(f);function A(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=p(t[o],t,u);if("throw"!==c.type){var s=c.arg,d=s.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){s.value=t,i(s)}),(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 s;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return s}var r=p(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,s;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,s):o:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,s)}function E(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 x(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function g(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function I(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:P}}function P(){return{value:void 0,done:!0}}return l.prototype=m,a(y,"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(y),t},t.awrap=function(t){return{__await:t}},A(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()}))},A(y),a(y,i,"Generator"),a(y,o,(function(){return this})),a(y,"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=I,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(x),!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,s):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),s},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),x(n),s}},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;x(n)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:I(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),s}},t}(t.exports);try{regeneratorRuntime=e}catch(t){"object"==typeof globalThis?globalThis.regeneratorRuntime=e:Function("r","regeneratorRuntime = r")(e)}}(R={exports:{}}),R.exports);(k=exports.Protocol||(exports.Protocol={})).V2="V2",k.V3="V3";var _=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 g(e,t),e}(d.Route),O=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 g(e,t),e}(i.Route),F=function(){function t(t){var e=t.v2Routes,n=t.v3Routes,r=t.tradeType;this.swaps=[],this.routes=[];for(var u,a=P(e);!(u=a()).done;){var c=u.value,p=c.inputAmount,s=c.outputAmount,l=new _(c.routev2);this.routes.push(l),this.swaps.push({route:l,inputAmount:p,outputAmount:s})}for(var m,f=P(n);!(m=f()).done;){var h=m.value,v=h.inputAmount,y=h.outputAmount,A=new O(h.routev3);this.routes.push(A),this.swaps.push({route:A,inputAmount:v,outputAmount:y})}this.tradeType=r;var T=this.swaps[0].inputAmount.currency,w=this.swaps[0].outputAmount.currency;this.swaps.every((function(t){return T.wrapped.equals(t.route.input.wrapped)}))||o(!1),this.swaps.every((function(t){return w.wrapped.equals(t.route.output.wrapped)}))||o(!1);for(var E,x=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),g=new Set,I=P(this.swaps);!(E=I()).done;)for(var k,R=E.value.route,N=P(R.pools);!(k=N()).done;){var F=k.value;R.protocol==exports.Protocol.V3?g.add(i.Pool.getAddress(F.token0,F.token1,F.fee)):g.add(d.Pair.getAddress(F.token0,F.token1))}x!=g.size&&o(!1)}var e,n=t.prototype;return n.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(f)&&o(!1),this.tradeType===c.TradeType.EXACT_OUTPUT)return e;var n=new c.Fraction(h).add(t).invert().multiply(e.quotient).quotient;return c.CurrencyAmount.fromRawAmount(e.currency,n)},n.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(f)&&o(!1),this.tradeType===c.TradeType.EXACT_INPUT)return e;var n=new c.Fraction(h).add(t).multiply(e.quotient).quotient;return c.CurrencyAmount.fromRawAmount(e.currency,n)},n.worstExecutionPrice=function(t){return new c.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.fromRoutes=function(){var e=x(N.mark((function e(n,r,o){var u,a,c,p,s,l,m,f,h,v,y,A,T;return N.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(u=[],a=[],c=P(n);!(p=c()).done;)m=new d.Trade(l=(s=p.value).routev2,s.amount,o),u.push({routev2:l,inputAmount:m.inputAmount,outputAmount:m.outputAmount});f=P(r);case 4:if((h=f()).done){e.next=13;break}return y=(v=h.value).routev3,A=v.amount,e.next=8,i.Trade.fromRoute(y,A,o);case 8:a.push({routev3:y,inputAmount:(T=e.sent).inputAmount,outputAmount:T.outputAmount});case 11:e.next=4;break;case 13:return e.abrupt("return",new t({v2Routes:u,v3Routes:a,tradeType:o}));case 14:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=x(N.mark((function e(n,r,o){var u,a,c,p;return N.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(!(n instanceof d.Route)){e.next=7;break}c=new d.Trade(n,r,o),u=[{routev2:n,inputAmount:c.inputAmount,outputAmount:c.outputAmount}],a=[],e.next=13;break;case 7:return e.next=9,i.Trade.fromRoute(n,r,o);case 9:a=[{routev3:n,inputAmount:(p=e.sent).inputAmount,outputAmount:p.outputAmount}],u=[];case 13:return e.abrupt("return",new t({v2Routes:u,v3Routes:a,tradeType:o}));case 14:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),(e=[{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)}),c.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)}),c.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 c.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=c.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),n=P(this.swaps);!(t=n()).done;){var r=t.value;e=e.add(r.route.midPrice.quote(r.inputAmount))}var o=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new c.Percent(o.numerator,o.denominator),this._priceImpact}}])&&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,r.key,r)}}(t.prototype,e),t}(),b=n.BigInt(0),M=function(){function t(){}return t.encodeV2Swap=function(e,n,r,o){var u=i.toHex(e.maximumAmountIn(n.slippageTolerance).quotient),a=i.toHex(e.minimumAmountOut(n.slippageTolerance).quotient),p=e.route.path.map((function(t){return t.address})),s=r?m:void 0===n.recipient?l:c.validateAndParseAddress(n.recipient);return e.tradeType===c.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[u,o?0:a,p,s]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[a,u,p,s])},t.encodeV3Swap=function(e,n,r,o){for(var u,a=[],p=P(e.swaps);!(u=p()).done;){var s=u.value,d=s.route,f=s.outputAmount,h=i.toHex(e.maximumAmountIn(n.slippageTolerance,s.inputAmount).quotient),v=i.toHex(e.minimumAmountOut(n.slippageTolerance,f).quotient),y=1===d.pools.length,A=r?m:void 0===n.recipient?l:c.validateAndParseAddress(n.recipient);if(y)a.push(e.tradeType===c.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:A,amountIn:h,amountOutMinimum:o?0:v,sqrtPriceLimitX96:0}]):t.INTERFACE.encodeFunctionData("exactOutputSingle",[{tokenIn:d.tokenPath[0].address,tokenOut:d.tokenPath[1].address,fee:d.pools[0].fee,recipient:A,amountOut:v,amountInMaximum:h,sqrtPriceLimitX96:0}]));else{var T=i.encodeRouteToPath(d,e.tradeType===c.TradeType.EXACT_OUTPUT);a.push(e.tradeType===c.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:T,recipient:A,amountIn:h,amountOutMinimum:o?0:v}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:T,recipient:A,amountOut:v,amountInMaximum:h}]))}}return a},t.encodeSwaps=function(e,n,r){if(e instanceof F){e.swaps.every((function(t){return t.route.protocol==exports.Protocol.V3||t.route.protocol==exports.Protocol.V2}))||o(!1);for(var u,a=[],p=P(e.swaps);!(u=p()).done;){var s=u.value,l=s.route,m=s.inputAmount,f=s.outputAmount;l.protocol==exports.Protocol.V2?a.push(new d.Trade(l,e.tradeType==c.TradeType.EXACT_INPUT?m:f,e.tradeType)):l.protocol==exports.Protocol.V3&&a.push(i.Trade.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}))}e=a}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof i.Trade?e.swaps.length:1)}),0),v=e[0];e.every((function(t){return t.inputAmount.currency.equals(v.inputAmount.currency)}))||o(!1),e.every((function(t){return t.outputAmount.currency.equals(v.outputAmount.currency)}))||o(!1),e.every((function(t){return t.tradeType===v.tradeType}))||o(!1);var y=[],A=v.inputAmount.currency.isNative,T=v.outputAmount.currency.isNative,w=v.tradeType===c.TradeType.EXACT_INPUT&&h>2,E=T||!!n.fee||!!r||w;n.inputTokenPermit&&(v.inputAmount.currency.isToken||o(!1),y.push(i.SelfPermit.encodePermit(v.inputAmount.currency,n.inputTokenPermit)));for(var x,g=P(e);!(x=g()).done;){var I=x.value;if(I instanceof d.Trade)y.push(t.encodeV2Swap(I,n,E,w));else for(var k,R=P(t.encodeV3Swap(I,n,E,w));!(k=R()).done;)y.push(k.value)}var N=c.CurrencyAmount.fromRawAmount(v.inputAmount.currency,0),_=c.CurrencyAmount.fromRawAmount(v.outputAmount.currency,0),O=e.reduce((function(t,e){return t.add(e.minimumAmountOut(n.slippageTolerance))}),_),b=e.reduce((function(t,e){return t.add(e.outputAmount)}),_),M=e.reduce((function(t,e){return t.add(e.maximumAmountIn(n.slippageTolerance))}),N);return{calldatas:y,sampleTrade:v,routerMustCustody:E,inputIsNative:A,outputIsNative:T,totalAmountIn:M,minimumAmountOut:O,quoteAmountOut:b}},t.swapCallParameters=function(e,n){var r=t.encodeSwaps(e,n),o=r.calldatas,u=r.sampleTrade,a=r.inputIsNative,p=r.totalAmountIn,s=r.minimumAmountOut;return r.routerMustCustody&&o.push(r.outputIsNative?w.encodeUnwrapWETH9(s.quotient,n.recipient,n.fee):w.encodeSweepToken(u.outputAmount.currency.wrapped,s.quotient,n.recipient,n.fee)),a&&u.tradeType===c.TradeType.EXACT_OUTPUT&&o.push(i.Payments.encodeRefundETH()),{calldata:A.encodeMulticall(o,n.deadlineOrPreviousBlockhash),value:i.toHex(a?p.quotient:b)}},t.swapAndAddCallParameters=function(e,n,r,u,a,p){var s=t.encodeSwaps(e,n,!0),d=s.calldatas,l=s.inputIsNative,m=s.outputIsNative,f=s.sampleTrade,h=s.totalAmountIn,v=s.quoteAmountOut,T=s.minimumAmountOut;n.outputTokenPermit&&(v.currency.isToken||o(!1),d.push(i.SelfPermit.encodePermit(v.currency,n.outputTokenPermit)));var E=f.route.chainId,x=r.pool.token0.wrapped.address===h.currency.wrapped.address,g=t.getPositionAmounts(r,x),I=g.positionAmountIn,P=g.positionAmountOut,k=l?c.WETH9[E]:I.currency.wrapped,R=m?c.WETH9[E]:P.currency.wrapped,N=P.subtract(v.wrapped);N.greaterThan(c.CurrencyAmount.fromRawAmount(P.currency,0))&&d.push(m?w.encodeWrapETH(N.quotient):w.encodePull(R,N.quotient)),d.push(l?w.encodeWrapETH(I.quotient):w.encodePull(k,I.quotient)),a!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(y.encodeApprove(k,a)),p!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(y.encodeApprove(R,p));var _,O=i.Position.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:x?r.amount0.quotient.toString():T.quotient.toString(),amount1:x?T.quotient.toString():r.amount1.quotient.toString(),useFullPrecision:!1});return d.push(y.encodeAddLiquidity(r,O,u,n.slippageTolerance)),d.push(l?w.encodeUnwrapWETH9(b):w.encodeSweepToken(k,b)),d.push(m?w.encodeUnwrapWETH9(b):w.encodeSweepToken(R,b)),_=l?h.wrapped.add(I.wrapped).quotient:m?N.quotient:b,{calldata:A.encodeMulticall(d,n.deadlineOrPreviousBlockhash),value:_.toString()}},t.getPositionAmounts=function(t,e){var n=t.mintAmounts,r=n.amount1,o=c.CurrencyAmount.fromRawAmount(t.pool.token0,n.amount0),u=c.CurrencyAmount.fromRawAmount(t.pool.token1,r),i=e?[o,u]:[u,o];return{positionAmountIn:i[0],positionAmountOut:i[1]}},t}();M.INTERFACE=new r.Interface(s.abi),exports.ADDRESS_THIS=m,exports.ApproveAndCall=y,exports.MSG_SENDER=l,exports.MulticallExtended=A,exports.ONE=h,exports.PaymentsExtended=w,exports.RouteV2=_,exports.RouteV3=O,exports.SwapRouter=M,exports.Trade=F,exports.ZERO=f,exports.isMint=v;
|
|
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=t(require("jsbi")),r=require("@ethersproject/abi"),o=t(require("tiny-invariant")),u=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IApproveAndCall.sol/IApproveAndCall.json"),i=require("@uniswap/v3-sdk"),a=require("@uniswap/swap-router-contracts/artifacts/contracts/interfaces/IMulticallExtended.sol/IMulticallExtended.json"),c=require("@uniswap/sdk-core"),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=n.BigInt(0),v=n.BigInt(1);function A(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 y=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||o(!1),1==e.length)return t.INTERFACE.encodeFunctionData("callPositionManager",e);var n=i.NonfungiblePositionManager.INTERFACE.encodeFunctionData("multicall",[e]);return t.INTERFACE.encodeFunctionData("callPositionManager",[n])},t.encodeAddLiquidity=function(e,r,o,u){var a=e.mintAmountsWithSlippage(u),c=a.amount0,s=a.amount1;return n.lessThan(r.amount0.quotient,c)&&(c=r.amount0.quotient),n.lessThan(r.amount1.quotient,s)&&(s=r.amount1.quotient),A(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:i.toHex(c),amount1Min:i.toHex(s),recipient:o.recipient}]):t.INTERFACE.encodeFunctionData("increaseLiquidity",[{token0:e.pool.token0.address,token1:e.pool.token1.address,amount0Min:i.toHex(c),amount1Min:i.toHex(s),tokenId:i.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}();y.INTERFACE=new r.Interface(u.abi);var T=function(){function t(){}return t.encodeMulticall=function(e,n){if(void 0===n)return i.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=i.toHex(n);return t.INTERFACE.encodeFunctionData("multicall(uint256,bytes[])",[o,e])},t}();function w(t){return i.toHex(t.multiply(1e4).quotient)}T.INTERFACE=new r.Interface(a.abi);var x=function(){function t(){}return t.encodeUnwrapWETH9=function(e,n,r){if("string"==typeof n)return i.Payments.encodeUnwrapWETH9(e,n,r);if(r){var o=w(r.fee),u=c.validateAndParseAddress(r.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee(uint256,uint256,address)",[i.toHex(e),o,u])}return t.INTERFACE.encodeFunctionData("unwrapWETH9(uint256)",[i.toHex(e)])},t.encodeSweepToken=function(e,n,r,o){if("string"==typeof r)return i.Payments.encodeSweepToken(e,n,r,o);if(o){var u=w(o.fee),a=c.validateAndParseAddress(o.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee(address,uint256,uint256,address)",[e.address,i.toHex(n),u,a])}return t.INTERFACE.encodeFunctionData("sweepToken(address,uint256)",[e.address,i.toHex(n)])},t.encodePull=function(e,n){return t.INTERFACE.encodeFunctionData("pull",[e.address,i.toHex(n)])},t.encodeWrapETH=function(e){return t.INTERFACE.encodeFunctionData("wrapETH",[i.toHex(e)])},t}();function E(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 k(t){return function(){var e=this,n=arguments;return new Promise((function(r,o){var u=t.apply(e,n);function i(t){E(u,r,o,i,a,"next",t)}function a(t){E(u,r,o,i,a,"throw",t)}i(void 0)}))}}function g(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 I(t,e,n){return e&&g(t.prototype,e),n&&g(t,n),t}function P(){return(P=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 R(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 b(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.")}x.INTERFACE=new r.Interface(s.abi);var O,N=(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)}}(O={exports:{}}),O.exports),F=function(){function t(t,e,n){this._midPrice=null,t.length>0||o(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||o(!1);var u=e.wrapped;t[0].involvesToken(u)||o(!1),t[t.length-1].involvesToken(n.wrapped)||o(!1);for(var i,a=[u],c=b(t.entries());!(i=c()).done;){var s=i.value,p=s[1],d=a[s[0]];d.equals(p.token0)||d.equals(p.token1)||o(!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 I(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 c.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function q(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||o(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||o(!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 C,M=function(){function t(t){var e=t.routes,n=t.tradeType,r=e[0].inputAmount.currency,u=e[0].outputAmount.currency;e.every((function(t){return r.wrapped.equals(t.route.input.wrapped)}))||o(!1),e.every((function(t){return u.wrapped.equals(t.route.output.wrapped)}))||o(!1);for(var a,s=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),p=new Set,l=b(e);!(a=l()).done;)for(var m,f=b(a.value.route.pools);!(m=f()).done;){var h=m.value;p.add(h instanceof i.Pool?i.Pool.getAddress(h.token0,h.token1,h.fee):d.Pair.getAddress(h.token0,h.token1))}s!=p.size&&o(!1),n!==c.TradeType.EXACT_INPUT&&o(!1),this.swaps=e,this.tradeType=n}t.fromRoute=function(){var e=k(N.mark((function e(n,r,u){var i,a,s,p,d;return N.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:i=new Array(n.path.length),u!==c.TradeType.EXACT_INPUT&&o(!1),r.currency.equals(n.input)||o(!1),i[0]=r.wrapped,p=0;case 5:if(!(p<n.path.length-1)){e.next=15;break}return d=n.pools[p],e.next=9,d.getOutputAmount(i[p]);case 9:i[p+1]=e.sent[0];case 12:p++,e.next=5;break;case 15:return a=c.CurrencyAmount.fromFractionalAmount(n.input,r.numerator,r.denominator),s=c.CurrencyAmount.fromFractionalAmount(n.output,i[i.length-1].numerator,i[i.length-1].denominator),e.abrupt("return",new t({routes:[{inputAmount:a,outputAmount:s,route:n}],tradeType:u}));case 18:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=k(N.mark((function e(n,r){var u,i,a,s,p,d,l,m,f,h,v;return N.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:u=[],r!==c.TradeType.EXACT_INPUT&&o(!1),i=b(n);case 3:if((a=i()).done){e.next=26;break}p=(s=a.value).route,d=s.amount,l=new Array(p.path.length),m=void 0,f=void 0,d.currency.equals(p.input)||o(!1),m=c.CurrencyAmount.fromFractionalAmount(p.input,d.numerator,d.denominator),l[0]=c.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=c.CurrencyAmount.fromFractionalAmount(p.output,l[l.length-1].numerator,l[l.length-1].denominator),u.push({route:p,inputAmount:m,outputAmount:f});case 24:e.next=3;break;case 26:return e.abrupt("return",new t({routes:u,tradeType:r}));case 27:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(P({},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)&&o(!1);var n=new c.Fraction(v).add(t).invert().multiply(e.quotient).quotient;return c.CurrencyAmount.fromRawAmount(e.currency,n)},e.maximumAmountIn=function(t,e){return void 0===e&&(e=this.inputAmount),t.lessThan(h)&&o(!1),e},e.worstExecutionPrice=function(t){return new c.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=k(N.mark((function e(n,r,u,i,a,s,p){var l,m,f,v,A,y,T,w,x,E,k;return N.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(m=(l=void 0===i?{}:i).maxNumResults)?3:m,A=void 0===(v=l.maxHops)?3:v,void 0===a&&(a=[]),void 0===s&&(s=r),void 0===p&&(p=[]),n.length>0||o(!1),A>0||o(!1),r===s||a.length>0||o(!1),y=s.wrapped,T=u.wrapped,w=0;case 10:if(!(w<n.length)){e.next=49;break}if((x=n[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=c.sortedInsert,e.t2=p,e.next=36,t.fromRoute(new F([].concat(a,[x]),r.currency,u),r,c.TradeType.EXACT_INPUT);case 36:e.t3=e.sent,e.t4=f,e.t5=q,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=46;break;case 42:if(!(A>1&&n.length>1)){e.next=46;break}return k=n.slice(0,w).concat(n.slice(w+1,n.length)),e.next=46,t.bestTradeExactIn(k,r,u,{maxNumResults:f,maxHops:A-1},[].concat(a,[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)}}(),I(t,[{key:"route",get:function(){return 1!=this.swaps.length&&o(!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)}),c.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)}),c.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 c.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=c.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),n=b(this.swaps);!(t=n()).done;){var r=t.value;e=e.add(r.route.midPrice.quote(r.inputAmount))}var o=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new c.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}();(C=exports.Protocol||(exports.Protocol={})).V2="V2",C.V3="V3",C.MIXED="MIXED";var S=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 R(e,t),e}(d.Route),H=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 R(e,t),e}(i.Route),U=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 R(e,t),e}(F),D=function(){function t(t){var e=t.v2Routes,n=t.v3Routes,r=t.tradeType,u=t.mixedRoutes;this.swaps=[],this.routes=[];for(var a,c=b(e);!(a=c()).done;){var s=a.value,p=s.inputAmount,l=s.outputAmount,m=new S(s.routev2);this.routes.push(m),this.swaps.push({route:m,inputAmount:p,outputAmount:l})}for(var f,h=b(n);!(f=h()).done;){var v=f.value,A=v.inputAmount,y=v.outputAmount,T=new H(v.routev3);this.routes.push(T),this.swaps.push({route:T,inputAmount:A,outputAmount:y})}if(u)for(var w,x=b(u);!(w=x()).done;){var E=w.value,k=E.inputAmount,g=E.outputAmount,I=new U(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)}))||o(!1),this.swaps.every((function(t){return R.wrapped.equals(t.route.output.wrapped)}))||o(!1);for(var _,O=this.swaps.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),N=new Set,F=b(this.swaps);!(_=F()).done;)for(var q,C=b(_.value.route.pools);!(q=C()).done;){var M=q.value;if(M instanceof i.Pool)N.add(i.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))}}O!=N.size&&o(!1)}var e=t.prototype;return e.minimumAmountOut=function(t,e){if(void 0===e&&(e=this.outputAmount),t.lessThan(h)&&o(!1),this.tradeType===c.TradeType.EXACT_OUTPUT)return e;var n=new c.Fraction(v).add(t).invert().multiply(e.quotient).quotient;return c.CurrencyAmount.fromRawAmount(e.currency,n)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(h)&&o(!1),this.tradeType===c.TradeType.EXACT_INPUT)return e;var n=new c.Fraction(v).add(t).multiply(e.quotient).quotient;return c.CurrencyAmount.fromRawAmount(e.currency,n)},e.worstExecutionPrice=function(t){return new c.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.fromRoutes=function(){var e=k(N.mark((function e(n,r,o,u){var a,c,s,p,l,m,f,h,v,A,y,T,w,x,E,k,g,I,P,R;return N.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:for(a=[],c=[],s=[],p=b(n);!(l=p()).done;)h=new d.Trade(f=(m=l.value).routev2,m.amount,o),a.push({routev2:f,inputAmount:h.inputAmount,outputAmount:h.outputAmount});v=b(r);case 5:if((A=v()).done){e.next=14;break}return T=(y=A.value).routev3,w=y.amount,e.next=9,i.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=b(u);case 16:if((k=E()).done){e.next=25;break}return I=(g=k.value).mixedRoute,P=g.amount,e.next=20,M.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:a,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=k(N.mark((function e(n,r,o){var u,a,c,s,p,l;return N.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u=[],a=[],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 i.Route)){e.next=17;break}return e.next=12,i.Trade.fromRoute(n,r,o);case 12:a=[{routev3:n,inputAmount:(p=e.sent).inputAmount,outputAmount:p.outputAmount}],e.next=26;break;case 17:if(!(n instanceof F)){e.next=25;break}return e.next=20,M.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:a,mixedRoutes:c,tradeType:o}));case 27:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),I(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)}),c.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)}),c.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 c.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=c.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),n=b(this.swaps);!(t=n()).done;){var r=t.value;e=e.add(r.route.midPrice.quote(r.inputAmount))}var o=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new c.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}();function L(t){var e=t.pools.reduce((function(t,e,n){var r=t.inputToken,o=t.path,u=t.types,a=e.token0.equals(r)?e.token1:e.token0;return 0===n?{inputToken:a,types:["address","uint24","address"],path:[r.address,e instanceof i.Pool?e.fee:8388608,a.address]}:{inputToken:a,types:[].concat(u,["uint24","address"]),path:[].concat(o,[e instanceof i.Pool?e.fee:8388608,a.address])}}),{inputToken:t.input.wrapped,path:[],types:[]});return l.pack(e.types,e.path)}var X=function(t){for(var e=[],n=0,r=0;r<t.pools.length;)(t.pools[n]instanceof i.Pool&&t.pools[r]instanceof d.Pair||t.pools[n]instanceof d.Pair&&t.pools[r]instanceof i.Pool)&&(e.push(t.pools.slice(n,r)),n=r),++r===t.pools.length&&e.push(t.pools.slice(n,r));return e},j=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},W=n.BigInt(0),V=new c.Percent(n.BigInt(50),n.BigInt(100)),Z=function(){function t(){}return t.encodeV2Swap=function(e,n,r,o){var u=i.toHex(e.maximumAmountIn(n.slippageTolerance).quotient),a=i.toHex(e.minimumAmountOut(n.slippageTolerance).quotient),s=e.route.path.map((function(t){return t.address})),p=r?f:void 0===n.recipient?m:c.validateAndParseAddress(n.recipient);return e.tradeType===c.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[u,o?0:a,s,p]):t.INTERFACE.encodeFunctionData("swapTokensForExactTokens",[a,u,s,p])},t.encodeV3Swap=function(e,n,r,o){for(var u,a=[],s=b(e.swaps);!(u=s()).done;){var p=u.value,d=p.route,l=p.outputAmount,h=i.toHex(e.maximumAmountIn(n.slippageTolerance,p.inputAmount).quotient),v=i.toHex(e.minimumAmountOut(n.slippageTolerance,l).quotient),A=1===d.pools.length,y=r?f:void 0===n.recipient?m:c.validateAndParseAddress(n.recipient);if(A)a.push(e.tradeType===c.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:o?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=i.encodeRouteToPath(d,e.tradeType===c.TradeType.EXACT_OUTPUT);a.push(e.tradeType===c.TradeType.EXACT_INPUT?t.INTERFACE.encodeFunctionData("exactInput",[{path:T,recipient:y,amountIn:h,amountOutMinimum:o?0:v}]):t.INTERFACE.encodeFunctionData("exactOutput",[{path:T,recipient:y,amountOut:v,amountInMaximum:h}]))}}return a},t.encodeMixedRouteSwap=function(e,n,r,u){var a=[];e.tradeType!==c.TradeType.EXACT_INPUT&&o(!1);for(var s,p=b(e.swaps);!(s=p()).done;){var d=s.value,l=d.route,h=d.outputAmount,v=i.toHex(e.maximumAmountIn(n.slippageTolerance,d.inputAmount).quotient),A=i.toHex(e.minimumAmountOut(n.slippageTolerance,h).quotient),y=1===l.pools.length,T=r?f:void 0===n.recipient?m:c.validateAndParseAddress(n.recipient),w=function(t){return t.pools.every((function(t){return t instanceof i.Pool}))};if(y)if(w(l))a.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:u?0:A,sqrtPriceLimitX96:0}]));else{var x=l.path.map((function(t){return t.address}));a.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",[v,u?0:A,x,T]))}else!function(){for(var e=X(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=j(i,o);var c=new F([].concat(i),i[0].token0.equals(o)?i[0].token0:i[0].token1,r),s=new U(c);if(o=r,w(s)){var p={path:L(s),recipient:n(u)?T:f,amountIn:0==u?v:0,amountOutMinimum:n(u)?A:0};a.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];a.push(t.INTERFACE.encodeFunctionData("swapExactTokensForTokens",d))}}}()}return a},t.encodeSwaps=function(e,n,r){if(e instanceof D){e.swaps.every((function(t){return t.route.protocol==exports.Protocol.V3||t.route.protocol==exports.Protocol.V2||t.route.protocol==exports.Protocol.MIXED}))||o(!1);for(var u,a=[],s=b(e.swaps);!(u=s()).done;){var p=u.value,l=p.route,m=p.inputAmount,f=p.outputAmount;if(l.protocol==exports.Protocol.V2)a.push(new d.Trade(l,e.tradeType==c.TradeType.EXACT_INPUT?m:f,e.tradeType));else if(l.protocol==exports.Protocol.V3)a.push(i.Trade.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}));else{if(l.protocol!=exports.Protocol.MIXED)throw new Error("UNSUPPORTED_TRADE_PROTOCOL");a.push(M.createUncheckedTrade({route:l,inputAmount:m,outputAmount:f,tradeType:e.tradeType}))}}e=a}Array.isArray(e)||(e=[e]);var h=e.reduce((function(t,e){return t+(e instanceof i.Trade||e instanceof M?e.swaps.length:1)}),0),v=e[0];e.every((function(t){return t.inputAmount.currency.equals(v.inputAmount.currency)}))||o(!1),e.every((function(t){return t.outputAmount.currency.equals(v.outputAmount.currency)}))||o(!1),e.every((function(t){return t.tradeType===v.tradeType}))||o(!1);var A=[],y=v.inputAmount.currency.isNative,T=v.outputAmount.currency.isNative,w=v.tradeType===c.TradeType.EXACT_INPUT&&h>2,x=T||!!n.fee||!!r||w;n.inputTokenPermit&&(v.inputAmount.currency.isToken||o(!1),A.push(i.SelfPermit.encodePermit(v.inputAmount.currency,n.inputTokenPermit)));for(var E,k=b(e);!(E=k()).done;){var g=E.value;if(g instanceof d.Trade)A.push(t.encodeV2Swap(g,n,x,w));else if(g instanceof i.Trade)for(var I,P=b(t.encodeV3Swap(g,n,x,w));!(I=P()).done;)A.push(I.value);else{if(!(g instanceof M))throw new Error("Unsupported trade object");for(var R,_=b(t.encodeMixedRouteSwap(g,n,x,w));!(R=_()).done;)A.push(R.value)}}var O=c.CurrencyAmount.fromRawAmount(v.inputAmount.currency,0),N=c.CurrencyAmount.fromRawAmount(v.outputAmount.currency,0),F=e.reduce((function(t,e){return t.add(e.minimumAmountOut(n.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(n.slippageTolerance))}),O);return{calldatas:A,sampleTrade:v,routerMustCustody:x,inputIsNative:y,outputIsNative:T,totalAmountIn:C,minimumAmountOut:F,quoteAmountOut:q}},t.swapCallParameters=function(e,n){var r=t.encodeSwaps(e,n),o=r.calldatas,u=r.sampleTrade,a=r.inputIsNative,s=r.totalAmountIn,p=r.minimumAmountOut;return r.routerMustCustody&&o.push(r.outputIsNative?x.encodeUnwrapWETH9(p.quotient,n.recipient,n.fee):x.encodeSweepToken(u.outputAmount.currency.wrapped,p.quotient,n.recipient,n.fee)),a&&(u.tradeType===c.TradeType.EXACT_OUTPUT||t.riskOfPartialFill(e))&&o.push(i.Payments.encodeRefundETH()),{calldata:T.encodeMulticall(o,n.deadlineOrPreviousBlockhash),value:i.toHex(a?s.quotient:W)}},t.swapAndAddCallParameters=function(e,n,r,u,a,s){var p=t.encodeSwaps(e,n,!0),d=p.calldatas,l=p.inputIsNative,m=p.outputIsNative,f=p.sampleTrade,h=p.totalAmountIn,v=p.quoteAmountOut,A=p.minimumAmountOut;n.outputTokenPermit&&(v.currency.isToken||o(!1),d.push(i.SelfPermit.encodePermit(v.currency,n.outputTokenPermit)));var w=f.route.chainId,E=r.pool.token0.wrapped.address===h.currency.wrapped.address,k=t.getPositionAmounts(r,E),g=k.positionAmountIn,I=k.positionAmountOut,P=l?c.WETH9[w]:g.currency.wrapped,R=m?c.WETH9[w]:I.currency.wrapped,_=I.subtract(v.wrapped);_.greaterThan(c.CurrencyAmount.fromRawAmount(I.currency,0))&&d.push(m?x.encodeWrapETH(_.quotient):x.encodePull(R,_.quotient)),d.push(l?x.encodeWrapETH(g.quotient):x.encodePull(P,g.quotient)),a!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(y.encodeApprove(P,a)),s!==exports.ApprovalTypes.NOT_REQUIRED&&d.push(y.encodeApprove(R,s));var b,O=i.Position.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:E?r.amount0.quotient.toString():A.quotient.toString(),amount1:E?A.quotient.toString():r.amount1.quotient.toString(),useFullPrecision:!1});return d.push(y.encodeAddLiquidity(r,O,u,n.slippageTolerance)),d.push(l?x.encodeUnwrapWETH9(W):x.encodeSweepToken(P,W)),d.push(m?x.encodeUnwrapWETH9(W):x.encodeSweepToken(R,W)),b=l?h.wrapped.add(g.wrapped).quotient:m?_.quotient:W,{calldata:T.encodeMulticall(d,n.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(V)},t.getPositionAmounts=function(t,e){var n=t.mintAmounts,r=n.amount1,o=c.CurrencyAmount.fromRawAmount(t.pool.token0,n.amount0),u=c.CurrencyAmount.fromRawAmount(t.pool.token1,r),i=e?[o,u]:[u,o];return{positionAmountIn:i[0],positionAmountOut:i[1]}},t}();Z.INTERFACE=new r.Interface(p.abi),exports.ADDRESS_THIS=f,exports.ApproveAndCall=y,exports.MSG_SENDER=m,exports.MixedRoute=U,exports.MixedRouteSDK=F,exports.MulticallExtended=T,exports.ONE=v,exports.PaymentsExtended=x,exports.RouteV2=S,exports.RouteV3=H,exports.SwapRouter=Z,exports.Trade=D,exports.V2_FEE_PATH_PLACEHOLDER=8388608,exports.ZERO=h,exports.encodeMixedRouteToPath=L,exports.getOutputOfPools=j,exports.isMint=A,exports.partitionMixedRouteByProtocol=X;
|
|
2
2
|
//# sourceMappingURL=router-sdk.cjs.production.min.js.map
|