dexbot 1.6.12 → 1.6.14
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 +65 -1
- package/README.md +2 -2
- package/analysis/README.md +9 -11
- package/analysis/ama_fitting/README.md +5 -3
- package/claw/README.md +1 -0
- package/claw/docs/AI_BOT_LIBRARY_API.md +3 -1
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -4
- package/claw/modules/claw_bridge.ts +0 -3
- package/claw/modules/claw_catalog.ts +8 -4
- package/claw/modules/claw_skill_md.ts +1 -0
- package/claw/modules/dexbot_profiles.ts +59 -15
- package/claw/modules/types.ts +2 -1
- package/claw/package.json +3 -3
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/claw/skills/margin-trading/SKILL.md +1 -1
- package/claw/skills/margin-trading/references/position-management.md +1 -1
- package/claw/tsconfig.json +2 -2
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +1 -14
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +51 -41
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +1 -24
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +36 -18
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +18 -66
- package/dist/analysis/analyze_args.d.ts +12 -0
- package/dist/analysis/analyze_args.js +20 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +1 -16
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +20 -101
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +26 -92
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +19 -34
- package/dist/analysis/bot_fitting/shared_utils.d.ts +71 -3
- package/dist/analysis/bot_fitting/shared_utils.js +124 -8
- package/dist/analysis/chart_ui.d.ts +30 -1
- package/dist/analysis/chart_ui.js +37 -1
- package/dist/analysis/fills_cache.d.ts +3 -23
- package/dist/analysis/fills_cache.js +3 -84
- package/dist/analysis/fills_source.d.ts +31 -1
- package/dist/analysis/fills_source.js +69 -1
- package/dist/analysis/grid_correction_check.d.ts +1 -23
- package/dist/analysis/grid_correction_check.js +15 -58
- package/dist/analysis/math_utils.d.ts +85 -1
- package/dist/analysis/math_utils.js +116 -1
- package/dist/analysis/price_sources.d.ts +22 -1
- package/dist/analysis/price_sources.js +23 -0
- package/dist/analysis/resolve_source.js +31 -10
- package/dist/analysis/trade_profitability.d.ts +6 -0
- package/dist/analysis/trade_profitability.js +23 -97
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +1 -17
- package/dist/analysis/tradingview/analyze_tradingview.js +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +27 -40
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +1 -101
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +22 -80
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +11 -37
- package/dist/analysis/trend_detection/volatility_chart_generator.js +9 -10
- package/dist/analysis/worker_pool.d.ts +38 -0
- package/dist/analysis/worker_pool.js +67 -0
- package/dist/dexbot.js +67 -48
- package/dist/market_adapter/ama_signal_runner.js +21 -54
- package/dist/market_adapter/candle_utils.d.ts +7 -1
- package/dist/market_adapter/candle_utils.js +11 -1
- package/dist/market_adapter/cli_args.d.ts +22 -0
- package/dist/market_adapter/cli_args.js +30 -0
- package/dist/market_adapter/core/config_normalizers.js +11 -6
- package/dist/market_adapter/core/kibana_candles.d.ts +3 -1
- package/dist/market_adapter/core/kibana_candles.js +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +85 -85
- package/dist/market_adapter/core/market_adapter_service.js +93 -158
- package/dist/market_adapter/core/signals/hurst_analyzer.d.ts +1 -6
- package/dist/market_adapter/core/signals/hurst_analyzer.js +1 -1
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.d.ts +1 -11
- package/dist/market_adapter/core/signals/permutation_entropy_analyzer.js +1 -1
- package/dist/market_adapter/inputs/fetch_book_data.js +0 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +63 -107
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +8 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +25 -7
- package/dist/market_adapter/inputs/kibana_feed_source.js +4 -26
- package/dist/market_adapter/inputs/window_cache.d.ts +4 -72
- package/dist/market_adapter/inputs/window_cache.js +52 -177
- package/dist/market_adapter/interval_utils.d.ts +11 -1
- package/dist/market_adapter/interval_utils.js +16 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +3 -0
- package/dist/market_adapter/lp_chart_runner.js +37 -19
- package/dist/market_adapter/market_adapter.js +27 -72
- package/dist/market_adapter/utils/data_discovery.d.ts +45 -1
- package/dist/market_adapter/utils/data_discovery.js +220 -27
- package/dist/market_adapter/utils/month_shards.d.ts +84 -0
- package/dist/market_adapter/utils/month_shards.js +237 -0
- package/dist/modules/account_bots.d.ts +8 -6
- package/dist/modules/account_bots.js +112 -131
- package/dist/modules/account_orders.d.ts +49 -4
- package/dist/modules/account_orders.js +114 -49
- package/dist/modules/bitshares-native/chain_client.d.ts +1 -1
- package/dist/modules/bitshares-native/chain_client.js +14 -13
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +1 -2
- package/dist/modules/bitshares-native/crypto/ecc_core.js +1 -1
- package/dist/modules/bitshares-native/resolvers.js +22 -25
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +1 -2
- package/dist/modules/bitshares-native/serial/chain_constants.js +1 -2
- package/dist/modules/bitshares-native/serial/types.js +22 -50
- package/dist/modules/bitshares-native/signing_client.d.ts +1 -1
- package/dist/modules/bot_defaults.d.ts +18 -3
- package/dist/modules/bot_defaults.js +34 -8
- package/dist/modules/bot_settings.d.ts +5 -1
- package/dist/modules/bot_settings.js +55 -21
- package/dist/modules/broadcast_failure.d.ts +2 -1
- package/dist/modules/chain_orders.d.ts +1 -1
- package/dist/modules/chain_orders.js +51 -96
- package/dist/modules/cli_start_onboarding.d.ts +2 -1
- package/dist/modules/config.js +6 -1
- package/dist/modules/constants.d.ts +14 -6
- package/dist/modules/constants.js +32 -6
- package/dist/modules/cr_planner.d.ts +1 -1
- package/dist/modules/cr_planner.js +1 -5
- package/dist/modules/credit_pricing.d.ts +2 -1
- package/dist/modules/credit_pricing.js +36 -40
- package/dist/modules/credit_runtime.d.ts +7 -0
- package/dist/modules/credit_runtime.js +45 -73
- package/dist/modules/daemon_node_health.d.ts +4 -3
- package/dist/modules/dexbot_class.d.ts +33 -17
- package/dist/modules/dexbot_class.js +113 -61
- package/dist/modules/dexbot_cow_runtime.d.ts +62 -181
- package/dist/modules/dexbot_cow_runtime.js +380 -69
- package/dist/modules/dexbot_credential_client.d.ts +1 -23
- package/dist/modules/dexbot_credential_client.js +2 -3
- package/dist/modules/dexbot_fill_runtime.d.ts +2 -3
- package/dist/modules/dexbot_fill_runtime.js +17 -7
- package/dist/modules/dexbot_maintenance_runtime.d.ts +36 -81
- package/dist/modules/dexbot_maintenance_runtime.js +137 -133
- package/dist/modules/dexbot_startup_runtime.d.ts +0 -1
- package/dist/modules/dexbot_startup_runtime.js +25 -14
- package/dist/modules/dexbot_state_recovery.js +16 -0
- package/dist/modules/general_settings.d.ts +1 -1
- package/dist/modules/graceful_shutdown.js +17 -11
- package/dist/modules/key_store.d.ts +0 -5
- package/dist/modules/key_store.js +1 -2
- package/dist/modules/lazy_shim.d.ts +11 -0
- package/dist/modules/lazy_shim.js +16 -0
- package/dist/modules/node_connect_policy.d.ts +3 -2
- package/dist/modules/node_failure_ledger.d.ts +6 -5
- package/dist/modules/order/accounting.js +11 -11
- package/dist/modules/order/export.js +2 -2
- package/dist/modules/order/format.d.ts +26 -3
- package/dist/modules/order/format.js +33 -3
- package/dist/modules/order/genesis_policy.d.ts +4 -4
- package/dist/modules/order/genesis_policy.js +6 -3
- package/dist/modules/order/grid.d.ts +26 -12
- package/dist/modules/order/grid.js +468 -80
- package/dist/modules/order/grid_reconcile.d.ts +1 -1
- package/dist/modules/order/grid_reconcile.js +5 -5
- package/dist/modules/order/grid_reconcile_internal.js +48 -40
- package/dist/modules/order/index.d.ts +35 -8
- package/dist/modules/order/logger.d.ts +1 -8
- package/dist/modules/order/logger.js +2 -11
- package/dist/modules/order/manager.d.ts +18 -15
- package/dist/modules/order/manager.js +91 -74
- package/dist/modules/order/strategy.d.ts +2 -2
- package/dist/modules/order/strategy.js +51 -21
- package/dist/modules/order/sync_engine.js +4 -0
- package/dist/modules/order/utils/math.d.ts +3 -3
- package/dist/modules/order/utils/math.js +38 -27
- package/dist/modules/order/utils/order.d.ts +58 -58
- package/dist/modules/order/utils/order.js +158 -137
- package/dist/modules/order/utils/system.d.ts +202 -35
- package/dist/modules/order/utils/system.js +409 -31
- package/dist/modules/order/utils/validate.js +28 -6
- package/dist/modules/order/utils/withPoolRef.d.ts +2 -1
- package/dist/modules/paths.js +32 -34
- package/dist/modules/runtime_settings.d.ts +3 -5
- package/dist/modules/runtime_settings.js +3 -3
- package/dist/modules/settings_merge.d.ts +2 -2
- package/dist/modules/socket_json_client.d.ts +2 -1
- package/dist/modules/types.d.ts +89 -30
- package/dist/modules/utils/errors.js +1 -3
- package/dist/modules/version_notice.d.ts +11 -10
- package/dist/pm2.d.ts +0 -1
- package/dist/pm2.js +56 -35
- package/dist/scripts/analyze-git.js +2 -15
- package/dist/scripts/analyze-orders.d.ts +1 -1
- package/dist/scripts/analyze-orders.js +4 -4
- package/dist/scripts/chart_command.js +2 -2
- package/dist/scripts/check_any.d.ts +4 -0
- package/dist/scripts/check_any.js +53 -21
- package/dist/scripts/diagnose-pool-history.js +1 -6
- package/dist/scripts/divergence-calc.js +6 -6
- package/dist/scripts/run-tests.js +0 -1
- package/dist/scripts/sync-version.js +0 -10
- package/dist/scripts/validate_bots.d.ts +1 -1
- package/dist/scripts/validate_bots.js +3 -3
- package/dist/unlock.js +7 -2
- package/docs/BITSHARES_ONBOARDING.md +8 -12
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +2 -3
- package/docs/COW_INVARIANTS.md +6 -6
- package/docs/DEXBOT_COMPARISON.md +7 -7
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +8 -6
- package/docs/GRID_PRICE_INVARIANT.md +3 -3
- package/docs/GRID_RECALCULATION.md +4 -1
- package/docs/GRID_RECONCILE.md +4 -4
- package/docs/LIFECYCLE.md +11 -11
- package/docs/LOGGING.md +14 -0
- package/docs/MPA_CREDIT_USAGE.md +1 -1
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +12 -4
- package/docs/README.md +3 -3
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +25 -16
- package/docs/developer_guide.md +7 -2
- package/market_adapter/README.md +6 -4
- package/package.json +6 -9
- package/scripts/README.md +43 -38
- package/tests/README.md +26 -11
- package/dist/scripts/diagnose-kibana-candles.d.ts +0 -3
- package/dist/scripts/diagnose-kibana-candles.js +0 -82
- package/scripts/git-viewer.sh +0 -489
- package/scripts/postinstall.js +0 -16
|
@@ -68,6 +68,18 @@ let cleanupHandlers = [];
|
|
|
68
68
|
let shutdownInProgress = false;
|
|
69
69
|
const shutdownLogger = new Logger('Shutdown');
|
|
70
70
|
const exitWipeCallbacks = [];
|
|
71
|
+
/**
|
|
72
|
+
* Shared registration guard for the cleanup and exit-wipe lists. Both hold
|
|
73
|
+
* `{ name, handler }` records and reject non-function handlers, so the
|
|
74
|
+
* validation and push live in one place.
|
|
75
|
+
* @private
|
|
76
|
+
*/
|
|
77
|
+
function registerHandler(list, name, handler, label) {
|
|
78
|
+
if (typeof handler !== 'function') {
|
|
79
|
+
throw new Error(`${label} for '${name}' must be a function`);
|
|
80
|
+
}
|
|
81
|
+
list.push({ name, handler });
|
|
82
|
+
}
|
|
71
83
|
/**
|
|
72
84
|
* Register a synchronous wipe callback that runs AFTER all LIFO cleanup
|
|
73
85
|
* handlers have completed, immediately before process exit. Unlike regular
|
|
@@ -79,10 +91,7 @@ const exitWipeCallbacks = [];
|
|
|
79
91
|
* @param {Function} wipeFn - Synchronous function to execute last
|
|
80
92
|
*/
|
|
81
93
|
function registerExitWipe(name, wipeFn) {
|
|
82
|
-
|
|
83
|
-
throw new Error(`Exit wipe callback for '${name}' must be a function`);
|
|
84
|
-
}
|
|
85
|
-
exitWipeCallbacks.push({ name, wipeFn });
|
|
94
|
+
registerHandler(exitWipeCallbacks, name, wipeFn, 'Exit wipe callback');
|
|
86
95
|
}
|
|
87
96
|
/**
|
|
88
97
|
* Register a cleanup function to be called on graceful shutdown
|
|
@@ -91,10 +100,7 @@ function registerExitWipe(name, wipeFn) {
|
|
|
91
100
|
* @param {Function} handler - Async or sync function to call on shutdown
|
|
92
101
|
*/
|
|
93
102
|
function registerCleanup(name, handler) {
|
|
94
|
-
|
|
95
|
-
throw new Error(`Cleanup handler for '${name}' must be a function`);
|
|
96
|
-
}
|
|
97
|
-
cleanupHandlers.push({ name, handler });
|
|
103
|
+
registerHandler(cleanupHandlers, name, handler, 'Cleanup handler');
|
|
98
104
|
}
|
|
99
105
|
/**
|
|
100
106
|
* Remove a previously registered cleanup function.
|
|
@@ -155,9 +161,9 @@ async function executeCleanup() {
|
|
|
155
161
|
}
|
|
156
162
|
}
|
|
157
163
|
for (let i = 0; i < exitWipeCallbacks.length; i++) {
|
|
158
|
-
const { name,
|
|
164
|
+
const { name, handler } = exitWipeCallbacks[i];
|
|
159
165
|
try {
|
|
160
|
-
|
|
166
|
+
handler();
|
|
161
167
|
shutdownLogger.info(`✓ ${name} (exit wipe)`);
|
|
162
168
|
}
|
|
163
169
|
catch (err) {
|
|
@@ -186,7 +192,7 @@ function setupGracefulShutdown() {
|
|
|
186
192
|
runtime.onSignal('exit', () => {
|
|
187
193
|
for (let i = 0; i < exitWipeCallbacks.length; i++) {
|
|
188
194
|
try {
|
|
189
|
-
exitWipeCallbacks[i].
|
|
195
|
+
exitWipeCallbacks[i].handler();
|
|
190
196
|
}
|
|
191
197
|
catch (_) { }
|
|
192
198
|
}
|
|
@@ -13,11 +13,6 @@ export interface KeyStore {
|
|
|
13
13
|
isDaemonSigningKey(key: unknown): boolean;
|
|
14
14
|
executeOperations(accountName: string, operations: ChainOrderOperation[], signingKey: unknown, extraOptions?: Record<string, unknown>): Promise<SigningResult>;
|
|
15
15
|
}
|
|
16
|
-
export declare class DaemonKeyStore implements KeyStore {
|
|
17
|
-
resolveSigningKey(accountName: string, vaultSecret?: unknown, chainClient?: unknown): Promise<unknown>;
|
|
18
|
-
isDaemonSigningKey(key: unknown): boolean;
|
|
19
|
-
executeOperations(accountName: string, operations: ChainOrderOperation[], signingKey: unknown, extraOptions?: Record<string, unknown>): Promise<SigningResult>;
|
|
20
|
-
}
|
|
21
16
|
export declare function setKeyStore(impl: KeyStore | null): void;
|
|
22
17
|
export declare function resetKeyStore(): void;
|
|
23
18
|
export declare function getKeyStore(): KeyStore;
|
|
@@ -42,7 +42,6 @@ function buildDaemonBroadcastOptions(signingKey, extraOptions, sessionIdOverride
|
|
|
42
42
|
requestType: 'broadcast',
|
|
43
43
|
batchId: signingKey.batchId || null,
|
|
44
44
|
...(extraOptions.nodeUrl ? { nodeUrl: extraOptions.nodeUrl } : {}),
|
|
45
|
-
...(extraOptions.fallbackNodes ? { fallbackNodes: extraOptions.fallbackNodes } : {}),
|
|
46
45
|
...(typeof extraOptions.onNodeFailed === 'function' ? { onNodeFailed: extraOptions.onNodeFailed } : {}),
|
|
47
46
|
};
|
|
48
47
|
}
|
|
@@ -70,7 +69,7 @@ async function broadcastViaChainOrders(accountName, operations, signingKey) {
|
|
|
70
69
|
await broadcastTxWithClassification(tx, accountName, operations);
|
|
71
70
|
return { success: true };
|
|
72
71
|
}
|
|
73
|
-
|
|
72
|
+
class DaemonKeyStore {
|
|
74
73
|
async resolveSigningKey(accountName, vaultSecret, chainClient) {
|
|
75
74
|
if (vaultSecret) {
|
|
76
75
|
return chainKeys.resolvePrivateKey(accountName, vaultSecret, chainClient);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build a lazy pass-through to a named export. The require runs on each call
|
|
3
|
+
* (Node caches modules), which keeps heavy or circular targets out of the
|
|
4
|
+
* static import graph without a hand-written wrapper per function. The
|
|
5
|
+
* returned function keeps the previous `(...args: unknown[]) => any` shape.
|
|
6
|
+
*
|
|
7
|
+
* Lives directly under modules/ so `require(modulePath)` resolves relative
|
|
8
|
+
* paths identically to the runtime modules that call it.
|
|
9
|
+
*/
|
|
10
|
+
export declare function lazyShim(modulePath: string, exportName: string): (...args: unknown[]) => any;
|
|
11
|
+
//# sourceMappingURL=lazy_shim.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Lazy named-export pass-through shared by the Node-only runtime modules. */
|
|
2
|
+
import { createRequire } from 'node:module';
|
|
3
|
+
const require = createRequire(import.meta.url);
|
|
4
|
+
/**
|
|
5
|
+
* Build a lazy pass-through to a named export. The require runs on each call
|
|
6
|
+
* (Node caches modules), which keeps heavy or circular targets out of the
|
|
7
|
+
* static import graph without a hand-written wrapper per function. The
|
|
8
|
+
* returned function keeps the previous `(...args: unknown[]) => any` shape.
|
|
9
|
+
*
|
|
10
|
+
* Lives directly under modules/ so `require(modulePath)` resolves relative
|
|
11
|
+
* paths identically to the runtime modules that call it.
|
|
12
|
+
*/
|
|
13
|
+
export function lazyShim(modulePath, exportName) {
|
|
14
|
+
return (...args) => require(modulePath)[exportName](...args);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=lazy_shim.js.map
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
* unit-tested without constructing the whole native client or a live
|
|
14
14
|
* NodeManager. Callers own the side effects.
|
|
15
15
|
*/
|
|
16
|
-
|
|
16
|
+
interface ConnectedNodePolicyInput {
|
|
17
17
|
/** `nodeConfig.healthCheck.enabled !== false`. */
|
|
18
18
|
healthCheckEnabled: boolean;
|
|
19
19
|
/** A restart/failover is already in progress; do not start another. */
|
|
@@ -25,7 +25,7 @@ export interface ConnectedNodePolicyInput {
|
|
|
25
25
|
/** `nodeManager.getHealthyNodes`. */
|
|
26
26
|
getHealthyNodes: () => string[];
|
|
27
27
|
}
|
|
28
|
-
|
|
28
|
+
type ConnectedNodePolicyAction = {
|
|
29
29
|
action: 'switch';
|
|
30
30
|
nodes: string[];
|
|
31
31
|
reason: 'connected-on-blacklisted-node';
|
|
@@ -49,4 +49,5 @@ export type ConnectedNodePolicyAction = {
|
|
|
49
49
|
* @returns {ConnectedNodePolicyAction}
|
|
50
50
|
*/
|
|
51
51
|
export declare function resolveConnectedNodeAction(input: ConnectedNodePolicyInput): ConnectedNodePolicyAction;
|
|
52
|
+
export {};
|
|
52
53
|
//# sourceMappingURL=node_connect_policy.d.ts.map
|
|
@@ -21,12 +21,12 @@
|
|
|
21
21
|
* already-blacklisted node, and restarts counting from 0 when a previous
|
|
22
22
|
* blacklist's cooldown expired.
|
|
23
23
|
*/
|
|
24
|
-
|
|
24
|
+
interface FailureLedgerEntry {
|
|
25
25
|
failureCount: number;
|
|
26
26
|
blacklistedUntil: number;
|
|
27
27
|
lastReportedAt: number;
|
|
28
28
|
}
|
|
29
|
-
|
|
29
|
+
interface FailureLedgerOptions {
|
|
30
30
|
/** Failure count that triggers a blacklist. */
|
|
31
31
|
threshold: number;
|
|
32
32
|
/** Blacklist duration once the threshold is reached. */
|
|
@@ -40,14 +40,14 @@ export interface FailureLedgerOptions {
|
|
|
40
40
|
/** Skip counting while the node is currently blacklisted (daemon). */
|
|
41
41
|
skipWhileBlacklisted?: boolean;
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
type FailureRecordOutcome = 'counted' | 'blacklisted' | 'rate-limited' | 'skipped-blacklisted';
|
|
44
|
+
interface FailureRecordResult {
|
|
45
45
|
outcome: FailureRecordOutcome;
|
|
46
46
|
/** The count as recorded (or the existing count for skipped outcomes). */
|
|
47
47
|
failureCount: number;
|
|
48
48
|
threshold: number;
|
|
49
49
|
}
|
|
50
|
-
|
|
50
|
+
interface FailureLedger {
|
|
51
51
|
isBlacklisted(key: string): boolean;
|
|
52
52
|
recordFailure(key: string, now?: number): FailureRecordResult;
|
|
53
53
|
/** Clear a single entry (recovery: health-check success, resetNode). */
|
|
@@ -58,4 +58,5 @@ export interface FailureLedger {
|
|
|
58
58
|
clear(): void;
|
|
59
59
|
}
|
|
60
60
|
export declare function createFailureLedger(options: FailureLedgerOptions): FailureLedger;
|
|
61
|
+
export {};
|
|
61
62
|
//# sourceMappingURL=node_failure_ledger.d.ts.map
|
|
@@ -74,7 +74,7 @@ import { createRequire } from 'node:module';
|
|
|
74
74
|
const require = createRequire(import.meta.url);
|
|
75
75
|
import { ORDER_TYPES, ORDER_STATES, PIPELINE_TIMING, TIMING, FEE_PARAMETERS, GRID_LIMITS } from '../constants.js';
|
|
76
76
|
import { resolveAccountRef } from './utils/system.js';
|
|
77
|
-
import { resolveSpreadOrderSide, parseSlotIndex, parseChainOrder, applyChainSizeToGridOrder, convertToSpreadPlaceholder,
|
|
77
|
+
import { resolveSpreadOrderSide, parseSlotIndex, parseChainOrder, applyChainSizeToGridOrder, convertToSpreadPlaceholder, resolveEdgeCount } from './utils/order.js';
|
|
78
78
|
import { isSlotInRail, floatToBlockchainInt } from './utils/math.js';
|
|
79
79
|
import * as Format from './format.js';
|
|
80
80
|
import * as fundRegistry from '../fund_registry.js';
|
|
@@ -429,19 +429,19 @@ class Accountant {
|
|
|
429
429
|
mgr.funds.total.grid = { buy: gridBuy + virtualBuy, sell: gridSell + virtualSell };
|
|
430
430
|
// STEP 6: Calculate available funds (what we can spend right now)
|
|
431
431
|
// Uses utils::calculateAvailableFundsValue which deducts committe amounts
|
|
432
|
-
//
|
|
432
|
+
// Edge ladder rides on the side counts for fee reservation: edge orders
|
|
433
433
|
// rest live on-chain and pay creation fees like window orders.
|
|
434
|
-
const
|
|
435
|
-
const
|
|
436
|
-
const
|
|
434
|
+
const edgeBuy = resolveEdgeCount(mgr.config, 'buy');
|
|
435
|
+
const edgeSell = resolveEdgeCount(mgr.config, 'sell');
|
|
436
|
+
const feeCoreOrders = mgr.config.coreOrders && typeof mgr.config.coreOrders === 'object'
|
|
437
437
|
? {
|
|
438
|
-
...mgr.config.
|
|
439
|
-
buy: Math.max(0, Number(mgr.config.
|
|
440
|
-
sell: Math.max(0, Number(mgr.config.
|
|
438
|
+
...mgr.config.coreOrders,
|
|
439
|
+
buy: Math.max(0, Number(mgr.config.coreOrders.buy) || 0) + edgeBuy,
|
|
440
|
+
sell: Math.max(0, Number(mgr.config.coreOrders.sell) || 0) + edgeSell,
|
|
441
441
|
}
|
|
442
|
-
: mgr.config.
|
|
443
|
-
mgr.funds.available.buy = calculateAvailableFundsValue('buy', mgr.accountTotals, mgr.funds, mgr.config.assetA, mgr.config.assetB,
|
|
444
|
-
mgr.funds.available.sell = calculateAvailableFundsValue('sell', mgr.accountTotals, mgr.funds, mgr.config.assetA, mgr.config.assetB,
|
|
442
|
+
: mgr.config.coreOrders;
|
|
443
|
+
mgr.funds.available.buy = calculateAvailableFundsValue('buy', mgr.accountTotals, mgr.funds, mgr.config.assetA, mgr.config.assetB, feeCoreOrders, mgr.config.min_BTS_value, mgr.config?.feeParams ?? null);
|
|
444
|
+
mgr.funds.available.sell = calculateAvailableFundsValue('sell', mgr.accountTotals, mgr.funds, mgr.config.assetA, mgr.config.assetB, feeCoreOrders, mgr.config.min_BTS_value, mgr.config?.feeParams ?? null);
|
|
445
445
|
// Ensure percentage-based allocations are applied to the newly calculated totals
|
|
446
446
|
if (typeof mgr.applyBotFundsAllocation === 'function') {
|
|
447
447
|
mgr.applyBotFundsAllocation();
|
|
@@ -477,8 +477,8 @@ async function writeSettingsJSON(botConfig, botName, outputPath) {
|
|
|
477
477
|
max_price: botConfig.maxPrice || DEFAULT_CONFIG.maxPrice,
|
|
478
478
|
increment_percent: botConfig.incrementPercent || DEFAULT_CONFIG.incrementPercent,
|
|
479
479
|
target_spread_percent: botConfig.targetSpreadPercent || DEFAULT_CONFIG.targetSpreadPercent,
|
|
480
|
-
|
|
481
|
-
|
|
480
|
+
core_orders: botConfig.coreOrders || DEFAULT_CONFIG.coreOrders,
|
|
481
|
+
edge_orders: botConfig.edgeOrders ?? DEFAULT_CONFIG.edgeOrders,
|
|
482
482
|
bot_funds: botConfig.botFunds || DEFAULT_CONFIG.botFunds,
|
|
483
483
|
weight_distribution: botConfig.weightDistribution || DEFAULT_CONFIG.weightDistribution,
|
|
484
484
|
dry_run: botConfig.dryRun || false,
|
|
@@ -38,10 +38,11 @@
|
|
|
38
38
|
* SECTION 4: RATIO/METRIC FORMATTING (1 function)
|
|
39
39
|
* 12. formatMetric2(value) - Format to 2 decimals (timing, performance)
|
|
40
40
|
*
|
|
41
|
-
* SECTION 5: HELPER UTILITIES (
|
|
41
|
+
* SECTION 5: HELPER UTILITIES (4 functions)
|
|
42
42
|
* 13. isValidNumber(value) - Check if value is defined and finite
|
|
43
43
|
* 14. toFiniteNumber(value, defaultValue) - Convert to finite number with fallback
|
|
44
|
-
* 15.
|
|
44
|
+
* 15. positiveOrNull(value) - Convert to a strictly-positive number, else null
|
|
45
|
+
* 16. safeFormat(value, decimals, fallback) - Safely format with fallback
|
|
45
46
|
*
|
|
46
47
|
* ===============================================================================
|
|
47
48
|
*/
|
|
@@ -156,6 +157,28 @@ declare function isValidNumber(value: unknown): boolean;
|
|
|
156
157
|
*/
|
|
157
158
|
declare function toFiniteNumber(value: unknown, defaultValue?: number): number;
|
|
158
159
|
declare function toFiniteNumber(value: unknown, defaultValue: number | null): number | null;
|
|
160
|
+
/**
|
|
161
|
+
* Convert a value to a strictly-positive finite number, else `null`.
|
|
162
|
+
*
|
|
163
|
+
* Single home for the `positiveOrNull` guard previously duplicated in
|
|
164
|
+
* cr_planner and credit_pricing. Zero, negatives, non-finite values and
|
|
165
|
+
* non-numeric strings all yield `null`.
|
|
166
|
+
*/
|
|
167
|
+
declare function positiveOrNull(value: unknown): number | null;
|
|
168
|
+
/**
|
|
169
|
+
* Convert a value to a finite number but treat an explicitly absent value
|
|
170
|
+
* (`null`/`undefined`/`''`) as unknown (`NaN`) instead of `0`.
|
|
171
|
+
*
|
|
172
|
+
* `Number(null) === 0` and `Number('') === 0` are finite, so a plain `Number()`
|
|
173
|
+
* coercion reads "no value" as the valid value 0 — the trap that made an
|
|
174
|
+
* unknown boundary read as slot 0, an unknown gap width collapse the band, and
|
|
175
|
+
* an unknown fill timestamp read as epoch. Use this for any geometry/index/
|
|
176
|
+
* count field where 0 is legitimate and absence must stay detectable.
|
|
177
|
+
*
|
|
178
|
+
* A genuine `0` (number, `'0'`, `false`) still converts to `0`. Pair with
|
|
179
|
+
* `Number.isFinite` at the call site where absent must fail closed.
|
|
180
|
+
*/
|
|
181
|
+
declare function toKnownNumber(value: unknown): number;
|
|
159
182
|
/**
|
|
160
183
|
* Safely format a numeric value with specified decimals and fallback.
|
|
161
184
|
*
|
|
@@ -165,5 +188,5 @@ declare function toFiniteNumber(value: unknown, defaultValue: number | null): nu
|
|
|
165
188
|
* @returns {string} Formatted value or fallback string
|
|
166
189
|
*/
|
|
167
190
|
declare function safeFormat(value: unknown, decimals: number, fallback?: string): string;
|
|
168
|
-
export { formatAmount8, formatAmount, formatAmountByPrecision, formatSizeByOrderType, formatPrice, formatPrice6, formatPrice4, formatCurrency, formatFundsValue, formatPercent2, formatPercent, formatMetric2, isValidNumber, toFiniteNumber, safeFormat };
|
|
191
|
+
export { formatAmount8, formatAmount, formatAmountByPrecision, formatSizeByOrderType, formatPrice, formatPrice6, formatPrice4, formatCurrency, formatFundsValue, formatPercent2, formatPercent, formatMetric2, isValidNumber, toFiniteNumber, toKnownNumber, positiveOrNull, safeFormat };
|
|
169
192
|
//# sourceMappingURL=format.d.ts.map
|
|
@@ -38,10 +38,11 @@
|
|
|
38
38
|
* SECTION 4: RATIO/METRIC FORMATTING (1 function)
|
|
39
39
|
* 12. formatMetric2(value) - Format to 2 decimals (timing, performance)
|
|
40
40
|
*
|
|
41
|
-
* SECTION 5: HELPER UTILITIES (
|
|
41
|
+
* SECTION 5: HELPER UTILITIES (4 functions)
|
|
42
42
|
* 13. isValidNumber(value) - Check if value is defined and finite
|
|
43
43
|
* 14. toFiniteNumber(value, defaultValue) - Convert to finite number with fallback
|
|
44
|
-
* 15.
|
|
44
|
+
* 15. positiveOrNull(value) - Convert to a strictly-positive number, else null
|
|
45
|
+
* 16. safeFormat(value, decimals, fallback) - Safely format with fallback
|
|
45
46
|
*
|
|
46
47
|
* ===============================================================================
|
|
47
48
|
*/
|
|
@@ -246,6 +247,35 @@ function toFiniteNumber(value, defaultValue = 0) {
|
|
|
246
247
|
const num = Number(value);
|
|
247
248
|
return Number.isFinite(num) ? num : defaultValue;
|
|
248
249
|
}
|
|
250
|
+
/**
|
|
251
|
+
* Convert a value to a strictly-positive finite number, else `null`.
|
|
252
|
+
*
|
|
253
|
+
* Single home for the `positiveOrNull` guard previously duplicated in
|
|
254
|
+
* cr_planner and credit_pricing. Zero, negatives, non-finite values and
|
|
255
|
+
* non-numeric strings all yield `null`.
|
|
256
|
+
*/
|
|
257
|
+
function positiveOrNull(value) {
|
|
258
|
+
const num = Number(value);
|
|
259
|
+
return Number.isFinite(num) && num > 0 ? num : null;
|
|
260
|
+
}
|
|
261
|
+
/**
|
|
262
|
+
* Convert a value to a finite number but treat an explicitly absent value
|
|
263
|
+
* (`null`/`undefined`/`''`) as unknown (`NaN`) instead of `0`.
|
|
264
|
+
*
|
|
265
|
+
* `Number(null) === 0` and `Number('') === 0` are finite, so a plain `Number()`
|
|
266
|
+
* coercion reads "no value" as the valid value 0 — the trap that made an
|
|
267
|
+
* unknown boundary read as slot 0, an unknown gap width collapse the band, and
|
|
268
|
+
* an unknown fill timestamp read as epoch. Use this for any geometry/index/
|
|
269
|
+
* count field where 0 is legitimate and absence must stay detectable.
|
|
270
|
+
*
|
|
271
|
+
* A genuine `0` (number, `'0'`, `false`) still converts to `0`. Pair with
|
|
272
|
+
* `Number.isFinite` at the call site where absent must fail closed.
|
|
273
|
+
*/
|
|
274
|
+
function toKnownNumber(value) {
|
|
275
|
+
if (value === null || value === undefined || value === '')
|
|
276
|
+
return NaN;
|
|
277
|
+
return Number(value);
|
|
278
|
+
}
|
|
249
279
|
/**
|
|
250
280
|
* Safely format a numeric value with specified decimals and fallback.
|
|
251
281
|
*
|
|
@@ -268,5 +298,5 @@ function safeFormat(value, decimals, fallback = 'N/A') {
|
|
|
268
298
|
// ===============================================================================
|
|
269
299
|
// EXPORTS
|
|
270
300
|
// ===============================================================================
|
|
271
|
-
export { formatAmount8, formatAmount, formatAmountByPrecision, formatSizeByOrderType, formatPrice, formatPrice6, formatPrice4, formatCurrency, formatFundsValue, formatPercent2, formatPercent, formatMetric2, isValidNumber, toFiniteNumber, safeFormat };
|
|
301
|
+
export { formatAmount8, formatAmount, formatAmountByPrecision, formatSizeByOrderType, formatPrice, formatPrice6, formatPrice4, formatCurrency, formatFundsValue, formatPercent2, formatPercent, formatMetric2, isValidNumber, toFiniteNumber, toKnownNumber, positiveOrNull, safeFormat };
|
|
272
302
|
//# sourceMappingURL=format.js.map
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* missing is therefore not a degraded grid -- it is an undefined one: every
|
|
7
7
|
* consumer that reads `priceForSlot(idx, genesis)` has no authority for a
|
|
8
8
|
* slot's price (nearest-slot adoption, the materialize descriptor-price
|
|
9
|
-
* fallback,
|
|
9
|
+
* fallback, edge anchoring, the `isSlotInRail` fail-open), and that is
|
|
10
10
|
* precisely the state on which an off-grid price became grid evidence and got
|
|
11
11
|
* re-emitted. The tolerance matcher that used to cover it has been removed:
|
|
12
12
|
* E2 refuses to sync such a grid and asks for the resync that re-derives the
|
|
@@ -45,12 +45,11 @@ export declare const MISSING_GENESIS_REASON: {
|
|
|
45
45
|
/** T4: the migration ladder build threw. */
|
|
46
46
|
readonly MIGRATION_FAILED: "migration_failed";
|
|
47
47
|
};
|
|
48
|
-
export type MissingGenesisReason = (typeof MISSING_GENESIS_REASON)[keyof typeof MISSING_GENESIS_REASON];
|
|
49
48
|
export declare const ON_MISSING_GENESIS: {
|
|
50
49
|
readonly REBUILD: "rebuild";
|
|
51
50
|
readonly HALT: "halt";
|
|
52
51
|
};
|
|
53
|
-
|
|
52
|
+
type OnMissingGenesisPolicy = (typeof ON_MISSING_GENESIS)[keyof typeof ON_MISSING_GENESIS];
|
|
54
53
|
/**
|
|
55
54
|
* Thrown by `loadGrid` (and the startup gate) when a snapshot carries orders
|
|
56
55
|
* but no usable ladder. Carries the policy so each caller can route the same
|
|
@@ -105,7 +104,7 @@ export declare function buildGenesisFromLiveRail(config: GridConfig | null | und
|
|
|
105
104
|
reason: string;
|
|
106
105
|
detail: string;
|
|
107
106
|
};
|
|
108
|
-
|
|
107
|
+
type GenesisResolution = {
|
|
109
108
|
ok: true;
|
|
110
109
|
genesis: GridGenesis | null;
|
|
111
110
|
source: 'persisted' | 'in_memory' | 'migration';
|
|
@@ -162,4 +161,5 @@ export declare function recordMissingGenesisFault(manager: OrderManagerLike, fau
|
|
|
162
161
|
detail: string;
|
|
163
162
|
mismatchRatio: number | null;
|
|
164
163
|
}): MissingGenesisError;
|
|
164
|
+
export {};
|
|
165
165
|
//# sourceMappingURL=genesis_policy.d.ts.map
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* missing is therefore not a degraded grid -- it is an undefined one: every
|
|
7
7
|
* consumer that reads `priceForSlot(idx, genesis)` has no authority for a
|
|
8
8
|
* slot's price (nearest-slot adoption, the materialize descriptor-price
|
|
9
|
-
* fallback,
|
|
9
|
+
* fallback, edge anchoring, the `isSlotInRail` fail-open), and that is
|
|
10
10
|
* precisely the state on which an off-grid price became grid evidence and got
|
|
11
11
|
* re-emitted. The tolerance matcher that used to cover it has been removed:
|
|
12
12
|
* E2 refuses to sync such a grid and asks for the resync that re-derives the
|
|
@@ -202,9 +202,12 @@ export function resolvePersistedGenesis({ config, grid, genesisInput = null, man
|
|
|
202
202
|
}
|
|
203
203
|
const built = buildGenesisFromLiveRail(config);
|
|
204
204
|
if (!built.ok) {
|
|
205
|
-
|
|
205
|
+
// strictNullChecks:false (tests build) does not discriminate this union,
|
|
206
|
+
// so name the failure shape explicitly.
|
|
207
|
+
const failure = built;
|
|
208
|
+
emit(`[GENESIS] Cannot migrate the persisted grid: ${failure.detail} — ` +
|
|
206
209
|
`no ladder available, refusing to load the snapshot without one`, 'error');
|
|
207
|
-
return { ok: false, reason:
|
|
210
|
+
return { ok: false, reason: failure.reason, detail: failure.detail, mismatchRatio: null };
|
|
208
211
|
}
|
|
209
212
|
// Cross-check the derived rail against the persisted slots. A user who
|
|
210
213
|
// edited startPrice/min/max/increment across restarts gets a rail the live
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* - Detects and flags out-of-spread conditions
|
|
13
13
|
*
|
|
14
14
|
* ===============================================================================
|
|
15
|
-
* TABLE OF CONTENTS - Grid Functions (
|
|
15
|
+
* TABLE OF CONTENTS - Grid Functions (23 exported functions)
|
|
16
16
|
* ===============================================================================
|
|
17
17
|
*
|
|
18
18
|
* CONFIGURATION & CALCULATION (2 functions)
|
|
@@ -34,8 +34,11 @@
|
|
|
34
34
|
* GRID RECALCULATION (1 function - async)
|
|
35
35
|
* 7. recalculateGrid(manager, opts) - Recalculate grid based on current state
|
|
36
36
|
*
|
|
37
|
-
* GRID STATE CHECKING (
|
|
38
|
-
* 8. checkAndUpdateGridIfNeeded(manager) -
|
|
37
|
+
* GRID STATE CHECKING (2 functions)
|
|
38
|
+
* 8. checkAndUpdateGridIfNeeded(manager) - Complete fund trigger: available-
|
|
39
|
+
* funds ratio + over-allocation + on-chain committed-drift legs
|
|
40
|
+
* 8b. checkCommittedSizeDrift(manager) - Async committed-drift-only accessor
|
|
41
|
+
* (the drift core is folded into checkAndUpdateGridIfNeeded)
|
|
39
42
|
*
|
|
40
43
|
* BLOCKCHAIN SYNCHRONIZATION (2 functions - async)
|
|
41
44
|
* 9. _recalculateGridOrderSizesFromBlockchain(manager, orderType, options) - Recalculate sizes from blockchain
|
|
@@ -93,6 +96,8 @@ interface SpreadCorrection {
|
|
|
93
96
|
partialOrder: ManagedOrder;
|
|
94
97
|
newSize: number;
|
|
95
98
|
}>;
|
|
99
|
+
plannedCount?: number;
|
|
100
|
+
stallHint?: SpreadCorrectionStall;
|
|
96
101
|
boundaryIdx?: number;
|
|
97
102
|
origin?: string;
|
|
98
103
|
[key: string]: unknown;
|
|
@@ -109,7 +114,7 @@ export declare function resolveRmsThresholdPct(manager: OrderManagerLike | null
|
|
|
109
114
|
import { calculateGapSlots as _mathGapSlots } from './utils/math.js';
|
|
110
115
|
import * as MathUtils from './utils/math.js';
|
|
111
116
|
import { WorkingGrid } from './working_grid.js';
|
|
112
|
-
import type { OrderManagerLike, ManagedOrder, GridConfig, OrderType, OrderState, CowAction } from '../types.js';
|
|
117
|
+
import type { OrderManagerLike, ManagedOrder, GridConfig, OrderType, OrderState, CowAction, SpreadCorrectionStall } from '../types.js';
|
|
113
118
|
import type { GridGenesis } from './utils/math.js';
|
|
114
119
|
declare const calculateGapSlots: typeof _mathGapSlots;
|
|
115
120
|
export { calculateGapSlots };
|
|
@@ -150,13 +155,9 @@ export declare function isGridBloatGraceActive(manager: OrderManagerLike): {
|
|
|
150
155
|
*/
|
|
151
156
|
export declare function clearGridBloatFlag(manager: OrderManagerLike): void;
|
|
152
157
|
/**
|
|
153
|
-
*
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* @param {import('./types').OrderManager} manager - OrderManager instance
|
|
157
|
-
* @param {string} side - 'buy' or 'sell'
|
|
158
|
-
* @returns {Promise<any|null>}
|
|
159
|
-
* @private
|
|
158
|
+
* Async sizing-context accessor. Refreshes funds unless `skipRecalc`, then
|
|
159
|
+
* delegates to the sync core. Both divergence legs (ratio and committed
|
|
160
|
+
* drift) size through the sync core so they read one fund snapshot.
|
|
160
161
|
*/
|
|
161
162
|
export declare function _getSizingContext(manager: OrderManagerLike, side: string, { skipRecalc }?: {
|
|
162
163
|
skipRecalc?: boolean;
|
|
@@ -285,6 +286,19 @@ export declare function checkAndUpdateGridIfNeeded(manager: OrderManagerLike): {
|
|
|
285
286
|
buyShrink: boolean;
|
|
286
287
|
sellShrink: boolean;
|
|
287
288
|
};
|
|
289
|
+
/**
|
|
290
|
+
* Async committed-drift accessor: refresh funds, then run the sync core.
|
|
291
|
+
* Public for callers/tests that want the drift-only result; the complete
|
|
292
|
+
* trigger is checkAndUpdateGridIfNeeded, which folds this core in.
|
|
293
|
+
* Naming mirrors the sizing pair: _computeCommittedSizeDriftSync is the
|
|
294
|
+
* private computation, checkCommittedSizeDrift the public accessor.
|
|
295
|
+
*/
|
|
296
|
+
export declare function checkCommittedSizeDrift(manager: OrderManagerLike): Promise<{
|
|
297
|
+
buyUpdated: boolean;
|
|
298
|
+
sellUpdated: boolean;
|
|
299
|
+
buyShrink: boolean;
|
|
300
|
+
sellShrink: boolean;
|
|
301
|
+
}>;
|
|
288
302
|
/**
|
|
289
303
|
* Standardize grid sizes using blockchain total context.
|
|
290
304
|
*
|
|
@@ -475,7 +489,7 @@ export declare function checkSpreadCondition(manager: OrderManagerLike, _BitShar
|
|
|
475
489
|
}>) | null): Promise<{
|
|
476
490
|
ordersPlaced: number;
|
|
477
491
|
partialsMoved: number;
|
|
478
|
-
|
|
492
|
+
stall?: SpreadCorrectionStall;
|
|
479
493
|
}>;
|
|
480
494
|
/**
|
|
481
495
|
* Grid health check for structural violations.
|