dexbot 1.6.13 → 1.6.14

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 (93) hide show
  1. package/CHANGELOG.md +32 -0
  2. package/README.md +2 -2
  3. package/claw/docs/AI_BOT_LIBRARY_API.md +1 -1
  4. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -4
  5. package/claw/modules/claw_catalog.ts +8 -4
  6. package/claw/modules/dexbot_profiles.ts +59 -15
  7. package/claw/modules/types.ts +2 -1
  8. package/claw/package.json +1 -1
  9. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  10. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  11. package/claw/skills/margin-trading/SKILL.md +1 -1
  12. package/claw/skills/margin-trading/references/position-management.md +1 -1
  13. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +25 -25
  14. package/dist/modules/account_bots.d.ts +7 -6
  15. package/dist/modules/account_bots.js +10 -10
  16. package/dist/modules/account_orders.d.ts +36 -4
  17. package/dist/modules/account_orders.js +76 -5
  18. package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +1 -2
  19. package/dist/modules/bitshares-native/crypto/ecc_core.js +1 -1
  20. package/dist/modules/bitshares-native/serial/chain_constants.d.ts +1 -2
  21. package/dist/modules/bitshares-native/serial/chain_constants.js +1 -2
  22. package/dist/modules/bot_defaults.d.ts +16 -2
  23. package/dist/modules/bot_defaults.js +34 -8
  24. package/dist/modules/bot_settings.d.ts +4 -0
  25. package/dist/modules/bot_settings.js +55 -21
  26. package/dist/modules/config.js +6 -1
  27. package/dist/modules/constants.d.ts +7 -5
  28. package/dist/modules/constants.js +12 -5
  29. package/dist/modules/dexbot_class.d.ts +5 -0
  30. package/dist/modules/dexbot_class.js +8 -3
  31. package/dist/modules/dexbot_cow_runtime.d.ts +62 -174
  32. package/dist/modules/dexbot_cow_runtime.js +331 -46
  33. package/dist/modules/dexbot_credential_client.d.ts +1 -16
  34. package/dist/modules/dexbot_credential_client.js +1 -1
  35. package/dist/modules/dexbot_fill_runtime.d.ts +1 -1
  36. package/dist/modules/dexbot_fill_runtime.js +12 -1
  37. package/dist/modules/dexbot_maintenance_runtime.d.ts +18 -80
  38. package/dist/modules/dexbot_maintenance_runtime.js +57 -68
  39. package/dist/modules/dexbot_startup_runtime.js +12 -0
  40. package/dist/modules/dexbot_state_recovery.js +16 -0
  41. package/dist/modules/key_store.d.ts +0 -5
  42. package/dist/modules/key_store.js +1 -1
  43. package/dist/modules/order/accounting.js +11 -11
  44. package/dist/modules/order/export.js +2 -2
  45. package/dist/modules/order/format.d.ts +15 -1
  46. package/dist/modules/order/format.js +19 -1
  47. package/dist/modules/order/genesis_policy.d.ts +1 -1
  48. package/dist/modules/order/genesis_policy.js +1 -1
  49. package/dist/modules/order/grid.d.ts +23 -11
  50. package/dist/modules/order/grid.js +383 -51
  51. package/dist/modules/order/grid_reconcile.d.ts +1 -1
  52. package/dist/modules/order/grid_reconcile.js +5 -5
  53. package/dist/modules/order/grid_reconcile_internal.js +48 -40
  54. package/dist/modules/order/index.d.ts +34 -8
  55. package/dist/modules/order/logger.js +2 -2
  56. package/dist/modules/order/manager.d.ts +9 -2
  57. package/dist/modules/order/manager.js +58 -24
  58. package/dist/modules/order/strategy.d.ts +2 -2
  59. package/dist/modules/order/strategy.js +51 -21
  60. package/dist/modules/order/sync_engine.js +4 -0
  61. package/dist/modules/order/utils/math.d.ts +3 -3
  62. package/dist/modules/order/utils/math.js +38 -27
  63. package/dist/modules/order/utils/order.d.ts +58 -58
  64. package/dist/modules/order/utils/order.js +119 -102
  65. package/dist/modules/order/utils/system.d.ts +193 -6
  66. package/dist/modules/order/utils/system.js +392 -29
  67. package/dist/modules/order/utils/validate.js +26 -4
  68. package/dist/modules/runtime_settings.d.ts +1 -1
  69. package/dist/modules/runtime_settings.js +3 -3
  70. package/dist/modules/types.d.ts +48 -4
  71. package/dist/scripts/analyze-orders.d.ts +1 -1
  72. package/dist/scripts/analyze-orders.js +4 -4
  73. package/dist/scripts/divergence-calc.js +6 -6
  74. package/dist/scripts/validate_bots.d.ts +1 -1
  75. package/dist/scripts/validate_bots.js +3 -3
  76. package/dist/unlock.js +7 -2
  77. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -2
  78. package/docs/COW_INVARIANTS.md +6 -6
  79. package/docs/DEXBOT_COMPARISON.md +5 -5
  80. package/docs/EVOLUTION.md +8 -7
  81. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +8 -6
  82. package/docs/GRID_PRICE_INVARIANT.md +3 -3
  83. package/docs/GRID_RECALCULATION.md +4 -1
  84. package/docs/GRID_RECONCILE.md +4 -4
  85. package/docs/LIFECYCLE.md +11 -11
  86. package/docs/LOGGING.md +14 -0
  87. package/docs/MPA_CREDIT_USAGE.md +1 -1
  88. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +12 -4
  89. package/docs/README.md +3 -3
  90. package/docs/architecture.md +6 -6
  91. package/docs/developer_guide.md +7 -2
  92. package/package.json +1 -1
  93. package/tests/README.md +1 -1
