import { BigintIsh, CurrencyAmount, Price, Token } from '@uniswap/sdk-core'; export declare const computePairAddress: ({ factoryAddress, tokenA, tokenB, }: { factoryAddress: string; tokenA: Token; tokenB: Token; }) => string; export declare class Pair { readonly liquidityToken: Token; private readonly tokenAmounts; static getAddress(tokenA: Token, tokenB: Token): string; constructor(currencyAmountA: CurrencyAmount, tokenAmountB: CurrencyAmount); /** * Returns true if the token is either token0 or token1 * @param token to check */ involvesToken(token: Token): boolean; /** * Returns the current mid price of the pair in terms of token0, i.e. the ratio of reserve1 to reserve0 */ get token0Price(): Price; /** * Returns the current mid price of the pair in terms of token1, i.e. the ratio of reserve0 to reserve1 */ get token1Price(): Price; /** * Return the price of the given token in terms of the other token in the pair. * @param token token to return price of */ priceOf(token: Token): Price; /** * Returns the chain ID of the tokens in the pair. */ get chainId(): number; get token0(): Token; get token1(): Token; get reserve0(): CurrencyAmount; get reserve1(): CurrencyAmount; reserveOf(token: Token): CurrencyAmount; /** * getAmountOut is the linear algebra of reserve ratio against amountIn:amountOut. * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000 * has the math deduction for the reserve calculation without fee-on-transfer fees. * * With fee-on-transfer tax, intuitively it's just: * inputAmountWithFeeAndTax = 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * = (1 - amountIn.sellFeesBips / 10000) * amountInWithFee * where amountInWithFee is the amountIn after taking out the LP fees * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000) * * But we are illustrating the math deduction below to ensure that's the case. * * before swap A * B = K where A = reserveIn B = reserveOut * * after swap A' * B' = K where only k is a constant value * * getAmountOut * * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000) * amountOut = (B - B') / (1 - amountOut.buyFeesBips / 10000) # where A' * B' still is k * = (B - K/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)) * / * (1 - amountOut.buyFeesBips / 10000) * = (B - AB/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)) * / * (1 - amountOut.buyFeesBips / 10000) * = ((BA + B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn - AB)/(A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn)) * / * (1 - amountOut.buyFeesBips / 10000) * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn / (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * / * (1 - amountOut.buyFeesBips / 10000) * amountOut * (1 - amountOut.buyFeesBips / 10000) = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * / * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * * outputAmountWithTax = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * / * (A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * = (B * 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn * 1000 * / * ((A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn) * 1000) * = (B * (1 - amountIn.sellFeesBips / 10000) 997 * * amountIn * / * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * 997 * amountIn) * = (B * (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee) * / * (1000 * A + (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee) * = (B * inputAmountWithFeeAndTax) * / * (1000 * A + inputAmountWithFeeAndTax) * * inputAmountWithFeeAndTax = (1 - amountIn.sellFeesBips / 10000) * inputAmountWithFee * outputAmountWithTax = amountOut * (1 - amountOut.buyFeesBips / 10000) * * @param inputAmount * @param calculateFotFees */ getOutputAmount(inputAmount: CurrencyAmount, calculateFotFees?: boolean): [CurrencyAmount, Pair]; /** * getAmountIn is the linear algebra of reserve ratio against amountIn:amountOut. * https://ethereum.stackexchange.com/questions/101629/what-is-math-for-uniswap-calculates-the-amountout-and-amountin-why-997-and-1000 * has the math deduction for the reserve calculation without fee-on-transfer fees. * * With fee-on-transfer fees, intuitively it's just: * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000) * inputAmountWithTax = amountIn / (1 - amountIn.sellFeesBips / 10000) / 0.997 * * But we are illustrating the math deduction below to ensure that's the case. * * before swap A * B = K where A = reserveIn B = reserveOut * * after swap A' * B' = K where only k is a constant value * * getAmountIn * * B' = B - amountOut * (1 - amountOut.buyFeesBips / 10000) * A' = A + 0.997 * (1 - amountIn.sellFeesBips / 10000) * amountIn # here 0.3% is deducted * amountIn = (A' - A) / (0.997 * (1 - amountIn.sellFeesBips / 10000)) * = (K / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A) * / * (0.997 * (1 - amountIn.sellFeesBips / 10000)) * = (AB / (B - amountOut / (1 - amountOut.buyFeesBips / 10000)) - A) * / * (0.997 * (1 - amountIn.sellFeesBips / 10000)) * = ((AB - AB + A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000))) * / * (0.997 * (1 - amountIn.sellFeesBips / 10000)) * = ((A * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000))) * / * (0.997 * (1 - amountIn.sellFeesBips / 10000)) * = ((A * 1000 * amountOut / (1 - amountOut.buyFeesBips / 10000)) / (B - amountOut / (1 - amountOut.buyFeesBips / 10000))) * / * (997 * (1 - amountIn.sellFeesBips / 10000)) * * outputAmountWithTax = amountOut / (1 - amountOut.buyFeesBips / 10000) * inputAmountWithTax = amountIn / (997 * (1 - amountIn.sellFeesBips / 10000)) * = (A * outputAmountWithTax * 1000) / ((B - outputAmountWithTax) * 997) * * @param outputAmount */ getInputAmount(outputAmount: CurrencyAmount, calculateFotFees?: boolean): [CurrencyAmount, Pair]; getLiquidityMinted(totalSupply: CurrencyAmount, tokenAmountA: CurrencyAmount, tokenAmountB: CurrencyAmount): CurrencyAmount; getLiquidityValue(token: Token, totalSupply: CurrencyAmount, liquidity: CurrencyAmount, feeOn?: boolean, kLast?: BigintIsh): CurrencyAmount; private derivePercentAfterSellFees; private derivePercentAfterBuyFees; }