dexbot 1.4.20 → 1.4.21

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.
Files changed (234) hide show
  1. package/CHANGELOG.md +23 -0
  2. package/README.md +22 -12
  3. package/analysis/ama_fitting/calibrate_convergence_er.ts +1 -1
  4. package/analysis/ama_fitting/package.json +1 -1
  5. package/analysis/bot_fitting/shared_utils.ts +1 -1
  6. package/analysis/bot_key_utils.ts +1 -5
  7. package/analysis/bot_usage/kibana_bot_queries.ts +1 -256
  8. package/analysis/chart_css.ts +1 -1
  9. package/analysis/math_utils.ts +1 -8
  10. package/analysis/trend_detection/package.json +1 -1
  11. package/claw/ecosystem.config.cjs +2 -3
  12. package/claw/examples/memu_integration_example.ts +17 -17
  13. package/claw/modules/chain_actions.ts +51 -54
  14. package/claw/modules/chain_broadcast.ts +66 -104
  15. package/claw/modules/claw_bridge.ts +60 -80
  16. package/claw/modules/claw_catalog.ts +47 -16
  17. package/claw/modules/claw_infra.ts +1 -5
  18. package/claw/modules/claw_launcher.ts +47 -49
  19. package/claw/modules/claw_skill_md.ts +8 -11
  20. package/claw/modules/credit_runtime_adapter.ts +2 -18
  21. package/claw/modules/decision_loop.ts +4 -0
  22. package/claw/modules/dexbot_bridge.ts +1 -1
  23. package/claw/modules/dexbot_profiles.ts +5 -21
  24. package/claw/modules/honest_ecosystem.ts +24 -8
  25. package/claw/modules/liquidity_pools.ts +10 -3
  26. package/claw/modules/mcp_utils.ts +109 -0
  27. package/claw/modules/memu_bridge.ts +76 -54
  28. package/claw/modules/mpa_utils.ts +26 -3
  29. package/claw/modules/position_discovery.ts +16 -27
  30. package/claw/modules/position_manager.ts +32 -41
  31. package/claw/modules/position_manager_watch.ts +3 -2
  32. package/claw/modules/short_mpa_strategy.ts +1 -9
  33. package/claw/modules/skill_utils.ts +5 -3
  34. package/claw/modules/utils.ts +9 -1
  35. package/claw/package.json +1 -1
  36. package/claw/runtimes/openclaw-plugin/index.ts +27 -10
  37. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  38. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  39. package/claw/scripts/claw_bridge.ts +1 -1
  40. package/claw/scripts/claw_mcp_server.ts +19 -78
  41. package/claw/scripts/honest_assets_report.ts +19 -84
  42. package/claw/scripts/memu_mcp_server.ts +57 -155
  43. package/claw/tests/test_claw_bridge.ts +6 -2
  44. package/claw/tests/test_claw_mcp_transport.ts +2 -2
  45. package/dist/analysis/ama_fitting/calibrate_convergence_er.js +1 -1
  46. package/dist/analysis/ama_fitting/calibrate_convergence_er.js.map +1 -1
  47. package/dist/analysis/bot_fitting/shared_utils.d.ts +1 -12
  48. package/dist/analysis/bot_fitting/shared_utils.d.ts.map +1 -1
  49. package/dist/analysis/bot_fitting/shared_utils.js +1 -1
  50. package/dist/analysis/bot_fitting/shared_utils.js.map +1 -1
  51. package/dist/analysis/bot_key_utils.d.ts +1 -1
  52. package/dist/analysis/bot_key_utils.d.ts.map +1 -1
  53. package/dist/analysis/bot_key_utils.js +1 -5
  54. package/dist/analysis/bot_key_utils.js.map +1 -1
  55. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +1 -337
  56. package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -1
  57. package/dist/analysis/bot_usage/kibana_bot_queries.js +1 -241
  58. package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -1
  59. package/dist/analysis/chart_css.d.ts +1 -15
  60. package/dist/analysis/chart_css.d.ts.map +1 -1
  61. package/dist/analysis/chart_css.js +1 -1
  62. package/dist/analysis/chart_css.js.map +1 -1
  63. package/dist/analysis/math_utils.d.ts +3 -5
  64. package/dist/analysis/math_utils.d.ts.map +1 -1
  65. package/dist/analysis/math_utils.js +3 -5
  66. package/dist/analysis/math_utils.js.map +1 -1
  67. package/dist/bot.js +2 -2
  68. package/dist/bot.js.map +1 -1
  69. package/dist/credential-daemon.js +1 -1
  70. package/dist/credential-daemon.js.map +1 -1
  71. package/dist/dexbot.d.ts.map +1 -1
  72. package/dist/dexbot.js +18 -14
  73. package/dist/dexbot.js.map +1 -1
  74. package/dist/market_adapter/ama_signal_runner.js +3 -3
  75. package/dist/market_adapter/core/kibana_client.d.ts +1 -3
  76. package/dist/market_adapter/core/kibana_client.d.ts.map +1 -1
  77. package/dist/market_adapter/core/kibana_client.js +1 -1
  78. package/dist/market_adapter/core/kibana_client.js.map +1 -1
  79. package/dist/market_adapter/core/market_adapter_service.d.ts +1 -2
  80. package/dist/market_adapter/core/market_adapter_service.d.ts.map +1 -1
  81. package/dist/market_adapter/core/market_adapter_service.js +1 -1
  82. package/dist/market_adapter/core/market_adapter_service.js.map +1 -1
  83. package/dist/market_adapter/core/strategies/regime_gate.d.ts +1 -2
  84. package/dist/market_adapter/core/strategies/regime_gate.d.ts.map +1 -1
  85. package/dist/market_adapter/core/strategies/regime_gate.js +1 -1
  86. package/dist/market_adapter/core/strategies/regime_gate.js.map +1 -1
  87. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -2
  88. package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
  89. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +5 -5
  90. package/dist/market_adapter/inputs/fetch_lp_data.js +5 -5
  91. package/dist/market_adapter/inputs/kibana_source.d.ts +1 -2
  92. package/dist/market_adapter/inputs/kibana_source.d.ts.map +1 -1
  93. package/dist/market_adapter/inputs/kibana_source.js +1 -1
  94. package/dist/market_adapter/inputs/kibana_source.js.map +1 -1
  95. package/dist/market_adapter/lp_chart_strategy_loader.d.ts +1 -2
  96. package/dist/market_adapter/lp_chart_strategy_loader.d.ts.map +1 -1
  97. package/dist/market_adapter/lp_chart_strategy_loader.js +4 -4
  98. package/dist/market_adapter/lp_chart_strategy_loader.js.map +1 -1
  99. package/dist/market_adapter/market_adapter.d.ts.map +1 -1
  100. package/dist/market_adapter/market_adapter.js +2 -1
  101. package/dist/market_adapter/market_adapter.js.map +1 -1
  102. package/dist/modules/account_bots.d.ts +3 -0
  103. package/dist/modules/account_bots.d.ts.map +1 -1
  104. package/dist/modules/account_bots.js +156 -46
  105. package/dist/modules/account_bots.js.map +1 -1
  106. package/dist/modules/account_orders.d.ts +1 -7
  107. package/dist/modules/account_orders.d.ts.map +1 -1
  108. package/dist/modules/account_orders.js +9 -17
  109. package/dist/modules/account_orders.js.map +1 -1
  110. package/dist/modules/bitshares_client.d.ts +2 -14
  111. package/dist/modules/bitshares_client.d.ts.map +1 -1
  112. package/dist/modules/bitshares_client.js +22 -31
  113. package/dist/modules/bitshares_client.js.map +1 -1
  114. package/dist/modules/bot_settings.js +1 -1
  115. package/dist/modules/bot_settings.js.map +1 -1
  116. package/dist/modules/chain_keys.js +2 -2
  117. package/dist/modules/chain_keys.js.map +1 -1
  118. package/dist/modules/chain_orders.d.ts +2 -3
  119. package/dist/modules/chain_orders.d.ts.map +1 -1
  120. package/dist/modules/chain_orders.js +8 -25
  121. package/dist/modules/chain_orders.js.map +1 -1
  122. package/dist/modules/config.d.ts.map +1 -1
  123. package/dist/modules/config.js +4 -1
  124. package/dist/modules/config.js.map +1 -1
  125. package/dist/modules/constants.d.ts +0 -1
  126. package/dist/modules/constants.d.ts.map +1 -1
  127. package/dist/modules/constants.js +0 -4
  128. package/dist/modules/constants.js.map +1 -1
  129. package/dist/modules/credential_policy.js +1 -1
  130. package/dist/modules/credential_policy.js.map +1 -1
  131. package/dist/modules/dexbot_class.d.ts.map +1 -1
  132. package/dist/modules/dexbot_class.js +3 -2
  133. package/dist/modules/dexbot_class.js.map +1 -1
  134. package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
  135. package/dist/modules/dexbot_state_recovery.js +2 -1
  136. package/dist/modules/dexbot_state_recovery.js.map +1 -1
  137. package/dist/modules/fund_registry.d.ts.map +1 -1
  138. package/dist/modules/fund_registry.js +5 -2
  139. package/dist/modules/fund_registry.js.map +1 -1
  140. package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
  141. package/dist/modules/launcher/bot_supervisor.js +6 -7
  142. package/dist/modules/launcher/bot_supervisor.js.map +1 -1
  143. package/dist/modules/launcher/foreign_cred_daemon.d.ts.map +1 -1
  144. package/dist/modules/launcher/foreign_cred_daemon.js +6 -0
  145. package/dist/modules/launcher/foreign_cred_daemon.js.map +1 -1
  146. package/dist/modules/launcher/market_adapter_runtime.d.ts +2 -3
  147. package/dist/modules/launcher/market_adapter_runtime.d.ts.map +1 -1
  148. package/dist/modules/launcher/market_adapter_runtime.js +7 -15
  149. package/dist/modules/launcher/market_adapter_runtime.js.map +1 -1
  150. package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
  151. package/dist/modules/launcher/monolithic_runtime.js +1 -0
  152. package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
  153. package/dist/modules/launcher/status_reporting.d.ts +1 -2
  154. package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
  155. package/dist/modules/launcher/status_reporting.js +1 -4
  156. package/dist/modules/launcher/status_reporting.js.map +1 -1
  157. package/dist/modules/order/accounting.js +2 -2
  158. package/dist/modules/order/accounting.js.map +1 -1
  159. package/dist/modules/order/format.d.ts +0 -8
  160. package/dist/modules/order/format.d.ts.map +1 -1
  161. package/dist/modules/order/format.js +0 -8
  162. package/dist/modules/order/format.js.map +1 -1
  163. package/dist/modules/order/logger.js +1 -1
  164. package/dist/modules/order/logger.js.map +1 -1
  165. package/dist/modules/order/logger_state.d.ts +1 -13
  166. package/dist/modules/order/logger_state.d.ts.map +1 -1
  167. package/dist/modules/order/logger_state.js +1 -11
  168. package/dist/modules/order/logger_state.js.map +1 -1
  169. package/dist/modules/order/processed_fill_store.d.ts +0 -5
  170. package/dist/modules/order/processed_fill_store.d.ts.map +1 -1
  171. package/dist/modules/order/processed_fill_store.js +1 -12
  172. package/dist/modules/order/processed_fill_store.js.map +1 -1
  173. package/dist/modules/order/sync_engine.d.ts.map +1 -1
  174. package/dist/modules/order/sync_engine.js +10 -3
  175. package/dist/modules/order/sync_engine.js.map +1 -1
  176. package/dist/modules/order/utils/math.d.ts +7 -1
  177. package/dist/modules/order/utils/math.d.ts.map +1 -1
  178. package/dist/modules/order/utils/math.js +19 -1
  179. package/dist/modules/order/utils/math.js.map +1 -1
  180. package/dist/modules/order/utils/order.d.ts.map +1 -1
  181. package/dist/modules/order/utils/order.js +10 -2
  182. package/dist/modules/order/utils/order.js.map +1 -1
  183. package/dist/modules/runtime_settings.js +3 -1
  184. package/dist/modules/runtime_settings.js.map +1 -1
  185. package/dist/modules/settings_merge.d.ts.map +1 -1
  186. package/dist/modules/settings_merge.js +3 -1
  187. package/dist/modules/settings_merge.js.map +1 -1
  188. package/dist/modules/storage/browser_adapter.d.ts +8 -3
  189. package/dist/modules/storage/browser_adapter.d.ts.map +1 -1
  190. package/dist/modules/storage/browser_adapter.js +53 -4
  191. package/dist/modules/storage/browser_adapter.js.map +1 -1
  192. package/dist/modules/utils/sanitize_key.d.ts +7 -0
  193. package/dist/modules/utils/sanitize_key.d.ts.map +1 -0
  194. package/dist/modules/utils/sanitize_key.js +15 -0
  195. package/dist/modules/utils/sanitize_key.js.map +1 -0
  196. package/dist/pm2.js +6 -6
  197. package/dist/pm2.js.map +1 -1
  198. package/dist/scripts/analyze-orders.d.ts +2 -2
  199. package/dist/scripts/analyze-orders.d.ts.map +1 -1
  200. package/dist/scripts/analyze-orders.js +4 -12
  201. package/dist/scripts/analyze-orders.js.map +1 -1
  202. package/dist/scripts/runner.js +1 -1
  203. package/dist/scripts/runner.js.map +1 -1
  204. package/dist/scripts/update.js +1 -1
  205. package/dist/scripts/update.js.map +1 -1
  206. package/docs/BITSHARES_ONBOARDING.md +63 -18
  207. package/docs/COPY_ON_WRITE_MASTER_PLAN.md +5 -14
  208. package/docs/COW_INVARIANTS.md +4 -4
  209. package/docs/CREDENTIAL_SECURITY.md +0 -11
  210. package/docs/DEXBOT_COMPARISON.md +11 -11
  211. package/docs/EVOLUTION.md +11 -10
  212. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +27 -83
  213. package/docs/GRID_RECALCULATION.md +1 -13
  214. package/docs/GRID_RECONCILE.md +24 -24
  215. package/docs/LIFECYCLE.md +4 -4
  216. package/docs/LOGGING.md +1 -1
  217. package/docs/MPA_CREDIT_USAGE.md +3 -3
  218. package/docs/README.md +2 -2
  219. package/docs/WORKFLOW.md +2 -2
  220. package/docs/architecture.md +43 -38
  221. package/docs/developer_guide.md +16 -18
  222. package/market_adapter/README.md +0 -2
  223. package/modules/README.md +2 -1
  224. package/package.json +1 -1
  225. package/scripts/README.md +1 -1
  226. package/claw/openclaw.plugin.json +0 -13
  227. package/dist/market_adapter/merge_lp_data.d.ts +0 -3
  228. package/dist/market_adapter/merge_lp_data.d.ts.map +0 -1
  229. package/dist/market_adapter/merge_lp_data.js +0 -125
  230. package/dist/market_adapter/merge_lp_data.js.map +0 -1
  231. package/dist/market_adapter/utils/paths.d.ts +0 -3
  232. package/dist/market_adapter/utils/paths.d.ts.map +0 -1
  233. package/dist/market_adapter/utils/paths.js +0 -5
  234. package/dist/market_adapter/utils/paths.js.map +0 -1
