@basex-fi/sdk-core
Version:
An SDK for building applications on top of BaseX
1 lines • 79.5 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=t(require("big.js")),r=t(require("jsbi")),i=t(require("tiny-invariant")),a=t(require("toformat")),o=t(require("decimal.js-light")),u=require("@ethersproject/bignumber"),s=require("@ethersproject/address"),p=require("@ethersproject/abi"),c=require("@ethersproject/solidity"),d="0x4200000000000000000000000000000000000006",l="0xdC323d16C451819890805737997F4Ede96b95e3e",m="0x0000000000000000000000000000000000000000",y={v3CoreFactoryAddress:l,multicallAddress:"0x6D93fC5ae3c3f5a147Ed92E9CD738BF45D8a29BB",quoterAddress:"0x30FF944EaEc54a433B7283dA42C6A9c65e20038F",nonfungiblePositionManagerAddress:"0xe9e4346431c2006026720d1e03d33f12FabDbc3f",tickLensAddress:"0x6f07aF1F970789B5CF29134B6f4506D9774ce935",swapRouter02Address:"0x875f7D1A45C5f9D8deeb19bEe68f72fe4187e490"};function f(){f=function(){return e};var t,e={},n=Object.prototype,r=n.hasOwnProperty,i=Object.defineProperty||function(t,e,n){t[e]=n.value},a="function"==typeof Symbol?Symbol:{},o=a.iterator||"@@iterator",u=a.asyncIterator||"@@asyncIterator",s=a.toStringTag||"@@toStringTag";function p(t,e,n){return Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{p({},"")}catch(t){p=function(t,e,n){return t[e]=n}}function c(t,e,n,r){var a=Object.create((e&&e.prototype instanceof b?e:b).prototype),o=new O(r||[]);return i(a,"_invoke",{value:q(t,n,o)}),a}function d(t,e,n){try{return{type:"normal",arg:t.call(e,n)}}catch(t){return{type:"throw",arg:t}}}e.wrap=c;var l="suspendedStart",m="executing",y="completed",h={};function b(){}function T(){}function g(){}var v={};p(v,o,(function(){return this}));var k=Object.getPrototypeOf,x=k&&k(k(P([])));x&&x!==n&&r.call(x,o)&&(v=x);var A=g.prototype=b.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function I(t,e){function n(i,a,o,u){var s=d(t[i],t,a);if("throw"!==s.type){var p=s.arg,c=p.value;return c&&"object"==typeof c&&r.call(c,"__await")?e.resolve(c.__await).then((function(t){n("next",t,o,u)}),(function(t){n("throw",t,o,u)})):e.resolve(c).then((function(t){p.value=t,o(p)}),(function(t){return n("throw",t,o,u)}))}u(s.arg)}var a;i(this,"_invoke",{value:function(t,r){function i(){return new e((function(e,i){n(t,r,e,i)}))}return a=a?a.then(i,i):i()}})}function q(e,n,r){var i=l;return function(a,o){if(i===m)throw new Error("Generator is already running");if(i===y){if("throw"===a)throw o;return{value:t,done:!0}}for(r.method=a,r.arg=o;;){var u=r.delegate;if(u){var s=R(u,r);if(s){if(s===h)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(i===l)throw i=y,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=m;var p=d(e,n,r);if("normal"===p.type){if(i=r.done?y:"suspendedYield",p.arg===h)continue;return{value:p.arg,done:r.done}}"throw"===p.type&&(i=y,r.method="throw",r.arg=p.arg)}}}function R(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,R(e,n),"throw"===n.method)||"return"!==r&&(n.method="throw",n.arg=new TypeError("The iterator does not provide a '"+r+"' method")),h;var a=d(i,e.iterator,n.arg);if("throw"===a.type)return n.method="throw",n.arg=a.arg,n.delegate=null,h;var o=a.arg;return o?o.done?(n[e.resultName]=o.value,n.next=e.nextLoc,"return"!==n.method&&(n.method="next",n.arg=t),n.delegate=null,h):o:(n.method="throw",n.arg=new TypeError("iterator result is not an object"),n.delegate=null,h)}function E(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function S(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(E,this),this.reset(!0)}function P(e){if(e||""===e){var n=e[o];if(n)return n.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length)){var i=-1,a=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 a.next=a}}throw new TypeError(typeof e+" is not iterable")}return T.prototype=g,i(A,"constructor",{value:g,configurable:!0}),i(g,"constructor",{value:T,configurable:!0}),T.displayName=p(g,s,"GeneratorFunction"),e.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===T||"GeneratorFunction"===(e.displayName||e.name))},e.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,p(t,s,"GeneratorFunction")),t.prototype=Object.create(A),t},e.awrap=function(t){return{__await:t}},w(I.prototype),p(I.prototype,u,(function(){return this})),e.AsyncIterator=I,e.async=function(t,n,r,i,a){void 0===a&&(a=Promise);var o=new I(c(t,n,r,i),a);return e.isGeneratorFunction(n)?o:o.next().then((function(t){return t.done?t.value:o.next()}))},w(A),p(A,s,"Generator"),p(A,o,(function(){return this})),p(A,"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=P,O.prototype={constructor:O,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(S),!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 a=this.tryEntries.length-1;a>=0;--a){var o=this.tryEntries[a],u=o.completion;if("root"===o.tryLoc)return i("end");if(o.tryLoc<=this.prev){var s=r.call(o,"catchLoc"),p=r.call(o,"finallyLoc");if(s&&p){if(this.prev<o.catchLoc)return i(o.catchLoc,!0);if(this.prev<o.finallyLoc)return i(o.finallyLoc)}else if(s){if(this.prev<o.catchLoc)return i(o.catchLoc,!0)}else{if(!p)throw new Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return i(o.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 a=i;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var o=a?a.completion:{};return o.type=t,o.arg=e,a?(this.method="next",this.next=a.finallyLoc,h):this.complete(o)},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),S(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;S(n)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:P(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),h}},e}function h(t,e,n,r,i,a,o){try{var u=t[a](o),s=u.value}catch(t){return void n(t)}u.done?e(s):Promise.resolve(s).then(r,i)}function b(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var a=t.apply(e,n);function o(t){h(a,r,i,o,u,"next",t)}function u(t){h(a,r,i,o,u,"throw",t)}o(void 0)}))}}function T(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 g(t,e,n){return e&&T(t.prototype,e),n&&T(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function v(){return(v=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 k(t,e){var n,r;t.prototype=Object.create(e.prototype),t.prototype.constructor=t,n=t,r=e,(Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(n,r)}function x(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 A(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 x(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)?x(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,I,q,R=r.BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");(w=exports.TradeType||(exports.TradeType={}))[w.EXACT_INPUT=0]="EXACT_INPUT",w[w.EXACT_OUTPUT=1]="EXACT_OUTPUT",(I=exports.Rounding||(exports.Rounding={}))[I.ROUND_DOWN=0]="ROUND_DOWN",I[I.ROUND_HALF_UP=1]="ROUND_HALF_UP",I[I.ROUND_UP=2]="ROUND_UP",(q=exports.FeeAmount||(exports.FeeAmount={}))[q.LOWEST=100]="LOWEST",q[q.LOW=500]="LOW",q[q.MEDIUM=3e3]="MEDIUM",q[q.HIGH=1e4]="HIGH";var E,S,O=((e={})[exports.FeeAmount.LOWEST]=1,e[exports.FeeAmount.LOW]=10,e[exports.FeeAmount.MEDIUM]=60,e[exports.FeeAmount.HIGH]=200,e),P=r.BigInt(-1),N=r.BigInt(0),_=r.BigInt(1),F=r.exponentiate(r.BigInt(2),r.BigInt(96)),D=r.exponentiate(F,r.BigInt(2)),C="0xe34f199b19b2b4f47f68442619d555527d244f78a3297ea89325f843f87b8b54",M=a(o),U=a(n),B=((E={})[exports.Rounding.ROUND_DOWN]=M.ROUND_DOWN,E[exports.Rounding.ROUND_HALF_UP]=M.ROUND_HALF_UP,E[exports.Rounding.ROUND_UP]=M.ROUND_UP,E),L=((S={})[exports.Rounding.ROUND_DOWN]=0,S[exports.Rounding.ROUND_HALF_UP]=1,S[exports.Rounding.ROUND_UP]=3,S),X=function(){function t(t,e){void 0===e&&(e=r.BigInt(1)),this.numerator=r.BigInt(t),this.denominator=r.BigInt(e)}t.tryParseFraction=function(e){if(e instanceof r||"number"==typeof e||"string"==typeof e)return new t(e);if("numerator"in e&&"denominator"in e)return e;throw new Error("Could not parse fraction")};var e=t.prototype;return e.invert=function(){return new t(this.denominator,this.numerator)},e.add=function(e){var n=t.tryParseFraction(e);return r.equal(this.denominator,n.denominator)?new t(r.add(this.numerator,n.numerator),this.denominator):new t(r.add(r.multiply(this.numerator,n.denominator),r.multiply(n.numerator,this.denominator)),r.multiply(this.denominator,n.denominator))},e.subtract=function(e){var n=t.tryParseFraction(e);return r.equal(this.denominator,n.denominator)?new t(r.subtract(this.numerator,n.numerator),this.denominator):new t(r.subtract(r.multiply(this.numerator,n.denominator),r.multiply(n.numerator,this.denominator)),r.multiply(this.denominator,n.denominator))},e.lessThan=function(e){var n=t.tryParseFraction(e);return r.lessThan(r.multiply(this.numerator,n.denominator),r.multiply(n.numerator,this.denominator))},e.equalTo=function(e){var n=t.tryParseFraction(e);return r.equal(r.multiply(this.numerator,n.denominator),r.multiply(n.numerator,this.denominator))},e.greaterThan=function(e){var n=t.tryParseFraction(e);return r.greaterThan(r.multiply(this.numerator,n.denominator),r.multiply(n.numerator,this.denominator))},e.multiply=function(e){var n=t.tryParseFraction(e);return new t(r.multiply(this.numerator,n.numerator),r.multiply(this.denominator,n.denominator))},e.divide=function(e){var n=t.tryParseFraction(e);return new t(r.multiply(this.numerator,n.denominator),r.multiply(this.denominator,n.numerator))},e.toSignificant=function(t,e,n){void 0===e&&(e={groupSeparator:""}),void 0===n&&(n=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||i(!1),t>0||i(!1),M.set({precision:t+1,rounding:B[n]});var r=new M(this.numerator.toString()).div(this.denominator.toString()).toSignificantDigits(t);return r.toFormat(r.decimalPlaces(),e)},e.toFixed=function(t,e,n){return void 0===e&&(e={groupSeparator:""}),void 0===n&&(n=exports.Rounding.ROUND_HALF_UP),Number.isInteger(t)||i(!1),t>=0||i(!1),U.DP=t,U.RM=L[n],new U(this.numerator.toString()).div(this.denominator.toString()).toFormat(t,e)},g(t,[{key:"quotient",get:function(){return r.divide(this.numerator,this.denominator)}},{key:"remainder",get:function(){return new t(r.remainder(this.numerator,this.denominator),this.denominator)}},{key:"asFraction",get:function(){return new t(this.numerator,this.denominator)}}]),t}(),W=a(n),H=function(t){function e(e,n,a){var o;return o=t.call(this,n,a)||this,r.lessThanOrEqual(o.quotient,R)||i(!1),o.currency=e,o.decimalScale=r.exponentiate(r.BigInt(10),r.BigInt(e.decimals)),o}k(e,t),e.fromRawAmount=function(t,n){return new e(t,n)},e.fromFractionalAmount=function(t,n,r){return new e(t,n,r)};var n=e.prototype;return n.add=function(n){this.currency.equals(n.currency)||i(!1);var r=t.prototype.add.call(this,n);return e.fromFractionalAmount(this.currency,r.numerator,r.denominator)},n.subtract=function(n){this.currency.equals(n.currency)||i(!1);var r=t.prototype.subtract.call(this,n);return e.fromFractionalAmount(this.currency,r.numerator,r.denominator)},n.multiply=function(n){var r=t.prototype.multiply.call(this,n);return e.fromFractionalAmount(this.currency,r.numerator,r.denominator)},n.divide=function(n){var r=t.prototype.divide.call(this,n);return e.fromFractionalAmount(this.currency,r.numerator,r.denominator)},n.toSignificant=function(e,n,r){return void 0===e&&(e=6),void 0===r&&(r=exports.Rounding.ROUND_DOWN),t.prototype.divide.call(this,this.decimalScale).toSignificant(e,n,r)},n.toFixed=function(e,n,r){return void 0===e&&(e=this.currency.decimals),void 0===r&&(r=exports.Rounding.ROUND_DOWN),e<=this.currency.decimals||i(!1),t.prototype.divide.call(this,this.decimalScale).toFixed(e,n,r)},n.toExact=function(t){return void 0===t&&(t={groupSeparator:""}),W.DP=this.currency.decimals,new W(this.quotient.toString()).div(this.decimalScale.toString()).toFormat(t)},g(e,[{key:"wrapped",get:function(){return this.currency.isToken?this:e.fromFractionalAmount(this.currency.wrapped,this.numerator,this.denominator)}}]),e}(X),j=function(t){function e(){for(var e,n,i,a,o,u=arguments.length,s=new Array(u),p=0;p<u;p++)s[p]=arguments[p];if(4===s.length)n=s[0],i=s[1],a=s[2],o=s[3];else{var c=s[0].quoteAmount.divide(s[0].baseAmount),d=[s[0].baseAmount.currency,s[0].quoteAmount.currency,c.denominator,c.numerator];n=d[0],i=d[1],a=d[2],o=d[3]}return(e=t.call(this,o,a)||this).baseCurrency=n,e.quoteCurrency=i,e.scalar=new X(r.exponentiate(r.BigInt(10),r.BigInt(n.decimals)),r.exponentiate(r.BigInt(10),r.BigInt(i.decimals))),e}k(e,t);var n=e.prototype;return n.invert=function(){return new e(this.quoteCurrency,this.baseCurrency,this.numerator,this.denominator)},n.multiply=function(n){this.quoteCurrency.equals(n.baseCurrency)||i(!1);var r=t.prototype.multiply.call(this,n);return new e(this.baseCurrency,n.quoteCurrency,r.denominator,r.numerator)},n.quote=function(e){e.currency.equals(this.baseCurrency)||i(!1);var n=t.prototype.multiply.call(this,e);return H.fromFractionalAmount(this.quoteCurrency,n.numerator,n.denominator)},n.toSignificant=function(t,e,n){return void 0===t&&(t=6),this.adjustedForDecimals.toSignificant(t,e,n)},n.toFixed=function(t,e,n){return void 0===t&&(t=4),this.adjustedForDecimals.toFixed(t,e,n)},g(e,[{key:"adjustedForDecimals",get:function(){return t.prototype.multiply.call(this,this.scalar)}}]),e}(X),G=new X(r.BigInt(100));function K(t){return new Q(t.numerator,t.denominator)}var Q=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).isPercent=!0,e}k(e,t);var n=e.prototype;return n.add=function(e){return K(t.prototype.add.call(this,e))},n.subtract=function(e){return K(t.prototype.subtract.call(this,e))},n.multiply=function(e){return K(t.prototype.multiply.call(this,e))},n.divide=function(e){return K(t.prototype.divide.call(this,e))},n.toSignificant=function(e,n,r){return void 0===e&&(e=5),t.prototype.multiply.call(this,G).toSignificant(e,n,r)},n.toFixed=function(e,n,r){return void 0===e&&(e=2),t.prototype.multiply.call(this,G).toFixed(e,n,r)},e}(X),z=function(t,e,n,r,a){t>=0&&t<255&&Number.isInteger(t)||i(!1),this.decimals=t,this.symbol=e,this.name=n,this.icon=r,this.coingeckoId=a},Y=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).isNative=!0,e.isToken=!1,e}return k(e,t),e}(z),V=function(t){function e(e,n,r,a,o,s,p,c){var d;return(d=t.call(this,n,r,a,o,s)||this).isNative=!1,d.isToken=!0,d.address=e,p&&(p.gte(u.BigNumber.from(0))||i(!1)),c&&(c.gte(u.BigNumber.from(0))||i(!1)),d.buyFeeBps=p,d.sellFeeBps=c,d}k(e,t);var n=e.prototype;return n.equals=function(t){return t.isToken&&this.address.toLowerCase()===t.address.toLowerCase()},n.sortsBefore=function(t){return this.address.toLowerCase()===t.address.toLowerCase()&&i(!1),this.address.toLowerCase()<t.address.toLowerCase()},g(e,[{key:"wrapped",get:function(){return this}}]),e}(z),Z=function(t){function e(){return t.call(this,18,"ETH","Ether","/icons/ETH.svg","ethereum")||this}return k(e,t),e.prototype.equals=function(t){return t.isNative},g(e,[{key:"wrapped",get:function(){return new V(d,18,"WETH","Wrapped Ether","/icons/ETH.svg","ethereum")}}]),e}(Y),$=function(){function t(){}var e=t.prototype;return e.getTick=function(){var e=b(f().mark((function e(n){return f().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=b(f().mark((function e(n,r,i){return f().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}();$.ERROR_MESSAGE="No tick data provider was given";var J=function(t){var e=t.index,n=t.liquidityGross,a=t.liquidityNet;e>=lt.MIN_TICK&&e<=lt.MAX_TICK||i(!1),this.index=e,this.liquidityGross=r.BigInt(n),this.liquidityNet=r.BigInt(a)},tt=function(){function t(t,e){var n=t.map((function(t){return t instanceof J?t:new J(t)}));Pt.validateList(n,e),this.ticks=n}var e=t.prototype;return e.getTick=function(){var t=b(f().mark((function t(e){return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Pt.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=b(f().mark((function t(e,n,r){return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",Pt.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}(),et=new $,nt=function(){function t(t,e,n,a,o,u,s){void 0===s&&(s=et),Number.isInteger(n)&&n<1e6||i(!1);var p=lt.getSqrtRatioAtTick(u),c=lt.getSqrtRatioAtTick(u+1);r.greaterThanOrEqual(r.BigInt(a),p)&&r.lessThanOrEqual(r.BigInt(a),c)||i(!1);var d=t.sortsBefore(e)?[t,e]:[e,t];this.token0=d[0],this.token1=d[1],this.fee=n,this.sqrtRatioX96=r.BigInt(a),this.liquidity=r.BigInt(o),this.tickCurrent=u,this.tickDataProvider=Array.isArray(s)?new tt(s,O[n]):s}t.getAddress=function(t,e,n,r,i){return It({factoryAddress:null!=i?i:l,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=b(f().mark((function e(n,a){var o,u,s,p,c;return f().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.involvesToken(n.currency)||i(!1),o=n.currency.equals(this.token0),e.next=4,this.swap(o,n.quotient,a);case 4:return s=(u=e.sent).sqrtRatioX96,p=u.liquidity,c=u.tickCurrent,e.abrupt("return",[H.fromRawAmount(o?this.token1:this.token0,r.multiply(u.amountCalculated,P)),new t(this.token0,this.token1,this.fee,s,p,c,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=b(f().mark((function e(n,a){var o,u,s,p,c;return f().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return n.currency.isToken&&this.involvesToken(n.currency)||i(!1),o=n.currency.equals(this.token1),e.next=4,this.swap(o,r.multiply(n.quotient,P),a);case 4:return s=(u=e.sent).sqrtRatioX96,p=u.liquidity,c=u.tickCurrent,e.abrupt("return",[H.fromRawAmount(o?this.token0:this.token1,u.amountCalculated),new t(this.token0,this.token1,this.fee,s,p,c,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=b(f().mark((function t(e,n,a){var o,u,s,p,c,d;return f().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:a||(a=e?r.add(lt.MIN_SQRT_RATIO,_):r.subtract(lt.MAX_SQRT_RATIO,_)),e?(r.greaterThan(a,lt.MIN_SQRT_RATIO)||i(!1),r.lessThan(a,this.sqrtRatioX96)||i(!1)):(r.lessThan(a,lt.MAX_SQRT_RATIO)||i(!1),r.greaterThan(a,this.sqrtRatioX96)||i(!1)),o=r.greaterThanOrEqual(n,N),u={amountSpecifiedRemaining:n,amountCalculated:N,sqrtPriceX96:this.sqrtRatioX96,tick:this.tickCurrent,liquidity:this.liquidity};case 4:if(!r.notEqual(u.amountSpecifiedRemaining,N)||u.sqrtPriceX96==a){t.next=35;break}return(s={}).sqrtPriceStartX96=u.sqrtPriceX96,t.next=9,this.tickDataProvider.nextInitializedTickWithinOneWord(u.tick,e,this.tickSpacing);case 9:if(s.tickNext=(p=t.sent)[0],s.initialized=p[1],s.tickNext<lt.MIN_TICK?s.tickNext=lt.MIN_TICK:s.tickNext>lt.MAX_TICK&&(s.tickNext=lt.MAX_TICK),s.sqrtPriceNextX96=lt.getSqrtRatioAtTick(s.tickNext),c=Et.computeSwapStep(u.sqrtPriceX96,(e?r.lessThan(s.sqrtPriceNextX96,a):r.greaterThan(s.sqrtPriceNextX96,a))?a:s.sqrtPriceNextX96,u.liquidity,u.amountSpecifiedRemaining,this.fee),u.sqrtPriceX96=c[0],s.amountIn=c[1],s.amountOut=c[2],s.feeAmount=c[3],o?(u.amountSpecifiedRemaining=r.subtract(u.amountSpecifiedRemaining,r.add(s.amountIn,s.feeAmount)),u.amountCalculated=r.subtract(u.amountCalculated,s.amountOut)):(u.amountSpecifiedRemaining=r.add(u.amountSpecifiedRemaining,s.amountOut),u.amountCalculated=r.add(u.amountCalculated,r.add(s.amountIn,s.feeAmount))),!r.equal(u.sqrtPriceX96,s.sqrtPriceNextX96)){t.next=32;break}if(!s.initialized){t.next=29;break}return t.t0=r,t.next=25,this.tickDataProvider.getTick(s.tickNext);case 25:t.t1=t.sent.liquidityNet,d=t.t0.BigInt.call(t.t0,t.t1),e&&(d=r.multiply(d,P)),u.liquidity=qt.addDelta(u.liquidity,d);case 29:u.tick=e?s.tickNext-1:s.tickNext,t.next=33;break;case 32:r.notEqual(u.sqrtPriceX96,s.sqrtPriceStartX96)&&(u.tick=lt.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)}}(),g(t,[{key:"token0Price",get:function(){var t;return null!=(t=this._token0Price)?t:this._token0Price=new j(this.token0,this.token1,D,r.multiply(this.sqrtRatioX96,this.sqrtRatioX96))}},{key:"token1Price",get:function(){var t;return null!=(t=this._token1Price)?t:this._token1Price=new j(this.token1,this.token0,r.multiply(this.sqrtRatioX96,this.sqrtRatioX96),D)}},{key:"tickSpacing",get:function(){return O[this.fee]}}]),t}(),rt=function(){function t(){}return t.mulDivRoundingUp=function(t,e,n){var i=r.multiply(t,e),a=r.divide(i,n);return r.notEqual(r.remainder(i,n),N)&&(a=r.add(a,_)),a},t}(),it=r.subtract(r.exponentiate(r.BigInt(2),r.BigInt(160)),_);function at(t,e){var n=r.multiply(t,e);return r.bitwiseAnd(n,R)}var ot=function(){function t(){}return t.getAmount0Delta=function(t,e,n,i){if(r.greaterThan(t,e)){var a=[e,t];t=a[0],e=a[1]}var o=r.leftShift(n,r.BigInt(96)),u=r.subtract(e,t);return i?rt.mulDivRoundingUp(rt.mulDivRoundingUp(o,u,e),_,t):r.divide(r.divide(r.multiply(o,u),e),t)},t.getAmount1Delta=function(t,e,n,i){if(r.greaterThan(t,e)){var a=[e,t];t=a[0],e=a[1]}return i?rt.mulDivRoundingUp(n,r.subtract(e,t),F):r.divide(r.multiply(n,r.subtract(e,t)),F)},t.getNextSqrtPriceFromInput=function(t,e,n,a){return r.greaterThan(t,N)||i(!1),r.greaterThan(e,N)||i(!1),a?this.getNextSqrtPriceFromAmount0RoundingUp(t,e,n,!0):this.getNextSqrtPriceFromAmount1RoundingDown(t,e,n,!0)},t.getNextSqrtPriceFromOutput=function(t,e,n,a){return r.greaterThan(t,N)||i(!1),r.greaterThan(e,N)||i(!1),a?this.getNextSqrtPriceFromAmount1RoundingDown(t,e,n,!1):this.getNextSqrtPriceFromAmount0RoundingUp(t,e,n,!1)},t.getNextSqrtPriceFromAmount0RoundingUp=function(t,e,n,a){if(r.equal(n,N))return t;var o=r.leftShift(e,r.BigInt(96));if(a){var u=at(n,t);if(r.equal(r.divide(u,n),t)){var s=(c=r.add(o,u),r.bitwiseAnd(c,R));if(r.greaterThanOrEqual(s,o))return rt.mulDivRoundingUp(o,t,s)}return rt.mulDivRoundingUp(o,_,r.add(r.divide(o,t),n))}var p=at(n,t);r.equal(r.divide(p,n),t)||i(!1),r.greaterThan(o,p)||i(!1);var c,d=r.subtract(o,p);return rt.mulDivRoundingUp(o,t,d)},t.getNextSqrtPriceFromAmount1RoundingDown=function(t,e,n,a){if(a){var o=r.lessThanOrEqual(n,it)?r.divide(r.leftShift(n,r.BigInt(96)),e):r.divide(r.multiply(n,F),e);return r.add(t,o)}var u=rt.mulDivRoundingUp(n,F,e);return r.greaterThan(t,u)||i(!1),r.subtract(t,u)},t}(),ut=r.BigInt(2),st=[128,64,32,16,8,4,2,1].map((function(t){return[t,r.exponentiate(ut,r.BigInt(t))]}));function pt(t){r.greaterThan(t,N)||i(!1),r.lessThanOrEqual(t,R)||i(!1);for(var e,n=0,a=A(st);!(e=a()).done;){var o=e.value,u=o[0];r.greaterThanOrEqual(t,o[1])&&(t=r.signedRightShift(t,r.BigInt(u)),n+=u)}return n}function ct(t,e){return r.signedRightShift(r.multiply(t,r.BigInt(e)),r.BigInt(128))}var dt=r.exponentiate(r.BigInt(2),r.BigInt(32)),lt=function(){function t(){}return t.getSqrtRatioAtTick=function(e){e>=t.MIN_TICK&&e<=t.MAX_TICK&&Number.isInteger(e)||i(!1);var n=e<0?-1*e:e,a=r.BigInt(0!=(1&n)?"0xfffcb933bd6fad37aa2d162d1a594001":"0x100000000000000000000000000000000");return 0!=(2&n)&&(a=ct(a,"0xfff97272373d413259a46990580e213a")),0!=(4&n)&&(a=ct(a,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&n)&&(a=ct(a,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&n)&&(a=ct(a,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&n)&&(a=ct(a,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&n)&&(a=ct(a,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&n)&&(a=ct(a,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&n)&&(a=ct(a,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&n)&&(a=ct(a,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&n)&&(a=ct(a,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&n)&&(a=ct(a,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&n)&&(a=ct(a,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&n)&&(a=ct(a,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&n)&&(a=ct(a,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&n)&&(a=ct(a,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&n)&&(a=ct(a,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&n)&&(a=ct(a,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&n)&&(a=ct(a,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&n)&&(a=ct(a,"0x48a170391f7dc42444e8fa2")),e>0&&(a=r.divide(R,a)),r.greaterThan(r.remainder(a,dt),N)?r.add(r.divide(a,dt),_):r.divide(a,dt)},t.getTickAtSqrtRatio=function(e){r.greaterThanOrEqual(e,t.MIN_SQRT_RATIO)&&r.lessThan(e,t.MAX_SQRT_RATIO)||i(!1);var n,a=r.leftShift(e,r.BigInt(32)),o=pt(a);n=r.greaterThanOrEqual(r.BigInt(o),r.BigInt(128))?r.signedRightShift(a,r.BigInt(o-127)):r.leftShift(a,r.BigInt(127-o));for(var u=r.leftShift(r.subtract(r.BigInt(o),r.BigInt(128)),r.BigInt(64)),s=0;s<14;s++){n=r.signedRightShift(r.multiply(n,n),r.BigInt(127));var p=r.signedRightShift(n,r.BigInt(128));u=r.bitwiseOr(u,r.leftShift(p,r.BigInt(63-s))),n=r.signedRightShift(n,p)}var c=r.multiply(u,r.BigInt("255738958999603826347141")),d=r.toNumber(r.signedRightShift(r.subtract(c,r.BigInt("3402992956809132418596140100660247210")),r.BigInt(128))),l=r.toNumber(r.signedRightShift(r.add(c,r.BigInt("291339464771989622907027621153398088495")),r.BigInt(128)));return d===l?d:r.lessThanOrEqual(t.getSqrtRatioAtTick(l),e)?l:d},t}();lt.MIN_TICK=-887272,lt.MAX_TICK=-lt.MIN_TICK,lt.MIN_SQRT_RATIO=r.BigInt("4295128739"),lt.MAX_SQRT_RATIO=r.BigInt("1461446703485210103287273052203988822378723970342");var mt=function(){function t(t){var e=t.pool,n=t.liquidity,a=t.tickLower,o=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,a<o||i(!1),a>=lt.MIN_TICK&&a%e.tickSpacing==0||i(!1),o<=lt.MAX_TICK&&o%e.tickSpacing==0||i(!1),this.pool=e,this.tickLower=a,this.tickUpper=o,this.liquidity=r.BigInt(n)}var e=t.prototype;return e.ratiosAfterSlippage=function(t){var e=this.pool.token0Price.asFraction.multiply(new Q(1).subtract(t)),n=this.pool.token0Price.asFraction.multiply(t.add(1)),i=Ct(e.numerator,e.denominator);r.lessThanOrEqual(i,lt.MIN_SQRT_RATIO)&&(i=r.add(lt.MIN_SQRT_RATIO,r.BigInt(1)));var a=Ct(n.numerator,n.denominator);return r.greaterThanOrEqual(a,lt.MAX_SQRT_RATIO)&&(a=r.subtract(lt.MAX_SQRT_RATIO,r.BigInt(1))),{sqrtRatioX96Lower:i,sqrtRatioX96Upper:a}},e.mintAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,a=new nt(this.pool.token0,this.pool.token1,this.pool.fee,i,0,lt.getTickAtSqrtRatio(i)),o=new nt(this.pool.token0,this.pool.token1,this.pool.fee,r,0,lt.getTickAtSqrtRatio(r)),u=t.fromAmounts(v({pool:this.pool,tickLower:this.tickLower,tickUpper:this.tickUpper},this.mintAmounts,{useFullPrecision:!1}));return{amount0:new t({pool:o,liquidity:u.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:new t({pool:a,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,a=new nt(this.pool.token0,this.pool.token1,this.pool.fee,i,0,lt.getTickAtSqrtRatio(i)),o=new t({pool:new nt(this.pool.token0,this.pool.token1,this.pool.fee,r,0,lt.getTickAtSqrtRatio(r)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,u=new t({pool:a,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:o.quotient,amount1:u.quotient}},t.fromAmounts=function(e){var n=e.pool,r=e.tickLower,i=e.tickUpper,a=e.amount0,o=e.amount1,u=e.useFullPrecision,s=lt.getSqrtRatioAtTick(r),p=lt.getSqrtRatioAtTick(i);return new t({pool:n,tickLower:r,tickUpper:i,liquidity:Dt(n.sqrtRatioX96,s,p,a,o,u)})},t.fromAmount0=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:e.amount0,amount1:R,useFullPrecision:e.useFullPrecision})},t.fromAmount1=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:R,amount1:e.amount1,useFullPrecision:!0})},g(t,[{key:"token0PriceLower",get:function(){return Mt(this.pool.token0,this.pool.token1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return Mt(this.pool.token0,this.pool.token1,this.tickUpper)}},{key:"amount0",get:function(){return null===this._token0Amount&&(this._token0Amount=H.fromRawAmount(this.pool.token0,this.pool.tickCurrent<this.tickLower?ot.getAmount0Delta(lt.getSqrtRatioAtTick(this.tickLower),lt.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):this.pool.tickCurrent<this.tickUpper?ot.getAmount0Delta(this.pool.sqrtRatioX96,lt.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):N)),this._token0Amount}},{key:"amount1",get:function(){return null===this._token1Amount&&(this._token1Amount=H.fromRawAmount(this.pool.token1,this.pool.tickCurrent<this.tickLower?N:ot.getAmount1Delta(lt.getSqrtRatioAtTick(this.tickLower),this.pool.tickCurrent<this.tickUpper?this.pool.sqrtRatioX96:lt.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1))),this._token1Amount}},{key:"mintAmounts",get:function(){return null===this._mintAmounts?this.pool.tickCurrent<this.tickLower?{amount0:ot.getAmount0Delta(lt.getSqrtRatioAtTick(this.tickLower),lt.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:N}:this.pool.tickCurrent<this.tickUpper?{amount0:ot.getAmount0Delta(this.pool.sqrtRatioX96,lt.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:ot.getAmount1Delta(lt.getSqrtRatioAtTick(this.tickLower),this.pool.sqrtRatioX96,this.liquidity,!0)}:{amount0:N,amount1:ot.getAmount1Delta(lt.getSqrtRatioAtTick(this.tickLower),lt.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0)}:this._mintAmounts}}]),t}(),yt=function(){function t(t,e,n){this._midPrice=null,t.length>0||i(!1);var r=e.wrapped;t[0].involvesToken(r)||i(!1),t[t.length-1].involvesToken(n.wrapped)||i(!1);for(var a,o=[r],u=A(t.entries());!(a=u()).done;){var s=a.value,p=s[1],c=o[s[0]];c.equals(p.token0)||c.equals(p.token1)||i(!1);var d=c.equals(p.token0)?p.token1:p.token0;o.push(d)}this.pools=t,this.tokenPath=o,this.input=e,this.output=null!=n?n:o[o.length-1]}return g(t,[{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 j(this.input,this.output,t.denominator,t.numerator)}}]),t}();function ft(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 ht=function(){function t(t){var e=t.routes,n=t.tradeType,r=e[0].inputAmount.currency,a=e[0].outputAmount.currency;e.every((function(t){return r.wrapped.equals(t.route.input.wrapped)}))||i(!1),e.every((function(t){return a.wrapped.equals(t.route.output.wrapped)}))||i(!1);for(var o,u=e.map((function(t){return t.route.pools.length})).reduce((function(t,e){return t+e}),0),s=new Set,p=A(e);!(o=p()).done;)for(var c,d=A(o.value.route.pools);!(c=d()).done;){var l=c.value;s.add(nt.getAddress(l.token0,l.token1,l.fee))}u!=s.size&&i(!1),this.swaps=e,this.tradeType=n}t.exactIn=function(){var e=b(f().mark((function e(n,r){return f().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(n,r,exports.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=b(f().mark((function e(n,r){return f().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(n,r,exports.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=b(f().mark((function e(n,r,a){var o,u,s,p,c,d,l;return f().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(o=new Array(n.tokenPath.length),a!==exports.TradeType.EXACT_INPUT){e.next=19;break}r.currency.equals(n.input)||i(!1),o[0]=r.wrapped,p=0;case 5:if(!(p<n.tokenPath.length-1)){e.next=15;break}return c=n.pools[p],e.next=9,c.getOutputAmount(o[p]);case 9:o[p+1]=e.sent[0];case 12:p++,e.next=5;break;case 15:u=H.fromFractionalAmount(n.input,r.numerator,r.denominator),s=H.fromFractionalAmount(n.output,o[o.length-1].numerator,o[o.length-1].denominator),e.next=34;break;case 19:r.currency.equals(n.output)||i(!1),o[o.length-1]=r.wrapped,d=n.tokenPath.length-1;case 22:if(!(d>0)){e.next=32;break}return l=n.pools[d-1],e.next=26,l.getInputAmount(o[d]);case 26:o[d-1]=e.sent[0];case 29:d--,e.next=22;break;case 32:u=H.fromFractionalAmount(n.input,o[0].numerator,o[0].denominator),s=H.fromFractionalAmount(n.output,r.numerator,r.denominator);case 34:return e.abrupt("return",new t({routes:[{inputAmount:u,outputAmount:s,route:n}],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=b(f().mark((function e(n,r){var a,o,u,s,p,c,d,l,m,y,h,b,T;return f().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:a=[],o=A(n);case 2:if((u=o()).done){e.next=43;break}if(p=(s=u.value).route,c=s.amount,d=new Array(p.tokenPath.length),l=void 0,m=void 0,r!==exports.TradeType.EXACT_INPUT){e.next=25;break}c.currency.equals(p.input)||i(!1),l=H.fromFractionalAmount(p.input,c.numerator,c.denominator),d[0]=H.fromFractionalAmount(p.input.wrapped,c.numerator,c.denominator),y=0;case 12:if(!(y<p.tokenPath.length-1)){e.next=22;break}return h=p.pools[y],e.next=16,h.getOutputAmount(d[y]);case 16:d[y+1]=e.sent[0];case 19:y++,e.next=12;break;case 22:m=H.fromFractionalAmount(p.output,d[d.length-1].numerator,d[d.length-1].denominator),e.next=40;break;case 25:c.currency.equals(p.output)||i(!1),m=H.fromFractionalAmount(p.output,c.numerator,c.denominator),d[d.length-1]=H.fromFractionalAmount(p.output.wrapped,c.numerator,c.denominator),b=p.tokenPath.length-1;case 29:if(!(b>0)){e.next=39;break}return T=p.pools[b-1],e.next=33,T.getInputAmount(d[b]);case 33:d[b-1]=e.sent[0];case 36:b--,e.next=29;break;case 39:l=H.fromFractionalAmount(p.input,d[0].numerator,d[0].denominator);case 40:a.push({route:p,inputAmount:l,outputAmount:m});case 41:e.next=2;break;case 43:return e.abrupt("return",new t({routes:a,tradeType:r}));case 44:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(v({},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(N)&&i(!1),this.tradeType===exports.TradeType.EXACT_OUTPUT)return e;var n=new X(_).add(t).invert().multiply(e.quotient).quotient;return H.fromRawAmount(e.currency,n)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(N)&&i(!1),this.tradeType===exports.TradeType.EXACT_INPUT)return e;var n=new X(_).add(t).multiply(e.quotient).quotient;return H.fromRawAmount(e.currency,n)},e.worstExecutionPrice=function(t){return new j(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=b(f().mark((function e(n,r,a,o,u,s,p){var c,d,l,m,y,h,b,T,g,v,k;return f().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:l=void 0===(d=(c=void 0===o?{}:o).maxNumResults)?3:d,y=void 0===(m=c.maxHops)?3:m,void 0===u&&(u=[]),void 0===s&&(s=r),void 0===p&&(p=[]),n.length>0||i(!1),y>0||i(!1),r===s||u.length>0||i(!1),h=s.wrapped,b=a.wrapped,T=0;case 10:if(!(T<n.length)){e.next=45;break}if((g=n[T]).token0.equals(h.currency)||g.token1.equals(h.currency)){e.next=14;break}return e.abrupt("continue",42);case 14:return v=void 0,e.prev=15,e.next=18,g.getOutputAmount(h);case 18:v=e.sent[0],e.next=27;break;case 22:if(e.prev=22,e.t0=e.catch(15),null==e.t0||!e.t0.isInsufficientInputAmountError){e.next=26;break}return e.abrupt("continue",42);case 26:throw e.t0;case 27:if(!v.currency.isToken||!v.currency.equals(b)){e.next=38;break}return e.t1=bt,e.t2=p,e.next=32,t.fromRoute(new yt([].concat(u,[g]),r.currency,a),r,exports.TradeType.EXACT_INPUT);case 32:e.t3=e.sent,e.t4=l,e.t5=ft,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=42;break;case 38:if(!(y>1&&n.length>1)){e.next=42;break}return k=n.slice(0,T).concat(n.slice(T+1,n.length)),e.next=42,t.bestTradeExactIn(k,r,a,{maxNumResults:l,maxHops:y-1},[].concat(u,[g]),v,p);case 42:T++,e.next=10;break;case 45:return e.abrupt("return",p);case 46:case"end":return e.stop()}}),e,null,[[15,22]])})));return function(t,n,r,i,a,o,u){return e.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var e=b(f().mark((function e(n,r,a,o,u,s,p){var c,d,l,m,y,h,b,T,g,v,k;return f().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:l=void 0===(d=(c=void 0===o?{}:o).maxNumResults)?3:d,y=void 0===(m=c.maxHops)?3:m,void 0===u&&(u=[]),void 0===s&&(s=a),void 0===p&&(p=[]),n.length>0||i(!1),y>0||i(!1),a===s||u.length>0||i(!1),h=s.wrapped,b=r.wrapped,T=0;case 10:if(!(T<n.length)){e.next=45;break}if((g=n[T]).token0.equals(h.currency)||g.token1.equals(h.currency)){e.next=14;break}return e.abrupt("continue",42);case 14:return v=void 0,e.prev=15,e.next=18,g.getInputAmount(h);case 18:v=e.sent[0],e.next=27;break;case 22:if(e.prev=22,e.t0=e.catch(15),null==e.t0||!e.t0.isInsufficientReservesError){e.next=26;break}return e.abrupt("continue",42);case 26:throw e.t0;case 27:if(!v.currency.equals(b)){e.next=38;break}return e.t1=bt,e.t2=p,e.next=32,t.fromRoute(new yt([g].concat(u),r,a.currency),a,exports.TradeType.EXACT_OUTPUT);case 32:e.t3=e.sent,e.t4=l,e.t5=ft,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=42;break;case 38:if(!(y>1&&n.length>1)){e.next=42;break}return k=n.slice(0,T).concat(n.slice(T+1,n.length)),e.next=42,t.bestTradeExactOut(k,r,a,{maxNumResults:l,maxHops:y-1},[g].concat(u),v,p);case 42:T++,e.next=10;break;case 45:return e.abrupt("return",p);case 46:case"end":return e.stop()}}),e,null,[[15,22]])})));return function(t,n,r,i,a,o,u){return e.apply(this,arguments)}}(),g(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)}),H.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)}),H.fromRawAmount(t,0));return this._outputAmount=e,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new j(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=H.fromRawAmount(this.outputAmount.currency,0),n=A(this.swaps);!(t=n()).done;){var r=t.value;e=e.add(r.route.midPrice.quote(r.inputAmount))}var i=e.subtract(this.outputAmount).divide(e);return this._priceImpact=new Q(i.numerator,i.denominator),this._priceImpact}}]),t}();function bt(t,e,n,r){if(n>0||i(!1),t.length<=n||i(!1),0===t.length)return t.push(e),null;var a=t.length===n;if(a&&r(t[t.length-1],e)<=0)return e;for(var o=0,u=t.length;o<u;){var s=o+u>>>1;r(t[s],e)<=0?o=s+1:u=s}return t.splice(o,0,e),a?t.pop():null}var Tt=r.BigInt(Number.MAX_SAFE_INTEGER),gt=r.BigInt(0),vt=r.BigInt(1),kt=r.BigInt(2);function xt(t){if(r.greaterThanOrEqual(t,gt)||i(!1),r.lessThan(t,Tt))return r.BigInt(Math.floor(Math.sqrt(r.toNumber(t))));var e,n;for(e=t,n=r.add(r.divide(t,kt),vt);r.lessThan(n,e);)e=n,n=r.divide(r.add(r.divide(t,n),n),kt);return e}function At(t){try{return s.getAddress(t)}catch(e){throw new Error(t+" is not a valid address.")}}var wt=/^0x[0-9a-fA-F]{40}$/;function It(t){var e=t.factoryAddress,n=t.tokenA,r=t.tokenB,i=t.fee,a=t.initCodeHashManualOverride,o=n.sortsBefore(r)?[n,r]:[r,n];return s.getCreate2Address(e,c.keccak256(["bytes"],[p.defaultAbiCoder.encode(["address","address","uint24"],[o[0].address,o[1].address,i])]),null!=a?a:C)}var qt=function(){function t(){}return t.addDelta=function(t,e){return r.lessThan(e,N)?r.subtract(t,r.multiply(e,P)):r.add(t,e)},t}(),Rt=r.exponentiate(r.BigInt(10),r.BigInt(6)),Et=function(){function t(){}return t.computeSwapStep=function(t,e,n,i,a){var o={},u=r.greaterThanOrEqual(t,e),s=r.greaterThanOrEqual(i,N);if(s){var p=r.divide(r.multiply(i,r.subtract(Rt,r.BigInt(a))),Rt);o.amountIn=u?ot.getAmount0Delta(e,t,n,!0):ot.getAmount1Delta(t,e,n,!0),o.sqrtRatioNextX96=r.greaterThanOrEqual(p,o.amountIn)?e:ot.getNextSqrtPriceFromInput(t,n,p,u)}else o.amountOut=u?ot.getAmount1Delta(e,t,n,!1):ot.getAmount0Delta(t,e,n,!1),o.sqrtRatioNextX96=r.greaterThanOrEqual(r.multiply(i,P),o.amountOut)?e:ot.getNextSqrtPriceFromOutput(t,n,r.multiply(i,P),u);var c=r.equal(e,o.sqrtRatioNextX96);return u?(o.amountIn=c&&s?o.amountIn:ot.getAmount0Delta(o.sqrtRatioNextX96,t,n,!0),o.amountOut=c&&!s?o.amountOut:ot.getAmount1Delta(o.sqrtRatioNextX96,t,n,!1)):(o.amountIn=c&&s?o.amountIn:ot.getAmount1Delta(t,o.sqrtRatioNextX96,n,!0),o.amountOut=c&&!s?o.amountOut:ot.getAmount0Delta(t,o.sqrtRatioNextX96,n,!1)),!s&&r.greaterThan(o.amountOut,r.multiply(i,P))&&(o.amountOut=r.multiply(i,P)),o.feeAmount=s&&r.notEqual(o.sqrtRatioNextX96,e)?r.subtract(i,o.amountIn):rt.mulDivRoundingUp(o.amountIn,r.BigInt(a),r.subtract(Rt,r.BigInt(a))),[o.sqrtRatioNextX96,o.amountIn,o.amountOut,o.feeAmount]},t}();function St(t,e){for(var n=0;n<t.length-1;n++)if(e(t[n],t[n+1])>0)return!1;return!0}function Ot(t,e){return t.index-e.index}var Pt=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)}),N),N)||i(!1),St(t,Ot)||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,a=t.length-1;;){if(t[n=Math.floor((r+a)/2)].index<=e&&(n===t.length-1||t[n+1].index>e))return n;t[n].index<e?r=n+1:a=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 a=Math.floor(n/i);if(r){var o=(a>>8<<8)*i;if(t.isBelowSmallest(e,n))return[o,!1];var u=t.nextInitializedTick(e,n,r).index,s=Math.max(o,u);return[s,s===u]}var p=((1+(a+1>>8)<<8)-1)*i;if(this.isAtOrAboveLargest(e,n))return[p,!1];var c=this.nextInitializedTick(e,n,r).index,d=Math.min(p,c);return[d,d===c]},t}();function Nt(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var a=r.divide(r.multiply(t,e),F);return r.divide(r.multiply(r.BigInt(n),a),r.subtract(e,t))}function _t(t,e,n){if(r.greaterThan(t,e)){var i=[e,t];t=i[0],e=i[1]}var a=r.multiply(r.multiply(r.BigInt(n),t),e),o=r.multiply(F,r.subtract(e,t));return r.divide(a,o)}function Ft(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),F),r.subtract(e,t))}function Dt(t,e,n,i,a,o){if(r.greaterThan(e,n)){var u=[n,e];e=u[0],n=u[1]}var s=o?_t:Nt;if(r.lessThanOrEqual(t,e))return s(e,n,i);if(r.lessThan(t,n)){var p=s(t,n,i),c=Ft(e,t,a);return r.lessThan(p,c)?p:c}return Ft(e,n,a)}function Ct(t,e){var n=r.leftShift(r.BigInt(t),r.BigInt(192)),i=r.BigInt(e);return xt(r.divide(n,i))}function Mt(t,e,n){var i=lt.getSqrtRatioAtTick(n),a=r.multiply(i,i);return t.sortsBefore(e)?new j(t,e,D,a):new j(t,e,a,D)}var Ut=r.exponentiate(r.BigInt(2),r.BigInt(256));function Bt(t,e){var n=r.subtract(t,e);return r.lessThan(n,N)?r.add(Ut,n):n}var Lt=function(){function t(){}return t.getFeeGrowthInside=function(t,e,n,r,i,a,o){var u,s,p,c;return i>=n?(u=t.feeGrowthOutside0X128,s=t.feeGrowthOutside1X128):(u=Bt(a,t.feeGrowthOutside0X128),s=Bt(o,t.feeGrowthOutside1X128)),i<r?(p=e.feeGrowthOutside0X128,c=e.feeGrowthOutside1X128):(p=Bt(a,e.feeGrowthOutside0X128),c=Bt(o,e.feeGrowthOutside1X128)),[Bt(Bt(a,u),p),Bt(Bt(o,s),c)]},t}(),Xt=r.exponentiate(r.BigInt(2),r.BigInt(128)),Wt=function(){function t(){}return t.getTokensOwed=function(t,e,n,i,a){return[r.divide(r.multiply(Bt(i,t),n),Xt),r.divide(r.multiply(Bt(a,e),n),Xt)]},t}();function Ht(t){var e=r.BigInt(t).toString(16);return e.length%2!=0&&(e="0"+e),"0x"+e}var jt=[{inputs:[{internalType:"bytes[]",name:"data",type:"bytes[]"}],name:"multicall",outputs:[{internalType:"bytes[]",name:"results",type:"bytes[]"}],stateMutability:"payable",type:"function"}],Gt=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}();Gt.INTERFACE=new p.Interface(jt);var Kt=[{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"uint256",name:"value",type:"uint256"},{internalType:"uint256",name:"deadline",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",name:"s",type:"bytes32"}],name:"selfPermit",outputs:[],stateMutability:"payable",type:"function"},{inputs:[{internalType:"address",name:"token",type:"address"},{internalType:"uint256",name:"nonce",type:"uint256"},{internalType:"uint256",name:"expiry",type:"uint256"},{internalType:"uint8",name:"v",type:"uint8"},{internalType:"bytes32",name:"r",type:"bytes32"},{internalType:"bytes32",nam