General Considerations & Disclaimer
Cross-chain investments involve multiple layers of risk, including vulnerabilities in source/target blockchains, bridge protocols, and the asset itself. Bridge exploits are a significant concern in DeFi.
This analysis is based on your subjective inputs and a simplified scoring model. It is NOT financial advice.
Thoroughly research each component (blockchains, bridge, asset, audits) before making any investment decisions. Diversification and risk management are crucial.
Disclaimer: This tool provides a generalized risk indication based on user-provided subjective assessments. Real-world risks can be more complex. Always conduct your own thorough due diligence (DYOR). Investing in cryptocurrencies, especially via cross-chain mechanisms, carries a high risk of loss.
`;
}
backToInputsBtn.addEventListener('click', () => {
hideMessage();
switchTab('inputsPanel');
});
downloadAnalysisPdfBtn.addEventListener('click', () => {
if (Object.keys(analysisResults).length === 0) {
showMessage("No analysis to download. Please calculate first.", "info");
return;
}
hideMessage();
if (typeof window.jspdf === 'undefined' || typeof window.jspdf.jsPDF === 'undefined') {
console.error('jsPDF library is not loaded.');
showMessage("Error: PDF library (jsPDF) could not be loaded.", "error");
return;
}
const { jsPDF: JSPDFConstructor } = window.jspdf;
const doc = new JSPDFConstructor({ orientation: 'p', unit: 'pt', format: 'a4' });
if (typeof doc.autoTable !== 'function') {
console.error('CRITICAL: doc.autoTable is NOT a function.');
showMessage("Error: PDF generation failed (autoTable function not available).", "error");
return;
}
const title = "Cross-Chain Asset Investment Risk Analysis";
const assetText = currentInputs.assetName !== "N/A" ? ` for ${currentInputs.assetName}` : "";
const timestamp = `Generated: ${new Date().toLocaleString()}`;
const pageWidth = doc.internal.pageSize.getWidth();
const margin = 40;
let startY = margin;
doc.setFontSize(18);
doc.text(title + assetText, pageWidth / 2, startY, { align: 'center' });
startY += 20;
doc.setFontSize(10);
doc.text(timestamp, pageWidth / 2, startY, { align: 'center' });
startY += 30;
// Input Summary Table
doc.setFontSize(12);
doc.setFont(undefined, 'bold');
doc.text("Investment & Risk Inputs Summary", margin, startY);
startY += 15;
const inputData = [
["Initial Investment ($ USD)", formatCurrency(currentInputs.initialInvestment)],
["Asset Name/Symbol", currentInputs.assetName],
["Source Blockchain", currentInputs.sourceBlockchain],
["Target Blockchain", currentInputs.targetBlockchain],
["Cross-Chain Mechanism", currentInputs.crossChainMechanism],
["Bridge/Protocol Name", currentInputs.bridgeProtocolName],
["Source Chain Security Score", currentInputs.sourceChainSecurity + "/5"],
["Target Chain Security Score", currentInputs.targetChainSecurity === 0 ? "N/A" : currentInputs.targetChainSecurity + "/5"],
["Bridge/Mechanism Security Score", currentInputs.bridgeSecurity === 0 ? "N/A" : currentInputs.bridgeSecurity + "/5"],
["Asset Volatility Score", currentInputs.assetVolatility + "/5"],
["Smart Contract Audit Score", currentInputs.smartContractAudit === 0 ? "N/A" : currentInputs.smartContractAudit + "/5"],
["Potential Loss in Exploit (%)", currentInputs.potentialLossPercentage + "%"],
];
doc.autoTable({
body: inputData,
startY: startY,
theme: 'striped',
styles: { fontSize: 9, cellPadding: 4 },
headStyles: { fillColor: [74, 85, 104] },
columnStyles: { 0: { fontStyle: 'bold' } }
});
startY = doc.lastAutoTable.finalY + 20;
// Analysis Summary
doc.setFontSize(12);
doc.setFont(undefined, 'bold');
doc.text("Risk Analysis Summary", margin, startY);
startY += 20;
doc.setFontSize(11);
doc.setFont(undefined, 'bold');
doc.text(`Overall Risk Assessment: ${analysisResults.overallRiskLevel} (Score: ${analysisResults.averageRiskScore}/5.00)`, margin, startY);
startY += 25;
doc.setFontSize(10);
doc.setFont(undefined, 'bold');
doc.text("Key Risk Factors Identified:", margin, startY);
startY += 15;
doc.setFont(undefined, 'normal');
analysisResults.keyFactors.forEach(factor => {
const splitFactor = doc.splitTextToSize(`- ${factor}`, pageWidth - margin * 2 -10);
doc.text(splitFactor, margin + 10, startY);
startY += (splitFactor.length * 12) + 2;
});
startY += 10;
doc.setFontSize(10);
doc.setFont(undefined, 'bold');
doc.text("Potential Financial Impact (Based on Your Estimate):", margin, startY);
startY += 15;
doc.setFont(undefined, 'normal');
const financialData = [
[`Initial Investment: ${formatCurrency(currentInputs.initialInvestment)}`],
[`Your Estimated Potential Loss Percentage: ${currentInputs.potentialLossPercentage}%`],
[`Calculated Potential Financial Loss: ${analysisResults.potentialFinancialLoss}`],
[`Estimated Remaining Value After Assumed Exploit: ${analysisResults.valueAfterExploit}`]
];
financialData.forEach(item => {
const splitItem = doc.splitTextToSize(item[0], pageWidth - margin * 2);
doc.text(splitItem, margin, startY);
startY += (splitItem.length * 12);
});
startY += 20;
// Disclaimer
doc.setFontSize(9);
doc.setFont(undefined, 'italic');
const disclaimer = "Disclaimer: This tool provides a generalized risk indication based on user-provided subjective assessments and a simplified model. Real-world risks can be more complex and dynamic. This is NOT financial advice. Always conduct your own thorough due diligence (DYOR) before investing in cryptocurrencies, especially those involving cross-chain mechanisms, as they carry a high risk of loss.";
const splitDisclaimer = doc.splitTextToSize(disclaimer, pageWidth - margin * 2);
doc.text(splitDisclaimer, margin, startY);
try {
doc.save(`CrossChain_Risk_Analysis_${currentInputs.assetName.replace(/\s+/g, '_')}.pdf`);
showMessage("PDF download initiated.", "success");
} catch (e) {
console.error("Error during PDF generation or save: ", e);
showMessage("Failed to generate or save PDF. See console for details.", "error");
}
});
// Initial tab setup
const initialActiveTab = document.querySelector('.tab-nav-item.active');
if (initialActiveTab) {
const initialTabContentId = initialActiveTab.dataset.tab;
const initialTabContent = document.getElementById(initialTabContentId);
if (initialTabContent) initialTabContent.classList.add('active');
} else if (tabNavItems.length > 0 && tabContents.length > 0) { // Fallback if no tab is initially active
tabNavItems[0].classList.add('active');
const firstTabId = tabNavItems[0].dataset.tab;
const firstContent = document.getElementById(firstTabId);
if (firstContent) firstContent.classList.add('active');
}
});