dexbot 1.6.1 → 1.6.3

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 (104) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/analysis/README.md +2 -2
  3. package/analysis/ama_fitting/package.json +1 -1
  4. package/analysis/grid_correction_check.ts +80 -7
  5. package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +2455 -0
  6. package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +218 -0
  7. package/analysis/tradingview/h-bts_tradingview.html +1570 -0
  8. package/analysis/tradingview/t-bts_tradingview.html +1570 -0
  9. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +19 -5
  10. package/analysis/trend_detection/package.json +1 -1
  11. package/claw/package.json +1 -1
  12. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  13. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  14. package/claw/tests/test_claw_mcp_transport.ts +2 -2
  15. package/dist/analysis/grid_correction_check.d.ts +5 -1
  16. package/dist/analysis/grid_correction_check.d.ts.map +1 -1
  17. package/dist/analysis/grid_correction_check.js +81 -7
  18. package/dist/analysis/grid_correction_check.js.map +1 -1
  19. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
  20. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +19 -5
  21. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
  22. package/dist/market_adapter/inputs/fetch_book_data.js +2 -2
  23. package/dist/market_adapter/inputs/fetch_book_data.js.map +1 -1
  24. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +22 -3
  25. package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
  26. package/dist/market_adapter/inputs/fetch_lp_data.js +15 -15
  27. package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
  28. package/dist/market_adapter/inputs/kibana_feed_source.js +2 -2
  29. package/dist/market_adapter/inputs/kibana_feed_source.js.map +1 -1
  30. package/dist/market_adapter/inputs/window_cache.d.ts +54 -8
  31. package/dist/market_adapter/inputs/window_cache.d.ts.map +1 -1
  32. package/dist/market_adapter/inputs/window_cache.js +328 -87
  33. package/dist/market_adapter/inputs/window_cache.js.map +1 -1
  34. package/dist/modules/bitshares-native/subscriptions.d.ts +1 -1
  35. package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
  36. package/dist/modules/bitshares-native/subscriptions.js +18 -4
  37. package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
  38. package/dist/modules/bitshares_client.d.ts.map +1 -1
  39. package/dist/modules/bitshares_client.js +10 -0
  40. package/dist/modules/bitshares_client.js.map +1 -1
  41. package/dist/modules/constants.d.ts +7 -3
  42. package/dist/modules/constants.d.ts.map +1 -1
  43. package/dist/modules/constants.js +44 -20
  44. package/dist/modules/constants.js.map +1 -1
  45. package/dist/modules/credit_runtime.d.ts.map +1 -1
  46. package/dist/modules/credit_runtime.js +24 -6
  47. package/dist/modules/credit_runtime.js.map +1 -1
  48. package/dist/modules/dexbot_class.d.ts +32 -7
  49. package/dist/modules/dexbot_class.d.ts.map +1 -1
  50. package/dist/modules/dexbot_class.js +55 -11
  51. package/dist/modules/dexbot_class.js.map +1 -1
  52. package/dist/modules/dexbot_cow_runtime.d.ts +137 -7
  53. package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
  54. package/dist/modules/dexbot_cow_runtime.js +955 -45
  55. package/dist/modules/dexbot_cow_runtime.js.map +1 -1
  56. package/dist/modules/dexbot_fill_runtime.d.ts +28 -1
  57. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
  58. package/dist/modules/dexbot_fill_runtime.js +116 -3
  59. package/dist/modules/dexbot_fill_runtime.js.map +1 -1
  60. package/dist/modules/dexbot_maintenance_runtime.d.ts +46 -0
  61. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
  62. package/dist/modules/dexbot_maintenance_runtime.js +193 -6
  63. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
  64. package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
  65. package/dist/modules/dexbot_startup_runtime.js +6 -1
  66. package/dist/modules/dexbot_startup_runtime.js.map +1 -1
  67. package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
  68. package/dist/modules/dexbot_state_recovery.js +16 -3
  69. package/dist/modules/dexbot_state_recovery.js.map +1 -1
  70. package/dist/modules/order/grid.d.ts +3 -1
  71. package/dist/modules/order/grid.d.ts.map +1 -1
  72. package/dist/modules/order/grid.js +47 -6
  73. package/dist/modules/order/grid.js.map +1 -1
  74. package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
  75. package/dist/modules/order/grid_reconcile_internal.js +39 -4
  76. package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
  77. package/dist/modules/order/manager.d.ts.map +1 -1
  78. package/dist/modules/order/manager.js +3 -1
  79. package/dist/modules/order/manager.js.map +1 -1
  80. package/dist/modules/order/sync_engine.d.ts.map +1 -1
  81. package/dist/modules/order/sync_engine.js +200 -15
  82. package/dist/modules/order/sync_engine.js.map +1 -1
  83. package/dist/modules/order/utils/math.d.ts +60 -14
  84. package/dist/modules/order/utils/math.d.ts.map +1 -1
  85. package/dist/modules/order/utils/math.js +87 -20
  86. package/dist/modules/order/utils/math.js.map +1 -1
  87. package/dist/modules/order/utils/order.d.ts +95 -7
  88. package/dist/modules/order/utils/order.d.ts.map +1 -1
  89. package/dist/modules/order/utils/order.js +277 -15
  90. package/dist/modules/order/utils/order.js.map +1 -1
  91. package/dist/modules/utils/errors.d.ts +22 -0
  92. package/dist/modules/utils/errors.d.ts.map +1 -1
  93. package/dist/modules/utils/errors.js +30 -0
  94. package/dist/modules/utils/errors.js.map +1 -1
  95. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
  96. package/docs/DEXBOT_COMPARISON.md +3 -7
  97. package/docs/EVOLUTION.md +9 -7
  98. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +4 -9
  99. package/docs/LIFECYCLE.md +2 -2
  100. package/docs/README.md +9 -1
  101. package/docs/architecture.md +7 -7
  102. package/docs/developer_guide.md +4 -4
  103. package/market_adapter/README.md +1 -1
  104. package/package.json +1 -1
package/docs/LIFECYCLE.md CHANGED
@@ -105,7 +105,7 @@ sequenceDiagram
105
105
  ```
106
106
 
107
107
  Why it matters:
108
- - **Fixed-cap batching** (`MAX_FILL_BATCH_SIZE`, default 4) keeps bursts
108
+ - **Gap-slot batching** (batch size = grid gap-slot count, `DEXBot._getGapSlotBatchSize`) keeps bursts
109
109
  deterministic — see `docs/architecture.md` §"Fill Processing Pipeline".
110
110
  - **Single rebalance cycle**: all fills in a batch share one broadcast, so proceeds
111
111
  are immediately available for replacement sizing (no split-across-cycles delay).
@@ -179,7 +179,7 @@ enforced*, not compiler-enforced — learn them or you will introduce fund bugs.
179
179
  | **Fund SSOT** | `Accounting` owns every fund number. Nothing else computes available funds. | `docs/architecture.md` §"Fund Flow Architecture" |
180
180
  | **Replay-safe fills** | A fill is credited exactly once via processed-fill keys; retries are idempotent. | `modules/dexbot_fill_runtime.ts` |
181
181
  | **Single broadcast per cycle** | One `updateOrdersOnChainBatch` per rebalance — never scatter writes. | `docs/architecture.md` §"Fill Processing Pipeline" |
182
- | **Browser/Node split** | Heavy runtime is Node-only; never import it from a browser bundle. | `AGENTS.md` "Browser-Safe Surface", `docs/BROWSER_COMPAT_PLAN.md` |
182
+ | **Browser/Node split** | Heavy runtime is Node-only; never import it from a browser bundle. | `AGENTS.md` "Browser-Safe Surface", `package.json` "browser" field |
183
183
  | **Lock ordering** | Fill drain and maintenance must not run a rebalance concurrently. | `docs/developer_guide.md` §"Startup Sequence & Lock Ordering" |
184
184
 
185
185
  ---
package/docs/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  This directory contains the comprehensive technical documentation for the DEXBot2 trading bot. It is designed to guide developers from high-level architecture down to the nuances of fund accounting and state management.
4
4
 
5
- **Version context:** v1.6.1 (released).
5
+ **Version context:** v1.6.3 (released).
6
6
 
7
7
  ---
8
8
 
@@ -162,6 +162,14 @@ This directory contains the comprehensive technical documentation for the DEXBot
162
162
  - **Test mapping**: Links each invariant to regression tests
163
163
  - **Review checklist**: Quick-use verification for COW/accounting changes
164
164
 
165
+ ### 📐 [Grid-Price Invariant](GRID_PRICE_INVARIANT.md)
166
+ *Why a slot's emitted price must equal its genesis level — and how that failed.*
167
+ - **The invariant**: `order.price === priceForSlot(idx, genesis)`, and why range guards cannot substitute for it
168
+ - **Failure mechanism**: Chain price overwriting slot identity, pre-broadcast substitution, untrusted fill-guard pivot
169
+ - **Enforcement**: The six emission sites, the blocking rejection of off-grid emissions, and the fail-open policy on unjudgeable inputs
170
+ - **Out-of-bounds policy**: Hold and surface; refill in-grid slots at their genesis price
171
+ - **Status**: What is landed, what remains open, and why the removed 5% sanity gate must not be naively re-landed
172
+
165
173
  ### 🧪 [Test Suite](../tests/README.md)
166
174
  *Test organization, categories, and key architectural patterns tested.*
167
175
  - **Test Layout**: Directory structure, helpers, and quick-start commands
@@ -377,13 +377,13 @@ The fill pipeline handles incoming filled orders efficiently through fixed-cap b
377
377
  ↓
378
378
  ┌─────────────────────────────────────────────────────────────┐
379
379
  │ processFilledOrders() - Entry Point │
380
- │ Use MAX_FILL_BATCH_SIZE cap for deterministic batching │
381
- │ Rules: <=cap unified, >cap chunked at cap size │
380
+ │ Use gap-slot batch size for deterministic batching │
381
+ │ Rules: <=gapSlots unified, >gapSlots chunked │
382
382
  └─────────────────────┬───────────────────────────────────────┘
383
383
  ↓
384
384
  ┌─────────────────────────────────────────────────────────────┐
385
- │ Pop Batch (up to MAX_FILL_BATCH_SIZE) │
386
- │ Takes N fills from queue head (N = 1-4) │
385
+ │ Pop Batch (up to gapSlots) │
386
+ │ Takes N fills from queue head (N = 1..gapSlots) │
387
387
  │ Example: pops [fill1, fill2, fill3] for batch processing │
388
388
  └─────────────────────┬───────────────────────────────────────┘
389
389
  ↓
@@ -418,9 +418,9 @@ The fill pipeline handles incoming filled orders efficiently through fixed-cap b
418
418
 
419
419
  ### Key Properties
420
420
 
421
- - **Fixed-Cap Batch Sizing**: Batch size is deterministic with `MAX_FILL_BATCH_SIZE` (default 4)
422
- - 1..4 awaiting: single unified batch (one rebalance/broadcast cycle)
423
- - 5+ awaiting: repeated chunks of 4 (last chunk may be smaller)
421
+ - **Gap-Slot Batch Sizing**: Batch size is deterministic, derived from the grid gap-slot count (`DEXBot._getGapSlotBatchSize`)
422
+ - 1..gapSlots awaiting: single unified batch (one rebalance/broadcast cycle)
423
+ - more than gapSlots awaiting: repeated chunks of gapSlots (last chunk may be smaller)
424
424
 
425
425
  - **Single Rebalance Cycle**: All fills in batch processed in ONE rebalance
426
426
  - No "split across cycles" delays
@@ -39,7 +39,7 @@ Follow this path through the codebase:
39
39
  ```
