How to setup dev workflow to auto run `deployProxy` followed by `upgradeProxy` when code is changed

Hi, could you give some ideas on how to setup dev workflow so that the proxies are redeployed & upgraded as dev code is changed.

currently i have a bunch of scripts which deploy & upgrade the proxy.

e.g.

scripts/deploy/01_deploy_box_proxy.js
scripts/deploy/02_upgrade_box_proxy_to_v2.js
scripts/deploy/03_upgrade_box_proxy_to_v3js

When i change code in any of *.sol files i would want to run hh compile followed by running these 3 scripts in the right order. How should i do this?

Or am i thinking of this wrong, and there is a better/different way to setup dev workflow?

PS: in the past i was using hardhat-deploy but since it doesnt leverage the safety features built in to hardhat-upgrades, I decided to write scripts to do deployment which use deployProxy and upgradeProxy to do the deployment.

You could take a look at https://www.npmjs.com/package/hardhat-watcher although I haven't tried it / can't vouch for it.

I have a similar working flow, and I'm wondering how we can get references to the proxies deployed in 01_deploy_box_proxy.js in 02_upgrade_box_proxy_to_v2.js. If the contracts were not upgradeable, the deployed contracts can be referenced even by the contract names const contract = await ethers.getContract<Contract>("Contract");, but it does not seem as straightforward as in the scenario with proxies. @ericglau Thanks.

thanks. I am able to get a decent workflow with hardhat-watcher.

@maxareo i am saving the proxy address after deployment to a json file and then reading that address in the upgrade files.

1 Like

Thanks, @Mister_Singh. Was expecting something like getProxy("ProxyName") where ProxyName should be the name of logic contract. Do you mind sharing the scripts for referencing proxies? Thanks.

Also asked a more detailed question here @ericglau @Mister_Singh :

@maxareo this is how i am getting the proxy address:

const frontendProjectPath = path.join(
    __dirname,
    "../../../react-app/src/contracts"
  );
  const proxyContractFilePath = path.join(
    frontendProjectPath,
    "proxy_contracts.json"
  );
  let proxyObj = {};
  try {
    const proxyFile = fs.readFileSync(proxyContractFilePath);
    proxyObj = JSON.parse(proxyFile);
  } catch (e) {
    console.log("Proxy Contract File not found. can NOT proceed with update!");
    return;
  }
  const proxyAddress = proxyObj[chainId][proxyContractName].address;
2 Likes

Thanks. I appreciate the sharing.