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.2.0 to 1.2.1

3

dist/utils/v4Planner.d.ts

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

import { BigNumber } from 'ethers';
import { Currency, Percent, TradeType } from '@uniswap/sdk-core';

@@ -32,3 +33,5 @@ import { Trade } from '../entities/trade';

addTrade(trade: Trade<Currency, Currency, TradeType>, slippageTolerance?: Percent): void;
addSettle(currency: Currency, payerIsUser: boolean, amount?: BigNumber): void;
addTake(currency: Currency, routerMustCustody: boolean, amount?: BigNumber): void;
finalize(): string;
}

2

dist/v4-sdk.cjs.production.min.js

@@ -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"),o=require("@uniswap/sdk-core"),u=require("@uniswap/v3-sdk"),i=require("ethers/lib/utils"),c=t(require("jsbi"));function a(){a=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,o=Object.defineProperty||function(t,r,e){t[r]=e.value},u="function"==typeof Symbol?Symbol:{},i=u.iterator||"@@iterator",c=u.asyncIterator||"@@asyncIterator",s=u.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 u=Object.create((r&&r.prototype instanceof v?r:v).prototype),i=new O(n||[]);return o(u,"_invoke",{value:b(t,e,i)}),u}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 f="suspendedStart",y="executing",d="completed",m={};function v(){}function A(){}function g(){}var T={};p(T,i,(function(){return this}));var x=Object.getPrototypeOf,I=x&&x(x(C([])));I&&I!==e&&n.call(I,i)&&(T=I);var k=g.prototype=v.prototype=Object.create(T);function w(t){["next","throw","return"].forEach((function(r){p(t,r,(function(t){return this._invoke(r,t)}))}))}function E(t,r){function e(o,u,i,c){var a=l(t[o],t,u);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,i,c)}),(function(t){e("throw",t,i,c)})):r.resolve(p).then((function(t){s.value=t,i(s)}),(function(t){return e("throw",t,i,c)}))}c(a.arg)}var u;o(this,"_invoke",{value:function(t,n){function o(){return new r((function(r,o){e(t,n,r,o)}))}return u=u?u.then(o,o):o()}})}function b(r,e,n){var o=f;return function(u,i){if(o===y)throw new Error("Generator is already running");if(o===d){if("throw"===u)throw i;return{value:t,done:!0}}for(n.method=u,n.arg=i;;){var c=n.delegate;if(c){var a=_(c,n);if(a){if(a===m)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(o===f)throw o=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);o=y;var s=l(r,e,n);if("normal"===s.type){if(o=n.done?d:"suspendedYield",s.arg===m)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(o=d,n.method="throw",n.arg=s.arg)}}}function _(r,e){var n=e.method,o=r.iterator[n];if(o===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")),m;var u=l(o,r.iterator,e.arg);if("throw"===u.type)return e.method="throw",e.arg=u.arg,e.delegate=null,m;var i=u.arg;return i?i.done?(e[r.resultName]=i.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,m):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,m)}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 S(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function C(r){if(r||""===r){var e=r[i];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var o=-1,u=function e(){for(;++o<r.length;)if(n.call(r,o))return e.value=r[o],e.done=!1,e;return e.value=t,e.done=!0,e};return u.next=u}}throw new TypeError(typeof r+" is not iterable")}return A.prototype=g,o(k,"constructor",{value:g,configurable:!0}),o(g,"constructor",{value:A,configurable:!0}),A.displayName=p(g,s,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===A||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,p(t,s,"GeneratorFunction")),t.prototype=Object.create(k),t},r.awrap=function(t){return{__await:t}},w(E.prototype),p(E.prototype,c,(function(){return this})),r.AsyncIterator=E,r.async=function(t,e,n,o,u){void 0===u&&(u=Promise);var i=new E(h(t,e,n,o),u);return r.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},w(k),p(k,s,"Generator"),p(k,i,(function(){return this})),p(k,"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=C,O.prototype={constructor:O,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(S),!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 o(n,o){return c.type="throw",c.arg=r,e.next=n,o&&(e.method="next",e.arg=t),!!o}for(var u=this.tryEntries.length-1;u>=0;--u){var i=this.tryEntries[u],c=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var a=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var o=this.tryEntries[e];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var u=o;break}}u&&("break"===t||"continue"===t)&&u.tryLoc<=r&&r<=u.finallyLoc&&(u=null);var i=u?u.completion:{};return i.type=t,i.arg=r,u?(this.method="next",this.next=u.finallyLoc,m):this.complete(i)},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),m},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),S(e),m}},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 o=n.arg;S(e)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:C(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),m}},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,o,u,i){try{var c=t[u](i),a=c.value}catch(t){return void e(t)}c.done?r(a):Promise.resolve(a).then(n,o)}function h(t){return function(){var r=this,e=arguments;return new Promise((function(n,o){var u=t.apply(r,e);function i(t){p(u,n,o,i,c,"next",t)}function c(t){p(u,n,o,i,c,"throw",t)}i(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 f(t,r,e){return r&&l(t.prototype,r),e&&l(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function y(){return(y=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 d(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 m(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 d(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)?d(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 v(t,r){return!!t.isNative||!r.isNative&&t.wrapped.sortsBefore(r.wrapped)}var A,g=require("ethers").constants.AddressZero,T=c.BigInt(-1),x=c.BigInt(0),I=c.BigInt(1),k=c.exponentiate(c.exponentiate(c.BigInt(2),c.BigInt(96)),c.BigInt(2));!function(t){t[t.LOWEST=100]="LOWEST",t[t.LOW=500]="LOW",t[t.MEDIUM=3e3]="MEDIUM",t[t.HIGH=1e4]="HIGH"}(A||(A={})),(r={})[A.LOWEST]=1,r[A.LOW]=10,r[A.MEDIUM]=60,r[A.HIGH]=200;var w=new u.NoTickDataProvider,E=function(){function t(r,n,o,a,s,p,h,l,f){void 0===f&&(f=w),i.isAddress(s)||e(!1),Number.isInteger(o)&&(8388608===o||o<1e6)||e(!1),8388608===o&&(Number(s)>0||e(!1));var y=u.TickMath.getSqrtRatioAtTick(l),d=u.TickMath.getSqrtRatioAtTick(l+1);c.greaterThanOrEqual(c.BigInt(p),y)&&c.lessThanOrEqual(c.BigInt(p),d)||e(!1);var m=v(r,n)?[r,n]:[n,r];this.currency0=m[0],this.currency1=m[1],this.fee=o,this.sqrtRatioX96=c.BigInt(p),this.tickSpacing=a,this.hooks=s,this.liquidity=c.BigInt(h),this.tickCurrent=l,this.tickDataProvider=Array.isArray(f)?new u.TickListDataProvider(f,a):f,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,o,u){i.isAddress(u)||e(!1);var c=v(t,r)?[t,r]:[r,t],a=c[0],s=c[1];return{currency0:a.isNative?g:a.wrapped.address,currency1:s.isNative?g:s.wrapped.address,fee:n,tickSpacing:o,hooks:u}},t.getPoolId=function(t,r,e,o,u){var c=v(t,r)?[t,r]:[r,t],a=c[0],s=c[1];return n.keccak256(["bytes"],[i.defaultAbiCoder.encode(["address","address","uint24","int24","address"],[a.isNative?g:a.wrapped.address,s.isNative?g:s.wrapped.address,e,o,u])])};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,u){var i,s,p,h,l;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return this.involvesCurrency(n.currency)||e(!1),i=n.currency.equals(this.currency0),r.next=4,this.swap(i,n.quotient,u);case 4:return p=(s=r.sent).sqrtRatioX96,h=s.liquidity,l=s.tickCurrent,r.abrupt("return",[o.CurrencyAmount.fromRawAmount(i?this.currency1:this.currency0,c.multiply(s.amountCalculated,T)),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,u){var i,s,p,h,l;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return this.involvesCurrency(n.currency)||e(!1),i=n.currency.equals(this.currency1),r.next=4,this.swap(i,c.multiply(n.quotient,T),u);case 4:return p=(s=r.sent).sqrtRatioX96,h=s.liquidity,l=s.tickCurrent,r.abrupt("return",[o.CurrencyAmount.fromRawAmount(i?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",u.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===g},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,k,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 o.Price(this.currency1,this.currency0,c.multiply(this.sqrtRatioX96,this.sqrtRatioX96),k)}},{key:"token1Price",get:function(){return this.currency1Price}},{key:"chainId",get:function(){return this.currency0.chainId}}]),t}(),b=function(){function t(t,r,n){this._midPrice=null,t.length>0||e(!1);var o=t[0].chainId;t.every((function(t){return t.chainId===o}))||e(!1),t[0].involvesCurrency(r)||e(!1),t[t.length-1].involvesCurrency(n)||e(!1);for(var u,i=[r],c=m(t.entries());!(u=c()).done;){var a=u.value,s=a[1],p=i[a[0]];p.equals(s.currency0)||p.equals(s.currency1)||e(!1);var h=p.equals(s.currency0)?s.currency1:s.currency0;i.push(h)}this.pools=t,this.currencyPath=i,this.input=r,this.output=null!=n?n:i[i.length-1]}return f(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 o.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function _(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 P,S,O=function(){function t(t){var r=t.routes,n=t.tradeType,o=r[0].inputAmount.currency,u=r[0].outputAmount.currency;r.every((function(t){return o.equals(t.route.input)}))||e(!1),r.every((function(t){return u.equals(t.route.output)}))||e(!1);for(var i,c=r.map((function(t){return t.route.pools.length})).reduce((function(t,r){return t+r}),0),a=new Set,s=m(r);!(i=s()).done;)for(var p,h=m(i.value.route.pools);!(p=h()).done;){var l=p.value;a.add(E.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,o.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,o.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,u,i){var c,s,p,h,l,f,y;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(c=new Array(n.currencyPath.length),i!==o.TradeType.EXACT_INPUT){r.next=19;break}u.currency.equals(n.input)||e(!1),c[0]=u,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=o.CurrencyAmount.fromFractionalAmount(n.input,u.numerator,u.denominator),p=o.CurrencyAmount.fromFractionalAmount(n.output,c[c.length-1].numerator,c[c.length-1].denominator),r.next=34;break;case 19:u.currency.equals(n.output)||e(!1),c[c.length-1]=u,f=n.currencyPath.length-1;case 22:if(!(f>0)){r.next=32;break}return y=n.pools[f-1],r.next=26,y.getInputAmount(c[f]);case 26:c[f-1]=r.sent[0];case 29:f--,r.next=22;break;case 32:s=o.CurrencyAmount.fromFractionalAmount(n.input,c[0].numerator,c[0].denominator),p=o.CurrencyAmount.fromFractionalAmount(n.output,u.numerator,u.denominator);case 34:return r.abrupt("return",new t({routes:[{inputAmount:s,outputAmount:p,route:n}],tradeType:i}));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,u){var i,c,s,p,h,l,f,y,d,v,A,g,T;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:i=[],c=m(n);case 2:if((s=c()).done){r.next=43;break}if(h=(p=s.value).route,l=p.amount,f=new Array(h.currencyPath.length),y=void 0,d=void 0,u!==o.TradeType.EXACT_INPUT){r.next=25;break}l.currency.equals(h.input)||e(!1),y=o.CurrencyAmount.fromFractionalAmount(h.input,l.numerator,l.denominator),f[0]=o.CurrencyAmount.fromFractionalAmount(h.input,l.numerator,l.denominator),v=0;case 12:if(!(v<h.currencyPath.length-1)){r.next=22;break}return A=h.pools[v],r.next=16,A.getOutputAmount(f[v]);case 16:f[v+1]=r.sent[0];case 19:v++,r.next=12;break;case 22:d=o.CurrencyAmount.fromFractionalAmount(h.output,f[f.length-1].numerator,f[f.length-1].denominator),r.next=40;break;case 25:l.currency.equals(h.output)||e(!1),d=o.CurrencyAmount.fromFractionalAmount(h.output,l.numerator,l.denominator),f[f.length-1]=o.CurrencyAmount.fromFractionalAmount(h.output,l.numerator,l.denominator),g=h.currencyPath.length-1;case 29:if(!(g>0)){r.next=39;break}return T=h.pools[g-1],r.next=33,T.getInputAmount(f[g]);case 33:f[g-1]=r.sent[0];case 36:g--,r.next=29;break;case 39:y=o.CurrencyAmount.fromFractionalAmount(h.input,f[0].numerator,f[0].denominator);case 40:i.push({route:h,inputAmount:y,outputAmount:d});case 41:r.next=2;break;case 43:return r.abrupt("return",new t({routes:i,tradeType:u}));case 44:case"end":return r.stop()}}),r)})));return function(t,e){return r.apply(this,arguments)}}(),t.createUncheckedTrade=function(r){return new t(y({},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(x)&&e(!1),this.tradeType===o.TradeType.EXACT_OUTPUT)return r;var n=new o.Fraction(I).add(t).invert().multiply(r.quotient).quotient;return o.CurrencyAmount.fromRawAmount(r.currency,n)},r.maximumAmountIn=function(t,r){if(void 0===r&&(r=this.inputAmount),t.lessThan(x)&&e(!1),this.tradeType===o.TradeType.EXACT_INPUT)return r;var n=new o.Fraction(I).add(t).multiply(r.quotient).quotient;return o.CurrencyAmount.fromRawAmount(r.currency,n)},r.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 r=h(a().mark((function r(n,u,i,c,s,p,h){var l,f,y,d,m,v,A,g,T,x;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:y=void 0===(f=(l=void 0===c?{}:c).maxNumResults)?3:f,m=void 0===(d=l.maxHops)?3:d,void 0===s&&(s=[]),void 0===p&&(p=u),void 0===h&&(h=[]),n.length>0||e(!1),m>0||e(!1),u===p||s.length>0||e(!1),v=p,A=0;case 9:if(!(A<n.length)){r.next=45;break}if((g=n[A]).currency0.equals(v.currency)||g.currency1.equals(v.currency)){r.next=13;break}return r.abrupt("continue",42);case 13:return T=void 0,r.prev=14,r.next=18,g.getOutputAmount(v);case 18:T=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(!T.currency.equals(i)){r.next=38;break}return r.t1=o.sortedInsert,r.t2=h,r.next=32,t.fromRoute(new b([].concat(s,[g]),u.currency,i),u,o.TradeType.EXACT_INPUT);case 32:r.t3=r.sent,r.t4=y,r.t5=_,(0,r.t1)(r.t2,r.t3,r.t4,r.t5),r.next=42;break;case 38:if(!(m>1&&n.length>1)){r.next=42;break}return x=n.slice(0,A).concat(n.slice(A+1,n.length)),r.next=42,t.bestTradeExactIn(x,u,i,{maxNumResults:y,maxHops:m-1},[].concat(s,[g]),T,h);case 42:A++,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,o,u,i,c){return r.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var r=h(a().mark((function r(n,u,i,c,s,p,h){var l,f,y,d,m,v,A,g,T,x;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:y=void 0===(f=(l=void 0===c?{}:c).maxNumResults)?3:f,m=void 0===(d=l.maxHops)?3:d,void 0===s&&(s=[]),void 0===p&&(p=i),void 0===h&&(h=[]),n.length>0||e(!1),m>0||e(!1),i===p||s.length>0||e(!1),v=p,A=0;case 9:if(!(A<n.length)){r.next=45;break}if((g=n[A]).currency0.equals(v.currency)||g.currency1.equals(v.currency)){r.next=13;break}return r.abrupt("continue",42);case 13:return T=void 0,r.prev=14,r.next=18,g.getInputAmount(v);case 18:T=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(!T.currency.equals(u)){r.next=38;break}return r.t1=o.sortedInsert,r.t2=h,r.next=32,t.fromRoute(new b([g].concat(s),u,i.currency),i,o.TradeType.EXACT_OUTPUT);case 32:r.t3=r.sent,r.t4=y,r.t5=_,(0,r.t1)(r.t2,r.t3,r.t4,r.t5),r.next=42;break;case 38:if(!(m>1&&n.length>1)){r.next=42;break}return x=n.slice(0,A).concat(n.slice(A+1,n.length)),r.next=42,t.bestTradeExactOut(x,u,i,{maxNumResults:y,maxHops:m-1},[g].concat(s),T,h);case 42:A++,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,o,u,i,c){return r.apply(this,arguments)}}(),f(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)}),o.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)}),o.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 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,r=o.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),e=m(this.swaps);!(t=e()).done;){var n=t.value;r=r.add(n.route.midPrice.quote(n.inputAmount))}var u=r.subtract(this.outputAmount).divide(r);return this._priceImpact=new o.Percent(u.numerator,u.denominator),this._priceImpact}}]),t}(),C=function(t,r){for(var e,n=r?t.output:t.input,o=[],u=m(r?t.pools.reverse():t.pools);!(e=u()).done;){var i=e.value,c=n.equals(i.currency0)?i.currency1:i.currency0;o.push({intermediateCurrency:c.isNative?g:c.address,fee:i.fee,tickSpacing:i.tickSpacing,hooks:i.hooks,hookData:"0x"}),n=c}return r?o.reverse():o};(S=exports.Actions||(exports.Actions={}))[S.INCREASE_LIQUIDITY=0]="INCREASE_LIQUIDITY",S[S.DECREASE_LIQUIDITY=1]="DECREASE_LIQUIDITY",S[S.MINT_POSITION=2]="MINT_POSITION",S[S.BURN_POSITION=3]="BURN_POSITION",S[S.SWAP_EXACT_IN_SINGLE=4]="SWAP_EXACT_IN_SINGLE",S[S.SWAP_EXACT_IN=5]="SWAP_EXACT_IN",S[S.SWAP_EXACT_OUT_SINGLE=6]="SWAP_EXACT_OUT_SINGLE",S[S.SWAP_EXACT_OUT=7]="SWAP_EXACT_OUT",S[S.SETTLE=9]="SETTLE",S[S.SETTLE_ALL=16]="SETTLE_ALL",S[S.TAKE=18]="TAKE",S[S.TAKE_ALL=19]="TAKE_ALL",S[S.TAKE_PORTION=20]="TAKE_PORTION",S[S.SETTLE_TAKE_PAIR=22]="SETTLE_TAKE_PAIR",S[S.CLOSE_CURRENCY=23]="CLOSE_CURRENCY",S[S.SWEEP=25]="SWEEP";var L=((P={})[exports.Actions.INCREASE_LIQUIDITY]=["uint256 tokenId","uint256 liquidity","uint128 amount0Max","uint128 amount1Max","bytes hookData"],P[exports.Actions.DECREASE_LIQUIDITY]=["uint256 tokenId","uint256 liquidity","uint128 amount0Min","uint128 amount1Min","bytes hookData"],P[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"],P[exports.Actions.BURN_POSITION]=["uint256 tokenId","uint128 amount0Min","uint128 amount1Min","bytes hookData"],P[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)"],P[exports.Actions.SWAP_EXACT_IN]=["(address currencyIn,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountIn,uint128 amountOutMinimum)"],P[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)"],P[exports.Actions.SWAP_EXACT_OUT]=["(address currencyOut,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountOut,uint128 amountInMaximum)"],P[exports.Actions.SETTLE]=["address","uint256","bool"],P[exports.Actions.SETTLE_ALL]=["address","uint256"],P[exports.Actions.TAKE]=["address","address","uint256"],P[exports.Actions.TAKE_ALL]=["address","uint256"],P[exports.Actions.TAKE_PORTION]=["address","address","uint256"],P[exports.Actions.SETTLE_TAKE_PAIR]=["address","address"],P[exports.Actions.CLOSE_CURRENCY]=["address"],P[exports.Actions.SWEEP]=["address","address"],P),q=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:i.defaultAbiCoder.encode(L[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){for(var e,n=t.tradeType===o.TradeType.EXACT_INPUT?exports.Actions.SWAP_EXACT_IN:exports.Actions.SWAP_EXACT_OUT,u=N(t.inputAmount.currency),i=N(t.outputAmount.currency),c=m(t.swaps);!(e=c()).done;){var a=e.value;this.addAction(n,[{currencyIn:u,path:C(a.route),amountIn:a.inputAmount.quotient.toString(),amountOutMinimum:r?t.minimumAmountOut(r).quotient.toString():0}])}this.addAction(exports.Actions.SETTLE_TAKE_PAIR,[u,i])},r.finalize=function(){return i.defaultAbiCoder.encode(["bytes","bytes[]"],[this.actions,this.params])},t}();function N(t){return t.isNative?g:t.wrapped.address}exports.DYNAMIC_FEE_FLAG=8388608,exports.Pool=E,exports.Route=b,exports.Trade=O,exports.V4Planner=q,exports.encodeRouteToPath=C,exports.toHex=function(t){var r=c.BigInt(t).toString(16);return r.length%2!=0&&(r="0"+r),"0x"+r},exports.tradeComparator=_;
"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"),u=require("@uniswap/sdk-core"),o=require("@uniswap/v3-sdk"),i=require("ethers/lib/utils"),c=t(require("jsbi"));function a(){a=function(){return r};var t,r={},e=Object.prototype,n=e.hasOwnProperty,u=Object.defineProperty||function(t,r,e){t[r]=e.value},o="function"==typeof Symbol?Symbol:{},i=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 v?r:v).prototype),i=new O(n||[]);return u(o,"_invoke",{value:b(t,e,i)}),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 f="suspendedStart",y="executing",d="completed",m={};function v(){}function A(){}function g(){}var T={};p(T,i,(function(){return this}));var x=Object.getPrototypeOf,k=x&&x(x(C([])));k&&k!==e&&n.call(k,i)&&(T=k);var I=g.prototype=v.prototype=Object.create(T);function w(t){["next","throw","return"].forEach((function(r){p(t,r,(function(t){return this._invoke(r,t)}))}))}function E(t,r){function e(u,o,i,c){var a=l(t[u],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,i,c)}),(function(t){e("throw",t,i,c)})):r.resolve(p).then((function(t){s.value=t,i(s)}),(function(t){return e("throw",t,i,c)}))}c(a.arg)}var o;u(this,"_invoke",{value:function(t,n){function u(){return new r((function(r,u){e(t,n,r,u)}))}return o=o?o.then(u,u):u()}})}function b(r,e,n){var u=f;return function(o,i){if(u===y)throw new Error("Generator is already running");if(u===d){if("throw"===o)throw i;return{value:t,done:!0}}for(n.method=o,n.arg=i;;){var c=n.delegate;if(c){var a=_(c,n);if(a){if(a===m)continue;return a}}if("next"===n.method)n.sent=n._sent=n.arg;else if("throw"===n.method){if(u===f)throw u=d,n.arg;n.dispatchException(n.arg)}else"return"===n.method&&n.abrupt("return",n.arg);u=y;var s=l(r,e,n);if("normal"===s.type){if(u=n.done?d:"suspendedYield",s.arg===m)continue;return{value:s.arg,done:n.done}}"throw"===s.type&&(u=d,n.method="throw",n.arg=s.arg)}}}function _(r,e){var n=e.method,u=r.iterator[n];if(u===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")),m;var o=l(u,r.iterator,e.arg);if("throw"===o.type)return e.method="throw",e.arg=o.arg,e.delegate=null,m;var i=o.arg;return i?i.done?(e[r.resultName]=i.value,e.next=r.nextLoc,"return"!==e.method&&(e.method="next",e.arg=t),e.delegate=null,m):i:(e.method="throw",e.arg=new TypeError("iterator result is not an object"),e.delegate=null,m)}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 S(t){var r=t.completion||{};r.type="normal",delete r.arg,t.completion=r}function O(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(P,this),this.reset(!0)}function C(r){if(r||""===r){var e=r[i];if(e)return e.call(r);if("function"==typeof r.next)return r;if(!isNaN(r.length)){var u=-1,o=function e(){for(;++u<r.length;)if(n.call(r,u))return e.value=r[u],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 A.prototype=g,u(I,"constructor",{value:g,configurable:!0}),u(g,"constructor",{value:A,configurable:!0}),A.displayName=p(g,s,"GeneratorFunction"),r.isGeneratorFunction=function(t){var r="function"==typeof t&&t.constructor;return!!r&&(r===A||"GeneratorFunction"===(r.displayName||r.name))},r.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,p(t,s,"GeneratorFunction")),t.prototype=Object.create(I),t},r.awrap=function(t){return{__await:t}},w(E.prototype),p(E.prototype,c,(function(){return this})),r.AsyncIterator=E,r.async=function(t,e,n,u,o){void 0===o&&(o=Promise);var i=new E(h(t,e,n,u),o);return r.isGeneratorFunction(e)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},w(I),p(I,s,"Generator"),p(I,i,(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=C,O.prototype={constructor:O,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(S),!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 u(n,u){return c.type="throw",c.arg=r,e.next=n,u&&(e.method="next",e.arg=t),!!u}for(var o=this.tryEntries.length-1;o>=0;--o){var i=this.tryEntries[o],c=i.completion;if("root"===i.tryLoc)return u("end");if(i.tryLoc<=this.prev){var a=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(a&&s){if(this.prev<i.catchLoc)return u(i.catchLoc,!0);if(this.prev<i.finallyLoc)return u(i.finallyLoc)}else if(a){if(this.prev<i.catchLoc)return u(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return u(i.finallyLoc)}}}},abrupt:function(t,r){for(var e=this.tryEntries.length-1;e>=0;--e){var u=this.tryEntries[e];if(u.tryLoc<=this.prev&&n.call(u,"finallyLoc")&&this.prev<u.finallyLoc){var o=u;break}}o&&("break"===t||"continue"===t)&&o.tryLoc<=r&&r<=o.finallyLoc&&(o=null);var i=o?o.completion:{};return i.type=t,i.arg=r,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(i)},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),m},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),S(e),m}},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 u=n.arg;S(e)}return u}}throw new Error("illegal catch attempt")},delegateYield:function(r,e,n){return this.delegate={iterator:C(r),resultName:e,nextLoc:n},"next"===this.method&&(this.arg=t),m}},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,u,o,i){try{var c=t[o](i),a=c.value}catch(t){return void e(t)}c.done?r(a):Promise.resolve(a).then(n,u)}function h(t){return function(){var r=this,e=arguments;return new Promise((function(n,u){var o=t.apply(r,e);function i(t){p(o,n,u,i,c,"next",t)}function c(t){p(o,n,u,i,c,"throw",t)}i(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 f(t,r,e){return r&&l(t.prototype,r),e&&l(t,e),Object.defineProperty(t,"prototype",{writable:!1}),t}function y(){return(y=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 d(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 m(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 d(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)?d(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 v(t,r){return!!t.isNative||!r.isNative&&t.wrapped.sortsBefore(r.wrapped)}var A,g=require("ethers").constants.AddressZero,T=c.BigInt(-1),x=c.BigInt(0),k=c.BigInt(1),I=c.exponentiate(c.exponentiate(c.BigInt(2),c.BigInt(96)),c.BigInt(2));!function(t){t[t.LOWEST=100]="LOWEST",t[t.LOW=500]="LOW",t[t.MEDIUM=3e3]="MEDIUM",t[t.HIGH=1e4]="HIGH"}(A||(A={})),(r={})[A.LOWEST]=1,r[A.LOW]=10,r[A.MEDIUM]=60,r[A.HIGH]=200;var w=new o.NoTickDataProvider,E=function(){function t(r,n,u,a,s,p,h,l,f){void 0===f&&(f=w),i.isAddress(s)||e(!1),Number.isInteger(u)&&(8388608===u||u<1e6)||e(!1),8388608===u&&(Number(s)>0||e(!1));var y=o.TickMath.getSqrtRatioAtTick(l),d=o.TickMath.getSqrtRatioAtTick(l+1);c.greaterThanOrEqual(c.BigInt(p),y)&&c.lessThanOrEqual(c.BigInt(p),d)||e(!1);var m=v(r,n)?[r,n]:[n,r];this.currency0=m[0],this.currency1=m[1],this.fee=u,this.sqrtRatioX96=c.BigInt(p),this.tickSpacing=a,this.hooks=s,this.liquidity=c.BigInt(h),this.tickCurrent=l,this.tickDataProvider=Array.isArray(f)?new o.TickListDataProvider(f,a):f,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,u,o){i.isAddress(o)||e(!1);var c=v(t,r)?[t,r]:[r,t],a=c[0],s=c[1];return{currency0:a.isNative?g:a.wrapped.address,currency1:s.isNative?g:s.wrapped.address,fee:n,tickSpacing:u,hooks:o}},t.getPoolId=function(t,r,e,u,o){var c=v(t,r)?[t,r]:[r,t],a=c[0],s=c[1];return n.keccak256(["bytes"],[i.defaultAbiCoder.encode(["address","address","uint24","int24","address"],[a.isNative?g:a.wrapped.address,s.isNative?g:s.wrapped.address,e,u,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 i,s,p,h,l;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return this.involvesCurrency(n.currency)||e(!1),i=n.currency.equals(this.currency0),r.next=4,this.swap(i,n.quotient,o);case 4:return p=(s=r.sent).sqrtRatioX96,h=s.liquidity,l=s.tickCurrent,r.abrupt("return",[u.CurrencyAmount.fromRawAmount(i?this.currency1:this.currency0,c.multiply(s.amountCalculated,T)),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 i,s,p,h,l;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:return this.involvesCurrency(n.currency)||e(!1),i=n.currency.equals(this.currency1),r.next=4,this.swap(i,c.multiply(n.quotient,T),o);case 4:return p=(s=r.sent).sqrtRatioX96,h=s.liquidity,l=s.tickCurrent,r.abrupt("return",[u.CurrencyAmount.fromRawAmount(i?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===g},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 u.Price(this.currency0,this.currency1,I,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 u.Price(this.currency1,this.currency0,c.multiply(this.sqrtRatioX96,this.sqrtRatioX96),I)}},{key:"token1Price",get:function(){return this.currency1Price}},{key:"chainId",get:function(){return this.currency0.chainId}}]),t}(),b=function(){function t(t,r,n){this._midPrice=null,t.length>0||e(!1);var u=t[0].chainId;t.every((function(t){return t.chainId===u}))||e(!1),t[0].involvesCurrency(r)||e(!1),t[t.length-1].involvesCurrency(n)||e(!1);for(var o,i=[r],c=m(t.entries());!(o=c()).done;){var a=o.value,s=a[1],p=i[a[0]];p.equals(s.currency0)||p.equals(s.currency1)||e(!1);var h=p.equals(s.currency0)?s.currency1:s.currency0;i.push(h)}this.pools=t,this.currencyPath=i,this.input=r,this.output=null!=n?n:i[i.length-1]}return f(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 u.Price(this.input,this.output,t.denominator,t.numerator)}}]),t}();function _(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 P,S,O=function(){function t(t){var r=t.routes,n=t.tradeType,u=r[0].inputAmount.currency,o=r[0].outputAmount.currency;r.every((function(t){return u.equals(t.route.input)}))||e(!1),r.every((function(t){return o.equals(t.route.output)}))||e(!1);for(var i,c=r.map((function(t){return t.route.pools.length})).reduce((function(t,r){return t+r}),0),a=new Set,s=m(r);!(i=s()).done;)for(var p,h=m(i.value.route.pools);!(p=h()).done;){var l=p.value;a.add(E.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,u.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,u.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,i){var c,s,p,h,l,f,y;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:if(c=new Array(n.currencyPath.length),i!==u.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=u.CurrencyAmount.fromFractionalAmount(n.input,o.numerator,o.denominator),p=u.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,f=n.currencyPath.length-1;case 22:if(!(f>0)){r.next=32;break}return y=n.pools[f-1],r.next=26,y.getInputAmount(c[f]);case 26:c[f-1]=r.sent[0];case 29:f--,r.next=22;break;case 32:s=u.CurrencyAmount.fromFractionalAmount(n.input,c[0].numerator,c[0].denominator),p=u.CurrencyAmount.fromFractionalAmount(n.output,o.numerator,o.denominator);case 34:return r.abrupt("return",new t({routes:[{inputAmount:s,outputAmount:p,route:n}],tradeType:i}));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 i,c,s,p,h,l,f,y,d,v,A,g,T;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:i=[],c=m(n);case 2:if((s=c()).done){r.next=43;break}if(h=(p=s.value).route,l=p.amount,f=new Array(h.currencyPath.length),y=void 0,d=void 0,o!==u.TradeType.EXACT_INPUT){r.next=25;break}l.currency.equals(h.input)||e(!1),y=u.CurrencyAmount.fromFractionalAmount(h.input,l.numerator,l.denominator),f[0]=u.CurrencyAmount.fromFractionalAmount(h.input,l.numerator,l.denominator),v=0;case 12:if(!(v<h.currencyPath.length-1)){r.next=22;break}return A=h.pools[v],r.next=16,A.getOutputAmount(f[v]);case 16:f[v+1]=r.sent[0];case 19:v++,r.next=12;break;case 22:d=u.CurrencyAmount.fromFractionalAmount(h.output,f[f.length-1].numerator,f[f.length-1].denominator),r.next=40;break;case 25:l.currency.equals(h.output)||e(!1),d=u.CurrencyAmount.fromFractionalAmount(h.output,l.numerator,l.denominator),f[f.length-1]=u.CurrencyAmount.fromFractionalAmount(h.output,l.numerator,l.denominator),g=h.currencyPath.length-1;case 29:if(!(g>0)){r.next=39;break}return T=h.pools[g-1],r.next=33,T.getInputAmount(f[g]);case 33:f[g-1]=r.sent[0];case 36:g--,r.next=29;break;case 39:y=u.CurrencyAmount.fromFractionalAmount(h.input,f[0].numerator,f[0].denominator);case 40:i.push({route:h,inputAmount:y,outputAmount:d});case 41:r.next=2;break;case 43:return r.abrupt("return",new t({routes:i,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(y({},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(x)&&e(!1),this.tradeType===u.TradeType.EXACT_OUTPUT)return r;var n=new u.Fraction(k).add(t).invert().multiply(r.quotient).quotient;return u.CurrencyAmount.fromRawAmount(r.currency,n)},r.maximumAmountIn=function(t,r){if(void 0===r&&(r=this.inputAmount),t.lessThan(x)&&e(!1),this.tradeType===u.TradeType.EXACT_INPUT)return r;var n=new u.Fraction(k).add(t).multiply(r.quotient).quotient;return u.CurrencyAmount.fromRawAmount(r.currency,n)},r.worstExecutionPrice=function(t){return new u.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,i,c,s,p,h){var l,f,y,d,m,v,A,g,T,x;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:y=void 0===(f=(l=void 0===c?{}:c).maxNumResults)?3:f,m=void 0===(d=l.maxHops)?3:d,void 0===s&&(s=[]),void 0===p&&(p=o),void 0===h&&(h=[]),n.length>0||e(!1),m>0||e(!1),o===p||s.length>0||e(!1),v=p,A=0;case 9:if(!(A<n.length)){r.next=45;break}if((g=n[A]).currency0.equals(v.currency)||g.currency1.equals(v.currency)){r.next=13;break}return r.abrupt("continue",42);case 13:return T=void 0,r.prev=14,r.next=18,g.getOutputAmount(v);case 18:T=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(!T.currency.equals(i)){r.next=38;break}return r.t1=u.sortedInsert,r.t2=h,r.next=32,t.fromRoute(new b([].concat(s,[g]),o.currency,i),o,u.TradeType.EXACT_INPUT);case 32:r.t3=r.sent,r.t4=y,r.t5=_,(0,r.t1)(r.t2,r.t3,r.t4,r.t5),r.next=42;break;case 38:if(!(m>1&&n.length>1)){r.next=42;break}return x=n.slice(0,A).concat(n.slice(A+1,n.length)),r.next=42,t.bestTradeExactIn(x,o,i,{maxNumResults:y,maxHops:m-1},[].concat(s,[g]),T,h);case 42:A++,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,u,o,i,c){return r.apply(this,arguments)}}(),t.bestTradeExactOut=function(){var r=h(a().mark((function r(n,o,i,c,s,p,h){var l,f,y,d,m,v,A,g,T,x;return a().wrap((function(r){for(;;)switch(r.prev=r.next){case 0:y=void 0===(f=(l=void 0===c?{}:c).maxNumResults)?3:f,m=void 0===(d=l.maxHops)?3:d,void 0===s&&(s=[]),void 0===p&&(p=i),void 0===h&&(h=[]),n.length>0||e(!1),m>0||e(!1),i===p||s.length>0||e(!1),v=p,A=0;case 9:if(!(A<n.length)){r.next=45;break}if((g=n[A]).currency0.equals(v.currency)||g.currency1.equals(v.currency)){r.next=13;break}return r.abrupt("continue",42);case 13:return T=void 0,r.prev=14,r.next=18,g.getInputAmount(v);case 18:T=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(!T.currency.equals(o)){r.next=38;break}return r.t1=u.sortedInsert,r.t2=h,r.next=32,t.fromRoute(new b([g].concat(s),o,i.currency),i,u.TradeType.EXACT_OUTPUT);case 32:r.t3=r.sent,r.t4=y,r.t5=_,(0,r.t1)(r.t2,r.t3,r.t4,r.t5),r.next=42;break;case 38:if(!(m>1&&n.length>1)){r.next=42;break}return x=n.slice(0,A).concat(n.slice(A+1,n.length)),r.next=42,t.bestTradeExactOut(x,o,i,{maxNumResults:y,maxHops:m-1},[g].concat(s),T,h);case 42:A++,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,u,o,i,c){return r.apply(this,arguments)}}(),f(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)}),u.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)}),u.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 u.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=u.CurrencyAmount.fromRawAmount(this.outputAmount.currency,0),e=m(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 u.Percent(o.numerator,o.denominator),this._priceImpact}}]),t}(),C=function(t,r){for(var e,n=r?t.output:t.input,u=[],o=m(r?t.pools.reverse():t.pools);!(e=o()).done;){var i=e.value,c=n.equals(i.currency0)?i.currency1:i.currency0;u.push({intermediateCurrency:c.isNative?g:c.address,fee:i.fee,tickSpacing:i.tickSpacing,hooks:i.hooks,hookData:"0x"}),n=c}return r?u.reverse():u};(S=exports.Actions||(exports.Actions={}))[S.INCREASE_LIQUIDITY=0]="INCREASE_LIQUIDITY",S[S.DECREASE_LIQUIDITY=1]="DECREASE_LIQUIDITY",S[S.MINT_POSITION=2]="MINT_POSITION",S[S.BURN_POSITION=3]="BURN_POSITION",S[S.SWAP_EXACT_IN_SINGLE=4]="SWAP_EXACT_IN_SINGLE",S[S.SWAP_EXACT_IN=5]="SWAP_EXACT_IN",S[S.SWAP_EXACT_OUT_SINGLE=6]="SWAP_EXACT_OUT_SINGLE",S[S.SWAP_EXACT_OUT=7]="SWAP_EXACT_OUT",S[S.SETTLE=9]="SETTLE",S[S.SETTLE_ALL=16]="SETTLE_ALL",S[S.TAKE=18]="TAKE",S[S.TAKE_ALL=19]="TAKE_ALL",S[S.TAKE_PORTION=20]="TAKE_PORTION",S[S.SETTLE_TAKE_PAIR=22]="SETTLE_TAKE_PAIR",S[S.CLOSE_CURRENCY=23]="CLOSE_CURRENCY",S[S.SWEEP=25]="SWEEP";var L=((P={})[exports.Actions.INCREASE_LIQUIDITY]=["uint256 tokenId","uint256 liquidity","uint128 amount0Max","uint128 amount1Max","bytes hookData"],P[exports.Actions.DECREASE_LIQUIDITY]=["uint256 tokenId","uint256 liquidity","uint128 amount0Min","uint128 amount1Min","bytes hookData"],P[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"],P[exports.Actions.BURN_POSITION]=["uint256 tokenId","uint128 amount0Min","uint128 amount1Min","bytes hookData"],P[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)"],P[exports.Actions.SWAP_EXACT_IN]=["(address currencyIn,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountIn,uint128 amountOutMinimum)"],P[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)"],P[exports.Actions.SWAP_EXACT_OUT]=["(address currencyOut,(address intermediateCurrency,uint256 fee,int24 tickSpacing,address hooks,bytes hookData)[] path,uint128 amountOut,uint128 amountInMaximum)"],P[exports.Actions.SETTLE]=["address","uint256","bool"],P[exports.Actions.SETTLE_ALL]=["address","uint256"],P[exports.Actions.TAKE]=["address","address","uint256"],P[exports.Actions.TAKE_ALL]=["address","uint256"],P[exports.Actions.TAKE_PORTION]=["address","address","uint256"],P[exports.Actions.SETTLE_TAKE_PAIR]=["address","address"],P[exports.Actions.CLOSE_CURRENCY]=["address"],P[exports.Actions.SWEEP]=["address","address"],P),q=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:i.defaultAbiCoder.encode(L[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===u.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,i=N(t.inputAmount.currency),c=N(t.outputAmount.currency);this.addAction(o,[n?{currencyOut:c,path:C(t.route,n),amountInMaximum:t.maximumAmountIn(null!=r?r:new u.Percent(0)).quotient.toString(),amountOut:t.inputAmount.quotient.toString()}:{currencyIn:i,path:C(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,[N(t),null!=e?e:0,r])},r.addTake=function(t,r,e){var n=r?"0x0000000000000000000000000000000000000002":"0x0000000000000000000000000000000000000001",u=null!=e?e:0;this.addAction(exports.Actions.TAKE,[N(t),n,u])},r.finalize=function(){return i.defaultAbiCoder.encode(["bytes","bytes[]"],[this.actions,this.params])},t}();function N(t){return t.isNative?g:t.wrapped.address}exports.DYNAMIC_FEE_FLAG=8388608,exports.Pool=E,exports.Route=b,exports.Trade=O,exports.V4Planner=q,exports.encodeRouteToPath=C,exports.toHex=function(t){var r=c.BigInt(t).toString(16);return r.length%2!=0&&(r="0"+r),"0x"+r},exports.tradeComparator=_;
//# sourceMappingURL=v4-sdk.cjs.production.min.js.map

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

},
"version": "1.2.0"
"version": "1.2.1"
}

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