dexbot 1.5.1 → 1.5.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 (94) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/analysis/ama_fitting/package.json +1 -1
  3. package/analysis/resolve_source.ts +3 -0
  4. package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +2455 -0
  5. package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +218 -0
  6. package/analysis/tradingview/README.md +5 -1
  7. package/analysis/tradingview/analyze_tradingview.ts +27 -1
  8. package/analysis/tradingview/h-bts_tradingview.html +1570 -0
  9. package/analysis/tradingview/t-bts_tradingview.html +1570 -0
  10. package/analysis/tradingview/tradingview_uplot_chart_generator.ts +351 -22
  11. package/analysis/trend_detection/package.json +1 -1
  12. package/claw/package.json +1 -1
  13. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  14. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  15. package/claw/tests/test_claw_mcp_transport.ts +2 -2
  16. package/dist/analysis/resolve_source.d.ts.map +1 -1
  17. package/dist/analysis/resolve_source.js +3 -0
  18. package/dist/analysis/resolve_source.js.map +1 -1
  19. package/dist/analysis/tradingview/analyze_tradingview.d.ts +3 -0
  20. package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -1
  21. package/dist/analysis/tradingview/analyze_tradingview.js +27 -2
  22. package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -1
  23. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
  24. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +348 -22
  25. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
  26. package/dist/dexbot.js +5 -5
  27. package/dist/dexbot.js.map +1 -1
  28. package/dist/market_adapter/core/asymmetric_bounds.d.ts +33 -1
  29. package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -1
  30. package/dist/market_adapter/core/asymmetric_bounds.js +38 -1
  31. package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
  32. package/dist/modules/dexbot_class.d.ts +2 -18
  33. package/dist/modules/dexbot_class.d.ts.map +1 -1
  34. package/dist/modules/dexbot_cow_runtime.d.ts +38 -37
  35. package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
  36. package/dist/modules/dexbot_cow_runtime.js +722 -557
  37. package/dist/modules/dexbot_cow_runtime.js.map +1 -1
  38. package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
  39. package/dist/modules/dexbot_fill_runtime.js +7 -1
  40. package/dist/modules/dexbot_fill_runtime.js.map +1 -1
  41. package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
  42. package/dist/modules/dexbot_maintenance_runtime.js +31 -51
  43. package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
  44. package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
  45. package/dist/modules/dexbot_startup_runtime.js +42 -3
  46. package/dist/modules/dexbot_startup_runtime.js.map +1 -1
  47. package/dist/modules/order/accounting.d.ts.map +1 -1
  48. package/dist/modules/order/accounting.js +19 -2
  49. package/dist/modules/order/accounting.js.map +1 -1
  50. package/dist/modules/order/export.d.ts +122 -15
  51. package/dist/modules/order/export.d.ts.map +1 -1
  52. package/dist/modules/order/export.js +310 -46
  53. package/dist/modules/order/export.js.map +1 -1
  54. package/dist/modules/order/grid.d.ts.map +1 -1
  55. package/dist/modules/order/grid.js +29 -38
  56. package/dist/modules/order/grid.js.map +1 -1
  57. package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
  58. package/dist/modules/order/grid_reconcile.js +7 -3
  59. package/dist/modules/order/grid_reconcile.js.map +1 -1
  60. package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
  61. package/dist/modules/order/grid_reconcile_internal.js +31 -33
  62. package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
  63. package/dist/modules/order/manager.d.ts +13 -6
  64. package/dist/modules/order/manager.d.ts.map +1 -1
  65. package/dist/modules/order/manager.js +22 -7
  66. package/dist/modules/order/manager.js.map +1 -1
  67. package/dist/modules/order/sync_engine.d.ts.map +1 -1
  68. package/dist/modules/order/sync_engine.js +231 -11
  69. package/dist/modules/order/sync_engine.js.map +1 -1
  70. package/dist/modules/order/utils/math.d.ts +38 -15
  71. package/dist/modules/order/utils/math.d.ts.map +1 -1
  72. package/dist/modules/order/utils/math.js +55 -16
  73. package/dist/modules/order/utils/math.js.map +1 -1
  74. package/dist/modules/order/utils/order.d.ts +116 -20
  75. package/dist/modules/order/utils/order.d.ts.map +1 -1
  76. package/dist/modules/order/utils/order.js +340 -35
  77. package/dist/modules/order/utils/order.js.map +1 -1
  78. package/dist/modules/order/utils/system.d.ts +1 -30
  79. package/dist/modules/order/utils/system.d.ts.map +1 -1
  80. package/dist/modules/order/utils/system.js +31 -98
  81. package/dist/modules/order/utils/system.js.map +1 -1
  82. package/dist/modules/order/utils/validate.d.ts +3 -2
  83. package/dist/modules/order/utils/validate.d.ts.map +1 -1
  84. package/dist/modules/order/utils/validate.js +49 -28
  85. package/dist/modules/order/utils/validate.js.map +1 -1
  86. package/dist/scripts/analyze-credit.d.ts.map +1 -1
  87. package/dist/scripts/analyze-credit.js +53 -33
  88. package/dist/scripts/analyze-credit.js.map +1 -1
  89. package/docs/DEXBOT_COMPARISON.md +3 -3
  90. package/docs/EVOLUTION.md +7 -5
  91. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  92. package/docs/README.md +2 -2
  93. package/docs/WORKFLOW.md +1 -1
  94. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,41 @@
