@aryze/v3-sdk
Version:
⚒️ An SDK for building applications on top of MAMA V3
1 lines • 53.6 kB
JavaScript
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n=require("@aryze/sdk-core"),r=t(require("jsbi")),i=t(require("tiny-invariant")),o=require("@ethersproject/abi"),a=require("@ethersproject/address"),u=require("@ethersproject/solidity"),c=t(require("@aryze/v3-periphery/artifacts/contracts/interfaces/IMulticall.sol/IMulticall.json")),s=t(require("@aryze/v3-periphery/artifacts/contracts/NonfungiblePositionManager.sol/NonfungiblePositionManager.json")),p=t(require("@aryze/v3-periphery/artifacts/contracts/interfaces/IPeripheryPaymentsWithFee.sol/IPeripheryPaymentsWithFee.json")),l=t(require("@aryze/v3-periphery/artifacts/contracts/interfaces/ISelfPermit.sol/ISelfPermit.json")),d=t(require("@aryze/swap-router-contracts/artifacts/contracts/lens/QuoterV2.sol/QuoterV2.json")),f=t(require("@aryze/v3-periphery/artifacts/contracts/lens/Quoter.sol/Quoter.json")),m=t(require("@aryze/v3-staker/artifacts/contracts/AryzeV3Staker.sol/AryzeV3Staker.json")),h=t(require("@aryze/v3-periphery/artifacts/contracts/SwapRouter.sol/SwapRouter.json"));function v(){v=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,i=Object.defineProperty||function(t,e,n){t[e]=n.value},o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",u=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function s(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{s({},"")}catch(t){s=function(t,e,n){return t[e]=n}}function p(t,e,n,r){var o=Object.create((e&&e.prototype instanceof y?e:y).prototype),a=new C(r||[]);return i(o,"_invoke",{value:b(t,n,a)}),o}function l(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=p;var d="suspendedStart",f="executing",m="completed",h={};function y(){}function k(){}function g(){}var A={};s(A,a,(function(){return this}));var T=Object.getPrototypeOf,I=T&&T(T(O([])));I&&I!==n&&r.call(I,a)&&(A=I);var x=g.prototype=y.prototype=Object.create(A);function w(t){["next","throw","return"].forEach((function(e){s(t,e,(function(t){return this._invoke(e,t)}))}))}function q(t,e){function n(i,o,a,u){var c=l(t[i],t,o);if("throw"!==c.type){var s=c.arg,p=s.value;return p&&"object"==typeof p&&r.call(p,"__await")?e.resolve(p.__await).then((function(t){n("next",t,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(p).then((function(t){s.value=t,a(s)}),(function(t){return n("throw",t,a,u)}))}u(c.arg)}var o;i(this,"_invoke",{value:function(t,r){function i(){return new e((function(e,i){n(t,r,e,i)}))}return o=o?o.then(i,i):i()}})}function b(e,n,r){var i=d;return function(o,a){if(i===f)throw new Error("Generator is already running");if(i===m){if("throw"===o)throw a;return{value:t,done:!0}}for(r.method=o,r.arg=a;;){var u=r.delegate;if(u){var c=E(u,r);if(c){if(c===h)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===d)throw i=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=f;var s=l(e,n,r);if("normal"===s.type){if(i=r.done?m:"suspendedYield",s.arg===h)continue;return{value:s.arg,done:r.done}}"throw"===s.type&&(i=m,r.method="throw",r.arg=s.arg)}}}function E(e,n){var r=n.method,i=e.iterator[r];if(i===t)return n.delegate=null,"throw"===r&&e.iterator.return&&(n.method="return",n.arg=t,E(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var o=l(i,e.iterator,n.arg);if("throw"===o.type)return n.method="throw",n.arg=o.arg,n.delegate=null,h;var a=o.arg;return a?a.done?(n[e.resultName]=a.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,h):a:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,h)}function R(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function P(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function C(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(R,this),this.reset(!0)}function O(e){if(e||""===e){var n=e[a];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,o=function n(){for(;++i<e.length;)if(r.call(e,i))return n.value=e[i],n.done=!1,n;return n.value=t,n.done=!0,n};return o.next=o}}throw new TypeError(typeof e+" is not iterable")}return k.prototype=g,i(x,"constructor",{value:g,configurable:!0}),i(g,"constructor",{value:k,configurable:!0}),k.displayName=s(g,c,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===k||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,s(t,c,"GeneratorFunction")),t.prototype=Object.create(x),t},e.awrap=function(t){return{__await:t}},w(q.prototype),s(q.prototype,u,(function(){return this})),e.AsyncIterator=q,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new q(p(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(x),s(x,c,"Generator"),s(x,a,(function(){return this})),s(x,"toString",(function(){return"[object Generator]"})),e.keys=function(t){var e=Object(t),n=[];for(var r in e)n.push(r);return n.reverse(),function t(){for(;n.length;){var r=n.pop();if(r in e)return t.value=r,t.done=!1,t}return t.done=!0,t}},e.values=O,C.prototype={constructor:C,reset:function(e){if(this.prev=0,this.next=0,this.sent=this._sent=t,this.done=!1,this.delegate=null,this.method="next",this.arg=t,this.tryEntries.forEach(P),!e)for(var n in this)"t"===n.charAt(0)&&r.call(this,n)&&!isNaN(+n.slice(1))&&(this[n]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(e){if(this.done)throw e;var n=this;function i(r,i){return u.type="throw",u.arg=e,n.next=r,i&&(n.method="next",n.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var a=this.tryEntries[o],u=a.completion;if("root"===a.tryLoc)return i("end");if(a.tryLoc<=this.prev){var c=r.call(a,"catchLoc"),s=r.call(a,"finallyLoc");if(c&&s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(c){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return i(a.finallyLoc)}}}},abrupt:function(t,e){for(var n=this.tryEntries.length-1;n>=0;--n){var i=this.tryEntries[n];if(i.tryLoc<=this.prev&&r.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 a=o?o.completion:{};return a.type=t,a.arg=e,o?(this.method="next",this.next=o.finallyLoc,h):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),h},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),P(n),h}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;P(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:O(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),h}},e}function y(t,e,n,r,i,o,a){try{var u=t[o](a),c=u.value}catch(t){return void n(t)}u.done?e(c):Promise.resolve(c).then(r,i)}function k(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function a(t){y(o,r,i,a,u,"next",t)}function u(t){y(o,r,i,a,u,"throw",t)}a(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,"symbol"==typeof(i=function(t,e){if("object"!=typeof t||null===t)return t;var n=t[Symbol.toPrimitive];if(void 0!==n){var r=n.call(t,"string");if("object"!=typeof r)return r;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(r.key))?i:String(i),r)}var i}function A(t,e,n){return e&&g(t.prototype,e),n&&g(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function T(){return(T=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function 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 x(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.")}var w,q="0x0000000000000000000000000000000000000000",b="0x8aeb7d9c447c5c3f6ad05ba4da15b42c982c77c5791901c09fef871b1a52e2e2";(w=exports.FeeAmount||(exports.FeeAmount={}))[w.LOWEST=100]="LOWEST",w[w.LOW=500]="LOW",w[w.LOWER_MEDIUM=1e3]="LOWER_MEDIUM",w[w.MEDIA_MEDIUM=2e3]="MEDIA_MEDIUM",w[w.MEDIUM=3e3]="MEDIUM",w[w.HIGH=1e4]="HIGH";var E=((e={})[exports.FeeAmount.LOWEST]=1,e[exports.FeeAmount.LOW]=10,e[exports.FeeAmount.LOWER_MEDIUM]=20,e[exports.FeeAmount.MEDIA_MEDIUM]=40,e[exports.FeeAmount.MEDIUM]=60,e[exports.FeeAmount.HIGH]=200,e),R=r.BigInt(-1),P=r.BigInt(0),C=r.BigInt(1),O=r.exponentiate(r.BigInt(2),r.BigInt(96)),S=r.exponentiate(O,r.BigInt(2));function N(t){var e=t.factoryAddress,n=t.tokenA,r=t.tokenB,i=t.fee,c=t.initCodeHashManualOverride,s=n.sortsBefore(r)?[n,r]:[r,n];return a.getCreate2Address(e,u.keccak256(["bytes"],[o.defaultAbiCoder.encode(["address","address","uint24"],[s[0].address,s[1].address,i])]),null!=c?c:b)}var _=function(){function t(){}return t.addDelta=function(t,e){return r.lessThan(e,P)?r.subtract(t,r.multiply(e,R)):r.add(t,e)},t}(),F=function(){function t(){}return t.mulDivRoundingUp=function(t,e,n){var i=r.multiply(t,e),o=r.divide(i,n);return r.notEqual(r.remainder(i,n),P)&&(o=r.add(o,C)),o},t}(),M=r.subtract(r.exponentiate(r.BigInt(2),r.BigInt(160)),C);function L(t,e){var i=r.multiply(t,e);return r.bitwiseAnd(i,n.MaxUint256)}var X=function(){function t(){}return t.getAmount0Delta=function(t,e,n,i){if(r.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}var a=r.leftShift(n,r.BigInt(96)),u=r.subtract(e,t);return i?F.mulDivRoundingUp(F.mulDivRoundingUp(a,u,e),C,t):r.divide(r.divide(r.multiply(a,u),e),t)},t.getAmount1Delta=function(t,e,n,i){if(r.greaterThan(t,e)){var o=[e,t];t=o[0],e=o[1]}return i?F.mulDivRoundingUp(n,r.subtract(e,t),O):r.divide(r.multiply(n,r.subtract(e,t)),O)},t.getNextSqrtPriceFromInput=function(t,e,n,o){return r.greaterThan(t,P)||i(!1),r.greaterThan(e,P)||i(!1),o?this.getNextSqrtPriceFromAmount0RoundingUp(t,e,n,!0):this.getNextSqrtPriceFromAmount1RoundingDown(t,e,n,!0)},t.getNextSqrtPriceFromOutput=function(t,e,n,o){return r.greaterThan(t,P)||i(!1),r.greaterThan(e,P)||i(!1),o?this.getNextSqrtPriceFromAmount1RoundingDown(t,e,n,!1):this.getNextSqrtPriceFromAmount0RoundingUp(t,e,n,!1)},t.getNextSqrtPriceFromAmount0RoundingUp=function(t,e,o,a){if(r.equal(o,P))return t;var u=r.leftShift(e,r.BigInt(96));if(a){var c=L(o,t);if(r.equal(r.divide(c,o),t)){var s=(l=r.add(u,c),r.bitwiseAnd(l,n.MaxUint256));if(r.greaterThanOrEqual(s,u))return F.mulDivRoundingUp(u,t,s)}return F.mulDivRoundingUp(u,C,r.add(r.divide(u,t),o))}var p=L(o,t);r.equal(r.divide(p,o),t)||i(!1),r.greaterThan(u,p)||i(!1);var l,d=r.subtract(u,p);return F.mulDivRoundingUp(u,t,d)},t.getNextSqrtPriceFromAmount1RoundingDown=function(t,e,n,o){if(o){var a=r.lessThanOrEqual(n,M)?r.divide(r.leftShift(n,r.BigInt(96)),e):r.divide(r.multiply(n,O),e);return r.add(t,a)}var u=F.mulDivRoundingUp(n,O,e);return r.greaterThan(t,u)||i(!1),r.subtract(t,u)},t}(),U=r.exponentiate(r.BigInt(10),r.BigInt(6)),D=function(){function t(){}return t.computeSwapStep=function(t,e,n,i,o){var a={},u=r.greaterThanOrEqual(t,e),c=r.greaterThanOrEqual(i,P);if(c){var s=r.divide(r.multiply(i,r.subtract(U,r.BigInt(o))),U);a.amountIn=u?X.getAmount0Delta(e,t,n,!0):X.getAmount1Delta(t,e,n,!0),a.sqrtRatioNextX96=r.greaterThanOrEqual(s,a.amountIn)?e:X.getNextSqrtPriceFromInput(t,n,s,u)}else a.amountOut=u?X.getAmount1Delta(e,t,n,!1):X.getAmount0Delta(t,e,n,!1),a.sqrtRatioNextX96=r.greaterThanOrEqual(r.multiply(i,R),a.amountOut)?e:X.getNextSqrtPriceFromOutput(t,n,r.multiply(i,R),u);var p=r.equal(e,a.sqrtRatioNextX96);return u?(a.amountIn=p&&c?a.amountIn:X.getAmount0Delta(a.sqrtRatioNextX96,t,n,!0),a.amountOut=p&&!c?a.amountOut:X.getAmount1Delta(a.sqrtRatioNextX96,t,n,!1)):(a.amountIn=p&&c?a.amountIn:X.getAmount1Delta(t,a.sqrtRatioNextX96,n,!0),a.amountOut=p&&!c?a.amountOut:X.getAmount0Delta(t,a.sqrtRatioNextX96,n,!1)),!c&&r.greaterThan(a.amountOut,r.multiply(i,R))&&(a.amountOut=r.multiply(i,R)),a.feeAmount=c&&r.notEqual(a.sqrtRatioNextX96,e)?r.subtract(i,a.amountIn):F.mulDivRoundingUp(a.amountIn,r.BigInt(o),r.subtract(U,r.BigInt(o))),[a.sqrtRatioNextX96,a.amountIn,a.amountOut,a.feeAmount]},t}(),B=r.BigInt(2),j=[128,64,32,16,8,4,2,1].map((function(t){return[t,r.exponentiate(B,r.BigInt(t))]}));function W(t){r.greaterThan(t,P)||i(!1),r.lessThanOrEqual(t,n.MaxUint256)||i(!1);for(var e,o=0,a=x(j);!(e=a()).done;){var u=e.value,c=u[0];r.greaterThanOrEqual(t,u[1])&&(t=r.signedRightShift(t,r.BigInt(c)),o+=c)}return o}function G(t,e){return r.signedRightShift(r.multiply(t,r.BigInt(e)),r.BigInt(128))}var K=r.exponentiate(r.BigInt(2),r.BigInt(32)),H=function(){function t(){}return t.getSqrtRatioAtTick=function(e){e>=t.MIN_TICK&&e<=t.MAX_TICK&&Number.isInteger(e)||i(!1);var o=e<0?-1*e:e,a=r.BigInt(0!=(1&o)?"0xfffcb933bd6fad37aa2d162d1a594001":"0x100000000000000000000000000000000");return 0!=(2&o)&&(a=G(a,"0xfff97272373d413259a46990580e213a")),0!=(4&o)&&(a=G(a,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&o)&&(a=G(a,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&o)&&(a=G(a,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&o)&&(a=G(a,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&o)&&(a=G(a,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&o)&&(a=G(a,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&o)&&(a=G(a,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&o)&&(a=G(a,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&o)&&(a=G(a,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&o)&&(a=G(a,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&o)&&(a=G(a,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&o)&&(a=G(a,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&o)&&(a=G(a,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&o)&&(a=G(a,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&o)&&(a=G(a,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&o)&&(a=G(a,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&o)&&(a=G(a,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&o)&&(a=G(a,"0x48a170391f7dc42444e8fa2")),e>0&&(a=r.divide(n.MaxUint256,a)),r.greaterThan(r.remainder(a,K),P)?r.add(r.divide(a,K),C):r.divide(a,K)},t.getTickAtSqrtRatio=function(e){r.greaterThanOrEqual(e,t.MIN_SQRT_RATIO)&&r.lessThan(e,t.MAX_SQRT_RATIO)||i(!1);var n,o=r.leftShift(e,r.BigInt(32)),a=W(o);n=r.greaterThanOrEqual(r.BigInt(a),r.BigInt(128))?r.signedRightShift(o,r.BigInt(a-127)):r.leftShift(o,r.BigInt(127-a));for(var u=r.leftShift(r.subtract(r.BigInt(a),r.BigInt(128)),r.BigInt(64)),c=0;c<14;c++){n=r.signedRightShift(r.multiply(n,n),r.BigInt(127));var s=r.signedRightShift(n,r.BigInt(128));u=r.bitwiseOr(u,r.leftShift(s,r.BigInt(63-c))),n=r.signedRightShift(n,s)}var p=r.multiply(u,r.BigInt("255738958999603826347141")),l=r.toNumber(r.signedRightShift(r.subtract(p,r.BigInt("3402992956809132418596140100660247210")),r.BigInt(128))),d=r.toNumber(r.signedRightShift(r.add(p,r.BigInt("291339464771989622907027621153398088495")),r.BigInt(128)));return l===d?l:r.lessThanOrEqual(t.getSqrtRatioAtTick(d),e)?d:l},t}();H.MIN_TICK=-887272,H.MAX_TICK=-H.MIN_TICK,H.MIN_SQRT_RATIO=r.BigInt("4295128739"),H.MAX_SQRT_RATIO=r.BigInt("1461446703485210103287273052203988822378723970342");var z=function(){function t(){}var e=t.prototype;return e.getTick=function(){var e=k(v().mark((function e(n){return v().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=k(v().mark((function e(n,r,i){return v().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 Q(t,e){for(var n=0;n<t.length-1;n++)if(e(t[n],t[n+1])>0)return!1;return!0}function V(t,e){return t.index-e.index}z.ERROR_MESSAGE="No tick data provider was given";var Y=function(){function t(){}return t.validateList=function(t,e){e>0||i(!1),t.every((function(t){return t.index%e==0}))||i(!1),r.equal(t.reduce((function(t,e){return r.add(t,e.liquidityNet)}),P),P)||i(!1),Q(t,V)||i(!1)},t.isBelowSmallest=function(t,e){return t.length>0||i(!1),e<t[0].index},t.isAtOrAboveLargest=function(t,e){return t.length>0||i(!1),e>=t[t.length-1].index},t.getTick=function(t,e){var n=t[this.binarySearch(t,e)];return n.index!==e&&i(!1),n},t.binarySearch=function(t,e){this.isBelowSmallest(t,e)&&i(!1);for(var n,r=0,o=t.length-1;;){if(t[n=Math.floor((r+o)/2)].index<=e&&(n===t.length-1||t[n+1].index>e))return n;t[n].index<e?r=n+1:o=n-1}},t.nextInitializedTick=function(e,n,r){return r?(t.isBelowSmallest(e,n)&&i(!1),t.isAtOrAboveLargest(e,n)?e[e.length-1]:e[this.binarySearch(e,n)]):(this.isAtOrAboveLargest(e,n)&&i(!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 a=(o>>8<<8)*i;if(t.isBelowSmallest(e,n))return[a,!1];var u=t.nextInitializedTick(e,n,r).index,c=Math.max(a,u);return[c,c===u]}var s=((1+(o+1>>8)<<8)-1)*i;if(this.isAtOrAboveLargest(e,n))return[s,!1];var p=this.nextInitializedTick(e,n,r).index,l=Math.min(s,p);return[l,l===p]},t}();function Z(t){var e=r.BigInt(t).toString(16);return e.length%2!=0&&(e="0"+e),"0x"+e}function $(t,e){var n=t.pools.reduce((function(t,e,n){var r=t.inputToken,i=t.path,o=t.types,a=e.token0.equals(r)?e.token1:e.token0;return 0===n?{inputToken:a,types:["address","uint24","address"],path:[r.address,e.fee,a.address]}:{inputToken:a,types:[].concat(o,["uint24","address"]),path:[].concat(i,[e.fee,a.address])}}),{inputToken:t.input.wrapped,path:[],types:[]}),r=n.path,i=n.types;return e?u.pack(i.reverse(),r.reverse()):u.pack(i,r)}function J(t,e){var i=r.leftShift(r.BigInt(t),r.BigInt(192)),o=r.BigInt(e),a=r.divide(i,o);return n.sqrt(a)}function tt(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=r.divide(r.multiply(t,e),O);return r.divide(r.multiply(r.BigInt(n),o),r.subtract(e,t))}function et(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=r.multiply(r.multiply(r.BigInt(n),t),e),a=r.multiply(O,r.subtract(e,t));return r.divide(o,a)}function nt(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}return r.divide(r.multiply(r.BigInt(n),O),r.subtract(e,t))}function rt(t,e,n,i,o,a){if(r.greaterThan(e,n)){var u=[n,e];e=u[0],n=u[1]}var c=a?et:tt;if(r.lessThanOrEqual(t,e))return c(e,n,i);if(r.lessThan(t,n)){var s=c(t,n,i),p=nt(e,t,o);return r.lessThan(s,p)?s:p}return nt(e,n,o)}var it=r.exponentiate(r.BigInt(2),r.BigInt(128)),ot=function(){function t(){}return t.getTokensOwed=function(t,e,n,i,o){return[r.divide(r.multiply(ct(i,t),n),it),r.divide(r.multiply(ct(o,e),n),it)]},t}();function at(t,e,i){var o=H.getSqrtRatioAtTick(i),a=r.multiply(o,o);return t.sortsBefore(e)?new n.Price(t,e,S,a):new n.Price(t,e,a,S)}var ut=r.exponentiate(r.BigInt(2),r.BigInt(256));function ct(t,e){var n=r.subtract(t,e);return r.lessThan(n,P)?r.add(ut,n):n}var st=function(){function t(){}return t.getFeeGrowthInside=function(t,e,n,r,i,o,a){var u,c,s,p;return i>=n?(u=t.feeGrowthOutside0X128,c=t.feeGrowthOutside1X128):(u=ct(o,t.feeGrowthOutside0X128),c=ct(a,t.feeGrowthOutside1X128)),i<r?(s=e.feeGrowthOutside0X128,p=e.feeGrowthOutside1X128):(s=ct(o,e.feeGrowthOutside0X128),p=ct(a,e.feeGrowthOutside1X128)),[ct(ct(o,u),s),ct(ct(a,c),p)]},t}(),pt=function(t){var e=t.index,n=t.liquidityGross,o=t.liquidityNet;e>=H.MIN_TICK&&e<=H.MAX_TICK||i(!1),this.index=e,this.liquidityGross=r.BigInt(n),this.liquidityNet=r.BigInt(o)},lt=function(){function t(t,e){var n=t.map((function(t){return t instanceof pt?t:new pt(t)}));Y.validateList(n,e),this.ticks=n}var e=t.prototype;return e.getTick=function(){var t=k(v().mark((function t(e){return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Y.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=k(v().mark((function t(e,n,r){return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Y.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}(),dt=new z,ft=function(){function t(t,e,n,o,a,u,c){void 0===c&&(c=dt),Number.isInteger(n)&&n<1e6||i(!1);var s=H.getSqrtRatioAtTick(u),p=H.getSqrtRatioAtTick(u+1);r.greaterThanOrEqual(r.BigInt(o),s)&&r.lessThanOrEqual(r.BigInt(o),p)||i(!1);var l=t.sortsBefore(e)?[t,e]:[e,t];this.token0=l[0],this.token1=l[1],this.fee=n,this.sqrtRatioX96=r.BigInt(o),this.liquidity=r.BigInt(a),this.tickCurrent=u,this.tickDataProvider=Array.isArray(c)?new lt(c,E[n]):c}t.getAddress=function(t,e,n,r,i){return N({factoryAddress:null!=i?i:"0xE7aE959bbC94BDF2E9FF28a214840aB3285d7765",fee:n,tokenA:t,tokenB:e,initCodeHashManualOverride:r})};var e=t.prototype;return e.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},e.priceOf=function(t){return this.involvesToken(t)||i(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.getOutputAmount=function(){var e=k(v().mark((function e(o,a){var u,c,s,p,l;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.involvesToken(o.currency)||i(!1),u=o.currency.equals(this.token0),e.next=4,this.swap(u,o.quotient,a);case 4:return s=(c=e.sent).sqrtRatioX96,p=c.liquidity,l=c.tickCurrent,e.abrupt("return",[n.CurrencyAmount.fromRawAmount(u?this.token1:this.token0,r.multiply(c.amountCalculated,R)),new t(this.token0,this.token1,this.fee,s,p,l,this.tickDataProvider)]);case 11:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.getInputAmount=function(){var e=k(v().mark((function e(o,a){var u,c,s,p,l;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return o.currency.isToken&&this.involvesToken(o.currency)||i(!1),u=o.currency.equals(this.token1),e.next=4,this.swap(u,r.multiply(o.quotient,R),a);case 4:return s=(c=e.sent).sqrtRatioX96,p=c.liquidity,l=c.tickCurrent,e.abrupt("return",[n.CurrencyAmount.fromRawAmount(u?this.token0:this.token1,c.amountCalculated),new t(this.token0,this.token1,this.fee,s,p,l,this.tickDataProvider)]);case 11:case"end":return e.stop()}}),e,this)})));return function(t,n){return e.apply(this,arguments)}}(),e.swap=function(){var t=k(v().mark((function t(e,n,o){var a,u,c,s,p,l;return v().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o||(o=e?r.add(H.MIN_SQRT_RATIO,C):r.subtract(H.MAX_SQRT_RATIO,C)),e?(r.greaterThan(o,H.MIN_SQRT_RATIO)||i(!1),r.lessThan(o,this.sqrtRatioX96)||i(!1)):(r.lessThan(o,H.MAX_SQRT_RATIO)||i(!1),r.greaterThan(o,this.sqrtRatioX96)||i(!1)),a=r.greaterThanOrEqual(n,P),u={amountSpecifiedRemaining:n,amountCalculated:P,sqrtPriceX96:this.sqrtRatioX96,tick:this.tickCurrent,liquidity:this.liquidity};case 4:if(!r.notEqual(u.amountSpecifiedRemaining,P)||u.sqrtPriceX96==o){t.next=35;break}return(c={}).sqrtPriceStartX96=u.sqrtPriceX96,t.next=9,this.tickDataProvider.nextInitializedTickWithinOneWord(u.tick,e,this.tickSpacing);case 9:if(c.tickNext=(s=t.sent)[0],c.initialized=s[1],c.tickNext<H.MIN_TICK?c.tickNext=H.MIN_TICK:c.tickNext>H.MAX_TICK&&(c.tickNext=H.MAX_TICK),c.sqrtPriceNextX96=H.getSqrtRatioAtTick(c.tickNext),p=D.computeSwapStep(u.sqrtPriceX96,(e?r.lessThan(c.sqrtPriceNextX96,o):r.greaterThan(c.sqrtPriceNextX96,o))?o:c.sqrtPriceNextX96,u.liquidity,u.amountSpecifiedRemaining,this.fee),u.sqrtPriceX96=p[0],c.amountIn=p[1],c.amountOut=p[2],c.feeAmount=p[3],a?(u.amountSpecifiedRemaining=r.subtract(u.amountSpecifiedRemaining,r.add(c.amountIn,c.feeAmount)),u.amountCalculated=r.subtract(u.amountCalculated,c.amountOut)):(u.amountSpecifiedRemaining=r.add(u.amountSpecifiedRemaining,c.amountOut),u.amountCalculated=r.add(u.amountCalculated,r.add(c.amountIn,c.feeAmount))),!r.equal(u.sqrtPriceX96,c.sqrtPriceNextX96)){t.next=32;break}if(!c.initialized){t.next=29;break}return t.t0=r,t.next=25,this.tickDataProvider.getTick(c.tickNext);case 25:t.t1=t.sent.liquidityNet,l=t.t0.BigInt.call(t.t0,t.t1),e&&(l=r.multiply(l,R)),u.liquidity=_.addDelta(u.liquidity,l);case 29:u.tick=e?c.tickNext-1:c.tickNext,t.next=33;break;case 32:r.notEqual(u.sqrtPriceX96,c.sqrtPriceStartX96)&&(u.tick=H.getTickAtSqrtRatio(u.sqrtPriceX96));case 33:t.next=4;break;case 35:return t.abrupt("return",{amountCalculated:u.amountCalculated,sqrtRatioX96:u.sqrtPriceX96,liquidity:u.liquidity,tickCurrent:u.tick});case 36:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),A(t,[{key:"token0Price",get:function(){var t;return null!=(t=this._token0Price)?t:this._token0Price=new n.Price(this.token0,this.token1,S,r.multiply(this.sqrtRatioX96,this.sqrtRatioX96))}},{key:"token1Price",get:function(){var t;return null!=(t=this._token1Price)?t:this._token1Price=new n.Price(this.token1,this.token0,r.multiply(this.sqrtRatioX96,this.sqrtRatioX96),S)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"tickSpacing",get:function(){return E[this.fee]}}]),t}(),mt=function(){function t(t){var e=t.pool,n=t.liquidity,o=t.tickLower,a=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,o<a||i(!1),o>=H.MIN_TICK&&o%e.tickSpacing==0||i(!1),a<=H.MAX_TICK&&a%e.tickSpacing==0||i(!1),this.pool=e,this.tickLower=o,this.tickUpper=a,this.liquidity=r.BigInt(n)}var e=t.prototype;return e.ratiosAfterSlippage=function(t){var e=this.pool.token0Price.asFraction.multiply(new n.Percent(1).subtract(t)),i=this.pool.token0Price.asFraction.multiply(t.add(1)),o=J(e.numerator,e.denominator);r.lessThanOrEqual(o,H.MIN_SQRT_RATIO)&&(o=r.add(H.MIN_SQRT_RATIO,r.BigInt(1)));var a=J(i.numerator,i.denominator);return r.greaterThanOrEqual(a,H.MAX_SQRT_RATIO)&&(a=r.subtract(H.MAX_SQRT_RATIO,r.BigInt(1))),{sqrtRatioX96Lower:o,sqrtRatioX96Upper:a}},e.mintAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new ft(this.pool.token0,this.pool.token1,this.pool.fee,i,0,H.getTickAtSqrtRatio(i)),a=new ft(this.pool.token0,this.pool.token1,this.pool.fee,r,0,H.getTickAtSqrtRatio(r)),u=t.fromAmounts(T({pool:this.pool,tickLower:this.tickLower,tickUpper:this.tickUpper},this.mintAmounts,{useFullPrecision:!1}));return{amount0:new t({pool:a,liquidity:u.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:new t({pool:o,liquidity:u.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount1}},e.burnAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new ft(this.pool.token0,this.pool.token1,this.pool.fee,i,0,H.getTickAtSqrtRatio(i)),a=new t({pool:new ft(this.pool.token0,this.pool.token1,this.pool.fee,r,0,H.getTickAtSqrtRatio(r)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,u=new t({pool:o,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:a.quotient,amount1:u.quotient}},t.fromAmounts=function(e){var n=e.pool,r=e.tickLower,i=e.tickUpper,o=e.amount0,a=e.amount1,u=e.useFullPrecision,c=H.getSqrtRatioAtTick(r),s=H.getSqrtRatioAtTick(i);return new t({pool:n,tickLower:r,tickUpper:i,liquidity:rt(n.sqrtRatioX96,c,s,o,a,u)})},t.fromAmount0=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:e.amount0,amount1:n.MaxUint256,useFullPrecision:e.useFullPrecision})},t.fromAmount1=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:n.MaxUint256,amount1:e.amount1,useFullPrecision:!0})},A(t,[{key:"token0PriceLower",get:function(){return at(this.pool.token0,this.pool.token1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return at(this.pool.token0,this.pool.token1,this.tickUpper)}},{key:"amount0",get:function(){return null===this._token0Amount&&(this._token0Amount=n.CurrencyAmount.fromRawAmount(this.pool.token0,this.pool.tickCurrent<this.tickLower?X.getAmount0Delta(H.getSqrtRatioAtTick(this.tickLower),H.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):this.pool.tickCurrent<this.tickUpper?X.getAmount0Delta(this.pool.sqrtRatioX96,H.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):P)),this._token0Amount}},{key:"amount1",get:function(){return null===this._token1Amount&&(this._token1Amount=n.CurrencyAmount.fromRawAmount(this.pool.token1,this.pool.tickCurrent<this.tickLower?P:X.getAmount1Delta(H.getSqrtRatioAtTick(this.tickLower),this.pool.tickCurrent<this.tickUpper?this.pool.sqrtRatioX96:H.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1))),this._token1Amount}},{key:"mintAmounts",get:function(){return null===this._mintAmounts?this.pool.tickCurrent<this.tickLower?{amount0:X.getAmount0Delta(H.getSqrtRatioAtTick(this.tickLower),H.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:P}:this.pool.tickCurrent<this.tickUpper?{amount0:X.getAmount0Delta(this.pool.sqrtRatioX96,H.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:X.getAmount1Delta(H.getSqrtRatioAtTick(this.tickLower),this.pool.sqrtRatioX96,this.liquidity,!0)}:{amount0:P,amount1:X.getAmount1Delta(H.getSqrtRatioAtTick(this.tickLower),H.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0)}:this._mintAmounts}}]),t}(),ht=function(){function t(t,e,n){this._midPrice=null,t.length>0||i(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||i(!1);var o=e.wrapped;t[0].involvesToken(o)||i(!1),t[t.length-1].involvesToken(n.wrapped)||i(!1);for(var a,u=[o],c=x(t.entries());!(a=c()).done;){var s=a.value,p=s[1],l=u[s[0]];l.equals(p.token0)||l.equals(p.token1)||i(!1);var d=l.equals(p.token0)?p.token1:p.token0;u.push(d)}this.pools=t,this.tokenPath=u,this.input=e,this.output=null!=n?n:u[u.length-1]}return A(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,e){var n=t.price;return t.nextInput.equals(e.token0)?{nextInput:e.token1,price:n.multiply(e.token0Price)}:{nextInput:e.token0,price:n.multiply(e.token1Price)}}),this.pools[0].token0.equals(this.input.wrapped)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price}).price;return this._midPrice=new n.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function vt(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||i(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||i(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?t.swaps.reduce((function(t,e){return t+e.route.tokenPath.length}),0)-e.swaps.reduce((function(t,e){return t+e.route.tokenPath.length}),0):t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}var yt=function(){function t(t){var e=t.routes,n=t.tradeType,r=e[0].inputAmount.currency,o=e[0].outputAmount.currency;e.every((function(t){return r.wrapped.equals(t.route.input.wrapped)}))||i(!1),e.every((function(t){return o.wrapped.equals(t.route.output.wrapped)}))||i(!1);for(var a,u=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,s=x(e);!(a=s()).done;)for(var p,l=x(a.value.route.pools);!(p=l()).done;){var d=p.value;c.add(ft.getAddress(d.token0,d.token1,d.fee))}u!=c.size&&i(!1),this.swaps=e,this.tradeType=n}t.exactIn=function(){var e=k(v().mark((function e(r,i){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(r,i,n.TradeType.EXACT_INPUT));case 1:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.exactOut=function(){var e=k(v().mark((function e(r,i){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(r,i,n.TradeType.EXACT_OUTPUT));case 1:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.fromRoute=function(){var e=k(v().mark((function e(r,o,a){var u,c,s,p,l,d,f;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(u=new Array(r.tokenPath.length),a!==n.TradeType.EXACT_INPUT){e.next=19;break}o.currency.equals(r.input)||i(!1),u[0]=o.wrapped,p=0;case 5:if(!(p<r.tokenPath.length-1)){e.next=15;break}return l=r.pools[p],e.next=9,l.getOutputAmount(u[p]);case 9:u[p+1]=e.sent[0];case 12:p++,e.next=5;break;case 15:c=n.CurrencyAmount.fromFractionalAmount(r.input,o.numerator,o.denominator),s=n.CurrencyAmount.fromFractionalAmount(r.output,u[u.length-1].numerator,u[u.length-1].denominator),e.next=34;break;case 19:o.currency.equals(r.output)||i(!1),u[u.length-1]=o.wrapped,d=r.tokenPath.length-1;case 22:if(!(d>0)){e.next=32;break}return f=r.pools[d-1],e.next=26,f.getInputAmount(u[d]);case 26:u[d-1]=e.sent[0];case 29:d--,e.next=22;break;case 32:c=n.CurrencyAmount.fromFractionalAmount(r.input,u[0].numerator,u[0].denominator),s=n.CurrencyAmount.fromFractionalAmount(r.output,o.numerator,o.denominator);case 34:return e.abrupt("return",new t({routes:[{inputAmount:c,outputAmount:s,route:r}],tradeType:a}));case 35:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=k(v().mark((function e(r,o){var a,u,c,s,p,l,d,f,m,h,y,k,g;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=[],u=x(r);case 2:if((c=u()).done){e.next=43;break}if(p=(s=c.value).route,l=s.amount,d=new Array(p.tokenPath.length),f=void 0,m=void 0,o!==n.TradeType.EXACT_INPUT){e.next=25;break}l.currency.equals(p.input)||i(!1),f=n.CurrencyAmount.fromFractionalAmount(p.input,l.numerator,l.denominator),d[0]=n.CurrencyAmount.fromFractionalAmount(p.input.wrapped,l.numerator,l.denominator),h=0;case 12:if(!(h<p.tokenPath.length-1)){e.next=22;break}return y=p.pools[h],e.next=16,y.getOutputAmount(d[h]);case 16:d[h+1]=e.sent[0];case 19:h++,e.next=12;break;case 22:m=n.CurrencyAmount.fromFractionalAmount(p.output,d[d.length-1].numerator,d[d.length-1].denominator),e.next=40;break;case 25:l.currency.equals(p.output)||i(!1),m=n.CurrencyAmount.fromFractionalAmount(p.output,l.numerator,l.denominator),d[d.length-1]=n.CurrencyAmount.fromFractionalAmount(p.output.wrapped,l.numerator,l.denominator),k=p.tokenPath.length-1;case 29:if(!(k>0)){e.next=39;break}return g=p.pools[k-1],e.next=33,g.getInputAmount(d[k]);case 33:d[k-1]=e.sent[0];case 36:k--,e.next=29;break;case 39:f=n.CurrencyAmount.fromFractionalAmount(p.input,d[0].numerator,d[0].denominator);case 40:a.push({route:p,inputAmount:f,outputAmount:m});case 41:e.next=2;break;case 43:return e.abrupt("return",new t({routes:a,tradeType:o}));case 44:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(T({},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){if(void 0===e&&(e=this.outputAmount),t.lessThan(P)&&i(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return e;var r=new n.Fraction(C).add(t).invert().multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(P)&&i(!1),this.tradeType===n.TradeType.EXACT_INPUT)return e;var r=new n.Fraction(C).add(t).multiply(e.quotient).quotient;return n.CurrencyAmount.fromRawAmount(e.currency,r)},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=k(v().mark((function e(r,o,a,u,c,s,p){var l,d,f,m,h,y,k,g,A,T,I;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(d=(l=void 0===u?{}:u).maxNumResults)?3:d,h=void 0===(m=l.maxHops)?3:m,void 0===c&&(c=[]),void 0===s&&(s=o),void 0===p&&(p=[]),r.length>0||i(!1),h>0||i(!1),o===s||c.length>0||i(!1),y=s.wrapped,k=a.wrapped,g=0;case 10:if(!(g<r.length)){e.next=46;break}if((A=r[g]).token0.equals(y.currency)||A.token1.equals(y.currency)){e.next=14;break}return e.abrupt("continue",43);case 14:return T=void 0,e.prev=15,e.next=19,A.getOutputAmount(y);case 19:T=e.sent[0],e.next=28;break;case 23:if(e.prev=23,e.t0=e.catch(15),!e.t0.isInsufficientInputAmountError){e.next=27;break}return e.abrupt("continue",43);case 27:throw e.t0;case 28:if(!T.currency.isToken||!T.currency.equals(k)){e.next=39;break}return e.t1=n.sortedInsert,e.t2=p,e.next=33,t.fromRoute(new ht([].concat(c,[A]),o.currency,a),o,n.TradeType.EXACT_INPUT);case 33:e.t3=e.sent,e.t4=f,e.t5=vt,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=43;break;case 39:if(!(h>1&&r.length>1)){e.next=43;break}return I=r.slice(0,g).concat(r.slice(g+1,r.length)),e.next=43,t.bestTradeExactIn(I,o,a,{maxNumResults:f,maxHops:h-1},[].concat(c,[A]),T,p);case 43:g++,e.next=10;break;case 46:return e.abrupt("return",p);case 47:case"end":return e.stop()}}),e,null,[[15,23]])})));return function(t,n,r,i,o,a,u){return e.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var e=k(v().mark((function e(r,o,a,u,c,s,p){var l,d,f,m,h,y,k,g,A,T,I;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:f=void 0===(d=(l=void 0===u?{}:u).maxNumResults)?3:d,h=void 0===(m=l.maxHops)?3:m,void 0===c&&(c=[]),void 0===s&&(s=a),void 0===p&&(p=[]),r.length>0||i(!1),h>0||i(!1),a===s||c.length>0||i(!1),y=s.wrapped,k=o.wrapped,g=0;case 10:if(!(g<r.length)){e.next=46;break}if((A=r[g]).token0.equals(y.currency)||A.token1.equals(y.currency)){e.next=14;break}return e.abrupt("continue",43);case 14:return T=void 0,e.prev=15,e.next=19,A.getInputAmount(y);case 19:T=e.sent[0],e.next=28;break;case 23:if(e.prev=23,e.t0=e.catch(15),!e.t0.isInsufficientReservesError){e.next=27;break}return e.abrupt("continue",43);case 27:throw e.t0;case 28:if(!T.currency.equals(k)){e.next=39;break}return e.t1=n.sortedInsert,e.t2=p,e.next=33,t.fromRoute(new ht([A].concat(c),o,a.currency),a,n.TradeType.EXACT_OUTPUT);case 33:e.t3=e.sent,e.t4=f,e.t5=vt,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=43;break;case 39:if(!(h>1&&r.length>1)){e.next=43;break}return I=r.slice(0,g).concat(r.slice(g+1,r.length)),e.next=43,t.bestTradeExactOut(I,o,a,{maxNumResults:f,maxHops:h-1},[A].concat(c),T,p);case 43:g++,e.next=10;break;case 46:return e.abrupt("return",p);case 47:case"end":return e.stop()}}),e,null,[[15,23]])})));return function(t,n,r,i,o,a,u){return e.apply(this,arguments)}}(),A(t,[{key:"route",get:function(){return 1!=this.swaps.length&&i(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=e,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,e=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),n.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.quotient,this.outputAmount.quotient)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,e=n.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=x(this.swaps);!(t=r()).done;){var i=t.value;e=e.add(i.route.midPrice.quote(i.inputAmount))}var o=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new n.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}(),kt=function(){function t(){}return t.encodeMulticall=function(e){return Array.isArray(e)||(e=[e]),1===e.length?e[0]:t.INTERFACE.encodeFunctionData("multicall",[e])},t}();kt.INTERFACE=new o.Interface(c.abi);var gt=function(){function t(){}return t.encodeFeeBips=function(t){return Z(t.multiply(1e4).quotient)},t.encodeUnwrapWETH9=function(e,r,i){if(r=n.validateAndParseAddress(r),i){var o=this.encodeFeeBips(i.fee),a=n.validateAndParseAddress(i.recipient);return t.INTERFACE.encodeFunctionData("unwrapWETH9WithFee",[Z(e),r,o,a])}return t.INTERFACE.encodeFunctionData("unwrapWETH9",[Z(e),r])},t.encodeSweepToken=function(e,r,i,o){if(i=n.validateAndParseAddress(i),o){var a=this.encodeFeeBips(o.fee),u=n.validateAndParseAddress(o.recipient);return t.INTERFACE.encodeFunctionData("sweepTokenWithFee",[e.address,Z(r),i,a,u])}return t.INTERFACE.encodeFunctionData("sweepToken",[e.address,Z(r),i])},t.encodeRefundETH=function(){return t.INTERFACE.encodeFunctionData("refundETH")},t}();gt.INTERFACE=new o.Interface(p.abi);var At=function(){function t(){}return t.encodePermit=function(e,n){return"nonce"in n?t.INTERFACE.encodeFunctionData("selfPermitAllowed",[e.address,Z(n.nonce),Z(n.expiry),n.v,n.r,n.s]):t.INTERFACE.encodeFunctionData("selfPermit",[e.address,Z(n.amount),Z(n.deadline),n.v,n.r,n.s])},t}();At.INTERFACE=new o.Interface(l.abi);var Tt=["expectedCurrencyOwed0","expectedCurrencyOwed1"],It=Z(r.subtract(r.exponentiate(r.BigInt(2),r.BigInt(128)),r.BigInt(1)));function xt(t){return Object.keys(t).some((function(t){return"recipient"===t}))}var wt=function(){function t(){}return t.encodeCreate=function(e){return t.INTERFACE.encodeFunctionData("createAndInitializePoolIfNecessary",[e.token0.address,e.token1.address,e.fee,Z(e.sqrtRatioX96)])},t.createCallParameters=function(t){return{calldata:this.encodeCreate(t),value:Z(0)}},t.addCallParameters=function(e,o){r.greaterThan(e.liquidity,P)||i(!1);var a=[],u=e.mintAmounts,c=u.amount0,s=u.amount1,p=e.mintAmountsWithSlippage(o.slippageTolerance),l=Z(p.amount0),d=Z(p.amount1),f=Z(o.deadline);if(xt(o)&&o.createPool&&a.push(this.encodeCreate(e.pool)),o.token0Permit&&a.push(At.encodePermit(e.pool.token0,o.token0Permit)),o.token1Permit&&a.push(At.encodePermit(e.pool.token1,o.token1Permit)),xt(o)){var m=n.validateAndParseAddress(o.recipient);console.log({token0:e.pool.token0.address,token1:e.pool.token1.address,fee:e.pool.fee,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0Desired:Z(c),amount1Desired:Z(s),amount0Min:l,amount1Min:d,recipient:m,deadline:f}),a.push(t.INTERFACE.encodeFunctionData("mint",[{token0:e.pool.token0.address,token1:e.pool.token1.address,fee:e.pool.fee,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0Desired:Z(c),amount1Desired:Z(s),amount0Min:l,amount1Min:d,recipient:m,deadline:f}]))}else a.push(t.INTERFACE.encodeFunctionData("increaseLiquidity",[{tokenId:Z(o.tokenId),amount0Desired:Z(c),amount1Desired:Z(s),amount0Min:l,amount1Min:d,deadline:f}]));var h=Z(0);if(o.useNative){var v=o.useNative.wrapped;e.pool.token0.equals(v)||e.pool.token1.equals(v)||i(!1);var y=e.pool.token0.equals(v)?c:s;r.greaterThan(y,P)&&a.push(gt.encodeRefundETH()),h=Z(y)}return{calldata:kt.encodeMulticall(a),value:h}},t.encodeCollect=function(e){var r=[],i=Z(e.tokenId),o=e.expectedCurrencyOwed0.currency.isNative||e.expectedCurrencyOwed1.currency.isNative,a=n.validateAndParseAddress(e.recipient);if(r.push(t.INTERFACE.encodeFunctionData("collect",[{tokenId:i,recipient:o?q:a,amount0Max:It,amount1Max:It}])),o){var u=e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed1.currency:e.expectedCurrencyOwed0.currency,c=e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed1.quotient:e.expectedCurrencyOwed0.quotient;r.push(gt.encodeUnwrapWETH9(e.expectedCurrencyOwed0.currency.isNative?e.expectedCurrencyOwed0.quotient:e.expectedCurrencyOwed1.quotient,a)),r.push(gt.encodeSweepToken(u,c,a))}return r},t.collectCallParameters=function(e){var n=t.encodeCollect(e);return{calldata:kt.encodeMulticall(n),value:Z(0)}},t.removeCallParameters=function(e,o){var a=[],u=Z(o.deadline),c=Z(o.tokenId),s=new mt({pool:e.pool,liquidity:o.liquidityPercentage.multiply(e.liquidity).quotient,tickLower:e.tickLower,tickUpper:e.tickUpper});r.greaterThan(s.liquidity,P)||i(!1);var p=s.burnAmountsWithSlippage(o.slippageTolerance),l=p.amount0,d=p.amount1;o.permit&&a.push(t.INTERFACE.encodeFunctionData("permit",[n.validateAndParseAddress(o.permit.spender),c,Z(o.permit.deadline),o.permit.v,o.permit.r,o.permit.s])),a.push(t.INTERFACE.encodeFunctionData("decreaseLiquidity",[{tokenId:c,liquidity:Z(s.liquidity),amount0Min:Z(l),amount1Min:Z(d),deadline:u}]));var f=o.collectOptions,m=f.expectedCurrencyOwed0,h=f.expectedCurrencyOwed1,v=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}(f,Tt);return a.push.apply(a,t.encodeCollect(T({tokenId:Z(o.tokenId),expectedCurrencyOwed0:m.add(n.CurrencyAmount.fromRawAmount(m.currency,l)),expectedCurrencyOwed1:h.add(n.CurrencyAmount.fromRawAmount(h.currency,d))},v))),o.liquidityPercentage.equalTo(C)?o.burnToken&&a.push(t.INTERFACE.encodeFunctionData("burn",[c])):!0===o.burnToken&&i(!1),{calldata:kt.encodeMulticall(a),value:Z(0)}},t.safeTransferFromParameters=function(e){var r=n.validateAndParseAddress(e.recipient),i=n.validateAndParseAddress(e.sender);return{calldata:e.data?t.INTERFACE.encodeFunctionData("safeTransferFrom(address,address,uint256,bytes)",[i,r,Z(e.tokenId),e.data]):t.INTERFACE.encodeFunctionData("safeTransferFrom(address,address,uint256)",[i,r,Z(e.tokenId)]),value:Z(0)}},t}();wt.INTERFACE=new o.Interface(s.abi);var qt=function(){function t(){}return t.quoteCallParameters=function(t,e,r,o){void 0===o&&(o={});var a,u=1===t.pools.length,c=Z(e.quotient),s=o.useQuoterV2?this.V2INTERFACE:this.V1INTERFACE;if(u){var p,l,d={tokenIn:t.tokenPath[0].address,tokenOut:t.tokenPath[1].address,fee:t.pools[0].fee,sqrtPriceLimitX96:Z(null!=(p=null==(l=o)?void 0:l.sqrtPriceLimitX96)?p:0)},f=T({},d,r==n.TradeType.EXACT_INPUT?{amountIn:c}:{amount:c});a=s.encodeFunctionData(r===n.TradeType.EXACT_INPUT?"quoteExactInputSingle":"quoteExactOutputSingle",o.useQuoterV2?[f]:[d.tokenIn,d.tokenOut,d.fee,c,d.sqrtPriceLimitX96])}else{var m;void 0!==(null==(m=o)?void 0:m.sqrtPriceLimitX96)&&i(!1);var h=$(t,r===n.TradeType.EXACT_OUTPUT);a=s.encodeFunctionData(r===n.TradeType.EXACT_INPUT?"quoteExactInput":"quoteExactOutput",[h,c])}return{calldata:a,value:Z(0)}},t}();qt.V1INTERFACE=new o.Interface(f.abi),qt.V2INTERFACE=new o.Interface(d.abi);var bt=function(){function t(){}return t.encodeClaim=function(e,r){var i,o=[];o.push(t.INTERFACE.encodeFunctionData("unstakeToken",[this._encodeIncentiveKey(e),Z(r.tokenId)]));var a=n.validateAndParseAddress(r.recipient),u=null!=(i=r.amount)?i:0;return o.push(t.INTERFACE.encodeFunctionData("claimReward",[e.rewardToken.address,a,Z(u)])),o},t.collectRewards=function(e,n){e=Array.isArray(e)?e:[e];for(var r=[],i=0;i<e.length;i++){var o=e[i];(r=r.concat(this.encodeClaim(o,n))).push(t.INTERFACE.encodeFunctionData("stakeToken",[this._encodeIncentiveKey(o),Z(n.tokenId)]))}return{calldata:kt.encodeMulticall(r),value:Z(0)}},t.withdrawToken=function(e,r){var i=[];e=Array.isArray(e)?e:[e];for(var o={tokenId:r.tokenId,recipient:r.recipient,amount:r.amount},a=0;a<e.length;a++)i=i.concat(this.encodeClaim(e[a],o));var u=n.validateAndParseAddress(r.owner);return i.push(t.INTERFACE.encodeFunctionData("withdrawToken",[Z(r.tokenId),u,r.data?r.data:Z(0)])),{calldata:kt.encodeMulticall(i),value:Z(0)}},t.encodeDeposit=function(e){var n;if((e=Array.isArray(e)?e:[e]).length>1){for(var r=[],i=0;i<e.length;i++)r.push(this._encodeIncentiveKey(e[i]));n=o.defaultAbiCoder.encode([t.INCENTIVE_KEY_ABI+"[]"],[r])}else n=o.defaultAbiCoder.encode([t.INCENTIVE_KEY_ABI],[this._encodeIncentiveKey(e[0])]);return n},t._encodeIncentiveKey=function(t){var e=t.pool,r=e.token0,i=e.token1,o=e.fee,a=n.validateAndParseAddress(t.refundee);return{rewardToken:t.rewardToken.address,pool:ft.getAddress(r,i,o),startTime:Z(t.startTime),endTime:Z(t.endTime),refundee:a}},t}();bt.INTERFACE=new o.Interface(m.abi),bt.INCENTIVE_KEY_ABI="tuple(address rewardToken, address pool, uint256 startTime, uint256 endTime, address refundee)";var Et=function(){function t(){}return t.swapCallParameters=function(e,r){Array.isArray(e)||(e=[e]);var o=e[0],a=o.inputAmount.currency.wrapped,u=o.outputAmount.currency.wrapped;e.every((function(t){return t.inputAmount.currency.wrapped.equals(a)}))||i(!1),e.every((function(t){return t.outputAmount.currency.wrapped.equals(u)}))||i(!1);var c=