How to differentiate the addition of liquidity from a token -> ETH swap to only have fees when selling tokens and not when adding liquidity

Hello everyone, I have a problem with the creation of a token.

My goal is to create a token with burn fees only when buying/selling and not when transferring between 2 wallets or when adding/removing liquidity.

In the constructor I also create the pair MyToken / ETH under the name "AddressPair" and the address of the Uniswap router is noted "UniswapRouterV2Address" I arrive at the following conclusions:

Transfer between 2 wallets: from and to != AddressPair or UniswapRouterV2Address

Remove liquidity: from or to = UniswapRouterV2Address

My problem is that for adding liquidity I notice that to = AddressPair but For a swap MyToken -> ETH : to = AddressPair too. So I can't separate the two cases, knowing that I only want fees when swapping and not when adding liquidity...

There is a similar subject without answer dating from 1 year and a half so I


repost it

Thanks for your help

Hello @0xMente

AFAIK, what you are trying to do is not possible. Even if it was. Anyone could just use another router, or another exchange, and completely bypass any fees you are trying to implement.

Hello, @Amxx thank you for your answer !

So there is no way to create a token which has only fees for buying/selling (swap) and no fees for providing liquidity ?

It is impossible due to when you add liqudity you are sending tokens to the pair, while when your remove it, the pair is sending tokens to you.
So if you charge the fee on swaps, then you must to it on add/remove liquidity.

A possible solution would be to check the LP balance before and after,if it changes then you revert the fee charge.

Hello @FreezyEx thank you for your answer. I actually think that's the only way. Have a good day !

1 Like