SAFEMOON Fork LP Issue

Hi everyone,

I forked SAFEMOON a few times but I’m having the same issue over and over. FYI I have the PancakeSwap Router v2 hardcoded into the contract the the problem should not stem from that.

Essentially, when I add LP, people can trade the token freely and everything works. However when I try to remove from the LP (or if anyone tries to add more to the LP), the token stops working. This means nobody can withdraw LP, or trade the token. LP withdrawal gets stuck as the “Confirm” button on the final stage doesn’t do anything, and swaps are met with:

“The transaction cannot succeed due to error: TransferHelper: TRANSFER_FROM_FAILED. This is probably an issue with one of the tokens you are swapping.”

After calling setSwapAndLiquify(false) on the contract, it is possible to withdraw from the LP and the token is able to be swapped (however, this literally removes the automatic 5% LP tax which is counterproductive). Setting it to true again throws the same errors as previously.

I’ve tried numerous contracts with different size LP pools etc, but the error is the same constantly.

Me removing LP:

My friend adding LP:

I know there are other threads with a similar issue, but I honestly cannot figure out why this may be happening and can’t run the risk of someone else adding liquidity to the token and stopping it from working.

Thank you in advance

Hi wab, welcome to Open Zeppelin Forums!

The problem is a little hard to explain. With Liquification, your contract will sell some of the tokens in it when setSwapAndLiquify is set to true and when the number of tokens to sell is reached in the contract.

From your code:
uint256 private numTokensSellToAddToLiquidity = 3000000000000 * 10**1 * 10**9;

This means that when the contract has 30,000,000,000,000,000,000,000 tokens in it, it will need to sell them to pancakeswap via your router that you have designated, which is V1 in your code. Your current real contract balance has 539679386573226075844086 RAWR in it. It needs to sell those tokens, but can’t because there isn’t enough liquidity.

IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x05fF2B0DB69458A0750badebc4f9e13aDd608C7F);

Although you moved to V2, your code is still V1.

What I’m saying is that when SwapAndLiquify tries to work, it’s going to V1 pancakeswap.

This is true of every safemoon clone that hardcoded V1 router address.