@@ -258,6 +258,24 @@ function positiveOrNull(value) {
258
258
  const num = Number(value);
259
259
  return Number.isFinite(num) && num > 0 ? num : null;
260
260
  }
261
+ /**
262
+ * Convert a value to a finite number but treat an explicitly absent value
263
+ * (`null`/`undefined`/`''`) as unknown (`NaN`) instead of `0`.
264
+ *
265
+ * `Number(null) === 0` and `Number('') === 0` are finite, so a plain `Number()`
266
+ * coercion reads "no value" as the valid value 0 — the trap that made an
267
+ * unknown boundary read as slot 0, an unknown gap width collapse the band, and
268
+ * an unknown fill timestamp read as epoch. Use this for any geometry/index/
269
+ * count field where 0 is legitimate and absence must stay detectable.
270
+ *
271
+ * A genuine `0` (number, `'0'`, `false`) still converts to `0`. Pair with
272
+ * `Number.isFinite` at the call site where absent must fail closed.
273
+ */
274
+ function toKnownNumber(value) {
275
+ if (value === null || value === undefined || value === '')
276
+ return NaN;
277
+ return Number(value);
278
+ }
261
279
  /**
262
280
  * Safely format a numeric value with specified decimals and fallback.
263
281
  *
@@ -280,5 +298,5 @@ function safeFormat(value, decimals, fallback = 'N/A') {
280
298
  // ===============================================================================
281
299
  // EXPORTS
282
300
  // ===============================================================================
283
- export { formatAmount8, formatAmount, formatAmountByPrecision, formatSizeByOrderType, formatPrice, formatPrice6, formatPrice4, formatCurrency, formatFundsValue, formatPercent2, formatPercent, formatMetric2, isValidNumber, toFiniteNumber, positiveOrNull, safeFormat };
301
+ export { formatAmount8, formatAmount, formatAmountByPrecision, formatSizeByOrderType, formatPrice, formatPrice6, formatPrice4, formatCurrency, formatFundsValue, formatPercent2, formatPercent, formatMetric2, isValidNumber, toFiniteNumber, toKnownNumber, positiveOrNull, safeFormat };
284
302
  //# sourceMappingURL=format.js.map
@@ -6,7 +6,7 @@
6
6
  * missing is therefore not a degraded grid -- it is an undefined one: every
7
7
  * consumer that reads `priceForSlot(idx, genesis)` has no authority for a
8
8
  * slot's price (nearest-slot adoption, the materialize descriptor-price
9
- * fallback, reserve-edge anchoring, the `isSlotInRail` fail-open), and that is
9
+ * fallback, edge anchoring, the `isSlotInRail` fail-open), and that is
10
10
  * precisely the state on which an off-grid price became grid evidence and got
11
11
  * re-emitted. The tolerance matcher that used to cover it has been removed:
12
12
  * E2 refuses to sync such a grid and asks for the resync that re-derives the
@@ -6,7 +6,7 @@
6
6
  * missing is therefore not a degraded grid -- it is an undefined one: every
7
7
  * consumer that reads `priceForSlot(idx, genesis)` has no authority for a
8
8
  * slot's price (nearest-slot adoption, the materialize descriptor-price
9
- * fallback, reserve-edge anchoring, the `isSlotInRail` fail-open), and that is
9
+ * fallback, edge anchoring, the `isSlotInRail` fail-open), and that is
10
10
  * precisely the state on which an off-grid price became grid evidence and got
11
11
  * re-emitted. The tolerance matcher that used to cover it has been removed:
12
12
  * E2 refuses to sync such a grid and asks for the resync that re-derives the
@@ -12,7 +12,7 @@
12
12
  * - Detects and flags out-of-spread conditions
13
13
  *
14
14
  * ===============================================================================
15
- * TABLE OF CONTENTS - Grid Functions (22 exported functions)
15
+ * TABLE OF CONTENTS - Grid Functions (23 exported functions)
16
16
  * ===============================================================================
17
17
  *
18
18
  * CONFIGURATION & CALCULATION (2 functions)
@@ -34,8 +34,11 @@
34
34
  * GRID RECALCULATION (1 function - async)
35
35
  * 7. recalculateGrid(manager, opts) - Recalculate grid based on current state
36
36
  *
37
- * GRID STATE CHECKING (1 function)
38
- * 8. checkAndUpdateGridIfNeeded(manager) - Check if grid needs update
37
+ * GRID STATE CHECKING (2 functions)
38
+ * 8. checkAndUpdateGridIfNeeded(manager) - Complete fund trigger: available-
39
+ * funds ratio + over-allocation + on-chain committed-drift legs
40
+ * 8b. checkCommittedSizeDrift(manager) - Async committed-drift-only accessor
41
+ * (the drift core is folded into checkAndUpdateGridIfNeeded)
39
42
  *
40
43
  * BLOCKCHAIN SYNCHRONIZATION (2 functions - async)
41
44
  * 9. _recalculateGridOrderSizesFromBlockchain(manager, orderType, options) - Recalculate sizes from blockchain
@@ -94,7 +97,7 @@ interface SpreadCorrection {
94
97
  newSize: number;
95
98
  }>;
96
99
  plannedCount?: number;
97
- stallHint?: 'unfunded' | 'no-candidates';
100
+ stallHint?: SpreadCorrectionStall;
98
101
  boundaryIdx?: number;
99
102
  origin?: string;
100
103
  [key: string]: unknown;
@@ -152,13 +155,9 @@ export declare function isGridBloatGraceActive(manager: OrderManagerLike): {
152
155
  */
