Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uniswap/v3-sdk

Package Overview
Dependencies
Maintainers
8
Versions
95
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniswap/v3-sdk - npm Package Compare versions

Comparing version 1.0.0-alpha.3 to 1.0.0-alpha.4

4

dist/utils/index.d.ts
import mostSignificantBit from './mostSignificantBit';
import TickMath from './tickMath';
import { tickToPrice } from './priceTickConversions';
export { mostSignificantBit, TickMath, tickToPrice };
export * from './priceTickConversions';
export { mostSignificantBit, TickMath };

@@ -13,3 +13,3 @@ 'use strict';

var invariant = _interopDefault(require('tiny-invariant'));
require('decimal.js-light');
var Decimal = _interopDefault(require('decimal.js-light'));

@@ -986,3 +986,22 @@ var _TICK_SPACINGS;

}
/**
* Returns the first tick for which the given price is greater than or equal to the tick price
* @param price for which to return the closest tick that represents a price less than or equal to the input price,
* i.e. the price of the returned tick is less than or equal to the input price
*/
function priceToClosestTick(price) {
!(price.baseCurrency instanceof sdkCore.Token && price.quoteCurrency instanceof sdkCore.Token) ? invariant(false, 'TOKENS') : void 0;
var ratioDecimal = price.baseCurrency.sortsBefore(price.quoteCurrency) ? new Decimal(price.raw.numerator.toString()).dividedBy(price.raw.denominator.toString()) : new Decimal(price.raw.denominator.toString()).dividedBy(price.raw.numerator.toString());
var sqrtRatio = ratioDecimal.sqrt(); // hacky way to avoid exponential notation without modifying a global configuration
var toExpPosBefore = Decimal.toExpPos;
Decimal.toExpPos = 9999999;
var sqrtRatioX96 = JSBI.BigInt(sqrtRatio.mul(new Decimal(2).pow(96)).toInteger().toString());
Decimal.toExpPos = toExpPosBefore;
var tick = TickMath.getTickAtSqrtRatio(sqrtRatioX96);
if (!tickToPrice(price.baseCurrency, price.quoteCurrency, tick + 1).greaterThan(price)) tick++;
return tick;
}
exports.FACTORY_ADDRESS = FACTORY_ADDRESS;

@@ -1000,4 +1019,5 @@ exports.INIT_CODE_HASH = INIT_CODE_HASH;

exports.mostSignificantBit = mostSignificantBit;
exports.priceToClosestTick = priceToClosestTick;
exports.tickToPrice = tickToPrice;
exports.tradeComparator = tradeComparator;
//# sourceMappingURL=v3-sdk.cjs.development.js.map

