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

@uniswap/v2-sdk

Package Overview
Dependencies
Maintainers
12
Versions
40
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 3.2.0 to 3.2.1

4

dist/constants.d.ts

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

import { Percent } from '@uniswap/sdk-core';
import JSBI from 'jsbi';

@@ -10,1 +11,4 @@ export declare const FACTORY_ADDRESS = "0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";

export declare const _1000: JSBI;
export declare const BASIS_POINTS: JSBI;
export declare const ZERO_PERCENT: Percent;
export declare const ONE_HUNDRED_PERCENT: Percent;

@@ -39,6 +39,109 @@ import { BigintIsh, Price, Token, CurrencyAmount } from '@uniswap/sdk-core';

reserveOf(token: Token): CurrencyAmount<Token>;
/**
* getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut.
* https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
* has the math deduction for the reserve calculation without fee-on-transfer fees.
*
* With fee-on-transfer tax, intuitively it's just:
* inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee
* where amountInWithFee is the amountIn after taking out the LP fees
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
*
* But we are illustrating the math deduction below to ensure that's the case.
*
* before swap A * B = K where A = reserveIn B = reserveOut
*
* after swap A' * B' = K where only k is a constant value
*
* getAmountOut
*
* A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
* B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
* amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k
* = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
* /
* (1 - amountOut.buyFeesBips / 10000)
* amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* /
* (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
*
* outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* /
* (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
* = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000
* /
* ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000)
* = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn
* /
* (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn)
* = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
* /
* (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
* = (B * inputAmountWithFeeAndTax)
* /
* (1000 * A + inputAmountWithFeeAndTax)
*
* inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
*
* @param inputAmount
*/
getOutputAmount(inputAmount: CurrencyAmount<Token>): [CurrencyAmount<Token>, Pair];
/**
* getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut.
* https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
* has the math deduction for the reserve calculation without fee-on-transfer fees.
*
* With fee-on-transfer fees, intuitively it's just:
* outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
* inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997
*
* But we are illustrating the math deduction below to ensure that's the case.
*
* before swap A * B = K where A = reserveIn B = reserveOut
*
* after swap A' * B' = K where only k is a constant value
*
* getAmountIn
*
* B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
* A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
* amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (997 * (1 - amountIn.sellFeesBips / 10000))
*
* outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
* inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000))
* = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997)
*
* @param outputAmount
*/
getInputAmount(outputAmount: CurrencyAmount<Token>): [CurrencyAmount<Token>, Pair];
getLiquidityMinted(totalSupply: CurrencyAmount<Token>, tokenAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>): CurrencyAmount<Token>;
getLiquidityValue(token: Token, totalSupply: CurrencyAmount<Token>, liquidity: CurrencyAmount<Token>, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount<Token>;
private derivePercentAfterSellFees;
private derivePercentAfterBuyFees;
}

@@ -7,7 +7,8 @@ 'use strict';

var sdkCore = require('@uniswap/sdk-core');
var JSBI = _interopDefault(require('jsbi'));
var sdkCore = require('@uniswap/sdk-core');
var invariant = _interopDefault(require('tiny-invariant'));
var solidity = require('@ethersproject/solidity');
var address = require('@ethersproject/address');
var bignumber = require('@ethersproject/bignumber');

@@ -23,2 +24,5 @@ var FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';

var _1000 = /*#__PURE__*/JSBI.BigInt(1000);
var BASIS_POINTS = /*#__PURE__*/JSBI.BigInt(10000);
var ZERO_PERCENT = /*#__PURE__*/new sdkCore.Percent(ZERO);
var ONE_HUNDRED_PERCENT = /*#__PURE__*/new sdkCore.Percent(ONE);

@@ -283,3 +287,63 @@ function _defineProperties(target, props) {

return token.equals(this.token0) ? this.reserve0 : this.reserve1;
};
}
/**
* getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut.
* https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
* has the math deduction for the reserve calculation without fee-on-transfer fees.
*
* With fee-on-transfer tax, intuitively it's just:
* inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee
* where amountInWithFee is the amountIn after taking out the LP fees
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
*
* But we are illustrating the math deduction below to ensure that's the case.
*
* before swap A * B = K where A = reserveIn B = reserveOut
*
* after swap A' * B' = K where only k is a constant value
*
* getAmountOut
*
* A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
* B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
* amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k
* = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
* /
* (1 - amountOut.buyFeesBips / 10000)
* amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* /
* (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
*
* outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* /
* (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
* = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000
* /
* ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000)
* = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn
* /
* (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn)
* = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
* /
* (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
* = (B * inputAmountWithFeeAndTax)
* /
* (1000 * A + inputAmountWithFeeAndTax)
*
* inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
*
* @param inputAmount
*/
;

