novaswap-v2-sdk 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"novaswap-v2-sdk.cjs.development.js","sources":["../src/constants.ts","../src/errors.ts","../src/entities/pair.ts","../src/entities/route.ts","../src/entities/trade.ts","../src/router.ts"],"sourcesContent":["import { Percent} from '@uniswap/sdk-core'\nimport {V2_FACTORY_ADDRESSES } from 'novaswap-core-sdk'\nimport JSBI from 'jsbi'\n\n/**\n * @deprecated use FACTORY_ADDRESS_MAP instead\n */\nexport const FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'\n\nexport const FACTORY_ADDRESS_MAP: { [chainId: number]: string } = V2_FACTORY_ADDRESSES\n\nexport const INIT_CODE_HASH = '0x0ef7ca4700ff7e705236379af2cdac62d4fa0bbd010fb163697b63379941118e'\n\nexport const MINIMUM_LIQUIDITY = JSBI.BigInt(1000)\n\n// exports for internal consumption\nexport const ZERO = JSBI.BigInt(0)\nexport const ONE = JSBI.BigInt(1)\nexport const FIVE = JSBI.BigInt(5)\nexport const _997 = JSBI.BigInt(997)\nexport const _1000 = JSBI.BigInt(1000)\nexport const BASIS_POINTS = JSBI.BigInt(10000)\n\nexport const ZERO_PERCENT = new Percent(ZERO)\nexport const ONE_HUNDRED_PERCENT = new Percent(ONE)\n","// see https://stackoverflow.com/a/41102306\nconst CAN_SET_PROTOTYPE = 'setPrototypeOf' in Object\n\n/**\n * Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be\n * obtained by sending any amount of input.\n */\nexport class InsufficientReservesError extends Error {\n public readonly isInsufficientReservesError: true = true\n\n public constructor() {\n super()\n this.name = this.constructor.name\n if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(this, new.target.prototype)\n }\n}\n\n/**\n * Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less\n * than the price of a single unit of output after fees.\n */\nexport class InsufficientInputAmountError extends Error {\n public readonly isInsufficientInputAmountError: true = true\n\n public constructor() {\n super()\n this.name = this.constructor.name\n if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(this, new.target.prototype)\n }\n}\n","import { getCreate2Address } from '@ethersproject/address'\nimport { BigNumber } from '@ethersproject/bignumber'\nimport { keccak256, pack } from '@ethersproject/solidity'\nimport { BigintIsh, CurrencyAmount, Percent, Price, sqrt, Token } from '@uniswap/sdk-core'\nimport JSBI from 'jsbi'\nimport invariant from 'tiny-invariant'\n\nimport {\n _1000,\n _997,\n BASIS_POINTS,\n FACTORY_ADDRESS,\n FACTORY_ADDRESS_MAP,\n FIVE,\n INIT_CODE_HASH,\n MINIMUM_LIQUIDITY,\n ONE,\n ONE_HUNDRED_PERCENT,\n ZERO,\n ZERO_PERCENT\n} from '../constants'\nimport { InsufficientInputAmountError, InsufficientReservesError } from '../errors'\n\nexport const computePairAddress = ({\n factoryAddress,\n tokenA,\n tokenB\n}: {\n factoryAddress: string\n tokenA: Token\n tokenB: Token\n}): string => {\n const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks\n return getCreate2Address(\n factoryAddress,\n keccak256(['bytes'], [pack(['address', 'address'], [token0.address, token1.address])]),\n INIT_CODE_HASH\n )\n}\nexport class Pair {\n public readonly liquidityToken: Token\n private readonly tokenAmounts: [CurrencyAmount<Token>, CurrencyAmount<Token>]\n\n public static getAddress(tokenA: Token, tokenB: Token): string {\n const factoryAddress = FACTORY_ADDRESS_MAP[tokenA.chainId] ?? FACTORY_ADDRESS\n return computePairAddress({ factoryAddress, tokenA, tokenB })\n }\n\n public constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>) {\n const tokenAmounts = currencyAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks\n ? [currencyAmountA, tokenAmountB]\n : [tokenAmountB, currencyAmountA]\n this.liquidityToken = new Token(\n tokenAmounts[0].currency.chainId,\n Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency),\n 18,\n 'UNI-V2',\n 'Uniswap V2'\n )\n this.tokenAmounts = tokenAmounts as [CurrencyAmount<Token>, CurrencyAmount<Token>]\n }\n\n /**\n * Returns true if the token is either token0 or token1\n * @param token to check\n */\n public involvesToken(token: Token): boolean {\n return token.equals(this.token0) || token.equals(this.token1)\n }\n\n /**\n * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0\n */\n public get token0Price(): Price<Token, Token> {\n const result = this.tokenAmounts[1].divide(this.tokenAmounts[0])\n return new Price(this.token0, this.token1, result.denominator, result.numerator)\n }\n\n /**\n * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1\n */\n public get token1Price(): Price<Token, Token> {\n const result = this.tokenAmounts[0].divide(this.tokenAmounts[1])\n return new Price(this.token1, this.token0, result.denominator, result.numerator)\n }\n\n /**\n * Return the price of the given token in terms of the other token in the pair.\n * @param token token to return price of\n */\n public priceOf(token: Token): Price<Token, Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n return token.equals(this.token0) ? this.token0Price : this.token1Price\n }\n\n /**\n * Returns the chain ID of the tokens in the pair.\n */\n public get chainId(): number {\n return this.token0.chainId\n }\n\n public get token0(): Token {\n return this.tokenAmounts[0].currency\n }\n\n public get token1(): Token {\n return this.tokenAmounts[1].currency\n }\n\n public get reserve0(): CurrencyAmount<Token> {\n return this.tokenAmounts[0]\n }\n\n public get reserve1(): CurrencyAmount<Token> {\n return this.tokenAmounts[1]\n }\n\n public reserveOf(token: Token): CurrencyAmount<Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n return token.equals(this.token0) ? this.reserve0 : this.reserve1\n }\n\n /**\n * getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut.\n * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000\n * has the math deduction for the reserve calculation without fee-on-transfer fees.\n *\n * With fee-on-transfer tax, intuitively it's just:\n * inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn\n * = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee\n * where amountInWithFee is the amountIn after taking out the LP fees\n * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)\n *\n * But we are illustrating the math deduction below to ensure that's the case.\n *\n * before swap A * B = K where A = reserveIn B = reserveOut\n *\n * after swap A' * B' = K where only k is a constant value\n *\n * getAmountOut\n *\n * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted\n * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)\n * amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k\n * = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))\n * /\n * (1 - amountOut.buyFeesBips / 10000)\n * = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))\n * /\n * (1 - amountOut.buyFeesBips / 10000)\n * = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))\n * /\n * (1 - amountOut.buyFeesBips / 10000)\n * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)\n * /\n * (1 - amountOut.buyFeesBips / 10000)\n * amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn\n * /\n * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)\n *\n * outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn\n * /\n * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)\n * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000\n * /\n * ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000)\n * = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn\n * /\n * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn)\n * = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)\n * /\n * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)\n * = (B * inputAmountWithFeeAndTax)\n * /\n * (1000 * A + inputAmountWithFeeAndTax)\n *\n * inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee\n * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)\n *\n * @param inputAmount\n * @param calculateFotFees\n */\n public getOutputAmount(\n inputAmount: CurrencyAmount<Token>,\n calculateFotFees: boolean = true\n ): [CurrencyAmount<Token>, Pair] {\n invariant(this.involvesToken(inputAmount.currency), 'TOKEN')\n if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) {\n throw new InsufficientReservesError()\n }\n const inputReserve = this.reserveOf(inputAmount.currency)\n const outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0)\n\n const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : ZERO_PERCENT\n const inputAmountAfterTax = percentAfterSellFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(\n inputAmount.currency,\n percentAfterSellFees.multiply(inputAmount).quotient // fraction.quotient will round down by itself, which is desired\n )\n : inputAmount\n\n const inputAmountWithFeeAndAfterTax = JSBI.multiply(inputAmountAfterTax.quotient, _997)\n const numerator = JSBI.multiply(inputAmountWithFeeAndAfterTax, outputReserve.quotient)\n const denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFeeAndAfterTax)\n const outputAmount = CurrencyAmount.fromRawAmount(\n inputAmount.currency.equals(this.token0) ? this.token1 : this.token0,\n JSBI.divide(numerator, denominator) // JSBI.divide will round down by itself, which is desired\n )\n\n if (JSBI.equal(outputAmount.quotient, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n\n const percentAfterBuyFees = calculateFotFees ? this.derivePercentAfterBuyFees(outputAmount) : ZERO_PERCENT\n const outputAmountAfterTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(\n outputAmount.currency,\n outputAmount.multiply(percentAfterBuyFees).quotient // fraction.quotient will round down by itself, which is desired\n )\n : outputAmount\n if (JSBI.equal(outputAmountAfterTax.quotient, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n\n return [\n outputAmountAfterTax,\n new Pair(inputReserve.add(inputAmountAfterTax), outputReserve.subtract(outputAmountAfterTax))\n ]\n }\n\n /**\n * getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut.\n * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000\n * has the math deduction for the reserve calculation without fee-on-transfer fees.\n *\n * With fee-on-transfer fees, intuitively it's just:\n * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)\n * inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997\n *\n * But we are illustrating the math deduction below to ensure that's the case.\n *\n * before swap A * B = K where A = reserveIn B = reserveOut\n *\n * after swap A' * B' = K where only k is a constant value\n *\n * getAmountIn\n *\n * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)\n * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted\n * amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)\n * /\n * (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)\n * /\n * (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))\n * /\n * (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))\n * /\n * (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))\n * /\n * (997 * (1 - amountIn.sellFeesBips / 10000))\n *\n * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)\n * inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000))\n * = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997)\n *\n * @param outputAmount\n */\n public getInputAmount(\n outputAmount: CurrencyAmount<Token>,\n calculateFotFees: boolean = true\n ): [CurrencyAmount<Token>, Pair] {\n invariant(this.involvesToken(outputAmount.currency), 'TOKEN')\n const percentAfterBuyFees = calculateFotFees ? this.derivePercentAfterBuyFees(outputAmount) : ZERO_PERCENT\n const outputAmountBeforeTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(\n outputAmount.currency,\n JSBI.add(outputAmount.divide(percentAfterBuyFees).quotient, ONE) // add 1 for rounding up\n )\n : outputAmount\n\n if (\n JSBI.equal(this.reserve0.quotient, ZERO) ||\n JSBI.equal(this.reserve1.quotient, ZERO) ||\n JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient) ||\n JSBI.greaterThanOrEqual(outputAmountBeforeTax.quotient, this.reserveOf(outputAmount.currency).quotient)\n ) {\n throw new InsufficientReservesError()\n }\n\n const outputReserve = this.reserveOf(outputAmount.currency)\n const inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0)\n\n const numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmountBeforeTax.quotient), _1000)\n const denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmountBeforeTax.quotient), _997)\n const inputAmount = CurrencyAmount.fromRawAmount(\n outputAmount.currency.equals(this.token0) ? this.token1 : this.token0,\n 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\n )\n\n const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : ZERO_PERCENT\n const inputAmountBeforeTax = percentAfterSellFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(\n inputAmount.currency,\n JSBI.add(inputAmount.divide(percentAfterSellFees).quotient, ONE) // add 1 for rounding up\n )\n : inputAmount\n return [inputAmountBeforeTax, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]\n }\n\n public getLiquidityMinted(\n totalSupply: CurrencyAmount<Token>,\n tokenAmountA: CurrencyAmount<Token>,\n tokenAmountB: CurrencyAmount<Token>\n ): CurrencyAmount<Token> {\n invariant(totalSupply.currency.equals(this.liquidityToken), 'LIQUIDITY')\n const tokenAmounts = tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks\n ? [tokenAmountA, tokenAmountB]\n : [tokenAmountB, tokenAmountA]\n invariant(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1), 'TOKEN')\n\n let liquidity: JSBI\n if (JSBI.equal(totalSupply.quotient, ZERO)) {\n liquidity = JSBI.subtract(\n sqrt(JSBI.multiply(tokenAmounts[0].quotient, tokenAmounts[1].quotient)),\n MINIMUM_LIQUIDITY\n )\n } else {\n const amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].quotient, totalSupply.quotient), this.reserve0.quotient)\n const amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].quotient, totalSupply.quotient), this.reserve1.quotient)\n liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1\n }\n if (!JSBI.greaterThan(liquidity, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n return CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity)\n }\n\n public getLiquidityValue(\n token: Token,\n totalSupply: CurrencyAmount<Token>,\n liquidity: CurrencyAmount<Token>,\n feeOn: boolean = false,\n kLast?: BigintIsh\n ): CurrencyAmount<Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n invariant(totalSupply.currency.equals(this.liquidityToken), 'TOTAL_SUPPLY')\n invariant(liquidity.currency.equals(this.liquidityToken), 'LIQUIDITY')\n invariant(JSBI.lessThanOrEqual(liquidity.quotient, totalSupply.quotient), 'LIQUIDITY')\n\n let totalSupplyAdjusted: CurrencyAmount<Token>\n if (!feeOn) {\n totalSupplyAdjusted = totalSupply\n } else {\n invariant(!!kLast, 'K_LAST')\n const kLastParsed = JSBI.BigInt(kLast)\n if (!JSBI.equal(kLastParsed, ZERO)) {\n const rootK = sqrt(JSBI.multiply(this.reserve0.quotient, this.reserve1.quotient))\n const rootKLast = sqrt(kLastParsed)\n if (JSBI.greaterThan(rootK, rootKLast)) {\n const numerator = JSBI.multiply(totalSupply.quotient, JSBI.subtract(rootK, rootKLast))\n const denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast)\n const feeLiquidity = JSBI.divide(numerator, denominator)\n totalSupplyAdjusted = totalSupply.add(CurrencyAmount.fromRawAmount(this.liquidityToken, feeLiquidity))\n } else {\n totalSupplyAdjusted = totalSupply\n }\n } else {\n totalSupplyAdjusted = totalSupply\n }\n }\n\n return CurrencyAmount.fromRawAmount(\n token,\n JSBI.divide(JSBI.multiply(liquidity.quotient, this.reserveOf(token).quotient), totalSupplyAdjusted.quotient)\n )\n }\n\n private derivePercentAfterSellFees(inputAmount: CurrencyAmount<Token>): Percent {\n const sellFeeBips = this.token0.wrapped.equals(inputAmount.wrapped.currency)\n ? this.token0.wrapped.sellFeeBps\n : this.token1.wrapped.sellFeeBps\n if (sellFeeBips?.gt(BigNumber.from(0))) {\n return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS))\n } else {\n return ZERO_PERCENT\n }\n }\n\n private derivePercentAfterBuyFees(outputAmount: CurrencyAmount<Token>): Percent {\n const buyFeeBps = this.token0.wrapped.equals(outputAmount.wrapped.currency)\n ? this.token0.wrapped.buyFeeBps\n : this.token1.wrapped.buyFeeBps\n if (buyFeeBps?.gt(BigNumber.from(0))) {\n return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS))\n } else {\n return ZERO_PERCENT\n }\n }\n}\n","import invariant from 'tiny-invariant'\nimport { Currency, Price, Token } from '@uniswap/sdk-core'\n\nimport { Pair } from './pair'\n\nexport class Route<TInput extends Currency, TOutput extends Currency> {\n public readonly pairs: Pair[]\n public readonly path: Token[]\n public readonly input: TInput\n public readonly output: TOutput\n\n public constructor(pairs: Pair[], input: TInput, output: TOutput) {\n invariant(pairs.length > 0, 'PAIRS')\n const chainId: number = pairs[0].chainId\n invariant(\n pairs.every(pair => pair.chainId === chainId),\n 'CHAIN_IDS'\n )\n\n const wrappedInput = input.wrapped\n invariant(pairs[0].involvesToken(wrappedInput), 'INPUT')\n invariant(typeof output === 'undefined' || pairs[pairs.length - 1].involvesToken(output.wrapped), 'OUTPUT')\n\n const path: Token[] = [wrappedInput]\n for (const [i, pair] of pairs.entries()) {\n const currentInput = path[i]\n invariant(currentInput.equals(pair.token0) || currentInput.equals(pair.token1), 'PATH')\n const output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0\n path.push(output)\n }\n\n this.pairs = pairs\n this.path = path\n this.input = input\n this.output = output\n }\n\n private _midPrice: Price<TInput, TOutput> | null = null\n\n public get midPrice(): Price<TInput, TOutput> {\n if (this._midPrice !== null) return this._midPrice\n const prices: Price<Currency, Currency>[] = []\n for (const [i, pair] of this.pairs.entries()) {\n prices.push(\n this.path[i].equals(pair.token0)\n ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient)\n : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient)\n )\n }\n const reduced = prices.slice(1).reduce((accumulator, currentValue) => accumulator.multiply(currentValue), prices[0])\n return (this._midPrice = new Price(this.input, this.output, reduced.denominator, reduced.numerator))\n }\n\n public get chainId(): number {\n return this.pairs[0].chainId\n }\n}\n","import {\n computePriceImpact,\n Token,\n Currency,\n CurrencyAmount,\n Fraction,\n Percent,\n Price,\n sortedInsert,\n TradeType\n} from '@uniswap/sdk-core'\nimport { ONE, ZERO } from '../constants'\nimport invariant from 'tiny-invariant'\n\nimport { Pair } from './pair'\nimport { Route } from './route'\n\n// minimal interface so the input output comparator may be shared across types\ninterface InputOutput<TInput extends Currency, TOutput extends Currency> {\n readonly inputAmount: CurrencyAmount<TInput>\n readonly outputAmount: CurrencyAmount<TOutput>\n}\n\n// comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts\n// in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first\nexport function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(\n a: InputOutput<TInput, TOutput>,\n b: InputOutput<TInput, TOutput>\n): number {\n // must have same input and output token for comparison\n invariant(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY')\n invariant(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY')\n if (a.outputAmount.equalTo(b.outputAmount)) {\n if (a.inputAmount.equalTo(b.inputAmount)) {\n return 0\n }\n // trade A requires less input than trade B, so A should come first\n if (a.inputAmount.lessThan(b.inputAmount)) {\n return -1\n } else {\n return 1\n }\n } else {\n // tradeA has less output than trade B, so should come second\n if (a.outputAmount.lessThan(b.outputAmount)) {\n return 1\n } else {\n return -1\n }\n }\n}\n\n// extension of the input output comparator that also considers other dimensions of the trade in ranking them\nexport function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n a: Trade<TInput, TOutput, TTradeType>,\n b: Trade<TInput, TOutput, TTradeType>\n) {\n const ioComp = inputOutputComparator(a, b)\n if (ioComp !== 0) {\n return ioComp\n }\n\n // consider lowest slippage next, since these are less likely to fail\n if (a.priceImpact.lessThan(b.priceImpact)) {\n return -1\n } else if (a.priceImpact.greaterThan(b.priceImpact)) {\n return 1\n }\n\n // finally consider the number of hops since each hop costs gas\n return a.route.path.length - b.route.path.length\n}\n\nexport interface BestTradeOptions {\n // how many results to return\n maxNumResults?: number\n // the maximum number of hops a trade should contain\n maxHops?: number\n}\n\n/**\n * Represents a trade executed against a list of pairs.\n * Does not account for slippage, i.e. trades that front run this trade and move the price.\n */\nexport class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {\n /**\n * The route of the trade, i.e. which pairs the trade goes through and the input/output currencies.\n */\n public readonly route: Route<TInput, TOutput>\n /**\n * The type of the trade, either exact in or exact out.\n */\n public readonly tradeType: TTradeType\n /**\n * The input amount for the trade assuming no slippage.\n */\n public readonly inputAmount: CurrencyAmount<TInput>\n /**\n * The output amount for the trade assuming no slippage.\n */\n public readonly outputAmount: CurrencyAmount<TOutput>\n /**\n * The price expressed in terms of output amount/input amount.\n */\n public readonly executionPrice: Price<TInput, TOutput>\n /**\n * The percent difference between the mid price before the trade and the trade execution price.\n */\n public readonly priceImpact: Percent\n\n /**\n * Constructs an exact in trade with the given amount in and route\n * @param route route of the exact in trade\n * @param amountIn the amount being passed in\n */\n public static exactIn<TInput extends Currency, TOutput extends Currency>(\n route: Route<TInput, TOutput>,\n amountIn: CurrencyAmount<TInput>\n ): Trade<TInput, TOutput, TradeType.EXACT_INPUT> {\n return new Trade(route, amountIn, TradeType.EXACT_INPUT)\n }\n\n /**\n * Constructs an exact out trade with the given amount out and route\n * @param route route of the exact out trade\n * @param amountOut the amount returned by the trade\n */\n public static exactOut<TInput extends Currency, TOutput extends Currency>(\n route: Route<TInput, TOutput>,\n amountOut: CurrencyAmount<TOutput>\n ): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT> {\n return new Trade(route, amountOut, TradeType.EXACT_OUTPUT)\n }\n\n public constructor(\n route: Route<TInput, TOutput>,\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>,\n tradeType: TTradeType\n ) {\n this.route = route\n this.tradeType = tradeType\n\n const tokenAmounts: CurrencyAmount<Token>[] = new Array(route.path.length)\n if (tradeType === TradeType.EXACT_INPUT) {\n invariant(amount.currency.equals(route.input), 'INPUT')\n tokenAmounts[0] = amount.wrapped\n for (let i = 0; i < route.path.length - 1; i++) {\n const pair = route.pairs[i]\n const [outputAmount] = pair.getOutputAmount(tokenAmounts[i])\n tokenAmounts[i + 1] = outputAmount\n }\n this.inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator)\n this.outputAmount = CurrencyAmount.fromFractionalAmount(\n route.output,\n tokenAmounts[tokenAmounts.length - 1].numerator,\n tokenAmounts[tokenAmounts.length - 1].denominator\n )\n } else {\n invariant(amount.currency.equals(route.output), 'OUTPUT')\n tokenAmounts[tokenAmounts.length - 1] = amount.wrapped\n for (let i = route.path.length - 1; i > 0; i--) {\n const pair = route.pairs[i - 1]\n const [inputAmount] = pair.getInputAmount(tokenAmounts[i])\n tokenAmounts[i - 1] = inputAmount\n }\n this.inputAmount = CurrencyAmount.fromFractionalAmount(\n route.input,\n tokenAmounts[0].numerator,\n tokenAmounts[0].denominator\n )\n this.outputAmount = CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator)\n }\n this.executionPrice = new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.inputAmount.quotient,\n this.outputAmount.quotient\n )\n this.priceImpact = computePriceImpact(route.midPrice, this.inputAmount, this.outputAmount)\n }\n\n /**\n * Get the minimum amount that must be received from this trade for the given slippage tolerance\n * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade\n */\n public minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n if (this.tradeType === TradeType.EXACT_OUTPUT) {\n return this.outputAmount\n } else {\n const slippageAdjustedAmountOut = new Fraction(ONE)\n .add(slippageTolerance)\n .invert()\n .multiply(this.outputAmount.quotient).quotient\n return CurrencyAmount.fromRawAmount(this.outputAmount.currency, slippageAdjustedAmountOut)\n }\n }\n\n /**\n * Get the maximum amount in that can be spent via this trade for the given slippage tolerance\n * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade\n */\n public maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n if (this.tradeType === TradeType.EXACT_INPUT) {\n return this.inputAmount\n } else {\n const slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.quotient)\n .quotient\n return CurrencyAmount.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn)\n }\n }\n\n /**\n * Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token\n * amount to an output token, making at most `maxHops` hops.\n * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting\n * the amount in among multiple routes.\n * @param pairs the pairs to consider in finding the best trade\n * @param nextAmountIn exact amount of input currency to spend\n * @param currencyOut the desired currency out\n * @param maxNumResults maximum number of results to return\n * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair\n * @param currentPairs used in recursion; the current list of pairs\n * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter\n * @param bestTrades used in recursion; the current list of best trades\n */\n public static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(\n pairs: Pair[],\n currencyAmountIn: CurrencyAmount<TInput>,\n currencyOut: TOutput,\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n // used in recursion.\n currentPairs: Pair[] = [],\n nextAmountIn: CurrencyAmount<Currency> = currencyAmountIn,\n bestTrades: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[] = []\n ): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[] {\n invariant(pairs.length > 0, 'PAIRS')\n invariant(maxHops > 0, 'MAX_HOPS')\n invariant(currencyAmountIn === nextAmountIn || currentPairs.length > 0, 'INVALID_RECURSION')\n\n const amountIn = nextAmountIn.wrapped\n const tokenOut = currencyOut.wrapped\n for (let i = 0; i < pairs.length; i++) {\n const pair = pairs[i]\n // pair irrelevant\n if (!pair.token0.equals(amountIn.currency) && !pair.token1.equals(amountIn.currency)) continue\n if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\n\n let amountOut: CurrencyAmount<Token>\n try {\n ;[amountOut] = pair.getOutputAmount(amountIn)\n } catch (error) {\n // input too low\n if (error.isInsufficientInputAmountError) {\n continue\n }\n throw error\n }\n // we have arrived at the output token, so this is the final trade of one of the paths\n if (amountOut.currency.equals(tokenOut)) {\n sortedInsert(\n bestTrades,\n new Trade(\n new Route([...currentPairs, pair], currencyAmountIn.currency, currencyOut),\n currencyAmountIn,\n TradeType.EXACT_INPUT\n ),\n maxNumResults,\n tradeComparator\n )\n } else if (maxHops > 1 && pairs.length > 1) {\n const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length))\n\n // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops\n Trade.bestTradeExactIn(\n pairsExcludingThisPair,\n currencyAmountIn,\n currencyOut,\n {\n maxNumResults,\n maxHops: maxHops - 1\n },\n [...currentPairs, pair],\n amountOut,\n bestTrades\n )\n }\n }\n\n return bestTrades\n }\n\n /**\n * Return the execution price after accounting for slippage tolerance\n * @param slippageTolerance the allowed tolerated slippage\n */\n public worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput> {\n return new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.maximumAmountIn(slippageTolerance).quotient,\n this.minimumAmountOut(slippageTolerance).quotient\n )\n }\n\n /**\n * similar to the above method but instead targets a fixed output amount\n * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token\n * to an output token amount, making at most `maxHops` hops\n * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting\n * the amount in among multiple routes.\n * @param pairs the pairs to consider in finding the best trade\n * @param currencyIn the currency to spend\n * @param nextAmountOut the exact amount of currency out\n * @param maxNumResults maximum number of results to return\n * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair\n * @param currentPairs used in recursion; the current list of pairs\n * @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter\n * @param bestTrades used in recursion; the current list of best trades\n */\n public static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(\n pairs: Pair[],\n currencyIn: TInput,\n currencyAmountOut: CurrencyAmount<TOutput>,\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n // used in recursion.\n currentPairs: Pair[] = [],\n nextAmountOut: CurrencyAmount<Currency> = currencyAmountOut,\n bestTrades: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[] = []\n ): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[] {\n invariant(pairs.length > 0, 'PAIRS')\n invariant(maxHops > 0, 'MAX_HOPS')\n invariant(currencyAmountOut === nextAmountOut || currentPairs.length > 0, 'INVALID_RECURSION')\n\n const amountOut = nextAmountOut.wrapped\n const tokenIn = currencyIn.wrapped\n for (let i = 0; i < pairs.length; i++) {\n const pair = pairs[i]\n // pair irrelevant\n if (!pair.token0.equals(amountOut.currency) && !pair.token1.equals(amountOut.currency)) continue\n if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\n\n let amountIn: CurrencyAmount<Token>\n try {\n ;[amountIn] = pair.getInputAmount(amountOut)\n } catch (error) {\n // not enough liquidity in this pair\n if (error.isInsufficientReservesError) {\n continue\n }\n throw error\n }\n // we have arrived at the input token, so this is the first trade of one of the paths\n if (amountIn.currency.equals(tokenIn)) {\n sortedInsert(\n bestTrades,\n new Trade(\n new Route([pair, ...currentPairs], currencyIn, currencyAmountOut.currency),\n currencyAmountOut,\n TradeType.EXACT_OUTPUT\n ),\n maxNumResults,\n tradeComparator\n )\n } else if (maxHops > 1 && pairs.length > 1) {\n const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length))\n\n // otherwise, consider all the other paths that arrive at this token as long as we have not exceeded maxHops\n Trade.bestTradeExactOut(\n pairsExcludingThisPair,\n currencyIn,\n currencyAmountOut,\n {\n maxNumResults,\n maxHops: maxHops - 1\n },\n [pair, ...currentPairs],\n amountIn,\n bestTrades\n )\n }\n }\n\n return bestTrades\n }\n}\n","import { Token, Currency, CurrencyAmount, Percent, TradeType, validateAndParseAddress } from '@uniswap/sdk-core'\nimport { Trade } from './entities'\nimport invariant from 'tiny-invariant'\n\n/**\n * Options for producing the arguments to send call to the router.\n */\nexport interface TradeOptions {\n /**\n * How much the execution price is allowed to move unfavorably from the trade execution price.\n */\n allowedSlippage: Percent\n /**\n * How long the swap is valid until it expires, in seconds.\n * This will be used to produce a `deadline` parameter which is computed from when the swap call parameters\n * are generated.\n */\n ttl: number\n /**\n * The account that should receive the output of the swap.\n */\n recipient: string\n\n /**\n * Whether any of the tokens in the path are fee on transfer tokens, which should be handled with special methods\n */\n feeOnTransfer?: boolean\n}\n\nexport interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {\n /**\n * When the transaction expires.\n * This is an atlernate to specifying the ttl, for when you do not want to use local time.\n */\n deadline: number\n}\n\n/**\n * The parameters to use in the call to the Uniswap V2 Router to execute a trade.\n */\nexport interface SwapParameters {\n /**\n * The method to call on the Uniswap V2 Router.\n */\n methodName: string\n /**\n * The arguments to pass to the method, all hex encoded.\n */\n args: (string | string[])[]\n /**\n * The amount of wei to send in hex.\n */\n value: string\n}\n\nfunction toHex(currencyAmount: CurrencyAmount<Currency>) {\n return `0x${currencyAmount.quotient.toString(16)}`\n}\n\nconst ZERO_HEX = '0x0'\n\n/**\n * Represents the Uniswap V2 Router, and has static methods for helping execute trades.\n */\nexport abstract class Router {\n /**\n * Cannot be constructed.\n */\n private constructor() {}\n /**\n * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.\n * @param trade to produce call parameters for\n * @param options options for the call parameters\n */\n public static swapCallParameters(\n trade: Trade<Currency, Currency, TradeType>,\n options: TradeOptions | TradeOptionsDeadline\n ): SwapParameters {\n const etherIn = trade.inputAmount.currency.isNative\n const etherOut = trade.outputAmount.currency.isNative\n // the router does not support both ether in and out\n invariant(!(etherIn && etherOut), 'ETHER_IN_OUT')\n invariant(!('ttl' in options) || options.ttl > 0, 'TTL')\n\n const to: string = validateAndParseAddress(options.recipient)\n const amountIn: string = toHex(trade.maximumAmountIn(options.allowedSlippage))\n const amountOut: string = toHex(trade.minimumAmountOut(options.allowedSlippage))\n const path: string[] = trade.route.path.map((token: Token) => token.address)\n const deadline =\n 'ttl' in options\n ? `0x${(Math.floor(new Date().getTime() / 1000) + options.ttl).toString(16)}`\n : `0x${options.deadline.toString(16)}`\n\n const useFeeOnTransfer = Boolean(options.feeOnTransfer)\n\n let methodName: string\n let args: (string | string[])[]\n let value: string\n switch (trade.tradeType) {\n case TradeType.EXACT_INPUT:\n if (etherIn) {\n methodName = useFeeOnTransfer ? 'swapExactETHForTokensSupportingFeeOnTransferTokens' : 'swapExactETHForTokens'\n // (uint amountOutMin, address[] calldata path, address to, uint deadline)\n args = [amountOut, path, to, deadline]\n value = amountIn\n } else if (etherOut) {\n methodName = useFeeOnTransfer ? 'swapExactTokensForETHSupportingFeeOnTransferTokens' : 'swapExactTokensForETH'\n // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)\n args = [amountIn, amountOut, path, to, deadline]\n value = ZERO_HEX\n } else {\n methodName = useFeeOnTransfer\n ? 'swapExactTokensForTokensSupportingFeeOnTransferTokens'\n : 'swapExactTokensForTokens'\n // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)\n args = [amountIn, amountOut, path, to, deadline]\n value = ZERO_HEX\n }\n break\n case TradeType.EXACT_OUTPUT:\n invariant(!useFeeOnTransfer, 'EXACT_OUT_FOT')\n if (etherIn) {\n methodName = 'swapETHForExactTokens'\n // (uint amountOut, address[] calldata path, address to, uint deadline)\n args = [amountOut, path, to, deadline]\n value = amountIn\n } else if (etherOut) {\n methodName = 'swapTokensForExactETH'\n // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)\n args = [amountOut, amountIn, path, to, deadline]\n value = ZERO_HEX\n } else {\n methodName = 'swapTokensForExactTokens'\n // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)\n args = [amountOut, amountIn, path, to, deadline]\n value = ZERO_HEX\n }\n break\n }\n return {\n methodName,\n args,\n value\n }\n }\n}\n"],"names":["FACTORY_ADDRESS","FACTORY_ADDRESS_MAP","V2_FACTORY_ADDRESSES","INIT_CODE_HASH","MINIMUM_LIQUIDITY","JSBI","BigInt","ZERO","ONE","FIVE","_997","_1000","BASIS_POINTS","ZERO_PERCENT","Percent","ONE_HUNDRED_PERCENT","CAN_SET_PROTOTYPE","Object","InsufficientReservesError","name","constructor","setPrototypeOf","prototype","Error","InsufficientInputAmountError","computePairAddress","factoryAddress","tokenA","tokenB","sortsBefore","token0","token1","getCreate2Address","keccak256","pack","address","Pair","currencyAmountA","tokenAmountB","tokenAmounts","currency","liquidityToken","Token","chainId","getAddress","involvesToken","token","equals","priceOf","invariant","token0Price","token1Price","reserveOf","reserve0","reserve1","getOutputAmount","inputAmount","calculateFotFees","equal","quotient","inputReserve","outputReserve","percentAfterSellFees","derivePercentAfterSellFees","inputAmountAfterTax","greaterThan","CurrencyAmount","fromRawAmount","multiply","inputAmountWithFeeAndAfterTax","numerator","denominator","add","outputAmount","divide","percentAfterBuyFees","derivePercentAfterBuyFees","outputAmountAfterTax","subtract","getInputAmount","outputAmountBeforeTax","greaterThanOrEqual","inputAmountBeforeTax","getLiquidityMinted","totalSupply","tokenAmountA","liquidity","sqrt","amount0","amount1","lessThanOrEqual","getLiquidityValue","feeOn","kLast","totalSupplyAdjusted","kLastParsed","rootK","rootKLast","feeLiquidity","sellFeeBips","wrapped","sellFeeBps","gt","BigNumber","from","buyFeeBps","result","Price","Route","pairs","input","output","length","every","pair","wrappedInput","path","entries","i","currentInput","push","_midPrice","prices","reduced","slice","reduce","accumulator","currentValue","inputOutputComparator","a","b","equalTo","lessThan","tradeComparator","ioComp","priceImpact","route","Trade","amount","tradeType","Array","TradeType","EXACT_INPUT","fromFractionalAmount","executionPrice","computePriceImpact","midPrice","exactIn","amountIn","exactOut","amountOut","EXACT_OUTPUT","minimumAmountOut","slippageTolerance","slippageAdjustedAmountOut","Fraction","invert","maximumAmountIn","slippageAdjustedAmountIn","bestTradeExactIn","currencyAmountIn","currencyOut","currentPairs","nextAmountIn","bestTrades","maxNumResults","maxHops","tokenOut","error","isInsufficientInputAmountError","sortedInsert","pairsExcludingThisPair","concat","worstExecutionPrice","bestTradeExactOut","currencyIn","currencyAmountOut","nextAmountOut","tokenIn","isInsufficientReservesError","toHex","currencyAmount","toString","ZERO_HEX","Router","swapCallParameters","trade","options","etherIn","isNative","etherOut","ttl","to","validateAndParseAddress","recipient","allowedSlippage","map","deadline","Math","floor","Date","getTime","useFeeOnTransfer","Boolean","feeOnTransfer","methodName","args","value"],"mappings":";;;;;;;;;;;;;;AAIA;;;;AAGO,IAAMA,eAAe,GAAG,4CAAxB;IAEMC,mBAAmB,GAAkCC;IAErDC,cAAc,GAAG;IAEjBC,iBAAiB,gBAAGC,IAAI,CAACC,MAAL,CAAY,IAAZ;;AAG1B,IAAMC,IAAI,gBAAGF,IAAI,CAACC,MAAL,CAAY,CAAZ,CAAb;AACA,IAAME,GAAG,gBAAGH,IAAI,CAACC,MAAL,CAAY,CAAZ,CAAZ;AACA,IAAMG,IAAI,gBAAGJ,IAAI,CAACC,MAAL,CAAY,CAAZ,CAAb;AACA,IAAMI,IAAI,gBAAGL,IAAI,CAACC,MAAL,CAAY,GAAZ,CAAb;AACA,IAAMK,KAAK,gBAAGN,IAAI,CAAC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;AACLsB,MAAAA,UAAU,EAAVA,UADK;AAELC,MAAAA,IAAI,EAAJA,IAFK;AAGLC,MAAAA,KAAK,EAALA;AAHK,KAAP;AAKD,GAhFH;;AAAA;AAAA;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ "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=require("novaswap-core-sdk"),n=t(require("jsbi")),u=require("@ethersproject/address"),o=require("@ethersproject/bignumber"),i=require("@ethersproject/solidity"),s=t(require("tiny-invariant")),a=r.V2_FACTORY_ADDRESSES,c="0x0ef7ca4700ff7e705236379af2cdac62d4fa0bbd010fb163697b63379941118e",p=n.BigInt(1e3),l=n.BigInt(0),m=n.BigInt(1),f=n.BigInt(5),h=n.BigInt(997),d=n.BigInt(1e3),y=n.BigInt(1e4),v=new e.Percent(l),A=new e.Percent(m);function T(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 q(t,e,r){return e&&T(t.prototype,e),r&&T(t,r),t}function k(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,t.__proto__=e}function w(t){return(w=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function g(t,e){return(g=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function b(){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 I(t,e,r){return(I=b()?Reflect.construct:function(t,e,r){var n=[null];n.push.apply(n,e);var u=new(Function.bind.apply(t,n));return r&&g(u,r.prototype),u}).apply(null,arguments)}function O(t){var e="function"==typeof Map?new Map:void 0;return(O=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 I(t,arguments,w(this).constructor)}return r.prototype=Object.create(t.prototype,{constructor:{value:r,enumerable:!1,writable:!0,configurable:!0}}),g(r,t)})(t)}function x(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}function P(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 E(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 P(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)?P(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 C="setPrototypeOf"in Object,_=function(t){function e(){var r;return(r=t.call(this)||this).isInsufficientReservesError=!0,r.name=r.constructor.name,C&&Object.setPrototypeOf(x(r),(this instanceof e?this.constructor:void 0).prototype),r}return k(e,t),e}(O(Error)),F=function(t){function e(){var r;return(r=t.call(this)||this).isInsufficientInputAmountError=!0,r.name=r.constructor.name,C&&Object.setPrototypeOf(x(r),(this instanceof e?this.constructor:void 0).prototype),r}return k(e,t),e}(O(Error)),R=function(t){var e=t.factoryAddress,r=t.tokenA,n=t.tokenB,o=r.sortsBefore(n)?[r,n]:[n,r];return u.getCreate2Address(e,i.keccak256(["bytes"],[i.pack(["address","address"],[o[0].address,o[1].address])]),c)},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){var r,n=null!=(r=a[t.chainId])?r:"0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f";return R({factoryAddress:n,tokenA:t,tokenB:e})};var r=t.prototype;return r.involvesToken=function(t){return t.equals(this.token0)||t.equals(this.token1)},r.priceOf=function(t){return this.involvesToken(t)||s(!1),t.equals(this.token0)?this.token0Price:this.token1Price},r.reserveOf=function(t){return this.involvesToken(t)||s(!1),t.equals(this.token0)?this.reserve0:this.reserve1},r.getOutputAmount=function(r,u){if(void 0===u&&(u=!0),this.involvesToken(r.currency)||s(!1),n.equal(this.reserve0.quotient,l)||n.equal(this.reserve1.quotient,l))throw new _;var o=this.reserveOf(r.currency),i=this.reserveOf(r.currency.equals(this.token0)?this.token1:this.token0),a=u?this.derivePercentAfterSellFees(r):v,c=a.greaterThan(v)?e.CurrencyAmount.fromRawAmount(r.currency,a.multiply(r).quotient):r,p=n.multiply(c.quotient,h),m=n.multiply(p,i.quotient),f=n.add(n.multiply(o.quotient,d),p),y=e.CurrencyAmount.fromRawAmount(r.currency.equals(this.token0)?this.token1:this.token0,n.divide(m,f));if(n.equal(y.quotient,l))throw new F;var A=u?this.derivePercentAfterBuyFees(y):v,T=A.greaterThan(v)?e.CurrencyAmount.fromRawAmount(y.currency,y.multiply(A).quotient):y;if(n.equal(T.quotient,l))throw new F;return[T,new t(o.add(c),i.subtract(T))]},r.getInputAmount=function(r,u){void 0===u&&(u=!0),this.involvesToken(r.currency)||s(!1);var o=u?this.derivePercentAfterBuyFees(r):v,i=o.greaterThan(v)?e.CurrencyAmount.fromRawAmount(r.currency,n.add(r.divide(o).quotient,m)):r;if(n.equal(this.reserve0.quotient,l)||n.equal(this.reserve1.quotient,l)||n.greaterThanOrEqual(r.quotient,this.reserveOf(r.currency).quotient)||n.greaterThanOrEqual(i.quotient,this.reserveOf(r.currency).quotient))throw new _;var a=this.reserveOf(r.currency),c=this.reserveOf(r.currency.equals(this.token0)?this.token1:this.token0),p=n.multiply(n.multiply(c.quotient,i.quotient),d),f=n.multiply(n.subtract(a.quotient,i.quotient),h),y=e.CurrencyAmount.fromRawAmount(r.currency.equals(this.token0)?this.token1:this.token0,n.add(n.divide(p,f),m)),A=u?this.derivePercentAfterSellFees(y):v;return[A.greaterThan(v)?e.CurrencyAmount.fromRawAmount(y.currency,n.add(y.divide(A).quotient,m)):y,new t(c.add(y),a.subtract(r))]},r.getLiquidityMinted=function(t,r,u){t.currency.equals(this.liquidityToken)||s(!1);var o,i=r.currency.sortsBefore(u.currency)?[r,u]:[u,r];if(i[0].currency.equals(this.token0)&&i[1].currency.equals(this.token1)||s(!1),n.equal(t.quotient,l))o=n.subtract(e.sqrt(n.multiply(i[0].quotient,i[1].quotient)),p);else{var a=n.divide(n.multiply(i[0].quotient,t.quotient),this.reserve0.quotient),c=n.divide(n.multiply(i[1].quotient,t.quotient),this.reserve1.quotient);o=n.lessThanOrEqual(a,c)?a:c}if(!n.greaterThan(o,l))throw new F;return e.CurrencyAmount.fromRawAmount(this.liquidityToken,o)},r.getLiquidityValue=function(t,r,u,o,i){var a;if(void 0===o&&(o=!1),this.involvesToken(t)||s(!1),r.currency.equals(this.liquidityToken)||s(!1),u.currency.equals(this.liquidityToken)||s(!1),n.lessThanOrEqual(u.quotient,r.quotient)||s(!1),o){i||s(!1);var c=n.BigInt(i);if(n.equal(c,l))a=r;else{var p=e.sqrt(n.multiply(this.reserve0.quotient,this.reserve1.quotient)),m=e.sqrt(c);if(n.greaterThan(p,m)){var h=n.multiply(r.quotient,n.subtract(p,m)),d=n.add(n.multiply(p,f),m),y=n.divide(h,d);a=r.add(e.CurrencyAmount.fromRawAmount(this.liquidityToken,y))}else a=r}}else a=r;return e.CurrencyAmount.fromRawAmount(t,n.divide(n.multiply(u.quotient,this.reserveOf(t).quotient),a.quotient))},r.derivePercentAfterSellFees=function(t){var r=this.token0.wrapped.equals(t.wrapped.currency)?this.token0.wrapped.sellFeeBps:this.token1.wrapped.sellFeeBps;return null!=r&&r.gt(o.BigNumber.from(0))?A.subtract(new e.Percent(n.BigInt(r)).divide(y)):v},r.derivePercentAfterBuyFees=function(t){var r=this.token0.wrapped.equals(t.wrapped.currency)?this.token0.wrapped.buyFeeBps:this.token1.wrapped.buyFeeBps;return null!=r&&r.gt(o.BigNumber.from(0))?A.subtract(new e.Percent(n.BigInt(r)).divide(y)):v},q(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}(),S=function(){function t(t,e,r){this._midPrice=null,t.length>0||s(!1);var n=t[0].chainId;t.every((function(t){return t.chainId===n}))||s(!1);var u=e.wrapped;t[0].involvesToken(u)||s(!1),void 0===r||t[t.length-1].involvesToken(r.wrapped)||s(!1);for(var o,i=[u],a=E(t.entries());!(o=a()).done;){var c=o.value,p=c[1],l=i[c[0]];l.equals(p.token0)||l.equals(p.token1)||s(!1);var m=l.equals(p.token0)?p.token1:p.token0;i.push(m)}this.pairs=t,this.path=i,this.input=e,this.output=r}return q(t,[{key:"midPrice",get:function(){if(null!==this._midPrice)return this._midPrice;for(var t,r=[],n=E(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 j(t,e){return t.inputAmount.currency.equals(e.inputAmount.currency)||s(!1),t.outputAmount.currency.equals(e.outputAmount.currency)||s(!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 U(t,e){var r=j(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 N=function(){function t(t,r,n){this.route=t,this.tradeType=n;var u=new Array(t.path.length);if(n===e.TradeType.EXACT_INPUT){r.currency.equals(t.input)||s(!1),u[0]=r.wrapped;for(var o=0;o<t.path.length-1;o++){var i=t.pairs[o].getOutputAmount(u[o]);u[o+1]=i[0]}this.inputAmount=e.CurrencyAmount.fromFractionalAmount(t.input,r.numerator,r.denominator),this.outputAmount=e.CurrencyAmount.fromFractionalAmount(t.output,u[u.length-1].numerator,u[u.length-1].denominator)}else{r.currency.equals(t.output)||s(!1),u[u.length-1]=r.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=e.CurrencyAmount.fromFractionalAmount(t.input,u[0].numerator,u[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(l)&&s(!1),this.tradeType===e.TradeType.EXACT_OUTPUT)return this.outputAmount;var r=new e.Fraction(m).add(t).invert().multiply(this.outputAmount.quotient).quotient;return e.CurrencyAmount.fromRawAmount(this.outputAmount.currency,r)},r.maximumAmountIn=function(t){if(t.lessThan(l)&&s(!1),this.tradeType===e.TradeType.EXACT_INPUT)return this.inputAmount;var r=new e.Fraction(m).add(t).multiply(this.inputAmount.quotient).quotient;return e.CurrencyAmount.fromRawAmount(this.inputAmount.currency,r)},t.bestTradeExactIn=function(r,n,u,o,i,a,c){var p=void 0===o?{}:o,m=p.maxNumResults,f=void 0===m?3:m,h=p.maxHops,d=void 0===h?3:h;void 0===i&&(i=[]),void 0===a&&(a=n),void 0===c&&(c=[]),r.length>0||s(!1),d>0||s(!1),n===a||i.length>0||s(!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(l)&&!T.reserve1.equalTo(l)){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(c,new t(new S([].concat(i,[T]),n.currency,u),n,e.TradeType.EXACT_INPUT),f,U);else if(d>1&&r.length>1){var k=r.slice(0,A).concat(r.slice(A+1,r.length));t.bestTradeExactIn(k,n,u,{maxNumResults:f,maxHops:d-1},[].concat(i,[T]),q,c)}}}return c},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,n,u,o,i,a,c){var p=void 0===o?{}:o,m=p.maxNumResults,f=void 0===m?3:m,h=p.maxHops,d=void 0===h?3:h;void 0===i&&(i=[]),void 0===a&&(a=u),void 0===c&&(c=[]),r.length>0||s(!1),d>0||s(!1),u===a||i.length>0||s(!1);for(var y=a.wrapped,v=n.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(l)&&!T.reserve1.equalTo(l)){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(c,new t(new S([T].concat(i),n,u.currency),u,e.TradeType.EXACT_OUTPUT),f,U);else if(d>1&&r.length>1){var k=r.slice(0,A).concat(r.slice(A+1,r.length));t.bestTradeExactOut(k,n,u,{maxNumResults:f,maxHops:d-1},[T].concat(i),q,c)}}}return c},t}();function H(t){return"0x"+t.quotient.toString(16)}var D=function(){function t(){}return t.swapCallParameters=function(t,r){var n=t.inputAmount.currency.isNative,u=t.outputAmount.currency.isNative;n&&u&&s(!1),!("ttl"in r)||r.ttl>0||s(!1);var o,i,a,c=e.validateAndParseAddress(r.recipient),p=H(t.maximumAmountIn(r.allowedSlippage)),l=H(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:n?(o=h?"swapExactETHForTokensSupportingFeeOnTransferTokens":"swapExactETHForTokens",i=[l,m,c,f],a=p):u?(o=h?"swapExactTokensForETHSupportingFeeOnTransferTokens":"swapExactTokensForETH",i=[p,l,m,c,f],a="0x0"):(o=h?"swapExactTokensForTokensSupportingFeeOnTransferTokens":"swapExactTokensForTokens",i=[p,l,m,c,f],a="0x0");break;case e.TradeType.EXACT_OUTPUT:h&&s(!1),n?(o="swapETHForExactTokens",i=[l,m,c,f],a=p):u?(o="swapTokensForExactETH",i=[l,p,m,c,f],a="0x0"):(o="swapTokensForExactTokens",i=[l,p,m,c,f],a="0x0")}return{methodName:o,args:i,value:a}},t}();exports.FACTORY_ADDRESS_MAP=a,exports.INIT_CODE_HASH=c,exports.InsufficientInputAmountError=F,exports.InsufficientReservesError=_,exports.MINIMUM_LIQUIDITY=p,exports.Pair=B,exports.Route=S,exports.Router=D,exports.Trade=N,exports.computePairAddress=R,exports.inputOutputComparator=j,exports.tradeComparator=U;
2
+ //# sourceMappingURL=novaswap-v2-sdk.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"novaswap-v2-sdk.cjs.production.min.js","sources":["../src/constants.ts","../src/errors.ts","../src/entities/pair.ts","../src/entities/route.ts","../src/entities/trade.ts","../src/router.ts"],"sourcesContent":["import { Percent} from '@uniswap/sdk-core'\nimport {V2_FACTORY_ADDRESSES } from 'novaswap-core-sdk'\nimport JSBI from 'jsbi'\n\n/**\n * @deprecated use FACTORY_ADDRESS_MAP instead\n */\nexport const FACTORY_ADDRESS = '0x5C69bEe701ef814a2B6a3EDD4B1652CB9cc5aA6f'\n\nexport const FACTORY_ADDRESS_MAP: { [chainId: number]: string } = V2_FACTORY_ADDRESSES\n\nexport const INIT_CODE_HASH = '0x0ef7ca4700ff7e705236379af2cdac62d4fa0bbd010fb163697b63379941118e'\n\nexport const MINIMUM_LIQUIDITY = JSBI.BigInt(1000)\n\n// exports for internal consumption\nexport const ZERO = JSBI.BigInt(0)\nexport const ONE = JSBI.BigInt(1)\nexport const FIVE = JSBI.BigInt(5)\nexport const _997 = JSBI.BigInt(997)\nexport const _1000 = JSBI.BigInt(1000)\nexport const BASIS_POINTS = JSBI.BigInt(10000)\n\nexport const ZERO_PERCENT = new Percent(ZERO)\nexport const ONE_HUNDRED_PERCENT = new Percent(ONE)\n","// see https://stackoverflow.com/a/41102306\nconst CAN_SET_PROTOTYPE = 'setPrototypeOf' in Object\n\n/**\n * Indicates that the pair has insufficient reserves for a desired output amount. I.e. the amount of output cannot be\n * obtained by sending any amount of input.\n */\nexport class InsufficientReservesError extends Error {\n public readonly isInsufficientReservesError: true = true\n\n public constructor() {\n super()\n this.name = this.constructor.name\n if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(this, new.target.prototype)\n }\n}\n\n/**\n * Indicates that the input amount is too small to produce any amount of output. I.e. the amount of input sent is less\n * than the price of a single unit of output after fees.\n */\nexport class InsufficientInputAmountError extends Error {\n public readonly isInsufficientInputAmountError: true = true\n\n public constructor() {\n super()\n this.name = this.constructor.name\n if (CAN_SET_PROTOTYPE) Object.setPrototypeOf(this, new.target.prototype)\n }\n}\n","import { getCreate2Address } from '@ethersproject/address'\nimport { BigNumber } from '@ethersproject/bignumber'\nimport { keccak256, pack } from '@ethersproject/solidity'\nimport { BigintIsh, CurrencyAmount, Percent, Price, sqrt, Token } from '@uniswap/sdk-core'\nimport JSBI from 'jsbi'\nimport invariant from 'tiny-invariant'\n\nimport {\n _1000,\n _997,\n BASIS_POINTS,\n FACTORY_ADDRESS,\n FACTORY_ADDRESS_MAP,\n FIVE,\n INIT_CODE_HASH,\n MINIMUM_LIQUIDITY,\n ONE,\n ONE_HUNDRED_PERCENT,\n ZERO,\n ZERO_PERCENT\n} from '../constants'\nimport { InsufficientInputAmountError, InsufficientReservesError } from '../errors'\n\nexport const computePairAddress = ({\n factoryAddress,\n tokenA,\n tokenB\n}: {\n factoryAddress: string\n tokenA: Token\n tokenB: Token\n}): string => {\n const [token0, token1] = tokenA.sortsBefore(tokenB) ? [tokenA, tokenB] : [tokenB, tokenA] // does safety checks\n return getCreate2Address(\n factoryAddress,\n keccak256(['bytes'], [pack(['address', 'address'], [token0.address, token1.address])]),\n INIT_CODE_HASH\n )\n}\nexport class Pair {\n public readonly liquidityToken: Token\n private readonly tokenAmounts: [CurrencyAmount<Token>, CurrencyAmount<Token>]\n\n public static getAddress(tokenA: Token, tokenB: Token): string {\n const factoryAddress = FACTORY_ADDRESS_MAP[tokenA.chainId] ?? FACTORY_ADDRESS\n return computePairAddress({ factoryAddress, tokenA, tokenB })\n }\n\n public constructor(currencyAmountA: CurrencyAmount<Token>, tokenAmountB: CurrencyAmount<Token>) {\n const tokenAmounts = currencyAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks\n ? [currencyAmountA, tokenAmountB]\n : [tokenAmountB, currencyAmountA]\n this.liquidityToken = new Token(\n tokenAmounts[0].currency.chainId,\n Pair.getAddress(tokenAmounts[0].currency, tokenAmounts[1].currency),\n 18,\n 'UNI-V2',\n 'Uniswap V2'\n )\n this.tokenAmounts = tokenAmounts as [CurrencyAmount<Token>, CurrencyAmount<Token>]\n }\n\n /**\n * Returns true if the token is either token0 or token1\n * @param token to check\n */\n public involvesToken(token: Token): boolean {\n return token.equals(this.token0) || token.equals(this.token1)\n }\n\n /**\n * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0\n */\n public get token0Price(): Price<Token, Token> {\n const result = this.tokenAmounts[1].divide(this.tokenAmounts[0])\n return new Price(this.token0, this.token1, result.denominator, result.numerator)\n }\n\n /**\n * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1\n */\n public get token1Price(): Price<Token, Token> {\n const result = this.tokenAmounts[0].divide(this.tokenAmounts[1])\n return new Price(this.token1, this.token0, result.denominator, result.numerator)\n }\n\n /**\n * Return the price of the given token in terms of the other token in the pair.\n * @param token token to return price of\n */\n public priceOf(token: Token): Price<Token, Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n return token.equals(this.token0) ? this.token0Price : this.token1Price\n }\n\n /**\n * Returns the chain ID of the tokens in the pair.\n */\n public get chainId(): number {\n return this.token0.chainId\n }\n\n public get token0(): Token {\n return this.tokenAmounts[0].currency\n }\n\n public get token1(): Token {\n return this.tokenAmounts[1].currency\n }\n\n public get reserve0(): CurrencyAmount<Token> {\n return this.tokenAmounts[0]\n }\n\n public get reserve1(): CurrencyAmount<Token> {\n return this.tokenAmounts[1]\n }\n\n public reserveOf(token: Token): CurrencyAmount<Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n return token.equals(this.token0) ? this.reserve0 : this.reserve1\n }\n\n /**\n * getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut.\n * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000\n * has the math deduction for the reserve calculation without fee-on-transfer fees.\n *\n * With fee-on-transfer tax, intuitively it's just:\n * inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn\n * = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee\n * where amountInWithFee is the amountIn after taking out the LP fees\n * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)\n *\n * But we are illustrating the math deduction below to ensure that's the case.\n *\n * before swap A * B = K where A = reserveIn B = reserveOut\n *\n * after swap A' * B' = K where only k is a constant value\n *\n * getAmountOut\n *\n * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted\n * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)\n * amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k\n * = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))\n * /\n * (1 - amountOut.buyFeesBips / 10000)\n * = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))\n * /\n * (1 - amountOut.buyFeesBips / 10000)\n * = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn))\n * /\n * (1 - amountOut.buyFeesBips / 10000)\n * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)\n * /\n * (1 - amountOut.buyFeesBips / 10000)\n * amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn\n * /\n * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)\n *\n * outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn\n * /\n * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)\n * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000\n * /\n * ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000)\n * = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn\n * /\n * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn)\n * = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)\n * /\n * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee)\n * = (B * inputAmountWithFeeAndTax)\n * /\n * (1000 * A + inputAmountWithFeeAndTax)\n *\n * inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee\n * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000)\n *\n * @param inputAmount\n * @param calculateFotFees\n */\n public getOutputAmount(\n inputAmount: CurrencyAmount<Token>,\n calculateFotFees: boolean = true\n ): [CurrencyAmount<Token>, Pair] {\n invariant(this.involvesToken(inputAmount.currency), 'TOKEN')\n if (JSBI.equal(this.reserve0.quotient, ZERO) || JSBI.equal(this.reserve1.quotient, ZERO)) {\n throw new InsufficientReservesError()\n }\n const inputReserve = this.reserveOf(inputAmount.currency)\n const outputReserve = this.reserveOf(inputAmount.currency.equals(this.token0) ? this.token1 : this.token0)\n\n const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : ZERO_PERCENT\n const inputAmountAfterTax = percentAfterSellFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(\n inputAmount.currency,\n percentAfterSellFees.multiply(inputAmount).quotient // fraction.quotient will round down by itself, which is desired\n )\n : inputAmount\n\n const inputAmountWithFeeAndAfterTax = JSBI.multiply(inputAmountAfterTax.quotient, _997)\n const numerator = JSBI.multiply(inputAmountWithFeeAndAfterTax, outputReserve.quotient)\n const denominator = JSBI.add(JSBI.multiply(inputReserve.quotient, _1000), inputAmountWithFeeAndAfterTax)\n const outputAmount = CurrencyAmount.fromRawAmount(\n inputAmount.currency.equals(this.token0) ? this.token1 : this.token0,\n JSBI.divide(numerator, denominator) // JSBI.divide will round down by itself, which is desired\n )\n\n if (JSBI.equal(outputAmount.quotient, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n\n const percentAfterBuyFees = calculateFotFees ? this.derivePercentAfterBuyFees(outputAmount) : ZERO_PERCENT\n const outputAmountAfterTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(\n outputAmount.currency,\n outputAmount.multiply(percentAfterBuyFees).quotient // fraction.quotient will round down by itself, which is desired\n )\n : outputAmount\n if (JSBI.equal(outputAmountAfterTax.quotient, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n\n return [\n outputAmountAfterTax,\n new Pair(inputReserve.add(inputAmountAfterTax), outputReserve.subtract(outputAmountAfterTax))\n ]\n }\n\n /**\n * getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut.\n * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000\n * has the math deduction for the reserve calculation without fee-on-transfer fees.\n *\n * With fee-on-transfer fees, intuitively it's just:\n * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)\n * inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997\n *\n * But we are illustrating the math deduction below to ensure that's the case.\n *\n * before swap A * B = K where A = reserveIn B = reserveOut\n *\n * after swap A' * B' = K where only k is a constant value\n *\n * getAmountIn\n *\n * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000)\n * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted\n * amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)\n * /\n * (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A)\n * /\n * (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))\n * /\n * (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))\n * /\n * (0.997 * (1 - amountIn.sellFeesBips / 10000))\n * = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)))\n * /\n * (997 * (1 - amountIn.sellFeesBips / 10000))\n *\n * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000)\n * inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000))\n * = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997)\n *\n * @param outputAmount\n */\n public getInputAmount(\n outputAmount: CurrencyAmount<Token>,\n calculateFotFees: boolean = true\n ): [CurrencyAmount<Token>, Pair] {\n invariant(this.involvesToken(outputAmount.currency), 'TOKEN')\n const percentAfterBuyFees = calculateFotFees ? this.derivePercentAfterBuyFees(outputAmount) : ZERO_PERCENT\n const outputAmountBeforeTax = percentAfterBuyFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(\n outputAmount.currency,\n JSBI.add(outputAmount.divide(percentAfterBuyFees).quotient, ONE) // add 1 for rounding up\n )\n : outputAmount\n\n if (\n JSBI.equal(this.reserve0.quotient, ZERO) ||\n JSBI.equal(this.reserve1.quotient, ZERO) ||\n JSBI.greaterThanOrEqual(outputAmount.quotient, this.reserveOf(outputAmount.currency).quotient) ||\n JSBI.greaterThanOrEqual(outputAmountBeforeTax.quotient, this.reserveOf(outputAmount.currency).quotient)\n ) {\n throw new InsufficientReservesError()\n }\n\n const outputReserve = this.reserveOf(outputAmount.currency)\n const inputReserve = this.reserveOf(outputAmount.currency.equals(this.token0) ? this.token1 : this.token0)\n\n const numerator = JSBI.multiply(JSBI.multiply(inputReserve.quotient, outputAmountBeforeTax.quotient), _1000)\n const denominator = JSBI.multiply(JSBI.subtract(outputReserve.quotient, outputAmountBeforeTax.quotient), _997)\n const inputAmount = CurrencyAmount.fromRawAmount(\n outputAmount.currency.equals(this.token0) ? this.token1 : this.token0,\n 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\n )\n\n const percentAfterSellFees = calculateFotFees ? this.derivePercentAfterSellFees(inputAmount) : ZERO_PERCENT\n const inputAmountBeforeTax = percentAfterSellFees.greaterThan(ZERO_PERCENT)\n ? CurrencyAmount.fromRawAmount(\n inputAmount.currency,\n JSBI.add(inputAmount.divide(percentAfterSellFees).quotient, ONE) // add 1 for rounding up\n )\n : inputAmount\n return [inputAmountBeforeTax, new Pair(inputReserve.add(inputAmount), outputReserve.subtract(outputAmount))]\n }\n\n public getLiquidityMinted(\n totalSupply: CurrencyAmount<Token>,\n tokenAmountA: CurrencyAmount<Token>,\n tokenAmountB: CurrencyAmount<Token>\n ): CurrencyAmount<Token> {\n invariant(totalSupply.currency.equals(this.liquidityToken), 'LIQUIDITY')\n const tokenAmounts = tokenAmountA.currency.sortsBefore(tokenAmountB.currency) // does safety checks\n ? [tokenAmountA, tokenAmountB]\n : [tokenAmountB, tokenAmountA]\n invariant(tokenAmounts[0].currency.equals(this.token0) && tokenAmounts[1].currency.equals(this.token1), 'TOKEN')\n\n let liquidity: JSBI\n if (JSBI.equal(totalSupply.quotient, ZERO)) {\n liquidity = JSBI.subtract(\n sqrt(JSBI.multiply(tokenAmounts[0].quotient, tokenAmounts[1].quotient)),\n MINIMUM_LIQUIDITY\n )\n } else {\n const amount0 = JSBI.divide(JSBI.multiply(tokenAmounts[0].quotient, totalSupply.quotient), this.reserve0.quotient)\n const amount1 = JSBI.divide(JSBI.multiply(tokenAmounts[1].quotient, totalSupply.quotient), this.reserve1.quotient)\n liquidity = JSBI.lessThanOrEqual(amount0, amount1) ? amount0 : amount1\n }\n if (!JSBI.greaterThan(liquidity, ZERO)) {\n throw new InsufficientInputAmountError()\n }\n return CurrencyAmount.fromRawAmount(this.liquidityToken, liquidity)\n }\n\n public getLiquidityValue(\n token: Token,\n totalSupply: CurrencyAmount<Token>,\n liquidity: CurrencyAmount<Token>,\n feeOn: boolean = false,\n kLast?: BigintIsh\n ): CurrencyAmount<Token> {\n invariant(this.involvesToken(token), 'TOKEN')\n invariant(totalSupply.currency.equals(this.liquidityToken), 'TOTAL_SUPPLY')\n invariant(liquidity.currency.equals(this.liquidityToken), 'LIQUIDITY')\n invariant(JSBI.lessThanOrEqual(liquidity.quotient, totalSupply.quotient), 'LIQUIDITY')\n\n let totalSupplyAdjusted: CurrencyAmount<Token>\n if (!feeOn) {\n totalSupplyAdjusted = totalSupply\n } else {\n invariant(!!kLast, 'K_LAST')\n const kLastParsed = JSBI.BigInt(kLast)\n if (!JSBI.equal(kLastParsed, ZERO)) {\n const rootK = sqrt(JSBI.multiply(this.reserve0.quotient, this.reserve1.quotient))\n const rootKLast = sqrt(kLastParsed)\n if (JSBI.greaterThan(rootK, rootKLast)) {\n const numerator = JSBI.multiply(totalSupply.quotient, JSBI.subtract(rootK, rootKLast))\n const denominator = JSBI.add(JSBI.multiply(rootK, FIVE), rootKLast)\n const feeLiquidity = JSBI.divide(numerator, denominator)\n totalSupplyAdjusted = totalSupply.add(CurrencyAmount.fromRawAmount(this.liquidityToken, feeLiquidity))\n } else {\n totalSupplyAdjusted = totalSupply\n }\n } else {\n totalSupplyAdjusted = totalSupply\n }\n }\n\n return CurrencyAmount.fromRawAmount(\n token,\n JSBI.divide(JSBI.multiply(liquidity.quotient, this.reserveOf(token).quotient), totalSupplyAdjusted.quotient)\n )\n }\n\n private derivePercentAfterSellFees(inputAmount: CurrencyAmount<Token>): Percent {\n const sellFeeBips = this.token0.wrapped.equals(inputAmount.wrapped.currency)\n ? this.token0.wrapped.sellFeeBps\n : this.token1.wrapped.sellFeeBps\n if (sellFeeBips?.gt(BigNumber.from(0))) {\n return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(sellFeeBips)).divide(BASIS_POINTS))\n } else {\n return ZERO_PERCENT\n }\n }\n\n private derivePercentAfterBuyFees(outputAmount: CurrencyAmount<Token>): Percent {\n const buyFeeBps = this.token0.wrapped.equals(outputAmount.wrapped.currency)\n ? this.token0.wrapped.buyFeeBps\n : this.token1.wrapped.buyFeeBps\n if (buyFeeBps?.gt(BigNumber.from(0))) {\n return ONE_HUNDRED_PERCENT.subtract(new Percent(JSBI.BigInt(buyFeeBps)).divide(BASIS_POINTS))\n } else {\n return ZERO_PERCENT\n }\n }\n}\n","import invariant from 'tiny-invariant'\nimport { Currency, Price, Token } from '@uniswap/sdk-core'\n\nimport { Pair } from './pair'\n\nexport class Route<TInput extends Currency, TOutput extends Currency> {\n public readonly pairs: Pair[]\n public readonly path: Token[]\n public readonly input: TInput\n public readonly output: TOutput\n\n public constructor(pairs: Pair[], input: TInput, output: TOutput) {\n invariant(pairs.length > 0, 'PAIRS')\n const chainId: number = pairs[0].chainId\n invariant(\n pairs.every(pair => pair.chainId === chainId),\n 'CHAIN_IDS'\n )\n\n const wrappedInput = input.wrapped\n invariant(pairs[0].involvesToken(wrappedInput), 'INPUT')\n invariant(typeof output === 'undefined' || pairs[pairs.length - 1].involvesToken(output.wrapped), 'OUTPUT')\n\n const path: Token[] = [wrappedInput]\n for (const [i, pair] of pairs.entries()) {\n const currentInput = path[i]\n invariant(currentInput.equals(pair.token0) || currentInput.equals(pair.token1), 'PATH')\n const output = currentInput.equals(pair.token0) ? pair.token1 : pair.token0\n path.push(output)\n }\n\n this.pairs = pairs\n this.path = path\n this.input = input\n this.output = output\n }\n\n private _midPrice: Price<TInput, TOutput> | null = null\n\n public get midPrice(): Price<TInput, TOutput> {\n if (this._midPrice !== null) return this._midPrice\n const prices: Price<Currency, Currency>[] = []\n for (const [i, pair] of this.pairs.entries()) {\n prices.push(\n this.path[i].equals(pair.token0)\n ? new Price(pair.reserve0.currency, pair.reserve1.currency, pair.reserve0.quotient, pair.reserve1.quotient)\n : new Price(pair.reserve1.currency, pair.reserve0.currency, pair.reserve1.quotient, pair.reserve0.quotient)\n )\n }\n const reduced = prices.slice(1).reduce((accumulator, currentValue) => accumulator.multiply(currentValue), prices[0])\n return (this._midPrice = new Price(this.input, this.output, reduced.denominator, reduced.numerator))\n }\n\n public get chainId(): number {\n return this.pairs[0].chainId\n }\n}\n","import {\n computePriceImpact,\n Token,\n Currency,\n CurrencyAmount,\n Fraction,\n Percent,\n Price,\n sortedInsert,\n TradeType\n} from '@uniswap/sdk-core'\nimport { ONE, ZERO } from '../constants'\nimport invariant from 'tiny-invariant'\n\nimport { Pair } from './pair'\nimport { Route } from './route'\n\n// minimal interface so the input output comparator may be shared across types\ninterface InputOutput<TInput extends Currency, TOutput extends Currency> {\n readonly inputAmount: CurrencyAmount<TInput>\n readonly outputAmount: CurrencyAmount<TOutput>\n}\n\n// comparator function that allows sorting trades by their output amounts, in decreasing order, and then input amounts\n// in increasing order. i.e. the best trades have the most outputs for the least inputs and are sorted first\nexport function inputOutputComparator<TInput extends Currency, TOutput extends Currency>(\n a: InputOutput<TInput, TOutput>,\n b: InputOutput<TInput, TOutput>\n): number {\n // must have same input and output token for comparison\n invariant(a.inputAmount.currency.equals(b.inputAmount.currency), 'INPUT_CURRENCY')\n invariant(a.outputAmount.currency.equals(b.outputAmount.currency), 'OUTPUT_CURRENCY')\n if (a.outputAmount.equalTo(b.outputAmount)) {\n if (a.inputAmount.equalTo(b.inputAmount)) {\n return 0\n }\n // trade A requires less input than trade B, so A should come first\n if (a.inputAmount.lessThan(b.inputAmount)) {\n return -1\n } else {\n return 1\n }\n } else {\n // tradeA has less output than trade B, so should come second\n if (a.outputAmount.lessThan(b.outputAmount)) {\n return 1\n } else {\n return -1\n }\n }\n}\n\n// extension of the input output comparator that also considers other dimensions of the trade in ranking them\nexport function tradeComparator<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType>(\n a: Trade<TInput, TOutput, TTradeType>,\n b: Trade<TInput, TOutput, TTradeType>\n) {\n const ioComp = inputOutputComparator(a, b)\n if (ioComp !== 0) {\n return ioComp\n }\n\n // consider lowest slippage next, since these are less likely to fail\n if (a.priceImpact.lessThan(b.priceImpact)) {\n return -1\n } else if (a.priceImpact.greaterThan(b.priceImpact)) {\n return 1\n }\n\n // finally consider the number of hops since each hop costs gas\n return a.route.path.length - b.route.path.length\n}\n\nexport interface BestTradeOptions {\n // how many results to return\n maxNumResults?: number\n // the maximum number of hops a trade should contain\n maxHops?: number\n}\n\n/**\n * Represents a trade executed against a list of pairs.\n * Does not account for slippage, i.e. trades that front run this trade and move the price.\n */\nexport class Trade<TInput extends Currency, TOutput extends Currency, TTradeType extends TradeType> {\n /**\n * The route of the trade, i.e. which pairs the trade goes through and the input/output currencies.\n */\n public readonly route: Route<TInput, TOutput>\n /**\n * The type of the trade, either exact in or exact out.\n */\n public readonly tradeType: TTradeType\n /**\n * The input amount for the trade assuming no slippage.\n */\n public readonly inputAmount: CurrencyAmount<TInput>\n /**\n * The output amount for the trade assuming no slippage.\n */\n public readonly outputAmount: CurrencyAmount<TOutput>\n /**\n * The price expressed in terms of output amount/input amount.\n */\n public readonly executionPrice: Price<TInput, TOutput>\n /**\n * The percent difference between the mid price before the trade and the trade execution price.\n */\n public readonly priceImpact: Percent\n\n /**\n * Constructs an exact in trade with the given amount in and route\n * @param route route of the exact in trade\n * @param amountIn the amount being passed in\n */\n public static exactIn<TInput extends Currency, TOutput extends Currency>(\n route: Route<TInput, TOutput>,\n amountIn: CurrencyAmount<TInput>\n ): Trade<TInput, TOutput, TradeType.EXACT_INPUT> {\n return new Trade(route, amountIn, TradeType.EXACT_INPUT)\n }\n\n /**\n * Constructs an exact out trade with the given amount out and route\n * @param route route of the exact out trade\n * @param amountOut the amount returned by the trade\n */\n public static exactOut<TInput extends Currency, TOutput extends Currency>(\n route: Route<TInput, TOutput>,\n amountOut: CurrencyAmount<TOutput>\n ): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT> {\n return new Trade(route, amountOut, TradeType.EXACT_OUTPUT)\n }\n\n public constructor(\n route: Route<TInput, TOutput>,\n amount: TTradeType extends TradeType.EXACT_INPUT ? CurrencyAmount<TInput> : CurrencyAmount<TOutput>,\n tradeType: TTradeType\n ) {\n this.route = route\n this.tradeType = tradeType\n\n const tokenAmounts: CurrencyAmount<Token>[] = new Array(route.path.length)\n if (tradeType === TradeType.EXACT_INPUT) {\n invariant(amount.currency.equals(route.input), 'INPUT')\n tokenAmounts[0] = amount.wrapped\n for (let i = 0; i < route.path.length - 1; i++) {\n const pair = route.pairs[i]\n const [outputAmount] = pair.getOutputAmount(tokenAmounts[i])\n tokenAmounts[i + 1] = outputAmount\n }\n this.inputAmount = CurrencyAmount.fromFractionalAmount(route.input, amount.numerator, amount.denominator)\n this.outputAmount = CurrencyAmount.fromFractionalAmount(\n route.output,\n tokenAmounts[tokenAmounts.length - 1].numerator,\n tokenAmounts[tokenAmounts.length - 1].denominator\n )\n } else {\n invariant(amount.currency.equals(route.output), 'OUTPUT')\n tokenAmounts[tokenAmounts.length - 1] = amount.wrapped\n for (let i = route.path.length - 1; i > 0; i--) {\n const pair = route.pairs[i - 1]\n const [inputAmount] = pair.getInputAmount(tokenAmounts[i])\n tokenAmounts[i - 1] = inputAmount\n }\n this.inputAmount = CurrencyAmount.fromFractionalAmount(\n route.input,\n tokenAmounts[0].numerator,\n tokenAmounts[0].denominator\n )\n this.outputAmount = CurrencyAmount.fromFractionalAmount(route.output, amount.numerator, amount.denominator)\n }\n this.executionPrice = new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.inputAmount.quotient,\n this.outputAmount.quotient\n )\n this.priceImpact = computePriceImpact(route.midPrice, this.inputAmount, this.outputAmount)\n }\n\n /**\n * Get the minimum amount that must be received from this trade for the given slippage tolerance\n * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade\n */\n public minimumAmountOut(slippageTolerance: Percent): CurrencyAmount<TOutput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n if (this.tradeType === TradeType.EXACT_OUTPUT) {\n return this.outputAmount\n } else {\n const slippageAdjustedAmountOut = new Fraction(ONE)\n .add(slippageTolerance)\n .invert()\n .multiply(this.outputAmount.quotient).quotient\n return CurrencyAmount.fromRawAmount(this.outputAmount.currency, slippageAdjustedAmountOut)\n }\n }\n\n /**\n * Get the maximum amount in that can be spent via this trade for the given slippage tolerance\n * @param slippageTolerance tolerance of unfavorable slippage from the execution price of this trade\n */\n public maximumAmountIn(slippageTolerance: Percent): CurrencyAmount<TInput> {\n invariant(!slippageTolerance.lessThan(ZERO), 'SLIPPAGE_TOLERANCE')\n if (this.tradeType === TradeType.EXACT_INPUT) {\n return this.inputAmount\n } else {\n const slippageAdjustedAmountIn = new Fraction(ONE).add(slippageTolerance).multiply(this.inputAmount.quotient)\n .quotient\n return CurrencyAmount.fromRawAmount(this.inputAmount.currency, slippageAdjustedAmountIn)\n }\n }\n\n /**\n * Given a list of pairs, and a fixed amount in, returns the top `maxNumResults` trades that go from an input token\n * amount to an output token, making at most `maxHops` hops.\n * Note this does not consider aggregation, as routes are linear. It's possible a better route exists by splitting\n * the amount in among multiple routes.\n * @param pairs the pairs to consider in finding the best trade\n * @param nextAmountIn exact amount of input currency to spend\n * @param currencyOut the desired currency out\n * @param maxNumResults maximum number of results to return\n * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair\n * @param currentPairs used in recursion; the current list of pairs\n * @param currencyAmountIn used in recursion; the original value of the currencyAmountIn parameter\n * @param bestTrades used in recursion; the current list of best trades\n */\n public static bestTradeExactIn<TInput extends Currency, TOutput extends Currency>(\n pairs: Pair[],\n currencyAmountIn: CurrencyAmount<TInput>,\n currencyOut: TOutput,\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n // used in recursion.\n currentPairs: Pair[] = [],\n nextAmountIn: CurrencyAmount<Currency> = currencyAmountIn,\n bestTrades: Trade<TInput, TOutput, TradeType.EXACT_INPUT>[] = []\n ): Trade<TInput, TOutput, TradeType.EXACT_INPUT>[] {\n invariant(pairs.length > 0, 'PAIRS')\n invariant(maxHops > 0, 'MAX_HOPS')\n invariant(currencyAmountIn === nextAmountIn || currentPairs.length > 0, 'INVALID_RECURSION')\n\n const amountIn = nextAmountIn.wrapped\n const tokenOut = currencyOut.wrapped\n for (let i = 0; i < pairs.length; i++) {\n const pair = pairs[i]\n // pair irrelevant\n if (!pair.token0.equals(amountIn.currency) && !pair.token1.equals(amountIn.currency)) continue\n if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\n\n let amountOut: CurrencyAmount<Token>\n try {\n ;[amountOut] = pair.getOutputAmount(amountIn)\n } catch (error) {\n // input too low\n if (error.isInsufficientInputAmountError) {\n continue\n }\n throw error\n }\n // we have arrived at the output token, so this is the final trade of one of the paths\n if (amountOut.currency.equals(tokenOut)) {\n sortedInsert(\n bestTrades,\n new Trade(\n new Route([...currentPairs, pair], currencyAmountIn.currency, currencyOut),\n currencyAmountIn,\n TradeType.EXACT_INPUT\n ),\n maxNumResults,\n tradeComparator\n )\n } else if (maxHops > 1 && pairs.length > 1) {\n const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length))\n\n // otherwise, consider all the other paths that lead from this token as long as we have not exceeded maxHops\n Trade.bestTradeExactIn(\n pairsExcludingThisPair,\n currencyAmountIn,\n currencyOut,\n {\n maxNumResults,\n maxHops: maxHops - 1\n },\n [...currentPairs, pair],\n amountOut,\n bestTrades\n )\n }\n }\n\n return bestTrades\n }\n\n /**\n * Return the execution price after accounting for slippage tolerance\n * @param slippageTolerance the allowed tolerated slippage\n */\n public worstExecutionPrice(slippageTolerance: Percent): Price<TInput, TOutput> {\n return new Price(\n this.inputAmount.currency,\n this.outputAmount.currency,\n this.maximumAmountIn(slippageTolerance).quotient,\n this.minimumAmountOut(slippageTolerance).quotient\n )\n }\n\n /**\n * similar to the above method but instead targets a fixed output amount\n * given a list of pairs, and a fixed amount out, returns the top `maxNumResults` trades that go from an input token\n * to an output token amount, making at most `maxHops` hops\n * note this does not consider aggregation, as routes are linear. it's possible a better route exists by splitting\n * the amount in among multiple routes.\n * @param pairs the pairs to consider in finding the best trade\n * @param currencyIn the currency to spend\n * @param nextAmountOut the exact amount of currency out\n * @param maxNumResults maximum number of results to return\n * @param maxHops maximum number of hops a returned trade can make, e.g. 1 hop goes through a single pair\n * @param currentPairs used in recursion; the current list of pairs\n * @param currencyAmountOut used in recursion; the original value of the currencyAmountOut parameter\n * @param bestTrades used in recursion; the current list of best trades\n */\n public static bestTradeExactOut<TInput extends Currency, TOutput extends Currency>(\n pairs: Pair[],\n currencyIn: TInput,\n currencyAmountOut: CurrencyAmount<TOutput>,\n { maxNumResults = 3, maxHops = 3 }: BestTradeOptions = {},\n // used in recursion.\n currentPairs: Pair[] = [],\n nextAmountOut: CurrencyAmount<Currency> = currencyAmountOut,\n bestTrades: Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[] = []\n ): Trade<TInput, TOutput, TradeType.EXACT_OUTPUT>[] {\n invariant(pairs.length > 0, 'PAIRS')\n invariant(maxHops > 0, 'MAX_HOPS')\n invariant(currencyAmountOut === nextAmountOut || currentPairs.length > 0, 'INVALID_RECURSION')\n\n const amountOut = nextAmountOut.wrapped\n const tokenIn = currencyIn.wrapped\n for (let i = 0; i < pairs.length; i++) {\n const pair = pairs[i]\n // pair irrelevant\n if (!pair.token0.equals(amountOut.currency) && !pair.token1.equals(amountOut.currency)) continue\n if (pair.reserve0.equalTo(ZERO) || pair.reserve1.equalTo(ZERO)) continue\n\n let amountIn: CurrencyAmount<Token>\n try {\n ;[amountIn] = pair.getInputAmount(amountOut)\n } catch (error) {\n // not enough liquidity in this pair\n if (error.isInsufficientReservesError) {\n continue\n }\n throw error\n }\n // we have arrived at the input token, so this is the first trade of one of the paths\n if (amountIn.currency.equals(tokenIn)) {\n sortedInsert(\n bestTrades,\n new Trade(\n new Route([pair, ...currentPairs], currencyIn, currencyAmountOut.currency),\n currencyAmountOut,\n TradeType.EXACT_OUTPUT\n ),\n maxNumResults,\n tradeComparator\n )\n } else if (maxHops > 1 && pairs.length > 1) {\n const pairsExcludingThisPair = pairs.slice(0, i).concat(pairs.slice(i + 1, pairs.length))\n\n // otherwise, consider all the other paths that arrive at this token as long as we have not exceeded maxHops\n Trade.bestTradeExactOut(\n pairsExcludingThisPair,\n currencyIn,\n currencyAmountOut,\n {\n maxNumResults,\n maxHops: maxHops - 1\n },\n [pair, ...currentPairs],\n amountIn,\n bestTrades\n )\n }\n }\n\n return bestTrades\n }\n}\n","import { Token, Currency, CurrencyAmount, Percent, TradeType, validateAndParseAddress } from '@uniswap/sdk-core'\nimport { Trade } from './entities'\nimport invariant from 'tiny-invariant'\n\n/**\n * Options for producing the arguments to send call to the router.\n */\nexport interface TradeOptions {\n /**\n * How much the execution price is allowed to move unfavorably from the trade execution price.\n */\n allowedSlippage: Percent\n /**\n * How long the swap is valid until it expires, in seconds.\n * This will be used to produce a `deadline` parameter which is computed from when the swap call parameters\n * are generated.\n */\n ttl: number\n /**\n * The account that should receive the output of the swap.\n */\n recipient: string\n\n /**\n * Whether any of the tokens in the path are fee on transfer tokens, which should be handled with special methods\n */\n feeOnTransfer?: boolean\n}\n\nexport interface TradeOptionsDeadline extends Omit<TradeOptions, 'ttl'> {\n /**\n * When the transaction expires.\n * This is an atlernate to specifying the ttl, for when you do not want to use local time.\n */\n deadline: number\n}\n\n/**\n * The parameters to use in the call to the Uniswap V2 Router to execute a trade.\n */\nexport interface SwapParameters {\n /**\n * The method to call on the Uniswap V2 Router.\n */\n methodName: string\n /**\n * The arguments to pass to the method, all hex encoded.\n */\n args: (string | string[])[]\n /**\n * The amount of wei to send in hex.\n */\n value: string\n}\n\nfunction toHex(currencyAmount: CurrencyAmount<Currency>) {\n return `0x${currencyAmount.quotient.toString(16)}`\n}\n\nconst ZERO_HEX = '0x0'\n\n/**\n * Represents the Uniswap V2 Router, and has static methods for helping execute trades.\n */\nexport abstract class Router {\n /**\n * Cannot be constructed.\n */\n private constructor() {}\n /**\n * Produces the on-chain method name to call and the hex encoded parameters to pass as arguments for a given trade.\n * @param trade to produce call parameters for\n * @param options options for the call parameters\n */\n public static swapCallParameters(\n trade: Trade<Currency, Currency, TradeType>,\n options: TradeOptions | TradeOptionsDeadline\n ): SwapParameters {\n const etherIn = trade.inputAmount.currency.isNative\n const etherOut = trade.outputAmount.currency.isNative\n // the router does not support both ether in and out\n invariant(!(etherIn && etherOut), 'ETHER_IN_OUT')\n invariant(!('ttl' in options) || options.ttl > 0, 'TTL')\n\n const to: string = validateAndParseAddress(options.recipient)\n const amountIn: string = toHex(trade.maximumAmountIn(options.allowedSlippage))\n const amountOut: string = toHex(trade.minimumAmountOut(options.allowedSlippage))\n const path: string[] = trade.route.path.map((token: Token) => token.address)\n const deadline =\n 'ttl' in options\n ? `0x${(Math.floor(new Date().getTime() / 1000) + options.ttl).toString(16)}`\n : `0x${options.deadline.toString(16)}`\n\n const useFeeOnTransfer = Boolean(options.feeOnTransfer)\n\n let methodName: string\n let args: (string | string[])[]\n let value: string\n switch (trade.tradeType) {\n case TradeType.EXACT_INPUT:\n if (etherIn) {\n methodName = useFeeOnTransfer ? 'swapExactETHForTokensSupportingFeeOnTransferTokens' : 'swapExactETHForTokens'\n // (uint amountOutMin, address[] calldata path, address to, uint deadline)\n args = [amountOut, path, to, deadline]\n value = amountIn\n } else if (etherOut) {\n methodName = useFeeOnTransfer ? 'swapExactTokensForETHSupportingFeeOnTransferTokens' : 'swapExactTokensForETH'\n // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)\n args = [amountIn, amountOut, path, to, deadline]\n value = ZERO_HEX\n } else {\n methodName = useFeeOnTransfer\n ? 'swapExactTokensForTokensSupportingFeeOnTransferTokens'\n : 'swapExactTokensForTokens'\n // (uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)\n args = [amountIn, amountOut, path, to, deadline]\n value = ZERO_HEX\n }\n break\n case TradeType.EXACT_OUTPUT:\n invariant(!useFeeOnTransfer, 'EXACT_OUT_FOT')\n if (etherIn) {\n methodName = 'swapETHForExactTokens'\n // (uint amountOut, address[] calldata path, address to, uint deadline)\n args = [amountOut, path, to, deadline]\n value = amountIn\n } else if (etherOut) {\n methodName = 'swapTokensForExactETH'\n // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)\n args = [amountOut, amountIn, path, to, deadline]\n value = ZERO_HEX\n } else {\n methodName = 'swapTokensForExactTokens'\n // (uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)\n args = [amountOut, amountIn, path, to, deadline]\n value = ZERO_HEX\n }\n break\n }\n return {\n methodName,\n args,\n value\n }\n }\n}\n"],"names":["FACTORY_ADDRESS_MAP","V2_FACTORY_ADDRESSES","INIT_CODE_HASH","MINIMUM_LIQUIDITY","JSBI","BigInt","ZERO","ONE","FIVE","_997","_1000","BASIS_POINTS","ZERO_PERCENT","Percent","ONE_HUNDRED_PERCENT","CAN_SET_PROTOTYPE","Object","InsufficientReservesError","name","_this","constructor","setPrototypeOf","prototype","Error","InsufficientInputAmountError","_this2","computePairAddress","factoryAddress","tokenA","tokenB","sortsBefore","getCreate2Address","keccak256","pack","address","Pair","currencyAmountA","tokenAmountB","tokenAmounts","currency","liquidityToken","Token","chainId","getAddress","involvesToken","token","equals","this","token0","token1","priceOf","invariant","token0Price","token1Price","reserveOf","reserve0","reserve1","getOutputAmount","inputAmount","calculateFotFees","equal","quotient","inputReserve","outputReserve","percentAfterSellFees","derivePercentAfterSellFees","inputAmountAfterTax","greaterThan","CurrencyAmount","fromRawAmount","multiply","inputAmountWithFeeAndAfterTax","numerator","denominator","add","outputAmount","divide","percentAfterBuyFees","derivePercentAfterBuyFees","outputAmountAfterTax","subtract","getInputAmount","outputAmountBeforeTax","greaterThanOrEqual","getLiquidityMinted","totalSupply","tokenAmountA","liquidity","sqrt","amount0","amount1","lessThanOrEqual","getLiquidityValue","feeOn","kLast","totalSupplyAdjusted","kLastParsed","rootK","rootKLast","feeLiquidity","sellFeeBips","wrapped","sellFeeBps","gt","BigNumber","from","buyFeeBps","result","Price","Route","pairs","input","output","length","every","pair","wrappedInput","path","entries","currentInput","push","_midPrice","prices","reduced","slice","reduce","accumulator","currentValue","inputOutputComparator","a","b","equalTo","lessThan","tradeComparator","ioComp","priceImpact","route","Trade","amount","tradeType","Array","TradeType","EXACT_INPUT","i","fromFractionalAmount","executionPrice","computePriceImpact","midPrice","exactIn","amountIn","exactOut","amountOut","EXACT_OUTPUT","minimumAmountOut","slippageTolerance","slippageAdjustedAmountOut","Fraction","invert","maximumAmountIn","slippageAdjustedAmountIn","bestTradeExactIn","currencyAmountIn","currencyOut","currentPairs","nextAmountIn","bestTrades","maxNumResults","maxHops","tokenOut","error","isInsufficientInputAmountError","sortedInsert","pairsExcludingThisPair","concat","worstExecutionPrice","bestTradeExactOut","currencyIn","currencyAmountOut","nextAmountOut","tokenIn","isInsufficientReservesError","toHex","currencyAmount","toString","Router","swapCallParameters","trade","options","etherIn","isNative","etherOut","ttl","methodName","args","value","to","validateAndParseAddress","recipient","allowedSlippage","map","deadline","Math","floor","Date","getTime","useFeeOnTransfer","Boolean","feeOnTransfer"],"mappings":"+WASaA,EAAqDC,uBAErDC,EAAiB,qEAEjBC,EAAoBC,EAAKC,OAAO,KAGhCC,EAAOF,EAAKC,OAAO,GACnBE,EAAMH,EAAKC,OAAO,GAClBG,EAAOJ,EAAKC,OAAO,GACnBI,EAAOL,EAAKC,OAAO,KACnBK,EAAQN,EAAKC,OAAO,KACpBM,EAAeP,EAAKC,OAAO,KAE3BO,EAAe,IAAIC,UAAQP,GAC3BQ,EAAsB,IAAID,UAAQN,m3ECvB/C,IAAMQ,EAAoB,mBAAoBC,OAMjCC,2FACyC,IAI7CC,KAAOC,EAAKC,YAAYF,KACzBH,GAAmBC,OAAOK,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