dexbot 1.6.14 → 1.6.16

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 (134) hide show
  1. package/CHANGELOG.md +60 -4
  2. package/README.md +4 -4
  3. package/analysis/README.md +6 -6
  4. package/analysis/tradingview/README.md +2 -1
  5. package/claw/README.md +7 -7
  6. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +3 -2
  7. package/claw/modules/chain_queries.ts +3 -3
  8. package/claw/package.json +1 -1
  9. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  10. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  11. package/dist/analysis/ama_fitting/fetch_lp_candles.js +8 -1
  12. package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +50 -1
  13. package/dist/analysis/ama_fitting/optimizer_high_resolution.js +33 -7
  14. package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +8 -6
  15. package/dist/analysis/bot_fitting/backtest_bot_fitting.js +8 -10
  16. package/dist/analysis/bot_key_utils.js +9 -7
  17. package/dist/analysis/chart_utils.d.ts +9 -2
  18. package/dist/analysis/chart_utils.js +51 -1
  19. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +2 -1
  20. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +99 -11
  21. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +57 -4
  22. package/dist/analysis/trend_detection/kalman_chart_generator.js +1 -0
  23. package/dist/analysis/trend_detection/regime_chart_generator.js +1 -1
  24. package/dist/analysis/trend_detection/volatility_chart_generator.js +1 -0
  25. package/dist/dexbot.js +112 -141
  26. package/dist/market_adapter/core/strategies/dynamic_weight_series.js +26 -11
  27. package/dist/market_adapter/inputs/fetch_book_data.js +36 -12
  28. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +6 -0
  29. package/dist/market_adapter/inputs/fetch_lp_data.js +65 -19
  30. package/dist/market_adapter/inputs/kibana_feed_source.js +45 -12
  31. package/dist/market_adapter/inputs/window_cache.d.ts +14 -1
  32. package/dist/market_adapter/inputs/window_cache.js +53 -17
  33. package/dist/market_adapter/lp_chart_core.js +1 -0
  34. package/dist/market_adapter/utils/chain.js +4 -3
  35. package/dist/market_adapter/utils/pair_orientation.d.ts +60 -0
  36. package/dist/market_adapter/utils/pair_orientation.js +142 -0
  37. package/dist/modules/account_bots.d.ts +40 -3
  38. package/dist/modules/account_bots.js +80 -37
  39. package/dist/modules/account_orders.d.ts +4 -1
  40. package/dist/modules/account_orders.js +4 -1
  41. package/dist/modules/bitshares-native/resolvers.js +3 -3
  42. package/dist/modules/bitshares-native/subscriptions.js +1 -1
  43. package/dist/modules/bitshares_client.d.ts +12 -10
  44. package/dist/modules/bitshares_client.js +12 -10
  45. package/dist/modules/bot_defaults.d.ts +13 -2
  46. package/dist/modules/bot_defaults.js +31 -2
  47. package/dist/modules/bot_settings.js +6 -3
  48. package/dist/modules/chain_keys.d.ts +5 -1
  49. package/dist/modules/chain_keys.js +5 -1
  50. package/dist/modules/chain_orders.d.ts +6 -2
  51. package/dist/modules/chain_orders.js +6 -2
  52. package/dist/modules/constants.d.ts +11 -0
  53. package/dist/modules/constants.js +31 -1
  54. package/dist/modules/credit_runtime.d.ts +35 -5
  55. package/dist/modules/credit_runtime.js +219 -38
  56. package/dist/modules/dexbot_class.d.ts +22 -2
  57. package/dist/modules/dexbot_class.js +61 -21
  58. package/dist/modules/dexbot_cow_runtime.js +19 -18
  59. package/dist/modules/dexbot_fill_runtime.d.ts +1 -1
  60. package/dist/modules/dexbot_fill_runtime.js +4 -7
  61. package/dist/modules/dexbot_maintenance_runtime.d.ts +7 -2
  62. package/dist/modules/dexbot_maintenance_runtime.js +52 -7
  63. package/dist/modules/dexbot_startup_runtime.js +3 -2
  64. package/dist/modules/dexbot_state_recovery.js +1 -1
  65. package/dist/modules/graceful_shutdown.d.ts +6 -2
  66. package/dist/modules/graceful_shutdown.js +6 -2
  67. package/dist/modules/launcher/bot_supervisor.js +4 -0
  68. package/dist/modules/launcher/launch_modes.js +6 -3
  69. package/dist/modules/launcher/monolithic_runtime.d.ts +39 -1
  70. package/dist/modules/launcher/monolithic_runtime.js +60 -1
  71. package/dist/modules/launcher/runtime_mode.d.ts +79 -0
  72. package/dist/modules/launcher/runtime_mode.js +223 -0
  73. package/dist/modules/market_adapter_whitelist.d.ts +8 -0
  74. package/dist/modules/market_adapter_whitelist.js +8 -0
  75. package/dist/modules/order/accounting.d.ts +15 -1
  76. package/dist/modules/order/accounting.js +15 -1
  77. package/dist/modules/order/async_lock.d.ts +9 -3
  78. package/dist/modules/order/async_lock.js +9 -3
  79. package/dist/modules/order/export.d.ts +0 -5
  80. package/dist/modules/order/export.js +2 -7
  81. package/dist/modules/order/format.d.ts +6 -4
  82. package/dist/modules/order/format.js +6 -4
  83. package/dist/modules/order/grid.d.ts +147 -19
  84. package/dist/modules/order/grid.js +321 -68
  85. package/dist/modules/order/grid_reconcile.js +4 -3
  86. package/dist/modules/order/grid_reconcile_internal.js +13 -18
  87. package/dist/modules/order/index.d.ts +4 -2
  88. package/dist/modules/order/index.js +1 -1
  89. package/dist/modules/order/logger_state.d.ts +1 -1
  90. package/dist/modules/order/logger_state.js +1 -1
  91. package/dist/modules/order/manager.d.ts +1 -0
  92. package/dist/modules/order/manager.js +5 -14
  93. package/dist/modules/order/sync_engine.d.ts +26 -11
  94. package/dist/modules/order/sync_engine.js +44 -20
  95. package/dist/modules/order/utils/math.d.ts +157 -47
  96. package/dist/modules/order/utils/math.js +236 -78
  97. package/dist/modules/order/utils/order.d.ts +64 -20
  98. package/dist/modules/order/utils/order.js +80 -24
  99. package/dist/modules/order/utils/system.d.ts +41 -11
  100. package/dist/modules/order/utils/system.js +43 -13
  101. package/dist/modules/order/utils/validate.d.ts +6 -3
  102. package/dist/modules/order/utils/validate.js +53 -60
  103. package/dist/modules/types.d.ts +7 -0
  104. package/dist/modules/utils/asset_symbols.d.ts +5 -5
  105. package/dist/modules/utils/asset_symbols.js +5 -5
  106. package/dist/modules/utils/errors.d.ts +2 -1
  107. package/dist/modules/utils/errors.js +2 -1
  108. package/dist/scripts/analyze-credit.js +44 -27
  109. package/dist/scripts/diagnose-pool-history.js +35 -30
  110. package/dist/scripts/pnl.js +1 -1
  111. package/dist/scripts/rich_list.d.ts +50 -0
  112. package/dist/scripts/rich_list.js +469 -0
  113. package/dist/scripts/run-tests.js +80 -4
  114. package/dist/unlock.d.ts +2 -1
  115. package/dist/unlock.js +53 -21
  116. package/docs/BITSHARES_ONBOARDING.md +7 -0
  117. package/docs/COW_INVARIANTS.md +7 -1
  118. package/docs/DEXBOT_COMPARISON.md +6 -6
  119. package/docs/EVOLUTION.md +11 -9
  120. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +3 -3
  121. package/docs/GRID_RECALCULATION.md +18 -6
  122. package/docs/LIFECYCLE.md +8 -8
  123. package/docs/LOGGING.md +16 -1
  124. package/docs/MPA_CREDIT_USAGE.md +10 -5
  125. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +163 -13
  126. package/docs/README.md +1 -1
  127. package/docs/WORKFLOW.md +6 -5
  128. package/docs/architecture.md +56 -2
  129. package/docs/developer_guide.md +5 -1
  130. package/market_adapter/README.md +14 -7
  131. package/modules/README.md +1 -1
  132. package/package.json +4 -1
  133. package/scripts/README.md +59 -32
  134. package/tests/README.md +40 -2
