TDLR: the same code that works with UniSwap is capable of returning an infinite "amountOut" when querying PancakeSwap router function "getAmountsOut".

I'm using web3.py to call the PancakeSwap's router contract's getAmountsOut function, and every time I increase the "amountIn" field by 1000 units, I get an amountOut that shows no sign of approaching a maximum amount.


1000 BUSD -> 51 CAKE

1,000,000,000,000,000 BUSD -> 51,268,108,544,566 CAKE

1,000,000,000,000,000,000,000 BUSD -> 51,266,437,221,038,640,244 CAKE

There is not 51 quintillion CAKE in the CAKE/BUSD pool, so this function is returning a false value.

When I use the same code for UniSwapV2, and change the tokens to ERC20s, the output amount approaches a maximum, which is the number of "buy" token in the liquidity pool.

My code (python):

buy_amount = router_contract.functions.getAmountsOut(
            [sell_token_contract_address, buy_token_contract_address]  # [SELL, BUY]

I found the answer... pancakeswap has some pairs quoted in maaany decimal places, so the output is not in tokens but in 1/1000000000000 of a token.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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