dexbot 1.6.18 → 1.7.0

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 (89) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +24 -18
  3. package/analysis/README.md +95 -3
  4. package/claw/package.json +1 -1
  5. package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
  6. package/claw/runtimes/openclaw-plugin/package.json +1 -1
  7. package/dist/analysis/analyze_dynamic_weight.js +2 -1
  8. package/dist/analysis/analyze_kalman.js +3 -2
  9. package/dist/analysis/analyze_liquidity.d.ts +17 -0
  10. package/dist/analysis/analyze_liquidity.js +325 -0
  11. package/dist/analysis/analyze_regime.js +3 -2
  12. package/dist/analysis/analyze_regime_windows.js +3 -2
  13. package/dist/analysis/analyze_volatility.js +3 -2
  14. package/dist/analysis/liquidity/liquidity_chain.d.ts +66 -0
  15. package/dist/analysis/liquidity/liquidity_chain.js +178 -0
  16. package/dist/analysis/liquidity/liquidity_chart_generator.d.ts +19 -0
  17. package/dist/analysis/liquidity/liquidity_chart_generator.js +523 -0
  18. package/dist/analysis/liquidity/liquidity_depth_model.d.ts +141 -0
  19. package/dist/analysis/liquidity/liquidity_depth_model.js +230 -0
  20. package/dist/analysis/liquidity/liquidity_view.d.ts +38 -0
  21. package/dist/analysis/liquidity/liquidity_view.js +55 -0
  22. package/dist/analysis/trade_profitability.js +2 -1
  23. package/dist/analysis/tradingview/analyze_tradingview.js +2 -1
  24. package/dist/dexbot.js +74 -169
  25. package/dist/modules/asset_lookup.d.ts +25 -0
  26. package/dist/modules/asset_lookup.js +75 -0
  27. package/dist/modules/chain_scan.d.ts +64 -0
  28. package/dist/modules/chain_scan.js +80 -0
  29. package/dist/modules/cli_colors.d.ts +5 -0
  30. package/dist/modules/cli_colors.js +7 -0
  31. package/dist/modules/cli_progress.d.ts +51 -0
  32. package/dist/modules/cli_progress.js +113 -0
  33. package/dist/modules/dexbot_cow_runtime.js +14 -4
  34. package/dist/modules/dexbot_fill_runtime.js +20 -0
  35. package/dist/modules/dexbot_maintenance_runtime.js +16 -1
  36. package/dist/modules/launcher/runtime_entry.d.ts +21 -1
  37. package/dist/modules/launcher/runtime_entry.js +36 -1
  38. package/dist/modules/liquidity_pool_ref.d.ts +32 -0
  39. package/dist/modules/liquidity_pool_ref.js +116 -0
  40. package/dist/modules/order/grid.js +9 -2
  41. package/dist/modules/order/grid_reconcile.js +22 -1
  42. package/dist/modules/order/grid_reconcile_internal.js +92 -14
  43. package/dist/modules/order/index.d.ts +15 -1
  44. package/dist/modules/order/manager.d.ts +2 -0
  45. package/dist/modules/order/manager.js +3 -0
  46. package/dist/modules/order/sync_engine.d.ts +20 -0
  47. package/dist/modules/order/sync_engine.js +101 -33
  48. package/dist/modules/order/utils/math.d.ts +18 -1
  49. package/dist/modules/order/utils/math.js +30 -1
  50. package/dist/modules/order/utils/order.d.ts +107 -1
  51. package/dist/modules/order/utils/order.js +298 -1
  52. package/dist/modules/order/utils/system.d.ts +63 -1
  53. package/dist/modules/order/utils/system.js +247 -36
  54. package/dist/modules/order/utils/validate.js +33 -2
  55. package/dist/modules/types.d.ts +5 -0
  56. package/dist/modules/utils/asset_symbols.d.ts +13 -2
  57. package/dist/modules/utils/asset_symbols.js +21 -2
  58. package/dist/scripts/analysis_runner.d.ts +10 -0
  59. package/dist/scripts/analysis_runner.js +33 -0
  60. package/dist/scripts/analyze-orders.js +2 -1
  61. package/dist/scripts/asset.d.ts +26 -0
  62. package/dist/scripts/asset.js +165 -0
  63. package/dist/scripts/bts_distribution.d.ts +1 -0
  64. package/dist/scripts/bts_distribution.js +194 -142
  65. package/dist/scripts/chart_command.d.ts +1 -1
  66. package/dist/scripts/chart_command.js +60 -86
  67. package/dist/scripts/chart_targets.d.ts +18 -0
  68. package/dist/scripts/chart_targets.js +52 -0
  69. package/dist/scripts/dw.js +1 -1
  70. package/dist/scripts/liquid.d.ts +24 -0
  71. package/dist/scripts/liquid.js +134 -0
  72. package/dist/scripts/rich_list.js +12 -16
  73. package/dist/scripts/token_distribution.d.ts +2 -0
  74. package/dist/scripts/token_distribution.js +132 -108
  75. package/dist/scripts/tv.js +1 -1
  76. package/dist/scripts/verify-browser-bundle.js +18 -0
  77. package/docs/COW_INVARIANTS.md +2 -2
  78. package/docs/DEXBOT_COMPARISON.md +6 -6
  79. package/docs/EVOLUTION.md +9 -8
  80. package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
  81. package/docs/GRID_PRICE_INVARIANT.md +4 -1
  82. package/docs/GRID_RECONCILE.md +20 -0
  83. package/docs/LOGGING.md +25 -3
  84. package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +2 -1
  85. package/docs/README.md +1 -1
  86. package/docs/WORKFLOW.md +3 -1
  87. package/modules/README.md +5 -1
  88. package/package.json +3 -1
  89. package/scripts/README.md +23 -7
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env node
2
+ 'use strict';
3
+ /**
4
+ * Usage:
5
+ * dexbot a bts [options] # shorthand for `dexbot asset bts`
6
+ * dexbot a <symbol|1.3.x> [options] # shorthand for an issued asset
7
+ * dexbot asset bts [options]
8
+ * dexbot asset <symbol|1.3.x> [options]
9
+ *
10
+ * Thin router behind the two live-chain supply distribution analyzers:
11
+ * bts -> scripts/bts_distribution.js (core asset 1.3.0)
12
+ * <symbol|1.3.x> -> scripts/token_distribution.js (any issued UIA/MPA)
13
+ *
14
+ * The analyzers own the chain scan, the terminal report and the HTML output;
15
+ * this entry only picks the target script, validates that the forwarded flags
16
+ * belong to it, and keeps the option order untouched. Per-target flag reference
17
+ * stays in the analyzers: `node dist/scripts/bts_distribution.js --help`,
18
+ * `node dist/scripts/token_distribution.js --help`.
19
+ */
20
+ import path from 'node:path';
21
+ import { dirname as _esmDirname } from 'node:path';
22
+ import { fileURLToPath, pathToFileURL } from 'node:url';
23
+ import { PATHS } from '../modules/paths.js';
24
+ import { getErrorMessage } from '../modules/utils/errors.js';
25
+ import { runRuntimeScript } from '../modules/launcher/runtime_entry.js';
26
+ const __filename = fileURLToPath(import.meta.url);
27
+ const __dirname = _esmDirname(__filename);
28
+ /** Shared by both analyzers. */
29
+ const COMMON_VALUE_FLAGS = ['--node', '--detail', '--vesting-max', '--gap', '--html'];
30
+ const COMMON_BOOLEAN_FLAGS = ['--json', '--no-html'];
31
+ /** Core-asset (BTS) analyzer only. */
32
+ const BTS_VALUE_FLAGS = ['--holders', '--circulating'];
33
+ /** Issued-asset (token) analyzer only. */
34
+ const TOKEN_VALUE_FLAGS = ['--concurrency'];
35
+ const TOKEN_BOOLEAN_FLAGS = ['--no-orders'];
36
+ const CORE_SYMBOL = 'BTS';
37
+ const CORE_ASSET_ID = '1.3.0';
38
+ const ANALYZERS = {
39
+ bts: { script: 'bts_distribution.js', label: 'BTS distribution analyzer' },
40
+ token: { script: 'token_distribution.js', label: 'Token distribution analyzer' },
41
+ };
42
+ const USAGE_SUFFIX = 'Usage: dexbot asset <bts|symbol|1.3.x> [options]';
43
+ function printUsage() {
44
+ console.log(USAGE_SUFFIX);
45
+ console.log('Live-chain supply distribution: where an asset sits across accounts, collateral,');
46
+ console.log('pools, orders, vesting and governance locks. Read-only (no keys, no transactions).');
47
+ console.log('Shorthand: dexbot a <bts|symbol|1.3.x>.');
48
+ console.log('');
49
+ console.log(' bts Core-asset supply distribution (BTS, 1.3.0)');
50
+ console.log(' <symbol|1.3.x> Issued-asset distribution (UIA/MPA) by symbol or object id');
51
+ console.log('');
52
+ console.log('Options (both targets):');
53
+ console.log(' --node URL Pin a WebSocket node (repeatable; default built-in pool)');
54
+ console.log(' --detail N Rows in detail tables');
55
+ console.log(' --vesting-max N Highest 1.13.x object id to probe');
56
+ console.log(' --gap N Stop id scans after N consecutive missing ids');
57
+ console.log(' --html PATH Report path');
58
+ console.log(' --no-html Do not write an HTML report');
59
+ console.log(' --json Print JSON instead of the terminal report (HTML still written)');
60
+ console.log(' --help Show this help');
61
+ console.log('');
62
+ console.log('bts only:');
63
+ console.log(' --holders N|all Liquid holders from asset_api (all = full rich list)');
64
+ console.log(' --circulating N Reference circulating supply to compare the derived float');
65
+ console.log('');
66
+ console.log('Issued asset only:');
67
+ console.log(' --no-orders Skip the per-asset limit-order scan (~20s on mainnet)');
68
+ console.log(' --concurrency N Concurrent get_limit_orders calls');
69
+ console.log('');
70
+ console.log('Output: analysis/charts/bts-distribution.html, analysis/charts/token-<SYMBOL>-distribution.html');
71
+ console.log('Full flag docs: node dist/scripts/bts_distribution.js --help');
72
+ console.log(' node dist/scripts/token_distribution.js --help');
73
+ }
74
+ /**
75
+ * Split `<target> <flags...>` into the analyzer identity plus the untouched
76
+ * flag list. `bts` (and the core asset id) route to the core-asset analyzer;
77
+ * anything else is an issued-asset symbol/id. Flags are validated per target so
78
+ * a `bts`-only option cannot be silently accepted (and ignored) by the token
79
+ * analyzer, or vice versa.
80
+ */
81
+ function parseArgs(argv) {
82
+ if (argv.some((arg) => arg === '--help' || arg === '-h')) {
83
+ return { kind: null, asset: null, scriptArgs: [], help: true };
84
+ }
85
+ const [first, ...args] = argv;
86
+ if (first === undefined)
87
+ return { kind: null, asset: null, scriptArgs: [], help: false };
88
+ if (first.startsWith('-')) {
89
+ throw new Error(`Expected a target (bts or an asset symbol/id). ${USAGE_SUFFIX}`);
90
+ }
91
+ const isCore = first.toLowerCase() === CORE_SYMBOL.toLowerCase() || first === CORE_ASSET_ID;
92
+ const kind = isCore ? 'bts' : 'token';
93
+ const asset = isCore ? null : first;
94
+ // `token` is not a word in this grammar — a target is either `bts` or the
95
+ // symbol itself. Catch the near-miss instead of looking up a symbol called
96
+ // "token" and reporting it as unknown.
97
+ if (asset !== null && asset.toLowerCase() === 'token' && args.length > 0 && !args[0].startsWith('-')) {
98
+ throw new Error('`token` is not a subcommand: pass the symbol directly (dexbot asset <symbol|1.3.x>).');
99
+ }
100
+ const valueFlags = new Set([...COMMON_VALUE_FLAGS, ...(kind === 'bts' ? BTS_VALUE_FLAGS : TOKEN_VALUE_FLAGS)]);
101
+ const booleanFlags = new Set([...COMMON_BOOLEAN_FLAGS, ...(kind === 'token' ? TOKEN_BOOLEAN_FLAGS : [])]);
102
+ const scriptArgs = [];
103
+ for (let i = 0; i < args.length; i++) {
104
+ const arg = args[i];
105
+ if (arg === '-h' || arg === '--help')
106
+ continue;
107
+ const eq = arg.startsWith('--') ? arg.indexOf('=') : -1;
108
+ if (eq > 0) {
109
+ const flag = arg.slice(0, eq);
110
+ if (!valueFlags.has(flag))
111
+ throw new Error(`${unknownFlagMessage(flag, kind)} ${USAGE_SUFFIX}`);
112
+ scriptArgs.push(arg);
113
+ continue;
114
+ }
115
+ if (booleanFlags.has(arg)) {
116
+ scriptArgs.push(arg);
117
+ continue;
118
+ }
119
+ if (valueFlags.has(arg)) {
120
+ const value = args[++i];
121
+ if (value === undefined)
122
+ throw new Error(`Missing value for ${arg}`);
123
+ scriptArgs.push(arg, value);
124
+ continue;
125
+ }
126
+ throw new Error(`${unknownFlagMessage(arg, kind)} ${USAGE_SUFFIX}`);
127
+ }
128
+ return { kind, asset, scriptArgs, help: false };
129
+ }
130
+ function unknownFlagMessage(flag, kind) {
131
+ if (!flag.startsWith('-'))
132
+ return `Unexpected argument "${flag}".`;
133
+ if (kind === 'bts' && (TOKEN_VALUE_FLAGS.includes(flag) || TOKEN_BOOLEAN_FLAGS.includes(flag))) {
134
+ return `${flag} applies to issued assets only; the core asset uses --holders and --circulating.`;
135
+ }
136
+ return `Unknown flag "${flag}".`;
137
+ }
138
+ /** Spawn the analyzer with inherited stdio and mirror its exit status. */
139
+ function runAnalyzer(kind, scriptArgs, asset) {
140
+ const { script, label } = ANALYZERS[kind];
141
+ const args = asset ? [asset, ...scriptArgs] : scriptArgs;
142
+ process.exitCode = runRuntimeScript(path.join(__dirname, script), args, {
143
+ label,
144
+ cwd: PATHS.PROJECT_ROOT,
145
+ });
146
+ }
147
+ async function run() {
148
+ const config = parseArgs(process.argv.slice(2));
149
+ if (config.help || !config.kind) {
150
+ printUsage();
151
+ if (!config.help)
152
+ process.exitCode = 1;
153
+ return;
154
+ }
155
+ runAnalyzer(config.kind, config.scriptArgs, config.asset);
156
+ }
157
+ const invoked = process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href;
158
+ if (invoked) {
159
+ run().catch((err) => {
160
+ console.error(`[Assets] Error: ${getErrorMessage(err)}`);
161
+ process.exit(1);
162
+ });
163
+ }
164
+ export { parseArgs, ANALYZERS, CORE_ASSET_ID };
165
+ //# sourceMappingURL=asset.js.map
@@ -54,6 +54,7 @@
54
54
  * never touches a running bot's connection) and has no runtime dependencies.
55
55
  *
56
56
  * Usage:
57
+ * dexbot asset bts [options] # CLI shortcut (also: dexbot a bts)
57
58
  * node dist/scripts/bts_distribution.js # terminal + HTML
58
59
  * node dist/scripts/bts_distribution.js --json # JSON + HTML
59
60
  * node dist/scripts/bts_distribution.js --no-html # terminal only