About judge the buy/seller action

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;  

I’m not able to understand the question. :frowning: If English is not your native language consider writing in your native language and using a translator.

Please also provide more background about the problem.

1 Like

Hi, welcome! :wave:

I am not sure why do you want to know the action is buy or sell, what is the difference?

@Skyge
Thx your reply! :slightly_smiling_face:
Because i have difference logic at the buy and sell action, if buy and sell action all the code write in the _transfer method, it’s too many lines of code are not conducive to reading. If packaged separately, it will be easier to read and maintain later

Hi,
It is what I want also to do, I have the same conditions as you. =)
To answer to others, huo_huo simply wants to detect when a transfer is a buy, sell with the pair, sell to other people, to do a specific action of all.
Best regards.

Maybe someone would like to add liquidity on the Uniswap V3.