New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@uniswap/v4-sdk

Package Overview
Dependencies
Maintainers
2
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniswap/v4-sdk - npm Package Compare versions

Comparing version 1.3.0 to 1.4.0

3

dist/internalConstants.d.ts

@@ -19,2 +19,5 @@ import JSBI from 'jsbi';

export declare const NO_NATIVE = "NO_NATIVE";
export declare const ZERO_LIQUIDITY = "ZERO_LIQUIDITY";
export declare const NO_SQRT_PRICE = "NO_SQRT_PRICE";
export declare const CANNOT_BURN = "CANNOT_BURN";
/**

@@ -21,0 +24,0 @@ * Function fragments that exist on the PositionManager contract.

11

dist/PositionManager.d.ts

@@ -73,6 +73,2 @@ import { BigintIsh, Percent, CurrencyAmount, Currency, NativeCurrency } from '@uniswap/sdk-core';

permit?: NFTPermitOptions;
/**
* Parameters to be passed on to collect
*/
collectOptions: Omit<CollectSpecificOptions, 'tokenId'>;
}

@@ -133,4 +129,11 @@ export interface CollectSpecificOptions {

static addCallParameters(position: Position, options: AddLiquidityOptions): MethodParameters;
/**
* Produces the calldata for completely or partially exiting a position
* @param position The position to exit
* @param options Additional information necessary for generating the calldata
* @returns The call parameters
*/
static removeCallParameters(position: Position, options: RemoveLiquidityOptions): MethodParameters;
private static encodeInitializePool;
static encodeModifyLiquidities(unlockData: string, deadline: BigintIsh): string;
}

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

