Web3.py – Fetching Liquidity Pool Details from Pancake Swap Using Token Address

pancakeswapweb3.py

Using python 3.10, web3 v5.31.1

Given only the contract address for a single token (tokenA), is there a method from PancakeSwap to return liquidity pool (LP) details?

Mainly given only the address of tokenA, how can I find out what LP is set up for tokenA?

Furthermore, assuming I want to buy tokenA with BNB, but tokenA has a LP with some other token, tokenB, but tokenB has an LP with BNB, I can swap via BNB -> tokenB -> tokenA.

How do dApps such as https://poocoin.app find these routes to trade. The image below shows that the dApp found a valid route BNB -> BUSD -> USDT -> token. How is this accomplished?

screenshot of poocoin.app swap example

I am new to coding web3 so example code would be greatly appreciated; thank you for help!

Best Answer

You can check PAIRS_TO_CHECK_TRADE_AGAINS addresses. Check within the factory if there's pairs between your token and WBNB, BUSD, TETHER and USDC. Maybe WBTC.

You can check calling getPool() from the pancake factory, pass the address of your token and the addresses of those tokens. With the address the pool you can do everything else.

Related Topic