@@ -3,11 +3,11 @@
3
3
  *
4
4
  * BitShares stores asset symbols canonically UPPERCASE, so the assetA and
5
5
  * assetB symbols of a bot pair are always UPPERCASE on chain.
6
- * Nodes accept a lowercase lookup and answer it without error, so a lowercase
7
- * symbol never fails — it just travels on as lowercase into everything built
8
- * from it: the `symbol` field we attach to resolved assets, chart titles,
9
- * cache-file names, Kibana query terms, and strict in-process comparisons such
10
- * as the core-asset side check `assetA === 'CORE'`. That is a
6
+ * `lookup_asset_symbols` is case-sensitive: a lowercase symbol resolves to
7
+ * null (not an error), so a lowercase input silently drops the asset. Casing
8
+ * also leaks into everything built from a resolved symbol: the `symbol` field
9
+ * we attach to assets, chart titles, cache-file names, Kibana query terms, and
10
+ * strict in-process comparisons such as `assetA === 'CORE'`. That is a
11
11
  * silent-wrong-answer class of bug, not a loud
12
12
  * one, so the conversion is done ONCE here and applied at every boundary that
13
13
  * accepts a pair from a human (CLI prompts, `dexbot tv`/`dw` targets) or hands
@@ -43,7 +43,8 @@ export declare function sleepMs(ms: number): Promise<void>;
43
43
  * queries) must throw immediately — retrying those only burns time.
