// Contract: CHAMP
// Target function: function swapAndLiquifyNow(uint256 Percent_of_Tokens_to_Process) external onlyOwner
// SPDX-License-Identifier: Unlicensed 
// This contract is not open source and can not be used/forked without permission
// Contract created at TokensByGen.com

/*


http://t.me/champiooontoken
www.champiooon.com
https://twitter.com/Champiooon2?s=09 
    

*/

pragma solidity 0.8.19;
 
interface IERC20 {

    function name() external view returns (string memory);
    function symbol() external view returns (string memory);
    function decimals() external view returns (uint256);
    function totalSupply() external view returns (uint256);
    function balanceOf(address account) external view returns (uint256);
    function transfer(address recipient, uint256 amount) external returns (bool);
    function allowance(address owner, address spender) external view returns (uint256);
    function approve(address spender, uint256 amount) external returns (bool);
    function transferFrom(address sender, address recipient, uint256 amount) external returns (bool);
}

interface IUniswapV2Factory {
    function createPair(address tokenA, address tokenB) external returns (address pair);
    function getPair(address tokenA, address tokenB) external view returns (address pair);
}

interface IUniswapV2Pair {
    function factory() external view returns (address);
}

interface IUniswapV2Router02 {

    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 swapExactTokensForETHSupportingFeeOnTransferTokens(
        uint amountIn,
        uint amountOutMin,
        address[] calldata path,
        address to,
        uint deadline
    ) external;
}

abstract contract Context {
    function _msgSender() internal view virtual returns (address) {
        return msg.sender;
    }
}