@@ -295,6 +359,10 @@ _proto.getOutputAmount = function getOutputAmount(inputAmount) {

var outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
var inputAmountWithFee = JSBI.multiply(inputAmount.quotient, _997);
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.quotient);
var denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFee);
var outputAmount = sdkCore.CurrencyAmount.fromRawAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator));
var percentAfterSellFees = this.derivePercentAfterSellFees(inputAmount);
var inputAmountAfterTax = percentAfterSellFees.greaterThan(ZERO_PERCENT) ? sdkCore.CurrencyAmount.fromRawAmount(inputAmount.currency, percentAfterSellFees.multiply(inputAmount).quotient // fraction.quotient will round down by itself, which is desired
) : inputAmount;
var inputAmountWithFeeAndAfterTax = JSBI.multiply(inputAmountAfterTax.quotient, _997);
var numerator = JSBI.multiply(inputAmountWithFeeAndAfterTax, outputReserve.quotient);
var denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFeeAndAfterTax);
var outputAmount = sdkCore.CurrencyAmount.fromRawAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator) // JSBI.divide will round down by itself, which is desired
);

@@ -305,9 +373,63 @@ if (JSBI.equal(outputAmount.quotient, ZERO)) {

return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
};
var percentAfterBuyFees = this.derivePercentAfterBuyFees(outputAmount);
var outputAmountAfterTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT) ? sdkCore.CurrencyAmount.fromRawAmount(outputAmount.currency, outputAmount.multiply(percentAfterBuyFees).quotient // fraction.quotient will round down by itself, which is desired
) : outputAmount;
if (JSBI.equal(outputAmountAfterTax.quotient, ZERO)) {
throw new InsufficientInputAmountError();
}
return [outputAmountAfterTax, new Pair(inputReserve.add(inputAmountAfterTax), outputReserve.subtract(outputAmountAfterTax))];
}
/**
* getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut.
* https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
* has the math deduction for the reserve calculation without fee-on-transfer fees.
*
* With fee-on-transfer fees, intuitively it's just:
* outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
* inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997
*
* But we are illustrating the math deduction below to ensure that's the case.
*
* before swap A * B = K where A = reserveIn B = reserveOut
*
* after swap A' * B' = K where only k is a constant value
*
* getAmountIn
*
* B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
* A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
* amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (997 * (1 - amountIn.sellFeesBips / 10000))
*
* outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
* inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000))
* = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997)
*
* @param outputAmount
*/
;
_proto.getInputAmount = function getInputAmount(outputAmount) {
!this.involvesToken(outputAmount.currency) ? invariant(false, 'TOKEN') : void 0;
var percentAfterBuyFees = this.derivePercentAfterBuyFees(outputAmount);
var outputAmountBeforeTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT) ? sdkCore.CurrencyAmount.fromRawAmount(outputAmount.currency, JSBI.add(outputAmount.divide(percentAfterBuyFees).quotient, ONE) // add 1 for rounding up
) : outputAmount;
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO) || JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient)) {
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO) || JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient) || JSBI.greaterThanOrEqual(outputAmountBeforeTax.quotient, this.reserveOf(outputAmount.currency).quotient)) {
throw new InsufficientReservesError();

@@ -318,6 +440,10 @@ }

var inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmount.quotient), _1000);
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmount.quotient), _997);
var inputAmount = sdkCore.CurrencyAmount.fromRawAmount(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))];
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmountBeforeTax.quotient), _1000);
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmountBeforeTax.quotient), _997);
var inputAmount = sdkCore.CurrencyAmount.fromRawAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE) // add 1 here is part of the formula, no rounding needed here, since there will not be decimal at this point
);
var percentAfterSellFees = this.derivePercentAfterSellFees(inputAmount);
var inputAmountBeforeTax = percentAfterSellFees.greaterThan(ZERO_PERCENT) ? sdkCore.CurrencyAmount.fromRawAmount(inputAmount.currency, JSBI.add(inputAmount.divide(percentAfterSellFees).quotient, ONE) // add 1 for rounding up
) : inputAmount;
return [inputAmountBeforeTax, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
};

