lotus-v4-sdk
Version:
⚒️ An SDK for building applications on top of Lotus V4
1 lines • 59.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,r=t(require("tiny-invariant")),i=require("@ethersproject/solidity"),o=require("@uniswap/sdk-core"),a=require("@uniswap/v3-sdk"),u=require("ethers/lib/utils"),s=t(require("jsbi")),p=require("ethers"),c=require("@ethersproject/abi"),y=t(require("@uniswap/v3-periphery/artifacts/contracts/interfaces/IMulticall.sol/IMulticall.json"));function l(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=Array(e);n<e;n++)r[n]=t[n];return r}function d(t,e,n,r,i,o,a){try{var u=t[o](a),s=u.value}catch(t){return void n(t)}u.done?e(s):Promise.resolve(s).then(r,i)}function m(t){return function(){var e=this,n=arguments;return new Promise((function(r,i){var o=t.apply(e,n);function a(t){d(o,r,i,a,u,"next",t)}function u(t){d(o,r,i,a,u,"throw",t)}a(void 0)}))}}function h(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,b(r.key),r)}}function f(t,e,n){return e&&h(t.prototype,e),n&&h(t,n),Object.defineProperty(t,"prototype",{writable:!1}),t}function T(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 l(t,e);var n={}.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)?l(t,e):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.")}function A(){return(A=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)({}).hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(null,arguments)}function k(){k=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",s=o.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 o=Object.create((e&&e.prototype instanceof f?e:f).prototype),a=new _(r||[]);return i(o,"_invoke",{value:S(t,n,a)}),o}function y(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",d="executing",m="completed",h={};function f(){}function T(){}function A(){}var v={};p(v,a,(function(){return this}));var b=Object.getPrototypeOf,I=b&&b(b(R([])));I&&I!==n&&r.call(I,a)&&(v=I);var g=A.prototype=f.prototype=Object.create(v);function w(t){["next","throw","return"].forEach((function(e){p(t,e,(function(t){return this._invoke(e,t)}))}))}function x(t,e){function n(i,o,a,u){var s=y(t[i],t,o);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,a,u)}),(function(t){n("throw",t,a,u)})):e.resolve(c).then((function(t){p.value=t,a(p)}),(function(t){return n("throw",t,a,u)}))}u(s.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 S(e,n,r){var i=l;return function(o,a){if(i===d)throw 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 s=P(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=m,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);i=d;var p=y(e,n,r);if("normal"===p.type){if(i=r.done?m:"suspendedYield",p.arg===h)continue;return{value:p.arg,done:r.done}}"throw"===p.type&&(i=m,r.method="throw",r.arg=p.arg)}}}function P(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,P(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=y(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 q(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function _(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(q,this),this.reset(!0)}function R(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 T.prototype=A,i(g,"constructor",{value:A,configurable:!0}),i(A,"constructor",{value:T,configurable:!0}),T.displayName=p(A,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,A):(t.__proto__=A,p(t,s,"GeneratorFunction")),t.prototype=Object.create(g),t},e.awrap=function(t){return{__await:t}},w(x.prototype),p(x.prototype,u,(function(){return this})),e.AsyncIterator=x,e.async=function(t,n,r,i,o){void 0===o&&(o=Promise);var a=new x(c(t,n,r,i),o);return e.isGeneratorFunction(n)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},w(g),p(g,s,"Generator"),p(g,a,(function(){return this})),p(g,"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=R,_.prototype={constructor:_,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(E),!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 s=r.call(a,"catchLoc"),p=r.call(a,"finallyLoc");if(s&&p){if(this.prev<a.catchLoc)return i(a.catchLoc,!0);if(this.prev<a.finallyLoc)return i(a.finallyLoc)}else if(s){if(this.prev<a.catchLoc)return i(a.catchLoc,!0)}else{if(!p)throw 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),E(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;E(n)}return i}}throw Error("illegal catch attempt")},delegateYield:function(e,n,r){return this.delegate={iterator:R(e),resultName:n,nextLoc:r},"next"===this.method&&(this.arg=t),h}},e}function v(t,e){return(v=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,e){return t.__proto__=e,t})(t,e)}function b(t){var e=function(t,e){if("object"!=typeof t||!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)}(t);return"symbol"==typeof e?e:e+""}function I(t,e){return!!t.isNative||!e.isNative&&t.wrapped.sortsBefore(e.wrapped)}(n=exports.HookOptions||(exports.HookOptions={})).AfterRemoveLiquidityReturnsDelta="afterRemoveLiquidityReturnsDelta",n.AfterAddLiquidityReturnsDelta="afterAddLiquidityReturnsDelta",n.AfterSwapReturnsDelta="afterSwapReturnsDelta",n.BeforeSwapReturnsDelta="beforeSwapReturnsDelta",n.AfterDonate="afterDonate",n.BeforeDonate="beforeDonate",n.AfterSwap="afterSwap",n.BeforeSwap="beforeSwap",n.AfterRemoveLiquidity="afterRemoveLiquidity",n.BeforeRemoveLiquidity="beforeRemoveLiquidity",n.AfterAddLiquidity="afterAddLiquidity",n.BeforeAddLiquidity="beforeAddLiquidity",n.AfterInitialize="afterInitialize",n.BeforeInitialize="beforeInitialize";var g,w,x,S=((e={})[exports.HookOptions.AfterRemoveLiquidityReturnsDelta]=0,e[exports.HookOptions.AfterAddLiquidityReturnsDelta]=1,e[exports.HookOptions.AfterSwapReturnsDelta]=2,e[exports.HookOptions.BeforeSwapReturnsDelta]=3,e[exports.HookOptions.AfterDonate]=4,e[exports.HookOptions.BeforeDonate]=5,e[exports.HookOptions.AfterSwap]=6,e[exports.HookOptions.BeforeSwap]=7,e[exports.HookOptions.AfterRemoveLiquidity]=8,e[exports.HookOptions.BeforeRemoveLiquidity]=9,e[exports.HookOptions.AfterAddLiquidity]=10,e[exports.HookOptions.BeforeAddLiquidity]=11,e[exports.HookOptions.AfterInitialize]=12,e[exports.HookOptions.BeforeInitialize]=13,e),P=function(){function t(){}return t.permissions=function(t){return this._checkAddress(t),{beforeInitialize:this._hasPermission(t,exports.HookOptions.BeforeInitialize),afterInitialize:this._hasPermission(t,exports.HookOptions.AfterInitialize),beforeAddLiquidity:this._hasPermission(t,exports.HookOptions.BeforeAddLiquidity),afterAddLiquidity:this._hasPermission(t,exports.HookOptions.AfterAddLiquidity),beforeRemoveLiquidity:this._hasPermission(t,exports.HookOptions.BeforeRemoveLiquidity),afterRemoveLiquidity:this._hasPermission(t,exports.HookOptions.AfterRemoveLiquidity),beforeSwap:this._hasPermission(t,exports.HookOptions.BeforeSwap),afterSwap:this._hasPermission(t,exports.HookOptions.AfterSwap),beforeDonate:this._hasPermission(t,exports.HookOptions.BeforeDonate),afterDonate:this._hasPermission(t,exports.HookOptions.AfterDonate),beforeSwapReturnsDelta:this._hasPermission(t,exports.HookOptions.BeforeSwapReturnsDelta),afterSwapReturnsDelta:this._hasPermission(t,exports.HookOptions.AfterSwapReturnsDelta),afterAddLiquidityReturnsDelta:this._hasPermission(t,exports.HookOptions.AfterAddLiquidityReturnsDelta),afterRemoveLiquidityReturnsDelta:this._hasPermission(t,exports.HookOptions.AfterRemoveLiquidityReturnsDelta)}},t.hasPermission=function(t,e){return this._checkAddress(t),this._hasPermission(t,e)},t.hasInitializePermissions=function(e){return this._checkAddress(e),this._hasPermission(e,exports.HookOptions.BeforeInitialize)||t._hasPermission(e,exports.HookOptions.AfterInitialize)},t.hasLiquidityPermissions=function(e){return this._checkAddress(e),this._hasPermission(e,exports.HookOptions.BeforeAddLiquidity)||t._hasPermission(e,exports.HookOptions.AfterAddLiquidity)||t._hasPermission(e,exports.HookOptions.BeforeRemoveLiquidity)||t._hasPermission(e,exports.HookOptions.AfterRemoveLiquidity)},t.hasSwapPermissions=function(e){return this._checkAddress(e),this._hasPermission(e,exports.HookOptions.BeforeSwap)||t._hasPermission(e,exports.HookOptions.AfterSwap)},t.hasDonatePermissions=function(e){return this._checkAddress(e),this._hasPermission(e,exports.HookOptions.BeforeDonate)||t._hasPermission(e,exports.HookOptions.AfterDonate)},t._hasPermission=function(t,e){return!!(parseInt(t,16)&1<<S[e])},t._checkAddress=function(t){u.isAddress(t)||r(!1)},t}(),q=p.constants.AddressZero,E=s.BigInt(-1),_=s.BigInt(0),R=s.BigInt(1),L=s.exponentiate(s.exponentiate(s.BigInt(2),s.BigInt(96)),s.BigInt(2)),O=p.constants.Zero;!function(t){t.INITIALIZE_POOL="initializePool",t.MODIFY_LIQUIDITIES="modifyLiquidities",t.PERMIT_BATCH="0x002a3e3a",t.ERC721PERMIT_PERMIT="0x0f5730f1"}(w||(w={})),function(t){t[t.LOWEST=100]="LOWEST",t[t.LOW=500]="LOW",t[t.MEDIUM=3e3]="MEDIUM",t[t.HIGH=1e4]="HIGH"}(x||(x={})),(g={})[x.LOWEST]=1,g[x.LOW]=10,g[x.MEDIUM]=60,g[x.HIGH]=200;var M=new a.NoTickDataProvider,C=function(){function t(e,n,i,o,p,c,y,l,d){void 0===d&&(d=M),u.isAddress(p)||r(!1),Number.isInteger(i)&&(8388608===i||i<1e6)||r(!1),8388608===i&&(Number(p)>0||r(!1));var m=a.TickMath.getSqrtRatioAtTick(l),h=a.TickMath.getSqrtRatioAtTick(l+1);s.greaterThanOrEqual(s.BigInt(c),m)&&s.lessThanOrEqual(s.BigInt(c),h)||r(!1);var f=I(e,n)?[e,n]:[n,e];this.currency0=f[0],this.currency1=f[1],this.fee=i,this.sqrtRatioX96=s.BigInt(c),this.tickSpacing=o,this.hooks=p,this.liquidity=s.BigInt(y),this.tickCurrent=l,this.tickDataProvider=Array.isArray(d)?new a.TickListDataProvider(d,o):d,this.poolKey=t.getPoolKey(this.currency0,this.currency1,this.fee,this.tickSpacing,this.hooks),this.poolId=t.getPoolId(this.currency0,this.currency1,this.fee,this.tickSpacing,this.hooks)}t.getPoolKey=function(t,e,n,i,o){u.isAddress(o)||r(!1);var a=I(t,e)?[t,e]:[e,t],s=a[0],p=a[1];return{currency0:s.isNative?q:s.wrapped.address,currency1:p.isNative?q:p.wrapped.address,fee:n,tickSpacing:i,hooks:o}},t.getPoolId=function(t,e,n,r,o){var a=I(t,e)?[t,e]:[e,t],s=a[0],p=a[1];return i.keccak256(["bytes"],[u.defaultAbiCoder.encode(["address","address","uint24","int24","address"],[s.isNative?q:s.wrapped.address,p.isNative?q:p.wrapped.address,n,r,o])])};var e=t.prototype;return e.involvesCurrency=function(t){return t.equals(this.currency0)||t.equals(this.currency1)},e.involvesToken=function(t){return this.involvesCurrency(t)},e.v4InvolvesToken=function(t){return this.involvesCurrency(t)||t.wrapped.equals(this.currency0)||t.wrapped.equals(this.currency1)||t.wrapped.equals(this.currency0.wrapped)||t.wrapped.equals(this.currency1.wrapped)},e.priceOf=function(t){return this.involvesCurrency(t)||r(!1),t.equals(this.currency0)?this.currency0Price:this.currency1Price},e.getOutputAmount=function(){var e=m(k().mark((function e(n,i){var a,u,p,c,y;return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.involvesCurrency(n.currency)||r(!1),a=n.currency.equals(this.currency0),e.next=4,this.swap(a,n.quotient,i);case 4:return p=(u=e.sent).sqrtRatioX96,c=u.liquidity,y=u.tickCurrent,e.abrupt("return",[o.CurrencyAmount.fromRawAmount(a?this.currency1:this.currency0,s.multiply(u.amountCalculated,E)),new t(this.currency0,this.currency1,this.fee,this.tickSpacing,this.hooks,p,c,y,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=m(k().mark((function e(n,i){var a,u,p,c,y;return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return this.involvesCurrency(n.currency)||r(!1),a=n.currency.equals(this.currency1),e.next=4,this.swap(a,s.multiply(n.quotient,E),i);case 4:return p=(u=e.sent).sqrtRatioX96,c=u.liquidity,y=u.tickCurrent,e.abrupt("return",[o.CurrencyAmount.fromRawAmount(a?this.currency0:this.currency1,u.amountCalculated),new t(this.currency0,this.currency1,this.fee,this.tickSpacing,this.hooks,p,c,y,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=m(k().mark((function t(e,n,r){return k().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(this.hookImpactsSwap()){t.next=4;break}return t.abrupt("return",a.v3Swap(s.BigInt(this.fee),this.sqrtRatioX96,this.tickCurrent,this.liquidity,this.tickSpacing,this.tickDataProvider,e,n,r));case 4:throw new Error("Unsupported hook");case 5:case"end":return t.stop()}}),t,this)})));return function(e,n,r){return t.apply(this,arguments)}}(),e.hookImpactsSwap=function(){return P.hasSwapPermissions(this.hooks)},f(t,[{key:"token0",get:function(){return this.currency0}},{key:"token1",get:function(){return this.currency1}},{key:"currency0Price",get:function(){var t;return null!=(t=this._currency0Price)?t:this._currency0Price=new o.Price(this.currency0,this.currency1,L,s.multiply(this.sqrtRatioX96,this.sqrtRatioX96))}},{key:"token0Price",get:function(){return this.currency0Price}},{key:"currency1Price",get:function(){var t;return null!=(t=this._currency1Price)?t:this._currency1Price=new o.Price(this.currency1,this.currency0,s.multiply(this.sqrtRatioX96,this.sqrtRatioX96),L)}},{key:"token1Price",get:function(){return this.currency1Price}},{key:"chainId",get:function(){return this.currency0.chainId}}])}();function D(t,e){return o.CurrencyAmount.fromFractionalAmount(N(t.currency,e),t.numerator,t.denominator)}function N(t,e){if(e.involvesCurrency(t))return t;if(e.involvesCurrency(t.wrapped))return t.wrapped;if(e.currency0.wrapped.equals(t))return e.currency0;if(e.currency1.wrapped.equals(t))return e.currency1;throw new Error("Expected currency "+t.symbol+" to be either "+e.currency0.symbol+" or "+e.currency1.symbol)}var U=function(){return f((function(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),this.pathInput=N(e,t[0]),this.pathOutput=N(n,t[t.length-1]);for(var o,a=[this.pathInput],u=T(t.entries());!(o=u()).done;){var s=o.value,p=s[1],c=a[s[0]];c.equals(p.currency0)||c.equals(p.currency1)||r(!1);var y=c.equals(p.currency0)?p.currency1:p.currency0;a.push(y)}this.pools=t,this.currencyPath=a,this.input=e,this.output=null!=n?n:a[a.length-1]}),[{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.currency0)?{nextInput:e.currency1,price:n.multiply(e.currency0Price)}:{nextInput:e.currency0,price:n.multiply(e.currency1Price)}}),this.pools[0].currency0.equals(this.input)?{nextInput:this.pools[0].currency1,price:this.pools[0].currency0Price}:{nextInput:this.pools[0].currency0,price:this.pools[0].currency1Price}).price;return this._midPrice=new o.Price(this.input,this.output,t.denominator,t.numerator)}}])}();function B(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.currencyPath.length}),0)-e.swaps.reduce((function(t,e){return t+e.route.currencyPath.length}),0):t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}var H=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.equals(t.route.input)}))||r(!1),e.every((function(t){return o.equals(t.route.output)}))||r(!1);for(var a,u=new Set,s=T(e);!(a=s()).done;)for(var p,c=T(a.value.route.pools);!(p=c()).done;){var y=p.value;u.add(C.getPoolId(y.currency0,y.currency1,y.fee,y.tickSpacing,y.hooks))}this.swaps=e,this.tradeType=n}t.exactIn=function(){var e=m(k().mark((function e(n,r){return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(n,r,o.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=m(k().mark((function e(n,r){return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",t.fromRoute(n,r,o.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=m(k().mark((function e(n,i,a){var u,s,p,c,y,l,d,m;return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(a!==o.TradeType.EXACT_INPUT){e.next=17;break}i.currency.equals(n.input)||r(!1),p=D(i,n.pools[0]),c=0;case 4:if(!(c<n.pools.length)){e.next=13;break}return y=n.pools[c],e.next=8,y.getOutputAmount(p);case 8:p=e.sent[0];case 10:c++,e.next=4;break;case 13:u=o.CurrencyAmount.fromFractionalAmount(n.input,i.numerator,i.denominator),s=o.CurrencyAmount.fromFractionalAmount(n.output,p.numerator,p.denominator),e.next=31;break;case 17:i.currency.equals(n.output)||r(!1),l=D(i,n.pools[n.pools.length-1]),d=n.pools.length-1;case 20:if(!(d>=0)){e.next=29;break}return m=n.pools[d],e.next=24,m.getInputAmount(l);case 24:l=e.sent[0];case 26:d--,e.next=20;break;case 29:u=o.CurrencyAmount.fromFractionalAmount(n.input,l.numerator,l.denominator),s=o.CurrencyAmount.fromFractionalAmount(n.output,i.numerator,i.denominator);case 31:return e.abrupt("return",new t({routes:[{inputAmount:u,outputAmount:s,route:n}],tradeType:a}));case 32:case"end":return e.stop()}}),e)})));return function(t,n,r){return e.apply(this,arguments)}}(),t.fromRoutes=function(){var e=m(k().mark((function e(n,r){return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,Promise.all(n.map(function(){var e=m(k().mark((function e(n){var i,o;return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return i=n.amount,o=n.route,e.next=3,t.fromRoute(o,i,r);case 3:return e.abrupt("return",e.sent.swaps[0]);case 5:case"end":return e.stop()}}),e)})));return function(t){return e.apply(this,arguments)}}()));case 2:return e.abrupt("return",new t({routes:e.sent,tradeType:r}));case 4:case"end":return e.stop()}}),e)})));return function(t,n){return e.apply(this,arguments)}}(),t.createUncheckedTrade=function(e){return new t(A({},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(_)&&r(!1),this.tradeType===o.TradeType.EXACT_OUTPUT)return e;var n=new o.Fraction(R).add(t).invert().multiply(e.quotient).quotient;return o.CurrencyAmount.fromRawAmount(e.currency,n)},e.maximumAmountIn=function(t,e){if(void 0===e&&(e=this.inputAmount),t.lessThan(_)&&r(!1),this.tradeType===o.TradeType.EXACT_INPUT)return e;var n=new o.Fraction(R).add(t).multiply(e.quotient).quotient;return o.CurrencyAmount.fromRawAmount(e.currency,n)},e.worstExecutionPrice=function(t){return new o.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var e=m(k().mark((function e(n,i,a,u,s,p,c){var y,l,d,m,h,f,T,A,v,b;return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:d=void 0===(l=(y=void 0===u?{}:u).maxNumResults)?3:l,h=void 0===(m=y.maxHops)?3:m,void 0===s&&(s=[]),void 0===p&&(p=i),void 0===c&&(c=[]),n.length>0||r(!1),h>0||r(!1),i===p||s.length>0||r(!1),f=p,T=0;case 9:if(!(T<n.length)){e.next=45;break}if((A=n[T]).currency0.equals(f.currency)||A.currency1.equals(f.currency)){e.next=13;break}return e.abrupt("continue",42);case 13:return v=void 0,e.prev=14,e.next=18,A.getOutputAmount(f);case 18:v=e.sent[0],e.next=27;break;case 22:if(e.prev=22,e.t0=e.catch(14),!e.t0.isInsufficientInputAmountError){e.next=26;break}return e.abrupt("continue",42);case 26:throw e.t0;case 27:if(!v.currency.equals(a)){e.next=38;break}return e.t1=o.sortedInsert,e.t2=c,e.next=32,t.fromRoute(new U([].concat(s,[A]),i.currency,a),i,o.TradeType.EXACT_INPUT);case 32:e.t3=e.sent,e.t4=d,e.t5=B,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=42;break;case 38:if(!(h>1&&n.length>1)){e.next=42;break}return b=n.slice(0,T).concat(n.slice(T+1,n.length)),e.next=42,t.bestTradeExactIn(b,i,a,{maxNumResults:d,maxHops:h-1},[].concat(s,[A]),v,c);case 42:T++,e.next=9;break;case 45:return e.abrupt("return",c);case 46:case"end":return e.stop()}}),e,null,[[14,22]])})));return function(t,n,r,i,o,a,u){return e.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var e=m(k().mark((function e(n,i,a,u,s,p,c){var y,l,d,m,h,f,T,A,v,b;return k().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:d=void 0===(l=(y=void 0===u?{}:u).maxNumResults)?3:l,h=void 0===(m=y.maxHops)?3:m,void 0===s&&(s=[]),void 0===p&&(p=a),void 0===c&&(c=[]),n.length>0||r(!1),h>0||r(!1),a===p||s.length>0||r(!1),f=p,T=0;case 9:if(!(T<n.length)){e.next=45;break}if((A=n[T]).currency0.equals(f.currency)||A.currency1.equals(f.currency)){e.next=13;break}return e.abrupt("continue",42);case 13:return v=void 0,e.prev=14,e.next=18,A.getInputAmount(f);case 18:v=e.sent[0],e.next=27;break;case 22:if(e.prev=22,e.t0=e.catch(14),!e.t0.isInsufficientReservesError){e.next=26;break}return e.abrupt("continue",42);case 26:throw e.t0;case 27:if(!v.currency.equals(i)){e.next=38;break}return e.t1=o.sortedInsert,e.t2=c,e.next=32,t.fromRoute(new U([A].concat(s),i,a.currency),a,o.TradeType.EXACT_OUTPUT);case 32:e.t3=e.sent,e.t4=d,e.t5=B,(0,e.t1)(e.t2,e.t3,e.t4,e.t5),e.next=42;break;case 38:if(!(h>1&&n.length>1)){e.next=42;break}return b=n.slice(0,T).concat(n.slice(T+1,n.length)),e.next=42,t.bestTradeExactOut(b,i,a,{maxNumResults:d,maxHops:h-1},[A].concat(s),v,c);case 42:T++,e.next=9;break;case 45:return e.abrupt("return",c);case 46:case"end":return e.stop()}}),e,null,[[14,22]])})));return function(t,n,r,i,o,a,u){return e.apply(this,arguments)}}(),f(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,e=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,e){return t.add(e)}),o.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)}),o.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 o.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=o.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),n=T(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 o.Percent(i.numerator,i.denominator),this._priceImpact}}])}();function F(t,e,n){var r=a.TickMath.getSqrtRatioAtTick(n),i=s.multiply(r,r);return I(t,e)?new o.Price(t,e,L,i):new o.Price(t,e,i,L)}var X,W,K,j=function(){function t(t){var e=t.pool,n=t.liquidity,i=t.tickLower,o=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,i<o||r(!1),i>=a.TickMath.MIN_TICK&&i%e.tickSpacing==0||r(!1),o<=a.TickMath.MAX_TICK&&o%e.tickSpacing==0||r(!1),this.pool=e,this.tickLower=i,this.tickUpper=o,this.liquidity=s.BigInt(n)}var e=t.prototype;return e.ratiosAfterSlippage=function(t){var e=this.pool.token0Price.asFraction.multiply(new o.Percent(1).subtract(t)),n=this.pool.token0Price.asFraction.multiply(t.add(1)),r=a.encodeSqrtRatioX96(e.numerator,e.denominator);s.lessThanOrEqual(r,a.TickMath.MIN_SQRT_RATIO)&&(r=s.add(a.TickMath.MIN_SQRT_RATIO,s.BigInt(1)));var i=a.encodeSqrtRatioX96(n.numerator,n.denominator);return s.greaterThanOrEqual(i,a.TickMath.MAX_SQRT_RATIO)&&(i=s.subtract(a.TickMath.MAX_SQRT_RATIO,s.BigInt(1))),{sqrtRatioX96Lower:r,sqrtRatioX96Upper:i}},e.mintAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new C(this.pool.token0,this.pool.token1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,i,0,a.TickMath.getTickAtSqrtRatio(i)),u=new t({pool:new C(this.pool.token0,this.pool.token1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,r,0,a.TickMath.getTickAtSqrtRatio(r)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount1;return{amount0:new t({pool:o,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:u}},e.burnAmountsWithSlippage=function(e){var n=this.ratiosAfterSlippage(e),r=n.sqrtRatioX96Upper,i=n.sqrtRatioX96Lower,o=new C(this.pool.currency0,this.pool.currency1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,i,0,a.TickMath.getTickAtSqrtRatio(i)),u=new t({pool:new C(this.pool.currency0,this.pool.currency1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,r,0,a.TickMath.getTickAtSqrtRatio(r)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,s=new t({pool:o,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:u.quotient,amount1:s.quotient}},e.permitBatchData=function(t,e,n,r){var i=this.mintAmountsWithSlippage(t);return{details:[{token:this.pool.currency0.wrapped.address,amount:i.amount0,expiration:r,nonce:n},{token:this.pool.currency1.wrapped.address,amount:i.amount1,expiration:r,nonce:n}],spender:e,sigDeadline:r}},t.fromAmounts=function(e){var n=e.pool,r=e.tickLower,i=e.tickUpper,o=e.amount0,u=e.amount1,s=e.useFullPrecision,p=a.TickMath.getSqrtRatioAtTick(r),c=a.TickMath.getSqrtRatioAtTick(i);return new t({pool:n,tickLower:r,tickUpper:i,liquidity:a.maxLiquidityForAmounts(n.sqrtRatioX96,p,c,o,u,s)})},t.fromAmount0=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:e.amount0,amount1:o.MaxUint256,useFullPrecision:e.useFullPrecision})},t.fromAmount1=function(e){return t.fromAmounts({pool:e.pool,tickLower:e.tickLower,tickUpper:e.tickUpper,amount0:o.MaxUint256,amount1:e.amount1,useFullPrecision:!0})},f(t,[{key:"token0PriceLower",get:function(){return F(this.pool.currency0,this.pool.currency1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return F(this.pool.currency0,this.pool.currency1,this.tickUpper)}},{key:"amount0",get:function(){return this._token0Amount||(this._token0Amount=o.CurrencyAmount.fromRawAmount(this.pool.currency0,this.pool.tickCurrent<this.tickLower?a.SqrtPriceMath.getAmount0Delta(a.TickMath.getSqrtRatioAtTick(this.tickLower),a.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):this.pool.tickCurrent<this.tickUpper?a.SqrtPriceMath.getAmount0Delta(this.pool.sqrtRatioX96,a.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):_)),this._token0Amount}},{key:"amount1",get:function(){return this._token1Amount||(this._token1Amount=o.CurrencyAmount.fromRawAmount(this.pool.currency1,this.pool.tickCurrent<this.tickLower?_:a.SqrtPriceMath.getAmount1Delta(a.TickMath.getSqrtRatioAtTick(this.tickLower),this.pool.tickCurrent<this.tickUpper?this.pool.sqrtRatioX96:a.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1))),this._token1Amount}},{key:"mintAmounts",get:function(){return null===this._mintAmounts?this.pool.tickCurrent<this.tickLower?{amount0:a.SqrtPriceMath.getAmount0Delta(a.TickMath.getSqrtRatioAtTick(this.tickLower),a.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:_}:this.pool.tickCurrent<this.tickUpper?{amount0:a.SqrtPriceMath.getAmount0Delta(this.pool.sqrtRatioX96,a.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:a.SqrtPriceMath.getAmount1Delta(a.TickMath.getSqrtRatioAtTick(this.tickLower),this.pool.sqrtRatioX96,this.liquidity,!0)}:{amount0:_,amount1:a.SqrtPriceMath.getAmount1Delta(a.TickMath.getSqrtRatioAtTick(this.tickLower),a.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0)}:this._mintAmounts}}])}(),z=function(t,e){var n=t.pools.map((function(t){return t}));e&&(n=n.reverse());for(var r,i=e?t.pathOutput:t.pathInput,o=[],a=T(n);!(r=a()).done;){var u=r.value,s=i.equals(u.currency0)?u.currency1:u.currency0;o.push({intermediateCurrency:s.isNative?q:s.address,fee:u.fee,tickSpacing:u.tickSpacing,hooks:u.hooks,hookData:"0x"}),i=s}return e?o.reverse():o};(W=exports.Actions||(exports.Actions={}))[W.INCREASE_LIQUIDITY=0]="INCREASE_LIQUIDITY",W[W.DECREASE_LIQUIDITY=1]="DECREASE_LIQUIDITY",W[W.MINT_POSITION=2]="MINT_POSITION",W[W.BURN_POSITION=3]="BURN_POSITION",W[W.SWAP_EXACT_IN_SINGLE=6]="SWAP_EXACT_IN_SINGLE",W[W.SWAP_EXACT_IN=7]="SWAP_EXACT_IN",W[W.SWAP_EXACT_OUT_SINGLE=8]="SWAP_EXACT_OUT_SINGLE",W[W.SWAP_EXACT_OUT=9]="SWAP_EXACT_OUT",W[W.SETTLE=11]="SETTLE",W[W.SETTLE_ALL=12]="SETTLE_ALL",W[W.SETTLE_PAIR=13]="SETTLE_PAIR",W[W.TAKE=14]="TAKE",W[W.TAKE_ALL=15]="TAKE_ALL",W[W.TAKE_PORTION=16]="TAKE_PORTION",W[W.TAKE_PAIR=17]="TAKE_PAIR",W[W.CLOSE_CURRENCY=18]="CLOSE_CURRENCY",W[W.SWEEP=20]="SWEEP",W[W.UNWRAP=22]="UNWRAP",(K=exports.Subparser||(exports.Subparser={}))[K.V4SwapExactInSingle=0]="V4SwapExactInSingle",K[K.V4SwapExactIn=1]="V4SwapExactIn",K[K.V4SwapExactOutSingle=2]="V4SwapExactOutSingle",K[K.V4SwapExactOut=3]="V4SwapExactOut",K[K.PoolKey=4]="PoolKey";var V=((X={})[exports.Actions.INCREASE_LIQUIDITY]=[{name:"tokenId",type:"uint256"},{name:"liquidity",type:"uint256"},{name:"amount0Max",type:"uint128"},{name:"amount1Max",type:"uint128"},{name:"hookData",type:"bytes"}],X[exports.Actions.DECREASE_LIQUIDITY]=[{name:"tokenId",type:"uint256"},{name:"liquidity",type:"uint256"},{name:"amount0Min",type:"uint128"},{name:"amount1Min",type:"uint128"},{name:"hookData",type:"bytes"}],X[exports.Actions.MINT_POSITION]=[{name:"poolKey",type:"(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)",subparser:exports.Subparser.PoolKey},{name:"tickLower",type:"int24"},{name:"tickUpper",type:"int24"},{name:"liquidity",type:"uint256"},{name:"amount0Max",type:"uint128"},{name:"amount1Max",type:"uint128"},{name:"owner",type:"address"},{name:"hookData",type:"bytes"}],X[exports.Actions.BURN_POSITION]=[{name:"tokenId",type:"uint256"},{name:"amount0Min",type:"uint128"},{name:"amount1Min",type:"uint128"},{name:"hookData",type:"bytes"}],X[exports.Actions.SWAP_EXACT_IN_SINGLE]=[{name:"swap",type:"((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 amountIn,uint128 amountOutMinimum,bytes hookData)",subparser:exports.Subparser.V4SwapExactInSingle}],X[exports.Actions.SWAP_EXACT_IN]=[{name:"swap",type:"(address currencyIn,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountIn,uint128 amountOutMinimum)",subparser:exports.Subparser.V4SwapExactIn}],X[exports.Actions.SWAP_EXACT_OUT_SINGLE]=[{name:"swap",type:"((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 amountOut,uint128 amountInMaximum,bytes hookData)",subparser:exports.Subparser.V4SwapExactOutSingle}],X[exports.Actions.SWAP_EXACT_OUT]=[{name:"swap",type:"(address currencyOut,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountOut,uint128 amountInMaximum)",subparser:exports.Subparser.V4SwapExactOut}],X[exports.Actions.SETTLE]=[{name:"currency",type:"address"},{name:"amount",type:"uint256"},{name:"payerIsUser",type:"bool"}],X[exports.Actions.SETTLE_ALL]=[{name:"currency",type:"address"},{name:"maxAmount",type:"uint256"}],X[exports.Actions.SETTLE_PAIR]=[{name:"currency0",type:"address"},{name:"currency1",type:"address"}],X[exports.Actions.TAKE]=[{name:"currency",type:"address"},{name:"recipient",type:"address"},{name:"amount",type:"uint256"}],X[exports.Actions.TAKE_ALL]=[{name:"currency",type:"address"},{name:"minAmount",type:"uint256"}],X[exports.Actions.TAKE_PORTION]=[{name:"currency",type:"address"},{name:"recipient",type:"address"},{name:"bips",type:"uint256"}],X[exports.Actions.TAKE_PAIR]=[{name:"currency0",type:"address"},{name:"currency1",type:"address"},{name:"recipient",type:"address"}],X[exports.Actions.CLOSE_CURRENCY]=[{name:"currency",type:"address"}],X[exports.Actions.SWEEP]=[{name:"currency",type:"address"},{name:"recipient",type:"address"}],X[exports.Actions.UNWRAP]=[{name:"amount",type:"uint256"}],X),G=function(){function t(){this.actions="0x",this.params=[]}var e=t.prototype;return e.addAction=function(t,e){var n=function(t,e){return{action:t,encodedInput:u.defaultAbiCoder.encode(V[t].map((function(t){return t.type})),e)}}(t,e);return this.params.push(n.encodedInput),this.actions=this.actions.concat(n.action.toString(16).padStart(2,"0")),this},e.addTrade=function(t,e){var n=t.tradeType===o.TradeType.EXACT_OUTPUT;n&&(e||r(!1)),1!==t.swaps.length&&r(!1);var i=n?exports.Actions.SWAP_EXACT_OUT:exports.Actions.SWAP_EXACT_IN,a=Y(t.route.pathInput),u=Y(t.route.pathOutput);return this.addAction(i,[n?{currencyOut:u,path:z(t.route,n),amountInMaximum:t.maximumAmountIn(null!=e?e:new o.Percent(0)).quotient.toString(),amountOut:t.outputAmount.quotient.toString()}:{currencyIn:a,path:z(t.route,n),amountIn:t.inputAmount.quotient.toString(),amountOutMinimum:e?t.minimumAmountOut(e).quotient.toString():0}]),this},e.addSettle=function(t,e,n){return this.addAction(exports.Actions.SETTLE,[Y(t),null!=n?n:0,e]),this},e.addTake=function(t,e,n){var r=null!=n?n:0;return this.addAction(exports.Actions.TAKE,[Y(t),e,r]),this},e.addUnwrap=function(t){return this.addAction(exports.Actions.UNWRAP,[t]),this},e.finalize=function(){return u.defaultAbiCoder.encode(["bytes","bytes[]"],[this.actions,this.params])},t}();function Y(t){return t.isNative?q:t.wrapped.address}function Q(t){return t.isNative?q:t.wrapped.address}var Z=function(t){function e(){return t.apply(this,arguments)||this}var n,r;r=t,(n=e).prototype=Object.create(r.prototype),n.prototype.constructor=n,v(n,r);var i=e.prototype;return i.addMint=function(t,e,n,r,i,o,a,u){void 0===u&&(u="0x");var s=[C.getPoolKey(t.currency0,t.currency1,t.fee,t.tickSpacing,t.hooks),e,n,r.toString(),i.toString(),o.toString(),a,u];this.addAction(exports.Actions.MINT_POSITION,s)},i.addIncrease=function(t,e,n,r,i){void 0===i&&(i="0x");var o=[t.toString(),e.toString(),n.toString(),r.toString(),i];this.addAction(exports.Actions.INCREASE_LIQUIDITY,o)},i.addDecrease=function(t,e,n,r,i){void 0===i&&(i="0x");var o=[t.toString(),e.toString(),n.toString(),r.toString(),i];this.addAction(exports.Actions.DECREASE_LIQUIDITY,o)},i.addBurn=function(t,e,n,r){void 0===r&&(r="0x");var i=[t.toString(),e.toString(),n.toString(),r];this.addAction(exports.Actions.BURN_POSITION,i)},i.addSettlePair=function(t,e){var n=[Q(t),Q(e)];this.addAction(exports.Actions.SETTLE_PAIR,n)},i.addTakePair=function(t,e,n){var r=[Q(t),Q(e),n];this.addAction(exports.Actions.TAKE_PAIR,r)},i.addSweep=function(t,e){var n=[Q(t),e];this.addAction(exports.Actions.SWEEP,n)},e}(G);function $(t){var e=s.BigInt(t).toString(16);return e.length%2!=0&&(e="0"+e),"0x"+e}var J=function(){function t(){}return t.parseCalldata=function(e){var n=p.ethers.utils.defaultAbiCoder.decode(["bytes","bytes[]"],e),r=n[1];return{actions:t.getActions(n[0]).map((function(t,e){var n=V[t],i=p.ethers.utils.defaultAbiCoder.decode(n.map((function(t){return t.type})),r[e]).map((function(t,e){switch(n[e].subparser){case exports.Subparser.V4SwapExactInSingle:return{name:n[e].name,value:(r=t,i=r[0],o=r[1],a=r[2],u=r[3],s=r[4],p=i[0],c=i[1],y=i[2],l=i[3],d=i[4],{poolKey:{currency0:p,currency1:c,fee:y,tickSpacing:l,hooks:d},zeroForOne:o,amountIn:a,amountOutMinimum:u,hookData:s})};case exports.Subparser.V4SwapExactIn:return{name:n[e].name,value:nt(t)};case exports.Subparser.V4SwapExactOutSingle:return{name:n[e].name,value:rt(t)};case exports.Subparser.V4SwapExactOut:return{name:n[e].name,value:it(t)};case exports.Subparser.PoolKey:return{name:n[e].name,value:tt(t)};default:return{name:n[e].name,value:t}}var r,i,o,a,u,s,p,c,y,l,d}));return{actionName:exports.Actions[t],actionType:t,params:i}}))}},t.getActions=function(t){for(var e=[],n=2;n<t.length;n+=2){var r=t.substring(n,n+2);e.push(parseInt(r,16))}return e},t}();function tt(t){var e=t[3],n=t[4];return{currency0:t[0],currency1:t[1],fee:parseInt(t[2]),tickSpacing:parseInt(e),hooks:n}}function et(t){var e=t[2],n=t[3],r=t[4];return{intermediateCurrency:t[0],fee:parseInt(t[1]),tickSpacing:parseInt(e),hooks:n,hookData:r}}function nt(t){var e=t[0],n=t[2],r=t[3];return{path:t[1].map((function(t){return et(t)})),currencyIn:e,amountIn:n,amountOutMinimum:r}}function rt(t){var e=t[0];return{poolKey:{currency0:e.currency0,currency1:e.currency1,fee:e.fee,tickSpacing:e.tickSpacing,hooks:e.hooks},zeroForOne:t[1],amountOut:t[2],amountInMaximum:t[3],hookData:t[4]}}function it(t){var e=t[0],n=t[2],r=t[3];return{path:t[1].map((function(t){return et(t)})),currencyOut:e,amountOut:n,amountInMaximum:r}}var ot="0x0000000000000000000000000000000000000001",at=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.decodeMulticall=function(e){return t.INTERFACE.decodeFunctionData("multicall",e)[0]},t}();at.INTERFACE=new c.Interface(y.abi);var ut=[{type:"constructor",inputs:[{name:"_poolManager",type:"address",internalType:"contract IPoolManager"},{name:"_permit2",type:"address",internalType:"contract IAllowanceTransfer"},{name:"_unsubscribeGasLimit",type:"uint256",internalType:"uint256"},{name:"_tokenDescriptor",type:"address",internalType:"contract IPositionDescriptor"},{name:"_weth9",type:"address",internalType:"contract IWETH9"}],stateMutability:"nonpayable"},{type:"receive",stateMutability:"payable"},{type:"function",name:"DOMAIN_SEPARATOR",inputs:[],outputs:[{name:"",type:"bytes32",internalType:"bytes32"}],stateMutability:"view"},{type:"function",name:"WETH9",inputs:[],outputs:[{name:"",type:"address",internalType:"contract IWETH9"}],stateMutability:"view"},{type:"function",name:"approve",inputs:[{name:"spender",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"balanceOf",inputs:[{name:"owner",type:"address",internalType:"address"}],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"getApproved",inputs:[{name:"",type:"uint256",internalType:"uint256"}],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"getPoolAndPositionInfo",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"poolKey",type:"tuple",internalType:"struct PoolKey",components:[{name:"currency0",type:"address",internalType:"Currency"},{name:"currency1",type:"address",internalType:"Currency"},{name:"fee",type:"uint24",internalType:"uint24"},{name:"tickSpacing",type:"int24",internalType:"int24"},{name:"hooks",type:"address",internalType:"contract IHooks"}]},{name:"info",type:"uint256",internalType:"PositionInfo"}],stateMutability:"view"},{type:"function",name:"getPositionLiquidity",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"liquidity",type:"uint128",internalType:"uint128"}],stateMutability:"view"},{type:"function",name:"initializePool",inputs:[{name:"key",type:"tuple",internalType:"struct PoolKey",components:[{name:"currency0",type:"address",internalType:"Currency"},{name:"currency1",type:"address",internalType:"Currency"},{name:"fee",type:"uint24",internalType:"uint24"},{name:"tickSpacing",type:"int24",internalType:"int24"},{name:"hooks",type:"address",internalType:"contract IHooks"}]},{name:"sqrtPriceX96",type:"uint160",internalType:"uint160"}],outputs:[{name:"",type:"int24",internalType:"int24"}],stateMutability:"payable"},{type:"function",name:"isApprovedForAll",inputs:[{name:"",type:"address",internalType:"address"},{name:"",type:"address",internalType:"address"}],outputs:[{name:"",type:"bool",internalType:"bool"}],stateMutability:"view"},{type:"function",name:"modifyLiquidities",inputs:[{name:"unlockData",type:"bytes",internalType:"bytes"},{name:"deadline",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"modifyLiquiditiesWithoutUnlock",inputs:[{name:"actions",type:"bytes",internalType:"bytes"},{name:"params",type:"bytes[]",internalType:"bytes[]"}],outputs:[],stateMutability:"payable"},{type:"function",name:"msgSender",inputs:[],outputs:[{name:"",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"multicall",inputs:[{name:"data",type:"bytes[]",internalType:"bytes[]"}],outputs:[{name:"results",type:"bytes[]",internalType:"bytes[]"}],stateMutability:"payable"},{type:"function",name:"name",inputs:[],outputs:[{name:"",type:"string",internalType:"string"}],stateMutability:"view"},{type:"function",name:"nextTokenId",inputs:[],outputs:[{name:"",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"nonces",inputs:[{name:"owner",type:"address",internalType:"address"},{name:"word",type:"uint256",internalType:"uint256"}],outputs:[{name:"bitmap",type:"uint256",internalType:"uint256"}],stateMutability:"view"},{type:"function",name:"ownerOf",inputs:[{name:"id",type:"uint256",internalType:"uint256"}],outputs:[{name:"owner",type:"address",internalType:"address"}],stateMutability:"view"},{type:"function",name:"permit",inputs:[{name:"spender",type:"address",internalType:"address"},{name:"tokenId",type:"uint256",internalType:"uint256"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"signature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"permit",inputs:[{name:"owner",type:"address",internalType:"address"},{name:"permitSingle",type:"tuple",internalType:"struct IAllowanceTransfer.PermitSingle",components:[{name:"details",type:"tuple",internalType:"struct IAllowanceTransfer.PermitDetails",components:[{name:"token",type:"address",internalType:"address"},{name:"amount",type:"uint160",internalType:"uint160"},{name:"expiration",type:"uint48",internalType:"uint48"},{name:"nonce",type:"uint48",internalType:"uint48"}]},{name:"spender",type:"address",internalType:"address"},{name:"sigDeadline",type:"uint256",internalType:"uint256"}]},{name:"signature",type:"bytes",internalType:"bytes"}],outputs:[{name:"err",type:"bytes",internalType:"bytes"}],stateMutability:"payable"},{type:"function",name:"permit2",inputs:[],outputs:[{name:"",type:"address",internalType:"contract IAllowanceTransfer"}],stateMutability:"view"},{type:"function",name:"permitBatch",inputs:[{name:"owner",type:"address",internalType:"address"},{name:"_permitBatch",type:"tuple",internalType:"struct IAllowanceTransfer.PermitBatch",components:[{name:"details",type:"tuple[]",internalType:"struct IAllowanceTransfer.PermitDetails[]",components:[{name:"token",type:"address",internalType:"address"},{name:"amount",type:"uint160",internalType:"uint160"},{name:"expiration",type:"uint48",internalType:"uint48"},{name:"nonce",type:"uint48",internalType:"uint48"}]},{name:"spender",type:"address",internalType:"address"},{name:"sigDeadline",type:"uint256",internalType:"uint256"}]},{name:"signature",type:"bytes",internalType:"bytes"}],outputs:[{name:"err",type:"bytes",internalType:"bytes"}],stateMutability:"payable"},{type:"function",name:"permitForAll",inputs:[{name:"owner",type:"address",internalType:"address"},{name:"operator",type:"address",internalType:"address"},{name:"approved",type:"bool",internalType:"bool"},{name:"deadline",type:"uint256",internalType:"uint256"},{name:"nonce",type:"uint256",internalType:"uint256"},{name:"signature",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"payable"},{type:"function",name:"poolKeys",inputs:[{name:"poolId",type:"bytes25",internalType:"bytes25"}],outputs:[{name:"currency0",type:"address",internalType:"Currency"},{name:"currency1",type:"address",internalType:"Currency"},{name:"fee",type:"uint24",internalType:"uint24"},{name:"tickSpacing",type:"int24",internalType:"int24"},{name:"hooks",type:"address",internalType:"contract IHooks"}],stateMutability:"view"},{type:"function",name:"poolManager",inputs:[],outputs:[{name:"",type:"address",internalType:"contract IPoolManager"}],stateMutability:"view"},{type:"function",name:"positionInfo",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"}],outputs:[{name:"info",type:"uint256",internalType:"PositionInfo"}],stateMutability:"view"},{type:"function",name:"revokeNonce",inputs:[{name:"nonce",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"payable"},{type:"function",name:"safeTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"safeTransferFrom",inputs:[{name:"from",type:"address",internalType:"address"},{name:"to",type:"address",internalType:"address"},{name:"id",type:"uint256",internalType:"uint256"},{name:"data",type:"bytes",internalType:"bytes"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"setApprovalForAll",inputs:[{name:"operator",type:"address",internalType:"address"},{name:"approved",type:"bool",internalType:"bool"}],outputs:[],stateMutability:"nonpayable"},{type:"function",name:"subscribe",inputs:[{name:"tokenId",type:"uint256",internalType:"uint256"},{name:"newSubscriber",type:"address",internalType:"address"},{name:"data",