Hey guys!
Been working on this for two days straight, thrown money at it, thrown devs at it, and spent a ton of time trying to learn some solidity context…and I’m still learning TONS.
But I am also on a deadline, so I defer to you, the pros.
I am trying to cut into the _transferStandard
function, and you can see that I added the function swapTokens
on line 1387.
What that is supposed to do is take the passed-in _tv.tMarketingFee
amount, and convert it into WETH via swapTokensForBNB
.
Not even sure that the conversion actually happens tbh – but ideally once converted, the function sendETHToFee
is used to send the converted amount to the payable marketingWallet
address.
However what is happening now, is that I am not able to add liquidity to the contract due to a “execution reverted: TransferHelper: TRANSFER_FROM_FAILED” error.
So I’m thinking that either my code has a bug I am not seeing, or the conversion into WETH / ETH is maybe off or something.
Do you guys have any ideas? Thank you!
Full code: Contract.sol · GitHub
Code sample (removed safemath, interfaces, router, etc because it was too long to post):
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.6;
contract Ownable {
address private _owner;
address private _previousOwner;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with GSN meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*/
function _msgSender() internal view returns (address payable) {
return payable(msg.sender);
}
function _msgData() internal view returns (bytes memory) {
this; // silence state mutability warning without generating bytecode - see https://github.com/ethereum/solidity/issues/2691
return msg.data;
}
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_owner = _msgSender();
emit OwnershipTransferred(address(0), _owner);
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(_owner == _msgSender(), "Ownable: caller is not the owner");
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view returns (address) {
return _owner;
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions anymore. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby removing any functionality that is only available to the owner.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipTransferred(_owner, address(0));
_owner = address(0);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
emit OwnershipTransferred(_owner, newOwner);
_owner = newOwner;
}
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
}
contract NFTBABY is IBEP20, Ownable {
using SafeMath for uint256;
using Address for address;
IBEP20 token;
mapping(address => uint256) private _rBalances;
mapping(address => uint256) private _tBalances;
mapping(address => mapping(address => uint256)) private _allowances;
mapping(address => bool) private _isExcludedFromFee;
mapping(address => bool) private _isExcluded;
address[] private _excluded;
uint256 public buyBackUpperLimit = 2 * 10**16; // check this
uint256 private _buyTaxFee = 2; // Reflections Fee
uint256 private _buyBurnFee = 1; // Burn Fee
uint256 private _buyLiquidityFee = 3; // LP Fee
uint256 private _buyMarketingFee = 7; // Marketing Fee
uint256 private _buyBuybackFee = 2; // Buyback Fee - TO DO: FIX Buyback in BNB
uint256 private _sellTaxFee = 2; // Reflections Fee
uint256 private _sellBurnFee = 1;
uint256 private _sellLiquidityFee = 3;
uint256 private _sellMarketingFee = 7;
uint256 private _sellBuybackFee = 2;
string private constant _name = "NFT BABY";
string private constant _symbol = "BBY";
uint8 private constant _decimals = 9;
uint256 private constant _tTotalSupply = 1000000000000 * 10 ** 9;
uint256 private constant _buyMaxTxAmount = 5000000000 * 10 ** 9;
uint256 private constant _sellMaxTxAmount = 5000000000 * 10 ** 9;
uint256 private constant MAX = ~uint256(0);
uint256 private _rTotalSupply;
uint256 private _maxTxAmount;
uint256 private _taxFee;
uint256 private _previousTaxFee;
uint256 private _liquidityFee;
uint256 private _previousLiquidityFee;
uint256 private _marketingFee;
uint256 private _previousMarketingFee;
uint256 private _burnFee;
uint256 private _previousBurnFee;
uint256 private _buybackFee;
uint256 private _previousBuybackFee;
uint256 private _tFeeTotal;
uint256 private _tMarketingTotal;
uint256 private _tBurnTotal;
uint256 private _tBuybackTotal;
// wallet for burning
address public constant burnWallet = 0x000000000000000000000000000000000000dEaD;
// wallet for buybacks
address public constant buybackWallet = 0x3308f174810FD9b158bFE6DF81115752c44c6457;
// wallet for marketing
address payable public marketingWallet = payable(0xB56b30bb189de3A7CE61178e2754EA59Ca6078C4);
// Mainnet BSC - PancakeSwap Router V2
address private constant _pancakeRouterAddress = 0x10ED43C718714eb63d5aA57B78B54704E256024E; // USE THIS FOR LAUNCH
// Testnet BSC - PancakeSwap Router V2
// address private constant _pancakeRouterAddress = 0xD99D1c33F9fC3444f8101754aBC46c52416550D1; // TESTING
// Mainnet, Ropsten and etc ETH - Uniswap V2
// address private constant _pancakeRouterAddress = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; // TESTING
IPancakeRouter02 public immutable pancakeRouter;
address public immutable pancakePair;
// structs to reflect transfers and fees
struct tValues {
uint256 tTransferAmount;
uint256 tFee;
uint256 tLiquidity;
uint256 tMarketingFee;
uint256 tBurnFee;
uint256 tBuybackFee;
}
// structs for transfers and fees
struct rValues {
uint256 rAmount;
uint256 rTransferAmount;
uint256 rFee;
uint256 rLiquidity;
uint256 rMarketingFee;
uint256 rBurnFee;
uint256 rBuybackFee;
}
constructor() {
// set utility variables
_maxTxAmount = _buyMaxTxAmount;
_taxFee = _buyTaxFee;
_previousTaxFee = _taxFee;
_liquidityFee = _buyLiquidityFee;
_previousLiquidityFee = _liquidityFee;
_marketingFee = _buyMarketingFee;
_previousMarketingFee = _marketingFee;
_burnFee = _buyBurnFee;
_previousBurnFee = _burnFee;
_buybackFee = _buyBuybackFee;
_previousBuybackFee = _buybackFee;
token = IBEP20(address(this));
// set reflect total supply
_rTotalSupply = (MAX - (MAX % _tTotalSupply));
_rBalances[_msgSender()] = _rTotalSupply;
IPancakeRouter02 _pancakeRouter = IPancakeRouter02(_pancakeRouterAddress);
// Create a pancake pair for this new token
pancakePair = IPancakeFactory(_pancakeRouter.factory()).createPair(address(this), _pancakeRouter.WETH());
// set the rest of the contract variables
pancakeRouter = _pancakeRouter;
// exclude owner, this contract and marketing wallet from fee
// _isExcludedFromFee[owner()] = true;
// _isExcludedFromFee[address(this)] = true;
// _isExcludedFromFee[marketingWallet] = true;
// _isExcludedFromFee[burnWallet] = true;
// _isExcludedFromFee[buybackWallet] = true;
//FOR TESTING ONLY, CHANGE TO TRUE ON LAUNCH *******************
_isExcludedFromFee[owner()] = false;
_isExcludedFromFee[address(this)] = false;
_isExcludedFromFee[marketingWallet] = false;
_isExcludedFromFee[burnWallet] = false;
_isExcludedFromFee[buybackWallet] = false;
}
receive() external payable {}
function name() public pure returns (string memory) {
return _name;
}
function symbol() public pure returns (string memory) {
return _symbol;
}
function decimals() public pure returns (uint8) {
return _decimals;
}
function totalSupply() public pure override returns (uint256) {
return _tTotalSupply;
}
function balanceOf(address account) public view override returns (uint256) {
if (_isExcluded[account]) return _tBalances[account];
return tokenFromReflection(_rBalances[account]);
}
function getOwner() public view returns (address) {
return owner();
}
function transfer(address recipient, uint256 amount) public override returns (bool) {
_transfer(_msgSender(), recipient, amount);
return true;
}
function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
_transfer(sender, recipient, amount);
_approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
return true;
}
function approve(address spender, uint256 amount) public override returns (bool) {
_approve(_msgSender(), spender, amount);
return true;
}
function allowance(address owner, address spender) public view override returns (uint256) {
return _allowances[owner][spender];
}
function increaseAllowance(address spender, uint256 addedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
return true;
}
function decreaseAllowance(address spender, uint256 subtractedValue) public returns (bool) {
_approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
return true;
}
function totalFees() public view returns (uint256) {
return _tFeeTotal;
}
function totalMarketingFees() public view returns (uint256) {
return _tMarketingTotal;
}
function totalBurnFee() public view returns (uint256) {
return _tBurnTotal;
}
function excludeFromFee(address account) public onlyOwner {
_isExcludedFromFee[account] = true;
}
function includeInFee(address account) public onlyOwner {
_isExcludedFromFee[account] = false;
}
function isExcludedFromFee(address account) public view returns(bool) {
return _isExcludedFromFee[account];
}
function excludeFromReward(address account) public onlyOwner() {
require(account != marketingWallet, 'We can not exclude donation and marketing wallet.');
require(!_isExcluded[account], "Account is already excluded");
if (_rBalances[account] > 0) {
_tBalances[account] = tokenFromReflection(_rBalances[account]);
}
_isExcluded[account] = true;
_excluded.push(account);
}
function includeInReward(address account) external onlyOwner() {
require(_isExcluded[account], "Account is not excluded");
for (uint256 i = 0; i < _excluded.length; i++) {
if (_excluded[i] == account) {
_excluded[i] = _excluded[_excluded.length - 1];
_tBalances[account] = 0;
_isExcluded[account] = false;
_excluded.pop();
break;
}
}
}
function isExcludedFromReward(address account) public view returns (bool) {
return _isExcluded[account];
}
function setBuyTaxFeePercent(uint256 taxFee) external onlyOwner() {
_buyTaxFee = taxFee;
}
function setSellTaxFeePercent(uint256 taxFee) external onlyOwner() {
_sellTaxFee = taxFee;
}
function setBuyLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() {
_buyLiquidityFee = liquidityFee;
}
function setSellLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() {
_sellLiquidityFee = liquidityFee;
}
function setBuyMarketingFeePercent(uint256 marketingFee) external onlyOwner() {
_buyMarketingFee = marketingFee;
}
function setSellMarketingFeePercent(uint256 marketingFee) external onlyOwner() {
_sellMarketingFee = marketingFee;
}
function setBuyBurnFeePercent(uint256 burnFee) external onlyOwner() {
_buyBurnFee = burnFee;
}
function setSellBurnFeePercent(uint256 burnFee) external onlyOwner() {
_sellBurnFee = burnFee;
}
function setBuyBuybackFeePercent(uint256 buybackFee) external onlyOwner() {
_buyBuybackFee = buybackFee;
}
function setSellBuybackFeePercent(uint256 buybackFee) external onlyOwner() {
_sellBuybackFee = buybackFee;
}
function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns (uint256) {
require(tAmount <= _tTotalSupply, "Amount must be less than supply");
if (!deductTransferFee) {
(rValues memory _rv, tValues memory _tv) = _getValues(tAmount);
_tv.tTransferAmount = 0; _tv.tFee = 0; _tv.tLiquidity = 0; _tv.tMarketingFee = 0; _tv.tBurnFee = 0; _tv.tBuybackFee = 0;
_rv.rTransferAmount = 0; _rv.rFee = 0; _rv.rLiquidity = 0; _rv.rMarketingFee = 0; _rv.rBurnFee = 0; _rv.rBuybackFee = 0;
return _rv.rAmount;
} else {
(rValues memory _rv, tValues memory _tv) = _getValues(tAmount);
_tv.tTransferAmount = 0; _tv.tFee = 0; _tv.tLiquidity = 0; _tv.tMarketingFee = 0; _tv.tBurnFee = 0; _tv.tBuybackFee = 0;
_rv.rTransferAmount = 0; _rv.rFee = 0; _rv.rLiquidity = 0; _rv.rMarketingFee = 0; _rv.rBurnFee = 0; _rv.rBuybackFee = 0;
return _rv.rTransferAmount;
}
}
function tokenFromReflection(uint256 rAmount) public view returns (uint256) {
require(rAmount <= _rTotalSupply, "Amount must be less than total reflections");
return rAmount.div(_getRate());
}
function _transfer(address from, address to, uint256 amount) private {
require(from != address(0), "ERC20: transfer from the zero address");
require(to != address(0), "ERC20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
if (from != owner() && to != owner()) {
if (from == pancakePair) { // Buy
_maxTxAmount = _buyMaxTxAmount;
} else if (to == pancakePair) { // Sell
_maxTxAmount = _sellMaxTxAmount;
} else { // other
_maxTxAmount = _buyMaxTxAmount;
}
require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
}
// indicates if fee should be deducted from transfer
bool takeFee = true;
// if any account belongs to _isExcludedFromFee account then remove the fee
if (_isExcludedFromFee[from] || _isExcludedFromFee[to]) {
takeFee = false;
} else {
// set _taxFee and _liquidityFee to buy or sell action
if (from == pancakePair) { // Buy
_taxFee = _buyTaxFee;
_liquidityFee = _buyLiquidityFee;
_marketingFee = _buyMarketingFee;
_burnFee = _buyBurnFee;
_buybackFee = _buyBuybackFee;
} else if (to == pancakePair) { // Sell
_taxFee = _sellTaxFee;
_liquidityFee = _sellLiquidityFee;
_marketingFee = _sellMarketingFee;
_burnFee = _sellBurnFee;
_buybackFee = _sellBuybackFee;
} else { // other
_taxFee = _buyTaxFee;
_liquidityFee = _buyLiquidityFee;
_marketingFee = _buyMarketingFee;
_burnFee = _buyBurnFee;
_buybackFee = _buyBuybackFee;
}
}
_tokenTransfer(from, to, amount, takeFee);
}
function _approve(address owner, address spender, uint256 amount) private {
require(owner != address(0), "ERC20: approve from the zero address");
require(spender != address(0), "ERC20: approve to the zero address");
_allowances[owner][spender] = amount;
emit Approval(owner, spender, amount);
}
function _getValues(uint256 tAmount) private view returns (rValues memory, tValues memory) {
tValues memory _tv = _getTValues(tAmount);
rValues memory _rv = _getRValues(tAmount, _tv.tFee, _tv.tLiquidity, _tv.tMarketingFee, _tv.tBurnFee, _tv.tBuybackFee, _getRate());
return (_rv, _tv);
}
function _getTValues(uint256 tAmount) private view returns (tValues memory) {
tValues memory _tv;
_tv.tFee = calculateTaxFee(tAmount);
_tv.tLiquidity = calculateLiquidityFee(tAmount);
_tv.tMarketingFee = calculateMarketingFee(tAmount);
_tv.tBurnFee = calculateBurnFee(tAmount);
_tv.tBuybackFee = calculateBuybackFee(tAmount);
_tv.tTransferAmount = tAmount.sub(_tv.tFee).sub(_tv.tLiquidity).sub(_tv.tMarketingFee).sub(_tv.tBurnFee).sub(_tv.tBuybackFee);
return (_tv);
}
function _getRValues(uint256 tAmount, uint256 tFee, uint256 tLiquidity, uint256 tMarketingFee, uint256 tBurnFee, uint256 tBuybackFee, uint256 currentRate) private pure returns (rValues memory) {
rValues memory _rv;
_rv.rAmount = tAmount.mul(currentRate);
_rv.rFee = tFee.mul(currentRate);
_rv.rLiquidity = tLiquidity.mul(currentRate);
_rv.rMarketingFee = tMarketingFee.mul(currentRate);
_rv.rBurnFee = tBurnFee.mul(currentRate);
_rv.rBuybackFee = tBuybackFee.mul(currentRate);
_rv.rTransferAmount = _rv.rAmount.sub(_rv.rFee).sub(_rv.rLiquidity).sub(_rv.rBurnFee).sub(_rv.rBuybackFee);
return (_rv);
}
function _getRate() private view returns (uint256) {
(uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
return rSupply.div(tSupply);
}
function _getCurrentSupply() private view returns (uint256, uint256) {
uint256 rSupply = _rTotalSupply;
uint256 tSupply = _tTotalSupply;
for (uint256 i = 0; i < _excluded.length; i++) {
if (_rBalances[_excluded[i]] > rSupply || _tBalances[_excluded[i]] > tSupply) return (_rTotalSupply, _tTotalSupply);
rSupply = rSupply.sub(_rBalances[_excluded[i]]);
tSupply = tSupply.sub(_tBalances[_excluded[i]]);
}
if (rSupply < _rTotalSupply.div(_tTotalSupply)) return (_rTotalSupply, _tTotalSupply);
return (rSupply, tSupply);
}
function calculateTaxFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_taxFee).div(10**2);
}
function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_liquidityFee).div(10**2);
}
function calculateMarketingFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_marketingFee).div(10**2);
}
function calculateBurnFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_burnFee).div(10**2);
}
function calculateBuybackFee(uint256 _amount) private view returns (uint256) {
return _amount.mul(_buybackFee).div(10**2);
}
function swapTokens(uint256 marketingTokensIn) private {
swapTokensForBNB(marketingTokensIn);
// swapTokensForBNB(contractTokenBalance);
uint256 contractETHBalance = address(this).balance;
if(contractETHBalance > 0) {
sendETHToFee(address(this).balance);
}
}
function sendETHToFee(uint256 amount) private {
marketingWallet.transfer(amount);
}
function swapTokensForBNB(uint256 tokenAmount) private {
// generate the pancake pair path of token -> wbnb
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = pancakeRouter.WETH();
_approve(address(this), address(pancakeRouter), tokenAmount);
// make the swap
pancakeRouter.swapExactTokensForETHSupportingFeeOnTransferTokens(
tokenAmount,
0, // accept any amount of BNB
path,
address(this),
block.timestamp
);
}
function swapBNBForTokens(uint256 amount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = pancakeRouter.WETH();
path[1] = address(this);
// make the swap
pancakeRouter.swapExactETHForTokensSupportingFeeOnTransferTokens{
value: amount
}(
0, // accept any amount of Tokens
path,
burnWallet, // dead address
block.timestamp.add(300)
);
}
function buyBackTokens() private {
uint256 amount = address(this).balance;
if (amount > buyBackUpperLimit) {amount = buyBackUpperLimit;}
if (amount > 0) {
swapBNBForTokens(amount);
}
}
function addLiquidity(uint256 tokenAmount, uint256 bnbAmount) private {
// approve token transfer to cover all possible scenarios
_approve(address(this), address(pancakeRouter), tokenAmount);
// add the liquidity
pancakeRouter.addLiquidityETH{value: bnbAmount}( // the return values of function not will are handled
address(this),
tokenAmount,
0,
0,
address(0),
block.timestamp
);
}
function removeAllFee() private {
if (_taxFee == 0 && _liquidityFee == 0 && _marketingFee == 0 && _burnFee == 0 && _buybackFee == 0) return;
_previousTaxFee = _taxFee;
_previousLiquidityFee = _liquidityFee;
_previousMarketingFee = _marketingFee;
_previousBurnFee = _burnFee;
_previousBuybackFee = _buybackFee;
_taxFee = 0;
_liquidityFee = 0;
_marketingFee = 0;
_burnFee = 0;
_buybackFee = 0;
}
function restoreAllFee() private {
_taxFee = _previousTaxFee;
_liquidityFee = _previousLiquidityFee;
_marketingFee = _previousMarketingFee;
_burnFee = _previousBurnFee;
_buybackFee = _previousBuybackFee;
}
// this method is responsible for taking all fee, if takeFee is true
function _tokenTransfer(address sender, address recipient, uint256 amount, bool takeFee) private {
if (!takeFee) {
removeAllFee();
}
if (_isExcluded[sender] && !_isExcluded[recipient]) {
_transferFromExcluded(sender, recipient, amount);
} else if (!_isExcluded[sender] && _isExcluded[recipient]) {
_transferToExcluded(sender, recipient, amount);
} else if (_isExcluded[sender] && _isExcluded[recipient]) {
_transferBothExcluded(sender, recipient, amount);
} else {
_transferStandard(sender, recipient, amount);
}
if (!takeFee) {
restoreAllFee();
}
}
function _transferStandard(address sender, address recipient, uint256 tAmount) private {
(rValues memory _rv, tValues memory _tv) = _getValues(tAmount);
_rBalances[sender] = _rBalances[sender].sub(_rv.rAmount);
_rBalances[recipient] = _rBalances[recipient].add(_rv.rTransferAmount);
_takeLiquidity(_tv.tLiquidity);
_reflectFee(_rv.rFee, _tv.tFee);
emit Transfer(sender, recipient, _tv.tTransferAmount);
swapTokens(_tv.tMarketingFee);
// _transferMarketingFee(sender, _rv.rMarketingFee, _tv.tMarketingFee);
_transferBurnFee(sender, _rv.rBurnFee, _tv.tBurnFee);
_transferBuybackFee(sender, _rv.rBuybackFee, _tv.tBuybackFee);
}
function _transferToExcluded(address sender, address recipient, uint256 tAmount) private {
(rValues memory _rv, tValues memory _tv) = _getValues(tAmount);
_rBalances[sender] = _rBalances[sender].sub(_rv.rAmount);
_tBalances[recipient] = _tBalances[recipient].add(_tv.tTransferAmount);
_rBalances[recipient] = _rBalances[recipient].add(_rv.rTransferAmount);
_takeLiquidity(_tv.tLiquidity);
_reflectFee(_rv.rFee, _tv.tFee);
emit Transfer(sender, recipient, _tv.tTransferAmount);
swapTokens(_tv.tMarketingFee);
_transferBurnFee(sender, _rv.rBurnFee, _tv.tBurnFee);
_transferBuybackFee(sender, _rv.rBuybackFee, _tv.tBuybackFee);
}
function _transferFromExcluded(address sender, address recipient, uint256 tAmount) private {
(rValues memory _rv, tValues memory _tv) = _getValues(tAmount);
_tBalances[sender] = _tBalances[sender].sub(tAmount);
_rBalances[sender] = _rBalances[sender].sub(_rv.rAmount);
_rBalances[recipient] = _rBalances[recipient].add(_rv.rTransferAmount);
_takeLiquidity(_tv.tLiquidity);
_reflectFee(_rv.rFee, _tv.tFee);
emit Transfer(sender, recipient, _tv.tTransferAmount);
swapTokens(_tv.tMarketingFee);
_transferBurnFee(sender, _rv.rBurnFee, _tv.tBurnFee);
_transferBuybackFee(sender, _rv.rBuybackFee, _tv.tBuybackFee);
}
function _transferBothExcluded(address sender, address recipient, uint256 tAmount) private {
(rValues memory _rv, tValues memory _tv) = _getValues(tAmount);
_tBalances[sender] = _tBalances[sender].sub(tAmount);
_rBalances[sender] = _rBalances[sender].sub(_rv.rAmount);
_tBalances[recipient] = _tBalances[recipient].add(_tv.tTransferAmount);
_rBalances[recipient] = _rBalances[recipient].add(_rv.rTransferAmount);
_takeLiquidity(_tv.tLiquidity);
_reflectFee(_rv.rFee, _tv.tFee);
emit Transfer(sender, recipient, _tv.tTransferAmount);
swapTokens(_tv.tMarketingFee);
_transferBurnFee(sender, _rv.rBurnFee, _tv.tBurnFee);
_transferBuybackFee(sender, _rv.rBuybackFee, _tv.tBuybackFee);
}
function _takeLiquidity(uint256 tLiquidity) private {
uint256 rLiquidity = tLiquidity.mul(_getRate());
_rBalances[address(this)] = _rBalances[address(this)].add(rLiquidity);
if (_isExcluded[address(this)]) {
_tBalances[address(this)] = _tBalances[address(this)].add(tLiquidity);
}
}
function _reflectFee(uint256 rFee, uint256 tFee) private {
_rTotalSupply = _rTotalSupply.sub(rFee);
_tFeeTotal = _tFeeTotal.add(tFee);
}
// function _transferMarketingFee(address sender, uint256 rMarketingFee, uint256 tMarketingFee) private {
// if (_marketingFee > 0) {
// _rBalances[marketingWallet] = _rBalances[marketingWallet].add(rMarketingFee);
// emit Transfer(sender, marketingWallet, tMarketingFee);
// _tMarketingTotal = _tMarketingTotal.add(tMarketingFee);
// }
// }
function _transferBurnFee(address sender, uint256 rBurnFee, uint256 tBurnFee) private {
if (_burnFee > 0) {
_rBalances[burnWallet] = _rBalances[burnWallet].add(rBurnFee);
emit Transfer(sender, burnWallet, tBurnFee);
_tBurnTotal = _tBurnTotal.add(tBurnFee);
}
}
function _transferBuybackFee(address sender, uint256 rBuybackFee, uint256 tBuybackFee) private {
if (_buybackFee > 0) {
_rBalances[buybackWallet] = _rBalances[buybackWallet].add(rBuybackFee);
emit Transfer(sender, buybackWallet, tBuybackFee);
_tBuybackTotal = _tBuybackTotal.add(tBuybackFee);
}
}
function initialTransfer(address sender, address recipient, uint256 tAmount) private{
uint256 rTransferAmount = reflectionFromToken(tAmount,false);
_rBalances[sender] = _rBalances[sender].sub(rTransferAmount);
_rBalances[recipient] = _rBalances[recipient].add(rTransferAmount);
emit Transfer(sender, recipient, tokenFromReflection(rTransferAmount));
}
}