UNPKG

deployment-tool

Version:

Tool to deploy and upgrade contracts on Ethereum Mainnet

102 lines 5.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); const deployProxy = async (env, contractName, initializeArguments = [], initializeSignature = 'initialize', tag, extra, skipGit = false, verifyContract = true, forceSave = false) => { try { // Set a timeout for the deployment let keepWaiting = true; setTimeout(() => { keepWaiting = false; }, 60000); const logOutput = []; let deployedContract = 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); // Deploy Proxy & initialize it deployedContract = await env.upgrades.deployProxy(contractInterface, initializeArguments, { initializer: initializeSignature }); // Get Transaction Receipt const deployedContractTnx = await deployedContract.deployTransaction.wait(); // Save deployment arguments const extraData = Object.assign(Object.assign({}, extra), { initializeArguments, initializeSignature }); // Save the deployment details await env.addressBook.saveContract(contractName, deployedContract.address, env.network.name, deployer.address, env.network.config.chainId, deployedContractTnx.blockHash, deployedContractTnx.blockNumber, tag, extraData, forceSave); logOutput.push({ contractName, address: deployedContract.address, network: env.network.name }); // Console log the address console.log('\x1b[32m%s\x1b[0m', `${contractName} deployed at address: `, deployedContract.address); try { // Retrieve Proxy Admin Address ProxyAdminAddress = await env.addressBook.retrieveOZAdminProxyContract(env.network.config.chainId); // Save Proxy Admin Address env.addressBook.saveContract('ProxyAdmin', ProxyAdminAddress, env.network.name, deployer.address); logOutput.push({ contractName: 'ProxyAdmin', address: ProxyAdminAddress, network: env.network.name }); // Console log the address console.log('Deployed using Proxy Admin contract address: ', ProxyAdminAddress); } catch (error) { console.log('Error retrieving Proxy Admin Address: ', error); } // Verify the contract if (verifyContract) await (0, utils_1.etherscanVerifyContract)(env, deployedContract.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} deployed from commitId: ${lastCommit.commitId}`, `Network: ${env.network.name}, Deployer: ${deployer.address}, Contract Address: ${deployedContract.address}, Initialize Arguments: ${JSON.stringify(initializeArguments)}, Initialize Signature: ${initializeSignature}, 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 deployed contract{ return { success: true, message: 'Deployment successful', contractName, contract: deployedContract, proxyAdminAddress: ProxyAdminAddress, proxyAddress: deployedContract.address }; } catch (err) { return { success: false, message: 'Deployment failed' }; } }; exports.default = deployProxy; //# sourceMappingURL=deployProxy.js.map