We are trying to process a fee when tokens are "Sold" on PancakeSwap. For now "Sold" is when the user swaps their tokens for BNB. Initially our current logic would also charge a fee when adding to the LP. (Which is not considered a sell in our usecase)
We noticed Pancake uses AddLiquidityETH to transfer tokens to the LP, and SwapETHForExactTokens also performs the same action during execution.
How can we differentiate during execution time between AddLiquidtyETH or SwapETHForExactTokens?
Our current _transfer
function looks as follows:
/// @dev overrides transfer function to meet tokenomics of UFF
function _transfer(address sender, address recipient, uint256 amount) internal virtual override antiWhale(sender, recipient, amount) {
// If not modified, full ammount is transfer
uint256 sendAmount = amount;
// Buy action?
if(lpToken != address(0) && msg.sender == lpToken && recipient != PCSRouter){
// default buy fee is 5% / Token OPs Team (dev and marketing)
uint256 buyFeeAmount = amount.mul(maxBuyFee).div(10000);
sendAmount = amount.sub(buyFeeAmount);
require(amount == sendAmount + buyFeeAmount, "UFF::transfer: Buy value invalid");
super._transfer(sender, team, buyFeeAmount);
}
// Sell Action?
if(lpToken != address(0) && recipient == lpToken && msg.sender != PCSRouter){
uint256 sellFeeAmount = amount.mul(maxSellFee).div(10000);
sendAmount = amount.sub(sellFeeAmount);
require(amount == sendAmount + sellFeeAmount, "UFF::transfer: Sell value invalid");
super._transfer(sender, team, sellFeeAmount);
}
// default 100% of transfer sent to recipient
super._transfer(sender, recipient, sendAmount);
}
Thank you in advance