I am trying to add liquidity to Uniswap V3 for my ERC20 token, which has a 4% tax deduction on transfers. The tax mechanism ensures that whenever users transfer tokens, 4% is sent to the owner's address.
This is I have tried: I have deployed an ERC20 token (T2T) with a 4% tax on transfers and integrated Uniswap V3 for swapping. However, when I try to add liquidity on Uniswap V3, it takes the approval for tokens but does not add liquidity successfully.
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.17;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@uniswap/v3-periphery/contracts/interfaces/ISwapRouter.sol";
contract T2T is ERC20, Ownable {
uint256 public constant TAX_PERCENT = 4; // 4% tax
ISwapRouter public immutable uniswapRouter;
address public immutable WETH;
address public immutable taxReceiver; // Owner receives tax
constructor(address _uniswapRouter, address _WETH) ERC20("T2T", "T2T") Ownable(msg.sender) {
_mint(msg.sender, 1_000_000 * 10 ** decimals()); // Mint initial supply
uniswapRouter = ISwapRouter(_uniswapRouter);
WETH = _WETH;
taxReceiver = msg.sender; // Tax goes to owner
}
function _update(address sender, address recipient, uint256 amount) internal override {
uint256 taxAmount = (amount * TAX_PERCENT) / 100;
uint256 amountAfterTax = amount - taxAmount;
super._update(sender, taxReceiver, taxAmount); // Transfer tax
super._update(sender, recipient, amountAfterTax); // Transfer remaining tokens
}
}
I have attempted to add liquidity on Uniswap V3, and when a user swaps tokens, I want to transfer 4% of the transaction amount to the owner's address.