dexbot 1.4.18 → 1.4.20
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 +24 -0
- package/README.md +1 -0
- package/analysis/ama_fitting/analyze_lambda_vs_slow.ts +2 -2
- package/analysis/ama_fitting/optimizer_high_resolution.ts +2 -1
- package/analysis/ama_fitting/package.json +1 -1
- package/analysis/analyze_derivatives.ts +4 -2
- package/analysis/analyze_dynamic_weight.ts +3 -1
- package/analysis/analyze_kalman.ts +3 -1
- package/analysis/analyze_regime.ts +3 -1
- package/analysis/analyze_regime_windows.ts +3 -1
- package/analysis/analyze_volatility.ts +2 -2
- package/analysis/bot_fitting/backtest_ama_sweep.ts +2 -1
- package/analysis/bot_fitting/backtest_bot_fitting.ts +17 -12
- package/analysis/chart_utils.ts +24 -0
- package/analysis/derivative_chart_generator.ts +3 -2
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/analysis/trend_detection/dynamic_weight_chart_generator.ts +91 -55
- package/analysis/trend_detection/package.json +1 -1
- package/claw/examples/claw_profiles_example.ts +4 -1
- package/claw/modules/claw_catalog.ts +1 -1
- package/claw/modules/claw_skill_md.ts +6 -5
- package/claw/modules/dexbot_profiles.ts +3 -1
- package/claw/modules/launcher_paths.ts +4 -2
- 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/ama_fitting/analyze_lambda_vs_slow.js +2 -2
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +2 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -1
- package/dist/analysis/analyze_derivatives.d.ts.map +1 -1
- package/dist/analysis/analyze_derivatives.js +4 -2
- package/dist/analysis/analyze_derivatives.js.map +1 -1
- package/dist/analysis/analyze_dynamic_weight.js +3 -1
- package/dist/analysis/analyze_dynamic_weight.js.map +1 -1
- package/dist/analysis/analyze_kalman.js +3 -1
- package/dist/analysis/analyze_kalman.js.map +1 -1
- package/dist/analysis/analyze_regime.js +3 -1
- package/dist/analysis/analyze_regime.js.map +1 -1
- package/dist/analysis/analyze_regime_windows.js +3 -1
- package/dist/analysis/analyze_regime_windows.js.map +1 -1
- package/dist/analysis/analyze_volatility.js +2 -2
- package/dist/analysis/analyze_volatility.js.map +1 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +2 -1
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -1
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +18 -13
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -1
- package/dist/analysis/chart_utils.d.ts +0 -3
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +25 -0
- 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 +3 -2
- package/dist/analysis/derivative_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 +82 -50
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -1
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +2 -3
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +8 -3
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/modules/account_bots.d.ts +1 -0
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +27 -5
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/config.d.ts +2 -0
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +2 -0
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +1 -0
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +13 -4
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +22 -0
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +27 -1
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +48 -8
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +263 -4
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
- package/dist/modules/dexbot_state_recovery.js +20 -1
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +146 -32
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +6 -27
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/manager.d.ts +13 -0
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +75 -2
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/strategy.d.ts.map +1 -1
- package/dist/modules/order/strategy.js +6 -15
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +102 -1
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +165 -2
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +2 -0
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +30 -2
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/paths.d.ts +26 -1
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +39 -6
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts +1 -0
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +13 -2
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/scripts/analyze-git.js +2 -1
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/analyze-orders.js +2 -2
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/docs/DEXBOT_COMPARISON.md +3 -3
- package/docs/EVOLUTION.md +27 -96
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/LIFECYCLE.md +207 -0
- package/docs/README.md +9 -1
- package/docs/developer_guide.md +4 -3
- package/package.json +3 -3
- package/scripts/lib/dexbot-paths.sh +20 -11
- package/scripts/repo-stats.html +0 -480
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
# DEXBot2 Lifecycle — End-to-End Walkthrough
|
|
2
|
+
|
|
3
|
+
This is the **one-page map** for newcomers. It stitches together the flows that are
|
|
4
|
+
otherwise spread across `architecture.md` and `developer_guide.md` into two concrete
|
|
5
|
+
lifecycles (fill-driven and maintenance-driven) plus the startup sequence. Read this
|
|
6
|
+
first; follow the file/function references into the deeper docs.
|
|
7
|
+
|
|
8
|
+
> All code references use `file:line` so you can jump straight to the source.
|
|
9
|
+
|
|
10
|
+
---
|
|
11
|
+
|
|
12
|
+
## 1. System Context
|
|
13
|
+
|
|
14
|
+
Who talks to what. DEXBot2 is a long-running Node process that both *reads* the
|
|
15
|
+
BitShares chain/market and *writes* limit orders back to it.
|
|
16
|
+
|
|
17
|
+
```mermaid
|
|
18
|
+
graph TB
|
|
19
|
+
OP[Operator<br/>CLI / PM2 / unlock.ts]
|
|
20
|
+
CHAIN[(BitShares Chain<br/>fills, open orders, balances)]
|
|
21
|
+
MKT[Market Data<br/>LP pools / order book / AMA feed]
|
|
22
|
+
STORE[(Local Storage<br/>profiles/orders/*.json<br/>profiles/bots.json)]
|
|
23
|
+
BOT[DEXBot2 Process<br/>dexbot_class.ts]
|
|
24
|
+
|
|
25
|
+
OP -->|configure / start| BOT
|
|
26
|
+
CHAIN -->|fill events op-4| BOT
|
|
27
|
+
CHAIN -->|open-order poll| BOT
|
|
28
|
+
MKT -->|price / AMA center| BOT
|
|
29
|
+
BOT -->|CREATE / UPDATE / CANCEL| CHAIN
|
|
30
|
+
BOT -->|grid snapshot| STORE
|
|
31
|
+
STORE -->|restore grid| BOT
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Three inputs drive everything: **fill events** (reactive), **market/AMA price**
|
|
35
|
+
(periodic), and **config/storage** (startup + recovery).
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## 2. Startup / Bootstrap Sequence
|
|
40
|
+
|
|
41
|
+
Runs once per bot launch. Goal: decrypt keys, load metadata, rebuild the master
|
|
42
|
+
grid from either config or the persisted snapshot, then hand off to the runtime
|
|
43
|
+
loops.
|
|
44
|
+
|
|
45
|
+
```mermaid
|
|
46
|
+
sequenceDiagram
|
|
47
|
+
participant OP as Operator
|
|
48
|
+
participant CL as dexbot_class.ts
|
|
49
|
+
participant CD as Credential Daemon
|
|
50
|
+
participant AM as Asset Metadata
|
|
51
|
+
participant OM as OrderManager
|
|
52
|
+
participant CH as Chain (open orders)
|
|
53
|
+
participant ST as Storage
|
|
54
|
+
|
|
55
|
+
OP->>CL: start(botKey)
|
|
56
|
+
CL->>CD: decrypt private key (AES, interactive/one-shot)
|
|
57
|
+
CD-->>CL: unlocked key
|
|
58
|
+
CL->>AM: load precision, fees, asset IDs
|
|
59
|
+
CL->>ST: load persisted grid snapshot (if present)
|
|
60
|
+
ST-->>CL: orders/botKey.json
|
|
61
|
+
CL->>OM: init Master Grid (config OR snapshot)
|
|
62
|
+
CL->>CH: SyncEngine 2-pass (grid<->chain match)
|
|
63
|
+
CH-->>OM: detect partials / stale / phantom
|
|
64
|
+
CL->>CL: start maintenance loop + market adapter (if AMA)
|
|
65
|
+
CL-->>OP: bot live, awaiting fills / ticks
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Key references:
|
|
69
|
+
- Credential unlock: `modules/credential_runtime.ts`, `CREDENTIAL_SECURITY.md`
|
|
70
|
+
- Master Grid init + COW: `docs/architecture.md` §"Copy-on-Write (COW) Grid Pattern"
|
|
71
|
+
- SyncEngine 2-pass: `modules/order/sync_engine.ts`, `docs/GRID_RECONCILE.md`
|
|
72
|
+
|
|
73
|
+
---
|
|
74
|
+
|
|
75
|
+
## 3. Lifecycle A — Fill-Driven (Reactive)
|
|
76
|
+
|
|
77
|
+
This is the hot path. A limit order gets filled on-chain and the bot must rebuild
|
|
78
|
+
grid symmetry, credit proceeds, and broadcast replacement orders — all inside a
|
|
79
|
+
single Copy-on-Write rebalance cycle.
|
|
80
|
+
|
|
81
|
+
```mermaid
|
|
82
|
+
sequenceDiagram
|
|
83
|
+
participant CH as Chain (op-4 fill)
|
|
84
|
+
participant Q as _incomingFillQueue
|
|
85
|
+
participant FR as dexbot_fill_runtime
|
|
86
|
+
participant OM as OrderManager
|
|
87
|
+
participant WG as WorkingGrid (COW)
|
|
88
|
+
participant AC as Accounting (SSOT)
|
|
89
|
+
participant ST as Strategy (calculateTargetGrid)
|
|
90
|
+
participant CO as chain_orders (broadcast)
|
|
91
|
+
participant STORE as Storage
|
|
92
|
+
|
|
93
|
+
CH->>Q: enqueue fill(s) (dexbot_fill_runtime.ts:325)
|
|
94
|
+
FR->>FR: drain queue -> _processFillsWithBatching
|
|
95
|
+
FR->>OM: processFilledOrders() (manager.ts)
|
|
96
|
+
OM->>AC: processFillAccounting() (single call, batch)
|
|
97
|
+
AC-->>WG: chainFree += combined proceeds
|
|
98
|
+
OM->>ST: calculateTargetGrid() (rotations + boundary shift)
|
|
99
|
+
ST-->>WG: mutated WorkingGrid only
|
|
100
|
+
OM->>CO: updateOrdersOnChainBatch() (atomic broadcast)
|
|
101
|
+
CO-->>CH: CREATE / CANCEL orders
|
|
102
|
+
CO-->>OM: confirm
|
|
103
|
+
OM->>WG: commit WorkingGrid -> Master Grid
|
|
104
|
+
OM->>STORE: persistGrid() (snapshot after confirm)
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
Why it matters:
|
|
108
|
+
- **Fixed-cap batching** (`MAX_FILL_BATCH_SIZE`, default 4) keeps bursts
|
|
109
|
+
deterministic — see `docs/architecture.md` §"Fill Processing Pipeline".
|
|
110
|
+
- **Single rebalance cycle**: all fills in a batch share one broadcast, so proceeds
|
|
111
|
+
are immediately available for replacement sizing (no split-across-cycles delay).
|
|
112
|
+
- **Replay-safe accounting**: processed-fill keys prevent double-credit on retries
|
|
113
|
+
(`modules/dexbot_fill_runtime.ts`, `PROCESSED_FILL_PERSISTENCE_MODES`).
|
|
114
|
+
|
|
115
|
+
References: `modules/dexbot_fill_runtime.ts`, `modules/order/manager.ts`,
|
|
116
|
+
`docs/FUND_MOVEMENT_AND_ACCOUNTING.md`.
|
|
117
|
+
|
|
118
|
+
---
|
|
119
|
+
|
|
120
|
+
## 4. Lifecycle B — Maintenance / AMA Signal-Driven (Periodic)
|
|
121
|
+
|
|
122
|
+
Runs on a timer (and on AMA center updates). The grid is *not* rebuilt from fills
|
|
123
|
+
here; instead funds are re-synced, the AMA center is promoted to the grid center,
|
|
124
|
+
and the grid is recalculated against the latest market view.
|
|
125
|
+
|
|
126
|
+
```mermaid
|
|
127
|
+
sequenceDiagram
|
|
128
|
+
participant MA as Market Adapter (AMA)
|
|
129
|
+
participant CL as dexbot_class.ts
|
|
130
|
+
participant RT as maintenance_runtime
|
|
131
|
+
participant AC as Accounting
|
|
132
|
+
participant GD as Grid (recalculateGrid)
|
|
133
|
+
participant CO as chain_orders
|
|
134
|
+
participant STORE as Storage
|
|
135
|
+
|
|
136
|
+
MA->>CL: AMA center snapshot updated
|
|
137
|
+
CL->>CL: _performPeriodicGridChecks() (dexbot_class.ts:1664)
|
|
138
|
+
CL->>RT: performPeriodicGridChecks() (dexbot_maintenance_runtime.ts:1043)
|
|
139
|
+
RT->>RT: runGridMaintenance(bot,'periodic') (dexbot_maintenance_runtime.ts:1845)
|
|
140
|
+
RT->>RT: executeMaintenanceLogic() (dexbot_maintenance_runtime.ts:1452)
|
|
141
|
+
RT->>AC: recalculate funds from balances
|
|
142
|
+
RT->>GD: promote AMA center -> grid center
|
|
143
|
+
RT->>GD: recalculateGrid() (grid.ts)
|
|
144
|
+
GD->>GD: rebuild levels via WorkingGrid (COW)
|
|
145
|
+
RT->>CO: broadcast adjustments (if any)
|
|
146
|
+
RT->>STORE: persistGrid()
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
Two triggers feed this loop:
|
|
150
|
+
1. **Timer** — periodic fund sync + grid checks (`_performPeriodicGridChecks`).
|
|
151
|
+
2. **AMA center change** — `market_adapter` recomputes the adaptive moving average;
|
|
152
|
+
when the center moves enough it promotes to the grid center and forces a recalc
|
|
153
|
+
(`modules/dexbot_maintenance_runtime.ts`, `market_adapter/market_adapter.ts`).
|
|
154
|
+
|
|
155
|
+
The AMA signal stack (AMA/Kalman/Hurst/PE) is *research-tuned* in `analysis/` and
|
|
156
|
+
*consumed* here at runtime — see `analysis/README.md` for the tooling that produces
|
|
157
|
+
the parameters.
|
|
158
|
+
|
|
159
|
+
> Note: `runMaintenance()` is a **different** subsystem — the credit/MPA debt
|
|
160
|
+
> runtime (`modules/credit_runtime.ts:3041`, reached via
|
|
161
|
+
> `_runCreditRuntimeMaintenance` at `dexbot_class.ts:1769`). The grid maintenance
|
|
162
|
+
> chain above is the one that matters for order/price upkeep.
|
|
163
|
+
|
|
164
|
+
References: `modules/dexbot_class.ts:1664` (`_performPeriodicGridChecks`) →
|
|
165
|
+
`modules/dexbot_maintenance_runtime.ts:1043` (`performPeriodicGridChecks`) →
|
|
166
|
+
`:1845` (`runGridMaintenance`) → `:1452` (`executeMaintenanceLogic`),
|
|
167
|
+
`docs/GRID_RECALCULATION.md`, `docs/GRID_RECONCILE.md`.
|
|
168
|
+
|
|
169
|
+
---
|
|
170
|
+
|
|
171
|
+
## 5. Cross-Cutting Invariants (read before touching anything)
|
|
172
|
+
|
|
173
|
+
These are the rules that make the two lifecycles safe. They are *convention-
|
|
174
|
+
enforced*, not compiler-enforced — learn them or you will introduce fund bugs.
|
|
175
|
+
|
|
176
|
+
| Invariant | Rule | Reference |
|
|
177
|
+
|---|---|---|
|
|
178
|
+
| **COW boundary** | All grid mutations happen on the WorkingGrid; Master Grid is frozen and only committed after chain confirmation. | `docs/developer_guide.md` §"Copy-on-Write (COW) Development Rules" |
|
|
179
|
+
| **Fund SSOT** | `Accounting` owns every fund number. Nothing else computes available funds. | `docs/architecture.md` §"Fund Flow Architecture" |
|
|
180
|
+
| **Replay-safe fills** | A fill is credited exactly once via processed-fill keys; retries are idempotent. | `modules/dexbot_fill_runtime.ts` |
|
|
181
|
+
| **Single broadcast per cycle** | One `updateOrdersOnChainBatch` per rebalance — never scatter writes. | `docs/architecture.md` §"Fill Processing Pipeline" |
|
|
182
|
+
| **Browser/Node split** | Heavy runtime is Node-only; never import it from a browser bundle. | `AGENTS.md` "Browser-Safe Surface", `docs/BROWSER_COMPAT_PLAN.md` |
|
|
183
|
+
| **Lock ordering** | Fill drain and maintenance must not run a rebalance concurrently. | `docs/developer_guide.md` §"Startup Sequence & Lock Ordering" |
|
|
184
|
+
|
|
185
|
+
---
|
|
186
|
+
|
|
187
|
+
## 6. File Map (where to go next)
|
|
188
|
+
|
|
189
|
+
| You want to understand… | Start here |
|
|
190
|
+
|---|---|
|
|
191
|
+
| How a fill becomes orders | `modules/dexbot_fill_runtime.ts` → `modules/order/manager.ts` |
|
|
192
|
+
| Grid math / recalculation | `modules/order/grid.ts`, `docs/GRID_RECALCULATION.md` |
|
|
193
|
+
| 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:1664` |
|
|
195
|
+
| Market signal source | `market_adapter/market_adapter.ts`, `analysis/README.md` |
|
|
196
|
+
| Startup & orchestration | `modules/dexbot_class.ts`, `docs/developer_guide.md` §"Startup Sequence" |
|
|
197
|
+
| Why COW exists | `docs/architecture.md` §"Copy-on-Write (COW) Grid Pattern", `docs/COW_INVARIANTS.md` |
|
|
198
|
+
|
|
199
|
+
---
|
|
200
|
+
|
|
201
|
+
### TL;DR mental model
|
|
202
|
+
|
|
203
|
+
> Blockchain fill (or AMA tick) → enqueue → drain in fixed-cap batches →
|
|
204
|
+
> credit proceeds to Accounting (SSOT) → mutate **WorkingGrid** only →
|
|
205
|
+
> calculate target grid → **single** atomic broadcast → commit WorkingGrid to
|
|
206
|
+
> Master → persist snapshot. Master Grid is immutable; everything else is a
|
|
207
|
+
> disposable copy until the chain confirms.
|
package/docs/README.md
CHANGED
|
@@ -109,6 +109,14 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
109
109
|
- **Market Adapter Signal Pipeline**: AMA center, dynamic weights, regime detection, and collateral advisories
|
|
110
110
|
- **Credit/Debt Runtime**: Native MPA and credit offer workflows with CR planning and grid reset coupling; `creditOnly` mode for runtime-only operation without grid trading
|
|
111
111
|
|
|
112
|
+
### 🔁 [Lifecycle](LIFECYCLE.md)
|
|
113
|
+
*The end-to-end walkthrough (start here for the big picture).*
|
|
114
|
+
- **System Context**: What DEXBot2 talks to (chain, market data, storage, operator).
|
|
115
|
+
- **Startup / Bootstrap**: Decrypt keys → load metadata → rebuild master grid → sync → runtime loops.
|
|
116
|
+
- **Lifecycle A (Fill-Driven)**: Reactive path from an on-chain fill to a single atomic rebalance + broadcast.
|
|
117
|
+
- **Lifecycle B (Maintenance / AMA-Driven)**: Periodic path from `_performPeriodicGridChecks` → `executeMaintenanceLogic`.
|
|
118
|
+
- **Cross-Cutting Invariants**: COW boundary, fund SSOT, replay-safe fills, lock ordering.
|
|
119
|
+
|
|
112
120
|
### 📖 [Developer Guide](developer_guide.md)
|
|
113
121
|
*Your daily companion for coding.*
|
|
114
122
|
- **Quick Start**: How to get the development environment running.
|
|
@@ -136,7 +144,7 @@ This directory contains the comprehensive technical documentation for the DEXBot
|
|
|
136
144
|
|
|
137
145
|
### 🧭 [Evolution Report](EVOLUTION.md)
|
|
138
146
|
*Project timeline and major architecture phases.*
|
|
139
|
-
- **Coverage**: Historical milestones from the initial December 2025 bootstrap through the v1.4.
|
|
147
|
+
- **Coverage**: Historical milestones from the initial December 2025 bootstrap through the v1.4.20 stable release (grid persistence safety, dust pipeline fix, net inventory lots); credit/debt runtime and maintenance hardening are covered under Phase 5 (Mar–Jun 2026)
|
|
140
148
|
- **Focus**: Architecture evolution, release history, test growth, and documentation changes
|
|
141
149
|
|
|
142
150
|
### 🗒️ [Changelog](../CHANGELOG.md)
|
package/docs/developer_guide.md
CHANGED
|
@@ -11,8 +11,9 @@ Welcome to DEXBot2! This guide will help you understand the codebase, navigate k
|
|
|
11
11
|
### 1. **Start Here** (5 minutes)
|
|
12
12
|
Read these files in order to get oriented:
|
|
13
13
|
1. [README](../README.md) - User documentation and setup
|
|
14
|
-
2. [
|
|
15
|
-
3. [
|
|
14
|
+
2. [LIFECYCLE.md](LIFECYCLE.md) - **End-to-end walkthrough** (startup, fill-driven, and AMA-driven flows with diagrams) — read this first for the big picture
|
|
15
|
+
3. [architecture.md](architecture.md) - System architecture and module relationships
|
|
16
|
+
4. [FUND_MOVEMENT_AND_ACCOUNTING.md](FUND_MOVEMENT_AND_ACCOUNTING.md) - Core algorithms and formulas
|
|
16
17
|
|
|
17
18
|
### 2. **Core Concepts** (15 minutes)
|
|
18
19
|
Understand these fundamental concepts before diving into code:
|
|
@@ -130,7 +131,7 @@ A **phantom order** is an order in ACTIVE/PARTIAL state WITHOUT a valid `orderId
|
|
|
130
131
|
| **Asymmetric Offset** | Directional weight shift (buy-heavy or sell-heavy) driven by AMA/Kalman trend |
|
|
131
132
|
| **Derivative Signal** | SMA/MACD/RSI-based entry bias and momentum gate for optional strategy filtering |
|
|
132
133
|
| **Momentum Gate** | N-bar commitment tracking that confirms derivative signals before acting |
|
|
133
|
-
| **
|
|
134
|
+
| **GridPrice** | Price anchor for grid math; can be numeric, `"pool"`, `"book"`, or AMA keyword (`"ama"`, `"ama1"`–`"ama4"`) |
|
|
134
135
|
|
|
135
136
|
### Grid Concepts
|
|
136
137
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dexbot",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.20",
|
|
4
4
|
"description": "The first open source trading bot with zero runtime dependencies and a fully adaptive market making strategy.",
|
|
5
5
|
"main": "dist/modules/dexbot_class.js",
|
|
6
6
|
"exports": {
|
|
@@ -14,7 +14,6 @@
|
|
|
14
14
|
},
|
|
15
15
|
"files": [
|
|
16
16
|
"dist",
|
|
17
|
-
|
|
18
17
|
"ecosystem.config.cjs",
|
|
19
18
|
"scripts/bots",
|
|
20
19
|
"scripts/clean-dist.js",
|
|
@@ -33,7 +32,6 @@
|
|
|
33
32
|
"scripts/postinstall.js",
|
|
34
33
|
"scripts/ptest.sh",
|
|
35
34
|
"scripts/README.md",
|
|
36
|
-
"scripts/repo-stats.html",
|
|
37
35
|
"scripts/reset-settings.sh",
|
|
38
36
|
"scripts/unlock",
|
|
39
37
|
"scripts/update.js",
|
|
@@ -52,10 +50,12 @@
|
|
|
52
50
|
"docs/WORKFLOW.md",
|
|
53
51
|
"docs/architecture.md",
|
|
54
52
|
"docs/developer_guide.md",
|
|
53
|
+
"docs/LIFECYCLE.md",
|
|
55
54
|
"docs/docker.md",
|
|
56
55
|
"market_adapter/README.md",
|
|
57
56
|
"modules/README.md",
|
|
58
57
|
"analysis",
|
|
58
|
+
"!analysis/charts",
|
|
59
59
|
"tests/README.md",
|
|
60
60
|
"CHANGELOG.md",
|
|
61
61
|
"README.md",
|
|
@@ -39,10 +39,13 @@ if [ -z "$PROFILE_ROOT" ]; then
|
|
|
39
39
|
else
|
|
40
40
|
# Home dir: $HOME normally; when unset (e.g. cron/systemd), mirror
|
|
41
41
|
# Node's os.homedir() passwd fallback so the shell side does not fall
|
|
42
|
-
# back into a node_modules package dir on npm installs.
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
42
|
+
# back into a node_modules package dir on npm installs. XDG_CONFIG_HOME
|
|
43
|
+
# overrides the config base, mirroring HOME_CONFIG_DIR in paths.ts.
|
|
44
|
+
CONFIG_BASE=""
|
|
45
|
+
if [ -n "$XDG_CONFIG_HOME" ]; then
|
|
46
|
+
CONFIG_BASE="$XDG_CONFIG_HOME"
|
|
47
|
+
elif [ -n "$HOME" ]; then
|
|
48
|
+
CONFIG_BASE="${HOME}/.config"
|
|
46
49
|
else
|
|
47
50
|
PASSWD_HOME=""
|
|
48
51
|
if command -v getent >/dev/null 2>&1; then
|
|
@@ -50,20 +53,26 @@ if [ -z "$PROFILE_ROOT" ]; then
|
|
|
50
53
|
elif command -v dscl >/dev/null 2>&1; then
|
|
51
54
|
PASSWD_HOME="$(dscl . -read "/Users/$(id -un)" NFSHomeDirectory 2>/dev/null | awk '{print $2}')"
|
|
52
55
|
fi
|
|
53
|
-
[ -n "$PASSWD_HOME" ] &&
|
|
56
|
+
[ -n "$PASSWD_HOME" ] && CONFIG_BASE="${PASSWD_HOME}/.config"
|
|
54
57
|
fi
|
|
58
|
+
HOME_PROFILES="${CONFIG_BASE:+${CONFIG_BASE}/dexbot2/profiles}"
|
|
55
59
|
# An existing home config is authoritative — the user has migrated.
|
|
56
60
|
if [ -n "$HOME_PROFILES" ] && has_profile_state "$HOME_PROFILES"; then
|
|
57
61
|
PROFILE_ROOT="$HOME_PROFILES"
|
|
58
62
|
else
|
|
59
63
|
# Legacy migration: keep a populated repo/cwd profiles dir until a
|
|
60
64
|
# home config exists. npm packages never fall back into the package
|
|
61
|
-
# dir
|
|
62
|
-
#
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
65
|
+
# dir — exact-parent check (basename of dirname), mirroring
|
|
66
|
+
# isGlobalNpmPackageDir() in modules/paths.ts; a substring match
|
|
67
|
+
# would also skip legit repos whose path merely contains the word.
|
|
68
|
+
# Written as explicit checks (no word-splitting loop) so it behaves
|
|
69
|
+
# identically under bash, dash, and zsh.
|
|
70
|
+
LEGACY_REPO=""
|
|
71
|
+
if [ "$(basename "$(dirname "$PROJECT_ROOT")")" = "node_modules" ]; then
|
|
72
|
+
LEGACY_REPO=""
|
|
73
|
+
else
|
|
74
|
+
LEGACY_REPO="${PROJECT_ROOT}/profiles"
|
|
75
|
+
fi
|
|
67
76
|
PROFILE_ROOT=""
|
|
68
77
|
if [ -n "$LEGACY_REPO" ] && has_profile_state "$LEGACY_REPO"; then
|
|
69
78
|
PROFILE_ROOT="$LEGACY_REPO"
|