UNPKG

dop-stick

Version:

Source control tooling for versionable-upgradeable smart contracts

64 lines 2.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.isContractDeployed = exports.deployContract = void 0; const ethers_1 = require("ethers"); const hardhatHelpers_1 = require("./hardhatHelpers"); /** * Deploys a contract module * @param moduleName - Name of the module to deploy * @param config - DopStick configuration * @returns Promise resolving to deployment result */ async function deployContract(moduleName, config) { var _a; // Get provider and signer const provider = await (0, hardhatHelpers_1.getProvider)(); if (!process.env.PRIVATE_KEY) { throw new Error('PRIVATE_KEY environment variable is not set'); } const signer = new ethers_1.ethers.Wallet(process.env.PRIVATE_KEY, provider); // Get contract factory const ModuleFactory = await (0, hardhatHelpers_1.getContractFactory)(moduleName, signer); // Prepare gas configuration const gasConfig = {}; // Handle EIP-1559 gas settings if ((_a = config.gas) === null || _a === void 0 ? void 0 : _a.maxFeePerGas) { gasConfig.maxFeePerGas = ethers_1.ethers.utils.parseUnits(config.gas.maxFeePerGas, 'gwei'); if (config.gas.maxPriorityFeePerGas) { gasConfig.maxPriorityFeePerGas = ethers_1.ethers.utils.parseUnits(config.gas.maxPriorityFeePerGas, 'gwei'); } } else { // Legacy gas price gasConfig.gasPrice = await provider.getGasPrice(); } // Deploy the contract const moduleInstance = await ModuleFactory.deploy(gasConfig); const receipt = await moduleInstance.deployTransaction.wait(); return { address: moduleInstance.address, contract: moduleInstance, gasUsed: receipt.gasUsed, gasPrice: receipt.effectiveGasPrice, transactionHash: moduleInstance.deployTransaction.hash, blockNumber: receipt.blockNumber }; } exports.deployContract = deployContract; /** * Checks if a contract is already deployed * @param address - Contract address to check * @param provider - Ethers provider * @returns Promise resolving to boolean indicating if contract exists */ async function isContractDeployed(address, provider) { try { const code = await provider.getCode(address); return code !== '0x'; } catch (_a) { return false; } } exports.isContractDeployed = isContractDeployed; //# sourceMappingURL=deploymentHelpers.js.map