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 1.0.10 to 2.0.0

18

dist/entities/pair.d.ts

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

import { BigintIsh, ChainId, Price, Token, TokenAmount } from '@uniswap/sdk-core';
import { BigintIsh, ChainId, Price, Token, CurrencyAmount } from '@uniswap/sdk-core';
export declare const computePairAddress: ({ factoryAddress, tokenA, tokenB }: {

@@ -11,3 +11,3 @@ factoryAddress: string;

static getAddress(tokenA: Token, tokenB: Token): string;
constructor(tokenAmountA: TokenAmount, tokenAmountB: TokenAmount);
constructor(currencyAmountA: CurrencyAmount, tokenAmountB: CurrencyAmount);
/**

@@ -37,9 +37,9 @@ * Returns true if the token is either token0 or token1

get token1(): Token;
get reserve0(): TokenAmount;
get reserve1(): TokenAmount;
reserveOf(token: Token): TokenAmount;
getOutputAmount(inputAmount: TokenAmount): [TokenAmount, Pair];
getInputAmount(outputAmount: TokenAmount): [TokenAmount, Pair];
getLiquidityMinted(totalSupply: TokenAmount, tokenAmountA: TokenAmount, tokenAmountB: TokenAmount): TokenAmount;
getLiquidityValue(token: Token, totalSupply: TokenAmount, liquidity: TokenAmount, feeOn?: boolean, kLast?: BigintIsh): TokenAmount;
get reserve0(): CurrencyAmount;
get reserve1(): CurrencyAmount;
reserveOf(token: Token): CurrencyAmount;
getOutputAmount(inputAmount: CurrencyAmount): [CurrencyAmount, Pair];
getInputAmount(outputAmount: CurrencyAmount): [CurrencyAmount, Pair];
getLiquidityMinted(totalSupply: CurrencyAmount, tokenAmountA: CurrencyAmount, tokenAmountB: CurrencyAmount): CurrencyAmount;
getLiquidityValue(token: Token, totalSupply: CurrencyAmount, liquidity: CurrencyAmount, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount;
}

@@ -235,6 +235,8 @@ 'use strict';

var Pair = /*#__PURE__*/function () {
function Pair(tokenAmountA, tokenAmountB) {
var tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks
? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
this.liquidityToken = new sdkCore.Token(tokenAmounts[0].token.chainId, Pair.getAddress(tokenAmounts[0].token, tokenAmounts[1].token), 18, 'UNI-V2', 'Uniswap V2');
function Pair(currencyAmountA, tokenAmountB) {
!(currencyAmountA.currency.isToken && tokenAmountB.currency.isToken) ? invariant(false, 'TOKEN') : void 0;
var tokenAmounts = currencyAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks
? [currencyAmountA, tokenAmountB] : [tokenAmountB, currencyAmountA];
!(tokenAmounts[0].currency.isToken && tokenAmounts[1].currency.isToken) ? invariant(false, 'TOKEN') : void 0;
this.liquidityToken = new sdkCore.Token(tokenAmounts[0].currency.chainId, Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency), 18, 'UNI-V2', 'Uniswap V2');
this.tokenAmounts = tokenAmounts;

@@ -285,3 +287,3 @@ }

_proto.getOutputAmount = function getOutputAmount(inputAmount) {
!this.involvesToken(inputAmount.token) ? invariant(false, 'TOKEN') : void 0;
!(inputAmount.currency.isToken && this.involvesToken(inputAmount.currency)) ? invariant(false, 'TOKEN') : void 0;

@@ -292,8 +294,8 @@ if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO)) {

var inputReserve = this.reserveOf(inputAmount.token);
var outputReserve = this.reserveOf(inputAmount.token.equals(this.token0) ? this.token1 : this.token0);
var inputReserve = this.reserveOf(inputAmount.currency);
var outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
var inputAmountWithFee = JSBI.multiply(inputAmount.raw, _997);
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.raw);
var denominator = JSBI.add(JSBI.multiply(inputReserve.raw, _1000), inputAmountWithFee);
var outputAmount = new sdkCore.TokenAmount(inputAmount.token.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator));
var outputAmount = new sdkCore.CurrencyAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator));

