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.
- package/CHANGELOG.md +42 -0
- package/README.md +3 -3
- package/analysis/README.md +33 -13
- 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_liquidity.js +15 -4
- 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_chart_generator.js +190 -20
- package/dist/analysis/liquidity/liquidity_depth_model.d.ts +41 -16
- package/dist/analysis/liquidity/liquidity_depth_model.js +49 -21
- package/dist/analysis/liquidity/liquidity_view.d.ts +15 -0
- package/dist/analysis/liquidity/liquidity_view.js +11 -0
- package/dist/analysis/resolve_bot_accounts.js +7 -6
- package/dist/analysis/trade_profitability.js +2 -1
- package/dist/credential-daemon.js +13 -2
- package/dist/dexbot.js +4 -4
- 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/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/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 +620 -132
- package/dist/modules/dexbot_fill_runtime.js +124 -35
- package/dist/modules/dexbot_maintenance_runtime.js +226 -73
- 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/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 +82 -11
- package/dist/modules/order/grid_reconcile.d.ts +5 -1
- package/dist/modules/order/grid_reconcile.js +333 -210
- package/dist/modules/order/grid_reconcile_internal.d.ts +38 -2
- package/dist/modules/order/grid_reconcile_internal.js +207 -87
- package/dist/modules/order/index.d.ts +4 -0
- package/dist/modules/order/lifecycle.d.ts +353 -0
- package/dist/modules/order/lifecycle.js +1109 -0
- package/dist/modules/order/manager.d.ts +271 -5
- package/dist/modules/order/manager.js +651 -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 +13 -1
- package/dist/modules/order/sync_engine.js +153 -53
- package/dist/modules/order/utils/math.d.ts +22 -1
- package/dist/modules/order/utils/math.js +54 -1
- package/dist/modules/order/utils/order.d.ts +75 -5
- package/dist/modules/order/utils/order.js +158 -9
- package/dist/modules/order/utils/system.d.ts +18 -0
- package/dist/modules/order/utils/system.js +84 -8
- package/dist/modules/order/utils/validate.d.ts +7 -1
- package/dist/modules/order/utils/validate.js +48 -2
- 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 +132 -0
- package/dist/scripts/analyze-credit.js +54 -17
- package/dist/scripts/analyze-orders.d.ts +4 -2
- package/dist/scripts/analyze-orders.js +113 -34
- package/dist/scripts/chart_targets.js +11 -15
- package/dist/scripts/test-credit-renewal.js +12 -5
- package/docs/COW_INVARIANTS.md +67 -8
- package/docs/DEXBOT_COMPARISON.md +6 -6
- package/docs/EVOLUTION.md +9 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +1 -1
- package/docs/GRID_RECONCILE.md +17 -12
- package/docs/LOGGING.md +25 -1
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +175 -26
- package/docs/README.md +23 -2
- package/docs/WORKFLOW.md +9 -3
- package/docs/architecture.md +42 -5
- package/docs/developer_guide.md +25 -8
- package/modules/README.md +3 -0
- package/package.json +1 -1
- package/scripts/README.md +16 -0
- package/scripts/pdev.sh +14 -1
- package/scripts/pmain.sh +23 -8
- package/scripts/ptest.sh +7 -0
- package/tests/README.md +30 -1
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modules/order/placement_lock.ts - Exclusive placement region
|
|
3
|
+
*
|
|
4
|
+
* One mutex shared by EVERY chain-mutating placement path (COW batches,
|
|
5
|
+
* startup reconcile Phase 2, correction drains). The broadcast refcount in
|
|
6
|
+
* OrderManager (startBroadcasting/stopBroadcasting) only tells fills to stand
|
|
7
|
+
* aside; it does NOT stop two placement paths from broadcasting at the same
|
|
8
|
+
* time. When two paths plan from the same chain snapshot but from different
|
|
9
|
+
* masters (one update-first, one create-first) both generations can land at
|
|
10
|
+
* identical prices — the duplicate-order incident this lock closes.
|
|
11
|
+
*
|
|
12
|
+
* Design notes:
|
|
13
|
+
* - Token based (acquire returns a release lease) so callers can hold the
|
|
14
|
+
* region across a multi-chunk broadcast without wrapping the whole method
|
|
15
|
+
* in a callback. The two token-level holders (COW broadcast body, startup
|
|
16
|
+
* reconcile Phase 1+2) own their lease explicitly; every other path goes
|
|
17
|
+
* through {@link withPlacement}, which is the one acquire/release contract.
|
|
18
|
+
* - NOT reentrant. Nested work must NOT acquire again: a caller that already
|
|
19
|
+
* holds the region hands its lease to the specific inner operation (the COW
|
|
20
|
+
* pre-batch drain does this via `correctAllPriceMismatches({ placementLease })`),
|
|
21
|
+
* and that inner operation verifies it with
|
|
22
|
+
* {@link PlacementCapableManager.isPlacementLeaseCurrent} before mutating —
|
|
23
|
+
* `isPlacementActive()` is NOT a substitute, it is true for any holder.
|
|
24
|
+
* - FIFO queue with a bounded wait. A waiter that times out or observes
|
|
25
|
+
* shutdown gets `null` and MUST abort its batch instead of broadcasting.
|
|
26
|
+
*/
|
|
27
|
+
export interface PlacementLease {
|
|
28
|
+
kind: string;
|
|
29
|
+
release(): void;
|
|
30
|
+
}
|
|
31
|
+
export interface PlacementAcquireOptions {
|
|
32
|
+
timeoutMs?: number;
|
|
33
|
+
isShuttingDown?: () => boolean;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Minimal manager surface needed by {@link withPlacement}. Kept structural so
|
|
37
|
+
* callers in utils/ can use it without importing OrderManager (cycle safety).
|
|
38
|
+
*/
|
|
39
|
+
export interface PlacementCapableManager {
|
|
40
|
+
acquirePlacement?(kind: string, options?: PlacementAcquireOptions): Promise<PlacementLease | null>;
|
|
41
|
+
tryAcquirePlacement?(kind: string): PlacementLease | null;
|
|
42
|
+
isPlacementActive?(): boolean;
|
|
43
|
+
/** Whether this lease still owns the region (see leaseTokens). */
|
|
44
|
+
isPlacementLeaseCurrent?(lease: PlacementLease | null | undefined): boolean;
|
|
45
|
+
placementKind?(): string | null;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Run `fn` inside the exclusive placement region.
|
|
49
|
+
*
|
|
50
|
+
* This is the single entry point every chain-mutating placement path should
|
|
51
|
+
* use (COW broadcast, startup reconcile Phase 2, correction drains, dust /
|
|
52
|
+
* residual cancels, pool swaps). It centralizes the acquire/release contract
|
|
53
|
+
* so a path cannot forget to release.
|
|
54
|
+
*
|
|
55
|
+
* Nesting is NOT expressed here: a caller that already holds the region passes
|
|
56
|
+
* its lease to the specific inner operation, which then checks
|
|
57
|
+
* `isPlacementLeaseCurrent()` before mutating (see the placement_lock header).
|
|
58
|
+
*
|
|
59
|
+
* @returns `null` when the region could not be acquired (timeout/shutdown);
|
|
60
|
+
* callers must abort/defer their broadcast in that case.
|
|
61
|
+
*/
|
|
62
|
+
export declare function withPlacement<T>(manager: PlacementCapableManager | null | undefined, kind: string, fn: (lease: PlacementLease) => Promise<T>, options?: PlacementAcquireOptions): Promise<T | null>;
|
|
63
|
+
interface PlacementWaiter {
|
|
64
|
+
kind: string;
|
|
65
|
+
resolve: (lease: PlacementLease | null) => void;
|
|
66
|
+
timer: ReturnType<typeof setTimeout> | null;
|
|
67
|
+
}
|
|
68
|
+
declare class PlacementLock {
|
|
69
|
+
_holder: string | null;
|
|
70
|
+
_since: number;
|
|
71
|
+
_waiters: PlacementWaiter[];
|
|
72
|
+
_token: number;
|
|
73
|
+
_onRegionEnd: (() => void) | null;
|
|
74
|
+
constructor(onRegionEnd?: () => void);
|
|
75
|
+
_notifyRegionEnd(): void;
|
|
76
|
+
isHeld(): boolean;
|
|
77
|
+
kind(): string | null;
|
|
78
|
+
heldForMs(): number;
|
|
79
|
+
queueLength(): number;
|
|
80
|
+
/**
|
|
81
|
+
* Acquire the exclusive placement region.
|
|
82
|
+
* Resolves with a lease, or null when the wait timed out / shutdown began.
|
|
83
|
+
*/
|
|
84
|
+
acquire(kind: string, options?: PlacementAcquireOptions): Promise<PlacementLease | null>;
|
|
85
|
+
/**
|
|
86
|
+
* Non-blocking acquire used by paths that must defer instead of queue.
|
|
87
|
+
* @returns a lease when the region was free, otherwise null.
|
|
88
|
+
*/
|
|
89
|
+
tryAcquire(kind: string): PlacementLease | null;
|
|
90
|
+
/**
|
|
91
|
+
* Force-release the region on shutdown: every waiter resolves null and the
|
|
92
|
+
* current holder's lease becomes a no-op. A hung broadcast can never block
|
|
93
|
+
* process exit on this lock.
|
|
94
|
+
*/
|
|
95
|
+
forceRelease(): void;
|
|
96
|
+
/** Whether the given lease is still the one that owns the region. */
|
|
97
|
+
isLeaseCurrent(lease: PlacementLease | null | undefined): boolean;
|
|
98
|
+
_makeLease(kind: string, token: number): PlacementLease;
|
|
99
|
+
_release(token: number): void;
|
|
100
|
+
}
|
|
101
|
+
export default PlacementLock;
|
|
102
|
+
//# sourceMappingURL=placement_lock.d.ts.map
|
|
@@ -0,0 +1,222 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* modules/order/placement_lock.ts - Exclusive placement region
|
|
3
|
+
*
|
|
4
|
+
* One mutex shared by EVERY chain-mutating placement path (COW batches,
|
|
5
|
+
* startup reconcile Phase 2, correction drains). The broadcast refcount in
|
|
6
|
+
* OrderManager (startBroadcasting/stopBroadcasting) only tells fills to stand
|
|
7
|
+
* aside; it does NOT stop two placement paths from broadcasting at the same
|
|
8
|
+
* time. When two paths plan from the same chain snapshot but from different
|
|
9
|
+
* masters (one update-first, one create-first) both generations can land at
|
|
10
|
+
* identical prices — the duplicate-order incident this lock closes.
|
|
11
|
+
*
|
|
12
|
+
* Design notes:
|
|
13
|
+
* - Token based (acquire returns a release lease) so callers can hold the
|
|
14
|
+
* region across a multi-chunk broadcast without wrapping the whole method
|
|
15
|
+
* in a callback. The two token-level holders (COW broadcast body, startup
|
|
16
|
+
* reconcile Phase 1+2) own their lease explicitly; every other path goes
|
|
17
|
+
* through {@link withPlacement}, which is the one acquire/release contract.
|
|
18
|
+
* - NOT reentrant. Nested work must NOT acquire again: a caller that already
|
|
19
|
+
* holds the region hands its lease to the specific inner operation (the COW
|
|
20
|
+
* pre-batch drain does this via `correctAllPriceMismatches({ placementLease })`),
|
|
21
|
+
* and that inner operation verifies it with
|
|
22
|
+
* {@link PlacementCapableManager.isPlacementLeaseCurrent} before mutating —
|
|
23
|
+
* `isPlacementActive()` is NOT a substitute, it is true for any holder.
|
|
24
|
+
* - FIFO queue with a bounded wait. A waiter that times out or observes
|
|
25
|
+
* shutdown gets `null` and MUST abort its batch instead of broadcasting.
|
|
26
|
+
*/
|
|
27
|
+
/**
|
|
28
|
+
* Lease → lock token registry.
|
|
29
|
+
*
|
|
30
|
+
* A lease object is all a nested caller holds, so it cannot prove ownership by
|
|
31
|
+
* `isPlacementActive()` (any holder satisfies that). The token the lock stamped
|
|
32
|
+
* into the lease at hand-out time is kept here out-of-band (WeakMap), which
|
|
33
|
+
* keeps the public lease shape unchanged while letting the lock answer "is this
|
|
34
|
+
* still the lease that owns the region?".
|
|
35
|
+
*/
|
|
36
|
+
const leaseTokens = new WeakMap();
|
|
37
|
+
/** Used when the caller has no lock (dry-run mocks / browser shims). */
|
|
38
|
+
const NOOP_PLACEMENT_LEASE = { kind: 'noop', release: () => { } };
|
|
39
|
+
/**
|
|
40
|
+
* Run `fn` inside the exclusive placement region.
|
|
41
|
+
*
|
|
42
|
+
* This is the single entry point every chain-mutating placement path should
|
|
43
|
+
* use (COW broadcast, startup reconcile Phase 2, correction drains, dust /
|
|
44
|
+
* residual cancels, pool swaps). It centralizes the acquire/release contract
|
|
45
|
+
* so a path cannot forget to release.
|
|
46
|
+
*
|
|
47
|
+
* Nesting is NOT expressed here: a caller that already holds the region passes
|
|
48
|
+
* its lease to the specific inner operation, which then checks
|
|
49
|
+
* `isPlacementLeaseCurrent()` before mutating (see the placement_lock header).
|
|
50
|
+
*
|
|
51
|
+
* @returns `null` when the region could not be acquired (timeout/shutdown);
|
|
52
|
+
* callers must abort/defer their broadcast in that case.
|
|
53
|
+
*/
|
|
54
|
+
export async function withPlacement(manager, kind, fn, options = {}) {
|
|
55
|
+
if (!manager || typeof manager.acquirePlacement !== 'function') {
|
|
56
|
+
return await fn(NOOP_PLACEMENT_LEASE);
|
|
57
|
+
}
|
|
58
|
+
const acquireOptions = {
|
|
59
|
+
...(options.timeoutMs != null ? { timeoutMs: options.timeoutMs } : {}),
|
|
60
|
+
...(options.isShuttingDown ? { isShuttingDown: options.isShuttingDown } : {}),
|
|
61
|
+
};
|
|
62
|
+
const lease = await manager.acquirePlacement(kind, acquireOptions);
|
|
63
|
+
if (!lease)
|
|
64
|
+
return null;
|
|
65
|
+
try {
|
|
66
|
+
return await fn(lease);
|
|
67
|
+
}
|
|
68
|
+
finally {
|
|
69
|
+
lease.release();
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
class PlacementLock {
|
|
73
|
+
_holder;
|
|
74
|
+
_since;
|
|
75
|
+
_waiters;
|
|
76
|
+
_token;
|
|
77
|
+
_onRegionEnd;
|
|
78
|
+
constructor(onRegionEnd) {
|
|
79
|
+
this._holder = null;
|
|
80
|
+
this._since = 0;
|
|
81
|
+
this._waiters = [];
|
|
82
|
+
this._token = 0;
|
|
83
|
+
this._onRegionEnd = typeof onRegionEnd === 'function' ? onRegionEnd : null;
|
|
84
|
+
}
|
|
85
|
+
_notifyRegionEnd() {
|
|
86
|
+
if (!this._onRegionEnd)
|
|
87
|
+
return;
|
|
88
|
+
try {
|
|
89
|
+
this._onRegionEnd();
|
|
90
|
+
}
|
|
91
|
+
catch { /* listener errors must never escape a release */ }
|
|
92
|
+
}
|
|
93
|
+
isHeld() {
|
|
94
|
+
return this._holder !== null;
|
|
95
|
+
}
|
|
96
|
+
kind() {
|
|
97
|
+
return this._holder;
|
|
98
|
+
}
|
|
99
|
+
heldForMs() {
|
|
100
|
+
return this._holder !== null && this._since > 0 ? Date.now() - this._since : 0;
|
|
101
|
+
}
|
|
102
|
+
queueLength() {
|
|
103
|
+
return this._waiters.length;
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Acquire the exclusive placement region.
|
|
107
|
+
* Resolves with a lease, or null when the wait timed out / shutdown began.
|
|
108
|
+
*/
|
|
109
|
+
async acquire(kind, options = {}) {
|
|
110
|
+
const timeoutMs = Number.isFinite(Number(options.timeoutMs)) && Number(options.timeoutMs) > 0
|
|
111
|
+
? Number(options.timeoutMs)
|
|
112
|
+
: 30000;
|
|
113
|
+
const isShuttingDown = typeof options.isShuttingDown === 'function'
|
|
114
|
+
? options.isShuttingDown
|
|
115
|
+
: () => false;
|
|
116
|
+
if (isShuttingDown())
|
|
117
|
+
return null;
|
|
118
|
+
if (this._holder === null) {
|
|
119
|
+
this._holder = kind;
|
|
120
|
+
this._since = Date.now();
|
|
121
|
+
this._token += 1;
|
|
122
|
+
return this._makeLease(kind, this._token);
|
|
123
|
+
}
|
|
124
|
+
return await new Promise((resolve) => {
|
|
125
|
+
const waiter = { kind, resolve, timer: null };
|
|
126
|
+
waiter.timer = setTimeout(() => {
|
|
127
|
+
const idx = this._waiters.indexOf(waiter);
|
|
128
|
+
if (idx >= 0)
|
|
129
|
+
this._waiters.splice(idx, 1);
|
|
130
|
+
resolve(null);
|
|
131
|
+
}, timeoutMs);
|
|
132
|
+
this._waiters.push(waiter);
|
|
133
|
+
if (isShuttingDown()) {
|
|
134
|
+
const idx = this._waiters.indexOf(waiter);
|
|
135
|
+
if (idx >= 0)
|
|
136
|
+
this._waiters.splice(idx, 1);
|
|
137
|
+
if (waiter.timer)
|
|
138
|
+
clearTimeout(waiter.timer);
|
|
139
|
+
resolve(null);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Non-blocking acquire used by paths that must defer instead of queue.
|
|
145
|
+
* @returns a lease when the region was free, otherwise null.
|
|
146
|
+
*/
|
|
147
|
+
tryAcquire(kind) {
|
|
148
|
+
// Fairness: never barge ahead of waiters queued behind the holder.
|
|
149
|
+
// Otherwise a rapid try-acquire loop can starve a bounded waiter until
|
|
150
|
+
// its timeout even though the region is momentarily free.
|
|
151
|
+
if (this._holder !== null || this._waiters.length > 0)
|
|
152
|
+
return null;
|
|
153
|
+
this._holder = kind;
|
|
154
|
+
this._since = Date.now();
|
|
155
|
+
this._token += 1;
|
|
156
|
+
return this._makeLease(kind, this._token);
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Force-release the region on shutdown: every waiter resolves null and the
|
|
160
|
+
* current holder's lease becomes a no-op. A hung broadcast can never block
|
|
161
|
+
* process exit on this lock.
|
|
162
|
+
*/
|
|
163
|
+
forceRelease() {
|
|
164
|
+
const waiters = this._waiters.splice(0, this._waiters.length);
|
|
165
|
+
for (const waiter of waiters) {
|
|
166
|
+
if (waiter.timer)
|
|
167
|
+
clearTimeout(waiter.timer);
|
|
168
|
+
waiter.resolve(null);
|
|
169
|
+
}
|
|
170
|
+
this._holder = null;
|
|
171
|
+
this._since = 0;
|
|
172
|
+
this._token += 1;
|
|
173
|
+
this._notifyRegionEnd();
|
|
174
|
+
}
|
|
175
|
+
/** Whether the given lease is still the one that owns the region. */
|
|
176
|
+
isLeaseCurrent(lease) {
|
|
177
|
+
if (!lease || this._holder === null)
|
|
178
|
+
return false;
|
|
179
|
+
const token = leaseTokens.get(lease);
|
|
180
|
+
return token !== undefined && token === this._token;
|
|
181
|
+
}
|
|
182
|
+
_makeLease(kind, token) {
|
|
183
|
+
let released = false;
|
|
184
|
+
const lease = {
|
|
185
|
+
kind,
|
|
186
|
+
release: () => {
|
|
187
|
+
if (released)
|
|
188
|
+
return;
|
|
189
|
+
released = true;
|
|
190
|
+
this._release(token);
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
leaseTokens.set(lease, token);
|
|
194
|
+
return lease;
|
|
195
|
+
}
|
|
196
|
+
_release(token) {
|
|
197
|
+
// Stale-lease guard: a lease released after forceRelease (or after the
|
|
198
|
+
// lock was re-acquired by someone else) must NOT release the current
|
|
199
|
+
// holder. Only the token that still owns the region may release it.
|
|
200
|
+
if (token !== this._token || this._holder === null)
|
|
201
|
+
return;
|
|
202
|
+
const next = this._waiters.shift();
|
|
203
|
+
if (!next) {
|
|
204
|
+
this._holder = null;
|
|
205
|
+
this._since = 0;
|
|
206
|
+
this._token += 1;
|
|
207
|
+
// The region is fully free: wake any fill/rebalance that deferred
|
|
208
|
+
// on isPlacementActive(). A handoff keeps the region contiguous and
|
|
209
|
+
// must NOT wake intermediate work.
|
|
210
|
+
this._notifyRegionEnd();
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
if (next.timer)
|
|
214
|
+
clearTimeout(next.timer);
|
|
215
|
+
this._holder = next.kind;
|
|
216
|
+
this._since = Date.now();
|
|
217
|
+
this._token += 1;
|
|
218
|
+
next.resolve(this._makeLease(next.kind, this._token));
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
export default PlacementLock;
|
|
222
|
+
//# sourceMappingURL=placement_lock.js.map
|
|
@@ -272,8 +272,20 @@ class StrategyEngine {
|
|
|
272
272
|
// inventory. The fill is the anchor: place it outside its own window.
|
|
273
273
|
// Validated like a boundary commit (strands no live in-band order), and
|
|
274
274
|
// only for an on-ladder fill price.
|
|
275
|
-
const
|
|
275
|
+
const allowReanchor = (() => {
|
|
276
|
+
const budget = this.manager._boundaryReanchorBudget;
|
|
277
|
+
// undefined = legacy/no fill cycle: allowed. 0 = this fill cycle
|
|
278
|
+
// already consumed its one absolute anchor. >0 = budget remaining.
|
|
279
|
+
return budget === undefined || Number(budget) !== 0;
|
|
280
|
+
})();
|
|
281
|
+
const reanchor = allowReanchor
|
|
282
|
+
? reanchorBoundaryFromLastFill(this.manager, newBoundaryIdx, allSlots, gapSlots, fills)
|
|
283
|
+
: { boundaryIdx: newBoundaryIdx, reanchored: false };
|
|
276
284
|
if (reanchor.reanchored) {
|
|
285
|
+
const budget = Number(this.manager._boundaryReanchorBudget);
|
|
286
|
+
this.manager._boundaryReanchorBudget = Number.isFinite(budget) && budget > 0
|
|
287
|
+
? budget - 1
|
|
288
|
+
: 0;
|
|
277
289
|
newBoundaryIdx = reanchor.boundaryIdx;
|
|
278
290
|
// An absolute fill anchor already reflects every older owed crawl.
|
|
279
291
|
// The derivation may have left records owed (cap exhausted, mixed
|
|
@@ -151,6 +151,17 @@ interface FillTransitionParams {
|
|
|
151
151
|
* (GRID-PRICE-INVARIANT).
|
|
152
152
|
*/
|
|
153
153
|
fillPrice?: number | null;
|
|
154
|
+
/**
|
|
155
|
+
* Base-amount units of this fill already reflected in the chain snapshot
|
|
156
|
+
* by sync pass 1. The transition subtracts only `filledAmountInt -
|
|
157
|
+
* alreadyAppliedInt`; a partial value handles split/aggregated fills.
|
|
158
|
+
*/
|
|
159
|
+
alreadyAppliedInt?: number;
|
|
160
|
+
/**
|
|
161
|
+
* Backward-compatible boolean form: true means the whole fill was already
|
|
162
|
+
* applied (equivalent to alreadyAppliedInt = filledAmountInt).
|
|
163
|
+
*/
|
|
164
|
+
alreadyAppliedChainSize?: boolean;
|
|
154
165
|
}
|
|
155
166
|
interface SyncChainData {
|
|
156
167
|
gridOrderId?: string;
|
|
@@ -284,6 +295,7 @@ declare class SyncEngine {
|
|
|
284
295
|
* @param {number} assetBPrecision - Asset B precision
|
|
285
296
|
* @param {Map<string, any>} parsedChainOrders - Parsed chain orders by ID
|
|
286
297
|
* @param {Map<string, Object>} rawChainOrders - Raw blockchain order objects by ID
|
|
298
|
+
* @param {Set<string>} malformedChainOrderIds - Chain order IDs that were returned but could not be parsed (UNKNOWN, not absent)
|
|
287
299
|
* @param {Set<string>} chainOrderIdsOnGrid - Output set: chain order IDs matched to grid
|
|
288
300
|
* @param {Set<string>} matchedGridOrderIds - Output set: grid order IDs matched to chain
|
|
289
301
|
* @param {Array<Object>} filledOrders - Output array: orders detected as filled
|
|
@@ -293,7 +305,7 @@ declare class SyncEngine {
|
|
|
293
305
|
* @param {Object} options - Sync options (skipAccounting, etc.)
|
|
294
306
|
* @returns {Promise<any>}
|
|
295
307
|
*/
|
|
296
|
-
_performSyncFromOpenOrders(mgr: OrderManagerLike, assetAPrecision: number, assetBPrecision: number, parsedChainOrders: Map<string, ParsedChainOrder>, rawChainOrders: Map<string, Record<string, unknown>>, chainOrderIdsOnGrid: Set<string>, matchedGridOrderIds: Set<string>, filledOrders: ManagedOrder[], updatedOrders: ManagedOrder[], ordersNeedingCorrection: PendingPriceCorrection[], unmatchedChainOrders: UnmatchedChainOrder[], options: Record<string, unknown>): Promise<{
|
|
308
|
+
_performSyncFromOpenOrders(mgr: OrderManagerLike, assetAPrecision: number, assetBPrecision: number, parsedChainOrders: Map<string, ParsedChainOrder>, rawChainOrders: Map<string, Record<string, unknown>>, malformedChainOrderIds: Set<string>, chainOrderIdsOnGrid: Set<string>, matchedGridOrderIds: Set<string>, filledOrders: ManagedOrder[], updatedOrders: ManagedOrder[], ordersNeedingCorrection: PendingPriceCorrection[], unmatchedChainOrders: UnmatchedChainOrder[], options: Record<string, unknown>): Promise<{
|
|
297
309
|
filledOrders: ManagedOrder[];
|
|
298
310
|
updatedOrders: ManagedOrder[];
|
|
299
311
|
ordersNeedingCorrection: PendingPriceCorrection[];
|