contract CHAMP is Context, IERC20 { /// Change contratc name to name of token!

    // Contract Wallets
    address public _owner = 0x5deA306c51aFC23cB6Df672f4F7eFa045593bfF0; 
    address public Wallet_Liquidity = 0x5deA306c51aFC23cB6Df672f4F7eFa045593bfF0; 
    address payable public Wallet_Marketing = payable(0x5deA306c51aFC23cB6Df672f4F7eFa045593bfF0);  
    address public constant Wallet_Burn = 0x000000000000000000000000000000000000dEaD;


    // Token Info
    string private  _name = "CHAMP"; 
    string private  _symbol = "CMP"; 
    uint256 private _decimals = 9; 
    uint256 private _tTotal = 100_000_000 * 10 ** _decimals;

    // Fees
    uint8 public _fee__Liquidity = 4;
    uint8 public _fee__Marketing = 2;


    // Total Fee for Swap
    uint8 private _SwapFeeTotal = 6;


    // Set factory
    IUniswapV2Router02 public uniswapV2Router;
    address public uniswapV2Pair;


    constructor () {

        // Whitelist owner so they can add initial liquidity 
        _isWhiteListed[_owner] = true;

        // Wallets excluded from fees
        _isExcludedFromFee[_owner] = true;
        _isExcludedFromFee[address(this)] = true;
        _isExcludedFromFee[Wallet_Burn] = true;

        _tOwned[_owner] = _tTotal;
      
        emit Transfer(address(0), _owner, _tTotal);
        emit OwnershipTransferred(address(0), _owner);

    }

    // Events
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
    event updated_fees(uint8 Marketing, uint8 Liquidity);
    event updated_SwapAndLiquify_Enabled(bool Swap_and_Liquify_Enabled);
    event SwapAndLiquify(uint256 tokensSwapped, uint256 ethReceived, uint256 tokensIntoLiqudity);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
    event TokenCreated(address indexed Token_CA);
    event LiquidityAdded(uint256 Tokens_Amount, uint256 BNB_Amount);


    // Restrict function to contract owner only 
    modifier onlyOwner() {
        require(owner() == _msgSender(), "Ownable: caller is not the owner");
        _;
    }

    // Address mappings
    mapping (address => uint256) private _tOwned;                               // Tokens Owned
    mapping (address => mapping (address => uint256)) private _allowances;      // Allowance to spend another wallets tokens
    mapping (address => bool) public _isExcludedFromFee;                        // Wallets that do not pay fees
    mapping (address => bool) public _isWhiteListed;                            // Wallets that have access before trade is open
    mapping (address => bool) public _isPair;                                   // Address is liquidity pair

    // Fee Processing Triggers
    uint256 private swapTrigger = 11; 
    uint256 private swapCounter = 1;    
    
    // Fee processing (SwapAndLiquify) Switch                  
    bool public processingFees;
    bool public feeProcessingEnabled; 

    // Launch Settings
    bool public Trade_Open;
    bool public no_Fee_Transfers = true;   // True at launch (Wallet to wallet transfers do not incur a fee)
    bool public noFeeWhenProcessing;        // False at launch (The sell that triggers fee processing still needs to pay the transaction fee)

    // Fee Tracker
    bool private takeFee;
    
    // Set Buy and Sell Fees
    function Set_Fees(

        uint8 Marketing,
        uint8 Liquidity

        ) external onlyOwner {

        // Buyer Protection: Max Fee 6% 
        require (Marketing + Liquidity <= 6, "FEE6");  // Max fee 6%

      
        // Update Fees
        _fee__Liquidity = Liquidity;
        _fee__Marketing = Marketing;

        // Fees For Processing
        _SwapFeeTotal = _fee__Liquidity + _fee__Marketing;

        emit updated_fees(_fee__Marketing, _fee__Liquidity);
    
    }

  

    // Open Trade
    function Open_Trade() external onlyOwner {

        require(!Trade_Open, "TradeOpen"); // Trade is already open - Trade can not be paused 
        feeProcessingEnabled = true;
        Trade_Open = true;

        // Check if router and pair have been set
        if (uniswapV2Router == IUniswapV2Router02(0x0000000000000000000000000000000000000000)){


        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D); // Eth Chain

                    uniswapV2Router = _uniswapV2Router;
        }

        if (uniswapV2Pair == address(0x0000000000000000000000000000000000000000)) {

            address pairCreated = IUniswapV2Factory(uniswapV2Router.factory()).getPair(address(this), uniswapV2Router.WETH());

                // Check if pair has been created
                if (pairCreated == address(0x0000000000000000000000000000000000000000)){

                    // Create and set the pair
                    uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());

                } else {

                    // Set the pair
                    uniswapV2Pair = pairCreated;
                }
            
        }

        // Set as pair and make limit exempt
        if (!_isPair[uniswapV2Pair]){_isPair[uniswapV2Pair] = true;} 

    }


    /*

    --------------
    FEE PROCESSING 
    --------------

    */


    // Add Liquidity Pair - required for correct fee calculations 
    function addNewLiquidityPair(

        address Wallet_Address,
        bool true_or_false)

        external onlyOwner {

        _isPair[Wallet_Address] = true_or_false;

    } 

    /*
    
    ---------------------------------
    NO FEE WALLET TO WALLET TRANSFERS
    ---------------------------------

    Default = true

    Having no fee on wallet-to-wallet transfers means that people can move tokens between wallets, 
    or send them to friends etc without incurring a fee. 

    If false, the 'Buy' fee will apply to all wallet to wallet transfers.

    */


    function no_Fee_Wallet_Transfers(bool true_or_false) external onlyOwner {

        no_Fee_Transfers = true_or_false;

    }


    // Auto Fee Processing Switch (SwapAndLiquify)
    function swapAndLiquifySwtich(bool true_or_false) external onlyOwner {
        feeProcessingEnabled = true_or_false;
        emit updated_SwapAndLiquify_Enabled(true_or_false);
    }
    
    function swapTriggerCount(uint256 Transaction_Count) external onlyOwner {

        require(Transaction_Count <= 20, "Max is 20 Transacitons to trigger fees");
        swapTrigger = Transaction_Count + 1; // Reset to 1 (not 0) to save gas
    }