Repository navigation
Expand file tree
/
Copy pathMulti_CIP_Simulator.html
More file actions
2296 lines (2150 loc) · 111 KB
/
Copy pathMulti_CIP_Simulator.html
File metadata and controls
2296 lines (2150 loc) · 111 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">
<title>Multi-CIP Simulator — Closing the Multipool Parameter Space</title>
<!--
To experiment with this live calculator go to the following webpage.
https://johnshearing.github.io/pool_ranger/Multi_CIP_Simulator.html
-->
<!--
Multi-CIP Simulator (Field / MRI mode).
A companion to the single-pool CIP-187 simulator
(CIP_UTILIZATION_SCALED_PLEDGE_BONUS.html). Where that tool examines ONE pool at
a time, this one renders the WHOLE parameter cube as a 3-D scalar field so the
*shape* of the region where multipool operation pays can be seen — and watched as
each CIP slider reshapes it.
Axes: X = Pledge P Y = Margin m Z = Delegation D (= total stake − pledge)
Color: a selectable output metric (default: the gain an operator makes by splitting
into N pools instead of running one — the region we are trying to close).
Levers (each maps to a CIP family from Multi_CIP_Plan.md §5.6):
• minPoolCost (fee F) — CIPs 23 / 74 / 75 (fee reform)
• L (leverage cap) — CIP-50 (σ' = min(σ, L·p))
• b (utilization blend) — CIP-187 (A_blend = A·(1 − b + b·u))
No real pool data is used: the grid is synthetic. Plotly.js (CDN) renders three
volume techniques — isosurface, semi-transparent volume fog, and a swept MRI slice.
Reward math is lifted verbatim from CIP_UTILIZATION_SCALED_PLEDGE_BONUS.html and
extended with the CIP-50 leverage cap.
-->
<script src="https://cdn.plot.ly/plotly-2.35.2.min.js" charset="utf-8"></script>
<style>
:root {
--bg: #0e1117;
--panel: #161b22;
--panel2: #1c2330;
--border: #2b333f;
--text: #d6dde6;
--muted: #8b97a7;
--accent: #ff9f43; /* CIP-187 / pledge orange */
--teal: #4ecdc4; /* proposed / good */
--red: #ff6b6b; /* MPO-wins / bad */
--blue: #5b8def;
}
* { box-sizing: border-box; }
html, body {
margin: 0; padding: 0;
background: var(--bg); color: var(--text);
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
font-size: 14px;
}
header {
padding: 0.8rem 1.1rem 0.5rem;
border-bottom: 1px solid var(--border);
}
header h1 { margin: 0 0 0.2rem; font-size: 1.15rem; }
header p { margin: 0; color: var(--muted); font-size: 0.82rem; max-width: 70ch; }
header a { color: var(--accent); }
#layout { display: flex; height: calc(100vh - 64px); min-height: 540px; }
#controls {
width: 340px; flex: 0 0 340px;
overflow-y: auto;
padding: 0.8rem 0.9rem 2rem;
border-right: 1px solid var(--border);
background: var(--panel);
}
#plotwrap { flex: 1 1 auto; position: relative; min-width: 0; }
#plot { width: 100%; height: 100%; }
.group {
background: var(--panel2);
border: 1px solid var(--border);
border-radius: 8px;
padding: 0.6rem 0.7rem;
margin-bottom: 0.7rem;
}
.group h3 {
margin: 0 0 0.5rem; font-size: 0.8rem; letter-spacing: 0.02em;
text-transform: uppercase; color: var(--muted);
}
.ctl { margin-bottom: 0.55rem; }
.ctl:last-child { margin-bottom: 0; }
.ctl label {
display: flex; justify-content: space-between; align-items: baseline;
font-size: 0.82rem; margin-bottom: 0.2rem;
}
.ctl label .val { color: var(--accent); font-variant-numeric: tabular-nums; font-weight: 600; }
input[type=range] { width: 100%; accent-color: var(--accent); cursor: pointer; }
select, button {
width: 100%; padding: 0.35rem 0.4rem;
background: var(--panel); color: var(--text);
border: 1px solid var(--border); border-radius: 6px;
font-size: 0.82rem; cursor: pointer;
}
/* Color-metric dropdown wears the same orange border as the "mission" button, so the
control that sets the question the colours answer reads as the page's focal point. */
#grp-metric select { border: 1px solid var(--accent); }
.cipline {
display: flex; align-items: center; gap: 0.5rem; margin-bottom: 0.3rem;
}
.cipline input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--teal); cursor: pointer; }
.cipline label { font-size: 0.83rem; font-weight: 600; cursor: pointer; flex: 1; }
.cip-on { color: var(--teal); }
.cip-off { color: var(--muted); }
.disabled { opacity: 0.4; pointer-events: none; }
.modebtns { display: flex; gap: 0.3rem; }
.modebtns button { flex: 1; padding: 0.4rem 0.2rem; font-size: 0.78rem; }
.modebtns button.active { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 700; }
.presets { display: grid; grid-template-columns: 1fr 1fr; gap: 0.3rem; }
.presets button { font-size: 0.74rem; padding: 0.4rem 0.2rem; }
.presets button.active { background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 700; }
#readout {
font-size: 0.78rem; color: var(--muted); line-height: 1.5;
background: var(--panel2); border: 1px solid var(--border);
border-radius: 8px; padding: 0.55rem 0.7rem;
}
#readout b { color: var(--text); }
#readout .hot { color: var(--red); }
#readout .cool { color: var(--teal); }
.hint { font-size: 0.72rem; color: var(--muted); margin-top: 0.3rem; line-height: 1.4; }
code { color: var(--accent); font-size: 0.92em; }
/* Field-view buttons: light the ACTIVE shell mode (single shell ↔ nested shells) so the
viewer can always tell which is showing, mirroring the render-mode buttons above. */
#btn-snap.active, #btn-shells.active {
background: var(--accent); color: #1a1205; border-color: var(--accent); font-weight: 700;
}
/* Physical-button press feedback. :active covers a click held by the mouse; the .pressed class
is added briefly from JS so even a fast — or scripted — click visibly depresses the button,
the way a real key bottoms out. */
#wrap-iso button:active,
#btn-save-surf.pressed, #btn-clear-surf.pressed {
transform: translateY(1px);
box-shadow: inset 0 2px 6px rgba(0,0,0,0.55);
}
/* ── Donations card (mirrors SPO_REWARD_ANALYSIS_CHART.html, themed teal) ─────── */
#donate-panel {
border: 2px dashed var(--teal);
background: linear-gradient(180deg, rgba(255,159,67,0.07) 0%, var(--panel2) 100%);
}
#donate-panel h3 a { color: var(--teal); text-decoration: underline; }
#donate-panel .donate-note { font-size: 0.74rem; color: var(--muted); line-height: 1.45; margin: 0 0 0.5rem; }
#donate-panel .donate-note ul { margin: 0; padding-left: 1.1rem; }
#donate-panel .donate-address {
display: block; font-family: monospace; font-size: 0.72rem;
color: var(--teal); background: var(--bg);
border: 1px dashed var(--teal); border-radius: 4px;
padding: 0.55rem 0.6rem; word-break: break-all; text-align: center;
}
/* ── Guided tutorial: launcher, dim, card, arrows ─────────────────────────── */
#tour-launcher button { margin-bottom: 0.4rem; text-align: left; font-weight: 700; line-height: 1.3; }
#tour-launcher .hint { margin-top: 0.45rem; }
.tour-launch-1 { background: var(--accent) !important; color: #1a1205 !important; border-color: var(--accent) !important; }
.tour-launch-2 { background: #233244 !important; color: var(--text) !important; border: 1px solid var(--accent) !important; }
#tour-launcher button:hover { opacity: 0.88; }
/* The cube is the whole point of the walkthrough, so we no longer darken it (or
the slider panel). The overlay is kept transparent — purely a stacking layer —
so the arrows and card still sit cleanly above the page. Give it a faint dim
again by setting e.g. background: rgba(0,0,0,0.30) if focus is ever wanted. */
#tour-dim {
position: fixed; inset: 0; background: transparent;
z-index: 9000; pointer-events: none; opacity: 0; transition: opacity 0.2s;
}
#tour-dim.shown { opacity: 1; }
#tour-arrow-layer { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 9100; pointer-events: none; }
#tour-card {
position: fixed; bottom: 1.2rem; right: 1.2rem;
width: clamp(320px, 28vw, 440px);
background: var(--panel2); border: 1px solid var(--accent);
border-radius: 10px; padding: 1rem 1.2rem 0.9rem; z-index: 9200;
box-shadow: 0 10px 30px rgba(0,0,0,0.6), 0 0 0 1px rgba(255,159,67,0.18);
font-size: 0.86rem; line-height: 1.5; color: var(--text);
}
.tour-step-counter { font-size: 0.66rem; text-transform: uppercase; letter-spacing: 0.1em; color: var(--muted); margin-bottom: 0.45rem; cursor: move; user-select: none;
display: inline-block; background: var(--panel); border: 1px solid var(--border); border-radius: 5px; padding: 0.2rem 0.5rem; }
#tour-title { font-size: 1.0rem; color: var(--accent); margin-bottom: 0.5rem; font-weight: 700; cursor: move; user-select: none;
background: var(--panel); border: 1px solid var(--border); border-radius: 6px; padding: 0.35rem 0.6rem; transition: border-color 0.15s, background 0.15s; }
.tour-step-counter:hover, #tour-title:hover { border-color: var(--accent); background: var(--bg); }
#tour-title::before { content: "⠿ "; color: var(--accent); font-weight: 400; }
#tour-title::after { content: " ⠿"; color: var(--muted); font-weight: 400; }
#tour-card.dragging { box-shadow: 0 14px 40px rgba(0,0,0,0.75), 0 0 0 1px rgba(255,159,67,0.4); }
#tour-body strong { color: var(--accent); }
#tour-body em { color: var(--teal); font-style: normal; font-weight: 600; }
#tour-body .bad { color: var(--red); font-weight: 700; }
#tour-body .good { color: var(--teal); font-weight: 700; }
/* Viridis colour language for both tutorials: the live colour scale runs from dark deep-purple
(low value) up to bright yellow (high value). So "hot" = the bright yellow splitting-pays zone
we want to close, and "cool" = the dark region where one honest pool already wins. The older
red/blue .bad/.good classes are retained only in case some legacy copy still references them;
both walkthroughs now speak Viridis. */
#tour-body .hot { color: #f2e23c; font-weight: 700; }
#tour-body .cool { color: #9aa6d8; font-weight: 700; }
#tour-body code { color: var(--accent); }
#tour-body p { margin: 0 0 0.55rem; }
#tour-body p:last-child { margin-bottom: 0; }
.tour-controls { display: flex; gap: 0.45rem; flex-wrap: wrap; margin-top: 0.85rem; padding-top: 0.7rem; border-top: 1px solid var(--border); }
.tour-controls button { width: auto; background: transparent; border: 1px solid var(--border); border-radius: 6px; color: var(--text); cursor: pointer; font-size: 0.76rem; font-weight: 600; padding: 0.4rem 0.7rem; }
.tour-controls button:hover { border-color: var(--accent); }
.tour-controls button:disabled { opacity: 0.35; cursor: default; }
#tour-autoplay { background: var(--accent); color: #1a1205; border-color: var(--accent); }
#tour-autoplay.playing { background: var(--teal); border-color: var(--teal); color: #06201d; }
#tour-exit { margin-left: auto; }
@keyframes tour-pulse {
0% { box-shadow: 0 0 0 0 rgba(78,205,196,0.65); }
70% { box-shadow: 0 0 0 12px rgba(78,205,196,0); }
100% { box-shadow: 0 0 0 0 rgba(78,205,196,0); }
}
.tour-pulse { outline: 2px solid var(--teal) !important; outline-offset: 3px; border-radius: 6px; animation: tour-pulse 1.4s ease-out infinite; position: relative; z-index: 9050; }
/* Spotlight: lift a control (a whole group or one slider) above the dim sheet and
force it to full opacity even when it's a greyed-out, switched-off CIP slider —
keeps the left panel and the fee slider bright while a card explains them. No
outline, so the arrow's own pulse stays the single visual focus. */
.tour-spotlight { position: relative; z-index: 9050; opacity: 1 !important; }
@media (max-width: 760px) { #tour-card { left: 0.6rem; right: 0.6rem; width: auto; bottom: 0.6rem; } }
</style>
</head>
<body>
<header>
<h1>Multi-CIP Simulator — the parameter cube where multipools live</h1>
<p>
The whole <b>(pledge × margin × delegation)</b> cube, colored by an output metric.
Move the three CIP levers and watch the region where splitting into many pools pays
(the <span style="color:var(--red)">red</span> habitable zone) shrink. Synthetic grid —
no pool data. Companion to the
<a href="CIP_UTILIZATION_SCALED_PLEDGE_BONUS.html">single-pool CIP-187 simulator</a>.
</p>
</header>
<div id="layout">
<div id="controls">
<div class="group" id="tour-launcher">
<h3>Guided tutorials</h3>
<button class="tour-launch-1" id="tour-btn-tour">▶ Start here — the cube & every control</button>
<button class="tour-launch-2" id="tour-btn-thesis">▶ The mission — close the multipool zones</button>
<div class="hint">Cards appear on screen and arrows point at the control being explained; some
sliders move by themselves. Click <b>▶ Play</b> in a card to run it hands-free, or press
<b>Esc</b> to leave the tour.</div>
</div>
<div class="group" id="grp-mode">
<h3>Render mode</h3>
<div class="modebtns" id="modebtns">
<button data-mode="volume" class="active">Volume fog</button>
<button data-mode="isosurface">Isosurface</button>
<button data-mode="slice">MRI slice</button>
</div>
<div class="hint" id="mode-hint">
Semi-transparent fog: opacity follows the metric, so dense color marks where the
metric is large. Best first look at the field's shape.
</div>
</div>
<div class="group" id="grp-field">
<h3>Field view</h3>
<div class="ctl" id="wrap-iso">
<label>Isosurface level <span class="val" id="v-iso">—</span></label>
<input type="range" id="sl-iso" min="0" max="100" step="1" value="50">
<div style="display:flex;gap:0.3rem;margin-top:0.3rem">
<button id="btn-snap" style="font-size:0.74rem">Snap to pivot (0 / 1)</button>
<button id="btn-shells" style="font-size:0.74rem">Nested shells</button>
</div>
<div style="display:flex;gap:0.3rem;margin-top:0.3rem">
<button id="btn-hidesat" style="font-size:0.74rem">Hide above saturation</button>
</div>
<div style="display:flex;gap:0.3rem;margin-top:0.3rem">
<button id="btn-save-surf" style="font-size:0.74rem">+ Save surface</button>
<button id="btn-clear-surf" style="font-size:0.74rem">Clear saved</button>
</div>
<div class="hint">Saturation = 75M ADA of combined pledge + delegation (P + D). Hiding it
blanks every voxel beyond that line so only sub-saturation pools are drawn.</div>
<div class="hint"><b>Save surface</b> freezes the shell now on screen in its own colour so you
can move the sliders or pick another metric and lay a new surface beside it — many surfaces at
once tell a story one can't. <b>Clear saved</b> removes them, leaving only the live surface.</div>
</div>
<div class="ctl" id="wrap-slice" style="display:none">
<label>Slice axis</label>
<select id="slice-axis">
<option value="z" selected>Delegation (horizontal plane)</option>
<option value="x">Pledge</option>
<option value="y">Margin</option>
</select>
<label style="margin-top:0.4rem">Slice position <span class="val" id="v-slicepos">50%</span></label>
<input type="range" id="sl-slicepos" min="0" max="100" step="2" value="50">
<div style="display:flex;gap:0.3rem;margin-top:0.3rem">
<button id="btn-sweep" style="font-size:0.74rem">▶ Sweep</button>
</div>
</div>
<div class="ctl">
<label>Grid resolution <span class="val" id="v-res">32</span></label>
<input type="range" id="sl-res" min="12" max="48" step="2" value="32">
</div>
</div>
<div class="group" id="grp-metric">
<h3>Color metric</h3>
<div class="ctl">
<select id="metric">
<option value="advantage">Splitting advantage — N-pool take − 1-pool take (ADA/epoch)</option>
<option value="advratio" selected>Splitting advantage — ratio (N-pool ÷ 1-pool)</option>
<option value="mpo">MPO combined take — all N pools (ADA/epoch)</option>
<option value="single">Single-pool operator take (ADA/epoch)</option>
<option value="roa">Delegator ROA (%/yr)</option>
<option value="fee">Operator fixed-fee income (ADA/epoch)</option>
<option value="margin">Operator margin income (ADA/epoch)</option>
<option value="pledgeinc">Operator pledge income (ADA/epoch)</option>
</select>
</div>
<div class="hint" id="metric-hint"></div>
</div>
<div class="group" id="grp-presets">
<h3>Scenario presets</h3>
<div class="presets">
<button data-preset="baseline" id="pre-baseline">Baseline (no CIP)</button>
<button data-preset="fee" id="pre-fee">Fee reform only</button>
<button data-preset="c50" id="pre-c50">CIP-50 only</button>
<button data-preset="c187" id="pre-c187">CIP-187 only</button>
<button data-preset="all" id="pre-all" style="grid-column:1/3">All three families</button>
</div>
</div>
<div class="group" id="grp-cip">
<h3>CIP levers</h3>
<div class="cipline">
<label class="cip-off" id="lbl-fee">Fee reform — CIPs 23/74/75</label>
</div>
<div class="ctl disabled" id="wrap-F">
<label>minPoolCost <code>F</code> (ADA/epoch) <span class="val" id="v-F">340</span></label>
<input type="range" id="sl-F" min="0" max="1000" step="5" value="340">
</div>
<div class="cipline">
<label class="cip-off" id="lbl-50">Leverage cap — CIP-50</label>
</div>
<div class="ctl disabled" id="wrap-L">
<label>L <span style="color:var(--muted);font-weight:400">σ′ = min(σ, L·p)</span> <span class="val" id="v-L">0</span></label>
<input type="range" id="sl-L" min="0" max="1000" step="10" value="0">
</div>
<div class="cipline">
<label class="cip-off" id="lbl-187">Utilization-scaled pledge bonus — CIP-187</label>
</div>
<div class="ctl disabled" id="wrap-b">
<label>b <span style="color:var(--muted);font-weight:400">A·(1−b+b·u)</span> <span class="val" id="v-b">0.00</span></label>
<input type="range" id="sl-b" min="0" max="1" step="0.01" value="0">
</div>
</div>
<div class="group" id="grp-strategy">
<h3>Operator strategy & protocol</h3>
<div class="ctl">
<label>Multipool count <code>N</code> <span class="val" id="v-N">5</span></label>
<input type="range" id="sl-N" min="1" max="10" step="1" value="5">
</div>
<div class="ctl">
<label>Base reward rate <code>r</code> <span class="val" id="v-r">0.000400</span></label>
<input type="range" id="sl-r" min="0.0003" max="0.0008" step="0.000005" value="0.000400">
</div>
<div class="ctl">
<label>Pledge influence <code>a₀</code> <span class="val" id="v-a0">0.30</span></label>
<input type="range" id="sl-a0" min="0" max="2" step="0.05" value="0.30">
</div>
</div>
<div id="readout">Recomputing…</div>
<div class="group" id="donate-panel">
<h3><a href="https://github.com/johnshearing/pool_ranger/blob/main/WHY_SUPPORT_POOL_RANGER.md"
target="_blank" rel="noopener noreferrer">Why donating to Pool Ranger has a positive expected return</a></h3>
<div class="donate-note">
<ul>
<li>How the free tools already pay back your donation.</li>
<li>Why the on-chain 99/1 split keeps paying you back after launch.</li>
<li>Why open-sourcing the code permanently caps Pool Ranger's fees.</li>
</ul>
</div>
<code class="donate-address" id="donate-address">addr1q9m7zdhxm7ecp560nyl7rnl2xstajnx0s96ppwfcv0upawzwfv6fkds3r7tagww4hq5ruz49jknfjaz5ujdch3gyng5qkhxd5v</code>
</div>
</div>
<div id="plotwrap">
<div id="plot"></div>
</div>
</div>
<script>
"use strict";
// ─────────────────────────────────────────────────────────────────────────────
// Constants
// ─────────────────────────────────────────────────────────────────────────────
const S_SAT = 75e6; // saturation point (ADA)
const EPOCHS_PER_YR = 73;
// ─────────────────────────────────────────────────────────────────────────────
// Reward math (lifted from CIP_UTILIZATION_SCALED_PLEDGE_BONUS.html, then
// extended with the CIP-50 leverage cap)
// ─────────────────────────────────────────────────────────────────────────────
// Blended utilization factor for CIP-187: at b=0 → 1 (current formula),
// at b=1 → u = min(S,S_sat)/S_sat. (1 − b + b·u).
function utilFactor(S, b) {
const u = Math.min(S, S_SAT) / S_SAT;
return (1 - b) + b * u;
}
// Gross pool rewards for ONE pool of total stake S and pledge P.
// • CIP-50 caps the rewardable stake at L·P (σ' = min(σ, L·p)).
// • CIP-187 multiplies only the a₀·P pledge term by the utilization factor.
function gross(S, P, cfg) {
const sSat = Math.min(S, S_SAT);
const sReward = cfg.cip50 ? Math.min(sSat, cfg.L * P) : sSat;
const pledgeTerm = cfg.a0 * P * (cfg.cip187 ? utilFactor(S, cfg.b) : 1);
return cfg.r * (sReward + pledgeTerm) / (1 + cfg.a0);
}
// Operator take for one pool: fixed fee + margin on net + pledge's share of net.
function spoIncome(S, P, m, cfg) {
if (S <= 0) return 0;
const F = cfg.cipFee ? cfg.F : 340; // fee charged = minPoolCost lever
const g = gross(S, P, cfg);
if (g <= F) return g; // can't extract more fee than the pool earns
const net = g - F;
return F + m * net + (P / S) * (1 - m) * net;
}
function delegROA(S, P, m, cfg) {
if (S <= 0) return 0;
const F = cfg.cipFee ? cfg.F : 340;
const g = gross(S, P, cfg);
if (g <= F) return 0;
return (1 - m) * (g - F) / S * EPOCHS_PER_YR * 100;
}
// Operator income broken into channels (single pool).
function feeIncome(S, P, m, cfg) {
const F = cfg.cipFee ? cfg.F : 340;
return Math.min(F, gross(S, P, cfg));
}
function marginIncome(S, P, m, cfg) {
const F = cfg.cipFee ? cfg.F : 340;
const g = gross(S, P, cfg);
if (g <= F) return 0;
return m * (g - F);
}
function pledgeIncome(S, P, m, cfg) {
const F = cfg.cipFee ? cfg.F : 340;
const g = gross(S, P, cfg);
if (g <= F) return 0;
return (P / S) * (1 - m) * (g - F);
}
// Combined take if the operator splits aggregate (P,D) into N identical pools,
// each holding P/N pledge and D/N delegation. Fee is charged once PER POOL.
function mpoCombined(P, D, m, cfg) {
const N = cfg.N;
const Pi = P / N, Di = D / N, Si = Pi + Di;
return N * spoIncome(Si, Pi, m, cfg);
}
// ─────────────────────────────────────────────────────────────────────────────
// Metric dispatch. (P, D in ADA; m in fraction.)
// ─────────────────────────────────────────────────────────────────────────────
const METRICS = {
advantage: {
label: 'Splitting advantage (ADA/epoch)',
colorscale: 'Viridis',
fn: (P, D, m, cfg) => mpoCombined(P, D, m, cfg) - spoIncome(P + D, P, m, cfg),
hint: 'How many extra ADA per epoch the operator earns by splitting into N pools '
+ 'instead of running one. Brighter (yellow) = a larger splitting advantage — the '
+ 'region to close. Dark = a single pool is as good or better.'
},
advratio: {
label: 'Splitting advantage (ratio)',
colorscale: 'Viridis', clamp: [0, 3],
fn: (P, D, m, cfg) => {
const single = spoIncome(P + D, P, m, cfg);
const comb = mpoCombined(P, D, m, cfg);
if (single < 1) return comb < 1 ? 1 : 3;
return Math.min(comb / single, 3);
},
hint: 'N-pool take ÷ 1-pool take, capped at 3×. Brighter = splitting pays more; '
+ 'dark = neutral or a single pool wins.'
},
mpo: {
label: 'MPO combined take (ADA/epoch)',
colorscale: 'Viridis',
fn: (P, D, m, cfg) => mpoCombined(P, D, m, cfg),
hint: 'Total operator income across all N pools. The high-value region is what each CIP family aims to shrink.'
},
single: {
label: 'Single-pool take (ADA/epoch)',
colorscale: 'Viridis',
fn: (P, D, m, cfg) => spoIncome(P + D, P, m, cfg),
hint: 'Operator income running ONE honest pool at the aggregate (P, D). We want this to dominate the multipool take.'
},
roa: {
label: 'Delegator ROA (%/yr)',
colorscale: 'Viridis',
fn: (P, D, m, cfg) => delegROA(P + D, P, m, cfg),
hint: 'Annualized return for delegators in a single pool. Bright = where delegator participation is most rewarded.'
},
fee: {
label: 'Operator fixed-fee income (ADA/epoch)',
colorscale: 'Viridis',
fn: (P, D, m, cfg) => feeIncome(P + D, P, m, cfg),
hint: 'The minPoolCost fee actually extracted (capped by what the pool earns). The fee-farm revenue stream.'
},
margin: {
label: 'Operator margin income (ADA/epoch)',
colorscale: 'Viridis',
fn: (P, D, m, cfg) => marginIncome(P + D, P, m, cfg),
hint: 'Income from the percentage margin on net rewards.'
},
pledgeinc: {
label: 'Operator pledge income (ADA/epoch)',
colorscale: 'Viridis',
fn: (P, D, m, cfg) => pledgeIncome(P + D, P, m, cfg),
hint: "The operator's own pledge share of net rewards — what CIP-187 scales by utilization."
}
};
// ─────────────────────────────────────────────────────────────────────────────
// Read controls into a config object
// ─────────────────────────────────────────────────────────────────────────────
const $ = id => document.getElementById(id);
let renderMode = 'volume';
let showShells = false;
// When true, the isosurface view blanks every grid point whose combined pledge +
// delegation exceeds saturation (S_SAT), so only sub-saturation pools are imaged.
let hideAboveSat = false;
// Isosurface level is tracked as an ABSOLUTE metric value (not a slider %) so that
// switching presets — which rescales the field — keeps the shell at the same value
// for comparison. Switching metric resets it (the units change). See render().
let isoLevel = null, isoMetric = null;
// Saved isosurfaces: frozen snapshots layered in the cube for comparison. Each entry is
// { trace, color, label } — the trace is a recoloured copy of whatever was live when the
// user clicked "Save surface", so moving the sliders afterwards never disturbs it. Only
// drawn in isosurface mode; switching render mode hides them but keeps them for later.
const SAVED_COLORS = ['#4ecdc4', '#ff6b6b', '#5b8def', '#ff9f43', '#b07cff', '#ffe066'];
const MAX_SAVED = 6;
let savedSurfaces = [];
let lastLiveIso = null; // the live isosurface trace from the most recent render()
let lastIsoDesc = ''; // a human label describing the field that produced it
// Which CIP families are active is now driven entirely by the scenario presets
// (the per-lever checkboxes were removed). A disabled/greyed slider == inactive CIP.
let cipState = { fee: false, c50: false, c187: false };
function readCfg() {
return {
cipFee : cipState.fee,
cip50 : cipState.c50,
cip187 : cipState.c187,
F : parseFloat($('sl-F').value),
L : parseFloat($('sl-L').value),
b : parseFloat($('sl-b').value),
N : parseInt($('sl-N').value, 10),
r : parseFloat($('sl-r').value),
a0 : parseFloat($('sl-a0').value),
res : parseInt($('sl-res').value, 10),
pmax : 75e6, // fixed reference box: pledge 0–75M ADA
mmax : 1.0, // fixed reference box: margin 0–100%
dmax : 75e6, // fixed reference box: delegation 0–75M ADA
metric : $('metric').value,
iso : parseFloat($('sl-iso').value) / 100,
sliceAxis: $('slice-axis').value,
slicePos : parseFloat($('sl-slicepos').value) / 100
};
}
// linspace helper
function lin(a, b, n) {
const out = new Array(n);
for (let i = 0; i < n; i++) out[i] = a + (b - a) * i / (n - 1);
return out;
}
// ─────────────────────────────────────────────────────────────────────────────
// Build the 3-D grid (for volume & isosurface)
// ─────────────────────────────────────────────────────────────────────────────
function buildGrid(cfg) {
const m = METRICS[cfg.metric];
const n = cfg.res;
const Pvals = lin(0, cfg.pmax, n); // ADA
const Mvals = lin(0, cfg.mmax, n); // fraction
const Dvals = lin(0, cfg.dmax, n); // ADA
const x = [], y = [], z = [], value = [];
let vmin = Infinity, vmax = -Infinity;
for (let k = 0; k < n; k++) { // delegation (Z)
for (let j = 0; j < n; j++) { // margin (Y)
for (let i = 0; i < n; i++) { // pledge (X)
const P = Pvals[i], mm = Mvals[j], D = Dvals[k];
let v = m.fn(P, D, mm, cfg);
if (!isFinite(v)) v = 0;
x.push(P / 1e6);
y.push(mm * 100);
z.push(D / 1e6);
value.push(v);
if (v < vmin) vmin = v;
if (v > vmax) vmax = v;
}
}
}
return { x, y, z, value, vmin, vmax, Pvals, Mvals, Dvals };
}
// Build a single oriented MRI plane perpendicular to one axis.
function buildSlice(cfg) {
const m = METRICS[cfg.metric];
const n = Math.max(cfg.res, 30);
const Pvals = lin(0, cfg.pmax, n);
const Mvals = lin(0, cfg.mmax, n);
const Dvals = lin(0, cfg.dmax, n);
const xs = [], ys = [], zs = [], cs = []; // 2-D arrays for surface
let vmin = Infinity, vmax = -Infinity;
// The two free axes (a, b) vary; the sliced axis is held at pos.
if (cfg.sliceAxis === 'z') { // horizontal plane, vary P & m
const D = cfg.dmax * cfg.slicePos;
for (let j = 0; j < n; j++) { // rows = margin
const rx = [], ry = [], rz = [], rc = [];
for (let i = 0; i < n; i++) { // cols = pledge
const v = clean(m.fn(Pvals[i], D, Mvals[j], cfg));
rx.push(Pvals[i] / 1e6); ry.push(Mvals[j] * 100); rz.push(D / 1e6); rc.push(v);
vmin = Math.min(vmin, v); vmax = Math.max(vmax, v);
}
xs.push(rx); ys.push(ry); zs.push(rz); cs.push(rc);
}
} else if (cfg.sliceAxis === 'x') { // plane at fixed pledge, vary m & D
const P = cfg.pmax * cfg.slicePos;
for (let k = 0; k < n; k++) { // rows = delegation
const rx = [], ry = [], rz = [], rc = [];
for (let j = 0; j < n; j++) { // cols = margin
const v = clean(m.fn(P, Dvals[k], Mvals[j], cfg));
rx.push(P / 1e6); ry.push(Mvals[j] * 100); rz.push(Dvals[k] / 1e6); rc.push(v);
vmin = Math.min(vmin, v); vmax = Math.max(vmax, v);
}
xs.push(rx); ys.push(ry); zs.push(rz); cs.push(rc);
}
} else { // plane at fixed margin, vary P & D
const mm = cfg.mmax * cfg.slicePos;
for (let k = 0; k < n; k++) { // rows = delegation
const rx = [], ry = [], rz = [], rc = [];
for (let i = 0; i < n; i++) { // cols = pledge
const v = clean(m.fn(Pvals[i], Dvals[k], mm, cfg));
rx.push(Pvals[i] / 1e6); ry.push(mm * 100); rz.push(Dvals[k] / 1e6); rc.push(v);
vmin = Math.min(vmin, v); vmax = Math.max(vmax, v);
}
xs.push(rx); ys.push(ry); zs.push(rz); cs.push(rc);
}
}
return { xs, ys, zs, cs, vmin, vmax };
}
function clean(v) { return isFinite(v) ? v : 0; }
// Whole-cube value range for the current metric. Used so the MRI slice keeps a FIXED
// colour scale as it sweeps: the plane moves through a stable field instead of the
// colours re-normalising on every slice.
function cubeRange(cfg) {
const m = METRICS[cfg.metric];
const n = cfg.res;
const Pvals = lin(0, cfg.pmax, n);
const Mvals = lin(0, cfg.mmax, n);
const Dvals = lin(0, cfg.dmax, n);
let vmin = Infinity, vmax = -Infinity;
for (let k = 0; k < n; k++)
for (let j = 0; j < n; j++)
for (let i = 0; i < n; i++) {
let v = m.fn(Pvals[i], Dvals[k], Mvals[j], cfg);
if (!isFinite(v)) v = 0;
if (v < vmin) vmin = v;
if (v > vmax) vmax = v;
}
return { vmin, vmax };
}
// ─────────────────────────────────────────────────────────────────────────────
// Color-range helper: for diverging metrics, center on the pivot.
// ─────────────────────────────────────────────────────────────────────────────
function colorRange(metric, vmin, vmax) {
const m = METRICS[metric];
if (m.diverging) {
const span = Math.max(Math.abs(vmax - m.pivot), Math.abs(vmin - m.pivot), 1e-9);
return { cmin: m.pivot - span, cmax: m.pivot + span, cmid: m.pivot };
}
return { cmin: vmin, cmax: vmax };
}
// ─────────────────────────────────────────────────────────────────────────────
// Main render
// ─────────────────────────────────────────────────────────────────────────────
const layout3d = {
paper_bgcolor: '#0e1117',
font: { color: '#d6dde6', size: 11 },
margin: { l: 0, r: 0, t: 0, b: 0 },
scene: {
xaxis: { title: 'Pledge P (M ADA)', backgroundcolor:'#0e1117', gridcolor:'#2b333f', zerolinecolor:'#3a4350', color:'#9aa6b5' },
yaxis: { title: 'Margin m (%)', backgroundcolor:'#0e1117', gridcolor:'#2b333f', zerolinecolor:'#3a4350', color:'#9aa6b5' },
zaxis: { title: 'Delegation D (M ADA)', backgroundcolor:'#0e1117', gridcolor:'#2b333f', zerolinecolor:'#3a4350', color:'#9aa6b5' },
// center.z lifts the cube's focal point so it sits vertically centred in the
// window instead of hugging the bottom. Make it more negative to raise the
// cube further; less negative (toward 0) to drop it back down.
camera: { eye: { x: 1.7, y: 1.5, z: 1.1 }, center: { x: 0, y: 0, z: -0.12 } },
aspectmode: 'cube'
}
};
const plotConfig = { displayModeBar: true, responsive: true,
modeBarButtonsToRemove: ['toImage'], displaylogo: false };
let lastGridRange = [0, 1]; // [vmin, vmax] of the most recent field, for the iso slider
function render() {
const cfg = readCfg();
const m = METRICS[cfg.metric];
const cs = m.reverse ? reverseScale(m.colorscale) : m.colorscale;
let traces = [];
let info = '';
if (renderMode === 'slice') {
const g = buildSlice(cfg);
const cubeR = cubeRange(cfg); // FIXED colour scale across the whole cube
lastGridRange = [cubeR.vmin, cubeR.vmax]; // → the slice moves; the colours don't rescale
const cr = colorRange(cfg.metric, cubeR.vmin, cubeR.vmax);
traces = [{
type: 'surface',
x: g.xs, y: g.ys, z: g.zs, surfacecolor: g.cs, text: g.cs,
colorscale: cs, cmin: cr.cmin, cmax: cr.cmax,
colorbar: { title: { text: m.label, side: 'right' }, len: 0.7, thickness: 14 },
contours: { z: { show: false } },
lighting: { ambient: 0.95, diffuse: 0.2, specular: 0.05 },
hovertemplate: 'P=%{x:.2f}M m=%{y:.2f}% D=%{z:.2f}M<br>'+m.label+': %{text:.3s}<extra></extra>'
}];
const axisName = cfg.sliceAxis === 'z' ? 'Delegation' : cfg.sliceAxis === 'x' ? 'Pledge' : 'Margin';
const axisMax = cfg.sliceAxis === 'z' ? cfg.dmax/1e6+' M' : cfg.sliceAxis === 'x' ? cfg.pmax/1e6+' M' : (cfg.mmax*100).toFixed(1)+'%';
const posVal = cfg.sliceAxis === 'z' ? (cfg.dmax*cfg.slicePos/1e6).toFixed(1)+' M ADA'
: cfg.sliceAxis === 'x' ? (cfg.pmax*cfg.slicePos/1e6).toFixed(2)+' M ADA'
: (cfg.mmax*cfg.slicePos*100).toFixed(2)+'%';
info = `MRI slice ⟂ <b>${axisName}</b> at <b>${posVal}</b> (range 0–${axisMax}).`;
} else {
const g = buildGrid(cfg);
lastGridRange = [g.vmin, g.vmax];
const cr = colorRange(cfg.metric, g.vmin, g.vmax);
if (renderMode === 'volume') {
traces = [{
type: 'volume',
x: g.x, y: g.y, z: g.z, value: g.value,
isomin: g.vmin, isomax: g.vmax,
cmin: cr.cmin, cmax: cr.cmax, cmid: cr.cmid,
colorscale: cs,
opacity: 0.12, surface: { count: 18 },
colorbar: { title: { text: m.label, side: 'right' }, len: 0.7, thickness: 14 },
// Only the coordinates at the cursor. The fog is only ever hovered on the
// cube's outer surface, and Plotly's value reading there snaps to the
// nearest grid corner (unreliable), so we deliberately omit the metric.
hovertemplate: 'P=%{x:.2f}M m=%{y:.2f}% D=%{z:.2f}M<extra></extra>'
}];
info = 'Volume fog — opacity follows the metric. Denser color = larger value.';
} else { // isosurface
// Keep the shell at a fixed ABSOLUTE value across presets (same metric); only a
// metric change resets it. Then reflect that value back onto the 0–100 slider.
let lvl;
if (isoMetric === cfg.metric && isoLevel !== null) {
lvl = Math.max(g.vmin, Math.min(g.vmax, isoLevel));
} else {
lvl = g.vmin + cfg.iso * (g.vmax - g.vmin);
isoMetric = cfg.metric;
}
isoLevel = lvl;
$('sl-iso').value = g.vmax > g.vmin ? 100 * (lvl - g.vmin) / (g.vmax - g.vmin) : 50;
const band = (g.vmax - g.vmin) * 0.001 || 1e-6;
const isomin = showShells ? g.vmin : lvl;
const isomax = showShells ? g.vmax : lvl + band;
// A single isosurface is, by definition, the surface where the metric equals
// the level — so the value at every point on it is exactly fmt(lvl), the same
// number shown on the Isosurface-level slider. Bake it into the hover. Nested
// shells have several different levels at once, so there we show coordinates only.
const isoValLine = showShells ? '' : '<br>' + m.label + ': ' + fmt(lvl);
// Optionally suppress everything above saturation. A NaN value blanks Plotly's
// entire isosurface trace, so instead we push every voxel whose combined pledge +
// delegation exceeds S_SAT to a sentinel far BELOW the iso level. No surface can
// form there (nothing crosses the level), so the above-saturation half disappears
// while the sub-saturation half renders normally — with a flat cap where the shell
// meets the saturation plane.
let isoValue = g.value;
if (hideAboveSat) {
const satM = S_SAT / 1e6; // g.x and g.z are stored in M ADA
const sentinel = g.vmin - (g.vmax - g.vmin) - 1; // strictly below any iso level
isoValue = g.value.map((v, idx) => (g.x[idx] + g.z[idx] > satM + 1e-9) ? sentinel : v);
}
traces = [{
type: 'isosurface',
x: g.x, y: g.y, z: g.z, value: isoValue,
isomin, isomax,
surface: { count: showShells ? 4 : 1, fill: 1.0 },
caps: { x:{show:false}, y:{show:false}, z:{show:false} },
cmin: cr.cmin, cmax: cr.cmax, cmid: cr.cmid,
colorscale: cs, opacity: showShells ? 0.35 : 0.9,
colorbar: { title: { text: m.label, side: 'right' }, len: 0.7, thickness: 14 },
hovertemplate: 'P=%{x:.2f}M m=%{y:.2f}% D=%{z:.2f}M' + isoValLine + '<extra></extra>'
}];
lastLiveIso = traces[0]; // what "Save surface" would freeze
lastIsoDesc = isoDescription(cfg, lvl, showShells);
$('v-iso').textContent = fmt(lvl);
info = showShells
? 'Nested shells — several constant-value surfaces from min to max.'
: `Isosurface at <b>${fmt(lvl)}</b> — the boundary of the region above this value.`;
if (hideAboveSat) info += ' <b>Above-saturation pools (P + D > 75M ADA) hidden.</b>';
}
}
// Layer any frozen surfaces beneath the live one (isosurface mode only).
if (renderMode === 'isosurface' && savedSurfaces.length) {
traces = savedSurfaces.map(s => s.trace).concat(traces);
}
Plotly.react('plot', traces, layout3d, plotConfig);
updateReadout(cfg, m, info);
syncFieldModeButtons();
}
// Light whichever shell-drawing mode is active: a single shell (Snap to pivot) or several
// (Nested shells). They are mutually exclusive ways to draw the isosurface, so exactly one
// reads as "on" — just like the render-mode buttons.
function syncFieldModeButtons() {
const snap = $('btn-snap'), shells = $('btn-shells');
if (snap) snap.classList.toggle('active', !showShells);
if (shells) shells.classList.toggle('active', showShells);
}
// Briefly depress a button so a click — even a scripted one from the tour — is visibly
// registered, like a physical key bottoming out.
function flashPressed(btn) {
if (!btn) return;
btn.classList.add('pressed');
setTimeout(() => btn.classList.remove('pressed'), 150);
}
// Build a reversed copy of a named Plotly colorscale (so red = "bad/MPO-wins").
function reverseScale(name) {
// RdBu reversed → red high, blue low.
if (name === 'RdBu') {
return [
[0.0, 'rgb(5,48,97)'], [0.1,'rgb(33,102,172)'], [0.2,'rgb(67,147,195)'],
[0.3,'rgb(146,197,222)'], [0.4,'rgb(209,229,240)'], [0.5,'rgb(247,247,247)'],
[0.6,'rgb(253,219,199)'], [0.7,'rgb(244,165,130)'], [0.8,'rgb(214,96,77)'],
[0.9,'rgb(178,24,43)'], [1.0,'rgb(103,0,31)']
];
}
return name;
}
function fmt(v) {
const a = Math.abs(v);
if (a >= 1e6) return (v/1e6).toFixed(2)+'M';
if (a >= 1e3) return (v/1e3).toFixed(1)+'k';
if (a >= 1) return v.toFixed(1);
return v.toFixed(3);
}
// ─────────────────────────────────────────────────────────────────────────────
// Readout panel
// ─────────────────────────────────────────────────────────────────────────────
function updateReadout(cfg, m, info) {
const active = [];
if (cfg.cipFee && cfg.F < 340) active.push(`fee→${cfg.F}`);
if (cfg.cip50) active.push(`CIP-50 L=${cfg.L}`);
if (cfg.cip187) active.push(`CIP-187 b=${cfg.b.toFixed(2)}`);
const cipTxt = active.length ? active.join(' · ') : 'none (baseline)';
// sample the splitting advantage at the three archetype corners
const corners = {
'Fee-farm (low P, low D)': [0.2e6, 2e6],
'Leveraged (low P, high D)': [0.2e6, cfg.dmax*0.9],
'Empty pledge (high P, low D)': [cfg.pmax*0.9, 1e6]
};
let rows = '';
for (const [name, pd] of Object.entries(corners)) {
const single = spoIncome(pd[0]+pd[1], pd[0], 0.0, cfg);
const comb = mpoCombined(pd[0], pd[1], 0.0, cfg);
const adv = comb - single;
const cls = adv > 0.5 ? 'hot' : adv < -0.5 ? 'cool' : '';
const verdict= adv > 0.5 ? 'multipool wins' : adv < -0.5 ? 'single wins' : '≈ neutral';
rows += `<div><b>${name}</b>: <span class="${cls}">${fmt(adv)} ADA/ep — ${verdict}</span></div>`;
}
const Pi = cfg.pmax*0.5, Di = cfg.dmax*0.5;
$('readout').innerHTML =
`<div style="margin-bottom:0.4rem">${info}</div>`
+ `<div style="margin-bottom:0.4rem">Active CIPs: <b>${cipTxt}</b> · N=<b>${cfg.N}</b></div>`
+ `<div style="font-size:0.74rem;color:var(--muted);margin-bottom:0.3rem">Splitting advantage (m=0%) at the three MPO archetypes:</div>`
+ rows
+ `<div class="hint">${m.hint}</div>`
+ savedLegendHtml();
}
// ─────────────────────────────────────────────────────────────────────────────
// Wiring
// ─────────────────────────────────────────────────────────────────────────────
function syncLabels() {
$('v-F').textContent = $('sl-F').value;
$('v-L').textContent = $('sl-L').value;
$('v-b').textContent = parseFloat($('sl-b').value).toFixed(2);
$('v-N').textContent = $('sl-N').value;
$('v-r').textContent = parseFloat($('sl-r').value).toFixed(6);
$('v-a0').textContent = parseFloat($('sl-a0').value).toFixed(2);
$('v-res').textContent= $('sl-res').value;
$('v-slicepos').textContent = $('sl-slicepos').value + '%';
// CIP label coloring + enable/disable dependent sliders (driven by the preset)
toggleCip(cipState.fee, 'lbl-fee', 'wrap-F');
toggleCip(cipState.c50, 'lbl-50', 'wrap-L');
toggleCip(cipState.c187, 'lbl-187', 'wrap-b');
$('metric-hint').innerHTML = METRICS[$('metric').value].hint;
}
function toggleCip(active, lbl, wrapId) {
$(lbl).className = active ? 'cip-on' : 'cip-off';
$(wrapId).classList.toggle('disabled', !active);
}
// Debounced heavy recompute (on release / change).
let pending = null;
function scheduleRender() {
syncLabels();
clearTimeout(pending);
pending = setTimeout(render, 30);
}
// Light controls update labels live during drag; heavy recompute on 'change'.
document.querySelectorAll('input[type=range]').forEach(el => {
el.addEventListener('input', syncLabels);
el.addEventListener('change', scheduleRender);
});
document.querySelectorAll('select').forEach(el => {
el.addEventListener('change', scheduleRender);
});
// Absolute iso level — update it live while the iso-level slider is dragged, using the
// range of the field currently on screen. render() then holds this value across presets.
$('sl-iso').addEventListener('input', () => {
const [vmin, vmax] = lastGridRange;
isoLevel = vmin + (parseFloat($('sl-iso').value) / 100) * (vmax - vmin);
isoMetric = $('metric').value;
});
// Render-mode buttons
$('modebtns').addEventListener('click', e => {
const btn = e.target.closest('button'); if (!btn) return;
renderMode = btn.dataset.mode;
document.querySelectorAll('#modebtns button').forEach(b => b.classList.toggle('active', b === btn));
$('wrap-iso').style.display = renderMode === 'isosurface' ? '' : 'none';
$('wrap-slice').style.display = renderMode === 'slice' ? '' : 'none';
const hints = {
volume: "Semi-transparent fog: opacity follows the metric, so dense color marks where the metric is large. Best first look at the field's shape.",
isosurface: 'A surface of constant metric value. Slide the level to find the boundary; for the advantage metrics, snap to the 0 / 1 pivot to see exactly where multipools stop winning.',
slice: 'A flat plane swept through the cube — the literal MRI view. Pick an axis and sweep its position.'
};
$('mode-hint').innerHTML = hints[renderMode];
render();
});
// Iso "snap to pivot" → set slider so the level sits on the metric's pivot (0 or 1).
$('btn-snap').addEventListener('click', () => {
const cfg = readCfg();
const m = METRICS[cfg.metric];
const [vmin, vmax] = lastGridRange;
const pivot = m.diverging ? m.pivot : (vmin + vmax) / 2;
isoLevel = Math.max(vmin, Math.min(vmax, pivot)); // set the absolute level directly
isoMetric = cfg.metric;
showShells = false;
scheduleRender();
});