function _transfer(address from, address to, uint256 amount) internal virtual override {
uint256 marketingFee = (amount * 2) / 100;
uint256 liquidityFee = (amount * 2) / 100;
uint256 fees = marketingFee + liquidityFee;
uint256 sendAmount = amount - fees;
super._transfer(from, to, sendAmount);
if (marketingFee > 0) {
super._transfer(from, marketingWallet, marketingFee);
}
if (liquidityFee > 0) {
super._transfer(from, address(this), liquidityFee);
}
uint256 accumulatedTokenThreshold = 5000000000 * 10**18; //For example,5000000000 tokens
if (liquidityFee > 0 && from != uniswapV2Pair && balanceOf(address(this)) >= accumulatedTokenThreshold) {
swapAccumulatedTokensForEth(balanceOf(address(this)));
}
uint256 minTimeInterval = 12 hours; // NaprĂklad 24 hodĂn
if (liquidityFee > 0 && from != uniswapV2Pair && address(this).balance >= minEthBeforeLiquidity && (block.timestamp - lastLiquidityAddTime) >= minTimeInterval) {
addLiquidity(liquidityFee, address(this).balance);
lastLiquidityAddTime = block.timestamp;
}
}
function swapAccumulatedTokensForEth(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
function addLiquidity(uint256 tokenAmount, uint256 ethAmount) private {
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.addLiquidityETH{value: ethAmount}(
address(this),
tokenAmount,
0,
0,
owner(),
block.timestamp
);
}
}
I think the problem might be here:
function swapAccumulatedTokensForEth(uint256 tokenAmount) private {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0,
path,
address(this),
block.timestamp
);
}
This condition is met when the contract reaches:
uint256 accumulatedTokenThreshold = 5000000000 * 10**18; // For example,5000000000 tokens
if (liquidityFee > 0 && from != uniswapV2Pair && balanceOf(address(this)) >= accumulatedTokenThreshold) {
swapAccumulatedTokensForEth(balanceOf(address(this)));
}
Since this condition is not fulfilled, the addLiquidity
function fails, which is what I suspect is occurring.
Do you have any specific suggestions on how I should resolve this issue? Do you think separating the swapping and liquidity addition processes from the basic _transfer function and executing them under the control of the administrator could be a suitable solution?
Thank you for your patience and help.