dexbot 1.4.10 → 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 +6 -5
- 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 +54 -23
- 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.d.ts +2 -0
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
- package/dist/market_adapter/core/market_adapter_service.js +100 -101
- 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 +163 -222
- 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 +4 -14
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +46 -78
- 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 +3 -2
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +97 -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 +8 -8
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +254 -266
- 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.d.ts +0 -8
- package/dist/modules/order/logger.d.ts.map +1 -1
- package/dist/modules/order/logger.js +28 -141
- 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 -79
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +131 -247
- 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.d.ts.map +1 -1
- package/dist/modules/process_discovery.js +14 -23
- 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 +93 -95
- 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 +258 -222
- 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/validate.ts
|
|
4
3
|
*
|
|
@@ -31,71 +30,17 @@
|
|
|
31
30
|
*
|
|
32
31
|
* ===============================================================================
|
|
33
32
|
*/
|
|
34
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
35
|
-
if (k2 === undefined) k2 = k;
|
|
36
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
37
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
38
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
39
|
-
}
|
|
40
|
-
Object.defineProperty(o, k2, desc);
|
|
41
|
-
}) : (function(o, m, k, k2) {
|
|
42
|
-
if (k2 === undefined) k2 = k;
|
|
43
|
-
o[k2] = m[k];
|
|
44
|
-
}));
|
|
45
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
46
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
47
|
-
}) : function(o, v) {
|
|
48
|
-
o["default"] = v;
|
|
49
|
-
});
|
|
50
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
51
|
-
var ownKeys = function(o) {
|
|
52
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
53
|
-
var ar = [];
|
|
54
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
55
|
-
return ar;
|
|
56
|
-
};
|
|
57
|
-
return ownKeys(o);
|
|
58
|
-
};
|
|
59
|
-
return function (mod) {
|
|
60
|
-
if (mod && mod.__esModule) return mod;
|
|
61
|
-
var result = {};
|
|
62
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
63
|
-
__setModuleDefault(result, mod);
|
|
64
|
-
return result;
|
|
65
|
-
};
|
|
66
|
-
})();
|
|
67
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
-
exports.VALID_ORDER_TYPES = exports.VALID_ORDER_STATES = void 0;
|
|
69
|
-
exports.validateOrder = validateOrder;
|
|
70
|
-
exports.validateGridForPersistence = validateGridForPersistence;
|
|
71
|
-
exports.calculateRequiredFunds = calculateRequiredFunds;
|
|
72
|
-
exports.validateWorkingGridFunds = validateWorkingGridFunds;
|
|
73
|
-
exports.checkFundDrift = checkFundDrift;
|
|
74
|
-
exports.reconcileGrid = reconcileGrid;
|
|
75
|
-
exports.optimizeRebalanceActions = optimizeRebalanceActions;
|
|
76
|
-
exports.summarizeActions = summarizeActions;
|
|
77
|
-
exports.hasExecutableActions = hasExecutableActions;
|
|
78
|
-
exports.validateCreateTargetSlots = validateCreateTargetSlots;
|
|
79
|
-
exports.hasActionForOrder = hasActionForOrder;
|
|
80
|
-
exports.removeActionsForOrder = removeActionsForOrder;
|
|
81
|
-
exports.projectTargetToWorkingGrid = projectTargetToWorkingGrid;
|
|
82
|
-
exports.buildStateUpdates = buildStateUpdates;
|
|
83
|
-
exports.buildAbortedResult = buildAbortedResult;
|
|
84
|
-
exports.buildSuccessResult = buildSuccessResult;
|
|
85
|
-
exports.evaluateCommit = evaluateCommit;
|
|
86
33
|
// ===============================================================================
|
|
87
34
|
// SECTION 1: EXTERNAL DEPENDENCIES
|
|
88
35
|
// ===============================================================================
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
36
|
+
import * as Format from '../format.js';
|
|
37
|
+
import { ORDER_STATES, ORDER_TYPES, COW_ACTIONS, GRID_LIMITS } from '../../constants.js';
|
|
38
|
+
import { floatToBlockchainInt, blockchainToFloat, getPrecisionSlack, getDoubleDustThreshold, findPriceCollision, calculatePriceTolerance } from './math.js';
|
|
39
|
+
import { isOrderOnChain, isPhantomOrder, convertToSpreadPlaceholder, isOrderPlaced } from './order.js';
|
|
93
40
|
const { isValidNumber, toFiniteNumber } = Format;
|
|
94
41
|
// Pre-computed valid sets
|
|
95
|
-
const VALID_ORDER_STATES = new Set(Object.values(
|
|
96
|
-
|
|
97
|
-
const VALID_ORDER_TYPES = new Set(Object.values(constants_1.ORDER_TYPES));
|
|
98
|
-
exports.VALID_ORDER_TYPES = VALID_ORDER_TYPES;
|
|
42
|
+
const VALID_ORDER_STATES = new Set(Object.values(ORDER_STATES));
|
|
43
|
+
const VALID_ORDER_TYPES = new Set(Object.values(ORDER_TYPES));
|
|
99
44
|
// ===============================================================================
|
|
100
45
|
// SECTION 2: VALIDATION
|
|
101
46
|
// ===============================================================================
|
|
@@ -114,10 +59,10 @@ function validateOrder(order, oldOrder = null, context = 'validate') {
|
|
|
114
59
|
errors.push({ code: 'MISSING_ID', message: 'Refusing to update order: missing ID' });
|
|
115
60
|
return { isValid: false, errors, warnings, normalizedOrder: null };
|
|
116
61
|
}
|
|
117
|
-
if (!normalizedOrder.type && normalizedOrder.state ===
|
|
62
|
+
if (!normalizedOrder.type && normalizedOrder.state === ORDER_STATES.VIRTUAL) {
|
|
118
63
|
const placeholderSize = toFiniteNumber(normalizedOrder.size);
|
|
119
64
|
if (placeholderSize === 0) {
|
|
120
|
-
normalizedOrder.type =
|
|
65
|
+
normalizedOrder.type = ORDER_TYPES.SPREAD;
|
|
121
66
|
}
|
|
122
67
|
}
|
|
123
68
|
if (!VALID_ORDER_STATES.has(normalizedOrder.state)) {
|
|
@@ -132,42 +77,42 @@ function validateOrder(order, oldOrder = null, context = 'validate') {
|
|
|
132
77
|
message: `Refusing to update order ${order.id}: invalid type '${normalizedOrder.type}' (context: ${context})`
|
|
133
78
|
});
|
|
134
79
|
}
|
|
135
|
-
if (normalizedOrder.type ===
|
|
80
|
+
if (normalizedOrder.type === ORDER_TYPES.SPREAD && toFiniteNumber(normalizedOrder.size) !== 0) {
|
|
136
81
|
warnings.push({
|
|
137
82
|
code: 'SPREAD_SIZE_NORMALIZED',
|
|
138
83
|
message: `[INVARIANT] Normalizing SPREAD order ${order.id} size ${normalizedOrder.size} -> 0 (context: ${context})`
|
|
139
84
|
});
|
|
140
85
|
normalizedOrder.size = 0;
|
|
141
86
|
}
|
|
142
|
-
const isOnChainState = (normalizedOrder.state ===
|
|
143
|
-
normalizedOrder.state ===
|
|
144
|
-
if (normalizedOrder.type ===
|
|
87
|
+
const isOnChainState = (normalizedOrder.state === ORDER_STATES.ACTIVE ||
|
|
88
|
+
normalizedOrder.state === ORDER_STATES.PARTIAL);
|
|
89
|
+
if (normalizedOrder.type === ORDER_TYPES.SPREAD && isOnChainState) {
|
|
145
90
|
errors.push({
|
|
146
91
|
code: 'ILLEGAL_SPREAD_STATE',
|
|
147
92
|
message: `ILLEGAL STATE: Refusing to move SPREAD order ${order.id} to ${normalizedOrder.state}. SPREAD orders must remain VIRTUAL.`,
|
|
148
93
|
isFatal: true
|
|
149
94
|
});
|
|
150
95
|
}
|
|
151
|
-
if (
|
|
96
|
+
if (isPhantomOrder(normalizedOrder)) {
|
|
152
97
|
errors.push({
|
|
153
98
|
code: 'PHANTOM_ORDER',
|
|
154
99
|
message: `ILLEGAL STATE: Refusing to set order ${order.id} to ${normalizedOrder.state} without orderId. Context: ${context}. This would create a phantom order that doubles fund tracking.`,
|
|
155
100
|
autoCorrect: {
|
|
156
|
-
state:
|
|
101
|
+
state: ORDER_STATES.VIRTUAL,
|
|
157
102
|
orderId: null,
|
|
158
103
|
rawOnChain: null,
|
|
159
104
|
size: 0
|
|
160
105
|
}
|
|
161
106
|
});
|
|
162
107
|
}
|
|
163
|
-
if (normalizedOrder.type ===
|
|
108
|
+
if (normalizedOrder.type === ORDER_TYPES.BUY || normalizedOrder.type === ORDER_TYPES.SELL) {
|
|
164
109
|
normalizedOrder.committedSide = normalizedOrder.type;
|
|
165
110
|
}
|
|
166
111
|
else if (!normalizedOrder.committedSide && oldOrder) {
|
|
167
112
|
if (oldOrder.committedSide) {
|
|
168
113
|
normalizedOrder.committedSide = oldOrder.committedSide;
|
|
169
114
|
}
|
|
170
|
-
else if (oldOrder.type ===
|
|
115
|
+
else if (oldOrder.type === ORDER_TYPES.BUY || oldOrder.type === ORDER_TYPES.SELL) {
|
|
171
116
|
normalizedOrder.committedSide = oldOrder.type;
|
|
172
117
|
}
|
|
173
118
|
}
|
|
@@ -186,7 +131,7 @@ function validateOrder(order, oldOrder = null, context = 'validate') {
|
|
|
186
131
|
*/
|
|
187
132
|
function validateGridForPersistence(orders, accountTotals) {
|
|
188
133
|
for (const order of orders.values()) {
|
|
189
|
-
if (
|
|
134
|
+
if (isPhantomOrder(order)) {
|
|
190
135
|
return {
|
|
191
136
|
isValid: false,
|
|
192
137
|
reason: `Phantom order detected: order ${order.id} is ${order.state} but has no orderId`
|
|
@@ -215,21 +160,21 @@ function calculateRequiredFunds(grid, precisions = {}) {
|
|
|
215
160
|
for (const order of grid.values()) {
|
|
216
161
|
const size = toFiniteNumber(order.size ?? order.amount);
|
|
217
162
|
const state = order.state;
|
|
218
|
-
const isActive = state ===
|
|
219
|
-
if (isActive &&
|
|
220
|
-
if (order.type ===
|
|
221
|
-
buyRequiredInt +=
|
|
163
|
+
const isActive = state === ORDER_STATES.ACTIVE || state === ORDER_STATES.PARTIAL;
|
|
164
|
+
if (isActive && isOrderOnChain(order)) {
|
|
165
|
+
if (order.type === ORDER_TYPES.BUY) {
|
|
166
|
+
buyRequiredInt += floatToBlockchainInt(size, buyPrecision);
|
|
222
167
|
}
|
|
223
|
-
else if (order.type ===
|
|
224
|
-
sellRequiredInt +=
|
|
168
|
+
else if (order.type === ORDER_TYPES.SELL) {
|
|
169
|
+
sellRequiredInt += floatToBlockchainInt(size, sellPrecision);
|
|
225
170
|
}
|
|
226
171
|
}
|
|
227
172
|
}
|
|
228
173
|
return {
|
|
229
174
|
buyInt: buyRequiredInt,
|
|
230
175
|
sellInt: sellRequiredInt,
|
|
231
|
-
buy:
|
|
232
|
-
sell:
|
|
176
|
+
buy: blockchainToFloat(buyRequiredInt, buyPrecision),
|
|
177
|
+
sell: blockchainToFloat(sellRequiredInt, sellPrecision)
|
|
233
178
|
};
|
|
234
179
|
}
|
|
235
180
|
/**
|
|
@@ -255,26 +200,26 @@ function validateWorkingGridFunds(workingGrid, projectedFunds, precisions = {},
|
|
|
255
200
|
? Number(projectedFunds.chainTotalSell)
|
|
256
201
|
: toFiniteNumber(projectedFunds?.freeSell ?? projectedFunds?.chainFreeSell);
|
|
257
202
|
const shortfalls = [];
|
|
258
|
-
const availableBuyInt =
|
|
259
|
-
const availableSellInt =
|
|
203
|
+
const availableBuyInt = floatToBlockchainInt(availableBuy, buyPrecision);
|
|
204
|
+
const availableSellInt = floatToBlockchainInt(availableSell, sellPrecision);
|
|
260
205
|
if (required.buyInt > availableBuyInt) {
|
|
261
|
-
const requiredBuyFloat =
|
|
262
|
-
const availableBuyFloat =
|
|
206
|
+
const requiredBuyFloat = blockchainToFloat(required.buyInt, buyPrecision);
|
|
207
|
+
const availableBuyFloat = blockchainToFloat(availableBuyInt, buyPrecision);
|
|
263
208
|
shortfalls.push({
|
|
264
209
|
asset: assets?.assetB?.symbol || 'buyAsset',
|
|
265
210
|
required: requiredBuyFloat,
|
|
266
211
|
available: availableBuyFloat,
|
|
267
|
-
deficit:
|
|
212
|
+
deficit: blockchainToFloat(required.buyInt - availableBuyInt, buyPrecision)
|
|
268
213
|
});
|
|
269
214
|
}
|
|
270
215
|
if (required.sellInt > availableSellInt) {
|
|
271
|
-
const requiredSellFloat =
|
|
272
|
-
const availableSellFloat =
|
|
216
|
+
const requiredSellFloat = blockchainToFloat(required.sellInt, sellPrecision);
|
|
217
|
+
const availableSellFloat = blockchainToFloat(availableSellInt, sellPrecision);
|
|
273
218
|
shortfalls.push({
|
|
274
219
|
asset: assets?.assetA?.symbol || 'sellAsset',
|
|
275
220
|
required: requiredSellFloat,
|
|
276
221
|
available: availableSellFloat,
|
|
277
|
-
deficit:
|
|
222
|
+
deficit: blockchainToFloat(required.sellInt - availableSellInt, sellPrecision)
|
|
278
223
|
});
|
|
279
224
|
}
|
|
280
225
|
return {
|
|
@@ -296,11 +241,11 @@ function checkFundDrift(orders, accountTotals, assets = null, gridLimits = null)
|
|
|
296
241
|
let gridBuy = 0, gridSell = 0;
|
|
297
242
|
for (const order of Array.from(orders.values())) {
|
|
298
243
|
const size = toFiniteNumber(order.size);
|
|
299
|
-
if (size <= 0 || !
|
|
244
|
+
if (size <= 0 || !isOrderOnChain(order))
|
|
300
245
|
continue;
|
|
301
|
-
if (order.type ===
|
|
246
|
+
if (order.type === ORDER_TYPES.BUY)
|
|
302
247
|
gridBuy += size;
|
|
303
|
-
else if (order.type ===
|
|
248
|
+
else if (order.type === ORDER_TYPES.SELL)
|
|
304
249
|
gridSell += size;
|
|
305
250
|
}
|
|
306
251
|
const chainFreeBuy = accountTotals?.buyFree || 0;
|
|
@@ -316,9 +261,9 @@ function checkFundDrift(orders, accountTotals, assets = null, gridLimits = null)
|
|
|
316
261
|
if (!isValidNumber(buyPrecision) || !isValidNumber(sellPrecision)) {
|
|
317
262
|
return { isValid: true, reason: 'Skipped: precision not available', driftBuy, driftSell };
|
|
318
263
|
}
|
|
319
|
-
const precisionSlackBuy =
|
|
320
|
-
const precisionSlackSell =
|
|
321
|
-
const fundInvariantTolerance = gridLimits?.FUND_INVARIANT_PERCENT_TOLERANCE ??
|
|
264
|
+
const precisionSlackBuy = getPrecisionSlack(buyPrecision);
|
|
265
|
+
const precisionSlackSell = getPrecisionSlack(sellPrecision);
|
|
266
|
+
const fundInvariantTolerance = gridLimits?.FUND_INVARIANT_PERCENT_TOLERANCE ?? GRID_LIMITS.FUND_INVARIANT_PERCENT_TOLERANCE;
|
|
322
267
|
const percentTolerance = fundInvariantTolerance / 100;
|
|
323
268
|
const allowedDriftBuy = Math.max(precisionSlackBuy, actualBuy * percentTolerance);
|
|
324
269
|
const allowedDriftSell = Math.max(precisionSlackSell, actualSell * percentTolerance);
|
|
@@ -349,7 +294,7 @@ function checkFundDrift(orders, accountTotals, assets = null, gridLimits = null)
|
|
|
349
294
|
* @returns {Object} Reconciliation result with actions
|
|
350
295
|
*/
|
|
351
296
|
function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
352
|
-
const { logger = null, dustThresholdPercent =
|
|
297
|
+
const { logger = null, dustThresholdPercent = GRID_LIMITS.PARTIAL_DUST_THRESHOLD_PERCENTAGE } = options;
|
|
353
298
|
const actions = [];
|
|
354
299
|
const surplusesBuy = [];
|
|
355
300
|
const surplusesSell = [];
|
|
@@ -361,7 +306,7 @@ function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
|
361
306
|
const idealSize = toFiniteNumber(order.idealSize || order.size);
|
|
362
307
|
if (idealSize <= 0)
|
|
363
308
|
return true;
|
|
364
|
-
const minHealthy =
|
|
309
|
+
const minHealthy = getDoubleDustThreshold(idealSize, dustThresholdPercent);
|
|
365
310
|
if (order.size < minHealthy) {
|
|
366
311
|
if (logger) {
|
|
367
312
|
logger(`[RECONCILE] Skipping dust target order: ${order.id} ` +
|
|
@@ -385,40 +330,40 @@ function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
|
385
330
|
}
|
|
386
331
|
for (const [id, targetOrder] of targetGrid) {
|
|
387
332
|
const masterOrder = masterGrid.get(id);
|
|
388
|
-
if (!masterOrder || masterOrder.state ===
|
|
333
|
+
if (!masterOrder || masterOrder.state === ORDER_STATES.VIRTUAL) {
|
|
389
334
|
// Slot is empty or virtual - check if we need to fill it
|
|
390
|
-
if (targetOrder.size > 0 && targetOrder.state ===
|
|
335
|
+
if (targetOrder.size > 0 && targetOrder.state === ORDER_STATES.ACTIVE) {
|
|
391
336
|
// This is a hole that needs filling
|
|
392
|
-
if (targetOrder.type ===
|
|
337
|
+
if (targetOrder.type === ORDER_TYPES.BUY) {
|
|
393
338
|
holesBuy.push({ id, order: targetOrder });
|
|
394
339
|
}
|
|
395
|
-
else if (targetOrder.type ===
|
|
340
|
+
else if (targetOrder.type === ORDER_TYPES.SELL) {
|
|
396
341
|
holesSell.push({ id, order: targetOrder });
|
|
397
342
|
}
|
|
398
343
|
}
|
|
399
344
|
continue;
|
|
400
345
|
}
|
|
401
346
|
if (masterOrder.type !== targetOrder.type) {
|
|
402
|
-
actions.push({ type:
|
|
403
|
-
if (targetOrder.size > 0 && targetOrder.state ===
|
|
404
|
-
actions.push({ type:
|
|
347
|
+
actions.push({ type: COW_ACTIONS.CANCEL, id, orderId: masterOrder.orderId, reason: 'type-mismatch' });
|
|
348
|
+
if (targetOrder.size > 0 && targetOrder.state === ORDER_STATES.ACTIVE && isCreateHealthy(targetOrder)) {
|
|
349
|
+
actions.push({ type: COW_ACTIONS.CREATE, id, order: targetOrder });
|
|
405
350
|
}
|
|
406
351
|
continue;
|
|
407
352
|
}
|
|
408
353
|
// If master is on-chain but target should be VIRTUAL (outside window),
|
|
409
354
|
// this is a surplus candidate for rotation.
|
|
410
|
-
if (
|
|
411
|
-
if (masterOrder.type ===
|
|
355
|
+
if (isOrderOnChain(masterOrder) && targetOrder.state === ORDER_STATES.VIRTUAL) {
|
|
356
|
+
if (masterOrder.type === ORDER_TYPES.BUY) {
|
|
412
357
|
surplusesBuy.push({ id, master: masterOrder, target: targetOrder });
|
|
413
358
|
}
|
|
414
|
-
else if (masterOrder.type ===
|
|
359
|
+
else if (masterOrder.type === ORDER_TYPES.SELL) {
|
|
415
360
|
surplusesSell.push({ id, master: masterOrder, target: targetOrder });
|
|
416
361
|
}
|
|
417
362
|
continue;
|
|
418
363
|
}
|
|
419
364
|
if (masterOrder.size !== targetOrder.size) {
|
|
420
365
|
if (targetOrder.size === 0) {
|
|
421
|
-
actions.push({ type:
|
|
366
|
+
actions.push({ type: COW_ACTIONS.CANCEL, id, orderId: masterOrder.orderId, reason: 'target-size-zero' });
|
|
422
367
|
}
|
|
423
368
|
// Intentionally no in-place size UPDATE here.
|
|
424
369
|
// Fill-driven COW rebalance keeps updates rotation-only (newGridId path).
|
|
@@ -429,7 +374,7 @@ function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
|
429
374
|
const cancelSurpluses = (surpluses) => {
|
|
430
375
|
for (const surplus of surpluses) {
|
|
431
376
|
if (surplus.master.orderId) {
|
|
432
|
-
actions.push({ type:
|
|
377
|
+
actions.push({ type: COW_ACTIONS.CANCEL, id: surplus.id, orderId: surplus.master.orderId, reason: 'surplus-no-rotation-target' });
|
|
433
378
|
}
|
|
434
379
|
}
|
|
435
380
|
};
|
|
@@ -442,11 +387,11 @@ function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
|
442
387
|
}
|
|
443
388
|
if (surpluses.length === 0) {
|
|
444
389
|
for (const hole of healthyHoles) {
|
|
445
|
-
actions.push({ type:
|
|
390
|
+
actions.push({ type: COW_ACTIONS.CREATE, id: hole.id, order: hole.order });
|
|
446
391
|
}
|
|
447
392
|
return;
|
|
448
393
|
}
|
|
449
|
-
const isBuy = surpluses[0]?.master?.type ===
|
|
394
|
+
const isBuy = surpluses[0]?.master?.type === ORDER_TYPES.BUY;
|
|
450
395
|
healthyHoles.sort((a, b) => isBuy ? b.order.price - a.order.price : a.order.price - b.order.price);
|
|
451
396
|
surpluses.sort((a, b) => isBuy ? a.master.price - b.master.price : b.master.price - a.master.price);
|
|
452
397
|
const rotationCount = Math.min(surpluses.length, healthyHoles.length);
|
|
@@ -454,7 +399,7 @@ function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
|
454
399
|
const surplus = surpluses[i];
|
|
455
400
|
const hole = healthyHoles[i];
|
|
456
401
|
actions.push({
|
|
457
|
-
type:
|
|
402
|
+
type: COW_ACTIONS.UPDATE,
|
|
458
403
|
id: surplus.id,
|
|
459
404
|
orderId: surplus.master.orderId,
|
|
460
405
|
newGridId: hole.id,
|
|
@@ -465,7 +410,7 @@ function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
|
465
410
|
});
|
|
466
411
|
}
|
|
467
412
|
for (let i = rotationCount; i < healthyHoles.length; i++) {
|
|
468
|
-
actions.push({ type:
|
|
413
|
+
actions.push({ type: COW_ACTIONS.CREATE, id: healthyHoles[i].id, order: healthyHoles[i].order });
|
|
469
414
|
}
|
|
470
415
|
// Cancel any surpluses that couldn't be paired with a hole
|
|
471
416
|
cancelSurpluses(surpluses.slice(rotationCount));
|
|
@@ -473,8 +418,8 @@ function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
|
473
418
|
pairRotations(surplusesBuy, holesBuy);
|
|
474
419
|
pairRotations(surplusesSell, holesSell);
|
|
475
420
|
for (const [id, masterOrder] of masterGrid) {
|
|
476
|
-
if (!targetGrid.has(id) &&
|
|
477
|
-
actions.push({ type:
|
|
421
|
+
if (!targetGrid.has(id) && isOrderOnChain(masterOrder)) {
|
|
422
|
+
actions.push({ type: COW_ACTIONS.CANCEL, id, orderId: masterOrder.orderId, reason: 'orphan-slot' });
|
|
478
423
|
}
|
|
479
424
|
}
|
|
480
425
|
return {
|
|
@@ -500,10 +445,10 @@ function optimizeRebalanceActions(actions, masterGrid) {
|
|
|
500
445
|
const cancels = [];
|
|
501
446
|
const passthrough = [];
|
|
502
447
|
for (const action of actions) {
|
|
503
|
-
if (action?.type ===
|
|
448
|
+
if (action?.type === COW_ACTIONS.CREATE) {
|
|
504
449
|
creates.push(action);
|
|
505
450
|
}
|
|
506
|
-
else if (action?.type ===
|
|
451
|
+
else if (action?.type === COW_ACTIONS.CANCEL) {
|
|
507
452
|
cancels.push(action);
|
|
508
453
|
}
|
|
509
454
|
else {
|
|
@@ -543,7 +488,7 @@ function optimizeRebalanceActions(actions, masterGrid) {
|
|
|
543
488
|
}
|
|
544
489
|
const createAction = remainingCreates.splice(bestIdx, 1)[0];
|
|
545
490
|
optimized.push({
|
|
546
|
-
type:
|
|
491
|
+
type: COW_ACTIONS.UPDATE,
|
|
547
492
|
id: cancelAction.id,
|
|
548
493
|
orderId: cancelAction.orderId,
|
|
549
494
|
newGridId: createAction.id,
|
|
@@ -566,9 +511,9 @@ function optimizeRebalanceActions(actions, masterGrid) {
|
|
|
566
511
|
function summarizeActions(actions) {
|
|
567
512
|
return {
|
|
568
513
|
total: actions.length,
|
|
569
|
-
creates: actions.filter((a) => a.type ===
|
|
570
|
-
cancels: actions.filter((a) => a.type ===
|
|
571
|
-
updates: actions.filter((a) => a.type ===
|
|
514
|
+
creates: actions.filter((a) => a.type === COW_ACTIONS.CREATE).length,
|
|
515
|
+
cancels: actions.filter((a) => a.type === COW_ACTIONS.CANCEL).length,
|
|
516
|
+
updates: actions.filter((a) => a.type === COW_ACTIONS.UPDATE).length
|
|
572
517
|
};
|
|
573
518
|
}
|
|
574
519
|
/**
|
|
@@ -610,11 +555,11 @@ function validateCreateTargetSlots(actions, orders, assets = null, chainOrderCan
|
|
|
610
555
|
const orderMap = orders instanceof Map ? orders : new Map();
|
|
611
556
|
const releasedSlotIds = new Set();
|
|
612
557
|
for (const action of safeActions) {
|
|
613
|
-
if (action?.type ===
|
|
558
|
+
if (action?.type === COW_ACTIONS.CANCEL && action.id) {
|
|
614
559
|
releasedSlotIds.add(action.id);
|
|
615
560
|
continue;
|
|
616
561
|
}
|
|
617
|
-
if (action?.type ===
|
|
562
|
+
if (action?.type === COW_ACTIONS.UPDATE &&
|
|
618
563
|
action.id &&
|
|
619
564
|
action.newGridId &&
|
|
620
565
|
action.newGridId !== action.id) {
|
|
@@ -624,14 +569,14 @@ function validateCreateTargetSlots(actions, orders, assets = null, chainOrderCan
|
|
|
624
569
|
const violations = [];
|
|
625
570
|
const createEntries = [];
|
|
626
571
|
for (const action of safeActions) {
|
|
627
|
-
if (action?.type !==
|
|
572
|
+
if (action?.type !== COW_ACTIONS.CREATE)
|
|
628
573
|
continue;
|
|
629
574
|
const targetId = action.id || action.order?.id;
|
|
630
575
|
if (!targetId || releasedSlotIds.has(targetId))
|
|
631
576
|
continue;
|
|
632
577
|
const current = orderMap.get(targetId);
|
|
633
578
|
// isOrderOnChain already checks orderId is truthy
|
|
634
|
-
if (current &&
|
|
579
|
+
if (current && isOrderOnChain(current)) {
|
|
635
580
|
violations.push({
|
|
636
581
|
targetId,
|
|
637
582
|
currentOrderId: current.orderId,
|
|
@@ -657,7 +602,7 @@ function validateCreateTargetSlots(actions, orders, assets = null, chainOrderCan
|
|
|
657
602
|
}
|
|
658
603
|
if (assets && createEntries.length > 0) {
|
|
659
604
|
for (const entry of createEntries) {
|
|
660
|
-
const collision =
|
|
605
|
+
const collision = findPriceCollision(orderMap.values(), entry.targetId, entry.price, entry.size, entry.type, assets, (o) => isOrderPlaced(o) && o.id !== entry.targetId);
|
|
661
606
|
if (collision) {
|
|
662
607
|
violations.push({
|
|
663
608
|
targetId: entry.targetId,
|
|
@@ -682,7 +627,7 @@ function validateCreateTargetSlots(actions, orders, assets = null, chainOrderCan
|
|
|
682
627
|
orderId: u.chainOrderId,
|
|
683
628
|
}));
|
|
684
629
|
for (const entry of createEntries) {
|
|
685
|
-
const chainCollision =
|
|
630
|
+
const chainCollision = findPriceCollision(mapped, entry.targetId, entry.price, entry.size, entry.type, assets, (item) => item.price != null);
|
|
686
631
|
if (chainCollision) {
|
|
687
632
|
violations.push({
|
|
688
633
|
targetId: entry.targetId,
|
|
@@ -709,8 +654,8 @@ function validateCreateTargetSlots(actions, orders, assets = null, chainOrderCan
|
|
|
709
654
|
for (let j = i + 1; j < createEntries.length; j++) {
|
|
710
655
|
const a = createEntries[i];
|
|
711
656
|
const b = createEntries[j];
|
|
712
|
-
const tolA =
|
|
713
|
-
const tolB =
|
|
657
|
+
const tolA = calculatePriceTolerance(Math.min(a.price, b.price), Math.max(a.size, b.size), a.type, assets);
|
|
658
|
+
const tolB = calculatePriceTolerance(Math.min(a.price, b.price), Math.max(a.size, b.size), b.type, assets);
|
|
714
659
|
const tolerance = (tolA != null && tolB != null)
|
|
715
660
|
? Math.min(tolA, tolB)
|
|
716
661
|
: (tolA != null ? tolA : tolB);
|
|
@@ -807,7 +752,7 @@ function _buildUpdateSelectors(actions) {
|
|
|
807
752
|
if (!Array.isArray(actions))
|
|
808
753
|
return selectors;
|
|
809
754
|
for (const action of actions) {
|
|
810
|
-
if (action?.type !==
|
|
755
|
+
if (action?.type !== COW_ACTIONS.UPDATE)
|
|
811
756
|
continue;
|
|
812
757
|
if (action.id)
|
|
813
758
|
selectors.slotIds.add(String(action.id));
|
|
@@ -872,13 +817,13 @@ function projectTargetToWorkingGrid(workingGrid, targetGrid, options = {}) {
|
|
|
872
817
|
workingGrid.set(id, {
|
|
873
818
|
...targetOrder,
|
|
874
819
|
size: Math.max(0, targetSize),
|
|
875
|
-
state:
|
|
820
|
+
state: ORDER_STATES.VIRTUAL,
|
|
876
821
|
orderId: null
|
|
877
822
|
});
|
|
878
823
|
continue;
|
|
879
824
|
}
|
|
880
825
|
if (targetSize > 0) {
|
|
881
|
-
const keepOrderId =
|
|
826
|
+
const keepOrderId = isOrderOnChain(current) && current.type === targetOrder.type;
|
|
882
827
|
const hasExplicitUpdate = _hasExplicitUpdateForOrder(updateSelectors, current, id);
|
|
883
828
|
// Orders without on-chain ID remain VIRTUAL until synchronizeWithChain
|
|
884
829
|
// confirms blockchain placement and triggers accounting deduction.
|
|
@@ -891,7 +836,7 @@ function projectTargetToWorkingGrid(workingGrid, targetGrid, options = {}) {
|
|
|
891
836
|
const preservedSize = shouldPreserveSize
|
|
892
837
|
? Math.max(0, toFiniteNumber(current.size))
|
|
893
838
|
: targetSize;
|
|
894
|
-
const resultState = keepOrderId ? current.state :
|
|
839
|
+
const resultState = keepOrderId ? current.state : ORDER_STATES.VIRTUAL;
|
|
895
840
|
const resultOrderId = keepOrderId ? current.orderId : null;
|
|
896
841
|
if (!_isProjectionUnchanged(current, targetOrder, preservedSize, resultState, resultOrderId)) {
|
|
897
842
|
workingGrid.set(id, {
|
|
@@ -904,12 +849,12 @@ function projectTargetToWorkingGrid(workingGrid, targetGrid, options = {}) {
|
|
|
904
849
|
}
|
|
905
850
|
}
|
|
906
851
|
else {
|
|
907
|
-
if (!_isProjectionUnchanged(current, targetOrder, 0,
|
|
852
|
+
if (!_isProjectionUnchanged(current, targetOrder, 0, ORDER_STATES.VIRTUAL, null)) {
|
|
908
853
|
workingGrid.set(id, {
|
|
909
854
|
...current,
|
|
910
855
|
...targetOrder,
|
|
911
856
|
size: 0,
|
|
912
|
-
state:
|
|
857
|
+
state: ORDER_STATES.VIRTUAL,
|
|
913
858
|
orderId: null
|
|
914
859
|
});
|
|
915
860
|
}
|
|
@@ -918,8 +863,8 @@ function projectTargetToWorkingGrid(workingGrid, targetGrid, options = {}) {
|
|
|
918
863
|
for (const [id, current] of workingGrid.entries()) {
|
|
919
864
|
if (targetIds.has(id))
|
|
920
865
|
continue;
|
|
921
|
-
if (
|
|
922
|
-
workingGrid.set(id,
|
|
866
|
+
if (isOrderOnChain(current)) {
|
|
867
|
+
workingGrid.set(id, convertToSpreadPlaceholder(current));
|
|
923
868
|
}
|
|
924
869
|
}
|
|
925
870
|
}
|
|
@@ -932,20 +877,20 @@ function projectTargetToWorkingGrid(workingGrid, targetGrid, options = {}) {
|
|
|
932
877
|
function buildStateUpdates(actions, masterGrid) {
|
|
933
878
|
const stateUpdates = [];
|
|
934
879
|
for (const action of actions) {
|
|
935
|
-
if (action.type ===
|
|
880
|
+
if (action.type === COW_ACTIONS.CREATE) {
|
|
936
881
|
stateUpdates.push({
|
|
937
882
|
...action.order,
|
|
938
|
-
state:
|
|
883
|
+
state: ORDER_STATES.VIRTUAL,
|
|
939
884
|
orderId: null
|
|
940
885
|
});
|
|
941
886
|
}
|
|
942
|
-
else if (action.type ===
|
|
887
|
+
else if (action.type === COW_ACTIONS.CANCEL) {
|
|
943
888
|
const masterOrder = masterGrid.get(action.id);
|
|
944
889
|
if (masterOrder) {
|
|
945
|
-
stateUpdates.push(
|
|
890
|
+
stateUpdates.push(convertToSpreadPlaceholder(masterOrder));
|
|
946
891
|
}
|
|
947
892
|
}
|
|
948
|
-
else if (action.type ===
|
|
893
|
+
else if (action.type === COW_ACTIONS.UPDATE) {
|
|
949
894
|
const masterOrder = masterGrid.get(action.id);
|
|
950
895
|
if (masterOrder) {
|
|
951
896
|
const newSize = toFiniteNumber(action.newSize ?? action.order?.size);
|
|
@@ -982,7 +927,7 @@ function buildSuccessResult({ actions, stateUpdates, workingGrid, workingBoundar
|
|
|
982
927
|
return {
|
|
983
928
|
actions,
|
|
984
929
|
stateUpdates,
|
|
985
|
-
hadRotation: actions.some((a) => a.type ===
|
|
930
|
+
hadRotation: actions.some((a) => a.type === COW_ACTIONS.CREATE || a.type === COW_ACTIONS.UPDATE),
|
|
986
931
|
workingGrid,
|
|
987
932
|
workingIndexes: workingGrid.getIndexes(),
|
|
988
933
|
workingBoundary,
|
|
@@ -1053,4 +998,8 @@ function evaluateCommit(workingGrid, options = {}) {
|
|
|
1053
998
|
}
|
|
1054
999
|
return { canCommit: true };
|
|
1055
1000
|
}
|
|
1001
|
+
// ===============================================================================
|
|
1002
|
+
// EXPORTS
|
|
1003
|
+
// ===============================================================================
|
|
1004
|
+
export { validateOrder, validateGridForPersistence, calculateRequiredFunds, validateWorkingGridFunds, checkFundDrift, VALID_ORDER_STATES, VALID_ORDER_TYPES, reconcileGrid, optimizeRebalanceActions, summarizeActions, hasExecutableActions, validateCreateTargetSlots, hasActionForOrder, removeActionsForOrder, projectTargetToWorkingGrid, buildStateUpdates, buildAbortedResult, buildSuccessResult, evaluateCommit };
|
|
1056
1005
|
//# sourceMappingURL=validate.js.map
|