-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
2607 lines (2441 loc) · 136 KB
/
Copy pathindex.html
File metadata and controls
2607 lines (2441 loc) · 136 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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="robots" content="noindex, nofollow">
<title>Multichain CSV Exporter</title>
<style>
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
:root {
--bg: #ffffff; --bg2: #f5f5f4; --bg3: #eeede9;
--text: #1a1a18; --text2: #6b6b67; --text3: #a0a09b;
--border: rgba(0,0,0,0.12); --border2: rgba(0,0,0,0.22);
--info-bg: #e6f1fb; --info-text: #185fa5;
--success-bg: #eaf3de; --success-text: #3b6d11;
--danger-text: #a32d2d; --danger-bg: #fcebeb;
--radius: 10px; --radius-sm: 7px;
}
@media (prefers-color-scheme: dark) {
:root {
--bg: #1c1c1a; --bg2: #242422; --bg3: #2c2c2a;
--text: #f0ede8; --text2: #a0a09b; --text3: #6b6b67;
--border: rgba(255,255,255,0.1); --border2: rgba(255,255,255,0.2);
--info-bg: #0c447c; --info-text: #b5d4f4;
--success-bg: #27500a; --success-text: #97c459;
--danger-text: #f09595; --danger-bg: #501313;
}
}
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg3); min-height: 100vh; }
.shell { max-width: 860px; margin: 0 auto; padding: 2rem 1rem; }
h1 { font-size: 18px; font-weight: 500; margin-bottom: 4px; }
.subtitle { font-size: 13px; color: var(--text2); margin-bottom: 1.5rem; }
.tabs { display: flex; gap: 2px; background: var(--bg2); border-radius: var(--radius); padding: 4px; margin-bottom: 1.5rem; }
.tab { flex: 1; padding: 8px; text-align: center; cursor: pointer; font-size: 13px; color: var(--text2); border-radius: var(--radius-sm); transition: all 0.15s; }
.tab.active { background: var(--bg); color: var(--text); font-weight: 500; box-shadow: 0 1px 3px rgba(0,0,0,0.1); }
.card { background: var(--bg); border: 0.5px solid var(--border); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 12px; }
.section-title { font-size: 11px; font-weight: 500; color: var(--text3); text-transform: uppercase; letter-spacing: 0.07em; margin-bottom: 12px; }
.chain-dot { width: 8px; height: 8px; border-radius: 50%; flex-shrink: 0; display: inline-block; }
input[type=text], input[type=password], input[type=date], select, textarea {
padding: 0 10px; font-size: 13px;
border: 0.5px solid var(--border); border-radius: var(--radius-sm);
background: var(--bg2); color: var(--text); outline: none; width: 100%;
}
input[type=text], input[type=password], input[type=date], select { height: 34px; }
textarea { padding: 8px 10px; resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--border2); }
input[type=date] { cursor: pointer; }
.btn { height: 34px; padding: 0 14px; border: 0.5px solid var(--border2); border-radius: var(--radius-sm); background: transparent; color: var(--text); font-size: 13px; cursor: pointer; white-space: nowrap; transition: background 0.1s; }
.btn:hover { background: var(--bg2); }
.btn:active { transform: scale(0.98); }
.btn.primary { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn.primary:hover { opacity: 0.85; }
.btn.danger { color: var(--danger-text); border-color: var(--danger-text); }
.btn.danger:hover { background: var(--danger-bg); }
.btn.small { height: 28px; padding: 0 10px; font-size: 12px; }
.btn.preset { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 999px; }
.btn.preset.active { background: var(--text); color: var(--bg); border-color: var(--text); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }
.label-tag { font-size: 12px; font-weight: 500; color: var(--info-text); background: var(--info-bg); padding: 2px 8px; border-radius: 999px; white-space: nowrap; max-width: 160px; overflow: hidden; text-overflow: ellipsis; flex-shrink: 0; }
.chain-tag { font-size: 11px; font-weight: 500; padding: 2px 7px; border-radius: 999px; white-space: nowrap; flex-shrink: 0; }
.addr-mono { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; color: var(--text2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status { font-size: 12px; color: var(--text2); white-space: nowrap; }
.status.ok { color: var(--success-text); }
.status.err { color: var(--danger-text); }
.progress { height: 3px; background: var(--bg2); border-radius: 2px; overflow: hidden; margin-top: 3px; margin-bottom: 2px; }
.progress-bar { height: 100%; background: var(--text); width: 0; transition: width 0.3s; }
.empty { font-size: 13px; color: var(--text3); padding: 1rem 0; text-align: center; }
.presets { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 10px; }
.date-row { display: flex; align-items: center; gap: 8px; }
.date-sep { font-size: 12px; color: var(--text3); flex-shrink: 0; }
.range-summary { font-size: 12px; color: var(--text2); margin-top: 6px; min-height: 16px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.field-label { font-size: 12px; color: var(--text2); margin-bottom: 4px; }
.export-item { display: flex; align-items: center; gap: 8px; padding: 7px 0; border-bottom: 0.5px solid var(--border); }
.export-item:last-child { border-bottom: none; }
.log-item { display: flex; align-items: center; gap: 8px; padding: 6px 0 6px 8px; border-bottom: 0.5px solid var(--border); }
.log-item:last-child { border-bottom: none; }
.mode-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.mode-card { border: 0.5px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; cursor: pointer; transition: border-color 0.15s, background 0.15s; background: var(--bg); }
.mode-card:hover { background: var(--bg2); }
.mode-card.selected { border: 2px solid var(--text); }
.mode-title { font-size: 13px; font-weight: 500; margin-bottom: 3px; }
.mode-desc { font-size: 11px; color: var(--text2); line-height: 1.5; }
.mode-example { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 10px; color: var(--text3); margin-top: 6px; line-height: 1.6; }
.log-addr-header { font-size: 12px; font-weight: 500; color: var(--text2); padding: 10px 0 4px; display: flex; align-items: center; gap: 8px; }
.log-addr-header + .log-addr-header { border-top: 0.5px solid var(--border); margin-top: 6px; }
/* chain picker grid */
.chain-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 6px; margin-top: 8px; }
.chain-chip { display: flex; align-items: center; gap: 7px; padding: 6px 10px; border: 0.5px solid var(--border); border-radius: var(--radius-sm); cursor: pointer; font-size: 12px; transition: background 0.1s; user-select: none; }
.chain-chip:hover { background: var(--bg2); }
.chain-chip.on { border-color: var(--border2); background: var(--bg2); font-weight: 500; }
.chain-chip input[type=checkbox] { width: 13px; height: 13px; flex-shrink: 0; accent-color: var(--text); }
.chain-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chain-id-badge { font-size: 10px; color: var(--text3); flex-shrink: 0; }
/* key panel */
.key-panel { display: flex; align-items: center; gap: 10px; }
.notice { font-size: 12px; color: var(--info-text); background: var(--info-bg); border-radius: var(--radius-sm); padding: 8px 12px; margin-bottom: 12px; line-height: 1.5; }
/* snapshots */
.snap-table { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 8px; }
.snap-table th { text-align: left; font-weight: 500; color: var(--text3); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; padding: 6px 8px; border-bottom: 0.5px solid var(--border); }
.snap-table td { padding: 7px 8px; border-bottom: 0.5px solid var(--border); vertical-align: middle; }
.snap-table tr:last-child td { border-bottom: none; }
.snap-table tr:hover td { background: var(--bg2); }
.token-bal { font-family: 'SF Mono','Fira Code',monospace; text-align: right; }
.snap-addr-head { font-size: 12px; font-weight: 500; color: var(--text2); padding: 10px 0 4px; display: flex; align-items: center; gap: 8px; border-top: 0.5px solid var(--border); margin-top: 6px; }
.snap-addr-head:first-child { border-top: none; margin-top: 0; }
/* interaction badge */
.ix-badge { display: inline-block; font-size: 10px; font-weight: 500; padding: 1px 6px; border-radius: 999px; white-space: nowrap; }
</style>
</head>
<body>
<div class="shell">
<h1>Multichain CSV Exporter</h1>
<p class="subtitle">Powered by Etherscan API V2 — one key, 60+ chains</p>
<div class="tabs">
<div class="tab active" onclick="showTab('keys')">API key</div>
<div class="tab" onclick="showTab('addresses')">Address book</div>
<div class="tab" onclick="showTab('counterparties')">Counterparties</div>
<div class="tab" onclick="showTab('export')">Export</div>
<div class="tab" onclick="showTab('snapshots')">Snapshots</div>
</div>
<!-- ── API KEY TAB ── -->
<div id="tab-keys">
<div class="notice">
Etherscan API V2 uses a <strong>single key</strong> for all supported chains. Get yours free at
<a href="https://etherscan.io/myapikey" target="_blank" style="color:var(--info-text)">etherscan.io/myapikey</a>.
</div>
<div class="card">
<div class="key-panel">
<input type="password" id="api-key" placeholder="Paste your Etherscan V2 API key…" style="flex:1">
<button class="btn small" onclick="toggleKeyVis()">show</button>
<button class="btn small primary" onclick="saveKey()">Save</button>
<span id="key-status" class="status" style="min-width:44px"></span>
</div>
</div>
<div class="section-title" style="margin-top:8px">Chains to export</div>
<div class="card">
<div style="display:flex;align-items:center;justify-content:space-between;margin-bottom:8px">
<span style="font-size:12px;color:var(--text2)">Select which chains to include in exports</span>
<div style="display:flex;gap:6px">
<button class="btn small" onclick="selectAllChains(true)">All</button>
<button class="btn small" onclick="selectAllChains(false)">None</button>
</div>
</div>
<div class="chain-grid" id="chain-grid"></div>
</div>
<p style="font-size:12px;color:var(--text3);margin-top:4px;">Your API key is saved in your browser's localStorage only.</p>
</div>
<!-- ── ADDRESS BOOK TAB ── -->
<div id="tab-addresses" style="display:none">
<div class="section-title">Saved addresses</div>
<div id="addr-list"></div>
<div class="card" style="margin-top:12px">
<div style="display:flex;gap:2px;background:var(--bg2);border-radius:var(--radius-sm);padding:3px;margin-bottom:14px">
<div id="atab-single" onclick="showAddTab('single')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;background:var(--bg);font-weight:500">Single</div>
<div id="atab-bulk" onclick="showAddTab('bulk')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;color:var(--text2)">Bulk paste</div>
<div id="atab-csv" onclick="showAddTab('csv')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;color:var(--text2)">CSV file</div>
</div>
<!-- single -->
<div id="apanel-single">
<div style="display:flex;gap:8px;margin-bottom:8px">
<input type="text" id="new-addr" placeholder="0x… wallet address" style="flex:2">
<input type="text" id="new-label" placeholder="Label (e.g. My Vault)" style="flex:1">
</div>
<div style="display:flex;gap:8px;align-items:center">
<select id="new-chain-scope" style="flex:1"></select>
<button class="btn primary" onclick="addAddress()" style="flex-shrink:0">Add</button>
</div>
</div>
<!-- bulk paste -->
<div id="apanel-bulk" style="display:none">
<div style="font-size:12px;color:var(--text2);margin-bottom:6px">
One address per line, or <code style="font-size:11px">address, label</code> pairs. Unlabelled addresses get auto-numbered.
</div>
<textarea id="bulk-text" placeholder="0xAbc123… 0xDef456…, My Vault 0x789…, Hot Wallet" style="height:110px;font-family:'SF Mono','Fira Code',monospace"></textarea>
<div style="display:flex;gap:8px;align-items:center;margin-top:8px">
<select id="bulk-chain-scope" style="flex:1"></select>
<button class="btn primary" onclick="importBulk()" style="flex-shrink:0">Import</button>
</div>
<div id="bulk-status" style="font-size:12px;margin-top:6px;min-height:16px"></div>
</div>
<!-- csv file -->
<div id="apanel-csv" style="display:none">
<div style="font-size:12px;color:var(--text2);margin-bottom:8px">
Upload a CSV with <code style="font-size:11px">address</code> and <code style="font-size:11px">label</code> columns (case-insensitive). An optional <code style="font-size:11px">chain</code> column sets per-row scope.
</div>
<div id="csv-drop" onclick="document.getElementById('csv-file').click()"
style="border:1.5px dashed var(--border2);border-radius:var(--radius-sm);padding:20px;text-align:center;cursor:pointer;transition:background 0.15s"
ondragover="event.preventDefault();this.style.background='var(--bg2)'"
ondragleave="this.style.background=''"
ondrop="onCSVDrop(event)">
<div style="font-size:13px;color:var(--text2)">Drop a CSV here, or click to browse</div>
<div style="font-size:11px;color:var(--text3);margin-top:4px">address, label [, chain]</div>
</div>
<input type="file" id="csv-file" accept=".csv,.txt" style="display:none" onchange="onCSVFile(event)">
<div style="display:flex;gap:8px;align-items:center;margin-top:8px">
<select id="csv-chain-scope" style="flex:1"></select>
<span style="font-size:11px;color:var(--text3)">fallback scope if no chain column</span>
</div>
<div id="csv-status" style="font-size:12px;margin-top:6px;min-height:16px"></div>
</div>
</div>
</div>
<!-- ── COUNTERPARTIES TAB ── -->
<div id="tab-counterparties" style="display:none">
<div class="notice">
Map any address to a human-readable label. These are joined onto every export's <code style="font-size:11px">from</code> / <code style="font-size:11px">to</code> / <code style="font-size:11px">contractAddress</code> as <code style="font-size:11px">_from_label</code> / <code style="font-size:11px">_to_label</code> / <code style="font-size:11px">_contract_label</code> columns. Labels from your address book are also picked up automatically, so transfers between your own wallets get labeled on both sides.
</div>
<div class="section-title">Saved counterparties (<span id="cp-count">0</span>)</div>
<div id="cp-list"></div>
<div class="card" style="margin-top:12px">
<div style="display:flex;gap:2px;background:var(--bg2);border-radius:var(--radius-sm);padding:3px;margin-bottom:14px">
<div id="cptab-single" onclick="showCpTab('single')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;background:var(--bg);font-weight:500">Single</div>
<div id="cptab-bulk" onclick="showCpTab('bulk')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;color:var(--text2)">Bulk paste</div>
<div id="cptab-csv" onclick="showCpTab('csv')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;color:var(--text2)">CSV file</div>
<div id="cptab-seed" onclick="showCpTab('seed')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;color:var(--text2)">Common contracts</div>
</div>
<!-- single -->
<div id="cppanel-single">
<div style="display:flex;gap:8px;margin-bottom:8px">
<input type="text" id="cp-new-addr" placeholder="0x… counterparty address" style="flex:2">
<input type="text" id="cp-new-label" placeholder="Label (e.g. Coinbase deposit)" style="flex:1">
</div>
<div style="display:flex;gap:8px;align-items:center">
<select id="cp-new-category" style="flex:1"></select>
<button class="btn primary" onclick="addCounterparty()" style="flex-shrink:0">Add</button>
</div>
</div>
<!-- bulk paste -->
<div id="cppanel-bulk" style="display:none">
<div style="font-size:12px;color:var(--text2);margin-bottom:6px">
One line per entry: <code style="font-size:11px">address, label</code> or <code style="font-size:11px">address, label, category</code>. Lines without a comma are ignored. Unrecognised categories fall back to "Other".
</div>
<textarea id="cp-bulk-text" placeholder="0xAbc123…, Coinbase deposit, Exchange (CEX) 0xDef456…, Uniswap V3 Router, DEX 0x789…, Friend's wallet, Wallet (Personal)" style="height:140px;font-family:'SF Mono','Fira Code',monospace"></textarea>
<div style="display:flex;gap:8px;align-items:center;margin-top:8px">
<select id="cp-bulk-fallback-category" style="flex:1"></select>
<span style="font-size:11px;color:var(--text3)">fallback if line omits category</span>
<button class="btn primary" onclick="importCounterpartiesBulk()" style="flex-shrink:0">Import</button>
</div>
<div id="cp-bulk-status" style="font-size:12px;margin-top:6px;min-height:16px"></div>
</div>
<!-- csv file -->
<div id="cppanel-csv" style="display:none">
<div style="font-size:12px;color:var(--text2);margin-bottom:8px">
Upload a CSV with <code style="font-size:11px">address</code>, <code style="font-size:11px">label</code>, and optional <code style="font-size:11px">category</code> columns (case-insensitive headers).
</div>
<div id="cp-csv-drop" onclick="document.getElementById('cp-csv-file').click()"
style="border:1.5px dashed var(--border2);border-radius:var(--radius-sm);padding:20px;text-align:center;cursor:pointer;transition:background 0.15s"
ondragover="event.preventDefault();this.style.background='var(--bg2)'"
ondragleave="this.style.background=''"
ondrop="onCpCSVDrop(event)">
<div style="font-size:13px;color:var(--text2)">Drop a CSV here, or click to browse</div>
<div style="font-size:11px;color:var(--text3);margin-top:4px">address, label [, category]</div>
</div>
<input type="file" id="cp-csv-file" accept=".csv,.txt" style="display:none" onchange="onCpCSVFile(event)">
<div style="display:flex;gap:8px;align-items:center;margin-top:8px">
<select id="cp-csv-fallback-category" style="flex:1"></select>
<span style="font-size:11px;color:var(--text3)">fallback if no category column</span>
</div>
<div id="cp-csv-status" style="font-size:12px;margin-top:6px;min-height:16px"></div>
</div>
<!-- common contracts (seeded list) -->
<div id="cppanel-seed" style="display:none">
<div style="font-size:12px;color:var(--text2);margin-bottom:8px">
Curated list of widely-used contract addresses. Most DEX aggregators and Aave V3 deploy at the same address across chains, so a single entry labels rows everywhere those protocols appear. Token addresses below are Ethereum mainnet — add your own for L2s. Already-saved entries are pre-checked and will be left untouched.
</div>
<div style="display:flex;gap:6px;margin-bottom:8px;flex-wrap:wrap">
<button class="btn small" onclick="seedSelectAll(true)">Select all</button>
<button class="btn small" onclick="seedSelectAll(false)">Select none</button>
<button class="btn small" onclick="toggleCustomSeedForm()" id="cs-toggle-btn">+ Add custom</button>
<div style="flex:1"></div>
<button class="btn primary small" onclick="addSelectedSeeds()">Add selected</button>
</div>
<div id="cp-custom-seed-form" style="display:none;margin-bottom:10px;padding:10px 12px;border:0.5px solid var(--border);border-radius:var(--radius-sm);background:var(--bg2)">
<div class="field-label" style="margin-bottom:6px">New custom contract</div>
<div style="display:flex;gap:8px;margin-bottom:8px">
<input type="text" id="cs-addr" placeholder="0x… address" style="flex:2">
<input type="text" id="cs-label" placeholder="Label" style="flex:1">
</div>
<div style="display:flex;gap:8px;margin-bottom:8px">
<select id="cs-category" style="flex:1"></select>
<input type="text" id="cs-notes" placeholder="Notes (optional, e.g. Arbitrum)" style="flex:2">
</div>
<div style="display:flex;gap:6px;align-items:center">
<div id="cs-form-status" style="font-size:12px;flex:1;min-height:16px"></div>
<button class="btn small" onclick="toggleCustomSeedForm()">Cancel</button>
<button class="btn small primary" onclick="saveCustomSeed()">Save</button>
</div>
</div>
<div id="cp-seed-list" style="max-height:380px;overflow-y:auto;border:0.5px solid var(--border);border-radius:var(--radius-sm);padding:4px 8px"></div>
<div id="cp-seed-status" style="font-size:12px;margin-top:8px;min-height:16px"></div>
</div>
</div>
<div style="margin-top:8px;display:flex;gap:8px;justify-content:flex-end">
<button class="btn small" onclick="exportCounterpartiesCSV()">Export to CSV</button>
<button class="btn small danger" onclick="clearCounterparties()">Clear all</button>
</div>
</div>
<!-- ── EXPORT TAB ── -->
<div id="tab-export" style="display:none">
<div class="section-title">Settings</div>
<div class="card" style="margin-bottom:12px">
<div class="grid2" style="margin-bottom:14px">
<div>
<div class="field-label">Data types</div>
<div style="display:flex;flex-direction:column;gap:6px;font-size:13px;line-height:1.3">
<label style="display:flex;align-items:center;gap:8px;cursor:pointer">
<input type="checkbox" id="exp-type-txlist" checked style="accent-color:var(--text);width:13px;height:13px"> Normal transactions
</label>
<label style="display:flex;align-items:center;gap:8px;cursor:pointer">
<input type="checkbox" id="exp-type-txlistinternal" checked style="accent-color:var(--text);width:13px;height:13px"> Internal transactions
</label>
<label style="display:flex;align-items:center;gap:8px;cursor:pointer">
<input type="checkbox" id="exp-type-tokentx" checked style="accent-color:var(--text);width:13px;height:13px"> ERC-20 token transfers
</label>
<label style="display:flex;align-items:center;gap:8px;cursor:pointer">
<input type="checkbox" id="exp-type-tokennfttx" style="accent-color:var(--text);width:13px;height:13px"> ERC-721 NFT transfers
</label>
<label style="display:flex;align-items:center;gap:8px;cursor:pointer">
<input type="checkbox" id="exp-type-token1155tx" style="accent-color:var(--text);width:13px;height:13px"> ERC-1155 transfers
</label>
</div>
</div>
<div>
<div class="field-label">Limit per address / chain</div>
<select id="exp-limit">
<option value="0" selected>All (recommended)</option>
<option value="1000">1,000</option>
<option value="5000">5,000</option>
<option value="10000">10,000</option>
<option value="25000">25,000</option>
<option value="50000">50,000</option>
<option value="100000">100,000</option>
</select>
</div>
</div>
<div class="field-label">Date range <span style="color:var(--text3);font-weight:normal">(UTC)</span></div>
<div class="presets" id="presets-row"></div>
<div class="date-row">
<input type="date" id="date-from" onchange="onDateChange()" style="flex:1">
<span class="date-sep">to</span>
<input type="date" id="date-to" onchange="onDateChange()" style="flex:1">
</div>
<div class="range-summary" id="range-summary"></div>
<div style="margin-top:10px;padding:10px;background:var(--bg2);border-radius:6px;border:1px solid var(--border)">
<label style="display:flex;align-items:flex-start;gap:8px;cursor:pointer;font-size:13px">
<input type="checkbox" id="exp-filter-spam" checked style="accent-color:var(--text);margin-top:2px;flex-shrink:0">
<span>
<strong>Filter spam / address poisoning</strong>
<span style="display:block;color:var(--text3);font-size:12px;margin-top:2px">
Drops zero-value ERC-20 and ERC-1155 transfers, which are nearly always
poisoning attempts. Has no effect on normal transactions or NFT transfers.
</span>
</span>
</label>
</div>
</div>
<div class="card" style="margin-bottom:12px">
<div class="field-label" style="margin-bottom:10px">Download mode</div>
<div class="mode-grid">
<div class="mode-card selected" data-mode="separate" onclick="selectMode('separate')">
<div class="mode-title">Separate files</div>
<div class="mode-desc">One CSV per address per chain</div>
<div class="mode-example">MyVault_eth.csv<br>MyVault_base.csv<br>HotWallet_eth.csv</div>
</div>
<div class="mode-card" data-mode="per-address" onclick="selectMode('per-address')">
<div class="mode-title">Per address</div>
<div class="mode-desc">All chains merged per address, with a <code style="font-size:10px">_chain</code> column</div>
<div class="mode-example">MyVault_all_chains.csv<br>HotWallet_all_chains.csv</div>
</div>
<div class="mode-card" data-mode="combined" onclick="selectMode('combined')">
<div class="mode-title">Combined</div>
<div class="mode-desc">Everything in one file with <code style="font-size:10px">_label</code> + <code style="font-size:10px">_chain</code></div>
<div class="mode-example">multichain_export.csv</div>
</div>
</div>
</div>
<div class="card" style="margin-bottom:1rem">
<div class="field-label" style="margin-bottom:8px">Addresses to export</div>
<div id="export-addr-list"></div>
</div>
<div id="export-cp-status" style="font-size:11px;color:var(--text3);margin-bottom:10px;text-align:right"></div>
<button class="btn primary" id="run-btn" onclick="runExport()">Run export</button>
<div id="export-log" style="margin-top:1rem"></div>
</div>
<!-- ── SNAPSHOTS TAB ── -->
<div id="tab-snapshots" style="display:none">
<div class="section-title">Token balance snapshots</div>
<div class="card" style="margin-bottom:12px">
<!-- Date mode -->
<div class="field-label" style="margin-bottom:8px">Snapshot date <span style="color:var(--text3);font-weight:normal">(UTC, end of day)</span></div>
<div style="display:flex;gap:2px;background:var(--bg2);border-radius:var(--radius-sm);padding:3px;margin-bottom:10px;max-width:340px">
<div id="sdtab-now" onclick="showSnapDateTab('now')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;background:var(--bg);font-weight:500">Current</div>
<div id="sdtab-hist" onclick="showSnapDateTab('hist')" style="flex:1;text-align:center;padding:6px;font-size:12px;border-radius:5px;cursor:pointer;color:var(--text2)">Historical date</div>
</div>
<div id="sdpanel-now" style="margin-bottom:10px">
<div style="font-size:12px;color:var(--text2)">Fetches live balances as of the latest block. Token list via <code style="font-size:11px">addresstokenbalance</code>.</div>
</div>
<div id="sdpanel-hist" style="display:none;margin-bottom:10px">
<div style="display:flex;gap:8px;align-items:center;margin-bottom:8px">
<input type="date" id="snap-date" style="max-width:180px;flex-shrink:0" onchange="onSnapDateChange()">
<div id="snap-block-display" style="font-size:12px;color:var(--text2);font-family:'SF Mono','Fira Code',monospace"></div>
</div>
<!-- Quick presets -->
<div style="display:flex;gap:6px;flex-wrap:wrap;margin-bottom:8px">
<button class="btn preset" onclick="applySnapPreset('year-end')">Last year-end</button>
<button class="btn preset" onclick="applySnapPreset('q-end')">Last quarter-end</button>
<button class="btn preset" onclick="applySnapPreset('month-end')">Last month-end</button>
</div>
<div class="notice" style="margin-bottom:0">
<strong>Native balance</strong> at a historical block requires an Etherscan <strong>PRO</strong> plan (<code style="font-size:11px">balancehistory</code>). On a free key it will fall back to current balance and be marked <em>approx</em>.<br>
<strong>Token balances</strong> are reconstructed from transfer history up to the chosen block — available on all plans.
</div>
</div>
<!-- Addresses -->
<div class="field-label" style="margin-bottom:6px">Addresses</div>
<div id="snap-addr-list"></div>
<div style="display:flex;gap:8px;margin-top:12px;align-items:center;flex-wrap:wrap">
<label style="display:flex;align-items:center;gap:6px;font-size:12px;color:var(--text2);cursor:pointer">
<input type="checkbox" id="snap-hide-zero" checked style="accent-color:var(--text)"> Hide zero balances
</label>
<div style="flex:1"></div>
<button class="btn primary" id="snap-btn" onclick="runSnapshot()">Take snapshot</button>
<button class="btn small" id="snap-dl-btn" onclick="downloadSnapshot()" style="display:none">Download CSV</button>
</div>
</div>
<div id="snap-log"></div>
<div id="snap-results"></div>
</div>
</div>
<script>
// ── Etherscan V2: single endpoint, chainid param ──────────────────────────────
const API_BASE = 'https://api.etherscan.io/v2/api';
// Full list from https://docs.etherscan.io/supported-chains
// { id, name, chainId, color, short }
const CHAINS = [
{ id:'eth', name:'Ethereum', chainId:1, color:'#627eea', short:'ETH' },
{ id:'op', name:'Optimism', chainId:10, color:'#ff0420', short:'OP' },
{ id:'bsc', name:'BNB Smart Chain', chainId:56, color:'#f0b90b', short:'BSC' },
{ id:'gnosis', name:'Gnosis', chainId:100, color:'#04795b', short:'GNO' },
{ id:'unichain', name:'Unichain', chainId:130, color:'#ff007a', short:'UNI' },
{ id:'poly', name:'Polygon', chainId:137, color:'#8247e5', short:'MATIC' },
{ id:'sonic', name:'Sonic', chainId:146, color:'#fe9a4c', short:'S' },
{ id:'wc', name:'World Chain', chainId:480, color:'#000000', short:'WLD' },
{ id:'hyperevm', name:'HyperEVM', chainId:999, color:'#00a3ff', short:'HYPE' },
{ id:'moonbeam', name:'Moonbeam', chainId:1284, color:'#53cbc8', short:'GLMR' },
{ id:'moonriver', name:'Moonriver', chainId:1285, color:'#f2a007', short:'MOVR' },
{ id:'mantle', name:'Mantle', chainId:5000, color:'#000000', short:'MNT' },
{ id:'base', name:'Base', chainId:8453, color:'#0052ff', short:'BASE' },
{ id:'arb', name:'Arbitrum One', chainId:42161, color:'#28a0f0', short:'ARB' },
{ id:'celo', name:'Celo', chainId:42220, color:'#35d07f', short:'CELO' },
{ id:'avax', name:'Avalanche C-Chain', chainId:43114, color:'#e84142', short:'AVAX' },
{ id:'linea', name:'Linea', chainId:59144, color:'#61dfff', short:'LINEA' },
{ id:'blast', name:'Blast', chainId:81457, color:'#fcfc03', short:'BLAST' },
{ id:'taiko', name:'Taiko', chainId:167000, color:'#e91898', short:'TAIKO' },
{ id:'scroll', name:'Scroll', chainId:534352, color:'#eeb878', short:'SCROLL' },
// Removed (Nov 2026): chains not present in Etherscan V2's supported chainlist
// (https://api.etherscan.io/v2/chainlist). Keeping them only produced
// "Missing or unsupported chainid parameter" errors. Removed: Flare,
// Rootstock, Telos, Fuse, Heco, Manta Pacific, Fantom, Boba, KCC, zkSync Era,
// Arbitrum Nova, Cronos, Metis, Ink, Soneium. If any are re-added to
// Etherscan V2 in the future, just append them back here.
// Fantom (250) is permanently gone — the network rebranded to Sonic (146)
// which is now supported by Etherscan V2 and added above.
];
// All preset boundaries are computed in UTC so that the date range matches
// what Etherscan's explorer shows (block timestamps are UTC).
// ── Counterparty categories ──────────────────────────────────────────────────
// Fixed enum so users don't fragment with typos like "cex"/"CEX"/"Cex".
const CATEGORIES = [
'Exchange (CEX)',
'DEX',
'Lending',
'Staking',
'Bridge',
'Token Contract',
'Wallet (Personal)',
'Service Provider',
'Other',
];
// ── Pre-seeded common contracts ──────────────────────────────────────────────
// Curated list of widely-used contract addresses. Most DEX aggregators and
// Aave V3 deploy at the same address across major EVM chains, so a single
// entry labels rows wherever those protocols appear. Token addresses are
// chain-specific; the entries below are Ethereum mainnet — users on other
// chains can add their local token addresses separately.
const SEED_CONTRACTS = [
// DEX routers / aggregators
{ address:'0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D', label:'Uniswap V2 Router', category:'DEX', notes:'Ethereum mainnet' },
{ address:'0xE592427A0AEce92De3Edee1F18E0157C05861564', label:'Uniswap V3 SwapRouter', category:'DEX', notes:'Multichain (canonical)' },
{ address:'0x68b3465833fb72A70ecDF485E0e4C7bD8665Fc45', label:'Uniswap V3 SwapRouter02', category:'DEX', notes:'Multichain (canonical)' },
{ address:'0xEf1c6E67703c7BD7107eed8303Fbe6EC2554BF6B', label:'Uniswap Universal Router', category:'DEX', notes:'Ethereum mainnet' },
{ address:'0xd9e1cE17f2641f24aE83637ab66a2cca9C378B9F', label:'SushiSwap Router', category:'DEX', notes:'Ethereum mainnet' },
{ address:'0x1111111254EEB25477B68fb85Ed929f73A960582', label:'1inch V5 Aggregation Router', category:'DEX', notes:'Multichain (same address)' },
{ address:'0x111111125421cA6dc452d289314280a0f8842A65', label:'1inch V6 Aggregation Router', category:'DEX', notes:'Multichain (same address)' },
{ address:'0xDef1C0ded9bec7F1a1670819833240f027b25EfF', label:'0x Exchange Proxy', category:'DEX', notes:'Multichain (same address)' },
{ address:'0x9008D19f58AAbD9eD0D60971565AA8510560ab41', label:'CoW Protocol Settlement', category:'DEX', notes:'Multichain (same address)' },
// Lending
{ address:'0x87870Bca3F3fD6335C3F4ce8392D69350B4fA4E2', label:'Aave V3 Pool', category:'Lending', notes:'Multichain (canonical)' },
{ address:'0x7d2768dE32b0b80b7a3454c06BdAc94A69DDc7A9', label:'Aave V2 Lending Pool', category:'Lending', notes:'Ethereum mainnet' },
{ address:'0xc3d688B66703497DAA19211EEdff47f25384cdc3', label:'Compound III cUSDCv3', category:'Lending', notes:'Ethereum mainnet' },
// Staking
{ address:'0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84', label:'Lido stETH', category:'Staking', notes:'Ethereum mainnet' },
{ address:'0x7f39C581F595B53c5cb19bD0b3f8dA6c935E2Ca0', label:'Lido wstETH', category:'Staking', notes:'Ethereum mainnet' },
{ address:'0xae78736Cd615f374D3085123A210448E74Fc6393', label:'Rocket Pool rETH', category:'Staking', notes:'Ethereum mainnet' },
{ address:'0x00000000219ab540356cBB839Cbe05303d7705Fa', label:'ETH 2.0 Deposit Contract', category:'Staking', notes:'Ethereum mainnet' },
// Bridges
{ address:'0x8731d54E9D02c286767d56ac03e8037C07e01e98', label:'Stargate Router', category:'Bridge', notes:'Ethereum mainnet' },
{ address:'0x66A71Dcef29A0fFBDBE3c6a460a3B5BC225Cd675', label:'LayerZero Endpoint V1', category:'Bridge', notes:'Ethereum mainnet' },
{ address:'0x5c7BCd6E7De5423a257D81B442095A1a6ced35C5', label:'Across SpokePool', category:'Bridge', notes:'Ethereum mainnet' },
// Token contracts (Ethereum mainnet)
{ address:'0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', label:'WETH', category:'Token Contract', notes:'Ethereum mainnet' },
{ address:'0xA0b86991c6218b36c1d19d4A2e9Eb0cE3606eB48', label:'USDC', category:'Token Contract', notes:'Ethereum mainnet' },
{ address:'0xdAC17F958D2ee523a2206206994597C13D831ec7', label:'USDT', category:'Token Contract', notes:'Ethereum mainnet' },
{ address:'0x6B175474E89094C44Da98b954EedeAC495271d0F', label:'DAI', category:'Token Contract', notes:'Ethereum mainnet' },
{ address:'0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599', label:'WBTC', category:'Token Contract', notes:'Ethereum mainnet' },
{ address:'0x514910771AF9Ca656af840dff83E8264EcF986CA', label:'LINK', category:'Token Contract', notes:'Ethereum mainnet' },
{ address:'0x1f9840a85d5aF5bf1D1762F925BdADdC4201F984', label:'UNI', category:'Token Contract', notes:'Ethereum mainnet' },
];
const PRESETS = [
{ label:'All time', id:'all', fn:()=>({from:null,to:null}) },
{ label:'This year', id:'ytd', fn:()=>{const n=new Date();const y=n.getUTCFullYear();return{from:new Date(Date.UTC(y,0,1)),to:n};} },
{ label:'Last year', id:'lasty', fn:()=>{const y=new Date().getUTCFullYear()-1;return{from:new Date(Date.UTC(y,0,1)),to:new Date(Date.UTC(y,11,31))};} },
{ label:'This quarter', id:'thisq', fn:()=>{const n=new Date(),y=n.getUTCFullYear(),q=Math.floor(n.getUTCMonth()/3);return{from:new Date(Date.UTC(y,q*3,1)),to:n};} },
{ label:'Last quarter', id:'lastq', fn:()=>{const n=new Date();let q=Math.floor(n.getUTCMonth()/3)-1,y=n.getUTCFullYear();if(q<0){q=3;y--;}return{from:new Date(Date.UTC(y,q*3,1)),to:new Date(Date.UTC(y,q*3+3,0))};} },
{ label:'Last 30 days', id:'l30', fn:()=>{const n=new Date(),f=new Date(n);f.setUTCDate(f.getUTCDate()-30);return{from:f,to:n};} },
{ label:'Last 90 days', id:'l90', fn:()=>{const n=new Date(),f=new Date(n);f.setUTCDate(f.getUTCDate()-90);return{from:f,to:n};} },
];
let activePreset = 'all';
let downloadMode = 'separate';
let results = [];
// ── Storage ───────────────────────────────────────────────────────────────────
function load(){ try{return JSON.parse(localStorage.getItem('mcex2')||'{}');}catch{return{};} }
function save(d){ localStorage.setItem('mcex2', JSON.stringify(d)); }
function getData(){
const d=load();
if(!d.apiKey) d.apiKey='';
if(!d.addresses) d.addresses=[];
if(!d.counterparties) d.counterparties=[];
if(!d.customSeeds) d.customSeeds=[];
// default: all chains enabled
if(!d.enabledChains) d.enabledChains=CHAINS.map(c=>c.id);
return d;
}
// ── API key tab ───────────────────────────────────────────────────────────────
function renderKeyTab(){
const d=getData();
document.getElementById('api-key').value=d.apiKey||'';
renderChainGrid();
}
function toggleKeyVis(){
const i=document.getElementById('api-key');
i.type=i.type==='password'?'text':'password';
}
function saveKey(){
const d=getData();
d.apiKey=document.getElementById('api-key').value.trim();
save(d);
const s=document.getElementById('key-status');
s.textContent=d.apiKey?'saved ✓':'cleared';
s.className=d.apiKey?'status ok':'status';
setTimeout(()=>{s.textContent='';},2000);
}
function renderChainGrid(){
const d=getData();
const enabled=new Set(d.enabledChains||[]);
document.getElementById('chain-grid').innerHTML=CHAINS.map(c=>`
<label class="chain-chip${enabled.has(c.id)?' on':''}" id="chip-${c.id}">
<input type="checkbox" ${enabled.has(c.id)?'checked':''} onchange="toggleChain('${c.id}',this.checked)">
<span class="chain-dot" style="background:${c.color}"></span>
<span class="chain-name">${c.name}</span>
<span class="chain-id-badge">${c.chainId}</span>
</label>
`).join('');
}
function toggleChain(id, on){
const d=getData();
const s=new Set(d.enabledChains||[]);
on ? s.add(id) : s.delete(id);
d.enabledChains=[...s];
save(d);
const chip=document.getElementById('chip-'+id);
if(chip) chip.className='chain-chip'+(on?' on':'');
renderChainScopeSelects();
}
function selectAllChains(on){
const d=getData();
d.enabledChains=on?CHAINS.map(c=>c.id):[];
save(d);
renderChainGrid();
renderChainScopeSelects();
}
// ── Address book ──────────────────────────────────────────────────────────────
function renderAddresses(){
const d=getData();
document.getElementById('addr-list').innerHTML=d.addresses.length ? d.addresses.map((a,i)=>`
<div class="card" style="display:flex;align-items:center;gap:10px">
<div style="flex:1;min-width:0">
<div style="display:flex;align-items:center;gap:8px;margin-bottom:4px">
<span class="label-tag">${esc(a.label)}</span>
<span style="font-size:11px;color:var(--text3)">${scopeLabel(a.scope)}</span>
</div>
<div class="addr-mono">${a.address}</div>
</div>
<button class="btn small danger" onclick="removeAddr(${i})">remove</button>
</div>
`).join('') : '<div class="empty">No addresses yet</div>';
renderExportAddrList();
}
function scopeLabel(scope){
if(scope==='all') return 'all enabled chains';
const c=CHAINS.find(x=>x.id===scope);
return c ? c.name : scope;
}
function renderChainScopeSelects(){
const d=getData();
const enabled=(d.enabledChains||[]).map(id=>CHAINS.find(c=>c.id===id)).filter(Boolean);
const opts='<option value="all">All enabled chains</option>'+enabled.map(c=>`<option value="${c.id}">${c.name}</option>`).join('');
['new-chain-scope','bulk-chain-scope','csv-chain-scope'].forEach(id=>{
const el=document.getElementById(id);
if(el) el.innerHTML=opts;
});
}
function addAddress(){
const addr=document.getElementById('new-addr').value.trim();
const label=document.getElementById('new-label').value.trim();
const scope=document.getElementById('new-chain-scope').value;
if(!addr||!label) return;
const d=getData();
d.addresses.push({address:addr,label,scope});
save(d);
document.getElementById('new-addr').value='';
document.getElementById('new-label').value='';
renderAddresses();
}
function removeAddr(i){
const d=getData();
d.addresses.splice(i,1);
save(d);
renderAddresses();
}
function renderExportAddrList(){
const d=getData();
const el=document.getElementById('export-addr-list');
if(d.addresses.length){
el.innerHTML=d.addresses.map((a,i)=>`
<div class="export-item">
<input type="checkbox" id="exp-cb-${i}" checked style="width:14px;height:14px;flex-shrink:0;accent-color:var(--text)">
<span class="label-tag">${esc(a.label)}</span>
<span class="addr-mono" style="flex:1">${a.address}</span>
<span style="font-size:11px;color:var(--text3);flex-shrink:0">${scopeLabel(a.scope)}</span>
</div>
`).join('');
} else {
el.innerHTML=`
<div class="empty" style="display:flex;flex-direction:column;align-items:center;gap:12px;padding:18px 12px">
<div>No addresses to export yet</div>
<button class="btn small primary" onclick="showTab('addresses')">Go to Address book →</button>
</div>`;
}
updateExportRunBtnState();
}
// Keep the Run button reflective of whether an export is even possible.
// Called whenever the address book or tab visibility changes.
function updateExportRunBtnState(){
const btn=document.getElementById('run-btn');
if(!btn) return;
// Don't clobber transient state set by runExport itself ("Running…", "Fetching…")
if(btn.dataset.running==='1') return;
const d=getData();
if(!d.addresses.length){
btn.disabled=true;
btn.textContent='No addresses to export';
} else {
btn.disabled=false;
btn.textContent='Run export';
}
}
// ── Add sub-tabs ──────────────────────────────────────────────────────────────
function showAddTab(t){
['single','bulk','csv'].forEach(id=>{
const panel=document.getElementById('apanel-'+id);
const tab=document.getElementById('atab-'+id);
if(!panel||!tab) return;
const active=id===t;
panel.style.display=active?'':'none';
tab.style.background=active?'var(--bg)':'';
tab.style.fontWeight=active?'500':'';
tab.style.color=active?'var(--text)':'var(--text2)';
});
}
// ── Bulk paste ────────────────────────────────────────────────────────────────
function importBulk(){
const raw=document.getElementById('bulk-text').value.trim();
const scope=document.getElementById('bulk-chain-scope').value;
const st=document.getElementById('bulk-status');
if(!raw){st.textContent='Nothing to import.';st.style.color='var(--danger-text)';return;}
const lines=raw.split(/\r?\n/).map(l=>l.trim()).filter(Boolean);
const {valid,invalid}=parseBulkLines(lines,scope);
if(!valid.length){st.textContent='No valid addresses found.';st.style.color='var(--danger-text)';return;}
const d=getData();
const existing=new Set(d.addresses.map(a=>a.address.toLowerCase()));
let added=0,skipped=0;
valid.forEach(a=>{
if(existing.has(a.address.toLowerCase())){skipped++;return;}
d.addresses.push(a); existing.add(a.address.toLowerCase()); added++;
});
save(d); renderAddresses();
const parts=[];
if(added) parts.push(`${added} added`);
if(skipped) parts.push(`${skipped} duplicate${skipped>1?'s':''} skipped`);
if(invalid) parts.push(`${invalid} invalid line${invalid>1?'s':''} ignored`);
st.textContent=parts.join(' · ');
st.style.color=added?'var(--success-text)':'var(--text2)';
if(added) document.getElementById('bulk-text').value='';
}
function parseBulkLines(lines, defaultScope){
const valid=[]; let invalid=0;
lines.forEach((line,i)=>{
const parts=line.split(',').map(p=>p.trim());
const addr=parts[0];
if(!isValidAddress(addr)){invalid++;return;}
const label=parts[1]||`Address ${i+1}`;
const chainHint=parts[2]?CHAINS.find(c=>c.id===parts[2].toLowerCase()||c.name.toLowerCase()===parts[2].toLowerCase()):null;
valid.push({address:addr,label,scope:chainHint?chainHint.id:defaultScope});
});
return{valid,invalid};
}
// ── CSV file import ───────────────────────────────────────────────────────────
function onCSVDrop(e){
e.preventDefault();
document.getElementById('csv-drop').style.background='';
const file=e.dataTransfer.files[0];
if(file) processCSVFile(file);
}
function onCSVFile(e){
const file=e.target.files[0];
if(file) processCSVFile(file);
e.target.value='';
}
function processCSVFile(file){
const st=document.getElementById('csv-status');
st.textContent='Reading…'; st.style.color='var(--text2)';
const reader=new FileReader();
reader.onload=ev=>{
try{
const scope=document.getElementById('csv-chain-scope').value;
const result=parseCSVContent(ev.target.result,scope);
if(!result.valid.length){st.textContent='No valid addresses found. Make sure your CSV has an "address" column.';st.style.color='var(--danger-text)';return;}
const d=getData();
const existing=new Set(d.addresses.map(a=>a.address.toLowerCase()));
let added=0,skipped=0;
result.valid.forEach(a=>{
if(existing.has(a.address.toLowerCase())){skipped++;return;}
d.addresses.push(a); existing.add(a.address.toLowerCase()); added++;
});
save(d); renderAddresses();
const parts=[];
if(added) parts.push(`${added} added`);
if(skipped) parts.push(`${skipped} duplicate${skipped>1?'s':''} skipped`);
if(result.invalid) parts.push(`${result.invalid} invalid row${result.invalid>1?'s':''} ignored`);
st.textContent=parts.join(' · ');
st.style.color=added?'var(--success-text)':'var(--text2)';
}catch(e){st.textContent='Error: '+e.message;st.style.color='var(--danger-text)';}
};
reader.readAsText(file);
}
function parseCSVContent(text,defaultScope){
const lines=text.split(/\r?\n/).filter(l=>l.trim());
if(!lines.length) return{valid:[],invalid:0};
const header=splitCSVRow(lines[0]).map(h=>h.trim().toLowerCase().replace(/^"|"$/g,''));
const addrIdx=header.findIndex(h=>['address','wallet','addr'].includes(h));
const labelIdx=header.findIndex(h=>['label','name','tag'].includes(h));
const chainIdx=header.findIndex(h=>['chain','network','scope'].includes(h));
const hasHeader=addrIdx>=0;
const startRow=hasHeader?1:0;
const aIdx=hasHeader?addrIdx:0;
const lIdx=hasHeader?labelIdx:1;
const cIdx=hasHeader?chainIdx:-1;
const valid=[]; let invalid=0;
lines.slice(startRow).forEach((line,i)=>{
if(!line.trim()) return;
const cols=splitCSVRow(line).map(c=>c.trim().replace(/^"|"$/g,''));
const addr=cols[aIdx]||'';
if(!isValidAddress(addr)){invalid++;return;}
const label=(lIdx>=0&&cols[lIdx])||`Row ${startRow+i+1}`;
const chainRaw=cIdx>=0?cols[cIdx]:'';
const chainHint=chainRaw?CHAINS.find(c=>c.id===chainRaw.toLowerCase()||c.name.toLowerCase()===chainRaw.toLowerCase()):null;
valid.push({address:addr,label,scope:chainHint?chainHint.id:defaultScope});
});
return{valid,invalid};
}
function splitCSVRow(line){
const result=[]; let cur='',inQ=false;
for(let i=0;i<line.length;i++){
const ch=line[i];
if(ch==='"'){ if(inQ&&line[i+1]==='"'){cur+='"';i++;}else inQ=!inQ; }
else if(ch===','&&!inQ){ result.push(cur); cur=''; }
else cur+=ch;
}
result.push(cur); return result;
}
function isValidAddress(addr){ return /^0x[0-9a-fA-F]{40}$/.test(addr); }
// ── Presets / date range ──────────────────────────────────────────────────────
function renderPresets(){
document.getElementById('presets-row').innerHTML=PRESETS.map(p=>
`<button class="btn preset${p.id===activePreset?' active':''}" onclick="applyPreset('${p.id}')">${p.label}</button>`
).join('');
}
function applyPreset(id){
activePreset=id;
const {from,to}=PRESETS.find(p=>p.id===id).fn();
document.getElementById('date-from').value=from?toDateInput(from):'';
document.getElementById('date-to').value=to?toDateInput(to):'';
renderPresets(); updateRangeSummary();
}
function onDateChange(){ activePreset=null; renderPresets(); updateRangeSummary(); }
function updateRangeSummary(){
const f=document.getElementById('date-from').value;
const t=document.getElementById('date-to').value;
const el=document.getElementById('range-summary');
if(!f&&!t){el.textContent='Fetching all available history';return;}
if(f&&t){const days=Math.round((new Date(t+'T00:00:00Z')-new Date(f+'T00:00:00Z'))/86400000)+1;el.textContent=`${days.toLocaleString()} day${days!==1?'s':''} selected · UTC, end-of-day inclusive`;return;}
el.textContent=(f?`From ${f} onwards`:`Up to ${t}`)+' · UTC';
}
function getBlockRange(){
// Use UTC explicitly on both boundaries so block resolution matches what
// Etherscan's explorer shows. Without the trailing Z, the end timestamp
// would be parsed in the user's local timezone — wrong for accounting.
const f=document.getElementById('date-from').value;
const t=document.getElementById('date-to').value;
return{
startTs: f ? toUnix(new Date(f+'T00:00:00Z')) : null,
endTs: t ? toUnix(new Date(t+'T23:59:59Z')) : null,
};
}
function toDateInput(d){ return d?d.toISOString().slice(0,10):''; }
function toUnix(d){ return Math.floor(d.getTime()/1000); }
// ── Download mode ─────────────────────────────────────────────────────────────
function selectMode(m){
downloadMode=m;
document.querySelectorAll('.mode-card').forEach(el=>el.classList.toggle('selected',el.dataset.mode===m));
}
// ── Tab routing ───────────────────────────────────────────────────────────────
function showTab(t){
['keys','addresses','counterparties','export','snapshots'].forEach(id=>{
document.getElementById('tab-'+id).style.display=id===t?'':'none';
});
document.querySelectorAll('.tab').forEach((el,i)=>{
el.classList.toggle('active',['keys','addresses','counterparties','export','snapshots'][i]===t);
});
if(t==='export'){ renderExportAddrList(); updateExportCpStatus(); }
if(t==='snapshots') renderSnapAddrList();
if(t==='counterparties') renderCounterparties();
}
// ── Counterparties ────────────────────────────────────────────────────────────
// A flat address→label map for joining onto export rows. Distinct from the
// address book (which is "wallets I own and want to export"). Counterparties
// are typically: CEX deposit addresses, friends' wallets, contract addresses
// (Uniswap router, Aave pool), etc.
function renderCounterparties(){
const d=getData();
const list=d.counterparties||[];
document.getElementById('cp-count').textContent=list.length;
const el=document.getElementById('cp-list');
if(!list.length){ el.innerHTML='<div class="empty">No counterparties yet</div>'; }
else {
// Show newest first so recent additions are visible without scrolling
el.innerHTML=list.slice().reverse().map((cp)=>{
const realIdx=list.indexOf(cp);
const cat=cp.category||'Other';
return `
<div class="card" style="display:flex;align-items:center;gap:10px">
<div style="flex:1;min-width:0">
<div style="display:flex;align-items:center;gap:8px;margin-bottom:4px;flex-wrap:wrap">
<span class="label-tag">${esc(cp.label)}</span>
<span style="font-size:11px;color:var(--text3);background:var(--bg2);padding:1px 7px;border-radius:999px">${esc(cat)}</span>
</div>
<div class="addr-mono">${cp.address}</div>
</div>
<button class="btn small danger" onclick="removeCounterparty(${realIdx})">remove</button>
</div>`;
}).join('');
}
// Refresh dependent UIs
renderCpCategorySelects();
renderSeedList();
updateExportCpStatus();
}
// Populate every <select> that lists CATEGORIES. Re-rendered on demand because
// some panels are display:none on first paint and innerHTML on hidden elements
// is harmless but worth re-running when the panel becomes visible.
function renderCpCategorySelects(){
const opts=CATEGORIES.map(c=>`<option value="${esc(c)}">${esc(c)}</option>`).join('');
['cp-new-category','cp-bulk-fallback-category','cp-csv-fallback-category','cs-category'].forEach(id=>{
const el=document.getElementById(id);
if(!el) return;
const prev=el.value;
el.innerHTML=opts;
// Default to "Other" for the single-add field; "Token Contract" feels
// like a sensible fallback for bulk/CSV (most dumps from explorers are tokens)
const fallback = id==='cp-new-category' ? 'Other' : 'Other';
el.value = (prev && CATEGORIES.includes(prev)) ? prev : fallback;
});
}
// ── Common-contracts seed panel ──────────────────────────────────────────────
// Combined list of built-in seeds + user-added custom seeds. Each entry gets
// a stable index based on its position in the combined list, used for the
// checkbox id. Custom entries are tagged with `_custom=true` so the renderer
// can show a remove button.
function getAllSeeds(){
const d=getData();
const builtins = SEED_CONTRACTS.map(s => ({...s, _custom:false}));
const custom = (d.customSeeds || []).map(s => ({...s, _custom:true}));
return [...builtins, ...custom].map((s,i) => ({...s, _idx:i}));
}
function renderSeedList(){
const el=document.getElementById('cp-seed-list');
if(!el) return;
const d=getData();
const saved=new Set((d.counterparties||[]).map(c=>c.address.toLowerCase()));
const all=getAllSeeds();
if(!all.length){ el.innerHTML='<div class="empty" style="padding:12px">No contracts yet — click "+ Add custom" to add one</div>'; return; }
// Group by category for readability. CATEGORIES order is preserved.
const byCat=new Map();
CATEGORIES.forEach(c=>byCat.set(c,[]));
all.forEach(s=>{
const cat=byCat.has(s.category)?s.category:'Other';
byCat.get(cat).push(s);
});
let html='';
byCat.forEach((items,cat)=>{
if(!items.length) return;
html+=`<div style="font-size:11px;font-weight:500;color:var(--text3);text-transform:uppercase;letter-spacing:0.05em;padding:8px 0 4px">${esc(cat)} <span style="color:var(--text3);font-weight:400">(${items.length})</span></div>`;
items.forEach(s=>{
const isSaved=saved.has(s.address.toLowerCase());
const customTag = s._custom
? `<span style="font-size:10px;color:var(--info-text);background:var(--info-bg);padding:1px 6px;border-radius:999px;flex-shrink:0">custom</span>`
: '';