"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var r,e=t(require("tiny-invariant")),n=require("@ethersproject/solidity"),i=require("@uniswap/sdk-core"),o=require("@uniswap/v3-sdk"),u=require("ethers/lib/utils"),c=t(require("jsbi"));function a(){a=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},o="function"==typeof Symbol?Symbol:{},u=o.iterator||"@@iterator",c=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function p(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{p({},"")}catch(t){p=function(t,r,e){return t[r]=e}}function h(t,r,e,n){var o=Object.create((r&&r.prototype instanceof A?r:A).prototype),u=new b(n||[]);return i(o,"_invoke",{value:E(t,e,u)}),o}function l(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var d="suspendedStart",m="executing",f="completed",y={};function A(){}function k(){}function v(){}var g={};p(g,u,(function(){return this}));var T=Object.getPrototypeOf,w=T&&T(T(L([])));w&&w!==e&&n.call(w,u)&&(g=w);var I=v.prototype=A.prototype=Object.create(g);function x(t){["next","throw","return"].forEach((function(r){p(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function e(i,o,u,c){var a=l(t[i],t,o);if("throw"!==a.type){var s=a.arg,p=s.value;return p&&"object"==typeof p&&n.call(p,"__await")?r.resolve(p.__await).then((function(t){e("next",t,u,c)}),(function(t){e("throw",t,u,c)})):r.resolve(p).then((function(t){s.value=t,u(s)}),(function(t){return e("throw",t,u,c)}))}c(a.arg)}var o;i(this,"_invoke",{value:function(t,n){function i(){return new r((function(r,i){e(t,n,r,i)}))}return o=o?o.then(i,i):i()}})}function E(r,e,n){var i=d;return function(o,u){if(i===m)throw new Error("Generator is already running");if(i===f){if("throw"===o)throw u;return{value:t,done:!0}}for(n.method=o,n.arg=u;;){var c=n.delegate;if(c){var a=_(c,n);if(a){if(a===y)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===d)throw i=f,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=m;var s=l(r,e,n);if("normal"===s.type){if(i=n.done?f:"suspendedYield",s.arg===y)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(i=f,n.method="throw",n.arg=s.arg)}}}function _(r,e){var n=e.method,i=r.iterator[n];if(i===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var o=l(i,r.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,y;var u=o.arg;return u?u.done?(e[r.resultName]=u.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,y):u:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function P(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function q(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function b(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function L(r){if(r||""===r){var e=r[u];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var i=-1,o=function e(){for(;++i<r.length;)if(n.call(r,i))return e.value=r[i],e.done=!1,e;return e.value=t,e.done=!0,e};return o.next=o}}throw new TypeError(typeof r+" is not iterable")}return k.prototype=v,i(I,"constructor",{value:v,configurable:!0}),i(v,"constructor",{value:k,configurable:!0}),k.displayName=p(v,s,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===k||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,p(t,s,"GeneratorFunction")),t.prototype=Object.create(I),t},r.awrap=function(t){return{__await:t}},x(S.prototype),p(S.prototype,c,(function(){return this})),r.AsyncIterator=S,r.async=function(t,e,n,i,o){void 0===o&&(o=Promise);var u=new S(h(t,e,n,i),o);return r.isGeneratorFunction(e)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},x(I),p(I,s,"Generator"),p(I,u,(function(){return this})),p(I,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=L,b.prototype={constructor:b,reset:function(r){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(q),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function i(n,i){return c.type="throw",c.arg=r,e.next=n,i&&(e.method="next",e.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],c=u.completion;if("root"===u.tryLoc)return i("end");if(u.tryLoc<=this.prev){var a=n.call(u,"catchLoc"),s=n.call(u,"finallyLoc");if(a&&s){if(this.prev<u.catchLoc)return i(u.catchLoc,!0);if(this.prev<u.finallyLoc)return i(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return i(u.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return i(u.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var i=this.tryEntries[e];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=t,u.arg=r,o?(this.method="next",this.next=o.finallyLoc,y):this.complete(u)},complete:function(t,r){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&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),q(e),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var i=n.arg;q(e)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:L(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),y}},r}function s(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof r?r:String(r)}function p(t,r,e,n,i,o,u){try{var c=t[o](u),a=c.value}catch(t){return void e(t)}c.done?r(a):Promise.resolve(a).then(n,i)}function h(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var o=t.apply(r,e);function u(t){p(o,n,i,u,c,"next",t)}function c(t){p(o,n,i,u,c,"throw",t)}u(void 0)}))}}function l(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}function d(t,r,e){return r&&l(t.prototype,r),e&&l(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function m(){return(m=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function f(t,r){return(f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t})(t,r)}function y(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function A(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,r){if(t){if("string"==typeof t)return y(t,void 0);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?y(t,void 0):void 0}}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}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 k(t,r){return!!t.isNative||!r.isNative&&t.wrapped.sortsBefore(r.wrapped)}var v,g,T=require("ethers").constants.AddressZero,w=c.BigInt(-1),I=c.BigInt(0),x=c.BigInt(1),S=c.exponentiate(c.exponentiate(c.BigInt(2),c.BigInt(96)),c.BigInt(2));!function(t){t.INITIALIZE_POOL="initializePool",t.MODIFY_LIQUIDITIES="modifyLiquidities"}(v||(v={})),function(t){t[t.LOWEST=100]="LOWEST",t[t.LOW=500]="LOW",t[t.MEDIUM=3e3]="MEDIUM",t[t.HIGH=1e4]="HIGH"}(g||(g={})),(r={})[g.LOWEST]=1,r[g.LOW]=10,r[g.MEDIUM]=60,r[g.HIGH]=200;var E=new o.NoTickDataProvider,_=function(){function t(r,n,i,a,s,p,h,l,d){void 0===d&&(d=E),u.isAddress(s)||e(!1),Number.isInteger(i)&&(8388608===i||i<1e6)||e(!1),8388608===i&&(Number(s)>0||e(!1));var m=o.TickMath.getSqrtRatioAtTick(l),f=o.TickMath.getSqrtRatioAtTick(l+1);c.greaterThanOrEqual(c.BigInt(p),m)&&c.lessThanOrEqual(c.BigInt(p),f)||e(!1);var y=k(r,n)?[r,n]:[n,r];this.currency0=y[0],this.currency1=y[1],this.fee=i,this.sqrtRatioX96=c.BigInt(p),this.tickSpacing=a,this.hooks=s,this.liquidity=c.BigInt(h),this.tickCurrent=l,this.tickDataProvider=Array.isArray(d)?new o.TickListDataProvider(d,a):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,r,n,i,o){u.isAddress(o)||e(!1);var c=k(t,r)?[t,r]:[r,t],a=c[0],s=c[1];return{currency0:a.isNative?T:a.wrapped.address,currency1:s.isNative?T:s.wrapped.address,fee:n,tickSpacing:i,hooks:o}},t.getPoolId=function(t,r,e,i,o){var c=k(t,r)?[t,r]:[r,t],a=c[0],s=c[1];return n.keccak256(["bytes"],[u.defaultAbiCoder.encode(["address","address","uint24","int24","address"],[a.isNative?T:a.wrapped.address,s.isNative?T:s.wrapped.address,e,i,o])])};var r=t.prototype;return r.involvesCurrency=function(t){return t.equals(this.currency0)||t.equals(this.currency1)},r.involvesToken=function(t){return this.involvesCurrency(t)},r.priceOf=function(t){return this.involvesCurrency(t)||e(!1),t.equals(this.currency0)?this.currency0Price:this.currency1Price},r.getOutputAmount=function(){var r=h(a().mark((function r(n,o){var u,s,p,h,l;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return this.involvesCurrency(n.currency)||e(!1),u=n.currency.equals(this.currency0),r.next=4,this.swap(u,n.quotient,o);case 4:return p=(s=r.sent).sqrtRatioX96,h=s.liquidity,l=s.tickCurrent,r.abrupt("return",[i.CurrencyAmount.fromRawAmount(u?this.currency1:this.currency0,c.multiply(s.amountCalculated,w)),new t(this.currency0,this.currency1,this.fee,this.tickSpacing,this.hooks,p,h,l,this.tickDataProvider)]);case 11:case"end":return r.stop()}}),r,this)})));return function(t,e){return r.apply(this,arguments)}}(),r.getInputAmount=function(){var r=h(a().mark((function r(n,o){var u,s,p,h,l;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return this.involvesCurrency(n.currency)||e(!1),u=n.currency.equals(this.currency1),r.next=4,this.swap(u,c.multiply(n.quotient,w),o);case 4:return p=(s=r.sent).sqrtRatioX96,h=s.liquidity,l=s.tickCurrent,r.abrupt("return",[i.CurrencyAmount.fromRawAmount(u?this.currency0:this.currency1,s.amountCalculated),new t(this.currency0,this.currency1,this.fee,this.tickSpacing,this.hooks,p,h,l,this.tickDataProvider)]);case 11:case"end":return r.stop()}}),r,this)})));return function(t,e){return r.apply(this,arguments)}}(),r.swap=function(){var t=h(a().mark((function t(r,e,n){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.nonImpactfulHook()){t.next=4;break}return t.abrupt("return",o.v3Swap(c.BigInt(this.fee),this.sqrtRatioX96,this.tickCurrent,this.liquidity,this.tickSpacing,this.tickDataProvider,r,e,n));case 4:throw new Error("Unsupported hook");case 5:case"end":return t.stop()}}),t,this)})));return function(r,e,n){return t.apply(this,arguments)}}(),r.nonImpactfulHook=function(){return this.hooks===T},d(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 i.Price(this.currency0,this.currency1,S,c.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 i.Price(this.currency1,this.currency0,c.multiply(this.sqrtRatioX96,this.sqrtRatioX96),S)}},{key:"token1Price",get:function(){return this.currency1Price}},{key:"chainId",get:function(){return this.currency0.chainId}}]),t}(),P=function(){function t(t,r,n){this._midPrice=null,t.length>0||e(!1);var i=t[0].chainId;t.every((function(t){return t.chainId===i}))||e(!1),t[0].involvesCurrency(r)||e(!1),t[t.length-1].involvesCurrency(n)||e(!1);for(var o,u=[r],c=A(t.entries());!(o=c()).done;){var a=o.value,s=a[1],p=u[a[0]];p.equals(s.currency0)||p.equals(s.currency1)||e(!1);var h=p.equals(s.currency0)?s.currency1:s.currency0;u.push(h)}this.pools=t,this.currencyPath=u,this.input=r,this.output=null!=n?n:u[u.length-1]}return d(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,r){var e=t.price;return t.nextInput.equals(r.currency0)?{nextInput:r.currency1,price:e.multiply(r.currency0Price)}:{nextInput:r.currency0,price:e.multiply(r.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 i.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function q(t,r){return t.inputAmount.currency.equals(r.inputAmount.currency)||e(!1),t.outputAmount.currency.equals(r.outputAmount.currency)||e(!1),t.outputAmount.equalTo(r.outputAmount)?t.inputAmount.equalTo(r.inputAmount)?t.swaps.reduce((function(t,r){return t+r.route.currencyPath.length}),0)-r.swaps.reduce((function(t,r){return t+r.route.currencyPath.length}),0):t.inputAmount.lessThan(r.inputAmount)?-1:1:t.outputAmount.lessThan(r.outputAmount)?1:-1}var b=function(){function t(t){var r=t.routes,n=t.tradeType,i=r[0].inputAmount.currency,o=r[0].outputAmount.currency;r.every((function(t){return i.equals(t.route.input)}))||e(!1),r.every((function(t){return o.equals(t.route.output)}))||e(!1);for(var u,c=r.map((function(t){return t.route.pools.length})).reduce((function(t,r){return t+r}),0),a=new Set,s=A(r);!(u=s()).done;)for(var p,h=A(u.value.route.pools);!(p=h()).done;){var l=p.value;a.add(_.getPoolId(l.currency0,l.currency1,l.fee,l.tickSpacing,l.hooks))}c!==a.size&&e(!1),this.swaps=r,this.tradeType=n}t.exactIn=function(){var r=h(a().mark((function r(e,n){return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",t.fromRoute(e,n,i.TradeType.EXACT_INPUT));case 1:case"end":return r.stop()}}),r)})));return function(t,e){return r.apply(this,arguments)}}(),t.exactOut=function(){var r=h(a().mark((function r(e,n){return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",t.fromRoute(e,n,i.TradeType.EXACT_OUTPUT));case 1:case"end":return r.stop()}}),r)})));return function(t,e){return r.apply(this,arguments)}}(),t.fromRoute=function(){var r=h(a().mark((function r(n,o,u){var c,s,p,h,l,d,m;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(c=new Array(n.currencyPath.length),u!==i.TradeType.EXACT_INPUT){r.next=19;break}o.currency.equals(n.input)||e(!1),c[0]=o,h=0;case 5:if(!(h<n.currencyPath.length-1)){r.next=15;break}return l=n.pools[h],r.next=9,l.getOutputAmount(c[h]);case 9:c[h+1]=r.sent[0];case 12:h++,r.next=5;break;case 15:s=i.CurrencyAmount.fromFractionalAmount(n.input,o.numerator,o.denominator),p=i.CurrencyAmount.fromFractionalAmount(n.output,c[c.length-1].numerator,c[c.length-1].denominator),r.next=34;break;case 19:o.currency.equals(n.output)||e(!1),c[c.length-1]=o,d=n.currencyPath.length-1;case 22:if(!(d>0)){r.next=32;break}return m=n.pools[d-1],r.next=26,m.getInputAmount(c[d]);case 26:c[d-1]=r.sent[0];case 29:d--,r.next=22;break;case 32:s=i.CurrencyAmount.fromFractionalAmount(n.input,c[0].numerator,c[0].denominator),p=i.CurrencyAmount.fromFractionalAmount(n.output,o.numerator,o.denominator);case 34:return r.abrupt("return",new t({routes:[{inputAmount:s,outputAmount:p,route:n}],tradeType:u}));case 35:case"end":return r.stop()}}),r)})));return function(t,e,n){return r.apply(this,arguments)}}(),t.fromRoutes=function(){var r=h(a().mark((function r(n,o){var u,c,s,p,h,l,d,m,f,y,k,v,g;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:u=[],c=A(n);case 2:if((s=c()).done){r.next=43;break}if(h=(p=s.value).route,l=p.amount,d=new Array(h.currencyPath.length),m=void 0,f=void 0,o!==i.TradeType.EXACT_INPUT){r.next=25;break}l.currency.equals(h.input)||e(!1),m=i.CurrencyAmount.fromFractionalAmount(h.input,l.numerator,l.denominator),d[0]=i.CurrencyAmount.fromFractionalAmount(h.input,l.numerator,l.denominator),y=0;case 12:if(!(y<h.currencyPath.length-1)){r.next=22;break}return k=h.pools[y],r.next=16,k.getOutputAmount(d[y]);case 16:d[y+1]=r.sent[0];case 19:y++,r.next=12;break;case 22:f=i.CurrencyAmount.fromFractionalAmount(h.output,d[d.length-1].numerator,d[d.length-1].denominator),r.next=40;break;case 25:l.currency.equals(h.output)||e(!1),f=i.CurrencyAmount.fromFractionalAmount(h.output,l.numerator,l.denominator),d[d.length-1]=i.CurrencyAmount.fromFractionalAmount(h.output,l.numerator,l.denominator),v=h.currencyPath.length-1;case 29:if(!(v>0)){r.next=39;break}return g=h.pools[v-1],r.next=33,g.getInputAmount(d[v]);case 33:d[v-1]=r.sent[0];case 36:v--,r.next=29;break;case 39:m=i.CurrencyAmount.fromFractionalAmount(h.input,d[0].numerator,d[0].denominator);case 40:u.push({route:h,inputAmount:m,outputAmount:f});case 41:r.next=2;break;case 43:return r.abrupt("return",new t({routes:u,tradeType:o}));case 44:case"end":return r.stop()}}),r)})));return function(t,e){return r.apply(this,arguments)}}(),t.createUncheckedTrade=function(r){return new t(m({},r,{routes:[{inputAmount:r.inputAmount,outputAmount:r.outputAmount,route:r.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(r){return new t(r)};var r=t.prototype;return r.minimumAmountOut=function(t,r){if(void 0===r&&(r=this.outputAmount),t.lessThan(I)&&e(!1),this.tradeType===i.TradeType.EXACT_OUTPUT)return r;var n=new i.Fraction(x).add(t).invert().multiply(r.quotient).quotient;return i.CurrencyAmount.fromRawAmount(r.currency,n)},r.maximumAmountIn=function(t,r){if(void 0===r&&(r=this.inputAmount),t.lessThan(I)&&e(!1),this.tradeType===i.TradeType.EXACT_INPUT)return r;var n=new i.Fraction(x).add(t).multiply(r.quotient).quotient;return i.CurrencyAmount.fromRawAmount(r.currency,n)},r.worstExecutionPrice=function(t){return new i.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var r=h(a().mark((function r(n,o,u,c,s,p,h){var l,d,m,f,y,A,k,v,g,T;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:m=void 0===(d=(l=void 0===c?{}:c).maxNumResults)?3:d,y=void 0===(f=l.maxHops)?3:f,void 0===s&&(s=[]),void 0===p&&(p=o),void 0===h&&(h=[]),n.length>0||e(!1),y>0||e(!1),o===p||s.length>0||e(!1),A=p,k=0;case 9:if(!(k<n.length)){r.next=45;break}if((v=n[k]).currency0.equals(A.currency)||v.currency1.equals(A.currency)){r.next=13;break}return r.abrupt("continue",42);case 13:return g=void 0,r.prev=14,r.next=18,v.getOutputAmount(A);case 18:g=r.sent[0],r.next=27;break;case 22:if(r.prev=22,r.t0=r.catch(14),!r.t0.isInsufficientInputAmountError){r.next=26;break}return r.abrupt("continue",42);case 26:throw r.t0;case 27:if(!g.currency.equals(u)){r.next=38;break}return r.t1=i.sortedInsert,r.t2=h,r.next=32,t.fromRoute(new P([].concat(s,[v]),o.currency,u),o,i.TradeType.EXACT_INPUT);case 32:r.t3=r.sent,r.t4=m,r.t5=q,(0,r.t1)(r.t2,r.t3,r.t4,r.t5),r.next=42;break;case 38:if(!(y>1&&n.length>1)){r.next=42;break}return T=n.slice(0,k).concat(n.slice(k+1,n.length)),r.next=42,t.bestTradeExactIn(T,o,u,{maxNumResults:m,maxHops:y-1},[].concat(s,[v]),g,h);case 42:k++,r.next=9;break;case 45:return r.abrupt("return",h);case 46:case"end":return r.stop()}}),r,null,[[14,22]])})));return function(t,e,n,i,o,u,c){return r.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var r=h(a().mark((function r(n,o,u,c,s,p,h){var l,d,m,f,y,A,k,v,g,T;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:m=void 0===(d=(l=void 0===c?{}:c).maxNumResults)?3:d,y=void 0===(f=l.maxHops)?3:f,void 0===s&&(s=[]),void 0===p&&(p=u),void 0===h&&(h=[]),n.length>0||e(!1),y>0||e(!1),u===p||s.length>0||e(!1),A=p,k=0;case 9:if(!(k<n.length)){r.next=45;break}if((v=n[k]).currency0.equals(A.currency)||v.currency1.equals(A.currency)){r.next=13;break}return r.abrupt("continue",42);case 13:return g=void 0,r.prev=14,r.next=18,v.getInputAmount(A);case 18:g=r.sent[0],r.next=27;break;case 22:if(r.prev=22,r.t0=r.catch(14),!r.t0.isInsufficientReservesError){r.next=26;break}return r.abrupt("continue",42);case 26:throw r.t0;case 27:if(!g.currency.equals(o)){r.next=38;break}return r.t1=i.sortedInsert,r.t2=h,r.next=32,t.fromRoute(new P([v].concat(s),o,u.currency),u,i.TradeType.EXACT_OUTPUT);case 32:r.t3=r.sent,r.t4=m,r.t5=q,(0,r.t1)(r.t2,r.t3,r.t4,r.t5),r.next=42;break;case 38:if(!(y>1&&n.length>1)){r.next=42;break}return T=n.slice(0,k).concat(n.slice(k+1,n.length)),r.next=42,t.bestTradeExactOut(T,o,u,{maxNumResults:m,maxHops:y-1},[v].concat(s),g,h);case 42:k++,r.next=9;break;case 45:return r.abrupt("return",h);case 46:case"end":return r.stop()}}),r,null,[[14,22]])})));return function(t,e,n,i,o,u,c){return r.apply(this,arguments)}}(),d(t,[{key:"route",get:function(){return 1!==this.swaps.length&&e(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,r=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,r){return t.add(r)}),i.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=r,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,r=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,r){return t.add(r)}),i.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=r,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new i.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,r=i.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),e=A(this.swaps);!(t=e()).done;){var n=t.value;r=r.add(n.route.midPrice.quote(n.inputAmount))}var o=r.subtract(this.outputAmount).divide(r);return this._priceImpact=new i.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}();function L(t,r,e){var n=o.TickMath.getSqrtRatioAtTick(e),u=c.multiply(n,n);return k(t,r)?new i.Price(t,r,S,u):new i.Price(t,r,u,S)}var R,O,C=function(){function t(t){var r=t.pool,n=t.liquidity,i=t.tickLower,u=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,i<u||e(!1),i>=o.TickMath.MIN_TICK&&i%r.tickSpacing==0||e(!1),u<=o.TickMath.MAX_TICK&&u%r.tickSpacing==0||e(!1),this.pool=r,this.tickLower=i,this.tickUpper=u,this.liquidity=c.BigInt(n)}var r=t.prototype;return r.ratiosAfterSlippage=function(t){var r=this.pool.token0Price.asFraction.multiply(new i.Percent(1).subtract(t)),e=this.pool.token0Price.asFraction.multiply(t.add(1)),n=o.encodeSqrtRatioX96(r.numerator,r.denominator);c.lessThanOrEqual(n,o.TickMath.MIN_SQRT_RATIO)&&(n=c.add(o.TickMath.MIN_SQRT_RATIO,c.BigInt(1)));var u=o.encodeSqrtRatioX96(e.numerator,e.denominator);return c.greaterThanOrEqual(u,o.TickMath.MAX_SQRT_RATIO)&&(u=c.subtract(o.TickMath.MAX_SQRT_RATIO,c.BigInt(1))),{sqrtRatioX96Lower:n,sqrtRatioX96Upper:u}},r.mintAmountsWithSlippage=function(r){var e=this.ratiosAfterSlippage(r),n=e.sqrtRatioX96Upper,i=e.sqrtRatioX96Lower,u=new _(this.pool.token0,this.pool.token1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,i,0,o.TickMath.getTickAtSqrtRatio(i)),c=new _(this.pool.token0,this.pool.token1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,n,0,o.TickMath.getTickAtSqrtRatio(n)),a=t.fromAmounts(m({pool:this.pool,tickLower:this.tickLower,tickUpper:this.tickUpper},this.mintAmounts,{useFullPrecision:!1})),s=new t({pool:c,liquidity:a.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount1;return{amount0:new t({pool:u,liquidity:a.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:s}},r.burnAmountsWithSlippage=function(r){var e=this.ratiosAfterSlippage(r),n=e.sqrtRatioX96Upper,i=e.sqrtRatioX96Lower,u=new _(this.pool.token0,this.pool.token1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,i,0,o.TickMath.getTickAtSqrtRatio(i)),c=new t({pool:new _(this.pool.token0,this.pool.token1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,n,0,o.TickMath.getTickAtSqrtRatio(n)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,a=new t({pool:u,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:c.quotient,amount1:a.quotient}},t.fromAmounts=function(r){var e=r.pool,n=r.tickLower,i=r.tickUpper,u=r.amount0,c=r.amount1,a=r.useFullPrecision,s=o.TickMath.getSqrtRatioAtTick(n),p=o.TickMath.getSqrtRatioAtTick(i);return new t({pool:e,tickLower:n,tickUpper:i,liquidity:o.maxLiquidityForAmounts(e.sqrtRatioX96,s,p,u,c,a)})},t.fromAmount0=function(r){return t.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:r.amount0,amount1:i.MaxUint256,useFullPrecision:r.useFullPrecision})},t.fromAmount1=function(r){return t.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:i.MaxUint256,amount1:r.amount1,useFullPrecision:!0})},d(t,[{key:"token0PriceLower",get:function(){return L(this.pool.currency0,this.pool.currency1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return L(this.pool.currency0,this.pool.currency1,this.tickUpper)}},{key:"amount0",get:function(){return this._token0Amount||(this._token0Amount=i.CurrencyAmount.fromRawAmount(this.pool.currency0,this.pool.tickCurrent<this.tickLower?o.SqrtPriceMath.getAmount0Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):this.pool.tickCurrent<this.tickUpper?o.SqrtPriceMath.getAmount0Delta(this.pool.sqrtRatioX96,o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):I)),this._token0Amount}},{key:"amount1",get:function(){return this._token1Amount||(this._token1Amount=i.CurrencyAmount.fromRawAmount(this.pool.currency1,this.pool.tickCurrent<this.tickLower?I:o.SqrtPriceMath.getAmount1Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),this.pool.tickCurrent<this.tickUpper?this.pool.sqrtRatioX96:o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1))),this._token1Amount}},{key:"mintAmounts",get:function(){return null===this._mintAmounts?this.pool.tickCurrent<this.tickLower?{amount0:o.SqrtPriceMath.getAmount0Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:I}:this.pool.tickCurrent<this.tickUpper?{amount0:o.SqrtPriceMath.getAmount0Delta(this.pool.sqrtRatioX96,o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:o.SqrtPriceMath.getAmount1Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),this.pool.sqrtRatioX96,this.liquidity,!0)}:{amount0:I,amount1:o.SqrtPriceMath.getAmount1Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0)}:this._mintAmounts}}]),t}(),U=function(t,r){for(var e,n=r?t.output:t.input,i=[],o=A(r?t.pools.reverse():t.pools);!(e=o()).done;){var u=e.value,c=n.equals(u.currency0)?u.currency1:u.currency0;i.push({intermediateCurrency:c.isNative?T:c.address,fee:u.fee,tickSpacing:u.tickSpacing,hooks:u.hooks,hookData:"0x"}),n=c}return r?i.reverse():i};(O=exports.Actions||(exports.Actions={}))[O.INCREASE_LIQUIDITY=0]="INCREASE_LIQUIDITY",O[O.DECREASE_LIQUIDITY=1]="DECREASE_LIQUIDITY",O[O.MINT_POSITION=2]="MINT_POSITION",O[O.BURN_POSITION=3]="BURN_POSITION",O[O.SWAP_EXACT_IN_SINGLE=4]="SWAP_EXACT_IN_SINGLE",O[O.SWAP_EXACT_IN=5]="SWAP_EXACT_IN",O[O.SWAP_EXACT_OUT_SINGLE=6]="SWAP_EXACT_OUT_SINGLE",O[O.SWAP_EXACT_OUT=7]="SWAP_EXACT_OUT",O[O.SETTLE=9]="SETTLE",O[O.SETTLE_ALL=16]="SETTLE_ALL",O[O.SETTLE_PAIR=17]="SETTLE_PAIR",O[O.TAKE=18]="TAKE",O[O.TAKE_ALL=19]="TAKE_ALL",O[O.TAKE_PORTION=20]="TAKE_PORTION",O[O.TAKE_PAIR=21]="TAKE_PAIR",O[O.SETTLE_TAKE_PAIR=22]="SETTLE_TAKE_PAIR",O[O.CLOSE_CURRENCY=23]="CLOSE_CURRENCY",O[O.SWEEP=25]="SWEEP";var N=((R={})[exports.Actions.INCREASE_LIQUIDITY]=["uint256 tokenId","uint256 liquidity","uint128 amount0Max","uint128 amount1Max","bytes hookData"],R[exports.Actions.DECREASE_LIQUIDITY]=["uint256 tokenId","uint256 liquidity","uint128 amount0Min","uint128 amount1Min","bytes hookData"],R[exports.Actions.MINT_POSITION]=["(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)","int24 tickLower","int24 tickUpper","uint256 liquidity","uint128 amount0Max","uint128 amount1Max","address owner","bytes hookData"],R[exports.Actions.BURN_POSITION]=["uint256 tokenId","uint128 amount0Min","uint128 amount1Min","bytes hookData"],R[exports.Actions.SWAP_EXACT_IN_SINGLE]=["((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 amountIn,uint128 amountOutMinimum,uint160 sqrtPriceLimitX96,bytes hookData)"],R[exports.Actions.SWAP_EXACT_IN]=["(address currencyIn,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountIn,uint128 amountOutMinimum)"],R[exports.Actions.SWAP_EXACT_OUT_SINGLE]=["((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 amountOut,uint128 amountInMaximum,uint160 sqrtPriceLimitX96,bytes hookData)"],R[exports.Actions.SWAP_EXACT_OUT]=["(address currencyOut,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountOut,uint128 amountInMaximum)"],R[exports.Actions.SETTLE]=["address","uint256","bool"],R[exports.Actions.SETTLE_ALL]=["address","uint256"],R[exports.Actions.SETTLE_PAIR]=["address","address"],R[exports.Actions.TAKE]=["address","address","uint256"],R[exports.Actions.TAKE_ALL]=["address","uint256"],R[exports.Actions.TAKE_PORTION]=["address","address","uint256"],R[exports.Actions.TAKE_PAIR]=["address","address","address"],R[exports.Actions.SETTLE_TAKE_PAIR]=["address","address"],R[exports.Actions.CLOSE_CURRENCY]=["address"],R[exports.Actions.SWEEP]=["address","address"],R),M=function(){function t(){this.actions="0x",this.params=[]}var r=t.prototype;return r.addAction=function(t,r){var e=function(t,r){return{action:t,encodedInput:u.defaultAbiCoder.encode(N[t],r)}}(t,r);this.params.push(e.encodedInput),this.actions=this.actions.concat(e.action.toString(16).padStart(2,"0"))},r.addTrade=function(t,r){var n=t.tradeType===i.TradeType.EXACT_OUTPUT;n&&(r||e(!1)),1!==t.swaps.length&&e(!1);var o=n?exports.Actions.SWAP_EXACT_OUT:exports.Actions.SWAP_EXACT_IN,u=X(t.inputAmount.currency),c=X(t.outputAmount.currency);this.addAction(o,[n?{currencyOut:c,path:U(t.route,n),amountInMaximum:t.maximumAmountIn(null!=r?r:new i.Percent(0)).quotient.toString(),amountOut:t.inputAmount.quotient.toString()}:{currencyIn:u,path:U(t.route,n),amountIn:t.inputAmount.quotient.toString(),amountOutMinimum:r?t.minimumAmountOut(r).quotient.toString():0}])},r.addSettle=function(t,r,e){this.addAction(exports.Actions.SETTLE,[X(t),null!=e?e:0,r])},r.addTake=function(t,r,e){var n=r?"0x0000000000000000000000000000000000000002":"0x0000000000000000000000000000000000000001",i=null!=e?e:0;this.addAction(exports.Actions.TAKE,[X(t),n,i])},r.finalize=function(){return u.defaultAbiCoder.encode(["bytes","bytes[]"],[this.actions,this.params])},t}();function X(t){return t.isNative?T:t.wrapped.address}function D(t){return t.isNative?T:t.wrapped.address}var j=function(t){var r,e;function n(){return t.apply(this,arguments)||this}e=t,(r=n).prototype=Object.create(e.prototype),r.prototype.constructor=r,f(r,e);var i=n.prototype;return i.addMint=function(t,r,e,n,i,o,u,c){void 0===c&&(c="0x");var a=[_.getPoolKey(t.currency0,t.currency1,t.fee,t.tickSpacing,t.hooks),r,e,n.toString(),i.toString(),o.toString(),u,c];this.addAction(exports.Actions.MINT_POSITION,a)},i.addIncrease=function(t,r,e,n,i){void 0===i&&(i="0x");var o=[t.toString(),r.toString(),e.toString(),n.toString(),i];this.addAction(exports.Actions.INCREASE_LIQUIDITY,o)},i.addDecrease=function(t,r,e,n,i){void 0===i&&(i="0x");var o=[t.toString(),r.toString(),e.toString(),n.toString(),i];this.addAction(exports.Actions.DECREASE_LIQUIDITY,o)},i.addBurn=function(t,r,e,n){void 0===n&&(n="0x");var i=[t.toString(),r.toString(),e.toString(),n];this.addAction(exports.Actions.BURN_POSITION,i)},i.addSettlePair=function(t,r){var e=[D(t),D(r)];this.addAction(exports.Actions.SETTLE_PAIR,e)},i.addTakePair=function(t,r,e){var n=[D(t),D(r),e];this.addAction(exports.Actions.TAKE_PAIR,n)},i.addSweep=function(t,r){var e=[D(t),r];this.addAction(exports.Actions.SWEEP,e)},n}(M);exports.DYNAMIC_FEE_FLAG=8388608,exports.Pool=_,exports.Position=C,exports.Route=P,exports.Trade=b,exports.V4Planner=M,exports.V4PositionPlanner=j,exports.encodeRouteToPath=U,exports.toHex=function(t){var r=c.BigInt(t).toString(16);return r.length%2!=0&&(r="0"+r),"0x"+r},exports.tradeComparator=q;
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var r,e=t(require("tiny-invariant")),n=require("@ethersproject/solidity"),i=require("@uniswap/sdk-core"),o=require("@uniswap/v3-sdk"),u=require("ethers/lib/utils"),c=t(require("jsbi"));function a(){a=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,i=Object.defineProperty||function(t,r,e){t[r]=e.value},o="function"==typeof Symbol?Symbol:{},u=o.iterator||"@@iterator",c=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function p(t,r,e){return Object.defineProperty(t,r,{value:e,enumerable:!0,configurable:!0,writable:!0}),t[r]}try{p({},"")}catch(t){p=function(t,r,e){return t[r]=e}}function h(t,r,e,n){var o=Object.create((r&&r.prototype instanceof A?r:A).prototype),u=new b(n||[]);return i(o,"_invoke",{value:E(t,e,u)}),o}function l(t,r,e){try{return{type:"normal",arg:t.call(r,e)}}catch(t){return{type:"throw",arg:t}}}r.wrap=h;var d="suspendedStart",m="executing",f="completed",y={};function A(){}function k(){}function v(){}var g={};p(g,u,(function(){return this}));var T=Object.getPrototypeOf,w=T&&T(T(L([])));w&&w!==e&&n.call(w,u)&&(g=w);var I=v.prototype=A.prototype=Object.create(g);function x(t){["next","throw","return"].forEach((function(r){p(t,r,(function(t){return this._invoke(r,t)}))}))}function S(t,r){function e(i,o,u,c){var a=l(t[i],t,o);if("throw"!==a.type){var s=a.arg,p=s.value;return p&&"object"==typeof p&&n.call(p,"__await")?r.resolve(p.__await).then((function(t){e("next",t,u,c)}),(function(t){e("throw",t,u,c)})):r.resolve(p).then((function(t){s.value=t,u(s)}),(function(t){return e("throw",t,u,c)}))}c(a.arg)}var o;i(this,"_invoke",{value:function(t,n){function i(){return new r((function(r,i){e(t,n,r,i)}))}return o=o?o.then(i,i):i()}})}function E(r,e,n){var i=d;return function(o,u){if(i===m)throw new Error("Generator is already running");if(i===f){if("throw"===o)throw u;return{value:t,done:!0}}for(n.method=o,n.arg=u;;){var c=n.delegate;if(c){var a=_(c,n);if(a){if(a===y)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(i===d)throw i=f,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);i=m;var s=l(r,e,n);if("normal"===s.type){if(i=n.done?f:"suspendedYield",s.arg===y)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(i=f,n.method="throw",n.arg=s.arg)}}}function _(r,e){var n=e.method,i=r.iterator[n];if(i===t)return e.delegate=null,"throw"===n&&r.iterator.return&&(e.method="return",e.arg=t,_(r,e),"throw"===e.method)||"return"!==n&&(e.method="throw",e.arg=new TypeError("The iterator does not provide a '"+n+"' method")),y;var o=l(i,r.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,y;var u=o.arg;return u?u.done?(e[r.resultName]=u.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,y):u:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,y)}function P(t){var r={tryLoc:t[0]};1 in t&&(r.catchLoc=t[1]),2 in t&&(r.finallyLoc=t[2],r.afterLoc=t[3]),this.tryEntries.push(r)}function q(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function b(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function L(r){if(r||""===r){var e=r[u];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var i=-1,o=function e(){for(;++i<r.length;)if(n.call(r,i))return e.value=r[i],e.done=!1,e;return e.value=t,e.done=!0,e};return o.next=o}}throw new TypeError(typeof r+" is not iterable")}return k.prototype=v,i(I,"constructor",{value:v,configurable:!0}),i(v,"constructor",{value:k,configurable:!0}),k.displayName=p(v,s,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===k||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,v):(t.__proto__=v,p(t,s,"GeneratorFunction")),t.prototype=Object.create(I),t},r.awrap=function(t){return{__await:t}},x(S.prototype),p(S.prototype,c,(function(){return this})),r.AsyncIterator=S,r.async=function(t,e,n,i,o){void 0===o&&(o=Promise);var u=new S(h(t,e,n,i),o);return r.isGeneratorFunction(e)?u:u.next().then((function(t){return t.done?t.value:u.next()}))},x(I),p(I,s,"Generator"),p(I,u,(function(){return this})),p(I,"toString",(function(){return"[object Generator]"})),r.keys=function(t){var r=Object(t),e=[];for(var n in r)e.push(n);return e.reverse(),function t(){for(;e.length;){var n=e.pop();if(n in r)return t.value=n,t.done=!1,t}return t.done=!0,t}},r.values=L,b.prototype={constructor:b,reset:function(r){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(q),!r)for(var e in this)"t"===e.charAt(0)&&n.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=t)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var e=this;function i(n,i){return c.type="throw",c.arg=r,e.next=n,i&&(e.method="next",e.arg=t),!!i}for(var o=this.tryEntries.length-1;o>=0;--o){var u=this.tryEntries[o],c=u.completion;if("root"===u.tryLoc)return i("end");if(u.tryLoc<=this.prev){var a=n.call(u,"catchLoc"),s=n.call(u,"finallyLoc");if(a&&s){if(this.prev<u.catchLoc)return i(u.catchLoc,!0);if(this.prev<u.finallyLoc)return i(u.finallyLoc)}else if(a){if(this.prev<u.catchLoc)return i(u.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<u.finallyLoc)return i(u.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var i=this.tryEntries[e];if(i.tryLoc<=this.prev&&n.call(i,"finallyLoc")&&this.prev<i.finallyLoc){var o=i;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var u=o?o.completion:{};return u.type=t,u.arg=r,o?(this.method="next",this.next=o.finallyLoc,y):this.complete(u)},complete:function(t,r){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&&r&&(this.next=r),y},finish:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.finallyLoc===t)return this.complete(e.completion,e.afterLoc),q(e),y}},catch:function(t){for(var r=this.tryEntries.length-1;r>=0;--r){var e=this.tryEntries[r];if(e.tryLoc===t){var n=e.completion;if("throw"===n.type){var i=n.arg;q(e)}return i}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:L(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),y}},r}function s(t){var r=function(t,r){if("object"!=typeof t||!t)return t;var e=t[Symbol.toPrimitive];if(void 0!==e){var n=e.call(t,"string");if("object"!=typeof n)return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return String(t)}(t);return"symbol"==typeof r?r:String(r)}function p(t,r,e,n,i,o,u){try{var c=t[o](u),a=c.value}catch(t){return void e(t)}c.done?r(a):Promise.resolve(a).then(n,i)}function h(t){return function(){var r=this,e=arguments;return new Promise((function(n,i){var o=t.apply(r,e);function u(t){p(o,n,i,u,c,"next",t)}function c(t){p(o,n,i,u,c,"throw",t)}u(void 0)}))}}function l(t,r){for(var e=0;e<r.length;e++){var n=r[e];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,s(n.key),n)}}function d(t,r,e){return r&&l(t.prototype,r),e&&l(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function m(){return(m=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t}).apply(this,arguments)}function f(t,r){return(f=Object.setPrototypeOf?Object.setPrototypeOf.bind():function(t,r){return t.__proto__=r,t})(t,r)}function y(t,r){(null==r||r>t.length)&&(r=t.length);for(var e=0,n=new Array(r);e<r;e++)n[e]=t[e];return n}function A(t,r){var e="undefined"!=typeof Symbol&&t[Symbol.iterator]||t["@@iterator"];if(e)return(e=e.call(t)).next.bind(e);if(Array.isArray(t)||(e=function(t,r){if(t){if("string"==typeof t)return y(t,void 0);var e=Object.prototype.toString.call(t).slice(8,-1);return"Object"===e&&t.constructor&&(e=t.constructor.name),"Map"===e||"Set"===e?Array.from(t):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?y(t,void 0):void 0}}(t))||r&&t&&"number"==typeof t.length){e&&(t=e);var n=0;return function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}}}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 k(t,r){return!!t.isNative||!r.isNative&&t.wrapped.sortsBefore(r.wrapped)}var v,g,T=require("ethers").constants.AddressZero,w=c.BigInt(-1),I=c.BigInt(0),x=c.BigInt(1),S=c.exponentiate(c.exponentiate(c.BigInt(2),c.BigInt(96)),c.BigInt(2));!function(t){t.INITIALIZE_POOL="initializePool",t.MODIFY_LIQUIDITIES="modifyLiquidities"}(v||(v={})),function(t){t[t.LOWEST=100]="LOWEST",t[t.LOW=500]="LOW",t[t.MEDIUM=3e3]="MEDIUM",t[t.HIGH=1e4]="HIGH"}(g||(g={})),(r={})[g.LOWEST]=1,r[g.LOW]=10,r[g.MEDIUM]=60,r[g.HIGH]=200;var E=new o.NoTickDataProvider,_=function(){function t(r,n,i,a,s,p,h,l,d){void 0===d&&(d=E),u.isAddress(s)||e(!1),Number.isInteger(i)&&(8388608===i||i<1e6)||e(!1),8388608===i&&(Number(s)>0||e(!1));var m=o.TickMath.getSqrtRatioAtTick(l),f=o.TickMath.getSqrtRatioAtTick(l+1);c.greaterThanOrEqual(c.BigInt(p),m)&&c.lessThanOrEqual(c.BigInt(p),f)||e(!1);var y=k(r,n)?[r,n]:[n,r];this.currency0=y[0],this.currency1=y[1],this.fee=i,this.sqrtRatioX96=c.BigInt(p),this.tickSpacing=a,this.hooks=s,this.liquidity=c.BigInt(h),this.tickCurrent=l,this.tickDataProvider=Array.isArray(d)?new o.TickListDataProvider(d,a):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,r,n,i,o){u.isAddress(o)||e(!1);var c=k(t,r)?[t,r]:[r,t],a=c[0],s=c[1];return{currency0:a.isNative?T:a.wrapped.address,currency1:s.isNative?T:s.wrapped.address,fee:n,tickSpacing:i,hooks:o}},t.getPoolId=function(t,r,e,i,o){var c=k(t,r)?[t,r]:[r,t],a=c[0],s=c[1];return n.keccak256(["bytes"],[u.defaultAbiCoder.encode(["address","address","uint24","int24","address"],[a.isNative?T:a.wrapped.address,s.isNative?T:s.wrapped.address,e,i,o])])};var r=t.prototype;return r.involvesCurrency=function(t){return t.equals(this.currency0)||t.equals(this.currency1)},r.involvesToken=function(t){return this.involvesCurrency(t)},r.priceOf=function(t){return this.involvesCurrency(t)||e(!1),t.equals(this.currency0)?this.currency0Price:this.currency1Price},r.getOutputAmount=function(){var r=h(a().mark((function r(n,o){var u,s,p,h,l;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return this.involvesCurrency(n.currency)||e(!1),u=n.currency.equals(this.currency0),r.next=4,this.swap(u,n.quotient,o);case 4:return p=(s=r.sent).sqrtRatioX96,h=s.liquidity,l=s.tickCurrent,r.abrupt("return",[i.CurrencyAmount.fromRawAmount(u?this.currency1:this.currency0,c.multiply(s.amountCalculated,w)),new t(this.currency0,this.currency1,this.fee,this.tickSpacing,this.hooks,p,h,l,this.tickDataProvider)]);case 11:case"end":return r.stop()}}),r,this)})));return function(t,e){return r.apply(this,arguments)}}(),r.getInputAmount=function(){var r=h(a().mark((function r(n,o){var u,s,p,h,l;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return this.involvesCurrency(n.currency)||e(!1),u=n.currency.equals(this.currency1),r.next=4,this.swap(u,c.multiply(n.quotient,w),o);case 4:return p=(s=r.sent).sqrtRatioX96,h=s.liquidity,l=s.tickCurrent,r.abrupt("return",[i.CurrencyAmount.fromRawAmount(u?this.currency0:this.currency1,s.amountCalculated),new t(this.currency0,this.currency1,this.fee,this.tickSpacing,this.hooks,p,h,l,this.tickDataProvider)]);case 11:case"end":return r.stop()}}),r,this)})));return function(t,e){return r.apply(this,arguments)}}(),r.swap=function(){var t=h(a().mark((function t(r,e,n){return a().wrap((function(t){for(;;)switch(t.prev=t.next){case 0:if(!this.nonImpactfulHook()){t.next=4;break}return t.abrupt("return",o.v3Swap(c.BigInt(this.fee),this.sqrtRatioX96,this.tickCurrent,this.liquidity,this.tickSpacing,this.tickDataProvider,r,e,n));case 4:throw new Error("Unsupported hook");case 5:case"end":return t.stop()}}),t,this)})));return function(r,e,n){return t.apply(this,arguments)}}(),r.nonImpactfulHook=function(){return this.hooks===T},d(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 i.Price(this.currency0,this.currency1,S,c.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 i.Price(this.currency1,this.currency0,c.multiply(this.sqrtRatioX96,this.sqrtRatioX96),S)}},{key:"token1Price",get:function(){return this.currency1Price}},{key:"chainId",get:function(){return this.currency0.chainId}}]),t}(),P=function(){function t(t,r,n){this._midPrice=null,t.length>0||e(!1);var i=t[0].chainId;t.every((function(t){return t.chainId===i}))||e(!1),t[0].involvesCurrency(r)||e(!1),t[t.length-1].involvesCurrency(n)||e(!1);for(var o,u=[r],c=A(t.entries());!(o=c()).done;){var a=o.value,s=a[1],p=u[a[0]];p.equals(s.currency0)||p.equals(s.currency1)||e(!1);var h=p.equals(s.currency0)?s.currency1:s.currency0;u.push(h)}this.pools=t,this.currencyPath=u,this.input=r,this.output=null!=n?n:u[u.length-1]}return d(t,[{key:"chainId",get:function(){return this.pools[0].chainId}},{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;var t=this.pools.slice(1).reduce((function(t,r){var e=t.price;return t.nextInput.equals(r.currency0)?{nextInput:r.currency1,price:e.multiply(r.currency0Price)}:{nextInput:r.currency0,price:e.multiply(r.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 i.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function q(t,r){return t.inputAmount.currency.equals(r.inputAmount.currency)||e(!1),t.outputAmount.currency.equals(r.outputAmount.currency)||e(!1),t.outputAmount.equalTo(r.outputAmount)?t.inputAmount.equalTo(r.inputAmount)?t.swaps.reduce((function(t,r){return t+r.route.currencyPath.length}),0)-r.swaps.reduce((function(t,r){return t+r.route.currencyPath.length}),0):t.inputAmount.lessThan(r.inputAmount)?-1:1:t.outputAmount.lessThan(r.outputAmount)?1:-1}var b=function(){function t(t){var r=t.routes,n=t.tradeType,i=r[0].inputAmount.currency,o=r[0].outputAmount.currency;r.every((function(t){return i.equals(t.route.input)}))||e(!1),r.every((function(t){return o.equals(t.route.output)}))||e(!1);for(var u,c=r.map((function(t){return t.route.pools.length})).reduce((function(t,r){return t+r}),0),a=new Set,s=A(r);!(u=s()).done;)for(var p,h=A(u.value.route.pools);!(p=h()).done;){var l=p.value;a.add(_.getPoolId(l.currency0,l.currency1,l.fee,l.tickSpacing,l.hooks))}c!==a.size&&e(!1),this.swaps=r,this.tradeType=n}t.exactIn=function(){var r=h(a().mark((function r(e,n){return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",t.fromRoute(e,n,i.TradeType.EXACT_INPUT));case 1:case"end":return r.stop()}}),r)})));return function(t,e){return r.apply(this,arguments)}}(),t.exactOut=function(){var r=h(a().mark((function r(e,n){return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return r.abrupt("return",t.fromRoute(e,n,i.TradeType.EXACT_OUTPUT));case 1:case"end":return r.stop()}}),r)})));return function(t,e){return r.apply(this,arguments)}}(),t.fromRoute=function(){var r=h(a().mark((function r(n,o,u){var c,s,p,h,l,d,m;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(c=new Array(n.currencyPath.length),u!==i.TradeType.EXACT_INPUT){r.next=19;break}o.currency.equals(n.input)||e(!1),c[0]=o,h=0;case 5:if(!(h<n.currencyPath.length-1)){r.next=15;break}return l=n.pools[h],r.next=9,l.getOutputAmount(c[h]);case 9:c[h+1]=r.sent[0];case 12:h++,r.next=5;break;case 15:s=i.CurrencyAmount.fromFractionalAmount(n.input,o.numerator,o.denominator),p=i.CurrencyAmount.fromFractionalAmount(n.output,c[c.length-1].numerator,c[c.length-1].denominator),r.next=34;break;case 19:o.currency.equals(n.output)||e(!1),c[c.length-1]=o,d=n.currencyPath.length-1;case 22:if(!(d>0)){r.next=32;break}return m=n.pools[d-1],r.next=26,m.getInputAmount(c[d]);case 26:c[d-1]=r.sent[0];case 29:d--,r.next=22;break;case 32:s=i.CurrencyAmount.fromFractionalAmount(n.input,c[0].numerator,c[0].denominator),p=i.CurrencyAmount.fromFractionalAmount(n.output,o.numerator,o.denominator);case 34:return r.abrupt("return",new t({routes:[{inputAmount:s,outputAmount:p,route:n}],tradeType:u}));case 35:case"end":return r.stop()}}),r)})));return function(t,e,n){return r.apply(this,arguments)}}(),t.fromRoutes=function(){var r=h(a().mark((function r(n,o){var u,c,s,p,h,l,d,m,f,y,k,v,g;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:u=[],c=A(n);case 2:if((s=c()).done){r.next=43;break}if(h=(p=s.value).route,l=p.amount,d=new Array(h.currencyPath.length),m=void 0,f=void 0,o!==i.TradeType.EXACT_INPUT){r.next=25;break}l.currency.equals(h.input)||e(!1),m=i.CurrencyAmount.fromFractionalAmount(h.input,l.numerator,l.denominator),d[0]=i.CurrencyAmount.fromFractionalAmount(h.input,l.numerator,l.denominator),y=0;case 12:if(!(y<h.currencyPath.length-1)){r.next=22;break}return k=h.pools[y],r.next=16,k.getOutputAmount(d[y]);case 16:d[y+1]=r.sent[0];case 19:y++,r.next=12;break;case 22:f=i.CurrencyAmount.fromFractionalAmount(h.output,d[d.length-1].numerator,d[d.length-1].denominator),r.next=40;break;case 25:l.currency.equals(h.output)||e(!1),f=i.CurrencyAmount.fromFractionalAmount(h.output,l.numerator,l.denominator),d[d.length-1]=i.CurrencyAmount.fromFractionalAmount(h.output,l.numerator,l.denominator),v=h.currencyPath.length-1;case 29:if(!(v>0)){r.next=39;break}return g=h.pools[v-1],r.next=33,g.getInputAmount(d[v]);case 33:d[v-1]=r.sent[0];case 36:v--,r.next=29;break;case 39:m=i.CurrencyAmount.fromFractionalAmount(h.input,d[0].numerator,d[0].denominator);case 40:u.push({route:h,inputAmount:m,outputAmount:f});case 41:r.next=2;break;case 43:return r.abrupt("return",new t({routes:u,tradeType:o}));case 44:case"end":return r.stop()}}),r)})));return function(t,e){return r.apply(this,arguments)}}(),t.createUncheckedTrade=function(r){return new t(m({},r,{routes:[{inputAmount:r.inputAmount,outputAmount:r.outputAmount,route:r.route}]}))},t.createUncheckedTradeWithMultipleRoutes=function(r){return new t(r)};var r=t.prototype;return r.minimumAmountOut=function(t,r){if(void 0===r&&(r=this.outputAmount),t.lessThan(I)&&e(!1),this.tradeType===i.TradeType.EXACT_OUTPUT)return r;var n=new i.Fraction(x).add(t).invert().multiply(r.quotient).quotient;return i.CurrencyAmount.fromRawAmount(r.currency,n)},r.maximumAmountIn=function(t,r){if(void 0===r&&(r=this.inputAmount),t.lessThan(I)&&e(!1),this.tradeType===i.TradeType.EXACT_INPUT)return r;var n=new i.Fraction(x).add(t).multiply(r.quotient).quotient;return i.CurrencyAmount.fromRawAmount(r.currency,n)},r.worstExecutionPrice=function(t){return new i.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).quotient,this.minimumAmountOut(t).quotient)},t.bestTradeExactIn=function(){var r=h(a().mark((function r(n,o,u,c,s,p,h){var l,d,m,f,y,A,k,v,g,T;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:m=void 0===(d=(l=void 0===c?{}:c).maxNumResults)?3:d,y=void 0===(f=l.maxHops)?3:f,void 0===s&&(s=[]),void 0===p&&(p=o),void 0===h&&(h=[]),n.length>0||e(!1),y>0||e(!1),o===p||s.length>0||e(!1),A=p,k=0;case 9:if(!(k<n.length)){r.next=45;break}if((v=n[k]).currency0.equals(A.currency)||v.currency1.equals(A.currency)){r.next=13;break}return r.abrupt("continue",42);case 13:return g=void 0,r.prev=14,r.next=18,v.getOutputAmount(A);case 18:g=r.sent[0],r.next=27;break;case 22:if(r.prev=22,r.t0=r.catch(14),!r.t0.isInsufficientInputAmountError){r.next=26;break}return r.abrupt("continue",42);case 26:throw r.t0;case 27:if(!g.currency.equals(u)){r.next=38;break}return r.t1=i.sortedInsert,r.t2=h,r.next=32,t.fromRoute(new P([].concat(s,[v]),o.currency,u),o,i.TradeType.EXACT_INPUT);case 32:r.t3=r.sent,r.t4=m,r.t5=q,(0,r.t1)(r.t2,r.t3,r.t4,r.t5),r.next=42;break;case 38:if(!(y>1&&n.length>1)){r.next=42;break}return T=n.slice(0,k).concat(n.slice(k+1,n.length)),r.next=42,t.bestTradeExactIn(T,o,u,{maxNumResults:m,maxHops:y-1},[].concat(s,[v]),g,h);case 42:k++,r.next=9;break;case 45:return r.abrupt("return",h);case 46:case"end":return r.stop()}}),r,null,[[14,22]])})));return function(t,e,n,i,o,u,c){return r.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var r=h(a().mark((function r(n,o,u,c,s,p,h){var l,d,m,f,y,A,k,v,g,T;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:m=void 0===(d=(l=void 0===c?{}:c).maxNumResults)?3:d,y=void 0===(f=l.maxHops)?3:f,void 0===s&&(s=[]),void 0===p&&(p=u),void 0===h&&(h=[]),n.length>0||e(!1),y>0||e(!1),u===p||s.length>0||e(!1),A=p,k=0;case 9:if(!(k<n.length)){r.next=45;break}if((v=n[k]).currency0.equals(A.currency)||v.currency1.equals(A.currency)){r.next=13;break}return r.abrupt("continue",42);case 13:return g=void 0,r.prev=14,r.next=18,v.getInputAmount(A);case 18:g=r.sent[0],r.next=27;break;case 22:if(r.prev=22,r.t0=r.catch(14),!r.t0.isInsufficientReservesError){r.next=26;break}return r.abrupt("continue",42);case 26:throw r.t0;case 27:if(!g.currency.equals(o)){r.next=38;break}return r.t1=i.sortedInsert,r.t2=h,r.next=32,t.fromRoute(new P([v].concat(s),o,u.currency),u,i.TradeType.EXACT_OUTPUT);case 32:r.t3=r.sent,r.t4=m,r.t5=q,(0,r.t1)(r.t2,r.t3,r.t4,r.t5),r.next=42;break;case 38:if(!(y>1&&n.length>1)){r.next=42;break}return T=n.slice(0,k).concat(n.slice(k+1,n.length)),r.next=42,t.bestTradeExactOut(T,o,u,{maxNumResults:m,maxHops:y-1},[v].concat(s),g,h);case 42:k++,r.next=9;break;case 45:return r.abrupt("return",h);case 46:case"end":return r.stop()}}),r,null,[[14,22]])})));return function(t,e,n,i,o,u,c){return r.apply(this,arguments)}}(),d(t,[{key:"route",get:function(){return 1!==this.swaps.length&&e(!1),this.swaps[0].route}},{key:"inputAmount",get:function(){if(this._inputAmount)return this._inputAmount;var t=this.swaps[0].inputAmount.currency,r=this.swaps.map((function(t){return t.inputAmount})).reduce((function(t,r){return t.add(r)}),i.CurrencyAmount.fromRawAmount(t,0));return this._inputAmount=r,this._inputAmount}},{key:"outputAmount",get:function(){if(this._outputAmount)return this._outputAmount;var t=this.swaps[0].outputAmount.currency,r=this.swaps.map((function(t){return t.outputAmount})).reduce((function(t,r){return t.add(r)}),i.CurrencyAmount.fromRawAmount(t,0));return this._outputAmount=r,this._outputAmount}},{key:"executionPrice",get:function(){var t;return null!=(t=this._executionPrice)?t:this._executionPrice=new i.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,r=i.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),e=A(this.swaps);!(t=e()).done;){var n=t.value;r=r.add(n.route.midPrice.quote(n.inputAmount))}var o=r.subtract(this.outputAmount).divide(r);return this._priceImpact=new i.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}();function L(t,r,e){var n=o.TickMath.getSqrtRatioAtTick(e),u=c.multiply(n,n);return k(t,r)?new i.Price(t,r,S,u):new i.Price(t,r,u,S)}var R,O,C=function(){function t(t){var r=t.pool,n=t.liquidity,i=t.tickLower,u=t.tickUpper;this._token0Amount=null,this._token1Amount=null,this._mintAmounts=null,i<u||e(!1),i>=o.TickMath.MIN_TICK&&i%r.tickSpacing==0||e(!1),u<=o.TickMath.MAX_TICK&&u%r.tickSpacing==0||e(!1),this.pool=r,this.tickLower=i,this.tickUpper=u,this.liquidity=c.BigInt(n)}var r=t.prototype;return r.ratiosAfterSlippage=function(t){var r=this.pool.token0Price.asFraction.multiply(new i.Percent(1).subtract(t)),e=this.pool.token0Price.asFraction.multiply(t.add(1)),n=o.encodeSqrtRatioX96(r.numerator,r.denominator);c.lessThanOrEqual(n,o.TickMath.MIN_SQRT_RATIO)&&(n=c.add(o.TickMath.MIN_SQRT_RATIO,c.BigInt(1)));var u=o.encodeSqrtRatioX96(e.numerator,e.denominator);return c.greaterThanOrEqual(u,o.TickMath.MAX_SQRT_RATIO)&&(u=c.subtract(o.TickMath.MAX_SQRT_RATIO,c.BigInt(1))),{sqrtRatioX96Lower:n,sqrtRatioX96Upper:u}},r.mintAmountsWithSlippage=function(r){var e=this.ratiosAfterSlippage(r),n=e.sqrtRatioX96Upper,i=e.sqrtRatioX96Lower,u=new _(this.pool.token0,this.pool.token1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,i,0,o.TickMath.getTickAtSqrtRatio(i)),c=new _(this.pool.token0,this.pool.token1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,n,0,o.TickMath.getTickAtSqrtRatio(n)),a=t.fromAmounts(m({pool:this.pool,tickLower:this.tickLower,tickUpper:this.tickUpper},this.mintAmounts,{useFullPrecision:!1})),s=new t({pool:c,liquidity:a.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount1;return{amount0:new t({pool:u,liquidity:a.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).mintAmounts.amount0,amount1:s}},r.burnAmountsWithSlippage=function(r){var e=this.ratiosAfterSlippage(r),n=e.sqrtRatioX96Upper,i=e.sqrtRatioX96Lower,u=new _(this.pool.currency0,this.pool.currency1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,i,0,o.TickMath.getTickAtSqrtRatio(i)),c=new t({pool:new _(this.pool.currency0,this.pool.currency1,this.pool.fee,this.pool.tickSpacing,this.pool.hooks,n,0,o.TickMath.getTickAtSqrtRatio(n)),liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount0,a=new t({pool:u,liquidity:this.liquidity,tickLower:this.tickLower,tickUpper:this.tickUpper}).amount1;return{amount0:c.quotient,amount1:a.quotient}},t.fromAmounts=function(r){var e=r.pool,n=r.tickLower,i=r.tickUpper,u=r.amount0,c=r.amount1,a=r.useFullPrecision,s=o.TickMath.getSqrtRatioAtTick(n),p=o.TickMath.getSqrtRatioAtTick(i);return new t({pool:e,tickLower:n,tickUpper:i,liquidity:o.maxLiquidityForAmounts(e.sqrtRatioX96,s,p,u,c,a)})},t.fromAmount0=function(r){return t.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:r.amount0,amount1:i.MaxUint256,useFullPrecision:r.useFullPrecision})},t.fromAmount1=function(r){return t.fromAmounts({pool:r.pool,tickLower:r.tickLower,tickUpper:r.tickUpper,amount0:i.MaxUint256,amount1:r.amount1,useFullPrecision:!0})},d(t,[{key:"token0PriceLower",get:function(){return L(this.pool.currency0,this.pool.currency1,this.tickLower)}},{key:"token0PriceUpper",get:function(){return L(this.pool.currency0,this.pool.currency1,this.tickUpper)}},{key:"amount0",get:function(){return this._token0Amount||(this._token0Amount=i.CurrencyAmount.fromRawAmount(this.pool.currency0,this.pool.tickCurrent<this.tickLower?o.SqrtPriceMath.getAmount0Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):this.pool.tickCurrent<this.tickUpper?o.SqrtPriceMath.getAmount0Delta(this.pool.sqrtRatioX96,o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1):I)),this._token0Amount}},{key:"amount1",get:function(){return this._token1Amount||(this._token1Amount=i.CurrencyAmount.fromRawAmount(this.pool.currency1,this.pool.tickCurrent<this.tickLower?I:o.SqrtPriceMath.getAmount1Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),this.pool.tickCurrent<this.tickUpper?this.pool.sqrtRatioX96:o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!1))),this._token1Amount}},{key:"mintAmounts",get:function(){return null===this._mintAmounts?this.pool.tickCurrent<this.tickLower?{amount0:o.SqrtPriceMath.getAmount0Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:I}:this.pool.tickCurrent<this.tickUpper?{amount0:o.SqrtPriceMath.getAmount0Delta(this.pool.sqrtRatioX96,o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0),amount1:o.SqrtPriceMath.getAmount1Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),this.pool.sqrtRatioX96,this.liquidity,!0)}:{amount0:I,amount1:o.SqrtPriceMath.getAmount1Delta(o.TickMath.getSqrtRatioAtTick(this.tickLower),o.TickMath.getSqrtRatioAtTick(this.tickUpper),this.liquidity,!0)}:this._mintAmounts}}]),t}(),U=function(t,r){for(var e,n=r?t.output:t.input,i=[],o=A(r?t.pools.reverse():t.pools);!(e=o()).done;){var u=e.value,c=n.equals(u.currency0)?u.currency1:u.currency0;i.push({intermediateCurrency:c.isNative?T:c.address,fee:u.fee,tickSpacing:u.tickSpacing,hooks:u.hooks,hookData:"0x"}),n=c}return r?i.reverse():i};(O=exports.Actions||(exports.Actions={}))[O.INCREASE_LIQUIDITY=0]="INCREASE_LIQUIDITY",O[O.DECREASE_LIQUIDITY=1]="DECREASE_LIQUIDITY",O[O.MINT_POSITION=2]="MINT_POSITION",O[O.BURN_POSITION=3]="BURN_POSITION",O[O.SWAP_EXACT_IN_SINGLE=4]="SWAP_EXACT_IN_SINGLE",O[O.SWAP_EXACT_IN=5]="SWAP_EXACT_IN",O[O.SWAP_EXACT_OUT_SINGLE=6]="SWAP_EXACT_OUT_SINGLE",O[O.SWAP_EXACT_OUT=7]="SWAP_EXACT_OUT",O[O.SETTLE=9]="SETTLE",O[O.SETTLE_ALL=16]="SETTLE_ALL",O[O.SETTLE_PAIR=17]="SETTLE_PAIR",O[O.TAKE=18]="TAKE",O[O.TAKE_ALL=19]="TAKE_ALL",O[O.TAKE_PORTION=20]="TAKE_PORTION",O[O.TAKE_PAIR=21]="TAKE_PAIR",O[O.SETTLE_TAKE_PAIR=22]="SETTLE_TAKE_PAIR",O[O.CLOSE_CURRENCY=23]="CLOSE_CURRENCY",O[O.SWEEP=25]="SWEEP";var N=((R={})[exports.Actions.INCREASE_LIQUIDITY]=["uint256 tokenId","uint256 liquidity","uint128 amount0Max","uint128 amount1Max","bytes hookData"],R[exports.Actions.DECREASE_LIQUIDITY]=["uint256 tokenId","uint256 liquidity","uint128 amount0Min","uint128 amount1Min","bytes hookData"],R[exports.Actions.MINT_POSITION]=["(address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks)","int24 tickLower","int24 tickUpper","uint256 liquidity","uint128 amount0Max","uint128 amount1Max","address owner","bytes hookData"],R[exports.Actions.BURN_POSITION]=["uint256 tokenId","uint128 amount0Min","uint128 amount1Min","bytes hookData"],R[exports.Actions.SWAP_EXACT_IN_SINGLE]=["((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 amountIn,uint128 amountOutMinimum,uint160 sqrtPriceLimitX96,bytes hookData)"],R[exports.Actions.SWAP_EXACT_IN]=["(address currencyIn,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountIn,uint128 amountOutMinimum)"],R[exports.Actions.SWAP_EXACT_OUT_SINGLE]=["((address currency0,address currency1,uint24 fee,int24 tickSpacing,address hooks) poolKey,bool zeroForOne,uint128 amountOut,uint128 amountInMaximum,uint160 sqrtPriceLimitX96,bytes hookData)"],R[exports.Actions.SWAP_EXACT_OUT]=["(address currencyOut,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountOut,uint128 amountInMaximum)"],R[exports.Actions.SETTLE]=["address","uint256","bool"],R[exports.Actions.SETTLE_ALL]=["address","uint256"],R[exports.Actions.SETTLE_PAIR]=["address","address"],R[exports.Actions.TAKE]=["address","address","uint256"],R[exports.Actions.TAKE_ALL]=["address","uint256"],R[exports.Actions.TAKE_PORTION]=["address","address","uint256"],R[exports.Actions.TAKE_PAIR]=["address","address","address"],R[exports.Actions.SETTLE_TAKE_PAIR]=["address","address"],R[exports.Actions.CLOSE_CURRENCY]=["address"],R[exports.Actions.SWEEP]=["address","address"],R),M=function(){function t(){this.actions="0x",this.params=[]}var r=t.prototype;return r.addAction=function(t,r){var e=function(t,r){return{action:t,encodedInput:u.defaultAbiCoder.encode(N[t],r)}}(t,r);this.params.push(e.encodedInput),this.actions=this.actions.concat(e.action.toString(16).padStart(2,"0"))},r.addTrade=function(t,r){var n=t.tradeType===i.TradeType.EXACT_OUTPUT;n&&(r||e(!1)),1!==t.swaps.length&&e(!1);var o=n?exports.Actions.SWAP_EXACT_OUT:exports.Actions.SWAP_EXACT_IN,u=X(t.inputAmount.currency),c=X(t.outputAmount.currency);this.addAction(o,[n?{currencyOut:c,path:U(t.route,n),amountInMaximum:t.maximumAmountIn(null!=r?r:new i.Percent(0)).quotient.toString(),amountOut:t.inputAmount.quotient.toString()}:{currencyIn:u,path:U(t.route,n),amountIn:t.inputAmount.quotient.toString(),amountOutMinimum:r?t.minimumAmountOut(r).quotient.toString():0}])},r.addSettle=function(t,r,e){this.addAction(exports.Actions.SETTLE,[X(t),null!=e?e:0,r])},r.addTake=function(t,r,e){var n=r?"0x0000000000000000000000000000000000000002":"0x0000000000000000000000000000000000000001",i=null!=e?e:0;this.addAction(exports.Actions.TAKE,[X(t),n,i])},r.finalize=function(){return u.defaultAbiCoder.encode(["bytes","bytes[]"],[this.actions,this.params])},t}();function X(t){return t.isNative?T:t.wrapped.address}function D(t){return t.isNative?T:t.wrapped.address}var j=function(t){var r,e;function n(){return t.apply(this,arguments)||this}e=t,(r=n).prototype=Object.create(e.prototype),r.prototype.constructor=r,f(r,e);var i=n.prototype;return i.addMint=function(t,r,e,n,i,o,u,c){void 0===c&&(c="0x");var a=[_.getPoolKey(t.currency0,t.currency1,t.fee,t.tickSpacing,t.hooks),r,e,n.toString(),i.toString(),o.toString(),u,c];this.addAction(exports.Actions.MINT_POSITION,a)},i.addIncrease=function(t,r,e,n,i){void 0===i&&(i="0x");var o=[t.toString(),r.toString(),e.toString(),n.toString(),i];this.addAction(exports.Actions.INCREASE_LIQUIDITY,o)},i.addDecrease=function(t,r,e,n,i){void 0===i&&(i="0x");var o=[t.toString(),r.toString(),e.toString(),n.toString(),i];this.addAction(exports.Actions.DECREASE_LIQUIDITY,o)},i.addBurn=function(t,r,e,n){void 0===n&&(n="0x");var i=[t.toString(),r.toString(),e.toString(),n];this.addAction(exports.Actions.BURN_POSITION,i)},i.addSettlePair=function(t,r){var e=[D(t),D(r)];this.addAction(exports.Actions.SETTLE_PAIR,e)},i.addTakePair=function(t,r,e){var n=[D(t),D(r),e];this.addAction(exports.Actions.TAKE_PAIR,n)},i.addSweep=function(t,r){var e=[D(t),r];this.addAction(exports.Actions.SWEEP,e)},n}(M);exports.DYNAMIC_FEE_FLAG=8388608,exports.Pool=_,exports.Position=C,exports.Route=P,exports.Trade=b,exports.V4Planner=M,exports.V4PositionPlanner=j,exports.encodeRouteToPath=U,exports.toHex=function(t){var r=c.BigInt(t).toString(16);return r.length%2!=0&&(r="0"+r),"0x"+r},exports.tradeComparator=q;
//# sourceMappingURL=v4-sdk.cjs.production.min.js.map

@@ -96,3 +96,3 @@ {

},
"version": "1.3.0"
"version": "1.4.0"
}

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc