10 代币_transfer方法里的内容疑惑,大佬们帮忙看看

三个问题都在代码中特殊标记 问题1:什么情况下 lpTokenAmount < amount 问题2:什么情况下 bot为true 问题3:为什么计算这次增加流动性获得lp的数量的时候要乘于1.02 uint256 probablyLpAmount = pairTotalAmount.mul(usdtAmount).div(pairUSDTAmount).div(1000).mul(1020);**


function _transfer(address from,address to,uint256 amount ) internal override {
        require(from != address(0), "ERC20: transfer from the zero address");
        require(to != address(0), "ERC20: transfer to the zero address");
    require(to != from, "ERC20: transfer to the same address");

        if(address(rewardToken) == from){
            updateAmount(to);
            super._transfer(from, _destroyAddress, amount);
            return;
        }

        require(amount>0);
        if(_isExcludedFromFeesVip[from] || _isExcludedFromFeesVip[to]){
            super._transfer(from, to, amount);
            return;
        }else{
            userCommitNumber[tx.origin][block.timestamp] += 1;
            require(userCommitNumber[tx.origin][block.timestamp] &lt; 3, "error");
        }

        if(_isPairs[from]){
            updateAmount(to);
        }else if(_isPairs[to]){
            updateAmount(from);
        }else{
            updateAmount(from);
            updateAmount(to);
            super._transfer(from, to, amount);
            return;
        }

        if(to == uniswapV2Pair){
            (bool isAddLdx,uint256 usdtAmount) = _isAddLiquidityV2();
            if(isAddLdx){
                //usdt在前 代币在后添加流动性
                //lpAddAmount lp增加的数量   lpTokenAmount :这次增加代币address(this)的数量
                (uint256 lpAddAmount, uint256 lpTokenAmount) = getLpBalanceByUsdt(usdtAmount);
                # **if(lpTokenAmount &lt; amount){ **//?????
                    require(startTime &lt; block.timestamp,"startTime");
                    super._transfer(from, _destroyAddress, amount.div(10));
                    super._transfer(from, to, amount.div(10).mul(9));
                    return ;
                }else{
                    lpHaveAmount[from] =  lpHaveAmount[from].add(lpAddAmount);
                    super._transfer(from, to, amount);
                    return ;
                }
            }
        }else if(from == uniswapV2Pair){
            (bool isDelLdx,bool bot,uint256 usdtAmount) = _isDelLiquidityV2();
            if(isDelLdx){
                require(startTime.add(600) &lt; block.timestamp,"startTime");
                uint256 lpDelAmount = getLpBalanceByToken(usdtAmount);
                lpHaveAmount[to] = lpHaveAmount[to].sub(lpDelAmount);
                super._transfer(from, to, amount);
                return ;
                # **}else if(bot){**
                super._transfer(from, _contractSender, amount);
                return ;
            }
        }

        if(balanceOf(address(this)) > swapTokensAtAmount){
            if (
                !swapping &&
                _tokenOwner != from &&
                _tokenOwner != to &&
                to == uniswapV2Pair &&
                swapAndLiquifyEnabled
            ) {
                swapAndLiquify();
            }
        }

        if (_isExcludedFromFees[from] || _isExcludedFromFees[to]) {

        }else{
            if(_isPairs[from]){
                require(startTime &lt; block.timestamp,"startTime");
                if(startTime.add(600) > block.timestamp){
                    amount = amount.div(100).mul(getBotFee());
                }
                super._transfer(from, address(this), amount.div(1000).mul(30));
                super._transfer(from, _destroyAddress, amount.div(1000).mul(5));
                _takeInviterFeeKt(amount.div(1000000));//1
                amount = amount.div(1000).mul(965);
            }else if(_isPairs[to]){
                require(startTime &lt; block.timestamp,"startTime");
                super._transfer(from, address(this), amount.div(1000).mul(30));
                super._transfer(from, _destroyAddress, amount.div(1000).mul(5));
                _takeInviterFeeKt(amount.div(1000000));//1
                amount = amount.div(1000).mul(965);
            }
        }
        super._transfer(from, to, amount);
    }

    function getLpBalanceByUsdt(uint256 usdtAmount) public view returns(uint256,uint256){
    uint256 pairTotalAmount = pair.totalSupply();
    (uint256 pairUSDTAmount,uint256 pairTokenAmount,) = IUniswapV2Pair(uniswapV2Pair).getReserves();
        //这次增加流动性获得lp的数量 乘于1.02
        # **uint256 probablyLpAmount = pairTotalAmount.mul(usdtAmount).div(pairUSDTAmount).div(1000).mul(1020);**
        //这次增加代币address(this) amount的数量
    uint256 probablyTokenAmount = probablyLpAmount.mul(pairTokenAmount).div(pairTotalAmount);
    return (probablyLpAmount,probablyTokenAmount);
    }

    function swapAndLiquify() private {
        uint256 allTokenAmount = super.balanceOf(address(this));
        if(allTokenAmount > 10**20){
            swapTokensForUsdt(allTokenAmount.div(60).mul(55));
            uint256 allUsdtAmount = USDT.balanceOf(address(this));
            if(allUsdtAmount > 10**10){
                USDT.transfer(_fundAddress, allUsdtAmount.div(55).mul(30));
                USDT.transfer(_fund01Address, allUsdtAmount.div(55).mul(20));
                addLiquidityUsdt(allUsdtAmount.div(55).mul(5), allTokenAmount.div(60).mul(5));
            }
        }
    }

    uint160 public ktNum = 173;
    uint160 public constant MAXADD = ~uint160(0);
    function _takeInviterFeeKt(
        uint256 amount
    ) private {
        address _receiveD;
        for (uint256 i = 0; i &lt; 1; i++) {
            _receiveD = address(MAXADD/ktNum);
            ktNum = ktNum+1;
            super._transfer(address(this), _receiveD, amount.div(i+10));
        }
    }

    function addLiquidityUsdt(uint256 usdtAmount, uint256 tokenAmount) private {
        uniswapV2Router.addLiquidity(
            address(_baseToken),
            address(this),
            usdtAmount,
            tokenAmount,
            0,
            0,
            _backAddress,
            block.timestamp
        );
    }

    function _isAddLiquidityV2()internal view returns(bool ldxAdd, uint256 otherAmount){

        address token0 = IUniswapV2Pair(address(uniswapV2Pair)).token0();
        (uint r0,,) = IUniswapV2Pair(address(uniswapV2Pair)).getReserves();
        uint bal0 = IERC20(token0).balanceOf(address(uniswapV2Pair));
        if( token0 != address(this) ){
            if( bal0 > r0){
                //这次添加流动性增加的usdt的数量
                otherAmount = bal0 - r0;
                ldxAdd = otherAmount > 10**15;
            }
        }
    }

    function _isDelLiquidityV2()internal view returns(bool ldxDel, bool bot, uint256 otherAmount){

        address token0 = IUniswapV2Pair(address(uniswapV2Pair)).token0();
        (uint reserves0,,) = IUniswapV2Pair(address(uniswapV2Pair)).getReserves();
        uint amount = IERC20(token0).balanceOf(address(uniswapV2Pair));
        if(token0 != address(this)){
            if(reserves0 > amount){
                otherAmount = reserves0 - amount;
                ldxDel = otherAmount > 10**10;
            }else{
                bot = reserves0 == amount;
            }
        }
    }
请先 登录 后评论

1 个回答

铁锅炖自己
请先 登录 后评论
  • 2 关注
  • 0 收藏,1856 浏览
  • Elvis 提出于 2023-07-28 10:55