hello guys.
I want to judge the buy/seller action, so i try to write some code, and i has verfiy at the testnet uniswap, when i do the buy/seller action and transfer between tow account the state variable change is expected. such as buy action the state variable value will be 2.
But now i am not sure it has include all cases.
i do not konw if the sender/recipient address will There are other unknown situations.
here is my code
uint256 public state = 0;
function _transfer(address sender, address recipient, uint256 amount) internal virtual {
require(sender != address(0), "ERC20: transfer from the zero address");
require(recipient != address(0), "ERC20: transfer to the zero address");
require(_balances[sender] >= amount, "ERC20: transfer amount exceeds balance");
if(adminAddress[sender] || adminAddress[recipient]){
state = 1;
_standerTransfer(sender, recipient, amount);
return;
}
//buy token
if(sender == uniswapV2Pair && recipient != address(this)){
state = 2;
_buyToken(sender, recipient, amount);
return;
}
//sell token
if(sender != address(this) && recipient == uniswapV2Pair){
state = 3;
_sellToken(sender, recipient, amount);
return;
}
//transfer between tow account
if(sender != address(this) && sender != uniswapV2Pair && recipient != address(this) && recipient != uniswapV2Pair){
state = 4;
_standerTransfer(sender, recipient, amount);
return;
}
//TODO other unkown
state = 5;
_standerTransfer(sender, recipient, amount);
}
function _standerTransfer(address sender, address recipient, uint256 amount) private {
_balances[sender] = _balances[sender].sub(amount);
_balances[recipient] = _balances[recipient].add(amount);
emit Transfer(sender, recipient, amount);
}
function _buyToken(address sender, address recipient, uint256 amount) private {
//_standerTransfer(sender, recipient, amount);
//TODO the buy action logic
}
function _sellToken(address sender, address recipient, uint256 amount) private {
//_standerTransfer(sender, recipient, amount);
//TODO the sell action logic
}
by the way the uniswapV2Pair i have build at the constructor method, and here the code
IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory()).createPair(address(this), _uniswapV2Router.WETH());
uniswapV2Router = _uniswapV2Router;