@@ -51,14 +51,6 @@ function booleanSchema(description: any) {
51
51
  };
52
52
  }
53
53
 
54
- function stringArraySchema(description: any) {
55
- return {
56
- type: 'array',
57
- items: { type: 'string' },
58
- ...(description ? { description } : {})
59
- };
60
- }
61
-
62
54
  function pairArraySchema(description: any) {
63
55
  return {
64
56
  type: 'array',
@@ -173,6 +165,45 @@ function payloadTool(argsDesc: string, schema: any, overrides: any) {
173
165
  });
174
166
  }
175
167
 
168
+ // Shared payload schemas for paired execute/plan tools so the two surfaces
169
+ // cannot drift apart.
170
+ function honestPairPayloadSchema() {
171
+ return objectSchema({
172
+ assetA: stringSchema('First asset symbol'),
173
+ assetB: stringSchema('Second asset symbol'),
174
+ pair: stringSchema('Pair such as HONEST.USD/BTS')
175
+ });
176
+ }
177
+
178
+ function shortLegPayloadSchema() {
179
+ return objectSchema({
180
+ accountName: stringSchema('BitShares account name'),
181
+ mpaAsset: stringSchema('MPA asset symbol'),
182
+ debtAmount: numberSchema('Debt amount to borrow'),
183
+ collateralAmount: numberSchema('Collateral to lock'),
184
+ sellPriceInBts: numberSchema('Sell price in BTS'),
185
+ targetCollateralRatio: numberSchema('Optional target collateral ratio')
186
+ }, ['mpaAsset', 'debtAmount', 'collateralAmount', 'sellPriceInBts']);
187
+ }
188
+
189
+ function takeProfitPayloadSchema() {
190
+ return objectSchema({
191
+ accountName: stringSchema('BitShares account name'),
192
+ mpaAsset: stringSchema('MPA asset symbol'),
193
+ amountToCover: numberSchema('Amount to cover'),
194
+ buyPriceInBts: numberSchema('Buy price in BTS')
195
+ }, ['mpaAsset', 'amountToCover', 'buyPriceInBts']);
196
+ }
197
+
198
+ function closeShortPayloadSchema() {
199
+ return objectSchema({
200
+ accountName: stringSchema('BitShares account name'),
201
+ mpaAsset: stringSchema('MPA asset symbol'),
202
+ amountToRepay: numberSchema('Debt amount to repay'),
203
+ releaseCollateralDelta: numberSchema('Optional collateral release amount')
204
+ }, ['mpaAsset', 'amountToRepay']);
205
+ }
206
+
176
207
  function launcherTool(command: string, description: string, toolName: string, botNameDesc = 'Bot name as defined in profiles/bots.json. Omit for all active bots.') {
177
208
  return payloadTool(
178
209
  `JSON object with botName (optional), profileRoot (optional)`,
@@ -321,8 +352,8 @@ const CLAW_TOOL_CATALOG = Object.freeze([
321
352
  }),
322
353
  toolName: 'claw_honest_context'
323
354
  }),
