anothe rissue presents itself! My problem is with the swapback function: (the function is public because i was testing it, it should be internal)
function swapBack() public swapping {
uint256 amountToSwap = IBEP20(address(this)).balanceOf(address(this));
require(amountToSwap > 0, "Nothing to swap");
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = WBNB;
uint256 balanceBefore = address(this).balance;
router.swapExactTokensForETHSupportingFeeOnTransferTokens(
amountToSwap,
0,
path,
address(this),
block.timestamp
);
uint256 amountBNB = address(this).balance.sub(balanceBefore); // total
// calculate relational dividends
uint256 divTax = amountBNB.div(totalFee.sub(burnTax));
// spread the pool costs relative to tax values
uint256 amountBNBLiquidity = divTax.mul(liquidityFee);
uint256 amountBNBMarketing = divTax.mul(marketingFee);
uint256 amountBNBDev = divTax.mul(devFee);
(bool tmpSuccess,) = payable(marketingFeeReceiver).call{value: amountBNBMarketing}("");
(tmpSuccess,) = payable(devFeeReceiver).call{value: amountBNBDev}("");
require(tmpSuccess, "Tax went unpaid to receivers");
// Supress warning msg
tmpSuccess = false;
if(amountBNBLiquidity > 0){
router.addLiquidityETH{value: amountBNBLiquidity}(
address(this),
amountBNBLiquidity,
0,
0,
autoLiquidityReceiver,
block.timestamp
);
emit AutoLiquify(amountBNBLiquidity, amountBNBLiquidity);
}
}
the idea is that when the token amount reaches a certain threshold, the tokens that have been sent to the contract would be converted into busdT, and then split up to the accounts with their respective tax % amount defined here:
uint256 public liquidityFee = 10;
uint256 public burnTax = 10;
uint256 public marketingFee = 5;
uint256 public devFee = 5;
uint256 public totalFee = marketingFee + liquidityFee + devFee + burnTax; // total 3%
uint256 public feeDenominator = 1000;
but for some reason, the transaction fails with "Eip838ExecutionError: execution reverted: TransferHelper: TRANSFER_FROM_FAILED"
there is liquidity in the LP and there are tokens in the contract but for some reason it doesnt work. could someome please have a look and see what could be the issue?
thanks!