Hey guys,
As described in a previous question I’m looking for a solution to manage a large number of smart contracts and especially upgrading them to include new functionality for all of them. This will also include not only adding new variables calculated by already existing ones but also initializing new variables after upgrading. So far the beacon proxy pattern seems to be the best, since I don’t have to iterate over each single proxy and change its implementation address. But what if I want to introduce a new variable and initalize it?
Here is an example:
pragma solidity >=0.4.22 <0.9.0;
contract BoxV1 {
uint256 private a;
uint256 private b;
function store(uint256 _a, uint256 _b) public {
a = _a;
b = _b;
}
function add() public view returns (uint256) {
return a + b;
}
}
contract BoxV2 {
uint256 private a;
uint256 private b;
uint256 private c;
function initialize(uint256 _c) public {
c = _c;
}
function store(uint256 _a, uint256 _b) public {
a = _a;
b = _b;
}
function add() public view returns (uint256) {
return a + b + c;
}
}
Both contracts act as implementation contracts and are deployed. So if I deploy a beacon proxy and store
some values all is good. If I upgrade the beacon to the new implementation V2 I have to invoke the new initialize
method(should only be called once) with a value in order to update the state of my proxy contract. Here are two things which come to my mind:
- After updating the beacon I will have again to iterate over all the deployed proxies in order to initialize them and set new values
- Since the initialize method should only be called once what will be the pattern for lets say a version 3? Do I add an
initilize3
method which can again only be called once?
In general I like the beacon proxy pattern a lot but I think there are some limitations or am I misunderstanding some fundamental concepts?