I'm trying to chain uniswap v2 pair price quotes together, when I quote a token amount exponentiated with it's decimals it reports the correct price
This code returns the proper price
const stableQuoteToken = getUSDC()
const MINIMUM_USDC_LIQUIDITY_AMOUNT = 1000000 as const
const stableQuoteAmount = CurrencyAmount.fromRawAmount(stableQuoteToken, MINIMUM_USDC_LIQUIDITY_AMOUNT)
const usdcWethPair = getUsdcWethPair()
const priceStable = usdcWethPair.priceOf(stableQuoteToken)
const quote = priceStable.quote(stableQuoteAmount)
console.log(
`Quoting: ${input.inputToken.symbol} at Stable Coin: ${
stableQuoteToken.symbol
} for ${bestStablePrice.toSignificant(6)} Or ${1 / Number(bestStablePrice.toSignificant(6))}`
)
Quoting: WETH at Stable Coin: USDC for 0.000442224 Or 2261.2974420203336
However if I try to invert the fraction
bestStablePrice = quote.invert()
It reports the decimals incorrectly
Quoting: WETH at Stable Coin: USDC for 0.00000000000000226068
Looks like the quote inversion is off maybe it's related to the difference between the decimals of the token vs quote token?
Is there a simple way to normalized the decimal amount to be ready in terms of usdc?