(Un)safe usage of immutable in UUPS

I am a bit confused regarding the safe use of immutable in UUPSUpgradable contracts. I assumed through https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable#avoid-initial-values-in-field-declarations that immutable can be used without any problems (as long as they are not defined within a constructor). Through
https://docs.openzeppelin.com/upgrades-plugins/1.x/faq#why-cant-i-use-immutable-variables, however, there seem to be unsafe cases of usage of immutable.

I would like to use immutable safely in a UUPSUpgradeable contract. Is there anything I need to pay attention to besides using the same slot in all proxy implementations?

For example, can I safely use this implementation if this remains constant in all my implementations?

contract TestUpgradable is UUPSUpgradeable, OwnableUpgradeable {
    address immutable WETH = 0xc778417E063141139Fce010982780140Aa0cD5Ab;

1 Like

The documentation may be slightly confusing. Immutable is safe to use as long as you're ok with sharing the same value throughout all proxies that share that impementation contract.

Immutable variables don't use storage slots so you don't need to worry about that either.

1 Like