Contract updating via governor and hardhat

Hi folks.

I'm implementing contract updating via OpenZepplin governance (and TransparentUpgradeableProxy). But I couldn't find how to do it properly via Hardhat. It works fine for a simple update but in the case of governance it requires to propose instead of "set implementation".
Is there Hardhat extension for this purpose? Or could someone give some tips regarding this?

Thanks.

Assuming you have the following 4 contracts:
A Governor contract that is the owner of a ProxyAdmin that is the admin of a TransparentUpgradeableProxy that points to the old version if your implementation.

You can do the following to propose an upgrade:

  1. Call upgrades.prepareUpgrade to deploy the new version of the implementation. That function returns the new implementation address.
  2. Create a proposal like in https://docs.openzeppelin.com/contracts/4.x/governance#create_a_proposal, but instead of following the transfer example there, encode the calldata for the ProxyAdmin's upgrade(contract TransparentUpgradeableProxy proxy, address implementation) or upgradeAndCall(contract TransparentUpgradeableProxy proxy, address implementation, bytes data) function, where
    • proxy is the address of the TransparentUpgradeableProxy
    • address is the new implementation address returned by upgrades.prepareUpgrade in Step 1
    • data (if using upgradeAndCall) is another encoded function call such as a reinitializer or migration function in your new implementation contract
1 Like