@@ -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 e,n=t(require("jsbi")),r=require("@ethersproject/abi"),o=require("@ethersproject/address"),i=require("@ethersproject/solidity"),u=require("@uniswap/sdk-core"),a=t(require("tiny-invariant"));require("decimal.js-light");var c,s="0x56cf930c850ce212aa057e794ef994327f2cb22ca6f87b126cc538e797b9541c",f=n.BigInt(0),p=n.BigInt(1);function l(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function d(t,e,n){return e&&l(t.prototype,e),n&&l(t,n),t}function h(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function T(t){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function v(t,e){return(v=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function m(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function g(t,e,n){return(g=m()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&v(o,n.prototype),o}).apply(null,arguments)}function k(t){var e="function"==typeof Map?new Map:void 0;return(k=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return g(t,arguments,T(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),v(n,t)})(t)}function y(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function A(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function I(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return A(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?A(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}!function(t){t[t.LOW=500]="LOW",t[t.MEDIUM=3e3]="MEDIUM",t[t.HIGH=1e4]="HIGH"}(c||(c={})),(e={})[c.LOW]=10,e[c.MEDIUM]=60,e[c.HIGH]=200;var b="setPrototypeOf"in Object,x=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,b&&Object.setPrototypeOf(y(n),(this instanceof e?this.constructor:void 0).prototype),n}return h(e,t),e}(k(Error)),E=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,b&&Object.setPrototypeOf(y(n),(this instanceof e?this.constructor:void 0).prototype),n}return h(e,t),e}(k(Error)),w=function(t){var e=t.factoryAddress,n=t.tokenA,u=t.tokenB,a=t.fee,c=n.sortsBefore(u)?[n,u]:[u,n];return o.getCreate2Address(e,i.keccak256(["bytes"],[r.defaultAbiCoder.encode(["address","address","uint24"],[c[0].address,c[1].address,a])]),s)},O=function(){function t(t,e,r,o,i,u){Number.isInteger(r)||a(!1),Boolean(null==u?void 0:u.head)||a(!1);var c=t.token.sortsBefore(e.token)?[t,e]:[e,t];this.tokenAmounts=c,this.fee=r,this.sqrtPriceX96=n.BigInt(o),this.ticks=u,this.liquidity=n.BigInt(i)}t.getAddress=function(t,e,n){return w({factoryAddress:"0x1F98431c8aD98523631AE4a59f267346ea31F984",fee:n,tokenA:t,tokenB:e})};var e=t.prototype;return e.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},e.priceOf=function(t){return this.involvesToken(t)||a(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||a(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(t){throw this.involvesToken(t.token)||a(!1),new Error("todo")},e.getInputAmount=function(t){throw this.involvesToken(t.token)||a(!1),new Error("todo")},e.getLiquidityMinted=function(t,e,n){throw new Error("todo")},e.getLiquidityValue=function(t,e,n,r,o){this.involvesToken(t)||a(!1),n.raw<=e.raw||a(!1),a(!1)},d(t,[{key:"token0Price",get:function(){return this.sqrtPriceX96||a(!1),new u.Price(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return this.sqrtPriceX96||a(!1),new u.Price(this.token1,this.token0,this.tokenAmounts[1].raw,this.tokenAmounts[0].raw)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"feeLevel",get:function(){return this.fee}},{key:"inRangeLiquidity",get:function(){return this.liquidity.toString()}},{key:"tickList",get:function(){return this.ticks}},{key:"token0",get:function(){return this.tokenAmounts[0].token}},{key:"token1",get:function(){return this.tokenAmounts[1].token}},{key:"reserve0",get:function(){return this.tokenAmounts[0]}},{key:"reserve1",get:function(){return this.tokenAmounts[1]}}]),t}(),q=function(){function t(t,e,n){t.length>0||a(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||a(!1);var o=u.WETH9[r],i=e instanceof u.Token&&t[0].involvesToken(e),c=e===u.ETHER&&o&&t[0].involvesToken(o);i||c||a(!1);var s=void 0===n,f=n instanceof u.Token&&t[t.length-1].involvesToken(n),p=n===u.ETHER&&o&&t[t.length-1].involvesToken(o);s||f||p||a(!1);for(var l,d=[e instanceof u.Token?e:o],h=I(t.entries());!(l=h()).done;){var T=l.value,v=T[1],m=d[T[0]];m.equals(v.token0)||m.equals(v.token1)||a(!1);var g=m.equals(v.token0)?v.token1:v.token0;d.push(g)}this.pools=t,this.tokenPath=d,this.input=e,this.output=null!=n?n:d[d.length-1]}return d(t,[{key:"chainId",get:function(){return this.pools[0].chainId}}]),t}();function P(t,e){return u.currencyEquals(t.inputAmount.currency,e.inputAmount.currency)||a(!1),u.currencyEquals(t.outputAmount.currency,e.outputAmount.currency)||a(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?0:t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}function R(t,e){var n=P(t,e);return 0!==n?n:t.priceImpact.lessThan(e.priceImpact)?-1:t.priceImpact.greaterThan(e.priceImpact)?1:t.route.tokenPath.length-e.route.tokenPath.length}function S(t,e){return t instanceof u.TokenAmount?t:t.currency===u.ETHER?new u.TokenAmount(u.WETH9[e],t.raw):void a(!1)}function B(t,e){return t instanceof u.Token?t:t===u.ETHER?u.WETH9[e]:void a(!1)}var _=function(){function t(t,e,n){var r,o,i,c=new Array(t.tokenPath.length),s=new Array(t.pools.length);if(n===u.TradeType.EXACT_INPUT){u.currencyEquals(e.currency,t.input)||a(!1),c[0]=S(e,t.chainId);for(var f=0;f<t.tokenPath.length-1;f++){var p=t.pools[f].getOutputAmount(c[f]),l=p[1];c[f+1]=p[0],s[f]=l}}else{u.currencyEquals(e.currency,t.output)||a(!1),c[c.length-1]=S(e,t.chainId);for(var d=t.tokenPath.length-1;d>0;d--){var h=t.pools[d-1].getInputAmount(c[d]),T=h[1];c[d-1]=h[0],s[d-1]=T}}this.route=t,this.tradeType=n,this.inputAmount=n===u.TradeType.EXACT_INPUT?e:t.input===u.ETHER?u.CurrencyAmount.ether(c[0].raw):c[0],this.outputAmount=n===u.TradeType.EXACT_OUTPUT?e:t.output===u.ETHER?u.CurrencyAmount.ether(c[c.length-1].raw):c[c.length-1],this.executionPrice=new u.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.priceImpact=(r=this.outputAmount,i=(o=this.executionPrice.raw.multiply(this.inputAmount.raw)).subtract(r.raw).divide(o),new u.Percent(i.numerator,i.denominator))}t.exactIn=function(e,n){return new t(e,n,u.TradeType.EXACT_INPUT)},t.exactOut=function(e,n){return new t(e,n,u.TradeType.EXACT_OUTPUT)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(f)&&a(!1),this.tradeType===u.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new u.Fraction(p).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof u.TokenAmount?new u.TokenAmount(this.outputAmount.token,e):u.CurrencyAmount.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(f)&&a(!1),this.tradeType===u.TradeType.EXACT_INPUT)return this.inputAmount;var e=new u.Fraction(p).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof u.TokenAmount?new u.TokenAmount(this.inputAmount.token,e):u.CurrencyAmount.ether(e)},t.bestTradeExactIn=function(e,n,r,o,i,c,s){var p=void 0===o?{}:o,l=p.maxNumResults,d=void 0===l?3:l,h=p.maxHops,T=void 0===h?3:h;void 0===i&&(i=[]),void 0===c&&(c=n),void 0===s&&(s=[]),e.length>0||a(!1),T>0||a(!1),c===n||i.length>0||a(!1);var v=n instanceof u.TokenAmount?n.token.chainId:r instanceof u.Token?r.chainId:void 0;void 0===v&&a(!1);for(var m=S(n,v),g=B(r,v),k=0;k<e.length;k++){var y=e[k];if((y.token0.equals(m.token)||y.token1.equals(m.token))&&!y.reserve0.equalTo(f)&&!y.reserve1.equalTo(f)){var A=void 0;try{A=y.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(A.token.equals(g))u.sortedInsert(s,new t(new q([].concat(i,[y]),c.currency,r),c,u.TradeType.EXACT_INPUT),d,R);else if(T>1&&e.length>1){var I=e.slice(0,k).concat(e.slice(k+1,e.length));t.bestTradeExactIn(I,A,r,{maxNumResults:d,maxHops:T-1},[].concat(i,[y]),c,s)}}}return s},t.bestTradeExactOut=function(e,n,r,o,i,c,s){var p=void 0===o?{}:o,l=p.maxNumResults,d=void 0===l?3:l,h=p.maxHops,T=void 0===h?3:h;void 0===i&&(i=[]),void 0===c&&(c=r),void 0===s&&(s=[]),e.length>0||a(!1),T>0||a(!1),c===r||i.length>0||a(!1);var v=r instanceof u.TokenAmount?r.token.chainId:n instanceof u.Token?n.chainId:void 0;void 0===v&&a(!1);for(var m=S(r,v),g=B(n,v),k=0;k<e.length;k++){var y=e[k];if((y.token0.equals(m.token)||y.token1.equals(m.token))&&!y.reserve0.equalTo(f)&&!y.reserve1.equalTo(f)){var A=void 0;try{A=y.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(A.token.equals(g))u.sortedInsert(s,new t(new q([y].concat(i),n,c.currency),c,u.TradeType.EXACT_OUTPUT),d,R);else if(T>1&&e.length>1){var I=e.slice(0,k).concat(e.slice(k+1,e.length));t.bestTradeExactOut(I,n,A,{maxNumResults:d,maxHops:T-1},[y].concat(i),c,s)}}}return s},t}();function H(t){return"0x"+t.raw.toString(16)}var C=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===u.ETHER,r=t.outputAmount.currency===u.ETHER;n&&r&&a(!1),!("ttl"in e)||e.ttl>0||a(!1);var o,i,c,s=u.validateAndParseAddress(e.recipient),f=H(t.maximumAmountIn(e.allowedSlippage)),p=H(t.minimumAmountOut(e.allowedSlippage)),l=t.route.tokenPath.map((function(t){return t.address})),d="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),h=Boolean(e.feeOnTransfer);switch(t.tradeType){case u.TradeType.EXACT_INPUT:n?(o=h?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[p,l,s,d],c=f):r?(o=h?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[f,p,l,s,d],c="0x0"):(o=h?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[f,p,l,s,d],c="0x0");break;case u.TradeType.EXACT_OUTPUT:h&&a(!1),n?(o="swapETHForExactTokens",i=[p,l,s,d],c=f):r?(o="swapTokensForExactETH",i=[p,f,l,s,d],c="0x0"):(o="swapTokensForExactTokens",i=[p,f,l,s,d],c="0x0");break;default:throw new Error("invalid trade type")}return{methodName:o,args:i,value:c}},t}(),M=n.BigInt(2),F=[128,64,32,16,8,4,2,1].map((function(t){return[t,n.exponentiate(M,n.BigInt(t))]}));function U(t){n.greaterThan(t,f)||a(!1);for(var e,r=0,o=I(F);!(e=o()).done;){var i=e.value,u=i[0];n.greaterThanOrEqual(t,i[1])&&(t=n.signedRightShift(t,n.BigInt(u)),r+=u)}return r}function j(t,e){return n.signedRightShift(n.multiply(t,n.BigInt(e)),n.BigInt(128))}var N=n.exponentiate(n.BigInt(2),n.BigInt(32)),X=function(){function t(){}return t.getSqrtRatioAtTick=function(e){var r=e<0?-1*e:e;r<=t.MAX_TICK||a(!1);var o=n.BigInt(0!=(1&r)?"0xfffcb933bd6fad37aa2d162d1a594001":"0x100000000000000000000000000000000");return 0!=(2&r)&&(o=j(o,"0xfff97272373d413259a46990580e213a")),0!=(4&r)&&(o=j(o,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&r)&&(o=j(o,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&r)&&(o=j(o,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&r)&&(o=j(o,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&r)&&(o=j(o,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&r)&&(o=j(o,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&r)&&(o=j(o,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&r)&&(o=j(o,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&r)&&(o=j(o,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&r)&&(o=j(o,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&r)&&(o=j(o,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&r)&&(o=j(o,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&r)&&(o=j(o,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&r)&&(o=j(o,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&r)&&(o=j(o,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&r)&&(o=j(o,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&r)&&(o=j(o,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&r)&&(o=j(o,"0x48a170391f7dc42444e8fa2")),e>0&&(o=n.divide(u.MaxUint256,o)),n.greaterThanOrEqual(n.remainder(o,N),f)?n.add(n.divide(o,N),p):n.divide(o,N)},t.getTickAtSqrtRatio=function(e){n.greaterThanOrEqual(e,t.MIN_SQRT_RATIO)&&n.lessThan(e,t.MAX_SQRT_RATIO)||a(!1);var r,o=n.leftShift(e,n.BigInt(32)),i=U(o);r=n.greaterThanOrEqual(n.BigInt(i),n.BigInt(128))?n.signedRightShift(o,n.BigInt(i-127)):n.leftShift(o,n.BigInt(127-i));for(var u=n.leftShift(n.subtract(n.BigInt(i),n.BigInt(128)),n.BigInt(64)),c=0;c<14;c++){r=n.signedRightShift(n.multiply(r,r),n.BigInt(127));var s=n.signedRightShift(r,n.BigInt(128));u=n.bitwiseOr(u,n.leftShift(s,n.BigInt(63-c))),r=n.signedRightShift(r,s)}var f=n.multiply(u,n.BigInt("255738958999603826347141")),p=n.toNumber(n.signedRightShift(n.subtract(f,n.BigInt("3402992956809132418596140100660247210")),n.BigInt(128))),l=n.toNumber(n.signedRightShift(n.add(f,n.BigInt("291339464771989622907027621153398088495")),n.BigInt(128)));return p===l?p:n.lessThanOrEqual(t.getSqrtRatioAtTick(l),e)?l:p},t}();X.MIN_TICK=-887272,X.MAX_TICK=-X.MIN_TICK,X.MIN_SQRT_RATIO=n.BigInt("4295128739"),X.MAX_SQRT_RATIO=n.BigInt("1461446703485210103287273052203988822378723970342");var D=n.exponentiate(n.BigInt(2),n.BigInt(192));exports.FACTORY_ADDRESS="0x1F98431c8aD98523631AE4a59f267346ea31F984",exports.INIT_CODE_HASH=s,exports.InsufficientInputAmountError=E,exports.InsufficientReservesError=x,exports.Pool=O,exports.Route=q,exports.Router=C,exports.TickMath=X,exports.Trade=_,exports.computePoolAddress=w,exports.inputOutputComparator=P,exports.mostSignificantBit=U,exports.tickToPrice=function(t,e,r){var o=X.getSqrtRatioAtTick(r),i=n.multiply(o,o);return t.sortsBefore(e)?new u.Price(t,e,D,i):new u.Price(t,e,i,D)},exports.tradeComparator=R;
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e,n,r=t(require("jsbi")),o=require("@ethersproject/abi"),i=require("@ethersproject/address"),u=require("@ethersproject/solidity"),a=require("@uniswap/sdk-core"),c=t(require("tiny-invariant")),s=t(require("decimal.js-light")),f="0x56cf930c850ce212aa057e794ef994327f2cb22ca6f87b126cc538e797b9541c",p=r.BigInt(0),d=r.BigInt(1);function l(t,e){for(var n=0;n<e.length;n++){var r=e[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(t,r.key,r)}}function h(t,e,n){return e&&l(t.prototype,e),n&&l(t,n),t}function T(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function v(t){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function m(t,e){return(m=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function g(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Date.prototype.toString.call(Reflect.construct(Date,[],(function(){}))),!0}catch(t){return!1}}function k(t,e,n){return(k=g()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&m(o,n.prototype),o}).apply(null,arguments)}function y(t){var e="function"==typeof Map?new Map:void 0;return(y=function(t){if(null===t||-1===Function.toString.call(t).indexOf("[native code]"))return t;if("function"!=typeof t)throw new TypeError("Super expression must either be null or a function");if(void 0!==e){if(e.has(t))return e.get(t);e.set(t,n)}function n(){return k(t,arguments,v(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),m(n,t)})(t)}function A(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function I(t,e){(null==e||e>t.length)&&(e=t.length);for(var n=0,r=new Array(e);n<e;n++)r[n]=t[n];return r}function b(t,e){var n;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(n=function(t,e){if(t){if("string"==typeof t)return I(t,void 0);var n=Object.prototype.toString.call(t).slice(8,-1);return"Object"===n&&t.constructor&&(n=t.constructor.name),"Map"===n||"Set"===n?Array.from(t):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?I(t,void 0):void 0}}(t))||e&&t&&"number"==typeof t.length){n&&(t=n);var r=0;return function(){return r>=t.length?{done:!0}:{done:!1,value:t[r++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}return(n=t[Symbol.iterator]()).next.bind(n)}!function(t){t[t.LOW=500]="LOW",t[t.MEDIUM=3e3]="MEDIUM",t[t.HIGH=1e4]="HIGH"}(n||(n={})),(e={})[n.LOW]=10,e[n.MEDIUM]=60,e[n.HIGH]=200;var x="setPrototypeOf"in Object,E=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,x&&Object.setPrototypeOf(A(n),(this instanceof e?this.constructor:void 0).prototype),n}return T(e,t),e}(y(Error)),w=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,x&&Object.setPrototypeOf(A(n),(this instanceof e?this.constructor:void 0).prototype),n}return T(e,t),e}(y(Error)),O=function(t){var e=t.factoryAddress,n=t.tokenA,r=t.tokenB,a=t.fee,c=n.sortsBefore(r)?[n,r]:[r,n];return i.getCreate2Address(e,u.keccak256(["bytes"],[o.defaultAbiCoder.encode(["address","address","uint24"],[c[0].address,c[1].address,a])]),f)},q=function(){function t(t,e,n,o,i,u){Number.isInteger(n)||c(!1),Boolean(null==u?void 0:u.head)||c(!1);var a=t.token.sortsBefore(e.token)?[t,e]:[e,t];this.tokenAmounts=a,this.fee=n,this.sqrtPriceX96=r.BigInt(o),this.ticks=u,this.liquidity=r.BigInt(i)}t.getAddress=function(t,e,n){return O({factoryAddress:"0x1F98431c8aD98523631AE4a59f267346ea31F984",fee:n,tokenA:t,tokenB:e})};var e=t.prototype;return e.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},e.priceOf=function(t){return this.involvesToken(t)||c(!1),t.equals(this.token0)?this.token0Price:this.token1Price},e.reserveOf=function(t){return this.involvesToken(t)||c(!1),t.equals(this.token0)?this.reserve0:this.reserve1},e.getOutputAmount=function(t){throw this.involvesToken(t.token)||c(!1),new Error("todo")},e.getInputAmount=function(t){throw this.involvesToken(t.token)||c(!1),new Error("todo")},e.getLiquidityMinted=function(t,e,n){throw new Error("todo")},e.getLiquidityValue=function(t,e,n,r,o){this.involvesToken(t)||c(!1),n.raw<=e.raw||c(!1),c(!1)},h(t,[{key:"token0Price",get:function(){return this.sqrtPriceX96||c(!1),new a.Price(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return this.sqrtPriceX96||c(!1),new a.Price(this.token1,this.token0,this.tokenAmounts[1].raw,this.tokenAmounts[0].raw)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"feeLevel",get:function(){return this.fee}},{key:"inRangeLiquidity",get:function(){return this.liquidity.toString()}},{key:"tickList",get:function(){return this.ticks}},{key:"token0",get:function(){return this.tokenAmounts[0].token}},{key:"token1",get:function(){return this.tokenAmounts[1].token}},{key:"reserve0",get:function(){return this.tokenAmounts[0]}},{key:"reserve1",get:function(){return this.tokenAmounts[1]}}]),t}(),P=function(){function t(t,e,n){t.length>0||c(!1);var r=t[0].chainId;t.every((function(t){return t.chainId===r}))||c(!1);var o=a.WETH9[r],i=e instanceof a.Token&&t[0].involvesToken(e),u=e===a.ETHER&&o&&t[0].involvesToken(o);i||u||c(!1);var s=void 0===n,f=n instanceof a.Token&&t[t.length-1].involvesToken(n),p=n===a.ETHER&&o&&t[t.length-1].involvesToken(o);s||f||p||c(!1);for(var d,l=[e instanceof a.Token?e:o],h=b(t.entries());!(d=h()).done;){var T=d.value,v=T[1],m=l[T[0]];m.equals(v.token0)||m.equals(v.token1)||c(!1);var g=m.equals(v.token0)?v.token1:v.token0;l.push(g)}this.pools=t,this.tokenPath=l,this.input=e,this.output=null!=n?n:l[l.length-1]}return h(t,[{key:"chainId",get:function(){return this.pools[0].chainId}}]),t}();function S(t,e){return a.currencyEquals(t.inputAmount.currency,e.inputAmount.currency)||c(!1),a.currencyEquals(t.outputAmount.currency,e.outputAmount.currency)||c(!1),t.outputAmount.equalTo(e.outputAmount)?t.inputAmount.equalTo(e.inputAmount)?0:t.inputAmount.lessThan(e.inputAmount)?-1:1:t.outputAmount.lessThan(e.outputAmount)?1:-1}function R(t,e){var n=S(t,e);return 0!==n?n:t.priceImpact.lessThan(e.priceImpact)?-1:t.priceImpact.greaterThan(e.priceImpact)?1:t.route.tokenPath.length-e.route.tokenPath.length}function B(t,e){return t instanceof a.TokenAmount?t:t.currency===a.ETHER?new a.TokenAmount(a.WETH9[e],t.raw):void c(!1)}function _(t,e){return t instanceof a.Token?t:t===a.ETHER?a.WETH9[e]:void c(!1)}var C=function(){function t(t,e,n){var r,o,i,u=new Array(t.tokenPath.length),s=new Array(t.pools.length);if(n===a.TradeType.EXACT_INPUT){a.currencyEquals(e.currency,t.input)||c(!1),u[0]=B(e,t.chainId);for(var f=0;f<t.tokenPath.length-1;f++){var p=t.pools[f].getOutputAmount(u[f]),d=p[1];u[f+1]=p[0],s[f]=d}}else{a.currencyEquals(e.currency,t.output)||c(!1),u[u.length-1]=B(e,t.chainId);for(var l=t.tokenPath.length-1;l>0;l--){var h=t.pools[l-1].getInputAmount(u[l]),T=h[1];u[l-1]=h[0],s[l-1]=T}}this.route=t,this.tradeType=n,this.inputAmount=n===a.TradeType.EXACT_INPUT?e:t.input===a.ETHER?a.CurrencyAmount.ether(u[0].raw):u[0],this.outputAmount=n===a.TradeType.EXACT_OUTPUT?e:t.output===a.ETHER?a.CurrencyAmount.ether(u[u.length-1].raw):u[u.length-1],this.executionPrice=new a.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.priceImpact=(r=this.outputAmount,i=(o=this.executionPrice.raw.multiply(this.inputAmount.raw)).subtract(r.raw).divide(o),new a.Percent(i.numerator,i.denominator))}t.exactIn=function(e,n){return new t(e,n,a.TradeType.EXACT_INPUT)},t.exactOut=function(e,n){return new t(e,n,a.TradeType.EXACT_OUTPUT)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(p)&&c(!1),this.tradeType===a.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new a.Fraction(d).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof a.TokenAmount?new a.TokenAmount(this.outputAmount.token,e):a.CurrencyAmount.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(p)&&c(!1),this.tradeType===a.TradeType.EXACT_INPUT)return this.inputAmount;var e=new a.Fraction(d).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof a.TokenAmount?new a.TokenAmount(this.inputAmount.token,e):a.CurrencyAmount.ether(e)},t.bestTradeExactIn=function(e,n,r,o,i,u,s){var f=void 0===o?{}:o,d=f.maxNumResults,l=void 0===d?3:d,h=f.maxHops,T=void 0===h?3:h;void 0===i&&(i=[]),void 0===u&&(u=n),void 0===s&&(s=[]),e.length>0||c(!1),T>0||c(!1),u===n||i.length>0||c(!1);var v=n instanceof a.TokenAmount?n.token.chainId:r instanceof a.Token?r.chainId:void 0;void 0===v&&c(!1);for(var m=B(n,v),g=_(r,v),k=0;k<e.length;k++){var y=e[k];if((y.token0.equals(m.token)||y.token1.equals(m.token))&&!y.reserve0.equalTo(p)&&!y.reserve1.equalTo(p)){var A=void 0;try{A=y.getOutputAmount(m)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(A.token.equals(g))a.sortedInsert(s,new t(new P([].concat(i,[y]),u.currency,r),u,a.TradeType.EXACT_INPUT),l,R);else if(T>1&&e.length>1){var I=e.slice(0,k).concat(e.slice(k+1,e.length));t.bestTradeExactIn(I,A,r,{maxNumResults:l,maxHops:T-1},[].concat(i,[y]),u,s)}}}return s},t.bestTradeExactOut=function(e,n,r,o,i,u,s){var f=void 0===o?{}:o,d=f.maxNumResults,l=void 0===d?3:d,h=f.maxHops,T=void 0===h?3:h;void 0===i&&(i=[]),void 0===u&&(u=r),void 0===s&&(s=[]),e.length>0||c(!1),T>0||c(!1),u===r||i.length>0||c(!1);var v=r instanceof a.TokenAmount?r.token.chainId:n instanceof a.Token?n.chainId:void 0;void 0===v&&c(!1);for(var m=B(r,v),g=_(n,v),k=0;k<e.length;k++){var y=e[k];if((y.token0.equals(m.token)||y.token1.equals(m.token))&&!y.reserve0.equalTo(p)&&!y.reserve1.equalTo(p)){var A=void 0;try{A=y.getInputAmount(m)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(A.token.equals(g))a.sortedInsert(s,new t(new P([y].concat(i),n,u.currency),u,a.TradeType.EXACT_OUTPUT),l,R);else if(T>1&&e.length>1){var I=e.slice(0,k).concat(e.slice(k+1,e.length));t.bestTradeExactOut(I,n,A,{maxNumResults:l,maxHops:T-1},[y].concat(i),u,s)}}}return s},t}();function H(t){return"0x"+t.raw.toString(16)}var M=function(){function t(){}return t.swapCallParameters=function(t,e){var n=t.inputAmount.currency===a.ETHER,r=t.outputAmount.currency===a.ETHER;n&&r&&c(!1),!("ttl"in e)||e.ttl>0||c(!1);var o,i,u,s=a.validateAndParseAddress(e.recipient),f=H(t.maximumAmountIn(e.allowedSlippage)),p=H(t.minimumAmountOut(e.allowedSlippage)),d=t.route.tokenPath.map((function(t){return t.address})),l="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),h=Boolean(e.feeOnTransfer);switch(t.tradeType){case a.TradeType.EXACT_INPUT:n?(o=h?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[p,d,s,l],u=f):r?(o=h?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[f,p,d,s,l],u="0x0"):(o=h?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[f,p,d,s,l],u="0x0");break;case a.TradeType.EXACT_OUTPUT:h&&c(!1),n?(o="swapETHForExactTokens",i=[p,d,s,l],u=f):r?(o="swapTokensForExactETH",i=[p,f,d,s,l],u="0x0"):(o="swapTokensForExactTokens",i=[p,f,d,s,l],u="0x0");break;default:throw new Error("invalid trade type")}return{methodName:o,args:i,value:u}},t}(),F=r.BigInt(2),U=[128,64,32,16,8,4,2,1].map((function(t){return[t,r.exponentiate(F,r.BigInt(t))]}));function j(t){r.greaterThan(t,p)||c(!1);for(var e,n=0,o=b(U);!(e=o()).done;){var i=e.value,u=i[0];r.greaterThanOrEqual(t,i[1])&&(t=r.signedRightShift(t,r.BigInt(u)),n+=u)}return n}function N(t,e){return r.signedRightShift(r.multiply(t,r.BigInt(e)),r.BigInt(128))}var X=r.exponentiate(r.BigInt(2),r.BigInt(32)),D=function(){function t(){}return t.getSqrtRatioAtTick=function(e){var n=e<0?-1*e:e;n<=t.MAX_TICK||c(!1);var o=r.BigInt(0!=(1&n)?"0xfffcb933bd6fad37aa2d162d1a594001":"0x100000000000000000000000000000000");return 0!=(2&n)&&(o=N(o,"0xfff97272373d413259a46990580e213a")),0!=(4&n)&&(o=N(o,"0xfff2e50f5f656932ef12357cf3c7fdcc")),0!=(8&n)&&(o=N(o,"0xffe5caca7e10e4e61c3624eaa0941cd0")),0!=(16&n)&&(o=N(o,"0xffcb9843d60f6159c9db58835c926644")),0!=(32&n)&&(o=N(o,"0xff973b41fa98c081472e6896dfb254c0")),0!=(64&n)&&(o=N(o,"0xff2ea16466c96a3843ec78b326b52861")),0!=(128&n)&&(o=N(o,"0xfe5dee046a99a2a811c461f1969c3053")),0!=(256&n)&&(o=N(o,"0xfcbe86c7900a88aedcffc83b479aa3a4")),0!=(512&n)&&(o=N(o,"0xf987a7253ac413176f2b074cf7815e54")),0!=(1024&n)&&(o=N(o,"0xf3392b0822b70005940c7a398e4b70f3")),0!=(2048&n)&&(o=N(o,"0xe7159475a2c29b7443b29c7fa6e889d9")),0!=(4096&n)&&(o=N(o,"0xd097f3bdfd2022b8845ad8f792aa5825")),0!=(8192&n)&&(o=N(o,"0xa9f746462d870fdf8a65dc1f90e061e5")),0!=(16384&n)&&(o=N(o,"0x70d869a156d2a1b890bb3df62baf32f7")),0!=(32768&n)&&(o=N(o,"0x31be135f97d08fd981231505542fcfa6")),0!=(65536&n)&&(o=N(o,"0x9aa508b5b7a84e1c677de54f3e99bc9")),0!=(131072&n)&&(o=N(o,"0x5d6af8dedb81196699c329225ee604")),0!=(262144&n)&&(o=N(o,"0x2216e584f5fa1ea926041bedfe98")),0!=(524288&n)&&(o=N(o,"0x48a170391f7dc42444e8fa2")),e>0&&(o=r.divide(a.MaxUint256,o)),r.greaterThanOrEqual(r.remainder(o,X),p)?r.add(r.divide(o,X),d):r.divide(o,X)},t.getTickAtSqrtRatio=function(e){r.greaterThanOrEqual(e,t.MIN_SQRT_RATIO)&&r.lessThan(e,t.MAX_SQRT_RATIO)||c(!1);var n,o=r.leftShift(e,r.BigInt(32)),i=j(o);n=r.greaterThanOrEqual(r.BigInt(i),r.BigInt(128))?r.signedRightShift(o,r.BigInt(i-127)):r.leftShift(o,r.BigInt(127-i));for(var u=r.leftShift(r.subtract(r.BigInt(i),r.BigInt(128)),r.BigInt(64)),a=0;a<14;a++){n=r.signedRightShift(r.multiply(n,n),r.BigInt(127));var s=r.signedRightShift(n,r.BigInt(128));u=r.bitwiseOr(u,r.leftShift(s,r.BigInt(63-a))),n=r.signedRightShift(n,s)}var f=r.multiply(u,r.BigInt("255738958999603826347141")),p=r.toNumber(r.signedRightShift(r.subtract(f,r.BigInt("3402992956809132418596140100660247210")),r.BigInt(128))),d=r.toNumber(r.signedRightShift(r.add(f,r.BigInt("291339464771989622907027621153398088495")),r.BigInt(128)));return p===d?p:r.lessThanOrEqual(t.getSqrtRatioAtTick(d),e)?d:p},t}();D.MIN_TICK=-887272,D.MAX_TICK=-D.MIN_TICK,D.MIN_SQRT_RATIO=r.BigInt("4295128739"),D.MAX_SQRT_RATIO=r.BigInt("1461446703485210103287273052203988822378723970342");var L=r.exponentiate(r.BigInt(2),r.BigInt(192));function W(t,e,n){var o=D.getSqrtRatioAtTick(n),i=r.multiply(o,o);return t.sortsBefore(e)?new a.Price(t,e,L,i):new a.Price(t,e,i,L)}exports.FACTORY_ADDRESS="0x1F98431c8aD98523631AE4a59f267346ea31F984",exports.INIT_CODE_HASH=f,exports.InsufficientInputAmountError=w,exports.InsufficientReservesError=E,exports.Pool=q,exports.Route=P,exports.Router=M,exports.TickMath=D,exports.Trade=C,exports.computePoolAddress=O,exports.inputOutputComparator=S,exports.mostSignificantBit=j,exports.priceToClosestTick=function(t){t.baseCurrency instanceof a.Token&&t.quoteCurrency instanceof a.Token||c(!1);var e=(t.baseCurrency.sortsBefore(t.quoteCurrency)?new s(t.raw.numerator.toString()).dividedBy(t.raw.denominator.toString()):new s(t.raw.denominator.toString()).dividedBy(t.raw.numerator.toString())).sqrt(),n=s.toExpPos;s.toExpPos=9999999;var o=r.BigInt(e.mul(new s(2).pow(96)).toInteger().toString());s.toExpPos=n;var i=D.getTickAtSqrtRatio(o);return W(t.baseCurrency,t.quoteCurrency,i+1).greaterThan(t)||i++,i},exports.tickToPrice=W,exports.tradeComparator=R;
//# sourceMappingURL=v3-sdk.cjs.production.min.js.map

@@ -7,3 +7,3 @@ import JSBI from 'jsbi';

import invariant from 'tiny-invariant';
import 'decimal.js-light';
import Decimal from 'decimal.js-light';

@@ -980,4 +980,23 @@ var _TICK_SPACINGS;

}
/**
* Returns the first tick for which the given price is greater than or equal to the tick price
* @param price for which to return the closest tick that represents a price less than or equal to the input price,
* i.e. the price of the returned tick is less than or equal to the input price
*/
export { FACTORY_ADDRESS, INIT_CODE_HASH, InsufficientInputAmountError, InsufficientReservesError, Pool, Route, Router, TickMath, Trade, computePoolAddress, inputOutputComparator, mostSignificantBit, tickToPrice, tradeComparator };
function priceToClosestTick(price) {
!(price.baseCurrency instanceof Token && price.quoteCurrency instanceof Token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKENS') : invariant(false) : void 0;
var ratioDecimal = price.baseCurrency.sortsBefore(price.quoteCurrency) ? new Decimal(price.raw.numerator.toString()).dividedBy(price.raw.denominator.toString()) : new Decimal(price.raw.denominator.toString()).dividedBy(price.raw.numerator.toString());
var sqrtRatio = ratioDecimal.sqrt(); // hacky way to avoid exponential notation without modifying a global configuration
var toExpPosBefore = Decimal.toExpPos;
Decimal.toExpPos = 9999999;
var sqrtRatioX96 = JSBI.BigInt(sqrtRatio.mul(new Decimal(2).pow(96)).toInteger().toString());
Decimal.toExpPos = toExpPosBefore;
var tick = TickMath.getTickAtSqrtRatio(sqrtRatioX96);
if (!tickToPrice(price.baseCurrency, price.quoteCurrency, tick + 1).greaterThan(price)) tick++;
return tick;
}
export { FACTORY_ADDRESS, INIT_CODE_HASH, InsufficientInputAmountError, InsufficientReservesError, Pool, Route, Router, TickMath, Trade, computePoolAddress, inputOutputComparator, mostSignificantBit, priceToClosestTick, tickToPrice, tradeComparator };
//# sourceMappingURL=v3-sdk.esm.js.map

@@ -7,3 +7,3 @@ {

},
"version": "1.0.0-alpha.3",
"version": "1.0.0-alpha.4",
"description": "⚒️ An SDK for building applications on top of Uniswap V3",

@@ -10,0 +10,0 @@ "main": "dist/index.js",

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 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