44
44
  *
45
45
  * Single home for the predicate previously triplicated across
46
- * kibana_client.ts / kibana_candles.ts / kibana_feed_source.ts.
46
+ * market_adapter/core/kibana_client.ts / market_adapter/core/kibana_candles.ts
47
+ * / market_adapter/inputs/kibana_feed_source.ts.
47
48
  */
48
49
  export declare function isTransientNetworkError(err: unknown): boolean;
49
50
  //# sourceMappingURL=errors.d.ts.map
@@ -70,7 +70,8 @@ export function sleepMs(ms) {
70
70
  * queries) must throw immediately — retrying those only burns time.
71
71
  *
72
72
  * Single home for the predicate previously triplicated across
73
- * kibana_client.ts / kibana_candles.ts / kibana_feed_source.ts.
73
+ * market_adapter/core/kibana_client.ts / market_adapter/core/kibana_candles.ts
74
+ * / market_adapter/inputs/kibana_feed_source.ts.
74
75
  */
75
76
  export function isTransientNetworkError(err) {
76
77
  const msg = String(getErrorMessage(err) || '');
@@ -590,7 +590,6 @@ async function main() {
590
590
  const ignoredRows = crRows.filter((r) => !r.supported);
591
591
  const pricedSupported = supportedRows.filter((r) => r.cr !== null && r.value !== null && r.debtFloat !== null);
592
592
  const unpricedSupported = supportedRows.filter((r) => r.cr === null);
593
- const avgCr = averageCreditCr(pricedSupported.map((r) => ({ debt: r.debtFloat, value: r.value })));
594
593
  async function fmtParts(m, showBiggest = false) {
595
594
  if (m.size === 0)
596
595
  return [];
@@ -639,39 +638,57 @@ async function main() {
639
638
  await printAssetLines('Credit coll', creditSumAll.coll, true, colors.buy);
640
639
  if (creditPairs.length > 0)
641
640
  console.log('');
642
- // Compact CR summary: one Avar. CR line per bot, then one Curr. CR
643
- // line per whitelisted pair. A CR exists only for pairs both whitelisted
644
- // in bots.json and listed on the current credit offer.
641
+ // Compact CR summary: one Avar. CR line per borrowed credit (debt
642
+ // asset), then one Curr. CR line per whitelisted pair. A CR exists only
643
+ // for pairs both whitelisted in bots.json and listed on the current
644
+ // credit offer.
645
645
  const feeDenom = Number(FEE_PARAMETERS?.GRAPHENE_FEE_RATE_DENOM) || 1000000;
646
646
  const walletRaw = await fetchWalletRaw(account);
647
647
  const matchPair = (pair, r) => (pair.debtId !== null && r.debtId !== null && pair.debtId === r.debtId && pair.collId !== null && r.collId !== null && pair.collId === r.collId) ||
648
648
  (isSameAssetSymbol(pair.debtSym, r.debtSym) && isSameAssetSymbol(pair.collSym, r.collSym));
649
- if (avgCr !== null) {
650
- // Label in orange to distinguish from Curr. CR; value keeps the
651
- // original health color (single shared max → green/red, mixed or
652
- // undefined max → white).
653
- const avgMaxSet = new Set();
649
+ if (pricedSupported.length > 0) {
650
+ // Group by borrowed credit (debt asset) so unrelated debt assets are
651
+ // not blended into one figure; each line carries its own
652
+ // value-weighted average CR.
653
+ const debtGroups = new Map();
654
654
  for (const r of pricedSupported) {
655
- const pair = creditPairs.find((p) => matchPair(p, r));
656
- if (pair?.maxCR != null)
657
- avgMaxSet.add(pair.maxCR);
655
+ const key = r.debtId ?? `sym:${normalizeAssetSymbol(r.debtSym)}`;
656
+ if (!debtGroups.has(key))
657
+ debtGroups.set(key, { debtSym: r.debtSym, rows: [] });
658
+ debtGroups.get(key).rows.push(r);
658
659
  }
659
- const avgMax = avgMaxSet.size === 1 ? [...avgMaxSet][0] : null;
660
- const avgColor = avgMax === null ? colors.white : avgCr > avgMax ? colors.sell : colors.buy;
661
- const pairTotals = new Map();
662
- for (const r of pricedSupported) {
663
- const key = `${r.debtSym}←${r.collSym}`;
664
- if (!pairTotals.has(key)) {
665
- pairTotals.set(key, { debtSym: r.debtSym, collSym: r.collSym, debt: 0, coll: 0 });
660
+ // Largest borrowed credit first so the biggest exposure leads.
661
+ const debtOrder = [...debtGroups.values()].sort((a, b) => b.rows.reduce((s, r) => s + (r.debtFloat || 0), 0)
662
+ - a.rows.reduce((s, r) => s + (r.debtFloat || 0), 0));
663
+ for (const group of debtOrder) {
664
+ const groupCr = averageCreditCr(group.rows.map((r) => ({ debt: r.debtFloat, value: r.value })));
665
+ if (groupCr === null)
666
+ continue;
667
+ // Label in orange to distinguish from Curr. CR; value keeps the
668
+ // original health color (single shared max → green/red, mixed or
669
+ // undefined max → white).
670
+ const groupMaxSet = new Set();
671
+ for (const r of group.rows) {
672
+ const pair = creditPairs.find((p) => matchPair(p, r));
673
+ if (pair?.maxCR != null)
674
+ groupMaxSet.add(pair.maxCR);
675
+ }
676
+ const groupMax = groupMaxSet.size === 1 ? [...groupMaxSet][0] : null;
677
+ const groupColor = groupMax === null ? colors.white : groupCr > groupMax ? colors.sell : colors.buy;
678
+ const collTotals = new Map();
679
+ for (const r of group.rows) {
680
+ const key = r.collId ?? `sym:${normalizeAssetSymbol(r.collSym)}`;
681
+ if (!collTotals.has(key))
682
+ collTotals.set(key, { collSym: r.collSym, debt: 0, coll: 0 });
683
+ const t = collTotals.get(key);
684
+ t.debt += r.debtFloat || 0;
685
+ t.coll += r.collFloat || 0;
666
686
  }
667
- const t = pairTotals.get(key);
668
- t.debt += r.debtFloat || 0;
669
- t.coll += r.collFloat || 0;
687
+ const segments = [...collTotals.values()]
688
+ .map((t) => `${formatAmount(t.debt)} ${group.debtSym} ← ${formatAmount(t.coll)} ${t.collSym}`)
689
+ .join(' + ');
690
+ console.log(` ${colors.orange}${colors.bold}Avar. CR:${colors.reset} ${groupColor}${formatAmount(groupCr)}${colors.reset}, ${segments} ${colors.gray}(x${group.rows.length})${colors.reset}`);
670
691
  }
671
- const segments = [...pairTotals.values()]
672
- .map((t) => `${formatAmount(t.debt)} ${t.debtSym} ← ${formatAmount(t.coll)} ${t.collSym}`)
673
- .join(' + ');
674
- console.log(` ${colors.orange}${colors.bold}Avar. CR:${colors.reset} ${avgColor}${formatAmount(avgCr)}${colors.reset}, ${segments} ${colors.gray}(x${pricedSupported.length})${colors.reset}`);
675
692
  }
676
693
  else if (supportedRows.length > 0) {
677
694
  console.log(` ${colors.orange}${colors.bold}Avar. CR:${colors.reset} n/a (no priced, available credit)`);
@@ -686,7 +703,7 @@ async function main() {
686
703
  reasons.push(`${unpriced} no offer price`);
687
704
  console.log(` ${colors.gray}Excluded: ${ignored + unpriced} deal${ignored + unpriced === 1 ? '' : 's'} (${reasons.join(', ')})${colors.reset}`);
688
705
  }
689
- if ((avgCr !== null || supportedRows.length > 0) && creditPairs.length > 0)
706
+ if (supportedRows.length > 0 && creditPairs.length > 0)
690
707
  console.log('');
691
708
  for (const pair of creditPairs) {
692
709
  const pairRows = supportedRows.filter((r) => matchPair(pair, r));
@@ -3,9 +3,12 @@ import { createRequire } from 'node:module';
3
3
  const require = createRequire(import.meta.url);
4
4
  'use strict';
5
5
  /**
6
- * Diagnostic: Inspect raw BitShares pool history API responses for pool 1.19.133.
6
+ * Diagnostic: Inspect raw BitShares pool history API responses for a liquidity pool.
7
7
  *
8
- * Usage: node dist/scripts/diagnose-pool-history.js [--pool <id>] [--limit <n>] [--hours <n>] [--maxPages <n>]
8
+ * The pool ID must be a concrete object ID (e.g. 1.19.133); placeholders such as
9
+ * "1.19.x" are rejected up front because the node cannot parse them as a uint64.
10
+ *
11
+ * Usage: node dist/scripts/diagnose-pool-history.js [--pool <1.19.N>] [--limit <n>] [--hours <n>] [--maxPages <n>]
9
12
  */
10
13
  const { BitShares, waitForConnected } = require('../modules/bitshares_client');
11
14
  const { getErrorMessage } = require('../modules/utils/errors');
@@ -23,6 +26,15 @@ const MAX_PAGES = process.argv.includes('--maxPages')
23
26
  ? Number(process.argv[process.argv.indexOf('--maxPages') + 1])
24
27
  : 20;
25
28
  const LP_OP_TYPE = 63;
29
+ // Fail fast on non-numeric pool IDs: the node parses the instance of a 1.19.N
30
+ // object ID as a uint64, so a placeholder like "1.19.x" surfaces as an opaque
31
+ // remote "Parse Error: Couldn't parse uint64_t".
32
+ if (!/^1\.19\.\d+$/.test(POOL_ID)) {
33
+ console.error(`Invalid pool ID: "${POOL_ID}"`);
34
+ console.error('Expected a numeric liquidity-pool object ID, e.g. 1.19.133 (not "1.19.x").');
35
+ console.error('Usage: node dist/scripts/diagnose-pool-history.js [--pool <1.19.N>] [--limit <n>] [--hours <n>] [--maxPages <n>]');
36
+ process.exit(1);
37
+ }
26
38
  function fmt(obj) {
27
39
  try {
28
40
  return JSON.stringify(obj);
@@ -198,43 +210,33 @@ async function main() {
198
210
  catch (err) {
199
211
  console.log(`Could not list methods: ${getErrorMessage(err)}`);
200
212
  }
201
- // ── Test 4: Try get_account_history for pool account ───────────
202
- console.log(`\n\n═══ TEST 4: get_account_history_by_operations for pool account ═══`);
213
+ // ── Test 4: get_liquidity_pool_history_by_sequence (pagination) ──
214
+ // Account-history APIs (get_account_history_by_operations,
215
+ // get_relative_account_history) do NOT apply here: a liquidity pool
216
+ // (1.19.N) is not an account (1.2.N). Their object IDs as the start/stop
217
+ // sequence arguments is what produced the old "Couldn't parse uint64_t".
218
+ console.log(`\n\n═══ TEST 4: get_liquidity_pool_history_by_sequence(poolId, startSeq, null, ${LIMIT}, 63) ═══`);
203
219
  try {
204
- // Pool "account" is 1.19.133 — try account history API
205
- if (typeof BitShares.history.get_account_history_by_operations === 'function') {
206
- const rows = await BitShares.history.get_account_history_by_operations(POOL_ID, [LP_OP_TYPE], '1.19.0', '1.19.999', LIMIT);
207
- console.log(`Result: ${Array.isArray(rows) ? `Array[${rows.length}]` : typeof rows}`);
208
- if (Array.isArray(rows)) {
209
- rows.slice(0, 3).forEach((r, i) => inspectRow(r, i));
210
- }
220
+ const firstPage = await BitShares.history.get_liquidity_pool_history(POOL_ID, null, null, LIMIT, LP_OP_TYPE);
221
+ const firstRows = Array.isArray(firstPage) ? firstPage : [];
222
+ const lastSeq = Number(firstRows[firstRows.length - 1]?.sequence);
223
+ if (!Number.isFinite(lastSeq) || lastSeq <= 1) {
224
+ console.log(`No usable sequence to page from (first page length: ${firstRows.length})`);
211
225
  }
212
226
  else {
213
- console.log('get_account_history_by_operations NOT available');
214
- }
215
- }
216
- catch (err) {
217
- console.log(`ERROR: ${getErrorMessage(err)}`);
218
- }
219
- // ── Test 5: Try get_relative_account_history ─────────────────
220
- console.log(`\n\n═══ TEST 5: get_relative_account_history ═══`);
221
- try {
222
- if (typeof BitShares.history.get_relative_account_history === 'function') {
223
- const rows = await BitShares.history.get_relative_account_history(POOL_ID, 0, LIMIT, 0);
227
+ const startSeq = lastSeq - 1;
228
+ const rows = await BitShares.history.get_liquidity_pool_history_by_sequence(POOL_ID, startSeq, null, LIMIT, LP_OP_TYPE);
224
229
  console.log(`Result: ${Array.isArray(rows) ? `Array[${rows.length}]` : typeof rows}`);
225
230
  if (Array.isArray(rows)) {
226
- rows.slice(0, 3).forEach((r, i) => inspectRow(r, i));
231
+ rows.slice(0, 5).forEach((r, i) => inspectRow(r, i));
227
232
  }
228
233
  }
229
- else {
230
- console.log('get_relative_account_history NOT available');
231
- }
232
234
  }
233
235
  catch (err) {
234
236
  console.log(`ERROR: ${getErrorMessage(err)}`);
235
237
  }
236
- // ── Test 6: Last 24h of trades — try to query recent only ─────
237
- console.log(`\n\n═══ TEST 6: Last 100 results with larger limit ═══`);
238
+ // ── Test 5: Last 24h of trades — try to query recent only ─────
239
+ console.log(`\n\n═══ TEST 5: Last 100 results with larger limit ═══`);
238
240
  try {
239
241
  const rows = await BitShares.history.get_liquidity_pool_history(POOL_ID, null, null, 100, LP_OP_TYPE);
240
242
  console.log(`Result: ${Array.isArray(rows) ? `Array[${rows.length}]` : typeof rows}`);
@@ -262,8 +264,8 @@ async function main() {
262
264
  catch (err) {
263
265
  console.log(`ERROR: ${getErrorMessage(err)}`);
264
266
  }
265
- // ── Test 7: Paged recent summary ──────────────────────────────
266
- console.log(`\n\n═══ TEST 7: Paged LP history summary, last ${HOURS}h ═══`);
267
+ // ── Test 6: Paged recent summary ──────────────────────────────
268
+ console.log(`\n\n═══ TEST 6: Paged LP history summary, last ${HOURS}h ═══`);
267
269
  try {
268
270
  const sinceMs = Date.now() - (HOURS * 3600 * 1000);
269
271
  const collected = await collectRecentPoolHistory(POOL_ID, sinceMs, Math.min(101, LIMIT), MAX_PAGES);
@@ -290,6 +292,9 @@ async function main() {
290
292
  if (typeof BitShares.disconnect === 'function') {
291
293
  BitShares.disconnect();
292
294
  }
295
+ // Force-exit: the native transport keeps reconnect timers alive and exposes
296
+ // no way to disable autoreconnect, so without this the process never exits.
297
+ process.exit(0);
293
298
  }
294
299
  main().catch(err => {
295
300
  console.error(`Fatal: ${getErrorMessage(err)}`);
@@ -23,7 +23,7 @@ if (invoked) {
23
23
  // explicit --html/--report untouched so their own handling wins.
24
24
  // Append (never prepend) the injected flag: the analyzer treats argv[0] as
25
25
  // the account/target positional, so a leading flag would be read as the
26
- // account name (`dexbot pnl bbot9` would become `--html bbot9`).
26
+ // account name (`dexbot pnl <account-name>` would become `--html <account-name>`).
27
27
  const hasTarget = args.some(a => !a.startsWith('-'));
28
28
  const ownsOutput = args.includes('--html') || args.includes('--report') || args.includes('--help') || args.includes('-h');
29
29
  if (hasTarget && !ownsOutput)
@@ -0,0 +1,50 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * BitShares per-asset rich list / top-holder reporter.
4
+ *
5
+ * Query one asset, or a list of assets, and print their top holders. Uses the
6
+ * chain's `asset_api` (`get_asset_holders`, `get_asset_holders_count`). Those
7
+ * endpoints are often restricted to allowlisted API users, so this script first
8
+ * tries candidate nodes that expose `asset_api` to anonymous logins.
9
+ *
10
+ * The returned holders are ordered by balance descending server-side (the
11
+ * account_balance_index `by_asset_balance` key sorts balance with
12
+ * `std::greater`), so page 0 is already the rich list.
13
+ *
14
+ * CLI: dexbot rich <ASSET> [ASSET...] [--top N]
15
+ * npm run richlist -- <ASSET> --top 10
16
+ */
17
+ interface AssetRef {
18
+ request: string;
19
+ found: boolean;
20
+ id?: string;
21
+ symbol?: string;
22
+ precision?: number;
23
+ alias?: string;
24
+ }
25
+ interface Session {
26
+ client: RpcClient;
27
+ assetApi: number;
28
+ dbApi: number;
29
+ holderLimit: number;
30
+ }
31
+ declare class RpcClient {
32
+ readonly url: string;
33
+ private _id;
34
+ private _pending;
35
+ private _closed;
36
+ private _ws;
37
+ constructor(url: string);
38
+ connect(timeoutMs?: number): Promise<void>;
39
+ call<T = unknown>(api: number, method: string, args: unknown[], timeoutMs?: number): Promise<T>;
40
+ close(): void;
41
+ }
42
+ export declare function lookupSymbols(session: Session, symbolsOrIds: string[]): Promise<AssetRef[]>;
43
+ /**
44
+ * Look up symbols/ids. Legacy `bit*` MPA names were renamed on-chain without the
45
+ * `bit` prefix, so unresolved `bit*` names are retried stripped and reported as
46
+ * an alias.
47
+ */
48
+ export declare function fetchAssets(session: Session, symbolsOrIds: string[]): Promise<AssetRef[]>;
49
+ export {};
50
+ //# sourceMappingURL=rich_list.d.ts.map