Hi,
I'm adding fees to a token and I want to distinguish buys and sells when swapping.
I don't want to include fees when the token is transferred or liquidity is added. While testing, I realized that adding liquidity takes fees from the user as well.
How can I make sure fees are only accounted for when swapping and not when adding liquidity?
Some code:
function _transfer(address sender, address recipient, uint amount) internal override virtual{
requires(...)
variables(...)
if (isExcludedFromFee[sender]) {
takeFee = false;
}
bool Buy = getLPStatus(sender) || getRouterStatus(sender);
bool Sell = getLPStatus(recipient) || getRouterStatus(recipient);
taxes = (Buy) ? amount.mul(buyFeePercentage).div(10000) : taxes;
taxes = (Sell) ? amount.mul(sellFeePercentage).div(10000) : taxes;
if (!takeFee || taxes == 0){
_realTransfer(sender, recipient, amount);
} else {
amount = amount.sub(taxes);
_realTransfer(sender, recipient, amount);
uint taxD = taxAmount.mul(devpercent).div(10000);
uint taxBurn = taxAmount.sub(taxD).mul(burnpercent).div(10000);
uint taxlps = taxAmount.sub(taxD).sub(taxBurn);
_realTransfers(...)
}
}
Also, I'm making transfers to another smart contract/wallet because I'm not sure how to prevent sandwich attacks unless I hardcode a low slippage but sounds like a pretty bad choice. Sending the funds to another smart contract will allow me to change it in the future once it's properly optimized.
Thank you,