dexbot 1.6.10 → 1.6.12
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 +50 -3
- package/README.md +3 -1
- package/analysis/README.md +51 -11
- package/analysis/bot_fitting/README.md +12 -0
- package/analysis/tradingview/README.md +3 -3
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +11 -37
- package/analysis/trend_detection/README.md +31 -0
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +4 -3
- package/claw/modules/chain_broadcast.ts +7 -1
- package/claw/modules/claw_launcher.ts +1 -1
- package/claw/modules/launcher_mode_detector.ts +9 -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/dist/analysis/account_resolver.d.ts +1 -1
- package/dist/analysis/account_resolver.js +15 -2
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +3 -4
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +2 -7
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +0 -1
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +4 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +20 -4
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +9 -6
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +16 -12
- package/dist/analysis/analyze_args.d.ts +31 -0
- package/dist/analysis/analyze_args.js +41 -0
- package/dist/analysis/analyze_dynamic_weight.js +7 -20
- package/dist/analysis/analyze_kalman.js +7 -17
- package/dist/analysis/analyze_regime.js +7 -17
- package/dist/analysis/analyze_regime_windows.js +8 -18
- package/dist/analysis/analyze_risk_profile.js +8 -18
- package/dist/analysis/analyze_trade_heatmap.js +7 -17
- package/dist/analysis/analyze_volatility.js +7 -17
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +220 -12
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +55 -10
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +34 -4
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +72 -66
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.d.ts +21 -0
- package/dist/analysis/bot_fitting/backtest_lookback_drawdown.js +315 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts +7 -7
- package/dist/analysis/bot_fitting/shared_utils.js +2 -2
- package/dist/analysis/bot_key_utils.d.ts +18 -10
- package/dist/analysis/bot_key_utils.js +10 -17
- package/dist/analysis/bot_usage/discover_bot_accounts.js +44 -47
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -21
- package/dist/analysis/chain_pool.d.ts +3 -1
- package/dist/analysis/chart_ui.d.ts +5 -2
- package/dist/analysis/chart_ui.js +6 -3
- package/dist/analysis/chart_utils.d.ts +5 -5
- package/dist/analysis/chart_utils.js +9 -0
- package/dist/analysis/fills_cache.d.ts +64 -0
- package/dist/analysis/fills_cache.js +254 -0
- package/dist/analysis/fills_source.d.ts +2 -2
- package/dist/analysis/fills_source.js +19 -14
- package/dist/analysis/grid_correction_check.d.ts +1 -1
- package/dist/analysis/grid_correction_check.js +12 -11
- package/dist/analysis/math_utils.d.ts +7 -6
- package/dist/analysis/math_utils.js +5 -8
- package/dist/analysis/pnl_report.d.ts +39 -0
- package/dist/analysis/pnl_report.js +325 -0
- package/dist/analysis/price_sources.d.ts +8 -8
- package/dist/analysis/price_sources.js +5 -4
- package/dist/analysis/resolve_bot_accounts.js +2 -2
- package/dist/analysis/resolve_source.d.ts +1 -2
- package/dist/analysis/trade_profitability.d.ts +32 -2
- package/dist/analysis/trade_profitability.js +232 -106
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +17 -6
- package/dist/analysis/tradingview/analyze_tradingview.js +9 -10
- package/dist/analysis/tradingview/grid_reset_config.d.ts +42 -31
- package/dist/analysis/tradingview/grid_reset_config.js +35 -6
- package/dist/analysis/tradingview/grid_reset_sim.d.ts +75 -8
- package/dist/analysis/tradingview/grid_reset_sim.js +42 -5
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +69 -4
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +20 -20
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.d.ts +102 -0
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +725 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +63 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +27 -112
- package/dist/analysis/trend_detection/huber_scale_variants.d.ts +40 -0
- package/dist/analysis/trend_detection/huber_scale_variants.js +176 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +30 -1
- package/dist/analysis/trend_detection/kalman_chart_generator.js +3 -3
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +31 -1
- package/dist/analysis/trend_detection/regime_chart_generator.js +2 -2
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +33 -1
- package/dist/credential-daemon.js +34 -20
- package/dist/dexbot.js +17 -14
- package/dist/market_adapter/candle_utils.d.ts +22 -18
- package/dist/market_adapter/candle_utils.js +24 -20
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +13 -4
- package/dist/market_adapter/core/config_normalizers.d.ts +3 -3
- package/dist/market_adapter/core/kibana_candles.d.ts +53 -18
- package/dist/market_adapter/core/kibana_candles.js +9 -7
- package/dist/market_adapter/core/kibana_client.d.ts +9 -1
- package/dist/market_adapter/core/kibana_client.js +8 -7
- package/dist/market_adapter/core/kibana_market_candles.d.ts +3 -2
- package/dist/market_adapter/core/market_adapter_service.d.ts +297 -115
- package/dist/market_adapter/core/market_adapter_service.js +184 -101
- package/dist/market_adapter/core/strategies/ama.d.ts +10 -2
- package/dist/market_adapter/core/strategies/ama.js +7 -32
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +14 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +12 -34
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +7 -2
- package/dist/market_adapter/core/strategies/atr/calculator.js +2 -34
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +7 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +0 -22
- package/dist/market_adapter/core/strategies/dynamic_weight_series.d.ts +36 -8
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +9 -9
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +24 -15
- package/dist/market_adapter/core/strategies/regime_gate.js +4 -31
- package/dist/market_adapter/core/strategies/regime_interp.d.ts +7 -1
- package/dist/market_adapter/core/strategies/regime_interp.js +14 -22
- package/dist/market_adapter/core/strategies/volatility_shift.d.ts +11 -1
- package/dist/market_adapter/core/strategies/volatility_shift.js +0 -13
- package/dist/market_adapter/inputs/cex_candle_parsing.d.ts +29 -0
- package/dist/market_adapter/inputs/cex_candle_parsing.js +52 -0
- package/dist/market_adapter/inputs/fetch_book_data.d.ts +20 -4
- package/dist/market_adapter/inputs/fetch_book_data.js +3 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +97 -226
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +42 -7
- package/dist/market_adapter/inputs/fetch_lp_data.js +22 -15
- package/dist/market_adapter/inputs/kibana_feed_source.d.ts +74 -15
- package/dist/market_adapter/inputs/kibana_feed_source.js +29 -22
- package/dist/market_adapter/inputs/kibana_source.d.ts +25 -3
- package/dist/market_adapter/inputs/kibana_source.js +2 -2
- package/dist/market_adapter/inputs/window_cache.d.ts +99 -94
- package/dist/market_adapter/inputs/window_cache.js +8 -8
- package/dist/market_adapter/interval_utils.d.ts +4 -4
- package/dist/market_adapter/log_format.d.ts +6 -6
- package/dist/market_adapter/log_format.js +28 -22
- package/dist/market_adapter/lp_chart_core.d.ts +22 -1
- package/dist/market_adapter/lp_chart_core.js +26 -192
- package/dist/market_adapter/lp_chart_runner.d.ts +7 -7
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +41 -6
- package/dist/market_adapter/lp_chart_strategy_loader.js +8 -7
- package/dist/market_adapter/market_adapter.d.ts +94 -33
- package/dist/market_adapter/market_adapter.js +69 -75
- package/dist/market_adapter/utils/adapter_client.d.ts +3 -3
- package/dist/market_adapter/utils/adapter_client.js +2 -2
- package/dist/market_adapter/utils/atomic_write.d.ts +8 -1
- package/dist/market_adapter/utils/chain.d.ts +50 -41
- package/dist/market_adapter/utils/chain.js +40 -46
- package/dist/market_adapter/utils/data_discovery.d.ts +4 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +12 -3
- package/dist/market_adapter/utils/file_json_cache.d.ts +2 -2
- package/dist/market_adapter/utils/file_lock.d.ts +28 -14
- package/dist/market_adapter/utils/file_lock.js +36 -32
- package/dist/market_adapter/utils/native_history.d.ts +9 -2
- package/dist/market_adapter/utils/native_history.js +35 -28
- package/dist/modules/account_bots.d.ts +577 -21
- package/dist/modules/account_bots.js +182 -158
- package/dist/modules/account_orders.d.ts +66 -30
- package/dist/modules/account_orders.js +22 -20
- package/dist/modules/authority_resolver.d.ts +12 -2
- package/dist/modules/authority_resolver.js +15 -8
- package/dist/modules/bitshares-native/chain_client.d.ts +38 -3
- package/dist/modules/bitshares-native/chain_client.js +45 -46
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +11 -171
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -176
- package/dist/modules/bitshares-native/crypto/ecc_core.d.ts +33 -0
- package/dist/modules/bitshares-native/crypto/ecc_core.js +213 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +1 -13
- package/dist/modules/bitshares-native/index.d.ts +1 -1
- package/dist/modules/bitshares-native/lru_cache.d.ts +7 -7
- package/dist/modules/bitshares-native/resolvers.d.ts +18 -6
- package/dist/modules/bitshares-native/serial/lazy_buffer.d.ts +4 -0
- package/dist/modules/bitshares-native/serial/lazy_buffer.js +21 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +1 -1
- package/dist/modules/bitshares-native/serial/serializer.d.ts +16 -12
- package/dist/modules/bitshares-native/serial/serializer.js +7 -13
- package/dist/modules/bitshares-native/serial/types.d.ts +25 -16
- package/dist/modules/bitshares-native/serial/types.js +55 -62
- package/dist/modules/bitshares-native/signing_client.d.ts +32 -2
- package/dist/modules/bitshares-native/signing_client.js +19 -14
- package/dist/modules/bitshares-native/subscriptions.d.ts +81 -1
- package/dist/modules/bitshares-native/subscriptions.js +12 -12
- package/dist/modules/bitshares-native/transport.d.ts +5 -4
- package/dist/modules/bitshares-native/transport.js +5 -4
- package/dist/modules/bitshares-native/tx/builder.d.ts +40 -5
- package/dist/modules/bitshares-native/tx/builder.js +4 -3
- package/dist/modules/bitshares-native/tx/tx_cache.d.ts +4 -4
- package/dist/modules/bitshares_client.d.ts +45 -13
- package/dist/modules/bitshares_client.js +28 -19
- package/dist/modules/bot_defaults.d.ts +6 -15
- package/dist/modules/bot_defaults.js +1 -5
- package/dist/modules/bot_settings.d.ts +44 -10
- package/dist/modules/bot_settings.js +11 -8
- package/dist/modules/bots_file_lock.d.ts +6 -6
- package/dist/modules/bots_file_lock.js +16 -12
- package/dist/modules/broadcast_failure.d.ts +2 -2
- package/dist/modules/broadcast_failure.js +5 -4
- package/dist/modules/chain_keys.d.ts +42 -40
- package/dist/modules/chain_keys.js +53 -45
- package/dist/modules/chain_orders.d.ts +93 -59
- package/dist/modules/chain_orders.js +31 -23
- package/dist/modules/constants.d.ts +530 -32
- package/dist/modules/constants.js +52 -60
- package/dist/modules/cr_planner.d.ts +40 -2
- package/dist/modules/credential_policy.d.ts +68 -8
- package/dist/modules/credential_policy.js +37 -31
- package/dist/modules/credential_session_cache.d.ts +2 -2
- package/dist/modules/credit_pricing.d.ts +42 -6
- package/dist/modules/credit_pricing.js +44 -30
- package/dist/modules/credit_runtime.d.ts +276 -118
- package/dist/modules/credit_runtime.js +462 -165
- package/dist/modules/crypto/browser_provider.js +6 -4
- package/dist/modules/crypto/node_provider.js +1 -1
- package/dist/modules/crypto/pure_scrypt.js +35 -4
- package/dist/modules/crypto/pure_secp256k1.js +72 -26
- package/dist/modules/crypto/sync.d.ts +9 -9
- package/dist/modules/crypto/sync.js +16 -9
- package/dist/modules/dexbot_class.d.ts +195 -139
- package/dist/modules/dexbot_class.js +78 -28
- package/dist/modules/dexbot_cow_runtime.d.ts +167 -87
- package/dist/modules/dexbot_cow_runtime.js +248 -206
- package/dist/modules/dexbot_credential_client.d.ts +19 -11
- package/dist/modules/dexbot_fill_runtime.d.ts +63 -48
- package/dist/modules/dexbot_fill_runtime.js +48 -41
- package/dist/modules/dexbot_maintenance_runtime.d.ts +109 -70
- package/dist/modules/dexbot_maintenance_runtime.js +117 -80
- package/dist/modules/dexbot_startup_runtime.d.ts +11 -10
- package/dist/modules/dexbot_startup_runtime.js +43 -43
- package/dist/modules/dexbot_state_recovery.d.ts +13 -12
- package/dist/modules/dexbot_state_recovery.js +18 -13
- package/dist/modules/fund_registry.d.ts +4 -2
- package/dist/modules/fund_registry.js +10 -10
- package/dist/modules/general_settings.d.ts +30 -4
- package/dist/modules/graceful_shutdown.d.ts +3 -3
- package/dist/modules/graceful_shutdown.js +2 -2
- package/dist/modules/grid_price_source.d.ts +1 -1
- package/dist/modules/key_store.d.ts +14 -8
- package/dist/modules/key_store.js +7 -6
- package/dist/modules/launcher/adapter_requirement.d.ts +11 -5
- package/dist/modules/launcher/adapter_requirement.js +5 -5
- package/dist/modules/launcher/bot_supervisor.d.ts +106 -24
- package/dist/modules/launcher/bot_supervisor.js +12 -11
- package/dist/modules/launcher/credential_bootstrap.d.ts +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +1 -1
- package/dist/modules/launcher/credential_daemon.d.ts +4 -4
- package/dist/modules/launcher/credential_daemon.js +2 -2
- package/dist/modules/launcher/credential_secret.d.ts +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -2
- package/dist/modules/launcher/market_adapter_runtime.d.ts +61 -6
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +10 -2
- package/dist/modules/launcher/market_adapter_watchdog.js +4 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +18 -16
- package/dist/modules/launcher/status_reporting.d.ts +22 -14
- package/dist/modules/launcher/supervisor_control.d.ts +8 -1
- package/dist/modules/launcher/supervisor_control.js +4 -2
- package/dist/modules/market_adapter_whitelist.d.ts +9 -3
- package/dist/modules/market_adapter_whitelist.js +15 -3
- package/dist/modules/node_manager.d.ts +41 -11
- package/dist/modules/node_manager.js +5 -4
- package/dist/modules/order/accounting.d.ts +53 -24
- package/dist/modules/order/accounting.js +40 -14
- package/dist/modules/order/async_lock.d.ts +5 -2
- package/dist/modules/order/async_lock.js +1 -1
- package/dist/modules/order/export.d.ts +7 -6
- package/dist/modules/order/export.js +1 -7
- package/dist/modules/order/format.d.ts +39 -19
- package/dist/modules/order/format.js +62 -16
- package/dist/modules/order/genesis_policy.d.ts +21 -18
- package/dist/modules/order/genesis_policy.js +12 -8
- package/dist/modules/order/grid.d.ts +142 -36
- package/dist/modules/order/grid.js +148 -123
- package/dist/modules/order/grid_reconcile.d.ts +21 -20
- package/dist/modules/order/grid_reconcile.js +13 -12
- package/dist/modules/order/grid_reconcile_internal.d.ts +85 -72
- package/dist/modules/order/grid_reconcile_internal.js +28 -19
- package/dist/modules/order/index.d.ts +263 -1
- package/dist/modules/order/logger.d.ts +45 -11
- package/dist/modules/order/logger.js +38 -40
- package/dist/modules/order/logger_state.d.ts +4 -4
- package/dist/modules/order/manager.d.ts +226 -180
- package/dist/modules/order/manager.js +101 -83
- package/dist/modules/order/processed_fill_store.d.ts +18 -3
- package/dist/modules/order/processed_fill_store.js +16 -27
- package/dist/modules/order/strategy.d.ts +21 -13
- package/dist/modules/order/strategy.js +5 -6
- package/dist/modules/order/sync_engine.d.ts +91 -33
- package/dist/modules/order/sync_engine.js +99 -54
- package/dist/modules/order/utils/math.d.ts +157 -102
- package/dist/modules/order/utils/math.js +77 -38
- package/dist/modules/order/utils/order.d.ts +326 -106
- package/dist/modules/order/utils/order.js +200 -99
- package/dist/modules/order/utils/slot.d.ts +1 -1
- package/dist/modules/order/utils/system.d.ts +176 -26
- package/dist/modules/order/utils/system.js +86 -69
- package/dist/modules/order/utils/validate.d.ts +89 -41
- package/dist/modules/order/utils/validate.js +24 -22
- package/dist/modules/order/utils/withPoolRef.d.ts +4 -3
- package/dist/modules/order/utils/withPoolRef.js +18 -12
- package/dist/modules/order/working_grid.d.ts +14 -13
- package/dist/modules/paths.d.ts +3 -4
- package/dist/modules/paths.js +3 -27
- package/dist/modules/process_discovery.d.ts +1 -1
- package/dist/modules/process_discovery.js +2 -1
- package/dist/modules/runtime.d.ts +7 -3
- package/dist/modules/runtime.js +4 -3
- package/dist/modules/runtime_settings.d.ts +15 -10
- package/dist/modules/runtime_settings.js +30 -24
- package/dist/modules/settings_merge.d.ts +29 -3
- package/dist/modules/settings_merge.js +56 -78
- package/dist/modules/socket_json_client.d.ts +7 -4
- package/dist/modules/storage/browser_adapter.d.ts +38 -53
- package/dist/modules/storage/browser_adapter.js +7 -30
- package/dist/modules/storage/index.d.ts +1 -1
- package/dist/modules/storage/node_adapter.d.ts +45 -27
- package/dist/modules/storage/node_adapter.js +9 -9
- package/dist/modules/storage/types.d.ts +5 -4
- package/dist/modules/types.d.ts +1071 -2
- package/dist/modules/types.js +4 -1
- package/dist/modules/utils/asset_symbols.d.ts +2 -1
- package/dist/modules/utils/asset_symbols.js +2 -1
- package/dist/modules/utils/errors.d.ts +9 -0
- package/dist/modules/utils/errors.js +23 -1
- package/dist/modules/utils/time_range.d.ts +4 -0
- package/dist/modules/utils/time_range.js +18 -0
- package/dist/modules/validate_profiles.js +53 -43
- package/dist/modules/version_notice.d.ts +14 -3
- package/dist/modules/version_notice.js +6 -4
- package/dist/pm2.d.ts +29 -27
- package/dist/pm2.js +5 -5
- package/dist/scripts/analyze-credit.d.ts +2 -1
- package/dist/scripts/analyze-credit.js +23 -24
- package/dist/scripts/analyze-orders.d.ts +77 -9
- package/dist/scripts/analyze-orders.js +66 -84
- package/dist/scripts/chart_command.d.ts +27 -18
- package/dist/scripts/chart_command.js +16 -15
- package/dist/scripts/check_any.d.ts +18 -0
- package/dist/scripts/check_any.js +126 -0
- package/dist/scripts/diagnose-pool-history.js +12 -7
- package/dist/scripts/pnl.d.ts +3 -0
- package/dist/scripts/pnl.js +40 -0
- package/dist/scripts/print_grid.js +0 -1
- package/dist/scripts/run-tests.js +39 -7
- package/dist/scripts/runner.js +1 -1
- package/dist/scripts/test-credit-renewal.js +30 -21
- package/dist/scripts/update.d.ts +10 -5
- package/dist/scripts/update.js +168 -103
- package/dist/scripts/update_dist_freshness.js +1 -0
- package/dist/scripts/update_layout.d.ts +61 -0
- package/dist/scripts/update_layout.js +180 -0
- package/dist/scripts/validate_bots.js +2 -1
- package/dist/scripts/verify-browser-bundle.js +8 -0
- package/dist/unlock.d.ts +28 -3
- package/dist/unlock.js +72 -10
- package/docs/BITSHARES_ONBOARDING.md +2 -0
- package/docs/COPY_ON_WRITE_MASTER_PLAN.md +1 -1
- package/docs/COW_INVARIANTS.md +13 -6
- package/docs/DEXBOT_COMPARISON.md +8 -8
- package/docs/EVOLUTION.md +12 -10
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -5
- package/docs/GRID_RECALCULATION.md +15 -16
- package/docs/GRID_RECONCILE.md +14 -3
- package/docs/LIFECYCLE.md +11 -11
- package/docs/MPA_CREDIT_USAGE.md +22 -3
- package/docs/README.md +15 -4
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +12 -9
- package/docs/developer_guide.md +6 -6
- package/market_adapter/README.md +9 -26
- package/modules/README.md +4 -1
- package/package.json +4 -1
- package/scripts/README.md +14 -0
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/** Credential client module - connects to credential daemon for key operations */
|
|
2
2
|
interface BroadcastUncertainErrorDetails {
|
|
3
|
-
operations?:
|
|
3
|
+
operations?: unknown[] | null;
|
|
4
4
|
accountName?: string | null;
|
|
5
5
|
batchId?: string | null;
|
|
6
|
-
payload?:
|
|
6
|
+
payload?: unknown;
|
|
7
7
|
timeoutMs?: number | null;
|
|
8
8
|
}
|
|
9
9
|
interface CredentialClientOptions {
|
|
@@ -34,7 +34,7 @@ interface CredentialClientOptions {
|
|
|
34
34
|
}
|
|
35
35
|
interface CredentialDaemonMeta {
|
|
36
36
|
uncertainOnTimeout?: boolean;
|
|
37
|
-
operations?:
|
|
37
|
+
operations?: unknown[] | null;
|
|
38
38
|
accountName?: string | null;
|
|
39
39
|
batchId?: string | null;
|
|
40
40
|
}
|
|
@@ -42,16 +42,24 @@ export interface CredentialDaemonResponse {
|
|
|
42
42
|
success?: boolean;
|
|
43
43
|
error?: string;
|
|
44
44
|
code?: string;
|
|
45
|
-
raw?:
|
|
46
|
-
operation_results?:
|
|
45
|
+
raw?: unknown;
|
|
46
|
+
operation_results?: unknown[];
|
|
47
47
|
/** Transaction envelope returned by some daemon/API broadcast replies. */
|
|
48
48
|
trx?: {
|
|
49
|
-
operation_results?:
|
|
50
|
-
[key: string]:
|
|
49
|
+
operation_results?: unknown[];
|
|
50
|
+
[key: string]: unknown;
|
|
51
51
|
} | null;
|
|
52
52
|
/** Node reported by the daemon as in play at the failure (typed replies). */
|
|
53
53
|
nodeUrl?: string | null;
|
|
54
54
|
}
|
|
55
|
+
interface RequestPayload {
|
|
56
|
+
type: string;
|
|
57
|
+
accountName: string;
|
|
58
|
+
operations: unknown[];
|
|
59
|
+
sessionId?: string | null;
|
|
60
|
+
hmac?: string;
|
|
61
|
+
nodeUrl?: string;
|
|
62
|
+
}
|
|
55
63
|
declare const DEFAULT_SOCKET_PATH: string;
|
|
56
64
|
declare const DEFAULT_READY_FILE: string;
|
|
57
65
|
declare const DEFAULT_BROADCAST_TIMEOUT_MS: number;
|
|
@@ -72,16 +80,16 @@ declare const DEFAULT_BROADCAST_TIMEOUT_MS: number;
|
|
|
72
80
|
*/
|
|
73
81
|
declare class BroadcastUncertainError extends Error {
|
|
74
82
|
code: string;
|
|
75
|
-
operations:
|
|
83
|
+
operations: unknown[] | null;
|
|
76
84
|
accountName: string | null;
|
|
77
85
|
batchId: string | null;
|
|
78
|
-
payload:
|
|
86
|
+
payload: unknown;
|
|
79
87
|
timeoutMs: number | null;
|
|
80
88
|
constructor(message: string, details?: BroadcastUncertainErrorDetails);
|
|
81
89
|
}
|
|
82
|
-
declare function sendCredentialDaemonRequest(socketPath: string, payload:
|
|
90
|
+
declare function sendCredentialDaemonRequest(socketPath: string, payload: RequestPayload, timeoutMs: number, meta?: CredentialDaemonMeta): Promise<CredentialDaemonResponse>;
|
|
83
91
|
declare function isCredentialDaemonReady(options?: CredentialClientOptions): boolean;
|
|
84
92
|
declare function waitForCredentialDaemon(timeoutMs?: number, options?: CredentialClientOptions): Promise<void>;
|
|
85
|
-
declare function executeOperationsViaCredentialDaemon(accountName: string, operations:
|
|
93
|
+
declare function executeOperationsViaCredentialDaemon(accountName: string, operations: unknown[], options?: CredentialClientOptions): Promise<CredentialDaemonResponse>;
|
|
86
94
|
export { DEFAULT_READY_FILE, DEFAULT_SOCKET_PATH, DEFAULT_BROADCAST_TIMEOUT_MS, sendCredentialDaemonRequest, executeOperationsViaCredentialDaemon, isCredentialDaemonReady, waitForCredentialDaemon, BroadcastUncertainError };
|
|
87
95
|
//# sourceMappingURL=dexbot_credential_client.d.ts.map
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
/** Fill processing runtime - handles order fill events and replay-safe accounting */
|
|
2
|
+
import * as chainOrders from './chain_orders.js';
|
|
3
|
+
import type { BotLike, ManagerLogger, IncomingFill } from './types.js';
|
|
4
|
+
type ChainOrdersLike = typeof chainOrders;
|
|
5
|
+
export interface FillOpLike {
|
|
6
|
+
order_id?: string;
|
|
7
|
+
[key: string]: unknown;
|
|
8
|
+
}
|
|
9
|
+
type MissingKeyMessageFn = (op: FillOpLike, fill: unknown) => string;
|
|
10
|
+
type FallbackKeyMessageFn = (op: FillOpLike, fill: unknown, fillKey: string) => string;
|
|
11
|
+
export type ReplayMessageFn = (op: FillOpLike, fill: unknown, fillKey: string) => string;
|
|
12
|
+
type FillErrorFn = (op: FillOpLike, fill: unknown, err: unknown) => string;
|
|
2
13
|
interface SweepOrphanFillOptions {
|
|
3
14
|
context: string;
|
|
4
15
|
label: string;
|
|
5
|
-
logger?:
|
|
6
|
-
replayMessage?:
|
|
16
|
+
logger?: Partial<ManagerLogger>;
|
|
17
|
+
replayMessage?: ReplayMessageFn;
|
|
7
18
|
}
|
|
8
19
|
/**
|
|
9
20
|
* Handle a sweep fill whose grid order could not be resolved (orphan): derive a
|
|
@@ -23,8 +34,8 @@ interface SweepOrphanFillOptions {
|
|
|
23
34
|
* @returns true when the fill was missing a replay-safe history identifier OR
|
|
24
35
|
* the fill was deferred to the adoption sync (order still live on-chain).
|
|
25
36
|
*/
|
|
26
|
-
declare function processSweepOrphanFill(bot:
|
|
27
|
-
declare function wireProcessedFillTracking(bot:
|
|
37
|
+
declare function processSweepOrphanFill(bot: BotLike, fill: unknown, fillOp: FillOpLike, processedFillKeys: Set<string>, opts: SweepOrphanFillOptions): Promise<boolean>;
|
|
38
|
+
declare function wireProcessedFillTracking(bot: BotLike): void;
|
|
28
39
|
/**
|
|
29
40
|
* Flush all pending processed fill writes to persistent storage.
|
|
30
41
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
@@ -32,7 +43,7 @@ declare function wireProcessedFillTracking(bot: any): void;
|
|
|
32
43
|
* @param {Object} [options] - Flush options forwarded to ProcessedFillStore.flush
|
|
33
44
|
* @returns {Promise<void>}
|
|
34
45
|
*/
|
|
35
|
-
declare function flushProcessedFillPersistence(bot:
|
|
46
|
+
declare function flushProcessedFillPersistence(bot: BotLike, reason?: string, options?: Record<string, unknown>): Promise<void>;
|
|
36
47
|
/**
|
|
37
48
|
* Flush pending processed fill writes for specific fill keys.
|
|
38
49
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
@@ -41,21 +52,28 @@ declare function flushProcessedFillPersistence(bot: any, reason?: any, options?:
|
|
|
41
52
|
* @param {Object} [options] - Flush options forwarded to ProcessedFillStore.flushKeys
|
|
42
53
|
* @returns {Promise<void>}
|
|
43
54
|
*/
|
|
44
|
-
declare function flushProcessedFillPersistenceForKeys(bot:
|
|
55
|
+
declare function flushProcessedFillPersistenceForKeys(bot: BotLike, fillKeys: string[] | Set<string>, reason?: string, options?: Record<string, unknown>): Promise<void>;
|
|
45
56
|
/**
|
|
46
57
|
* Build a degraded orphan fill replay key when the standard fill history id is missing.
|
|
47
58
|
* The fallback key is derived from order_id, block_num, pays/receives amounts and asset IDs.
|
|
48
59
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
49
|
-
* @param {
|
|
60
|
+
* @param {unknown} fill - Raw fill event
|
|
50
61
|
* @returns {string|null} Orphan fallback key or null if insufficient data
|
|
51
62
|
*/
|
|
52
|
-
|
|
63
|
+
export interface FillLike {
|
|
64
|
+
op?: unknown[];
|
|
65
|
+
block_num?: unknown;
|
|
66
|
+
trx_in_block?: unknown;
|
|
67
|
+
op_in_trx?: unknown;
|
|
68
|
+
[key: string]: unknown;
|
|
69
|
+
}
|
|
70
|
+
declare function buildOrphanFillFallbackKey(bot: BotLike, fill: FillLike): string | null;
|
|
53
71
|
/**
|
|
54
72
|
* Apply fill accounting with replay-safe deduplication.
|
|
55
73
|
* Prevents the same fill from being accounted twice across restarts or re-syncs.
|
|
56
74
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
57
|
-
* @param {
|
|
58
|
-
* @param {
|
|
75
|
+
* @param {unknown} fill - Raw fill event
|
|
76
|
+
* @param {unknown} fillOp - Extracted fill operation data
|
|
59
77
|
* @param {Object} [options] - Options
|
|
60
78
|
* @param {Function} [options.missingKeyMessage] - Callback to generate log message when fill key is missing
|
|
61
79
|
* @param {Function} [options.fallbackKeyMessage] - Callback to generate log message when fallback key is used
|
|
@@ -69,16 +87,16 @@ declare function buildOrphanFillFallbackKey(bot: any, fill: any): string | null;
|
|
|
69
87
|
* @param {boolean} [options.allowOrphanFallbackKey=false] - Allow degraded orphan fallback key
|
|
70
88
|
* @returns {Promise<any>}
|
|
71
89
|
*/
|
|
72
|
-
declare function applyReplaySafeFillAccounting(bot:
|
|
73
|
-
missingKeyMessage?:
|
|
74
|
-
fallbackKeyMessage?:
|
|
75
|
-
replayMessage?:
|
|
76
|
-
errorMessage?:
|
|
77
|
-
logger?:
|
|
90
|
+
declare function applyReplaySafeFillAccounting(bot: BotLike, fill: unknown, fillOp: FillOpLike, { missingKeyMessage, fallbackKeyMessage, replayMessage, errorMessage, logger, missingKeyLevel, fallbackKeyLevel, replayLevel, persistenceMode, allowOrphanFallbackKey }?: {
|
|
91
|
+
missingKeyMessage?: MissingKeyMessageFn;
|
|
92
|
+
fallbackKeyMessage?: FallbackKeyMessageFn;
|
|
93
|
+
replayMessage?: ReplayMessageFn;
|
|
94
|
+
errorMessage?: FillErrorFn;
|
|
95
|
+
logger?: Partial<ManagerLogger>;
|
|
78
96
|
missingKeyLevel?: string;
|
|
79
97
|
fallbackKeyLevel?: string;
|
|
80
98
|
replayLevel?: string;
|
|
81
|
-
persistenceMode?:
|
|
99
|
+
persistenceMode?: string;
|
|
82
100
|
allowOrphanFallbackKey?: boolean;
|
|
83
101
|
}): Promise<{
|
|
84
102
|
status: string;
|
|
@@ -93,15 +111,22 @@ declare function applyReplaySafeFillAccounting(bot: any, fill: any, fillOp: any,
|
|
|
93
111
|
} | {
|
|
94
112
|
status: string;
|
|
95
113
|
fillKey: any;
|
|
96
|
-
error:
|
|
114
|
+
error: unknown;
|
|
97
115
|
usedFallbackKey?: undefined;
|
|
98
116
|
}>;
|
|
117
|
+
/** Shared options for the replay-safe accounting wrappers. */
|
|
118
|
+
interface ReplaySafeFillAccountingOptions {
|
|
119
|
+
context?: string;
|
|
120
|
+
logger?: Partial<ManagerLogger>;
|
|
121
|
+
replayMessage?: ReplayMessageFn;
|
|
122
|
+
persistenceMode?: string;
|
|
123
|
+
}
|
|
99
124
|
/**
|
|
100
125
|
* Apply replay-safe fill accounting for tracked fills (with fill history id).
|
|
101
126
|
* Wraps applyReplaySafeFillAccounting with context and default message builders.
|
|
102
127
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
103
|
-
* @param {
|
|
104
|
-
* @param {
|
|
128
|
+
* @param {unknown} fill - Raw fill event
|
|
129
|
+
* @param {unknown} fillOp - Extracted fill operation data
|
|
105
130
|
* @param {Object} [options] - Options
|
|
106
131
|
* @param {string} [options.context] - Context label for log messages
|
|
107
132
|
* @param {Object} [options.logger] - Logger instance
|
|
@@ -109,12 +134,7 @@ declare function applyReplaySafeFillAccounting(bot: any, fill: any, fillOp: any,
|
|
|
109
134
|
* @param {string} [options.persistenceMode='batched'] - Processed fill persistence mode
|
|
110
135
|
* @returns {Promise<any>}
|
|
111
136
|
*/
|
|
112
|
-
declare function applyReplaySafeTrackedFillAccounting(bot:
|
|
113
|
-
context?: string;
|
|
114
|
-
logger?: any;
|
|
115
|
-
replayMessage?: any;
|
|
116
|
-
persistenceMode?: any;
|
|
117
|
-
}): Promise<{
|
|
137
|
+
declare function applyReplaySafeTrackedFillAccounting(bot: BotLike, fill: unknown, fillOp: FillOpLike, options?: ReplaySafeFillAccountingOptions): Promise<{
|
|
118
138
|
status: string;
|
|
119
139
|
fillKey: any;
|
|
120
140
|
usedFallbackKey?: undefined;
|
|
@@ -127,15 +147,15 @@ declare function applyReplaySafeTrackedFillAccounting(bot: any, fill: any, fillO
|
|
|
127
147
|
} | {
|
|
128
148
|
status: string;
|
|
129
149
|
fillKey: any;
|
|
130
|
-
error:
|
|
150
|
+
error: unknown;
|
|
131
151
|
usedFallbackKey?: undefined;
|
|
132
152
|
}>;
|
|
133
153
|
/**
|
|
134
154
|
* Apply replay-safe fill accounting for orphan fills (missing fill history id).
|
|
135
155
|
* Uses a degraded orphan fallback key when the standard key is unavailable.
|
|
136
156
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
137
|
-
* @param {
|
|
138
|
-
* @param {
|
|
157
|
+
* @param {unknown} fill - Raw fill event
|
|
158
|
+
* @param {unknown} fillOp - Extracted fill operation data
|
|
139
159
|
* @param {Object} [options] - Options
|
|
140
160
|
* @param {string} [options.context] - Context label for log messages
|
|
141
161
|
* @param {Object} [options.logger] - Logger instance
|
|
@@ -143,12 +163,7 @@ declare function applyReplaySafeTrackedFillAccounting(bot: any, fill: any, fillO
|
|
|
143
163
|
* @param {string} [options.persistenceMode='batched'] - Processed fill persistence mode
|
|
144
164
|
* @returns {Promise<any>}
|
|
145
165
|
*/
|
|
146
|
-
declare function applyReplaySafeOrphanFillAccounting(bot:
|
|
147
|
-
context?: string;
|
|
148
|
-
logger?: any;
|
|
149
|
-
replayMessage?: any;
|
|
150
|
-
persistenceMode?: any;
|
|
151
|
-
}): Promise<{
|
|
166
|
+
declare function applyReplaySafeOrphanFillAccounting(bot: BotLike, fill: unknown, fillOp: FillOpLike, options?: ReplaySafeFillAccountingOptions): Promise<{
|
|
152
167
|
status: string;
|
|
153
168
|
fillKey: any;
|
|
154
169
|
usedFallbackKey?: undefined;
|
|
@@ -161,7 +176,7 @@ declare function applyReplaySafeOrphanFillAccounting(bot: any, fill: any, fillOp
|
|
|
161
176
|
} | {
|
|
162
177
|
status: string;
|
|
163
178
|
fillKey: any;
|
|
164
|
-
error:
|
|
179
|
+
error: unknown;
|
|
165
180
|
usedFallbackKey?: undefined;
|
|
166
181
|
}>;
|
|
167
182
|
/**
|
|
@@ -171,7 +186,7 @@ declare function applyReplaySafeOrphanFillAccounting(bot: any, fill: any, fillOp
|
|
|
171
186
|
* @param {Object} chainOrders - Chain orders module
|
|
172
187
|
* @returns {Function} Async callback function accepting an array of fill events
|
|
173
188
|
*/
|
|
174
|
-
declare function createFillCallback(bot:
|
|
189
|
+
declare function createFillCallback(bot: BotLike, chainOrders: ChainOrdersLike): (fills: IncomingFill[]) => Promise<void>;
|
|
175
190
|
/**
|
|
176
191
|
* Consume the deferred-drain marker at the start of a fill cycle.
|
|
177
192
|
*
|
|
@@ -182,10 +197,10 @@ declare function createFillCallback(bot: any, chainOrders: any): (fills: any) =>
|
|
|
182
197
|
* manager._orphanFillsCreditedAt so the fund-invariant tolerance is widened
|
|
183
198
|
* (×5) for this cycle only — the drain itself must not trip the invariant.
|
|
184
199
|
* Idempotent: returns true only when a marker was actually consumed.
|
|
185
|
-
* @param {
|
|
200
|
+
* @param {unknown} bot
|
|
186
201
|
* @returns {boolean} true when the drain marker was consumed (tolerance widened)
|
|
187
202
|
*/
|
|
188
|
-
export declare function consumeDeferredDrainMarker(bot:
|
|
203
|
+
export declare function consumeDeferredDrainMarker(bot: BotLike): boolean;
|
|
189
204
|
/**
|
|
190
205
|
* Decide whether the fill consumer must defer because a broadcast region is
|
|
191
206
|
* active — WITHOUT acquiring _fillProcessingLock first.
|
|
@@ -213,7 +228,7 @@ export declare function consumeDeferredDrainMarker(bot: any): boolean;
|
|
|
213
228
|
* @returns {{ defer: boolean; stuckFallback: boolean }} defer=true means the
|
|
214
229
|
* caller must return without acquiring the lock.
|
|
215
230
|
*/
|
|
216
|
-
declare function shouldDeferFillForBroadcast(bot:
|
|
231
|
+
declare function shouldDeferFillForBroadcast(bot: BotLike, nowMs?: number): {
|
|
217
232
|
defer: boolean;
|
|
218
233
|
stuckFallback: boolean;
|
|
219
234
|
};
|
|
@@ -224,7 +239,7 @@ declare function shouldDeferFillForBroadcast(bot: any, nowMs?: number): {
|
|
|
224
239
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
225
240
|
* @param {Object} chainOrders - Chain orders module
|
|
226
241
|
*/
|
|
227
|
-
declare function scheduleFillConsumerRestart(bot:
|
|
242
|
+
declare function scheduleFillConsumerRestart(bot: BotLike, chainOrders: ChainOrdersLike): void;
|
|
228
243
|
/**
|
|
229
244
|
* Level-triggered retry for fills parked by consumeFillQueue's pre-lock
|
|
230
245
|
* gates (order-pipeline or broadcast deferral).
|
|
@@ -243,13 +258,13 @@ declare function scheduleFillConsumerRestart(bot: any, chainOrders: any): void;
|
|
|
243
258
|
* drains; once drained the timer settles. At most one retry is pending per
|
|
244
259
|
* bot. The timer is unref'd so a parked queue never holds the process open
|
|
245
260
|
* (and fakes that never clear the gate cannot hang the test runner).
|
|
246
|
-
* @param {
|
|
261
|
+
* @param {unknown} bot
|
|
247
262
|
* @param {Object} chainOrders - Chain orders module for blockchain operations
|
|
248
263
|
* @param {string} reason - Gate label for logging
|
|
249
264
|
* @param {Object} [options]
|
|
250
265
|
* @param {number} [options.retryDelayMs] - Override the derived backoff (tests)
|
|
251
266
|
*/
|
|
252
|
-
declare function scheduleDeferredFillRetry(bot:
|
|
267
|
+
declare function scheduleDeferredFillRetry(bot: BotLike, chainOrders: ChainOrdersLike, reason: string, options?: {
|
|
253
268
|
retryDelayMs?: number;
|
|
254
269
|
}): void;
|
|
255
270
|
/**
|
|
@@ -259,7 +274,7 @@ declare function scheduleDeferredFillRetry(bot: any, chainOrders: any, reason: s
|
|
|
259
274
|
* @param {Object} chainOrders - Chain orders module for blockchain operations
|
|
260
275
|
* @returns {Promise<void>}
|
|
261
276
|
*/
|
|
262
|
-
declare function processFillsWithBootstrapMode(bot:
|
|
277
|
+
declare function processFillsWithBootstrapMode(bot: BotLike, chainOrders: ChainOrdersLike): Promise<void>;
|
|
263
278
|
/**
|
|
264
279
|
* Park fills deferred on a stale accountTotals refresh for a bounded retry.
|
|
265
280
|
*
|
|
@@ -276,13 +291,13 @@ declare function processFillsWithBootstrapMode(bot: any, chainOrders: any): Prom
|
|
|
276
291
|
* released. Retries never stop (attempt counter resets on the first cycle
|
|
277
292
|
* with no deferrals); the parked array is capped at MAX_INCOMING_FILL_QUEUE
|
|
278
293
|
* with a critical log as a catastrophic backstop.
|
|
279
|
-
* @param {
|
|
294
|
+
* @param {unknown} bot
|
|
280
295
|
* @param {Object} chainOrders - Chain orders module for blockchain operations
|
|
281
|
-
* @param {
|
|
296
|
+
* @param {unknown[]} fills - Raw fill events to park
|
|
282
297
|
* @param {Object} [options]
|
|
283
298
|
* @param {number} [options.retryDelayMs] - Override the computed backoff (tests)
|
|
284
299
|
*/
|
|
285
|
-
export declare function parkFillsForTotalsRetry(bot:
|
|
300
|
+
export declare function parkFillsForTotalsRetry(bot: BotLike, chainOrders: ChainOrdersLike, fills: unknown[], options?: {
|
|
286
301
|
retryDelayMs?: number;
|
|
287
302
|
}): void;
|
|
288
303
|
/**
|
|
@@ -294,6 +309,6 @@ export declare function parkFillsForTotalsRetry(bot: any, chainOrders: any, fill
|
|
|
294
309
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
295
310
|
* @param {Object} chainOrders - Chain orders module for blockchain operations
|
|
296
311
|
*/
|
|
297
|
-
declare function consumeFillQueue(bot:
|
|
312
|
+
declare function consumeFillQueue(bot: BotLike, chainOrders: ChainOrdersLike): Promise<void>;
|
|
298
313
|
export { wireProcessedFillTracking, flushProcessedFillPersistence, flushProcessedFillPersistenceForKeys, buildOrphanFillFallbackKey, applyReplaySafeFillAccounting, applyReplaySafeTrackedFillAccounting, applyReplaySafeOrphanFillAccounting, processSweepOrphanFill, createFillCallback, scheduleFillConsumerRestart, scheduleDeferredFillRetry, shouldDeferFillForBroadcast, consumeFillQueue, processFillsWithBootstrapMode };
|
|
299
314
|
//# sourceMappingURL=dexbot_fill_runtime.d.ts.map
|
|
@@ -4,7 +4,7 @@ const require = createRequire(import.meta.url);
|
|
|
4
4
|
import * as chainOrders from './chain_orders.js';
|
|
5
5
|
import { PROCESSED_FILL_PERSISTENCE_MODES } from './order/processed_fill_store.js';
|
|
6
6
|
import { NATIVE_CLIENT, FILL_PROCESSING, TIMING, MAINTENANCE, ORDER_TYPES } from './constants.js';
|
|
7
|
-
import { getErrorMessage, resolveSeamMsOrNull } from './utils/errors.js';
|
|
7
|
+
import { getErrorMessage, resolveSeamMsOrNull, getErrorField } from './utils/errors.js';
|
|
8
8
|
import { isOrderDoesNotExistError } from './dexbot_maintenance_runtime.js';
|
|
9
9
|
import { slotIndexForPrice, isChainPriceOutOfGrid, isSlotInRail } from './order/utils/math.js';
|
|
10
10
|
import { ORDER_STATES } from './constants.js';
|
|
@@ -21,7 +21,7 @@ const { readOpenOrdersGuarded } = chainOrders;
|
|
|
21
21
|
* orders on shared accounts or other markets, which keep the legacy
|
|
22
22
|
* credit-as-orphan path.
|
|
23
23
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
24
|
-
* @param {
|
|
24
|
+
* @param {unknown} fillOp - Fill operation ({order_id, ...})
|
|
25
25
|
* @returns {Promise<boolean>} True when the order is live and in-grid-range
|
|
26
26
|
*/
|
|
27
27
|
async function isUnknownFillOrderAdoptable(bot, fillOp) {
|
|
@@ -82,7 +82,7 @@ async function isUnknownFillOrderAdoptable(bot, fillOp) {
|
|
|
82
82
|
}
|
|
83
83
|
let minPrice = Infinity;
|
|
84
84
|
let maxPrice = 0;
|
|
85
|
-
for (const o of (bot.manager?.orders?.values?.() ?? [])) {
|
|
85
|
+
for (const o of Array.from(bot.manager?.orders?.values?.() ?? [])) {
|
|
86
86
|
const p = Number(o?.price);
|
|
87
87
|
if (!Number.isFinite(p) || p <= 0)
|
|
88
88
|
continue;
|
|
@@ -128,7 +128,7 @@ async function processSweepOrphanFill(bot, fill, fillOp, processedFillKeys, opts
|
|
|
128
128
|
return false;
|
|
129
129
|
}
|
|
130
130
|
if (await isUnknownFillOrderAdoptable(bot, fillOp)) {
|
|
131
|
-
(opts.logger ?? bot.manager.logger).log(`[${opts.label}] Unknown order ${fillOp.order_id} is LIVE on-chain inside grid range — deferring proceeds credit to adoption sync`, 'warn');
|
|
131
|
+
(opts.logger ?? bot.manager.logger).log?.(`[${opts.label}] Unknown order ${fillOp.order_id} is LIVE on-chain inside grid range — deferring proceeds credit to adoption sync`, 'warn');
|
|
132
132
|
// Release the dedupe key consumed by _isNewFillKey so the fill can be
|
|
133
133
|
// re-processed against the adopted slot after the sync runs.
|
|
134
134
|
if (orphanFillKey) {
|
|
@@ -137,7 +137,7 @@ async function processSweepOrphanFill(bot, fill, fillOp, processedFillKeys, opts
|
|
|
137
137
|
}
|
|
138
138
|
return true;
|
|
139
139
|
}
|
|
140
|
-
(opts.logger ?? bot.manager.logger).log(`[${opts.label}] Processing funds for unknown order ${fillOp.order_id} (not in grid but crediting proceeds)`, 'warn');
|
|
140
|
+
(opts.logger ?? bot.manager.logger).log?.(`[${opts.label}] Processing funds for unknown order ${fillOp.order_id} (not in grid but crediting proceeds)`, 'warn');
|
|
141
141
|
const accountingResult = await bot._applyReplaySafeOrphanFillAccounting(fill, fillOp, {
|
|
142
142
|
context: opts.context,
|
|
143
143
|
logger: opts.logger,
|
|
@@ -208,21 +208,16 @@ async function flushProcessedFillPersistenceForKeys(bot, fillKeys, reason = 'man
|
|
|
208
208
|
bot._processedFillStore.setShuttingDown(bot._shuttingDown);
|
|
209
209
|
await bot._processedFillStore.flushKeys(fillKeys, reason, options);
|
|
210
210
|
}
|
|
211
|
-
/**
|
|
212
|
-
* Build a degraded orphan fill replay key when the standard fill history id is missing.
|
|
213
|
-
* The fallback key is derived from order_id, block_num, pays/receives amounts and asset IDs.
|
|
214
|
-
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
215
|
-
* @param {any} fill - Raw fill event
|
|
216
|
-
* @returns {string|null} Orphan fallback key or null if insufficient data
|
|
217
|
-
*/
|
|
218
211
|
function buildOrphanFillFallbackKey(bot, fill) {
|
|
219
212
|
const fillOp = fill?.op?.[1];
|
|
220
213
|
const orderId = fillOp?.order_id;
|
|
221
214
|
const blockNum = fill?.block_num;
|
|
222
|
-
const
|
|
223
|
-
const
|
|
224
|
-
const
|
|
225
|
-
const
|
|
215
|
+
const pays = fillOp?.pays;
|
|
216
|
+
const receives = fillOp?.receives;
|
|
217
|
+
const paysAssetId = pays?.asset_id;
|
|
218
|
+
const paysAmount = pays?.amount;
|
|
219
|
+
const receivesAssetId = receives?.asset_id;
|
|
220
|
+
const receivesAmount = receives?.amount;
|
|
226
221
|
if (fillOp?.is_maker == null) {
|
|
227
222
|
bot?._warn?.(`[ORPHAN-FALLBACK] is_maker undefined for fill ${fillOp?.order_id}; defaulting to 'maker' for dedup key`);
|
|
228
223
|
}
|
|
@@ -242,8 +237,8 @@ function buildOrphanFillFallbackKey(bot, fill) {
|
|
|
242
237
|
* Apply fill accounting with replay-safe deduplication.
|
|
243
238
|
* Prevents the same fill from being accounted twice across restarts or re-syncs.
|
|
244
239
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
245
|
-
* @param {
|
|
246
|
-
* @param {
|
|
240
|
+
* @param {unknown} fill - Raw fill event
|
|
241
|
+
* @param {unknown} fillOp - Extracted fill operation data
|
|
247
242
|
* @param {Object} [options] - Options
|
|
248
243
|
* @param {Function} [options.missingKeyMessage] - Callback to generate log message when fill key is missing
|
|
249
244
|
* @param {Function} [options.fallbackKeyMessage] - Callback to generate log message when fallback key is used
|
|
@@ -291,12 +286,20 @@ async function applyReplaySafeFillAccounting(bot, fill, fillOp, { missingKeyMess
|
|
|
291
286
|
throw err;
|
|
292
287
|
}
|
|
293
288
|
}
|
|
289
|
+
/**
|
|
290
|
+
* Resolve wrapper options with shared defaults (logger falls back to the
|
|
291
|
+
* manager's logger, persistence mode to batched). Centralized so both
|
|
292
|
+
* wrappers apply identical defaults.
|
|
293
|
+
*/
|
|
294
|
+
function resolveReplaySafeFillOptions(bot, { context, logger = bot.manager?.logger, replayMessage, persistenceMode = PROCESSED_FILL_PERSISTENCE_MODES.BATCHED, } = {}) {
|
|
295
|
+
return { context, logger, replayMessage, persistenceMode };
|
|
296
|
+
}
|
|
294
297
|
/**
|
|
295
298
|
* Apply replay-safe fill accounting for tracked fills (with fill history id).
|
|
296
299
|
* Wraps applyReplaySafeFillAccounting with context and default message builders.
|
|
297
300
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
298
|
-
* @param {
|
|
299
|
-
* @param {
|
|
301
|
+
* @param {unknown} fill - Raw fill event
|
|
302
|
+
* @param {unknown} fillOp - Extracted fill operation data
|
|
300
303
|
* @param {Object} [options] - Options
|
|
301
304
|
* @param {string} [options.context] - Context label for log messages
|
|
302
305
|
* @param {Object} [options.logger] - Logger instance
|
|
@@ -304,7 +307,8 @@ async function applyReplaySafeFillAccounting(bot, fill, fillOp, { missingKeyMess
|
|
|
304
307
|
* @param {string} [options.persistenceMode='batched'] - Processed fill persistence mode
|
|
305
308
|
* @returns {Promise<any>}
|
|
306
309
|
*/
|
|
307
|
-
async function applyReplaySafeTrackedFillAccounting(bot, fill, fillOp,
|
|
310
|
+
async function applyReplaySafeTrackedFillAccounting(bot, fill, fillOp, options = {}) {
|
|
311
|
+
const { context, logger, replayMessage, persistenceMode } = resolveReplaySafeFillOptions(bot, options);
|
|
308
312
|
return applyReplaySafeFillAccounting(bot, fill, fillOp, {
|
|
309
313
|
logger,
|
|
310
314
|
missingKeyMessage: (op) => `[${context}] Missing fill history id for ${op.order_id}; deferring to open-orders sync`,
|
|
@@ -317,8 +321,8 @@ async function applyReplaySafeTrackedFillAccounting(bot, fill, fillOp, { context
|
|
|
317
321
|
* Apply replay-safe fill accounting for orphan fills (missing fill history id).
|
|
318
322
|
* Uses a degraded orphan fallback key when the standard key is unavailable.
|
|
319
323
|
* @param {import('./dexbot_class.js').DEXBot} bot
|
|
320
|
-
* @param {
|
|
321
|
-
* @param {
|
|
324
|
+
* @param {unknown} fill - Raw fill event
|
|
325
|
+
* @param {unknown} fillOp - Extracted fill operation data
|
|
322
326
|
* @param {Object} [options] - Options
|
|
323
327
|
* @param {string} [options.context] - Context label for log messages
|
|
324
328
|
* @param {Object} [options.logger] - Logger instance
|
|
@@ -326,7 +330,8 @@ async function applyReplaySafeTrackedFillAccounting(bot, fill, fillOp, { context
|
|
|
326
330
|
* @param {string} [options.persistenceMode='batched'] - Processed fill persistence mode
|
|
327
331
|
* @returns {Promise<any>}
|
|
328
332
|
*/
|
|
329
|
-
async function applyReplaySafeOrphanFillAccounting(bot, fill, fillOp,
|
|
333
|
+
async function applyReplaySafeOrphanFillAccounting(bot, fill, fillOp, options = {}) {
|
|
334
|
+
const { context, logger, replayMessage, persistenceMode } = resolveReplaySafeFillOptions(bot, options);
|
|
330
335
|
return applyReplaySafeFillAccounting(bot, fill, fillOp, {
|
|
331
336
|
logger,
|
|
332
337
|
missingKeyMessage: (op) => `[${context}] Missing fill history id and orphan fallback key for ${op.order_id}; deferring to open-orders sync`,
|
|
@@ -383,8 +388,8 @@ function maxConsecutiveFillConsumerFailures(bot) {
|
|
|
383
388
|
*/
|
|
384
389
|
function computeFillConsumerBackoffMs(bot, failures) {
|
|
385
390
|
const fp = bot.config.fillProcessing || FILL_PROCESSING;
|
|
386
|
-
const initial = fp.CONSUMER_BACKOFF_INITIAL_MS;
|
|
387
|
-
const max = fp.CONSUMER_BACKOFF_MAX_MS;
|
|
391
|
+
const initial = fp.CONSUMER_BACKOFF_INITIAL_MS ?? FILL_PROCESSING.CONSUMER_BACKOFF_INITIAL_MS;
|
|
392
|
+
const max = fp.CONSUMER_BACKOFF_MAX_MS ?? FILL_PROCESSING.CONSUMER_BACKOFF_MAX_MS;
|
|
388
393
|
const stepAfterMax = Math.max(0, failures - maxConsecutiveFillConsumerFailures(bot));
|
|
389
394
|
return Math.min(max, initial * Math.pow(2, stepAfterMax));
|
|
390
395
|
}
|
|
@@ -398,7 +403,7 @@ function computeFillConsumerBackoffMs(bot, failures) {
|
|
|
398
403
|
* manager._orphanFillsCreditedAt so the fund-invariant tolerance is widened
|
|
399
404
|
* (×5) for this cycle only — the drain itself must not trip the invariant.
|
|
400
405
|
* Idempotent: returns true only when a marker was actually consumed.
|
|
401
|
-
* @param {
|
|
406
|
+
* @param {unknown} bot
|
|
402
407
|
* @returns {boolean} true when the drain marker was consumed (tolerance widened)
|
|
403
408
|
*/
|
|
404
409
|
export function consumeDeferredDrainMarker(bot) {
|
|
@@ -554,7 +559,7 @@ function scheduleFillConsumerRestart(bot, chainOrders) {
|
|
|
554
559
|
* drains; once drained the timer settles. At most one retry is pending per
|
|
555
560
|
* bot. The timer is unref'd so a parked queue never holds the process open
|
|
556
561
|
* (and fakes that never clear the gate cannot hang the test runner).
|
|
557
|
-
* @param {
|
|
562
|
+
* @param {unknown} bot
|
|
558
563
|
* @param {Object} chainOrders - Chain orders module for blockchain operations
|
|
559
564
|
* @param {string} reason - Gate label for logging
|
|
560
565
|
* @param {Object} [options]
|
|
@@ -639,7 +644,7 @@ async function processFillsWithBootstrapMode(bot, chainOrders) {
|
|
|
639
644
|
continue;
|
|
640
645
|
const fillOp = fill.op[1];
|
|
641
646
|
const gridOrder = bot.manager.orders.get(fillOp.order_id) ||
|
|
642
|
-
Array.from(bot.manager.orders.values()).find((o) => o.orderId === fillOp.order_id);
|
|
647
|
+
(Array.from(bot.manager.orders.values())).find((o) => o.orderId === fillOp.order_id);
|
|
643
648
|
if (!gridOrder) {
|
|
644
649
|
if (await processSweepOrphanFill(bot, fill, fillOp, processedFillKeys, { context: 'BOOTSTRAP', label: 'BOOTSTRAP' })) {
|
|
645
650
|
requiresOpenOrdersSync = true;
|
|
@@ -722,9 +727,9 @@ async function processFillsWithBootstrapMode(bot, chainOrders) {
|
|
|
722
727
|
* re-queued fill is skipped as a duplicate within _fillDedupeWindowMs — the
|
|
723
728
|
* deferral would credit nothing AND poison the retry. Mirrors the
|
|
724
729
|
* orphan-adoption release in processSweepOrphanFill.
|
|
725
|
-
* @param {
|
|
730
|
+
* @param {unknown} bot
|
|
726
731
|
* @param {Set<any>} processedFillKeys - Per-cycle key set to release from
|
|
727
|
-
* @param {
|
|
732
|
+
* @param {unknown[]} fills - Raw fill events whose keys were consumed
|
|
728
733
|
*/
|
|
729
734
|
function releaseFillDedupeKeys(bot, processedFillKeys, fills) {
|
|
730
735
|
if (!bot || !processedFillKeys || !Array.isArray(fills))
|
|
@@ -756,9 +761,9 @@ function releaseFillDedupeKeys(bot, processedFillKeys, fills) {
|
|
|
756
761
|
* released. Retries never stop (attempt counter resets on the first cycle
|
|
757
762
|
* with no deferrals); the parked array is capped at MAX_INCOMING_FILL_QUEUE
|
|
758
763
|
* with a critical log as a catastrophic backstop.
|
|
759
|
-
* @param {
|
|
764
|
+
* @param {unknown} bot
|
|
760
765
|
* @param {Object} chainOrders - Chain orders module for blockchain operations
|
|
761
|
-
* @param {
|
|
766
|
+
* @param {unknown[]} fills - Raw fill events to park
|
|
762
767
|
* @param {Object} [options]
|
|
763
768
|
* @param {number} [options.retryDelayMs] - Override the computed backoff (tests)
|
|
764
769
|
*/
|
|
@@ -768,7 +773,7 @@ export function parkFillsForTotalsRetry(bot, chainOrders, fills, options = {}) {
|
|
|
768
773
|
if (!Array.isArray(bot._fillTotalsParkedFills))
|
|
769
774
|
bot._fillTotalsParkedFills = [];
|
|
770
775
|
const parked = bot._fillTotalsParkedFills;
|
|
771
|
-
const maxParked = Number(NATIVE_CLIENT
|
|
776
|
+
const maxParked = Number(NATIVE_CLIENT.SUBSCRIPTIONS.MAX_INCOMING_FILL_QUEUE) > 0
|
|
772
777
|
? Number(NATIVE_CLIENT.SUBSCRIPTIONS.MAX_INCOMING_FILL_QUEUE)
|
|
773
778
|
: 1000;
|
|
774
779
|
if (parked.length + fills.length > maxParked) {
|
|
@@ -987,7 +992,7 @@ async function consumeFillQueue(bot, chainOrders) {
|
|
|
987
992
|
continue;
|
|
988
993
|
}
|
|
989
994
|
const gridOrder = bot.manager.orders.get(fillOp.order_id) ||
|
|
990
|
-
Array.from(bot.manager.orders.values()).find((o) => o.orderId === fillOp.order_id);
|
|
995
|
+
(Array.from(bot.manager.orders.values())).find((o) => o.orderId === fillOp.order_id);
|
|
991
996
|
if (!gridOrder) {
|
|
992
997
|
const staleMarkedAt = bot._staleCleanedOrderIds.get(fillOp.order_id);
|
|
993
998
|
if (staleMarkedAt != null) {
|
|
@@ -1020,7 +1025,7 @@ async function consumeFillQueue(bot, chainOrders) {
|
|
|
1020
1025
|
if (!bot._isNewFillKey(fillKey, processedFillKeys, '[FILL]', fillOp.order_id)) {
|
|
1021
1026
|
continue;
|
|
1022
1027
|
}
|
|
1023
|
-
validFills.push(fill);
|
|
1028
|
+
validFills.push({ ...fill, gridOrder });
|
|
1024
1029
|
const paysAmount = fillOp.pays ? fillOp.pays.amount : '?';
|
|
1025
1030
|
const receivesAmount = fillOp.receives ? fillOp.receives.amount : '?';
|
|
1026
1031
|
// Asset IDs are logged alongside the raw satoshi amounts so
|
|
@@ -1164,8 +1169,9 @@ async function consumeFillQueue(bot, chainOrders) {
|
|
|
1164
1169
|
const initialRequiresSync = requiresOpenOrdersSync;
|
|
1165
1170
|
for (const blockNum of sortedBlocks) {
|
|
1166
1171
|
requiresOpenOrdersSync = false;
|
|
1167
|
-
|
|
1168
|
-
|
|
1172
|
+
const blockFills = fillsByBlock.get(blockNum) ?? [];
|
|
1173
|
+
bot.manager.logger.log(`[FILL-BLOCK] Processing ${blockFills.length} fill(s) from block ${blockNum}`, 'debug');
|
|
1174
|
+
const blockResult = await processValidFills(blockFills);
|
|
1169
1175
|
accumulatedOrders.push(...blockResult);
|
|
1170
1176
|
if (requiresOpenOrdersSync)
|
|
1171
1177
|
anyRequiresSync = true;
|
|
@@ -1278,7 +1284,7 @@ async function consumeFillQueue(bot, chainOrders) {
|
|
|
1278
1284
|
: 100;
|
|
1279
1285
|
if (bot._fillCleanupCounter >= cleanupThreshold) {
|
|
1280
1286
|
try {
|
|
1281
|
-
await bot.accountOrders
|
|
1287
|
+
await bot.accountOrders?.cleanOldProcessedFills(TIMING.FILL_RECORD_RETENTION_MS);
|
|
1282
1288
|
bot._fillCleanupCounter = 0;
|
|
1283
1289
|
}
|
|
1284
1290
|
catch (err) {
|
|
@@ -1336,8 +1342,9 @@ async function consumeFillQueue(bot, chainOrders) {
|
|
|
1336
1342
|
bot._suspendGridPersistenceForCredentialOutage(`credential outage during fill processing: ${getErrorMessage(err)}`);
|
|
1337
1343
|
}
|
|
1338
1344
|
bot._log(`Error processing fills: ${getErrorMessage(err)}`, 'error');
|
|
1339
|
-
|
|
1340
|
-
|
|
1345
|
+
const errorStack = getErrorField(err, 'stack');
|
|
1346
|
+
if (errorStack)
|
|
1347
|
+
bot._log(errorStack, 'error');
|
|
1341
1348
|
}
|
|
1342
1349
|
// Clean settle: a drain that reached the end with an empty queue is the
|
|
1343
1350
|
// only place the retry counter is retired — otherwise the elevated count
|