153
156
  export declare function clearGridBloatFlag(manager: OrderManagerLike): void;
154
157
  /**
155
- * Unifies budget calculation and fee deduction for all grid sizing scenarios.
156
- * Ensures consistent fund context (Allocated vs Total) across the bot.
157
- *
158
- * @param {import('./types').OrderManager} manager - OrderManager instance
159
- * @param {string} side - 'buy' or 'sell'
160
- * @returns {Promise<any|null>}
161
- * @private
158
+ * Async sizing-context accessor. Refreshes funds unless `skipRecalc`, then
159
+ * delegates to the sync core. Both divergence legs (ratio and committed
160
+ * drift) size through the sync core so they read one fund snapshot.
162
161
  */
163
162
  export declare function _getSizingContext(manager: OrderManagerLike, side: string, { skipRecalc }?: {
164
163
  skipRecalc?: boolean;
@@ -287,6 +286,19 @@ export declare function checkAndUpdateGridIfNeeded(manager: OrderManagerLike): {
287
286
  buyShrink: boolean;
288
287
  sellShrink: boolean;
289
288
  };
289
+ /**
290
+ * Async committed-drift accessor: refresh funds, then run the sync core.
291
+ * Public for callers/tests that want the drift-only result; the complete
292
+ * trigger is checkAndUpdateGridIfNeeded, which folds this core in.
293
+ * Naming mirrors the sizing pair: _computeCommittedSizeDriftSync is the
294
+ * private computation, checkCommittedSizeDrift the public accessor.
295
+ */
296
+ export declare function checkCommittedSizeDrift(manager: OrderManagerLike): Promise<{
297
+ buyUpdated: boolean;
298
+ sellUpdated: boolean;
299
+ buyShrink: boolean;
300
+ sellShrink: boolean;
301
+ }>;
290
302
  /**
291
303
  * Standardize grid sizes using blockchain total context.
292
304
  *