Best practice when deploying multiple upgradeable contracts with the same source code?

Hi!

So I have a upgradeable contract A and contract B that is basically the same as A since it just extends it. In my migrations I do something like this:

const { deployProxy } = require('@openzeppelin/truffle-upgrades');
const ContractA = artifacts.require('A');
const Contract B = artifacts.require('B');

module.exports = async (deployer) => {
    await deployProxy(ContractA, [... init params...], { deployer });
    await deployProxy(ContractB, [... init params...], { deployer });
};

Deployment goes through, but… When checking the ProxyAdmin for implementation addresses on ContractA’s proxy contract and ContractB’s proxy contract they both use the same implementation address. How’s that even possible? That’s why I created a new separate source code for ContractB that just extends ContractA, because I figured something like this might happen if I would just do:

    await deployProxy(Contract, [... init params...], { deployer });
    await deployProxy(Contract, [... init params...], { deployer });

What’s the best practice when deploying multiple upgradeable contracts with the same source code?
Best regards!

1 Like

Hi @kesopeso,

When deploying upgradeable contracts A and B with the same bytecode we get the following deployed:

  1. A (no need to deploy B as it had the same bytecode as A)
  2. ProxyAdmin (one per project per network, see: https://docs.openzeppelin.com/upgrades-plugins/1.x/faq#what-is-a-proxy-admin)
  3. Proxy for A
  4. Proxy for B

You can make contracts A and B different if you choose, so that you get contract A and contract B deployed, though this is of course more expensive, so you most likely want to avoid doing this.

The address for the proxy in Truffle is stored in the build artifact, so you will want to track the address of the proxy separately instead.

oh snap, nevermind… I get it. It doesn’t matter, since states are stored in the proxy contracts, only one instance of implementation contract needs to be deployed and of course two proxy contracts. my bad, yikes :relaxed:

1 Like