I cant send my coins to another wallet

I cant send my coins to another wallet. I have sufficient bnb on my metamask. I tried sending both 100 and 1 million token. This is my smart contract

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.9;

import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/token/ERC20/ERC20.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/access/Ownable.sol";
import "https://github.com/OpenZeppelin/openzeppelin-contracts/blob/v4.9.0/contracts/security/ReentrancyGuard.sol";

interface IUniswapV2Factory {
    function createPair(address tokenA, address tokenB) external returns (address pair);
}

interface IUniswapV2Router02 {
    function factory() external pure returns (address);
    function WETH() external pure returns (address);
    
    function swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
    
    function addLiquidityETH(
        address token,
        uint amountTokenDesired,
        uint amountTokenMin,
        uint amountETHMin,
        address to,
        uint deadline
    ) external payable returns (uint amountToken, uint amountETH, uint liquidity);
}

contract ElonBucks is ERC20, Ownable, ReentrancyGuard {
    IUniswapV2Router02 public immutable uniswapV2Router;
    address public immutable uniswapV2Pair;
    
    bool private swapping;

    // Max Transaction/Wallet Settings
    mapping(address => bool) private _isExcludedFromMaxTx;
    mapping(address => bool) private _isExcludedFromMaxWallet;
    uint256 public maxTransactionAmount;
    uint256 public maxWalletAmount;

    // Fee Settings
    struct Fees {
        uint256 liquidityFee;   // Auto-LP fee
        uint256 burnFee;        // Token burn fee
    }

    Fees public buyFees;
    Fees public sellFees;
    uint256 public constant MAX_TOTAL_FEE = 25;  // Maximum 25% total fee
    
    // Auto-LP Settings
    uint256 public swapTokensAtAmount;
    bool public swapEnabled = true;

    // Events
    event MaxTxAmountUpdated(uint256 newAmount);
    event MaxWalletAmountUpdated(uint256 newAmount);
    event AutoLiquidityAdded(uint256 tokensToLiquidity, uint256 bnbToLiquidity);
    event TokensBurned(uint256 amount);

    constructor(
        string memory name_,
        string memory symbol_,
        uint256 totalSupply_
    ) ERC20(name_, symbol_) {
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(
            0x10ED43C718714eb63d5aA57B78B54704E256024E  // PancakeSwap Router
        );
        
        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());
            
        uniswapV2Router = _uniswapV2Router;
        
        // Initialize fees (Buy: 2% total, Sell: 2.5% total)
        buyFees = Fees({
            liquidityFee: 17,    // 1.7% to LP (17 = 1.7%)
            burnFee: 3           // 0.3% to Burn (3 = 0.3%)
        });

        sellFees = Fees({
            liquidityFee: 22,    // 2.2% to LP (22 = 2.2%)
            burnFee: 3           // 0.3% to Burn (3 = 0.3%)
        });

        // Set limits
        maxTransactionAmount = totalSupply_ * 5 / 100;  // 5% max tx
        maxWalletAmount = totalSupply_ * 4 / 100;       // 4% max wallet
        swapTokensAtAmount = totalSupply_ * 1 / 1000;   // 0.1% swap threshold

        // Exclude contract and owner from limits
        _isExcludedFromMaxTx[address(this)] = true;
        _isExcludedFromMaxTx[owner()] = true;
        _isExcludedFromMaxWallet[address(this)] = true;
        _isExcludedFromMaxWallet[owner()] = true;

        _mint(owner(), totalSupply_ * 10**decimals());
    }

    // Fee Management
    function setBuyFees(uint256 _liquidityFee, uint256 _burnFee) external onlyOwner {
        require(_liquidityFee + _burnFee <= MAX_TOTAL_FEE, "Fees too high");
        buyFees.liquidityFee = _liquidityFee;
        buyFees.burnFee = _burnFee;
    }

    function setSellFees(uint256 _liquidityFee, uint256 _burnFee) external onlyOwner {
        require(_liquidityFee + _burnFee <= MAX_TOTAL_FEE, "Fees too high");
        sellFees.liquidityFee = _liquidityFee;
        sellFees.burnFee = _burnFee;
    }

    // Transaction/Wallet Limit Management
    function setMaxTxAmount(uint256 newAmount) external onlyOwner {
        require(newAmount >= totalSupply() / 1000, "Max TX too low");
        maxTransactionAmount = newAmount;
        emit MaxTxAmountUpdated(newAmount);
    }

    function setMaxWalletAmount(uint256 newAmount) external onlyOwner {
        require(newAmount >= totalSupply() / 1000, "Max wallet too low");
        maxWalletAmount = newAmount;
        emit MaxWalletAmountUpdated(newAmount);
    }

    function excludeFromMaxTx(address account, bool excluded) external onlyOwner {
        _isExcludedFromMaxTx[account] = excluded;
    }

    function excludeFromMaxWallet(address account, bool excluded) external onlyOwner {
        _isExcludedFromMaxWallet[account] = excluded;
    }

    // Main transfer function
    function _transfer(
        address from,
        address to,
        uint256 amount
    ) internal virtual override {
        require(from != address(0), "Transfer from zero");
        require(to != address(0), "Transfer to zero");
        
        // Handle max transaction/wallet limits
        if (!_isExcludedFromMaxTx[from] && !_isExcludedFromMaxTx[to]) {
            require(amount <= maxTransactionAmount, "Exceeds max tx");
        }
        
        if (!_isExcludedFromMaxWallet[to]) {
            require(balanceOf(to) + amount <= maxWalletAmount, "Exceeds max wallet");
        }

        // Check if taking fee
        bool takeFee = !swapping;

        if (takeFee) {
            uint256 feeAmount = 0;
            // Calculate fees based on buy/sell
            if (from == uniswapV2Pair) { // Buy
                feeAmount = (amount * (buyFees.liquidityFee + buyFees.burnFee)) / 1000;
            } else if (to == uniswapV2Pair) { // Sell
                feeAmount = (amount * (sellFees.liquidityFee + sellFees.burnFee)) / 1000;
            }

            if (feeAmount > 0) {
                // Handle burn fee
                uint256 burnAmount = (from == uniswapV2Pair) 
                    ? (amount * buyFees.burnFee) / 1000
                    : (amount * sellFees.burnFee) / 1000;
                
                if (burnAmount > 0) {
                    super._transfer(from, address(0xdead), burnAmount);
                    emit TokensBurned(burnAmount);
                    feeAmount -= burnAmount;
                }

                // Transfer remaining fees (liquidity) to contract
                if (feeAmount > 0) {
                    super._transfer(from, address(this), feeAmount);
                    amount -= (feeAmount + burnAmount);
                }
            }
        }

        super._transfer(from, to, amount);

        // Handle auto-liquidity
        if (
            !swapping &&
            swapEnabled &&
            balanceOf(address(this)) >= swapTokensAtAmount &&
            from != uniswapV2Pair
        ) {
            swapAndLiquify();
        }
    }

    // Auto-Liquidity Function
    function swapAndLiquify() private {
        swapping = true;
        
        uint256 contractTokenBalance = balanceOf(address(this));
        uint256 half = contractTokenBalance / 2;
        uint256 otherHalf = contractTokenBalance - half;

        uint256 initialBalance = address(this).balance;

        // Swap half tokens for BNB
        swapTokensForBNB(half);

        uint256 newBalance = address(this).balance - initialBalance;

        // Add liquidity
        addLiquidity(otherHalf, newBalance);
        
        emit AutoLiquidityAdded(otherHalf, newBalance);
        swapping = false;
    }

    function swapTokensForBNB(uint256 tokenAmount) private {
        address[] memory path = new address[](2);
        path[0] = address(this);
        path[1] = uniswapV2Router.WETH();

        _approve(address(this), address(uniswapV2Router), tokenAmount);
        uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
            tokenAmount,
            0,
            path,
            address(this),
            block.timestamp
        );
    }

    function addLiquidity(uint256 tokenAmount, uint256 bnbAmount) private {
        _approve(address(this), address(uniswapV2Router), tokenAmount);
        uniswapV2Router.addLiquidityETH{value: bnbAmount}(
            address(this),
            tokenAmount,
            0,
            0,
            owner(),
            block.timestamp
        );
    }

    receive() external payable {}
}
1 Like