@@ -308,13 +310,13 @@ if (JSBI.equal(outputAmount.raw, ZERO)) {

_proto.getInputAmount = function getInputAmount(outputAmount) {
!this.involvesToken(outputAmount.token) ? invariant(false, 'TOKEN') : void 0;
!(outputAmount.currency.isToken && this.involvesToken(outputAmount.currency)) ? invariant(false, 'TOKEN') : void 0;
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO) || JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.token).raw)) {
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO) || JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.currency).raw)) {
throw new InsufficientReservesError();
}
var outputReserve = this.reserveOf(outputAmount.token);
var inputReserve = this.reserveOf(outputAmount.token.equals(this.token0) ? this.token1 : this.token0);
var outputReserve = this.reserveOf(outputAmount.currency);
var inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.raw, outputAmount.raw), _1000);
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.raw, outputAmount.raw), _997);
var inputAmount = new sdkCore.TokenAmount(outputAmount.token.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE));
var inputAmount = new sdkCore.CurrencyAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE));
return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];

@@ -324,6 +326,7 @@ };

_proto.getLiquidityMinted = function getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) {
!totalSupply.token.equals(this.liquidityToken) ? invariant(false, 'LIQUIDITY') : void 0;
var tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks
!(totalSupply.currency.isToken && totalSupply.currency.equals(this.liquidityToken)) ? invariant(false, 'LIQUIDITY') : void 0;
var tokenAmounts = tokenAmountA.currency.isToken && tokenAmountB.currency.isToken && tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks
? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
!(tokenAmounts[0].token.equals(this.token0) && tokenAmounts[1].token.equals(this.token1)) ? invariant(false, 'TOKEN') : void 0;
!(tokenAmounts[0].currency.isToken && tokenAmounts[1].currency.isToken) ? invariant(false) : void 0;
!(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1)) ? invariant(false, 'TOKEN') : void 0;
var liquidity;

@@ -343,3 +346,3 @@

return new sdkCore.TokenAmount(this.liquidityToken, liquidity);
return new sdkCore.CurrencyAmount(this.liquidityToken, liquidity);
};

@@ -353,4 +356,4 @@

!this.involvesToken(token) ? invariant(false, 'TOKEN') : void 0;
!totalSupply.token.equals(this.liquidityToken) ? invariant(false, 'TOTAL_SUPPLY') : void 0;
!liquidity.token.equals(this.liquidityToken) ? invariant(false, 'LIQUIDITY') : void 0;
!(totalSupply.currency.isToken && totalSupply.currency.equals(this.liquidityToken)) ? invariant(false, 'TOTAL_SUPPLY') : void 0;
!(liquidity.currency.isToken && liquidity.currency.equals(this.liquidityToken)) ? invariant(false, 'LIQUIDITY') : void 0;
!JSBI.lessThanOrEqual(liquidity.raw, totalSupply.raw) ? invariant(false, 'LIQUIDITY') : void 0;

@@ -373,3 +376,3 @@ var totalSupplyAdjusted;

var feeLiquidity = JSBI.divide(numerator, denominator);
totalSupplyAdjusted = totalSupply.add(new sdkCore.TokenAmount(this.liquidityToken, feeLiquidity));
totalSupplyAdjusted = totalSupply.add(new sdkCore.CurrencyAmount(this.liquidityToken, feeLiquidity));
} else {

@@ -383,3 +386,3 @@ totalSupplyAdjusted = totalSupply;

return new sdkCore.TokenAmount(token, JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw));
return new sdkCore.CurrencyAmount(token, JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw));
};

@@ -409,3 +412,4 @@

get: function get() {
return this.tokenAmounts[0].token;
!this.tokenAmounts[0].currency.isToken ? invariant(false) : void 0;
return this.tokenAmounts[0].currency;
}

