@thenafi/v3-sdk
Version:
⚒️ An SDK for building applications on top of Thena V3 Fusion
3 lines (2 loc) • 41.4 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=require("thena-sdk-core"),n=t(require("jsbi")),r=t(require("tiny-invariant")),i=require("@ethersproject/abi"),o=require("@ethersproject/address"),u=require("@ethersproject/solidity");function a(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 c(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function u(t){a(o,r,i,u,c,"next",t)}function c(t){a(o,r,i,u,c,"throw",t)}u(void 0)}))}}function s(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function p(t,e,n){return e&&s(t.prototype,e),n&&s(t,n),t}function l(){return(l=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 h(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function f(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return h(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)?h(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 d,m,g,k,v=(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 l?e:l).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=A(u,n);if(a){if(a===p)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if("suspendedStart"===r)throw r="completed",n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);r="executing";var c=s(t,e,n);if("normal"===c.type){if(r=n.done?"completed":"suspendedYield",c.arg===p)continue;return{value:c.arg,done:n.done}}"throw"===c.type&&(r="completed",n.method="throw",n.arg=c.arg)}}}(t,n,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 p={};function l(){}function h(){}function f(){}var d={};d[i]=function(){return this};var m=Object.getPrototypeOf,g=m&&m(m(q([])));g&&g!==e&&n.call(g,i)&&(d=g);var k=f.prototype=l.prototype=Object.create(d);function v(t){["next","throw","return"].forEach((function(e){a(t,e,(function(t){return this._invoke(e,t)}))}))}function y(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 p=c.arg,l=p.value;return l&&"object"==typeof l&&n.call(l,"__await")?e.resolve(l.__await).then((function(t){r("next",t,u,a)}),(function(t){r("throw",t,u,a)})):e.resolve(l).then((function(t){p.value=t,u(p)}),(function(t){return r("throw",t,u,a)}))}a(c.arg)}(i,o,r,u)}))}return r=r?r.then(u,u):u()}}function A(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,A(t,e),"throw"===e.method))return p;e.method="throw",e.arg=new TypeError("The iterator does not provide a 'throw' method")}return p}var r=s(n,t.iterator,e.arg);if("throw"===r.type)return e.method="throw",e.arg=r.arg,e.delegate=null,p;var 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,p):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,p)}function x(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function T(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 q(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:I}}function I(){return{value:void 0,done:!0}}return h.prototype=k.constructor=f,f.constructor=h,h.displayName=a(f,u,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===h||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,f):(t.__proto__=f,a(t,u,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},v(y.prototype),y.prototype[o]=function(){return this},t.AsyncIterator=y,t.async=function(e,n,r,i,o){void 0===o&&(o=Promise);var u=new y(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=q,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(T),!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,p):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),p},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.finallyLoc===t)return this.complete(n.completion,n.afterLoc),T(n),p}},catch:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var n=this.tryEntries[e];if(n.tryLoc===t){var r=n.completion;if("throw"===r.type){var i=r.arg;T(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(t,e,n){return this.delegate={iterator:q(t),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=void 0),p}},t}(t.exports);try{regeneratorRuntime=e}catch(t){Function("r","regeneratorRuntime = r")(e)}}(k={exports:{}}),k.exports),y=((d={})[e.ChainId.BSC]="0x06852dC9D6E44782Dd02994C368feBc4dC1b8a17",d[e.ChainId.OPBNB]="0x306F06C147f064A010530292A1EB6737c3e378e4",d),A=((m={})[e.ChainId.BSC]="0xb3fc09be5eb433d99b1ec89fd8435aaf5ffea75c1879e19028aa2414a14b3c85",m[e.ChainId.OPBNB]="0xc65e01e65f37c1ec2735556a24a9c10e4c33b2613ad486dd8209d465524bc3f4",m),x="0x0000000000000000000000000000000000000000";(g=exports.FeeAmount||(exports.FeeAmount={}))[g.LOWEST=100]="LOWEST",g[g.LOW=500]="LOW",g[g.MEDIUM=3e3]="MEDIUM",g[g.HIGH=1e4]="HIGH";var T=n.BigInt(-1),w=n.BigInt(0),q=n.BigInt(1),I=n.exponentiate(n.BigInt(2),n.BigInt(96)),b=n.exponentiate(I,n.BigInt(2));function R(t){var e=t.tokenA,n=t.tokenB,r=e.sortsBefore(n)?[e,n]:[n,e];return o.getCreate2Address(y[e.chainId],u.keccak256(["bytes"],[i.defaultAbiCoder.encode(["address","address"],[r[0].address,r[1].address])]),A[e.chainId])}var S=function(){function t(){}return t.addDelta=function(t,e){return n.lessThan(e,w)?n.subtract(t,n.multiply(e,T)):n.add(t,e)},t}(),P=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),w)&&(o=n.add(o,q)),o},t}(),O=n.subtract(n.exponentiate(n.BigInt(2),n.BigInt(160)),q);function _(t,r){var i=n.multiply(t,r);return n.bitwiseAnd(i,e.MaxUint256)}var C=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?P.mulDivRoundingUp(P.mulDivRoundingUp(u,a,e),q,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?P.mulDivRoundingUp(r,n.subtract(e,t),I):n.divide(n.multiply(r,n.subtract(e,t)),I)},t.getNextSqrtPriceFromInput=function(t,e,i,o){return n.greaterThan(t,w)||r(!1),n.greaterThan(e,w)||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,w)||r(!1),n.greaterThan(e,w)||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,w))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=(l=n.add(a,c),n.bitwiseAnd(l,e.MaxUint256));if(n.greaterThanOrEqual(s,a))return P.mulDivRoundingUp(a,t,s)}return P.mulDivRoundingUp(a,q,n.add(n.divide(a,t),o))}var p=_(o,t);n.equal(n.divide(p,o),t)||r(!1),n.greaterThan(a,p)||r(!1);var l,h=n.subtract(a,p);return P.mulDivRoundingUp(a,t,h)},t.getNextSqrtPriceFromAmount1RoundingDown=function(t,e,i,o){if(o){var u=n.lessThanOrEqual(i,O)?n.divide(n.leftShift(i,n.BigInt(96)),e):n.divide(n.multiply(i,I),e);return n.add(t,u)}var a=P.mulDivRoundingUp(i,I,e);return n.greaterThan(t,a)||r(!1),n.subtract(t,a)},t}(),E=n.exponentiate(n.BigInt(10),n.BigInt(6)),B=function(){function t(){}return t.computeSwapStep=function(t,e,r,i,o){var u={},a=n.greaterThanOrEqual(t,e),c=n.greaterThanOrEqual(i,w);if(c){var s=n.divide(n.multiply(i,n.subtract(E,n.BigInt(o))),E);u.amountIn=a?C.getAmount0Delta(e,t,r,!0):C.getAmount1Delta(t,e,r,!0),u.sqrtRatioNextX96=n.greaterThanOrEqual(s,u.amountIn)?e:C.getNextSqrtPriceFromInput(t,r,s,a)}else u.amountOut=a?C.getAmount1Delta(e,t,r,!1):C.getAmount0Delta(t,e,r,!1),u.sqrtRatioNextX96=n.greaterThanOrEqual(n.multiply(i,T),u.amountOut)?e:C.getNextSqrtPriceFromOutput(t,r,n.multiply(i,T),a);var p=n.equal(e,u.sqrtRatioNextX96);return a?(u.amountIn=p&&c?u.amountIn:C.getAmount0Delta(u.sqrtRatioNextX96,t,r,!0),u.amountOut=p&&!c?u.amountOut:C.getAmount1Delta(u.sqrtRatioNextX96,t,r,!1)):(u.amountIn=p&&c?u.amountIn:C.getAmount1Delta(t,u.sqrtRatioNextX96,r,!0),u.amountOut=p&&!c?u.amountOut:C.getAmount0Delta(t,u.sqrtRatioNextX96,r,!1)),!c&&n.greaterThan(u.amountOut,n.multiply(i,T))&&(u.amountOut=n.multiply(i,T)),u.feeAmount=c&&n.notEqual(u.sqrtRatioNextX96,e)?n.subtract(i,u.amountIn):P.mulDivRoundingUp(u.amountIn,n.BigInt(o),n.subtract(E,n.BigInt(o))),[u.sqrtRatioNextX96,u.amountIn,u.amountOut,u.feeAmount]},t}(),N=n.BigInt(2),L=[128,64,32,16,8,4,2,1].map((function(t){return[t,n.exponentiate(N,n.BigInt(t))]}));function X(t){n.greaterThan(t,w)||r(!1),n.lessThanOrEqual(t,e.MaxUint256)||r(!1);for(var i,o=0,u=f(L);!(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 U(t,e){return n.signedRightShift(n.multiply(t,n.BigInt(e)),n.BigInt(128))}var M=n.exponentiate(n.BigInt(2),n.BigInt(32)),D=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=U(u,"0xfff97272373d413259a46990580e213a")),0!=(4&o)&&(u=U(u,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&o)&&(u=U(u,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&o)&&(u=U(u,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&o)&&(u=U(u,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&o)&&(u=U(u,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&o)&&(u=U(u,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&o)&&(u=U(u,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&o)&&(u=U(u,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&o)&&(u=U(u,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&o)&&(u=U(u,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&o)&&(u=U(u,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&o)&&(u=U(u,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&o)&&(u=U(u,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&o)&&(u=U(u,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&o)&&(u=U(u,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&o)&&(u=U(u,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&o)&&(u=U(u,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&o)&&(u=U(u,"0x48a170391f7dc42444e8fa2")),i>0&&(u=n.divide(e.MaxUint256,u)),n.greaterThan(n.remainder(u,M),w)?n.add(n.divide(u,M),q):n.divide(u,M)},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=X(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 p=n.multiply(a,n.BigInt("255738958999603826347141")),l=n.toNumber(n.signedRightShift(n.subtract(p,n.BigInt("3402992956809132418596140100660247210")),n.BigInt(128))),h=n.toNumber(n.signedRightShift(n.add(p,n.BigInt("291339464771989622907027621153398088495")),n.BigInt(128)));return l===h?l:n.lessThanOrEqual(t.getSqrtRatioAtTick(h),e)?h:l},t}();D.MIN_TICK=-887272,D.MAX_TICK=-D.MIN_TICK,D.MIN_SQRT_RATIO=n.BigInt("4295128739"),D.MAX_SQRT_RATIO=n.BigInt("1461446703485210103287273052203988822378723970342");var F=function(){function t(){}var e=t.prototype;return e.getTick=function(){var e=c(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=c(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 G(t,e){for(var n=0;n<t.length-1;n++)if(e(t[n],t[n+1])>0)return!1;return!0}function j(t,e){return t.index-e.index}F.ERROR_MESSAGE="No tick data provider was given";var K=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)}),w),w)||r(!1),G(t,j)||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)-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 W(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 Q(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),I);return n.divide(n.multiply(n.BigInt(r),o),n.subtract(e,t))}function z(t,e,r){if(n.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var o=n.multiply(n.multiply(n.BigInt(r),t),e),u=n.multiply(I,n.subtract(e,t));return n.divide(o,u)}function H(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),I),n.subtract(e,t))}function Y(t,e,r,i,o,u){if(n.greaterThan(e,r)){var a=[r,e];e=a[0],r=a[1]}var c=u?z:Q;if(n.lessThanOrEqual(t,e))return c(e,r,i);if(n.lessThan(t,r)){var s=c(t,r,i),p=H(e,t,o);return n.lessThan(s,p)?s:p}return H(e,r,o)}var Z=n.exponentiate(n.BigInt(2),n.BigInt(128)),$=function(){function t(){}return t.getTokensOwed=function(t,e,r,i,o){return[n.divide(n.multiply(tt(i,t),r),Z),n.divide(n.multiply(tt(o,e),r),Z)]},t}();function J(t,r,i){var o=D.getSqrtRatioAtTick(i),u=n.multiply(o,o);return t.sortsBefore(r)?new e.Price(t,r,b,u):new e.Price(t,r,u,b)}var V=n.exponentiate(n.BigInt(2),n.BigInt(256));function tt(t,e){var r=n.subtract(t,e);return n.lessThan(r,w)?n.add(V,r):r}var et=function(){function t(){}return t.getFeeGrowthInside=function(t,e,n,r,i,o,u){var a,c,s,p;return i>=n?(a=t.feeGrowthOutside0X128,c=t.feeGrowthOutside1X128):(a=tt(o,t.feeGrowthOutside0X128),c=tt(u,t.feeGrowthOutside1X128)),i<r?(s=e.feeGrowthOutside0X128,p=e.feeGrowthOutside1X128):(s=tt(o,e.feeGrowthOutside0X128),p=tt(u,e.feeGrowthOutside1X128)),[tt(tt(o,a),s),tt(tt(u,c),p)]},t}(),nt=function(t){var e=t.index,i=t.liquidityGross,o=t.liquidityNet;e>=D.MIN_TICK&&e<=D.MAX_TICK||r(!1),this.index=e,this.liquidityGross=n.BigInt(i),this.liquidityNet=n.BigInt(o)},rt=function(){function t(t,e){var n=t.map((function(t){return t instanceof nt?t:new nt(t)}));K.validateList(n,e),this.ticks=n}var e=t.prototype;return e.getTick=function(){var t=c(v.mark((function t(e){return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",K.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=c(v.mark((function t(e,n,r){return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",K.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}(),it=new F,ot=function(){function t(t,e,i,o,u,a,c,s){void 0===s&&(s=it),Number.isInteger(i)&&i<1e6||r(!1);var p=D.getSqrtRatioAtTick(a),l=D.getSqrtRatioAtTick(a+1);n.greaterThanOrEqual(n.BigInt(o),p)&&n.lessThanOrEqual(n.BigInt(o),l)||r(!1);var h=t.sortsBefore(e)?[t,e]:[e,t];this.token0=h[0],this.token1=h[1],this.fee=i,this.sqrtRatioX96=n.BigInt(o),this.liquidity=n.BigInt(u),this.tickCurrent=a,this.tickSpacing=null!=c?c:60,this.tickDataProvider=Array.isArray(s)?new rt(s,this.tickSpacing):s}t.getAddress=function(t,e){return R({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=c(v.mark((function i(o,u){var a,c,s,p,l;return v.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return this.involvesToken(o.currency)||r(!1),a=o.currency.equals(this.token0),i.next=4,this.swap(a,o.quotient,u);case 4:return s=(c=i.sent).sqrtRatioX96,p=c.liquidity,l=c.tickCurrent,i.abrupt("return",[e.CurrencyAmount.fromRawAmount(a?this.token1:this.token0,n.multiply(c.amountCalculated,T)),new t(this.token0,this.token1,this.fee,s,p,l,this.tickSpacing,this.tickDataProvider)]);case 11:case"end":return i.stop()}}),i,this)})));return function(t,e){return i.apply(this,arguments)}}(),i.getInputAmount=function(){var i=c(v.mark((function i(o,u){var a,c,s,p,l;return v.wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return o.currency.isToken&&this.involvesToken(o.currency)||r(!1),a=o.currency.equals(this.token1),i.next=4,this.swap(a,n.multiply(o.quotient,T),u);case 4:return s=(c=i.sent).sqrtRatioX96,p=c.liquidity,l=c.tickCurrent,i.abrupt("return",[e.CurrencyAmount.fromRawAmount(a?this.token0:this.token1,c.amountCalculated),new t(this.token0,this.token1,this.fee,s,p,l,this.tickSpacing,this.tickDataProvider)]);case 11:case"end":return i.stop()}}),i,this)})));return function(t,e){return i.apply(this,arguments)}}(),i.swap=function(){var t=c(v.mark((function t(e,i,o){var u,a,c,s,p,l;return v.wrap((function(t){for(;;)switch(t.prev=t.next){case 0:o||(o=e?n.add(D.MIN_SQRT_RATIO,q):n.subtract(D.MAX_SQRT_RATIO,q)),e?(n.greaterThan(o,D.MIN_SQRT_RATIO)||r(!1),n.lessThan(o,this.sqrtRatioX96)||r(!1)):(n.lessThan(o,D.MAX_SQRT_RATIO)||r(!1),n.greaterThan(o,this.sqrtRatioX96)||r(!1)),u=n.greaterThanOrEqual(i,w),a={amountSpecifiedRemaining:i,amountCalculated:w,sqrtPriceX96:this.sqrtRatioX96,tick:this.tickCurrent,liquidity:this.liquidity};case 4:if(!n.notEqual(a.amountSpecifiedRemaining,w)||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<D.MIN_TICK?c.tickNext=D.MIN_TICK:c.tickNext>D.MAX_TICK&&(c.tickNext=D.MAX_TICK),c.sqrtPriceNextX96=D.getSqrtRatioAtTick(c.tickNext),p=B.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=p[0],c.amountIn=p[1],c.amountOut=p[2],c.feeAmount=p[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,l=t.t0.BigInt.call(t.t0,t.t1),e&&(l=n.multiply(l,T)),a.liquidity=S.addDelta(a.liquidity,l);case 29:a.tick=e?c.tickNext-1:c.tickNext,t.next=33;break;case 32:n.notEqual(a.sqrtPriceX96,c.sqrtPriceStartX96)&&(a.tick=D.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)}}(),p(t,[{key:"token0Price",get:function(){var t;return null!=(t=this._token0Price)?t:this._token0Price=new e.Price(this.token0,this.token1,b,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),b)}},{key:"chainId",get:function(){return this.token0.chainId}}]),t}(),ut=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>=D.MIN_TICK&&o%e.tickSpacing==0||r(!1),u<=D.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.ratiosAfterSlippage=function(t){var r=this.pool.token0Price.asFraction.multiply(new e.Percent(1).subtract(t)),i=this.pool.token0Price.asFraction.multiply(t.add(1)),o=W(r.numerator,r.denominator);n.lessThanOrEqual(o,D.MIN_SQRT_RATIO)&&(o=n.add(D.MIN_SQRT_RATIO,n.BigInt(1)));var u=W(i.numerator,i.denominator);return n.greaterThanOrEqual(u,D.MAX_SQRT_RATIO)&&(u=n.subtract(D.MAX_SQRT_RATIO,n.BigInt(1))),{sqrtRatioX96Lower:o,sqrtRatioX96Upper:u}},i.mintAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new ot(this.pool.token0,this.pool.token1,this.pool.fee,i,0,D.getTickAtSqrtRatio(i),this.pool.tickSpacing),u=new ot(this.pool.token0,this.pool.token1,this.pool.fee,r,0,D.getTickAtSqrtRatio(r),this.pool.tickSpacing),a=t.fromAmounts(l({pool:this.pool,tickLower:this.tickLower,tickUpper:this.tickUpper},this.mintAmounts,{useFullPrecision:!1}));return{amount0:new t({pool:u,liquidity:a.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:new t({pool:o,liquidity:a.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount1}},i.burnAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new ot(this.pool.token0,this.pool.token1,this.pool.fee,i,0,D.getTickAtSqrtRatio(i),this.pool.tickSpacing),u=new t({pool:new ot(this.pool.token0,this.pool.token1,this.pool.fee,r,0,D.getTickAtSqrtRatio(r),this.pool.tickSpacing),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,a=new t({pool:o,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:u.quotient,amount1:a.quotient}},t.fromAmounts=function(e){var n=e.pool,r=e.tickLower,i=e.tickUpper,o=e.amount0,u=e.amount1,a=e.useFullPrecision,c=D.getSqrtRatioAtTick(r),s=D.getSqrtRatioAtTick(i);return new t({pool:n,tickLower:r,tickUpper:i,liquidity:Y(n.sqrtRatioX96,c,s,o,u,a)})},t.fromAmount0=function(n){return t.fromAmounts({pool:n.pool,tickLower:n.tickLower,tickUpper:n.tickUpper,amount0:n.amount0,amount1:e.MaxUint256,useFullPrecision:n.useFullPrecision})},t.fromAmount1=function(n){return t.fromAmounts({pool:n.pool,tickLower:n.tickLower,tickUpper:n.tickUpper,amount0:e.MaxUint256,amount1:n.amount1,useFullPrecision:!0})},p(t,[{key:"token0PriceLower",get:function(){return J(this.pool.token0,this.pool.token1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return J(this.pool.token0,this.pool.token1,this.tickUpper)}},{key:"amount0",get:function(){return null===this._token0Amount&&(this._token0Amount=e.CurrencyAmount.fromRawAmount(this.pool.token0,this.pool.tickCurrent<this.tickLower?C.getAmount0Delta(D.getSqrtRatioAtTick(this.tickLower),D.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):this.pool.tickCurrent<this.tickUpper?C.getAmount0Delta(this.pool.sqrtRatioX96,D.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):w)),this._token0Amount}},{key:"amount1",get:function(){return null===this._token1Amount&&(this._token1Amount=e.CurrencyAmount.fromRawAmount(this.pool.token1,this.pool.tickCurrent<this.tickLower?w:C.getAmount1Delta(D.getSqrtRatioAtTick(this.tickLower),this.pool.tickCurrent<this.tickUpper?this.pool.sqrtRatioX96:D.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1))),this._token1Amount}},{key:"mintAmounts",get:function(){return null===this._mintAmounts?this.pool.tickCurrent<this.tickLower?{amount0:C.getAmount0Delta(D.getSqrtRatioAtTick(this.tickLower),D.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:w}:this.pool.tickCurrent<this.tickUpper?{amount0:C.getAmount0Delta(this.pool.sqrtRatioX96,D.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:C.getAmount1Delta(D.getSqrtRatioAtTick(this.tickLower),this.pool.sqrtRatioX96,this.liquidity,!0)}:{amount0:w,amount1:C.getAmount1Delta(D.getSqrtRatioAtTick(this.tickLower),D.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0)}:this._mintAmounts}}]),t}(),at=function(){function t(t,e,n){this._midPrice=null,t.length>0||r(!1);var i=t[0].chainId;t.every((function(t){return t.chainId===i}))||r(!1);var o=e.wrapped;t[0].involvesToken(o)||r(!1),t[t.length-1].involvesToken(n.wrapped)||r(!1);for(var u,a=[o],c=f(t.entries());!(u=c()).done;){var s=u.value,p=s[1],l=a[s[0]];l.equals(p.token0)||l.equals(p.token1)||r(!1);var h=l.equals(p.token0)?p.token1:p.token0;a.push(h)}this.pools=t,this.tokenPath=a,this.input=e,this.output=null!=n?n:a[a.length-1]}return p(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,e){var n=t.price;return t.nextInput.equals(e.token0)?{nextInput:e.token1,price:n.multiply(e.token0Price)}:{nextInput:e.token0,price:n.multiply(e.token1Price)}}),this.pools[0].token0.equals(this.input.wrapped)?{nextInput:this.pools[0].token1,price:this.pools[0].token0Price}:{nextInput:this.pools[0].token0,price:this.pools[0].token1Price}).price;return this._midPrice=new e.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function ct(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||r(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||r(!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 st=function(){function t(t){var e=t.routes,n=t.tradeType,i=e[0].inputAmount.currency,o=e[0].outputAmount.currency;e.every((function(t){return i.wrapped.equals(t.route.input.wrapped)}))||r(!1),e.every((function(t){return o.wrapped.equals(t.route.output.wrapped)}))||r(!1);for(var u,a=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),c=new Set,s=f(e);!(u=s()).done;)for(var p,l=f(u.value.route.pools);!(p=l()).done;){var h=p.value;c.add(ot.getAddress(h.token0,h.token1))}a!=c.size&&r(!1),this.swaps=e,this.tradeType=n}t.exactIn=function(){var n=c(v.mark((function n(r,i){return v.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=c(v.mark((function n(r,i){return v.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=c(v.mark((function n(i,o,u){var a,c,s,p,l,h,f;return v.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=19;break}o.currency.equals(i.input)||r(!1),a[0]=o.wrapped,p=0;case 5:if(!(p<i.tokenPath.length-1)){n.next=15;break}return l=i.pools[p],n.next=9,l.getOutputAmount(a[p]);case 9:a[p+1]=n.sent[0];case 12:p++,n.next=5;break;case 15:c=e.CurrencyAmount.fromFractionalAmount(i.input,o.numerator,o.denominator),s=e.CurrencyAmount.fromFractionalAmount(i.output,a[a.length-1].numerator,a[a.length-1].denominator),n.next=34;break;case 19:o.currency.equals(i.output)||r(!1),a[a.length-1]=o.wrapped,h=i.tokenPath.length-1;case 22:if(!(h>0)){n.next=32;break}return f=i.pools[h-1],n.next=26,f.getInputAmount(a[h]);case 26:a[h-1]=n.sent[0];case 29:h--,n.next=22;break;case 32:c=e.CurrencyAmount.fromFractionalAmount(i.input,a[0].numerator,a[0].denominator),s=e.CurrencyAmount.fromFractionalAmount(i.output,o.numerator,o.denominator);case 34:return n.abrupt("return",new t({routes:[{inputAmount:c,outputAmount:s,route:i}],tradeType:u}));case 35:case"end":return n.stop()}}),n)})));return function(t,e,r){return n.apply(this,arguments)}}(),t.fromRoutes=function(){var n=c(v.mark((function n(i,o){var u,a,c,s,p,l,h,d,m,g,k,y,A;return v.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:u=[],a=f(i);case 2:if((c=a()).done){n.next=43;break}if(p=(s=c.value).route,l=s.amount,h=new Array(p.tokenPath.length),d=void 0,m=void 0,o!==e.TradeType.EXACT_INPUT){n.next=25;break}l.currency.equals(p.input)||r(!1),d=e.CurrencyAmount.fromFractionalAmount(p.input,l.numerator,l.denominator),h[0]=e.CurrencyAmount.fromFractionalAmount(p.input.wrapped,l.numerator,l.denominator),g=0;case 12:if(!(g<p.tokenPath.length-1)){n.next=22;break}return k=p.pools[g],n.next=16,k.getOutputAmount(h[g]);case 16:h[g+1]=n.sent[0];case 19:g++,n.next=12;break;case 22:m=e.CurrencyAmount.fromFractionalAmount(p.output,h[h.length-1].numerator,h[h.length-1].denominator),n.next=40;break;case 25:l.currency.equals(p.output)||r(!1),m=e.CurrencyAmount.fromFractionalAmount(p.output,l.numerator,l.denominator),h[h.length-1]=e.CurrencyAmount.fromFractionalAmount(p.output.wrapped,l.numerator,l.denominator),y=p.tokenPath.length-1;case 29:if(!(y>0)){n.next=39;break}return A=p.pools[y-1],n.next=33,A.getInputAmount(h[y]);case 33:h[y-1]=n.sent[0];case 36:y--,n.next=29;break;case 39:d=e.CurrencyAmount.fromFractionalAmount(p.input,h[0].numerator,h[0].denominator);case 40:u.push({route:p,inputAmount:d,outputAmount:m});case 41:n.next=2;break;case 43:return n.abrupt("return",new t({routes:u,tradeType:o}));case 44:case"end":return n.stop()}}),n)})));return function(t,e){return n.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(l({},e,{routes:[{inputAmount:e.inputAmount,outputAmount:e.outputAmount,route:e.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(e){return new t(e)};var n=t.prototype;return n.minimumAmountOut=function(t,n){if(void 0===n&&(n=this.outputAmount),t.lessThan(w)&&r(!1),this.tradeType===e.TradeType.EXACT_OUTPUT)return n;var i=new e.Fraction(q).add(t).invert().multiply(n.quotient).quotient;return e.CurrencyAmount.fromRawAmount(n.currency,i)},n.maximumAmountIn=function(t,n){if(void 0===n&&(n=this.inputAmount),t.lessThan(w)&&r(!1),this.tradeType===e.TradeType.EXACT_INPUT)return n;var i=new e.Fraction(q).add(t).multiply(n.quotient).quotient;return e.CurrencyAmount.fromRawAmount(n.currency,i)},n.worstExecutionPrice=function(t){return new e.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var n=c(v.mark((function n(i,o,u,a,c,s,p){var l,h,f,d,m,g,k,y,A,x,T;return v.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:f=void 0===(h=(l=void 0===a?{}:a).maxNumResults)?3:h,m=void 0===(d=l.maxHops)?3:d,void 0===c&&(c=[]),void 0===s&&(s=o),void 0===p&&(p=[]),i.length>0||r(!1),m>0||r(!1),o===s||c.length>0||r(!1),g=s.wrapped,k=u.wrapped,y=0;case 10:if(!(y<i.length)){n.next=46;break}if((A=i[y]).token0.equals(g.currency)||A.token1.equals(g.currency)){n.next=14;break}return n.abrupt("continue",43);case 14:return x=void 0,n.prev=15,n.next=19,A.getOutputAmount(g);case 19:x=n.sent[0],n.next=28;break;case 23:if(n.prev=23,n.t0=n.catch(15),!n.t0.isInsufficientInputAmountError){n.next=27;break}return n.abrupt("continue",43);case 27:throw n.t0;case 28:if(!x.currency.isToken||!x.currency.equals(k)){n.next=39;break}return n.t1=e.sortedInsert,n.t2=p,n.next=33,t.fromRoute(new at([].concat(c,[A]),o.currency,u),o,e.TradeType.EXACT_INPUT);case 33:n.t3=n.sent,n.t4=f,n.t5=ct,(0,n.t1)(n.t2,n.t3,n.t4,n.t5),n.next=43;break;case 39:if(!(m>1&&i.length>1)){n.next=43;break}return T=i.slice(0,y).concat(i.slice(y+1,i.length)),n.next=43,t.bestTradeExactIn(T,o,u,{maxNumResults:f,maxHops:m-1},[].concat(c,[A]),x,p);case 43:y++,n.next=10;break;case 46:return n.abrupt("return",p);case 47:case"end":return n.stop()}}),n,null,[[15,23]])})));return function(t,e,r,i,o,u,a){return n.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var n=c(v.mark((function n(i,o,u,a,c,s,p){var l,h,f,d,m,g,k,y,A,x,T;return v.wrap((function(n){for(;;)switch(n.prev=n.next){case 0:f=void 0===(h=(l=void 0===a?{}:a).maxNumResults)?3:h,m=void 0===(d=l.maxHops)?3:d,void 0===c&&(c=[]),void 0===s&&(s=u),void 0===p&&(p=[]),i.length>0||r(!1),m>0||r(!1),u===s||c.length>0||r(!1),g=s.wrapped,k=o.wrapped,y=0;case 10:if(!(y<i.length)){n.next=46;break}if((A=i[y]).token0.equals(g.currency)||A.token1.equals(g.currency)){n.next=14;break}return n.abrupt("continue",43);case 14:return x=void 0,n.prev=15,n.next=19,A.getInputAmount(g);case 19:x=n.sent[0],n.next=28;break;case 23:if(n.prev=23,n.t0=n.catch(15),!n.t0.isInsufficientReservesError){n.next=27;break}return n.abrupt("continue",43);case 27:throw n.t0;case 28:if(!x.currency.equals(k)){n.next=39;break}return n.t1=e.sortedInsert,n.t2=p,n.next=33,t.fromRoute(new at([A].concat(c),o,u.currency),u,e.TradeType.EXACT_OUTPUT);case 33:n.t3=n.sent,n.t4=f,n.t5=ct,(0,n.t1)(n.t2,n.t3,n.t4,n.t5),n.next=43;break;case 39:if(!(m>1&&i.length>1)){n.next=43;break}return T=i.slice(0,y).concat(i.slice(y+1,i.length)),n.next=43,t.bestTradeExactOut(T,o,u,{maxNumResults:f,maxHops:m-1},[A].concat(c),x,p);case 43:y++,n.next=10;break;case 46:return n.abrupt("return",p);case 47:case"end":return n.stop()}}),n,null,[[15,23]])})));return function(t,e,r,i,o,u,a){return n.apply(this,arguments)}}(),p(t,[{key:"route",get:function(){return 1!=this.swaps.length&&r(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,n=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),e.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=n,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,n=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,e){return t.add(e)}),e.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=n,this._outputAmount}},{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.quotient,this.outputAmount.quotient)}},{key:"priceImpact",get:function(){if(this._priceImpact)return this._priceImpact;for(var t,n=e.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),r=f(this.swaps);!(t=r()).done;){var i=t.value;n=n.add(i.route.midPrice.quote(i.inputAmount))}var o=n.subtract(this.outputAmount).divide(n);return this._priceImpact=new e.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}();exports.ADDRESS_ZERO=x,exports.FACTORY_ADDRESS="0x30055F87716d3DFD0E5198C27024481099fB4A98",exports.FullMath=P,exports.LiquidityMath=S,exports.NoTickDataProvider=F,exports.POOL_DEPLOYER_ADDRESSES=y,exports.POOL_INIT_CODE_HASHES=A,exports.Pool=ot,exports.Position=ut,exports.PositionLibrary=$,exports.Route=at,exports.SqrtPriceMath=C,exports.SwapMath=B,exports.TICK_SPACING=60,exports.Tick=nt,exports.TickLibrary=et,exports.TickList=K,exports.TickListDataProvider=rt,exports.TickMath=D,exports.Trade=st,exports.computePoolAddress=R,exports.encodeRouteToPath=function(t,e){var n=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","address","address"],path:[r.address,x,u.address]}:{inputToken:u,types:[].concat(o,["address"]),path:[].concat(i,[u.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)},exports.encodeSqrtRatioX96=W,exports.isSorted=G,exports.maxLiquidityForAmounts=Y,exports.mostSignificantBit=X,exports.nearestUsableTick=function(t,e){Number.isInteger(t)&&Number.isInteger(e)||r(!1),e>0||r(!1),t>=D.MIN_TICK&&t<=D.MAX_TICK||r(!1);var n=Math.round(t/e)*e;return n<D.MIN_TICK?n+e:n>D.MAX_TICK?n-e:n},exports.priceToClosestTick=function(t){var e=t.baseCurrency.sortsBefore(t.quoteCurrency),n=e?W(t.numerator,t.denominator):W(t.denominator,t.numerator),r=D.getTickAtSqrtRatio(n),i=J(t.baseCurrency,t.quoteCurrency,r+1);return e?t.lessThan(i)||r++:t.greaterThan(i)||r++,r},exports.subIn256=tt,exports.tickToPrice=J,exports.toHex=function(t){var e=n.BigInt(t).toString(16);return e.length%2!=0&&(e="0"+e),"0x"+e},exports.tradeComparator=ct;
//# sourceMappingURL=v3-sdk.cjs.production.min.js.map