-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdex-contracts-system.html
More file actions
827 lines (721 loc) · 52.4 KB
/
Copy pathdex-contracts-system.html
File metadata and controls
827 lines (721 loc) · 52.4 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
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8" />
<title>DEX.DO Contracts System</title>
<style>
:root {
--bg: #f4efe3;
--bg2: #fffaf0;
--card: #fffdfa;
--ink: #1f2937;
--muted: #526071;
--border: #d7c6a3;
--accent: #0f766e;
--accent-fill: #ecfeff;
--event: #b91c1c;
--event-fill: #fff1f2;
--line: #475569;
--note-fill: #f8fafc;
--note-stroke: #94a3b8;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
padding: 32px;
color: var(--ink);
background:
radial-gradient(circle at top left, #fff6dd 0, #fff6dd 18%, transparent 42%),
linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
font-family: Georgia, "Times New Roman", serif;
line-height: 1.55;
}
main {
max-width: 1240px;
margin: 0 auto;
}
h1,
h2,
h3 {
font-family: "Helvetica Neue", Arial, sans-serif;
letter-spacing: 0.01em;
margin: 0 0 12px;
}
h1 {
font-size: 34px;
}
h2 {
font-size: 24px;
}
h3 {
font-size: 18px;
}
p {
margin: 0 0 12px;
}
a {
color: #8b4513;
}
.card {
background: var(--card);
border: 1px solid var(--border);
border-radius: 18px;
padding: 24px;
margin: 22px 0;
box-shadow: 0 10px 30px rgba(54, 36, 10, 0.08);
}
.hero {
padding: 28px;
}
.hero p:last-child {
margin-bottom: 0;
}
.links {
display: flex;
gap: 18px;
flex-wrap: wrap;
margin-top: 14px;
font-family: "Helvetica Neue", Arial, sans-serif;
font-size: 14px;
}
.pill {
display: inline-block;
padding: 4px 10px;
border-radius: 999px;
background: #f5efe1;
border: 1px solid #dbc7a1;
margin: 0 8px 8px 0;
font-family: "Helvetica Neue", Arial, sans-serif;
font-size: 13px;
}
.legend {
display: flex;
gap: 18px;
flex-wrap: wrap;
margin-top: 10px;
font-family: "Helvetica Neue", Arial, sans-serif;
font-size: 14px;
color: var(--muted);
}
.legend-item {
display: flex;
align-items: center;
gap: 8px;
}
.legend-box {
width: 30px;
height: 16px;
border-radius: 8px;
border: 3px solid var(--event);
background: var(--event-fill);
}
.legend-line {
width: 34px;
border-top: 2px solid var(--line);
}
table {
width: 100%;
border-collapse: collapse;
font-size: 14px;
}
th,
td {
padding: 10px 12px;
border-bottom: 1px solid #eadcc3;
vertical-align: top;
}
th {
text-align: left;
font-family: "Helvetica Neue", Arial, sans-serif;
}
.muted {
color: var(--muted);
}
.diagram {
margin-top: 14px;
}
.diagram svg {
width: 100%;
height: auto;
display: block;
background: #fff;
border: 1px solid #eadcc3;
border-radius: 14px;
}
.caption {
margin-top: 10px;
color: var(--muted);
font-size: 14px;
}
@media (max-width: 900px) {
body {
padding: 18px;
}
.card {
padding: 18px;
}
}
</style>
</head>
<body>
<main>
<section class="card hero">
<h1>DEX.DO Contract System</h1>
<p>HTML documentation for the entire contract system under `contracts/`. The diagrams below are inline SVG with no external JS — predictable rendering and easy local inspection.</p>
<p>Red badges on the sequence diagrams are external events. They are deliberately rendered thicker and separated from regular calls so the event layer is immediately distinguishable.</p>
<div class="links">
<a href="dex-contracts-object-diagram.drawio">Object Diagram (.drawio)</a>
<a href="dex-events-routing.md">Event Routing Tables</a>
</div>
<div style="margin-top: 14px;">
<span class="pill">RootPN</span>
<span class="pill">PrivateNote</span>
<span class="pill">Nullifier</span>
<span class="pill">RootOracle</span>
<span class="pill">Oracle</span>
<span class="pill">OracleEventList</span>
<span class="pill">PMP</span>
<span class="pill">OrderBook</span>
</div>
<div class="legend">
<div class="legend-item"><span class="legend-line"></span><span>call / callback</span></div>
<div class="legend-item"><span class="legend-box"></span><span>external event object (`emit ...{dest: ...}`)</span></div>
</div>
</section>
<section class="card">
<h2>Contract Map</h2>
<table>
<thead>
<tr>
<th>Contract</th>
<th>Role</th>
<th>Key deterministic keys</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>RootPN</strong></td>
<td>Root deployer for `PrivateNote`, `Nullifier`, and the vault flow.</td>
<td>`_depositIdentifierHash`, `_nullifierHash`</td>
</tr>
<tr>
<td><strong>PrivateNote</strong></td>
<td>User-side DEX wallet: stake, split/merge, claim, orders, transfer.</td>
<td>`_depositIdentifierHash`, `stakeHash = hash(eventId, oracleListHash, tokenType)`</td>
</tr>
<tr>
<td><strong>Nullifier</strong></td>
<td>One-shot relay for shell-fee top-up into `PrivateNote`.</td>
<td>`_nullifierHash`</td>
</tr>
<tr>
<td><strong>RootOracle</strong></td>
<td>Root deployer for `Oracle`.</td>
<td>`_name` on the downstream `Oracle`</td>
</tr>
<tr>
<td><strong>Oracle</strong></td>
<td>Oracle-owner contract that creates `OracleEventList`.</td>
<td>`_name`, `(_oracle, _index)` on `OracleEventList`</td>
</tr>
<tr>
<td><strong>OracleEventList</strong></td>
<td>Event registry and the oracle-confirmation entry point for PMP.</td>
<td>`(_oracle, _index)` for the contract address; `eventId` for the inner `EventInfo` entries</td>
</tr>
<tr>
<td><strong>PMP</strong></td>
<td>Prediction market pool, approvals, timings, resolve, split/merge.</td>
<td>`(eventId, oracleListHash, tokenType)`</td>
</tr>
<tr>
<td><strong>OrderBook</strong></td>
<td>Order book for a frozen market — queues, match/fill/cancel.</td>
<td>`(eventId, oracleListHash, tokenType)`, `orderId`, `clientOrderId`</td>
</tr>
</tbody>
</table>
</section>
<section class="card">
<h2>1. Vault And Note Lifecycle</h2>
<p>This chain covers three separate flows: `PrivateNote` creation, shell-fee top-up via `Nullifier`, and voucher-event generation in `RootPN`.</p>
<div class="diagram">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 880 500" role="img" aria-label="Vault and PrivateNote lifecycle">
<defs>
<marker id="arrow-vault" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#475569" />
</marker>
<marker id="arrow-vault-red" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#b91c1c" />
</marker>
</defs>
<rect x="40" y="20" width="140" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="240" y="20" width="140" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="440" y="20" width="140" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="640" y="20" width="170" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<text x="110" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">User</text>
<text x="310" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">RootPN</text>
<text x="510" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">Nullifier</text>
<text x="725" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PrivateNote</text>
<line x1="110" y1="60" x2="110" y2="460" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="310" y1="60" x2="310" y2="460" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="510" y1="60" x2="510" y2="460" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="725" y1="60" x2="725" y2="460" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="110" y1="95" x2="310" y2="95" stroke="#475569" stroke-width="2" marker-end="url(#arrow-vault)" />
<text x="145" y="86" font-family="Arial" font-size="13">deployPrivateNote(...)</text>
<line x1="310" y1="140" x2="725" y2="140" stroke="#475569" stroke-width="2" marker-end="url(#arrow-vault)" />
<text x="430" y="131" font-family="Arial" font-size="13">new PrivateNote(...)</text>
<line x1="725" y1="185" x2="310" y2="185" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-vault)" />
<text x="455" y="176" font-family="Arial" font-size="13">privateNoteDeployed(...)</text>
<line x1="310" y1="215" x2="565" y2="215" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-vault-red)" />
<rect x="570" y="198" width="220" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="680" y="220" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: PrivateNoteDeployed</text>
<line x1="110" y1="270" x2="310" y2="270" stroke="#475569" stroke-width="2" marker-end="url(#arrow-vault)" />
<text x="132" y="261" font-family="Arial" font-size="13">sendEccShellToPrivateNote(...)</text>
<line x1="310" y1="315" x2="510" y2="315" stroke="#475569" stroke-width="2" marker-end="url(#arrow-vault)" />
<text x="360" y="306" font-family="Arial" font-size="13">new Nullifier(noteAddress)</text>
<line x1="310" y1="345" x2="565" y2="345" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-vault-red)" />
<rect x="570" y="328" width="196" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="668" y="350" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: NullifierDeployed</text>
<line x1="510" y1="390" x2="725" y2="390" stroke="#475569" stroke-width="2" marker-end="url(#arrow-vault)" />
<text x="555" y="381" font-family="Arial" font-size="13">transfer shell fee</text>
<line x1="110" y1="430" x2="310" y2="430" stroke="#475569" stroke-width="2" marker-end="url(#arrow-vault)" />
<text x="170" y="421" font-family="Arial" font-size="13">generateVoucher(...)</text>
<line x1="310" y1="450" x2="565" y2="450" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-vault-red)" />
<rect x="570" y="433" width="185" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="662" y="455" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: VoucherGenerated</text>
</svg>
</div>
<p class="caption">`Nullifier` declares no events of its own: the event is emitted by `RootPN`, then `Nullifier` simply forwards funds into the target `PrivateNote`.</p>
</section>
<section class="card">
<h2>2. Oracle Control Plane</h2>
<p>The Oracle branch consists of `RootOracle`, `Oracle`, and `OracleEventList`. `OracleEventList` is what stores the `EventInfo` records and confirms the market for PMP.</p>
<div class="diagram">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 920 460" role="img" aria-label="Oracle deployment and event registry">
<defs>
<marker id="arrow-oracle" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#475569" />
</marker>
<marker id="arrow-oracle-red" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#b91c1c" />
</marker>
</defs>
<rect x="40" y="20" width="150" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="250" y="20" width="170" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="480" y="20" width="150" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="690" y="20" width="180" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<text x="115" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">Operator</text>
<text x="335" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">RootOracle</text>
<text x="555" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">Oracle</text>
<text x="780" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">OracleEventList</text>
<line x1="115" y1="60" x2="115" y2="420" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="335" y1="60" x2="335" y2="420" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="555" y1="60" x2="555" y2="420" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="780" y1="60" x2="780" y2="420" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="115" y1="95" x2="335" y2="95" stroke="#475569" stroke-width="2" marker-end="url(#arrow-oracle)" />
<text x="172" y="86" font-family="Arial" font-size="13">deployOracle(pubkey, name)</text>
<line x1="335" y1="140" x2="555" y2="140" stroke="#475569" stroke-width="2" marker-end="url(#arrow-oracle)" />
<text x="408" y="131" font-family="Arial" font-size="13">new Oracle(...)</text>
<line x1="335" y1="170" x2="560" y2="170" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-oracle-red)" />
<rect x="565" y="153" width="175" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="652" y="175" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OracleDeployed</text>
<line x1="555" y1="220" x2="780" y2="220" stroke="#475569" stroke-width="2" marker-end="url(#arrow-oracle)" />
<text x="613" y="211" font-family="Arial" font-size="13">new OracleEventList(index = 0)</text>
<line x1="555" y1="250" x2="760" y2="250" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-oracle-red)" />
<rect x="565" y="233" width="205" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="668" y="255" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OracleEventListDeployed</text>
<line x1="115" y1="300" x2="555" y2="300" stroke="#475569" stroke-width="2" marker-end="url(#arrow-oracle)" />
<text x="250" y="291" font-family="Arial" font-size="13">deployEventList(index)</text>
<line x1="555" y1="335" x2="780" y2="335" stroke="#475569" stroke-width="2" marker-end="url(#arrow-oracle)" />
<text x="612" y="326" font-family="Arial" font-size="13">new OracleEventList(index)</text>
<line x1="115" y1="380" x2="780" y2="380" stroke="#475569" stroke-width="2" marker-end="url(#arrow-oracle)" />
<text x="320" y="371" font-family="Arial" font-size="13">addEvent(eventName, oracleFee, deadline, describe, outcomeNames, trustAddr)</text>
<line x1="780" y1="405" x2="600" y2="405" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-oracle-red)" />
<rect x="605" y="388" width="165" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="688" y="410" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: EventAdded</text>
<rect x="40" y="404" width="250" height="38" rx="10" fill="#f8fafc" stroke="#94a3b8" stroke-width="2" stroke-dasharray="5 4" />
<text x="165" y="428" text-anchor="middle" font-family="Arial" font-size="12" fill="#526071">EventPublished declared only, no emit in current code</text>
</svg>
</div>
</section>
<section class="card">
<h2>3. Market Deployment, Oracle Approval, Freeze</h2>
<p>`PrivateNote` creates the `PMP`, the `PMP` collects approvals from every `OracleEventList`, records the deployer's initial stakes on the first approval, then transitions into approved state, receives timings, and only after freezing brings up `OrderBook`.</p>
<div class="diagram">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1120 520" role="img" aria-label="PMP deployment, approvals and freeze">
<defs>
<marker id="arrow-market" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#475569" />
</marker>
<marker id="arrow-market-red" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#b91c1c" />
</marker>
</defs>
<rect x="30" y="20" width="120" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="190" y="20" width="150" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="380" y="20" width="120" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="540" y="20" width="160" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="740" y="20" width="160" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="940" y="20" width="140" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<text x="90" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">User</text>
<text x="265" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PrivateNote</text>
<text x="440" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PMP</text>
<text x="620" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">OracleEventList A</text>
<text x="820" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">OracleEventList B</text>
<text x="1010" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">OrderBook</text>
<line x1="90" y1="60" x2="90" y2="470" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="265" y1="60" x2="265" y2="470" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="440" y1="60" x2="440" y2="470" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="620" y1="60" x2="620" y2="470" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="820" y1="60" x2="820" y2="470" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="1010" y1="60" x2="1010" y2="470" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="90" y1="95" x2="265" y2="95" stroke="#475569" stroke-width="2" marker-end="url(#arrow-market)" />
<text x="118" y="86" font-family="Arial" font-size="13">deployPMP(...)</text>
<line x1="265" y1="120" x2="500" y2="120" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-market-red)" />
<rect x="505" y="103" width="160" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="585" y="125" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: PMPDeployed</text>
<line x1="265" y1="165" x2="440" y2="165" stroke="#475569" stroke-width="2" marker-end="url(#arrow-market)" />
<text x="302" y="156" font-family="Arial" font-size="13">new PMP(...)</text>
<line x1="440" y1="215" x2="620" y2="215" stroke="#475569" stroke-width="2" marker-end="url(#arrow-market)" />
<text x="470" y="206" font-family="Arial" font-size="13">confirmEvent(eventId, oracleListHash, tokenType)</text>
<line x1="620" y1="245" x2="480" y2="245" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-market-red)" />
<rect x="485" y="228" width="175" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="572" y="250" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: EventConfirmed</text>
<line x1="620" y1="290" x2="440" y2="290" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-market)" />
<text x="492" y="281" font-family="Arial" font-size="13">approveEvent(...)</text>
<line x1="440" y1="325" x2="820" y2="325" stroke="#475569" stroke-width="2" marker-end="url(#arrow-market)" />
<text x="544" y="316" font-family="Arial" font-size="13">confirmEvent(...) for second oracle</text>
<line x1="820" y1="355" x2="500" y2="355" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-market)" />
<text x="622" y="346" font-family="Arial" font-size="13">approveEvent(...)</text>
<line x1="440" y1="385" x2="690" y2="385" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-market-red)" />
<rect x="695" y="368" width="195" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="792" y="390" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: ApprovedByOracle</text>
<path d="M 440 425 C 500 425 500 455 440 455" fill="none" stroke="#475569" stroke-width="2" marker-end="url(#arrow-market)" />
<text x="455" y="418" font-family="Arial" font-size="13">setTimings(resultStart)</text>
<line x1="440" y1="440" x2="690" y2="440" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-market-red)" />
<rect x="695" y="423" width="142" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="766" y="445" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: TimingsSet</text>
<line x1="440" y1="470" x2="1010" y2="470" stroke="#475569" stroke-width="2" marker-end="url(#arrow-market)" />
<text x="640" y="461" font-family="Arial" font-size="13">_ensureFrozen() - new OrderBook(...)</text>
<line x1="440" y1="495" x2="690" y2="495" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-market-red)" />
<rect x="695" y="478" width="150" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="770" y="500" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: PoolsFrozen</text>
</svg>
</div>
<p class="caption">`OrderBook` is not created during `deployPMP()` itself: it comes up later, when the PMP actually freezes. The same lifecycle includes internal callbacks with no external event object: `onInitialStakesAccepted(...)`, `onInitialStakesFailed(...)`, and then `onPmpCleanRefund(...)` before `PoolsFrozen`.</p>
</section>
<section class="card">
<h2>4. Stake, Split, Merge, Resolve, Claim</h2>
<p>This is the main market execution path after approval: regular stake, full-set split/merge, then resolve and claim. The mirrored PMP/PrivateNote event pairs are most visible here.</p>
<div class="diagram">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 760 940" role="img" aria-label="Stake, split, merge, resolve and claim">
<defs>
<marker id="arrow-stake" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#475569" />
</marker>
<marker id="arrow-stake-red" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#b91c1c" />
</marker>
</defs>
<rect x="50" y="20" width="130" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="280" y="20" width="150" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="520" y="20" width="130" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<text x="115" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">User</text>
<text x="355" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PrivateNote</text>
<text x="585" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PMP</text>
<line x1="115" y1="60" x2="115" y2="900" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="355" y1="60" x2="355" y2="900" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="585" y1="60" x2="585" y2="900" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="115" y1="95" x2="355" y2="95" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="185" y="86" font-family="Arial" font-size="13">setStake(...)</text>
<line x1="355" y1="135" x2="585" y2="135" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="420" y="126" font-family="Arial" font-size="13">acceptStake(...)</text>
<line x1="585" y1="165" x2="455" y2="165" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="460" y="148" width="145" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="532" y="170" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: StakeAccepted</text>
<line x1="585" y1="205" x2="355" y2="205" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-stake)" />
<text x="430" y="196" font-family="Arial" font-size="13">onStakeAccepted(...)</text>
<line x1="355" y1="235" x2="505" y2="235" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="510" y="218" width="155" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="588" y="240" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: StakeConfirmed</text>
<line x1="115" y1="295" x2="355" y2="295" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="178" y="286" font-family="Arial" font-size="13">splitFullSet(...)</text>
<line x1="355" y1="335" x2="585" y2="335" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="424" y="326" font-family="Arial" font-size="13">splitFullSet(...)</text>
<line x1="585" y1="365" x2="455" y2="365" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="460" y="348" width="150" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="535" y="370" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: SplitProcessed</text>
<line x1="585" y1="405" x2="355" y2="405" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-stake)" />
<text x="428" y="396" font-family="Arial" font-size="13">onSplitAccepted(...)</text>
<line x1="355" y1="435" x2="455" y2="435" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="460" y="418" width="195" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="558" y="440" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: FullSetStakeConfirmed</text>
<line x1="115" y1="495" x2="355" y2="495" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="172" y="486" font-family="Arial" font-size="13">mergeFullSet(...)</text>
<line x1="355" y1="535" x2="585" y2="535" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="424" y="526" font-family="Arial" font-size="13">mergeFullSet(...)</text>
<line x1="585" y1="565" x2="455" y2="565" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="460" y="548" width="158" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="539" y="570" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: MergeProcessed</text>
<line x1="585" y1="605" x2="355" y2="605" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-stake)" />
<text x="425" y="596" font-family="Arial" font-size="13">onMergeAccepted(...)</text>
<line x1="355" y1="635" x2="455" y2="635" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="460" y="618" width="190" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="555" y="640" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: FullSetStakeCancelled</text>
<path d="M 585 690 C 650 690 650 735 585 735" fill="none" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="598" y="682" font-family="Arial" font-size="13">resolve(outcomeId)</text>
<line x1="585" y1="715" x2="455" y2="715" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="460" y="698" width="185" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="552" y="720" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: Resolved / CreatorFeeCollected</text>
<line x1="115" y1="770" x2="355" y2="770" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="220" y="761" font-family="Arial" font-size="13">claim(...)</text>
<line x1="355" y1="805" x2="585" y2="805" stroke="#475569" stroke-width="2" marker-end="url(#arrow-stake)" />
<text x="445" y="796" font-family="Arial" font-size="13">claim(...)</text>
<line x1="585" y1="830" x2="455" y2="830" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="460" y="813" width="150" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="535" y="835" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: ClaimProcessed</text>
<line x1="585" y1="870" x2="355" y2="870" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-stake)" />
<text x="425" y="861" font-family="Arial" font-size="13">onClaimAccepted(...)</text>
<line x1="355" y1="900" x2="505" y2="900" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-stake-red)" />
<rect x="510" y="883" width="150" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="585" y="905" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: ClaimAccepted</text>
</svg>
</div>
<p class="caption">In the actual code the `PMP -> PrivateNote.onClaimAccepted(...)` callback and the external `ClaimProcessed` event live in the same PMP flow; `PrivateNote` then separately emits `ClaimAccepted` inside its own callback.</p>
</section>
<section class="card">
<h2>5. OrderBook: Placement And Fill</h2>
<p>The order flow is split into a queue and callbacks. In the single-order path, `PrivateNote` first emits `OrderSubmitted` and only then receives `OrderBook`'s callbacks via `OrderPlacedConfirmed` / `OrderFilledConfirmed`. Batch placement reuses the same queue/match machinery without an `OrderSubmitted` per item, terminated by `onBatchComplete(...)`.</p>
<div class="diagram">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 640" role="img" aria-label="Order placement and fill sequence">
<defs>
<marker id="arrow-order" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#475569" />
</marker>
<marker id="arrow-order-red" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#b91c1c" />
</marker>
</defs>
<rect x="50" y="20" width="130" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="285" y="20" width="160" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="560" y="20" width="160" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<text x="115" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">User</text>
<text x="365" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PrivateNote</text>
<text x="640" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">OrderBook</text>
<line x1="115" y1="60" x2="115" y2="600" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="365" y1="60" x2="365" y2="600" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="640" y1="60" x2="640" y2="600" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="115" y1="95" x2="365" y2="95" stroke="#475569" stroke-width="2" marker-end="url(#arrow-order)" />
<text x="205" y="86" font-family="Arial" font-size="13">placeOrder(...)</text>
<line x1="365" y1="125" x2="520" y2="125" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-order-red)" />
<rect x="525" y="108" width="170" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="610" y="130" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OrderSubmitted</text>
<line x1="365" y1="170" x2="640" y2="170" stroke="#475569" stroke-width="2" marker-end="url(#arrow-order)" />
<text x="440" y="161" font-family="Arial" font-size="13">executeBatch(orders, [])</text>
<line x1="640" y1="200" x2="505" y2="200" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-order-red)" />
<rect x="510" y="183" width="130" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="575" y="205" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: Queued</text>
<path d="M 640 245 C 705 245 705 285 640 285" fill="none" stroke="#475569" stroke-width="2" marker-end="url(#arrow-order)" />
<text x="652" y="237" font-family="Arial" font-size="13">processHead()</text>
<line x1="640" y1="300" x2="505" y2="300" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-order-red)" />
<rect x="510" y="283" width="145" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="582" y="305" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OrderPlaced</text>
<line x1="640" y1="345" x2="365" y2="345" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-order)" />
<text x="450" y="336" font-family="Arial" font-size="13">onOrderPlaced(...)</text>
<line x1="365" y1="375" x2="520" y2="375" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-order-red)" />
<rect x="525" y="358" width="190" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="620" y="380" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OrderPlacedConfirmed</text>
<path d="M 640 415 C 720 415 720 455 640 455" fill="none" stroke="#475569" stroke-width="2" marker-end="url(#arrow-order)" />
<text x="652" y="407" font-family="Arial" font-size="13">match / fill loop</text>
<line x1="640" y1="470" x2="500" y2="470" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-order-red)" />
<rect x="505" y="453" width="140" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="575" y="475" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OrderFilled</text>
<line x1="640" y1="505" x2="475" y2="505" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-order-red)" />
<rect x="480" y="488" width="205" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="582" y="510" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: PartialFill / FullyFilled</text>
<line x1="640" y1="550" x2="365" y2="550" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-order)" />
<text x="450" y="541" font-family="Arial" font-size="13">onOrderFilled(...)</text>
<line x1="365" y1="585" x2="535" y2="585" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-order-red)" />
<rect x="540" y="568" width="190" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="635" y="590" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OrderFilledConfirmed</text>
</svg>
</div>
<p class="caption">`PartialFill` and `FullyFilled` use the dedicated external channel `address.makeAddrExtern(0, bitCntAddress)` and are aggregated across the processing of a single taker order. `PrivateNote.placeBatch()` and `OrderBook.executeBatch()` reuse exactly the same path; the terminating signal there is the `onBatchComplete(...)` callback rather than a dedicated external event.</p>
</section>
<section class="card">
<h2>6. OrderBook: Cancel, Reject, Bounce</h2>
<p>Cancellation, reject, and callback-bounce form a separate observability path. The service events `Queued`, `Rejected`, and `CallbackBounced` are what matters here. For the batch cancel path `cancelBatch()` / `cancelAllOrders()`, `OrderBook` also terminates the series with the `onBatchComplete(...)` callback without a dedicated event object.</p>
<div class="diagram">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 900 520" role="img" aria-label="Order cancel, reject and bounce sequence">
<defs>
<marker id="arrow-cancel" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#475569" />
</marker>
<marker id="arrow-cancel-red" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#b91c1c" />
</marker>
</defs>
<rect x="50" y="20" width="130" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="285" y="20" width="160" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="560" y="20" width="160" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<text x="115" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">User</text>
<text x="365" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PrivateNote</text>
<text x="640" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">OrderBook</text>
<line x1="115" y1="60" x2="115" y2="480" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="365" y1="60" x2="365" y2="480" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="640" y1="60" x2="640" y2="480" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="115" y1="95" x2="365" y2="95" stroke="#475569" stroke-width="2" marker-end="url(#arrow-cancel)" />
<text x="175" y="86" font-family="Arial" font-size="13">cancelOrder / cancelAll / cancelByClient</text>
<line x1="365" y1="140" x2="640" y2="140" stroke="#475569" stroke-width="2" marker-end="url(#arrow-cancel)" />
<text x="438" y="131" font-family="Arial" font-size="13">executeBatch(cancel) / cancelByClientId</text>
<line x1="640" y1="170" x2="505" y2="170" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-cancel-red)" />
<rect x="510" y="153" width="130" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="575" y="175" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: Queued</text>
<path d="M 640 215 C 705 215 705 255 640 255" fill="none" stroke="#475569" stroke-width="2" marker-end="url(#arrow-cancel)" />
<text x="652" y="207" font-family="Arial" font-size="13">cancel path / queue drain</text>
<line x1="640" y1="270" x2="490" y2="270" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-cancel-red)" />
<rect x="495" y="253" width="160" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="575" y="275" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OrderCancelled</text>
<line x1="640" y1="315" x2="365" y2="315" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-cancel)" />
<text x="445" y="306" font-family="Arial" font-size="13">onOrderCancelled(...)</text>
<line x1="365" y1="345" x2="495" y2="345" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-cancel-red)" />
<rect x="500" y="328" width="205" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="602" y="350" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: OrderCancelledConfirmed</text>
<rect x="90" y="385" width="300" height="42" rx="10" fill="#f8fafc" stroke="#94a3b8" stroke-width="2" stroke-dasharray="5 4" />
<text x="240" y="411" text-anchor="middle" font-family="Arial" font-size="12" fill="#526071">invalid params or full queue</text>
<line x1="640" y1="405" x2="500" y2="405" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-cancel-red)" />
<rect x="505" y="388" width="135" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="572" y="410" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: Rejected</text>
<line x1="640" y1="445" x2="365" y2="445" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-cancel)" />
<text x="450" y="436" font-family="Arial" font-size="13">onOrderRejected(...)</text>
<line x1="640" y1="475" x2="480" y2="475" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-cancel-red)" />
<rect x="485" y="458" width="185" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="577" y="480" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: CallbackBounced</text>
</svg>
</div>
</section>
<section class="card">
<h2>7. PrivateNote To PrivateNote Transfer</h2>
<p>P2P transfer lives apart from the order/stake machinery: the sender locks the amount, the receiver immediately credits the balance, then sends the ack.</p>
<div class="diagram">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 860 380" role="img" aria-label="PrivateNote to PrivateNote transfer sequence">
<defs>
<marker id="arrow-transfer" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#475569" />
</marker>
<marker id="arrow-transfer-red" markerWidth="12" markerHeight="8" refX="10" refY="4" orient="auto">
<polygon points="0,0 12,4 0,8" fill="#b91c1c" />
</marker>
</defs>
<rect x="40" y="20" width="120" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="220" y="20" width="190" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<rect x="490" y="20" width="210" height="40" rx="10" fill="#ecfeff" stroke="#0f766e" stroke-width="2" />
<text x="100" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">User</text>
<text x="315" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PrivateNote Sender</text>
<text x="595" y="45" text-anchor="middle" font-family="Arial" font-size="16" font-weight="700">PrivateNote Receiver</text>
<line x1="100" y1="60" x2="100" y2="340" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="315" y1="60" x2="315" y2="340" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="595" y1="60" x2="595" y2="340" stroke="#94a3b8" stroke-dasharray="6 6" />
<line x1="100" y1="95" x2="315" y2="95" stroke="#475569" stroke-width="2" marker-end="url(#arrow-transfer)" />
<text x="138" y="86" font-family="Arial" font-size="13">initTransfer(destDepositHash, tokenType, amount)</text>
<line x1="315" y1="125" x2="470" y2="125" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-transfer-red)" />
<rect x="475" y="108" width="175" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="562" y="130" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: TransferInitiated</text>
<line x1="315" y1="180" x2="595" y2="180" stroke="#475569" stroke-width="2" marker-end="url(#arrow-transfer)" />
<text x="380" y="171" font-family="Arial" font-size="13">offerTransfer(tokenType, amount, senderDepositHash)</text>
<line x1="595" y1="210" x2="440" y2="210" stroke="#b91c1c" stroke-width="2" marker-end="url(#arrow-transfer-red)" />
<rect x="445" y="193" width="175" height="34" rx="10" fill="#fff1f2" stroke="#b91c1c" stroke-width="3" />
<text x="532" y="215" text-anchor="middle" font-family="Arial" font-size="13" font-weight="800" fill="#b91c1c">EVENT: TransferReceived</text>
<line x1="595" y1="265" x2="315" y2="265" stroke="#475569" stroke-width="2" stroke-dasharray="7 5" marker-end="url(#arrow-transfer)" />
<text x="425" y="256" font-family="Arial" font-size="13">onTransferAccepted()</text>
<rect x="135" y="292" width="580" height="46" rx="10" fill="#f8fafc" stroke="#94a3b8" stroke-width="2" stroke-dasharray="5 4" />
<text x="425" y="320" text-anchor="middle" font-family="Arial" font-size="12" fill="#526071">If `offerTransfer` bounces, the sender restores the amount via `onBounce`; if the ack is lost, `clearTransferBusy()` is available.</text>
</svg>
</div>
</section>
<section class="card">
<h2>8. Internal Callbacks With State Changes</h2>
<p>Not every important transition in the system has an external event object. Below are the internal callbacks that actually mutate contract state and therefore matter when reading flows alongside the sequence diagrams.</p>
<table>
<thead>
<tr>
<th>Where it fires</th>
<th>Internal callback</th>
<th>What it changes</th>
<th>Adjacent external event</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>PMP</strong> first `approveEvent()`</td>
<td>`PrivateNote.onInitialStakesAccepted(...)`</td>
<td>Records the deployer's initial stakes across the outcome arrays and clears the initial indeterminacy of `_busy` on the creator note.</td>
<td>`ApprovedByOracle` may follow later in the same approval lifecycle, but only on the final oracle.</td>
</tr>
<tr>
<td><strong>PMP</strong> reject / invalid initial stakes</td>
<td>`PrivateNote.onInitialStakesFailed(...)`</td>
<td>Refunds the deployer's initial stakes and unfreezes the note when the market fails to initialize.</td>
<td>Typically followed by `PMPRejected`, but the callback itself has no event object.</td>
</tr>
<tr>
<td><strong>PMP</strong> `_ensureFrozen()`</td>
<td>`PrivateNote.onPmpCleanRefund(...)`</td>
<td>Refunds the creator the clean-pool remainders before the integer split/merge basket is built.</td>
<td>`PoolsFrozen` follows.</td>
</tr>
<tr>
<td><strong>OrderBook</strong> reject place-path</td>
<td>`PrivateNote.onOrderRejected(...)`</td>
<td>Restores the buy-lock or sell-lock when an order is rejected during pre-validation or because of an overflowed queue.</td>
<td>`Rejected` is emitted on the `OrderBook` side.</td>
</tr>
<tr>
<td><strong>OrderBook</strong> batch place / cancel / cancel-all</td>
<td>`PrivateNote.onBatchComplete(...)`</td>
<td>Clears the `_pendingBatch*` guard and `_busy` after the entire batch has been dispatched through callbacks.</td>
<td>No dedicated event object; the batch reuses the regular `Queued` / `OrderPlaced` / `OrderCancelled` / `OrderFilled` along the way.</td>
</tr>
</tbody>
</table>
</section>
<section class="card">
<h2>Declared But Not Emitted</h2>
<table>
<thead>
<tr>
<th>Contract</th>
<th>Event</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<tr>
<td><strong>Oracle</strong></td>
<td>`EventPublished(eventId, eventName)`</td>
<td>Declared, but no `emit` in the current code produces it.</td>
</tr>
<tr>
<td><strong>PMP</strong></td>
<td>`NetworkFeeBurned(amount)`</td>
<td>Declared as a reserved event, but not currently emitted.</td>
</tr>
<tr>
<td><strong>PMP</strong></td>
<td>`NumOutcomesSet(numOutcomes)`</td>
<td>Declared, but `_numOutcomes` is currently set inside `approveEvent()` without a dedicated event.</td>
</tr>
<tr>
<td><strong>Nullifier</strong></td>
<td>No `event` declarations of its own</td>
<td>Observability flows through `RootPN.NullifierDeployed`.</td>
</tr>
</tbody>
</table>
</section>
</main>
</body>
</html>