I'm hoping I just did something silly that I'm overlooking, been banging my head on a wall.
Conditions - TOKENTST
Using https://pancake.kiemtienonline360.com/#/swap
Router: 0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3
BNB: 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd
swapEnabled = true
TOKENTST contract has 100t TOKENTST and .5 BNB
ISSUE
When calling swapBack() from Remix, the function works perfectly. No problems.
During a normal buy/sell through https://pancake.kiemtienonline360.com/#/swap everything works aside from the swapBack() call in the _transferfrom function.
Transfer Functions
function transferFrom(address sender, address recipient, uint256 amount) external override returns (bool) {
if(_allowances[sender][msg.sender] != ~uint256(0)){
_allowances[sender][msg.sender] = _allowances[sender][msg.sender].sub(amount, "Insufficient Allowance");
}
return _transferFrom(sender, recipient, amount);
}
function _transferFrom(address sender, address recipient, uint256 amount) internal returns (bool) {
require(!freeze_contract, "Contract frozen!");
if(inSwap){ return _basicTransfer(sender, recipient, amount); }
checkTxLimit(sender, amount);
if(!launched() && recipient == pancakeV2BNBPair){ require(_balances[sender] > 0); launch(); }
_balances[sender] = _balances[sender].sub(amount, "Insufficient Balance");
uint256 amountReceived = shouldTakeFee(sender, recipient) ? takeFee(sender, amount) : amount;
_balances[recipient] = _balances[recipient].add(amountReceived);
if(!isDividendExempt[sender]){ try distributor.setShare(sender, _balances[sender]) {} catch {} }
if(!isDividendExempt[recipient]){ try distributor.setShare(recipient, _balances[recipient]) {} catch {} }
uint256 swapAmount = amount.sub(amountReceived);
if(swapAmount > 0 && shouldSwapBack()) {
swapBack(swapAmount);
uint256 burnAmount = swapAmount.div(2);
IBEP20(address(this)).transfer(DEAD, burnAmount);
}
try distributor.process(distributorGas) {} catch {}
emit Transfer(sender, recipient, amountReceived);
return true;
}
function _basicTransfer(address sender, address recipient, uint256 amount) internal returns (bool) {
_balances[sender] = _balances[sender].sub(amount, "Insufficient Balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
return true;
}
Swap Functions
function shouldSwapBack() internal view returns (bool) {
return swapEnabled
&& !inSwap;
}
function swapBack(uint256 _swapamount) public Swapping {
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = WBNB;
uint256 startBNBBalance = address(this).balance;
try router.swapExactTokensForETHSupportingFeeOnTransferTokens(
_swapamount,
0,
path,
address(this),
block.timestamp
) {
uint256 amountToLiquify = _swapamount.mul(liquidityFee).div(totalFee).div(2);
uint256 addedBNB = address(this).balance.sub(startBNBBalance);
uint256 lpBNB = addedBNB.mul(liquidityFee).div(totalFee);
try router.addLiquidityETH{ value: lpBNB }(
address(this),
amountToLiquify,
0,
0,
autoLiquidityReceiver,
block.timestamp
) { } catch { }
} catch { }
if(shouldSendBNB()){ sendBNB(); }
if(shouldSendBUSD()) { sendBUSD(); }
}