How to deploy Clones

I went trough the OpenZeppelin docs for the hardhat-upgrade plugin, for the upgradeable contracts, for the Minimum proxy pattern and for the Clones library.
I have a contract using the Clones library, as I don't need any upgrades. But I don't understand how the deployment script has to look like.

  • Do I have to deploy it using upgrades.deployProxy or deploy ?

  • Should I have this call inside the ERC20 token from this example:
    address clone = Clones.clone(tokenImplementation);

  • Assuming I will have just one contract, how can I verify it ? The issue is the call to the Clones.clone function.

Is there a tutorial for using the new Clones library ?

Many thanks !!

=====================================

EDIT: I made it work. I deployed two different contracts:

  • The main contract, which is equivalent to the ERC20 token in this example.
  • The factory contract, which has only one function called createToken that calls the Clones library and hence deploys the minimal proxy contract.

My question now is if I can have state variables for each proxy, not declared in the main contract. I need to be able to pause each proxy. I was using OpenZeppelin's Pausable contract, but I didn't have a proxy.

If you are using Clones, all of the logic must be in the implementation contract because the clone itself simply delegates calls to it. So to add variables or Pausable, do this in the implementation contract.

You can also use the upgrades plugins to validate the implementation prior to deploying it.

Thank you, @ericglau. I figured it out by myself.