UNPKG

dop-stick

Version:

Source control tooling for versionable-upgradeable smart contracts

170 lines 7.91 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeploymentTimelineAdapter = void 0; const terminal_1 = require("../core/terminal"); const timelineLogAdapter_1 = require("./timelineLogAdapter"); const ethers_1 = require("ethers"); const logFormatters_1 = require("../logFormatters"); const ICONS = { NETWORK: '🌐', CHECKS: '🔍', BYTECODE: '⌘', DEPLOYMENT: '📡', SENT: '⚡', PENDING: '⠋', SUCCESS: '✓', ERROR: '✖', PROGRESS: '📈', CHECK: '✓' }; const COLORS = { HEADER: '\x1b[95m', SUCCESS: terminal_1.Terminal.colors.success, PENDING: terminal_1.Terminal.colors.muted, ERROR: terminal_1.Terminal.colors.error, RESET: terminal_1.Terminal.colors.reset }; class DeploymentTimelineAdapter { constructor() { this.totalModules = 0; this.timeline = new timelineLogAdapter_1.TimelineLogAdapter(); } startDeployment(networkInfo) { this.timeline.startSection('⭐ SEQUENTIAL DEPLOYMENT PROCESS'); this.timeline.logStep(`${ICONS.NETWORK} ${COLORS.HEADER}Network Info${COLORS.RESET}`); this.timeline.logInnerStep(`• Network: ${networkInfo.name}`, 1); this.timeline.logInnerStep(`• ChainId: ${networkInfo.chainId}`, 1); this.timeline.logInnerStep(`• Gas Price: ${networkInfo.gasPrice} gwei`, 1); this.timeline.logEmptyStep(); } logPreDeploymentChecks(checks) { this.timeline.logStep('🔍 Pre-deployment checks'); checks.forEach(check => { var _a, _b; const label = this.getCheckLabel(check.type); const details = this.getCheckDetails(check); const icon = this.getStatusIcon(check.status); const color = this.getStatusColor(check.status); this.timeline.logColoredStep(`${icon} ${label}${details}`, 1, color); // If it's a library check with libraries, list them if (check.type === 'libraries' && ((_b = (_a = check.details) === null || _a === void 0 ? void 0 : _a.libraries) === null || _b === void 0 ? void 0 : _b.length)) { check.details.libraries.forEach(lib => { this.timeline.logInnerStep(`• ${lib}`, 2); }); } }); this.timeline.logEmptyStep(); } setTotalModules(total) { this.totalModules = total; this.timeline.logStep(`${ICONS.DEPLOYMENT} ${COLORS.HEADER}Deploying ${total} modules...${COLORS.RESET}`); this.timeline.logEmptyStep(); } startModuleDeployment(moduleName, index) { const moduleHeader = `${COLORS.PENDING}[${index + 1}/${this.totalModules}]${COLORS.RESET} ${moduleName}`; this.timeline.logStep(moduleHeader); } updateModuleProgress(progress) { const { moduleName, stage, txHash, address, gasUsed, bytecodeSize, error, details } = progress; switch (stage) { case 'linking': this.timeline.logInnerStep(`📎 ${details || 'Linking libraries...'}`, 1); break; case 'pending': this.timeline.logInnerStep('⏳ Deployment pending...', 1); break; case 'bytecode': this.timeline.logInnerStep(`📦 Bytecode size: ${bytecodeSize} bytes`, 1); break; case 'transaction': this.timeline.logInnerStep(`🚀 Transaction sent: ${logFormatters_1.LogFormatters.makeHashCopyable(txHash)}`, 1); break; case 'deployed': this.timeline.logInnerStep(`✅ Deployed at: ${logFormatters_1.LogFormatters.makeAddressCopyable(address)}`, 1); if (gasUsed) { this.timeline.logInnerStep(`⛽ Gas used: ${gasUsed.toString()}`, 1); } break; case 'error': this.timeline.logInnerColoredStep(`❌ Error: ${error}`, 1, terminal_1.Terminal.colors.error); break; } } displaySummary(results, duration) { this.timeline.logStep(`${ICONS.PROGRESS} ${COLORS.HEADER}Deployment Summary${COLORS.RESET}`); const successful = results.filter(r => r.status === 'success'); const failed = results.filter(r => r.status === 'failed'); const totalGas = successful.reduce((sum, r) => sum.add(r.gasUsed || 0), ethers_1.ethers.BigNumber.from(0)); const totalBytecode = successful.reduce((sum, r) => sum + (r.bytecodeSize || 0), 0); this.timeline.logInnerStep(`• Successful deployments: ${COLORS.SUCCESS}${successful.length}/${this.totalModules}${COLORS.RESET}`, 1); if (failed.length > 0) { this.timeline.logInnerStep(`• Failed deployments: ${COLORS.ERROR}${failed.length}${COLORS.RESET}`, 1); } this.timeline.logInnerStep(`• Total bytecode: ${(totalBytecode / 1024).toFixed(1)} KB`, 1); this.timeline.logInnerColoredStep(`• Total gas used: ${formatGas(totalGas)}`, 1, COLORS.PENDING); this.timeline.logInnerStep(`• Total deployment time: ${(duration / 1000).toFixed(1)}s`, 1); if (failed.length > 0) { this.timeline.logEmptyStep(); this.timeline.logInnerStep(`${COLORS.ERROR}Failed Deployments:${COLORS.RESET}`, 1); failed.forEach(result => { this.timeline.logInnerStep(`• ${result.moduleName}: ${result.error}`, 2); }); } this.timeline.logEmptyStep(); this.timeline.logSuccessWithTime(`Sequential deployment completed`); } getCheckLabel(type) { const labels = { cuts: 'Cuts validation ', emergency: 'Emergency status ', gas: 'Gas price check ', balance: 'Balance check ', libraries: 'Libraries check ' }; return labels[type] || ''; } getCheckDetails(check) { const { type, details } = check; switch (type) { case 'cuts': return `${(details === null || details === void 0 ? void 0 : details.moduleCount) || 0} modules, ${(details === null || details === void 0 ? void 0 : details.functionCount) || 0} functions`; case 'gas': return (details === null || details === void 0 ? void 0 : details.gasPrice) ? `${details.gasPrice} gwei` : 'Unknown gas price'; case 'balance': return (details === null || details === void 0 ? void 0 : details.current) ? `${details.current} ETH` : 'Unknown balance'; case 'libraries': return (details === null || details === void 0 ? void 0 : details.count) ? `${details.count} libraries required` : 'No libraries required'; default: return (details === null || details === void 0 ? void 0 : details.error) || ''; } } getStatusIcon(status) { switch (status) { case 'success': return '✓'; case 'warning': return '⚠'; case 'failed': return '✖'; default: return '•'; } } getStatusColor(status) { switch (status) { case 'success': return terminal_1.Terminal.colors.success; case 'warning': return terminal_1.Terminal.colors.warning; case 'failed': return terminal_1.Terminal.colors.error; default: return terminal_1.Terminal.colors.muted; // Use muted color for default case } } } exports.DeploymentTimelineAdapter = DeploymentTimelineAdapter; function formatGas(gas) { return gas.gt(1000000) ? `${(gas.toNumber() / 1000000).toFixed(1)}M` : `${(gas.toNumber() / 1000).toFixed(1)}K`; } //# sourceMappingURL=deploymentTimelineAdapter.js.map