Inherit from non-upgradable contracts

I've been wondering what are the implications of having an upgradable contract inherit from a non upgradable.

For example, which of the following version is correct

import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

contract ContractA is Initializable, OwnableUpgradeable, ReentrancyGuardUpgradeable {
 
}

or

import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";

contract ContractA is Initializable, Ownable, ReentrancyGuard {
 
}

and finally what if mix them i.e. have upgradable and non upgradable in the inheritance hierarchy

import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts-upgradeable/security/ReentrancyGuardUpgradeable.sol";

contract ContractA is Initializable, Ownable, ReentrancyGuardUpgradeable, ERC20 {
 
}
1 Like

If you try to deploy your second contract using our Upgrades Plugins you will receive errors: Ownable and ReentrancyGuard have construtors, this is not supported in upgradeable contracts. That's why the contracts-upgradeable package exists.

You can mix and match, in some cases, if the Upgrades Plugins allow it! The only downside there is that you run the risk of breaking storage layout in future upgrades, if we add new storage variables. This is also mitigated in the contracts-upgradeable package.

1 Like

Hi @frangio

Thanks for explaining this for me. Yes it makes sense now.

The only downside there is that you run the risk of breaking storage layout in future upgrades, This is also mitigated in the contracts-upgradeable package.

I assume you mean the ____gap field that those contracts have, correct?

Yes the gap is what I meant.

1 Like