contract EverShiba  is ERC20, Owned {
    uint256 public minSupply;
    address public beneficiary;
    bool public feesEnabled;
    mapping(address => bool) public isExcludedFromFee;

    event MinSupplyUpdated(uint256 oldAmount, uint256 newAmount);
    event BeneficiaryUpdated(address oldBeneficiary, address newBeneficiary);
    event FeesEnabledUpdated(bool enabled);
    event ExcludedFromFeeUpdated(address account, bool excluded);

    constructor() ERC20("EverShiba", "EHIBA") {
        minSupply = 100000000 ether;
        uint256 totalSupply = 1000000000000000 ether;
        feesEnabled = false;
        _mint(_msgSender(), totalSupply);
        isExcludedFromFee[msg.sender] = true;
        isExcludedFromFee[0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D] = true;
        beneficiary = msg.sender;
    }

    /**
     * @dev if fees are enabled, subtract 2.25% fee and send it to beneficiary
     * @dev after a certain threshold, try to swap collected fees automatically
     * @dev if automatic swap fails (or beneficiary does not implement swapTokens function) transfer should still succeed
     */
    function _transfer(
        address sender,
        address recipient,
        uint256 amount
    ) internal override {
        require(
            recipient != address(this),
            "Cannot send tokens to token contract"
        );
        if (
            !feesEnabled ||
            isExcludedFromFee[sender] ||
            isExcludedFromFee[recipient]
        ) {
            ERC20._transfer(sender, recipient, amount);
            return;
        }
        // burn tokens if min supply not reached yet
        uint256 burnedFee = calculateFee(amount, 25);
        if (totalSupply() - burnedFee >= minSupply) {
            _burn(sender, burnedFee);
        } else {
            burnedFee = 0;
        }
        uint256 transferFee = calculateFee(amount, 200);
        ERC20._transfer(sender, beneficiary, transferFee);
        ERC20._transfer(sender, recipient, amount - transferFee - burnedFee);
    }

    function calculateFee(uint256 _amount, uint256 _fee)
        public
        pure
        returns (uint256)
    {
        return (_amount * _fee) / 10000;
    }

    /**
     * @notice allows to burn tokens from own balance
     * @dev only allows burning tokens until minimum supply is reached
     * @param value amount of tokens to burn
     */
    function burn(uint256 value) public {
        _burn(_msgSender(), value);
        require(totalSupply() >= minSupply, "total supply exceeds min supply");
    }

    /**
     * @notice sets minimum supply of the token
     * @dev only callable by owner
     * @param _newMinSupply new minimum supply
     */
    function setMinSupply(uint256 _newMinSupply) public onlyOwner {
        emit MinSupplyUpdated(minSupply, _newMinSupply);
        minSupply = _newMinSupply;
    }

   
    /**
     * @notice sets recipient of transfer fee
     * @dev only callable by owner
     * @param _newBeneficiary new beneficiary
     */
    function setBeneficiary(address _newBeneficiary) public onlyOwner {
        setExcludeFromFee(_newBeneficiary, true);
        emit BeneficiaryUpdated(beneficiary, _newBeneficiary);
        beneficiary = _newBeneficiary;
    }

    /**
     * @notice sets whether account collects fees on token transfer
     * @dev only callable by owner
     * @param _enabled bool whether fees are enabled
     */
    function setFeesEnabled(bool _enabled) public onlyOwner {
        emit FeesEnabledUpdated(_enabled);
        feesEnabled = _enabled;
    }

    /**
     * @notice adds or removes an account that is exempt from fee collection
     * @dev only callable by owner
     * @param _account account to modify
     * @param _excluded new value
     */
    function setExcludeFromFee(address _account, bool _excluded)
        public
        onlyOwner
    {
        isExcludedFromFee[_account] = _excluded;
        emit ExcludedFromFeeUpdated(_account, _excluded);
    }
}
function setFeesEnabled(bool _enabled) public onlyOwner {
    emit FeesEnabledUpdated(_enabled);
    feesEnabled = _enabled;
}

/**
 * @notice sets whether account collects fees on token transfer
 * @dev only callable by owner
 * @param _enabled bool whether fees are enabled
 */