Can upgradeable contracts have immutable vars?

I have an upgradeable contract (that is a factory) that has the deployable contract as an immutable var, the factory's constructor is setting the immutable var

Code:

import "./IMPL.sol";

contract Factory is OwnableUpgradeable {
  address public immutable implementation;
  constructor() {
    implementation = address(new IMPL());
    _disableInitializers()
  }

  function initialize() initializer public {
    __Ownable_init();
  }

IMPL is the contract the factory should deploy, and it's in another solidity file that is being imported

Please see this section of the docs about immutable variables: https://docs.openzeppelin.com/upgrades-plugins/1.x/faq#why-cant-i-use-immutable-variables

Thanks for the answer! somehow that section has eluded me.

And it works great for my use case, as i want all proxies to share the same inmutable value.

1 Like