@@ -415,3 +419,4 @@ }, {

get: function get() {
return this.tokenAmounts[1].token;
!this.tokenAmounts[1].currency.isToken ? invariant(false) : void 0;
return this.tokenAmounts[1].currency;
}

@@ -441,5 +446,5 @@ }, {

var weth = sdkCore.WETH9[chainId];
!(input instanceof sdkCore.Token && pairs[0].involvesToken(input) || input === sdkCore.ETHER && weth && pairs[0].involvesToken(weth)) ? invariant(false, 'INPUT') : void 0;
!(typeof output === 'undefined' || output instanceof sdkCore.Token && pairs[pairs.length - 1].involvesToken(output) || output === sdkCore.ETHER && weth && pairs[pairs.length - 1].involvesToken(weth)) ? invariant(false, 'OUTPUT') : void 0;
var path = [input instanceof sdkCore.Token ? input : weth];
!(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;
var path = [input.isToken ? input : weth];

@@ -556,11 +561,11 @@ for (var _iterator = _createForOfIteratorHelperLoose(pairs.entries()), _step; !(_step = _iterator()).done;) {

function wrappedAmount(currencyAmount, chainId) {
if (currencyAmount instanceof sdkCore.TokenAmount) return currencyAmount;
if (currencyAmount.currency === sdkCore.ETHER) return new sdkCore.TokenAmount(sdkCore.WETH9[chainId], currencyAmount.raw);
invariant(false, 'CURRENCY') ;
if (currencyAmount.currency.isToken) return currencyAmount;
if (currencyAmount.currency.isEther) return new sdkCore.CurrencyAmount(sdkCore.WETH9[chainId], currencyAmount.raw);
throw new Error('CURRENCY');
}
function wrappedCurrency(currency, chainId) {
if (currency instanceof sdkCore.Token) return currency;
if (currency.isToken) return currency;
if (currency === sdkCore.ETHER) return sdkCore.WETH9[chainId];
invariant(false, 'CURRENCY') ;
throw new Error('CURRENCY');
}

@@ -651,3 +656,3 @@ /**

var slippageAdjustedAmountOut = new sdkCore.Fraction(ONE).add(slippageTolerance).invert().multiply(this.outputAmount.raw).quotient;
return this.outputAmount instanceof sdkCore.TokenAmount ? new sdkCore.TokenAmount(this.outputAmount.token, slippageAdjustedAmountOut) : sdkCore.CurrencyAmount.ether(slippageAdjustedAmountOut);
return new sdkCore.CurrencyAmount(this.outputAmount.currency, slippageAdjustedAmountOut);
}

@@ -668,3 +673,3 @@ }

var slippageAdjustedAmountIn = new sdkCore.Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.raw).quotient;
return this.inputAmount instanceof sdkCore.TokenAmount ? new sdkCore.TokenAmount(this.inputAmount.token, slippageAdjustedAmountIn) : sdkCore.CurrencyAmount.ether(slippageAdjustedAmountIn);
return new sdkCore.CurrencyAmount(this.inputAmount.currency, slippageAdjustedAmountIn);
}

@@ -711,3 +716,3 @@ }

!(originalAmountIn === currencyAmountIn || currentPairs.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0;
var chainId = currencyAmountIn instanceof sdkCore.TokenAmount ? currencyAmountIn.token.chainId : currencyOut instanceof sdkCore.Token ? currencyOut.chainId : undefined;
var chainId = currencyAmountIn.currency.isToken ? currencyAmountIn.currency.chainId : currencyOut.isToken ? currencyOut.chainId : undefined;
!(chainId !== undefined) ? invariant(false, 'CHAIN_ID') : void 0;

@@ -720,3 +725,3 @@ var amountIn = wrappedAmount(currencyAmountIn, chainId);

if (!pair.token0.equals(amountIn.token) && !pair.token1.equals(amountIn.token)) continue;
if (!sdkCore.currencyEquals(pair.token0, amountIn.currency) && !sdkCore.currencyEquals(pair.token1, amountIn.currency)) continue;
if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue;

@@ -741,3 +746,3 @@ var amountOut = void 0;

if (amountOut.token.equals(tokenOut)) {
if (sdkCore.currencyEquals(amountOut.currency, tokenOut)) {
sdkCore.sortedInsert(bestTrades, new Trade(new Route([].concat(currentPairs, [pair]), originalAmountIn.currency, currencyOut), originalAmountIn, sdkCore.TradeType.EXACT_INPUT), maxNumResults, tradeComparator);

@@ -805,3 +810,3 @@ } else if (maxHops > 1 && pairs.length > 1) {

!(originalAmountOut === currencyAmountOut || currentPairs.length > 0) ? invariant(false, 'INVALID_RECURSION') : void 0;
var chainId = currencyAmountOut instanceof sdkCore.TokenAmount ? currencyAmountOut.token.chainId : currencyIn instanceof sdkCore.Token ? currencyIn.chainId : undefined;
var chainId = currencyAmountOut.currency.isToken ? currencyAmountOut.currency.chainId : currencyIn.isToken ? currencyIn.chainId : undefined;
!(chainId !== undefined) ? invariant(false, 'CHAIN_ID') : void 0;

@@ -814,3 +819,3 @@ var amountOut = wrappedAmount(currencyAmountOut, chainId);

if (!pair.token0.equals(amountOut.token) && !pair.token1.equals(amountOut.token)) continue;
if (!sdkCore.currencyEquals(pair.token0, amountOut.currency) && !sdkCore.currencyEquals(pair.token1, amountOut.currency)) continue;
if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue;

@@ -835,3 +840,3 @@ var amountIn = void 0;

if (amountIn.token.equals(tokenIn)) {
if (sdkCore.currencyEquals(amountIn.currency, tokenIn)) {
sdkCore.sortedInsert(bestTrades, new Trade(new Route([pair].concat(currentPairs), currencyIn, originalAmountOut.currency), originalAmountOut, sdkCore.TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator);

@@ -838,0 +843,0 @@ } else if (maxHops > 1 && pairs.length > 1) {

@@ -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=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;
"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=_;
//# sourceMappingURL=v2-sdk.cjs.production.min.js.map
import JSBI from 'jsbi';
export { default as JSBI } from 'jsbi';
import { TokenAmount, sqrt, Token, Price, ETHER, WETH9, currencyEquals, TradeType, Fraction, CurrencyAmount, Percent, sortedInsert, validateAndParseAddress } from '@uniswap/sdk-core';
import { CurrencyAmount, sqrt, Token, Price, ETHER, WETH9, currencyEquals, TradeType, Fraction, Percent, sortedInsert, validateAndParseAddress } from '@uniswap/sdk-core';
import invariant from 'tiny-invariant';

@@ -230,6 +230,8 @@ import { keccak256, pack } from '@ethersproject/solidity';

var Pair = /*#__PURE__*/function () {
function Pair(tokenAmountA, tokenAmountB) {
var tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks
? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
this.liquidityToken = new Token(tokenAmounts[0].token.chainId, Pair.getAddress(tokenAmounts[0].token, tokenAmounts[1].token), 18, 'UNI-V2', 'Uniswap V2');
function Pair(currencyAmountA, tokenAmountB) {
!(currencyAmountA.currency.isToken && tokenAmountB.currency.isToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
var tokenAmounts = currencyAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks
? [currencyAmountA, tokenAmountB] : [tokenAmountB, currencyAmountA];
!(tokenAmounts[0].currency.isToken && tokenAmounts[1].currency.isToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
this.liquidityToken = new Token(tokenAmounts[0].currency.chainId, Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency), 18, 'UNI-V2', 'Uniswap V2');
this.tokenAmounts = tokenAmounts;

@@ -280,3 +282,3 @@ }

_proto.getOutputAmount = function getOutputAmount(inputAmount) {
!this.involvesToken(inputAmount.token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
!(inputAmount.currency.isToken && this.involvesToken(inputAmount.currency)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;

@@ -287,8 +289,8 @@ if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO)) {

var inputReserve = this.reserveOf(inputAmount.token);
var outputReserve = this.reserveOf(inputAmount.token.equals(this.token0) ? this.token1 : this.token0);
var inputReserve = this.reserveOf(inputAmount.currency);
var outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
var inputAmountWithFee = JSBI.multiply(inputAmount.raw, _997);
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.raw);
var denominator = JSBI.add(JSBI.multiply(inputReserve.raw, _1000), inputAmountWithFee);
var outputAmount = new TokenAmount(inputAmount.token.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator));
var outputAmount = new CurrencyAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator));

@@ -303,13 +305,13 @@ if (JSBI.equal(outputAmount.raw, ZERO)) {

_proto.getInputAmount = function getInputAmount(outputAmount) {
!this.involvesToken(outputAmount.token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
!(outputAmount.currency.isToken && this.involvesToken(outputAmount.currency)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO) || JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.token).raw)) {
if (JSBI.equal(this.reserve0.raw, ZERO) || JSBI.equal(this.reserve1.raw, ZERO) || JSBI.greaterThanOrEqual(outputAmount.raw, this.reserveOf(outputAmount.currency).raw)) {
throw new InsufficientReservesError();
}
var outputReserve = this.reserveOf(outputAmount.token);
var inputReserve = this.reserveOf(outputAmount.token.equals(this.token0) ? this.token1 : this.token0);
var outputReserve = this.reserveOf(outputAmount.currency);
var inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.raw, outputAmount.raw), _1000);
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.raw, outputAmount.raw), _997);
var inputAmount = new TokenAmount(outputAmount.token.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE));
var inputAmount = new CurrencyAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE));
return [inputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];

