dexbot 1.7.0 → 1.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +3 -3
  3. package/analysis/README.md +33 -13
  4. package/claw/package.json +1 -1
  5. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  6. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  7. package/dist/analysis/account_resolver.js +5 -6
  8. package/dist/analysis/analyze_liquidity.js +15 -4
  9. package/dist/analysis/bot_key_utils.d.ts +44 -1
  10. package/dist/analysis/bot_key_utils.js +76 -7
  11. package/dist/analysis/fills_cache.js +2 -1
  12. package/dist/analysis/grid_correction_check.d.ts +1 -19
  13. package/dist/analysis/grid_correction_check.js +12 -30
  14. package/dist/analysis/liquidity/liquidity_chart_generator.js +190 -20
  15. package/dist/analysis/liquidity/liquidity_depth_model.d.ts +41 -16
  16. package/dist/analysis/liquidity/liquidity_depth_model.js +49 -21
  17. package/dist/analysis/liquidity/liquidity_view.d.ts +15 -0
  18. package/dist/analysis/liquidity/liquidity_view.js +11 -0
  19. package/dist/analysis/resolve_bot_accounts.js +7 -6
  20. package/dist/analysis/trade_profitability.js +2 -1
  21. package/dist/credential-daemon.js +13 -2
  22. package/dist/dexbot.js +4 -4
  23. package/dist/modules/account_bots.d.ts +11 -1
  24. package/dist/modules/account_orders.d.ts +12 -0
  25. package/dist/modules/account_orders.js +30 -0
  26. package/dist/modules/bitshares-native/transport.js +24 -6
  27. package/dist/modules/bitshares_client.d.ts +24 -6
  28. package/dist/modules/bitshares_client.js +44 -7
  29. package/dist/modules/bot_settings.d.ts +2 -0
  30. package/dist/modules/constants.d.ts +26 -3
  31. package/dist/modules/constants.js +63 -8
  32. package/dist/modules/dexbot_class.d.ts +1 -6
  33. package/dist/modules/dexbot_class.js +14 -0
  34. package/dist/modules/dexbot_cow_runtime.d.ts +97 -7
  35. package/dist/modules/dexbot_cow_runtime.js +620 -132
  36. package/dist/modules/dexbot_fill_runtime.js +124 -35
  37. package/dist/modules/dexbot_maintenance_runtime.js +226 -73
  38. package/dist/modules/dexbot_startup_runtime.js +32 -20
  39. package/dist/modules/dexbot_state_recovery.d.ts +33 -1
  40. package/dist/modules/dexbot_state_recovery.js +167 -5
  41. package/dist/modules/node_connect_policy.d.ts +8 -1
  42. package/dist/modules/node_connect_policy.js +18 -2
  43. package/dist/modules/node_flap_score.d.ts +87 -0
  44. package/dist/modules/node_flap_score.js +124 -0
  45. package/dist/modules/node_health_cache.d.ts +40 -3
  46. package/dist/modules/node_health_cache.js +66 -20
  47. package/dist/modules/node_manager.d.ts +101 -19
  48. package/dist/modules/node_manager.js +255 -65
  49. package/dist/modules/order/accounting.js +56 -7
  50. package/dist/modules/order/format.d.ts +24 -10
  51. package/dist/modules/order/format.js +30 -10
  52. package/dist/modules/order/grid.js +82 -11
  53. package/dist/modules/order/grid_reconcile.d.ts +5 -1
  54. package/dist/modules/order/grid_reconcile.js +333 -210
  55. package/dist/modules/order/grid_reconcile_internal.d.ts +38 -2
  56. package/dist/modules/order/grid_reconcile_internal.js +207 -87
  57. package/dist/modules/order/index.d.ts +4 -0
  58. package/dist/modules/order/lifecycle.d.ts +353 -0
  59. package/dist/modules/order/lifecycle.js +1109 -0
  60. package/dist/modules/order/manager.d.ts +271 -5
  61. package/dist/modules/order/manager.js +651 -48
  62. package/dist/modules/order/placement_lock.d.ts +102 -0
  63. package/dist/modules/order/placement_lock.js +222 -0
  64. package/dist/modules/order/strategy.js +13 -1
  65. package/dist/modules/order/sync_engine.d.ts +13 -1
  66. package/dist/modules/order/sync_engine.js +153 -53
  67. package/dist/modules/order/utils/math.d.ts +22 -1
  68. package/dist/modules/order/utils/math.js +54 -1
  69. package/dist/modules/order/utils/order.d.ts +75 -5
  70. package/dist/modules/order/utils/order.js +158 -9
  71. package/dist/modules/order/utils/system.d.ts +18 -0
  72. package/dist/modules/order/utils/system.js +84 -8
  73. package/dist/modules/order/utils/validate.d.ts +7 -1
  74. package/dist/modules/order/utils/validate.js +48 -2
  75. package/dist/modules/outcome.d.ts +54 -0
  76. package/dist/modules/outcome.js +51 -0
  77. package/dist/modules/settings_merge.d.ts +4 -0
  78. package/dist/modules/settings_merge.js +9 -0
  79. package/dist/modules/timing_policy.d.ts +82 -0
  80. package/dist/modules/timing_policy.js +244 -0
  81. package/dist/modules/types.d.ts +132 -0
  82. package/dist/scripts/analyze-credit.js +54 -17
  83. package/dist/scripts/analyze-orders.d.ts +4 -2
  84. package/dist/scripts/analyze-orders.js +113 -34
  85. package/dist/scripts/chart_targets.js +11 -15
  86. package/dist/scripts/test-credit-renewal.js +12 -5
  87. package/docs/COW_INVARIANTS.md +67 -8
  88. package/docs/DEXBOT_COMPARISON.md +6 -6
  89. package/docs/EVOLUTION.md +9 -8
  90. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  91. package/docs/GRID_PRICE_INVARIANT.md +1 -1
  92. package/docs/GRID_RECONCILE.md +17 -12
  93. package/docs/LOGGING.md +25 -1
  94. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +175 -26
  95. package/docs/README.md +23 -2
  96. package/docs/WORKFLOW.md +9 -3
  97. package/docs/architecture.md +42 -5
  98. package/docs/developer_guide.md +25 -8
  99. package/modules/README.md +3 -0
  100. package/package.json +1 -1
  101. package/scripts/README.md +16 -0
  102. package/scripts/pdev.sh +14 -1
  103. package/scripts/pmain.sh +23 -8
  104. package/scripts/ptest.sh +7 -0
  105. package/tests/README.md +30 -1
