Socket
Socket
Sign inDemoInstall

@uniswap/v2-sdk

Package Overview
Dependencies
Maintainers
9
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniswap/v2-sdk - npm Package Compare versions

Comparing version 2.0.0 to 2.0.1

2

dist/v2-sdk.cjs.development.js

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

!(input.isToken && pairs[0].involvesToken(input) || input === sdkCore.ETHER && weth && pairs[0].involvesToken(weth)) ? invariant(false, 'INPUT') : void 0;
!(typeof output === 'undefined' || output.isToken && pairs[pairs.length - 1].involvesToken(output) || output === sdkCore.ETHER && weth && pairs[pairs.length - 1].involvesToken(weth)) ? invariant(false, 'OUTPUT') : void 0;
!((output == null ? void 0 : output.isToken) && pairs[pairs.length - 1].involvesToken(output) || output === sdkCore.ETHER && weth && pairs[pairs.length - 1].involvesToken(weth)) ? invariant(false, 'OUTPUT') : void 0;
var path = [input.isToken ? input : weth];

@@ -439,0 +439,0 @@

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

"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("jsbi")),r=require("@uniswap/sdk-core"),n=e(require("tiny-invariant")),u=require("@ethersproject/solidity"),o=require("@ethersproject/address"),i="0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",c=t.BigInt(1e3),s=t.BigInt(0),a=t.BigInt(1),l=t.BigInt(5),p=t.BigInt(997),h=t.BigInt(1e3);function y(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function f(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),e}function d(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function v(e){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function T(e,t){return(T=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}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(e){return!1}}function k(e,t,r){return(k=m()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var u=new(Function.bind.apply(e,n));return r&&T(u,r.prototype),u}).apply(null,arguments)}function w(e){var t="function"==typeof Map?new Map:void 0;return(w=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return k(e,arguments,v(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),T(r,e)})(e)}function A(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function g(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return E(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?E(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[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.")}return(r=e[Symbol.iterator]()).next.bind(r)}var I="setPrototypeOf"in Object,q=function(e){function t(){var r;return(r=e.call(this)||this).isInsufficientReservesError=!0,r.name=r.constructor.name,I&&Object.setPrototypeOf(A(r),(this instanceof t?this.constructor:void 0).prototype),r}return d(t,e),t}(w(Error)),x=function(e){function t(){var r;return(r=e.call(this)||this).isInsufficientInputAmountError=!0,r.name=r.constructor.name,I&&Object.setPrototypeOf(A(r),(this instanceof t?this.constructor:void 0).prototype),r}return d(t,e),t}(w(Error)),b=function(e){var t=e.factoryAddress,r=e.tokenA,n=e.tokenB,c=r.sortsBefore(n)?[r,n]:[n,r];return o.getCreate2Address(t,u.keccak256(["bytes"],[u.pack(["address","address"],[c[0].address,c[1].address])]),i)},O=function(){function e(t,u){t.currency.isToken&&u.currency.isToken||n(!1);var o=t.currency.sortsBefore(u.currency)?[t,u]:[u,t];o[0].currency.isToken&&o[1].currency.isToken||n(!1),this.liquidityToken=new r.Token(o[0].currency.chainId,e.getAddress(o[0].currency,o[1].currency),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=o}e.getAddress=function(e,t){return b({factoryAddress:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",tokenA:e,tokenB:t})};var u=e.prototype;return u.involvesToken=function(e){return e.equals(this.token0)||e.equals(this.token1)},u.priceOf=function(e){return this.involvesToken(e)||n(!1),e.equals(this.token0)?this.token0Price:this.token1Price},u.reserveOf=function(e){return this.involvesToken(e)||n(!1),e.equals(this.token0)?this.reserve0:this.reserve1},u.getOutputAmount=function(u){if(u.currency.isToken&&this.involvesToken(u.currency)||n(!1),t.equal(this.reserve0.raw,s)||t.equal(this.reserve1.raw,s))throw new q;var o=this.reserveOf(u.currency),i=this.reserveOf(u.currency.equals(this.token0)?this.token1:this.token0),c=t.multiply(u.raw,p),a=t.multiply(c,i.raw),l=t.add(t.multiply(o.raw,h),c),y=new r.CurrencyAmount(u.currency.equals(this.token0)?this.token1:this.token0,t.divide(a,l));if(t.equal(y.raw,s))throw new x;return[y,new e(o.add(u),i.subtract(y))]},u.getInputAmount=function(u){if(u.currency.isToken&&this.involvesToken(u.currency)||n(!1),t.equal(this.reserve0.raw,s)||t.equal(this.reserve1.raw,s)||t.greaterThanOrEqual(u.raw,this.reserveOf(u.currency).raw))throw new q;var o=this.reserveOf(u.currency),i=this.reserveOf(u.currency.equals(this.token0)?this.token1:this.token0),c=t.multiply(t.multiply(i.raw,u.raw),h),l=t.multiply(t.subtract(o.raw,u.raw),p),y=new r.CurrencyAmount(u.currency.equals(this.token0)?this.token1:this.token0,t.add(t.divide(c,l),a));return[y,new e(i.add(y),o.subtract(u))]},u.getLiquidityMinted=function(e,u,o){e.currency.isToken&&e.currency.equals(this.liquidityToken)||n(!1);var i,a=u.currency.isToken&&o.currency.isToken&&u.currency.sortsBefore(o.currency)?[u,o]:[o,u];if(a[0].currency.isToken&&a[1].currency.isToken||n(!1),a[0].currency.equals(this.token0)&&a[1].currency.equals(this.token1)||n(!1),t.equal(e.raw,s))i=t.subtract(r.sqrt(t.multiply(a[0].raw,a[1].raw)),c);else{var l=t.divide(t.multiply(a[0].raw,e.raw),this.reserve0.raw),p=t.divide(t.multiply(a[1].raw,e.raw),this.reserve1.raw);i=t.lessThanOrEqual(l,p)?l:p}if(!t.greaterThan(i,s))throw new x;return new r.CurrencyAmount(this.liquidityToken,i)},u.getLiquidityValue=function(e,u,o,i,c){var a;if(void 0===i&&(i=!1),this.involvesToken(e)||n(!1),u.currency.isToken&&u.currency.equals(this.liquidityToken)||n(!1),o.currency.isToken&&o.currency.equals(this.liquidityToken)||n(!1),t.lessThanOrEqual(o.raw,u.raw)||n(!1),i){c||n(!1);var p=t.BigInt(c);if(t.equal(p,s))a=u;else{var h=r.sqrt(t.multiply(this.reserve0.raw,this.reserve1.raw)),y=r.sqrt(p);if(t.greaterThan(h,y)){var f=t.multiply(u.raw,t.subtract(h,y)),d=t.add(t.multiply(h,l),y),v=t.divide(f,d);a=u.add(new r.CurrencyAmount(this.liquidityToken,v))}else a=u}}else a=u;return new r.CurrencyAmount(e,t.divide(t.multiply(o.raw,this.reserveOf(e).raw),a.raw))},f(e,[{key:"token0Price",get:function(){return new r.Price(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new r.Price(this.token1,this.token0,this.tokenAmounts[1].raw,this.tokenAmounts[0].raw)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"token0",get:function(){return this.tokenAmounts[0].currency.isToken||n(!1),this.tokenAmounts[0].currency}},{key:"token1",get:function(){return this.tokenAmounts[1].currency.isToken||n(!1),this.tokenAmounts[1].currency}},{key:"reserve0",get:function(){return this.tokenAmounts[0]}},{key:"reserve1",get:function(){return this.tokenAmounts[1]}}]),e}(),P=function(){function e(e,t,u){e.length>0||n(!1);var o=e[0].chainId;e.every((function(e){return e.chainId===o}))||n(!1);var i=r.WETH9[o];t.isToken&&e[0].involvesToken(t)||t===r.ETHER&&i&&e[0].involvesToken(i)||n(!1),void 0===u||u.isToken&&e[e.length-1].involvesToken(u)||u===r.ETHER&&i&&e[e.length-1].involvesToken(i)||n(!1);for(var c,s=[t.isToken?t:i],a=g(e.entries());!(c=a()).done;){var l=c.value,p=l[1],h=s[l[0]];h.equals(p.token0)||h.equals(p.token1)||n(!1);var y=h.equals(p.token0)?p.token1:p.token0;s.push(y)}this.pairs=e,this.path=s,this.input=t,this.output=null!=u?u:s[s.length-1]}return f(e,[{key:"midPrice",get:function(){for(var e,t=[],n=g(this.pairs.entries());!(e=n()).done;){var u=e.value,o=u[1];t.push(this.path[u[0]].equals(o.token0)?new r.Price(o.reserve0.currency,o.reserve1.currency,o.reserve0.raw,o.reserve1.raw):new r.Price(o.reserve1.currency,o.reserve0.currency,o.reserve1.raw,o.reserve0.raw))}return t.slice(1).reduce((function(e,t){return e.multiply(t)}),t[0])}},{key:"chainId",get:function(){return this.pairs[0].chainId}}]),e}();function C(e,t){return r.currencyEquals(e.inputAmount.currency,t.inputAmount.currency)||n(!1),r.currencyEquals(e.outputAmount.currency,t.outputAmount.currency)||n(!1),e.outputAmount.equalTo(t.outputAmount)?e.inputAmount.equalTo(t.inputAmount)?0:e.inputAmount.lessThan(t.inputAmount)?-1:1:e.outputAmount.lessThan(t.outputAmount)?1:-1}function _(e,t){var r=C(e,t);return 0!==r?r:e.priceImpact.lessThan(t.priceImpact)?-1:e.priceImpact.greaterThan(t.priceImpact)?1:e.route.path.length-t.route.path.length}function R(e,t){if(e.currency.isToken)return e;if(e.currency.isEther)return new r.CurrencyAmount(r.WETH9[t],e.raw);throw new Error("CURRENCY")}function U(e,t){if(e.isToken)return e;if(e===r.ETHER)return r.WETH9[t];throw new Error("CURRENCY")}var H=function(){function e(e,t,u){var o,i,c,s=new Array(e.path.length),a=new Array(e.pairs.length);if(u===r.TradeType.EXACT_INPUT){r.currencyEquals(t.currency,e.input)||n(!1),s[0]=R(t,e.chainId);for(var l=0;l<e.path.length-1;l++){var p=e.pairs[l].getOutputAmount(s[l]),h=p[1];s[l+1]=p[0],a[l]=h}}else{r.currencyEquals(t.currency,e.output)||n(!1),s[s.length-1]=R(t,e.chainId);for(var y=e.path.length-1;y>0;y--){var f=e.pairs[y-1].getInputAmount(s[y]),d=f[1];s[y-1]=f[0],a[y-1]=d}}this.route=e,this.tradeType=u,this.inputAmount=u===r.TradeType.EXACT_INPUT?t:e.input===r.ETHER?r.CurrencyAmount.ether(s[0].raw):s[0],this.outputAmount=u===r.TradeType.EXACT_OUTPUT?t:e.output===r.ETHER?r.CurrencyAmount.ether(s[s.length-1].raw):s[s.length-1],this.executionPrice=new r.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=new P(a,e.input).midPrice,this.priceImpact=(o=this.outputAmount,c=(i=e.midPrice.raw.multiply(this.inputAmount.raw)).subtract(o.raw).divide(i),new r.Percent(c.numerator,c.denominator))}e.exactIn=function(t,n){return new e(t,n,r.TradeType.EXACT_INPUT)},e.exactOut=function(t,n){return new e(t,n,r.TradeType.EXACT_OUTPUT)};var t=e.prototype;return t.minimumAmountOut=function(e){if(e.lessThan(s)&&n(!1),this.tradeType===r.TradeType.EXACT_OUTPUT)return this.outputAmount;var t=new r.Fraction(a).add(e).invert().multiply(this.outputAmount.raw).quotient;return new r.CurrencyAmount(this.outputAmount.currency,t)},t.maximumAmountIn=function(e){if(e.lessThan(s)&&n(!1),this.tradeType===r.TradeType.EXACT_INPUT)return this.inputAmount;var t=new r.Fraction(a).add(e).multiply(this.inputAmount.raw).quotient;return new r.CurrencyAmount(this.inputAmount.currency,t)},e.bestTradeExactIn=function(t,u,o,i,c,a,l){var p=void 0===i?{}:i,h=p.maxNumResults,y=void 0===h?3:h,f=p.maxHops,d=void 0===f?3:f;void 0===c&&(c=[]),void 0===a&&(a=u),void 0===l&&(l=[]),t.length>0||n(!1),d>0||n(!1),a===u||c.length>0||n(!1);var v=u.currency.isToken?u.currency.chainId:o.isToken?o.chainId:void 0;void 0===v&&n(!1);for(var T=R(u,v),m=U(o,v),k=0;k<t.length;k++){var w=t[k];if((r.currencyEquals(w.token0,T.currency)||r.currencyEquals(w.token1,T.currency))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getOutputAmount(T)[0]}catch(e){if(e.isInsufficientInputAmountError)continue;throw e}if(r.currencyEquals(A.currency,m))r.sortedInsert(l,new e(new P([].concat(c,[w]),a.currency,o),a,r.TradeType.EXACT_INPUT),y,_);else if(d>1&&t.length>1){var E=t.slice(0,k).concat(t.slice(k+1,t.length));e.bestTradeExactIn(E,A,o,{maxNumResults:y,maxHops:d-1},[].concat(c,[w]),a,l)}}}return l},t.worstExecutionPrice=function(e){return new r.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(e).raw,this.minimumAmountOut(e).raw)},e.bestTradeExactOut=function(t,u,o,i,c,a,l){var p=void 0===i?{}:i,h=p.maxNumResults,y=void 0===h?3:h,f=p.maxHops,d=void 0===f?3:f;void 0===c&&(c=[]),void 0===a&&(a=o),void 0===l&&(l=[]),t.length>0||n(!1),d>0||n(!1),a===o||c.length>0||n(!1);var v=o.currency.isToken?o.currency.chainId:u.isToken?u.chainId:void 0;void 0===v&&n(!1);for(var T=R(o,v),m=U(u,v),k=0;k<t.length;k++){var w=t[k];if((r.currencyEquals(w.token0,T.currency)||r.currencyEquals(w.token1,T.currency))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getInputAmount(T)[0]}catch(e){if(e.isInsufficientReservesError)continue;throw e}if(r.currencyEquals(A.currency,m))r.sortedInsert(l,new e(new P([w].concat(c),u,a.currency),a,r.TradeType.EXACT_OUTPUT),y,_);else if(d>1&&t.length>1){var E=t.slice(0,k).concat(t.slice(k+1,t.length));e.bestTradeExactOut(E,u,A,{maxNumResults:y,maxHops:d-1},[w].concat(c),a,l)}}}return l},e}();function S(e){return"0x"+e.raw.toString(16)}var B=function(){function e(){}return e.swapCallParameters=function(e,t){var u=e.inputAmount.currency===r.ETHER,o=e.outputAmount.currency===r.ETHER;u&&o&&n(!1),!("ttl"in t)||t.ttl>0||n(!1);var i,c,s,a=r.validateAndParseAddress(t.recipient),l=S(e.maximumAmountIn(t.allowedSlippage)),p=S(e.minimumAmountOut(t.allowedSlippage)),h=e.route.path.map((function(e){return e.address})),y="ttl"in t?"0x"+(Math.floor((new Date).getTime()/1e3)+t.ttl).toString(16):"0x"+t.deadline.toString(16),f=Boolean(t.feeOnTransfer);switch(e.tradeType){case r.TradeType.EXACT_INPUT:u?(i=f?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",c=[p,h,a,y],s=l):o?(i=f?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",c=[l,p,h,a,y],s="0x0"):(i=f?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",c=[l,p,h,a,y],s="0x0");break;case r.TradeType.EXACT_OUTPUT:f&&n(!1),u?(i="swapETHForExactTokens",c=[p,h,a,y],s=l):o?(i="swapTokensForExactETH",c=[p,l,h,a,y],s="0x0"):(i="swapTokensForExactTokens",c=[p,l,h,a,y],s="0x0")}return{methodName:i,args:c,value:s}},e}();exports.JSBI=t,exports.FACTORY_ADDRESS="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.INIT_CODE_HASH=i,exports.InsufficientInputAmountError=x,exports.InsufficientReservesError=q,exports.MINIMUM_LIQUIDITY=c,exports.Pair=O,exports.Route=P,exports.Router=B,exports.Trade=H,exports.computePairAddress=b,exports.inputOutputComparator=C,exports.tradeComparator=_;
"use strict";function e(e){return e&&"object"==typeof e&&"default"in e?e.default:e}Object.defineProperty(exports,"__esModule",{value:!0});var t=e(require("jsbi")),r=require("@uniswap/sdk-core"),n=e(require("tiny-invariant")),u=require("@ethersproject/solidity"),o=require("@ethersproject/address"),i="0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",c=t.BigInt(1e3),s=t.BigInt(0),a=t.BigInt(1),l=t.BigInt(5),p=t.BigInt(997),h=t.BigInt(1e3);function y(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function f(e,t,r){return t&&y(e.prototype,t),r&&y(e,r),e}function d(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function v(e){return(v=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function T(e,t){return(T=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}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(e){return!1}}function k(e,t,r){return(k=m()?Reflect.construct:function(e,t,r){var n=[null];n.push.apply(n,t);var u=new(Function.bind.apply(e,n));return r&&T(u,r.prototype),u}).apply(null,arguments)}function w(e){var t="function"==typeof Map?new Map:void 0;return(w=function(e){if(null===e||-1===Function.toString.call(e).indexOf("[native code]"))return e;if("function"!=typeof e)throw new TypeError("Super expression must either be null or a function");if(void 0!==t){if(t.has(e))return t.get(e);t.set(e,r)}function r(){return k(e,arguments,v(this).constructor)}return r.prototype=Object.create(e.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),T(r,e)})(e)}function A(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function E(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}function g(e,t){var r;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return E(e,void 0);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?E(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[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.")}return(r=e[Symbol.iterator]()).next.bind(r)}var I="setPrototypeOf"in Object,q=function(e){function t(){var r;return(r=e.call(this)||this).isInsufficientReservesError=!0,r.name=r.constructor.name,I&&Object.setPrototypeOf(A(r),(this instanceof t?this.constructor:void 0).prototype),r}return d(t,e),t}(w(Error)),x=function(e){function t(){var r;return(r=e.call(this)||this).isInsufficientInputAmountError=!0,r.name=r.constructor.name,I&&Object.setPrototypeOf(A(r),(this instanceof t?this.constructor:void 0).prototype),r}return d(t,e),t}(w(Error)),b=function(e){var t=e.factoryAddress,r=e.tokenA,n=e.tokenB,c=r.sortsBefore(n)?[r,n]:[n,r];return o.getCreate2Address(t,u.keccak256(["bytes"],[u.pack(["address","address"],[c[0].address,c[1].address])]),i)},O=function(){function e(t,u){t.currency.isToken&&u.currency.isToken||n(!1);var o=t.currency.sortsBefore(u.currency)?[t,u]:[u,t];o[0].currency.isToken&&o[1].currency.isToken||n(!1),this.liquidityToken=new r.Token(o[0].currency.chainId,e.getAddress(o[0].currency,o[1].currency),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=o}e.getAddress=function(e,t){return b({factoryAddress:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",tokenA:e,tokenB:t})};var u=e.prototype;return u.involvesToken=function(e){return e.equals(this.token0)||e.equals(this.token1)},u.priceOf=function(e){return this.involvesToken(e)||n(!1),e.equals(this.token0)?this.token0Price:this.token1Price},u.reserveOf=function(e){return this.involvesToken(e)||n(!1),e.equals(this.token0)?this.reserve0:this.reserve1},u.getOutputAmount=function(u){if(u.currency.isToken&&this.involvesToken(u.currency)||n(!1),t.equal(this.reserve0.raw,s)||t.equal(this.reserve1.raw,s))throw new q;var o=this.reserveOf(u.currency),i=this.reserveOf(u.currency.equals(this.token0)?this.token1:this.token0),c=t.multiply(u.raw,p),a=t.multiply(c,i.raw),l=t.add(t.multiply(o.raw,h),c),y=new r.CurrencyAmount(u.currency.equals(this.token0)?this.token1:this.token0,t.divide(a,l));if(t.equal(y.raw,s))throw new x;return[y,new e(o.add(u),i.subtract(y))]},u.getInputAmount=function(u){if(u.currency.isToken&&this.involvesToken(u.currency)||n(!1),t.equal(this.reserve0.raw,s)||t.equal(this.reserve1.raw,s)||t.greaterThanOrEqual(u.raw,this.reserveOf(u.currency).raw))throw new q;var o=this.reserveOf(u.currency),i=this.reserveOf(u.currency.equals(this.token0)?this.token1:this.token0),c=t.multiply(t.multiply(i.raw,u.raw),h),l=t.multiply(t.subtract(o.raw,u.raw),p),y=new r.CurrencyAmount(u.currency.equals(this.token0)?this.token1:this.token0,t.add(t.divide(c,l),a));return[y,new e(i.add(y),o.subtract(u))]},u.getLiquidityMinted=function(e,u,o){e.currency.isToken&&e.currency.equals(this.liquidityToken)||n(!1);var i,a=u.currency.isToken&&o.currency.isToken&&u.currency.sortsBefore(o.currency)?[u,o]:[o,u];if(a[0].currency.isToken&&a[1].currency.isToken||n(!1),a[0].currency.equals(this.token0)&&a[1].currency.equals(this.token1)||n(!1),t.equal(e.raw,s))i=t.subtract(r.sqrt(t.multiply(a[0].raw,a[1].raw)),c);else{var l=t.divide(t.multiply(a[0].raw,e.raw),this.reserve0.raw),p=t.divide(t.multiply(a[1].raw,e.raw),this.reserve1.raw);i=t.lessThanOrEqual(l,p)?l:p}if(!t.greaterThan(i,s))throw new x;return new r.CurrencyAmount(this.liquidityToken,i)},u.getLiquidityValue=function(e,u,o,i,c){var a;if(void 0===i&&(i=!1),this.involvesToken(e)||n(!1),u.currency.isToken&&u.currency.equals(this.liquidityToken)||n(!1),o.currency.isToken&&o.currency.equals(this.liquidityToken)||n(!1),t.lessThanOrEqual(o.raw,u.raw)||n(!1),i){c||n(!1);var p=t.BigInt(c);if(t.equal(p,s))a=u;else{var h=r.sqrt(t.multiply(this.reserve0.raw,this.reserve1.raw)),y=r.sqrt(p);if(t.greaterThan(h,y)){var f=t.multiply(u.raw,t.subtract(h,y)),d=t.add(t.multiply(h,l),y),v=t.divide(f,d);a=u.add(new r.CurrencyAmount(this.liquidityToken,v))}else a=u}}else a=u;return new r.CurrencyAmount(e,t.divide(t.multiply(o.raw,this.reserveOf(e).raw),a.raw))},f(e,[{key:"token0Price",get:function(){return new r.Price(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new r.Price(this.token1,this.token0,this.tokenAmounts[1].raw,this.tokenAmounts[0].raw)}},{key:"chainId",get:function(){return this.token0.chainId}},{key:"token0",get:function(){return this.tokenAmounts[0].currency.isToken||n(!1),this.tokenAmounts[0].currency}},{key:"token1",get:function(){return this.tokenAmounts[1].currency.isToken||n(!1),this.tokenAmounts[1].currency}},{key:"reserve0",get:function(){return this.tokenAmounts[0]}},{key:"reserve1",get:function(){return this.tokenAmounts[1]}}]),e}(),P=function(){function e(e,t,u){e.length>0||n(!1);var o=e[0].chainId;e.every((function(e){return e.chainId===o}))||n(!1);var i=r.WETH9[o];t.isToken&&e[0].involvesToken(t)||t===r.ETHER&&i&&e[0].involvesToken(i)||n(!1),(null==u?void 0:u.isToken)&&e[e.length-1].involvesToken(u)||u===r.ETHER&&i&&e[e.length-1].involvesToken(i)||n(!1);for(var c,s=[t.isToken?t:i],a=g(e.entries());!(c=a()).done;){var l=c.value,p=l[1],h=s[l[0]];h.equals(p.token0)||h.equals(p.token1)||n(!1);var y=h.equals(p.token0)?p.token1:p.token0;s.push(y)}this.pairs=e,this.path=s,this.input=t,this.output=null!=u?u:s[s.length-1]}return f(e,[{key:"midPrice",get:function(){for(var e,t=[],n=g(this.pairs.entries());!(e=n()).done;){var u=e.value,o=u[1];t.push(this.path[u[0]].equals(o.token0)?new r.Price(o.reserve0.currency,o.reserve1.currency,o.reserve0.raw,o.reserve1.raw):new r.Price(o.reserve1.currency,o.reserve0.currency,o.reserve1.raw,o.reserve0.raw))}return t.slice(1).reduce((function(e,t){return e.multiply(t)}),t[0])}},{key:"chainId",get:function(){return this.pairs[0].chainId}}]),e}();function C(e,t){return r.currencyEquals(e.inputAmount.currency,t.inputAmount.currency)||n(!1),r.currencyEquals(e.outputAmount.currency,t.outputAmount.currency)||n(!1),e.outputAmount.equalTo(t.outputAmount)?e.inputAmount.equalTo(t.inputAmount)?0:e.inputAmount.lessThan(t.inputAmount)?-1:1:e.outputAmount.lessThan(t.outputAmount)?1:-1}function _(e,t){var r=C(e,t);return 0!==r?r:e.priceImpact.lessThan(t.priceImpact)?-1:e.priceImpact.greaterThan(t.priceImpact)?1:e.route.path.length-t.route.path.length}function R(e,t){if(e.currency.isToken)return e;if(e.currency.isEther)return new r.CurrencyAmount(r.WETH9[t],e.raw);throw new Error("CURRENCY")}function U(e,t){if(e.isToken)return e;if(e===r.ETHER)return r.WETH9[t];throw new Error("CURRENCY")}var H=function(){function e(e,t,u){var o,i,c,s=new Array(e.path.length),a=new Array(e.pairs.length);if(u===r.TradeType.EXACT_INPUT){r.currencyEquals(t.currency,e.input)||n(!1),s[0]=R(t,e.chainId);for(var l=0;l<e.path.length-1;l++){var p=e.pairs[l].getOutputAmount(s[l]),h=p[1];s[l+1]=p[0],a[l]=h}}else{r.currencyEquals(t.currency,e.output)||n(!1),s[s.length-1]=R(t,e.chainId);for(var y=e.path.length-1;y>0;y--){var f=e.pairs[y-1].getInputAmount(s[y]),d=f[1];s[y-1]=f[0],a[y-1]=d}}this.route=e,this.tradeType=u,this.inputAmount=u===r.TradeType.EXACT_INPUT?t:e.input===r.ETHER?r.CurrencyAmount.ether(s[0].raw):s[0],this.outputAmount=u===r.TradeType.EXACT_OUTPUT?t:e.output===r.ETHER?r.CurrencyAmount.ether(s[s.length-1].raw):s[s.length-1],this.executionPrice=new r.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=new P(a,e.input).midPrice,this.priceImpact=(o=this.outputAmount,c=(i=e.midPrice.raw.multiply(this.inputAmount.raw)).subtract(o.raw).divide(i),new r.Percent(c.numerator,c.denominator))}e.exactIn=function(t,n){return new e(t,n,r.TradeType.EXACT_INPUT)},e.exactOut=function(t,n){return new e(t,n,r.TradeType.EXACT_OUTPUT)};var t=e.prototype;return t.minimumAmountOut=function(e){if(e.lessThan(s)&&n(!1),this.tradeType===r.TradeType.EXACT_OUTPUT)return this.outputAmount;var t=new r.Fraction(a).add(e).invert().multiply(this.outputAmount.raw).quotient;return new r.CurrencyAmount(this.outputAmount.currency,t)},t.maximumAmountIn=function(e){if(e.lessThan(s)&&n(!1),this.tradeType===r.TradeType.EXACT_INPUT)return this.inputAmount;var t=new r.Fraction(a).add(e).multiply(this.inputAmount.raw).quotient;return new r.CurrencyAmount(this.inputAmount.currency,t)},e.bestTradeExactIn=function(t,u,o,i,c,a,l){var p=void 0===i?{}:i,h=p.maxNumResults,y=void 0===h?3:h,f=p.maxHops,d=void 0===f?3:f;void 0===c&&(c=[]),void 0===a&&(a=u),void 0===l&&(l=[]),t.length>0||n(!1),d>0||n(!1),a===u||c.length>0||n(!1);var v=u.currency.isToken?u.currency.chainId:o.isToken?o.chainId:void 0;void 0===v&&n(!1);for(var T=R(u,v),m=U(o,v),k=0;k<t.length;k++){var w=t[k];if((r.currencyEquals(w.token0,T.currency)||r.currencyEquals(w.token1,T.currency))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getOutputAmount(T)[0]}catch(e){if(e.isInsufficientInputAmountError)continue;throw e}if(r.currencyEquals(A.currency,m))r.sortedInsert(l,new e(new P([].concat(c,[w]),a.currency,o),a,r.TradeType.EXACT_INPUT),y,_);else if(d>1&&t.length>1){var E=t.slice(0,k).concat(t.slice(k+1,t.length));e.bestTradeExactIn(E,A,o,{maxNumResults:y,maxHops:d-1},[].concat(c,[w]),a,l)}}}return l},t.worstExecutionPrice=function(e){return new r.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(e).raw,this.minimumAmountOut(e).raw)},e.bestTradeExactOut=function(t,u,o,i,c,a,l){var p=void 0===i?{}:i,h=p.maxNumResults,y=void 0===h?3:h,f=p.maxHops,d=void 0===f?3:f;void 0===c&&(c=[]),void 0===a&&(a=o),void 0===l&&(l=[]),t.length>0||n(!1),d>0||n(!1),a===o||c.length>0||n(!1);var v=o.currency.isToken?o.currency.chainId:u.isToken?u.chainId:void 0;void 0===v&&n(!1);for(var T=R(o,v),m=U(u,v),k=0;k<t.length;k++){var w=t[k];if((r.currencyEquals(w.token0,T.currency)||r.currencyEquals(w.token1,T.currency))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getInputAmount(T)[0]}catch(e){if(e.isInsufficientReservesError)continue;throw e}if(r.currencyEquals(A.currency,m))r.sortedInsert(l,new e(new P([w].concat(c),u,a.currency),a,r.TradeType.EXACT_OUTPUT),y,_);else if(d>1&&t.length>1){var E=t.slice(0,k).concat(t.slice(k+1,t.length));e.bestTradeExactOut(E,u,A,{maxNumResults:y,maxHops:d-1},[w].concat(c),a,l)}}}return l},e}();function S(e){return"0x"+e.raw.toString(16)}var B=function(){function e(){}return e.swapCallParameters=function(e,t){var u=e.inputAmount.currency===r.ETHER,o=e.outputAmount.currency===r.ETHER;u&&o&&n(!1),!("ttl"in t)||t.ttl>0||n(!1);var i,c,s,a=r.validateAndParseAddress(t.recipient),l=S(e.maximumAmountIn(t.allowedSlippage)),p=S(e.minimumAmountOut(t.allowedSlippage)),h=e.route.path.map((function(e){return e.address})),y="ttl"in t?"0x"+(Math.floor((new Date).getTime()/1e3)+t.ttl).toString(16):"0x"+t.deadline.toString(16),f=Boolean(t.feeOnTransfer);switch(e.tradeType){case r.TradeType.EXACT_INPUT:u?(i=f?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",c=[p,h,a,y],s=l):o?(i=f?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",c=[l,p,h,a,y],s="0x0"):(i=f?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",c=[l,p,h,a,y],s="0x0");break;case r.TradeType.EXACT_OUTPUT:f&&n(!1),u?(i="swapETHForExactTokens",c=[p,h,a,y],s=l):o?(i="swapTokensForExactETH",c=[p,l,h,a,y],s="0x0"):(i="swapTokensForExactTokens",c=[p,l,h,a,y],s="0x0")}return{methodName:i,args:c,value:s}},e}();exports.JSBI=t,exports.FACTORY_ADDRESS="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.INIT_CODE_HASH=i,exports.InsufficientInputAmountError=x,exports.InsufficientReservesError=q,exports.MINIMUM_LIQUIDITY=c,exports.Pair=O,exports.Route=P,exports.Router=B,exports.Trade=H,exports.computePairAddress=b,exports.inputOutputComparator=C,exports.tradeComparator=_;
//# sourceMappingURL=v2-sdk.cjs.production.min.js.map

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

!(input.isToken && pairs[0].involvesToken(input) || input === ETHER && weth && pairs[0].involvesToken(weth)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INPUT') : invariant(false) : void 0;
!(typeof output === 'undefined' || output.isToken && pairs[pairs.length - 1].involvesToken(output) || output === ETHER && weth && pairs[pairs.length - 1].involvesToken(weth)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
!((output == null ? void 0 : output.isToken) && pairs[pairs.length - 1].involvesToken(output) || output === ETHER && weth && pairs[pairs.length - 1].involvesToken(weth)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'OUTPUT') : invariant(false) : void 0;
var path = [input.isToken ? input : weth];

@@ -434,0 +434,0 @@

{
"name": "@uniswap/v2-sdk",
"license": "MIT",
"version": "2.0.0",
"version": "2.0.1",
"description": "🛠 An SDK for building applications on top of Uniswap V2",

@@ -6,0 +6,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