324
- payloadTool('JSON object with assetA and assetB, or pair', objectSchema({ assetA: stringSchema('First asset symbol'), assetB: stringSchema('Second asset symbol'), pair: stringSchema('Pair such as HONEST.USD/BTS') }), { command: 'honest-pair', description: 'Resolve HONEST pair context', toolName: 'claw_honest_pair' }),
325
- payloadTool('JSON object with assetA and assetB, or pair', objectSchema({ assetA: stringSchema('First asset symbol'), assetB: stringSchema('Second asset symbol'), pair: stringSchema('Pair such as HONEST.USD/BTS') }), { command: 'honest-price', description: 'Resolve HONEST pair price', toolName: 'claw_honest_price' }),
355
+ payloadTool('JSON object with assetA and assetB, or pair', honestPairPayloadSchema(), { command: 'honest-pair', description: 'Resolve HONEST pair context', toolName: 'claw_honest_pair' }),
356
+ payloadTool('JSON object with assetA and assetB, or pair', honestPairPayloadSchema(), { command: 'honest-price', description: 'Resolve HONEST pair price', toolName: 'claw_honest_price' }),
326
357
  createToolDefinition({
327
358
  command: 'create-limit-order',
328
359
  description: 'Create a BitShares limit order',
@@ -480,12 +511,12 @@ const CLAW_TOOL_CATALOG = Object.freeze([
480
511
  risk: 'execute',
481
512
  toolName: 'claw_settle_mpa'
482
513
  }),
483
- payloadTool('JSON object with accountName, mpaAsset, debtAmount, collateralAmount, sellPriceInBts, optional targetCollateralRatio', objectSchema({ accountName: stringSchema('BitShares account name'), mpaAsset: stringSchema('MPA asset symbol'), debtAmount: numberSchema('Debt amount to borrow'), collateralAmount: numberSchema('Collateral to lock'), sellPriceInBts: numberSchema('Sell price in BTS'), targetCollateralRatio: numberSchema('Optional target collateral ratio') }, ['mpaAsset', 'debtAmount', 'collateralAmount', 'sellPriceInBts']), { command: 'open-short-bts', description: 'Build and execute the open leg of a BTS-backed short', risk: 'execute', toolName: 'claw_open_short_bts' }),
484
- payloadTool('JSON object with accountName, mpaAsset, debtAmount, collateralAmount, sellPriceInBts', objectSchema({ accountName: stringSchema('BitShares account name'), mpaAsset: stringSchema('MPA asset symbol'), debtAmount: numberSchema('Debt amount to borrow'), collateralAmount: numberSchema('Collateral to lock'), sellPriceInBts: numberSchema('Sell price in BTS') }, ['mpaAsset', 'debtAmount', 'collateralAmount', 'sellPriceInBts']), { command: 'build-open-short-plan', description: 'Build the open-short plan without broadcasting', risk: 'plan', toolName: 'claw_build_open_short_plan' }),
485
- payloadTool('JSON object with accountName, mpaAsset, amountToCover, buyPriceInBts', objectSchema({ accountName: stringSchema('BitShares account name'), mpaAsset: stringSchema('MPA asset symbol'), amountToCover: numberSchema('Amount to cover'), buyPriceInBts: numberSchema('Buy price in BTS') }, ['mpaAsset', 'amountToCover', 'buyPriceInBts']), { command: 'take-profit-bts', description: 'Place the take-profit leg for a BTS-backed short', risk: 'execute', toolName: 'claw_take_profit_bts' }),
486
- payloadTool('JSON object with accountName, mpaAsset, amountToCover, buyPriceInBts', objectSchema({ accountName: stringSchema('BitShares account name'), mpaAsset: stringSchema('MPA asset symbol'), amountToCover: numberSchema('Amount to cover'), buyPriceInBts: numberSchema('Buy price in BTS') }, ['mpaAsset', 'amountToCover', 'buyPriceInBts']), { command: 'build-take-profit-plan', description: 'Build the take-profit plan without broadcasting', risk: 'plan', toolName: 'claw_build_take_profit_plan' }),
487
- payloadTool('JSON object with accountName, mpaAsset, amountToRepay, optional releaseCollateralDelta', objectSchema({ accountName: stringSchema('BitShares account name'), mpaAsset: stringSchema('MPA asset symbol'), amountToRepay: numberSchema('Debt amount to repay'), releaseCollateralDelta: numberSchema('Optional collateral release amount') }, ['mpaAsset', 'amountToRepay']), { command: 'close-short-bts', description: 'Close a BTS-backed short', risk: 'execute', toolName: 'claw_close_short_bts' }),
488
- payloadTool('JSON object with accountName, mpaAsset, amountToRepay, optional releaseCollateralDelta', objectSchema({ accountName: stringSchema('BitShares account name'), mpaAsset: stringSchema('MPA asset symbol'), amountToRepay: numberSchema('Debt amount to repay'), releaseCollateralDelta: numberSchema('Optional collateral release amount') }, ['mpaAsset', 'amountToRepay']), { command: 'build-close-short-plan', description: 'Build the close-short plan without broadcasting', risk: 'plan', toolName: 'claw_build_close_short_plan' }),
514
+ payloadTool('JSON object with accountName, mpaAsset, debtAmount, collateralAmount, sellPriceInBts, optional targetCollateralRatio', shortLegPayloadSchema(), { command: 'open-short-bts', description: 'Build and execute the open leg of a BTS-backed short', risk: 'execute', toolName: 'claw_open_short_bts' }),
515
+ payloadTool('JSON object with accountName, mpaAsset, debtAmount, collateralAmount, sellPriceInBts, optional targetCollateralRatio', shortLegPayloadSchema(), { command: 'build-open-short-plan', description: 'Build the open-short plan without broadcasting', risk: 'plan', toolName: 'claw_build_open_short_plan' }),
516
+ payloadTool('JSON object with accountName, mpaAsset, amountToCover, buyPriceInBts', takeProfitPayloadSchema(), { command: 'take-profit-bts', description: 'Place the take-profit leg for a BTS-backed short', risk: 'execute', toolName: 'claw_take_profit_bts' }),
517
+ payloadTool('JSON object with accountName, mpaAsset, amountToCover, buyPriceInBts', takeProfitPayloadSchema(), { command: 'build-take-profit-plan', description: 'Build the take-profit plan without broadcasting', risk: 'plan', toolName: 'claw_build_take_profit_plan' }),
518
+ payloadTool('JSON object with accountName, mpaAsset, amountToRepay, optional releaseCollateralDelta', closeShortPayloadSchema(), { command: 'close-short-bts', description: 'Close a BTS-backed short', risk: 'execute', toolName: 'claw_close_short_bts' }),
519
+ payloadTool('JSON object with accountName, mpaAsset, amountToRepay, optional releaseCollateralDelta', closeShortPayloadSchema(), { command: 'build-close-short-plan', description: 'Build the close-short plan without broadcasting', risk: 'plan', toolName: 'claw_build_close_short_plan' }),
489
520
  createToolDefinition({
490
521
  command: 'mpa-position',
491
522
  description: 'Read the on-chain MPA position for an account',
@@ -15,8 +15,6 @@ import { acquireFileLock } from '../../market_adapter/utils/file_lock.js';
15
15
  import { clone } from './utils.js';
16
16
  const storage = getStorage();
17
17
 
18
- import { createPositionManagerWatcher, parsePositionManagerWatchArgs, runPositionManagerWatch } from './position_manager_watch.js';
19
-
20
18
  import type {
21
19
  RuntimeContextOptions,
22
20
  CredentialClientOptions,
@@ -27,9 +25,7 @@ import type {
27
25
  } from './types.js';
28
26
  import { getErrorMessage } from '../../modules/utils/errors.js';
29
27
 
30
- const CLAW_ROOT = PATHS.CLAW.DIR;
31
28
  const DEFAULT_DATA_DIR = PATHS.CLAW.DATA_DIR;
32
- const DEFAULT_STATE_DIR = PATHS.CLAW.STATE_DIR;
33
29
 
34
30
 
35
31
  /**
@@ -332,5 +328,5 @@ function createClawInfrastructure(options: ClawInfrastructureOptions = {}) {
332
328
  };
333
329
  }
334
330
 
335
- export { DEFAULT_DATA_DIR, DEFAULT_STATE_DIR, createBitsharesClient, createClawInfrastructure, createCredentialClient, createHonestEcosystemAdapter, createMarketAdapter, createOrderTools, createRuntimeContext, createStateStore, createPositionManagerWatcher, parsePositionManagerWatchArgs, runPositionManagerWatch }
331
+ export { createClawInfrastructure, createRuntimeContext, createStateStore }
336
332
 
@@ -56,6 +56,40 @@ function getSpawn(): any {
56
56
  return _spawn;
57
57
  }
58
58
 
59
+ /**
60
+ * Spawn a detached background child and wait for the spawn itself to succeed.
61
+ * Spawn failures (missing script, ENOENT, EACCES) are reported asynchronously
62
+ * via the child's 'error' event; waiting one macrotask lets those surface as a
63
+ * thrown error instead of callers receiving a false { started: true } result.
64
+ * A permanent 'error' handler remains attached so late errors are logged
65
+ * rather than crashing the host with an unhandled 'error' event.
66
+ */
67
+ function spawnDetached(scriptPath: string, args: string[], cwd: string): Promise<any> {
68
+ const child = getSpawn()('node', [scriptPath, ...args], {
69
+ detached: true,
70
+ stdio: 'ignore',
71
+ cwd
72
+ });
73
+
74
+ return new Promise((resolve, reject) => {
75
+ let settled = false;
76
+ child.on('error', (err: any) => {
77
+ if (!settled) {
78
+ settled = true;
79
+ reject(new Error(`Failed to spawn ${scriptPath}: ${getErrorMessage(err)}`));
80
+ return;
81
+ }
82
+ console.error(`[LAUNCHER] Child process error (${scriptPath}): ${getErrorMessage(err)}`);
83
+ });
84
+ setImmediate(() => {
85
+ if (!settled) {
86
+ settled = true;
87
+ resolve(child);
88
+ }
89
+ });
90
+ });
91
+ }
92
+
59
93
  let _pm2: any;
60
94
  function getPM2Module(): any {
61
95
  if (_pm2 === undefined) {
@@ -88,16 +122,7 @@ async function launcherStart(botName: string | null, options: Record<string, any
88
122
  args.push(botName);
89
123
  }
90
124
 
91
- const child = getSpawn()('node', [dexbotPath, ...args], {
92
- detached: true,
93
- stdio: 'ignore',
94
- cwd: ROOT
95
- });
96
-
97
- child.on('error', (err: any) => {
98
- console.error(`[LAUNCHER] Failed to spawn ${dexbotPath}: ${getErrorMessage(err)}`);
99
- });
100
-
125
+ const child = await spawnDetached(dexbotPath, args, ROOT);
101
126
  child.unref();
102
127
 
103
128
  return {
@@ -124,16 +149,7 @@ async function launcherDrystart(botName: string | null, options: Record<string,
124
149
  args.push(botName);
125
150
  }
126
151
 
127
- const child = getSpawn()('node', [dexbotPath, ...args], {
128
- detached: true,
129
- stdio: 'ignore',
130
- cwd: ROOT
131
- });
132
-
133
- child.on('error', (err: any) => {
134
- console.error(`[LAUNCHER] Failed to spawn ${dexbotPath}: ${getErrorMessage(err)}`);
135
- });
136
-
152
+ const child = await spawnDetached(dexbotPath, args, ROOT);
137
153
  child.unref();
138
154
 
139
155
  return {
@@ -158,10 +174,10 @@ async function launcherReset(botName: string | null, options: Record<string, any
158
174
  const { config } = loadSettingsFile(PROFILES_BOTS_FILE);
159
175
  const entries = normalizeBotEntries(resolveRawBotEntries(config));
160
176
 
161
- const targets = botName ? entries.filter((b: any) => b.name === botName) : entries.filter((b: any) => b.active);
177
+ const targets = botName ? entries.filter((b: any) => b.name === botName) : entries.filter((b: any) => b.active !== false);
162
178
 
163
179
  if (botName && targets.length === 0) {
164
- throw new Error(`Bot '${botName}' not found in profiles/bots.json`);
180
+ throw new Error(`Bot '${botName}' not found in ${PROFILES_BOTS_FILE}`);
165
181
  }
166
182
 
167
183
  const triggered: Array<Record<string, any>> = [];
@@ -221,7 +237,7 @@ async function launcherDisable(botName: string | null, options: Record<string, a
221
237
 
222
238
  const match = entries.find((b: any) => b.name === botName);
223
239
  if (!match) {
224
- throw new Error(`Bot '${botName}' not found in profiles/bots.json`);
240
+ throw new Error(`Bot '${botName}' not found in ${PROFILES_BOTS_FILE}`);
225
241
  }
226
242
 
227
243
  if (match.active === false) {
@@ -252,10 +268,10 @@ async function launcherPm2Start(botName: string | null, options: Record<string,
252
268
  const { config } = loadSettingsFile(PROFILES_BOTS_FILE);
253
269
  const entries = normalizeBotEntries(resolveRawBotEntries(config));
254
270
 
255
- const targets = botName ? entries.filter((b: any) => b.name === botName) : entries.filter((b: any) => b.active);
271
+ const targets = botName ? entries.filter((b: any) => b.name === botName) : entries.filter((b: any) => b.active !== false);
256
272
 
257
273
  if (botName && targets.length === 0) {
258
- throw new Error(`Bot '${botName}' not found or not active in profiles/bots.json`);
274
+ throw new Error(`Bot '${botName}' not found or not active in ${PROFILES_BOTS_FILE}`);
259
275
  }
260
276
 
261
277
  // Then check if daemon is ready
@@ -292,7 +308,7 @@ async function launcherPm2Start(botName: string | null, options: Record<string,
292
308
  * @param {Object} [options={}] - Options
293
309
  * @returns {Promise<Object>} { stopped: true, target }
294
310
  */
295
- async function launcherPm2Stop(target: string, options: Record<string, any> = {}) {
311
+ async function launcherPm2Stop(target: string, _options: Record<string, any> = {}) {
296
312
  await getPM2Module().stopPM2Processes(target || 'all');
297
313
  return {
298
314
  stopped: true,
@@ -306,7 +322,7 @@ async function launcherPm2Stop(target: string, options: Record<string, any> = {}
306
322
  * @param {Object} [options={}] - Options
307
323
  * @returns {Promise<Object>} { deleted: true, target }
308
324
  */
309
- async function launcherPm2Delete(target: string, options: Record<string, any> = {}) {
325
+ async function launcherPm2Delete(target: string, _options: Record<string, any> = {}) {
310
326
  await getPM2Module().deletePM2Processes(target || 'all');
311
327
  return {
312
328
  deleted: true,
@@ -320,7 +336,7 @@ async function launcherPm2Delete(target: string, options: Record<string, any> =
320
336
  * @param {Object} [options={}] - Options
321
337
  * @returns {Promise<Object>} { restarted: true, target }
322
338
  */
323
- async function launcherPm2Restart(target: string, options: Record<string, any> = {}) {
339
+ async function launcherPm2Restart(target: string, _options: Record<string, any> = {}) {
324
340
  await getPM2Module().restartPM2Processes(target || 'all');
325
341
  return {
326
342
  restarted: true,
@@ -422,16 +438,7 @@ async function launcherClawOnly(options: Record<string, any> = {}) {
422
438
  const ROOT = normalizeRoot(options);
423
439
  const pm2ScriptPath = resolveRuntimeScript(ROOT, 'pm2.js');
424
440
 
425
- const child = getSpawn()('node', [pm2ScriptPath, 'claw-only'], {
426
- detached: true,
427
- stdio: 'ignore',
428
- cwd: ROOT
429
- });
430
-
431
- child.on('error', (err: any) => {
432
- console.error(`[LAUNCHER] Failed to spawn ${pm2ScriptPath}: ${getErrorMessage(err)}`);
433
- });
434
-
441
+ const child = await spawnDetached(pm2ScriptPath, ['claw-only'], ROOT);
435
442
  child.unref();
436
443
 
437
444
  return {
@@ -459,16 +466,7 @@ async function launcherUnlockStart(botName: string | null, options: Record<strin
459
466
  args.push(botName);
460
467
  }
461
468
 
462
- const child = getSpawn()('node', [unlockPath, ...args], {
463
- detached: true,
464
- stdio: 'ignore',
465
- cwd: ROOT
466
- });
467
-
468
- child.on('error', (err: any) => {
469
- console.error(`[LAUNCHER] Failed to spawn ${unlockPath}: ${getErrorMessage(err)}`);
470
- });
471
-
469
+ const child = await spawnDetached(unlockPath, args, ROOT);
472
470
  child.unref();
473
471
 
474
472
  return {
@@ -481,5 +479,5 @@ async function launcherUnlockStart(botName: string | null, options: Record<strin
481
479
  };
482
480
  }
483
481
 
484
- export { launcherRun, launcherStart, launcherDrystart, launcherReset, launcherDisable, launcherPm2Start, launcherPm2Stop, launcherPm2Delete, launcherPm2Restart }
482
+ export { launcherRun, launcherDrystart, launcherReset, launcherDisable, launcherPm2Start, launcherPm2Stop, launcherPm2Delete, launcherPm2Restart }
485
483
 
@@ -237,20 +237,17 @@ function buildRuntimeSetup(runtime: any, repoRoot: string, profileRoot: string)
237
237
  }
238
238
 
239
239
  function buildRuntimeWorkflow(runtime: any) {
240
- if (runtime.runtime === 'hermes') {
241
- return [
242
- '- Start with `claw_manifest`, `claw_runtime`, `claw_profile_context`, `claw_market_snapshot`, `claw_account_snapshot`, or `claw_open_orders`.',
243
- '- For MPA and short workflows, use `claw_build_open_short_plan`, `claw_build_take_profit_plan`, or `claw_build_close_short_plan` before executing trades.',
244
- '- Use `claw_honest_context`, `claw_honest_pair`, and `claw_honest_price` when the task involves HONEST assets or discovery.',
245
- '- The shared Claw MCP server registers raw tool ids such as `claw_manifest`; if Hermes shows a namespaced label in its UI, follow the label shown there.'
246
- ].join('\n');
247
- }
248
-
249
- return [
240
+ const baseLines = [
250
241
  '- Start with `claw_manifest`, `claw_runtime`, `claw_profile_context`, `claw_market_snapshot`, `claw_account_snapshot`, or `claw_open_orders`.',
251
242
  '- For MPA and short workflows, use `claw_build_open_short_plan`, `claw_build_take_profit_plan`, or `claw_build_close_short_plan` before executing trades.',
252
243
  '- Use `claw_honest_context`, `claw_honest_pair`, and `claw_honest_price` when the task involves HONEST assets or discovery.'
253
- ].join('\n');
244
+ ];
245
+
246
+ if (runtime.runtime === 'hermes') {
247
+ baseLines.push('- The shared Claw MCP server registers raw tool ids such as `claw_manifest`; if Hermes shows a namespaced label in its UI, follow the label shown there.');
248
+ }
249
+
250
+ return baseLines.join('\n');
254
251
  }
255
252
 
256
253
  function buildRuntimeSkillToml(runtime: any, repoRoot: string, profileRoot: string) {
@@ -24,7 +24,7 @@ function createCreditRuntimeAdapter(infra: any, options: Record<string, any> = {
24
24
  assetA: botEntry.assetA,
25
25
  assetB: botEntry.assetB,
26
26
  },
27
- _log: (msg: string, level?: string) => {
27
+ _log: (msg: string) => {
28
28
  const logger = infra.runtime?.logger || console;
29
29
  if (typeof logger.info === 'function') logger.info(`[credit-runtime] ${msg}`);
30
30
  else logger.log(`[credit-runtime] ${msg}`);
@@ -100,10 +100,7 @@ function createCreditRuntimeAdapter(infra: any, options: Record<string, any> = {
100
100
  const rt = await _getRuntime(botRef);
101
101
  if (!rt) {
102
102
  try {
103
- const bundle = await infra.profiles.loadBundle();
104
- const bot = bundle.bots.find(
105
- (b: Record<string, any>) => b.botKey === botRef || b.name === botRef,
106
- );
103
+ const bot = await _resolveBotEntry(botRef);
107
104
  if (!bot) return { error: `bot not found: ${botRef}` };
108
105
  if (!bot.debtPolicy) return { error: `bot ${botRef} has no debtPolicy configured` };
109
106
  return { error: `unable to initialize credit runtime for ${botRef}` };
@@ -142,19 +139,6 @@ function createCreditRuntimeAdapter(infra: any, options: Record<string, any> = {
142
139
  _ensureSigningKey(rt, privateKey);
143
140
  return rt.processPendingReborrows();
144
141
  },
145
-
146
- listRuntimes(): any[] {
147
- return Array.from(_runtimes.entries())
148
- .filter(([_, rt]) => rt.isEnabled())
149
- .map(([key, rt]) => ({
150
- botKey: key,
151
- enabled: rt.isEnabled(),
152
- }));
153
- },
154
-
155
- getRuntime(botRef: string): any | null {
156
- return _runtimes.get(botRef) || null;
157
- },
158
142
  };
159
143
  }
160
144
 
@@ -186,6 +186,10 @@ function buildSummary(assessments: Array<Record<string, any>>) {
186
186
  function resetAnalyzers() {
187
187
  analyzers.clear();
188
188
  analyzerConfigs.clear();
189
+ // Premiums belong to the analyzer generation that produced them; keeping
190
+ // them across a reset would let the reuse path report a stale value from
191
+ // discarded config.
192
+ marketPremiums.clear();
189
193
  }
190
194
 
191
195
  export { evaluate, getOrCreateAnalyzer, resetAnalyzers }
@@ -78,5 +78,5 @@ function loadDexbotOrderSystemUtils() {
78
78
  return requireDexbot2Module('modules/order/utils/system');
79
79
  }
80
80
 
81
- export { getDexbot2Root, loadDexbotOrderConstants, loadDexbotOrderSubsystem, loadDexbotOrderSystemUtils, loadDexbotOrderUtils, requireDexbot2Module, resolveDexbot2Path }
81
+ export { getDexbot2Root, loadDexbotOrderConstants, loadDexbotOrderSubsystem, loadDexbotOrderSystemUtils, loadDexbotOrderUtils, requireDexbot2Module }
82
82
 
@@ -12,7 +12,7 @@ import { clone } from './utils.js';
12
12
  import { createBotKey, sanitizeKey } from '../../modules/account_orders.js';
13
13
  const storage = getStorage();
14
14
 
15
- import type { BotSettings, ProfileOptions, Logger, ClawProfileBundle } from './types.js';
15
+ import type { BotSettings, ProfileOptions, ClawProfileBundle } from './types.js';
16
16
  import { getErrorMessage } from '../../modules/utils/errors.js';
17
17
 
18
18
  const DEFAULT_MANIFEST_FILE = 'config.json';
@@ -661,7 +661,7 @@ async function normalizeBotEntries(rawEntries: Record<string, any>[], options: P
661
661
  if (logger) {
662
662
  validateBotEntry(entry, index, logger);
663
663
  }
664
- const normalized = { active: entry.active === undefined ? true : !!entry.active, ...entry };
664
+ const normalized = { ...entry, active: entry.active === undefined ? true : !!entry.active };
665
665
  results.push({ ...normalized, botIndex: index, botKey: createBotKey(normalized, index) });
666
666
  }
667
667
  return results;
@@ -1008,8 +1008,8 @@ async function loadDexbotProfileBundle(profileRoot: string | null, options: Part
1008
1008
  * The adapter wraps bundle loading, settings validation, and atomic writes behind
1009
1009
  * per-file locks so concurrent updates do not clobber each other.
1010
1010
  *
1011
- * @returns {Object} Adapter with loadBundle, listBots, findBot, getBotBundle,
1012
- * getBotSettings, previewBotSettingsUpdate, applyBotSettingsPatch, getProfilesDir
1011
+ * @returns {Object} Adapter with loadBundle, getBotSettings,
1012
+ * previewBotSettingsUpdate, applyBotSettingsPatch, updateBotSettings, getClawProfileContext
1013
1013
  */
1014
1014
  function createDexbotProfileAdapter(profileRoot: string | null, options: Partial<ProfileOptions> = {}) {
1015
1015
  let cachedBundle: any = null;
@@ -1025,16 +1025,6 @@ function createDexbotProfileAdapter(profileRoot: string | null, options: Partial
1025
1025
  return resolveProfilesDir(profileRoot || options.profileRoot);
1026
1026
  }
1027
1027
 
1028
- async function listBots({ activeOnly = false, forceReload = false } = {}) {
1029
- const bundle = await loadBundle(forceReload);
1030
- return activeOnly ? bundle.activeBots : bundle.bots;
1031
- }
1032
-
1033
- async function findBot(identifier: any, forceReload = false) {
1034
- const bundle = await loadBundle(forceReload);
1035
- return bundle.bots.find((bot: any) => matchBotIdentifier(bot, identifier)) || null;
1036
- }
1037
-
1038
1028
  async function getBotBundle(identifier: any, forceReload = false) {
1039
1029
  const bundle = await loadBundle(forceReload);
1040
1030
  const bot = bundle.bots.find((entry: any) => matchBotIdentifier(entry, identifier)) || null;
@@ -1272,20 +1262,14 @@ function createDexbotProfileAdapter(profileRoot: string | null, options: Partial
1272
1262
  }
1273
1263
 
1274
1264
  return {
1275
- buildClawProfileContext: (bundle: any, contextOptions = {}) => buildClawProfileContext(bundle, contextOptions),
1276
1265
  applyBotSettingsPatch,
1277
- findBot,
1278
- getBotBundle,
1279
1266
  getBotSettings,
1280
1267
  getClawProfileContext,
1281
- getProfilesDir,
1282
- listBots,
1283
1268
  loadBundle,
1284
1269
  previewBotSettingsUpdate,
1285
- resolveProfilesDir: () => resolveProfilesDir(profileRoot || options.profileRoot),
1286
1270
  updateBotSettings
1287
1271
  };
1288
1272
  }
1289
1273
 
1290
- export { buildBotSettingsView, createBotKey, createDexbotProfileAdapter, buildClawProfileContext, describeBotSettingMutability, loadDexbotProfileBundle, matchBotIdentifier, normalizeBotSettings, normalizeBotEntries, readTriggerFile, resolveProfilesDir, resolveRawBotEntries, sanitizeKey, validateBotEntry, validateBotSettingsPatch, validateBotSettingsState, writeJsonFileAtomic }
1274
+ export { createBotKey, createDexbotProfileAdapter, matchBotIdentifier, normalizeBotEntries, resolveProfilesDir, resolveRawBotEntries, validateBotEntry, writeJsonFileAtomic }
1291
1275
 
@@ -88,7 +88,11 @@ async function fetchLivePoolReserves(poolId: string = HARDCODED_POOL_ID) {
88
88
  };
89
89
  _poolReservesCache = { poolId, ts: Date.now(), value: result };
90
90
  return result;
91
- } catch {
91
+ } catch (err: any) {
92
+ // Never cache failures, but surface them: silently serving the hardcoded
93
+ // fallback snapshot hides a degraded node and produces confidently-wrong
94
+ // bridge prices with no telemetry trail.
95
+ console.warn(`[honest-ecosystem] live pool reserves fetch failed for ${poolId}, using hardcoded fallback: ${err?.message || err}`);
92
96
  return null;
93
97
  }
94
98
  }
@@ -217,10 +221,15 @@ async function resolveHonestPairContext(assetA: any, assetB: any, options: Recor
217
221
  };
218
222
  }
219
223
 
220
- async function loadHonestAssets({ prefix = DEFAULT_PREFIX, batchSize = 100, maxPages = 100, startSymbol = DEFAULT_PREFIX }: Record<string, any> = {}) {
221
- const all = [];
224
+ /**
225
+ * Paginate list_assets with the shared dedup/boundary rules used across the
226
+ * HONEST tooling. `onPage` receives each de-duplicated page and accumulates
227
+ * whatever it needs; returning `false` stops pagination early (e.g. crossing
228
+ * a prefix boundary).
229
+ */
230
+ async function paginateListAssets({ batchSize = 100, maxPages = 100, startSymbol = '' }: Record<string, any> = {}, onPage: (pageItems: any[], batch: any[]) => boolean | void) {
222
231
  let lowerBound = startSymbol;
223
- let previousLastSymbol = null;
232
+ let previousLastSymbol: string | null = null;
224
233
 
225
234
  for (let page = 0; page < maxPages; page += 1) {
226
235
  const batch = await listAssets(lowerBound, batchSize);
@@ -237,17 +246,24 @@ async function loadHonestAssets({ prefix = DEFAULT_PREFIX, batchSize = 100, maxP
237
246
  break;
238
247
  }
239
248
 
240
- const matching = pageItems.filter((asset) => isHonestAsset(asset) && asset.symbol.startsWith(prefix));
241
- all.push(...matching);
249
+ const keepGoing = await onPage(pageItems, batch);
242
250
 
243
251
  previousLastSymbol = pageItems[pageItems.length - 1].symbol;
244
252
  lowerBound = previousLastSymbol;
245
253
 
246
- if (batch.length < batchSize) {
254
+ if (keepGoing === false || batch.length < batchSize) {
247
255
  break;
248
256
  }
249
257
  }
258
+ }
250
259
 
260
+ async function loadHonestAssets({ prefix = DEFAULT_PREFIX, batchSize = 100, maxPages = 100, startSymbol = DEFAULT_PREFIX }: Record<string, any> = {}) {
261
+ const all: any[] = [];
262
+
263
+ await paginateListAssets({ batchSize, maxPages, startSymbol }, (pageItems) => {
264
+ const matching = pageItems.filter((asset) => isHonestAsset(asset) && asset.symbol.startsWith(prefix));
265
+ all.push(...matching);
266
+ });
251
267
  const mpas = [];
252
268
  for (const asset of all) {
253
269
  if (!isMpa(asset)) {
@@ -357,5 +373,5 @@ function createHonestEcosystemAdapter(options: Record<string, any> = {}) {
357
373
  };
358
374
  }
359
375
 
360
- export { CORE_SYMBOL, DEFAULT_PREFIX, REFERENCE_SYMBOL, buildHonestEcosystemContext, createHonestEcosystemAdapter, getHardcodedHonestMoneyBridge, loadHonestAssets, isHardcodedHonestMoneyBtsPair, resolveHardcodedHonestMoneyPrice, resolveHonestPairContext, resolveHonestPairPrice }
376
+ export { buildHonestEcosystemContext, createHonestEcosystemAdapter, getHardcodedHonestMoneyBridge, getHonestMoneyBridge, isMpa, loadHonestAssets, paginateListAssets, resolveHardcodedHonestMoneyPrice, resolveHonestPairContext, resolveHonestPairPrice }
361
377
 
@@ -1,7 +1,7 @@
1
1
 
2
2
 
3
3
  import * as client from './bitshares_client.js';
4
- import { getDexbot2Root, loadDexbotOrderSystemUtils, requireDexbot2Module } from './dexbot_bridge.js';
4
+ import { loadDexbotOrderSystemUtils, requireDexbot2Module } from './dexbot_bridge.js';
5
5
  function getDexbotSystem() {
6
6
  return loadDexbotOrderSystemUtils();
7
7
  }
@@ -13,9 +13,16 @@ function derivePoolPrice(assetA: any, assetB: any, poolRef?: string | null | Rec
13
13
  try {
14
14
  const { withPoolRef: wrapWithPoolRef } = requireDexbot2Module('modules/order/utils/withPoolRef') as any;
15
15
  const override = wrapWithPoolRef(client.BitShares, resolvedPoolRef);
16
- if (override) return override.derivePoolPrice(assetA, assetB);
16
+ // The caller pinned a specific pool: honoring the pin or failing is
17
+ // correct, silently deriving from a different auto-selected pool is not.
18
+ if (!override) {
19
+ console.warn(`[liquidity-pools] derivePoolPrice could not pin pool ${resolvedPoolRef}`);
20
+ return null;
21
+ }
22
+ return override.derivePoolPrice(assetA, assetB);
17
23
  } catch (e: any) {
18
24
  console.warn(`[liquidity-pools] derivePoolPrice with poolRef failed: ${e?.message || e}`);
25
+ return null;
19
26
  }
20
27
  }
21
28
  return system.derivePoolPrice(client.BitShares, assetA, assetB);
@@ -47,5 +54,5 @@ function createDexbotPoolHelper() {
47
54
  };
48
55
  }
49
56
 
50
- export { derivePoolPrice, derivePrice, createDexbotPoolHelper, getDexbot2Root, requireDexbot2Module }
57
+ export { derivePoolPrice, derivePrice, createDexbotPoolHelper }
51
58