Hey folks! We have been discussing about adding support for CREATE2
for proxies in zos
, so you could "park" an address before you actually create the proxy. This is the basis for counterfactual deployment: by knowing where your contract will be deployed, you can start interacting with it (by sending funds, for instance) even before it is actually deployed.
Note that this is a very different thing to supporting proxy-less upgradeability via CREATE2. Here, we are only talking about being able to reserve an address for deploying an upgradeable instance (ie a proxy).
How would this work? We are considering on adding two new options to the zos create
command: one for providing a salt, that will be used in computing the deployment address, and the other for querying the address instead of actually creating the contract.
For instance, let's say you want to use this pattern to deploy a contract Foo
. Instead of the regular zos create Foo
, you could run:
$ zos create Foo --salt mysupersalt --query
> Contract would be deployed at 0x13ea86b358aa83543783742567c2964283cde77f
Then, when you want to actually deploy the contract, you can remove the query
flag to actually run the creation.
$ zos create Foo --salt mysupersalt
> Contract has been deployed at 0x13ea86b358aa83543783742567c2964283cde77f
Of course, different salts yield different deployment addresses:
$ zos create Foo --salt anothersalt
> Contract has been deployed at 0x1c3d2d14cb40ee63ba3c56128946a1bac98344c3
Initialization arguments should not be used when calculating the deployment address - this allows you to decide the arguments only when you want to actually deploy.
$ zos create Foo --salt mysupersalt --args "foo"
> Contract has been deployed at 0x13ea86b358aa83543783742567c2964283cde77f
$ zos create Foo --salt mysupersalt --args "bar"
> Error: contract already deployed at 0x13ea86b358aa83543783742567c2964283cde77f
However, what is used for calculating the deployment address is the sender. This allows you to reserve an address, knowing that no one else (even if they know the salt you will be using) can deploy there.
$ zos create Foo --salt mysupersalt --from 0x94e6b68e770c9de517be57aef6f7653279eb24fa
> Contract has been deployed at 0x13ea86b358aa83543783742567c2964283cde77f
$ zos create Foo --salt mysupersalt --from 0xecf8e68f0d487c866bee8266f580211e176642ea
> Contract has been deployed at 0x64f70539776f08c5ef505254c2426f3e47a5204d
This could be implemented by adding a new method on the ProxyAdmin
contract, or by spawning a new Factory
contract altogether, that act as a CREATE2 factory for Proxies, where the actual deployment salt is calculated from the salt provided as a parameter and the msg.sender
.
We will start working on this soon. Please share your thoughts about this!