1

I'm able to do swap transactions using multicall and exactInputSingle functions on both Uniswap v3 and Pancakeswap v3. However, I have no idea how would I be able to set the slippage. The v2 routers has a getAmountsOut function, which makes it possible to set slippage because I would know what is the exact exchange between two tokens in a pool. As for v3, there's no way to check the price and set the slippage.

Edit:
I saw there's a checkOracleSlippage function on the "read contract" tab of the Pancakeswap Smart Router v3, but I have no any idea how to use it. I couldn't find any documentations about it either.

1 Answer 1

0

I somehow found a way to do this by using the sqrtPriceX96 in the token's pool address by querying slot0. The documentation for this is gone but I've searched and saw other people using this formula:

price_ratio = ((sqrtPriceX96**2)/(2**192))*(10**token_decimal/10**18)

The ratio and amount was close, but not quite as exact was what I see on Pancakeswap swap page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.