wighawag / hardhat-deploy

hardhat deployment plugin
MIT License
1.19k stars 292 forks source link

add an `importPath` option for the `deploy` function #343

Open nataouze opened 2 years ago

nataouze commented 2 years ago

Is your feature request related to a problem? Please describe. When a project depends on artifacts from external libraries and several artifacts have the same name, calling deploy with a contract name does not allow selecting which artifact to load.

Describe the solution you'd like An optional importPath field in DeployOptionsBase which allows to retrieve the artifact by its name from a specific folder.

Describe alternatives you've considered As a workaround, one can do:

const {getArtifactFromFolders} = require('hardhat-deploy/dist/src/utils');
// ...
const options = {
  contract: await getArtifactFromFolders(artifactName, [artifactPath]),
  // ...
};
await deploy(name, options);
wighawag commented 2 years ago

did you try specifying contract: "<path>:<contractName>" ?

nataouze commented 2 years ago

It doesn't look like it will help much for my use-case, because the internal structure of the external libraries artifacts is the same:

I have these dependencies: node_modules/projectA/artifacts/contracts/Contract.sol/ node_modules/projectB/artifacts/contracts/Contract.sol/

To use fully-qualified names, I need to have an external config similar to this:

external: {
  contracts: [
    {artifacts: 'node_modules/projectA/artifacts'},
    {artifacts: 'node_modules/projectB/artifacts'},
  ],
}

In the end, I have the same issue when deploying, still not specifying which folder to read the artifact from:

await deploy("Contract", {contract: "contracts/Contract.sol:Contract"});
nataouze commented 2 years ago

What I am proposing works as follows:

await deploy("Contract", {contract: "Contract", importPath: "node_modules/projectA/artifacts"});
n00b21337 commented 1 year ago

The solution should be to use Full Qualified Name.

await deploy('src/projectA/Contract.sol:ContractName'); or better yet with identifier

await deploy('ContractA, { contract: 'src/projectA/Contract.sol:ContractName'});