Socket
Socket
Sign inDemoInstall

@uniswap/v3-sdk

Package Overview
Dependencies
Maintainers
9
Versions
89
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniswap/v3-sdk - npm Package Compare versions

Comparing version 2.0.1 to 2.0.2

16

dist/entities/position.d.ts

@@ -46,6 +46,7 @@ import { BigintIsh, Percent, Price, CurrencyAmount } from '@uniswap/sdk-core';

/**
* Get the minimum amounts that must be spent to safely create this position, for the given slippage tolerance
* Returns the minimum amounts that must be sent in order to safely mint the amount of liquidity held by the position
* with the given slippage tolerance
* @param slippageTolerance tolerance of unfavorable slippage from the current price
*/
minimumAmounts(slippageTolerance: Percent): Readonly<{
mintAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
amount0: JSBI;

@@ -55,3 +56,12 @@ amount1: JSBI;

/**
* Returns the minimum amount that must be sent in order to mint the amount of liquidity held by the position at
* Returns the minimum amounts that should be requested in order to safely burn the amount of liquidity held by the
* position with the given slippage tolerance
* @param slippageTolerance tolerance of unfavorable slippage from the current price
*/
burnAmountsWithSlippage(slippageTolerance: Percent): Readonly<{
amount0: JSBI;
amount1: JSBI;
}>;
/**
* Returns the minimum amounts that must be sent in order to mint the amount of liquidity held by the position at
* the current price for the pool

@@ -58,0 +68,0 @@ */

2

dist/v3-sdk.cjs.production.min.js

@@ -1,2 +0,2 @@

"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@uniswap/sdk-core"),n=t(require("jsbi")),r=t(require("tiny-invariant")),i=require("@ethersproject/abi"),o=require("@ethersproject/address"),u=require("@ethersproject/solidity"),a=require("@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json"),c=require("@uniswap/v3-periphery/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json"),s=require("@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json");function l(t,e,n,r,i,o,u){try{var a=t[o](u),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(r,i)}function p(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function u(t){l(o,r,i,u,a,"next",t)}function a(t){l(o,r,i,u,a,"throw",t)}u(void 0)}))}}function d(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 h(t,e,n){return e&&d(t.prototype,e),n&&d(t,n),t}function f(){return(f=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 m(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function y(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 k(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return y(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)?y(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.")}return(n=t[Symbol.iterator]()).next.bind(n)}var v,g,T,x=(function(t){var e=function(t){var e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",u=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 i=Object.create((e&&e.prototype instanceof p?e:p).prototype),o=new I(r||[]);return i._invoke=function(t,e,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return{value:void 0,done:!0}}for(n.method=i,n.arg=o;;){var u=n.delegate;if(u){var a=T(u,n);if(a){if(a===l)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===l)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(t,n,o),i}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 l={};function p(){}function d(){}function h(){}var f={};f[i]=function(){return this};var m=Object.getPrototypeOf,y=m&&m(m(w([])));y&&y!==e&&n.call(y,i)&&(f=y);var k=h.prototype=p.prototype=Object.create(f);function v(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){var r;this._invoke=function(i,o){function u(){return new e((function(r,u){!function r(i,o,u,a){var c=s(t[i],t,o);if("throw"!==c.type){var l=c.arg,p=l.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,u,a)}),(function(t){r("throw",t,u,a)})):e.resolve(p).then((function(t){l.value=t,u(l)}),(function(t){return r("throw",t,u,a)}))}a(c.arg)}(i,o,r,u)}))}return r=r?r.then(u,u):u()}}function T(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,T(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=s(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,l;var i=r.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}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 A(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function I(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function w(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=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 o.next=o}}return{next:E}}function E(){return{value:void 0,done:!0}}return d.prototype=k.constructor=h,h.constructor=d,d.displayName=a(h,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,a(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},v(g.prototype),g.prototype[o]=function(){return this},t.AsyncIterator=g,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var u=new g(c(e,n,r,i),o);return t.isGeneratorFunction(n)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},v(k),a(k,u,"Generator"),k[i]=function(){return this},k.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=w,I.prototype={constructor:I,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(A),!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 u.type="throw",u.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var a=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=t,u.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(u)},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),l},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),A(n),l}},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 i=r.arg;A(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:w(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(T={exports:{}}),T.exports),A="0x0000000000000000000000000000000000000000",I="0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54";(g=exports.FeeAmount||(exports.FeeAmount={}))[g.LOW=500]="LOW",g[g.MEDIUM=3e3]="MEDIUM",g[g.HIGH=1e4]="HIGH";var w=((v={})[exports.FeeAmount.LOW]=10,v[exports.FeeAmount.MEDIUM]=60,v[exports.FeeAmount.HIGH]=200,v),E=n.BigInt(-1),q=n.BigInt(0),b=n.BigInt(1),R=n.exponentiate(n.BigInt(2),n.BigInt(96)),P=n.exponentiate(R,n.BigInt(2));function C(t){var e=t.factoryAddress,n=t.tokenA,r=t.tokenB,a=t.fee,c=n.sortsBefore(r)?[n,r]:[r,n];return o.getCreate2Address(e,u.keccak256(["bytes"],[i.defaultAbiCoder.encode(["address","address","uint24"],[c[0].address,c[1].address,a])]),I)}var O=function(){function t(){}return t.addDelta=function(t,e){return n.lessThan(e,q)?n.subtract(t,n.multiply(e,E)):n.add(t,e)},t}(),S=function(){function t(){}return t.mulDivRoundingUp=function(t,e,r){var i=n.multiply(t,e),o=n.divide(i,r);return n.notEqual(n.remainder(i,r),q)&&(o=n.add(o,b)),o},t}(),N=n.subtract(n.exponentiate(n.BigInt(2),n.BigInt(160)),b);function _(t,r){var i=n.multiply(t,r);return n.bitwiseAnd(i,e.MaxUint256)}var F=function(){function t(){}return t.getAmount0Delta=function(t,e,r,i){if(n.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}var u=n.leftShift(r,n.BigInt(96)),a=n.subtract(e,t);return i?S.mulDivRoundingUp(S.mulDivRoundingUp(u,a,e),b,t):n.divide(n.divide(n.multiply(u,a),e),t)},t.getAmount1Delta=function(t,e,r,i){if(n.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}return i?S.mulDivRoundingUp(r,n.subtract(e,t),R):n.divide(n.multiply(r,n.subtract(e,t)),R)},t.getNextSqrtPriceFromInput=function(t,e,i,o){return n.greaterThan(t,q)||r(!1),n.greaterThan(e,q)||r(!1),o?this.getNextSqrtPriceFromAmount0RoundingUp(t,e,i,!0):this.getNextSqrtPriceFromAmount1RoundingDown(t,e,i,!0)},t.getNextSqrtPriceFromOutput=function(t,e,i,o){return n.greaterThan(t,q)||r(!1),n.greaterThan(e,q)||r(!1),o?this.getNextSqrtPriceFromAmount1RoundingDown(t,e,i,!1):this.getNextSqrtPriceFromAmount0RoundingUp(t,e,i,!1)},t.getNextSqrtPriceFromAmount0RoundingUp=function(t,i,o,u){if(n.equal(o,q))return t;var a=n.leftShift(i,n.BigInt(96));if(u){var c=_(o,t);if(n.equal(n.divide(c,o),t)){var s=(p=n.add(a,c),n.bitwiseAnd(p,e.MaxUint256));if(n.greaterThanOrEqual(s,a))return S.mulDivRoundingUp(a,t,s)}return S.mulDivRoundingUp(a,b,n.add(n.divide(a,t),o))}var l=_(o,t);n.equal(n.divide(l,o),t)||r(!1),n.greaterThan(a,l)||r(!1);var p,d=n.subtract(a,l);return S.mulDivRoundingUp(a,t,d)},t.getNextSqrtPriceFromAmount1RoundingDown=function(t,e,i,o){if(o){var u=n.lessThanOrEqual(i,N)?n.divide(n.leftShift(i,n.BigInt(96)),e):n.divide(n.multiply(i,R),e);return n.add(t,u)}var a=S.mulDivRoundingUp(i,R,e);return n.greaterThan(t,a)||r(!1),n.subtract(t,a)},t}(),D=n.exponentiate(n.BigInt(10),n.BigInt(6)),L=function(){function t(){}return t.computeSwapStep=function(t,e,r,i,o){var u={},a=n.greaterThanOrEqual(t,e),c=n.greaterThanOrEqual(i,q);if(c){var s=n.divide(n.multiply(i,n.subtract(D,n.BigInt(o))),D);u.amountIn=a?F.getAmount0Delta(e,t,r,!0):F.getAmount1Delta(t,e,r,!0),u.sqrtRatioNextX96=n.greaterThanOrEqual(s,u.amountIn)?e:F.getNextSqrtPriceFromInput(t,r,s,a)}else u.amountOut=a?F.getAmount1Delta(e,t,r,!1):F.getAmount0Delta(t,e,r,!1),u.sqrtRatioNextX96=n.greaterThanOrEqual(n.multiply(i,E),u.amountOut)?e:F.getNextSqrtPriceFromOutput(t,r,n.multiply(i,E),a);var l=n.equal(e,u.sqrtRatioNextX96);return a?(u.amountIn=l&&c?u.amountIn:F.getAmount0Delta(u.sqrtRatioNextX96,t,r,!0),u.amountOut=l&&!c?u.amountOut:F.getAmount1Delta(u.sqrtRatioNextX96,t,r,!1)):(u.amountIn=l&&c?u.amountIn:F.getAmount1Delta(t,u.sqrtRatioNextX96,r,!0),u.amountOut=l&&!c?u.amountOut:F.getAmount0Delta(t,u.sqrtRatioNextX96,r,!1)),!c&&n.greaterThan(u.amountOut,n.multiply(i,E))&&(u.amountOut=n.multiply(i,E)),u.feeAmount=c&&n.notEqual(u.sqrtRatioNextX96,e)?n.subtract(i,u.amountIn):S.mulDivRoundingUp(u.amountIn,n.BigInt(o),n.subtract(D,n.BigInt(o))),[u.sqrtRatioNextX96,u.amountIn,u.amountOut,u.feeAmount]},t}(),X=n.BigInt(2),B=[128,64,32,16,8,4,2,1].map((function(t){return[t,n.exponentiate(X,n.BigInt(t))]}));function U(t){n.greaterThan(t,q)||r(!1),n.lessThanOrEqual(t,e.MaxUint256)||r(!1);for(var i,o=0,u=k(B);!(i=u()).done;){var a=i.value,c=a[0];n.greaterThanOrEqual(t,a[1])&&(t=n.signedRightShift(t,n.BigInt(c)),o+=c)}return o}function M(t,e){return n.signedRightShift(n.multiply(t,n.BigInt(e)),n.BigInt(128))}var H=n.exponentiate(n.BigInt(2),n.BigInt(32)),j=function(){function t(){}return t.getSqrtRatioAtTick=function(i){i>=t.MIN_TICK&&i<=t.MAX_TICK&&Number.isInteger(i)||r(!1);var o=i<0?-1*i:i,u=n.BigInt(0!=(1&o)?"0xfffcb933bd6fad37aa2d162d1a594001":"0x100000000000000000000000000000000");return 0!=(2&o)&&(u=M(u,"0xfff97272373d413259a46990580e213a")),0!=(4&o)&&(u=M(u,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&o)&&(u=M(u,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&o)&&(u=M(u,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&o)&&(u=M(u,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&o)&&(u=M(u,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&o)&&(u=M(u,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&o)&&(u=M(u,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&o)&&(u=M(u,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&o)&&(u=M(u,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&o)&&(u=M(u,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&o)&&(u=M(u,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&o)&&(u=M(u,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&o)&&(u=M(u,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&o)&&(u=M(u,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&o)&&(u=M(u,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&o)&&(u=M(u,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&o)&&(u=M(u,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&o)&&(u=M(u,"0x48a170391f7dc42444e8fa2")),i>0&&(u=n.divide(e.MaxUint256,u)),n.greaterThan(n.remainder(u,H),q)?n.add(n.divide(u,H),b):n.divide(u,H)},t.getTickAtSqrtRatio=function(e){n.greaterThanOrEqual(e,t.MIN_SQRT_RATIO)&&n.lessThan(e,t.MAX_SQRT_RATIO)||r(!1);var i,o=n.leftShift(e,n.BigInt(32)),u=U(o);i=n.greaterThanOrEqual(n.BigInt(u),n.BigInt(128))?n.signedRightShift(o,n.BigInt(u-127)):n.leftShift(o,n.BigInt(127-u));for(var a=n.leftShift(n.subtract(n.BigInt(u),n.BigInt(128)),n.BigInt(64)),c=0;c<14;c++){i=n.signedRightShift(n.multiply(i,i),n.BigInt(127));var s=n.signedRightShift(i,n.BigInt(128));a=n.bitwiseOr(a,n.leftShift(s,n.BigInt(63-c))),i=n.signedRightShift(i,s)}var l=n.multiply(a,n.BigInt("255738958999603826347141")),p=n.toNumber(n.signedRightShift(n.subtract(l,n.BigInt("3402992956809132418596140100660247210")),n.BigInt(128))),d=n.toNumber(n.signedRightShift(n.add(l,n.BigInt("291339464771989622907027621153398088495")),n.BigInt(128)));return p===d?p:n.lessThanOrEqual(t.getSqrtRatioAtTick(d),e)?d:p},t}();j.MIN_TICK=-887272,j.MAX_TICK=-j.MIN_TICK,j.MIN_SQRT_RATIO=n.BigInt("4295128739"),j.MAX_SQRT_RATIO=n.BigInt("1461446703485210103287273052203988822378723970342");var W=function(){function t(){}var e=t.prototype;return e.getTick=function(){var e=p(x.mark((function e(n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error(t.ERROR_MESSAGE);case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.nextInitializedTickWithinOneWord=function(){var e=p(x.mark((function e(n,r,i){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error(t.ERROR_MESSAGE);case 1:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t}();function K(t,e){for(var n=0;n<t.length-1;n++)if(e(t[n],t[n+1])>0)return!1;return!0}function G(t,e){return t.index-e.index}W.ERROR_MESSAGE="No tick data provider was given";var z=function(){function t(){}return t.validateList=function(t,e){e>0||r(!1),t.every((function(t){return t.index%e==0}))||r(!1),n.equal(t.reduce((function(t,e){return n.add(t,e.liquidityNet)}),q),q)||r(!1),K(t,G)||r(!1)},t.isBelowSmallest=function(t,e){return t.length>0||r(!1),e<t[0].index},t.isAtOrAboveLargest=function(t,e){return t.length>0||r(!1),e>=t[t.length-1].index},t.getTick=function(t,e){var n=t[this.binarySearch(t,e)];return n.index!==e&&r(!1),n},t.binarySearch=function(t,e){this.isBelowSmallest(t,e)&&r(!1);for(var n,i=0,o=t.length-1;;){if(t[n=Math.floor((i+o)/2)].index<=e&&(n===t.length-1||t[n+1].index>e))return n;t[n].index<e?i=n+1:o=n-1}},t.nextInitializedTick=function(e,n,i){return i?(t.isBelowSmallest(e,n)&&r(!1),t.isAtOrAboveLargest(e,n)?e[e.length-1]:e[this.binarySearch(e,n)]):(this.isAtOrAboveLargest(e,n)&&r(!1),this.isBelowSmallest(e,n)?e[0]:e[this.binarySearch(e,n)+1])},t.nextInitializedTickWithinOneWord=function(e,n,r,i){var o=Math.floor(n/i);if(r){var u=(o>>8<<8)*i;if(t.isBelowSmallest(e,n))return[u,!1];var a=t.nextInitializedTick(e,n,r).index,c=Math.max(u,a);return[c,c===a]}var s=(1+(o+1>>8)<<8)*i-1;if(this.isAtOrAboveLargest(e,n))return[s,!1];var l=this.nextInitializedTick(e,n,r).index,p=Math.min(s,l);return[p,p===l]},t}();function Q(t){var e=n.BigInt(t).toString(16);return e.length%2!=0&&(e="0"+e),"0x"+e}function Y(t,n){var r=t.input.isToken?t.input:t.input.isEther?e.WETH9[t.chainId]:void 0;if(!r)throw new Error("Could not wrap input currency");var i=t.pools.reduce((function(t,e,n){var r=t.inputToken,i=t.path,o=t.types,u=e.token0.equals(r)?e.token1:e.token0;return 0===n?{inputToken:u,types:["address","uint24","address"],path:[r.address,e.fee,u.address]}:{inputToken:u,types:[].concat(o,["uint24","address"]),path:[].concat(i,[e.fee,u.address])}}),{inputToken:r,path:[],types:[]}),o=i.path,a=i.types;return n?u.pack(a.reverse(),o.reverse()):u.pack(a,o)}function Z(t,r){var i=n.leftShift(n.BigInt(t),n.BigInt(192)),o=n.BigInt(r),u=n.divide(i,o);return e.sqrt(u)}function $(t,e,r){if(n.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=n.divide(n.multiply(t,e),R);return n.divide(n.multiply(n.BigInt(r),o),n.subtract(e,t))}function J(t,e,r){if(n.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}return n.divide(n.multiply(n.BigInt(r),R),n.subtract(e,t))}function V(t,e,r,i,o){if(n.greaterThan(e,r)){var u=[r,e];e=u[0],r=u[1]}if(n.lessThanOrEqual(t,e))return $(e,r,i);if(n.lessThan(t,r)){var a=$(t,r,i),c=J(e,t,o);return n.lessThan(a,c)?a:c}return J(e,r,o)}function tt(t,r,i){var o=j.getSqrtRatioAtTick(i),u=n.multiply(o,o);return t.sortsBefore(r)?new e.Price(t,r,P,u):new e.Price(t,r,u,P)}var et=function(t){var e=t.index,i=t.liquidityGross,o=t.liquidityNet;e>=j.MIN_TICK&&e<=j.MAX_TICK||r(!1),this.index=e,this.liquidityGross=n.BigInt(i),this.liquidityNet=n.BigInt(o)},nt=function(){function t(t,e){var n=t.map((function(t){return t instanceof et?t:new et(t)}));z.validateList(n,e),this.ticks=n}var e=t.prototype;return e.getTick=function(){var t=p(x.mark((function t(e){return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",z.getTick(this.ticks,e));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.nextInitializedTickWithinOneWord=function(){var t=p(x.mark((function t(e,n,r){return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",z.nextInitializedTickWithinOneWord(this.ticks,e,n,r));case 1:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),t}(),rt=new W,it=function(){function t(t,e,i,o,u,a,c){void 0===c&&(c=rt),Number.isInteger(i)&&i<1e6||r(!1);var s=j.getSqrtRatioAtTick(a),l=j.getSqrtRatioAtTick(a+1);n.greaterThanOrEqual(n.BigInt(o),s)&&n.lessThanOrEqual(n.BigInt(o),l)||r(!1);var p=t.sortsBefore(e)?[t,e]:[e,t];this.token0=p[0],this.token1=p[1],this.fee=i,this.sqrtRatioX96=n.BigInt(o),this.liquidity=n.BigInt(u),this.tickCurrent=a,this.tickDataProvider=Array.isArray(c)?new nt(c,w[i]):c}t.getAddress=function(t,e,n){return C({factoryAddress:"0x1F98431c8aD98523631AE4a59f267346ea31F984",fee:n,tokenA:t,tokenB:e})};var i=t.prototype;return i.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},i.priceOf=function(t){return this.involvesToken(t)||r(!1),t.equals(this.token0)?this.token0Price:this.token1Price},i.getOutputAmount=function(){var i=p(x.mark((function i(o){var u,a,c,s,l;return x.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return o.currency.isToken&&this.involvesToken(o.currency)||r(!1),u=o.currency.equals(this.token0),i.next=4,this.swap(u,o.raw);case 4:return c=(a=i.sent).sqrtRatioX96,s=a.liquidity,l=a.tickCurrent,i.abrupt("return",[new e.CurrencyAmount(u?this.token1:this.token0,n.multiply(a.amountCalculated,E)),new t(this.token0,this.token1,this.fee,c,s,l,this.tickDataProvider)]);case 11:case"end":return i.stop()}}),i,this)})));return function(t){return i.apply(this,arguments)}}(),i.getInputAmount=function(){var i=p(x.mark((function i(o){var u,a,c,s,l;return x.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return o.currency.isToken&&this.involvesToken(o.currency)||r(!1),u=o.currency.equals(this.token1),i.next=4,this.swap(u,n.multiply(o.raw,E));case 4:return c=(a=i.sent).sqrtRatioX96,s=a.liquidity,l=a.tickCurrent,i.abrupt("return",[new e.CurrencyAmount(u?this.token0:this.token1,a.amountCalculated),new t(this.token0,this.token1,this.fee,c,s,l,this.tickDataProvider)]);case 11:case"end":return i.stop()}}),i,this)})));return function(t){return i.apply(this,arguments)}}(),i.swap=function(){var t=p(x.mark((function t(e,i,o){var u,a,c,s,l,p;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o||(o=e?n.add(j.MIN_SQRT_RATIO,b):n.subtract(j.MAX_SQRT_RATIO,b)),e?(n.greaterThan(o,j.MIN_SQRT_RATIO)||r(!1),n.lessThan(o,this.sqrtRatioX96)||r(!1)):(n.lessThan(o,j.MAX_SQRT_RATIO)||r(!1),n.greaterThan(o,this.sqrtRatioX96)||r(!1)),u=n.greaterThanOrEqual(i,q),a={amountSpecifiedRemaining:i,amountCalculated:q,sqrtPriceX96:this.sqrtRatioX96,tick:this.tickCurrent,liquidity:this.liquidity};case 4:if(!n.notEqual(a.amountSpecifiedRemaining,q)||a.sqrtPriceX96==o){t.next=35;break}return(c={}).sqrtPriceStartX96=a.sqrtPriceX96,t.next=9,this.tickDataProvider.nextInitializedTickWithinOneWord(a.tick,e,this.tickSpacing);case 9:if(c.tickNext=(s=t.sent)[0],c.initialized=s[1],c.tickNext<j.MIN_TICK?c.tickNext=j.MIN_TICK:c.tickNext>j.MAX_TICK&&(c.tickNext=j.MAX_TICK),c.sqrtPriceNextX96=j.getSqrtRatioAtTick(c.tickNext),l=L.computeSwapStep(a.sqrtPriceX96,(e?n.lessThan(c.sqrtPriceNextX96,o):n.greaterThan(c.sqrtPriceNextX96,o))?o:c.sqrtPriceNextX96,a.liquidity,a.amountSpecifiedRemaining,this.fee),a.sqrtPriceX96=l[0],c.amountIn=l[1],c.amountOut=l[2],c.feeAmount=l[3],u?(a.amountSpecifiedRemaining=n.subtract(a.amountSpecifiedRemaining,n.add(c.amountIn,c.feeAmount)),a.amountCalculated=n.subtract(a.amountCalculated,c.amountOut)):(a.amountSpecifiedRemaining=n.add(a.amountSpecifiedRemaining,c.amountOut),a.amountCalculated=n.add(a.amountCalculated,n.add(c.amountIn,c.feeAmount))),!n.equal(a.sqrtPriceX96,c.sqrtPriceNextX96)){t.next=32;break}if(!c.initialized){t.next=29;break}return t.t0=n,t.next=25,this.tickDataProvider.getTick(c.tickNext);case 25:t.t1=t.sent.liquidityNet,p=t.t0.BigInt.call(t.t0,t.t1),e&&(p=n.multiply(p,E)),a.liquidity=O.addDelta(a.liquidity,p);case 29:a.tick=e?c.tickNext-1:c.tickNext,t.next=33;break;case 32:a.sqrtPriceX96!=c.sqrtPriceStartX96&&(a.tick=j.getTickAtSqrtRatio(a.sqrtPriceX96));case 33:t.next=4;break;case 35:return t.abrupt("return",{amountCalculated:a.amountCalculated,sqrtRatioX96:a.sqrtPriceX96,liquidity:a.liquidity,tickCurrent:a.tick});case 36:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),h(t,[{key:"token0Price",get:function(){var t;return null!=(t=this._token0Price)?t:this._token0Price=new e.Price(this.token0,this.token1,P,n.multiply(this.sqrtRatioX96,this.sqrtRatioX96))}},{key:"token1Price",get:function(){var t;return null!=(t=this._token1Price)?t:this._token1Price=new e.Price(this.token1,this.token0,n.multiply(this.sqrtRatioX96,this.sqrtRatioX96),P)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"tickSpacing",get:function(){return w[this.fee]}}]),t}(),ot=function(){function t(t){var e=t.pool,i=t.liquidity,o=t.tickLower,u=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,o<u||r(!1),o>=j.MIN_TICK&&o%e.tickSpacing==0||r(!1),u<=j.MAX_TICK&&u%e.tickSpacing==0||r(!1),this.pool=e,this.tickLower=o,this.tickUpper=u,this.liquidity=n.BigInt(i)}return t.prototype.minimumAmounts=function(n){var r=this.pool.token0Price.raw.multiply(new e.Percent(1).subtract(n)),i=this.pool.token0Price.raw.multiply(n.add(1)),o=Z(r.numerator,r.denominator),u=Z(i.numerator,i.denominator),a=new it(this.pool.token0,this.pool.token1,this.pool.fee,o,0,j.getTickAtSqrtRatio(o)),c=new t({pool:new it(this.pool.token0,this.pool.token1,this.pool.fee,u,0,j.getTickAtSqrtRatio(u)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,s=new t({pool:a,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:c.raw,amount1:s.raw}},t.fromAmounts=function(e){var n=e.pool,r=e.tickLower,i=e.tickUpper,o=e.amount0,u=e.amount1,a=j.getSqrtRatioAtTick(r),c=j.getSqrtRatioAtTick(i);return new t({pool:n,tickLower:r,tickUpper:i,liquidity:V(n.sqrtRatioX96,a,c,o,u)})},t.fromAmount0=function(n){return t.fromAmounts({pool:n.pool,tickLower:n.tickLower,tickUpper:n.tickUpper,amount0:n.amount0,amount1:e.MaxUint256})},t.fromAmount1=function(n){return t.fromAmounts({pool:n.pool,tickLower:n.tickLower,tickUpper:n.tickUpper,amount0:e.MaxUint256,amount1:n.amount1})},h(t,[{key:"token0PriceLower",get:function(){return tt(this.pool.token0,this.pool.token1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return tt(this.pool.token0,this.pool.token1,this.tickUpper)}},{key:"amount0",get:function(){return null===this._token0Amount&&(this._token0Amount=new e.CurrencyAmount(this.pool.token0,this.pool.tickCurrent<this.tickLower?F.getAmount0Delta(j.getSqrtRatioAtTick(this.tickLower),j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):this.pool.tickCurrent<this.tickUpper?F.getAmount0Delta(this.pool.sqrtRatioX96,j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):q)),this._token0Amount}},{key:"amount1",get:function(){return null===this._token1Amount&&(this._token1Amount=new e.CurrencyAmount(this.pool.token1,this.pool.tickCurrent<this.tickLower?q:F.getAmount1Delta(j.getSqrtRatioAtTick(this.tickLower),this.pool.tickCurrent<this.tickUpper?this.pool.sqrtRatioX96:j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1))),this._token1Amount}},{key:"mintAmounts",get:function(){return null===this._mintAmounts?this.pool.tickCurrent<this.tickLower?{amount0:F.getAmount0Delta(j.getSqrtRatioAtTick(this.tickLower),j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:q}:this.pool.tickCurrent<this.tickUpper?{amount0:F.getAmount0Delta(this.pool.sqrtRatioX96,j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:F.getAmount1Delta(j.getSqrtRatioAtTick(this.tickLower),this.pool.sqrtRatioX96,this.liquidity,!0)}:{amount0:q,amount1:F.getAmount1Delta(j.getSqrtRatioAtTick(this.tickLower),j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0)}:this._mintAmounts}}]),t}(),ut=function(){function t(t,n,i){this._midPrice=null,t.length>0||r(!1);var o=t[0].chainId;t.every((function(t){return t.chainId===o}))||r(!1);var u=e.WETH9[o],a=n.isToken&&t[0].involvesToken(n),c=n===e.ETHER&&u&&t[0].involvesToken(u);a||c||r(!1);var s=void 0===i,l=(null==i?void 0:i.isToken)&&t[t.length-1].involvesToken(i),p=i===e.ETHER&&u&&t[t.length-1].involvesToken(u);s||l||p||r(!1);for(var d,h=[n.isToken?n:u],f=k(t.entries());!(d=f()).done;){var m=d.value,y=m[1],v=h[m[0]];v.equals(y.token0)||v.equals(y.token1)||r(!1);var g=v.equals(y.token0)?y.token1:y.token0;h.push(g)}this.pools=t,this.tokenPath=h,this.input=n,this.output=null!=i?i:h[h.length-1]}return h(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"inputToken",get:function(){return this.input.isToken?this.input:(this.input!==e.ETHER&&r(!1),e.WETH9[this.chainId])}},{key:"outputToken",get:function(){return this.output.isToken?this.output:(this.output!==e.ETHER&&r(!1),e.WETH9[this.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.inputToken)?{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 e.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function at(t,n){return e.currencyEquals(t.inputAmount.currency,n.inputAmount.currency)||r(!1),e.currencyEquals(t.outputAmount.currency,n.outputAmount.currency)||r(!1),t.outputAmount.equalTo(n.outputAmount)?t.inputAmount.equalTo(n.inputAmount)?t.route.tokenPath.length-n.route.tokenPath.length:t.inputAmount.lessThan(n.inputAmount)?-1:1:t.outputAmount.lessThan(n.outputAmount)?1:-1}function ct(t,n){return t.currency.isToken?t:t.currency.isEther?new e.CurrencyAmount(e.WETH9[n],t.raw):void r(!1)}function st(t,n){return t.isToken?t:t===e.ETHER?e.WETH9[n]:void r(!1)}var lt=function(){function t(t){var n=t.route,i=t.inputAmount,o=t.outputAmount,u=t.tradeType;e.currencyEquals(i.currency,n.input)||r(!1),e.currencyEquals(o.currency,n.output)||r(!1),this.route=n,this.inputAmount=i,this.outputAmount=o,this.tradeType=u}t.exactIn=function(){var n=p(x.mark((function n(r,i){return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",t.fromRoute(r,i,e.TradeType.EXACT_INPUT));case 1:case"end":return n.stop()}}),n)})));return function(t,e){return n.apply(this,arguments)}}(),t.exactOut=function(){var n=p(x.mark((function n(r,i){return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",t.fromRoute(r,i,e.TradeType.EXACT_OUTPUT));case 1:case"end":return n.stop()}}),n)})));return function(t,e){return n.apply(this,arguments)}}(),t.fromRoute=function(){var n=p(x.mark((function n(i,o,u){var a,c,s,l,p,d,h;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(a=new Array(i.tokenPath.length),u!==e.TradeType.EXACT_INPUT){n.next=17;break}e.currencyEquals(o.currency,i.input)||r(!1),a[0]=ct(o,i.chainId),c=0;case 5:if(!(c<i.tokenPath.length-1)){n.next=15;break}return s=i.pools[c],n.next=9,s.getOutputAmount(a[c]);case 9:a[c+1]=n.sent[0];case 12:c++,n.next=5;break;case 15:n.next=30;break;case 17:e.currencyEquals(o.currency,i.output)||r(!1),a[a.length-1]=ct(o,i.chainId),l=i.tokenPath.length-1;case 20:if(!(l>0)){n.next=30;break}return p=i.pools[l-1],n.next=24,p.getInputAmount(a[l]);case 24:a[l-1]=n.sent[0];case 27:l--,n.next=20;break;case 30:return d=u===e.TradeType.EXACT_INPUT?o:i.input===e.ETHER?e.CurrencyAmount.ether(a[0].raw):a[0],h=u===e.TradeType.EXACT_OUTPUT?o:i.output===e.ETHER?e.CurrencyAmount.ether(a[a.length-1].raw):a[a.length-1],n.abrupt("return",new t({route:i,tradeType:u,inputAmount:d,outputAmount:h}));case 33:case"end":return n.stop()}}),n)})));return function(t,e,r){return n.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(e)};var n=t.prototype;return n.minimumAmountOut=function(t){if(t.lessThan(q)&&r(!1),this.tradeType===e.TradeType.EXACT_OUTPUT)return this.outputAmount;var n=new e.Fraction(b).add(t).invert().multiply(this.outputAmount.raw).quotient;return new e.CurrencyAmount(this.outputAmount.currency,n)},n.maximumAmountIn=function(t){if(t.lessThan(q)&&r(!1),this.tradeType===e.TradeType.EXACT_INPUT)return this.inputAmount;var n=new e.Fraction(b).add(t).multiply(this.inputAmount.raw).quotient;return new e.CurrencyAmount(this.inputAmount.currency,n)},n.worstExecutionPrice=function(t){return new e.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).raw,this.minimumAmountOut(t).raw)},t.bestTradeExactIn=function(){var n=p(x.mark((function n(i,o,u,a,c,s,l){var p,d,h,f,m,y,k,v,g,T,A,I;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:h=void 0===(d=(p=void 0===a?{}:a).maxNumResults)?3:d,m=void 0===(f=p.maxHops)?3:f,void 0===c&&(c=[]),void 0===s&&(s=o),void 0===l&&(l=[]),i.length>0||r(!1),m>0||r(!1),s===o||c.length>0||r(!1),void 0===(y=o.currency.isToken?o.currency.chainId:u.isToken?u.chainId:void 0)&&r(!1),k=ct(o,y),v=st(u,y),g=0;case 12:if(!(g<i.length)){n.next=48;break}if(e.currencyEquals((T=i[g]).token0,k.currency)||e.currencyEquals(T.token1,k.currency)){n.next=16;break}return n.abrupt("continue",45);case 16:return A=void 0,n.prev=17,n.next=21,T.getOutputAmount(k);case 21:A=n.sent[0],n.next=30;break;case 25:if(n.prev=25,n.t0=n.catch(17),!n.t0.isInsufficientInputAmountError){n.next=29;break}return n.abrupt("continue",45);case 29:throw n.t0;case 30:if(!A.currency.isToken||!A.currency.equals(v)){n.next=41;break}return n.t1=e.sortedInsert,n.t2=l,n.next=35,t.fromRoute(new ut([].concat(c,[T]),s.currency,u),s,e.TradeType.EXACT_INPUT);case 35:n.t3=n.sent,n.t4=h,n.t5=at,(0,n.t1)(n.t2,n.t3,n.t4,n.t5),n.next=45;break;case 41:if(!(m>1&&i.length>1)){n.next=45;break}return I=i.slice(0,g).concat(i.slice(g+1,i.length)),n.next=45,t.bestTradeExactIn(I,A,u,{maxNumResults:h,maxHops:m-1},[].concat(c,[T]),s,l);case 45:g++,n.next=12;break;case 48:return n.abrupt("return",l);case 49:case"end":return n.stop()}}),n,null,[[17,25]])})));return function(t,e,r,i,o,u,a){return n.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var n=p(x.mark((function n(i,o,u,a,c,s,l){var p,d,h,f,m,y,k,v,g,T,A,I;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:h=void 0===(d=(p=void 0===a?{}:a).maxNumResults)?3:d,m=void 0===(f=p.maxHops)?3:f,void 0===c&&(c=[]),void 0===s&&(s=u),void 0===l&&(l=[]),i.length>0||r(!1),m>0||r(!1),s===u||c.length>0||r(!1),void 0===(y=u.currency.isToken?u.currency.chainId:o.isToken?o.chainId:void 0)&&r(!1),k=ct(u,y),v=st(o,y),g=0;case 12:if(!(g<i.length)){n.next=48;break}if(e.currencyEquals((T=i[g]).token0,k.currency)||e.currencyEquals(T.token1,k.currency)){n.next=16;break}return n.abrupt("continue",45);case 16:return A=void 0,n.prev=17,n.next=21,T.getInputAmount(k);case 21:A=n.sent[0],n.next=30;break;case 25:if(n.prev=25,n.t0=n.catch(17),!n.t0.isInsufficientReservesError){n.next=29;break}return n.abrupt("continue",45);case 29:throw n.t0;case 30:if(!e.currencyEquals(A.currency,v)){n.next=41;break}return n.t1=e.sortedInsert,n.t2=l,n.next=35,t.fromRoute(new ut([T].concat(c),o,s.currency),s,e.TradeType.EXACT_OUTPUT);case 35:n.t3=n.sent,n.t4=h,n.t5=at,(0,n.t1)(n.t2,n.t3,n.t4,n.t5),n.next=45;break;case 41:if(!(m>1&&i.length>1)){n.next=45;break}return I=i.slice(0,g).concat(i.slice(g+1,i.length)),n.next=45,t.bestTradeExactOut(I,o,A,{maxNumResults:h,maxHops:m-1},[T].concat(c),s,l);case 45:g++,n.next=12;break;case 48:return n.abrupt("return",l);case 49:case"end":return n.stop()}}),n,null,[[17,25]])})));return function(t,e,r,i,o,u,a){return n.apply(this,arguments)}}(),h(t,[{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new e.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw)}}]),t}(),pt=function(){function t(){}return t.encodePermit=function(e,n){return"nonce"in n?t.INTERFACE.encodeFunctionData("selfPermitAllowed",[e.address,Q(n.nonce),Q(n.expiry),n.v,n.r,n.s]):t.INTERFACE.encodeFunctionData("selfPermit",[e.address,Q(n.amount),Q(n.deadline),n.v,n.r,n.s])},t}();pt.INTERFACE=new i.Interface(c.abi);var dt=Q(n.subtract(n.exponentiate(n.BigInt(2),n.BigInt(128)),n.BigInt(1)));function ht(t){return Object.keys(t).some((function(t){return"recipient"===t}))}var ft=function(t){function i(){return t.call(this)||this}return m(i,t),i.addCallParameters=function(t,o){n.greaterThan(t.liquidity,q)||r(!1);var u=[],a=t.mintAmounts,c=a.amount0,s=a.amount1,l=t.minimumAmounts(o.slippageTolerance),p=Q(l.amount0),d=Q(l.amount1),h=Q(o.deadline);if(ht(o)&&o.createPool&&u.push(i.INTERFACE.encodeFunctionData("createAndInitializePoolIfNecessary",[t.pool.token0.address,t.pool.token1.address,t.pool.fee,Q(t.pool.sqrtRatioX96)])),o.token0Permit&&u.push(i.encodePermit(t.pool.token0,o.token0Permit)),o.token1Permit&&u.push(i.encodePermit(t.pool.token1,o.token1Permit)),ht(o)){var f=e.validateAndParseAddress(o.recipient);u.push(i.INTERFACE.encodeFunctionData("mint",[{token0:t.pool.token0.address,token1:t.pool.token1.address,fee:t.pool.fee,tickLower:t.tickLower,tickUpper:t.tickUpper,amount0Desired:Q(c),amount1Desired:Q(s),amount0Min:p,amount1Min:d,recipient:f,deadline:h}]))}else u.push(i.INTERFACE.encodeFunctionData("increaseLiquidity",[{tokenId:Q(o.tokenId),amount0Desired:Q(c),amount1Desired:Q(s),amount0Min:p,amount1Min:d,deadline:h}]));var m=Q(0);if(o.useEther){var y=e.WETH9[t.pool.chainId];y&&(t.pool.token0.equals(y)||t.pool.token1.equals(y))||r(!1);var k=t.pool.token0.equals(y)?c:s;n.greaterThan(k,q)&&u.push(i.INTERFACE.encodeFunctionData("refundETH")),m=Q(k)}return{calldata:1===u.length?u[0]:i.INTERFACE.encodeFunctionData("multicall",[u]),value:m}},i.encodeCollect=function(t){var n=[],r=Q(t.tokenId),o=e.currencyEquals(t.expectedCurrencyOwed0.currency,e.ETHER)||e.currencyEquals(t.expectedCurrencyOwed1.currency,e.ETHER),u=e.validateAndParseAddress(t.recipient);if(n.push(i.INTERFACE.encodeFunctionData("collect",[{tokenId:r,recipient:o?A:u,amount0Max:dt,amount1Max:dt}])),o){var a=e.currencyEquals(t.expectedCurrencyOwed0.currency,e.ETHER)?t.expectedCurrencyOwed0.raw:t.expectedCurrencyOwed1.raw,c=e.currencyEquals(t.expectedCurrencyOwed0.currency,e.ETHER)?t.expectedCurrencyOwed1.currency:t.expectedCurrencyOwed0.currency,s=e.currencyEquals(t.expectedCurrencyOwed0.currency,e.ETHER)?t.expectedCurrencyOwed1.raw:t.expectedCurrencyOwed0.raw;n.push(i.INTERFACE.encodeFunctionData("unwrapWETH9",[Q(a),u])),n.push(i.INTERFACE.encodeFunctionData("sweepToken",[c.address,Q(s),u]))}return n},i.collectCallParameters=function(t){var e=i.encodeCollect(t);return{calldata:1===e.length?e[0]:i.INTERFACE.encodeFunctionData("multicall",[e]),value:Q(0)}},i.removeCallParameters=function(t,o){var u=[],a=Q(o.deadline),c=Q(o.tokenId),s=new ot({pool:t.pool,liquidity:o.liquidityPercentage.multiply(t.liquidity).quotient,tickLower:t.tickLower,tickUpper:t.tickUpper});n.greaterThan(s.liquidity,q)||r(!1);var l=t.minimumAmounts(o.slippageTolerance),p=l.amount0,d=l.amount1;o.permit&&u.push(i.INTERFACE.encodeFunctionData("permit",[e.validateAndParseAddress(o.permit.spender),c,Q(o.permit.deadline),o.permit.v,o.permit.r,o.permit.s])),u.push(i.INTERFACE.encodeFunctionData("decreaseLiquidity",[{tokenId:c,liquidity:Q(s.liquidity),amount0Min:Q(p),amount1Min:Q(d),deadline:a}]));var h=o.collectOptions,m=h.expectedCurrencyOwed0,y=h.expectedCurrencyOwed1,k=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)e.indexOf(n=o[r])>=0||(i[n]=t[n]);return i}(h,["expectedCurrencyOwed0","expectedCurrencyOwed1"]);return u.push.apply(u,i.encodeCollect(f({tokenId:o.tokenId,expectedCurrencyOwed0:m.add(e.currencyEquals(m.currency,e.ETHER)?e.CurrencyAmount.ether(p):new e.CurrencyAmount(m.currency,p)),expectedCurrencyOwed1:y.add(e.currencyEquals(y.currency,e.ETHER)?e.CurrencyAmount.ether(d):new e.CurrencyAmount(y.currency,d))},k))),o.liquidityPercentage.equalTo(b)?o.burnToken&&u.push(i.INTERFACE.encodeFunctionData("burn",[c])):!0===o.burnToken&&r(!1),{calldata:i.INTERFACE.encodeFunctionData("multicall",[u]),value:Q(0)}},i}(pt);ft.INTERFACE=new i.Interface(a.abi);var mt=function(t){function n(){return t.call(this)||this}return m(n,t),n.swapCallParameters=function(t,i){var o=[];i.inputTokenPermit&&(t.inputAmount.currency instanceof e.Token||r(!1),o.push(n.encodePermit(t.inputAmount.currency,i.inputTokenPermit)));var u=e.validateAndParseAddress(i.recipient),a=Q(i.deadline),c=Q(t.maximumAmountIn(i.slippageTolerance).raw),s=Q(t.minimumAmountOut(i.slippageTolerance).raw),l=e.currencyEquals(t.inputAmount.currency,e.ETHER)?c:Q(0),p=1===t.route.pools.length,d=e.currencyEquals(t.inputAmount.currency,e.ETHER)&&t.tradeType===e.TradeType.EXACT_OUTPUT,h=e.currencyEquals(t.outputAmount.currency,e.ETHER),f=h||!!i.fee;if(p)if(t.tradeType===e.TradeType.EXACT_INPUT){var m,y={tokenIn:t.route.tokenPath[0].address,tokenOut:t.route.tokenPath[1].address,fee:t.route.pools[0].fee,recipient:f?A:u,deadline:a,amountIn:c,amountOutMinimum:s,sqrtPriceLimitX96:Q(null!=(m=i.sqrtPriceLimitX96)?m:0)};o.push(n.INTERFACE.encodeFunctionData("exactInputSingle",[y]))}else{var k,v={tokenIn:t.route.tokenPath[0].address,tokenOut:t.route.tokenPath[1].address,fee:t.route.pools[0].fee,recipient:f?A:u,deadline:a,amountOut:s,amountInMaximum:c,sqrtPriceLimitX96:Q(null!=(k=i.sqrtPriceLimitX96)?k:0)};o.push(n.INTERFACE.encodeFunctionData("exactOutputSingle",[v]))}else{void 0!==i.sqrtPriceLimitX96&&r(!1);var g=Y(t.route,t.tradeType===e.TradeType.EXACT_OUTPUT);o.push(t.tradeType===e.TradeType.EXACT_INPUT?n.INTERFACE.encodeFunctionData("exactInput",[{path:g,recipient:f?A:u,deadline:a,amountIn:c,amountOutMinimum:s}]):n.INTERFACE.encodeFunctionData("exactOutput",[{path:g,recipient:f?A:u,deadline:a,amountOut:s,amountInMaximum:c}]))}if(d&&o.push(n.INTERFACE.encodeFunctionData("refundETH")),f)if(i.fee){var T=e.validateAndParseAddress(i.fee.recipient),x=Q(i.fee.fee.multiply(1e4).quotient);o.push(h?n.INTERFACE.encodeFunctionData("unwrapWETH9WithFee",[s,u,x,T]):n.INTERFACE.encodeFunctionData("sweepTokenWithFee",[t.route.tokenPath[t.route.tokenPath.length-1].address,s,u,x,T]))}else o.push(n.INTERFACE.encodeFunctionData("unwrapWETH9",[s,u]));return{calldata:1===o.length?o[0]:n.INTERFACE.encodeFunctionData("multicall",[o]),value:l}},n}(pt);mt.INTERFACE=new i.Interface(s.abi),exports.ADDRESS_ZERO=A,exports.FACTORY_ADDRESS="0x1F98431c8aD98523631AE4a59f267346ea31F984",exports.FullMath=S,exports.LiquidityMath=O,exports.NoTickDataProvider=W,exports.NonfungiblePositionManager=ft,exports.POOL_INIT_CODE_HASH=I,exports.Pool=it,exports.Position=ot,exports.Route=ut,exports.SqrtPriceMath=F,exports.SwapRouter=mt,exports.TICK_SPACINGS=w,exports.Tick=et,exports.TickList=z,exports.TickListDataProvider=nt,exports.TickMath=j,exports.Trade=lt,exports.computePoolAddress=C,exports.encodeRouteToPath=Y,exports.encodeSqrtRatioX96=Z,exports.isSorted=K,exports.maxLiquidityForAmounts=V,exports.mostSignificantBit=U,exports.nearestUsableTick=function(t,e){Number.isInteger(t)&&Number.isInteger(e)||r(!1),e>0||r(!1),t>=j.MIN_TICK&&t<=j.MAX_TICK||r(!1);var n=Math.round(t/e)*e;return n<j.MIN_TICK?n+e:n>j.MAX_TICK?n-e:n},exports.priceToClosestTick=function(t){t.baseCurrency.isToken&&t.quoteCurrency.isToken||r(!1);var e=t.baseCurrency.sortsBefore(t.quoteCurrency),n=e?Z(t.raw.numerator,t.raw.denominator):Z(t.raw.denominator,t.raw.numerator),i=j.getTickAtSqrtRatio(n),o=tt(t.baseCurrency,t.quoteCurrency,i+1);return e?t.lessThan(o)||i++:t.greaterThan(o)||i++,i},exports.tickToPrice=tt,exports.toHex=Q,exports.tradeComparator=at;
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@uniswap/sdk-core"),n=t(require("jsbi")),r=t(require("tiny-invariant")),i=require("@ethersproject/abi"),o=require("@ethersproject/address"),u=require("@ethersproject/solidity"),a=require("@uniswap/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json"),c=require("@uniswap/v3-periphery/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json"),s=require("@uniswap/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json");function l(t,e,n,r,i,o,u){try{var a=t[o](u),c=a.value}catch(t){return void n(t)}a.done?e(c):Promise.resolve(c).then(r,i)}function p(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function u(t){l(o,r,i,u,a,"next",t)}function a(t){l(o,r,i,u,a,"throw",t)}u(void 0)}))}}function d(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 h(t,e,n){return e&&d(t.prototype,e),n&&d(t,n),t}function f(){return(f=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 m(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function y(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 k(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return y(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)?y(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.")}return(n=t[Symbol.iterator]()).next.bind(n)}var v,g,T,x=(function(t){var e=function(t){var e=Object.prototype,n=e.hasOwnProperty,r="function"==typeof Symbol?Symbol:{},i=r.iterator||"@@iterator",o=r.asyncIterator||"@@asyncIterator",u=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 i=Object.create((e&&e.prototype instanceof p?e:p).prototype),o=new w(r||[]);return i._invoke=function(t,e,n){var r="suspendedStart";return function(i,o){if("executing"===r)throw new Error("Generator is already running");if("completed"===r){if("throw"===i)throw o;return{value:void 0,done:!0}}for(n.method=i,n.arg=o;;){var u=n.delegate;if(u){var a=T(u,n);if(a){if(a===l)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===l)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(t,n,o),i}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 l={};function p(){}function d(){}function h(){}var f={};f[i]=function(){return this};var m=Object.getPrototypeOf,y=m&&m(m(I([])));y&&y!==e&&n.call(y,i)&&(f=y);var k=h.prototype=p.prototype=Object.create(f);function v(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function g(t,e){var r;this._invoke=function(i,o){function u(){return new e((function(r,u){!function r(i,o,u,a){var c=s(t[i],t,o);if("throw"!==c.type){var l=c.arg,p=l.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,u,a)}),(function(t){r("throw",t,u,a)})):e.resolve(p).then((function(t){l.value=t,u(l)}),(function(t){return r("throw",t,u,a)}))}a(c.arg)}(i,o,r,u)}))}return r=r?r.then(u,u):u()}}function T(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,T(t,e),"throw"===e.method))return l;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return l}var r=s(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,l;var i=r.arg;return i?i.done?(e[t.resultName]=i.value,e.next=t.nextLoc,"return"!==e.method&&(e.method="next",e.arg=void 0),e.delegate=null,l):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,l)}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 A(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function w(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(x,this),this.reset(!0)}function I(t){if(t){var e=t[i];if(e)return e.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var r=-1,o=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 o.next=o}}return{next:q}}function q(){return{value:void 0,done:!0}}return d.prototype=k.constructor=h,h.constructor=d,d.displayName=a(h,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===d||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,h):(t.__proto__=h,a(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},v(g.prototype),g.prototype[o]=function(){return this},t.AsyncIterator=g,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var u=new g(c(e,n,r,i),o);return t.isGeneratorFunction(n)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},v(k),a(k,u,"Generator"),k[i]=function(){return this},k.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,w.prototype={constructor:w,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(A),!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 u.type="throw",u.arg=t,e.next=n,r&&(e.method="next",e.arg=void 0),!!r}for(var i=this.tryEntries.length-1;i>=0;--i){var o=this.tryEntries[i],u=o.completion;if("root"===o.tryLoc)return r("end");if(o.tryLoc<=this.prev){var a=n.call(o,"catchLoc"),c=n.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return r(o.catchLoc,!0);if(this.prev<o.finallyLoc)return r(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return r(o.catchLoc,!0)}else{if(!c)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return r(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var i=this.tryEntries[r];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=t,u.arg=e,o?(this.method="next",this.next=o.finallyLoc,l):this.complete(u)},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),l},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),A(n),l}},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 i=r.arg;A(n)}return i}}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),l}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(T={exports:{}}),T.exports),A="0x0000000000000000000000000000000000000000",w="0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54";(g=exports.FeeAmount||(exports.FeeAmount={}))[g.LOW=500]="LOW",g[g.MEDIUM=3e3]="MEDIUM",g[g.HIGH=1e4]="HIGH";var I=((v={})[exports.FeeAmount.LOW]=10,v[exports.FeeAmount.MEDIUM]=60,v[exports.FeeAmount.HIGH]=200,v),q=n.BigInt(-1),E=n.BigInt(0),b=n.BigInt(1),R=n.exponentiate(n.BigInt(2),n.BigInt(96)),P=n.exponentiate(R,n.BigInt(2));function C(t){var e=t.factoryAddress,n=t.tokenA,r=t.tokenB,a=t.fee,c=n.sortsBefore(r)?[n,r]:[r,n];return o.getCreate2Address(e,u.keccak256(["bytes"],[i.defaultAbiCoder.encode(["address","address","uint24"],[c[0].address,c[1].address,a])]),w)}var S=function(){function t(){}return t.addDelta=function(t,e){return n.lessThan(e,E)?n.subtract(t,n.multiply(e,q)):n.add(t,e)},t}(),O=function(){function t(){}return t.mulDivRoundingUp=function(t,e,r){var i=n.multiply(t,e),o=n.divide(i,r);return n.notEqual(n.remainder(i,r),E)&&(o=n.add(o,b)),o},t}(),N=n.subtract(n.exponentiate(n.BigInt(2),n.BigInt(160)),b);function _(t,r){var i=n.multiply(t,r);return n.bitwiseAnd(i,e.MaxUint256)}var F=function(){function t(){}return t.getAmount0Delta=function(t,e,r,i){if(n.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}var u=n.leftShift(r,n.BigInt(96)),a=n.subtract(e,t);return i?O.mulDivRoundingUp(O.mulDivRoundingUp(u,a,e),b,t):n.divide(n.divide(n.multiply(u,a),e),t)},t.getAmount1Delta=function(t,e,r,i){if(n.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}return i?O.mulDivRoundingUp(r,n.subtract(e,t),R):n.divide(n.multiply(r,n.subtract(e,t)),R)},t.getNextSqrtPriceFromInput=function(t,e,i,o){return n.greaterThan(t,E)||r(!1),n.greaterThan(e,E)||r(!1),o?this.getNextSqrtPriceFromAmount0RoundingUp(t,e,i,!0):this.getNextSqrtPriceFromAmount1RoundingDown(t,e,i,!0)},t.getNextSqrtPriceFromOutput=function(t,e,i,o){return n.greaterThan(t,E)||r(!1),n.greaterThan(e,E)||r(!1),o?this.getNextSqrtPriceFromAmount1RoundingDown(t,e,i,!1):this.getNextSqrtPriceFromAmount0RoundingUp(t,e,i,!1)},t.getNextSqrtPriceFromAmount0RoundingUp=function(t,i,o,u){if(n.equal(o,E))return t;var a=n.leftShift(i,n.BigInt(96));if(u){var c=_(o,t);if(n.equal(n.divide(c,o),t)){var s=(p=n.add(a,c),n.bitwiseAnd(p,e.MaxUint256));if(n.greaterThanOrEqual(s,a))return O.mulDivRoundingUp(a,t,s)}return O.mulDivRoundingUp(a,b,n.add(n.divide(a,t),o))}var l=_(o,t);n.equal(n.divide(l,o),t)||r(!1),n.greaterThan(a,l)||r(!1);var p,d=n.subtract(a,l);return O.mulDivRoundingUp(a,t,d)},t.getNextSqrtPriceFromAmount1RoundingDown=function(t,e,i,o){if(o){var u=n.lessThanOrEqual(i,N)?n.divide(n.leftShift(i,n.BigInt(96)),e):n.divide(n.multiply(i,R),e);return n.add(t,u)}var a=O.mulDivRoundingUp(i,R,e);return n.greaterThan(t,a)||r(!1),n.subtract(t,a)},t}(),L=n.exponentiate(n.BigInt(10),n.BigInt(6)),D=function(){function t(){}return t.computeSwapStep=function(t,e,r,i,o){var u={},a=n.greaterThanOrEqual(t,e),c=n.greaterThanOrEqual(i,E);if(c){var s=n.divide(n.multiply(i,n.subtract(L,n.BigInt(o))),L);u.amountIn=a?F.getAmount0Delta(e,t,r,!0):F.getAmount1Delta(t,e,r,!0),u.sqrtRatioNextX96=n.greaterThanOrEqual(s,u.amountIn)?e:F.getNextSqrtPriceFromInput(t,r,s,a)}else u.amountOut=a?F.getAmount1Delta(e,t,r,!1):F.getAmount0Delta(t,e,r,!1),u.sqrtRatioNextX96=n.greaterThanOrEqual(n.multiply(i,q),u.amountOut)?e:F.getNextSqrtPriceFromOutput(t,r,n.multiply(i,q),a);var l=n.equal(e,u.sqrtRatioNextX96);return a?(u.amountIn=l&&c?u.amountIn:F.getAmount0Delta(u.sqrtRatioNextX96,t,r,!0),u.amountOut=l&&!c?u.amountOut:F.getAmount1Delta(u.sqrtRatioNextX96,t,r,!1)):(u.amountIn=l&&c?u.amountIn:F.getAmount1Delta(t,u.sqrtRatioNextX96,r,!0),u.amountOut=l&&!c?u.amountOut:F.getAmount0Delta(t,u.sqrtRatioNextX96,r,!1)),!c&&n.greaterThan(u.amountOut,n.multiply(i,q))&&(u.amountOut=n.multiply(i,q)),u.feeAmount=c&&n.notEqual(u.sqrtRatioNextX96,e)?n.subtract(i,u.amountIn):O.mulDivRoundingUp(u.amountIn,n.BigInt(o),n.subtract(L,n.BigInt(o))),[u.sqrtRatioNextX96,u.amountIn,u.amountOut,u.feeAmount]},t}(),U=n.BigInt(2),X=[128,64,32,16,8,4,2,1].map((function(t){return[t,n.exponentiate(U,n.BigInt(t))]}));function B(t){n.greaterThan(t,E)||r(!1),n.lessThanOrEqual(t,e.MaxUint256)||r(!1);for(var i,o=0,u=k(X);!(i=u()).done;){var a=i.value,c=a[0];n.greaterThanOrEqual(t,a[1])&&(t=n.signedRightShift(t,n.BigInt(c)),o+=c)}return o}function M(t,e){return n.signedRightShift(n.multiply(t,n.BigInt(e)),n.BigInt(128))}var H=n.exponentiate(n.BigInt(2),n.BigInt(32)),j=function(){function t(){}return t.getSqrtRatioAtTick=function(i){i>=t.MIN_TICK&&i<=t.MAX_TICK&&Number.isInteger(i)||r(!1);var o=i<0?-1*i:i,u=n.BigInt(0!=(1&o)?"0xfffcb933bd6fad37aa2d162d1a594001":"0x100000000000000000000000000000000");return 0!=(2&o)&&(u=M(u,"0xfff97272373d413259a46990580e213a")),0!=(4&o)&&(u=M(u,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&o)&&(u=M(u,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&o)&&(u=M(u,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&o)&&(u=M(u,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&o)&&(u=M(u,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&o)&&(u=M(u,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&o)&&(u=M(u,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&o)&&(u=M(u,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&o)&&(u=M(u,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&o)&&(u=M(u,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&o)&&(u=M(u,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&o)&&(u=M(u,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&o)&&(u=M(u,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&o)&&(u=M(u,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&o)&&(u=M(u,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&o)&&(u=M(u,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&o)&&(u=M(u,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&o)&&(u=M(u,"0x48a170391f7dc42444e8fa2")),i>0&&(u=n.divide(e.MaxUint256,u)),n.greaterThan(n.remainder(u,H),E)?n.add(n.divide(u,H),b):n.divide(u,H)},t.getTickAtSqrtRatio=function(e){n.greaterThanOrEqual(e,t.MIN_SQRT_RATIO)&&n.lessThan(e,t.MAX_SQRT_RATIO)||r(!1);var i,o=n.leftShift(e,n.BigInt(32)),u=B(o);i=n.greaterThanOrEqual(n.BigInt(u),n.BigInt(128))?n.signedRightShift(o,n.BigInt(u-127)):n.leftShift(o,n.BigInt(127-u));for(var a=n.leftShift(n.subtract(n.BigInt(u),n.BigInt(128)),n.BigInt(64)),c=0;c<14;c++){i=n.signedRightShift(n.multiply(i,i),n.BigInt(127));var s=n.signedRightShift(i,n.BigInt(128));a=n.bitwiseOr(a,n.leftShift(s,n.BigInt(63-c))),i=n.signedRightShift(i,s)}var l=n.multiply(a,n.BigInt("255738958999603826347141")),p=n.toNumber(n.signedRightShift(n.subtract(l,n.BigInt("3402992956809132418596140100660247210")),n.BigInt(128))),d=n.toNumber(n.signedRightShift(n.add(l,n.BigInt("291339464771989622907027621153398088495")),n.BigInt(128)));return p===d?p:n.lessThanOrEqual(t.getSqrtRatioAtTick(d),e)?d:p},t}();j.MIN_TICK=-887272,j.MAX_TICK=-j.MIN_TICK,j.MIN_SQRT_RATIO=n.BigInt("4295128739"),j.MAX_SQRT_RATIO=n.BigInt("1461446703485210103287273052203988822378723970342");var W=function(){function t(){}var e=t.prototype;return e.getTick=function(){var e=p(x.mark((function e(n){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error(t.ERROR_MESSAGE);case 1:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}(),e.nextInitializedTickWithinOneWord=function(){var e=p(x.mark((function e(n,r,i){return x.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:throw new Error(t.ERROR_MESSAGE);case 1:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t}();function K(t,e){for(var n=0;n<t.length-1;n++)if(e(t[n],t[n+1])>0)return!1;return!0}function G(t,e){return t.index-e.index}W.ERROR_MESSAGE="No tick data provider was given";var z=function(){function t(){}return t.validateList=function(t,e){e>0||r(!1),t.every((function(t){return t.index%e==0}))||r(!1),n.equal(t.reduce((function(t,e){return n.add(t,e.liquidityNet)}),E),E)||r(!1),K(t,G)||r(!1)},t.isBelowSmallest=function(t,e){return t.length>0||r(!1),e<t[0].index},t.isAtOrAboveLargest=function(t,e){return t.length>0||r(!1),e>=t[t.length-1].index},t.getTick=function(t,e){var n=t[this.binarySearch(t,e)];return n.index!==e&&r(!1),n},t.binarySearch=function(t,e){this.isBelowSmallest(t,e)&&r(!1);for(var n,i=0,o=t.length-1;;){if(t[n=Math.floor((i+o)/2)].index<=e&&(n===t.length-1||t[n+1].index>e))return n;t[n].index<e?i=n+1:o=n-1}},t.nextInitializedTick=function(e,n,i){return i?(t.isBelowSmallest(e,n)&&r(!1),t.isAtOrAboveLargest(e,n)?e[e.length-1]:e[this.binarySearch(e,n)]):(this.isAtOrAboveLargest(e,n)&&r(!1),this.isBelowSmallest(e,n)?e[0]:e[this.binarySearch(e,n)+1])},t.nextInitializedTickWithinOneWord=function(e,n,r,i){var o=Math.floor(n/i);if(r){var u=(o>>8<<8)*i;if(t.isBelowSmallest(e,n))return[u,!1];var a=t.nextInitializedTick(e,n,r).index,c=Math.max(u,a);return[c,c===a]}var s=(1+(o+1>>8)<<8)*i-1;if(this.isAtOrAboveLargest(e,n))return[s,!1];var l=this.nextInitializedTick(e,n,r).index,p=Math.min(s,l);return[p,p===l]},t}();function Q(t){var e=n.BigInt(t).toString(16);return e.length%2!=0&&(e="0"+e),"0x"+e}function Y(t,n){var r=t.input.isToken?t.input:t.input.isEther?e.WETH9[t.chainId]:void 0;if(!r)throw new Error("Could not wrap input currency");var i=t.pools.reduce((function(t,e,n){var r=t.inputToken,i=t.path,o=t.types,u=e.token0.equals(r)?e.token1:e.token0;return 0===n?{inputToken:u,types:["address","uint24","address"],path:[r.address,e.fee,u.address]}:{inputToken:u,types:[].concat(o,["uint24","address"]),path:[].concat(i,[e.fee,u.address])}}),{inputToken:r,path:[],types:[]}),o=i.path,a=i.types;return n?u.pack(a.reverse(),o.reverse()):u.pack(a,o)}function Z(t,r){var i=n.leftShift(n.BigInt(t),n.BigInt(192)),o=n.BigInt(r),u=n.divide(i,o);return e.sqrt(u)}function $(t,e,r){if(n.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=n.divide(n.multiply(t,e),R);return n.divide(n.multiply(n.BigInt(r),o),n.subtract(e,t))}function J(t,e,r){if(n.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}return n.divide(n.multiply(n.BigInt(r),R),n.subtract(e,t))}function V(t,e,r,i,o){if(n.greaterThan(e,r)){var u=[r,e];e=u[0],r=u[1]}if(n.lessThanOrEqual(t,e))return $(e,r,i);if(n.lessThan(t,r)){var a=$(t,r,i),c=J(e,t,o);return n.lessThan(a,c)?a:c}return J(e,r,o)}function tt(t,r,i){var o=j.getSqrtRatioAtTick(i),u=n.multiply(o,o);return t.sortsBefore(r)?new e.Price(t,r,P,u):new e.Price(t,r,u,P)}var et=function(t){var e=t.index,i=t.liquidityGross,o=t.liquidityNet;e>=j.MIN_TICK&&e<=j.MAX_TICK||r(!1),this.index=e,this.liquidityGross=n.BigInt(i),this.liquidityNet=n.BigInt(o)},nt=function(){function t(t,e){var n=t.map((function(t){return t instanceof et?t:new et(t)}));z.validateList(n,e),this.ticks=n}var e=t.prototype;return e.getTick=function(){var t=p(x.mark((function t(e){return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",z.getTick(this.ticks,e));case 1:case"end":return t.stop()}}),t,this)})));return function(e){return t.apply(this,arguments)}}(),e.nextInitializedTickWithinOneWord=function(){var t=p(x.mark((function t(e,n,r){return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",z.nextInitializedTickWithinOneWord(this.ticks,e,n,r));case 1:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),t}(),rt=new W,it=function(){function t(t,e,i,o,u,a,c){void 0===c&&(c=rt),Number.isInteger(i)&&i<1e6||r(!1);var s=j.getSqrtRatioAtTick(a),l=j.getSqrtRatioAtTick(a+1);n.greaterThanOrEqual(n.BigInt(o),s)&&n.lessThanOrEqual(n.BigInt(o),l)||r(!1);var p=t.sortsBefore(e)?[t,e]:[e,t];this.token0=p[0],this.token1=p[1],this.fee=i,this.sqrtRatioX96=n.BigInt(o),this.liquidity=n.BigInt(u),this.tickCurrent=a,this.tickDataProvider=Array.isArray(c)?new nt(c,I[i]):c}t.getAddress=function(t,e,n){return C({factoryAddress:"0x1F98431c8aD98523631AE4a59f267346ea31F984",fee:n,tokenA:t,tokenB:e})};var i=t.prototype;return i.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},i.priceOf=function(t){return this.involvesToken(t)||r(!1),t.equals(this.token0)?this.token0Price:this.token1Price},i.getOutputAmount=function(){var i=p(x.mark((function i(o){var u,a,c,s,l;return x.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return o.currency.isToken&&this.involvesToken(o.currency)||r(!1),u=o.currency.equals(this.token0),i.next=4,this.swap(u,o.raw);case 4:return c=(a=i.sent).sqrtRatioX96,s=a.liquidity,l=a.tickCurrent,i.abrupt("return",[new e.CurrencyAmount(u?this.token1:this.token0,n.multiply(a.amountCalculated,q)),new t(this.token0,this.token1,this.fee,c,s,l,this.tickDataProvider)]);case 11:case"end":return i.stop()}}),i,this)})));return function(t){return i.apply(this,arguments)}}(),i.getInputAmount=function(){var i=p(x.mark((function i(o){var u,a,c,s,l;return x.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return o.currency.isToken&&this.involvesToken(o.currency)||r(!1),u=o.currency.equals(this.token1),i.next=4,this.swap(u,n.multiply(o.raw,q));case 4:return c=(a=i.sent).sqrtRatioX96,s=a.liquidity,l=a.tickCurrent,i.abrupt("return",[new e.CurrencyAmount(u?this.token0:this.token1,a.amountCalculated),new t(this.token0,this.token1,this.fee,c,s,l,this.tickDataProvider)]);case 11:case"end":return i.stop()}}),i,this)})));return function(t){return i.apply(this,arguments)}}(),i.swap=function(){var t=p(x.mark((function t(e,i,o){var u,a,c,s,l,p;return x.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o||(o=e?n.add(j.MIN_SQRT_RATIO,b):n.subtract(j.MAX_SQRT_RATIO,b)),e?(n.greaterThan(o,j.MIN_SQRT_RATIO)||r(!1),n.lessThan(o,this.sqrtRatioX96)||r(!1)):(n.lessThan(o,j.MAX_SQRT_RATIO)||r(!1),n.greaterThan(o,this.sqrtRatioX96)||r(!1)),u=n.greaterThanOrEqual(i,E),a={amountSpecifiedRemaining:i,amountCalculated:E,sqrtPriceX96:this.sqrtRatioX96,tick:this.tickCurrent,liquidity:this.liquidity};case 4:if(!n.notEqual(a.amountSpecifiedRemaining,E)||a.sqrtPriceX96==o){t.next=35;break}return(c={}).sqrtPriceStartX96=a.sqrtPriceX96,t.next=9,this.tickDataProvider.nextInitializedTickWithinOneWord(a.tick,e,this.tickSpacing);case 9:if(c.tickNext=(s=t.sent)[0],c.initialized=s[1],c.tickNext<j.MIN_TICK?c.tickNext=j.MIN_TICK:c.tickNext>j.MAX_TICK&&(c.tickNext=j.MAX_TICK),c.sqrtPriceNextX96=j.getSqrtRatioAtTick(c.tickNext),l=D.computeSwapStep(a.sqrtPriceX96,(e?n.lessThan(c.sqrtPriceNextX96,o):n.greaterThan(c.sqrtPriceNextX96,o))?o:c.sqrtPriceNextX96,a.liquidity,a.amountSpecifiedRemaining,this.fee),a.sqrtPriceX96=l[0],c.amountIn=l[1],c.amountOut=l[2],c.feeAmount=l[3],u?(a.amountSpecifiedRemaining=n.subtract(a.amountSpecifiedRemaining,n.add(c.amountIn,c.feeAmount)),a.amountCalculated=n.subtract(a.amountCalculated,c.amountOut)):(a.amountSpecifiedRemaining=n.add(a.amountSpecifiedRemaining,c.amountOut),a.amountCalculated=n.add(a.amountCalculated,n.add(c.amountIn,c.feeAmount))),!n.equal(a.sqrtPriceX96,c.sqrtPriceNextX96)){t.next=32;break}if(!c.initialized){t.next=29;break}return t.t0=n,t.next=25,this.tickDataProvider.getTick(c.tickNext);case 25:t.t1=t.sent.liquidityNet,p=t.t0.BigInt.call(t.t0,t.t1),e&&(p=n.multiply(p,q)),a.liquidity=S.addDelta(a.liquidity,p);case 29:a.tick=e?c.tickNext-1:c.tickNext,t.next=33;break;case 32:a.sqrtPriceX96!=c.sqrtPriceStartX96&&(a.tick=j.getTickAtSqrtRatio(a.sqrtPriceX96));case 33:t.next=4;break;case 35:return t.abrupt("return",{amountCalculated:a.amountCalculated,sqrtRatioX96:a.sqrtPriceX96,liquidity:a.liquidity,tickCurrent:a.tick});case 36:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),h(t,[{key:"token0Price",get:function(){var t;return null!=(t=this._token0Price)?t:this._token0Price=new e.Price(this.token0,this.token1,P,n.multiply(this.sqrtRatioX96,this.sqrtRatioX96))}},{key:"token1Price",get:function(){var t;return null!=(t=this._token1Price)?t:this._token1Price=new e.Price(this.token1,this.token0,n.multiply(this.sqrtRatioX96,this.sqrtRatioX96),P)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"tickSpacing",get:function(){return I[this.fee]}}]),t}(),ot=function(){function t(t){var e=t.pool,i=t.liquidity,o=t.tickLower,u=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,o<u||r(!1),o>=j.MIN_TICK&&o%e.tickSpacing==0||r(!1),u<=j.MAX_TICK&&u%e.tickSpacing==0||r(!1),this.pool=e,this.tickLower=o,this.tickUpper=u,this.liquidity=n.BigInt(i)}var i=t.prototype;return i.mintAmountsWithSlippage=function(n){var r=this.pool.token0Price.raw.multiply(new e.Percent(1).subtract(n)),i=this.pool.token0Price.raw.multiply(n.add(1)),o=Z(r.numerator,r.denominator),u=Z(i.numerator,i.denominator),a=new it(this.pool.token0,this.pool.token1,this.pool.fee,o,0,j.getTickAtSqrtRatio(o));return{amount0:new t({pool:new it(this.pool.token0,this.pool.token1,this.pool.fee,u,0,j.getTickAtSqrtRatio(u)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:new t({pool:a,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount1}},i.burnAmountsWithSlippage=function(n){var r=this.pool.token0Price.raw.multiply(new e.Percent(1).subtract(n)),i=this.pool.token0Price.raw.multiply(n.add(1)),o=Z(r.numerator,r.denominator),u=Z(i.numerator,i.denominator),a=new it(this.pool.token0,this.pool.token1,this.pool.fee,o,0,j.getTickAtSqrtRatio(o)),c=new t({pool:new it(this.pool.token0,this.pool.token1,this.pool.fee,u,0,j.getTickAtSqrtRatio(u)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,s=new t({pool:a,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:c.raw,amount1:s.raw}},t.fromAmounts=function(e){var n=e.pool,r=e.tickLower,i=e.tickUpper,o=e.amount0,u=e.amount1,a=j.getSqrtRatioAtTick(r),c=j.getSqrtRatioAtTick(i);return new t({pool:n,tickLower:r,tickUpper:i,liquidity:V(n.sqrtRatioX96,a,c,o,u)})},t.fromAmount0=function(n){return t.fromAmounts({pool:n.pool,tickLower:n.tickLower,tickUpper:n.tickUpper,amount0:n.amount0,amount1:e.MaxUint256})},t.fromAmount1=function(n){return t.fromAmounts({pool:n.pool,tickLower:n.tickLower,tickUpper:n.tickUpper,amount0:e.MaxUint256,amount1:n.amount1})},h(t,[{key:"token0PriceLower",get:function(){return tt(this.pool.token0,this.pool.token1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return tt(this.pool.token0,this.pool.token1,this.tickUpper)}},{key:"amount0",get:function(){return null===this._token0Amount&&(this._token0Amount=new e.CurrencyAmount(this.pool.token0,this.pool.tickCurrent<this.tickLower?F.getAmount0Delta(j.getSqrtRatioAtTick(this.tickLower),j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):this.pool.tickCurrent<this.tickUpper?F.getAmount0Delta(this.pool.sqrtRatioX96,j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):E)),this._token0Amount}},{key:"amount1",get:function(){return null===this._token1Amount&&(this._token1Amount=new e.CurrencyAmount(this.pool.token1,this.pool.tickCurrent<this.tickLower?E:F.getAmount1Delta(j.getSqrtRatioAtTick(this.tickLower),this.pool.tickCurrent<this.tickUpper?this.pool.sqrtRatioX96:j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1))),this._token1Amount}},{key:"mintAmounts",get:function(){return null===this._mintAmounts?this.pool.tickCurrent<this.tickLower?{amount0:F.getAmount0Delta(j.getSqrtRatioAtTick(this.tickLower),j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:E}:this.pool.tickCurrent<this.tickUpper?{amount0:F.getAmount0Delta(this.pool.sqrtRatioX96,j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:F.getAmount1Delta(j.getSqrtRatioAtTick(this.tickLower),this.pool.sqrtRatioX96,this.liquidity,!0)}:{amount0:E,amount1:F.getAmount1Delta(j.getSqrtRatioAtTick(this.tickLower),j.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0)}:this._mintAmounts}}]),t}(),ut=function(){function t(t,n,i){this._midPrice=null,t.length>0||r(!1);var o=t[0].chainId;t.every((function(t){return t.chainId===o}))||r(!1);var u=e.WETH9[o],a=n.isToken&&t[0].involvesToken(n),c=n===e.ETHER&&u&&t[0].involvesToken(u);a||c||r(!1);var s=void 0===i,l=(null==i?void 0:i.isToken)&&t[t.length-1].involvesToken(i),p=i===e.ETHER&&u&&t[t.length-1].involvesToken(u);s||l||p||r(!1);for(var d,h=[n.isToken?n:u],f=k(t.entries());!(d=f()).done;){var m=d.value,y=m[1],v=h[m[0]];v.equals(y.token0)||v.equals(y.token1)||r(!1);var g=v.equals(y.token0)?y.token1:y.token0;h.push(g)}this.pools=t,this.tokenPath=h,this.input=n,this.output=null!=i?i:h[h.length-1]}return h(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"inputToken",get:function(){return this.input.isToken?this.input:(this.input!==e.ETHER&&r(!1),e.WETH9[this.chainId])}},{key:"outputToken",get:function(){return this.output.isToken?this.output:(this.output!==e.ETHER&&r(!1),e.WETH9[this.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.inputToken)?{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 e.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function at(t,n){return e.currencyEquals(t.inputAmount.currency,n.inputAmount.currency)||r(!1),e.currencyEquals(t.outputAmount.currency,n.outputAmount.currency)||r(!1),t.outputAmount.equalTo(n.outputAmount)?t.inputAmount.equalTo(n.inputAmount)?t.route.tokenPath.length-n.route.tokenPath.length:t.inputAmount.lessThan(n.inputAmount)?-1:1:t.outputAmount.lessThan(n.outputAmount)?1:-1}function ct(t,n){return t.currency.isToken?t:t.currency.isEther?new e.CurrencyAmount(e.WETH9[n],t.raw):void r(!1)}function st(t,n){return t.isToken?t:t===e.ETHER?e.WETH9[n]:void r(!1)}var lt=function(){function t(t){var n=t.route,i=t.inputAmount,o=t.outputAmount,u=t.tradeType;e.currencyEquals(i.currency,n.input)||r(!1),e.currencyEquals(o.currency,n.output)||r(!1),this.route=n,this.inputAmount=i,this.outputAmount=o,this.tradeType=u}t.exactIn=function(){var n=p(x.mark((function n(r,i){return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",t.fromRoute(r,i,e.TradeType.EXACT_INPUT));case 1:case"end":return n.stop()}}),n)})));return function(t,e){return n.apply(this,arguments)}}(),t.exactOut=function(){var n=p(x.mark((function n(r,i){return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:return n.abrupt("return",t.fromRoute(r,i,e.TradeType.EXACT_OUTPUT));case 1:case"end":return n.stop()}}),n)})));return function(t,e){return n.apply(this,arguments)}}(),t.fromRoute=function(){var n=p(x.mark((function n(i,o,u){var a,c,s,l,p,d,h;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:if(a=new Array(i.tokenPath.length),u!==e.TradeType.EXACT_INPUT){n.next=17;break}e.currencyEquals(o.currency,i.input)||r(!1),a[0]=ct(o,i.chainId),c=0;case 5:if(!(c<i.tokenPath.length-1)){n.next=15;break}return s=i.pools[c],n.next=9,s.getOutputAmount(a[c]);case 9:a[c+1]=n.sent[0];case 12:c++,n.next=5;break;case 15:n.next=30;break;case 17:e.currencyEquals(o.currency,i.output)||r(!1),a[a.length-1]=ct(o,i.chainId),l=i.tokenPath.length-1;case 20:if(!(l>0)){n.next=30;break}return p=i.pools[l-1],n.next=24,p.getInputAmount(a[l]);case 24:a[l-1]=n.sent[0];case 27:l--,n.next=20;break;case 30:return d=u===e.TradeType.EXACT_INPUT?o:i.input===e.ETHER?e.CurrencyAmount.ether(a[0].raw):a[0],h=u===e.TradeType.EXACT_OUTPUT?o:i.output===e.ETHER?e.CurrencyAmount.ether(a[a.length-1].raw):a[a.length-1],n.abrupt("return",new t({route:i,tradeType:u,inputAmount:d,outputAmount:h}));case 33:case"end":return n.stop()}}),n)})));return function(t,e,r){return n.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(e)};var n=t.prototype;return n.minimumAmountOut=function(t){if(t.lessThan(E)&&r(!1),this.tradeType===e.TradeType.EXACT_OUTPUT)return this.outputAmount;var n=new e.Fraction(b).add(t).invert().multiply(this.outputAmount.raw).quotient;return new e.CurrencyAmount(this.outputAmount.currency,n)},n.maximumAmountIn=function(t){if(t.lessThan(E)&&r(!1),this.tradeType===e.TradeType.EXACT_INPUT)return this.inputAmount;var n=new e.Fraction(b).add(t).multiply(this.inputAmount.raw).quotient;return new e.CurrencyAmount(this.inputAmount.currency,n)},n.worstExecutionPrice=function(t){return new e.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).raw,this.minimumAmountOut(t).raw)},t.bestTradeExactIn=function(){var n=p(x.mark((function n(i,o,u,a,c,s,l){var p,d,h,f,m,y,k,v,g,T,A,w;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:h=void 0===(d=(p=void 0===a?{}:a).maxNumResults)?3:d,m=void 0===(f=p.maxHops)?3:f,void 0===c&&(c=[]),void 0===s&&(s=o),void 0===l&&(l=[]),i.length>0||r(!1),m>0||r(!1),s===o||c.length>0||r(!1),void 0===(y=o.currency.isToken?o.currency.chainId:u.isToken?u.chainId:void 0)&&r(!1),k=ct(o,y),v=st(u,y),g=0;case 12:if(!(g<i.length)){n.next=48;break}if(e.currencyEquals((T=i[g]).token0,k.currency)||e.currencyEquals(T.token1,k.currency)){n.next=16;break}return n.abrupt("continue",45);case 16:return A=void 0,n.prev=17,n.next=21,T.getOutputAmount(k);case 21:A=n.sent[0],n.next=30;break;case 25:if(n.prev=25,n.t0=n.catch(17),!n.t0.isInsufficientInputAmountError){n.next=29;break}return n.abrupt("continue",45);case 29:throw n.t0;case 30:if(!A.currency.isToken||!A.currency.equals(v)){n.next=41;break}return n.t1=e.sortedInsert,n.t2=l,n.next=35,t.fromRoute(new ut([].concat(c,[T]),s.currency,u),s,e.TradeType.EXACT_INPUT);case 35:n.t3=n.sent,n.t4=h,n.t5=at,(0,n.t1)(n.t2,n.t3,n.t4,n.t5),n.next=45;break;case 41:if(!(m>1&&i.length>1)){n.next=45;break}return w=i.slice(0,g).concat(i.slice(g+1,i.length)),n.next=45,t.bestTradeExactIn(w,A,u,{maxNumResults:h,maxHops:m-1},[].concat(c,[T]),s,l);case 45:g++,n.next=12;break;case 48:return n.abrupt("return",l);case 49:case"end":return n.stop()}}),n,null,[[17,25]])})));return function(t,e,r,i,o,u,a){return n.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var n=p(x.mark((function n(i,o,u,a,c,s,l){var p,d,h,f,m,y,k,v,g,T,A,w;return x.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:h=void 0===(d=(p=void 0===a?{}:a).maxNumResults)?3:d,m=void 0===(f=p.maxHops)?3:f,void 0===c&&(c=[]),void 0===s&&(s=u),void 0===l&&(l=[]),i.length>0||r(!1),m>0||r(!1),s===u||c.length>0||r(!1),void 0===(y=u.currency.isToken?u.currency.chainId:o.isToken?o.chainId:void 0)&&r(!1),k=ct(u,y),v=st(o,y),g=0;case 12:if(!(g<i.length)){n.next=48;break}if(e.currencyEquals((T=i[g]).token0,k.currency)||e.currencyEquals(T.token1,k.currency)){n.next=16;break}return n.abrupt("continue",45);case 16:return A=void 0,n.prev=17,n.next=21,T.getInputAmount(k);case 21:A=n.sent[0],n.next=30;break;case 25:if(n.prev=25,n.t0=n.catch(17),!n.t0.isInsufficientReservesError){n.next=29;break}return n.abrupt("continue",45);case 29:throw n.t0;case 30:if(!e.currencyEquals(A.currency,v)){n.next=41;break}return n.t1=e.sortedInsert,n.t2=l,n.next=35,t.fromRoute(new ut([T].concat(c),o,s.currency),s,e.TradeType.EXACT_OUTPUT);case 35:n.t3=n.sent,n.t4=h,n.t5=at,(0,n.t1)(n.t2,n.t3,n.t4,n.t5),n.next=45;break;case 41:if(!(m>1&&i.length>1)){n.next=45;break}return w=i.slice(0,g).concat(i.slice(g+1,i.length)),n.next=45,t.bestTradeExactOut(w,o,A,{maxNumResults:h,maxHops:m-1},[T].concat(c),s,l);case 45:g++,n.next=12;break;case 48:return n.abrupt("return",l);case 49:case"end":return n.stop()}}),n,null,[[17,25]])})));return function(t,e,r,i,o,u,a){return n.apply(this,arguments)}}(),h(t,[{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new e.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw)}}]),t}(),pt=function(){function t(){}return t.encodePermit=function(e,n){return"nonce"in n?t.INTERFACE.encodeFunctionData("selfPermitAllowed",[e.address,Q(n.nonce),Q(n.expiry),n.v,n.r,n.s]):t.INTERFACE.encodeFunctionData("selfPermit",[e.address,Q(n.amount),Q(n.deadline),n.v,n.r,n.s])},t}();pt.INTERFACE=new i.Interface(c.abi);var dt=Q(n.subtract(n.exponentiate(n.BigInt(2),n.BigInt(128)),n.BigInt(1)));function ht(t){return Object.keys(t).some((function(t){return"recipient"===t}))}var ft=function(t){function i(){return t.call(this)||this}return m(i,t),i.addCallParameters=function(t,o){n.greaterThan(t.liquidity,E)||r(!1);var u=[],a=t.mintAmounts,c=a.amount0,s=a.amount1,l=t.mintAmountsWithSlippage(o.slippageTolerance),p=Q(l.amount0),d=Q(l.amount1),h=Q(o.deadline);if(ht(o)&&o.createPool&&u.push(i.INTERFACE.encodeFunctionData("createAndInitializePoolIfNecessary",[t.pool.token0.address,t.pool.token1.address,t.pool.fee,Q(t.pool.sqrtRatioX96)])),o.token0Permit&&u.push(i.encodePermit(t.pool.token0,o.token0Permit)),o.token1Permit&&u.push(i.encodePermit(t.pool.token1,o.token1Permit)),ht(o)){var f=e.validateAndParseAddress(o.recipient);u.push(i.INTERFACE.encodeFunctionData("mint",[{token0:t.pool.token0.address,token1:t.pool.token1.address,fee:t.pool.fee,tickLower:t.tickLower,tickUpper:t.tickUpper,amount0Desired:Q(c),amount1Desired:Q(s),amount0Min:p,amount1Min:d,recipient:f,deadline:h}]))}else u.push(i.INTERFACE.encodeFunctionData("increaseLiquidity",[{tokenId:Q(o.tokenId),amount0Desired:Q(c),amount1Desired:Q(s),amount0Min:p,amount1Min:d,deadline:h}]));var m=Q(0);if(o.useEther){var y=e.WETH9[t.pool.chainId];y&&(t.pool.token0.equals(y)||t.pool.token1.equals(y))||r(!1);var k=t.pool.token0.equals(y)?c:s;n.greaterThan(k,E)&&u.push(i.INTERFACE.encodeFunctionData("refundETH")),m=Q(k)}return{calldata:1===u.length?u[0]:i.INTERFACE.encodeFunctionData("multicall",[u]),value:m}},i.encodeCollect=function(t){var n=[],r=Q(t.tokenId),o=e.currencyEquals(t.expectedCurrencyOwed0.currency,e.ETHER)||e.currencyEquals(t.expectedCurrencyOwed1.currency,e.ETHER),u=e.validateAndParseAddress(t.recipient);if(n.push(i.INTERFACE.encodeFunctionData("collect",[{tokenId:r,recipient:o?A:u,amount0Max:dt,amount1Max:dt}])),o){var a=e.currencyEquals(t.expectedCurrencyOwed0.currency,e.ETHER)?t.expectedCurrencyOwed0.raw:t.expectedCurrencyOwed1.raw,c=e.currencyEquals(t.expectedCurrencyOwed0.currency,e.ETHER)?t.expectedCurrencyOwed1.currency:t.expectedCurrencyOwed0.currency,s=e.currencyEquals(t.expectedCurrencyOwed0.currency,e.ETHER)?t.expectedCurrencyOwed1.raw:t.expectedCurrencyOwed0.raw;n.push(i.INTERFACE.encodeFunctionData("unwrapWETH9",[Q(a),u])),n.push(i.INTERFACE.encodeFunctionData("sweepToken",[c.address,Q(s),u]))}return n},i.collectCallParameters=function(t){var e=i.encodeCollect(t);return{calldata:1===e.length?e[0]:i.INTERFACE.encodeFunctionData("multicall",[e]),value:Q(0)}},i.removeCallParameters=function(t,o){var u=[],a=Q(o.deadline),c=Q(o.tokenId),s=new ot({pool:t.pool,liquidity:o.liquidityPercentage.multiply(t.liquidity).quotient,tickLower:t.tickLower,tickUpper:t.tickUpper});n.greaterThan(s.liquidity,E)||r(!1);var l=s.burnAmountsWithSlippage(o.slippageTolerance),p=l.amount0,d=l.amount1;o.permit&&u.push(i.INTERFACE.encodeFunctionData("permit",[e.validateAndParseAddress(o.permit.spender),c,Q(o.permit.deadline),o.permit.v,o.permit.r,o.permit.s])),u.push(i.INTERFACE.encodeFunctionData("decreaseLiquidity",[{tokenId:c,liquidity:Q(s.liquidity),amount0Min:Q(p),amount1Min:Q(d),deadline:a}]));var h=o.collectOptions,m=h.expectedCurrencyOwed0,y=h.expectedCurrencyOwed1,k=function(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)e.indexOf(n=o[r])>=0||(i[n]=t[n]);return i}(h,["expectedCurrencyOwed0","expectedCurrencyOwed1"]);return u.push.apply(u,i.encodeCollect(f({tokenId:o.tokenId,expectedCurrencyOwed0:m.add(e.currencyEquals(m.currency,e.ETHER)?e.CurrencyAmount.ether(p):new e.CurrencyAmount(m.currency,p)),expectedCurrencyOwed1:y.add(e.currencyEquals(y.currency,e.ETHER)?e.CurrencyAmount.ether(d):new e.CurrencyAmount(y.currency,d))},k))),o.liquidityPercentage.equalTo(b)?o.burnToken&&u.push(i.INTERFACE.encodeFunctionData("burn",[c])):!0===o.burnToken&&r(!1),{calldata:i.INTERFACE.encodeFunctionData("multicall",[u]),value:Q(0)}},i}(pt);ft.INTERFACE=new i.Interface(a.abi);var mt=function(t){function n(){return t.call(this)||this}return m(n,t),n.swapCallParameters=function(t,i){var o=[];i.inputTokenPermit&&(t.inputAmount.currency instanceof e.Token||r(!1),o.push(n.encodePermit(t.inputAmount.currency,i.inputTokenPermit)));var u=e.validateAndParseAddress(i.recipient),a=Q(i.deadline),c=Q(t.maximumAmountIn(i.slippageTolerance).raw),s=Q(t.minimumAmountOut(i.slippageTolerance).raw),l=e.currencyEquals(t.inputAmount.currency,e.ETHER)?c:Q(0),p=1===t.route.pools.length,d=e.currencyEquals(t.inputAmount.currency,e.ETHER)&&t.tradeType===e.TradeType.EXACT_OUTPUT,h=e.currencyEquals(t.outputAmount.currency,e.ETHER),f=h||!!i.fee;if(p)if(t.tradeType===e.TradeType.EXACT_INPUT){var m,y={tokenIn:t.route.tokenPath[0].address,tokenOut:t.route.tokenPath[1].address,fee:t.route.pools[0].fee,recipient:f?A:u,deadline:a,amountIn:c,amountOutMinimum:s,sqrtPriceLimitX96:Q(null!=(m=i.sqrtPriceLimitX96)?m:0)};o.push(n.INTERFACE.encodeFunctionData("exactInputSingle",[y]))}else{var k,v={tokenIn:t.route.tokenPath[0].address,tokenOut:t.route.tokenPath[1].address,fee:t.route.pools[0].fee,recipient:f?A:u,deadline:a,amountOut:s,amountInMaximum:c,sqrtPriceLimitX96:Q(null!=(k=i.sqrtPriceLimitX96)?k:0)};o.push(n.INTERFACE.encodeFunctionData("exactOutputSingle",[v]))}else{void 0!==i.sqrtPriceLimitX96&&r(!1);var g=Y(t.route,t.tradeType===e.TradeType.EXACT_OUTPUT);o.push(t.tradeType===e.TradeType.EXACT_INPUT?n.INTERFACE.encodeFunctionData("exactInput",[{path:g,recipient:f?A:u,deadline:a,amountIn:c,amountOutMinimum:s}]):n.INTERFACE.encodeFunctionData("exactOutput",[{path:g,recipient:f?A:u,deadline:a,amountOut:s,amountInMaximum:c}]))}if(d&&o.push(n.INTERFACE.encodeFunctionData("refundETH")),f)if(i.fee){var T=e.validateAndParseAddress(i.fee.recipient),x=Q(i.fee.fee.multiply(1e4).quotient);o.push(h?n.INTERFACE.encodeFunctionData("unwrapWETH9WithFee",[s,u,x,T]):n.INTERFACE.encodeFunctionData("sweepTokenWithFee",[t.route.tokenPath[t.route.tokenPath.length-1].address,s,u,x,T]))}else o.push(n.INTERFACE.encodeFunctionData("unwrapWETH9",[s,u]));return{calldata:1===o.length?o[0]:n.INTERFACE.encodeFunctionData("multicall",[o]),value:l}},n}(pt);mt.INTERFACE=new i.Interface(s.abi),exports.ADDRESS_ZERO=A,exports.FACTORY_ADDRESS="0x1F98431c8aD98523631AE4a59f267346ea31F984",exports.FullMath=O,exports.LiquidityMath=S,exports.NoTickDataProvider=W,exports.NonfungiblePositionManager=ft,exports.POOL_INIT_CODE_HASH=w,exports.Pool=it,exports.Position=ot,exports.Route=ut,exports.SqrtPriceMath=F,exports.SwapRouter=mt,exports.TICK_SPACINGS=I,exports.Tick=et,exports.TickList=z,exports.TickListDataProvider=nt,exports.TickMath=j,exports.Trade=lt,exports.computePoolAddress=C,exports.encodeRouteToPath=Y,exports.encodeSqrtRatioX96=Z,exports.isSorted=K,exports.maxLiquidityForAmounts=V,exports.mostSignificantBit=B,exports.nearestUsableTick=function(t,e){Number.isInteger(t)&&Number.isInteger(e)||r(!1),e>0||r(!1),t>=j.MIN_TICK&&t<=j.MAX_TICK||r(!1);var n=Math.round(t/e)*e;return n<j.MIN_TICK?n+e:n>j.MAX_TICK?n-e:n},exports.priceToClosestTick=function(t){t.baseCurrency.isToken&&t.quoteCurrency.isToken||r(!1);var e=t.baseCurrency.sortsBefore(t.quoteCurrency),n=e?Z(t.raw.numerator,t.raw.denominator):Z(t.raw.denominator,t.raw.numerator),i=j.getTickAtSqrtRatio(n),o=tt(t.baseCurrency,t.quoteCurrency,i+1);return e?t.lessThan(o)||i++:t.greaterThan(o)||i++,i},exports.tickToPrice=tt,exports.toHex=Q,exports.tradeComparator=at;
//# sourceMappingURL=v3-sdk.cjs.production.min.js.map

@@ -7,3 +7,3 @@ {

},
"version": "2.0.1",
"version": "2.0.2",
"description": "⚒️ An SDK for building applications on top of Uniswap V3",

@@ -10,0 +10,0 @@ "main": "dist/index.js",

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc