dexbot 1.6.18 → 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.
- package/CHANGELOG.md +68 -0
- package/README.md +24 -18
- package/analysis/README.md +117 -5
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/account_resolver.js +5 -6
- package/dist/analysis/analyze_dynamic_weight.js +2 -1
- package/dist/analysis/analyze_kalman.js +3 -2
- package/dist/analysis/analyze_liquidity.d.ts +17 -0
- package/dist/analysis/analyze_liquidity.js +336 -0
- package/dist/analysis/analyze_regime.js +3 -2
- package/dist/analysis/analyze_regime_windows.js +3 -2
- package/dist/analysis/analyze_volatility.js +3 -2
- package/dist/analysis/bot_key_utils.d.ts +44 -1
- package/dist/analysis/bot_key_utils.js +76 -7
- package/dist/analysis/fills_cache.js +2 -1
- package/dist/analysis/grid_correction_check.d.ts +1 -19
- package/dist/analysis/grid_correction_check.js +12 -30
- package/dist/analysis/liquidity/liquidity_chain.d.ts +66 -0
- package/dist/analysis/liquidity/liquidity_chain.js +178 -0
- package/dist/analysis/liquidity/liquidity_chart_generator.d.ts +19 -0
- package/dist/analysis/liquidity/liquidity_chart_generator.js +693 -0
- package/dist/analysis/liquidity/liquidity_depth_model.d.ts +166 -0
- package/dist/analysis/liquidity/liquidity_depth_model.js +258 -0
- package/dist/analysis/liquidity/liquidity_view.d.ts +53 -0
- package/dist/analysis/liquidity/liquidity_view.js +66 -0
- package/dist/analysis/resolve_bot_accounts.js +7 -6
- package/dist/analysis/trade_profitability.js +4 -2
- package/dist/analysis/tradingview/analyze_tradingview.js +2 -1
- package/dist/credential-daemon.js +13 -2
- package/dist/dexbot.js +77 -172
- package/dist/modules/account_bots.d.ts +11 -1
- package/dist/modules/account_orders.d.ts +12 -0
- package/dist/modules/account_orders.js +30 -0
- package/dist/modules/asset_lookup.d.ts +25 -0
- package/dist/modules/asset_lookup.js +75 -0
- package/dist/modules/bitshares-native/transport.js +24 -6
- package/dist/modules/bitshares_client.d.ts +24 -6
- package/dist/modules/bitshares_client.js +44 -7
- package/dist/modules/bot_settings.d.ts +2 -0
- package/dist/modules/chain_scan.d.ts +64 -0
- package/dist/modules/chain_scan.js +80 -0
- package/dist/modules/cli_colors.d.ts +5 -0
- package/dist/modules/cli_colors.js +7 -0
- package/dist/modules/cli_progress.d.ts +51 -0
- package/dist/modules/cli_progress.js +113 -0
- package/dist/modules/constants.d.ts +26 -3
- package/dist/modules/constants.js +63 -8
- package/dist/modules/dexbot_class.d.ts +1 -6
- package/dist/modules/dexbot_class.js +14 -0
- package/dist/modules/dexbot_cow_runtime.d.ts +97 -7
- package/dist/modules/dexbot_cow_runtime.js +634 -136
- package/dist/modules/dexbot_fill_runtime.js +132 -23
- package/dist/modules/dexbot_maintenance_runtime.js +242 -74
- package/dist/modules/dexbot_startup_runtime.js +32 -20
- package/dist/modules/dexbot_state_recovery.d.ts +33 -1
- package/dist/modules/dexbot_state_recovery.js +167 -5
- package/dist/modules/launcher/runtime_entry.d.ts +21 -1
- package/dist/modules/launcher/runtime_entry.js +36 -1
- package/dist/modules/liquidity_pool_ref.d.ts +32 -0
- package/dist/modules/liquidity_pool_ref.js +116 -0
- package/dist/modules/node_connect_policy.d.ts +8 -1
- package/dist/modules/node_connect_policy.js +18 -2
- package/dist/modules/node_flap_score.d.ts +87 -0
- package/dist/modules/node_flap_score.js +124 -0
- package/dist/modules/node_health_cache.d.ts +40 -3
- package/dist/modules/node_health_cache.js +66 -20
- package/dist/modules/node_manager.d.ts +101 -19
- package/dist/modules/node_manager.js +255 -65
- package/dist/modules/order/accounting.js +56 -7
- package/dist/modules/order/format.d.ts +24 -10
- package/dist/modules/order/format.js +30 -10
- package/dist/modules/order/grid.js +91 -13
- package/dist/modules/order/grid_reconcile.d.ts +5 -1
- package/dist/modules/order/grid_reconcile.js +333 -189
- package/dist/modules/order/grid_reconcile_internal.d.ts +38 -2
- package/dist/modules/order/grid_reconcile_internal.js +298 -100
- package/dist/modules/order/index.d.ts +19 -1
- package/dist/modules/order/lifecycle.d.ts +353 -0
- package/dist/modules/order/lifecycle.js +1109 -0
- package/dist/modules/order/manager.d.ts +273 -5
- package/dist/modules/order/manager.js +654 -48
- package/dist/modules/order/placement_lock.d.ts +102 -0
- package/dist/modules/order/placement_lock.js +222 -0
- package/dist/modules/order/strategy.js +13 -1
- package/dist/modules/order/sync_engine.d.ts +33 -1
- package/dist/modules/order/sync_engine.js +241 -73
- package/dist/modules/order/utils/math.d.ts +39 -1
- package/dist/modules/order/utils/math.js +83 -1
- package/dist/modules/order/utils/order.d.ts +181 -5
- package/dist/modules/order/utils/order.js +455 -9
- package/dist/modules/order/utils/system.d.ts +81 -1
- package/dist/modules/order/utils/system.js +331 -44
- package/dist/modules/order/utils/validate.d.ts +7 -1
- package/dist/modules/order/utils/validate.js +80 -3
- package/dist/modules/outcome.d.ts +54 -0
- package/dist/modules/outcome.js +51 -0
- package/dist/modules/settings_merge.d.ts +4 -0
- package/dist/modules/settings_merge.js +9 -0
- package/dist/modules/timing_policy.d.ts +82 -0
- package/dist/modules/timing_policy.js +244 -0
- package/dist/modules/types.d.ts +137 -0
- package/dist/modules/utils/asset_symbols.d.ts +13 -2
- package/dist/modules/utils/asset_symbols.js +21 -2
- package/dist/scripts/analysis_runner.d.ts +10 -0
- package/dist/scripts/analysis_runner.js +33 -0
- package/dist/scripts/analyze-credit.js +54 -17
- package/dist/scripts/analyze-orders.d.ts +4 -2
- package/dist/scripts/analyze-orders.js +115 -35
- package/dist/scripts/asset.d.ts +26 -0
- package/dist/scripts/asset.js +165 -0
- package/dist/scripts/bts_distribution.d.ts +1 -0
- package/dist/scripts/bts_distribution.js +194 -142
- package/dist/scripts/chart_command.d.ts +1 -1
- package/dist/scripts/chart_command.js +60 -86
- package/dist/scripts/chart_targets.d.ts +18 -0
- package/dist/scripts/chart_targets.js +48 -0
- package/dist/scripts/dw.js +1 -1
- package/dist/scripts/liquid.d.ts +24 -0
- package/dist/scripts/liquid.js +134 -0
- package/dist/scripts/rich_list.js +12 -16
- package/dist/scripts/test-credit-renewal.js +12 -5
- package/dist/scripts/token_distribution.d.ts +2 -0
- package/dist/scripts/token_distribution.js +132 -108
- package/dist/scripts/tv.js +1 -1
- package/dist/scripts/verify-browser-bundle.js +18 -0
- package/docs/COW_INVARIANTS.md +69 -10
- package/docs/DEXBOT_COMPARISON.md +6 -6
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +5 -2
- package/docs/GRID_RECONCILE.md +36 -11
- package/docs/LOGGING.md +50 -4
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +177 -27
- package/docs/README.md +23 -2
- package/docs/WORKFLOW.md +12 -4
- package/docs/architecture.md +42 -5
- package/docs/developer_guide.md +25 -8
- package/modules/README.md +8 -1
- package/package.json +3 -1
- package/scripts/README.md +39 -7
- package/scripts/pdev.sh +14 -1
- package/scripts/pmain.sh +23 -8
- package/scripts/ptest.sh +7 -0
- package/tests/README.md +30 -1
|
@@ -18,6 +18,10 @@ import Logger from './logger.js';
|
|
|
18
18
|
import Accountant from './accounting.js';
|
|
19
19
|
import StrategyEngine from './strategy.js';
|
|
20
20
|
import SyncEngine from './sync_engine.js';
|
|
21
|
+
import { LifecycleRegistry } from './lifecycle.js';
|
|
22
|
+
import type { LifecycleView } from './lifecycle.js';
|
|
23
|
+
import PlacementLock from './placement_lock.js';
|
|
24
|
+
import type { PlacementLease } from './placement_lock.js';
|
|
21
25
|
import type { GridGenesis } from './utils/math.js';
|
|
22
26
|
import type { OrderManagerLike, ManagedOrder, GridConfig, AssetPair, AccountTotals, ManagerFunds, PendingPriceCorrection, ProcessedFillStoreLike, PendingBroadcast, ManagerLock, IllegalStateSignal, AccountingFailureSignal, BotMetrics, AccountOrdersLike, CowAction, RebalanceResult, ProjectedFunds, SyncResult, FillHistorySyncResult, FundDriftCheck, ChainFundsSnapshot, OrderType, OrderState, UnknownRecord } from '../types.js';
|
|
23
27
|
/**
|
|
@@ -107,6 +111,10 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
107
111
|
sync: SyncEngine;
|
|
108
112
|
_rebalanceState: string;
|
|
109
113
|
_bootstrapping: number;
|
|
114
|
+
_structuralRebuildDepth: number;
|
|
115
|
+
_structuralRebuildStartedAt: number;
|
|
116
|
+
_structuralRebuildDeferWarnAt: number;
|
|
117
|
+
_structuralRebuildReason: string | null;
|
|
110
118
|
_endOfBootstrapValidationDone: boolean;
|
|
111
119
|
_broadcastingFlag: number;
|
|
112
120
|
_broadcastingStartedAt: number;
|
|
@@ -157,6 +165,13 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
157
165
|
private _getOrderIdIndex;
|
|
158
166
|
initialSpreadCount: number;
|
|
159
167
|
currentSpreadCount: number;
|
|
168
|
+
/**
|
|
169
|
+
* True once a grid has been loaded/created and the spread metric measured.
|
|
170
|
+
* Before that both counters are 0, which is indistinguishable from a
|
|
171
|
+
* genuinely empty band — telemetry must print "unknown" instead of "0"
|
|
172
|
+
* (the restore line otherwise claims the spread band is gone).
|
|
173
|
+
*/
|
|
174
|
+
_spreadCountKnown: boolean;
|
|
160
175
|
outOfSpread: number;
|
|
161
176
|
assets: AssetPair;
|
|
162
177
|
accountId: string | null;
|
|
@@ -172,6 +187,7 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
172
187
|
processedFillStore: ProcessedFillStoreLike | null;
|
|
173
188
|
_syncLock: ManagerLock;
|
|
174
189
|
_fillProcessingLock: ManagerLock;
|
|
190
|
+
_placementLock: PlacementLock;
|
|
175
191
|
_divergenceLock: ManagerLock;
|
|
176
192
|
_gridLock: ManagerLock;
|
|
177
193
|
_fundLock: ManagerLock;
|
|
@@ -187,11 +203,22 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
187
203
|
_syncGeneration: number;
|
|
188
204
|
_gridVersion: number;
|
|
189
205
|
_gridPersistenceSuspendedReason: string | null;
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Single owner of "does this order exist on chain, and how sure are we".
|
|
208
|
+
* The legacy maps below are live views onto it — see modules/order/lifecycle.ts.
|
|
209
|
+
*/
|
|
210
|
+
readonly _lifecycle: LifecycleRegistry;
|
|
211
|
+
/** Live view onto `_lifecycle`. Assigned as a whole by the COW commit path. */
|
|
212
|
+
get _committedOrderIds(): Set<string>;
|
|
213
|
+
set _committedOrderIds(value: Iterable<string>);
|
|
214
|
+
get _committedOrderIdsBuiltAt(): number;
|
|
215
|
+
set _committedOrderIdsBuiltAt(value: number);
|
|
216
|
+
get _orderIdAssignedAt(): Map<string, number>;
|
|
217
|
+
set _orderIdAssignedAt(value: Map<string, number>);
|
|
218
|
+
get _placedAt(): Map<string, number>;
|
|
219
|
+
set _placedAt(value: Map<string, number>);
|
|
220
|
+
get _pendingBroadcasts(): Map<string, PendingBroadcast>;
|
|
221
|
+
set _pendingBroadcasts(value: Map<string, PendingBroadcast>);
|
|
195
222
|
_gapSlots: number;
|
|
196
223
|
_genesis: GridGenesis | null;
|
|
197
224
|
_missingGenesis: unknown;
|
|
@@ -213,12 +240,28 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
213
240
|
side: string;
|
|
214
241
|
ts: number;
|
|
215
242
|
}[];
|
|
243
|
+
/**
|
|
244
|
+
* Chain-size resizes already absorbed by sync pass 1 (partial fill seen in
|
|
245
|
+
* an open-orders snapshot). The fill-history batch that follows the same
|
|
246
|
+
* fill must not subtract / credit the same amount a second time.
|
|
247
|
+
* Live view onto `_lifecycle`; key = chain orderId.
|
|
248
|
+
*/
|
|
249
|
+
get _chainSizeAppliedFills(): Map<string, {
|
|
250
|
+
filledInt: number;
|
|
251
|
+
at: number;
|
|
252
|
+
}>;
|
|
253
|
+
set _chainSizeAppliedFills(value: Map<string, {
|
|
254
|
+
filledInt: number;
|
|
255
|
+
at: number;
|
|
256
|
+
}>);
|
|
216
257
|
_recentFillKeysSnapshot: Record<string, number> | null;
|
|
217
258
|
_lastFilledBuyPrice: number | null;
|
|
218
259
|
_lastFilledSellPrice: number | null;
|
|
219
260
|
_lastFilledPrice: number | null;
|
|
220
261
|
_lastFilledType: string | null;
|
|
221
262
|
_lastFilledAt: number;
|
|
263
|
+
/** Timestamp of the fill reference whose read-time expiry was already logged (one line per expired value). */
|
|
264
|
+
_lastFillPivotExpiryLoggedAt: number;
|
|
222
265
|
lastFillPivotSource: 'fill' | 'book' | null;
|
|
223
266
|
_lastMarketFillPrice: number | null;
|
|
224
267
|
_lastMarketFillType: string | null;
|
|
@@ -294,16 +337,187 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
294
337
|
* @returns {boolean}
|
|
295
338
|
*/
|
|
296
339
|
isBootstrapping(): boolean;
|
|
340
|
+
/**
|
|
341
|
+
* Mark a structural grid rebuild (trigger-file resync, startup regenerate)
|
|
342
|
+
* as in progress. While active, fill-driven COW rebalances DEFER: they would
|
|
343
|
+
* otherwise re-plan against the freshly rebuilt, order-id-less master and
|
|
344
|
+
* emit a create-only batch while the reconcile re-prices the live orders
|
|
345
|
+
* onto the same levels (duplicate-price orphan incident 2026-11-03).
|
|
346
|
+
* This is deliberately narrower than isBootstrapping(): the constructor's
|
|
347
|
+
* initial bootstrap is not a rebuild and fills may still rebalance there.
|
|
348
|
+
* @param {string} reason - Diagnostic label (e.g. 'trigger-file resync')
|
|
349
|
+
*/
|
|
350
|
+
beginStructuralRebuild(reason?: string): void;
|
|
351
|
+
/** End a structural rebuild region (balanced with beginStructuralRebuild). */
|
|
352
|
+
endStructuralRebuild(): void;
|
|
353
|
+
/** Whether a structural rebuild currently owns placement. */
|
|
354
|
+
isStructuralRebuildInProgress(): boolean;
|
|
355
|
+
/** Diagnostic label of the active structural rebuild, or null. */
|
|
356
|
+
structuralRebuildReason(): string | null;
|
|
357
|
+
/**
|
|
358
|
+
* Run a chain-mutating placement path inside the exclusive region.
|
|
359
|
+
*
|
|
360
|
+
* SINGLE SOURCE OF TRUTH: every caller that can broadcast (COW, startup
|
|
361
|
+
* reconcile Phase 2, correction drain, dust/residual cancels, pool swaps)
|
|
362
|
+
* must go through this helper. It is NOT reentrant: a nested caller must not
|
|
363
|
+
* call it again — the COW body hands its lease to the pre-batch drain
|
|
364
|
+
* (`correctAllPriceMismatches({ placementLease })`), which verifies it with
|
|
365
|
+
* `isPlacementLeaseCurrent()` before mutating.
|
|
366
|
+
*
|
|
367
|
+
* Lock hierarchy: acquire placement BEFORE `_gridLock`; never acquire it
|
|
368
|
+
* while holding `_gridLock` (Level 0.5 — see `manageLocks`).
|
|
369
|
+
*
|
|
370
|
+
* @returns `null` when the region could not be acquired; the caller must
|
|
371
|
+
* defer/abort its broadcast.
|
|
372
|
+
*/
|
|
373
|
+
withPlacement<T>(kind: string, fn: (lease: PlacementLease) => Promise<T>, options?: {
|
|
374
|
+
timeoutMs?: number;
|
|
375
|
+
isShuttingDown?: () => boolean;
|
|
376
|
+
}): Promise<T | null>;
|
|
377
|
+
/**
|
|
378
|
+
* Acquire the exclusive placement region (see placement_lock.ts).
|
|
379
|
+
* Callers MUST release the lease in a finally block before returning.
|
|
380
|
+
* @param {string} kind - Owner label for diagnostics (e.g. 'cow-broadcast')
|
|
381
|
+
* @param {Object} [options] - Wait bound + shutdown probe
|
|
382
|
+
* @returns {Promise<Object|null>} Lease, or null on timeout/shutdown
|
|
383
|
+
*/
|
|
384
|
+
acquirePlacement(kind: string, options?: {
|
|
385
|
+
timeoutMs?: number;
|
|
386
|
+
isShuttingDown?: () => boolean;
|
|
387
|
+
}): Promise<PlacementLease | null>;
|
|
388
|
+
/**
|
|
389
|
+
* Non-blocking placement acquire for paths that must defer rather than queue.
|
|
390
|
+
* @param {string} kind - Owner label
|
|
391
|
+
* @returns {Object|null} Lease when free, otherwise null
|
|
392
|
+
*/
|
|
393
|
+
tryAcquirePlacement(kind: string): PlacementLease | null;
|
|
394
|
+
/** Whether another placement path currently holds the exclusive region. */
|
|
395
|
+
isPlacementActive(): boolean;
|
|
396
|
+
/**
|
|
397
|
+
* Whether the given lease is STILL the one that owns the region.
|
|
398
|
+
*
|
|
399
|
+
* The authoritative nesting predicate: a nested caller (the COW pre-batch
|
|
400
|
+
* drain) must verify its inherited lease with this before mutating.
|
|
401
|
+
* `isPlacementActive()` cannot answer it — it is true for any holder, so a
|
|
402
|
+
* lease invalidated by `forceRelease()` would still read as "live".
|
|
403
|
+
* @param {Object|null|undefined} lease - Lease to verify
|
|
404
|
+
* @returns {boolean}
|
|
405
|
+
*/
|
|
406
|
+
isPlacementLeaseCurrent(lease: PlacementLease | null | undefined): boolean;
|
|
407
|
+
/** Owner label of the active placement region, or null. */
|
|
408
|
+
placementKind(): string | null;
|
|
409
|
+
/** Milliseconds the current placement region has been held (0 when free). */
|
|
410
|
+
placementHeldForMs(): number;
|
|
411
|
+
/**
|
|
412
|
+
* True when the given staleness reason means the master grid was
|
|
413
|
+
* structurally rebuilt while a plan was in flight. Such a plan must NOT be
|
|
414
|
+
* re-planned from the fresh (order-id-less) master: a create-only re-plan
|
|
415
|
+
* duplicates every live chain order the reconcile is about to update.
|
|
416
|
+
*/
|
|
417
|
+
isStructuralRebuildStale(reason: unknown): boolean;
|
|
297
418
|
/**
|
|
298
419
|
* Whether a broadcast is currently active (no side-effects).
|
|
299
420
|
* @returns {boolean}
|
|
300
421
|
*/
|
|
301
422
|
isBroadcastingActive(): boolean;
|
|
423
|
+
/**
|
|
424
|
+
* Record that sync pass 1 already applied a chain-size reduction (a
|
|
425
|
+
* partial fill) for this order. The following fill-history batch checks it
|
|
426
|
+
* to stay idempotent: subtracting/crediting the same fill again shrinks the
|
|
427
|
+
* order twice and over-credits free balance (2026-11-03 log: 3.6604 ->
|
|
428
|
+
* 3.3046 by pass 1, then 3.3046 -> 2.9488 by the fill batch).
|
|
429
|
+
*
|
|
430
|
+
* Markers ACCUMULATE: two pass-1 detections before the fill queue drains
|
|
431
|
+
* (or one aggregated fill-history entry covering both) must add up, not
|
|
432
|
+
* overwrite — an overwritten marker makes the batch total unmatchable and
|
|
433
|
+
* re-opens the double-shrink. The map is mirrored into the persisted grid
|
|
434
|
+
* snapshot (debugInputs) so a restart between pass 1 and fill processing
|
|
435
|
+
* does not lose the evidence.
|
|
436
|
+
* @param {string} orderId - Chain order id
|
|
437
|
+
* @param {number} filledInt - Base-amount delta in chain integer units
|
|
438
|
+
* @returns {void}
|
|
439
|
+
*/
|
|
440
|
+
noteChainSizeAppliedFill(orderId: string, filledInt: number, maxAgeMs?: number): void;
|
|
441
|
+
/**
|
|
442
|
+
* Consume a pass-1 chain-size marker for a fill without requiring an exact
|
|
443
|
+
* total match. Returns the number of chain-size units this fill may treat
|
|
444
|
+
* as ALREADY reflected in `rawOnChain` (0 when there is no marker).
|
|
445
|
+
*
|
|
446
|
+
* Partial consumption is the split-batch case: pass 1 absorbed A+B, the
|
|
447
|
+
* fill queue drains A first (marker keeps B), then B. The old all-or-nothing
|
|
448
|
+
* match rejected both and double-shrunk the slot twice.
|
|
449
|
+
* @param {string} orderId - Chain order id
|
|
450
|
+
* @param {number} filledInt - Base-amount delta in chain integer units
|
|
451
|
+
* @param {number} [maxAgeMs] - Marker freshness bound
|
|
452
|
+
* @returns {number} Applied (already-in-snapshot) amount, 0..filledInt
|
|
453
|
+
*/
|
|
454
|
+
consumeChainSizeAppliedFillAmount(orderId: string, filledInt: number, maxAgeMs?: number): number;
|
|
455
|
+
/**
|
|
456
|
+
* Boolean compatibility wrapper for {@link consumeChainSizeAppliedFillAmount}.
|
|
457
|
+
* @param {string} orderId - Chain order id
|
|
458
|
+
* @param {number} filledInt - Base-amount delta in chain integer units
|
|
459
|
+
* @param {number} [maxAgeMs] - Marker freshness bound
|
|
460
|
+
* @returns {boolean} true when any part of the fill was already applied
|
|
461
|
+
*/
|
|
462
|
+
consumeChainSizeAppliedFill(orderId: string, filledInt: number, maxAgeMs?: number): boolean;
|
|
463
|
+
/**
|
|
464
|
+
* Merge persisted pass-1 markers into the in-memory set (recovery reload).
|
|
465
|
+
* Live markers win on conflict: they may already be partially consumed,
|
|
466
|
+
* and replacing them with the older persisted total would double-count.
|
|
467
|
+
* Entries are sanitized and the clock is freshened (see below).
|
|
468
|
+
* @param {unknown} payload - `{ [orderId]: { filledInt, at } }`
|
|
469
|
+
* @returns {void}
|
|
470
|
+
*/
|
|
471
|
+
restoreChainSizeAppliedFills(payload: unknown): void;
|
|
472
|
+
/** Snapshot the live pass-1 markers for persistence (empty when none). */
|
|
473
|
+
snapshotChainSizeAppliedFills(): Record<string, {
|
|
474
|
+
filledInt: number;
|
|
475
|
+
at: number;
|
|
476
|
+
}>;
|
|
477
|
+
/**
|
|
478
|
+
* Wake the tasks that deferred on isPlacementActive() when the region ends.
|
|
479
|
+
* The broadcast-region-end listener reschedules a deferred rebalance and
|
|
480
|
+
* drains queued fills; without this a fill deferred because a correction
|
|
481
|
+
* drain/COW held placement would only retry on the next unrelated event.
|
|
482
|
+
* Skipped while a broadcast region is still active (stopBroadcasting will
|
|
483
|
+
* fire the same listeners when it ends).
|
|
484
|
+
* @returns {void}
|
|
485
|
+
*/
|
|
486
|
+
_handlePlacementRegionEnd(): void;
|
|
302
487
|
/**
|
|
303
488
|
* @param {boolean} value
|
|
304
489
|
* @returns {void}
|
|
305
490
|
*/
|
|
306
491
|
setShuttingDown(value: boolean): void;
|
|
492
|
+
/**
|
|
493
|
+
* Auto-clears a stale placement region after
|
|
494
|
+
* TIMING.PLACEMENT_STALE_CLEAR_MS so a hung chain call / missed release
|
|
495
|
+
* cannot park fills and rebalances forever. The holder's lease becomes a
|
|
496
|
+
* no-op on release (token guard), so a late finally cannot release a
|
|
497
|
+
* successor.
|
|
498
|
+
*
|
|
499
|
+
* TWO GUARDS, ONE TEARDOWN:
|
|
500
|
+
* - A bot-level batch/recovery still in flight and YOUNGER than the bound is
|
|
501
|
+
* evidence of progress, so the region is not torn down (a long create-group
|
|
502
|
+
* reconcile must survive). Only a batch older than the same bound is
|
|
503
|
+
* treated as part of the hung region.
|
|
504
|
+
* - When the teardown does happen it also clears a broadcast refcount that
|
|
505
|
+
* is itself past its bound, atomically. A refcount raised by a placement
|
|
506
|
+
* holder belongs to the same region (the COW body and the reconcile call
|
|
507
|
+
* startBroadcasting() INSIDE it), so clearing both in one place stops the
|
|
508
|
+
* maintenance tick from tearing down placement first and the refcount
|
|
509
|
+
* second (two authorities, one hung region). A refcount raised OUTSIDE any
|
|
510
|
+
* region (the spread-correction pre-broadcast hold in `order/grid.ts`) is
|
|
511
|
+
* not this region's and is left to `_clearStaleBroadcastFlag`, which still
|
|
512
|
+
* refuses to act on its own while a placement lease is held.
|
|
513
|
+
* @param {number} [maxAgeMs] - Override for tests
|
|
514
|
+
* @param {Object} [options] - `batchInFlightMs`: age of the LAST raised
|
|
515
|
+
* bot-level pipeline counter (0/undefined when none).
|
|
516
|
+
* @returns {boolean} true when a stale region was force-released
|
|
517
|
+
*/
|
|
518
|
+
_clearStalePlacementRegion(maxAgeMs?: number, options?: {
|
|
519
|
+
batchInFlightMs?: number;
|
|
520
|
+
}): boolean;
|
|
307
521
|
/**
|
|
308
522
|
* Auto-clears a stale broadcast flag after 120s so a hung
|
|
309
523
|
* broadcast cannot permanently block rebalancing.
|
|
@@ -545,6 +759,32 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
545
759
|
*/
|
|
546
760
|
getActiveShadowLockCount(): number;
|
|
547
761
|
_cleanExpiredLocks(): void;
|
|
762
|
+
/**
|
|
763
|
+
* The single answer to "does this order exist on chain, and how sure are we".
|
|
764
|
+
*
|
|
765
|
+
* Every consumer that used to infer this from one of the legacy maps must
|
|
766
|
+
* read it here instead — that is the whole point of the lifecycle registry:
|
|
767
|
+
* four sites consulting four different structures is how the engine ended up
|
|
768
|
+
* with four different answers for the same order.
|
|
769
|
+
*
|
|
770
|
+
* A `createUncertain` slot flag (persisted across restarts) is folded into
|
|
771
|
+
* `phase === 'unknown'` here, so no caller has to remember to check it.
|
|
772
|
+
*
|
|
773
|
+
* @param identity - Slot id, chain order id, or pending-broadcast fingerprint
|
|
774
|
+
* @returns {LifecycleView} Unified read surface (never null)
|
|
775
|
+
*/
|
|
776
|
+
getLifecycle(identity: string | null | undefined): LifecycleView;
|
|
777
|
+
/**
|
|
778
|
+
* Lifecycle view for a slot, folding in the slot's own persisted flags.
|
|
779
|
+
* Prefer this over `getLifecycle(slotId)` wherever a slot object is at hand.
|
|
780
|
+
* @param slot - Grid slot (ManagedOrder) or null
|
|
781
|
+
* @returns {LifecycleView}
|
|
782
|
+
*/
|
|
783
|
+
getSlotLifecycle(slot: {
|
|
784
|
+
id?: string;
|
|
785
|
+
orderId?: string | null;
|
|
786
|
+
createUncertain?: boolean;
|
|
787
|
+
} | null | undefined): LifecycleView;
|
|
548
788
|
_normalizeOrderUpdateOptions(options?: UnknownRecord): {
|
|
549
789
|
skipAccounting: boolean;
|
|
550
790
|
fee: number;
|
|
@@ -555,6 +795,34 @@ declare class OrderManager implements OrderManagerLike {
|
|
|
555
795
|
};
|
|
556
796
|
_updateOrder(order: ManagedOrder, context?: string, options?: UnknownRecord): Promise<boolean>;
|
|
557
797
|
_applyOrderUpdate(order: ManagedOrder, context?: string, options?: UnknownRecord): Promise<boolean>;
|
|
798
|
+
/**
|
|
799
|
+
* Project one order mutation into the lifecycle registry.
|
|
800
|
+
*
|
|
801
|
+
* This is the single write funnel for chain existence: every mutation goes
|
|
802
|
+
* through `_applyOrderUpdate`, so no call site has to remember which of the
|
|
803
|
+
* seven legacy structures to touch. A slot is the record's identity, so a
|
|
804
|
+
* chain-id change (rotation / re-place) updates the same record instead of
|
|
805
|
+
* starting a parallel one.
|
|
806
|
+
*
|
|
807
|
+
* @param previous - Slot before the mutation (absent on create)
|
|
808
|
+
* @param next - Slot after the mutation
|
|
809
|
+
* @param context - Mutation context label
|
|
810
|
+
* @returns {void}
|
|
811
|
+
*/
|
|
812
|
+
_syncLifecycleFromMutation(previous: ManagedOrder | null | undefined, next: ManagedOrder, context: string): void;
|
|
813
|
+
/**
|
|
814
|
+
* Abandon an unresolved pending CREATE (TTL sweep / give-up).
|
|
815
|
+
*
|
|
816
|
+
* Distinct from `_pendingBroadcasts.delete()`: dropping an entry because the
|
|
817
|
+
* create RESOLVED leaves the slot free, while dropping it because we ran out
|
|
818
|
+
* of patience means the order may still be live. Collapsing both into one
|
|
819
|
+
* delete is how a lost receipt turned into a clean hole that got re-CREATEd.
|
|
820
|
+
*
|
|
821
|
+
* @param fingerprint - Pending-broadcast fingerprint being abandoned
|
|
822
|
+
* @param entry - The abandoned entry (carries the slot id)
|
|
823
|
+
* @returns {void}
|
|
824
|
+
*/
|
|
825
|
+
_expirePendingBroadcast(fingerprint: string, entry: PendingBroadcast | null | undefined): void;
|
|
558
826
|
_peekWorkingGrid(): WorkingGrid | null;
|
|
559
827
|
_syncWorkingGridFromMasterMutation(orderId: string, context: string): void;
|
|
560
828
|
/**
|