How do upgradeable Clones work?

From the documentation:

The Clones library provides a way to deploy minimal non-upgradeable proxies for cheap. This can be useful for applications that require deploying many instances of the same contract (for example one per user, or one per task). These instances are designed to be both cheap to deploy, and cheap to call. The drawback being that they are not upgradeable.

However, I see a contract called ClonesUpgradeable.sol in the openzeppelin-contracts-upgradeable package, but its implementation at first glance seems no different than the regular Clones.sol?

I have an application in which a user can deploy an instance of a Game contract. Each Game contract should store the deployer as the admin, and maintains its own state, funds, and storage. At first I implemented a Clone factory where users can call createGame, which deploys a new Game using an implementation contract address that was set earlier. However, I later found that Clones might not have been the way to go if I wanted the Game implementation to be upgradeable, and switched to UpgradeableProxy pattern instead

Would Clones be the appropriate choice if I want to:

  • (high priority) deploy multiple contracts that use the same implementation but separate storage and state
  • (high priority) have a way to upgrade these instances at once
  • minimise gas costs for Game instantiation - this was my reasoning for opting for Clones in the first place before finding out they weren’t upgradeable

Thanks for any help/suggestions!

Read Using with Upgrades to understand why you’re seeing the contract ClonesUpgradeable.

For your requirementes you can consider using beacon proxies. Read about them here.

1 Like