@@ -319,6 +321,7 @@ };

_proto.getLiquidityMinted = function getLiquidityMinted(totalSupply, tokenAmountA, tokenAmountB) {
!totalSupply.token.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0;
var tokenAmounts = tokenAmountA.token.sortsBefore(tokenAmountB.token) // does safety checks
!(totalSupply.currency.isToken && totalSupply.currency.equals(this.liquidityToken)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0;
var tokenAmounts = tokenAmountA.currency.isToken && tokenAmountB.currency.isToken && tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks
? [tokenAmountA, tokenAmountB] : [tokenAmountB, tokenAmountA];
!(tokenAmounts[0].token.equals(this.token0) && tokenAmounts[1].token.equals(this.token1)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
!(tokenAmounts[0].currency.isToken && tokenAmounts[1].currency.isToken) ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0;
!(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
var liquidity;

@@ -338,3 +341,3 @@

return new TokenAmount(this.liquidityToken, liquidity);
return new CurrencyAmount(this.liquidityToken, liquidity);
};

@@ -348,4 +351,4 @@

!this.involvesToken(token) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
!totalSupply.token.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOTAL_SUPPLY') : invariant(false) : void 0;
!liquidity.token.equals(this.liquidityToken) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0;
!(totalSupply.currency.isToken && totalSupply.currency.equals(this.liquidityToken)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOTAL_SUPPLY') : invariant(false) : void 0;
!(liquidity.currency.isToken && liquidity.currency.equals(this.liquidityToken)) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0;
!JSBI.lessThanOrEqual(liquidity.raw, totalSupply.raw) ? process.env.NODE_ENV !== "production" ? invariant(false, 'LIQUIDITY') : invariant(false) : void 0;

@@ -368,3 +371,3 @@ var totalSupplyAdjusted;

var feeLiquidity = JSBI.divide(numerator, denominator);
totalSupplyAdjusted = totalSupply.add(new TokenAmount(this.liquidityToken, feeLiquidity));
totalSupplyAdjusted = totalSupply.add(new CurrencyAmount(this.liquidityToken, feeLiquidity));
} else {

@@ -378,3 +381,3 @@ totalSupplyAdjusted = totalSupply;

return new TokenAmount(token, JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw));
return new CurrencyAmount(token, JSBI.divide(JSBI.multiply(liquidity.raw, this.reserveOf(token).raw), totalSupplyAdjusted.raw));
};

@@ -404,3 +407,4 @@

get: function get() {
return this.tokenAmounts[0].token;
!this.tokenAmounts[0].currency.isToken ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0;
return this.tokenAmounts[0].currency;
}

@@ -410,3 +414,4 @@ }, {

get: function get() {
return this.tokenAmounts[1].token;
!this.tokenAmounts[1].currency.isToken ? process.env.NODE_ENV !== "production" ? invariant(false) : invariant(false) : void 0;
return this.tokenAmounts[1].currency;
}

@@ -436,5 +441,5 @@ }, {

var weth = WETH9[chainId];
!(input instanceof Token && 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 instanceof Token && 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 instanceof Token ? input : weth];
!(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;
var path = [input.isToken ? input : weth];

@@ -551,11 +556,11 @@ for (var _iterator = _createForOfIteratorHelperLoose(pairs.entries()), _step; !(_step = _iterator()).done;) {

function wrappedAmount(currencyAmount, chainId) {
if (currencyAmount instanceof TokenAmount) return currencyAmount;
if (currencyAmount.currency === ETHER) return new TokenAmount(WETH9[chainId], currencyAmount.raw);
process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) ;
if (currencyAmount.currency.isToken) return currencyAmount;
if (currencyAmount.currency.isEther) return new CurrencyAmount(WETH9[chainId], currencyAmount.raw);
throw new Error('CURRENCY');
}
function wrappedCurrency(currency, chainId) {
if (currency instanceof Token) return currency;
if (currency.isToken) return currency;
if (currency === ETHER) return WETH9[chainId];
process.env.NODE_ENV !== "production" ? invariant(false, 'CURRENCY') : invariant(false) ;
throw new Error('CURRENCY');
}

@@ -646,3 +651,3 @@ /**

var slippageAdjustedAmountOut = new Fraction(ONE).add(slippageTolerance).invert().multiply(this.outputAmount.raw).quotient;
return this.outputAmount instanceof TokenAmount ? new TokenAmount(this.outputAmount.token, slippageAdjustedAmountOut) : CurrencyAmount.ether(slippageAdjustedAmountOut);
return new CurrencyAmount(this.outputAmount.currency, slippageAdjustedAmountOut);
}

@@ -663,3 +668,3 @@ }

var slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.raw).quotient;
return this.inputAmount instanceof TokenAmount ? new TokenAmount(this.inputAmount.token, slippageAdjustedAmountIn) : CurrencyAmount.ether(slippageAdjustedAmountIn);
return new CurrencyAmount(this.inputAmount.currency, slippageAdjustedAmountIn);
}

@@ -706,3 +711,3 @@ }

!(originalAmountIn === currencyAmountIn || currentPairs.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0;
var chainId = currencyAmountIn instanceof TokenAmount ? currencyAmountIn.token.chainId : currencyOut instanceof Token ? currencyOut.chainId : undefined;
var chainId = currencyAmountIn.currency.isToken ? currencyAmountIn.currency.chainId : currencyOut.isToken ? currencyOut.chainId : undefined;
!(chainId !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_ID') : invariant(false) : void 0;

@@ -715,3 +720,3 @@ var amountIn = wrappedAmount(currencyAmountIn, chainId);

if (!pair.token0.equals(amountIn.token) && !pair.token1.equals(amountIn.token)) continue;
if (!currencyEquals(pair.token0, amountIn.currency) && !currencyEquals(pair.token1, amountIn.currency)) continue;
if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue;

@@ -736,3 +741,3 @@ var amountOut = void 0;

if (amountOut.token.equals(tokenOut)) {
if (currencyEquals(amountOut.currency, tokenOut)) {
sortedInsert(bestTrades, new Trade(new Route([].concat(currentPairs, [pair]), originalAmountIn.currency, currencyOut), originalAmountIn, TradeType.EXACT_INPUT), maxNumResults, tradeComparator);

@@ -800,3 +805,3 @@ } else if (maxHops > 1 && pairs.length > 1) {

!(originalAmountOut === currencyAmountOut || currentPairs.length > 0) ? process.env.NODE_ENV !== "production" ? invariant(false, 'INVALID_RECURSION') : invariant(false) : void 0;
var chainId = currencyAmountOut instanceof TokenAmount ? currencyAmountOut.token.chainId : currencyIn instanceof Token ? currencyIn.chainId : undefined;
var chainId = currencyAmountOut.currency.isToken ? currencyAmountOut.currency.chainId : currencyIn.isToken ? currencyIn.chainId : undefined;
!(chainId !== undefined) ? process.env.NODE_ENV !== "production" ? invariant(false, 'CHAIN_ID') : invariant(false) : void 0;

@@ -809,3 +814,3 @@ var amountOut = wrappedAmount(currencyAmountOut, chainId);

if (!pair.token0.equals(amountOut.token) && !pair.token1.equals(amountOut.token)) continue;
if (!currencyEquals(pair.token0, amountOut.currency) && !currencyEquals(pair.token1, amountOut.currency)) continue;
if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue;

@@ -830,3 +835,3 @@ var amountIn = void 0;

if (amountIn.token.equals(tokenIn)) {
if (currencyEquals(amountIn.currency, tokenIn)) {
sortedInsert(bestTrades, new Trade(new Route([pair].concat(currentPairs), currencyIn, originalAmountOut.currency), originalAmountOut, TradeType.EXACT_OUTPUT), maxNumResults, tradeComparator);

@@ -833,0 +838,0 @@ } else if (maxHops > 1 && pairs.length > 1) {

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

@@ -27,3 +27,3 @@ "main": "dist/index.js",

"@ethersproject/solidity": "^5.0.0",
"@uniswap/sdk-core": "^1.0.11",
"@uniswap/sdk-core": "^2.0.2",
"tiny-invariant": "^1.1.0",

@@ -30,0 +30,0 @@ "tiny-warning": "^1.0.3"

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