Hello,
I have a transfer override function to add fees - taxes when users swap my token.
My issue is that the taxes work when the user is swapping BNB for Token, but when user tries to Swap Token for BNB they wont. What am i missing?
function transfer(address recipient, uint256 amount) public override returns (bool) {
if (_msgSender() == uniswapPair) {
// If wallets are excluded from fees dont pay taxes for swap
if (excludedFromFees[_msgSender()] || excludedFromFees[recipient]) {
_transfer(_msgSender(), recipient, amount);
return true;
}
// Stops investors from owning more than 2% of the total supply from purchasing YMT from PancakeSwap.
if (!excludedFromFees[_msgSender()] && !excludedFromFees[recipient]) {
require((balanceOf(recipient) + amount) < (totalSupply() / 75), "You can't have more than 2% of the total YMT supply after a PancakeSwap swap.");
}
}
if (_msgSender() != uniswapPair) {
// No fees from wallet to wallet transactions but check for 2% of recipient
if (!excludedFromFees[_msgSender()] && !excludedFromFees[recipient]) {
require((balanceOf(recipient) + amount) < (totalSupply() / 75), "You can't have more than 2% of the total YMT supply.");
_transfer(_msgSender(), recipient, amount);
return true;
}
// No fees for sending from or to contract wallets
if (excludedFromFees[_msgSender()] || excludedFromFees[recipient]) {
_transfer(_msgSender(), recipient, amount);
return true;
}
}
// Yacht transaction fee.
uint256 yachtFee = (amount * yachtTransactionFeePercent) / 100;
// Marketing team transaction fee.
uint256 marketingFee = (amount * marketingFeePercent) / 100;
// Developer team transaction fee.
uint256 developerFee = (amount * developerFeePercent) / 100;
// Burn fee
uint256 burnFee = (amount * burnFeePercent) / 100;
// The total fee to send to the contract address.
uint256 totalFee = yachtFee + marketingFee + developerFee + burnFee;
// Sends the transaction fees to the contract address
_transfer(_msgSender(), address(this), totalFee);
// Sends [initial amount] - [fees] to the recipient
uint256 valueAfterFees = amount - totalFee;
_transfer(_msgSender(), recipient, valueAfterFees);
return true;
}