-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathanalysis.html
More file actions
640 lines (559 loc) · 23 KB
/
analysis.html
File metadata and controls
640 lines (559 loc) · 23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Token Analysis Results</title>
<style>
:root {
--primary: #10B981;
--secondary: #047857;
--background: #111827;
--card: #1F2937;
--text: #F9FAFB;
--accent: #8B5CF6;
}
body {
font-family: 'Inter', sans-serif;
background-color: var(--background);
color: var(--text);
min-height: 100vh;
background-image:
radial-gradient(at 40% 20%, hsla(128,100%,74%,0.1) 0px, transparent 50%),
radial-gradient(at 80% 0%, hsla(189,100%,56%,0.1) 0px, transparent 50%),
radial-gradient(at 0% 50%, hsla(355,100%,93%,0.1) 0px, transparent 50%);
background-attachment: fixed;
margin: 0;
padding: 20px;
}
.container {
max-width: 1200px;
margin: 0 auto;
padding: 20px;
}
.header {
text-align: center;
margin-bottom: 40px;
}
.header h1 {
font-size: 2.5rem;
background: linear-gradient(to right, var(--primary), var(--accent));
-webkit-background-clip: text;
background-clip: text;
-webkit-text-fill-color: transparent;
margin-bottom: 10px;
}
.token-header {
background: rgba(31, 41, 55, 0.7);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 15px;
margin-bottom: 30px;
display: flex;
justify-content: space-between;
align-items: center;
}
.token-basics {
display: flex;
align-items: center;
gap: 15px;
}
.token-image {
width: 60px;
height: 60px;
border-radius: 50%;
background: rgba(255, 255, 255, 0.1);
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
}
.metrics-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 20px;
margin-bottom: 30px;
}
.metric-card {
background: rgba(31, 41, 55, 0.7);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
padding: 20px;
border-radius: 15px;
transition: transform 0.3s ease;
}
.metric-card:hover {
transform: translateY(-5px);
}
.metric-title {
color: var(--primary);
margin-bottom: 15px;
font-size: 1.2rem;
}
.metric {
display: flex;
justify-content: space-between;
padding: 10px;
background: rgba(17, 24, 39, 0.6);
border-radius: 8px;
margin-bottom: 10px;
}
.metric-value {
font-weight: bold;
}
.ai-analysis {
background: rgba(31, 41, 55, 0.7);
backdrop-filter: blur(10px);
border: 1px solid rgba(255, 255, 255, 0.1);
padding: 25px;
border-radius: 15px;
margin-top: 30px;
}
.analysis-section {
margin-bottom: 20px;
}
.analysis-section h3 {
color: var(--primary);
margin-bottom: 10px;
}
.risk-meter {
height: 10px;
background: rgba(17, 24, 39, 0.6);
border-radius: 5px;
overflow: hidden;
margin: 10px 0;
}
.risk-level {
height: 100%;
transition: width 0.5s ease;
background: linear-gradient(to right, var(--primary), var(--accent));
}
.loading {
text-align: center;
padding: 40px;
}
.loading-spinner {
border: 4px solid rgba(255, 255, 255, 0.1);
border-left-color: var(--primary);
border-radius: 50%;
width: 40px;
height: 40px;
animation: spin 1s linear infinite;
margin: 0 auto;
}
@keyframes spin {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}
.back-button {
background: linear-gradient(135deg, var(--primary), var(--accent));
color: white;
border: none;
padding: 10px 20px;
border-radius: 8px;
cursor: pointer;
text-decoration: none;
display: inline-block;
margin-bottom: 20px;
}
.error-message {
background: rgba(239, 68, 68, 0.2);
border: 1px solid rgba(239, 68, 68, 0.5);
padding: 15px;
border-radius: 8px;
margin: 20px 0;
color: #FCA5A5;
}
.metric-container {
background: rgba(255, 255, 255, 0.05);
border-radius: 8px;
padding: 15px;
margin-bottom: 15px;
}
.metric-reasoning {
font-size: 0.9em;
color: #9CA3AF;
margin-top: 8px;
padding-left: 10px;
border-left: 2px solid var(--primary);
line-height: 1.4;
}
.security-score-container {
position: relative;
}
.security-score-reasoning {
margin-top: 10px;
}
.analysis-content {
background: rgba(31, 41, 55, 0.7);
padding: 20px;
border-radius: 12px;
margin-top: 15px;
line-height: 1.6;
color: var(--text);
font-size: 1.1em;
}
#aiAnalysisText {
white-space: pre-line;
margin: 15px 0;
}
</style>
</head>
<body>
<div class="container">
<a href="/" class="back-button">← Back to Analyzer</a>
<div id="loading" class="loading">
<div class="loading-spinner"></div>
<p>Analyzing token data... (Wait couple of seconds)</p>
</div>
<div id="error-message" class="error-message" style="display: none;"></div>
<div id="analysis-content" style="display: none;">
<div class="token-header">
<div class="token-basics">
<div class="token-image" id="tokenImage"></div>
<div>
<h1 id="tokenName">Token Name</h1>
<p id="tokenAddress">Address</p>
</div>
</div>
</div>
<div class="metrics-grid">
<div class="metric-card">
<div class="metric-title">Market Metrics</div>
<div id="marketMetrics"></div>
</div>
<div class="metric-card">
<div class="metric-title">AI Metrics</div>
<div id="socialMetrics"></div>
</div>
<div class="metric-card">
<div class="metric-title">Overall Potential</div>
<div class="metric">
<span class="metric-label">Score</span>
<span class="metric-value" id="overallScoreValue"></span>
</div>
<div class="risk-meter">
<div class="risk-level" id="overallMeter"></div>
</div>
<div id="overallReasoning" class="metric-reasoning"></div>
</div>
</div>
</div>
<div class="ai-analysis">
<h2>AI Analysis</h2>
<div id="aiAnalysisText" class="analysis-content"></div>
</div>
</div>
</div>
<script>
const OPENROUTER_API_KEY = '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';
async function loadAnalysis(mintAddress) {
try {
document.getElementById('loading').style.display = 'block';
document.getElementById('analysis-content').style.display = 'none';
document.getElementById('error-message').style.display = 'none';
const tokenData = await fetchTokenData(mintAddress);
const aiAnalysis = await getAIAnalysis(tokenData);
updateUI(tokenData, aiAnalysis);
} catch (error) {
console.error('Error:', error);
showError(error.message);
document.getElementById('loading').style.display = 'none';
document.getElementById('analysis-content').style.display = 'none';
}
}
function showError(message) {
document.getElementById('loading').style.display = 'none';
const errorDiv = document.getElementById('error-message');
errorDiv.textContent = message;
errorDiv.style.display = 'block';
}
async function fetchTokenData(mintAddress) {
try {
const response = await fetch(`/proxy.php?mint=${mintAddress}`);
const data = await response.json();
// Get AI metrics
const aiMetrics = await analyzeTokenWithAI(data.name, data.description || 'No description available');
return {
name: data.name,
address: mintAddress,
description: data.description || "",
image_uri: data.image_uri,
marketMetrics: {
"Market Cap": `$${data.usd_market_cap?.toFixed(2) || "0"}`,
"Replies Amount": data.reply_count || "0",
"Created At": new Date(data.created_timestamp).toLocaleString()
},
socialMetrics: {
"AI Virality Score": `${aiMetrics.viralityScore}/100`,
"Idea Quality Score": `${aiMetrics.qualityScore}/100`,
"Matches Meta": aiMetrics.matchesMeta
},
// Store full AI responses
viralityReasoning: aiMetrics.viralityReasoning,
qualityReasoning: aiMetrics.qualityReasoning,
metaReasoning: aiMetrics.metaReasoning,
overallScore: aiMetrics.overallScore,
overallReason: aiMetrics.overallReason
};
} catch (error) {
console.error('Error in fetchTokenData:', error);
throw error;
}
}
async function analyzeTokenWithAI(name, description) {
try {
// First API call for scores
const scoreResponse = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${OPENROUTER_API_KEY}`,
"Content-Type": "application/json",
"HTTP-Referer": `${window.location.origin}`,
"X-Title": "Token Analysis"
},
body: JSON.stringify({
"model": "anthropic/claude-2",
"messages": [{
"role": "system",
"content": "You are a crypto token analyzer. Provide numerical scores and reasoning based on token analysis."
}, {
"role": "user",
"content": `Analyze this token and provide scores:
Name: ${name}
Description: ${description}
Rate each category from 0-100 and explain why.
1. Virality Score: Consider meme potential, name catchiness, social appeal, ai narrative and if it suits in ai& agent dominated market
2. Quality Score: Consider uniqueness, utility, market fit, meme potential, and overall score of all
3. Meta Match: Yes/No with explanation AI and Agents, Framework etc are Meta right now.
4. Overall Quality Score: Consider the overall potential based on name and concept (NOT security/risk focused)
Respond ONLY with this exact format:
VIRALITY_SCORE: [number]
VIRALITY_REASON: [explanation]
QUALITY_SCORE: [number]
QUALITY_REASON: [explanation]
META_MATCH: [Yes/No]
META_REASON: [explanation]
OVERALL_SCORE: [number]
OVERALL_REASON: [detailed assessment of overall potential based on concept]`
}]
})
});
const scoreData = await scoreResponse.json();
const scoreText = scoreData.choices[0].message.content;
// Parse the AI response
const scores = {
viralityScore: parseInt(scoreText.match(/VIRALITY_SCORE: (\d+)/)?.[1]),
viralityReasoning: scoreText.match(/VIRALITY_REASON: (.*?)(?=\n|$)/)?.[1],
qualityScore: parseInt(scoreText.match(/QUALITY_SCORE: (\d+)/)?.[1]),
qualityReasoning: scoreText.match(/QUALITY_REASON: (.*?)(?=\n|$)/)?.[1],
matchesMeta: scoreText.match(/META_MATCH: (Yes|No)/)?.[1],
metaReasoning: scoreText.match(/META_REASON: (.*?)(?=\n|$)/)?.[1],
overallScore: parseInt(scoreText.match(/OVERALL_SCORE: (\d+)/)?.[1]),
overallReason: scoreText.match(/OVERALL_REASON: (.*?)(?=\n|$)/)?.[1]
};
// Validate if we got proper AI responses
const isValidAIResponse =
scores.viralityScore > 0 &&
scores.qualityScore > 0 &&
scores.overallScore > 0 &&
scores.viralityReasoning &&
scores.qualityReasoning &&
scores.matchesMeta &&
scores.overallReason;
// Return AI scores if valid, otherwise use failsafe
return isValidAIResponse ? scores : getFailsafeScores(name);
} catch (error) {
console.error('AI Analysis error:', error);
return getFailsafeScores(name);
}
}
async function getAIAnalysis(tokenData) {
try {
const response = await fetch("https://openrouter.ai/api/v1/chat/completions", {
method: "POST",
headers: {
"Authorization": `Bearer ${OPENROUTER_API_KEY}`,
"Content-Type": "application/json",
"HTTP-Referer": `${window.location.origin}`,
"X-Title": "Token Analysis"
},
body: JSON.stringify({
"model": "anthropic/claude-2",
"messages": [{
"role": "system",
"content": "You are a crypto token analyzer.Analysing token names and descriptions and more informations for people. Provide a brief but comprehensive analysis with your own thoughts as degene memecoin trader, current hype are AI coins."
}, {
"role": "user",
"content": `Analyze this token concept:
Name: ${tokenData.name}
Description: ${tokenData.description || 'No description provided'}
Provide a comprehensive analysis in 4-5 sentences roughly covering:
- The token's concept strength and market potential in an AI/Agent market
- Possible challenges on market with its Meme/AI Sentiment and it it matches that or to generic
- Key opportunities and recommendations for the coin in the market, make sure to include saying its early still.
- Only output the answer, nothing else and no added statements like "here is your answer".
`
}]
})
});
const data = await response.json();
return data.choices[0].message.content;
} catch (error) {
console.error('AI Analysis error:', error);
// Provide a fallback analysis based on the token name
return `Analysis of ${tokenData.name}: This token concept shows potential in the current market environment. The main strengths lie in its targeted approach and market timing. However, success will depend on execution quality and community building efforts. Key focus should be on developing clear utility and maintaining strong community engagement.`;
}
}
function parseAIResponse(analysis) {
const sections = {
overview: "",
risks: "",
recommendations: []
};
const parts = analysis.split('\n\n');
parts.forEach(part => {
if (part.toLowerCase().includes('overview')) {
sections.overview = part.replace('Overview:', '').trim();
} else if (part.toLowerCase().includes('risk')) {
sections.risks = part.replace('Risk Assessment:', '').trim();
} else if (part.toLowerCase().includes('recommend')) {
const recs = part.replace('Recommendations:', '').trim();
sections.recommendations = recs.split('\n')
.map(r => r.replace(/^-\s*/, '').trim())
.filter(r => r.length > 0);
}
});
return sections;
}
function getFailsafeScores(tokenName) {
return {
viralityScore: 50,
viralityReasoning: `${tokenName} demonstrates moderate viral potential in current market conditions.`,
qualityScore: 50,
qualityReasoning: `${tokenName} shows standard implementation with potential for growth.`,
matchesMeta: "No", // Default to No for failsafe
metaReasoning: "Current market trends favor AI and agent narratives.",
overallScore: 50,
overallReason: `${tokenName} presents balanced potential with room for growth in the current market.`,
fallbackReasoning: `Analysis for ${tokenName}: This token shows standard potential in the current market environment. While the concept has merit, success will depend on execution and community building. Early stage projects often have room for growth with proper development and marketing strategy. Consider monitoring community engagement and development progress for future potential.`
};
}
function loadTokenImage(imageUri) {
const tokenImage = document.getElementById('tokenImage');
if (imageUri) {
tokenImage.innerHTML = `<img src="${imageUri}" alt="Token" style="width: 100%; height: 100%; object-fit: cover; border-radius: 50%;" onerror="this.src='data:image/svg+xml,<svg xmlns=\'http://www.w3.org/2000/svg\' width=\'60\' height=\'60\'><rect width=\'60\' height=\'60\' fill=\'%23cccccc\'/></svg>'">`;
} else {
tokenImage.style.background = 'rgba(255, 255, 255, 0.1)';
}
}
function getScoreColor(score) {
if (score >= 80) return '#10B981'; // Green for high scores
if (score >= 60) return '#F59E0B'; // Yellow/Orange for medium scores
if (score >= 40) return '#EF4444'; // Red for low scores
return '#EF4444'; // Default red for very low scores
}
function updateUI(tokenData, aiAnalysis) {
document.getElementById('loading').style.display = 'none';
document.getElementById('analysis-content').style.display = 'block';
// Basic Token Info
document.getElementById('tokenName').textContent = tokenData.name;
document.getElementById('tokenAddress').textContent = `Address: ${tokenData.address}`;
// Load token image if exists
if (tokenData.image_uri) {
loadTokenImage(tokenData.image_uri);
}
// Market Metrics
document.getElementById('marketMetrics').innerHTML = createMetricsHTML(tokenData.marketMetrics);
// AI Metrics with reasoning
const enhancedSocialMetrics = {
"AI Virality Score": {
value: `${tokenData.socialMetrics["AI Virality Score"]}`,
reasoning: tokenData.viralityReasoning
},
"Idea Quality Score": {
value: `${tokenData.socialMetrics["Idea Quality Score"]}`,
reasoning: tokenData.qualityReasoning
},
"Matches Meta": {
value: tokenData.socialMetrics["Matches Meta"],
reasoning: tokenData.metaReasoning
}
};
document.getElementById('socialMetrics').innerHTML = createEnhancedMetricsHTML(enhancedSocialMetrics);
// Overall Score
const overallScoreValue = document.getElementById('overallScoreValue');
const overallMeter = document.getElementById('overallMeter');
const overallReasoning = document.getElementById('overallReasoning');
if (overallScoreValue) {
overallScoreValue.textContent = `${tokenData.overallScore}/100`;
}
if (overallMeter) {
overallMeter.style.width = `${tokenData.overallScore}%`;
// Using the getScoreColor function safely with a fallback
const scoreColor = tokenData.overallScore ? getScoreColor(tokenData.overallScore) : '#EF4444';
overallMeter.style.backgroundColor = scoreColor;
}
if (overallReasoning) {
overallReasoning.textContent = tokenData.overallReason;
}
// AI Analysis (simplified version)
const aiAnalysisElement = document.getElementById('aiAnalysisText');
if (aiAnalysisElement && aiAnalysis) {
aiAnalysisElement.textContent = aiAnalysis;
aiAnalysisElement.style.display = 'block'; // Make sure it's visible
}
// Debug log
console.log('UI Update Complete', {
name: tokenData.name,
scores: tokenData.socialMetrics,
analysis: aiAnalysis
});
}
async function initializeAnalysis() {
const urlParams = new URLSearchParams(window.location.search);
const mintAddress = urlParams.get('mint');
if (mintAddress) {
await loadAnalysis(mintAddress);
} else {
showError('No mint address provided');
}
}
document.addEventListener('DOMContentLoaded', () => {
initializeAnalysis().catch(error => {
console.error('Initialization error:', error);
showError('Failed to initialize analysis');
});
});
function createMetricsHTML(metrics) {
return Object.entries(metrics)
.map(([key, value]) => `
<div class="metric">
<span class="metric-label">${key}</span>
<span class="metric-value">${value}</span>
</div>
`).join('');
}
// Add the new function here
function createEnhancedMetricsHTML(metrics) {
return Object.entries(metrics)
.map(([key, data]) => `
<div class="metric-container">
<div class="metric">
<span class="metric-label">${key}</span>
<span class="metric-value">${data.value || 'N/A'}</span>
</div>
${data.reasoning ? `
<div class="metric-reasoning">
${data.reasoning}
</div>
` : ''}
</div>
`).join('');
}
function createRecommendationsHTML(recommendations) {
return `<ul>${recommendations.map(rec => `<li>${rec}</li>`).join('')}</ul>`;
}
</script>
</body>
</html>