solidity – Swapping for Tokens with Bot Protection Enabled on PancakeSwap

bscscanetherscanpancakeswapsolidityweb3js

!!Apology in advance for such verbosity!!

Background

I came across this BEP20 token (0xcc7a91413769891de2e9ebbfc96d2eb1874b5760) which had sufficient Liquidity added at TGE but bot protection was enabled. The rules were the swap to be allowed only on or after a certain time (say at 7:00 AM) with only whitelisted wallet addresses to be able to buy up to 2500 (worth $200 say) tokens for the first 180s and then it gets opened to all.

When the Liquidity got added (say at 6:50 AM), I could see the conversion rate on PancakeSwap but every time I click the Swap button, it was showing me the Transfer Failed error and not even submitting the transaction on the blockchain. Once the go-ahead was given by the project team that token is live for swap, if I (Note: I was a WL address) set the amount greater than $200, PancakeSwap was still giving Transfer Failed error and not submitting the transaction. This was not the slippage issue, as I tried setting it to the highest and still didn't make the difference.

enter image description here

Question

  • Apart from Liquidity Pair & sufficient liquidity amount check, what else PancakeSwap (Router Contract) checks before submitting the swap transaction?
  • How PancakeSwap determined though the Liquidity Exists the token is not yet swappable?
  • How PancakeSwap did determine the limit on buy amount?
  • Not sure if PancakeSwap also has the ability to know if the wallet address is the Whitelisted one before submitting the transaction?

BSC Scan Token Swap

If you see in the image there is a roughly 10 mins difference between the AddLiquidity transaction and the first swap. I checked the first swap address and that person had submitted multiple transactions before (which I guess either through sniper bot or maybe through Write contract option of PancakeRouter BscScan) and of course, all failed until the time & amount criteria were met. And all the failed transactions had the same Transfer Failed error too.

(Success txn: 0xb1e0e23c34e0a8090d4ef879792701eb324ef83c1d95f5eee5cf95bb89ad24bb, wallet: 0x96d5f755220a03712eb85d490659288f859ccb8e, Failed Txn: 0xe80ff57297df7f580c726e923d200da6357c3ddac4b50f279b9504012054b32e)

So how one can determine the swap-ability of such token through web3j code libraries without submitting the transaction (meant to fail)? And which contract to interact with?

NOTE: I did notice the BP contract 0xb930a172f9205f87f7d28ffa6cc3b5c3fd87ac19 doesn't have code available to understand it better. Bytecode decompilers are not of much help. 🙁

Best Answer

I traced a transaction to find the root of the error.

The Pancake: TRANSFER_FAILED is thrown by the pancakeswap pair when it is unable to transfer a token.

The reason given for the transfer fail is BP: the address is not whitelisted. The BP contract has not been verified on bscscan so I am not sure what caused the error, but based on the description it is simply because your address was not whitelisted.

As for your other questions: Pancakeswap simply tries the transaction virtually and see that it fails, then gives you the error on the UI. You can do the same with web3js by making a call on the function that you want to try. Depending on the type of swap that you want to do, the pancakeswap router has different functions that you can use.

Related Topic