dexbot 1.4.11 → 1.4.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/README.md +4 -4
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +9 -18
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/math_utils.d.ts.map +1 -1
- package/dist/analysis/math_utils.js +6 -16
- package/dist/analysis/math_utils.js.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +31 -38
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -1
- package/dist/analysis/trend_detection/hurst_analyzer.js +7 -10
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +10 -14
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -1
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +10 -15
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -1
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +7 -10
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +4 -12
- package/dist/bot.js.map +1 -1
- package/dist/credential-daemon.d.ts +0 -1
- package/dist/credential-daemon.d.ts.map +1 -1
- package/dist/credential-daemon.js +3 -123
- package/dist/credential-daemon.js.map +1 -1
- package/dist/dexbot.d.ts +0 -87
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +11 -14
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +8 -9
- package/dist/market_adapter/ama_signal_runner.js.map +1 -1
- package/dist/market_adapter/candle_utils.js +1 -7
- package/dist/market_adapter/candle_utils.js.map +1 -1
- package/dist/market_adapter/core/asymmetric_bounds.js +1 -4
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -1
- package/dist/market_adapter/core/config_normalizers.js +5 -9
- package/dist/market_adapter/core/config_normalizers.js.map +1 -1
- package/dist/market_adapter/core/kibana_candles.js +8 -15
- package/dist/market_adapter/core/kibana_candles.js.map +1 -1
- package/dist/market_adapter/core/kibana_client.js +7 -13
- package/dist/market_adapter/core/kibana_client.js.map +1 -1
- package/dist/market_adapter/core/kibana_market_candles.js +6 -12
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +92 -102
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama.js +5 -10
- package/dist/market_adapter/core/strategies/ama.js.map +1 -1
- package/dist/market_adapter/core/strategies/ama_slope_model.js +21 -24
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -1
- package/dist/market_adapter/core/strategies/atr/calculator.js +3 -5
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -1
- package/dist/market_adapter/core/strategies/collateral_manager.js +4 -6
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -1
- package/dist/market_adapter/core/strategies/regime_gate.js +15 -22
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
- package/dist/market_adapter/index.d.ts +23 -23
- package/dist/market_adapter/index.d.ts.map +1 -1
- package/dist/market_adapter/index.js +24 -82
- package/dist/market_adapter/index.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +59 -98
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/market_adapter/inputs/kibana_source.js +11 -17
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
- package/dist/market_adapter/interval_utils.js +1 -2
- package/dist/market_adapter/interval_utils.js.map +1 -1
- package/dist/market_adapter/log_format.js +1 -7
- package/dist/market_adapter/log_format.js.map +1 -1
- package/dist/market_adapter/lp_chart_core.js +20 -22
- package/dist/market_adapter/lp_chart_core.js.map +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts +1 -1
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -1
- package/dist/market_adapter/lp_chart_runner.js +41 -57
- package/dist/market_adapter/lp_chart_runner.js.map +1 -1
- package/dist/market_adapter/lp_chart_strategy_loader.js +30 -34
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
- package/dist/market_adapter/market_adapter.d.ts +2 -2
- package/dist/market_adapter/market_adapter.d.ts.map +1 -1
- package/dist/market_adapter/market_adapter.js +157 -221
- package/dist/market_adapter/market_adapter.js.map +1 -1
- package/dist/market_adapter/merge_lp_data.js +17 -18
- package/dist/market_adapter/merge_lp_data.js.map +1 -1
- package/dist/market_adapter/test_helpers.js +3 -14
- package/dist/market_adapter/test_helpers.js.map +1 -1
- package/dist/market_adapter/utils/adapter_client.js +7 -16
- package/dist/market_adapter/utils/adapter_client.js.map +1 -1
- package/dist/market_adapter/utils/atomic_write.js +3 -5
- package/dist/market_adapter/utils/atomic_write.js.map +1 -1
- package/dist/market_adapter/utils/chain.d.ts.map +1 -1
- package/dist/market_adapter/utils/chain.js +9 -17
- package/dist/market_adapter/utils/chain.js.map +1 -1
- package/dist/market_adapter/utils/data_discovery.js +8 -10
- package/dist/market_adapter/utils/data_discovery.js.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -1
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +11 -14
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -1
- package/dist/market_adapter/utils/file_lock.js +14 -19
- package/dist/market_adapter/utils/file_lock.js.map +1 -1
- package/dist/market_adapter/utils/native_history.js +8 -14
- package/dist/market_adapter/utils/native_history.js.map +1 -1
- package/dist/market_adapter/utils/paths.js +3 -6
- package/dist/market_adapter/utils/paths.js.map +1 -1
- package/dist/modules/account_bots.d.ts +1 -1
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +90 -97
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +0 -9
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +26 -121
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/authority_resolver.js +12 -18
- package/dist/modules/authority_resolver.js.map +1 -1
- package/dist/modules/bitshares-native/chain_client.js +16 -21
- package/dist/modules/bitshares-native/chain_client.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +12 -72
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc.js +13 -40
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -1
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +5 -6
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -1
- package/dist/modules/bitshares-native/index.d.ts +8 -8
- package/dist/modules/bitshares-native/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/index.js +11 -68
- package/dist/modules/bitshares-native/index.js.map +1 -1
- package/dist/modules/bitshares-native/lru_cache.js +3 -6
- package/dist/modules/bitshares-native/lru_cache.js.map +1 -1
- package/dist/modules/bitshares-native/resolvers.js +9 -11
- package/dist/modules/bitshares-native/resolvers.js.map +1 -1
- package/dist/modules/bitshares-native/serial/chain_constants.js +3 -28
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -1
- package/dist/modules/bitshares-native/serial/index.d.ts +4 -4
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/index.js +5 -46
- package/dist/modules/bitshares-native/serial/index.js.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.d.ts +98 -98
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -1
- package/dist/modules/bitshares-native/serial/operations.js +372 -473
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -1
- package/dist/modules/bitshares-native/serial/serializer.js +3 -8
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -1
- package/dist/modules/bitshares-native/serial/types.js +9 -74
- package/dist/modules/bitshares-native/serial/types.js.map +1 -1
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -1
- package/dist/modules/bitshares-native/signing_client.js +11 -48
- package/dist/modules/bitshares-native/signing_client.js.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -1
- package/dist/modules/bitshares-native/subscriptions.js +24 -27
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -1
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -1
- package/dist/modules/bitshares-native/transport.js +14 -26
- package/dist/modules/bitshares-native/transport.js.map +1 -1
- package/dist/modules/bitshares-native/tx/builder.js +29 -72
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -1
- package/dist/modules/bitshares-native/tx/tx_cache.js +12 -21
- package/dist/modules/bitshares-native/tx/tx_cache.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts +21 -0
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +32 -86
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +30 -49
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/bots_file_lock.d.ts.map +1 -1
- package/dist/modules/bots_file_lock.js +5 -13
- package/dist/modules/bots_file_lock.js.map +1 -1
- package/dist/modules/broadcast_failure.js +1 -3
- package/dist/modules/broadcast_failure.js.map +1 -1
- package/dist/modules/chain_keys.d.ts +4 -9
- package/dist/modules/chain_keys.d.ts.map +1 -1
- package/dist/modules/chain_keys.js +77 -182
- package/dist/modules/chain_keys.js.map +1 -1
- package/dist/modules/chain_orders.d.ts +2 -2
- package/dist/modules/chain_orders.d.ts.map +1 -1
- package/dist/modules/chain_orders.js +81 -144
- package/dist/modules/chain_orders.js.map +1 -1
- package/dist/modules/config.d.ts.map +1 -1
- package/dist/modules/config.js +23 -28
- package/dist/modules/config.js.map +1 -1
- package/dist/modules/constants.d.ts +2 -9
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +38 -73
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/cr_planner.js +15 -26
- package/dist/modules/cr_planner.js.map +1 -1
- package/dist/modules/credential_policy.d.ts +3 -6
- package/dist/modules/credential_policy.d.ts.map +1 -1
- package/dist/modules/credential_policy.js +62 -153
- package/dist/modules/credential_policy.js.map +1 -1
- package/dist/modules/credential_runtime.d.ts +1 -1
- package/dist/modules/credential_runtime.d.ts.map +1 -1
- package/dist/modules/credential_runtime.js +34 -41
- package/dist/modules/credential_runtime.js.map +1 -1
- package/dist/modules/credential_session_cache.d.ts +1 -1
- package/dist/modules/credential_session_cache.d.ts.map +1 -1
- package/dist/modules/credential_session_cache.js +5 -42
- package/dist/modules/credential_session_cache.js.map +1 -1
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +126 -162
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/crypto/browser_provider.d.ts +1 -1
- package/dist/modules/crypto/browser_provider.d.ts.map +1 -1
- package/dist/modules/crypto/browser_provider.js +7 -11
- package/dist/modules/crypto/browser_provider.js.map +1 -1
- package/dist/modules/crypto/index.d.ts +6 -6
- package/dist/modules/crypto/index.d.ts.map +1 -1
- package/dist/modules/crypto/index.js +12 -30
- package/dist/modules/crypto/index.js.map +1 -1
- package/dist/modules/crypto/node_provider.d.ts +1 -1
- package/dist/modules/crypto/node_provider.d.ts.map +1 -1
- package/dist/modules/crypto/node_provider.js +3 -5
- package/dist/modules/crypto/node_provider.js.map +1 -1
- package/dist/modules/crypto/provider.js +1 -2
- package/dist/modules/crypto/pure_ripemd160.js +1 -3
- package/dist/modules/crypto/pure_ripemd160.js.map +1 -1
- package/dist/modules/crypto/pure_scrypt.js +1 -4
- package/dist/modules/crypto/pure_scrypt.js.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts +1 -1
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -1
- package/dist/modules/crypto/pure_secp256k1.js +1 -16
- package/dist/modules/crypto/pure_secp256k1.js.map +1 -1
- package/dist/modules/crypto/sync.d.ts.map +1 -1
- package/dist/modules/crypto/sync.js +16 -17
- package/dist/modules/crypto/sync.js.map +1 -1
- package/dist/modules/daemon_node_health.js +14 -16
- package/dist/modules/daemon_node_health.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +19 -14
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +127 -164
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +28 -27
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +55 -45
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_credential_client.d.ts +6 -2
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -1
- package/dist/modules/dexbot_credential_client.js +21 -31
- package/dist/modules/dexbot_credential_client.js.map +1 -1
- package/dist/modules/dexbot_fill_runtime.d.ts +23 -23
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_fill_runtime.js +119 -77
- package/dist/modules/dexbot_fill_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +46 -38
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +81 -81
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts +3 -3
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_startup_runtime.js +43 -81
- package/dist/modules/dexbot_startup_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts +11 -11
- package/dist/modules/dexbot_state_recovery.js +32 -78
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/env.js +3 -7
- package/dist/modules/env.js.map +1 -1
- package/dist/modules/fund_registry.d.ts.map +1 -1
- package/dist/modules/fund_registry.js +12 -24
- package/dist/modules/fund_registry.js.map +1 -1
- package/dist/modules/general_settings.js +10 -16
- package/dist/modules/general_settings.js.map +1 -1
- package/dist/modules/graceful_shutdown.d.ts.map +1 -1
- package/dist/modules/graceful_shutdown.js +12 -19
- package/dist/modules/graceful_shutdown.js.map +1 -1
- package/dist/modules/key_store.d.ts.map +1 -1
- package/dist/modules/key_store.js +27 -65
- package/dist/modules/key_store.js.map +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts +1 -1
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +89 -118
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/child_env.js +1 -5
- package/dist/modules/launcher/child_env.js.map +1 -1
- package/dist/modules/launcher/credential_bootstrap.js +22 -31
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -1
- package/dist/modules/launcher/credential_daemon.js +37 -75
- package/dist/modules/launcher/credential_daemon.js.map +1 -1
- package/dist/modules/launcher/credential_secret.js +2 -37
- package/dist/modules/launcher/credential_secret.js.map +1 -1
- package/dist/modules/launcher/foreign_cred_daemon.js +25 -31
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
- package/dist/modules/launcher/headless_password.js +10 -12
- package/dist/modules/launcher/headless_password.js.map +1 -1
- package/dist/modules/launcher/launch_modes.js +3 -9
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts +1 -1
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_runtime.js +25 -35
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -1
- package/dist/modules/launcher/market_adapter_watchdog.js +42 -45
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +67 -138
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/runtime_entry.d.ts +1 -11
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -1
- package/dist/modules/launcher/runtime_entry.js +12 -15
- package/dist/modules/launcher/runtime_entry.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +1 -1
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +15 -36
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/launcher/supervisor_control.js +4 -9
- package/dist/modules/launcher/supervisor_control.js.map +1 -1
- package/dist/modules/logger.d.ts +1 -1
- package/dist/modules/logger.d.ts.map +1 -1
- package/dist/modules/logger.js +3 -38
- package/dist/modules/logger.js.map +1 -1
- package/dist/modules/market_adapter_whitelist.js +9 -18
- package/dist/modules/market_adapter_whitelist.js.map +1 -1
- package/dist/modules/node_failure_ledger.js +1 -3
- package/dist/modules/node_failure_ledger.js.map +1 -1
- package/dist/modules/node_health_cache.d.ts.map +1 -1
- package/dist/modules/node_health_cache.js +15 -25
- package/dist/modules/node_health_cache.js.map +1 -1
- package/dist/modules/node_manager.d.ts +1 -1
- package/dist/modules/node_manager.d.ts.map +1 -1
- package/dist/modules/node_manager.js +44 -43
- package/dist/modules/node_manager.js.map +1 -1
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +102 -118
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/async_lock.d.ts +3 -15
- package/dist/modules/order/async_lock.d.ts.map +1 -1
- package/dist/modules/order/async_lock.js +6 -26
- package/dist/modules/order/async_lock.js.map +1 -1
- package/dist/modules/order/export.js +34 -75
- package/dist/modules/order/export.js.map +1 -1
- package/dist/modules/order/format.d.ts +1 -3
- package/dist/modules/order/format.d.ts.map +1 -1
- package/dist/modules/order/format.js +4 -24
- package/dist/modules/order/format.js.map +1 -1
- package/dist/modules/order/grid.d.ts +3 -3
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +206 -262
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile.js +77 -94
- package/dist/modules/order/grid_reconcile.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +117 -149
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/index.d.ts.map +1 -1
- package/dist/modules/order/index.js +11 -45
- package/dist/modules/order/index.js.map +1 -1
- package/dist/modules/order/logger.js +28 -69
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/logger_state.d.ts.map +1 -1
- package/dist/modules/order/logger_state.js +3 -4
- package/dist/modules/order/logger_state.js.map +1 -1
- package/dist/modules/order/manager.d.ts +10 -0
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +131 -151
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/processed_fill_store.js +2 -7
- package/dist/modules/order/processed_fill_store.js.map +1 -1
- package/dist/modules/order/strategy.js +23 -25
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts +27 -0
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +232 -181
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +1 -25
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +49 -172
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +46 -2
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +165 -143
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +3 -1
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +152 -211
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/timeout.js +1 -4
- package/dist/modules/order/utils/timeout.js.map +1 -1
- package/dist/modules/order/utils/validate.js +91 -142
- package/dist/modules/order/utils/validate.js.map +1 -1
- package/dist/modules/order/utils/withPoolRef.js +21 -61
- package/dist/modules/order/utils/withPoolRef.js.map +1 -1
- package/dist/modules/order/working_grid.js +6 -9
- package/dist/modules/order/working_grid.js.map +1 -1
- package/dist/modules/path_api.d.ts.map +1 -1
- package/dist/modules/path_api.js +8 -11
- package/dist/modules/path_api.js.map +1 -1
- package/dist/modules/paths.d.ts.map +1 -1
- package/dist/modules/paths.js +61 -67
- package/dist/modules/paths.js.map +1 -1
- package/dist/modules/process_discovery.js +13 -21
- package/dist/modules/process_discovery.js.map +1 -1
- package/dist/modules/runtime.js +7 -11
- package/dist/modules/runtime.js.map +1 -1
- package/dist/modules/runtime_settings.d.ts.map +1 -1
- package/dist/modules/runtime_settings.js +14 -16
- package/dist/modules/runtime_settings.js.map +1 -1
- package/dist/modules/settings_merge.js +1 -3
- package/dist/modules/settings_merge.js.map +1 -1
- package/dist/modules/socket_json_client.js +3 -5
- package/dist/modules/socket_json_client.js.map +1 -1
- package/dist/modules/storage/browser_adapter.js +1 -4
- package/dist/modules/storage/browser_adapter.js.map +1 -1
- package/dist/modules/storage/index.d.ts +3 -2
- package/dist/modules/storage/index.d.ts.map +1 -1
- package/dist/modules/storage/index.js +5 -8
- package/dist/modules/storage/index.js.map +1 -1
- package/dist/modules/storage/node_adapter.d.ts +3 -4
- package/dist/modules/storage/node_adapter.d.ts.map +1 -1
- package/dist/modules/storage/node_adapter.js +12 -16
- package/dist/modules/storage/node_adapter.js.map +1 -1
- package/dist/modules/storage/types.js +1 -2
- package/dist/modules/types.d.ts +0 -6
- package/dist/modules/types.d.ts.map +1 -1
- package/dist/modules/types.js +1 -2
- package/dist/modules/types.js.map +1 -1
- package/dist/modules/utils/base58check.js +8 -15
- package/dist/modules/utils/base58check.js.map +1 -1
- package/dist/modules/utils/build_dir.js +3 -7
- package/dist/modules/utils/build_dir.js.map +1 -1
- package/dist/modules/utils/errors.js +1 -5
- package/dist/modules/utils/errors.js.map +1 -1
- package/dist/modules/utils/math_utils.d.ts +1 -1
- package/dist/modules/utils/math_utils.d.ts.map +1 -1
- package/dist/modules/utils/math_utils.js +2 -7
- package/dist/modules/utils/math_utils.js.map +1 -1
- package/dist/modules/validate_profiles.d.ts.map +1 -1
- package/dist/modules/validate_profiles.js +18 -25
- package/dist/modules/validate_profiles.js.map +1 -1
- package/dist/pm2.d.ts +4 -70
- package/dist/pm2.d.ts.map +1 -1
- package/dist/pm2.js +106 -132
- package/dist/pm2.js.map +1 -1
- package/dist/scripts/analyze-git.js +13 -17
- package/dist/scripts/analyze-git.js.map +1 -1
- package/dist/scripts/analyze-orders.d.ts.map +1 -1
- package/dist/scripts/analyze-orders.js +48 -63
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -1
- package/dist/scripts/diagnose-kibana-candles.js +2 -1
- package/dist/scripts/diagnose-kibana-candles.js.map +1 -1
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -1
- package/dist/scripts/diagnose-pool-history.js +2 -1
- package/dist/scripts/diagnose-pool-history.js.map +1 -1
- package/dist/scripts/divergence-calc.d.ts.map +1 -1
- package/dist/scripts/divergence-calc.js +2 -2
- package/dist/scripts/divergence-calc.js.map +1 -1
- package/dist/scripts/fix-err-message.js +17 -22
- package/dist/scripts/fix-err-message.js.map +1 -1
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -1
- package/dist/scripts/generate_lp_chart.js +7 -15
- package/dist/scripts/generate_lp_chart.js.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -1
- package/dist/scripts/generate_mainnet_corpus_report.js +3 -2
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -1
- package/dist/scripts/generate_market_adapter_whitelist.js +18 -24
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -1
- package/dist/scripts/native_release_gates.js +15 -19
- package/dist/scripts/native_release_gates.js.map +1 -1
- package/dist/scripts/print_grid.d.ts.map +1 -1
- package/dist/scripts/print_grid.js +2 -2
- package/dist/scripts/print_grid.js.map +1 -1
- package/dist/scripts/run-tests.js +12 -17
- package/dist/scripts/run-tests.js.map +1 -1
- package/dist/scripts/runner.d.ts.map +1 -1
- package/dist/scripts/runner.js +18 -20
- package/dist/scripts/runner.js.map +1 -1
- package/dist/scripts/sync-version.js +2 -2
- package/dist/scripts/sync-version.js.map +1 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
- package/dist/scripts/test-credit-renewal.js +4 -3
- package/dist/scripts/test-credit-renewal.js.map +1 -1
- package/dist/scripts/update.js +77 -89
- package/dist/scripts/update.js.map +1 -1
- package/dist/scripts/validate_bots.d.ts.map +1 -1
- package/dist/scripts/validate_bots.js +2 -2
- package/dist/scripts/validate_bots.js.map +1 -1
- package/dist/scripts/verify-browser-bundle.js +12 -17
- package/dist/scripts/verify-browser-bundle.js.map +1 -1
- package/dist/unlock.d.ts +0 -30
- package/dist/unlock.d.ts.map +1 -1
- package/dist/unlock.js +95 -143
- package/dist/unlock.js.map +1 -1
- package/package.json +5 -8
- package/scripts/README.md +1 -1
- package/scripts/create-bot-symlinks.sh +2 -2
- package/dist/modules/utils/fs_utils.d.ts +0 -18
- package/dist/modules/utils/fs_utils.d.ts.map +0 -1
- package/dist/modules/utils/fs_utils.js +0 -32
- package/dist/modules/utils/fs_utils.js.map +0 -1
- package/dist/scripts/migrate_bot_keys.d.ts +0 -3
- package/dist/scripts/migrate_bot_keys.d.ts.map +0 -1
- package/dist/scripts/migrate_bot_keys.js +0 -225
- package/dist/scripts/migrate_bot_keys.js.map +0 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* modules/order/utils/system.ts - System and I/O Utilities
|
|
4
3
|
*
|
|
@@ -47,84 +46,26 @@
|
|
|
47
46
|
*
|
|
48
47
|
* ===============================================================================
|
|
49
48
|
*/
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
67
|
-
var ownKeys = function(o) {
|
|
68
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
69
|
-
var ar = [];
|
|
70
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
71
|
-
return ar;
|
|
72
|
-
};
|
|
73
|
-
return ownKeys(o);
|
|
74
|
-
};
|
|
75
|
-
return function (mod) {
|
|
76
|
-
if (mod && mod.__esModule) return mod;
|
|
77
|
-
var result = {};
|
|
78
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
79
|
-
__setModuleDefault(result, mod);
|
|
80
|
-
return result;
|
|
81
|
-
};
|
|
82
|
-
})();
|
|
83
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
84
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
85
|
-
};
|
|
86
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
87
|
-
exports.ensureDir = exports.derivePrice = exports.derivePoolPrice = exports.deriveMarketPrice = exports.lookupAsset = void 0;
|
|
88
|
-
exports.resolveLiquidityPoolByShareAsset = resolveLiquidityPoolByShareAsset;
|
|
89
|
-
exports.deriveLiquidityPoolTokenValue = deriveLiquidityPoolTokenValue;
|
|
90
|
-
exports.loadAmaCenterSnapshot = loadAmaCenterSnapshot;
|
|
91
|
-
exports.loadAmaCenterPrice = loadAmaCenterPrice;
|
|
92
|
-
exports._loadFeeCacheFromDisk = _loadFeeCacheFromDisk;
|
|
93
|
-
exports._saveFeeCacheToDisk = _saveFeeCacheToDisk;
|
|
94
|
-
exports.initializeFeeCache = initializeFeeCache;
|
|
95
|
-
exports.persistGridSnapshot = persistGridSnapshot;
|
|
96
|
-
exports.retryPersistenceIfNeeded = retryPersistenceIfNeeded;
|
|
97
|
-
exports.applyGridDivergenceCorrections = applyGridDivergenceCorrections;
|
|
98
|
-
exports.syncBoundaryToFunds = syncBoundaryToFunds;
|
|
99
|
-
exports.ensureProfilesDirectory = ensureProfilesDirectory;
|
|
100
|
-
exports.sleep = sleep;
|
|
101
|
-
exports.readInput = readInput;
|
|
102
|
-
exports.readPassword = readPassword;
|
|
103
|
-
exports.withRetry = withRetry;
|
|
104
|
-
exports.withBlockchainRetry = withBlockchainRetry;
|
|
105
|
-
exports.resolveAccountRef = resolveAccountRef;
|
|
106
|
-
exports.deepFreeze = deepFreeze;
|
|
107
|
-
exports.cloneMap = cloneMap;
|
|
108
|
-
exports.parseJsonWithComments = parseJsonWithComments;
|
|
109
|
-
const path_api_1 = require("../../path_api");
|
|
110
|
-
const storage_1 = require("../../storage");
|
|
111
|
-
const storage = (0, storage_1.getStorage)();
|
|
112
|
-
const constants_1 = require("../../constants");
|
|
113
|
-
const paths_1 = require("../../paths");
|
|
114
|
-
const format_1 = require("../format");
|
|
115
|
-
const MathUtils = __importStar(require("./math"));
|
|
116
|
-
const OrderUtils = __importStar(require("./order"));
|
|
117
|
-
const logger_1 = __importDefault(require("../../logger"));
|
|
118
|
-
const runtime_1 = require("../../runtime");
|
|
119
|
-
const fs_utils_1 = require("../../utils/fs_utils");
|
|
120
|
-
Object.defineProperty(exports, "ensureDir", { enumerable: true, get: function () { return fs_utils_1.ensureDir; } });
|
|
121
|
-
const errors_1 = require("../../utils/errors");
|
|
122
|
-
const timeout_1 = require("./timeout");
|
|
123
|
-
const systemLogger = new logger_1.default('System');
|
|
49
|
+
import { createRequire } from 'node:module';
|
|
50
|
+
const require = createRequire(import.meta.url);
|
|
51
|
+
import { path } from '../../path_api.js';
|
|
52
|
+
import { getStorage } from '../../storage/index.js';
|
|
53
|
+
const storage = getStorage();
|
|
54
|
+
import { API_LIMITS, ORDER_TYPES, COW_ACTIONS, FEE_PARAMETERS, BTS_PRECISION, PIPELINE_TIMING, NATIVE_CLIENT } from '../../constants.js';
|
|
55
|
+
import { PATHS } from '../../paths.js';
|
|
56
|
+
import { toFiniteNumber, isValidNumber } from '../format.js';
|
|
57
|
+
import * as MathUtils from './math.js';
|
|
58
|
+
import * as OrderUtils from './order.js';
|
|
59
|
+
import Logger from '../../logger.js';
|
|
60
|
+
import { runtime } from '../../runtime.js';
|
|
61
|
+
import { getErrorMessage } from '../../utils/errors.js';
|
|
62
|
+
import { withTimeout } from './timeout.js';
|
|
63
|
+
const { ensureDir, readJSON } = storage;
|
|
64
|
+
const systemLogger = new Logger('System');
|
|
124
65
|
function _debugLogAndNull(method, symA, symB) {
|
|
125
66
|
return (err) => {
|
|
126
67
|
// debug level: underlying derivePoolPrice/deriveMarketPrice already log at warn
|
|
127
|
-
systemLogger.debug(`derivePrice(${method}) for ${symA}/${symB}: ${
|
|
68
|
+
systemLogger.debug(`derivePrice(${method}) for ${symA}/${symB}: ${getErrorMessage(err)}`);
|
|
128
69
|
return null;
|
|
129
70
|
};
|
|
130
71
|
}
|
|
@@ -141,7 +82,7 @@ const poolIdCache = new Map();
|
|
|
141
82
|
* @returns {Promise<Object>} Asset metadata with id, symbol, precision
|
|
142
83
|
* @throws {Error} If asset cannot be found on blockchain
|
|
143
84
|
*/
|
|
144
|
-
const lookupAsset = async (BitShares, s) => {
|
|
85
|
+
export const lookupAsset = async (BitShares, s) => {
|
|
145
86
|
if (!BitShares)
|
|
146
87
|
return null;
|
|
147
88
|
let cached = null;
|
|
@@ -170,12 +111,11 @@ const lookupAsset = async (BitShares, s) => {
|
|
|
170
111
|
}
|
|
171
112
|
}
|
|
172
113
|
catch (e) {
|
|
173
|
-
systemLogger.debug(`lookupAsset: method failed for ${s}: ${
|
|
114
|
+
systemLogger.debug(`lookupAsset: method failed for ${s}: ${getErrorMessage(e)}`);
|
|
174
115
|
}
|
|
175
116
|
}
|
|
176
117
|
throw new Error(`CRITICAL: Cannot fetch asset precision for '${s}'`);
|
|
177
118
|
};
|
|
178
|
-
exports.lookupAsset = lookupAsset;
|
|
179
119
|
/**
|
|
180
120
|
* Derive price from BitShares DEX order book.
|
|
181
121
|
* Returns price in B/A format (units of asset B per 1 unit of asset A).
|
|
@@ -186,11 +126,11 @@ exports.lookupAsset = lookupAsset;
|
|
|
186
126
|
* @param {string} symB - Second asset symbol
|
|
187
127
|
* @returns {Promise<number|null>} Derived market price or null if unavailable
|
|
188
128
|
*/
|
|
189
|
-
const deriveMarketPrice = async (BitShares, symA, symB) => {
|
|
129
|
+
export const deriveMarketPrice = async (BitShares, symA, symB) => {
|
|
190
130
|
try {
|
|
191
131
|
const [aMeta, bMeta] = await Promise.all([
|
|
192
|
-
|
|
193
|
-
|
|
132
|
+
lookupAsset(BitShares, symA),
|
|
133
|
+
lookupAsset(BitShares, symB)
|
|
194
134
|
]);
|
|
195
135
|
if (!aMeta?.id || !bMeta?.id)
|
|
196
136
|
return null;
|
|
@@ -199,23 +139,23 @@ const deriveMarketPrice = async (BitShares, symA, symB) => {
|
|
|
199
139
|
let mid = null;
|
|
200
140
|
if (typeof BitShares.db?.get_order_book === 'function') {
|
|
201
141
|
try {
|
|
202
|
-
const ob = await BitShares.db.get_order_book(baseId, quoteId,
|
|
203
|
-
const bestBid =
|
|
204
|
-
const bestAsk =
|
|
142
|
+
const ob = await BitShares.db.get_order_book(baseId, quoteId, API_LIMITS.ORDERBOOK_DEPTH);
|
|
143
|
+
const bestBid = isValidNumber(ob.bids?.[0]?.price) ? toFiniteNumber(ob.bids[0].price) : null;
|
|
144
|
+
const bestAsk = isValidNumber(ob.asks?.[0]?.price) ? toFiniteNumber(ob.asks[0].price) : null;
|
|
205
145
|
if (bestBid !== null && bestAsk !== null)
|
|
206
146
|
mid = (bestBid + bestAsk) / 2;
|
|
207
147
|
}
|
|
208
148
|
catch (e) {
|
|
209
|
-
systemLogger.debug(`deriveMarketPrice: get_order_book failed for ${symA}/${symB}: ${
|
|
149
|
+
systemLogger.debug(`deriveMarketPrice: get_order_book failed for ${symA}/${symB}: ${getErrorMessage(e)}`);
|
|
210
150
|
}
|
|
211
151
|
}
|
|
212
152
|
if (mid === null && typeof BitShares.db?.get_ticker === 'function') {
|
|
213
153
|
try {
|
|
214
154
|
const t = await BitShares.db.get_ticker(baseId, quoteId);
|
|
215
|
-
mid =
|
|
155
|
+
mid = isValidNumber(t?.latest) ? toFiniteNumber(t.latest) : (isValidNumber(t?.latest_price) ? toFiniteNumber(t.latest_price) : null);
|
|
216
156
|
}
|
|
217
157
|
catch (err) {
|
|
218
|
-
systemLogger.debug(`deriveMarketPrice: get_ticker failed for ${symA}/${symB}: ${
|
|
158
|
+
systemLogger.debug(`deriveMarketPrice: get_ticker failed for ${symA}/${symB}: ${getErrorMessage(err)}`);
|
|
219
159
|
}
|
|
220
160
|
}
|
|
221
161
|
// Return B/A orientation to match market price format
|
|
@@ -226,11 +166,10 @@ const deriveMarketPrice = async (BitShares, symA, symB) => {
|
|
|
226
166
|
return finalPrice;
|
|
227
167
|
}
|
|
228
168
|
catch (err) {
|
|
229
|
-
systemLogger.warn(`deriveMarketPrice failed for ${symA}/${symB}: ${
|
|
169
|
+
systemLogger.warn(`deriveMarketPrice failed for ${symA}/${symB}: ${getErrorMessage(err)}`);
|
|
230
170
|
return null;
|
|
231
171
|
}
|
|
232
172
|
};
|
|
233
|
-
exports.deriveMarketPrice = deriveMarketPrice;
|
|
234
173
|
/**
|
|
235
174
|
* Derive price from BitShares Liquidity Pool (AMM).
|
|
236
175
|
* Returns price in B/A format (units of asset B per 1 unit of asset A).
|
|
@@ -241,11 +180,11 @@ exports.deriveMarketPrice = deriveMarketPrice;
|
|
|
241
180
|
* @param {string} symB - Second asset symbol
|
|
242
181
|
* @returns {Promise<number|null>} Derived pool price or null if unavailable
|
|
243
182
|
*/
|
|
244
|
-
const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
183
|
+
export const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
245
184
|
try {
|
|
246
185
|
const [aMeta, bMeta] = await Promise.all([
|
|
247
|
-
|
|
248
|
-
|
|
186
|
+
lookupAsset(BitShares, symA),
|
|
187
|
+
lookupAsset(BitShares, symB)
|
|
249
188
|
]);
|
|
250
189
|
if (!aMeta?.id || !bMeta?.id)
|
|
251
190
|
return null;
|
|
@@ -259,7 +198,7 @@ const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
|
259
198
|
const valid = pools.filter((p) => p?.id);
|
|
260
199
|
if (valid.length) {
|
|
261
200
|
chosen = valid.sort((a, b) => {
|
|
262
|
-
const getBal = (p) =>
|
|
201
|
+
const getBal = (p) => toFiniteNumber(String(p.asset_a) === String(aMeta.id) ? p.balance_a : p.balance_b);
|
|
263
202
|
return getBal(b) - getBal(a);
|
|
264
203
|
})[0];
|
|
265
204
|
if (chosen)
|
|
@@ -268,7 +207,7 @@ const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
|
268
207
|
}
|
|
269
208
|
}
|
|
270
209
|
catch (e) {
|
|
271
|
-
systemLogger.debug(`derivePoolPrice: get_liquidity_pools_by_both_assets failed: ${
|
|
210
|
+
systemLogger.debug(`derivePoolPrice: get_liquidity_pools_by_both_assets failed: ${getErrorMessage(e)}`);
|
|
272
211
|
}
|
|
273
212
|
}
|
|
274
213
|
if (!chosen && cachedPoolId && typeof BitShares.db?.get_objects === 'function') {
|
|
@@ -286,10 +225,13 @@ const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
|
286
225
|
if (typeof listFn === 'function') {
|
|
287
226
|
try {
|
|
288
227
|
let startId = '1.19.0';
|
|
289
|
-
const
|
|
228
|
+
const pageSize = API_LIMITS.POOL_BATCH_SIZE;
|
|
290
229
|
const allMatches = [];
|
|
230
|
+
let scannedBatches = 0;
|
|
291
231
|
while (true) {
|
|
292
|
-
|
|
232
|
+
if (scannedBatches++ >= API_LIMITS.MAX_POOL_SCAN_BATCHES)
|
|
233
|
+
break;
|
|
234
|
+
const pools = await listFn(pageSize, startId);
|
|
293
235
|
if (!pools || pools.length === 0)
|
|
294
236
|
break;
|
|
295
237
|
// BitShares list_liquidity_pools is inclusive of startId.
|
|
@@ -304,7 +246,7 @@ const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
|
304
246
|
if (matches.length) {
|
|
305
247
|
allMatches.push(...matches);
|
|
306
248
|
}
|
|
307
|
-
if (pools.length <
|
|
249
|
+
if (pools.length < pageSize) {
|
|
308
250
|
break;
|
|
309
251
|
}
|
|
310
252
|
else {
|
|
@@ -314,44 +256,44 @@ const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
|
314
256
|
if (allMatches.length) {
|
|
315
257
|
// Select pool with highest balance for our assetA
|
|
316
258
|
chosen = allMatches.sort((a, b) => {
|
|
317
|
-
const getBal = (p) =>
|
|
259
|
+
const getBal = (p) => toFiniteNumber(String(p.asset_a) === String(aMeta.id) ? p.balance_a : p.balance_b);
|
|
318
260
|
return getBal(b) - getBal(a);
|
|
319
261
|
})[0];
|
|
320
262
|
poolIdCache.set(cacheKey, chosen.id);
|
|
321
263
|
}
|
|
322
264
|
}
|
|
323
265
|
catch (e) {
|
|
324
|
-
systemLogger.warn(`derivePoolPrice: pool pagination failed: ${
|
|
266
|
+
systemLogger.warn(`derivePoolPrice: pool pagination failed: ${getErrorMessage(e) || e}`);
|
|
325
267
|
}
|
|
326
268
|
}
|
|
327
269
|
}
|
|
328
270
|
if (!chosen)
|
|
329
271
|
return null;
|
|
330
|
-
if (!chosen.reserves && !
|
|
272
|
+
if (!chosen.reserves && !isValidNumber(chosen.balance_a) && typeof BitShares.db?.get_objects === 'function') {
|
|
331
273
|
try {
|
|
332
274
|
const [full] = await BitShares.db.get_objects([chosen.id]);
|
|
333
275
|
if (full)
|
|
334
276
|
chosen = full;
|
|
335
277
|
}
|
|
336
278
|
catch (e) {
|
|
337
|
-
systemLogger.debug(`derivePoolPrice: get_objects failed for pool ${chosen.id}: ${
|
|
279
|
+
systemLogger.debug(`derivePoolPrice: get_objects failed for pool ${chosen.id}: ${getErrorMessage(e)}`);
|
|
338
280
|
}
|
|
339
281
|
}
|
|
340
282
|
let amtA = null, amtB = null;
|
|
341
|
-
if (
|
|
283
|
+
if (isValidNumber(chosen.balance_a) && isValidNumber(chosen.balance_b)) {
|
|
342
284
|
// Pools store assets ordered by ID: lower ID is always first (asset_a)
|
|
343
|
-
const aIdNum =
|
|
344
|
-
const bIdNum =
|
|
285
|
+
const aIdNum = toFiniteNumber(String(aMeta.id).split('.')[2]);
|
|
286
|
+
const bIdNum = toFiniteNumber(String(bMeta.id).split('.')[2]);
|
|
345
287
|
const aIsFirst = aIdNum < bIdNum;
|
|
346
288
|
// If config's assetA has lower ID, it's the pool's first asset (asset_a)
|
|
347
289
|
// Otherwise, our assetA corresponds to pool's second asset (asset_b)
|
|
348
290
|
if (aIsFirst) {
|
|
349
|
-
amtA =
|
|
350
|
-
amtB =
|
|
291
|
+
amtA = toFiniteNumber(chosen.balance_a);
|
|
292
|
+
amtB = toFiniteNumber(chosen.balance_b);
|
|
351
293
|
}
|
|
352
294
|
else {
|
|
353
|
-
amtA =
|
|
354
|
-
amtB =
|
|
295
|
+
amtA = toFiniteNumber(chosen.balance_b);
|
|
296
|
+
amtB = toFiniteNumber(chosen.balance_a);
|
|
355
297
|
}
|
|
356
298
|
}
|
|
357
299
|
else if (Array.isArray(chosen.reserves)) {
|
|
@@ -362,7 +304,7 @@ const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
|
362
304
|
amtB = resB.amount;
|
|
363
305
|
}
|
|
364
306
|
}
|
|
365
|
-
if (!
|
|
307
|
+
if (!isValidNumber(amtA) || !isValidNumber(amtB) || toFiniteNumber(amtB) === 0)
|
|
366
308
|
return null;
|
|
367
309
|
const floatA = MathUtils.blockchainToFloat(amtA, aMeta.precision);
|
|
368
310
|
const floatB = MathUtils.blockchainToFloat(amtB, bMeta.precision);
|
|
@@ -374,11 +316,10 @@ const derivePoolPrice = async (BitShares, symA, symB) => {
|
|
|
374
316
|
return finalPrice;
|
|
375
317
|
}
|
|
376
318
|
catch (err) {
|
|
377
|
-
systemLogger.warn(`derivePoolPrice failed for ${symA}/${symB}: ${
|
|
319
|
+
systemLogger.warn(`derivePoolPrice failed for ${symA}/${symB}: ${getErrorMessage(err)}`);
|
|
378
320
|
return null;
|
|
379
321
|
}
|
|
380
322
|
};
|
|
381
|
-
exports.derivePoolPrice = derivePoolPrice;
|
|
382
323
|
/**
|
|
383
324
|
* Derive price from blockchain using specified mode.
|
|
384
325
|
* Attempts pool or market derivation based on mode, with fallback chain.
|
|
@@ -389,7 +330,7 @@ exports.derivePoolPrice = derivePoolPrice;
|
|
|
389
330
|
* @param {string} [mode='auto'] - Derivation mode: "pool", "book", or "auto" (pool → book).
|
|
390
331
|
* @returns {Promise<number|null>} Derived price or null if all methods fail
|
|
391
332
|
*/
|
|
392
|
-
const derivePrice = async (BitShares, symA, symB, mode = 'auto') => {
|
|
333
|
+
export const derivePrice = async (BitShares, symA, symB, mode = 'auto') => {
|
|
393
334
|
mode = String(mode).toLowerCase();
|
|
394
335
|
const validModes = new Set(['pool', 'book', 'auto']);
|
|
395
336
|
if (!validModes.has(mode)) {
|
|
@@ -397,23 +338,22 @@ const derivePrice = async (BitShares, symA, symB, mode = 'auto') => {
|
|
|
397
338
|
return null;
|
|
398
339
|
}
|
|
399
340
|
if (mode === 'pool') {
|
|
400
|
-
return await
|
|
341
|
+
return await derivePoolPrice(BitShares, symA, symB).catch(_debugLogAndNull('pool', symA, symB));
|
|
401
342
|
}
|
|
402
343
|
if (mode === 'book') {
|
|
403
|
-
return await
|
|
344
|
+
return await deriveMarketPrice(BitShares, symA, symB).catch(_debugLogAndNull('book', symA, symB));
|
|
404
345
|
}
|
|
405
346
|
// mode === 'auto': pool preferred, market fallback
|
|
406
347
|
let poolP = null;
|
|
407
|
-
poolP = await
|
|
348
|
+
poolP = await derivePoolPrice(BitShares, symA, symB).catch(_debugLogAndNull('auto/pool', symA, symB));
|
|
408
349
|
if (poolP != null && poolP > 0)
|
|
409
350
|
return poolP;
|
|
410
|
-
const m = await
|
|
351
|
+
const m = await deriveMarketPrice(BitShares, symA, symB).catch(_debugLogAndNull('auto/book', symA, symB));
|
|
411
352
|
if (m != null && m > 0)
|
|
412
353
|
return m;
|
|
413
354
|
systemLogger.debug(`derivePrice: all methods failed for ${symA}/${symB}`);
|
|
414
355
|
return null;
|
|
415
356
|
};
|
|
416
|
-
exports.derivePrice = derivePrice;
|
|
417
357
|
/**
|
|
418
358
|
* Resolve a liquidity pool from a share asset reference.
|
|
419
359
|
* Looks up the share asset, then queries the blockchain for associated pools.
|
|
@@ -422,19 +362,19 @@ exports.derivePrice = derivePrice;
|
|
|
422
362
|
* @param {string} shareAssetRef - Share asset symbol or reference
|
|
423
363
|
* @returns {Promise<Object|null>} Object with {shareAsset, pool} or null if not found
|
|
424
364
|
*/
|
|
425
|
-
async function resolveLiquidityPoolByShareAsset(BitShares, shareAssetRef) {
|
|
365
|
+
export async function resolveLiquidityPoolByShareAsset(BitShares, shareAssetRef) {
|
|
426
366
|
if (!BitShares?.db || typeof BitShares.db.get_liquidity_pools_by_share_asset !== 'function') {
|
|
427
367
|
return null;
|
|
428
368
|
}
|
|
429
|
-
const shareAsset = await
|
|
430
|
-
systemLogger.debug(`resolveLiquidityPoolByShareAsset: lookupAsset failed for ${shareAssetRef}: ${
|
|
369
|
+
const shareAsset = await lookupAsset(BitShares, shareAssetRef).catch((e) => {
|
|
370
|
+
systemLogger.debug(`resolveLiquidityPoolByShareAsset: lookupAsset failed for ${shareAssetRef}: ${getErrorMessage(e)}`);
|
|
431
371
|
return null;
|
|
432
372
|
});
|
|
433
373
|
if (!shareAsset?.id) {
|
|
434
374
|
return null;
|
|
435
375
|
}
|
|
436
376
|
const response = await BitShares.db.get_liquidity_pools_by_share_asset([shareAsset.id], false, false).catch((e) => {
|
|
437
|
-
systemLogger.debug(`resolveLiquidityPoolByShareAsset: get_liquidity_pools_by_share_asset failed for ${shareAssetRef}: ${
|
|
377
|
+
systemLogger.debug(`resolveLiquidityPoolByShareAsset: get_liquidity_pools_by_share_asset failed for ${shareAssetRef}: ${getErrorMessage(e)}`);
|
|
438
378
|
return null;
|
|
439
379
|
});
|
|
440
380
|
if (!Array.isArray(response)) {
|
|
@@ -452,8 +392,8 @@ async function resolveLiquidityPoolByShareAsset(BitShares, shareAssetRef) {
|
|
|
452
392
|
async function getAssetCurrentSupply(BitShares, assetRef) {
|
|
453
393
|
const asset = typeof assetRef === 'object' && assetRef !== null
|
|
454
394
|
? assetRef
|
|
455
|
-
: await
|
|
456
|
-
systemLogger.debug(`getAssetCurrentSupply: lookupAsset failed for ${assetRef}: ${
|
|
395
|
+
: await lookupAsset(BitShares, assetRef).catch((e) => {
|
|
396
|
+
systemLogger.debug(`getAssetCurrentSupply: lookupAsset failed for ${assetRef}: ${getErrorMessage(e)}`);
|
|
457
397
|
return null;
|
|
458
398
|
});
|
|
459
399
|
if (!asset) {
|
|
@@ -461,7 +401,7 @@ async function getAssetCurrentSupply(BitShares, assetRef) {
|
|
|
461
401
|
}
|
|
462
402
|
const hasDirectSupply = asset.current_supply != null;
|
|
463
403
|
const directSupply = hasDirectSupply
|
|
464
|
-
?
|
|
404
|
+
? toFiniteNumber(asset.current_supply?.amount ?? asset.current_supply, -1)
|
|
465
405
|
: -1;
|
|
466
406
|
if (hasDirectSupply && Number.isFinite(directSupply) && directSupply >= 0) {
|
|
467
407
|
return directSupply;
|
|
@@ -471,11 +411,11 @@ async function getAssetCurrentSupply(BitShares, assetRef) {
|
|
|
471
411
|
return null;
|
|
472
412
|
}
|
|
473
413
|
const objects = await BitShares.db.get_objects([dynamicId]).catch((e) => {
|
|
474
|
-
systemLogger.debug(`getAssetCurrentSupply: get_objects failed for ${dynamicId}: ${
|
|
414
|
+
systemLogger.debug(`getAssetCurrentSupply: get_objects failed for ${dynamicId}: ${getErrorMessage(e)}`);
|
|
475
415
|
return null;
|
|
476
416
|
});
|
|
477
417
|
const dynamicData = Array.isArray(objects) ? objects[0] : null;
|
|
478
|
-
const supply =
|
|
418
|
+
const supply = toFiniteNumber(dynamicData?.current_supply?.amount
|
|
479
419
|
?? dynamicData?.current_supply?.value
|
|
480
420
|
?? dynamicData?.current_supply, undefined);
|
|
481
421
|
return Number.isFinite(supply) && supply >= 0 ? supply : null;
|
|
@@ -491,11 +431,11 @@ async function getAssetCurrentSupply(BitShares, assetRef) {
|
|
|
491
431
|
* @param {string} [mode='auto'] - Price derivation mode ("pool", "book", or "auto")
|
|
492
432
|
* @returns {Promise<number|null>} Value per share in denomination asset, or null
|
|
493
433
|
*/
|
|
494
|
-
async function deriveLiquidityPoolTokenValue(BitShares, shareAssetRef, denominationAssetRef, mode = 'auto') {
|
|
434
|
+
export async function deriveLiquidityPoolTokenValue(BitShares, shareAssetRef, denominationAssetRef, mode = 'auto') {
|
|
495
435
|
try {
|
|
496
436
|
const [shareAsset, denominationAsset] = await Promise.all([
|
|
497
|
-
|
|
498
|
-
|
|
437
|
+
lookupAsset(BitShares, shareAssetRef),
|
|
438
|
+
lookupAsset(BitShares, denominationAssetRef),
|
|
499
439
|
]);
|
|
500
440
|
if (!shareAsset?.id || !denominationAsset?.id) {
|
|
501
441
|
return null;
|
|
@@ -505,8 +445,8 @@ async function deriveLiquidityPoolTokenValue(BitShares, shareAssetRef, denominat
|
|
|
505
445
|
return null;
|
|
506
446
|
}
|
|
507
447
|
const [assetA, assetB, supply] = await Promise.all([
|
|
508
|
-
|
|
509
|
-
|
|
448
|
+
lookupAsset(BitShares, poolInfo.pool.asset_a),
|
|
449
|
+
lookupAsset(BitShares, poolInfo.pool.asset_b),
|
|
510
450
|
getAssetCurrentSupply(BitShares, shareAsset),
|
|
511
451
|
]);
|
|
512
452
|
if (!assetA?.id || !assetB?.id || !Number.isFinite(supply) || supply <= 0) {
|
|
@@ -514,34 +454,34 @@ async function deriveLiquidityPoolTokenValue(BitShares, shareAssetRef, denominat
|
|
|
514
454
|
}
|
|
515
455
|
const reserveA = MathUtils.blockchainToFloat(poolInfo.pool.balance_a, assetA.precision);
|
|
516
456
|
const reserveB = MathUtils.blockchainToFloat(poolInfo.pool.balance_b, assetB.precision);
|
|
517
|
-
if (!
|
|
457
|
+
if (!isValidNumber(reserveA) || !isValidNumber(reserveB)) {
|
|
518
458
|
return null;
|
|
519
459
|
}
|
|
520
460
|
const priceA = String(assetA.id) === String(denominationAsset.id)
|
|
521
461
|
? 1
|
|
522
|
-
: await
|
|
523
|
-
systemLogger.debug(`deriveLiquidityPoolTokenValue: derivePrice failed for ${assetA.id}/${denominationAsset.id}: ${
|
|
462
|
+
: await derivePrice(BitShares, assetA.id, denominationAsset.id, mode).catch((e) => {
|
|
463
|
+
systemLogger.debug(`deriveLiquidityPoolTokenValue: derivePrice failed for ${assetA.id}/${denominationAsset.id}: ${getErrorMessage(e)}`);
|
|
524
464
|
return null;
|
|
525
465
|
});
|
|
526
466
|
const priceB = String(assetB.id) === String(denominationAsset.id)
|
|
527
467
|
? 1
|
|
528
|
-
: await
|
|
529
|
-
systemLogger.debug(`deriveLiquidityPoolTokenValue: derivePrice failed for ${assetB.id}/${denominationAsset.id}: ${
|
|
468
|
+
: await derivePrice(BitShares, assetB.id, denominationAsset.id, mode).catch((e) => {
|
|
469
|
+
systemLogger.debug(`deriveLiquidityPoolTokenValue: derivePrice failed for ${assetB.id}/${denominationAsset.id}: ${getErrorMessage(e)}`);
|
|
530
470
|
return null;
|
|
531
471
|
});
|
|
532
|
-
if (priceA == null || priceB == null || !
|
|
472
|
+
if (priceA == null || priceB == null || !isValidNumber(priceA) || !isValidNumber(priceB) || priceA <= 0 || priceB <= 0) {
|
|
533
473
|
return null;
|
|
534
474
|
}
|
|
535
475
|
const supplyFloat = MathUtils.blockchainToFloat(supply, shareAsset.precision);
|
|
536
|
-
if (!
|
|
476
|
+
if (!isValidNumber(supplyFloat) || supplyFloat <= 0) {
|
|
537
477
|
return null;
|
|
538
478
|
}
|
|
539
479
|
const totalValue = reserveA * priceA + reserveB * priceB;
|
|
540
480
|
const valuePerShare = totalValue / supplyFloat;
|
|
541
|
-
return
|
|
481
|
+
return isValidNumber(valuePerShare) && valuePerShare > 0 ? valuePerShare : null;
|
|
542
482
|
}
|
|
543
483
|
catch (err) {
|
|
544
|
-
systemLogger.debug(`deriveLiquidityPoolTokenValue failed for ${shareAssetRef}/${denominationAssetRef}: ${
|
|
484
|
+
systemLogger.debug(`deriveLiquidityPoolTokenValue failed for ${shareAssetRef}/${denominationAssetRef}: ${getErrorMessage(err)}`);
|
|
545
485
|
return null;
|
|
546
486
|
}
|
|
547
487
|
}
|
|
@@ -560,10 +500,10 @@ async function deriveLiquidityPoolTokenValue(BitShares, shareAssetRef, denominat
|
|
|
560
500
|
* @param {string} botKey - Bot key (e.g. "iob-xrp-bts-0")
|
|
561
501
|
* @returns {Object|null} Snapshot with center and optional dynamicWeights fields, or null if invalid
|
|
562
502
|
*/
|
|
563
|
-
function loadAmaCenterSnapshot(botKey) {
|
|
503
|
+
export function loadAmaCenterSnapshot(botKey) {
|
|
564
504
|
try {
|
|
565
|
-
const gridPriceFile =
|
|
566
|
-
const data =
|
|
505
|
+
const gridPriceFile = path.join(PATHS.ORDERS_DIR, `${botKey}.dynamicgrid.json`);
|
|
506
|
+
const data = readJSON(gridPriceFile);
|
|
567
507
|
const gridCenterPrice = Number(data?.gridCenterPrice ?? data?.centerPrice);
|
|
568
508
|
const amaCenterPrice = Number(data?.amaCenterPrice);
|
|
569
509
|
if (!Number.isFinite(gridCenterPrice) || gridCenterPrice <= 0) {
|
|
@@ -603,7 +543,7 @@ function loadAmaCenterSnapshot(botKey) {
|
|
|
603
543
|
* @param {string} botKey - Bot key (e.g. "iob-xrp-bts-0")
|
|
604
544
|
* @returns {number|null} Grid center price in B/A format, or null if file absent/invalid
|
|
605
545
|
*/
|
|
606
|
-
function loadAmaCenterPrice(botKey) {
|
|
546
|
+
export function loadAmaCenterPrice(botKey) {
|
|
607
547
|
const snapshot = loadAmaCenterSnapshot(botKey);
|
|
608
548
|
return snapshot ? snapshot.gridCenterPrice : null;
|
|
609
549
|
}
|
|
@@ -614,9 +554,9 @@ function loadAmaCenterPrice(botKey) {
|
|
|
614
554
|
* Load previously persisted fee cache from disk.
|
|
615
555
|
* @returns {Record<string, any>} Cached fee data or empty object
|
|
616
556
|
*/
|
|
617
|
-
function _loadFeeCacheFromDisk() {
|
|
557
|
+
export function _loadFeeCacheFromDisk() {
|
|
618
558
|
try {
|
|
619
|
-
const filePath =
|
|
559
|
+
const filePath = PATHS.PROFILES.FEE_CACHE_JSON;
|
|
620
560
|
if (storage.exists(filePath)) {
|
|
621
561
|
const diskCache = storage.readJSON(filePath);
|
|
622
562
|
if (diskCache && typeof diskCache === 'object') {
|
|
@@ -626,7 +566,7 @@ function _loadFeeCacheFromDisk() {
|
|
|
626
566
|
}
|
|
627
567
|
}
|
|
628
568
|
catch (e) {
|
|
629
|
-
systemLogger.debug(`_loadFeeCacheFromDisk: ${
|
|
569
|
+
systemLogger.debug(`_loadFeeCacheFromDisk: ${getErrorMessage(e)}`);
|
|
630
570
|
}
|
|
631
571
|
return {};
|
|
632
572
|
}
|
|
@@ -634,12 +574,12 @@ function _loadFeeCacheFromDisk() {
|
|
|
634
574
|
* Persist fee cache to disk for recovery across restarts.
|
|
635
575
|
* @param {Record<string, any>} cache - Fee cache to persist
|
|
636
576
|
*/
|
|
637
|
-
function _saveFeeCacheToDisk(cache) {
|
|
577
|
+
export function _saveFeeCacheToDisk(cache) {
|
|
638
578
|
try {
|
|
639
|
-
storage.writeJSON(
|
|
579
|
+
storage.writeJSON(PATHS.PROFILES.FEE_CACHE_JSON, cache);
|
|
640
580
|
}
|
|
641
581
|
catch (e) {
|
|
642
|
-
systemLogger.debug(`_saveFeeCacheToDisk: ${
|
|
582
|
+
systemLogger.debug(`_saveFeeCacheToDisk: ${getErrorMessage(e)}`);
|
|
643
583
|
}
|
|
644
584
|
}
|
|
645
585
|
/**
|
|
@@ -652,7 +592,7 @@ function _saveFeeCacheToDisk(cache) {
|
|
|
652
592
|
* @param {Object} BitShares - BitShares client instance
|
|
653
593
|
* @returns {Promise<Object>} Fee cache object keyed by asset symbol
|
|
654
594
|
*/
|
|
655
|
-
async function initializeFeeCache(botsConfig, BitShares) {
|
|
595
|
+
export async function initializeFeeCache(botsConfig, BitShares) {
|
|
656
596
|
const uniqueAssets = new Set(['BTS']);
|
|
657
597
|
for (const bot of botsConfig) {
|
|
658
598
|
if (bot.assetA)
|
|
@@ -662,8 +602,8 @@ async function initializeFeeCache(botsConfig, BitShares) {
|
|
|
662
602
|
}
|
|
663
603
|
// Seed from disk so previously cached assets survive transient API failures
|
|
664
604
|
const cache = _loadFeeCacheFromDisk();
|
|
665
|
-
const maxAttempts =
|
|
666
|
-
const baseDelay =
|
|
605
|
+
const maxAttempts = FEE_PARAMETERS.FEE_CACHE_RETRY_ATTEMPTS;
|
|
606
|
+
const baseDelay = FEE_PARAMETERS.FEE_CACHE_RETRY_DELAY_MS;
|
|
667
607
|
for (const assetSymbol of uniqueAssets) {
|
|
668
608
|
let lastError = null;
|
|
669
609
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
@@ -674,23 +614,23 @@ async function initializeFeeCache(botsConfig, BitShares) {
|
|
|
674
614
|
const findFee = (opCode) => {
|
|
675
615
|
const param = currentFees.find((p) => p[0] === opCode);
|
|
676
616
|
const fee = param?.[1]?.fee;
|
|
677
|
-
const feeNum =
|
|
617
|
+
const feeNum = toFiniteNumber(fee);
|
|
678
618
|
return {
|
|
679
619
|
raw: feeNum,
|
|
680
620
|
satoshis: feeNum,
|
|
681
|
-
bts: MathUtils.blockchainToFloat(feeNum,
|
|
621
|
+
bts: MathUtils.blockchainToFloat(feeNum, BTS_PRECISION)
|
|
682
622
|
};
|
|
683
623
|
};
|
|
684
|
-
const makerFeeDiscountRaw =
|
|
624
|
+
const makerFeeDiscountRaw = toFiniteNumber(globalProps?.parameters?.extensions?.maker_fee_discount_percent, FEE_PARAMETERS.MAKER_REFUND_PERCENT * NATIVE_CLIENT.CHAIN.PERCENT_100);
|
|
685
625
|
cache.BTS = {
|
|
686
|
-
limitOrderCreate: findFee(
|
|
687
|
-
limitOrderCancel: findFee(
|
|
688
|
-
limitOrderUpdate: findFee(
|
|
689
|
-
makerFeeDiscountPercent: Math.max(0, makerFeeDiscountRaw) /
|
|
626
|
+
limitOrderCreate: findFee(NATIVE_CLIENT.OPERATIONS.LIMIT_ORDER_CREATE),
|
|
627
|
+
limitOrderCancel: findFee(NATIVE_CLIENT.OPERATIONS.LIMIT_ORDER_CANCEL),
|
|
628
|
+
limitOrderUpdate: findFee(NATIVE_CLIENT.OPERATIONS.LIMIT_ORDER_UPDATE),
|
|
629
|
+
makerFeeDiscountPercent: Math.max(0, makerFeeDiscountRaw) / NATIVE_CLIENT.CHAIN.PERCENT_100
|
|
690
630
|
};
|
|
691
631
|
}
|
|
692
632
|
else {
|
|
693
|
-
const fullAsset = await
|
|
633
|
+
const fullAsset = await lookupAsset(BitShares, assetSymbol);
|
|
694
634
|
const options = fullAsset.options || {};
|
|
695
635
|
cache[assetSymbol] = {
|
|
696
636
|
assetId: fullAsset.id,
|
|
@@ -712,14 +652,14 @@ async function initializeFeeCache(botsConfig, BitShares) {
|
|
|
712
652
|
lastError = error;
|
|
713
653
|
if (attempt < maxAttempts) {
|
|
714
654
|
const delay = baseDelay * attempt;
|
|
715
|
-
systemLogger.warn(`initializeFeeCache: attempt ${attempt}/${maxAttempts} failed for ${assetSymbol}: ${
|
|
655
|
+
systemLogger.warn(`initializeFeeCache: attempt ${attempt}/${maxAttempts} failed for ${assetSymbol}: ${getErrorMessage(error)}. Retrying in ${delay}ms...`);
|
|
716
656
|
await sleep(delay);
|
|
717
657
|
}
|
|
718
658
|
}
|
|
719
659
|
}
|
|
720
660
|
if (lastError) {
|
|
721
661
|
const hasDiskFallback = cache[assetSymbol] !== undefined;
|
|
722
|
-
systemLogger.warn(`initializeFeeCache: all ${maxAttempts} attempts failed for ${assetSymbol}: ${
|
|
662
|
+
systemLogger.warn(`initializeFeeCache: all ${maxAttempts} attempts failed for ${assetSymbol}: ${getErrorMessage(lastError)}` +
|
|
723
663
|
(hasDiskFallback ? '. Using previously cached value from disk.' : '.'));
|
|
724
664
|
}
|
|
725
665
|
}
|
|
@@ -738,7 +678,7 @@ async function initializeFeeCache(botsConfig, BitShares) {
|
|
|
738
678
|
* @param {Object} accountOrders - AccountOrders data accessor
|
|
739
679
|
* @returns {Promise<boolean>} True if persistence succeeded, false on error
|
|
740
680
|
*/
|
|
741
|
-
async function persistGridSnapshot(manager, accountOrders, snapshotOrders, recentFillKeys, fundSnapshot) {
|
|
681
|
+
export async function persistGridSnapshot(manager, accountOrders, snapshotOrders, recentFillKeys, fundSnapshot) {
|
|
742
682
|
if (!manager || !accountOrders)
|
|
743
683
|
return false;
|
|
744
684
|
try {
|
|
@@ -782,7 +722,7 @@ async function persistGridSnapshot(manager, accountOrders, snapshotOrders, recen
|
|
|
782
722
|
* @param {Object} manager - OrderManager instance
|
|
783
723
|
* @returns {Promise<boolean>} True if persisted successfully or no warning, false on error
|
|
784
724
|
*/
|
|
785
|
-
async function retryPersistenceIfNeeded(manager) {
|
|
725
|
+
export async function retryPersistenceIfNeeded(manager) {
|
|
786
726
|
if (!manager || !manager._persistenceWarning)
|
|
787
727
|
return true;
|
|
788
728
|
try {
|
|
@@ -793,7 +733,7 @@ async function retryPersistenceIfNeeded(manager) {
|
|
|
793
733
|
return success;
|
|
794
734
|
}
|
|
795
735
|
catch (e) {
|
|
796
|
-
systemLogger.warn(`retryPersistenceIfNeeded failed: ${
|
|
736
|
+
systemLogger.warn(`retryPersistenceIfNeeded failed: ${getErrorMessage(e)}`);
|
|
797
737
|
return false;
|
|
798
738
|
}
|
|
799
739
|
}
|
|
@@ -812,7 +752,7 @@ async function retryPersistenceIfNeeded(manager) {
|
|
|
812
752
|
* @param {Function} updateGridFromBlockchainSnapshotFn - Grid resize function (injected to avoid circular dependency with grid.ts)
|
|
813
753
|
* @returns {Promise<void>}
|
|
814
754
|
*/
|
|
815
|
-
async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, updateOrdersOnChainBatchFn, updateGridFromBlockchainSnapshotFn) {
|
|
755
|
+
export async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, updateOrdersOnChainBatchFn, updateGridFromBlockchainSnapshotFn) {
|
|
816
756
|
if (!manager._gridLock)
|
|
817
757
|
return;
|
|
818
758
|
if (typeof updateGridFromBlockchainSnapshotFn !== 'function') {
|
|
@@ -830,13 +770,13 @@ async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, u
|
|
|
830
770
|
let pendingBoundaryIdx = manager.boundaryIdx;
|
|
831
771
|
let hadBoundaryShift = false;
|
|
832
772
|
if (manager._gridSidesUpdated && manager._gridSidesUpdated.size > 0) {
|
|
833
|
-
const hasBuy = manager._gridSidesUpdated.has(
|
|
834
|
-
const hasSell = manager._gridSidesUpdated.has(
|
|
773
|
+
const hasBuy = manager._gridSidesUpdated.has(ORDER_TYPES.BUY);
|
|
774
|
+
const hasSell = manager._gridSidesUpdated.has(ORDER_TYPES.SELL);
|
|
835
775
|
let resizeOrderType = hasBuy && hasSell
|
|
836
776
|
? 'both'
|
|
837
777
|
: hasBuy
|
|
838
|
-
?
|
|
839
|
-
:
|
|
778
|
+
? ORDER_TYPES.BUY
|
|
779
|
+
: ORDER_TYPES.SELL;
|
|
840
780
|
// If out-of-spread correction moves boundary, recompute both sides.
|
|
841
781
|
// syncBoundaryToFunds is a pure computation — it does NOT write
|
|
842
782
|
// manager.boundaryIdx. We store the result in pendingBoundaryIdx
|
|
@@ -847,14 +787,14 @@ async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, u
|
|
|
847
787
|
if (hadBoundaryShift) {
|
|
848
788
|
pendingBoundaryIdx = boundarySync.newIdx;
|
|
849
789
|
resizeOrderType = 'both';
|
|
850
|
-
manager._gridSidesUpdated.add(
|
|
851
|
-
manager._gridSidesUpdated.add(
|
|
790
|
+
manager._gridSidesUpdated.add(ORDER_TYPES.BUY);
|
|
791
|
+
manager._gridSidesUpdated.add(ORDER_TYPES.SELL);
|
|
852
792
|
}
|
|
853
793
|
try {
|
|
854
794
|
resizeCowResult = await updateGridFromBlockchainSnapshotFn(manager, resizeOrderType, true, pendingBoundaryIdx);
|
|
855
795
|
}
|
|
856
796
|
catch (err) {
|
|
857
|
-
manager.logger?.log?.(`[DIVERGENCE-COW] Grid resize failed: ${
|
|
797
|
+
manager.logger?.log?.(`[DIVERGENCE-COW] Grid resize failed: ${getErrorMessage(err)}`, 'error');
|
|
858
798
|
manager._gridSidesUpdated.clear();
|
|
859
799
|
return undefined;
|
|
860
800
|
}
|
|
@@ -871,7 +811,7 @@ async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, u
|
|
|
871
811
|
: new WorkingGrid(manager.orders, { baseVersion: manager._gridVersion });
|
|
872
812
|
const actions = resizeCowResult?.actions ? [...resizeCowResult.actions] : [];
|
|
873
813
|
for (const orderType of manager._gridSidesUpdated) {
|
|
874
|
-
const sideName = orderType ===
|
|
814
|
+
const sideName = orderType === ORDER_TYPES.BUY ? 'buy' : 'sell';
|
|
875
815
|
const sidePrecision = MathUtils.getPrecisionByOrderType(manager.assets, orderType);
|
|
876
816
|
// Get current on-chain orders for this side.
|
|
877
817
|
// Filter by WORKING GRID type (not master type) so that slots whose
|
|
@@ -907,13 +847,13 @@ async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, u
|
|
|
907
847
|
// Get current slot from working grid (may have been updated in Phase 1)
|
|
908
848
|
const slot = workingGrid.get(onChainOrder.id);
|
|
909
849
|
const isDesired = desiredSlotIds.has(onChainOrder.id);
|
|
910
|
-
if (!isDesired || !slot || !(
|
|
911
|
-
removeActionsForOrder(actions,
|
|
912
|
-
const hasQueuedCancel = hasActionForOrder(actions,
|
|
850
|
+
if (!isDesired || !slot || !(toFiniteNumber(slot.size) > 0)) {
|
|
851
|
+
removeActionsForOrder(actions, COW_ACTIONS.UPDATE, onChainOrder);
|
|
852
|
+
const hasQueuedCancel = hasActionForOrder(actions, COW_ACTIONS.CANCEL, onChainOrder);
|
|
913
853
|
if (!hasQueuedCancel) {
|
|
914
854
|
manager.logger.log(`[DIVERGENCE-COW] Queueing cancel for surplus ${onChainOrder.id} (chain id ${onChainOrder.orderId})`, 'info');
|
|
915
855
|
actions.push({
|
|
916
|
-
type:
|
|
856
|
+
type: COW_ACTIONS.CANCEL,
|
|
917
857
|
id: onChainOrder.id,
|
|
918
858
|
orderId: onChainOrder.orderId
|
|
919
859
|
});
|
|
@@ -923,20 +863,20 @@ async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, u
|
|
|
923
863
|
continue;
|
|
924
864
|
}
|
|
925
865
|
// Phase 1 already queued committed size updates. Avoid duplicate UPDATEs.
|
|
926
|
-
const hasQueuedUpdate = hasActionForOrder(actions,
|
|
927
|
-
const hasQueuedCancel = hasActionForOrder(actions,
|
|
866
|
+
const hasQueuedUpdate = hasActionForOrder(actions, COW_ACTIONS.UPDATE, onChainOrder);
|
|
867
|
+
const hasQueuedCancel = hasActionForOrder(actions, COW_ACTIONS.CANCEL, onChainOrder);
|
|
928
868
|
if (hasQueuedUpdate || hasQueuedCancel) {
|
|
929
869
|
continue;
|
|
930
870
|
}
|
|
931
|
-
const newSize =
|
|
932
|
-
const currentSize =
|
|
871
|
+
const newSize = toFiniteNumber(slot.size);
|
|
872
|
+
const currentSize = toFiniteNumber(onChainOrder.size);
|
|
933
873
|
const sizeChanged = Number.isFinite(sidePrecision)
|
|
934
874
|
? MathUtils.floatToBlockchainInt(newSize, sidePrecision) !== MathUtils.floatToBlockchainInt(currentSize, sidePrecision)
|
|
935
875
|
: newSize !== currentSize;
|
|
936
876
|
if (sizeChanged) {
|
|
937
877
|
manager.logger.log(`[DIVERGENCE-COW] Queueing size update for ${onChainOrder.id}: ${currentSize} -> ${newSize}`, 'info');
|
|
938
878
|
actions.push({
|
|
939
|
-
type:
|
|
879
|
+
type: COW_ACTIONS.UPDATE,
|
|
940
880
|
id: onChainOrder.id,
|
|
941
881
|
orderId: onChainOrder.orderId,
|
|
942
882
|
newGridId: onChainOrder.id,
|
|
@@ -953,11 +893,11 @@ async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, u
|
|
|
953
893
|
}
|
|
954
894
|
// Process holes: CREATE new orders for empty desired slots
|
|
955
895
|
for (const slot of desiredSlots) {
|
|
956
|
-
const hasCreate = hasActionForOrder(actions,
|
|
896
|
+
const hasCreate = hasActionForOrder(actions, COW_ACTIONS.CREATE, slot);
|
|
957
897
|
if (!onChainBySlotId.has(slot.id) && slot.size > 0 && !hasCreate) {
|
|
958
898
|
manager.logger.log(`[DIVERGENCE-COW] Queueing new placement for slot ${slot.id}`, 'info');
|
|
959
899
|
actions.push({
|
|
960
|
-
type:
|
|
900
|
+
type: COW_ACTIONS.CREATE,
|
|
961
901
|
id: slot.id,
|
|
962
902
|
order: {
|
|
963
903
|
id: slot.id,
|
|
@@ -1036,7 +976,7 @@ async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, u
|
|
|
1036
976
|
}
|
|
1037
977
|
}
|
|
1038
978
|
catch (err) {
|
|
1039
|
-
manager.logger.log(`[DIVERGENCE-COW] Error executing divergence corrections: ${
|
|
979
|
+
manager.logger.log(`[DIVERGENCE-COW] Error executing divergence corrections: ${getErrorMessage(err)}`, 'error');
|
|
1040
980
|
manager._gridSidesUpdated.clear();
|
|
1041
981
|
return { committed: false, boundaryChanged: hadBoundaryShift };
|
|
1042
982
|
}
|
|
@@ -1071,7 +1011,7 @@ async function applyGridDivergenceCorrections(manager, accountOrders, _botKey, u
|
|
|
1071
1011
|
* @param {Object} manager - OrderManager instance
|
|
1072
1012
|
* @returns {{ changed: boolean, newIdx?: number }}
|
|
1073
1013
|
*/
|
|
1074
|
-
function syncBoundaryToFunds(manager) {
|
|
1014
|
+
export function syncBoundaryToFunds(manager) {
|
|
1075
1015
|
const availA = (manager.funds?.available?.sell || 0);
|
|
1076
1016
|
const availB = (manager.funds?.available?.buy || 0);
|
|
1077
1017
|
const allSlots = Array.from(manager.orders.values()).sort((a, b) => a.price - b.price);
|
|
@@ -1084,9 +1024,9 @@ function syncBoundaryToFunds(manager) {
|
|
|
1084
1024
|
let minSellIdx = allSlots.length;
|
|
1085
1025
|
for (let i = 0; i < allSlots.length; i++) {
|
|
1086
1026
|
const slot = allSlots[i];
|
|
1087
|
-
if (slot.type ===
|
|
1027
|
+
if (slot.type === ORDER_TYPES.BUY && i > maxBuyIdx)
|
|
1088
1028
|
maxBuyIdx = i;
|
|
1089
|
-
if (slot.type ===
|
|
1029
|
+
if (slot.type === ORDER_TYPES.SELL && i < minSellIdx)
|
|
1090
1030
|
minSellIdx = i;
|
|
1091
1031
|
}
|
|
1092
1032
|
// Build clamp bounds from whichever sides have typed slots.
|
|
@@ -1115,9 +1055,9 @@ function syncBoundaryToFunds(manager) {
|
|
|
1115
1055
|
* @param {string} profilesDir - Path to profiles directory
|
|
1116
1056
|
* @returns {boolean} True if directory was created, false if it already existed
|
|
1117
1057
|
*/
|
|
1118
|
-
function ensureProfilesDirectory(profilesDir) {
|
|
1058
|
+
export function ensureProfilesDirectory(profilesDir) {
|
|
1119
1059
|
if (!storage.exists(profilesDir)) {
|
|
1120
|
-
|
|
1060
|
+
ensureDir(profilesDir);
|
|
1121
1061
|
return true;
|
|
1122
1062
|
}
|
|
1123
1063
|
return false;
|
|
@@ -1127,7 +1067,7 @@ function ensureProfilesDirectory(profilesDir) {
|
|
|
1127
1067
|
* @param {number} ms - Milliseconds to sleep
|
|
1128
1068
|
* @returns {Promise<void>}
|
|
1129
1069
|
*/
|
|
1130
|
-
function sleep(ms) {
|
|
1070
|
+
export function sleep(ms) {
|
|
1131
1071
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
1132
1072
|
}
|
|
1133
1073
|
/**
|
|
@@ -1141,10 +1081,10 @@ function sleep(ms) {
|
|
|
1141
1081
|
* @param {string} [options.mask=''] - Character to display instead of input
|
|
1142
1082
|
* @returns {Promise<string>} Trimmed user input
|
|
1143
1083
|
*/
|
|
1144
|
-
function readInput(prompt, options = {}) {
|
|
1084
|
+
export function readInput(prompt, options = {}) {
|
|
1145
1085
|
return new Promise((resolve) => {
|
|
1146
|
-
const stdin =
|
|
1147
|
-
const stdout =
|
|
1086
|
+
const stdin = runtime.stdin;
|
|
1087
|
+
const stdout = runtime.stdout;
|
|
1148
1088
|
const ESC_SEQUENCE_TIMEOUT_MS = 150;
|
|
1149
1089
|
let input = '';
|
|
1150
1090
|
let cursorPos = 0;
|
|
@@ -1235,7 +1175,7 @@ function readInput(prompt, options = {}) {
|
|
|
1235
1175
|
if (ch === '\u0003') {
|
|
1236
1176
|
cleanup();
|
|
1237
1177
|
stdout.write('\r\x1b[K\n');
|
|
1238
|
-
|
|
1178
|
+
runtime.exit(0);
|
|
1239
1179
|
}
|
|
1240
1180
|
// Backspace
|
|
1241
1181
|
if (ch === '\u007f' || ch === '\u0008') {
|
|
@@ -1289,7 +1229,7 @@ function readInput(prompt, options = {}) {
|
|
|
1289
1229
|
* @param {string} prompt - Prompt text to display
|
|
1290
1230
|
* @returns {Promise<string>} User-entered password
|
|
1291
1231
|
*/
|
|
1292
|
-
async function readPassword(prompt) { return readInput(prompt, { mask: '*', hideEchoBack: false }); }
|
|
1232
|
+
export async function readPassword(prompt) { return readInput(prompt, { mask: '*', hideEchoBack: false }); }
|
|
1293
1233
|
/**
|
|
1294
1234
|
* Execute async function with exponential backoff retry logic.
|
|
1295
1235
|
* Retries on failure with increasing delays up to maxDelayMs.
|
|
@@ -1304,8 +1244,8 @@ async function readPassword(prompt) { return readInput(prompt, { mask: '*', hide
|
|
|
1304
1244
|
* @returns {Promise<*>} Result of function execution
|
|
1305
1245
|
* @throws {Error} If all attempts fail, throws the final error
|
|
1306
1246
|
*/
|
|
1307
|
-
async function withRetry(fn, options = {}) {
|
|
1308
|
-
const { maxAttempts =
|
|
1247
|
+
export async function withRetry(fn, options = {}) {
|
|
1248
|
+
const { maxAttempts = PIPELINE_TIMING.RETRY_MAX_ATTEMPTS, baseDelayMs = PIPELINE_TIMING.RETRY_BASE_DELAY_MS, maxDelayMs = PIPELINE_TIMING.RETRY_MAX_DELAY_MS, logger = null, operationName = 'operation' } = options;
|
|
1309
1249
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
1310
1250
|
try {
|
|
1311
1251
|
return await fn();
|
|
@@ -1339,9 +1279,9 @@ async function withRetry(fn, options = {}) {
|
|
|
1339
1279
|
* @param options.maxRetries - Override max retry count (default PIPELINE_TIMING.RETRY_MAX_ATTEMPTS)
|
|
1340
1280
|
* @param options.retryDelayMs - Override delay between retries (default 2000)
|
|
1341
1281
|
*/
|
|
1342
|
-
async function withBlockchainRetry(fn, label, options) {
|
|
1282
|
+
export async function withBlockchainRetry(fn, label, options) {
|
|
1343
1283
|
const timeoutMs = options?.timeoutMs ?? 30000;
|
|
1344
|
-
const maxRetries = options?.maxRetries ??
|
|
1284
|
+
const maxRetries = options?.maxRetries ?? PIPELINE_TIMING.RETRY_MAX_ATTEMPTS;
|
|
1345
1285
|
const retryDelayMs = options?.retryDelayMs ?? 2000;
|
|
1346
1286
|
const logger = options?.logger;
|
|
1347
1287
|
let lastError;
|
|
@@ -1349,7 +1289,7 @@ async function withBlockchainRetry(fn, label, options) {
|
|
|
1349
1289
|
function raceWithTimeout(attemptLabel) {
|
|
1350
1290
|
const p = fn();
|
|
1351
1291
|
Promise.resolve(p).catch(() => { });
|
|
1352
|
-
return
|
|
1292
|
+
return withTimeout(p, timeoutMs, { label: `${label} ${attemptLabel}` });
|
|
1353
1293
|
}
|
|
1354
1294
|
for (let attempt = 1; attempt <= maxRetries; attempt++) {
|
|
1355
1295
|
try {
|
|
@@ -1363,12 +1303,12 @@ async function withBlockchainRetry(fn, label, options) {
|
|
|
1363
1303
|
const nodeManager = getNodeManager?.();
|
|
1364
1304
|
const nodeUrl = nodeManager?.getBestNode?.();
|
|
1365
1305
|
if (nodeUrl && typeof nodeManager.reportNodeFailure === 'function') {
|
|
1366
|
-
nodeManager.reportNodeFailure(nodeUrl,
|
|
1306
|
+
nodeManager.reportNodeFailure(nodeUrl, getErrorMessage(err), 'blockchain-op');
|
|
1367
1307
|
}
|
|
1368
1308
|
}
|
|
1369
1309
|
catch (_) { /* reporting errors are non-fatal */ }
|
|
1370
1310
|
if (attempt < maxRetries) {
|
|
1371
|
-
logger?.log?.(`${label} attempt ${attempt}/${maxRetries} failed: ${
|
|
1311
|
+
logger?.log?.(`${label} attempt ${attempt}/${maxRetries} failed: ${getErrorMessage(err)}. Retrying in ${retryDelayMs}ms...`, 'warn');
|
|
1372
1312
|
await sleep(retryDelayMs);
|
|
1373
1313
|
}
|
|
1374
1314
|
}
|
|
@@ -1389,7 +1329,7 @@ async function withBlockchainRetry(fn, label, options) {
|
|
|
1389
1329
|
}
|
|
1390
1330
|
}
|
|
1391
1331
|
catch (_) { /* failover recovery errors are non-fatal — throw original error */ }
|
|
1392
|
-
throw new Error(`${label} failed after ${maxRetries} attempts: ${
|
|
1332
|
+
throw new Error(`${label} failed after ${maxRetries} attempts: ${getErrorMessage(lastError)}`);
|
|
1393
1333
|
}
|
|
1394
1334
|
// ================================================================================
|
|
1395
1335
|
// SECTION 6: GENERAL UTILITIES
|
|
@@ -1402,7 +1342,7 @@ async function withBlockchainRetry(fn, label, options) {
|
|
|
1402
1342
|
* @param {string} account - Account name (optional)
|
|
1403
1343
|
* @returns {string|null} Resolved account reference or null
|
|
1404
1344
|
*/
|
|
1405
|
-
function resolveAccountRef(manager, account) {
|
|
1345
|
+
export function resolveAccountRef(manager, account) {
|
|
1406
1346
|
if (manager && typeof manager.accountId === 'string' && manager.accountId) {
|
|
1407
1347
|
return manager.accountId;
|
|
1408
1348
|
}
|
|
@@ -1419,7 +1359,7 @@ function resolveAccountRef(manager, account) {
|
|
|
1419
1359
|
* @param {Object} obj
|
|
1420
1360
|
* @returns {Object}
|
|
1421
1361
|
*/
|
|
1422
|
-
function deepFreeze(obj) {
|
|
1362
|
+
export function deepFreeze(obj) {
|
|
1423
1363
|
if (obj === null || typeof obj !== 'object')
|
|
1424
1364
|
return obj;
|
|
1425
1365
|
Object.freeze(obj);
|
|
@@ -1438,7 +1378,7 @@ function deepFreeze(obj) {
|
|
|
1438
1378
|
* @param {Map} map
|
|
1439
1379
|
* @returns {Map}
|
|
1440
1380
|
*/
|
|
1441
|
-
function cloneMap(map) {
|
|
1381
|
+
export function cloneMap(map) {
|
|
1442
1382
|
return new Map(map);
|
|
1443
1383
|
}
|
|
1444
1384
|
/**
|
|
@@ -1447,8 +1387,9 @@ function cloneMap(map) {
|
|
|
1447
1387
|
* @param {string} raw - The raw string content with possible comments.
|
|
1448
1388
|
* @returns {Object} The parsed JSON object.
|
|
1449
1389
|
*/
|
|
1450
|
-
function parseJsonWithComments(raw) {
|
|
1390
|
+
export function parseJsonWithComments(raw) {
|
|
1451
1391
|
const stripped = raw.replace(/\/\*(?:.|[\r\n])*?\*\//g, '').replace(/(^|\s*)\/\/.*$/gm, '');
|
|
1452
1392
|
return JSON.parse(stripped);
|
|
1453
1393
|
}
|
|
1394
|
+
export { ensureDir };
|
|
1454
1395
|
//# sourceMappingURL=system.js.map
|