@@ -384,2 +510,22 @@

_proto.derivePercentAfterSellFees = function derivePercentAfterSellFees(inputAmount) {
var sellFeeBips = inputAmount.currency.sellFeeBps;
if (sellFeeBips != null && sellFeeBips.gt(bignumber.BigNumber.from(0))) {
return ONE_HUNDRED_PERCENT.subtract(new sdkCore.Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS));
} else {
return ZERO_PERCENT;
}
};
_proto.derivePercentAfterBuyFees = function derivePercentAfterBuyFees(outputAmount) {
var buyFeeBps = outputAmount.currency.buyFeeBps;
if (buyFeeBps != null && buyFeeBps.gt(bignumber.BigNumber.from(0))) {
return ONE_HUNDRED_PERCENT.subtract(new sdkCore.Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS));
} else {
return ZERO_PERCENT;
}
};
_createClass(Pair, [{

@@ -386,0 +532,0 @@ key: "token0Price",

2

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

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

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

@@ -0,6 +1,7 @@

import { Percent, CurrencyAmount, sqrt, Token, Price, TradeType, Fraction, computePriceImpact, sortedInsert, validateAndParseAddress } from '@uniswap/sdk-core';
import JSBI from 'jsbi';
import { CurrencyAmount, sqrt, Token, Price, TradeType, Fraction, computePriceImpact, sortedInsert, validateAndParseAddress } from '@uniswap/sdk-core';
import invariant from 'tiny-invariant';
import { keccak256, pack } from '@ethersproject/solidity';
import { getCreate2Address } from '@ethersproject/address';
import { BigNumber } from '@ethersproject/bignumber';

@@ -16,2 +17,5 @@ var FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f';

var _1000 = /*#__PURE__*/JSBI.BigInt(1000);
var BASIS_POINTS = /*#__PURE__*/JSBI.BigInt(10000);
var ZERO_PERCENT = /*#__PURE__*/new Percent(ZERO);
var ONE_HUNDRED_PERCENT = /*#__PURE__*/new Percent(ONE);

@@ -276,3 +280,63 @@ function _defineProperties(target, props) {

return token.equals(this.token0) ? this.reserve0 : this.reserve1;
};
}
/**
* getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut.
* https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
* has the math deduction for the reserve calculation without fee-on-transfer fees.
*
* With fee-on-transfer tax, intuitively it's just:
* inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee
* where amountInWithFee is the amountIn after taking out the LP fees
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
*
* But we are illustrating the math deduction below to ensure that's the case.
*
* before swap A * B = K where A = reserveIn B = reserveOut
*
* after swap A' * B' = K where only k is a constant value
*
* getAmountOut
*
* A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
* B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
* amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k
* = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))
* /
* (1 - amountOut.buyFeesBips / 10000)
* = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
* /
* (1 - amountOut.buyFeesBips / 10000)
* amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* /
* (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
*
* outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn
* /
* (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)
* = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000
* /
* ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000)
* = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn
* /
* (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn)
* = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
* /
* (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)
* = (B * inputAmountWithFeeAndTax)
* /
* (1000 * A + inputAmountWithFeeAndTax)
*
* inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee
* outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)
*
* @param inputAmount
*/
;

@@ -288,6 +352,10 @@ _proto.getOutputAmount = function getOutputAmount(inputAmount) {

var outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
var inputAmountWithFee = JSBI.multiply(inputAmount.quotient, _997);
var numerator = JSBI.multiply(inputAmountWithFee, outputReserve.quotient);
var denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFee);
var outputAmount = CurrencyAmount.fromRawAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator));
var percentAfterSellFees = this.derivePercentAfterSellFees(inputAmount);
var inputAmountAfterTax = percentAfterSellFees.greaterThan(ZERO_PERCENT) ? CurrencyAmount.fromRawAmount(inputAmount.currency, percentAfterSellFees.multiply(inputAmount).quotient // fraction.quotient will round down by itself, which is desired
) : inputAmount;
var inputAmountWithFeeAndAfterTax = JSBI.multiply(inputAmountAfterTax.quotient, _997);
var numerator = JSBI.multiply(inputAmountWithFeeAndAfterTax, outputReserve.quotient);
var denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFeeAndAfterTax);
var outputAmount = CurrencyAmount.fromRawAmount(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.divide(numerator, denominator) // JSBI.divide will round down by itself, which is desired
);

