Can you omit the ERC20, ERC20Permit inheritance in an ERC20Votes derived token?

When creating an Erc20Votes token, the Contracts Wizard suggests inheriting ERC20 and ERC20Permit and then adding the required overrides:

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";

contract MyToken is ERC20, ERC20Permit, ERC20Votes {
    constructor() ERC20("MyToken", "MTK") ERC20Permit("MyToken") {}

    // The following functions are overrides required by Solidity.

    function _afterTokenTransfer(address from, address to, uint256 amount)
        internal
        override(ERC20, ERC20Votes)
    {
        super._afterTokenTransfer(from, to, amount);
    }

    function _mint(address to, uint256 amount)
        internal
        override(ERC20, ERC20Votes)
    {
        super._mint(to, amount);
    }

    function _burn(address account, uint256 amount)
        internal
        override(ERC20, ERC20Votes)
    {
        super._burn(account, amount);
    }
}

But seems it fees much cleaner to omit ERC20 and ERC20Permit since ERC20Votes already inherits those.

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.2;

import "@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol";

contract MyToken is ERC20Votes {
    constructor() ERC20("MyToken", "MTK") ERC20Permit("MyToken") {}
}

Is there anything wrong with doing this?

My guess is that this is fine as long as you are not inheriting from any other contracts that inherit from those contracts and override the same methods?

3 Likes

@frangio Can you please take a look at this question?

Nothing wrong. It's just a convention that we follow to include the parents even if they're implied by other parent contracts.

3 Likes