UNPKG

deployment-tool

Version:

Tool to deploy and upgrade contracts on Ethereum Mainnet

88 lines 4.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); const upgradeProxy = async (env, contractName, tag, extra, skipGit, verifyContract) => { try { // Set a timeout for the deployment let keepWaiting = true; setTimeout(() => { keepWaiting = false; }, 60000); const logOutput = []; let upgradedContract = null; let ProxyAdminAddress = ''; while (keepWaiting) { // Get deployer account const [deployer] = await env.ethers.getSigners(); // Make sure contract is compiled await (0, utils_1.compileContract)(env); // Get Interface const contractInterface = await env.ethers.getContractFactory(contractName); // Get contract details const contractAddress = await env.addressBook.retrieveContract(contractName, env.network.name); // Sanity check on contract address if (!contractAddress) throw new Error(`Contract ${contractName} not found in address book`); // Deploy Proxy & initialize it upgradedContract = await env.upgrades.upgradeProxy(contractAddress, contractInterface); // Get Transaction Receipt const upgradedContractTnx = await upgradedContract.deployTransaction.wait(); // Save the deployment details await env.addressBook.saveContract(contractName, upgradedContract.address, env.network.name, deployer.address, upgradedContractTnx.blockHash, upgradedContractTnx.blockNumber, tag, extra); logOutput.push({ contractName, address: upgradedContract.address, network: env.network.name }); // Console log the address console.log('\x1b[32m%s\x1b[0m', `${contractName} upgraded at address: `, upgradedContract.address); // Retrieve Proxy Admin Address ProxyAdminAddress = await env.addressBook.retrieveOZAdminProxyContract(env.network.config.chainId); // Verify the contract if (verifyContract) await (0, utils_1.etherscanVerifyContract)(env, upgradedContract.address); if (!skipGit) { // Add the contract address files and contract storage layout to the next commit const filesToCommit = `.openzeppelin/ contractsAddressDeployed.json contractsAddressDeployedHistory.json`; const isAddedToCommit = await (0, utils_1.addToCommit)(filesToCommit); let isCommitted = false; // Get last CommitId const lastCommit = await (0, utils_1.getLastCommit)(); // Commit if (isAddedToCommit && lastCommit.success) isCommitted = await (0, utils_1.commitChanges)(`💪 ${contractName} upgraded from commitId: ${lastCommit.commitId}`, `Network: ${env.network.name}, Deployer: ${deployer.address}, Contract Address: ${upgradedContract.address}${ProxyAdminAddress ? ', Proxy Admin Address: ' + ProxyAdminAddress : ''}`, filesToCommit); let isPull = false; // Pull if (isCommitted) isPull = await (0, utils_1.pullFromGit)(); // Push if (isPull) await (0, utils_1.pushToGit)(filesToCommit); } else console.log('Skipping git commit, pull & push'); // Exit keepWaiting = false; // Return the deployed contract and Proxy Admin if (logOutput.length > 0) console.table(logOutput); } // Return the upgraded contract return { success: true, message: 'Upgrade successful', contractName, contract: upgradedContract, proxyAdminAddress: ProxyAdminAddress, proxyAddress: upgradedContract.addressBook }; } catch (err) { return { success: false, message: 'Upgrade failed' }; } }; exports.default = upgradeProxy; //# sourceMappingURL=upgradeProxy.js.map