@openzeppelin/hardhat-upgrades
Version:
[](https://docs.openzeppelin.com/upgrades-plugins/hardhat-upgrades) [](https://www.npmjs.org/package/@openzeppelin/h
40 lines • 2.45 kB
JavaScript
import { deploy } from './utils/index.js';
import { getDeployData } from './utils/deploy-impl.js';
import { enableDefender } from './defender/utils.js';
import { getContractNameAndRunValidation, inferProxyKind, UpgradesError, inferInitializable, } from '@openzeppelin/upgrades-core';
import { getContractInstance } from './utils/contract-instance.js';
async function deployNonUpgradeableContract(hre, Contract, opts, connection) {
const deployData = await getDeployData(hre, Contract, opts, connection);
if (!opts.unsafeAllowDeployContract) {
assertNonUpgradeable(deployData);
}
const deployment = await deploy(hre, opts, Contract, ...deployData.fullOpts.constructorArgs);
return deployment;
}
function assertNonUpgradeable(deployData) {
const [fullContractName, runValidation] = getContractNameAndRunValidation(deployData.validations, deployData.version);
const c = runValidation[fullContractName];
if (inferInitializable(c) || inferProxyKind(deployData.validations, deployData.version) === 'uups') {
throw new UpgradesError(`The contract ${fullContractName} looks like an upgradeable contract.`, () => 'Upgradable contracts cannot be deployed using the deployContract function. Use deployProxy, deployBeacon, or deployImplementation.\n' +
'If this is not intended to be an upgradeable contract, set the unsafeAllowDeployContract option to true and run the deployContract function again.');
}
}
export function makeDeployContract(hre, defenderModule, connection) {
return async function deployContract(Contract, args = [], opts = {}) {
if (!Array.isArray(args)) {
opts = args;
args = [];
}
opts = enableDefender(hre, defenderModule, opts);
if (!opts.useDefenderDeploy) {
throw new Error(`The ${deployContract.name} function cannot have the \`useDefenderDeploy\` option disabled.`);
}
if (opts.constructorArgs !== undefined) {
throw new Error(`The ${deployContract.name} function does not support the constructorArgs option. Pass in constructor arguments using the format: deployContract(MyContract, [ 'my arg' ]);`);
}
opts.constructorArgs = args;
const deployment = await deployNonUpgradeableContract(hre, Contract, opts, connection);
return getContractInstance(hre, Contract, opts, deployment);
};
}
//# sourceMappingURL=deploy-contract.js.map