dop-stick
Version:
Source control tooling for versionable-upgradeable smart contracts
102 lines • 5.01 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExecuteUpgradeTimelineAdapter = void 0;
const timelineLogAdapter_1 = require("./timelineLogAdapter");
const terminal_1 = require("../core/terminal");
const logFormatters_1 = require("../logFormatters");
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
};
const ICONS = {
DIAMOND: '💎',
NETWORK: '🌐',
PREPARE: '🔧',
EXECUTE: '📡',
PENDING: '⠋',
SUCCESS: '✓',
ERROR: '✖',
STATS: '📊'
};
class ExecuteUpgradeTimelineAdapter {
constructor() {
this.timeline = new timelineLogAdapter_1.TimelineLogAdapter();
}
startUpgrade(networkInfo) {
this.networkInfo = networkInfo;
this.timeline.startSection('DIAMOND UPGRADE EXECUTION');
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(`• Diamond: ${logFormatters_1.LogFormatters.makeAddressCopyable(networkInfo.diamondAddress)}`, 1);
this.timeline.logEmptyStep();
}
logPreparation(cuts) {
this.timeline.logStep(`${ICONS.PREPARE} ${COLORS.HEADER}Preparation${COLORS.RESET}`);
this.timeline.logInnerStep(`• Formatted ${cuts} facet cuts ${COLORS.SUCCESS}${ICONS.SUCCESS}${COLORS.RESET}`, 1);
this.timeline.logInnerStep(`• Retrieved upgrade service ${COLORS.SUCCESS}${ICONS.SUCCESS}${COLORS.RESET}`, 1);
}
logGasEstimate(gas) {
this.timeline.logInnerStep(`• Estimated gas: ${formatGas(gas)} ${COLORS.SUCCESS}${ICONS.SUCCESS}${COLORS.RESET}`, 1);
this.timeline.logEmptyStep();
}
startExecution(cuts, functionName = 'diamondCut') {
this.timeline.logStep(`${ICONS.EXECUTE} ${COLORS.HEADER}Executing Diamond Cut${COLORS.RESET}`);
this.timeline.logInnerStep(`• Method: ${functionName}`, 1);
this.timeline.logInnerStep(`• Modules: ${cuts}`, 1);
this.timeline.logInnerColoredStep(`${ICONS.PENDING} Sending transaction...`, 1, terminal_1.Terminal.colors.yellow);
}
logTransactionSent(txHash) {
this.timeline.logInnerStep(`• TxHash: ${logFormatters_1.LogFormatters.makeHashCopyable(txHash)}`, 1);
this.timeline.logInnerColoredStep(`${ICONS.PENDING} Waiting for confirmation...`, 1, COLORS.PENDING);
}
logConfirmation(blockNumber, gasUsed, cost) {
this.timeline.logInnerColoredStep(`${ICONS.SUCCESS} Confirmed in block #${blockNumber}`, 1, COLORS.SUCCESS);
this.timeline.logInnerStep(`• Gas used: ${formatGas(gasUsed)}`, 1);
this.timeline.logInnerStep(`• Cost: ${cost} ETH`, 1);
this.timeline.logEmptyStep();
}
logError(error, txHash) {
this.timeline.logInnerColoredStep(`${ICONS.ERROR} Transaction failed`, 1, COLORS.ERROR);
this.timeline.logInnerColoredStep(`• Error: ${error}`, 1, COLORS.ERROR);
if (txHash) {
this.timeline.logInnerStep(`• TxHash: ${logFormatters_1.LogFormatters.makeHashCopyable(txHash)}`, 1);
}
this.timeline.logEmptyStep();
}
logFinalStatus(blockNumber, totalGas, totalCost) {
this.timeline.logStep(`${ICONS.STATS} ${COLORS.HEADER}Final Status${COLORS.RESET}`);
this.timeline.logInnerStep(`• Block: #${blockNumber}`, 1);
this.timeline.logInnerStep(`• Total gas: ${formatGas(totalGas)}`, 1);
this.timeline.logInnerStep(`• Total cost: ${totalCost} ETH`, 1);
this.timeline.logEmptyStep();
this.timeline.logSuccessWithTime('Diamond upgrade completed');
}
logInfo(message) {
this.timeline.logColoredStep(`${ICONS.PREPARE} ${message}`, 1, terminal_1.Terminal.colors.info);
}
logSuccess(message) {
this.timeline.logColoredStep(`${ICONS.SUCCESS} ${message}`, 1, COLORS.SUCCESS);
}
logWarning(message) {
this.timeline.logColoredStep(`⚠️ ${message}`, 1, terminal_1.Terminal.colors.warning);
this.timeline.logEmptyStep();
}
logBatchStatus(batchNumber, totalBatches, moduleCount) {
this.timeline.logStep(`${ICONS.DIAMOND} ${COLORS.HEADER}Batch ${batchNumber}/${totalBatches}${COLORS.RESET}`);
this.timeline.logInnerStep(`• Processing ${moduleCount} modules`, 1);
}
logBatchProgress(message) {
this.timeline.logColoredStep(`${ICONS.PENDING} ${message}`, 1, terminal_1.Terminal.colors.info);
}
}
exports.ExecuteUpgradeTimelineAdapter = ExecuteUpgradeTimelineAdapter;
function formatGas(gas) {
return gas.gt(1000000) ?
`${(gas.toNumber() / 1000000).toFixed(1)}M` :
`${(gas.toNumber() / 1000).toFixed(1)}K`;
}
//# sourceMappingURL=executeUpgradeTimelineAdapter.js.map