UNPKG

@nbouvier/hardhat-configs-proxy

Version:
59 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeDeployProxy = exports.ProxyDeploymentException = void 0; const hardhat_configs_1 = require("@nbouvier/hardhat-configs"); class ProxyDeploymentException extends Error { constructor(name, error) { super(`Failed to deploy proxy ${name}: ${error.reason}.`); this.name = 'ProxyDeploymentException'; } } exports.ProxyDeploymentException = ProxyDeploymentException; function makeDeployProxy(hre) { /** * Deploys an upgradeable contract instance of <name> coontract or * an upgradeable contract instance of <artifactName> under <name> in the config file or * returns the already deployed contract <name> * @param {string} name - the name of the contract in the config file * @param {any[]|string} [args=[]] - the constructor parameters * @param {string} [artifactName] - the name of the contract artifact * @returns {Promis<Contract>} a promise resolving to the deployed or already deployed contract * * deployProxy(name: string) * deployProxy(name: string, args: any[]) * deployProxy(name: string, artifactName: string) */ return async function deployProxy(name, args = [], artifactName) { // Get the used network const network = await hre.configs.getNetwork(); // Take the contract from the config file if it has already been deployed const configLine = await (0, hardhat_configs_1.getContractConfigLine)(name, network); if (configLine) { const contractArtifact = artifactName || configLine.artifact; // Returns the contract return await hre.ethers.getContractAt(contractArtifact, configLine.address); } // Process parameters in order to support overloading if (typeof (args) === 'string') { artifactName = args; args = []; } // Deploy the contract const contractArtifact = artifactName || name; var contract; try { const factory = await hre.ethers.getContractFactory(contractArtifact); contract = await hre.upgrades.deployProxy(factory, args); } catch (e) { throw new ProxyDeploymentException(name, e); } // Update the config (0, hardhat_configs_1.addToConfig)(name, contract.address, contractArtifact, network); // Returns the new contract console.log(`Deployed ${name} to ${contract.address} (proxy)`); return contract; }; } exports.makeDeployProxy = makeDeployProxy; //# sourceMappingURL=deploy-proxy.js.map