dexbot 1.1.10
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/LICENSE +21 -0
- package/README.md +287 -0
- package/claw/README.md +513 -0
- package/claw/scripts/memu_runner.py +385 -0
- package/claw/skills/bitshares-guide/SKILL.md +14 -0
- package/claw/skills/bitshares-guide/references/example-skill-shells.md +18 -0
- package/claw/skills/bitshares-guide/references/presentation-patterns.md +19 -0
- package/claw/skills/bitshares-guide/references/scope-guardrails.md +9 -0
- package/claw/skills/launcher-ops/SKILL.md +18 -0
- package/claw/skills/launcher-ops/references/launcher-workflow.md +23 -0
- package/claw/skills/margin-trading/SKILL.md +23 -0
- package/claw/skills/margin-trading/references/honest-asset-list.md +74 -0
- package/claw/skills/margin-trading/references/honest-assets.md +44 -0
- package/claw/skills/margin-trading/references/position-management.md +203 -0
- package/claw/skills/margin-trading/references/trading-concepts.md +80 -0
- package/claw/skills/memu-memory/SKILL.md +218 -0
- package/claw/skills/shared/references/js-automation-overview.md +24 -0
- package/claw/skills/shared/references/safety-and-staleness.md +11 -0
- package/claw/skills/shared/references/skill-boundaries.md +17 -0
- package/claw/skills/trend-detection/SKILL.md +33 -0
- package/claw/skills/trend-detection/agents/openai.yaml +3 -0
- package/claw/skills/trend-detection/references/service.md +45 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts +3 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js +149 -0
- package/dist/analysis/ama_fitting/analyze_ama_price_changes.js.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts +3 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +387 -0
- package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js.map +1 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts +3 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js +200 -0
- package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts +3 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +212 -0
- package/dist/analysis/ama_fitting/fetch_lp_candles.js.map +1 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts +31 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js +249 -0
- package/dist/analysis/ama_fitting/generate_unified_comparison_chart.js.map +1 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +2 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts.map +1 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +782 -0
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js.map +1 -0
- package/dist/analysis/analyze_derivatives.d.ts +95 -0
- package/dist/analysis/analyze_derivatives.d.ts.map +1 -0
- package/dist/analysis/analyze_derivatives.js +295 -0
- package/dist/analysis/analyze_derivatives.js.map +1 -0
- package/dist/analysis/analyze_dynamic_weight.d.ts +14 -0
- package/dist/analysis/analyze_dynamic_weight.d.ts.map +1 -0
- package/dist/analysis/analyze_dynamic_weight.js +208 -0
- package/dist/analysis/analyze_dynamic_weight.js.map +1 -0
- package/dist/analysis/analyze_kalman.d.ts +13 -0
- package/dist/analysis/analyze_kalman.d.ts.map +1 -0
- package/dist/analysis/analyze_kalman.js +123 -0
- package/dist/analysis/analyze_kalman.js.map +1 -0
- package/dist/analysis/analyze_regime.d.ts +20 -0
- package/dist/analysis/analyze_regime.d.ts.map +1 -0
- package/dist/analysis/analyze_regime.js +139 -0
- package/dist/analysis/analyze_regime.js.map +1 -0
- package/dist/analysis/analyze_regime_windows.d.ts +19 -0
- package/dist/analysis/analyze_regime_windows.d.ts.map +1 -0
- package/dist/analysis/analyze_regime_windows.js +413 -0
- package/dist/analysis/analyze_regime_windows.js.map +1 -0
- package/dist/analysis/analyze_risk_profile.d.ts +3 -0
- package/dist/analysis/analyze_risk_profile.d.ts.map +1 -0
- package/dist/analysis/analyze_risk_profile.js +159 -0
- package/dist/analysis/analyze_risk_profile.js.map +1 -0
- package/dist/analysis/analyze_trade_heatmap.d.ts +3 -0
- package/dist/analysis/analyze_trade_heatmap.d.ts.map +1 -0
- package/dist/analysis/analyze_trade_heatmap.js +367 -0
- package/dist/analysis/analyze_trade_heatmap.js.map +1 -0
- package/dist/analysis/analyze_volatility.d.ts +22 -0
- package/dist/analysis/analyze_volatility.d.ts.map +1 -0
- package/dist/analysis/analyze_volatility.js +172 -0
- package/dist/analysis/analyze_volatility.js.map +1 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts +99 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js +804 -0
- package/dist/analysis/bot_fitting/backtest_ama_sweep.js.map +1 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +2 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +347 -0
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js.map +1 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts +15 -0
- package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -0
- package/dist/analysis/bot_fitting/shared_utils.js +48 -0
- package/dist/analysis/bot_fitting/shared_utils.js.map +1 -0
- package/dist/analysis/bot_key_utils.d.ts +16 -0
- package/dist/analysis/bot_key_utils.d.ts.map +1 -0
- package/dist/analysis/bot_key_utils.js +61 -0
- package/dist/analysis/bot_key_utils.js.map +1 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts +3 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.d.ts.map +1 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.js +498 -0
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +546 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.js +427 -0
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -0
- package/dist/analysis/chart_utils.d.ts +13 -0
- package/dist/analysis/chart_utils.d.ts.map +1 -0
- package/dist/analysis/chart_utils.js +142 -0
- package/dist/analysis/chart_utils.js.map +1 -0
- package/dist/analysis/derivative_chart_generator.d.ts +18 -0
- package/dist/analysis/derivative_chart_generator.d.ts.map +1 -0
- package/dist/analysis/derivative_chart_generator.js +896 -0
- package/dist/analysis/derivative_chart_generator.js.map +1 -0
- package/dist/analysis/math_utils.d.ts +35 -0
- package/dist/analysis/math_utils.d.ts.map +1 -0
- package/dist/analysis/math_utils.js +121 -0
- package/dist/analysis/math_utils.js.map +1 -0
- package/dist/analysis/price_sources.d.ts +34 -0
- package/dist/analysis/price_sources.d.ts.map +1 -0
- package/dist/analysis/price_sources.js +103 -0
- package/dist/analysis/price_sources.js.map +1 -0
- package/dist/analysis/trade_profitability.d.ts +115 -0
- package/dist/analysis/trade_profitability.d.ts.map +1 -0
- package/dist/analysis/trade_profitability.js +1247 -0
- package/dist/analysis/trade_profitability.js.map +1 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts +38 -0
- package/dist/analysis/tradingview/analyze_tradingview.d.ts.map +1 -0
- package/dist/analysis/tradingview/analyze_tradingview.js +212 -0
- package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +9 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts.map +1 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +1717 -0
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts +250 -0
- package/dist/analysis/trend_detection/derivative_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/derivative_analyzer.js +903 -0
- package/dist/analysis/trend_detection/derivative_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +1449 -0
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts +42 -0
- package/dist/analysis/trend_detection/hurst_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/hurst_analyzer.js +159 -0
- package/dist/analysis/trend_detection/hurst_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.js +408 -0
- package/dist/analysis/trend_detection/kalman_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts +103 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js +229 -0
- package/dist/analysis/trend_detection/kalman_trend_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts +34 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.d.ts.map +1 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js +89 -0
- package/dist/analysis/trend_detection/kalman_velocity_smoothing.js.map +1 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts +39 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.d.ts.map +1 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js +132 -0
- package/dist/analysis/trend_detection/permutation_entropy_analyzer.js.map +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/regime_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js +345 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts +2 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.d.ts.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js +130 -0
- package/dist/analysis/trend_detection/tests/test_kalman_trend.js.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts +2 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.d.ts.map +1 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js +38 -0
- package/dist/analysis/trend_detection/tests/test_kalman_velocity_smoothing.js.map +1 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts +6 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.d.ts.map +1 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.js +732 -0
- package/dist/analysis/trend_detection/volatility_chart_generator.js.map +1 -0
- package/dist/bot.d.ts +49 -0
- package/dist/bot.d.ts.map +1 -0
- package/dist/bot.js +221 -0
- package/dist/bot.js.map +1 -0
- package/dist/credential-daemon.d.ts +64 -0
- package/dist/credential-daemon.d.ts.map +1 -0
- package/dist/credential-daemon.js +987 -0
- package/dist/credential-daemon.js.map +1 -0
- package/dist/dexbot.d.ts +87 -0
- package/dist/dexbot.d.ts.map +1 -0
- package/dist/dexbot.js +1222 -0
- package/dist/dexbot.js.map +1 -0
- package/dist/market_adapter/ama_signal_runner.d.ts +3 -0
- package/dist/market_adapter/ama_signal_runner.d.ts.map +1 -0
- package/dist/market_adapter/ama_signal_runner.js +175 -0
- package/dist/market_adapter/ama_signal_runner.js.map +1 -0
- package/dist/market_adapter/candle_utils.d.ts +57 -0
- package/dist/market_adapter/candle_utils.d.ts.map +1 -0
- package/dist/market_adapter/candle_utils.js +252 -0
- package/dist/market_adapter/candle_utils.js.map +1 -0
- package/dist/market_adapter/core/asymmetric_bounds.d.ts +20 -0
- package/dist/market_adapter/core/asymmetric_bounds.d.ts.map +1 -0
- package/dist/market_adapter/core/asymmetric_bounds.js +88 -0
- package/dist/market_adapter/core/asymmetric_bounds.js.map +1 -0
- package/dist/market_adapter/core/config_normalizers.d.ts +10 -0
- package/dist/market_adapter/core/config_normalizers.d.ts.map +1 -0
- package/dist/market_adapter/core/config_normalizers.js +24 -0
- package/dist/market_adapter/core/config_normalizers.js.map +1 -0
- package/dist/market_adapter/core/kibana_candles.d.ts +74 -0
- package/dist/market_adapter/core/kibana_candles.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_candles.js +249 -0
- package/dist/market_adapter/core/kibana_candles.js.map +1 -0
- package/dist/market_adapter/core/kibana_client.d.ts +27 -0
- package/dist/market_adapter/core/kibana_client.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_client.js +120 -0
- package/dist/market_adapter/core/kibana_client.js.map +1 -0
- package/dist/market_adapter/core/kibana_market_candles.d.ts +143 -0
- package/dist/market_adapter/core/kibana_market_candles.d.ts.map +1 -0
- package/dist/market_adapter/core/kibana_market_candles.js +170 -0
- package/dist/market_adapter/core/kibana_market_candles.js.map +1 -0
- package/dist/market_adapter/core/market_adapter_service.d.ts +210 -0
- package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -0
- package/dist/market_adapter/core/market_adapter_service.js +2328 -0
- package/dist/market_adapter/core/market_adapter_service.js.map +1 -0
- package/dist/market_adapter/core/strategies/ama.d.ts +2 -0
- package/dist/market_adapter/core/strategies/ama.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/ama.js +138 -0
- package/dist/market_adapter/core/strategies/ama.js.map +1 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts +50 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.js +143 -0
- package/dist/market_adapter/core/strategies/ama_slope_model.js.map +1 -0
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts +12 -0
- package/dist/market_adapter/core/strategies/atr/calculator.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/atr/calculator.js +47 -0
- package/dist/market_adapter/core/strategies/atr/calculator.js.map +1 -0
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts +32 -0
- package/dist/market_adapter/core/strategies/collateral_manager.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/collateral_manager.js +68 -0
- package/dist/market_adapter/core/strategies/collateral_manager.js.map +1 -0
- package/dist/market_adapter/core/strategies/regime_gate.d.ts +66 -0
- package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -0
- package/dist/market_adapter/core/strategies/regime_gate.js +189 -0
- package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -0
- package/dist/market_adapter/index.d.ts +10 -0
- package/dist/market_adapter/index.d.ts.map +1 -0
- package/dist/market_adapter/index.js +71 -0
- package/dist/market_adapter/index.js.map +1 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts +3 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.d.ts.map +1 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +1165 -0
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -0
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +54 -0
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -0
- package/dist/market_adapter/inputs/fetch_lp_data.js +743 -0
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -0
- package/dist/market_adapter/inputs/kibana_source.d.ts +68 -0
- package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -0
- package/dist/market_adapter/inputs/kibana_source.js +143 -0
- package/dist/market_adapter/inputs/kibana_source.js.map +1 -0
- package/dist/market_adapter/interval_utils.d.ts +6 -0
- package/dist/market_adapter/interval_utils.d.ts.map +1 -0
- package/dist/market_adapter/interval_utils.js +14 -0
- package/dist/market_adapter/interval_utils.js.map +1 -0
- package/dist/market_adapter/log_format.d.ts +16 -0
- package/dist/market_adapter/log_format.d.ts.map +1 -0
- package/dist/market_adapter/log_format.js +72 -0
- package/dist/market_adapter/log_format.js.map +1 -0
- package/dist/market_adapter/lp_chart_core.d.ts +6 -0
- package/dist/market_adapter/lp_chart_core.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_core.js +874 -0
- package/dist/market_adapter/lp_chart_core.js.map +1 -0
- package/dist/market_adapter/lp_chart_runner.d.ts +135 -0
- package/dist/market_adapter/lp_chart_runner.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_runner.js +337 -0
- package/dist/market_adapter/lp_chart_runner.js.map +1 -0
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts +23 -0
- package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -0
- package/dist/market_adapter/lp_chart_strategy_loader.js +169 -0
- package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -0
- package/dist/market_adapter/market_adapter.d.ts +133 -0
- package/dist/market_adapter/market_adapter.d.ts.map +1 -0
- package/dist/market_adapter/market_adapter.js +1331 -0
- package/dist/market_adapter/market_adapter.js.map +1 -0
- package/dist/market_adapter/merge_lp_data.d.ts +3 -0
- package/dist/market_adapter/merge_lp_data.d.ts.map +1 -0
- package/dist/market_adapter/merge_lp_data.js +125 -0
- package/dist/market_adapter/merge_lp_data.js.map +1 -0
- package/dist/market_adapter/test_helpers.d.ts +14 -0
- package/dist/market_adapter/test_helpers.d.ts.map +1 -0
- package/dist/market_adapter/test_helpers.js +22 -0
- package/dist/market_adapter/test_helpers.js.map +1 -0
- package/dist/market_adapter/utils/adapter_client.d.ts +20 -0
- package/dist/market_adapter/utils/adapter_client.d.ts.map +1 -0
- package/dist/market_adapter/utils/adapter_client.js +88 -0
- package/dist/market_adapter/utils/adapter_client.js.map +1 -0
- package/dist/market_adapter/utils/atomic_write.d.ts +9 -0
- package/dist/market_adapter/utils/atomic_write.d.ts.map +1 -0
- package/dist/market_adapter/utils/atomic_write.js +13 -0
- package/dist/market_adapter/utils/atomic_write.js.map +1 -0
- package/dist/market_adapter/utils/chain.d.ts +50 -0
- package/dist/market_adapter/utils/chain.d.ts.map +1 -0
- package/dist/market_adapter/utils/chain.js +196 -0
- package/dist/market_adapter/utils/chain.js.map +1 -0
- package/dist/market_adapter/utils/data_discovery.d.ts +6 -0
- package/dist/market_adapter/utils/data_discovery.d.ts.map +1 -0
- package/dist/market_adapter/utils/data_discovery.js +35 -0
- package/dist/market_adapter/utils/data_discovery.js.map +1 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts +15 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.d.ts.map +1 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js +60 -0
- package/dist/market_adapter/utils/dynamic_grid_snapshot.js.map +1 -0
- package/dist/market_adapter/utils/file_lock.d.ts +19 -0
- package/dist/market_adapter/utils/file_lock.d.ts.map +1 -0
- package/dist/market_adapter/utils/file_lock.js +191 -0
- package/dist/market_adapter/utils/file_lock.js.map +1 -0
- package/dist/market_adapter/utils/native_history.d.ts +19 -0
- package/dist/market_adapter/utils/native_history.d.ts.map +1 -0
- package/dist/market_adapter/utils/native_history.js +172 -0
- package/dist/market_adapter/utils/native_history.js.map +1 -0
- package/dist/market_adapter/utils/paths.d.ts +5 -0
- package/dist/market_adapter/utils/paths.d.ts.map +1 -0
- package/dist/market_adapter/utils/paths.js +7 -0
- package/dist/market_adapter/utils/paths.js.map +1 -0
- package/dist/modules/account_bots.d.ts +112 -0
- package/dist/modules/account_bots.d.ts.map +1 -0
- package/dist/modules/account_bots.js +1259 -0
- package/dist/modules/account_bots.js.map +1 -0
- package/dist/modules/account_orders.d.ts +273 -0
- package/dist/modules/account_orders.d.ts.map +1 -0
- package/dist/modules/account_orders.js +662 -0
- package/dist/modules/account_orders.js.map +1 -0
- package/dist/modules/authority_resolver.d.ts +2 -0
- package/dist/modules/authority_resolver.d.ts.map +1 -0
- package/dist/modules/authority_resolver.js +231 -0
- package/dist/modules/authority_resolver.js.map +1 -0
- package/dist/modules/bitshares-native/chain_client.d.ts +38 -0
- package/dist/modules/bitshares-native/chain_client.d.ts.map +1 -0
- package/dist/modules/bitshares-native/chain_client.js +322 -0
- package/dist/modules/bitshares-native/chain_client.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts +59 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.js +456 -0
- package/dist/modules/bitshares-native/crypto/ecc.browser.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.d.ts +66 -0
- package/dist/modules/bitshares-native/crypto/ecc.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc.js +557 -0
- package/dist/modules/bitshares-native/crypto/ecc.js.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts +2 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.d.ts.map +1 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.js +20 -0
- package/dist/modules/bitshares-native/crypto/ecc_selector.js.map +1 -0
- package/dist/modules/bitshares-native/index.d.ts +3 -0
- package/dist/modules/bitshares-native/index.d.ts.map +1 -0
- package/dist/modules/bitshares-native/index.js +32 -0
- package/dist/modules/bitshares-native/index.js.map +1 -0
- package/dist/modules/bitshares-native/resolvers.d.ts +40 -0
- package/dist/modules/bitshares-native/resolvers.d.ts.map +1 -0
- package/dist/modules/bitshares-native/resolvers.js +161 -0
- package/dist/modules/bitshares-native/resolvers.js.map +1 -0
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts +56 -0
- package/dist/modules/bitshares-native/serial/chain_constants.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/chain_constants.js +92 -0
- package/dist/modules/bitshares-native/serial/chain_constants.js.map +1 -0
- package/dist/modules/bitshares-native/serial/index.d.ts +10 -0
- package/dist/modules/bitshares-native/serial/index.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/index.js +14 -0
- package/dist/modules/bitshares-native/serial/index.js.map +1 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts +102 -0
- package/dist/modules/bitshares-native/serial/operations.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/operations.js +615 -0
- package/dist/modules/bitshares-native/serial/operations.js.map +1 -0
- package/dist/modules/bitshares-native/serial/serializer.d.ts +64 -0
- package/dist/modules/bitshares-native/serial/serializer.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/serializer.js +252 -0
- package/dist/modules/bitshares-native/serial/serializer.js.map +1 -0
- package/dist/modules/bitshares-native/serial/types.d.ts +120 -0
- package/dist/modules/bitshares-native/serial/types.d.ts.map +1 -0
- package/dist/modules/bitshares-native/serial/types.js +837 -0
- package/dist/modules/bitshares-native/serial/types.js.map +1 -0
- package/dist/modules/bitshares-native/signing_client.d.ts +6 -0
- package/dist/modules/bitshares-native/signing_client.d.ts.map +1 -0
- package/dist/modules/bitshares-native/signing_client.js +141 -0
- package/dist/modules/bitshares-native/signing_client.js.map +1 -0
- package/dist/modules/bitshares-native/subscriptions.d.ts +6 -0
- package/dist/modules/bitshares-native/subscriptions.d.ts.map +1 -0
- package/dist/modules/bitshares-native/subscriptions.js +865 -0
- package/dist/modules/bitshares-native/subscriptions.js.map +1 -0
- package/dist/modules/bitshares-native/transport.d.ts +51 -0
- package/dist/modules/bitshares-native/transport.d.ts.map +1 -0
- package/dist/modules/bitshares-native/transport.js +447 -0
- package/dist/modules/bitshares-native/transport.js.map +1 -0
- package/dist/modules/bitshares-native/tx/builder.d.ts +30 -0
- package/dist/modules/bitshares-native/tx/builder.d.ts.map +1 -0
- package/dist/modules/bitshares-native/tx/builder.js +262 -0
- package/dist/modules/bitshares-native/tx/builder.js.map +1 -0
- package/dist/modules/bitshares_client.d.ts +129 -0
- package/dist/modules/bitshares_client.d.ts.map +1 -0
- package/dist/modules/bitshares_client.js +627 -0
- package/dist/modules/bitshares_client.js.map +1 -0
- package/dist/modules/bot_settings.d.ts +33 -0
- package/dist/modules/bot_settings.d.ts.map +1 -0
- package/dist/modules/bot_settings.js +328 -0
- package/dist/modules/bot_settings.js.map +1 -0
- package/dist/modules/bots_file_lock.d.ts +88 -0
- package/dist/modules/bots_file_lock.d.ts.map +1 -0
- package/dist/modules/bots_file_lock.js +161 -0
- package/dist/modules/bots_file_lock.js.map +1 -0
- package/dist/modules/chain_keys.d.ts +302 -0
- package/dist/modules/chain_keys.d.ts.map +1 -0
- package/dist/modules/chain_keys.js +1095 -0
- package/dist/modules/chain_keys.js.map +1 -0
- package/dist/modules/chain_orders.d.ts +423 -0
- package/dist/modules/chain_orders.d.ts.map +1 -0
- package/dist/modules/chain_orders.js +1201 -0
- package/dist/modules/chain_orders.js.map +1 -0
- package/dist/modules/cli_whitelist_args.d.ts +6 -0
- package/dist/modules/cli_whitelist_args.d.ts.map +1 -0
- package/dist/modules/cli_whitelist_args.js +13 -0
- package/dist/modules/cli_whitelist_args.js.map +1 -0
- package/dist/modules/config.d.ts +57 -0
- package/dist/modules/config.d.ts.map +1 -0
- package/dist/modules/config.js +107 -0
- package/dist/modules/config.js.map +1 -0
- package/dist/modules/constants.d.ts +635 -0
- package/dist/modules/constants.d.ts.map +1 -0
- package/dist/modules/constants.js +1464 -0
- package/dist/modules/constants.js.map +1 -0
- package/dist/modules/cr_planner.d.ts +51 -0
- package/dist/modules/cr_planner.d.ts.map +1 -0
- package/dist/modules/cr_planner.js +299 -0
- package/dist/modules/cr_planner.js.map +1 -0
- package/dist/modules/credential_policy.d.ts +188 -0
- package/dist/modules/credential_policy.d.ts.map +1 -0
- package/dist/modules/credential_policy.js +1452 -0
- package/dist/modules/credential_policy.js.map +1 -0
- package/dist/modules/credential_runtime.d.ts +42 -0
- package/dist/modules/credential_runtime.d.ts.map +1 -0
- package/dist/modules/credential_runtime.js +148 -0
- package/dist/modules/credential_runtime.js.map +1 -0
- package/dist/modules/credential_session_cache.d.ts +36 -0
- package/dist/modules/credential_session_cache.d.ts.map +1 -0
- package/dist/modules/credential_session_cache.js +106 -0
- package/dist/modules/credential_session_cache.js.map +1 -0
- package/dist/modules/credit_runtime.d.ts +412 -0
- package/dist/modules/credit_runtime.d.ts.map +1 -0
- package/dist/modules/credit_runtime.js +2866 -0
- package/dist/modules/credit_runtime.js.map +1 -0
- package/dist/modules/crypto/browser_provider.d.ts +15 -0
- package/dist/modules/crypto/browser_provider.d.ts.map +1 -0
- package/dist/modules/crypto/browser_provider.js +113 -0
- package/dist/modules/crypto/browser_provider.js.map +1 -0
- package/dist/modules/crypto/index.d.ts +9 -0
- package/dist/modules/crypto/index.d.ts.map +1 -0
- package/dist/modules/crypto/index.js +44 -0
- package/dist/modules/crypto/index.js.map +1 -0
- package/dist/modules/crypto/node_provider.d.ts +15 -0
- package/dist/modules/crypto/node_provider.d.ts.map +1 -0
- package/dist/modules/crypto/node_provider.js +74 -0
- package/dist/modules/crypto/node_provider.js.map +1 -0
- package/dist/modules/crypto/provider.d.ts +34 -0
- package/dist/modules/crypto/provider.d.ts.map +1 -0
- package/dist/modules/crypto/provider.js +3 -0
- package/dist/modules/crypto/provider.js.map +1 -0
- package/dist/modules/crypto/pure_ripemd160.d.ts +8 -0
- package/dist/modules/crypto/pure_ripemd160.d.ts.map +1 -0
- package/dist/modules/crypto/pure_ripemd160.js +142 -0
- package/dist/modules/crypto/pure_ripemd160.js.map +1 -0
- package/dist/modules/crypto/pure_scrypt.d.ts +23 -0
- package/dist/modules/crypto/pure_scrypt.d.ts.map +1 -0
- package/dist/modules/crypto/pure_scrypt.js +161 -0
- package/dist/modules/crypto/pure_scrypt.js.map +1 -0
- package/dist/modules/crypto/pure_secp256k1.d.ts +29 -0
- package/dist/modules/crypto/pure_secp256k1.d.ts.map +1 -0
- package/dist/modules/crypto/pure_secp256k1.js +195 -0
- package/dist/modules/crypto/pure_secp256k1.js.map +1 -0
- package/dist/modules/crypto/sync.d.ts +13 -0
- package/dist/modules/crypto/sync.d.ts.map +1 -0
- package/dist/modules/crypto/sync.js +37 -0
- package/dist/modules/crypto/sync.js.map +1 -0
- package/dist/modules/dexbot_class.d.ts +1074 -0
- package/dist/modules/dexbot_class.d.ts.map +1 -0
- package/dist/modules/dexbot_class.js +4613 -0
- package/dist/modules/dexbot_class.js.map +1 -0
- package/dist/modules/dexbot_credential_client.d.ts +71 -0
- package/dist/modules/dexbot_credential_client.d.ts.map +1 -0
- package/dist/modules/dexbot_credential_client.js +224 -0
- package/dist/modules/dexbot_credential_client.js.map +1 -0
- package/dist/modules/dexbot_fill_runtime.d.ts +173 -0
- package/dist/modules/dexbot_fill_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_fill_runtime.js +217 -0
- package/dist/modules/dexbot_fill_runtime.js.map +1 -0
- package/dist/modules/dexbot_maintenance_runtime.d.ts +279 -0
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -0
- package/dist/modules/dexbot_maintenance_runtime.js +1613 -0
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -0
- package/dist/modules/env.d.ts +12 -0
- package/dist/modules/env.d.ts.map +1 -0
- package/dist/modules/env.js +57 -0
- package/dist/modules/env.js.map +1 -0
- package/dist/modules/fund_registry.d.ts +96 -0
- package/dist/modules/fund_registry.d.ts.map +1 -0
- package/dist/modules/fund_registry.js +261 -0
- package/dist/modules/fund_registry.js.map +1 -0
- package/dist/modules/general_settings.d.ts +36 -0
- package/dist/modules/general_settings.d.ts.map +1 -0
- package/dist/modules/general_settings.js +63 -0
- package/dist/modules/general_settings.js.map +1 -0
- package/dist/modules/graceful_shutdown.d.ts +86 -0
- package/dist/modules/graceful_shutdown.d.ts.map +1 -0
- package/dist/modules/graceful_shutdown.js +164 -0
- package/dist/modules/graceful_shutdown.js.map +1 -0
- package/dist/modules/key_store.d.ts +60 -0
- package/dist/modules/key_store.d.ts.map +1 -0
- package/dist/modules/key_store.js +215 -0
- package/dist/modules/key_store.js.map +1 -0
- package/dist/modules/launcher/bot_supervisor.d.ts +84 -0
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -0
- package/dist/modules/launcher/bot_supervisor.js +1067 -0
- package/dist/modules/launcher/bot_supervisor.js.map +1 -0
- package/dist/modules/launcher/child_env.d.ts +9 -0
- package/dist/modules/launcher/child_env.d.ts.map +1 -0
- package/dist/modules/launcher/child_env.js +78 -0
- package/dist/modules/launcher/child_env.js.map +1 -0
- package/dist/modules/launcher/credential_bootstrap.d.ts +22 -0
- package/dist/modules/launcher/credential_bootstrap.d.ts.map +1 -0
- package/dist/modules/launcher/credential_bootstrap.js +303 -0
- package/dist/modules/launcher/credential_bootstrap.js.map +1 -0
- package/dist/modules/launcher/credential_daemon.d.ts +32 -0
- package/dist/modules/launcher/credential_daemon.d.ts.map +1 -0
- package/dist/modules/launcher/credential_daemon.js +173 -0
- package/dist/modules/launcher/credential_daemon.js.map +1 -0
- package/dist/modules/launcher/credential_secret.d.ts +6 -0
- package/dist/modules/launcher/credential_secret.d.ts.map +1 -0
- package/dist/modules/launcher/credential_secret.js +15 -0
- package/dist/modules/launcher/credential_secret.js.map +1 -0
- package/dist/modules/launcher/foreign_cred_daemon.d.ts +2 -0
- package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -0
- package/dist/modules/launcher/foreign_cred_daemon.js +166 -0
- package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -0
- package/dist/modules/launcher/headless_password.d.ts +8 -0
- package/dist/modules/launcher/headless_password.d.ts.map +1 -0
- package/dist/modules/launcher/headless_password.js +33 -0
- package/dist/modules/launcher/headless_password.js.map +1 -0
- package/dist/modules/launcher/launch_modes.d.ts +36 -0
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -0
- package/dist/modules/launcher/launch_modes.js +129 -0
- package/dist/modules/launcher/launch_modes.js.map +1 -0
- package/dist/modules/launcher/market_adapter_runtime.d.ts +43 -0
- package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -0
- package/dist/modules/launcher/market_adapter_runtime.js +217 -0
- package/dist/modules/launcher/market_adapter_runtime.js.map +1 -0
- package/dist/modules/launcher/market_adapter_watchdog.d.ts +26 -0
- package/dist/modules/launcher/market_adapter_watchdog.d.ts.map +1 -0
- package/dist/modules/launcher/market_adapter_watchdog.js +214 -0
- package/dist/modules/launcher/market_adapter_watchdog.js.map +1 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts +89 -0
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -0
- package/dist/modules/launcher/monolithic_runtime.js +425 -0
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -0
- package/dist/modules/launcher/runtime_entry.d.ts +26 -0
- package/dist/modules/launcher/runtime_entry.d.ts.map +1 -0
- package/dist/modules/launcher/runtime_entry.js +49 -0
- package/dist/modules/launcher/runtime_entry.js.map +1 -0
- package/dist/modules/launcher/status_reporting.d.ts +48 -0
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -0
- package/dist/modules/launcher/status_reporting.js +113 -0
- package/dist/modules/launcher/status_reporting.js.map +1 -0
- package/dist/modules/launcher/supervisor_control.d.ts +6 -0
- package/dist/modules/launcher/supervisor_control.d.ts.map +1 -0
- package/dist/modules/launcher/supervisor_control.js +59 -0
- package/dist/modules/launcher/supervisor_control.js.map +1 -0
- package/dist/modules/logger.d.ts +2 -0
- package/dist/modules/logger.d.ts.map +1 -0
- package/dist/modules/logger.js +71 -0
- package/dist/modules/logger.js.map +1 -0
- package/dist/modules/market_adapter_whitelist.d.ts +22 -0
- package/dist/modules/market_adapter_whitelist.d.ts.map +1 -0
- package/dist/modules/market_adapter_whitelist.js +82 -0
- package/dist/modules/market_adapter_whitelist.js.map +1 -0
- package/dist/modules/node_health_cache.d.ts +55 -0
- package/dist/modules/node_health_cache.d.ts.map +1 -0
- package/dist/modules/node_health_cache.js +134 -0
- package/dist/modules/node_health_cache.js.map +1 -0
- package/dist/modules/node_manager.d.ts +215 -0
- package/dist/modules/node_manager.d.ts.map +1 -0
- package/dist/modules/node_manager.js +628 -0
- package/dist/modules/node_manager.js.map +1 -0
- package/dist/modules/order/accounting.d.ts +349 -0
- package/dist/modules/order/accounting.d.ts.map +1 -0
- package/dist/modules/order/accounting.js +1191 -0
- package/dist/modules/order/accounting.js.map +1 -0
- package/dist/modules/order/async_lock.d.ts +126 -0
- package/dist/modules/order/async_lock.d.ts.map +1 -0
- package/dist/modules/order/async_lock.js +195 -0
- package/dist/modules/order/async_lock.js.map +1 -0
- package/dist/modules/order/export.d.ts +129 -0
- package/dist/modules/order/export.d.ts.map +1 -0
- package/dist/modules/order/export.js +316 -0
- package/dist/modules/order/export.js.map +1 -0
- package/dist/modules/order/format.d.ts +158 -0
- package/dist/modules/order/format.d.ts.map +1 -0
- package/dist/modules/order/format.js +232 -0
- package/dist/modules/order/format.js.map +1 -0
- package/dist/modules/order/grid.d.ts +549 -0
- package/dist/modules/order/grid.d.ts.map +1 -0
- package/dist/modules/order/grid.js +1746 -0
- package/dist/modules/order/grid.js.map +1 -0
- package/dist/modules/order/grid_reconcile.d.ts +154 -0
- package/dist/modules/order/grid_reconcile.d.ts.map +1 -0
- package/dist/modules/order/grid_reconcile.js +1192 -0
- package/dist/modules/order/grid_reconcile.js.map +1 -0
- package/dist/modules/order/index.d.ts +55 -0
- package/dist/modules/order/index.d.ts.map +1 -0
- package/dist/modules/order/index.js +79 -0
- package/dist/modules/order/index.js.map +1 -0
- package/dist/modules/order/logger.d.ts +136 -0
- package/dist/modules/order/logger.d.ts.map +1 -0
- package/dist/modules/order/logger.js +614 -0
- package/dist/modules/order/logger.js.map +1 -0
- package/dist/modules/order/logger_state.d.ts +133 -0
- package/dist/modules/order/logger_state.d.ts.map +1 -0
- package/dist/modules/order/logger_state.js +170 -0
- package/dist/modules/order/logger_state.js.map +1 -0
- package/dist/modules/order/manager.d.ts +413 -0
- package/dist/modules/order/manager.d.ts.map +1 -0
- package/dist/modules/order/manager.js +1605 -0
- package/dist/modules/order/manager.js.map +1 -0
- package/dist/modules/order/processed_fill_store.d.ts +135 -0
- package/dist/modules/order/processed_fill_store.d.ts.map +1 -0
- package/dist/modules/order/processed_fill_store.js +288 -0
- package/dist/modules/order/processed_fill_store.js.map +1 -0
- package/dist/modules/order/runner.d.ts +70 -0
- package/dist/modules/order/runner.d.ts.map +1 -0
- package/dist/modules/order/runner.js +140 -0
- package/dist/modules/order/runner.js.map +1 -0
- package/dist/modules/order/strategy.d.ts +196 -0
- package/dist/modules/order/strategy.d.ts.map +1 -0
- package/dist/modules/order/strategy.js +398 -0
- package/dist/modules/order/strategy.js.map +1 -0
- package/dist/modules/order/sync_engine.d.ts +386 -0
- package/dist/modules/order/sync_engine.d.ts.map +1 -0
- package/dist/modules/order/sync_engine.js +1459 -0
- package/dist/modules/order/sync_engine.js.map +1 -0
- package/dist/modules/order/utils/math.d.ts +677 -0
- package/dist/modules/order/utils/math.d.ts.map +1 -0
- package/dist/modules/order/utils/math.js +1172 -0
- package/dist/modules/order/utils/math.js.map +1 -0
- package/dist/modules/order/utils/order.d.ts +572 -0
- package/dist/modules/order/utils/order.d.ts.map +1 -0
- package/dist/modules/order/utils/order.js +1145 -0
- package/dist/modules/order/utils/order.js.map +1 -0
- package/dist/modules/order/utils/system.d.ts +268 -0
- package/dist/modules/order/utils/system.d.ts.map +1 -0
- package/dist/modules/order/utils/system.js +1261 -0
- package/dist/modules/order/utils/system.js.map +1 -0
- package/dist/modules/order/utils/validate.d.ts +280 -0
- package/dist/modules/order/utils/validate.d.ts.map +1 -0
- package/dist/modules/order/utils/validate.js +918 -0
- package/dist/modules/order/utils/validate.js.map +1 -0
- package/dist/modules/order/working_grid.d.ts +212 -0
- package/dist/modules/order/working_grid.d.ts.map +1 -0
- package/dist/modules/order/working_grid.js +279 -0
- package/dist/modules/order/working_grid.js.map +1 -0
- package/dist/modules/path_api.d.ts +32 -0
- package/dist/modules/path_api.d.ts.map +1 -0
- package/dist/modules/path_api.js +148 -0
- package/dist/modules/path_api.js.map +1 -0
- package/dist/modules/paths.d.ts +58 -0
- package/dist/modules/paths.d.ts.map +1 -0
- package/dist/modules/paths.js +82 -0
- package/dist/modules/paths.js.map +1 -0
- package/dist/modules/process_discovery.d.ts +58 -0
- package/dist/modules/process_discovery.d.ts.map +1 -0
- package/dist/modules/process_discovery.js +265 -0
- package/dist/modules/process_discovery.js.map +1 -0
- package/dist/modules/runtime.d.ts +34 -0
- package/dist/modules/runtime.d.ts.map +1 -0
- package/dist/modules/runtime.js +98 -0
- package/dist/modules/runtime.js.map +1 -0
- package/dist/modules/runtime_settings.d.ts +12 -0
- package/dist/modules/runtime_settings.d.ts.map +1 -0
- package/dist/modules/runtime_settings.js +122 -0
- package/dist/modules/runtime_settings.js.map +1 -0
- package/dist/modules/settings_merge.d.ts +38 -0
- package/dist/modules/settings_merge.d.ts.map +1 -0
- package/dist/modules/settings_merge.js +246 -0
- package/dist/modules/settings_merge.js.map +1 -0
- package/dist/modules/storage/browser_adapter.d.ts +56 -0
- package/dist/modules/storage/browser_adapter.d.ts.map +1 -0
- package/dist/modules/storage/browser_adapter.js +231 -0
- package/dist/modules/storage/browser_adapter.js.map +1 -0
- package/dist/modules/storage/index.d.ts +28 -0
- package/dist/modules/storage/index.d.ts.map +1 -0
- package/dist/modules/storage/index.js +52 -0
- package/dist/modules/storage/index.js.map +1 -0
- package/dist/modules/storage/node_adapter.d.ts +49 -0
- package/dist/modules/storage/node_adapter.d.ts.map +1 -0
- package/dist/modules/storage/node_adapter.js +167 -0
- package/dist/modules/storage/node_adapter.js.map +1 -0
- package/dist/modules/storage/types.d.ts +92 -0
- package/dist/modules/storage/types.d.ts.map +1 -0
- package/dist/modules/storage/types.js +3 -0
- package/dist/modules/storage/types.js.map +1 -0
- package/dist/modules/types.d.ts +1382 -0
- package/dist/modules/types.d.ts.map +1 -0
- package/dist/modules/types.js +11 -0
- package/dist/modules/types.js.map +1 -0
- package/dist/modules/utils/base58check.d.ts +12 -0
- package/dist/modules/utils/base58check.d.ts.map +1 -0
- package/dist/modules/utils/base58check.js +112 -0
- package/dist/modules/utils/base58check.js.map +1 -0
- package/dist/modules/utils/build_dir.d.ts +7 -0
- package/dist/modules/utils/build_dir.d.ts.map +1 -0
- package/dist/modules/utils/build_dir.js +8 -0
- package/dist/modules/utils/build_dir.js.map +1 -0
- package/dist/modules/utils/fs_utils.d.ts +25 -0
- package/dist/modules/utils/fs_utils.d.ts.map +1 -0
- package/dist/modules/utils/fs_utils.js +27 -0
- package/dist/modules/utils/fs_utils.js.map +1 -0
- package/dist/modules/utils/math_utils.d.ts +10 -0
- package/dist/modules/utils/math_utils.d.ts.map +1 -0
- package/dist/modules/utils/math_utils.js +17 -0
- package/dist/modules/utils/math_utils.js.map +1 -0
- package/dist/modules/validate_profiles.d.ts +37 -0
- package/dist/modules/validate_profiles.d.ts.map +1 -0
- package/dist/modules/validate_profiles.js +369 -0
- package/dist/modules/validate_profiles.js.map +1 -0
- package/dist/pm2.d.ts +167 -0
- package/dist/pm2.d.ts.map +1 -0
- package/dist/pm2.js +998 -0
- package/dist/pm2.js.map +1 -0
- package/dist/scripts/analyze-git.d.ts +11 -0
- package/dist/scripts/analyze-git.d.ts.map +1 -0
- package/dist/scripts/analyze-git.js +851 -0
- package/dist/scripts/analyze-git.js.map +1 -0
- package/dist/scripts/analyze-orders.d.ts +17 -0
- package/dist/scripts/analyze-orders.d.ts.map +1 -0
- package/dist/scripts/analyze-orders.js +1568 -0
- package/dist/scripts/analyze-orders.js.map +1 -0
- package/dist/scripts/diagnose-kibana-candles.d.ts +3 -0
- package/dist/scripts/diagnose-kibana-candles.d.ts.map +1 -0
- package/dist/scripts/diagnose-kibana-candles.js +82 -0
- package/dist/scripts/diagnose-kibana-candles.js.map +1 -0
- package/dist/scripts/diagnose-pool-history.d.ts +3 -0
- package/dist/scripts/diagnose-pool-history.d.ts.map +1 -0
- package/dist/scripts/diagnose-pool-history.js +296 -0
- package/dist/scripts/diagnose-pool-history.js.map +1 -0
- package/dist/scripts/divergence-calc.d.ts +26 -0
- package/dist/scripts/divergence-calc.d.ts.map +1 -0
- package/dist/scripts/divergence-calc.js +119 -0
- package/dist/scripts/divergence-calc.js.map +1 -0
- package/dist/scripts/generate_lp_chart.d.ts +31 -0
- package/dist/scripts/generate_lp_chart.d.ts.map +1 -0
- package/dist/scripts/generate_lp_chart.js +92 -0
- package/dist/scripts/generate_lp_chart.js.map +1 -0
- package/dist/scripts/generate_mainnet_corpus_report.d.ts +24 -0
- package/dist/scripts/generate_mainnet_corpus_report.d.ts.map +1 -0
- package/dist/scripts/generate_mainnet_corpus_report.js +237 -0
- package/dist/scripts/generate_mainnet_corpus_report.js.map +1 -0
- package/dist/scripts/generate_market_adapter_whitelist.d.ts +2 -0
- package/dist/scripts/generate_market_adapter_whitelist.d.ts.map +1 -0
- package/dist/scripts/generate_market_adapter_whitelist.js +111 -0
- package/dist/scripts/generate_market_adapter_whitelist.js.map +1 -0
- package/dist/scripts/migrate_bot_keys.d.ts +6 -0
- package/dist/scripts/migrate_bot_keys.d.ts.map +1 -0
- package/dist/scripts/migrate_bot_keys.js +301 -0
- package/dist/scripts/migrate_bot_keys.js.map +1 -0
- package/dist/scripts/native_release_gates.d.ts +3 -0
- package/dist/scripts/native_release_gates.d.ts.map +1 -0
- package/dist/scripts/native_release_gates.js +52 -0
- package/dist/scripts/native_release_gates.js.map +1 -0
- package/dist/scripts/print_grid.d.ts +16 -0
- package/dist/scripts/print_grid.d.ts.map +1 -0
- package/dist/scripts/print_grid.js +80 -0
- package/dist/scripts/print_grid.js.map +1 -0
- package/dist/scripts/run-tests.d.ts +2 -0
- package/dist/scripts/run-tests.d.ts.map +1 -0
- package/dist/scripts/run-tests.js +49 -0
- package/dist/scripts/run-tests.js.map +1 -0
- package/dist/scripts/sync-version.d.ts +14 -0
- package/dist/scripts/sync-version.d.ts.map +1 -0
- package/dist/scripts/sync-version.js +158 -0
- package/dist/scripts/sync-version.js.map +1 -0
- package/dist/scripts/test-credit-renewal.d.ts +2 -0
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -0
- package/dist/scripts/test-credit-renewal.js +329 -0
- package/dist/scripts/test-credit-renewal.js.map +1 -0
- package/dist/scripts/update.d.ts +24 -0
- package/dist/scripts/update.d.ts.map +1 -0
- package/dist/scripts/update.js +650 -0
- package/dist/scripts/update.js.map +1 -0
- package/dist/scripts/validate_bots.d.ts +16 -0
- package/dist/scripts/validate_bots.d.ts.map +1 -0
- package/dist/scripts/validate_bots.js +106 -0
- package/dist/scripts/validate_bots.js.map +1 -0
- package/dist/scripts/verify-browser-bundle.d.ts +22 -0
- package/dist/scripts/verify-browser-bundle.d.ts.map +1 -0
- package/dist/scripts/verify-browser-bundle.js +339 -0
- package/dist/scripts/verify-browser-bundle.js.map +1 -0
- package/dist/unlock.d.ts +48 -0
- package/dist/unlock.d.ts.map +1 -0
- package/dist/unlock.js +925 -0
- package/dist/unlock.js.map +1 -0
- package/package.json +112 -0
- package/scripts/README.md +356 -0
- package/scripts/clear-all.sh +195 -0
- package/scripts/clear-logs.sh +95 -0
- package/scripts/clear-market-adapter.sh +196 -0
- package/scripts/clear-orders.sh +113 -0
- package/scripts/create-bot-symlinks.sh +51 -0
- package/scripts/postinstall.js +9 -0
- package/scripts/reset-settings.sh +118 -0
|
@@ -0,0 +1,918 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* modules/order/utils/validate.ts
|
|
4
|
+
*
|
|
5
|
+
* Pure functions for order validation, grid reconciliation, and immutable mutations.
|
|
6
|
+
*
|
|
7
|
+
* ===============================================================================
|
|
8
|
+
* TABLE OF CONTENTS
|
|
9
|
+
* ===============================================================================
|
|
10
|
+
*
|
|
11
|
+
* SECTION 1: EXTERNAL DEPENDENCIES
|
|
12
|
+
*
|
|
13
|
+
* SECTION 2: VALIDATION
|
|
14
|
+
* - validateOrder()
|
|
15
|
+
* - validateGridForPersistence()
|
|
16
|
+
* - calculateRequiredFunds()
|
|
17
|
+
* - validateWorkingGridFunds()
|
|
18
|
+
* - checkFundDrift()
|
|
19
|
+
*
|
|
20
|
+
* SECTION 3: GRID RECONCILIATION (COW Pipeline)
|
|
21
|
+
* - reconcileGrid()
|
|
22
|
+
* - optimizeRebalanceActions()
|
|
23
|
+
* - summarizeActions()
|
|
24
|
+
* - hasActionForOrder()
|
|
25
|
+
* - removeActionsForOrder()
|
|
26
|
+
* - projectTargetToWorkingGrid()
|
|
27
|
+
* - buildStateUpdates()
|
|
28
|
+
* - buildAbortedResult()
|
|
29
|
+
* - buildSuccessResult()
|
|
30
|
+
* - evaluateCommit()
|
|
31
|
+
*
|
|
32
|
+
* ===============================================================================
|
|
33
|
+
*/
|
|
34
|
+
// ===============================================================================
|
|
35
|
+
// SECTION 1: EXTERNAL DEPENDENCIES
|
|
36
|
+
// ===============================================================================
|
|
37
|
+
const { ORDER_STATES, ORDER_TYPES, COW_ACTIONS, GRID_LIMITS } = require('../../constants');
|
|
38
|
+
const { floatToBlockchainInt, blockchainToFloat, getPrecisionSlack, getDoubleDustThreshold } = require('./math');
|
|
39
|
+
const { isOrderOnChain, isPhantomOrder, convertToSpreadPlaceholder } = require('./order');
|
|
40
|
+
const Format = require('../format');
|
|
41
|
+
const { isValidNumber, toFiniteNumber } = Format;
|
|
42
|
+
const { deepFreeze, cloneMap } = require('./system');
|
|
43
|
+
// Pre-computed valid sets
|
|
44
|
+
const VALID_ORDER_STATES = new Set(Object.values(ORDER_STATES));
|
|
45
|
+
const VALID_ORDER_TYPES = new Set(Object.values(ORDER_TYPES));
|
|
46
|
+
// ===============================================================================
|
|
47
|
+
// SECTION 2: VALIDATION
|
|
48
|
+
// ===============================================================================
|
|
49
|
+
/**
|
|
50
|
+
* Validate a complete order object
|
|
51
|
+
* @param {Object} order - Order to validate
|
|
52
|
+
* @param {Object} oldOrder - Previous order state (for context)
|
|
53
|
+
* @param {string} context - Operation context for error messages
|
|
54
|
+
* @returns {Object} Validation result
|
|
55
|
+
*/
|
|
56
|
+
function validateOrder(order, oldOrder = null, context = 'validate') {
|
|
57
|
+
const errors = [];
|
|
58
|
+
const warnings = [];
|
|
59
|
+
let normalizedOrder = { ...(oldOrder || {}), ...order };
|
|
60
|
+
if (!order || !order.id) {
|
|
61
|
+
errors.push({ code: 'MISSING_ID', message: 'Refusing to update order: missing ID' });
|
|
62
|
+
return { isValid: false, errors, warnings, normalizedOrder: null };
|
|
63
|
+
}
|
|
64
|
+
if (!normalizedOrder.type && normalizedOrder.state === ORDER_STATES.VIRTUAL) {
|
|
65
|
+
const placeholderSize = toFiniteNumber(normalizedOrder.size);
|
|
66
|
+
if (placeholderSize === 0) {
|
|
67
|
+
normalizedOrder.type = ORDER_TYPES.SPREAD;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
if (!VALID_ORDER_STATES.has(normalizedOrder.state)) {
|
|
71
|
+
errors.push({
|
|
72
|
+
code: 'INVALID_STATE',
|
|
73
|
+
message: `Refusing to update order ${order.id}: invalid state '${normalizedOrder.state}' (context: ${context})`
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
if (!VALID_ORDER_TYPES.has(normalizedOrder.type)) {
|
|
77
|
+
errors.push({
|
|
78
|
+
code: 'INVALID_TYPE',
|
|
79
|
+
message: `Refusing to update order ${order.id}: invalid type '${normalizedOrder.type}' (context: ${context})`
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
if (normalizedOrder.type === ORDER_TYPES.SPREAD && toFiniteNumber(normalizedOrder.size) !== 0) {
|
|
83
|
+
warnings.push({
|
|
84
|
+
code: 'SPREAD_SIZE_NORMALIZED',
|
|
85
|
+
message: `[INVARIANT] Normalizing SPREAD order ${order.id} size ${normalizedOrder.size} -> 0 (context: ${context})`
|
|
86
|
+
});
|
|
87
|
+
normalizedOrder.size = 0;
|
|
88
|
+
}
|
|
89
|
+
const isOnChainState = (normalizedOrder.state === ORDER_STATES.ACTIVE ||
|
|
90
|
+
normalizedOrder.state === ORDER_STATES.PARTIAL);
|
|
91
|
+
if (normalizedOrder.type === ORDER_TYPES.SPREAD && isOnChainState) {
|
|
92
|
+
errors.push({
|
|
93
|
+
code: 'ILLEGAL_SPREAD_STATE',
|
|
94
|
+
message: `ILLEGAL STATE: Refusing to move SPREAD order ${order.id} to ${normalizedOrder.state}. SPREAD orders must remain VIRTUAL.`,
|
|
95
|
+
isFatal: true
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
if (isPhantomOrder(normalizedOrder)) {
|
|
99
|
+
errors.push({
|
|
100
|
+
code: 'PHANTOM_ORDER',
|
|
101
|
+
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.`,
|
|
102
|
+
autoCorrect: {
|
|
103
|
+
state: ORDER_STATES.VIRTUAL,
|
|
104
|
+
orderId: null,
|
|
105
|
+
rawOnChain: null,
|
|
106
|
+
size: 0
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
if (normalizedOrder.type === ORDER_TYPES.BUY || normalizedOrder.type === ORDER_TYPES.SELL) {
|
|
111
|
+
normalizedOrder.committedSide = normalizedOrder.type;
|
|
112
|
+
}
|
|
113
|
+
else if (!normalizedOrder.committedSide && oldOrder) {
|
|
114
|
+
if (oldOrder.committedSide) {
|
|
115
|
+
normalizedOrder.committedSide = oldOrder.committedSide;
|
|
116
|
+
}
|
|
117
|
+
else if (oldOrder.type === ORDER_TYPES.BUY || oldOrder.type === ORDER_TYPES.SELL) {
|
|
118
|
+
normalizedOrder.committedSide = oldOrder.type;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
isValid: errors.length === 0 || !errors.some(e => e.isFatal),
|
|
123
|
+
errors,
|
|
124
|
+
warnings,
|
|
125
|
+
normalizedOrder
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Validate grid state for persistence
|
|
130
|
+
* @param {Map} orders - Master grid orders
|
|
131
|
+
* @param {Object} accountTotals - Current account totals
|
|
132
|
+
* @returns {Object} Validation result
|
|
133
|
+
*/
|
|
134
|
+
function validateGridForPersistence(orders, accountTotals) {
|
|
135
|
+
for (const order of orders.values()) {
|
|
136
|
+
if (isPhantomOrder(order)) {
|
|
137
|
+
return {
|
|
138
|
+
isValid: false,
|
|
139
|
+
reason: `Phantom order detected: order ${order.id} is ${order.state} but has no orderId`
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (!accountTotals || !isValidNumber(accountTotals.buy) || !isValidNumber(accountTotals.sell)) {
|
|
144
|
+
return {
|
|
145
|
+
isValid: false,
|
|
146
|
+
reason: 'Account totals not initialized'
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
return { isValid: true, reason: null };
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Calculate required funds from a grid
|
|
153
|
+
* @param {Map|WorkingGrid} grid - Grid to analyze
|
|
154
|
+
* @param {Object} precisions - Precision config
|
|
155
|
+
* @returns {Object} Required funds { buyInt, sellInt, buy, sell }
|
|
156
|
+
*/
|
|
157
|
+
function calculateRequiredFunds(grid, precisions = {}) {
|
|
158
|
+
const buyPrecision = precisions.buyPrecision;
|
|
159
|
+
const sellPrecision = precisions.sellPrecision;
|
|
160
|
+
let buyRequiredInt = 0;
|
|
161
|
+
let sellRequiredInt = 0;
|
|
162
|
+
for (const order of grid.values()) {
|
|
163
|
+
const size = toFiniteNumber(order.size ?? order.amount);
|
|
164
|
+
const state = order.state;
|
|
165
|
+
const isActive = state === 'active' || state === 'partial';
|
|
166
|
+
if (isActive && isOrderOnChain(order)) {
|
|
167
|
+
if (order.type === 'buy') {
|
|
168
|
+
buyRequiredInt += floatToBlockchainInt(size, buyPrecision);
|
|
169
|
+
}
|
|
170
|
+
else if (order.type === 'sell') {
|
|
171
|
+
sellRequiredInt += floatToBlockchainInt(size, sellPrecision);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
buyInt: buyRequiredInt,
|
|
177
|
+
sellInt: sellRequiredInt,
|
|
178
|
+
buy: blockchainToFloat(buyRequiredInt, buyPrecision),
|
|
179
|
+
sell: blockchainToFloat(sellRequiredInt, sellPrecision)
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Validate working grid against available funds
|
|
184
|
+
* @param {WorkingGrid} workingGrid - Grid to validate
|
|
185
|
+
* @param {Object} projectedFunds - Available funds
|
|
186
|
+
* @param {Object} precisions - Asset precisions
|
|
187
|
+
* @param {Object} assets - Asset metadata
|
|
188
|
+
* @returns {Object} Validation result
|
|
189
|
+
*/
|
|
190
|
+
function validateWorkingGridFunds(workingGrid, projectedFunds, precisions = {}, assets = null) {
|
|
191
|
+
const buyPrecision = precisions.buyPrecision ?? assets?.assetB?.precision;
|
|
192
|
+
const sellPrecision = precisions.sellPrecision ?? assets?.assetA?.precision;
|
|
193
|
+
const required = calculateRequiredFunds(workingGrid, { buyPrecision, sellPrecision });
|
|
194
|
+
const availableBuy = isValidNumber(projectedFunds?.allocatedBuy)
|
|
195
|
+
? Number(projectedFunds.allocatedBuy)
|
|
196
|
+
: isValidNumber(projectedFunds?.chainTotalBuy)
|
|
197
|
+
? Number(projectedFunds.chainTotalBuy)
|
|
198
|
+
: toFiniteNumber(projectedFunds?.freeBuy ?? projectedFunds?.chainFreeBuy);
|
|
199
|
+
const availableSell = isValidNumber(projectedFunds?.allocatedSell)
|
|
200
|
+
? Number(projectedFunds.allocatedSell)
|
|
201
|
+
: isValidNumber(projectedFunds?.chainTotalSell)
|
|
202
|
+
? Number(projectedFunds.chainTotalSell)
|
|
203
|
+
: toFiniteNumber(projectedFunds?.freeSell ?? projectedFunds?.chainFreeSell);
|
|
204
|
+
const shortfalls = [];
|
|
205
|
+
const availableBuyInt = floatToBlockchainInt(availableBuy, buyPrecision);
|
|
206
|
+
const availableSellInt = floatToBlockchainInt(availableSell, sellPrecision);
|
|
207
|
+
if (required.buyInt > availableBuyInt) {
|
|
208
|
+
const requiredBuyFloat = blockchainToFloat(required.buyInt, buyPrecision);
|
|
209
|
+
const availableBuyFloat = blockchainToFloat(availableBuyInt, buyPrecision);
|
|
210
|
+
shortfalls.push({
|
|
211
|
+
asset: assets?.assetB?.symbol || 'buyAsset',
|
|
212
|
+
required: requiredBuyFloat,
|
|
213
|
+
available: availableBuyFloat,
|
|
214
|
+
deficit: blockchainToFloat(required.buyInt - availableBuyInt, buyPrecision)
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (required.sellInt > availableSellInt) {
|
|
218
|
+
const requiredSellFloat = blockchainToFloat(required.sellInt, sellPrecision);
|
|
219
|
+
const availableSellFloat = blockchainToFloat(availableSellInt, sellPrecision);
|
|
220
|
+
shortfalls.push({
|
|
221
|
+
asset: assets?.assetA?.symbol || 'sellAsset',
|
|
222
|
+
required: requiredSellFloat,
|
|
223
|
+
available: availableSellFloat,
|
|
224
|
+
deficit: blockchainToFloat(required.sellInt - availableSellInt, sellPrecision)
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
isValid: shortfalls.length === 0,
|
|
229
|
+
reason: shortfalls.length > 0 ? `Fund shortfall: ${JSON.stringify(shortfalls)}` : null,
|
|
230
|
+
shortfalls,
|
|
231
|
+
required,
|
|
232
|
+
available: { buy: availableBuy, sell: availableSell }
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Check fund drift against blockchain totals
|
|
237
|
+
* @param {Map} orders - Current orders
|
|
238
|
+
* @param {Object} accountTotals - Blockchain account totals
|
|
239
|
+
* @param {Object} assets - Asset metadata
|
|
240
|
+
* @returns {Object} Drift check result
|
|
241
|
+
*/
|
|
242
|
+
function checkFundDrift(orders, accountTotals, assets = null, gridLimits = null) {
|
|
243
|
+
let gridBuy = 0, gridSell = 0;
|
|
244
|
+
for (const order of Array.from(orders.values())) {
|
|
245
|
+
const size = toFiniteNumber(order.size);
|
|
246
|
+
if (size <= 0 || !isOrderOnChain(order))
|
|
247
|
+
continue;
|
|
248
|
+
if (order.type === 'buy')
|
|
249
|
+
gridBuy += size;
|
|
250
|
+
else if (order.type === 'sell')
|
|
251
|
+
gridSell += size;
|
|
252
|
+
}
|
|
253
|
+
const chainFreeBuy = accountTotals?.buyFree || 0;
|
|
254
|
+
const chainFreeSell = accountTotals?.sellFree || 0;
|
|
255
|
+
const actualBuy = accountTotals?.buy || 0;
|
|
256
|
+
const actualSell = accountTotals?.sell || 0;
|
|
257
|
+
const expectedBuy = chainFreeBuy + gridBuy;
|
|
258
|
+
const expectedSell = chainFreeSell + gridSell;
|
|
259
|
+
const driftBuy = Math.abs(actualBuy - expectedBuy);
|
|
260
|
+
const driftSell = Math.abs(actualSell - expectedSell);
|
|
261
|
+
const buyPrecision = assets?.assetB?.precision;
|
|
262
|
+
const sellPrecision = assets?.assetA?.precision;
|
|
263
|
+
if (!isValidNumber(buyPrecision) || !isValidNumber(sellPrecision)) {
|
|
264
|
+
return { isValid: true, reason: 'Skipped: precision not available', driftBuy, driftSell };
|
|
265
|
+
}
|
|
266
|
+
const precisionSlackBuy = getPrecisionSlack(buyPrecision);
|
|
267
|
+
const precisionSlackSell = getPrecisionSlack(sellPrecision);
|
|
268
|
+
const fundInvariantTolerance = gridLimits?.FUND_INVARIANT_PERCENT_TOLERANCE ?? GRID_LIMITS.FUND_INVARIANT_PERCENT_TOLERANCE;
|
|
269
|
+
const percentTolerance = fundInvariantTolerance / 100;
|
|
270
|
+
const allowedDriftBuy = Math.max(precisionSlackBuy, actualBuy * percentTolerance);
|
|
271
|
+
const allowedDriftSell = Math.max(precisionSlackSell, actualSell * percentTolerance);
|
|
272
|
+
const buyOk = driftBuy <= allowedDriftBuy;
|
|
273
|
+
const sellOk = driftSell <= allowedDriftSell;
|
|
274
|
+
return {
|
|
275
|
+
isValid: buyOk && sellOk,
|
|
276
|
+
driftBuy,
|
|
277
|
+
driftSell,
|
|
278
|
+
allowedDriftBuy,
|
|
279
|
+
allowedDriftSell,
|
|
280
|
+
reason: !buyOk
|
|
281
|
+
? `BUY drift ${Format.formatAmountByPrecision(driftBuy, buyPrecision)} > ${Format.formatAmountByPrecision(allowedDriftBuy, buyPrecision)}`
|
|
282
|
+
: !sellOk
|
|
283
|
+
? `SELL drift ${Format.formatAmountByPrecision(driftSell, sellPrecision)} > ${Format.formatAmountByPrecision(allowedDriftSell, sellPrecision)}`
|
|
284
|
+
: null
|
|
285
|
+
};
|
|
286
|
+
}
|
|
287
|
+
// ===============================================================================
|
|
288
|
+
// SECTION 3: GRID RECONCILIATION (COW Pipeline)
|
|
289
|
+
// ===============================================================================
|
|
290
|
+
/**
|
|
291
|
+
* Reconcile target grid against master state
|
|
292
|
+
* @param {Map} masterGrid - Current master grid
|
|
293
|
+
* @param {Map} targetGrid - Target state from strategy
|
|
294
|
+
* @param {number} targetBoundary - Target boundary index
|
|
295
|
+
* @param {Object} options - Options
|
|
296
|
+
* @returns {Object} Reconciliation result with actions
|
|
297
|
+
*/
|
|
298
|
+
function reconcileGrid(masterGrid, targetGrid, targetBoundary, options = {}) {
|
|
299
|
+
const { logger = null, dustThresholdPercent = 5 } = options;
|
|
300
|
+
const actions = [];
|
|
301
|
+
const surplusesBuy = [];
|
|
302
|
+
const surplusesSell = [];
|
|
303
|
+
const holesBuy = [];
|
|
304
|
+
const holesSell = [];
|
|
305
|
+
const isCreateHealthy = (order) => {
|
|
306
|
+
if (!order || order.size <= 0)
|
|
307
|
+
return false;
|
|
308
|
+
const idealSize = toFiniteNumber(order.idealSize || order.size);
|
|
309
|
+
if (idealSize <= 0)
|
|
310
|
+
return true;
|
|
311
|
+
const minHealthy = getDoubleDustThreshold(idealSize, dustThresholdPercent);
|
|
312
|
+
if (order.size < minHealthy) {
|
|
313
|
+
if (logger) {
|
|
314
|
+
logger(`[RECONCILE] Skipping dust target order: ${order.id} ` +
|
|
315
|
+
`size=${Format.formatAmount8(order.size)} < minHealthy=${Format.formatAmount8(minHealthy)} ` +
|
|
316
|
+
`(ideal=${Format.formatAmount8(idealSize)}, threshold=${dustThresholdPercent * 2}%)`, 'warn');
|
|
317
|
+
}
|
|
318
|
+
return false;
|
|
319
|
+
}
|
|
320
|
+
return true;
|
|
321
|
+
};
|
|
322
|
+
let validatedBoundary = targetBoundary;
|
|
323
|
+
if (targetBoundary !== null) {
|
|
324
|
+
const maxIdx = Math.max(0, masterGrid.size - 1);
|
|
325
|
+
if (targetBoundary < 0 || targetBoundary > maxIdx) {
|
|
326
|
+
const clamped = Math.max(0, Math.min(maxIdx, targetBoundary));
|
|
327
|
+
if (logger) {
|
|
328
|
+
logger(`[RECONCILE] Clamping target boundary ${targetBoundary} -> ${clamped} (max ${maxIdx}).`, 'warn');
|
|
329
|
+
}
|
|
330
|
+
validatedBoundary = clamped;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
for (const [id, targetOrder] of targetGrid) {
|
|
334
|
+
const masterOrder = masterGrid.get(id);
|
|
335
|
+
if (!masterOrder || masterOrder.state === ORDER_STATES.VIRTUAL) {
|
|
336
|
+
// Slot is empty or virtual - check if we need to fill it
|
|
337
|
+
if (targetOrder.size > 0 && targetOrder.state === ORDER_STATES.ACTIVE) {
|
|
338
|
+
// This is a hole that needs filling
|
|
339
|
+
if (targetOrder.type === ORDER_TYPES.BUY) {
|
|
340
|
+
holesBuy.push({ id, order: targetOrder });
|
|
341
|
+
}
|
|
342
|
+
else if (targetOrder.type === ORDER_TYPES.SELL) {
|
|
343
|
+
holesSell.push({ id, order: targetOrder });
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
continue;
|
|
347
|
+
}
|
|
348
|
+
if (masterOrder.type !== targetOrder.type) {
|
|
349
|
+
actions.push({ type: COW_ACTIONS.CANCEL, id, orderId: masterOrder.orderId, reason: 'type-mismatch' });
|
|
350
|
+
if (targetOrder.size > 0 && targetOrder.state === ORDER_STATES.ACTIVE && isCreateHealthy(targetOrder)) {
|
|
351
|
+
actions.push({ type: COW_ACTIONS.CREATE, id, order: targetOrder });
|
|
352
|
+
}
|
|
353
|
+
continue;
|
|
354
|
+
}
|
|
355
|
+
// If master is on-chain but target should be VIRTUAL (outside window),
|
|
356
|
+
// this is a surplus candidate for rotation.
|
|
357
|
+
if (isOrderOnChain(masterOrder) && targetOrder.state === ORDER_STATES.VIRTUAL) {
|
|
358
|
+
if (masterOrder.type === ORDER_TYPES.BUY) {
|
|
359
|
+
surplusesBuy.push({ id, master: masterOrder, target: targetOrder });
|
|
360
|
+
}
|
|
361
|
+
else if (masterOrder.type === ORDER_TYPES.SELL) {
|
|
362
|
+
surplusesSell.push({ id, master: masterOrder, target: targetOrder });
|
|
363
|
+
}
|
|
364
|
+
continue;
|
|
365
|
+
}
|
|
366
|
+
if (masterOrder.size !== targetOrder.size) {
|
|
367
|
+
if (targetOrder.size === 0) {
|
|
368
|
+
actions.push({ type: COW_ACTIONS.CANCEL, id, orderId: masterOrder.orderId, reason: 'target-size-zero' });
|
|
369
|
+
}
|
|
370
|
+
// Intentionally no in-place size UPDATE here.
|
|
371
|
+
// Fill-driven COW rebalance keeps updates rotation-only (newGridId path).
|
|
372
|
+
// Non-rotation size corrections are handled by dedicated maintenance flows
|
|
373
|
+
// (divergence/surplus cache-funds correction plans).
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
const cancelSurpluses = (surpluses) => {
|
|
377
|
+
for (const surplus of surpluses) {
|
|
378
|
+
if (surplus.master.orderId) {
|
|
379
|
+
actions.push({ type: COW_ACTIONS.CANCEL, id: surplus.id, orderId: surplus.master.orderId, reason: 'surplus-no-rotation-target' });
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
const pairRotations = (surpluses, holes) => {
|
|
384
|
+
const healthyHoles = holes.filter(hole => isCreateHealthy(hole.order));
|
|
385
|
+
if (healthyHoles.length === 0) {
|
|
386
|
+
// No viable rotation targets — cancel all unmatched surpluses
|
|
387
|
+
cancelSurpluses(surpluses);
|
|
388
|
+
return;
|
|
389
|
+
}
|
|
390
|
+
if (surpluses.length === 0) {
|
|
391
|
+
for (const hole of healthyHoles) {
|
|
392
|
+
actions.push({ type: COW_ACTIONS.CREATE, id: hole.id, order: hole.order });
|
|
393
|
+
}
|
|
394
|
+
return;
|
|
395
|
+
}
|
|
396
|
+
const isBuy = surpluses[0]?.master?.type === ORDER_TYPES.BUY;
|
|
397
|
+
healthyHoles.sort((a, b) => isBuy ? b.order.price - a.order.price : a.order.price - b.order.price);
|
|
398
|
+
surpluses.sort((a, b) => isBuy ? a.master.price - b.master.price : b.master.price - a.master.price);
|
|
399
|
+
const rotationCount = Math.min(surpluses.length, healthyHoles.length);
|
|
400
|
+
for (let i = 0; i < rotationCount; i++) {
|
|
401
|
+
const surplus = surpluses[i];
|
|
402
|
+
const hole = healthyHoles[i];
|
|
403
|
+
actions.push({
|
|
404
|
+
type: COW_ACTIONS.UPDATE,
|
|
405
|
+
id: surplus.id,
|
|
406
|
+
orderId: surplus.master.orderId,
|
|
407
|
+
newGridId: hole.id,
|
|
408
|
+
newSize: hole.order.size,
|
|
409
|
+
newPrice: hole.order.price,
|
|
410
|
+
order: hole.order,
|
|
411
|
+
isRotation: true
|
|
412
|
+
});
|
|
413
|
+
}
|
|
414
|
+
for (let i = rotationCount; i < healthyHoles.length; i++) {
|
|
415
|
+
actions.push({ type: COW_ACTIONS.CREATE, id: healthyHoles[i].id, order: healthyHoles[i].order });
|
|
416
|
+
}
|
|
417
|
+
// Cancel any surpluses that couldn't be paired with a hole
|
|
418
|
+
cancelSurpluses(surpluses.slice(rotationCount));
|
|
419
|
+
};
|
|
420
|
+
pairRotations(surplusesBuy, holesBuy);
|
|
421
|
+
pairRotations(surplusesSell, holesSell);
|
|
422
|
+
for (const [id, masterOrder] of masterGrid) {
|
|
423
|
+
if (!targetGrid.has(id) && isOrderOnChain(masterOrder)) {
|
|
424
|
+
actions.push({ type: COW_ACTIONS.CANCEL, id, orderId: masterOrder.orderId, reason: 'orphan-slot' });
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
return {
|
|
428
|
+
actions,
|
|
429
|
+
aborted: false,
|
|
430
|
+
boundaryIdx: validatedBoundary,
|
|
431
|
+
summary: summarizeActions(actions)
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
/**
|
|
435
|
+
* Pair same-side CREATE+CANCEL actions into rotation-style UPDATE actions.
|
|
436
|
+
* This reduces churn and matches boundary-crawl behavior where an on-chain
|
|
437
|
+
* order is moved to a new slot instead of cancel+recreate.
|
|
438
|
+
*
|
|
439
|
+
* @param {Array<Object>} actions - Reconcile action list
|
|
440
|
+
* @param {Map} masterGrid - Current master grid
|
|
441
|
+
* @returns {Array<Object>} Optimized action list
|
|
442
|
+
*/
|
|
443
|
+
function optimizeRebalanceActions(actions, masterGrid) {
|
|
444
|
+
if (!Array.isArray(actions) || actions.length === 0)
|
|
445
|
+
return [];
|
|
446
|
+
const creates = [];
|
|
447
|
+
const cancels = [];
|
|
448
|
+
const passthrough = [];
|
|
449
|
+
for (const action of actions) {
|
|
450
|
+
if (action?.type === COW_ACTIONS.CREATE) {
|
|
451
|
+
creates.push(action);
|
|
452
|
+
}
|
|
453
|
+
else if (action?.type === COW_ACTIONS.CANCEL) {
|
|
454
|
+
cancels.push(action);
|
|
455
|
+
}
|
|
456
|
+
else {
|
|
457
|
+
passthrough.push(action);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
if (creates.length === 0 || cancels.length === 0) {
|
|
461
|
+
return actions;
|
|
462
|
+
}
|
|
463
|
+
const remainingCreates = [...creates];
|
|
464
|
+
const optimized = [...passthrough];
|
|
465
|
+
for (const cancelAction of cancels) {
|
|
466
|
+
const masterOrder = masterGrid.get(cancelAction.id);
|
|
467
|
+
const cancelType = masterOrder?.type;
|
|
468
|
+
if (!masterOrder || !cancelAction.orderId || !cancelType) {
|
|
469
|
+
optimized.push(cancelAction);
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
let bestIdx = -1;
|
|
473
|
+
let bestDistance = Infinity;
|
|
474
|
+
for (let i = 0; i < remainingCreates.length; i++) {
|
|
475
|
+
const createAction = remainingCreates[i];
|
|
476
|
+
const createType = createAction?.order?.type;
|
|
477
|
+
if (createType !== cancelType)
|
|
478
|
+
continue;
|
|
479
|
+
const fromPrice = toFiniteNumber(masterOrder.price);
|
|
480
|
+
const toPrice = toFiniteNumber(createAction?.order?.price);
|
|
481
|
+
const distance = Math.abs(toPrice - fromPrice);
|
|
482
|
+
if (distance < bestDistance) {
|
|
483
|
+
bestDistance = distance;
|
|
484
|
+
bestIdx = i;
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
if (bestIdx === -1) {
|
|
488
|
+
optimized.push(cancelAction);
|
|
489
|
+
continue;
|
|
490
|
+
}
|
|
491
|
+
const createAction = remainingCreates.splice(bestIdx, 1)[0];
|
|
492
|
+
optimized.push({
|
|
493
|
+
type: COW_ACTIONS.UPDATE,
|
|
494
|
+
id: cancelAction.id,
|
|
495
|
+
orderId: cancelAction.orderId,
|
|
496
|
+
newGridId: createAction.id,
|
|
497
|
+
newSize: toFiniteNumber(createAction?.order?.size),
|
|
498
|
+
newPrice: toFiniteNumber(createAction?.order?.price),
|
|
499
|
+
order: createAction.order,
|
|
500
|
+
isRotation: true
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
for (const createAction of remainingCreates) {
|
|
504
|
+
optimized.push(createAction);
|
|
505
|
+
}
|
|
506
|
+
return optimized;
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* Summarize actions for logging/debugging
|
|
510
|
+
* @param {Array} actions - Action list
|
|
511
|
+
* @returns {Object} Summary counts
|
|
512
|
+
*/
|
|
513
|
+
function summarizeActions(actions) {
|
|
514
|
+
return {
|
|
515
|
+
total: actions.length,
|
|
516
|
+
creates: actions.filter(a => a.type === COW_ACTIONS.CREATE).length,
|
|
517
|
+
cancels: actions.filter(a => a.type === COW_ACTIONS.CANCEL).length,
|
|
518
|
+
updates: actions.filter(a => a.type === COW_ACTIONS.UPDATE).length
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* Check if a rebalance result has executable actions.
|
|
523
|
+
*
|
|
524
|
+
* @param {import('./types').ReconcileResult} rebalanceResult - Rebalance result to check
|
|
525
|
+
* @returns {boolean} True if actions array is non-empty
|
|
526
|
+
*/
|
|
527
|
+
function hasExecutableActions(rebalanceResult) {
|
|
528
|
+
const actions = rebalanceResult?.actions;
|
|
529
|
+
return Array.isArray(actions) && actions.length > 0;
|
|
530
|
+
}
|
|
531
|
+
/**
|
|
532
|
+
* Validate that CREATE actions target slots that are not already occupied on-chain.
|
|
533
|
+
* Cancelled or rotation-released slots are considered free.
|
|
534
|
+
*
|
|
535
|
+
* @param {Array<import('./types').CowAction>} actions - List of COW actions
|
|
536
|
+
* @param {Map} orders - Current order grid
|
|
537
|
+
* @returns {{isValid: boolean, violations: Array<Object>}} Validation result with any violations
|
|
538
|
+
*/
|
|
539
|
+
function validateCreateTargetSlots(actions, orders) {
|
|
540
|
+
const safeActions = Array.isArray(actions) ? actions : [];
|
|
541
|
+
const orderMap = orders instanceof Map ? orders : new Map();
|
|
542
|
+
const releasedSlotIds = new Set();
|
|
543
|
+
for (const action of safeActions) {
|
|
544
|
+
if (action?.type === COW_ACTIONS.CANCEL && action.id) {
|
|
545
|
+
releasedSlotIds.add(action.id);
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (action?.type === COW_ACTIONS.UPDATE &&
|
|
549
|
+
action.id &&
|
|
550
|
+
action.newGridId &&
|
|
551
|
+
action.newGridId !== action.id) {
|
|
552
|
+
releasedSlotIds.add(action.id);
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
const violations = [];
|
|
556
|
+
for (const action of safeActions) {
|
|
557
|
+
if (action?.type !== COW_ACTIONS.CREATE)
|
|
558
|
+
continue;
|
|
559
|
+
const targetId = action.id || action.order?.id;
|
|
560
|
+
if (!targetId || releasedSlotIds.has(targetId))
|
|
561
|
+
continue;
|
|
562
|
+
const current = orderMap.get(targetId);
|
|
563
|
+
if (!current)
|
|
564
|
+
continue;
|
|
565
|
+
if (isOrderOnChain(current)) {
|
|
566
|
+
violations.push({
|
|
567
|
+
targetId,
|
|
568
|
+
currentOrderId: current.orderId,
|
|
569
|
+
currentType: current.type,
|
|
570
|
+
currentState: current.state
|
|
571
|
+
});
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
return {
|
|
575
|
+
isValid: violations.length === 0,
|
|
576
|
+
violations
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
/**
|
|
580
|
+
* Check whether an action targets a given order reference.
|
|
581
|
+
* Matches by orderId first (when present on both), otherwise by slot id.
|
|
582
|
+
*
|
|
583
|
+
* @param {Object} action - Action object
|
|
584
|
+
* @param {Object} orderRef - Reference with id/orderId
|
|
585
|
+
* @returns {boolean}
|
|
586
|
+
*/
|
|
587
|
+
function actionMatchesOrder(action, orderRef) {
|
|
588
|
+
if (!action || !orderRef)
|
|
589
|
+
return false;
|
|
590
|
+
if (orderRef.orderId && action.orderId && String(orderRef.orderId) === String(action.orderId)) {
|
|
591
|
+
return true;
|
|
592
|
+
}
|
|
593
|
+
return !!orderRef.id && String(orderRef.id) === String(action.id);
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
596
|
+
* Check if an action list already contains a matching action for an order.
|
|
597
|
+
*
|
|
598
|
+
* @param {Array<Object>} actions - Action list
|
|
599
|
+
* @param {string|null} actionType - Optional action type filter
|
|
600
|
+
* @param {Object} orderRef - Reference with id/orderId
|
|
601
|
+
* @returns {boolean}
|
|
602
|
+
*/
|
|
603
|
+
function hasActionForOrder(actions, actionType, orderRef) {
|
|
604
|
+
if (!Array.isArray(actions))
|
|
605
|
+
return false;
|
|
606
|
+
return actions.some(action => {
|
|
607
|
+
if (actionType && action?.type !== actionType)
|
|
608
|
+
return false;
|
|
609
|
+
return actionMatchesOrder(action, orderRef);
|
|
610
|
+
});
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* Remove matching actions for an order from action list in-place.
|
|
614
|
+
*
|
|
615
|
+
* @param {Array<Object>} actions - Action list (mutated)
|
|
616
|
+
* @param {string|null} actionType - Optional action type filter
|
|
617
|
+
* @param {Object} orderRef - Reference with id/orderId
|
|
618
|
+
* @returns {number} Number of removed actions
|
|
619
|
+
*/
|
|
620
|
+
function removeActionsForOrder(actions, actionType, orderRef) {
|
|
621
|
+
if (!Array.isArray(actions))
|
|
622
|
+
return 0;
|
|
623
|
+
let removed = 0;
|
|
624
|
+
for (let i = actions.length - 1; i >= 0; i--) {
|
|
625
|
+
const action = actions[i];
|
|
626
|
+
if (actionType && action?.type !== actionType)
|
|
627
|
+
continue;
|
|
628
|
+
if (!actionMatchesOrder(action, orderRef))
|
|
629
|
+
continue;
|
|
630
|
+
actions.splice(i, 1);
|
|
631
|
+
removed++;
|
|
632
|
+
}
|
|
633
|
+
return removed;
|
|
634
|
+
}
|
|
635
|
+
/**
|
|
636
|
+
* @param {Array} [actions]
|
|
637
|
+
* @returns {{slotIds: Set<string>, orderIds: Set<string>}}
|
|
638
|
+
*/
|
|
639
|
+
function _buildUpdateSelectors(actions) {
|
|
640
|
+
const selectors = {
|
|
641
|
+
slotIds: new Set(),
|
|
642
|
+
orderIds: new Set()
|
|
643
|
+
};
|
|
644
|
+
if (!Array.isArray(actions))
|
|
645
|
+
return selectors;
|
|
646
|
+
for (const action of actions) {
|
|
647
|
+
if (action?.type !== COW_ACTIONS.UPDATE)
|
|
648
|
+
continue;
|
|
649
|
+
if (action.id)
|
|
650
|
+
selectors.slotIds.add(String(action.id));
|
|
651
|
+
if (action.newGridId)
|
|
652
|
+
selectors.slotIds.add(String(action.newGridId));
|
|
653
|
+
if (action.orderId)
|
|
654
|
+
selectors.orderIds.add(String(action.orderId));
|
|
655
|
+
}
|
|
656
|
+
return selectors;
|
|
657
|
+
}
|
|
658
|
+
/**
|
|
659
|
+
* @param {{slotIds: Set<string>, orderIds: Set<string>}|null} selectors
|
|
660
|
+
* @param {Object} [current]
|
|
661
|
+
* @param {string} [id]
|
|
662
|
+
* @returns {boolean}
|
|
663
|
+
*/
|
|
664
|
+
function _hasExplicitUpdateForOrder(selectors, current, id) {
|
|
665
|
+
if (!selectors)
|
|
666
|
+
return false;
|
|
667
|
+
if (id && selectors.slotIds.has(String(id))) {
|
|
668
|
+
return true;
|
|
669
|
+
}
|
|
670
|
+
const orderId = current?.orderId;
|
|
671
|
+
return !!orderId && selectors.orderIds.has(String(orderId));
|
|
672
|
+
}
|
|
673
|
+
/**
|
|
674
|
+
* @param {Object} current
|
|
675
|
+
* @param {Object} targetOrder
|
|
676
|
+
* @param {number} resultSize
|
|
677
|
+
* @param {string} resultState
|
|
678
|
+
* @param {string|null} resultOrderId
|
|
679
|
+
* @returns {boolean}
|
|
680
|
+
*/
|
|
681
|
+
function _isProjectionUnchanged(current, targetOrder, resultSize, resultState, resultOrderId) {
|
|
682
|
+
if (current.price === targetOrder.price &&
|
|
683
|
+
current.type === targetOrder.type &&
|
|
684
|
+
current.state === resultState &&
|
|
685
|
+
current.size === resultSize &&
|
|
686
|
+
current.orderId === resultOrderId) {
|
|
687
|
+
return true;
|
|
688
|
+
}
|
|
689
|
+
return false;
|
|
690
|
+
}
|
|
691
|
+
/**
|
|
692
|
+
* Project target grid into working grid
|
|
693
|
+
* @param {import('./types').WorkingGrid} workingGrid - Working grid to modify
|
|
694
|
+
* @param {Map} targetGrid - Target state
|
|
695
|
+
* @param {Object} [options] - Optional parameters
|
|
696
|
+
* @param {Array} [options.actions] - Pre-existing COW actions to consider
|
|
697
|
+
* @returns {void}
|
|
698
|
+
*/
|
|
699
|
+
function projectTargetToWorkingGrid(workingGrid, targetGrid, options = {}) {
|
|
700
|
+
const updateSelectors = _buildUpdateSelectors(options.actions);
|
|
701
|
+
const targetIds = new Set();
|
|
702
|
+
for (const [id, targetOrder] of targetGrid.entries()) {
|
|
703
|
+
targetIds.add(id);
|
|
704
|
+
const current = workingGrid.get(id);
|
|
705
|
+
const targetSize = toFiniteNumber(targetOrder?.size);
|
|
706
|
+
if (!current) {
|
|
707
|
+
// New orders start as VIRTUAL - transition to ACTIVE happens in synchronizeWithChain
|
|
708
|
+
// after blockchain confirms placement. This ensures accounting deduction occurs.
|
|
709
|
+
workingGrid.set(id, {
|
|
710
|
+
...targetOrder,
|
|
711
|
+
size: Math.max(0, targetSize),
|
|
712
|
+
state: ORDER_STATES.VIRTUAL,
|
|
713
|
+
orderId: null
|
|
714
|
+
});
|
|
715
|
+
continue;
|
|
716
|
+
}
|
|
717
|
+
if (targetSize > 0) {
|
|
718
|
+
const keepOrderId = isOrderOnChain(current) && current.type === targetOrder.type;
|
|
719
|
+
const hasExplicitUpdate = _hasExplicitUpdateForOrder(updateSelectors, current, id);
|
|
720
|
+
// Orders without on-chain ID remain VIRTUAL until synchronizeWithChain
|
|
721
|
+
// confirms blockchain placement and triggers accounting deduction.
|
|
722
|
+
//
|
|
723
|
+
// Preserve actual on-chain size for any unchanged on-chain order (ACTIVE/PARTIAL)
|
|
724
|
+
// unless there is an explicit UPDATE action for this slot/order.
|
|
725
|
+
// This prevents synthetic target sizes from being committed when no
|
|
726
|
+
// blockchain update operation will be broadcast.
|
|
727
|
+
const shouldPreserveSize = keepOrderId && !hasExplicitUpdate;
|
|
728
|
+
const preservedSize = shouldPreserveSize
|
|
729
|
+
? Math.max(0, toFiniteNumber(current.size))
|
|
730
|
+
: targetSize;
|
|
731
|
+
const resultState = keepOrderId ? current.state : ORDER_STATES.VIRTUAL;
|
|
732
|
+
const resultOrderId = keepOrderId ? current.orderId : null;
|
|
733
|
+
if (!_isProjectionUnchanged(current, targetOrder, preservedSize, resultState, resultOrderId)) {
|
|
734
|
+
workingGrid.set(id, {
|
|
735
|
+
...current,
|
|
736
|
+
...targetOrder,
|
|
737
|
+
size: preservedSize,
|
|
738
|
+
state: resultState,
|
|
739
|
+
orderId: resultOrderId
|
|
740
|
+
});
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
if (!_isProjectionUnchanged(current, targetOrder, 0, ORDER_STATES.VIRTUAL, null)) {
|
|
745
|
+
workingGrid.set(id, {
|
|
746
|
+
...current,
|
|
747
|
+
...targetOrder,
|
|
748
|
+
size: 0,
|
|
749
|
+
state: ORDER_STATES.VIRTUAL,
|
|
750
|
+
orderId: null
|
|
751
|
+
});
|
|
752
|
+
}
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
for (const [id, current] of workingGrid.entries()) {
|
|
756
|
+
if (targetIds.has(id))
|
|
757
|
+
continue;
|
|
758
|
+
if (isOrderOnChain(current)) {
|
|
759
|
+
workingGrid.set(id, convertToSpreadPlaceholder(current));
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Build optimistic state updates from rebalance actions
|
|
765
|
+
* @param {Array<Object>} actions - Array of rebalance action objects
|
|
766
|
+
* @param {Map} masterGrid - Master grid Map containing current order states
|
|
767
|
+
* @returns {Array<Object>} State update objects for optimistic rendering
|
|
768
|
+
*/
|
|
769
|
+
function buildStateUpdates(actions, masterGrid) {
|
|
770
|
+
const stateUpdates = [];
|
|
771
|
+
for (const action of actions) {
|
|
772
|
+
if (action.type === COW_ACTIONS.CREATE) {
|
|
773
|
+
stateUpdates.push({
|
|
774
|
+
...action.order,
|
|
775
|
+
state: ORDER_STATES.VIRTUAL,
|
|
776
|
+
orderId: null
|
|
777
|
+
});
|
|
778
|
+
}
|
|
779
|
+
else if (action.type === COW_ACTIONS.CANCEL) {
|
|
780
|
+
const masterOrder = masterGrid.get(action.id);
|
|
781
|
+
if (masterOrder) {
|
|
782
|
+
stateUpdates.push(convertToSpreadPlaceholder(masterOrder));
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
else if (action.type === COW_ACTIONS.UPDATE) {
|
|
786
|
+
const masterOrder = masterGrid.get(action.id);
|
|
787
|
+
if (masterOrder) {
|
|
788
|
+
const newSize = toFiniteNumber(action.newSize ?? action.order?.size);
|
|
789
|
+
stateUpdates.push({ ...masterOrder, size: newSize });
|
|
790
|
+
}
|
|
791
|
+
}
|
|
792
|
+
}
|
|
793
|
+
return stateUpdates;
|
|
794
|
+
}
|
|
795
|
+
/**
|
|
796
|
+
* Build an aborted COW result
|
|
797
|
+
* @param {string} reason - Abort reason
|
|
798
|
+
* @returns {Object} Aborted result object
|
|
799
|
+
*/
|
|
800
|
+
function buildAbortedResult(reason) {
|
|
801
|
+
return {
|
|
802
|
+
actions: [],
|
|
803
|
+
stateUpdates: [],
|
|
804
|
+
hadRotation: false,
|
|
805
|
+
workingGrid: null,
|
|
806
|
+
workingIndexes: null,
|
|
807
|
+
workingBoundary: null,
|
|
808
|
+
planningDuration: 0,
|
|
809
|
+
aborted: true,
|
|
810
|
+
reason
|
|
811
|
+
};
|
|
812
|
+
}
|
|
813
|
+
/**
|
|
814
|
+
* Build successful COW result
|
|
815
|
+
* @param {Object} params - Result parameters
|
|
816
|
+
* @returns {Object} Success result object
|
|
817
|
+
*/
|
|
818
|
+
function buildSuccessResult({ actions, stateUpdates, workingGrid, workingBoundary, planningDuration }) {
|
|
819
|
+
return {
|
|
820
|
+
actions,
|
|
821
|
+
stateUpdates,
|
|
822
|
+
hadRotation: actions.some(a => a.type === COW_ACTIONS.CREATE || a.type === COW_ACTIONS.UPDATE),
|
|
823
|
+
workingGrid,
|
|
824
|
+
workingIndexes: workingGrid.getIndexes(),
|
|
825
|
+
workingBoundary,
|
|
826
|
+
planningDuration,
|
|
827
|
+
aborted: false
|
|
828
|
+
};
|
|
829
|
+
}
|
|
830
|
+
/**
|
|
831
|
+
* Evaluate if a working grid can be committed
|
|
832
|
+
* @param {WorkingGrid} workingGrid - Grid to evaluate
|
|
833
|
+
* @param {Object} options - Evaluation options
|
|
834
|
+
* @returns {Object} Evaluation result
|
|
835
|
+
*/
|
|
836
|
+
function evaluateCommit(workingGrid, options = {}) {
|
|
837
|
+
const hasLock = typeof options === 'boolean' ? options : !!options?.hasLock;
|
|
838
|
+
const currentVersion = toFiniteNumber(options?.currentVersion, null);
|
|
839
|
+
const masterGrid = typeof options === 'object' ? options.masterGrid : null;
|
|
840
|
+
if (!workingGrid) {
|
|
841
|
+
return {
|
|
842
|
+
canCommit: false,
|
|
843
|
+
reason: 'No working grid to commit',
|
|
844
|
+
level: 'error'
|
|
845
|
+
};
|
|
846
|
+
}
|
|
847
|
+
if (workingGrid.isStale()) {
|
|
848
|
+
return {
|
|
849
|
+
canCommit: false,
|
|
850
|
+
reason: `Refusing stale working grid commit${hasLock ? ' (under lock)' : ''}: ${workingGrid.getStaleReason() || 'Master grid changed during planning'}`,
|
|
851
|
+
level: 'warn'
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
const baseVersion = (typeof workingGrid.getBaseVersion === 'function')
|
|
855
|
+
? workingGrid.getBaseVersion()
|
|
856
|
+
: workingGrid.baseVersion;
|
|
857
|
+
if (baseVersion === null || baseVersion === undefined) {
|
|
858
|
+
return {
|
|
859
|
+
canCommit: false,
|
|
860
|
+
reason: 'Working grid has no base version',
|
|
861
|
+
level: 'error'
|
|
862
|
+
};
|
|
863
|
+
}
|
|
864
|
+
if (currentVersion !== null && isValidNumber(baseVersion) && Number(baseVersion) !== currentVersion) {
|
|
865
|
+
return {
|
|
866
|
+
canCommit: false,
|
|
867
|
+
reason: `Refusing working grid commit: base version ${Number(baseVersion)} != current ${currentVersion}`,
|
|
868
|
+
level: 'warn'
|
|
869
|
+
};
|
|
870
|
+
}
|
|
871
|
+
if (masterGrid && typeof workingGrid.buildDelta === 'function') {
|
|
872
|
+
const delta = workingGrid.buildDelta(masterGrid, {
|
|
873
|
+
precisions: options?.comparePrecisions || null
|
|
874
|
+
});
|
|
875
|
+
if (Array.isArray(delta) && delta.length === 0) {
|
|
876
|
+
return {
|
|
877
|
+
canCommit: false,
|
|
878
|
+
reason: 'Delta empty at commit - nothing to commit',
|
|
879
|
+
level: 'debug'
|
|
880
|
+
};
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
if (hasLock) {
|
|
884
|
+
const stats = workingGrid.getMemoryStats();
|
|
885
|
+
if (stats.size === 0) {
|
|
886
|
+
return {
|
|
887
|
+
canCommit: false,
|
|
888
|
+
reason: 'Working grid is empty',
|
|
889
|
+
level: 'warn'
|
|
890
|
+
};
|
|
891
|
+
}
|
|
892
|
+
}
|
|
893
|
+
return { canCommit: true };
|
|
894
|
+
}
|
|
895
|
+
module.exports = {
|
|
896
|
+
// Validation
|
|
897
|
+
validateOrder,
|
|
898
|
+
validateGridForPersistence,
|
|
899
|
+
calculateRequiredFunds,
|
|
900
|
+
validateWorkingGridFunds,
|
|
901
|
+
checkFundDrift,
|
|
902
|
+
VALID_ORDER_STATES,
|
|
903
|
+
VALID_ORDER_TYPES,
|
|
904
|
+
// Grid reconciliation (COW pipeline)
|
|
905
|
+
reconcileGrid,
|
|
906
|
+
optimizeRebalanceActions,
|
|
907
|
+
summarizeActions,
|
|
908
|
+
hasExecutableActions,
|
|
909
|
+
validateCreateTargetSlots,
|
|
910
|
+
hasActionForOrder,
|
|
911
|
+
removeActionsForOrder,
|
|
912
|
+
projectTargetToWorkingGrid,
|
|
913
|
+
buildStateUpdates,
|
|
914
|
+
buildAbortedResult,
|
|
915
|
+
buildSuccessResult,
|
|
916
|
+
evaluateCommit
|
|
917
|
+
};
|
|
918
|
+
//# sourceMappingURL=validate.js.map
|