40
40
 
41
41
  **Additional Resources**:
42
- - `modules/constants.ts::FILL_PROCESSING` - Batch configuration (`MAX_FILL_BATCH_SIZE`)
42
+ - `modules/constants.ts::FILL_PROCESSING` - Fill-event handling configuration (batch sizing is gap-slot derived, see `DEXBot._getGapSlotBatchSize`)
43
43
  - `modules/constants.ts::PIPELINE_TIMING` - Recovery configuration (RECOVERY_RETRY_INTERVAL_MS, MAX_RECOVERY_ATTEMPTS)
44
44
  - `modules/constants.ts::MARKET_ADAPTER` - AMA, dynamic weight, and regime detection defaults
45
45
  - `modules/constants.ts::REGIME_TABLE` - Hurst/PE regime signal-strength table
@@ -79,7 +79,7 @@ A **phantom order** is an order in ACTIVE/PARTIAL state WITHOUT a valid `orderId
79
79
 
80
80
  | Term | Meaning |
81
81
  |------|---------|
82
- | **Fixed-Cap Batch Fill Processing** | Groups fills with a hard cap using `MAX_FILL_BATCH_SIZE` (default 4): `<= cap` uses one unified batch; `> cap` chunks at cap size. In the documented 29-fill Feb 7 crash scenario, this reduces the estimated divergence window from ~90s to ~24s; see [`FUND_MOVEMENT_AND_ACCOUNTING.md`](FUND_MOVEMENT_AND_ACCOUNTING.md#15-fill-batch-processing--timeline). |
82
+ | **Gap-Slot Batch Fill Processing** | Groups fills using the grid gap-slot count as batch size (`DEXBot._getGapSlotBatchSize`): `<= gapSlots` uses one unified batch; `> gapSlots` chunks at gapSlots. In the documented 29-fill Feb 7 crash scenario, this reduces the estimated divergence window from ~90s to ~24s; see [`FUND_MOVEMENT_AND_ACCOUNTING.md`](FUND_MOVEMENT_AND_ACCOUNTING.md#15-fill-batch-processing--timeline). |
83
83
  | **Recovery Retry System** | Count+time-based retry mechanism with periodic reset. Replaces one-shot `_recoveryAttempted` flag. Max 5 attempts per episode with 60s minimum interval between retries. |
84
84
  | **Orphan-Fill Deduplication** | Map+TTL-based tracking of stale-cleaned order IDs to prevent double-crediting. Delayed orphan fill events are still blocked by checking `_staleCleanedOrderIds`. |
85
85
 
@@ -171,8 +171,8 @@ A **phantom order** is an order in ACTIVE/PARTIAL state WITHOUT a valid `orderId
171
171
  | **Atomic Check-and-Deduct** | Verify funds + deduct in single operation |
