contract BearnTokenERC20 is
    ERC20WithPermit,
    CanReclaimTokens {

    uint public cap = 12500 ether;

    function initialize(
        uint _chainId,
        address _nextOwner,
        string memory _version,
        string memory _name,
        string memory _symbol,
        uint8 _decimals
    ) public initializer {
        __ERC20_init(_name, _symbol);
        _setupDecimals(_decimals);
        ERC20WithPermit.initialize(
            _chainId,
            _version,
            _name,
            _symbol,
            _decimals
        );
        CanReclaimTokens.initialize(_nextOwner);
        _mint(msg.sender, cap.sub(2000 ether)); // first mint to setup liquidity
    }

    // Can be called by only Gateway
    function mint(address _to, uint _amount) external onlyOwner {
        _mint(_to, _amount);
    }

    // Can be called by only Gateway
    function burn(uint _amount) external onlyOwner {
        _burn(msg.sender, _amount);
    }

    function transfer(address recipient, uint amount) public override returns (bool) {
        require(
            recipient != address(this),
            "BEARN ERC20UpgradeSafe: can't transfer to token address"
        );
        return super.transfer(recipient, amount);
    }

    function transferFrom(address sender, address recipient, uint amount) public override returns (bool) {
        require(
            recipient != address(this),
            "BEARN ERC20UpgradeSafe: can't transfer to stoken address"
        );
        return super.transferFrom(sender, recipient, amount);
    }

    /**
     * @dev See {ERC20-_beforeTokenTransfer}.
     *
     * Requirements:
     *
     * - minted tokens must not cause the total supply to go over the cap.
     */
    function _beforeTokenTransfer(address from, address to, uint amount) internal virtual override {
        super._beforeTokenTransfer(from, to, amount);

        if (from == address(0)) { // When minting tokens
            require(totalSupply().add(amount) <= cap, "ERC20Capped: cap exceeded");
        }
    }
}
/**
 * @dev Wrapped BFI on Ethereum
 *
 * Read more about its tokenomic here: https://bearn-defi.medium.com/bearn-fi-introduction-9e65f6395dfc
 *
 * Total 12,500 BFI issued (minted) on Ethereum:
 * - 500 BFIE for initial supply (Uniswap and Value Liquid)
 * - 3000 BFIE for UNIv2 BFIE-ETH (50/50) mining incentive (4 months)
 * - 7000 BFIE for ValueLiquid VLP BFIE-VALUE (70/30) mining incentive (18 months)
 * - 2000 BFIE reserve for public mint (from BFI Bsc)
 */
function mint(address _to, uint _amount) external onlyOwner {
    _mint(_to, _amount);
}

// Can be called by only Gateway