2
2
 
3
3
  All notable changes to this project will be documented in this file.
4
4
 
5
+ ## [1.5.3] - 2026-09-09 - Boundary Ownership Hardening, COW Dedup, TradingView Range Highlight, Sync Materialize Fix
6
+
7
+ ### 2026-09-07
8
+
9
+ - **Docs(curve)**: dynamic rho, StableSwap context, and clarity fixes in the power-law curve comparison — new "variable price p" section (`p = (y/x)^(1-rho)` sliding along the invariant as reserves shift and what that means for liquidity placement); deviation/regime-driven dynamic-rho table plus keeper pseudocode reusing the AMA signal stack (ATR, Kalman velocity, Hurst/PE) with branches aligned to table rows; new "Relation to the StableSwap protocol" section (upstream design link, A/rho interpolation-axis comparison, CES-vs-StableSwap contrast table, flexibility split: StableSwap the more general/operationally complete protocol, CES the more flexible curve shape); stablecoin recommendation justified via tail behavior (StableSwap degrades toward constant product on depeg while high-rho CES thins exponentially below it); rho_buy/rho_sell renamed to tail-oriented rho_high/rho_low with naming note (`docs/DEXBOT2_VS_POWER_LAW_CURVE.md`; docs-only, no code paths affected).
10
+
11
+ ### 2026-09-08
12
+
13
+ - **Refactor(cow)**: deduplicate COW runtime broadcast/reconcile paths — `modules/dexbot_cow_runtime.ts` (~4700 lines) shared sequences extracted into single spellings: `recoverRefusedCommit` (3 identical commit-refused recovery sequences, named options object, original log wordings preserved), `runPreBroadcastGuards` (create-slot validation, recovery-exhausted block, pending/unmatched guards, crossed-book gate), `matchPendingToChain`/`adoptMatchedEntries`/`restoreDiscardedCreates`/`resyncIfUnreconciled` (4-phase split of `reconcileAfterUncertainBroadcastImpl`, persist ownership stays with caller), `runLastFillGuardCheck` (all 3 guard sites), `createOpFingerprintForSlot`/`findChainOrderForPendingEntry`, `rawOnChainFromInts`/`applyOptimisticFeeBalance`, `isAuthoritativeChainRead`, `getPendingBroadcasts`/`countPendingBroadcasts`; pure helpers (`chainOrderUnchangedFromCache`, `detectCrossedBookPlan`, `collectKnownOnChainOrderIds`) moved to `modules/order/utils/order.ts`; getAssetFeesSafe require hack removed (direct ESM import); per-kind op builders and broadcast commit/catch blocks deliberately kept inline (threading ~15 shared locals through broadcast-critical code judged riskier than the duplication); full suite 266 passed, 0 failed.
14
+
15
+ ### 2026-09-09
16
+
17
+ - **Feat(tradingview)**: bot-grid range highlight with AMA-slope scaling — Range / Scale controls, grid-span slider (1.25-2x, default from bot grid ratio), legend readout (+up% / -down%), range-band draw plugin behind candles/AMA with axis-fit to band when Scale is on; band math embeds canonical sources verbatim via `embedFunctionSources` (`computeAverageAmaSlopePct`, `resolveBaseBounds`, `computeAsymmetricBoundsMetrics`, `applyAsymmetricBounds`, `applyNarrowingSideGuard`, `parseRelativeMultiplier`, same runtime values: lookback 9, maxSlope 0.09, clamp 0.5, maxAsym 0.35, minSlots 10, plus per-bot overrides); CLI `--no-range`/`--range-scale`/`--range-span`, grid bounds resolved from bot meta (`analysis/tradingview/*`, `analysis/resolve_source.ts`, `analysis/tradingview/analyze_tradingview.ts`); canonical `applyNarrowingSideGuard` exported from `market_adapter/core/asymmetric_bounds.ts` with `modules/order/grid.ts` routing its narrowing-side slot logic through it (behavior-identical); restored `.time-btn` click listeners, removed y-axis maxSpan zoom-out cap (floor/ceiling anti-slip guards remain).
18
+ - **Fix(boundary)**: remove fund-driven boundary sync, fills move the boundary — the periodic fund-ratio check moved rails without guaranteed same-batch refills, so guard-vetoed refill rotations left the commit keeping the boundary move with empty slots stranded past it (no repair path: sell-side spread pass could not touch buy-rail holes, promotion quota exhausted, budget spent on far orphans); `syncBoundaryToFunds` deleted (`modules/order/utils/system.ts` divergence pins the boundary to the committed value, `boundaryChanged` dropped from the return contract), `calculateFundDrivenBoundary` deleted (`modules/order/utils/order.ts`), failed-commit immediate retry and boundary-shift spread-skip removed (`modules/dexbot_maintenance_runtime.ts`); remaining writers are fills (`deriveTargetBoundary` with same-cycle rotations) and spread promotion (shifts only onto same-batch placements); fund changes still drive sizing via budget allocation, never rails; tests pinning the deleted writer removed (unanchored-spread, boundary-sync, fallback retry/crosser, skip-gate cases; abort-reason propagation and master-unpatched contracts kept).
19
+ - **Fix(boundary)**: hold committed boundary when guard-skipped refills strand rail holes — a fill-driven replan could shift the boundary on hole-CREATE refills, then have those refills guard-skipped at broadcast: working grid restores empties, the commit gate skips empties, and the overrun self-legalizes via gap-band re-derivation next cycle; `plan.refillSlotIds` threaded through `buildCowResultFromPlan` (string ids only) with skipped CREATE ids tracked at all five guard-skip sites, new `resolveRefillBoundaryHold`/`toRefillSlotIdSet` intersect skips (UPDATE + post-fill-clamped + CREATE) with the refill set, frozen `effectiveBoundary` routed to both `_commitWorkingGrid` calls and all three `recoverRefusedCommit` sites (`modules/dexbot_cow_runtime.ts`, `modules/order/manager.ts`, `modules/order/utils/validate.ts`, `modules/order/utils/system.ts`; `tests/test_cow_boundary_hold.ts` HOLD-001..008); hold keeps the committed boundary on refill intersect only, grid still commits, unrelated vetoes advance, absent wire never pins; interior skips can delay a justified shift by one cycle (fail-closed, self-healing).
20
+ - **Fix(sync)**: materialize-or-error on unknown grid id in createOrder sync path — a broadcast landing after a grid reset replaced master left the live chain order untracked: `synchronizeWithChain(createOrder)` missed the master lookup and dropped the linkage silently, so the next cycle re-placed the level, duplicating live orders and locking funds; chain id already tracked elsewhere warns + skips (idempotent), caller-supplied placement descriptor materializes the slot (ACTIVE/PARTIAL, orderId set, deferredFee restored), no descriptor logs an error naming both ids with the next readOpenOrders sync adopting the order as an orphan; `restoreDiscardedCreates` materializes creation-uncertain slots from the broadcast-time descriptor (VIRTUAL, planned size, no orderId so orphan adoption can reconcile) with error logs for unusable descriptors, all three createOrder call sites now pass the descriptor, plus a warn for the cancelOrder post-lock re-fetch miss (`modules/order/sync_engine.ts`, `modules/dexbot_cow_runtime.ts`, `tests/test_sync_create_unknown_id.ts` 5 regression tests).
21
+
22
+ ## [1.5.2] - 2026-09-07 - Sync Rejection & Adoption Hardening, Crossing-Guard Coverage, Credit Display Fixes
23
+
24
+ ### 2026-09-06
25
+
26
+ - **Fix(export)**: derive offline export trades from fill blocks — the parser only matched a legacy single-line fill format no runtime code emits anymore, so offline export found zero trades; `modules/order/export.ts` now parses multi-line FILL DETECTED blocks (with and without asset IDs) deriving side/price/amount from precision-scaled amounts via persisted grid metadata (bare blocks fall back to grid-median disambiguation, ambiguous cases skipped; legacy format kept), fee lines attribute the per-fill share to each fill in the window (closest match, fixing aggregated-total double-count), BUY proceeds report quote-asset cost; `modules/dexbot_fill_runtime.ts` logs pays/receives asset IDs alongside raw amounts (log-only, no behavior change); export help text points at local analysis tooling (`dexbot.ts`, `docs/WORKFLOW.md`, `modules/order/export.ts`, new `tests/test_order_export_fill_blocks.ts`).
27
+ - **Feat(credit)**: show next credit expiry in debt summary lines — debt asset lines in `dexbot credit` include the earliest `latest_repay_time` per asset as a 2-digit-year date in bold yellow, bracket-ordered with the biggest single position before the deal count (`scripts/analyze-credit.ts`).
28
+ - **Fix(credit)**: credit overview debt/coll display reflects whole account — the overview summed only deals/call orders matching the analyzed bot's debtPolicy, silently hiding real debt/collateral on shared accounts or from MPA-only configs; MPA debt/coll sums now use all call orders and credit sums all borrower deals on the account (section gates, spacing, and the empty-state note keyed to the same unfiltered lists); CR rows, per-pair/average CR, offer fetch, borrow-now preview, and summary totals stay debtPolicy-filtered (`scripts/analyze-credit.ts`).
29
+
30
+ ### 2026-09-07
31
+
32
+ - **Fix(guard)**: close crossing-guard, empty-read, and rail adoption blind spots — crossing-placement guards saw only master-grid orders, so an UPDATE-only rotation batch could re-price across a pending-broadcast or un-adopted chain order and self-trade: new shared `buildCrossingCheckCandidates` (master orders + pending-broadcast wrappers + unmatched chain orders) with `isCrossingCheckCandidate`/`crossingCandidateChainId` predicates in `modules/order/utils/order.ts`, all guards delegate to it (`modules/dexbot_cow_runtime.ts`, `modules/order/grid_reconcile_internal.ts`, `correctOrderPriceOnChain`); suspect empty reads now require one delayed confirming re-read (`confirmSuspectEmptyRead` in `modules/order/sync_engine.ts`) plus a STARTUP-CONFIRM re-read when a persisted grid meets an empty snapshot (first launch exempt), and `adoptPlacedBatchFromChain` routes by-id whenever any id hints exist; uncertain-landed creates adopt with `chainOrderMatchesSlotWithTolerance` (~2 price quanta, strict matcher kept for genesis mapping); `validateCreateTargetSlots` orphan-price fallback is per-candidate for slotless candidates with a top-level `priceSlotEqual` import; `isSlotInRail` returns true for unparseable legacy ids (fail-open) and pre-boundary orphans defer with an explicit `boundary-unknown-deferred` reason visible to crossing guards; last-fill-guard docstrings corrected to single-pivot semantics (`modules/dexbot_cow_runtime.ts`, `modules/dexbot_startup_runtime.ts`, `modules/order/grid.ts`, `modules/order/grid_reconcile.ts`, `modules/order/grid_reconcile_internal.ts`, `modules/order/manager.ts`, `modules/order/sync_engine.ts`, `modules/order/utils/math.ts`, `modules/order/utils/order.ts`, `modules/order/utils/validate.ts`; new `tests/test_crossing_candidate_helpers.ts`, `tests/test_sync_empty_confirm.ts`, `tests/test_validate_mixed_orphan_tolerance.ts`).
33
+ - **Fix(grid)**: correct vacated-rail refill guard comment and repurpose vacuous VRR-6 — the comment referenced a non-existent CANCELED slot state; refill targets are VIRTUAL slots without `orderId` (in-flight cancels stay ACTIVE/PARTIAL and never reach the scan); VRR-6 now tests that an ACTIVE slot with an `orderId` at the vacated price keeps the level matched (no re-map UPDATE, no refill CREATE) (`modules/order/grid_reconcile_internal.ts`, `tests/test_vacated_rail_refill.ts`).
34
+ - **Fix(grid)**: key CREATE-batch price validation on broadcast price and fail closed on unpriceable CREATEs — layer-5 collision detection keyed on live slot price (falling back to broadcast) let two CREATEs broadcasting the same price onto divergent live slots pass; entries now record the broadcast price and non-finite prices push a `create_price_invalid` violation instead of being skipped (`modules/order/utils/validate.ts`, `modules/dexbot_cow_runtime.ts`, `tests/test_validate_create_target_slots.ts`).
35
+ - **Fix(sync)**: release slot match on rejected pass-2 adoption so the next chain order can adopt — `adoptChainOrderIntoSlot` marked the slot matched before `_applyOrderUpdate` ran, and on rejection the poisoned mark misclassified the next chain order for the same slot as no-available-nearest-slot (forcing structural resync on genesis builds); both rejection paths now delete the slot from `matchedGridOrderIds` before returning false (`modules/order/sync_engine.ts`, new `tests/test_sync_adoption_poison.ts`).
36
+ - **Fix(accounting)**: run fund recalibration on empty chain reads and never virtualize unparseable live orders — dropped the `openOrders.length === 0` early return in `_recalibrateTrackedFundsFromChain` (lag guards make empty reads safe) and track parse failures in `malformedOrderIds` so the absent branch skips them (unknown is not absent) instead of virtualizing a still-live slot (`modules/order/accounting.ts`, `tests/test_accounting_logic.ts`).
37
+ - **Fix(sync)**: honor `_applyOrderUpdate` rejection across pass-1 sync paths — duplicate-swap mutated `chainOrderIdsOnGrid` before the apply while filled/phantom-cleanup paths pushed fills unconditionally, so rejected updates were treated as applied; set operations moved after successful apply (rejected swap keeps old binding, candidate stays unmatched for pass-2 cancel), rejected filled/partial/phantom paths book nothing and re-detect next sync (`modules/order/sync_engine.ts`, `tests/test_sync_duplicate_orphan_swap.ts`).
38
+ - **Fix(grid)**: re-prove stamped gap-evacuation size against live booked remaining — a B-stamped gap-evacuation UPDATE bypassed the live probe on stamp geometry alone, so an unprocessed fill landing between plan-build and execution could grow a partially-filled live order back to planned size; new pure `isEvacuationSizeStillValid` in `modules/order/utils/math.ts` (planned size must not exceed live booked remaining, blockchain-int compare, fail closed) re-proves the stamped path against the live master slot, invalid stamps route into the existing unstamped probe (`modules/dexbot_cow_runtime.ts`, `tests/test_gap_evacuation.ts` EVAC-020).
39
+
5
40
  ## [1.5.1] - 2026-09-06 - Gap-Evacuation Guard Allowance & Rail-Typed Holes
6
41
 
7
42
  ### 2026-09-05
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ama_fitting",
3
- "version": "1.5.1",
3
+ "version": "1.5.3",
4
4
  "description": "Tools for fitting AMA parameters to market data",
5
5
  "main": "../../dist/analysis/ama_fitting/optimizer_high_resolution.js",
6
6
  "scripts": {
@@ -79,6 +79,9 @@ function resolveSource(config: SourceConfig, options: { quiet?: boolean } = {}):
79
79
  }
80
80
  }
81
81
  const source = createSource('json', { filePath: filePath! });
82
+ if (config.botKey) {
83
+ return { source, botKey: config.botKey, amaConfig: resolveAmaConfig(config.botKey), amaKey: resolveAmaKey(config.botKey) };
84
+ }
82
85
  return { source, amaConfig: resolveAmaConfig(''), amaKey: 'AMA3' };
83
86
  }
84
87