@@ -298,9 +366,63 @@ if (JSBI.equal(outputAmount.quotient, ZERO)) {

return [outputAmount, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
};
var percentAfterBuyFees = this.derivePercentAfterBuyFees(outputAmount);
var outputAmountAfterTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT) ? CurrencyAmount.fromRawAmount(outputAmount.currency, outputAmount.multiply(percentAfterBuyFees).quotient // fraction.quotient will round down by itself, which is desired
) : outputAmount;
if (JSBI.equal(outputAmountAfterTax.quotient, ZERO)) {
throw new InsufficientInputAmountError();
}
return [outputAmountAfterTax, new Pair(inputReserve.add(inputAmountAfterTax), outputReserve.subtract(outputAmountAfterTax))];
}
/**
* getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut.
* https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000
* has the math deduction for the reserve calculation without fee-on-transfer fees.
*
* With fee-on-transfer fees, intuitively it's just:
* outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
* inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997
*
* But we are illustrating the math deduction below to ensure that's the case.
*
* before swap A * B = K where A = reserveIn B = reserveOut
*
* after swap A' * B' = K where only k is a constant value
*
* getAmountIn
*
* B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)
* A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted
* amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (0.997 * (1 - amountIn.sellFeesBips / 10000))
* = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))
* /
* (997 * (1 - amountIn.sellFeesBips / 10000))
*
* outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)
* inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000))
* = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997)
*
* @param outputAmount
*/
;
_proto.getInputAmount = function getInputAmount(outputAmount) {
!this.involvesToken(outputAmount.currency) ? process.env.NODE_ENV !== "production" ? invariant(false, 'TOKEN') : invariant(false) : void 0;
var percentAfterBuyFees = this.derivePercentAfterBuyFees(outputAmount);
var outputAmountBeforeTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT) ? CurrencyAmount.fromRawAmount(outputAmount.currency, JSBI.add(outputAmount.divide(percentAfterBuyFees).quotient, ONE) // add 1 for rounding up
) : outputAmount;
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO) || JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient)) {
if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO) || JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient) || JSBI.greaterThanOrEqual(outputAmountBeforeTax.quotient, this.reserveOf(outputAmount.currency).quotient)) {
throw new InsufficientReservesError();

@@ -311,6 +433,10 @@ }

var inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0);
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmount.quotient), _1000);
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmount.quotient), _997);
var inputAmount = CurrencyAmount.fromRawAmount(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))];
var numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmountBeforeTax.quotient), _1000);
var denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmountBeforeTax.quotient), _997);
var inputAmount = CurrencyAmount.fromRawAmount(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0, JSBI.add(JSBI.divide(numerator, denominator), ONE) // add 1 here is part of the formula, no rounding needed here, since there will not be decimal at this point
);
var percentAfterSellFees = this.derivePercentAfterSellFees(inputAmount);
var inputAmountBeforeTax = percentAfterSellFees.greaterThan(ZERO_PERCENT) ? CurrencyAmount.fromRawAmount(inputAmount.currency, JSBI.add(inputAmount.divide(percentAfterSellFees).quotient, ONE) // add 1 for rounding up
) : inputAmount;
return [inputAmountBeforeTax, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))];
};

@@ -377,2 +503,22 @@

_proto.derivePercentAfterSellFees = function derivePercentAfterSellFees(inputAmount) {
var sellFeeBips = inputAmount.currency.sellFeeBps;
if (sellFeeBips != null && sellFeeBips.gt(BigNumber.from(0))) {
return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS));
} else {
return ZERO_PERCENT;
}
};
_proto.derivePercentAfterBuyFees = function derivePercentAfterBuyFees(outputAmount) {
var buyFeeBps = outputAmount.currency.buyFeeBps;
if (buyFeeBps != null && buyFeeBps.gt(BigNumber.from(0))) {
return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS));
} else {
return ZERO_PERCENT;
}
};
_createClass(Pair, [{

@@ -379,0 +525,0 @@ key: "token0Price",

{
"name": "@uniswap/v2-sdk",
"license": "MIT",
"version": "3.2.0",
"version": "3.2.1",
"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": "^4.0.2",
"@uniswap/sdk-core": "^4.0.7",
"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