dexbot 1.6.2 → 1.6.4
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 +53 -3
- package/README.md +11 -7
- package/analysis/README.md +20 -14
- 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/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 +104 -244
- package/analysis/results/ama_sweep_results_lp_pool_133_1h.json +2455 -0
- package/analysis/results/bot_fitting_results_lp_pool_133_1h.json +218 -0
- package/analysis/trade_profitability.ts +169 -304
- package/analysis/tradingview/README.md +2 -2
- package/analysis/tradingview/h-bts_tradingview.html +1570 -0
- package/analysis/tradingview/t-bts_tradingview.html +1570 -0
- package/analysis/tradingview/tradingview_uplot_chart_generator.ts +3 -4
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +2 -3
- 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/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/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/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 +4 -20
- package/dist/analysis/grid_correction_check.d.ts.map +1 -1
- package/dist/analysis/grid_correction_check.js +95 -248
- 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/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +3 -4
- 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 +2 -3
- 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/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 +1 -18
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +1 -1
- 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/cli_colors.d.ts +0 -1
- package/dist/modules/cli_colors.d.ts.map +1 -1
- package/dist/modules/constants.js +5 -5
- 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 +9 -8
- 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 +87 -7
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +489 -14
- 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 +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +21 -5
- 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 +1 -1
- 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 +1 -2
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -1
- package/dist/modules/launcher/launch_modes.js +1 -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 +1 -1
- 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/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 +7 -0
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +52 -98
- 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 -7
- 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 +25 -20
- 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/order.d.ts +45 -7
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +160 -15
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +0 -15
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +2 -2
- 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/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/scripts/analyze-git.js +2 -2
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/update.js +46 -31
- package/dist/scripts/update.js.map +1 -1
- package/docs/BITSHARES_ONBOARDING.md +110 -40
- 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 +75 -29
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +6 -6
- package/docs/GRID_RECALCULATION.md +14 -6
- package/docs/GRID_RECONCILE.md +28 -25
- package/docs/LIFECYCLE.md +12 -11
- package/docs/README.md +48 -42
- package/docs/architecture.md +19 -30
- package/docs/developer_guide.md +3 -3
- package/package.json +1 -1
- package/scripts/git-viewer.sh +1 -1
- package/tests/README.md +10 -1
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.4 (released).
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
|
@@ -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**: Implementation phases, commit boundaries, and test coverage
|
|
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
|
+
- **Test mapping**: Links each invariant to regression tests
|
|
129
|
+
- **Review checklist**: Quick-use verification for COW/accounting changes
|
|
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 (`<=4` unified, `>4` chunked)
|
|
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.
|
|
@@ -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, and fund invariants 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/architecture.md
CHANGED
|
@@ -377,13 +377,13 @@ The fill pipeline handles incoming filled orders efficiently through fixed-cap b
|
|
|
377
377
|
↓
|
|
378
378
|
┌─────────────────────────────────────────────────────────────┐
|
|
379
379
|
│ processFilledOrders() - Entry Point │
|
|
380
|
-
│ Use gap-slot batch size for deterministic batching │
|
|
381
|
-
│ Rules: <=gapSlots unified, >gapSlots chunked │
|
|
380
|
+
│ Use gap-slot batch size (gapSlots+1) for deterministic batching │
|
|
381
|
+
│ Rules: <=gapSlots+1 unified, >gapSlots+1 chunked │
|
|
382
382
|
└─────────────────────┬───────────────────────────────────────┘
|
|
383
383
|
↓
|
|
384
384
|
┌─────────────────────────────────────────────────────────────┐
|
|
385
|
-
│ Pop Batch (up to gapSlots) │
|
|
386
|
-
│ Takes N fills from queue head (N = 1..gapSlots) │
|
|
385
|
+
│ Pop Batch (up to gapSlots+1) │
|
|
386
|
+
│ Takes N fills from queue head (N = 1..gapSlots+1) │
|
|
387
387
|
│ Example: pops [fill1, fill2, fill3] for batch processing │
|
|
388
388
|
└─────────────────────┬───────────────────────────────────────┘
|
|
389
389
|
↓
|
|
@@ -418,9 +418,9 @@ The fill pipeline handles incoming filled orders efficiently through fixed-cap b
|
|
|
418
418
|
|
|
419
419
|
### Key Properties
|
|
420
420
|
|
|
421
|
-
- **Gap-Slot Batch Sizing**: Batch size is deterministic, derived from the grid gap-slot count (`DEXBot._getGapSlotBatchSize`)
|
|
422
|
-
- 1..gapSlots awaiting: single unified batch (one rebalance/broadcast cycle)
|
|
423
|
-
- more than gapSlots awaiting: repeated chunks of gapSlots (last chunk may be smaller)
|
|
421
|
+
- **Gap-Slot Batch Sizing**: Batch size is deterministic, derived from the grid gap-slot count + 1 (`DEXBot._getGapSlotBatchSize`)
|
|
422
|
+
- 1..gapSlots+1 awaiting: single unified batch (one rebalance/broadcast cycle)
|
|
423
|
+
- more than gapSlots+1 awaiting: repeated chunks of gapSlots+1 (last chunk may be smaller)
|
|
424
424
|
|
|
425
425
|
- **Single Rebalance Cycle**: All fills in batch processed in ONE rebalance
|
|
426
426
|
- No "split across cycles" delays
|
|
@@ -916,7 +916,7 @@ graph TB
|
|
|
916
916
|
START[Grid Update Triggered] --> CALC[Calculate Ideal Grid<br/>Based on current funds]
|
|
917
917
|
CALC --> RELOAD[Force Reload Persisted Grid<br/>Ensure fresh blockchain state]
|
|
918
918
|
RELOAD --> COMPARE[Compare to Persisted Grid]
|
|
919
|
-
COMPARE --> RMS[Calculate RMS Divergence<br/>
|
|
919
|
+
COMPARE --> RMS[Calculate RMS Divergence<br/>ACTIVE + VIRTUAL orders per side]
|
|
920
920
|
|
|
921
921
|
RMS --> CHECK{RMS > Threshold?}
|
|
922
922
|
CHECK -->|Yes| UPDATE[Update Grid Sizes<br/>Trigger rebalance]
|
|
@@ -1043,28 +1043,17 @@ graph LR
|
|
|
1043
1043
|
|
|
1044
1044
|
The system has been optimized to use a "memory-driven" model for order updates, eliminating redundant blockchain API calls during normal operation.
|
|
1045
1045
|
|
|
1046
|
-
###
|
|
1047
|
-
|
|
1048
|
-
**
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
- **
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
-
|
|
1056
|
-
|
|
1057
|
-
- The bot now trusts its internal state, backed by real-time fill listener, to build transactions
|
|
1058
|
-
|
|
1059
|
-
**3. Refactored `buildUpdateOrderOp()`**
|
|
1060
|
-
- Updated to support optional `cachedOrder` parameter
|
|
1061
|
-
- Allows callers to bypass blockchain queries if they have raw state in memory
|
|
1062
|
-
- Returns `finalInts` along with operation data for local tracking
|
|
1063
|
-
|
|
1064
|
-
**4. Self-Healing Resilience**
|
|
1065
|
-
- Maintains "State Recovery Sync" fallback
|
|
1066
|
-
- If a memory-driven transaction fails, bot catches error and performs a full refresh
|
|
1067
|
-
- Ensures internal ledger stays synchronized with BitShares blockchain
|
|
1046
|
+
### How it works
|
|
1047
|
+
|
|
1048
|
+
- **Raw order cache (`rawOnChain`):** each grid slot stores the exact blockchain order integers
|
|
1049
|
+
(satoshis) — seeded from broadcast arguments on placement, updated in place on partial fills,
|
|
1050
|
+
and refreshed on updates/rotations.
|
|
1051
|
+
- **Chain-free planning:** size updates and rotations build their operations from the cache;
|
|
1052
|
+
only placements and recovery syncs query the blockchain.
|
|
1053
|
+
- **`buildUpdateOrderOp(cachedOrder?)`:** accepts an optional cached order and returns
|
|
1054
|
+
`finalInts` alongside the operation for local tracking.
|
|
1055
|
+
- **Self-healing:** a failed memory-driven transaction triggers a full state-recovery sync so the
|
|
1056
|
+
internal ledger stays consistent with the chain.
|
|
1068
1057
|
|
|
1069
1058
|
### Benefits
|
|
1070
1059
|
- **Faster reaction time**: No waiting for blockchain queries during order updates
|
package/docs/developer_guide.md
CHANGED
|
@@ -79,7 +79,7 @@ A **phantom order** is an order in ACTIVE/PARTIAL state WITHOUT a valid `orderId
|
|
|
79
79
|
|
|
80
80
|
| Term | Meaning |
|
|
81
81
|
|------|---------|
|
|
82
|
-
| **Gap-Slot Batch Fill Processing** | Groups fills using the grid gap-slot count as batch size (`DEXBot._getGapSlotBatchSize`): `<= gapSlots` uses one unified batch; `> gapSlots` chunks at gapSlots
|
|
82
|
+
| **Gap-Slot Batch Fill Processing** | Groups fills using the grid gap-slot count + 1 as batch size (`DEXBot._getGapSlotBatchSize`): `<= gapSlots + 1` uses one unified batch; `> gapSlots + 1` chunks at `gapSlots + 1`. In the documented 29-fill Feb 7 crash scenario, this reduces the estimated divergence window from ~90s to ~24s; see [`FUND_MOVEMENT_AND_ACCOUNTING.md`](FUND_MOVEMENT_AND_ACCOUNTING.md#15-fill-batch-processing--timeline). |
|
|
83
83
|
| **Recovery Retry System** | Count+time-based retry mechanism with periodic reset. Replaces one-shot `_recoveryAttempted` flag. Max 5 attempts per episode with 60s minimum interval between retries. |
|
|
84
84
|
| **Orphan-Fill Deduplication** | Map+TTL-based tracking of stale-cleaned order IDs to prevent double-crediting. Delayed orphan fill events are still blocked by checking `_staleCleanedOrderIds`. |
|
|
85
85
|
|
|
@@ -171,8 +171,8 @@ A **phantom order** is an order in ACTIVE/PARTIAL state WITHOUT a valid `orderId
|
|
|
171
171
|
| **Atomic Check-and-Deduct** | Verify funds + deduct in single operation |
|
|
172
172
|
| **Divergence Detection** | Comparing ideal grid vs. persisted grid |
|
|
173
173
|
| **Invariant Verification** | Checking fund accounting consistency |
|
|
174
|
-
| **Batch Processing** | Grouping multiple fills into a single rebalance cycle instead of one-at-a-time. Gap-slot sizing: `<= gapSlots` unified, otherwise chunked at gapSlots
|
|
175
|
-
| **Gap-Slot Batch Sizing** | Deterministic chunking model with the grid gap-slot count as the per-broadcast bound. Keeps throughput high while avoiding tier-lookup complexity. |
|
|
174
|
+
| **Batch Processing** | Grouping multiple fills into a single rebalance cycle instead of one-at-a-time. Gap-slot sizing: `<= gapSlots + 1` unified, otherwise chunked at `gapSlots + 1`. |
|
|
175
|
+
| **Gap-Slot Batch Sizing** | Deterministic chunking model with the grid gap-slot count + 1 as the per-broadcast bound. Keeps throughput high while avoiding tier-lookup complexity. |
|
|
176
176
|
| **Stale-Order Recovery** | Fast-path recovery for single-operation batches that encounter stale orders on-chain. Executes cleanup without full state sync. |
|
|
177
177
|
| **Orphan-Fill Prevention** | Deduplication mechanism that prevents double-crediting fills from stale-cleaned orders using timestamp-based ID tracking (TTL pruning). |
|
|
178
178
|
|
package/package.json
CHANGED
package/scripts/git-viewer.sh
CHANGED
|
@@ -44,7 +44,7 @@ check_dependencies() {
|
|
|
44
44
|
elif command -v dnf &> /dev/null; then
|
|
45
45
|
sudo dnf install -y "${missing_packages[@]}"
|
|
46
46
|
elif command -v pacman &> /dev/null; then
|
|
47
|
-
sudo pacman -
|
|
47
|
+
sudo pacman -Syu --noconfirm "${missing_packages[@]}"
|
|
48
48
|
else
|
|
49
49
|
echo "Warning: Could not detect package manager. Please install manually: ${missing_packages[@]}"
|
|
50
50
|
echo " apt-get: sudo apt-get install ${missing_packages[*]}"
|
package/tests/README.md
CHANGED
|
@@ -88,7 +88,7 @@ Interactive tools and performance benchmarks (not part of CI).
|
|
|
88
88
|
|
|
89
89
|
### Edge Cases & Regression
|
|
90
90
|
Tests targeting specific bugs, race conditions, and failure modes.
|
|
91
|
-
*Examples:* `test_critical_bug_fixes.ts`, `test_race_condition_fixes_batch1.ts`, `test_patch17_invariants.ts`, `test_shutdown_reentrancy.ts`, `test_multifill_opposite_partial.ts`
|
|
91
|
+
*Examples:* `test_critical_bug_fixes.ts`, `test_race_condition_fixes_batch1.ts`, `test_patch17_invariants.ts`, `test_shutdown_reentrancy.ts`, `test_multifill_opposite_partial.ts`, `test_correction_queue_staleness.ts`, `test_spread_pure_fund_driven.ts`, `test_sync_lock_id_verification.ts`
|
|
92
92
|
|
|
93
93
|
### Utilities & Helpers
|
|
94
94
|
Shared utility functions, precision handling, chain helpers.
|
|
@@ -120,6 +120,15 @@ Shared utility functions, precision handling, chain helpers.
|
|
|
120
120
|
|
|
121
121
|
**Reference:** [docs/FUND_MOVEMENT_AND_ACCOUNTING.md](../docs/FUND_MOVEMENT_AND_ACCOUNTING.md)
|
|
122
122
|
|
|
123
|
+
### Grid-Price Invariant & Hold Guards
|
|
124
|
+
- Every emitted order's price must equal its slot's genesis level (`priceForSlot(idx, genesis)`); off-grid emissions are blocked, not counted
|
|
125
|
+
- The guard itself plus the live batch wiring, escalation thresholds, and per-order stranded-hold clocks are each pinned and mutation-tested
|
|
126
|
+
- Adoption keeps the slot's own level; `loadGrid` repairs a pre-existing off-grid slot price
|
|
127
|
+
|
|
128
|
+
**Reference:** [docs/GRID_PRICE_INVARIANT.md](../docs/GRID_PRICE_INVARIANT.md)
|
|
129
|
+
|
|
130
|
+
**Examples:** `test_grid_price_invariant_guard.ts`, `test_grid_price_invariant_wiring.ts`, `test_grid_price_slot_invariant.ts`, `test_final_pivot_gate.ts`, `test_hold_and_center_guards.ts`, `test_sync_out_of_grid_defer.ts`
|
|
131
|
+
|
|
123
132
|
---
|
|
124
133
|
|
|
125
134
|
## Documentation References
|