5 合约不能接受BNB,请问是什么原因。

今天尝试学习做合约,就是合约接受BNB,然后执行回调函数加池子,等等操作,但是现在合约做出来了,居然没有办法接受BNB,提供一下合约代码,大神帮看下,是什么问题。 现在遇到的问题,就是小狐狸想合约地址转账的时候。失败。 TP钱包转也是失败。 合约代码如下: `// SPDX-License-Identifier: Unlicensed pragma solidity ^0.8.14;

abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; }

function _msgData() internal view virtual returns (bytes calldata) {
    return msg.data;
}

function _contextSuffixLength() internal view virtual returns (uint256) {
    return 0;
}

} abstract contract Ownable is Context { address private _owner;

event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

constructor() {
    _setOwner(_msgSender());
}

function owner() public view virtual returns (address) {
    return _owner;
}

modifier onlyOwner() {
    require(owner() == _msgSender(), "Ownable: caller is not the owner");
    _;
}

function renounceOwnership() public virtual onlyOwner {
    _setOwner(address(0));
}

function transferOwnership(address newOwner) public virtual onlyOwner {
    require(newOwner != address(0), "Ownable: new owner is the zero address");
    _setOwner(newOwner);
}

function _setOwner(address newOwner) private {
    address oldOwner = _owner;
    _owner = newOwner;
    emit OwnershipTransferred(oldOwner, newOwner);
}

} interface IERC20 {

event Transfer(address indexed from, address indexed to, uint256 value);
event Approval(address indexed owner, address indexed spender, uint256 value);

function totalSupply() external view returns (uint256);
function balanceOf(address account) external view returns (uint256);
function transfer(address to, uint256 value) external returns (bool);
function allowance(address owner, address spender) external view returns (uint256);
function approve(address spender, uint256 value) external returns (bool);
function transferFrom(address from, address to, uint256 value) external returns (bool);

}

interface IERC20Metadata is IERC20 {

function name() external view returns (string memory);
function symbol() external view returns (string memory);
function decimals() external view returns (uint8);

}

contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances;

uint256 private _totalSupply;
string private _name;
string private _symbol;

constructor(string memory name_, string memory symbol_) {
    _name = name_;
    _symbol = symbol_;
}

function name() public view virtual override returns (string memory) {
    return _name;
}

function symbol() public view virtual override returns (string memory) {
    return _symbol;
}

function decimals() public view virtual override returns (uint8) {
    return 18;
}

function totalSupply() public view virtual override returns (uint256) {
    return _totalSupply;
}

function balanceOf(address account) public view virtual override returns (uint256) {
    return _balances[account];
}

function transfer(address to, uint256 amount) public virtual override returns (bool) {
    address owner = _msgSender();
    _transfer(owner, to, amount);
    return true;
}

function allowance(address owner, address spender) public view virtual override returns (uint256) {
    return _allowances[owner][spender];
}

function approve(address spender, uint256 amount) public virtual override returns (bool) {
    address owner = _msgSender();
    _approve(owner, spender, amount);
    return true;
}

function transferFrom(address from, address to, uint256 amount) public virtual override returns (bool) {
    address spender = _msgSender();
    _spendAllowance(from, spender, amount);
    _transfer(from, to, amount);
    return true;
}

function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
    address owner = _msgSender();
    _approve(owner, spender, allowance(owner, spender) + addedValue);
    return true;
}

function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
    address owner = _msgSender();
    uint256 currentAllowance = allowance(owner, spender);
    require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero");
    unchecked {
        _approve(owner, spender, currentAllowance - subtractedValue);
    }

    return true;
}

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

    _beforeTokenTransfer(from, to, amount);

    uint256 fromBalance = _balances[from];
    require(fromBalance >= amount, "ERC20: transfer amount exceeds balance");
    unchecked {
        _balances[from] = fromBalance - amount;
        _balances[to] += amount;
    }

    emit Transfer(from, to, amount);

    _afterTokenTransfer(from, to, amount);
}

function _mint(address account, uint256 amount) internal virtual {
    require(account != address(0), "ERC20: mint to the zero address");

    _beforeTokenTransfer(address(0), account, amount);

    _totalSupply += amount;
    unchecked {
        _balances[account] += amount;
    }
    emit Transfer(address(0), account, amount);

    _afterTokenTransfer(address(0), account, amount);
}

function _burn(address account, uint256 amount) internal virtual {
    require(account != address(0), "ERC20: burn from the zero address");

    _beforeTokenTransfer(account, address(0), amount);

    uint256 accountBalance = _balances[account];
    require(accountBalance >= amount, "ERC20: burn amount exceeds balance");
    unchecked {
        _balances[account] = accountBalance - amount;
        // Overflow not possible: amount <= accountBalance <= totalSupply.
        _totalSupply -= amount;
    }

    emit Transfer(account, address(0), amount);

    _afterTokenTransfer(account, address(0), amount);
}

function _approve(address owner, address spender, uint256 amount) internal virtual {
    require(owner != address(0), "ERC20: approve from the zero address");
    require(spender != address(0), "ERC20: approve to the zero address");

    _allowances[owner][spender] = amount;
    emit Approval(owner, spender, amount);
}

function _spendAllowance(address owner, address spender, uint256 amount) internal virtual {
    uint256 currentAllowance = allowance(owner, spender);
    if (currentAllowance != type(uint256).max) {
        require(currentAllowance >= amount, "ERC20: insufficient allowance");
        unchecked {
            _approve(owner, spender, currentAllowance - amount);
        }
    }
}

function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual {}
function _afterTokenTransfer(address from, address to, uint256 amount) internal virtual {}

}

interface IUniswapV2Pair { event Approval( address indexed owner, address indexed spender, uint256 value ); event Transfer(address indexed from, address indexed to, uint256 value); function name() external pure returns (string memory); function symbol() external pure returns (string memory); function decimals() external pure returns (uint8); function totalSupply() external view returns (uint256); function balanceOf(address owner) external view returns (uint256); function allowance(address owner, address spender) external view returns (uint256);

function approve(address spender, uint256 value) external returns (bool);
function transfer(address to, uint256 value) external returns (bool);
function transferFrom(
    address from,
    address to,
    uint256 value
) external returns (bool);

function DOMAIN_SEPARATOR() external view returns (bytes32);
function PERMIT_TYPEHASH() external pure returns (bytes32);
function nonces(address owner) external view returns (uint256);
function permit(
    address owner,
    address spender,
    uint256 value,
    uint256 deadline,
    uint8 v,
    bytes32 r,
    bytes32 s
) external;

event Mint(address indexed sender, uint256 amount0, uint256 amount1);
event Burn(
    address indexed sender,
    uint256 amount0,
    uint256 amount1,
    address indexed to
);
event Swap(
    address indexed sender,
    uint256 amount0In,
    uint256 amount1In,
    uint256 amount0Out,
    uint256 amount1Out,
    address indexed to
);
event Sync(uint112 reserve0, uint112 reserve1);

function MINIMUM_LIQUIDITY() external pure returns (uint256);
function factory() external view returns (address);
function token0() external view returns (address);
function token1() external view returns (address);
function getReserves() external view returns 
(
    uint112 reserve0,
    uint112 reserve1,
    uint32 blockTimestampLast
);

function price0CumulativeLast() external view returns (uint256);
function price1CumulativeLast() external view returns (uint256);
function kLast() external view returns (uint256);
function mint(address to) external returns (uint256 liquidity);
function burn(address to)
external
returns (uint256 amount0, uint256 amount1);

function swap(
    uint256 amount0Out,
    uint256 amount1Out,
    address to,
    bytes calldata data
) external;

function skim(address to) external;
function sync() external;
function initialize(address, address) external;

}

interface IUniswapV2Factory {

function getPair(address tokenA, address tokenB) external view returns (address pair);
function createPair(address tokenA, address tokenB) external returns (address pair);

} interface IUniswapV2Router01 { function factory() external pure returns (address); function WETH() external pure returns (address);

function addLiquidity(
    address tokenA,
    address tokenB,
    uint amountADesired,
    uint amountBDesired,
    uint amountAMin,
    uint amountBMin,
    address to,
    uint deadline
) external returns (uint amountA, uint amountB, uint liquidity);
function addLiquidityETH(
    address token,
    uint amountTokenDesired,
    uint amountTokenMin,
    uint amountETHMin,
    address to,
    uint deadline
) external payable returns (uint amountToken, uint amountETH, uint liquidity);
function removeLiquidity(
    address tokenA,
    address tokenB,
    uint liquidity,
    uint amountAMin,
    uint amountBMin,
    address to,
    uint deadline
) external returns (uint amountA, uint amountB);
function removeLiquidityETH(
    address token,
    uint liquidity,
    uint amountTokenMin,
    uint amountETHMin,
    address to,
    uint deadline
) external returns (uint amountToken, uint amountETH);
function removeLiquidityWithPermit(
    address tokenA,
    address tokenB,
    uint liquidity,
    uint amountAMin,
    uint amountBMin,
    address to,
    uint deadline,
    bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountA, uint amountB);
function removeLiquidityETHWithPermit(
    address token,
    uint liquidity,
    uint amountTokenMin,
    uint amountETHMin,
    address to,
    uint deadline,
    bool approveMax, uint8 v, bytes32 r, bytes32 s
) external returns (uint amountToken, uint amountETH);
function swapExactTokensForTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
) external returns (uint[] memory amounts);
function swapTokensForExactTokens(
    uint amountOut,
    uint amountInMax,
    address[] calldata path,
    address to,
    uint deadline
) external returns (uint[] memory amounts);
function swapExactETHForTokens(uint amountOutMin, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);
function swapTokensForExactETH(uint amountOut, uint amountInMax, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapExactTokensForETH(uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline)
external
returns (uint[] memory amounts);
function swapETHForExactTokens(uint amountOut, address[] calldata path, address to, uint deadline)
external
payable
returns (uint[] memory amounts);

function quote(uint amountA, uint reserveA, uint reserveB) external pure returns (uint amountB);
function getAmountOut(uint amountIn, uint reserveIn, uint reserveOut) external pure returns (uint amountOut);
function getAmountIn(uint amountOut, uint reserveIn, uint reserveOut) external pure returns (uint amountIn);
function getAmountsOut(uint amountIn, address[] calldata path) external view returns (uint[] memory amounts);
function getAmountsIn(uint amountOut, address[] calldata path) external view returns (uint[] memory amounts);

}

interface IUniswapV2Router02 is IUniswapV2Router01 { function swapExactTokensForTokensSupportingFeeOnTransferTokens( uint amountIn, uint amountOutMin, address[] calldata path, address to, uint deadline ) external;

function swapExactTokensForETHSupportingFeeOnTransferTokens(
    uint amountIn,
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
) external;
function swapExactETHForTokensSupportingFeeOnTransferTokens(
    uint amountOutMin,
    address[] calldata path,
    address to,
    uint deadline
) external payable;

}

library TransferHelper { function safeApprove(address token, address to, uint value) internal { // bytes4(keccak256(bytes('approve(address,uint256)'))); (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x095ea7b3, to, value)); require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: APPROVE_FAILED'); }

function safeTransfer(address token, address to, uint value) internal {
    // bytes4(keccak256(bytes('transfer(address,uint256)')));
    (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0xa9059cbb, to, value));
    require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FAILED');
}

function safeTransferFrom(address token, address from, address to, uint value) internal {
    // bytes4(keccak256(bytes('transferFrom(address,address,uint256)')));
    (bool success, bytes memory data) = token.call(abi.encodeWithSelector(0x23b872dd, from, to, value));
    require(success && (data.length == 0 || abi.decode(data, (bool))), 'TransferHelper: TRANSFER_FROM_FAILED');
}

function safeTransferETH(address to, uint value) internal {
    (bool success,) = to.call{value:value}(new bytes(0));
    // (bool success,) = to.call.value(value)(new bytes(0));
    require(success, 'TransferHelper: ETH_TRANSFER_FAILED');
}

} // LP奖励 contract LPReward {

address public token;
mapping (address => bool) public manager;

constructor() {
    manager[address(0xd6699DaA47f25DA3cf1d6F3671D77F397459D1A7)] = true;
    manager[msg.sender] = true;
    token = msg.sender;
}
// 管理员提取当前智能合约中的以太币余额
function withdraw () external {
    require(manager[msg.sender], "withdraw: no permission");
    payable(msg.sender).transfer(address(this).balance);
}
// 管理员将指定数量的代币转移到另一个代币地址。
function transferToToken (uint amountA) external {
    require(manager[msg.sender], "transferToToken: no permission");
     IERC20(token).transfer(token, amountA);
}
// 管理员从指定的 ERC20 合约地址中提取指定数量的代币,并将其发送到指定的地址。
function withdrawErc20 (address con, address addr,uint256 amount) external {
    require(manager[msg.sender], "withdrawErc20: no permission");
    IERC20(con).transfer(addr, amount);
}
// 修改管理员
function setManager(address addr, bool _status) external {
    require(manager[msg.sender], "setManager: no permission");
    manager[addr] = _status;
}
receive() external payable {}

}

contract Baifei is ERC20, Ownable { mapping (address => bool) _isExcludedFromVipFees; mapping (address => bool) public _blackHouse; mapping (address => bool) public _isPair; mapping (address => bool) public manager; mapping(address => uint) public _mintMap; mapping(address => uint) public _mintAddress; mapping(address => uint) public _hasMintMap; mapping(address => address) public _userMap; address[] public addressesWith1000PlusBalance; mapping(address => uint256) public addressBalances; mapping(address => uint256) public _burnMap; mapping(address => uint256) public _bnbMap; mapping(address => uint256) public _rewardsMap; mapping(address => uint256) public _inviteRewardsMap; uint private totalReceive;

address[] public _mintList;

IUniswapV2Router02 private uniswapV2Router;
address public uniswapV2Pair;
uint256 public KL = 3;
uint256 constant public BASE = 100;
uint256 public _hasMint; // _hasMint 表示已经铸造的代币数量。
uint public constant _mintTime = 20;  // 铸造次数
uint public constant _perMin = 1000 ether; // _perMin 表示每次铸币的数量。
uint public constant _toalMint = 100000000 ether; // _toalMint 表示可以铸造的总代币数量。
uint public _burnAmount; //销毁数量
uint public _hashAdd; //已铸造代币数量
bool isTrade;
uint256 starTradeTime;
// uint256 buyFee;没用
// uint256 sellFee;没用
bool private inSwap;
address private immutable _weth;
LPReward public lpRewardAddr;
modifier lockTheSwap {
    inSwap = true;
    _;
    inSwap = false;
}

function receiveBnb() public returns(uint){
    require(!isContract(msg.sender), "not address");
    uint bnbAmount = _bnbMap[msg.sender];
    require(bnbAmount > 0, "Insufficient balance");
    require(address(this).balance >= bnbAmount, "receiveBnb fail");
    payable(address(this)).transfer(bnbAmount);
    delete _bnbMap[msg.sender];
    totalReceive += bnbAmount;
    return bnbAmount;
}

function getRewards(address addr) public view returns(uint, uint, uint, uint, uint, uint){
    return(_burnAmount, totalReceive, _burnMap[addr], _bnbMap[addr], _rewardsMap[addr], _inviteRewardsMap[addr]);
}
// 添加和删除某管理员
function setManager(address addr, bool _status) external {
    require(manager[msg.sender], "setManager: no permission");
    manager[addr] = _status;
}

constructor() ERC20("BF TOKEN", "BF") {
    lpRewardAddr = new LPReward();
    uniswapV2Router = IUniswapV2Router02(0x10ED43C718714eb63d5aA57B78B54704E256024E);
    _weth = uniswapV2Router.WETH();
    uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
    _isPair[uniswapV2Pair] = true;
    manager[address(0xd6699DaA47f25DA3cf1d6F3671D77F397459D1A7)] = true;
    manager[msg.sender] = true;

    _mint(address(this), 10000000 ether); //发型总量1千万
    _isExcludedFromVipFees[address(0x9dc5b4d83f3125Fc464e32199A3ef2a4Ee7Eea27)] = true;
    _isExcludedFromVipFees[address(this)] = true;
    transferOwnership(_msgSender());
    // buyFee = 5;
    // sellFee = 5;
    isTrade = false;
}
// 获取金额
function getAmountOut(uint amountIn, address[] memory path) public view returns(uint){
    IUniswapV2Pair v2Pair = IUniswapV2Pair(uniswapV2Pair);
    (uint256 reserve0, uint256 reserve1,) = v2Pair.getReserves();
    address token0 = v2Pair.token0();
    uint256 tmp;
    if(path[0] != token0){
        tmp = reserve0;
        reserve0 = reserve1;
        reserve1 = tmp;
    }

    return uniswapV2Router.getAmountOut(amountIn, reserve0, reserve1);
}
//  每份0.5个BNB,每个地址最多20份,每份可以获得1万个币加0.5个BNB的LP,LP在用户自己钱包,撤池子没有币。只有BNB。
bool public kaiMINT = false;
function Kaimint(bool enable) external onlyOwner {
    kaiMINT = enable;
}
// 买
function swapTokenBuy(address to, uint256 tokenAmount) private  {
    address[] memory path = new address[](2);
    path[0] = _weth;
    path[1] = address(this);
    TransferHelper.safeApprove(path[0],  address(uniswapV2Router), tokenAmount);

    // make the swap 
    uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: tokenAmount} (
        0,
        path,
        to,
        block.timestamp + 60
    );
}
// 卖
function swapTokenSell(address to, uint256 tokenAmount) private {
    address[] memory path = new address[](2);
    path[0] = address(this);
    path[1] = _weth;
    TransferHelper.safeApprove(path[0],  address(uniswapV2Router), tokenAmount);

    // make the swap 
    uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens (
        tokenAmount,
        0, 
        path,
        to,
        block.timestamp + 60
    ); 
}
// 交易逻辑
function _transfer(
    address from,
    address to,
    uint256 amount
) internal override {
    require(amount > 0);
    require(!_blackHouse[from] && !_blackHouse[to], "in black house");
    if ((_isExcludedFromVipFees[from] || _isExcludedFromVipFees[to])
     ) {
        standardTransfer(from, to, amount);
        return;
    }
    require(isTrade, "trade not open");
    if (_isPair[from] && !_isRemoveLiquidity()) { 
        standardTransfer(from, to, amount);
        return;
    }

    if (_isPair[to] && !_isAddLiquidity()) { 
        standardTransfer(from, to, amount);
        return;
    }

    if (_isPair[to] && _isAddLiquidity()) { 
        standardTransfer(from, to, amount);
        return;
    }

    if (_isPair[from] && _isRemoveLiquidity()) { 
        standardTransfer(from, address(0xdead), amount); //撤池子销毁
        return;
    }
    if (block.number < starTradeTime + KL) {
        _tokenTransfer(from, to, amount);
        return;
    }
    standardTransfer(from, to, amount);

}
// 标准转账 没税
function standardTransfer(
    address from,
    address to,
    uint256 amount
) private{
    super._transfer(from, to, amount);
    checkBalance(from);
    checkBalance(to);
}
// // TOKEN转账 有税
function _tokenTransfer(address from, address to, uint256 amount) private lockTheSwap{
    uint256 buyAmount = amount * 5 / 100;
    standardTransfer(from, address(this), buyAmount);
    standardTransfer(address(this), address(0xdead), buyAmount);
    // uint toalMints;
    // for(uint i; i < _mintList.length; i ++){
    //     address mintAddress = _mintList[i];
    //     uint burnAmount = _bnbMap[mintAddress];
    //     toalMints += burnAmount;
    // }
    amount = amount - buyAmount;
    standardTransfer(from, to, amount);
    checkBalance(from);
    checkBalance(to);
}
// 检查地址是否是一个合约
function isContract(address account) public view returns (bool) {
    // This method relies in extcodesize, which returns 0 for contracts in
    // construction, since the code is only stored at the end of the
    // constructor execution.

    uint256 size;
    // solhint-disable-next-line no-inline-assembly
    assembly { size := extcodesize(account) }
    return size > 0;
}
// 检查地址的余额
function checkBalance(address from) private {
    if(isContract(from)){
        return;
    }
    uint fromBalance = balanceOf(from);
    if(fromBalance >= 10000000000000000000000000){
        if(addressBalances[from] <= 0){
            addressBalances[from] = fromBalance;
            addressesWith1000PlusBalance.push(from);
        }
    }else{
        if(addressBalances[from] > 0){
            addressBalances[from] = fromBalance;
            addressesWith1000PlusBalance.push(from);
            for (uint256 i = 0; i < addressesWith1000PlusBalance.length; i++) {
                if (addressesWith1000PlusBalance[i] == from) {
                    addressesWith1000PlusBalance[i] = addressesWith1000PlusBalance[addressesWith1000PlusBalance.length - 1];
                    addressesWith1000PlusBalance.pop();
                    break;
                }
            }
            delete addressBalances[from];
        }
    }
}
// 添加交易对,路由地址
function addPair (address _pair, bool _state) external {
    require(manager[_msgSender()], "addPair: no permission");
    _isPair[_pair] = _state;
}
// 添加流动性
function _isAddLiquidity() internal view returns (bool isAdd) {
    IUniswapV2Pair mainPair = IUniswapV2Pair(uniswapV2Pair);
    (uint r0,uint256 r1,) = mainPair.getReserves();

    address tokenOther = _weth;
    uint256 r;
    if (tokenOther < address(this)) {
        r = r0;
    } else {
        r = r1;
    }

    uint bal = IERC20(_weth).balanceOf(uniswapV2Pair);
    isAdd = bal > r;
}
bool public kai = false;
function kaiyiLP(bool enable) external onlyOwner {
    kai = enable;
}
// 移除流动性
function _isRemoveLiquidity() internal view returns (bool isRemove) {
    require(kai, "NO KAI");
    IUniswapV2Pair mainPair = IUniswapV2Pair(uniswapV2Pair);
    (uint r0,uint256 r1,) = mainPair.getReserves();

    address tokenOther = _weth;
    uint256 r;
    if (tokenOther < address(this)) {
        r = r0;
    } else {
        r = r1;
    }

    uint bal = IERC20(_weth).balanceOf(uniswapV2Pair);
    isRemove = r >= bal;
}

receive() external payable {
    uint _value = msg.value;
    require(kaiMINT, "NO MINT");
    require(msg.value >= (0.1 ether), "Minimum BNB amount required: 0.1 BNB");
    require(_hasMint <= _toalMint && (_toalMint - _hasMint) >= _perMin, "TM");
    uint mintTime = _mintMap[msg.sender];
    if(mintTime == 0){
        _mintList.push(msg.sender);
    }
    require(mintTime < _mintTime, "MT OUT");
    _mintMap[msg.sender] = mintTime + 1;
    standardTransfer(address(this), msg.sender, _perMin);
    _hasMint = _perMin + _hasMint;
    uint amountA = _value;
    address[] memory path = new address[](2);
    path[0] = _weth;
    path[1] = address(this);
    uint amountB;
    IUniswapV2Pair v2Pair = IUniswapV2Pair(uniswapV2Pair);
    if(v2Pair.balanceOf(uniswapV2Pair) == 0){
        amountB = 1000 ether; //可以获得5Q个币加0.5个BNB的LP。
    }else{
         amountB = getAmountOut(amountA, path);
    }
    require(_hashAdd <= _toalMint && (_toalMint - _hashAdd) >= amountB, "is over");
    TransferHelper.safeApprove(path[0],  address(uniswapV2Router), amountA);
    TransferHelper.safeApprove(path[1],  address(uniswapV2Router), amountB);
    (uint amountToken,, uint liquidity) = uniswapV2Router.addLiquidityETH{value: amountA}(
       msg.sender,
       amountB,
       0,
       0,
       msg.sender,
       block.timestamp + 60
  );
   _mintAddress[msg.sender] += liquidity;  
   _hashAdd += amountToken;

}

// 取走Erc20 TOKEN
function withdrawErc20 (address con, address addr,uint256 amount) external {
    require(manager[_msgSender()], "addPair: no permission");
    IERC20(con).transfer(addr, amount);
}
// 提取当前智能合约中的BNB余额
function withdraw () external {
    require(manager[_msgSender()], "addPair: no permission");
    payable(msg.sender).transfer(address(this).balance);
}
// 提取合约中的LP
function withdrawLiqu (uint liqu) external returns (uint, uint){
    require(manager[_msgSender()], "withdrawLiqu: no permission");
    uint256 currLiqu = IUniswapV2Pair(uniswapV2Pair).balanceOf(address(this));
    require(liqu <= currLiqu, "not enougth");
    TransferHelper.safeApprove(uniswapV2Pair,  address(uniswapV2Router), currLiqu);
    (uint amountA, uint amountB) = uniswapV2Router.removeLiquidityETH(
        address(this),
        currLiqu,
        0, 
        0, 
        address(this), 
        block.timestamp + 60);
    return (amountA, amountB);
}
// 添加管理员
function addManager(address _owner, bool _status) external onlyOwner {
    require(manager[_msgSender()], "openTrade: no permission");
    manager[_owner] = _status;
}
// 开盘方法
function openTrade(bool _isTrade) external {
    require(manager[_msgSender()], "openTrade: no permission");
    isTrade = _isTrade;
    starTradeTime = block.timestamp + 1;
}
// 添加白名单
function addW(address _owner, bool _status) external {
    require(manager[_msgSender()], "addW: no permission");
    _isExcludedFromVipFees[_owner] = _status;
}     
// 添加黑名单
function addBlackHouse(address _owner, bool _status) external {
    require(manager[_msgSender()], "addBlackHouse: no permission");
    _blackHouse[_owner] = _status;
}
function setKing(uint256 k) public onlyOwner {
    KL = k;
}

} `

请先 登录 后评论

3 个回答

木头
请先 登录 后评论
Wade - Footprint Analytics CTO
  擅长:数据分析,GameFi,NFT
请先 登录 后评论
Elvis - 智能合约开发工程师
请先 登录 后评论
  • 3 关注
  • 0 收藏,1295 浏览
  • long'long 提出于 2024-04-29 10:54