@@ -275,8 +275,33 @@ The master grid (`this.orders`) is **immutable** - it can only be replaced atomi
275
275
  | `deepFreeze()` | `manager.ts` | Individual order objects are deep-frozen |
276
276
  | `_gridVersion` | `manager.ts` | Version counter for staleness detection |
277
277
  | `_gridLock` | `manager.ts` | AsyncLock serializes grid mutations |
278
+ | `_placementLock` | `manager.ts` / `placement_lock.ts` | Exclusive placement region: serializes every chain-mutating path (COW broadcast, reconcile Phase 1+2, correction drain, dust/residual cancel, pool swap) |
278
279
  | Encapsulation | `manager.ts` | Index Sets are private; mutations only via `_applyOrderUpdate()` |
279
280
 
281
+ ### Exclusive Placement Region
282
+
283
+ `_gridVersion` protects the MASTER from a stale plan; it does not stop two paths
284
+ from broadcasting at the same time. That is the placement region
285
+ (`modules/order/placement_lock.ts`): a non-reentrant FIFO lease claimed once per
286
+ chain-mutating operation.
287
+
288
+ - Non-token holders use `manager.withPlacement(kind, fn)`, which owns the bounded
289
+ wait, the shutdown probe and the release. The two token-level holders are the
290
+ COW batch body and startup reconcile (they hold the lease across plan →
291
+ broadcast → commit).
292
+ - Nested work must NOT acquire again: it receives the holder's lease and verifies
293
+ it with `manager.isPlacementLeaseCurrent(lease)` — `isPlacementActive()` is true
294
+ for ANY holder, so it cannot prove ownership (a lease invalidated by
295
+ `forceRelease()` would still read as live).
296
+ - Anything that cannot get the region aborts or defers its batch instead of
297
+ broadcasting unprotected (`[PLACEMENT]`/`[DUST]`/`[RESIDUAL]`/`[MAINT]` deferral
298
+ lines).
299
+ - Leak protection: `_clearStalePlacementRegion()` force-releases a region held past
300
+ `TIMING.PLACEMENT_STALE_CLEAR_MS`, refuses while a bot-level pipeline counter
301
+ younger than that bound proves progress, and clears the hung region's stale
302
+ broadcast refcount in the same step. The broadcast-refcount watchdog mirrors the
303
+ rule in reverse (it refuses while a placement lease is held).
304
+
280
305
  ### Master Grid Update Pattern
