dexbot 1.6.3 โ 1.6.5
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 +78 -2
- package/README.md +23 -19
- package/analysis/README.md +26 -13
- package/analysis/account_resolver.ts +171 -0
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +2 -5
- package/analysis/ama_fitting/package.json +1 -1
- package/analysis/analyze_dynamic_weight.ts +9 -3
- package/analysis/bot_usage/discover_bot_accounts.ts +20 -27
- package/analysis/chain_pool.ts +47 -0
- package/analysis/chart_utils.ts +33 -20
- package/analysis/derivative_chart_generator.ts +2 -3
- package/analysis/fills_source.ts +234 -0
- package/analysis/grid_correction_check.ts +38 -251
- package/analysis/trade_profitability.ts +169 -304
- package/analysis/tradingview/README.md +2 -2
- package/analysis/tradingview/analyze_tradingview.ts +5 -0
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +5 -6
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +35 -2
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +84 -13
- package/analysis/trend_detection/kalman_chart_generator.ts +2 -3
- package/analysis/trend_detection/package.json +1 -1
- package/analysis/trend_detection/regime_chart_generator.ts +2 -3
- package/analysis/trend_detection/volatility_chart_generator.ts +2 -3
- package/claw/modules/dexbot_profiles.ts +4 -3
- 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/claw/tests/test_claw_mcp_transport.ts +2 -2
- package/claw/tests/test_dexbot_profiles.ts +18 -1
- package/dist/analysis/account_resolver.d.ts +43 -0
- package/dist/analysis/account_resolver.d.ts.map +1 -0
- package/dist/analysis/account_resolver.js +137 -0
- package/dist/analysis/account_resolver.js.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +1 -1
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -4
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -1
- package/dist/analysis/analyze_dynamic_weight.js +9 -3
- package/dist/analysis/analyze_dynamic_weight.js.map +1 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js +20 -28
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -1
- package/dist/analysis/chain_pool.d.ts +10 -0
- package/dist/analysis/chain_pool.d.ts.map +1 -0
- package/dist/analysis/chain_pool.js +47 -0
- package/dist/analysis/chain_pool.js.map +1 -0
- package/dist/analysis/chart_utils.d.ts +14 -1
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +32 -22
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/derivative_chart_generator.d.ts.map +1 -1
- package/dist/analysis/derivative_chart_generator.js +2 -3
- package/dist/analysis/derivative_chart_generator.js.map +1 -1
- package/dist/analysis/fills_source.d.ts +79 -0
- package/dist/analysis/fills_source.d.ts.map +1 -0
- package/dist/analysis/fills_source.js +186 -0
- package/dist/analysis/fills_source.js.map +1 -0
- package/dist/analysis/grid_correction_check.d.ts +1 -21
- package/dist/analysis/grid_correction_check.d.ts.map +1 -1
- package/dist/analysis/grid_correction_check.js +30 -257
- package/dist/analysis/grid_correction_check.js.map +1 -1
- package/dist/analysis/trade_profitability.d.ts +18 -19
- package/dist/analysis/trade_profitability.d.ts.map +1 -1
- package/dist/analysis/trade_profitability.js +136 -280
- package/dist/analysis/trade_profitability.js.map +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.js +5 -0
- package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +5 -6
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +84 -13
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +2 -3
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +2 -3
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +1 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js +2 -3
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -1
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +27 -68
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +2 -2
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.js +15 -12
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
- package/dist/market_adapter/interval_utils.d.ts +1 -1
- package/dist/market_adapter/interval_utils.js +1 -1
- package/dist/market_adapter/lp_chart_core.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_core.js +2 -3
- package/dist/market_adapter/lp_chart_core.js.map +1 -1
- package/dist/modules/account_bots.d.ts +51 -18
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +258 -117
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts +1 -84
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.js +1 -38
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
- package/dist/modules/bot_defaults.d.ts +98 -0
- package/dist/modules/bot_defaults.d.ts.map +1 -0
- package/dist/modules/bot_defaults.js +169 -0
- package/dist/modules/bot_defaults.js.map +1 -0
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +4 -1
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/cli_colors.d.ts +0 -1
- package/dist/modules/cli_colors.d.ts.map +1 -1
- package/dist/modules/config.d.ts +1 -0
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +1 -0
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +11 -2
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +45 -32
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/credential_policy.d.ts +1 -25
- package/dist/modules/credential_policy.d.ts.map +1 -1
- package/dist/modules/credential_policy.js +1 -1
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/credential_runtime.d.ts +1 -6
- package/dist/modules/credential_runtime.d.ts.map +1 -1
- package/dist/modules/credential_runtime.js +1 -1
- package/dist/modules/credential_runtime.js.map +1 -1
- package/dist/modules/credential_session_cache.d.ts +1 -5
- package/dist/modules/credential_session_cache.d.ts.map +1 -1
- package/dist/modules/credential_session_cache.js +1 -1
- package/dist/modules/credential_session_cache.js.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts +1 -2
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.js +1 -1
- package/dist/modules/crypto/pure_secp256k1.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +8 -7
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +9 -8
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +7 -6
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +8 -7
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +1 -17
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +1 -1
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +2 -2
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +24 -8
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts +1 -7
- package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
- package/dist/modules/dexbot_state_recovery.js +1 -1
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/launcher/adapter_requirement.d.ts +1 -5
- package/dist/modules/launcher/adapter_requirement.d.ts.map +1 -1
- package/dist/modules/launcher/adapter_requirement.js +2 -2
- package/dist/modules/launcher/adapter_requirement.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts +1 -6
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +1 -1
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +1 -3
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/launch_modes.d.ts +17 -2
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -1
- package/dist/modules/launcher/launch_modes.js +18 -1
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts +1 -3
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts +1 -5
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +9 -2
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +1 -2
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +1 -1
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/market_adapter_whitelist.d.ts +40 -1
- package/dist/modules/market_adapter_whitelist.d.ts.map +1 -1
- package/dist/modules/market_adapter_whitelist.js +161 -11
- package/dist/modules/market_adapter_whitelist.js.map +1 -1
- package/dist/modules/order/export.d.ts +1 -8
- package/dist/modules/order/export.d.ts.map +1 -1
- package/dist/modules/order/export.js +1 -1
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/grid.d.ts +16 -0
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +75 -103
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts +1 -10
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +2 -2
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/manager.d.ts +10 -2
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +20 -8
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +8 -15
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +1 -10
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +1 -1
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +5 -16
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +7 -4
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/process_discovery.d.ts +0 -3
- package/dist/modules/process_discovery.d.ts.map +1 -1
- package/dist/modules/process_discovery.js +1 -1
- package/dist/modules/process_discovery.js.map +1 -1
- package/dist/modules/settings_merge.d.ts +10 -1
- package/dist/modules/settings_merge.d.ts.map +1 -1
- package/dist/modules/settings_merge.js +27 -17
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/utils/chain_logs.d.ts +1 -2
- package/dist/modules/utils/chain_logs.d.ts.map +1 -1
- package/dist/modules/utils/chain_logs.js +1 -1
- package/dist/modules/utils/chain_logs.js.map +1 -1
- package/dist/modules/validate_profiles.d.ts.map +1 -1
- package/dist/modules/validate_profiles.js +4 -3
- package/dist/modules/validate_profiles.js.map +1 -1
- package/dist/scripts/analyze-git.js +2 -2
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/chart_command.d.ts +48 -0
- package/dist/scripts/chart_command.d.ts.map +1 -0
- package/dist/scripts/chart_command.js +504 -0
- package/dist/scripts/chart_command.js.map +1 -0
- package/dist/scripts/dw.d.ts +3 -0
- package/dist/scripts/dw.d.ts.map +1 -0
- package/dist/scripts/dw.js +30 -0
- package/dist/scripts/dw.js.map +1 -0
- package/dist/scripts/tv.d.ts +1 -31
- package/dist/scripts/tv.d.ts.map +1 -1
- package/dist/scripts/tv.js +10 -463
- package/dist/scripts/tv.js.map +1 -1
- package/dist/scripts/update.js +145 -93
- package/dist/scripts/update.js.map +1 -1
- package/dist/scripts/update_dist_freshness.d.ts +46 -0
- package/dist/scripts/update_dist_freshness.d.ts.map +1 -0
- package/dist/scripts/update_dist_freshness.js +115 -0
- package/dist/scripts/update_dist_freshness.js.map +1 -0
- package/dist/unlock.js +1 -1
- package/dist/unlock.js.map +1 -1
- package/docs/BITSHARES_ONBOARDING.md +117 -44
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +10 -207
- package/docs/COW_INVARIANTS.md +16 -10
- package/docs/DEXBOT_COMPARISON.md +3 -3
- package/docs/EVOLUTION.md +76 -30
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +9 -9
- package/docs/GRID_RECALCULATION.md +34 -30
- package/docs/GRID_RECONCILE.md +30 -27
- package/docs/LIFECYCLE.md +12 -11
- package/docs/LOGGING.md +1 -0
- package/docs/README.md +58 -52
- package/docs/WORKFLOW.md +1 -2
- package/docs/architecture.md +21 -32
- package/docs/developer_guide.md +4 -3
- package/market_adapter/README.md +36 -60
- package/modules/README.md +2 -1
- package/package.json +1 -2
- package/scripts/README.md +18 -25
- package/scripts/git-viewer.sh +1 -1
- package/scripts/reset-settings.sh +1 -1
- package/tests/README.md +10 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts +0 -15
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +0 -1
- package/dist/scripts/generate_market_adapter_whitelist.js +0 -191
- package/dist/scripts/generate_market_adapter_whitelist.js.map +0 -1
|
@@ -25,7 +25,7 @@ rebuild around that snapshot.
|
|
|
25
25
|
| **Initial AMA Snapshot** | Market adapter | Bot has no accepted AMA `gridCenterPrice` yet | Write `dynamicgrid.json`, then write a trigger file | Full grid resync around the first accepted AMA center |
|
|
26
26
|
| **AMA Center Move** | Market adapter | Current AMA center moves past the configured delta threshold | Write `dynamicgrid.json`, then write a trigger file | Full grid resync around the new accepted AMA center |
|
|
27
27
|
| **AMA Slope Range Move** | Market adapter | Range-scaling bot's accepted AMA-slope baseline moves past threshold | Write range-scaling fields to `dynamicgrid.json`, then write a trigger file | Full grid resync with updated asymmetric range/offset data |
|
|
28
|
-
| **RMS Structural Divergence** | Bot runtime maintenance | Current grid shape diverges from persisted
|
|
28
|
+
| **RMS Structural Divergence** | Bot runtime maintenance | Current grid shape diverges from persisted grid (ACTIVE + VIRTUAL) by RMS threshold | Refresh `gridCenterPrice` from latest `amaCenterPrice`, then run full grid resync | Full grid resync from latest market-adapter snapshot |
|
|
29
29
|
| **Available-Funds Resize** | Bot runtime maintenance | Filled-order proceeds exceed `GRID_REGENERATION_PERCENTAGE` (grow), or grid-tracked size exceeds allocation by that threshold after fund removal (shrink) | Recalculate affected side/order sizes through maintenance logic | Order-size/grid maintenance update, not an AMA recenter trigger |
|
|
30
30
|
|
|
31
31
|
Each source is evaluated independently. Market-adapter full-resync requests are
|
|
@@ -260,27 +260,10 @@ need a reset to move to the new asymmetric range and offset placement price.
|
|
|
260
260
|
### Configuration
|
|
261
261
|
|
|
262
262
|
Range scaling is enabled by the whitelist's `asymmetricBounds: true` flag.
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
This writes `profiles/market_adapter_whitelist.json`. The default generation
|
|
270
|
-
enables AMA live writes for new AMA bots, while leaving dynamic weights and
|
|
271
|
-
range scaling disabled.
|
|
272
|
-
|
|
273
|
-
To opt new AMA entries into range scaling:
|
|
274
|
-
|
|
275
|
-
```bash
|
|
276
|
-
dexbot white --asymmetric-bounds
|
|
277
|
-
```
|
|
278
|
-
|
|
279
|
-
To overwrite one existing bot (otherwise preserved):
|
|
280
|
-
|
|
281
|
-
```bash
|
|
282
|
-
dexbot white --asymmetric-bounds --bot <botKey>
|
|
283
|
-
```
|
|
263
|
+
Set it per bot in the editor: `dexbot bot` โ `2) Modify bot` โ pick the bot โ
|
|
264
|
+
`6) Adapter` โ **Range** = yes. The flag is stored in
|
|
265
|
+
`profiles/market_adapter_whitelist.json` next to **Price** (AMA pricing) and
|
|
266
|
+
**Weight** (dynamic weights); all three default to off until enabled.
|
|
284
267
|
|
|
285
268
|
The snapshot fields involved are:
|
|
286
269
|
|
|
@@ -290,6 +273,14 @@ The snapshot fields involved are:
|
|
|
290
273
|
- `amaSlopeDeltaPercent`: distance from the accepted baseline
|
|
291
274
|
- `amaSlopeThresholdPercent`: threshold required to trigger the reset
|
|
292
275
|
|
|
276
|
+
**Trigger threshold.** By default the reset fires when the slope delta crosses
|
|
277
|
+
`AMA_SLOPE_DELTA_THRESHOLD_PERCENT`, a percentage of the AMA max slope
|
|
278
|
+
(`(value/100) ร maxSlopePct`) โ default `8%`, stored under `MARKET_ADAPTER` in
|
|
279
|
+
`profiles/general.settings.json` and editable via `dexbot bot` โ `1) Grid
|
|
280
|
+
Health` (`AMA-Slope ฮ`). An explicit `amaSlopeDeltaThresholdPercent` in
|
|
281
|
+
`profiles/market_adapter_settings.json` bypasses the factor and is used
|
|
282
|
+
directly as an average percent-per-bar threshold.
|
|
283
|
+
|
|
293
284
|
AMA slope values are stored and compared as average percent per bar. Older
|
|
294
285
|
settings that used cumulative percent over the full lookback can either be
|
|
295
286
|
divided by `amaSlope.lookbackBars`, or marked with
|
|
@@ -313,17 +304,25 @@ so the adapter converts them when loading overrides. New settings should use
|
|
|
313
304
|
|
|
314
305
|
### What It Does
|
|
315
306
|
Compares the **calculated grid** currently held by the bot with the
|
|
316
|
-
**persisted
|
|
317
|
-
|
|
307
|
+
**persisted grid state** (ACTIVE on-chain orders plus VIRTUAL planned
|
|
308
|
+
reservations). When structural divergence exceeds the threshold, the bot
|
|
309
|
+
performs a full grid resync.
|
|
310
|
+
|
|
311
|
+
**Scope (per side):** the metric covers **ACTIVE + VIRTUAL** orders. PARTIAL
|
|
312
|
+
orders are excluded (expected to deviate mid-fill) and SPREAD placeholders are
|
|
313
|
+
excluded (size-0). VIRTUAL slots carry the planned reservation for unplaced
|
|
314
|
+
rail slots (`funds.virtual`), so a persisted-vs-ideal drift there moves
|
|
315
|
+
`Available = ChainFree โ Virtual โ fees` and is treated as structural.
|
|
318
316
|
|
|
319
317
|
**Why it matters:** Order fills, rotations, and fee deductions can make the
|
|
320
|
-
|
|
318
|
+
grid shape drift away from the stored picture. RMS divergence
|
|
321
319
|
detects that structural drift. Once it crosses the threshold, DEXBot rebuilds
|
|
322
320
|
from the latest market-adapter snapshot instead of trying to keep patching the
|
|
323
321
|
old shape.
|
|
324
322
|
|
|
325
323
|
The RMS calculation compares the runtime grid (calculated from the bot's
|
|
326
|
-
config and live dynamic weights) against the persisted
|
|
324
|
+
config and live dynamic weights) against the persisted grid state
|
|
325
|
+
(ACTIVE + VIRTUAL).
|
|
327
326
|
Crossing the threshold only changes the follow-up action: the bot refreshes
|
|
328
327
|
`gridCenterPrice` from the latest `amaCenterPrice` in `dynamicgrid.json`,
|
|
329
328
|
then runs the full resync path.
|
|
@@ -336,7 +335,7 @@ code paths and log differently:
|
|
|
336
335
|
|
|
337
336
|
| Path | Fires from | Trigger | Log signature |
|
|
338
337
|
|------|-----------|---------|---------------|
|
|
339
|
-
| **Periodic divergence** | `dexbot_maintenance_runtime.ts` periodic sync loop | `Grid.monitorDivergence()` reports `buy.rms` or `sell.rms` above threshold | `Grid update triggered by structural divergence during periodic: buy
|
|
338
|
+
| **Periodic divergence** | `dexbot_maintenance_runtime.ts` periodic sync loop | `Grid.monitorDivergence()` reports `buy.rms` or `sell.rms` above threshold | `[RMS] Grid update triggered by structural divergence during periodic: buy=...% sell=...% (threshold=...%) sides=... โ TRIGGER-RESYNC (rms_structural_grid_resync)` |
|
|
340
339
|
| **Structural recovery (COW guard)** | `dexbot_class.ts` `_wireStructuralGridResyncRequest()` | Order manager detects unmatched chain orders during copy-on-write placement | `[RECOVERY] Running structural full grid resync for <reason> (N unmatched chain order(s))` |
|
|
341
340
|
|
|
342
341
|
The structural-recovery path is debounced through `_structuralGridResyncTimer`
|
|
@@ -376,7 +375,7 @@ and dedupes while one resync is already pending or running.
|
|
|
376
375
|
### How It Works
|
|
377
376
|
|
|
378
377
|
1. **Grid Engine** (`modules/order/grid.ts`) calculates the ideal grid state
|
|
379
|
-
2. Compares with the
|
|
378
|
+
2. Compares with the persisted grid state โ ACTIVE on-chain orders plus VIRTUAL planned reservations โ after fills/rotations
|
|
380
379
|
3. Computes RMS divergence metric:
|
|
381
380
|
```
|
|
382
381
|
RMS = โ(mean of ((calculated - persisted) / persisted)ยฒ)
|
|
@@ -558,11 +557,16 @@ market_adapter_ama_slope_delta_threshold
|
|
|
558
557
|
|
|
559
558
|
**RMS Divergence Trigger:**
|
|
560
559
|
```
|
|
561
|
-
Grid update triggered by structural divergence during periodic: buy
|
|
560
|
+
[RMS] Grid update triggered by structural divergence during periodic: buy=16.20% sell=2.10% (threshold=14.3%) sides=buy โ TRIGGER-RESYNC (rms_structural_grid_resync)
|
|
562
561
|
Grid regeneration triggered. Performing full grid resync...
|
|
563
562
|
Recorded grid reset metadata for dynamic grid state.
|
|
564
563
|
```
|
|
565
564
|
|
|
565
|
+
At `debug` level each tick also emits the per-side check detail (mirroring the `[DIVERGENCE]` ratio-check line):
|
|
566
|
+
```
|
|
567
|
+
[RMS] BUY check: metric=...% (threshold=14.3%) โ TRIGGER-RESYNC/no trigger | SELL check: metric=...% (threshold=14.3%) โ TRIGGER-RESYNC/no trigger
|
|
568
|
+
```
|
|
569
|
+
|
|
566
570
|
**Available-Funds Resize Trigger:**
|
|
567
571
|
```
|
|
568
572
|
Grid update triggered by funds during periodic (buy: ..., sell: ...)
|
|
@@ -613,6 +617,6 @@ Removed trigger file.
|
|
|
613
617
|
- `modules/dexbot_class.ts` โ `_performGridResync()`, `requestGridReset()`, and COW-guard structural recovery wiring
|
|
614
618
|
- `modules/order/grid.ts` โ RMS divergence check and grid comparison
|
|
615
619
|
- `modules/order/manager.ts` โ Available-funds resize threshold logic
|
|
616
|
-
- `modules/market_adapter_whitelist.ts` / `
|
|
620
|
+
- `modules/market_adapter_whitelist.ts` โ Whitelist storage/read helpers (the bot editor's `6) Adapter` reads and writes the same file)
|
|
617
621
|
- `profiles/general.settings.json` โ User-editable configuration
|
|
618
622
|
- `profiles/bots.json` โ Per-bot configuration including AMA
|
package/docs/GRID_RECONCILE.md
CHANGED
|
@@ -13,7 +13,7 @@ Reconciliation aligns the bot's model with on-chain reality. It runs at startup
|
|
|
13
13
|
|
|
14
14
|
### Why Not Cancel Everything
|
|
15
15
|
|
|
16
|
-
- No atomic cancel+create on BitShares โ `
|
|
16
|
+
- No atomic cancel+create on BitShares โ `limit_order_cancel` cancels the full order; there is no partial size reduction
|
|
17
17
|
- A full teardown leaves the bot unable to trade during the rebuild window
|
|
18
18
|
|
|
19
19
|
---
|
|
@@ -38,7 +38,7 @@ Phase 2 and 3 both respect the `dryRun` flag: when true, no on-chain mutations a
|
|
|
38
38
|
โ โข Sanitize phantom orders (ACTIVE/PARTIAL with โ
|
|
39
39
|
โ orderId absent on-chain โ VIRTUAL, skip); โ
|
|
40
40
|
โ defer freshly-assigned orderIds, ghost pass โ
|
|
41
|
-
โ โข Detect suspected duplicates (
|
|
41
|
+
โ โข Detect suspected duplicates (exact price) โ โ
|
|
42
42
|
โ queue for Phase 2 cancel โ
|
|
43
43
|
โ โข Match unmatched chain orders to virtual slots โ
|
|
44
44
|
โ โ plan updates โ
|
|
@@ -85,7 +85,7 @@ Phase 2 and 3 both respect the `dryRun` flag: when true, no on-chain mutations a
|
|
|
85
85
|
- **Ghost heuristic** (line 229): an order with `size <= 0` && `PARTIAL` (a known filled ghost) still passes through so known fills get cleaned up.
|
|
86
86
|
- Virtualization always uses `{ skipAccounting: true }` so startup cleanup never inflates `ChainFree`.
|
|
87
87
|
|
|
88
|
-
2. **Duplicate detection** (lines 258-331): For each unmatched chain order, find the nearest active same-side grid order. If `
|
|
88
|
+
2. **Duplicate detection** (lines 258-331): For each unmatched chain order, find the nearest active same-side grid order. If its price equals that grid order's slot price exactly (`priceSlotEqual` at the asset precision), flag it as a suspected duplicate and queue for a Phase 2 cancel (never cancelled under lock). Non-equal neighbours are only logged with nearest-same-side diagnostics and continue into per-side reconciliation. Duplicate IDs are removed from the unmatched set so they aren't also paired for updates/creates.
|
|
89
89
|
|
|
90
90
|
3. **Per-side reconciliation** via `_reconcileStartupSide(planOnly=true)` (lines 343-372):
|
|
91
91
|
- Count `matchedOnGrid` (active grid orders with `orderId`)
|
|
@@ -132,8 +132,8 @@ If Phase 2 partially succeeds (some cancels, some creates fail), there is no rol
|
|
|
132
132
|
### Timeouts and Read Coverage
|
|
133
133
|
|
|
134
134
|
- **No per-attempt race** around the reconcile itself โ the 1.4.8 change removed it to avoid orphaning mid-batch broadcasts (see the [`recalculateGrid`](../modules/order/grid.ts) call site in `modules/order/grid.ts`).
|
|
135
|
-
- The whole resync is bounded by a **10-minute total timeout** (`PIPELINE_TIMING.TIMEOUT_MS * 2` at `grid.ts:
|
|
136
|
-
- Every internal chain read goes through `readOpenOrdersGuarded` (`chain_orders.ts:
|
|
135
|
+
- The whole resync is bounded by a **10-minute total timeout** (`PIPELINE_TIMING.TIMEOUT_MS * 2` at `grid.ts:1511`), applied via `Promise.race` at `grid.ts:1617`.
|
|
136
|
+
- Every internal chain read goes through `readOpenOrdersGuarded` (`chain_orders.ts:608`) with the 30s / 3-retry / node-failover standard, and empty/truncated reads are treated as **ambiguous** โ never as authoritative absence.
|
|
137
137
|
|
|
138
138
|
---
|
|
139
139
|
|
|
@@ -141,7 +141,7 @@ If Phase 2 partially succeeds (some cancels, some creates fail), there is no rol
|
|
|
141
141
|
|
|
142
142
|
### Fresh Grid Guard (`matchedOnGrid > 0`)
|
|
143
143
|
|
|
144
|
-
**`grid_reconcile_internal.ts:
|
|
144
|
+
**`grid_reconcile_internal.ts:1738`**
|
|
145
145
|
|
|
146
146
|
When a brand-new grid is generated, every slot is VIRTUAL โ `matchedOnGrid = 0`. Without a guard, every on-chain order appears "unmatched" and would be cancelled as excess:
|
|
147
147
|
|
|
@@ -155,27 +155,27 @@ When `matchedOnGrid === 0` AND scaling up (`neededSlots > 0`), excess cancellati
|
|
|
155
155
|
|
|
156
156
|
### Grid-Edge Lock
|
|
157
157
|
|
|
158
|
-
**`grid_reconcile_internal.ts:
|
|
158
|
+
**`grid_reconcile_internal.ts:355`** โ `_isGridEdgeFullyActive` detects when the grid boundary is fully active (all slots on-chain) before cancelling excess orders.
|
|
159
159
|
|
|
160
|
-
When all outermost orders of a side are ACTIVE with `orderId`, all balance is committed to the edges. Cancel the **largest** order among the update candidates (`_cancelLargestOrder`, line
|
|
160
|
+
When all outermost orders of a side are ACTIVE with `orderId`, all balance is committed to the edges. Cancel the **largest** order among the update candidates (`_cancelLargestOrder`, line 425) to free maximum funds with minimum operations, since the DEX does not expose partial-reduce in one operation. The cancelled slot gets a replacement create.
|
|
161
161
|
|
|
162
|
-
Detection (`_isGridEdgeFullyActive`, line
|
|
162
|
+
Detection (`_isGridEdgeFullyActive`, line 355): sort orders by price (BUY descending, SELL ascending), and check the outermost ones are all `isOrderPlaced()`.
|
|
163
163
|
|
|
164
|
-
### Duplicate
|
|
164
|
+
### Duplicate Cancellation
|
|
165
165
|
|
|
166
|
-
**`grid_reconcile.ts:
|
|
166
|
+
**`grid_reconcile.ts:278`**
|
|
167
167
|
|
|
168
|
-
|
|
168
|
+
An unmatched chain order whose price equals an active same-type grid slot's price โ exact slot-price equality via `priceSlotEqual` at the asset precision โ is a **suspected duplicate** โ queued for Phase 2 cancellation (not cancelled under lock). Non-equal neighbours are only logged with nearest-same-side diagnostics, never cancelled here. The earlier fuzzy `SUSPECTED_DUPLICATE_TOLERANCE_MULTIPLIER` (5ร `calculatePriceTolerance`) was removed.
|
|
169
169
|
|
|
170
170
|
### Batch Update Failure Recovery
|
|
171
171
|
|
|
172
|
-
**`grid_reconcile.ts:
|
|
172
|
+
**`grid_reconcile.ts:436`**
|
|
173
173
|
|
|
174
174
|
Up to 3 batch attempts. Each failure triggers a recovery sync + plan refresh. If all plans are empty โ resolved early. After 3ร โ sequential fallback with per-plan recovery (each individual failure triggers a recovery sync + queue refresh).
|
|
175
175
|
|
|
176
176
|
### Phantom Orders via Reconcile
|
|
177
177
|
|
|
178
|
-
**`grid_reconcile.ts:
|
|
178
|
+
**`grid_reconcile.ts:227-253`** โ Reconcile's role in the defense-in-depth: during Phase 1, any ACTIVE/PARTIAL order whose `orderId` is not found on-chain is reset to VIRTUAL with `skipAccounting`. The freshly-assigned deferral protects in-flight broadcasts, and the ghost heuristic lets known fills pass. See [`developer_guide.md`](developer_guide.md#phantom-orders-prevention-defense-in-depth) for the full 3-layer defense.
|
|
179
179
|
|
|
180
180
|
### Shelf Orders (Fork-Kept Manual Orders)
|
|
181
181
|
|
|
@@ -189,13 +189,17 @@ Live on-chain orders with non-slot-N ids below the rail (e.g. `deep-*` manuals k
|
|
|
189
189
|
|
|
190
190
|
Reconcile Phase 1 runs under `_gridLock` with no side effects on the frozen master Map. The working grid is not involved โ reconcile is a startup operation that runs before the COW pipeline is active. See [`COPY_ON_WRITE_MASTER_PLAN.md`](COPY_ON_WRITE_MASTER_PLAN.md#safety-guardrails) and [`COW_INVARIANTS.md`](COW_INVARIANTS.md#reconcile-grid_reconcilemd) for COW rules.
|
|
191
191
|
|
|
192
|
+
### Slot-Price Invariant at the Reconcile Emission Sites
|
|
193
|
+
|
|
194
|
+
Three of the six guarded emission sites are reconcile sites (`RECONCILE-CREATE`, `RECONCILE-UPDATE`, `STARTUP-CREATE` in `grid_reconcile_internal.ts`): every op reconcile emits is checked against the slot's genesis level and an off-grid emission is skipped, not broadcast โ see [`GRID_PRICE_INVARIANT.md`](GRID_PRICE_INVARIANT.md). The coupling is bidirectional: the invariant guard's persistent-rejection escalation and the deferred-hold escalation both exit through the same structural resync (debounced reload โ full reset) described here, and a full reset's update-first reconcile emits the rail's genesis level, so the guard does not block its own resolution.
|
|
195
|
+
|
|
192
196
|
### Truncated-Read Ambiguity (since 1.4.8)
|
|
193
197
|
|
|
194
|
-
Every chain read feeding an absence/surplus decision goes through `readOpenOrdersGuarded` (`chain_orders.ts:
|
|
198
|
+
Every chain read feeding an absence/surplus decision goes through `readOpenOrdersGuarded` (`chain_orders.ts:608`) and treats an empty or truncated snapshot as **unreadable** โ never as "nothing landed" or "nothing to cancel":
|
|
195
199
|
|
|
196
|
-
- `_recoverSyncFromChain` (`grid_reconcile_internal.ts:
|
|
197
|
-
- `_adoptPossiblyLandedCreate` (`grid_reconcile_internal.ts:
|
|
198
|
-
- Phase 3 final refresh (`grid_reconcile.ts:
|
|
200
|
+
- `_recoverSyncFromChain` (`grid_reconcile_internal.ts:726`) โ plus its three recovery sites in `_createOrderFromGrid` / `_cancelChainOrder` โ defers on empty/truncated reads (`deferEmpty: true`). A pass-1 phantom cleanup would otherwise virtualize live slots from a partial window.
|
|
201
|
+
- `_adoptPossiblyLandedCreate` (`grid_reconcile_internal.ts:1112`) defers to an uncertain outcome on truncated reads, and the startup group batch uncertain verification follows the same rule.
|
|
202
|
+
- Phase 3 final refresh (`grid_reconcile.ts:533`) skips adoption/surplus-cancel on a truncated read, keeping the pre-phase-2 counts for the summary log.
|
|
199
203
|
- Adoption paths (`_adoptPossiblyLandedCreate`, grouping path, reconcile adoption loop) apply the create-fee deduction via `_applySync` for accounting parity.
|
|
200
204
|
|
|
201
205
|
The underlying rule is `INV-BROADCAST-004`: a capped `get_full_accounts` window omits the freshest orders (fresh creates sort last), so absence can never be authoritative on a truncated read.
|
|
@@ -204,7 +208,7 @@ The underlying rule is `INV-BROADCAST-004`: a capped `get_full_accounts` window
|
|
|
204
208
|
|
|
205
209
|
## Lock Hierarchy
|
|
206
210
|
|
|
207
|
-
**`manager.ts:
|
|
211
|
+
**`manager.ts:593-597`** โ canonical reference in [`developer_guide.md`](developer_guide.md#lock-ordering-for-deadlock-prevention).
|
|
208
212
|
|
|
209
213
|
```
|
|
210
214
|
Level 0: _fillProcessingLock Level 1: _divergenceLock
|
|
@@ -230,11 +234,10 @@ Commit `e64db685` replaced 6 single-value boolean state fields with refcounts/st
|
|
|
230
234
|
|
|
231
235
|
| Constant | Value | File | Role |
|
|
232
236
|
|----------|-------|------|------|
|
|
233
|
-
| `
|
|
234
|
-
| `
|
|
235
|
-
| `
|
|
236
|
-
| `
|
|
237
|
-
| `PIPELINE_TIMING.TIMEOUT_MS` | `300000` (5min) | `constants.ts:800` | Base pipeline timing; resync uses 2ร (10 min) |
|
|
237
|
+
| `maxBatchAttempts` | `3` | `grid_reconcile.ts:436` | Update-batch retry limit |
|
|
238
|
+
| `PRICE_TOLERANCE_MAX_PERCENT` | `0.01` (1%) | `constants.ts:566` | Cap on price tolerance |
|
|
239
|
+
| `PRICE_TOLERANCE_MIN_ABSOLUTE` | `0.0001` | `constants.ts:570` | Floor for price tolerance |
|
|
240
|
+
| `PIPELINE_TIMING.TIMEOUT_MS` | `300000` (5min) | `constants.ts:973` | Base pipeline timing; resync uses 2ร (10 min) |
|
|
238
241
|
|
|
239
242
|
---
|
|
240
243
|
|
|
@@ -260,10 +263,10 @@ Commit `e64db685` replaced 6 single-value boolean state fields with refcounts/st
|
|
|
260
263
|
|
|
261
264
|
| File | Role |
|
|
262
265
|
|------|------|
|
|
263
|
-
| `modules/order/grid_reconcile.ts` | Public API + 3-phase orchestrator (
|
|
264
|
-
| `modules/order/grid_reconcile_internal.ts` | Internal helpers โ `_reconcileStartupSide`, grid detection, recovery, uncertainty (
|
|
266
|
+
| `modules/order/grid_reconcile.ts` | Public API + 3-phase orchestrator (670 lines) |
|
|
267
|
+
| `modules/order/grid_reconcile_internal.ts` | Internal helpers โ `_reconcileStartupSide`, grid detection, recovery, uncertainty (2132 lines) |
|
|
265
268
|
| `modules/order/manager.ts` | Lock hierarchy definition, `_applyOrderUpdate`, phantom guard, `reconcileGrid` entry, COW integration |
|
|
266
|
-
| `modules/order/async_lock.ts` | AsyncLock engine with ALS re-entrancy (
|
|
269
|
+
| `modules/order/async_lock.ts` | AsyncLock engine with ALS re-entrancy (435 lines) |
|
|
267
270
|
| `modules/order/sync_engine.ts` | Blockchain sync pipeline |
|
|
268
271
|
| `modules/order/grid.ts` | Grid creation, `recalculateGrid` (full resync) calls reconcile |
|
|
269
272
|
| `modules/chain_orders.ts` | `readOpenOrdersGuarded` / guarded read infrastructure |
|
package/docs/LIFECYCLE.md
CHANGED
|
@@ -90,7 +90,7 @@ sequenceDiagram
|
|
|
90
90
|
participant CO as chain_orders (broadcast)
|
|
91
91
|
participant STORE as Storage
|
|
92
92
|
|
|
93
|
-
CH->>Q: enqueue fill(s) (dexbot_fill_runtime.ts:
|
|
93
|
+
CH->>Q: enqueue fill(s) (dexbot_fill_runtime.ts:414)
|
|
94
94
|
FR->>FR: drain queue -> _processFillsWithBatching
|
|
95
95
|
FR->>OM: processFilledOrders() (manager.ts)
|
|
96
96
|
OM->>AC: processFillAccounting() (single call, batch)
|
|
@@ -105,7 +105,7 @@ sequenceDiagram
|
|
|
105
105
|
```
|
|
106
106
|
|
|
107
107
|
Why it matters:
|
|
108
|
-
- **Gap-slot batching** (batch size = grid gap-slot count, `DEXBot._getGapSlotBatchSize`) keeps bursts
|
|
108
|
+
- **Gap-slot batching** (batch size = grid gap-slot count + 1, `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).
|
|
@@ -134,10 +134,10 @@ sequenceDiagram
|
|
|
134
134
|
participant STORE as Storage
|
|
135
135
|
|
|
136
136
|
MA->>CL: AMA center snapshot updated
|
|
137
|
-
CL->>CL: _performPeriodicGridChecks() (dexbot_class.ts:
|
|
138
|
-
CL->>RT: performPeriodicGridChecks() (dexbot_maintenance_runtime.ts:
|
|
139
|
-
RT->>RT: runGridMaintenance(bot,'periodic') (dexbot_maintenance_runtime.ts:
|
|
140
|
-
RT->>RT: executeMaintenanceLogic() (dexbot_maintenance_runtime.ts:
|
|
137
|
+
CL->>CL: _performPeriodicGridChecks() (dexbot_class.ts:1673)
|
|
138
|
+
CL->>RT: performPeriodicGridChecks() (dexbot_maintenance_runtime.ts:1554)
|
|
139
|
+
RT->>RT: runGridMaintenance(bot,'periodic') (dexbot_maintenance_runtime.ts:2770)
|
|
140
|
+
RT->>RT: executeMaintenanceLogic() (dexbot_maintenance_runtime.ts:2270)
|
|
141
141
|
RT->>AC: recalculate funds from balances
|
|
142
142
|
RT->>GD: promote AMA center -> grid center
|
|
143
143
|
RT->>GD: recalculateGrid() (grid.ts)
|
|
@@ -157,12 +157,12 @@ The AMA signal stack (AMA/Kalman/Hurst/PE) is *research-tuned* in `analysis/` an
|
|
|
157
157
|
the parameters.
|
|
158
158
|
|
|
159
159
|
> Note: `runMaintenance()` is a **different** subsystem โ the credit/MPA debt
|
|
160
|
-
> runtime (`modules/credit_runtime.ts:
|
|
161
|
-
> `_runCreditRuntimeMaintenance` at `dexbot_class.ts:
|
|
160
|
+
> runtime (`modules/credit_runtime.ts:3019`, reached via
|
|
161
|
+
> `_runCreditRuntimeMaintenance` at `dexbot_class.ts:1790`). The grid maintenance
|
|
162
162
|
> chain above is the one that matters for order/price upkeep.
|
|
163
163
|
|
|
164
|
-
References: `modules/dexbot_class.ts:
|
|
165
|
-
`modules/dexbot_maintenance_runtime.ts:
|
|
164
|
+
References: `modules/dexbot_class.ts:1673` (`_performPeriodicGridChecks`) โ
|
|
165
|
+
`modules/dexbot_maintenance_runtime.ts:1554` (`performPeriodicGridChecks`) โ
|
|
166
166
|
`:1845` (`runGridMaintenance`) โ `:1452` (`executeMaintenanceLogic`),
|
|
167
167
|
`docs/GRID_RECALCULATION.md`, `docs/GRID_RECONCILE.md`.
|
|
168
168
|
|
|
@@ -179,6 +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
|
+
| **Slot price = genesis level** | Every emitted order's price must equal `priceForSlot(idx, genesis)` for its slot โ range guards cannot substitute for grid membership; off-grid emissions are blocked. | `docs/GRID_PRICE_INVARIANT.md` |
|
|
182
183
|
| **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
184
|
| **Lock ordering** | Fill drain and maintenance must not run a rebalance concurrently. | `docs/developer_guide.md` ยง"Startup Sequence & Lock Ordering" |
|
|
184
185
|
|
|
@@ -191,7 +192,7 @@ enforced*, not compiler-enforced โ learn them or you will introduce fund bugs.
|
|
|
191
192
|
| How a fill becomes orders | `modules/dexbot_fill_runtime.ts` โ `modules/order/manager.ts` |
|
|
192
193
|
| Grid math / recalculation | `modules/order/grid.ts`, `docs/GRID_RECALCULATION.md` |
|
|
193
194
|
| Funds & accounting | `modules/order/accounting.ts`, `docs/FUND_MOVEMENT_AND_ACCOUNTING.md` |
|
|
194
|
-
| Periodic loop & AMA hook | `modules/dexbot_maintenance_runtime.ts`, `modules/dexbot_class.ts:
|
|
195
|
+
| Periodic loop & AMA hook | `modules/dexbot_maintenance_runtime.ts`, `modules/dexbot_class.ts:1673` |
|
|
195
196
|
| Market signal source | `market_adapter/market_adapter.ts`, `analysis/README.md` |
|
|
196
197
|
| Startup & orchestration | `modules/dexbot_class.ts`, `docs/developer_guide.md` ยง"Startup Sequence" |
|
|
197
198
|
| Why COW exists | `docs/architecture.md` ยง"Copy-on-Write (COW) Grid Pattern", `docs/COW_INVARIANTS.md` |
|
package/docs/LOGGING.md
CHANGED
|
@@ -243,6 +243,7 @@ Prefix tags used in log messages to help operators identify event types. To find
|
|
|
243
243
|
| `[SPREAD-CORRECTION]` | `order/grid.ts` | Partial order spread correction |
|
|
244
244
|
| `[STRATEGY]` | `order/strategy.ts` | Fee event cache and strategy decisions |
|
|
245
245
|
| `[RECONCILE]` | `order/utils/validate.ts` | Grid reconciliation ([GRID_RECONCILE.md](GRID_RECONCILE.md)) |
|
|
246
|
+
| `[RMS]` | `order/grid.ts`, `dexbot_maintenance_runtime.ts` | RMS structural-divergence checks: per-side `metric vs threshold โ TRIGGER-RESYNC/no trigger` at `debug` (plus a `checks disabled` variant when the threshold is 0), reset line with threshold + breaching sides at `info` |
|
|
246
247
|
| `[GAP-EVAC]` | `order/utils/validate.ts`, `order/manager.ts`, `dexbot_startup_runtime.ts`, `dexbot_state_recovery.ts` | Stuck in-band (gap-band) order streak warnings, cancel-only evacuation teeth, persisted-streak restore counts |
|
|
247
248
|
| `[GRID-TYPE-CORRECT]` | `order/grid.ts` | One-time backfill retype of legacy empty slots to rail-typed holes on load |
|
|
248
249
|
| `[LAST-FILL-GUARD]` | `dexbot_cow_runtime.ts` | Last-fill-guard blocks plus gap-evacuation bypass allows/stale-stamp downgrades |
|
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.
|
|
5
|
+
**Version context:** v1.6.5 (released).
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -17,7 +17,7 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
17
17
|
|
|
18
18
|
### ๐ก [Market Adapter](../market_adapter/README.md)
|
|
19
19
|
*Live AMA pricing, dynamic weights, and recalc trigger orchestration.*
|
|
20
|
-
- **Quick Start**: Enable AMA,
|
|
20
|
+
- **Quick Start**: Enable AMA, set the per-bot adapter flags in `dexbot bot`, and start DEXBot2
|
|
21
21
|
- **Settings**: Global, pair, and bot-specific adapter overrides
|
|
22
22
|
- **Dynamic Weights**: How adapter signals write live weight snapshots
|
|
23
23
|
- **Troubleshooting**: Common adapter startup and trigger issues
|
|
@@ -44,7 +44,7 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
44
44
|
- **Purpose**: Exposes BitShares capabilities and DEXBot2 infrastructure through JSON/CLI bridges, MCP, and runtime-native skill packaging for OpenClaw and compatible runtimes (see [claw/README.md](../claw/README.md) for the full list).
|
|
45
45
|
- **API Boundary**: Responsibility split between the AI decision layer and the DEXBot2 execution substrate ([AI_BOT_LIBRARY_API.md](../claw/docs/AI_BOT_LIBRARY_API.md))
|
|
46
46
|
- **Tuning Reference**: Practical grid-tuning baselines ([DEXBOT2_TUNING_CHEAT_SHEET.md](../claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md))
|
|
47
|
-
- **Position Management**:
|
|
47
|
+
- **Position Management**: Short-position tracking, position health monitoring (3-zone CR model), and shared CR planning via `cr_planner.ts`
|
|
48
48
|
- **Skills**: Presentation-only, concept-reference, and launcher-orchestration skill packs for bitshares-guide, margin-trading, launcher-ops, and shared references
|
|
49
49
|
|
|
50
50
|
## Operational & Security
|
|
@@ -65,19 +65,19 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
65
65
|
### ๐ [Grid Reconciliation](GRID_RECONCILE.md)
|
|
66
66
|
*How the bot re-aligns its intended grid with on-chain reality at startup.*
|
|
67
67
|
- **3-Phase Plan-then-Execute**: Phase 1 pure in-memory planning under `_gridLock`, Phase 2 blockchain execution outside the lock, Phase 3 fresh re-read and stale surplus cleanup
|
|
68
|
-
- **Safety Guardrails**: Fresh-grid `matchedOnGrid > 0` guard,
|
|
68
|
+
- **Safety Guardrails**: Fresh-grid `matchedOnGrid > 0` guard, exact slot-price duplicate cancel, freshly-assigned deferral, and truncated-read ambiguity handling
|
|
69
69
|
- **Partial Failure State**: No rollback on partial Phase 2 success; remaining mismatches caught by the next maintenance or startup cycle
|
|
70
70
|
- **Lock Hierarchy**: Canonical `_syncLock`/`_gridLock` level reference and the 1.4.6 ABBA deadlock correction
|
|
71
71
|
|
|
72
72
|
### ๐ [Logging System](LOGGING.md)
|
|
73
73
|
*Configuration reference for log levels, rotation, JSON output, and categories.*
|
|
74
74
|
- **5 Severity Levels**: `debug`, `info`, `warn`, `error`, `critical`.
|
|
75
|
-
- **Rotation**: Size-based (1GB default), auto-prune (
|
|
75
|
+
- **Rotation**: Size-based (1.1GB total budget default), auto-prune (10 rotated files).
|
|
76
76
|
- **JSON Output**: Structured lines for log aggregators (opt-in).
|
|
77
77
|
- **Categories**: 6 independently enablable category groups.
|
|
78
78
|
- **Change Detection**: Skips redundant logs (40-50% reduction).
|
|
79
79
|
- **Batch Processing Logs**: Fill batching, recovery retry, and orphan-fill deduplication messages.
|
|
80
|
-
- **Fill History Scans**: The `Subscriptions` logger emits `fetchFillHistoryEntries: maxPages (X) reached` at `
|
|
80
|
+
- **Fill History Scans**: The `Subscriptions` logger emits `fetchFillHistoryEntries: maxPages (X) reached` at `debug` level when the history scan hits its page cap โ normal on busy accounts; see LOGGING.md for the `--partial-operations` diagnostic.
|
|
81
81
|
|
|
82
82
|
### ๐ณ [Docker](docker.md)
|
|
83
83
|
*Container build, release images, and secure startup.*
|
|
@@ -88,8 +88,8 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
88
88
|
### ๐ ๏ธ [Scripts](../scripts/README.md)
|
|
89
89
|
*CLI maintenance and diagnostic utilities.*
|
|
90
90
|
- **Update**: Safe production update via `dexbot update`
|
|
91
|
-
- **Reset & Cleanup**: Log
|
|
92
|
-
- **
|
|
91
|
+
- **Reset & Cleanup**: Log/order wipes, settings resets, and market-adapter/claw state cleanup
|
|
92
|
+
- **Diagnostics**: Configuration audit, grid divergence/trading analysis, and candle/pool history checks
|
|
93
93
|
|
|
94
94
|
## Reference Docs
|
|
95
95
|
|
|
@@ -97,9 +97,9 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
97
97
|
*The blueprint of the system.*
|
|
98
98
|
- **Design Philosophy**: Simplicity, constant spread, minimal blockchain interaction, and closed-loop market dynamics.
|
|
99
99
|
- **System Design**: High-level overview of how the bot components interact.
|
|
100
|
-
- **Module Responsibilities**: Detailed breakdown of the **Manager**, **Accountant**, **Strategy**, **Grid**, **FillRuntime**, and **MaintenanceRuntime** modules.
|
|
100
|
+
- **Module Responsibilities**: Detailed breakdown of the **Manager**, **Accountant**, **Strategy**, **SyncEngine**, **Grid**, **FillRuntime**, and **MaintenanceRuntime** modules.
|
|
101
101
|
- **Copy-on-Write Pattern**: Safe concurrent rebalancing with isolated working grids (see [COPY_ON_WRITE_MASTER_PLAN.md](COPY_ON_WRITE_MASTER_PLAN.md))
|
|
102
|
-
- **Fill Processing Pipeline**: Fixed-cap batch fill processing (1
|
|
102
|
+
- **Fill Processing Pipeline**: Fixed-cap batch fill processing (`gapSlots+1` fills per broadcast; documented Feb 7 29-fill scenario: ~24s)
|
|
103
103
|
- **Spread Correction**: Conservative, fund-aware maintenance of constant spread width
|
|
104
104
|
- **Periodic Market Price Refresh**: Background 4-hour price updates
|
|
105
105
|
- **Pipeline Safety & Diagnostics**: 5-minute timeout safeguard and health monitoring
|
|
@@ -116,6 +116,38 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
116
116
|
- **Lifecycle B (Maintenance / AMA-Driven)**: Periodic path from `_performPeriodicGridChecks` โ `executeMaintenanceLogic`.
|
|
117
117
|
- **Cross-Cutting Invariants**: COW boundary, fund SSOT, replay-safe fills, lock ordering.
|
|
118
118
|
|
|
119
|
+
### ๐งฉ [Copy-on-Write Master Plan](COPY_ON_WRITE_MASTER_PLAN.md)
|
|
120
|
+
*COW design, phases, and state machine details.*
|
|
121
|
+
- **Architecture**: Master-grid projection model and rebalance flow
|
|
122
|
+
- **Lifecycle**: State machine, rebalance/fill data flows, fill handling strategy, and operational rules
|
|
123
|
+
- **Safety**: Invariants and guardrails for concurrent updates
|
|
124
|
+
|
|
125
|
+
### ๐ [COW Invariants](COW_INVARIANTS.md)
|
|
126
|
+
*Stable theory contract for COW pipeline.*
|
|
127
|
+
- **Non-negotiable invariants**: Master immutability, commit atomicity, projection rules, accounting separation
|
|
128
|
+
- **Subsystem Scope**: 13 `INV-*` prefix groups mapping each invariant to its runtime subsystem
|
|
129
|
+
- **Change Policy**: Required steps for an intentional invariant change โ same-PR doc update, rationale, and regression tests
|
|
130
|
+
|
|
131
|
+
### ๐ [Grid-Price Invariant](GRID_PRICE_INVARIANT.md)
|
|
132
|
+
*Why a slot's emitted price must equal its genesis level โ and how that failed.*
|
|
133
|
+
- **The invariant**: `order.price === priceForSlot(idx, genesis)`, and why range guards cannot substitute for it
|
|
134
|
+
- **Failure mechanism**: Chain price overwriting slot identity, pre-broadcast substitution, untrusted fill-guard pivot
|
|
135
|
+
- **Enforcement**: The six emission sites, the blocking rejection of off-grid emissions, the final pre-broadcast pivot gate, and the fail-open policy on unjudgeable inputs
|
|
136
|
+
- **Out-of-bounds policy**: Hold and surface; refill in-grid slots at their genesis price
|
|
137
|
+
- **Status**: Landed enforcement map, key constants, and why the removed 5% sanity gate must not be naively re-landed
|
|
138
|
+
|
|
139
|
+
### ๐ฐ [Fund Movement & Accounting](FUND_MOVEMENT_AND_ACCOUNTING.md)
|
|
140
|
+
*The most critical part of the bot: safe capital management.*
|
|
141
|
+
- **Single Source of Truth**: How the bot avoids double-spending and out-of-sync balances.
|
|
142
|
+
- **Optimistic ChainFree**: The mechanism that allows the bot to trade with fill proceeds before they are finalized on-chain.
|
|
143
|
+
- **Fill Batch Processing**: Fixed-cap batching for efficient fill processing (`1..gapSlots+1` unified, deeper queues chunked at `gapSlots+1`)
|
|
144
|
+
- **Partial Order Consolidation**: Simplified, direct consolidation through grid rebuilding (no merge/split mechanics)
|
|
145
|
+
- **Dust Detection & Management**: Partials below the dust threshold are cancelled on-chain immediately on detection (no delay, no timer)
|
|
146
|
+
- **BTS Fee Object Structure**: `netProceeds` field for accounting precision
|
|
147
|
+
- **BUY Side Sizing & Fee Accounting**: Correct fee application by order side
|
|
148
|
+
- **Mixed Order Fund Validation**: Separate validation for BUY vs SELL order fund checks
|
|
149
|
+
- **Fee Management**: Detailed logic for BTS fee reservations and market fee deductions.
|
|
150
|
+
|
|
119
151
|
### ๐ [Developer Guide](developer_guide.md)
|
|
120
152
|
*Your daily companion for coding.*
|
|
121
153
|
- **Quick Start**: How to get the development environment running.
|
|
@@ -128,7 +160,7 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
128
160
|
- **Order State Helper Functions**: Centralized predicate functions for state checking
|
|
129
161
|
- **Signal Concepts**: Dynamic weights, regime detection, derivative signals, and market adapter integration
|
|
130
162
|
- **Debt Policy**: Native MPA and credit offer configuration and runtime rules
|
|
131
|
-
- **
|
|
163
|
+
- **Practical How-Tos**: Adding features step by step, common pitfalls to avoid, and useful debugging commands.
|
|
132
164
|
- **Glossary**: Definitions of project-specific terminology (e.g., "Virtual Orders", "Rotation", "Pipeline Safety", "WorkingGrid", "COW Commit", "Dynamic Weight", "Regime Detection").
|
|
133
165
|
|
|
134
166
|
### ๐ [Workflow](WORKFLOW.md)
|
|
@@ -136,57 +168,31 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
136
168
|
- **Branching Strategy**: Explanation of the `test` โ `dev` โ `main` lifecycle.
|
|
137
169
|
- **CI/CD Patterns**: Standards for merging and ensuring code quality across branches.
|
|
138
170
|
|
|
139
|
-
###
|
|
140
|
-
*
|
|
141
|
-
- **
|
|
142
|
-
- **
|
|
171
|
+
### ๐งช [Test Suite](../tests/README.md)
|
|
172
|
+
*Test organization, categories, and key architectural patterns tested.*
|
|
173
|
+
- **Test Layout**: Directory structure, helpers, and quick-start commands
|
|
174
|
+
- **Categories**: Core infrastructure, order management, COW rebalancing, fees/accounting, integration, edge cases, and more
|
|
175
|
+
- **Architectural Patterns**: COW rebalancing, RMS divergence, fund invariants, and the grid-price invariant with doc cross-references
|
|
143
176
|
|
|
144
177
|
### ๐งญ [Evolution Report](EVOLUTION.md)
|
|
145
178
|
*Project timeline and major architecture phases.*
|
|
146
179
|
- **Coverage**: Historical milestones from bootstrap through the current stable release; per-release detail lives in [CHANGELOG.md](../CHANGELOG.md)
|
|
147
180
|
- **Focus**: Architecture evolution, release history, and test growth
|
|
148
181
|
|
|
182
|
+
### โช [Order Engine Retrospective](ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md)
|
|
183
|
+
*Why the post-1.0.0 order engine kept misbehaving โ synthesis plus the incident/fix ledger.*
|
|
184
|
+
- **Part I โ Synthesis**: root cause (uncertain broadcast), recurring bug families, meta-patterns, what actually fixed it, lessons
|
|
185
|
+
- **Part II โ Incident & Fix Ledger**: preserved gap-band / ladder-recenter / orphan-fill / price-first plans with `LANDED`/`REVERTED`/`SUPERSEDED` status and commit hashes
|
|
186
|
+
- **Regression gate**: `npm run analysis:grid-check` (see [analysis/README.md](../analysis/README.md))
|
|
187
|
+
|
|
149
188
|
### ๐๏ธ [Changelog](../CHANGELOG.md)
|
|
150
189
|
*Release notes and documentation history.*
|
|
151
190
|
- **Scope**: Versioned notes per release
|
|
152
191
|
|
|
153
|
-
###
|
|
154
|
-
*
|
|
155
|
-
- **
|
|
156
|
-
- **
|
|
157
|
-
- **Safety**: Invariants and guardrails for concurrent updates
|
|
158
|
-
|
|
159
|
-
### ๐ [COW Invariants](COW_INVARIANTS.md)
|
|
160
|
-
*Stable theory contract for COW pipeline.*
|
|
161
|
-
- **Non-negotiable invariants**: Master immutability, commit atomicity, projection rules, accounting separation
|
|
162
|
-
- **Test mapping**: Links each invariant to regression tests
|
|
163
|
-
- **Review checklist**: Quick-use verification for COW/accounting changes
|
|
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
|
-
|
|
173
|
-
### ๐งช [Test Suite](../tests/README.md)
|
|
174
|
-
*Test organization, categories, and key architectural patterns tested.*
|
|
175
|
-
- **Test Layout**: Directory structure, helpers, and quick-start commands
|
|
176
|
-
- **Categories**: Core infrastructure, order management, COW rebalancing, fees/accounting, integration, edge cases, and more
|
|
177
|
-
- **Architectural Patterns**: COW rebalancing, RMS divergence, and fund invariants with doc cross-references
|
|
178
|
-
|
|
179
|
-
### ๐ฐ [Fund Movement & Accounting](FUND_MOVEMENT_AND_ACCOUNTING.md)
|
|
180
|
-
*The most critical part of the bot: safe capital management.*
|
|
181
|
-
- **Single Source of Truth**: How the bot avoids double-spending and out-of-sync balances.
|
|
182
|
-
- **Optimistic ChainFree**: The mechanism that allows the bot to trade with fill proceeds before they are finalized on-chain.
|
|
183
|
-
- **Fill Batch Processing**: Fixed-cap batching for efficient fill processing (`<=4` unified, `>4` chunked)
|
|
184
|
-
- **Partial Order Consolidation**: Simplified, direct consolidation through grid rebuilding (no merge/split mechanics)
|
|
185
|
-
- **Dust Detection & Management**: Partials below the dust threshold are cancelled on-chain immediately on detection (no delay, no timer)
|
|
186
|
-
- **BTS Fee Object Structure**: `netProceeds` field for accounting precision
|
|
187
|
-
- **BUY Side Sizing & Fee Accounting**: Correct fee application by order side
|
|
188
|
-
- **Mixed Order Fund Validation**: Separate validation for BUY vs SELL order fund checks
|
|
189
|
-
- **Fee Management**: Detailed logic for BTS fee reservations and market fee deductions.
|
|
192
|
+
### ๐งฎ [DEXBot vs DEXBot2 Comparison](DEXBOT_COMPARISON.md)
|
|
193
|
+
*Architectural, functional, and operational comparison with the original Python DEXBot.*
|
|
194
|
+
- **Scope**: Full side-by-side of technology stack, architecture, trading strategies, order management, configuration, blockchain integration, fund accounting, and concurrency safety
|
|
195
|
+
- **Audience**: Developers and operators evaluating or migrating between the two projects
|
|
190
196
|
|
|
191
197
|
---
|
|
192
198
|
|
package/docs/WORKFLOW.md
CHANGED
|
@@ -238,7 +238,7 @@ the canonical name is preferred in scripts and docs.
|
|
|
238
238
|
|
|
239
239
|
| Command (canonical) | Aliases | Purpose |
|
|
240
240
|
|---------|---------|---------|
|
|
241
|
-
| `dexbot test <bot>` | โ |
|
|
241
|
+
| `dexbot test <bot>` | โ | Run a single bot in live mode (one-shot; not a dry run) |
|
|
242
242
|
| `dexbot drystart <bot>` | โ | Same as `test` but forces dry-run execution |
|
|
243
243
|
| `dexbot reset <bot>` | โ | Trigger a grid reset (applies live or on next start) |
|
|
244
244
|
| `dexbot default` | `defaults` | Reset settings to defaults (deletes generated settings files) |
|
|
@@ -258,7 +258,6 @@ the canonical name is preferred in scripts and docs.
|
|
|
258
258
|
| `dexbot reload` | `reloadall` | Reload the monolithic runtime without touching the credential daemon (unlock mode) |
|
|
259
259
|
| `dexbot restart` | `restartall` | Restart the monolithic runtime (unlock mode, re-unlocks credential daemon) |
|
|
260
260
|
| `dexbot delete` | โ | Shut down and clean up the monolithic runtime (unlock mode) |
|
|
261
|
-
| `dexbot whitelist` | `white` | Generate market adapter whitelist from AMA bot configs |
|
|
262
261
|
| `dexbot clear` | โ | Remove all log files from the logs directory (`<profiles>/logs`) |
|
|
263
262
|
|
|
264
263
|
## NPM Scripts for Branch Synchronization
|