UNPKG

deployment-tool

Version:

Tool to deploy and upgrade contracts on Ethereum Mainnet

83 lines 3.98 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const utils_1 = require("./utils"); const deploy = async (env, contractName, constructorArguments = [], 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; 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 contractInterface.deploy(constructorArguments); // Get Transaction Receipt const deployedContractTnx = await deployedContract.deployTransaction.wait(); await deployedContract.deployed(); // Save deployment arguments const extraData = Object.assign(Object.assign({}, extra), { constructorArguments }); // 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); // 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}, Constructor Arguments: ${JSON.stringify(constructorArguments)}`, 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, address: deployedContract.address }; } catch (err) { return { success: false, message: 'Deployment failed', error: err }; } }; exports.default = deploy; //# sourceMappingURL=deploy.js.map