172
172
  | **Divergence Detection** | Comparing ideal grid vs. persisted grid |
173
173
  | **Invariant Verification** | Checking fund accounting consistency |
174
- | **Batch Processing** | Grouping multiple fills into a single rebalance cycle instead of one-at-a-time. Fixed-cap sizing: `<= MAX_FILL_BATCH_SIZE` unified, otherwise chunked at cap size (default max 4). |
175
- | **Fixed-Cap Batch Sizing** | Deterministic chunking model with hard upper bound per broadcast. Keeps throughput high while avoiding tier-lookup complexity. |
174
+ | **Batch Processing** | Grouping multiple fills into a single rebalance cycle instead of one-at-a-time. Gap-slot sizing: `<= gapSlots` unified, otherwise chunked at gapSlots. |
175
+ | **Gap-Slot Batch Sizing** | Deterministic chunking model with the grid gap-slot count as the per-broadcast bound. Keeps throughput high while avoiding tier-lookup complexity. |
176
176
  | **Stale-Order Recovery** | Fast-path recovery for single-operation batches that encounter stale orders on-chain. Executes cleanup without full state sync. |
177
177
  | **Orphan-Fill Prevention** | Deduplication mechanism that prevents double-crediting fills from stale-cleaned orders using timestamp-based ID tracking (TTL pruning). |
178
178
 
@@ -854,7 +854,7 @@ closed 1h candles.
854
854
 
855
855
  #### Shared Chunk Cache and Fetch Robustness
856
856
 
857
- Pool, book, and feed candle fetches share one cache entry point (`runCachedWindows` in `market_adapter/inputs/window_cache.ts`): sibling chunk files load once, only missing buckets plus a bounded 48h tail refresh are queried, and chunk metas record the ranges actually queried (`meta.queriedRanges`). A missing range is pruned only when recorded query coverage genuinely covers it — the absence of local buckets alone never certifies history as empty. Partial windows merge into the run output but are never persisted, and orphan chunks are deleted after complete runs only. Every range fetch runs through `fetchRangeWithRetry` (per-range attempts + linear backoff + abort-signal timeout; the LP path keeps a 4-attempt budget), one-shot Kibana queries retry transient errors (3 attempts), paged fetchers cap at `kibanaMaxPages` (500), and bidirectional fetches tolerate a one-direction failure.
857
+ Pool, book, and feed candle fetches share one cache entry point (`runCachedWindows` in `market_adapter/inputs/window_cache.ts`): candles live in fixed calendar-month shards (`<base>.shard_YYYY-MM.json`, UTC) whose names never shift, so a run loads only the shards overlapping its requested range, queries only genuinely missing buckets plus a bounded 48h tail refresh, and rewrites only shards that gained buckets or query coverage — pure-reuse runs perform zero writes and zero deletes. Shard metas record the ranges actually queried (`meta.queriedRanges`, monotonically unioned). A missing range is pruned only when recorded query coverage genuinely covers it — the absence of local buckets alone never certifies history as empty. Partial windows merge into the run output but are never persisted. Legacy run-relative `*.chunk_*` files are still read: overlapping ones are absorbed into the shards (buckets + coverage) and retired once every bucket provably lives in a shard, while disjoint ones are never loaded and never deleted — narrow runs cannot wipe older history by construction. Every range fetch runs through `fetchRangeWithRetry` (per-range attempts + linear backoff + abort-signal timeout; the LP path keeps a 4-attempt budget), one-shot Kibana queries retry transient errors (3 attempts), paged fetchers cap at `kibanaMaxPages` (500), and bidirectional fetches tolerate a one-direction failure.
858
858
 
859
859
  #### AMA Warmup Window — Why Candle Length Matters
860
860
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dexbot",
3
- "version": "1.6.1",
3
+ "version": "1.6.3",
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": {