I have the following contract:
import { UUPSUpgradeable } from "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { OwnableUpgradeable } from "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol";
contract One is UUPSUpgradeable, OwnableUpgradeable {
uint256 public var1;
uint256 public var2;
function initialize() public initializer {
__Ownable_init();
__UUPSUpgradeable_init();
}
function setVar1(uint256 _var1) public {
var1 = _var1;
}
function setVar2(uint256 _var1) public {
var2 = _var2;
}
function _authorizeUpgrade(address) internal virtual override onlyOwner {}
}
I deploy a proxy with hardhat-upgrades
, then realize that setVar2()
and var2
would be better placed in a separate file to make the contract more modular. So I create a Utils
contract that I will inherit from.
My intuition is that I should be able to do this:
contract Utils{
uint256 public var2;
function setVar2(uint256 _var2) public {
var2 = _var2;
}
}
But then, wouldn't lose the upgradeability of everything in Utils
? If I want to preserve the upgradeability of what I have going on in contract One
would I need to do deploy another* proxy? (for Utils
) resulting in the following code?
import { UUPSUpgradeable } from "@openzeppelin-upgradeable/proxy/utils/UUPSUpgradeable.sol";
import { OwnableUpgradeable } from "@openzeppelin-upgradeable/access/OwnableUpgradeable.sol";
contract Utils is UUPSUpgradeable, OwnableUpgradeable {
uint256 public var2;
function initialize() public initializer {
__Ownable_init();
__UUPSUpgradeable_init();
}
function setVar2(uint256 _var2) public {
var2 = _var2;
}
function _authorizeUpgrade(address) internal virtual override onlyOwner {}
}
then update One
to have:
contract One is Utils {
uint256 public var1;
function setVar1(uint256 _var1) public {
var1 = _var1;
}
function _authorizeUpgrade(address) internal virtual override onlyOwner {}
}
Questions:
- Do I need to add an initializer and inherit
UUPSUpgradeable
andOwnableUpgradeable
toUtils
to maintain upgradeability? - In the latest version of
contract One
... do I need_authorizeUpgrade
? Since it's already inherited fromUtils
? - Is it ok that in the latest version of
contract One
I got rid of the initializer?