dexbot 1.6.15 → 1.6.17

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 (130) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +4 -4
  3. package/analysis/tradingview/README.md +2 -2
  4. package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
  5. package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +3 -2
  6. package/claw/modules/chain_queries.ts +3 -3
  7. package/claw/package.json +1 -1
  8. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  9. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  10. package/dist/analysis/ama_fitting/analyze_lambda_vs_slow.js +5 -3
  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/grid_reset_sim.js +1 -1
  20. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +2 -1
  21. package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +23 -9
  22. package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +1 -1
  23. package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +21 -2
  24. package/dist/analysis/trend_detection/kalman_chart_generator.js +1 -0
  25. package/dist/analysis/trend_detection/regime_chart_generator.js +1 -1
  26. package/dist/analysis/trend_detection/volatility_chart_generator.js +1 -0
  27. package/dist/dexbot.js +89 -138
  28. package/dist/market_adapter/inputs/fetch_book_data.js +36 -12
  29. package/dist/market_adapter/inputs/fetch_lp_data.d.ts +6 -0
  30. package/dist/market_adapter/inputs/fetch_lp_data.js +65 -19
  31. package/dist/market_adapter/inputs/kibana_feed_source.js +45 -12
  32. package/dist/market_adapter/inputs/window_cache.d.ts +14 -1
  33. package/dist/market_adapter/inputs/window_cache.js +53 -17
  34. package/dist/market_adapter/lp_chart_core.js +1 -0
  35. package/dist/market_adapter/utils/chain.js +4 -3
  36. package/dist/market_adapter/utils/pair_orientation.d.ts +60 -0
  37. package/dist/market_adapter/utils/pair_orientation.js +142 -0
  38. package/dist/modules/account_bots.d.ts +40 -3
  39. package/dist/modules/account_bots.js +77 -37
  40. package/dist/modules/account_orders.d.ts +4 -1
  41. package/dist/modules/account_orders.js +4 -1
  42. package/dist/modules/bitshares-native/resolvers.js +3 -3
  43. package/dist/modules/bitshares_client.d.ts +12 -10
  44. package/dist/modules/bitshares_client.js +12 -10
  45. package/dist/modules/bot_settings.js +3 -3
  46. package/dist/modules/chain_keys.d.ts +6 -2
  47. package/dist/modules/chain_keys.js +5 -1
  48. package/dist/modules/chain_orders.d.ts +6 -2
  49. package/dist/modules/chain_orders.js +6 -2
  50. package/dist/modules/constants.d.ts +11 -0
  51. package/dist/modules/constants.js +41 -7
  52. package/dist/modules/credit_pricing.d.ts +20 -1
  53. package/dist/modules/credit_pricing.js +23 -1
  54. package/dist/modules/credit_runtime.js +33 -16
  55. package/dist/modules/dexbot_class.d.ts +6 -2
  56. package/dist/modules/dexbot_class.js +8 -3
  57. package/dist/modules/dexbot_cow_runtime.d.ts +28 -37
  58. package/dist/modules/dexbot_cow_runtime.js +47 -66
  59. package/dist/modules/dexbot_maintenance_runtime.js +68 -10
  60. package/dist/modules/graceful_shutdown.d.ts +6 -2
  61. package/dist/modules/graceful_shutdown.js +6 -2
  62. package/dist/modules/launcher/bot_supervisor.js +4 -0
  63. package/dist/modules/launcher/credential_daemon.d.ts +14 -2
  64. package/dist/modules/launcher/credential_daemon.js +60 -26
  65. package/dist/modules/launcher/launch_modes.js +6 -3
  66. package/dist/modules/launcher/monolithic_runtime.d.ts +39 -1
  67. package/dist/modules/launcher/monolithic_runtime.js +60 -1
  68. package/dist/modules/launcher/runtime_mode.d.ts +79 -0
  69. package/dist/modules/launcher/runtime_mode.js +223 -0
  70. package/dist/modules/market_adapter_whitelist.d.ts +8 -0
  71. package/dist/modules/market_adapter_whitelist.js +8 -0
  72. package/dist/modules/order/accounting.d.ts +15 -1
  73. package/dist/modules/order/accounting.js +15 -1
  74. package/dist/modules/order/async_lock.d.ts +9 -3
  75. package/dist/modules/order/async_lock.js +9 -3
  76. package/dist/modules/order/export.d.ts +0 -5
  77. package/dist/modules/order/export.js +0 -5
  78. package/dist/modules/order/format.d.ts +6 -4
  79. package/dist/modules/order/format.js +6 -4
  80. package/dist/modules/order/grid.d.ts +36 -18
  81. package/dist/modules/order/grid.js +186 -33
  82. package/dist/modules/order/index.d.ts +16 -1
  83. package/dist/modules/order/index.js +1 -1
  84. package/dist/modules/order/logger_state.d.ts +1 -1
  85. package/dist/modules/order/logger_state.js +1 -1
  86. package/dist/modules/order/manager.d.ts +30 -7
  87. package/dist/modules/order/manager.js +108 -12
  88. package/dist/modules/order/strategy.d.ts +5 -0
  89. package/dist/modules/order/strategy.js +23 -2
  90. package/dist/modules/order/sync_engine.d.ts +26 -11
  91. package/dist/modules/order/sync_engine.js +26 -11
  92. package/dist/modules/order/utils/math.d.ts +100 -22
  93. package/dist/modules/order/utils/math.js +106 -22
  94. package/dist/modules/order/utils/order.d.ts +77 -20
  95. package/dist/modules/order/utils/order.js +125 -27
  96. package/dist/modules/order/utils/system.d.ts +107 -11
  97. package/dist/modules/order/utils/system.js +176 -11
  98. package/dist/modules/order/utils/validate.d.ts +8 -3
  99. package/dist/modules/order/utils/validate.js +10 -3
  100. package/dist/modules/types.d.ts +35 -2
  101. package/dist/modules/utils/asset_symbols.d.ts +5 -5
  102. package/dist/modules/utils/asset_symbols.js +5 -5
  103. package/dist/modules/utils/errors.d.ts +2 -1
  104. package/dist/modules/utils/errors.js +2 -1
  105. package/dist/scripts/analyze-credit.js +64 -23
  106. package/dist/scripts/bts_distribution.d.ts +66 -0
  107. package/dist/scripts/bts_distribution.js +2102 -0
  108. package/dist/scripts/rich_list.d.ts +32 -0
  109. package/dist/scripts/rich_list.js +16 -8
  110. package/dist/scripts/token_distribution.d.ts +45 -0
  111. package/dist/scripts/token_distribution.js +1870 -0
  112. package/dist/unlock.js +91 -42
  113. package/docs/BITSHARES_ONBOARDING.md +7 -0
  114. package/docs/COW_INVARIANTS.md +7 -1
  115. package/docs/DEXBOT_COMPARISON.md +5 -5
  116. package/docs/EVOLUTION.md +10 -8
  117. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -3
  118. package/docs/GRID_PRICE_INVARIANT.md +6 -0
  119. package/docs/GRID_RECALCULATION.md +18 -6
  120. package/docs/LIFECYCLE.md +8 -8
  121. package/docs/LOGGING.md +9 -0
  122. package/docs/MPA_CREDIT_USAGE.md +3 -2
  123. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +121 -4
  124. package/docs/README.md +1 -1
  125. package/docs/WORKFLOW.md +5 -5
  126. package/docs/architecture.md +98 -1
  127. package/market_adapter/README.md +10 -3
  128. package/package.json +5 -1
  129. package/scripts/README.md +85 -148
  130. package/tests/README.md +29 -0