281
306
 
282
307
  All master grid updates follow clone-and-replace semantics:
@@ -483,7 +508,10 @@ The correction path is fund-only and never manufactures budget by shrinking a re
483
508
  is never a correction target: a top-up grows an order at its current price, so
484
509
  it cannot move bestBuy/bestSell and cannot narrow the spread.
485
510
  4. Contiguous gap-slot promotion may extend the window while preserving
486
- MIN_SPREAD_ORDERS and the opposite placed rail.
511
+ MIN_SPREAD_ORDERS and the opposite placed rail. A same-side order already
512
+ **placed inside the band** is absorbed by the slide (it becomes a legal rail
513
+ member); the walk steps over it and promotes only the next empty slot, so a
514
+ placed edge never becomes a duplicate CREATE target.
487
515
  5. If free funds cannot cover every target, place the affordable prefix, then
488
516
  **rotate a resting same-side order** into each unfunded promoted gap slot
489
517
  (same booked size, never a new commitment). A fully allocated rail has ~0
@@ -605,9 +633,15 @@ rail-edge price would teleport the window to that edge (observed: boundary 29
605
633
  anchor — a partial at a far slot is still a real trade, and its residual is the
606
634
  allow-listed case below.
607
635
 
608
- A live order inside the re-typed band still refuses the re-anchor
609
- (`unsafe: placed_order_in_band`) with one deliberate exception: the fill's
610
- **own PARTIAL residual** at the anchor slot (same side, same ladder level) is
636
+ A move that strands **strictly fewer** placed orders than the committed boundary
637
+ is accepted as a violation-reducing repair; an equal count still refuses
638
+ (canonical statement: `INV-COW-006` in
639
+ [COW_INVARIANTS.md](COW_INVARIANTS.md#cow-pipeline) — this section is
640
+ its rationale, not a second definition). The
641
+ comparison uses `validatePersistedBoundary`'s own in-band count
642
+ (`boundaryMoveReducesStrands`), so the fill re-anchor and the rail clamp cannot
643
+ disagree about what "stranded" means. Within that bound, the fill's **own
644
+ PARTIAL residual** at the anchor slot (same side, same ladder level) is
611
645
  allow-listed, because any boundary that puts the fill outside its window
612
646
  necessarily puts that remainder inside the band. A partial fill therefore no
613
647
  longer deadlocks the geometry; GAP-EVAC cleans the residual afterwards.
@@ -668,7 +702,10 @@ GAP-EVAC / the next plan owns the offending order. The result is then passed
668
702
  through the shared `validatePersistedBoundary` gate (skipped only for a sparse
669
703
  ladder, whose array-length ceiling would reject everything), with the slots the
670
704
  batch cancels or rotates away allow-listed — so the rail clamp and the re-anchor
671
- cannot disagree about what "stranded in the band" means.
705
+ cannot disagree about what "stranded in the band" means. The gate accepts a
706
+ candidate that strands **strictly fewer** placed orders than the committed
707
+ boundary (the same violation-reducing rule the re-anchor uses), which is what
708
+ lets a fill-derived retreat land while GAP-EVAC is still draining older strands.
672
709
 
673
710
  ### Live-Price Provenance (fill, gap, crossing)
674
711
 
@@ -907,18 +907,32 @@ _finishStartupSequence()
907
907
 
908
908
  **Critical Rule: Always acquire locks in ascending level order**
909
909
 
910
- The canonical 5-level hierarchy (defined at `manager.ts`):
910
+ The canonical hierarchy (defined at `manager.ts`):
911
911
 
912
912
  ```
913
- Level 0: _fillProcessingLock (fill processing — outermost)
914
- Level 1: _divergenceLock (divergence checks)
915
- Level 2: _syncLock (sync operations — timeout-protected)
916
- Level 3: _gridLock (grid mutations)
917
- Level 4: _fundLock (fund operations — innermost)
913
+ Level 0: _fillProcessingLock (fill processing — outermost)
914
+ Level 0.5: placement region (exclusive chain-mutation mutex — PlacementLock)
915
+ Level 1: _divergenceLock (divergence checks)
916
+ Level 2: _syncLock (sync operations — timeout-protected)
917
+ Level 3: _gridLock (grid mutations)
918
+ Level 4: _fundLock (fund operations — innermost)
918
919
  ```
919
920
 
920
- All five locks live on the `OrderManager` instance. The `level` property is a
921
- convention marker — AsyncLock does not enforce it at runtime.
921
+ All levels live on the `OrderManager` instance (the placement region is
922
+ `_placementLock`, see `modules/order/placement_lock.ts`). The `level` property
923
+ is a convention marker — AsyncLock does not enforce it at runtime, and
924
+ `PlacementLock` is not an AsyncLock (it is a FIFO, non-reentrant lease).
925
+
926
+ **Placement region (Level 0.5)** serializes every chain-mutating path: COW
927
+ broadcasts, reconcile Phase 1+2, correction drains, dust/residual cancels and
928
+ pool swaps. It is acquired **before** `_gridLock` and never while holding it,
929
+ and it is `NOT` reentrant — nested work receives the holder's lease instead of
930
+ acquiring again, and verifies it with `manager.isPlacementLeaseCurrent(lease)`
931
+ (`isPlacementActive()` is true for ANY holder and must not be used for that).
932
+ The canonical region order is:
933
+ `startBroadcasting → placement → gridLock → fundLock → release placement → stopBroadcasting`.
934
+ A leaked region is force-released by `_clearStalePlacementRegion()`, which also
935
+ drops the hung region's stale broadcast refcount in the same step.
922
936
 
923
937
  **Why This Order?**
924
938
 
@@ -926,6 +940,9 @@ convention marker — AsyncLock does not enforce it at runtime.
926
940
  - Divergence checks (Level 1) nest inside fill processing
927
941
  - Sync operations (Level 2) are acquired before grid mutations — the timeout-protected lock is inner, so a stuck sync releases the outer lock
928
942
  - Grid mutations (Level 3) and fund operations (Level 4) are innermost
943
+ - The placement region (Level 0.5) sits between fill processing and the grid
944
+ locks: it is broader than one grid mutation (it spans plan → broadcast →
945
+ commit) but must never be taken while a grid lock is held
929
946
  - All paths follow the same order
930
947
 
931
948
  **`adjustTotalBalance` Locking Contract** (v1.4.7):
package/modules/README.md CHANGED
@@ -70,6 +70,7 @@ modules/
70
70
  ├── chain_keys.ts master-password vault + signing-key retrieval
71
71
  ├── daemon_node_health.ts daemon-side node failure ledger (shared rules)
72
72
  ├── node_failure_ledger.ts node failure counting shared by bot + daemon
73
+ ├── node_flap_score.ts time-decayed connection-churn score used for node ranking
73
74
  ├── node_health_cache.ts shared node-health cache file I/O + ordering
74
75
  ├── socket_json_client.ts newline-delimited JSON Unix-socket client
75
76
  ├── market_adapter_whitelist.ts adapter whitelist I/O
@@ -98,9 +99,11 @@ modules/
98
99
  │ ├── strategy.ts grid rebalancing, consolidation, rotation
99
100
  │ ├── accounting.ts fund tracking, fee accounting
100
101
  │ ├── sync_engine.ts blockchain sync, fill detection, reconciliation
102
+ │ ├── lifecycle.ts one record per slot: chain existence, phase, evidence, clocks (docs/ORDER_LIFECYCLE.md)
101
103
  │ ├── genesis_policy.ts missing-ladder refusal + rebuild policy (docs/GRID_PRICE_INVARIANT.md)
102
104
  │ ├── grid_reconcile.ts startup grid reconciliation (docs/GRID_RECONCILE.md)
103
105
  │ ├── grid_reconcile_internal.ts internal grid reconciliation helpers
106
+ │ ├── placement_lock.ts exclusive chain-mutating region: FIFO lease, non-reentrant, bounded wait
104
107
  │ ├── index.ts barrel export
105
108
  │ ├── logger.ts order-scoped logging
106
109
  │ ├── logger_state.ts logger state management
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dexbot",
3
- "version": "1.7.0",
3
+ "version": "1.7.1",
4
4
  "description": "The first open source trading bot with zero runtime dependencies and a fully adaptive market making strategy.",
5
5
  "main": "dist/modules/dexbot_class.js",
6
6
  "exports": {
package/scripts/README.md CHANGED
@@ -67,8 +67,14 @@ All are irreversible and prompt for confirmation.
67
67
  ```bash
68
68
  # Analyzes spread accuracy, geometric consistency, and fund distribution
69
69
  node dist/scripts/analyze-orders.js
70
+
71
+ # One bot (name or key), or every grid on one account (name or 1.2.x id)
72
+ node dist/scripts/analyze-orders.js <bot|account>
70
73
  ```
71
74
 
75
+ Bot/account targets share one rule set with `dexbot credit`, `dexbot pnl` and
76
+ the chart commands (`analysis/bot_key_utils.ts`).
77
+
72
78
  For AMA bots (`gridPrice: ama`) the analyzer reads `<botKey>.dynamicgrid.json`
73
79
  and, when fresh (`2 × MARKET_ADAPTER.RUNTIME_DEFAULTS.pollSeconds`, default 2h),
74
80
  shows live weights with color: higher = red (losing), lower = green (winning),
@@ -84,6 +90,9 @@ node dist/scripts/analyze-credit.js
84
90
 
85
91
  # Single bot (name or key)
86
92
  node dist/scripts/analyze-credit.js <bot>
93
+
94
+ # Every bot trading one account (preferredAccount name or 1.2.x id)
95
+ node dist/scripts/analyze-credit.js <account>
87
96
  ```
88
97
  Credit deals report per-pair and average CR, but only for pairs whitelisted in `bots.json` (`debtPolicy.lending`) and listed on the current credit offer; everything else is shown as ignored/unpriced and excluded from the average. A borrow-now preview per configured pair shows today's rate.
89
98
 
@@ -301,6 +310,13 @@ npm run version:sync
301
310
  | `pdev.sh` | `npm run pdev` | sync `test` → `dev` |
302
311
  | `pmain.sh` | `npm run pmain` | sync `test` → `dev` → `main` |
303
312
 
313
+ Before any push, all three scripts run a shared preflight
314
+ (`scripts/lib/git_preflight.sh`): one read-only `git ls-remote` against `origin`,
315
+ so an unreachable remote or a key the server no longer accepts fails **before** a
316
+ branch moves. `pmain.sh` mirrors `dev` and `main` in a single `--atomic` push —
317
+ either both move or neither does. Set `DEXBOT_SKIP_GIT_PREFLIGHT=1` to bypass
318
+ the preflight.
319
+
304
320
  ---
305
321
 
306
322
  ## ⚡ CONVENIENCE WRAPPERS
package/scripts/pdev.sh CHANGED
@@ -7,6 +7,13 @@ set -e
7
7
 
8
8
  echo "🔄 Starting safe branch synchronization (test -> dev)..."
9
9
 
10
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
+ # shellcheck source=scripts/lib/git_preflight.sh
12
+ source "$SCRIPT_DIR/lib/git_preflight.sh"
13
+
14
+ # 0. Fail fast when the remote cannot be read — before any branch is touched.
15
+ require_origin_access origin || exit 1
16
+
10
17
  # 1. Ensure we are on 'test'
11
18
  CURRENT=$(git rev-parse --abbrev-ref HEAD)
12
19
  if [ "$CURRENT" != "test" ]; then
@@ -31,8 +38,14 @@ echo "🚀 Synchronizing 'dev' with 'test' on origin..."
31
38
  git push origin test:dev --force
32
39
 
33
40
  # 5. Update local 'dev' branch pointer to match origin
41
+ # Best-effort: the push above already moved origin/dev, so a failure here is
42
+ # cosmetic (a stale local label) and self-heals on the next successful fetch.
34
43
  echo "📍 Updating local 'dev' branch pointer..."
35
- git fetch origin dev:dev --force
44
+ if ! git fetch origin dev:dev --force; then
45
+ echo "⚠️ Local 'dev' pointer was not refreshed — origin/dev is already synced."
46
+ echo " Re-run 'npm run pdev' once the remote is reachable again."
47
+ exit 1
48
+ fi
36
49
 
37
50
  echo "✅ Synchronization complete: test == dev"
38
51
  echo "✨ Your uncommitted changes on 'test' were never at risk."
package/scripts/pmain.sh CHANGED
@@ -8,6 +8,13 @@ set -e
8
8
 
9
9
  echo "🔄 Starting safe branch synchronization..."
10
10
 
11
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12
+ # shellcheck source=scripts/lib/git_preflight.sh
13
+ source "$SCRIPT_DIR/lib/git_preflight.sh"
14
+
15
+ # 0. Fail fast when the remote cannot be read — before any branch is touched.
16
+ require_origin_access origin || exit 1
17
+
11
18
  # 1. Ensure we are on 'test'
12
19
  CURRENT=$(git rev-parse --abbrev-ref HEAD)
13
20
  if [ "$CURRENT" != "test" ]; then
@@ -28,17 +35,25 @@ if ! git push origin test; then
28
35
  exit 1
29
36
  fi
30
37
 
31
- # 4. Force update 'dev' and 'main' on origin (Zero-Checkout)
32
- # This updates the server branches directly from your local test branch
33
- echo "🚀 Synchronizing 'dev' and 'main' on origin..."
34
- git push origin test:dev --force
35
- git push origin test:main --force
38
+ # 4. Force update 'dev' and 'main' on origin in ONE atomic push (Zero-Checkout)
39
+ # --atomic makes the mirror all-or-nothing: either both branches move or neither
40
+ # does, so a refusal can never leave dev ahead of main.
41
+ echo "🚀 Synchronizing 'dev' and 'main' with 'test' on origin (atomic)..."
42
+ if ! git push --atomic origin test:dev test:main --force; then
43
+ echo "❌ Atomic push to dev/main failed — neither branch was moved."
44
+ echo "⚠️ Please check 'git status' or sync manually."
45
+ exit 1
46
+ fi
36
47
 
37
48
  # 5. Update local branch pointers to match origin
38
- # This makes your local 'dev' and 'main' labels match without switching to them
49
+ # Best-effort: the atomic push above already moved origin, so a failure here is
50
+ # cosmetic (a stale local label) and self-heals on the next successful fetch.
39
51
  echo "📍 Updating local branch pointers..."
40
- git fetch origin dev:dev --force
41
- git fetch origin main:main --force
52
+ if ! git fetch origin dev:dev main:main --force; then
53
+ echo "⚠️ Local 'dev'/'main' pointers were not refreshed — origin is already synced."
54
+ echo " Re-run 'npm run pmain' once the remote is reachable again."
55
+ exit 1
56
+ fi
42
57
 
43
58
  echo "✅ Everything is synchronized: test == dev == main"
44
59
  echo "✨ Your uncommitted changes on 'test' were never at risk."
package/scripts/ptest.sh CHANGED
@@ -7,6 +7,13 @@ set -e
7
7
 
8
8
  echo "🔄 Starting safe branch synchronization (test -> origin/test)..."
9
9
 
10
+ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
11
+ # shellcheck source=scripts/lib/git_preflight.sh
12
+ source "$SCRIPT_DIR/lib/git_preflight.sh"
13
+
14
+ # 0. Fail fast when the remote cannot be read — before any branch is touched.
15
+ require_origin_access origin || exit 1
16
+
10
17
  # 1. Ensure we are on 'test'
11
18
  CURRENT=$(git rev-parse --abbrev-ref HEAD)
12
19
  if [ "$CURRENT" != "test" ]; then
package/tests/README.md CHANGED
@@ -33,7 +33,7 @@ claw/tests/ # Claw integration tests (same conventions, run by npm test)
33
33
  - `bitshares_client_stub.ts` — mock blockchain client
34
34
  - `chain_orders_stub.ts` — order lifecycle test doubles
35
35
  - `fee_cache_init.ts` — fee cache seeding for tests
36
- - `order_test_helpers.ts` — order construction utilities
36
+ - `order_test_helpers.ts` — order construction utilities + genesis ladders (`ageChainIdAssignment` settles a fixture's fresh chain id so absence scenarios test the decision, not the in-flight guard)
37
37
  - `silent_logger.ts` — suppresses log output during tests
38
38
  - `module_cache_stub.ts` — isolates module state per test
39
39
  - `vault_fixture.ts` — chain-key vault fixtures
@@ -80,6 +80,10 @@ Research/analysis tools: chart generators, backtests, and the grid-reset replay
80
80
  Order lifecycle, fill processing, trade history, batch execution.
81
81
  *Examples:* `test_open_orders.ts`, `test_fills.ts`, `test_fill_batch_chunking.ts`, `test_fill_replay_guards.ts`, `test_uncertain_broadcast.ts`
82
82
 
83
+ ### Order Lifecycle Registry
84
+ The single answer to "does this order exist on chain, and how sure are we" ([ORDER_LIFECYCLE.md](../docs/ORDER_LIFECYCLE.md)): phases (`unknown ≠ gone`), evidence monotonicity, the unresolved bound, the write funnel (including the COW whole-map commit), and the unified absence guard the sync/reconcile/recovery sites share.
85
+ *Files:* `test_order_lifecycle.ts` (registry + manager integration), `recon_fuzz.ts` (interleaving fuzzer; `RECON_FUZZ_SCENARIOS`/`RECON_FUZZ_STEPS` scale it)
86
+
83
87
  ### Strategy & Grid Logic
84
88
  Grid generation, sizing, rotation, divergence detection, reconciliation.
85
89
  *Examples:* `test_order_grid.ts`, `test_strategy_logic.ts`, `test_grid_reconcile.ts`, `test_working_grid.ts`, `test_rotation_order_sizing.ts`, `test_strategy_edge_cases.ts`, `test_edge_orders.ts`
@@ -204,3 +208,28 @@ Shared utility functions, precision handling, chain helpers.
204
208
  ---
205
209
 
206
210
  **Note:** Interactive/diagnostic scripts (`connection_test.ts`, `diag_*`, `benchmark_cow.ts`, `sim_batching.ts`, `repro_phantom_orders.ts`) require network access or real state and are **not** run by `npm test` — the runner only globs `test_*.js`. Run these manually when debugging.
211
+
212
+ ## Harnesses (not run by `npm test`)
213
+
214
+ Two files are investigative harnesses rather than assertions about production
215
+ code, so they are deliberately *not* `test_*.ts`:
216
+
217
+ - `recon_fuzz.ts` — the interleaving fuzzer for the reconciliation engine. Drives
218
+ the real `SyncEngine` against a scripted chain (landed / vanished / partially
219
+ filled / orphaned / duplicated / lagging / unparseable reads), asserts
220
+ policy-free invariants after **every** event, and shrinks a failing sequence to
221
+ a seed + step count.
222
+
223
+ ```bash
224
+ npm run build:tests
225
+ node dist/tests/recon_fuzz.js # 40 scenarios × 25 steps
226
+ RECON_FUZZ_SCENARIOS=120 RECON_FUZZ_STEPS=40 node dist/tests/recon_fuzz.js
227
+ RECON_FUZZ_TRACE=1 RECON_FUZZ_DEBUG=1 node dist/tests/recon_fuzz.js
228
+ ```
229
+
230
+ `RECON_FUZZ_SEED=<n> RECON_FUZZ_STEPS=<n>` replays a reported failure. The run
231
+ fails if the scenarios are vacuous (coverage floors on placed-slot
232
+ observations and on un-adoptable orphans), so a green run means the engine was
233
+ actually exercised.
234
+
235
+ - `sim_batching.ts` — arithmetic mirror of the gap-slot batch sizing rule.