@uniswap/v2-sdk
Advanced tools
Comparing version 1.0.8 to 1.0.9
@@ -86,2 +86,7 @@ import { Currency, CurrencyAmount, Percent, Price, TradeType } from '@uniswap/sdk-core'; | ||
/** | ||
* Return the execution price after accounting for slippage tolerance | ||
* @param slippageTolerance the allowed tolerated slippage | ||
*/ | ||
worstExecutionPrice(slippageTolerance: Percent): Price; | ||
/** | ||
* similar to the above method but instead targets a fixed output amount | ||
@@ -88,0 +93,0 @@ * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token |
@@ -739,2 +739,11 @@ 'use strict'; | ||
/** | ||
* Return the execution price after accounting for slippage tolerance | ||
* @param slippageTolerance the allowed tolerated slippage | ||
*/ | ||
; | ||
_proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) { | ||
return new sdkCore.Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).raw, this.minimumAmountOut(slippageTolerance).raw); | ||
} | ||
/** | ||
* similar to the above method but instead targets a fixed output amount | ||
@@ -741,0 +750,0 @@ * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token |
@@ -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")),n=require("@uniswap/sdk-core"),r=e(require("tiny-invariant")),o=require("@ethersproject/solidity"),i=require("@ethersproject/address"),u="0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",a=t.BigInt(1e3),s=t.BigInt(0),c=t.BigInt(1),l=t.BigInt(5),p=t.BigInt(997),f=t.BigInt(1e3);function h(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function d(e,t,n){return t&&h(e.prototype,t),n&&h(e,n),e}function v(e,t){e.prototype=Object.create(t.prototype),e.prototype.constructor=e,e.__proto__=t}function T(e){return(T=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function k(e,t){return(k=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 y(e,t,n){return(y=m()?Reflect.construct:function(e,t,n){var r=[null];r.push.apply(r,t);var o=new(Function.bind.apply(e,r));return n&&k(o,n.prototype),o}).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,n)}function n(){return y(e,arguments,T(this).constructor)}return n.prototype=Object.create(e.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),k(n,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 g(e,t){(null==t||t>e.length)&&(t=e.length);for(var n=0,r=new Array(t);n<t;n++)r[n]=e[n];return r}function E(e,t){var n;if("undefined"==typeof Symbol||null==e[Symbol.iterator]){if(Array.isArray(e)||(n=function(e,t){if(e){if("string"==typeof e)return g(e,void 0);var n=Object.prototype.toString.call(e).slice(8,-1);return"Object"===n&&e.constructor&&(n=e.constructor.name),"Map"===n||"Set"===n?Array.from(e):"Arguments"===n||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)?g(e,void 0):void 0}}(e))||t&&e&&"number"==typeof e.length){n&&(e=n);var r=0;return function(){return r>=e.length?{done:!0}:{done:!1,value:e[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=e[Symbol.iterator]()).next.bind(n)}var I="setPrototypeOf"in Object,q=function(e){function t(){var n;return(n=e.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,I&&Object.setPrototypeOf(A(n),(this instanceof t?this.constructor:void 0).prototype),n}return v(t,e),t}(w(Error)),x=function(e){function t(){var n;return(n=e.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,I&&Object.setPrototypeOf(A(n),(this instanceof t?this.constructor:void 0).prototype),n}return v(t,e),t}(w(Error)),b=function(e){var t=e.factoryAddress,n=e.tokenA,r=e.tokenB,a=n.sortsBefore(r)?[n,r]:[r,n];return i.getCreate2Address(t,o.keccak256(["bytes"],[o.pack(["address","address"],[a[0].address,a[1].address])]),u)},O=function(){function e(t,r){var o=t.token.sortsBefore(r.token)?[t,r]:[r,t];this.liquidityToken=new n.Token(o[0].token.chainId,e.getAddress(o[0].token,o[1].token),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=o}e.getAddress=function(e,t){return b({factoryAddress:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",tokenA:e,tokenB:t})};var o=e.prototype;return o.involvesToken=function(e){return e.equals(this.token0)||e.equals(this.token1)},o.priceOf=function(e){return this.involvesToken(e)||r(!1),e.equals(this.token0)?this.token0Price:this.token1Price},o.reserveOf=function(e){return this.involvesToken(e)||r(!1),e.equals(this.token0)?this.reserve0:this.reserve1},o.getOutputAmount=function(o){if(this.involvesToken(o.token)||r(!1),t.equal(this.reserve0.raw,s)||t.equal(this.reserve1.raw,s))throw new q;var i=this.reserveOf(o.token),u=this.reserveOf(o.token.equals(this.token0)?this.token1:this.token0),a=t.multiply(o.raw,p),c=t.multiply(a,u.raw),l=t.add(t.multiply(i.raw,f),a),h=new n.TokenAmount(o.token.equals(this.token0)?this.token1:this.token0,t.divide(c,l));if(t.equal(h.raw,s))throw new x;return[h,new e(i.add(o),u.subtract(h))]},o.getInputAmount=function(o){if(this.involvesToken(o.token)||r(!1),t.equal(this.reserve0.raw,s)||t.equal(this.reserve1.raw,s)||t.greaterThanOrEqual(o.raw,this.reserveOf(o.token).raw))throw new q;var i=this.reserveOf(o.token),u=this.reserveOf(o.token.equals(this.token0)?this.token1:this.token0),a=t.multiply(t.multiply(u.raw,o.raw),f),l=t.multiply(t.subtract(i.raw,o.raw),p),h=new n.TokenAmount(o.token.equals(this.token0)?this.token1:this.token0,t.add(t.divide(a,l),c));return[h,new e(u.add(h),i.subtract(o))]},o.getLiquidityMinted=function(e,o,i){e.token.equals(this.liquidityToken)||r(!1);var u,c=o.token.sortsBefore(i.token)?[o,i]:[i,o];if(c[0].token.equals(this.token0)&&c[1].token.equals(this.token1)||r(!1),t.equal(e.raw,s))u=t.subtract(n.sqrt(t.multiply(c[0].raw,c[1].raw)),a);else{var l=t.divide(t.multiply(c[0].raw,e.raw),this.reserve0.raw),p=t.divide(t.multiply(c[1].raw,e.raw),this.reserve1.raw);u=t.lessThanOrEqual(l,p)?l:p}if(!t.greaterThan(u,s))throw new x;return new n.TokenAmount(this.liquidityToken,u)},o.getLiquidityValue=function(e,o,i,u,a){var c;if(void 0===u&&(u=!1),this.involvesToken(e)||r(!1),o.token.equals(this.liquidityToken)||r(!1),i.token.equals(this.liquidityToken)||r(!1),t.lessThanOrEqual(i.raw,o.raw)||r(!1),u){a||r(!1);var p=t.BigInt(a);if(t.equal(p,s))c=o;else{var f=n.sqrt(t.multiply(this.reserve0.raw,this.reserve1.raw)),h=n.sqrt(p);if(t.greaterThan(f,h)){var d=t.multiply(o.raw,t.subtract(f,h)),v=t.add(t.multiply(f,l),h),T=t.divide(d,v);c=o.add(new n.TokenAmount(this.liquidityToken,T))}else c=o}}else c=o;return new n.TokenAmount(e,t.divide(t.multiply(i.raw,this.reserveOf(e).raw),c.raw))},d(e,[{key:"token0Price",get:function(){return new n.Price(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new n.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].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]}}]),e}(),P=function(){function e(e,t,o){e.length>0||r(!1);var i=e[0].chainId;e.every((function(e){return e.chainId===i}))||r(!1);var u=n.WETH9[i];t instanceof n.Token&&e[0].involvesToken(t)||t===n.ETHER&&u&&e[0].involvesToken(u)||r(!1),void 0===o||o instanceof n.Token&&e[e.length-1].involvesToken(o)||o===n.ETHER&&u&&e[e.length-1].involvesToken(u)||r(!1);for(var a,s=[t instanceof n.Token?t:u],c=E(e.entries());!(a=c()).done;){var l=a.value,p=l[1],f=s[l[0]];f.equals(p.token0)||f.equals(p.token1)||r(!1);var h=f.equals(p.token0)?p.token1:p.token0;s.push(h)}this.pairs=e,this.path=s,this.input=t,this.output=null!=o?o:s[s.length-1]}return d(e,[{key:"midPrice",get:function(){for(var e,t=[],r=E(this.pairs.entries());!(e=r()).done;){var o=e.value,i=o[1];t.push(this.path[o[0]].equals(i.token0)?new n.Price(i.reserve0.currency,i.reserve1.currency,i.reserve0.raw,i.reserve1.raw):new n.Price(i.reserve1.currency,i.reserve0.currency,i.reserve1.raw,i.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 _(e,t){return n.currencyEquals(e.inputAmount.currency,t.inputAmount.currency)||r(!1),n.currencyEquals(e.outputAmount.currency,t.outputAmount.currency)||r(!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 C(e,t){var n=_(e,t);return 0!==n?n:e.priceImpact.lessThan(t.priceImpact)?-1:e.priceImpact.greaterThan(t.priceImpact)?1:e.route.path.length-t.route.path.length}function R(e,t){return e instanceof n.TokenAmount?e:e.currency===n.ETHER?new n.TokenAmount(n.WETH9[t],e.raw):void r(!1)}function H(e,t){return e instanceof n.Token?e:e===n.ETHER?n.WETH9[t]:void r(!1)}var S=function(){function e(e,t,o){var i,u,a,s=new Array(e.path.length),c=new Array(e.pairs.length);if(o===n.TradeType.EXACT_INPUT){n.currencyEquals(t.currency,e.input)||r(!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]),f=p[1];s[l+1]=p[0],c[l]=f}}else{n.currencyEquals(t.currency,e.output)||r(!1),s[s.length-1]=R(t,e.chainId);for(var h=e.path.length-1;h>0;h--){var d=e.pairs[h-1].getInputAmount(s[h]),v=d[1];s[h-1]=d[0],c[h-1]=v}}this.route=e,this.tradeType=o,this.inputAmount=o===n.TradeType.EXACT_INPUT?t:e.input===n.ETHER?n.CurrencyAmount.ether(s[0].raw):s[0],this.outputAmount=o===n.TradeType.EXACT_OUTPUT?t:e.output===n.ETHER?n.CurrencyAmount.ether(s[s.length-1].raw):s[s.length-1],this.executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=new P(c,e.input).midPrice,this.priceImpact=(i=this.outputAmount,a=(u=e.midPrice.raw.multiply(this.inputAmount.raw)).subtract(i.raw).divide(u),new n.Percent(a.numerator,a.denominator))}e.exactIn=function(t,r){return new e(t,r,n.TradeType.EXACT_INPUT)},e.exactOut=function(t,r){return new e(t,r,n.TradeType.EXACT_OUTPUT)};var t=e.prototype;return t.minimumAmountOut=function(e){if(e.lessThan(s)&&r(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return this.outputAmount;var t=new n.Fraction(c).add(e).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof n.TokenAmount?new n.TokenAmount(this.outputAmount.token,t):n.CurrencyAmount.ether(t)},t.maximumAmountIn=function(e){if(e.lessThan(s)&&r(!1),this.tradeType===n.TradeType.EXACT_INPUT)return this.inputAmount;var t=new n.Fraction(c).add(e).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof n.TokenAmount?new n.TokenAmount(this.inputAmount.token,t):n.CurrencyAmount.ether(t)},e.bestTradeExactIn=function(t,o,i,u,a,c,l){var p=void 0===u?{}:u,f=p.maxNumResults,h=void 0===f?3:f,d=p.maxHops,v=void 0===d?3:d;void 0===a&&(a=[]),void 0===c&&(c=o),void 0===l&&(l=[]),t.length>0||r(!1),v>0||r(!1),c===o||a.length>0||r(!1);var T=o instanceof n.TokenAmount?o.token.chainId:i instanceof n.Token?i.chainId:void 0;void 0===T&&r(!1);for(var k=R(o,T),m=H(i,T),y=0;y<t.length;y++){var w=t[y];if((w.token0.equals(k.token)||w.token1.equals(k.token))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getOutputAmount(k)[0]}catch(e){if(e.isInsufficientInputAmountError)continue;throw e}if(A.token.equals(m))n.sortedInsert(l,new e(new P([].concat(a,[w]),c.currency,i),c,n.TradeType.EXACT_INPUT),h,C);else if(v>1&&t.length>1){var g=t.slice(0,y).concat(t.slice(y+1,t.length));e.bestTradeExactIn(g,A,i,{maxNumResults:h,maxHops:v-1},[].concat(a,[w]),c,l)}}}return l},e.bestTradeExactOut=function(t,o,i,u,a,c,l){var p=void 0===u?{}:u,f=p.maxNumResults,h=void 0===f?3:f,d=p.maxHops,v=void 0===d?3:d;void 0===a&&(a=[]),void 0===c&&(c=i),void 0===l&&(l=[]),t.length>0||r(!1),v>0||r(!1),c===i||a.length>0||r(!1);var T=i instanceof n.TokenAmount?i.token.chainId:o instanceof n.Token?o.chainId:void 0;void 0===T&&r(!1);for(var k=R(i,T),m=H(o,T),y=0;y<t.length;y++){var w=t[y];if((w.token0.equals(k.token)||w.token1.equals(k.token))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getInputAmount(k)[0]}catch(e){if(e.isInsufficientReservesError)continue;throw e}if(A.token.equals(m))n.sortedInsert(l,new e(new P([w].concat(a),o,c.currency),c,n.TradeType.EXACT_OUTPUT),h,C);else if(v>1&&t.length>1){var g=t.slice(0,y).concat(t.slice(y+1,t.length));e.bestTradeExactOut(g,o,A,{maxNumResults:h,maxHops:v-1},[w].concat(a),c,l)}}}return l},e}();function U(e){return"0x"+e.raw.toString(16)}var B=function(){function e(){}return e.swapCallParameters=function(e,t){var o=e.inputAmount.currency===n.ETHER,i=e.outputAmount.currency===n.ETHER;o&&i&&r(!1),!("ttl"in t)||t.ttl>0||r(!1);var u,a,s,c=n.validateAndParseAddress(t.recipient),l=U(e.maximumAmountIn(t.allowedSlippage)),p=U(e.minimumAmountOut(t.allowedSlippage)),f=e.route.path.map((function(e){return e.address})),h="ttl"in t?"0x"+(Math.floor((new Date).getTime()/1e3)+t.ttl).toString(16):"0x"+t.deadline.toString(16),d=Boolean(t.feeOnTransfer);switch(e.tradeType){case n.TradeType.EXACT_INPUT:o?(u=d?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",a=[p,f,c,h],s=l):i?(u=d?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",a=[l,p,f,c,h],s="0x0"):(u=d?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",a=[l,p,f,c,h],s="0x0");break;case n.TradeType.EXACT_OUTPUT:d&&r(!1),o?(u="swapETHForExactTokens",a=[p,f,c,h],s=l):i?(u="swapTokensForExactETH",a=[p,l,f,c,h],s="0x0"):(u="swapTokensForExactTokens",a=[p,l,f,c,h],s="0x0")}return{methodName:u,args:a,value:s}},e}();exports.JSBI=t,exports.FACTORY_ADDRESS="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.INIT_CODE_HASH=u,exports.InsufficientInputAmountError=x,exports.InsufficientReservesError=q,exports.MINIMUM_LIQUIDITY=a,exports.Pair=O,exports.Route=P,exports.Router=B,exports.Trade=S,exports.computePairAddress=b,exports.inputOutputComparator=_,exports.tradeComparator=C; | ||
"use strict";function t(t){return t&&"object"==typeof t&&"default"in t?t.default:t}Object.defineProperty(exports,"__esModule",{value:!0});var e=t(require("jsbi")),n=require("@uniswap/sdk-core"),r=t(require("tiny-invariant")),o=require("@ethersproject/solidity"),i=require("@ethersproject/address"),u="0x96e8ac4277198ff8b6f785478aa9a39f403cb768dd02cbee326c3e7da348845f",a=e.BigInt(1e3),s=e.BigInt(0),c=e.BigInt(1),l=e.BigInt(5),p=e.BigInt(997),h=e.BigInt(1e3);function f(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&&f(t.prototype,e),n&&f(t,n),t}function v(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function m(t){return(m=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function T(t,e){return(T=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function k(){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 y(t,e,n){return(y=k()?Reflect.construct:function(t,e,n){var r=[null];r.push.apply(r,e);var o=new(Function.bind.apply(t,r));return n&&T(o,n.prototype),o}).apply(null,arguments)}function w(t){var e="function"==typeof Map?new Map:void 0;return(w=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 y(t,arguments,m(this).constructor)}return n.prototype=Object.create(t.prototype,{constructor:{value:n,enumerable:!1,writable:!0,configurable:!0}}),T(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 g(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 E(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 g(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)?g(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)}var I="setPrototypeOf"in Object,q=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientReservesError=!0,n.name=n.constructor.name,I&&Object.setPrototypeOf(A(n),(this instanceof e?this.constructor:void 0).prototype),n}return v(e,t),e}(w(Error)),x=function(t){function e(){var n;return(n=t.call(this)||this).isInsufficientInputAmountError=!0,n.name=n.constructor.name,I&&Object.setPrototypeOf(A(n),(this instanceof e?this.constructor:void 0).prototype),n}return v(e,t),e}(w(Error)),b=function(t){var e=t.factoryAddress,n=t.tokenA,r=t.tokenB,a=n.sortsBefore(r)?[n,r]:[r,n];return i.getCreate2Address(e,o.keccak256(["bytes"],[o.pack(["address","address"],[a[0].address,a[1].address])]),u)},O=function(){function t(e,r){var o=e.token.sortsBefore(r.token)?[e,r]:[r,e];this.liquidityToken=new n.Token(o[0].token.chainId,t.getAddress(o[0].token,o[1].token),18,"UNI-V2","Uniswap V2"),this.tokenAmounts=o}t.getAddress=function(t,e){return b({factoryAddress:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",tokenA:t,tokenB:e})};var o=t.prototype;return o.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},o.priceOf=function(t){return this.involvesToken(t)||r(!1),t.equals(this.token0)?this.token0Price:this.token1Price},o.reserveOf=function(t){return this.involvesToken(t)||r(!1),t.equals(this.token0)?this.reserve0:this.reserve1},o.getOutputAmount=function(o){if(this.involvesToken(o.token)||r(!1),e.equal(this.reserve0.raw,s)||e.equal(this.reserve1.raw,s))throw new q;var i=this.reserveOf(o.token),u=this.reserveOf(o.token.equals(this.token0)?this.token1:this.token0),a=e.multiply(o.raw,p),c=e.multiply(a,u.raw),l=e.add(e.multiply(i.raw,h),a),f=new n.TokenAmount(o.token.equals(this.token0)?this.token1:this.token0,e.divide(c,l));if(e.equal(f.raw,s))throw new x;return[f,new t(i.add(o),u.subtract(f))]},o.getInputAmount=function(o){if(this.involvesToken(o.token)||r(!1),e.equal(this.reserve0.raw,s)||e.equal(this.reserve1.raw,s)||e.greaterThanOrEqual(o.raw,this.reserveOf(o.token).raw))throw new q;var i=this.reserveOf(o.token),u=this.reserveOf(o.token.equals(this.token0)?this.token1:this.token0),a=e.multiply(e.multiply(u.raw,o.raw),h),l=e.multiply(e.subtract(i.raw,o.raw),p),f=new n.TokenAmount(o.token.equals(this.token0)?this.token1:this.token0,e.add(e.divide(a,l),c));return[f,new t(u.add(f),i.subtract(o))]},o.getLiquidityMinted=function(t,o,i){t.token.equals(this.liquidityToken)||r(!1);var u,c=o.token.sortsBefore(i.token)?[o,i]:[i,o];if(c[0].token.equals(this.token0)&&c[1].token.equals(this.token1)||r(!1),e.equal(t.raw,s))u=e.subtract(n.sqrt(e.multiply(c[0].raw,c[1].raw)),a);else{var l=e.divide(e.multiply(c[0].raw,t.raw),this.reserve0.raw),p=e.divide(e.multiply(c[1].raw,t.raw),this.reserve1.raw);u=e.lessThanOrEqual(l,p)?l:p}if(!e.greaterThan(u,s))throw new x;return new n.TokenAmount(this.liquidityToken,u)},o.getLiquidityValue=function(t,o,i,u,a){var c;if(void 0===u&&(u=!1),this.involvesToken(t)||r(!1),o.token.equals(this.liquidityToken)||r(!1),i.token.equals(this.liquidityToken)||r(!1),e.lessThanOrEqual(i.raw,o.raw)||r(!1),u){a||r(!1);var p=e.BigInt(a);if(e.equal(p,s))c=o;else{var h=n.sqrt(e.multiply(this.reserve0.raw,this.reserve1.raw)),f=n.sqrt(p);if(e.greaterThan(h,f)){var d=e.multiply(o.raw,e.subtract(h,f)),v=e.add(e.multiply(h,l),f),m=e.divide(d,v);c=o.add(new n.TokenAmount(this.liquidityToken,m))}else c=o}}else c=o;return new n.TokenAmount(t,e.divide(e.multiply(i.raw,this.reserveOf(t).raw),c.raw))},d(t,[{key:"token0Price",get:function(){return new n.Price(this.token0,this.token1,this.tokenAmounts[0].raw,this.tokenAmounts[1].raw)}},{key:"token1Price",get:function(){return new n.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].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,o){t.length>0||r(!1);var i=t[0].chainId;t.every((function(t){return t.chainId===i}))||r(!1);var u=n.WETH9[i];e instanceof n.Token&&t[0].involvesToken(e)||e===n.ETHER&&u&&t[0].involvesToken(u)||r(!1),void 0===o||o instanceof n.Token&&t[t.length-1].involvesToken(o)||o===n.ETHER&&u&&t[t.length-1].involvesToken(u)||r(!1);for(var a,s=[e instanceof n.Token?e:u],c=E(t.entries());!(a=c()).done;){var l=a.value,p=l[1],h=s[l[0]];h.equals(p.token0)||h.equals(p.token1)||r(!1);var f=h.equals(p.token0)?p.token1:p.token0;s.push(f)}this.pairs=t,this.path=s,this.input=e,this.output=null!=o?o:s[s.length-1]}return d(t,[{key:"midPrice",get:function(){for(var t,e=[],r=E(this.pairs.entries());!(t=r()).done;){var o=t.value,i=o[1];e.push(this.path[o[0]].equals(i.token0)?new n.Price(i.reserve0.currency,i.reserve1.currency,i.reserve0.raw,i.reserve1.raw):new n.Price(i.reserve1.currency,i.reserve0.currency,i.reserve1.raw,i.reserve0.raw))}return e.slice(1).reduce((function(t,e){return t.multiply(e)}),e[0])}},{key:"chainId",get:function(){return this.pairs[0].chainId}}]),t}();function _(t,e){return n.currencyEquals(t.inputAmount.currency,e.inputAmount.currency)||r(!1),n.currencyEquals(t.outputAmount.currency,e.outputAmount.currency)||r(!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 C(t,e){var n=_(t,e);return 0!==n?n:t.priceImpact.lessThan(e.priceImpact)?-1:t.priceImpact.greaterThan(e.priceImpact)?1:t.route.path.length-e.route.path.length}function R(t,e){return t instanceof n.TokenAmount?t:t.currency===n.ETHER?new n.TokenAmount(n.WETH9[e],t.raw):void r(!1)}function H(t,e){return t instanceof n.Token?t:t===n.ETHER?n.WETH9[e]:void r(!1)}var S=function(){function t(t,e,o){var i,u,a,s=new Array(t.path.length),c=new Array(t.pairs.length);if(o===n.TradeType.EXACT_INPUT){n.currencyEquals(e.currency,t.input)||r(!1),s[0]=R(e,t.chainId);for(var l=0;l<t.path.length-1;l++){var p=t.pairs[l].getOutputAmount(s[l]),h=p[1];s[l+1]=p[0],c[l]=h}}else{n.currencyEquals(e.currency,t.output)||r(!1),s[s.length-1]=R(e,t.chainId);for(var f=t.path.length-1;f>0;f--){var d=t.pairs[f-1].getInputAmount(s[f]),v=d[1];s[f-1]=d[0],c[f-1]=v}}this.route=t,this.tradeType=o,this.inputAmount=o===n.TradeType.EXACT_INPUT?e:t.input===n.ETHER?n.CurrencyAmount.ether(s[0].raw):s[0],this.outputAmount=o===n.TradeType.EXACT_OUTPUT?e:t.output===n.ETHER?n.CurrencyAmount.ether(s[s.length-1].raw):s[s.length-1],this.executionPrice=new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.inputAmount.raw,this.outputAmount.raw),this.nextMidPrice=new P(c,t.input).midPrice,this.priceImpact=(i=this.outputAmount,a=(u=t.midPrice.raw.multiply(this.inputAmount.raw)).subtract(i.raw).divide(u),new n.Percent(a.numerator,a.denominator))}t.exactIn=function(e,r){return new t(e,r,n.TradeType.EXACT_INPUT)},t.exactOut=function(e,r){return new t(e,r,n.TradeType.EXACT_OUTPUT)};var e=t.prototype;return e.minimumAmountOut=function(t){if(t.lessThan(s)&&r(!1),this.tradeType===n.TradeType.EXACT_OUTPUT)return this.outputAmount;var e=new n.Fraction(c).add(t).invert().multiply(this.outputAmount.raw).quotient;return this.outputAmount instanceof n.TokenAmount?new n.TokenAmount(this.outputAmount.token,e):n.CurrencyAmount.ether(e)},e.maximumAmountIn=function(t){if(t.lessThan(s)&&r(!1),this.tradeType===n.TradeType.EXACT_INPUT)return this.inputAmount;var e=new n.Fraction(c).add(t).multiply(this.inputAmount.raw).quotient;return this.inputAmount instanceof n.TokenAmount?new n.TokenAmount(this.inputAmount.token,e):n.CurrencyAmount.ether(e)},t.bestTradeExactIn=function(e,o,i,u,a,c,l){var p=void 0===u?{}:u,h=p.maxNumResults,f=void 0===h?3:h,d=p.maxHops,v=void 0===d?3:d;void 0===a&&(a=[]),void 0===c&&(c=o),void 0===l&&(l=[]),e.length>0||r(!1),v>0||r(!1),c===o||a.length>0||r(!1);var m=o instanceof n.TokenAmount?o.token.chainId:i instanceof n.Token?i.chainId:void 0;void 0===m&&r(!1);for(var T=R(o,m),k=H(i,m),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(T.token)||w.token1.equals(T.token))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getOutputAmount(T)[0]}catch(t){if(t.isInsufficientInputAmountError)continue;throw t}if(A.token.equals(k))n.sortedInsert(l,new t(new P([].concat(a,[w]),c.currency,i),c,n.TradeType.EXACT_INPUT),f,C);else if(v>1&&e.length>1){var g=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactIn(g,A,i,{maxNumResults:f,maxHops:v-1},[].concat(a,[w]),c,l)}}}return l},e.worstExecutionPrice=function(t){return new n.Price(this.inputAmount.currency,this.outputAmount.currency,this.maximumAmountIn(t).raw,this.minimumAmountOut(t).raw)},t.bestTradeExactOut=function(e,o,i,u,a,c,l){var p=void 0===u?{}:u,h=p.maxNumResults,f=void 0===h?3:h,d=p.maxHops,v=void 0===d?3:d;void 0===a&&(a=[]),void 0===c&&(c=i),void 0===l&&(l=[]),e.length>0||r(!1),v>0||r(!1),c===i||a.length>0||r(!1);var m=i instanceof n.TokenAmount?i.token.chainId:o instanceof n.Token?o.chainId:void 0;void 0===m&&r(!1);for(var T=R(i,m),k=H(o,m),y=0;y<e.length;y++){var w=e[y];if((w.token0.equals(T.token)||w.token1.equals(T.token))&&!w.reserve0.equalTo(s)&&!w.reserve1.equalTo(s)){var A=void 0;try{A=w.getInputAmount(T)[0]}catch(t){if(t.isInsufficientReservesError)continue;throw t}if(A.token.equals(k))n.sortedInsert(l,new t(new P([w].concat(a),o,c.currency),c,n.TradeType.EXACT_OUTPUT),f,C);else if(v>1&&e.length>1){var g=e.slice(0,y).concat(e.slice(y+1,e.length));t.bestTradeExactOut(g,o,A,{maxNumResults:f,maxHops:v-1},[w].concat(a),c,l)}}}return l},t}();function U(t){return"0x"+t.raw.toString(16)}var B=function(){function t(){}return t.swapCallParameters=function(t,e){var o=t.inputAmount.currency===n.ETHER,i=t.outputAmount.currency===n.ETHER;o&&i&&r(!1),!("ttl"in e)||e.ttl>0||r(!1);var u,a,s,c=n.validateAndParseAddress(e.recipient),l=U(t.maximumAmountIn(e.allowedSlippage)),p=U(t.minimumAmountOut(e.allowedSlippage)),h=t.route.path.map((function(t){return t.address})),f="ttl"in e?"0x"+(Math.floor((new Date).getTime()/1e3)+e.ttl).toString(16):"0x"+e.deadline.toString(16),d=Boolean(e.feeOnTransfer);switch(t.tradeType){case n.TradeType.EXACT_INPUT:o?(u=d?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",a=[p,h,c,f],s=l):i?(u=d?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",a=[l,p,h,c,f],s="0x0"):(u=d?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",a=[l,p,h,c,f],s="0x0");break;case n.TradeType.EXACT_OUTPUT:d&&r(!1),o?(u="swapETHForExactTokens",a=[p,h,c,f],s=l):i?(u="swapTokensForExactETH",a=[p,l,h,c,f],s="0x0"):(u="swapTokensForExactTokens",a=[p,l,h,c,f],s="0x0")}return{methodName:u,args:a,value:s}},t}();exports.JSBI=e,exports.FACTORY_ADDRESS="0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f",exports.INIT_CODE_HASH=u,exports.InsufficientInputAmountError=x,exports.InsufficientReservesError=q,exports.MINIMUM_LIQUIDITY=a,exports.Pair=O,exports.Route=P,exports.Router=B,exports.Trade=S,exports.computePairAddress=b,exports.inputOutputComparator=_,exports.tradeComparator=C; | ||
//# sourceMappingURL=v2-sdk.cjs.production.min.js.map |
@@ -734,2 +734,11 @@ import JSBI from 'jsbi'; | ||
/** | ||
* Return the execution price after accounting for slippage tolerance | ||
* @param slippageTolerance the allowed tolerated slippage | ||
*/ | ||
; | ||
_proto.worstExecutionPrice = function worstExecutionPrice(slippageTolerance) { | ||
return new Price(this.inputAmount.currency, this.outputAmount.currency, this.maximumAmountIn(slippageTolerance).raw, this.minimumAmountOut(slippageTolerance).raw); | ||
} | ||
/** | ||
* similar to the above method but instead targets a fixed output amount | ||
@@ -736,0 +745,0 @@ * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token |
{ | ||
"name": "@uniswap/v2-sdk", | ||
"license": "MIT", | ||
"version": "1.0.8", | ||
"version": "1.0.9", | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
273268
1848