I want to implement different behavior in the transfer function of an ERC20 token if the transaction is swapping the token for ETH on Uniswap. The straight forward approach is, to check whether the associated uniswap pool is the recipient of the transfer. But that would also hold true for liquidity providing, in which tokens get transfered to the same address (Uniswap pool) and I want to apply a different logic for liquidity providing. How can I achieve this?
One thing I thought of was an additional contract for liquidity providing that can act as a proxy. Users could call a function on said contract, which would do the liquidity providing. The transfer function could then check whether the sender of a transaction is that contract and apply different behavior. But I am not sure whether this would work out.
Edit: To explain the aim more precisely: I want to burn tokens on sells but not when liquidity is provided. Therefore I reworked the transfer function in my token:
function myTransfer(address sender, address recipient, uint256 amount) internal {
if (sender == uniswapPool)
{
_transfer(sender, recipient, amount); // no burn when buying
}
else if(recipient == uniswapPool) // burn 10% for selling
{
uint256 burn = amount.div(10);
uint256 amountSent = amount.sub(burn);
_transfer(sender, recipient, amountSent);
_burnFrom(sender, burn);
}
}
But with this code in case of liquidity providing, tokens would also be burned.
- Is there a way I can find out in my transfer function whether we are sending tokens to the pool for selling/swapping them or for liquidity providing?
- If not: How can I work around the problem?