Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
734 lines (692 loc) · 26 KB
/
Copy pathindex.html
File metadata and controls
734 lines (692 loc) · 26 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
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
<!DOCTYPE html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<title>V3 宽区间评估表(实时更新版)</title>
<style>
:root { color-scheme: light; }
body {
font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
background: #f5f7fb;
margin: 0;
padding: 20px;
color: #1f2937;
}
.container { max-width: 1100px; margin: 0 auto; }
h1 { font-size: 22px; margin: 0; }
.card {
background: #ffffff;
border-radius: 16px;
padding: 18px 20px;
box-shadow: 0 4px 16px rgba(0, 0, 0, 0.06);
margin-bottom: 18px;
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
gap: 16px;
}
fieldset {
border: 1px solid #e5e7eb;
border-radius: 12px;
padding: 12px 14px;
}
legend { font-weight: 600; padding: 0 6px; color: #374151; }
label {
display: flex;
flex-direction: column;
font-size: 13px;
color: #4b5563;
margin-bottom: 10px;
}
input {
margin-top: 4px;
padding: 8px 10px;
border: 1px solid #d1d5db;
border-radius: 8px;
font-size: 14px;
width: 100%;
box-sizing: border-box;
background: #fafafa;
}
input:focus { outline: none; border-color: #6366f1; background: #fff; }
input[readonly] {
background: #f3f4f6;
color: #374151;
cursor: not-allowed;
}
button {
margin-top: 16px;
padding: 10px 18px;
font-size: 15px;
border: none;
border-radius: 10px;
background: #4f46e5;
color: white;
font-weight: 600;
cursor: pointer;
}
button:hover { background: #4338ca; }
.summary {
display: flex;
flex-wrap: wrap;
gap: 12px;
margin: 14px 0 16px;
}
.summary-item {
flex: 1 1 150px;
background: #f9fafb;
border: 1px solid #e5e7eb;
border-radius: 12px;
padding: 12px 14px;
}
.summary-item .label { font-size: 12px; color: #6b7280; }
.summary-item .value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.pos { color: #16a34a; }
.neg { color: #dc2626; }
table {
width: 100%;
border-collapse: collapse;
font-size: 13px;
white-space: nowrap;
}
th, td {
padding: 8px 10px;
border-bottom: 1px solid #e5e7eb;
text-align: right;
}
th {
background: #f3f4f6;
color: #374151;
font-weight: 600;
position: sticky;
top: 0;
}
th:first-child, td:first-child { text-align: left; }
tbody tr:hover { background: #f9fafb; }
.notes {
font-size: 12px;
color: #6b7280;
line-height: 1.6;
}
.error {
color: #dc2626;
font-weight: 600;
margin-top: 10px;
}
/* ---- 语言切换 & 头部操作 ---- */
.header-actions {
display: flex;
align-items: center;
gap: 10px;
flex-wrap: wrap;
}
.lang-btn {
background: #ffffff;
color: #374151;
border: 1px solid #d1d5db;
padding: 6px 16px;
border-radius: 30px;
font-weight: 600;
font-size: 13px;
cursor: pointer;
margin: 0;
white-space: nowrap;
}
.lang-btn:hover { background: #f3f4f6; border-color: #9ca3af; }
/* ---- 关注区域 ---- */
.header-row {
display: flex;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
gap: 12px;
margin-bottom: 16px;
}
.follow-area {
display: flex;
align-items: center;
gap: 8px 12px;
background: #f0f4fa;
padding: 6px 16px 6px 18px;
border-radius: 40px;
border: 1px solid #d9e2ef;
flex-wrap: wrap;
}
.follow-btn {
background: #3b82f6;
color: white;
border: none;
padding: 6px 18px;
border-radius: 30px;
font-weight: 600;
font-size: 14px;
cursor: pointer;
transition: background 0.15s;
white-space: nowrap;
margin: 0;
}
.follow-btn:hover {
background: #2563eb;
}
.follow-btn.followed {
background: #0b7e4b;
cursor: default;
opacity: 0.8;
}
.follow-status {
font-size: 14px;
font-weight: 500;
color: #1f2a3f;
}
.follow-hint {
font-size: 12px;
color: #6b7a8f;
font-weight: 400;
}
/* ---- 联系方式 ---- */
.contact-area {
display: flex;
flex-wrap: wrap;
align-items: center;
justify-content: center;
gap: 20px 32px;
padding: 4px 0;
}
.contact-item {
display: flex;
align-items: center;
gap: 8px;
font-size: 15px;
color: #1f2937;
}
.contact-item a {
color: #4f46e5;
text-decoration: none;
font-weight: 500;
}
.contact-item a:hover {
text-decoration: underline;
}
.contact-item .icon {
font-size: 20px;
}
</style>
</head>
<body>
<div class="container">
<!-- 标题 + 关注 -->
<div class="header-row">
<h1 data-i18n="app_title">🧊 新 V3 宽区间评估表</h1>
<div class="header-actions">
<button type="button" id="langToggle" class="lang-btn" title="Switch language">EN</button>
<div class="follow-area">
<span class="follow-status" id="followStatus">🔔 关注我们</span>
<button class="follow-btn" id="followBtn">关注</button>
<span class="follow-hint" data-i18n="follow_hint">点击后跳转关注</span>
</div>
</div>
</div>
<!-- 主卡片 -->
<div class="card">
<div class="grid">
<fieldset>
<legend data-i18n="fees_range">费用与区间</legend>
<label><span data-i18n="fee_rate">费率 %</span>
<input id="feeRate" type="number" step="0.01" value="0.30" />
</label>
<label><span data-i18n="lower_price">下限 (USDG/PONS)</span>
<input id="lowerPrice" type="number" step="any" value="0.40" />
</label>
<label><span data-i18n="upper_price">上限 (USDG/PONS)</span>
<input id="upperPrice" type="number" step="any" value="0.80" />
</label>
<label><span data-i18n="price_spread">表格价格扩展 (±)</span>
<input id="priceSpread" type="number" step="0.01" value="0.10" />
</label>
</fieldset>
<fieldset>
<legend data-i18n="token_info">代币信息</legend>
<label><span data-i18n="label_nameA">代币A名称</span>
<input id="nameA" type="text" value="USDG" />
</label>
<label><span data-i18n="label_qtyA">代币A数量</span>
<input id="qtyA" type="number" step="any" value="1000" />
</label>
<label><span data-i18n="label_priceA">代币A价格</span>
<input id="priceA" type="number" step="any" value="1.00" />
</label>
<hr style="border: none; border-top: 1px solid #e5e7eb; margin: 10px 0;" />
<label><span data-i18n="label_nameB">代币B名称</span>
<input id="nameB" type="text" value="PONS" />
</label>
<label><span data-i18n="label_qtyB">代币B数量</span>
<input id="qtyB" type="number" step="any" value="2000" />
</label>
<label><span data-i18n="label_priceB">代币B价格(投入LP时)</span>
<input id="priceB" type="number" step="any" value="0.50" />
</label>
<label><span data-i18n="label_current_price">当前 PONS 价格</span>
<input id="currentPrice" type="number" step="any" value="0.50" />
</label>
</fieldset>
<fieldset>
<legend data-i18n="revenue_settings">收益设置</legend>
<label><span data-i18n="apr_label">APR %</span>
<input id="apr" type="number" step="0.01" value="20.00" />
</label>
<label><span data-i18n="income1h_label">1h 收益 ($/h)(自动计算)</span>
<input id="income1h" type="number" step="any" readonly value="0" />
</label>
</fieldset>
</div>
<button type="button" data-i18n="update_btn" onclick="updateEvaluation()">更新评估</button>
<div id="errorMsg" class="error"></div>
</div>
<!-- 统计与表格 -->
<div class="card">
<h2 style="margin-top:0;" data-i18n="summary_title">当前统计摘要</h2>
<div id="summary" class="summary"></div>
<div style="overflow-x:auto;">
<table id="resultTable"></table>
</div>
</div>
<!-- 底部说明 -->
<div class="card notes" id="notesBox"></div>
<!-- 联系方式区 -->
<div class="card" style="padding: 12px 20px;">
<div class="contact-area">
<div class="contact-item">
<span class="icon">📢</span>
<a href="https://t.me/web6kol" target="_blank" rel="noopener" data-i18n="telegram">Telegram 频道</a>
</div>
<div class="contact-item">
<span class="icon">🐦</span>
<a href="https://x.com/web5_kol" target="_blank" rel="noopener" data-i18n="twitter">Twitter / X</a>
</div>
<div class="contact-item">
<span class="icon">🪙</span>
<span><span data-i18n="binance_search">币安搜:</span><strong>web5kol</strong></span>
</div>
</div>
</div>
</div>
<script>
// ========== 中英文切换(i18n) ==========
const I18N = {
zh: {
page_title: 'V3 宽区间评估表(实时更新版)',
app_title: '🧊 新 V3 宽区间评估表',
follow_us: '🔔 关注我们',
follow_btn: '关注',
follow_btn_done: '已关注 ✓',
follow_thanks: '🎉 感谢关注!',
follow_hint: '点击后跳转关注',
fees_range: '费用与区间',
token_info: '代币信息',
revenue_settings: '收益设置',
fee_rate: '费率 %',
lower_price: '下限 (USDG/PONS)',
upper_price: '上限 (USDG/PONS)',
price_spread: '表格价格扩展 (±)',
label_nameA: '代币A名称',
label_qtyA: '代币A数量',
label_priceA: '代币A价格',
label_nameB: '代币B名称',
label_qtyB: '代币B数量',
label_priceB: '代币B价格(投入LP时)',
label_current_price: '当前 PONS 价格',
apr_label: 'APR %',
income1h_label: '1h 收益 ($/h)(自动计算)',
update_btn: '更新评估',
summary_title: '当前统计摘要',
summary_current_price: '当前 {nameB} 价格',
summary_hodl: 'HODL 市值',
summary_lp: 'LP 市值',
summary_il: '无常缺口',
summary_abs: 'LP 绝对浮亏',
summary_backfee: '回本手续费',
summary_backtime: '回本时间',
table_price_col: '{nameB} 价格 ({nameA}/{nameB})',
table_hodl: 'HODL 市值 ($)',
table_lp: 'LP 市值 ($)',
table_il: '无常缺口 ($)',
table_abs: 'LP 绝对浮亏 ($)',
table_backfee: '回本手续费 ($)',
table_backtime: '回本时间 (h)',
current_marker: '← 当前',
notes_title: '底部说明 / 计算假设',
telegram: 'Telegram 频道',
twitter: 'Twitter / X',
binance_search: '币安搜:',
fallback_nameA: '代币A',
fallback_nameB: '代币B',
err_invalid_number: '请输入有效数字:',
err_range: '区间设置错误:需满足 0 < 下限 < 上限',
err_amounts: '代币数量和价格必须大于等于 0,价格必须大于 0',
err_both_zero: '代币A和代币B数量不能同时为 0',
err_entry_range: '投入时价格必须位于 [下限, 上限] 区间内',
err_spread_neg: '表格价格扩展不能为负数',
err_liquidity: '无法计算流动性,请检查价格区间和价格设置',
unit_year: ' 年',
unit_month: ' 月',
unit_week: ' 周',
unit_day: ' 天',
unit_hour: ' h',
notes: [
'代币A 为报价币,代币B 为基准币,价格口径为 USDG/PONS。',
'代币B价格(投入LP时)用于计算初始投入市值;当前 PONS 价格用于计算当前持仓和收益。',
'流动性 L 由初始总价值(A数量 × A价格 + B数量 × 投入价)联合求解,确保在投入价格处 LP 市值 = HODL 市值 = 初始总价值。',
'HODL 市值 = 初始A数量 × A价格 + 初始B数量 × 当前 PONS 价格。',
'LP 市值 = 按 V3 宽区间和当前价格计算的实际持仓市值(基于上述流动性 L)。',
'无常缺口 = HODL 市值 - LP 市值。',
'LP 绝对浮亏 = 初始投入市值 - 当前 LP 市值。',
'回本手续费 = |LP 绝对浮亏| = |初始投入市值 − 当前 LP 市值|(价格涨、跌两个方向都计算)。',
'回本时间 = 回本手续费 ÷ 1h收益;1h收益 = 当前LP市值 × APR / 8760。',
'表格价格范围 = [下限 - 表格价格扩展, 上限 + 表格价格扩展],均匀生成价格点。',
'所有金额显示为完整美元数值(保留两位小数),不使用 K/M 缩写。',
'输入任何参数后,表格和摘要将实时自动刷新,无需点击按钮。'
]
},
en: {
page_title: 'V3 Wide-Range Evaluation Table (Live)',
app_title: '🧊 New V3 Wide-Range Evaluation Table',
follow_us: '🔔 Follow Us',
follow_btn: 'Follow',
follow_btn_done: 'Followed ✓',
follow_thanks: '🎉 Thanks for following!',
follow_hint: 'Click to follow',
fees_range: 'Fees & Range',
token_info: 'Token Info',
revenue_settings: 'Revenue Settings',
fee_rate: 'Fee Rate %',
lower_price: 'Lower Bound (USDG/PONS)',
upper_price: 'Upper Bound (USDG/PONS)',
price_spread: 'Table Price Extension (±)',
label_nameA: 'Token A Name',
label_qtyA: 'Token A Amount',
label_priceA: 'Token A Price',
label_nameB: 'Token B Name',
label_qtyB: 'Token B Amount',
label_priceB: 'Token B Price (at LP entry)',
label_current_price: 'Current PONS Price',
apr_label: 'APR %',
income1h_label: '1h Income ($/h) (auto)',
update_btn: 'Update Evaluation',
summary_title: 'Current Stats Summary',
summary_current_price: 'Current {nameB} Price',
summary_hodl: 'HODL Value',
summary_lp: 'LP Value',
summary_il: 'Impermanent Loss Gap',
summary_abs: 'LP Absolute Loss',
summary_backfee: 'Breakeven Fee',
summary_backtime: 'Breakeven Time',
table_price_col: '{nameB} Price ({nameA}/{nameB})',
table_hodl: 'HODL Value ($)',
table_lp: 'LP Value ($)',
table_il: 'Imp. Loss Gap ($)',
table_abs: 'LP Abs. Loss ($)',
table_backfee: 'Breakeven Fee ($)',
table_backtime: 'Breakeven Time (h)',
current_marker: '← now',
notes_title: 'Notes / Calculation Assumptions',
telegram: 'Telegram Channel',
twitter: 'Twitter / X',
binance_search: 'Binance search: ',
fallback_nameA: 'Token A',
fallback_nameB: 'Token B',
err_invalid_number: 'Please enter a valid number: ',
err_range: 'Range error: need 0 < lower < upper',
err_amounts: 'Amounts must be >= 0, and prices must be > 0',
err_both_zero: 'Token A and Token B amounts cannot both be 0',
err_entry_range: 'Entry price must be within [lower, upper]',
err_spread_neg: 'Table price extension cannot be negative',
err_liquidity: 'Cannot compute liquidity; check range and price settings',
unit_year: ' yr',
unit_month: ' mo',
unit_week: ' wk',
unit_day: ' d',
unit_hour: ' h',
notes: [
'Token A is the quote token, Token B is the base token; price is quoted in USDG/PONS.',
'Token B price (at LP entry) is used to compute the initial investment value; the current PONS price is used for the current position and income.',
'Liquidity L is solved from the initial total value (A amount × A price + B amount × entry price) so that at the entry price, LP value = HODL value = initial total value.',
'HODL value = initial A amount × A price + initial B amount × current PONS price.',
'LP value = the actual position value computed from the V3 wide range and the current price (based on the liquidity L above).',
'Impermanent loss gap = HODL value − LP value.',
'LP absolute loss = initial investment value − current LP value.',
'Breakeven fee = |LP absolute loss| = |initial investment value − current LP value| (computed in both price directions).',
'Breakeven time = breakeven fee ÷ 1h income; 1h income = current LP value × APR / 8760.',
'Table price range = [lower − price extension, upper + price extension], with evenly spaced price points.',
'All amounts are shown as full dollar values (2 decimals), without K/M abbreviations.',
'After entering any parameter, the table and summary refresh automatically in real time.'
]
}
};
let LANG = (function () {
try { return localStorage.getItem('v3_lang') === 'en' ? 'en' : 'zh'; }
catch (e) { return 'zh'; }
})();
function t(key) {
if (I18N[LANG] && I18N[LANG][key] != null) return I18N[LANG][key];
if (I18N.zh[key] != null) return I18N.zh[key];
return key;
}
function applyStaticI18n() {
document.querySelectorAll('[data-i18n]').forEach(function (el) {
el.textContent = t(el.getAttribute('data-i18n'));
});
}
function renderNotes() {
const box = $('notesBox');
if (!box) return;
const notes = I18N[LANG].notes;
box.innerHTML = '<b>' + t('notes_title') + '</b><br>' +
notes.map(function (s, i) { return (i + 1) + '. ' + s; }).join('<br>');
}
function updateLangBtn() {
const b = $('langToggle');
if (b) b.textContent = (LANG === 'zh') ? 'EN' : '中文';
}
function setLang(next) {
LANG = next;
try { localStorage.setItem('v3_lang', LANG); } catch (e) {}
document.title = t('page_title');
applyStaticI18n();
renderNotes();
updateLangBtn();
}
// ========== 原始评估脚本 ==========
function $(id) { return document.getElementById(id); }
function num(id) {
const v = parseFloat($(id).value);
if (Number.isNaN(v)) throw new Error(t('err_invalid_number') + id);
return v;
}
function fmtPrice(p) {
if (p >= 1000) return p.toFixed(2);
if (p >= 1) return p.toFixed(4);
if (p >= 0.01) return p.toFixed(6);
return p.toPrecision(4);
}
function fmtMoney(v) {
return v.toLocaleString('en-US', { minimumFractionDigits: 2, maximumFractionDigits: 2 });
}
function fmtHours(h) {
if (!Number.isFinite(h)) return '∞';
if (h >= 8760) return (h / 8760).toFixed(2) + t('unit_year');
if (h >= 720) return (h / 720).toFixed(2) + t('unit_month');
if (h >= 168) return (h / 168).toFixed(2) + t('unit_week');
if (h >= 24) return (h / 24).toFixed(2) + t('unit_day');
return h.toFixed(1) + t('unit_hour');
}
function generatePrices(Pa, Pb, currentP, priceB, spread) {
const keyPrices = [Pa, Pb, currentP, priceB];
if (!(spread > 0)) {
return Array.from(new Set(keyPrices.map(p => +p.toFixed(10)))).sort((a, b) => a - b);
}
const minP = Math.max(0.000001, Pa - spread);
const maxP = Pb + spread;
const steps = 30;
const step = (maxP - minP) / steps;
const prices = [];
for (let i = 0; i <= steps; i++) {
prices.push(minP + i * step);
}
keyPrices.forEach(p => prices.push(p));
prices.sort((a, b) => a - b);
return Array.from(new Set(prices.map(p => +p.toFixed(10)))).sort((a, b) => a - b);
}
function updateEvaluation() {
const errorBox = $('errorMsg');
errorBox.textContent = '';
try {
const Pa = num('lowerPrice');
const Pb = num('upperPrice');
const qtyA = num('qtyA');
const priceA = num('priceA');
const qtyB = num('qtyB');
const priceB = num('priceB');
const currentP = num('currentPrice');
const apr = num('apr') / 100;
const spread = num('priceSpread');
const nameA = $('nameA').value.trim() || t('fallback_nameA');
const nameB = $('nameB').value.trim() || t('fallback_nameB');
if (Pa <= 0 || Pb <= Pa) throw new Error(t('err_range'));
if (qtyA < 0 || qtyB < 0 || priceA <= 0 || priceB <= 0 || currentP <= 0) {
throw new Error(t('err_amounts'));
}
if (qtyA === 0 && qtyB === 0) throw new Error(t('err_both_zero'));
if (priceB < Pa || priceB > Pb) throw new Error(t('err_entry_range'));
if (spread < 0) throw new Error(t('err_spread_neg'));
const sqrtPa = Math.sqrt(Pa);
const sqrtPb = Math.sqrt(Pb);
const sqrtP0 = Math.sqrt(priceB);
const numerator = qtyA * priceA + qtyB * priceB;
const denominator = (sqrtP0 - sqrtPa) * priceA + (1 / sqrtP0 - 1 / sqrtPb) * priceB;
if (denominator <= 0) throw new Error(t('err_liquidity'));
const L = numerator / denominator;
function currentAmounts(P) {
if (P <= Pa) {
return { A: 0, B: L * (1 / sqrtPa - 1 / sqrtPb) };
} else if (P >= Pb) {
return { A: L * (sqrtPb - sqrtPa), B: 0 };
} else {
const sqrtP = Math.sqrt(P);
return {
A: L * (sqrtP - sqrtPa),
B: L * (1 / sqrtP - 1 / sqrtPb)
};
}
}
const initialValue = numerator;
function calcRow(P) {
const hodlValue = qtyA * priceA + qtyB * P;
const amounts = currentAmounts(P);
const lpValue = amounts.A * priceA + amounts.B * P;
const impLoss = hodlValue - lpValue;
const absLoss = initialValue - lpValue;
// 回本手续费 = |LP 绝对浮亏|,价格涨、跌两个方向都计算
const backFee = Math.abs(absLoss);
const hourlyIncome = lpValue * apr / 8760;
const backHours = hourlyIncome > 0 ? backFee / hourlyIncome : Infinity;
return { P, hodlValue, lpValue, impLoss, absLoss, backFee, backHours, hourlyIncome };
}
const currentRow = calcRow(currentP);
$('income1h').value = currentRow.hourlyIncome.toFixed(6);
const summary = $('summary');
const curPriceLabel = t('summary_current_price').replace('{nameB}', nameB);
summary.innerHTML = `
<div class="summary-item"><div class="label">${curPriceLabel}</div><div class="value">${fmtPrice(currentP)}</div></div>
<div class="summary-item"><div class="label">${t('summary_hodl')}</div><div class="value">$${fmtMoney(currentRow.hodlValue)}</div></div>
<div class="summary-item"><div class="label">${t('summary_lp')}</div><div class="value">$${fmtMoney(currentRow.lpValue)}</div></div>
<div class="summary-item"><div class="label">${t('summary_il')}</div><div class="value ${currentRow.impLoss >= 0 ? 'neg' : 'pos'}">$${fmtMoney(currentRow.impLoss)}</div></div>
<div class="summary-item"><div class="label">${t('summary_abs')}</div><div class="value ${currentRow.absLoss >= 0 ? 'neg' : 'pos'}">$${fmtMoney(currentRow.absLoss)}</div></div>
<div class="summary-item"><div class="label">${t('summary_backfee')}</div><div class="value">$${fmtMoney(currentRow.backFee)}</div></div>
<div class="summary-item"><div class="label">${t('summary_backtime')}</div><div class="value">${fmtHours(currentRow.backHours)}</div></div>
`;
const prices = generatePrices(Pa, Pb, currentP, priceB, spread);
const priceCol = t('table_price_col').replace('{nameB}', nameB).replace('{nameA}', nameA);
let html = `
<thead><tr>
<th>${priceCol}</th>
<th>${t('table_hodl')}</th>
<th>${t('table_lp')}</th>
<th>${t('table_il')}</th>
<th>${t('table_abs')}</th>
<th>${t('table_backfee')}</th>
<th>${t('table_backtime')}</th>
</tr></thead><tbody>
`;
prices.forEach(P => {
const row = calcRow(P);
const isCurrent = Math.abs(P - currentP) < Math.max(1e-12, currentP * 1e-12);
const highlight = isCurrent ? 'background: #eef2ff;' : '';
html += `<tr style="${highlight}">
<td>${fmtPrice(P)}${isCurrent ? ' ' + t('current_marker') : ''}</td>
<td>$${fmtMoney(row.hodlValue)}</td>
<td>$${fmtMoney(row.lpValue)}</td>
<td class="${row.impLoss >= 0 ? 'neg' : 'pos'}">$${fmtMoney(row.impLoss)}</td>
<td class="${row.absLoss >= 0 ? 'neg' : 'pos'}">$${fmtMoney(row.absLoss)}</td>
<td>$${fmtMoney(row.backFee)}</td>
<td>${fmtHours(row.backHours)}</td>
</tr>`;
});
html += '</tbody>';
$('resultTable').innerHTML = html;
} catch (e) {
$('errorMsg').textContent = '⚠️ ' + e.message;
}
}
// 实时更新:监听所有输入框的 input 事件
document.addEventListener('DOMContentLoaded', function() {
// 初始化语言
document.title = t('page_title');
applyStaticI18n();
renderNotes();
updateLangBtn();
const inputs = document.querySelectorAll('input');
inputs.forEach(input => {
if (!input.readOnly) {
input.addEventListener('input', updateEvaluation);
}
});
updateEvaluation();
// ========== 关注功能 ==========
const followBtn = document.getElementById('followBtn');
const followStatus = document.getElementById('followStatus');
const STORAGE_KEY = 'v3_eval_followed';
const TWITTER_URL = 'https://x.com/web5_kol';
let followed = localStorage.getItem(STORAGE_KEY) === 'true';
function updateFollowUI(isFollowed) {
if (isFollowed) {
followBtn.textContent = t('follow_btn_done');
followBtn.classList.add('followed');
followStatus.textContent = t('follow_thanks');
followBtn.disabled = true;
} else {
followBtn.textContent = t('follow_btn');
followBtn.classList.remove('followed');
followStatus.textContent = t('follow_us');
followBtn.disabled = false;
}
}
updateFollowUI(followed);
followBtn.addEventListener('click', function() {
if (this.disabled) return;
localStorage.setItem(STORAGE_KEY, 'true');
followed = true;
updateFollowUI(true);
// 在新标签页打开推特,保留当前页面
window.open(TWITTER_URL, '_blank', 'noopener,noreferrer');
});
// ========== 语言切换 ==========
document.getElementById('langToggle').addEventListener('click', function() {
setLang(LANG === 'zh' ? 'en' : 'zh');
updateFollowUI(followed);
updateEvaluation();
});
});
</script>
</body>
</html>