@@ -14,5 +14,37 @@
14
14
  * CLI: dexbot rich <ASSET> [ASSET...] [--top N]
15
15
  * npm run richlist -- <ASSET> --top 10
16
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[]>;
17
49
  export {};
18
50
  //# sourceMappingURL=rich_list.d.ts.map
@@ -14,6 +14,8 @@
14
14
  * CLI: dexbot rich <ASSET> [ASSET...] [--top N]
15
15
  * npm run richlist -- <ASSET> --top 10
16
16
  */
17
+ import { pathToFileURL } from 'node:url';
18
+ import { normalizeAssetSymbol } from '../modules/utils/asset_symbols.js';
17
19
  const DB_API = 0; // database_api is always registered first
18
20
  const LOGIN_API = 1; // login_api (registered second)
19
21
  const FALLBACK_HOLDER_LIMIT = 100; // used when the node does not report api_limit_get_asset_holders
@@ -239,11 +241,16 @@ async function readHolderLimit(client) {
239
241
  // ---------------------------------------------------------------------------
240
242
  // Chain queries
241
243
  // ---------------------------------------------------------------------------
242
- async function lookupSymbols(session, symbolsOrIds) {
244
+ export async function lookupSymbols(session, symbolsOrIds) {
243
245
  const out = [];
244
246
  for (let i = 0; i < symbolsOrIds.length; i += LOOKUP_PAGE) {
245
247
  const slice = symbolsOrIds.slice(i, i + LOOKUP_PAGE);
246
- const res = await session.client.call(session.dbApi, 'lookup_asset_symbols', [slice]);
248
+ // `lookup_asset_symbols` is case-sensitive: a lowercase symbol returns
249
+ // null on-chain, so canonicalize before handing it to the node. Asset
250
+ // object ids ("1.3.x") pass through untouched. `request` keeps the
251
+ // caller's spelling so "asset not found" still echoes the input.
252
+ const refs = slice.map((s) => normalizeAssetSymbol(s));
253
+ const res = await session.client.call(session.dbApi, 'lookup_asset_symbols', [refs]);
247
254
  res.forEach((a, j) => out.push(a
248
255
  ? { request: slice[j], found: true, id: a.id, symbol: a.symbol, precision: a.precision }
249
256
  : { request: slice[j], found: false }));
@@ -255,7 +262,7 @@ async function lookupSymbols(session, symbolsOrIds) {
255
262
  * `bit` prefix, so unresolved `bit*` names are retried stripped and reported as
256
263
  * an alias.
257
264
  */
258
- async function fetchAssets(session, symbolsOrIds) {
265
+ export async function fetchAssets(session, symbolsOrIds) {
259
266
  const out = await lookupSymbols(session, symbolsOrIds);
260
267
  const retry = [];
261
268
  out.forEach((a, i) => {
@@ -453,9 +460,10 @@ async function main() {
453
460
  session.client.close();
454
461
  }
455
462
  }
456
- main().catch((e) => {
457
- console.error(`Error: ${e.message}`);
458
- process.exit(1);
459
- });
460
- export {};
463
+ if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
464
+ main().catch((e) => {
465
+ console.error(`Error: ${e.message}`);
466
+ process.exit(1);
467
+ });
468
+ }
461
469
  //# sourceMappingURL=rich_list.js.map
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * BitShares token distribution analyzer.
4
+ *
5
+ * The per-asset companion to scripts/bts_distribution.ts: answers "where is all
6
+ * of <token>?" on the live chain. Works for any issued asset (UIA/MPA) except
7
+ * the core asset (use bts_distribution for BTS).
8
+ *
9
+ * Buckets:
10
+ * - free account balances 2.5.x account_balance_object (asset_api rich list)
11
+ * - limit orders 1.7.x limit_order_object.for_sale (token sold)
12
+ * - liquidity pools 1.19.x liquidity_pool_object reserves
13
+ * - vesting balances 1.13.x vesting_balance_object (worker/witness/cashback/...)
14
+ * - P2P credit offers 1.21.x credit_offer_object.current_balance
15
+ * - P2P deal collateral 1.22.x credit_deal_object.collateral_amount
16
+ * - SameT funds 1.20.x samet_fund_object.balance
17
+ * - HTLC escrow 1.16.x htlc_object.transfer
18
+ * - accumulated market fees 2.3.x asset_dynamic_data_object.accumulated_fees
19
+ * - blinded balances 2.3.x asset_dynamic_data_object.confidential_supply
20
+ *
21
+ * The liquidity side is grouped by *counterpart asset*: every pool and every
22
+ * token sell order is bucketed by the asset on the other side of the trade
23
+ * (token/BTS, token/USD, token/other), so you can see which markets actually
24
+ * hold the token. The HTML report adds a separate liquidity donut and a 3%
25
+ * depth comparison: how much token can be sold (price -3%) or bought (price
26
+ * +3%), combining orderbook and constant-product pool per market, with the
27
+ * result also expressed as a percentage of total supply.
28
+ *
29
+ * Limit orders are not globally indexed by asset in bitshares-core, so the only
30
+ * exact enumeration is one get_limit_orders(token, other) call per listed asset
31
+ * (~6k calls on mainnet). Those calls run concurrently and are skipped with
32
+ * --no-orders.
33
+ *
34
+ * Read-only: opens its own ephemeral WebSocket, never touches a running bot,
35
+ * no keys, no transactions. Chain source of truth: bitshares-core 7.0.x.
36
+ *
37
+ * Usage:
38
+ * node dist/scripts/token_distribution.js <symbol|1.3.x>
39
+ * node dist/scripts/token_distribution.js <token> --json
40
+ * node dist/scripts/token_distribution.js <asset-id> --no-html
41
+ * node dist/scripts/token_distribution.js <token> --no-orders
42
+ * node dist/scripts/token_distribution.js <token> --node wss://cloud.xbts.io/ws
43
+ */
44
+ export {};
45
+ //# sourceMappingURL=token_distribution.d.ts.map