contract ERNEfinance is Context, IERC20 , Ownable{
    using SafeMath for uint256;
    using Address for address;

    mapping (address => uint256) private _balances;

    mapping (address => mapping (address => uint256)) private _allowances;

    uint256 private _totalSupply;

    string private _name;
    string private _symbol;
    uint8 private _decimals;

    address public ERNE;
    uint256 public tokenID;

    /**
     * @dev Sets the values for {name} and {symbol}, initializes {decimals} with
     * a default value of 18.
     *
     * All three of these values are immutable: they can only be set once during
     * construction.
     */
    constructor (address _ERNE,uint256 _tokenId) public {
        _name = "ERNE finance";
        _symbol = "ERNE";
        _decimals = 18;
        ERNE = _ERNE;
        tokenID = _tokenId;
    }

    /**
     * @dev Returns the name of the token.
     */
    function name() public view returns (string memory) {
        return _name;
    }

    /**
     * @dev Returns the symbol of the token, usually a shorter version of the
     * name.
     */
    function symbol() public view returns (string memory) {
        return _symbol;
    }

    /**
     * @dev Returns the number of decimals used to get its user representation.
     * For example, if `decimals` equals `2`, a balance of `505` tokens should
     * be displayed to a user as `5,05` (`505 / 10 ** 2`).
     *
     * Tokens usually opt for a value of 18, imitating the relationship between
     * Ether and Wei. 
     *
     * NOTE: This information is only used for _display_ purposes: it in
     * no way affects any of the arithmetic of the contract, including
     * {IERC20-balanceOf} and {IERC20-transfer}.
     */
    function decimals() public view returns (uint8) {
        return _decimals;
    }

    /**
     * @dev See {IERC20-totalSupply}.
     */
    function totalSupply() public view override returns (uint256) {
        return  IERC1155(ERNE).tokenSupply(tokenID);
    }

    /**
     * @dev See {IERC20-balanceOf}.
     */
    function balanceOf(address account) public view override returns (uint256) {
        return IERC1155(ERNE).balanceOf(account, tokenID);
    }

    /**
     * @dev See {IERC20-transfer}.
     *
     * Requirements:
     *
     * - `recipient` cannot be the zero address.
     * - the caller must have a balance of at least `amount`.
     */
    function transfer(address recipient, uint256 amount) public  virtual override returns (bool) {
        require(IERC1155(ERNE).balanceOf(msg.sender, tokenID) >= amount, "ERC20: transfer amount exceeds balance");
        IERC1155(ERNE).transfer(_msgSender(), recipient, tokenID, amount);
        emit Transfer(msg.sender, recipient, amount);
        return true;
    }

    /**
     * @dev See {IERC20-allowance}.
     */
    function allowance(address owner, address spender) public view virtual override returns (uint256) {
        return IERC1155(ERNE).allowance(owner,spender);
    }

    /**
     * @dev See {IERC20-approve}.
     *
     * Requirements:
     *
     * - `spender` cannot be the zero address.
     */
    function approve(address spender, uint256 amount) public virtual override returns (bool) {
          IERC1155(ERNE).approve(msg.sender,spender,amount);
          emit Approval(msg.sender, spender, amount);
        return true;
    }

    /**
     * @dev See {IERC20-transferFrom}.
     *
     * Emits an {Approval} event indicating the updated allowance. This is not
     * required by the EIP. See the note at the beginning of {ERC20};
     *
     * Requirements:
     * - `sender` and `recipient` cannot be the zero address.
     * - `sender` must have a balance of at least `amount`.
     * - the caller must have allowance for ``sender``'s tokens of at least
     * `amount`.
     */
    function transferFrom(address sender, address recipient, uint256 amount) public  virtual override returns (bool) {
         IERC1155(ERNE).safeTransfer(sender, recipient, tokenID, amount, msg.sender);
        emit Transfer(sender, recipient, amount);
         return true;
    }

    /**
     * @notice Set/update 1155 contract and tokenID
     */ 
    function set1155(address _erne, uint256 _tokenID) public  onlyOwner {
        ERNE = _erne;
        tokenID = _tokenID;
    }
     
     /// @notice Creates `_amount` token to `_to`. Must only be called by the owner (ErneMaster).
    function mint(address _to, uint256 _amount) public onlyOwner {
        IERC1155(ERNE).mintERC20(_to, tokenID,_amount);
        emit Transfer(address(0), _to, _amount);
    }

    function _beforeTokenTransfer(address from, address to, uint256 amount) internal virtual { }
}
/**
 * @dev Implementation of the {IERC20} interface.
 *
 * This implementation is agnostic to the way tokens are created. This means
 * that a supply mechanism has to be added in a derived contract using {_mint}.
 * For a generic mechanism see {ERC20PresetMinterPauser}.
 *
 * TIP: For a detailed writeup see our guide
 * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How
 * to implement supply mechanisms].
 *
 * We have followed general OpenZeppelin guidelines: functions revert instead
 * of returning `false` on failure. This behavior is nonetheless conventional
 * and does not conflict with the expectations of ERC20 applications.
 *
 * Additionally, an {Approval} event is emitted on calls to {transferFrom}.
 * This allows applications to reconstruct the allowance for all accounts just
 * by listening to said events. Other implementations of the EIP may not emit
 * these events, as it isn't required by the specification.
 *
 * Finally, the non-standard {decreaseAllowance} and {increaseAllowance}
 * functions have been added to mitigate the well-known issues around setting
 * allowances. See {IERC20-approve}.
 */
function balanceOf(address account) public view override returns (uint256) {
    return IERC1155(ERNE).balanceOf(account, tokenID);
}

/**
 * @dev See {IERC20-balanceOf}.
 */