UNPKG

@nbouvier/hardhat-configs-proxy

Version:
36 lines 1.45 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.makeUpgradeProxy = exports.ProxyUpgradeException = void 0; class ProxyUpgradeException extends Error { constructor(name) { super(`Failed to upgrade proxy ${name}.`); this.name = 'ProxyUpgradeException'; } } exports.ProxyUpgradeException = ProxyUpgradeException; function makeUpgradeProxy(hre) { /** * Upgrades the <name> contract to the <artifactName> logic implementation * @param {string} name - the name of the contract in the config file * @param {string} artifactName - the name of the contract artifact * @returns {Promise<Contract>} a promise resolving to the upgraded contract */ return async function upgradeProxy(name, artifactName) { // Get the contract const contract = await hre.configs.getContract(name); // Upgrade the contract var newContract; try { const factory = await hre.ethers.getContractFactory(artifactName); newContract = await hre.upgrades.upgradeProxy(contract.address, factory); } catch (e) { throw new ProxyUpgradeException(name); } // Return the upgraded contract console.log(`Upgraded ${name}`); return newContract; }; } exports.makeUpgradeProxy = makeUpgradeProxy; //# sourceMappingURL=upgrade-proxy.js.map