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.
- package/CHANGELOG.md +26 -0
- package/README.md +24 -18
- package/analysis/README.md +95 -3
- package/claw/package.json +1 -1
- package/claw/runtimes/openclaw-plugin/openclaw.plugin.json +1 -1
- package/claw/runtimes/openclaw-plugin/package.json +1 -1
- package/dist/analysis/analyze_dynamic_weight.js +2 -1
- package/dist/analysis/analyze_kalman.js +3 -2
- package/dist/analysis/analyze_liquidity.d.ts +17 -0
- package/dist/analysis/analyze_liquidity.js +325 -0
- package/dist/analysis/analyze_regime.js +3 -2
- package/dist/analysis/analyze_regime_windows.js +3 -2
- package/dist/analysis/analyze_volatility.js +3 -2
- package/dist/analysis/liquidity/liquidity_chain.d.ts +66 -0
- package/dist/analysis/liquidity/liquidity_chain.js +178 -0
- package/dist/analysis/liquidity/liquidity_chart_generator.d.ts +19 -0
- package/dist/analysis/liquidity/liquidity_chart_generator.js +523 -0
- package/dist/analysis/liquidity/liquidity_depth_model.d.ts +141 -0
- package/dist/analysis/liquidity/liquidity_depth_model.js +230 -0
- package/dist/analysis/liquidity/liquidity_view.d.ts +38 -0
- package/dist/analysis/liquidity/liquidity_view.js +55 -0
- package/dist/analysis/trade_profitability.js +2 -1
- package/dist/analysis/tradingview/analyze_tradingview.js +2 -1
- package/dist/dexbot.js +74 -169
- package/dist/modules/asset_lookup.d.ts +25 -0
- package/dist/modules/asset_lookup.js +75 -0
- package/dist/modules/chain_scan.d.ts +64 -0
- package/dist/modules/chain_scan.js +80 -0
- package/dist/modules/cli_colors.d.ts +5 -0
- package/dist/modules/cli_colors.js +7 -0
- package/dist/modules/cli_progress.d.ts +51 -0
- package/dist/modules/cli_progress.js +113 -0
- package/dist/modules/dexbot_cow_runtime.js +14 -4
- package/dist/modules/dexbot_fill_runtime.js +20 -0
- package/dist/modules/dexbot_maintenance_runtime.js +16 -1
- package/dist/modules/launcher/runtime_entry.d.ts +21 -1
- package/dist/modules/launcher/runtime_entry.js +36 -1
- package/dist/modules/liquidity_pool_ref.d.ts +32 -0
- package/dist/modules/liquidity_pool_ref.js +116 -0
- package/dist/modules/order/grid.js +9 -2
- package/dist/modules/order/grid_reconcile.js +22 -1
- package/dist/modules/order/grid_reconcile_internal.js +92 -14
- package/dist/modules/order/index.d.ts +15 -1
- package/dist/modules/order/manager.d.ts +2 -0
- package/dist/modules/order/manager.js +3 -0
- package/dist/modules/order/sync_engine.d.ts +20 -0
- package/dist/modules/order/sync_engine.js +101 -33
- package/dist/modules/order/utils/math.d.ts +18 -1
- package/dist/modules/order/utils/math.js +30 -1
- package/dist/modules/order/utils/order.d.ts +107 -1
- package/dist/modules/order/utils/order.js +298 -1
- package/dist/modules/order/utils/system.d.ts +63 -1
- package/dist/modules/order/utils/system.js +247 -36
- package/dist/modules/order/utils/validate.js +33 -2
- package/dist/modules/types.d.ts +5 -0
- package/dist/modules/utils/asset_symbols.d.ts +13 -2
- package/dist/modules/utils/asset_symbols.js +21 -2
- package/dist/scripts/analysis_runner.d.ts +10 -0
- package/dist/scripts/analysis_runner.js +33 -0
- package/dist/scripts/analyze-orders.js +2 -1
- package/dist/scripts/asset.d.ts +26 -0
- package/dist/scripts/asset.js +165 -0
- package/dist/scripts/bts_distribution.d.ts +1 -0
- package/dist/scripts/bts_distribution.js +194 -142
- package/dist/scripts/chart_command.d.ts +1 -1
- package/dist/scripts/chart_command.js +60 -86
- package/dist/scripts/chart_targets.d.ts +18 -0
- package/dist/scripts/chart_targets.js +52 -0
- package/dist/scripts/dw.js +1 -1
- package/dist/scripts/liquid.d.ts +24 -0
- package/dist/scripts/liquid.js +134 -0
- package/dist/scripts/rich_list.js +12 -16
- package/dist/scripts/token_distribution.d.ts +2 -0
- package/dist/scripts/token_distribution.js +132 -108
- package/dist/scripts/tv.js +1 -1
- package/dist/scripts/verify-browser-bundle.js +18 -0
- package/docs/COW_INVARIANTS.md +2 -2
- package/docs/DEXBOT_COMPARISON.md +6 -6
- package/docs/EVOLUTION.md +9 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/GRID_PRICE_INVARIANT.md +4 -1
- package/docs/GRID_RECONCILE.md +20 -0
- package/docs/LOGGING.md +25 -3
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +2 -1
- package/docs/README.md +1 -1
- package/docs/WORKFLOW.md +3 -1
- package/modules/README.md +5 -1
- package/package.json +3 -1
- package/scripts/README.md +23 -7
package/dist/dexbot.js
CHANGED
|
@@ -48,7 +48,8 @@ const __dirname = _esmDirname(__filename);
|
|
|
48
48
|
* Trading: dexbot test <bot> | drystart <bot> | reset {all|<bot>}
|
|
49
49
|
* Config: dexbot bot | key | enable {all|<bot>} | disable {all|<bot>} | default | update
|
|
50
50
|
* Analysis: dexbot order [<bot>] | export <bot> | credit [<bot>] | rich <asset...>
|
|
51
|
-
* dexbot tv <target> | dw <target> | pnl <account>
|
|
51
|
+
* dexbot tv <target> | dw <target> | liquid <target> | pnl <account>
|
|
52
|
+
* dexbot asset <bts|symbol> (shorthand: dexbot a <bts|symbol>)
|
|
52
53
|
* Files: dexbot clear | clear-orders | clear-market-adapter | clear-all
|
|
53
54
|
*
|
|
54
55
|
* NPM SCRIPTS (alternative invocation):
|
|
@@ -120,7 +121,7 @@ async function _resolveCollateralAssetId(ref) {
|
|
|
120
121
|
}
|
|
121
122
|
const { setupGracefulShutdown, registerCleanup, unregisterCleanup } = require('./modules/graceful_shutdown');
|
|
122
123
|
const { collectValidationIssues, loadSettingsFile, normalizeBotEntries, resolveRawBotEntries, saveSettingsFile, } = require('./modules/bot_settings');
|
|
123
|
-
const {
|
|
124
|
+
const { buildRuntimeScriptPath, runRuntimeScript } = require('./modules/launcher/runtime_entry');
|
|
124
125
|
const { parseWorkerArgs, LAUNCHER_WORKER_COMMAND } = require('./modules/launcher/launch_modes');
|
|
125
126
|
const { detectRuntimeMode, runtimeControlHelp, runtimeModeLabel, checkStatusTarget, resolveStatusRoute } = require('./modules/launcher/runtime_mode');
|
|
126
127
|
const { PATHS, getHomeProfilesDir, getRecalculateTriggerFile, printRelocationNotices } = require('./modules/paths');
|
|
@@ -143,8 +144,8 @@ if (typeof credentialPolicy.checkPolicyFileSecurity === 'function')
|
|
|
143
144
|
// Primary CLI driver that manages tracked bots and helper utilities such as key/bot editors.
|
|
144
145
|
const PROFILES_BOTS_FILE = PATHS.PROFILES.BOTS_JSON;
|
|
145
146
|
const PROFILES_DIR = PATHS.PROFILES_DIR;
|
|
146
|
-
const CLI_COMMANDS = ['start', 'test', 'reset', 'default', 'disable', 'enable', 'drystart', 'key', 'bot', 'pm2', 'update', 'export', 'order', 'credit', 'rich', 'tv', 'dw', 'pnl', 'git', 'clear', 'clear-orders', 'clear-market-adapter', 'clear-all', 'status', 'unlock', 'delete', 'stop', 'restart', 'reload', 'help'];
|
|
147
|
-
const COMMAND_ALIASES = { orders: 'order', keys: 'key', bots: 'bot', stat: 'status', stats: 'status', start: 'unlock', defaults: 'default', stp: 'stop', stopall: 'stop', restartall: 'restart', reloadall: 'reload' };
|
|
147
|
+
const CLI_COMMANDS = ['start', 'test', 'reset', 'default', 'disable', 'enable', 'drystart', 'key', 'bot', 'pm2', 'update', 'export', 'order', 'credit', 'rich', 'tv', 'dw', 'liquid', 'pnl', 'asset', 'git', 'clear', 'clear-orders', 'clear-market-adapter', 'clear-all', 'status', 'unlock', 'delete', 'stop', 'restart', 'reload', 'help'];
|
|
148
|
+
const COMMAND_ALIASES = { orders: 'order', keys: 'key', bots: 'bot', stat: 'status', stats: 'status', start: 'unlock', defaults: 'default', stp: 'stop', stopall: 'stop', restartall: 'restart', reloadall: 'reload', liq: 'liquid', liqu: 'liquid', liquidity: 'liquid', a: 'asset' };
|
|
148
149
|
const CLI_HELP_FLAGS = ['-h', '--help'];
|
|
149
150
|
const CLI_EXAMPLES_FLAG = '--cli-examples';
|
|
150
151
|
const CLI_EXAMPLES = [
|
|
@@ -159,7 +160,9 @@ const CLI_EXAMPLES = [
|
|
|
159
160
|
{ title: 'Analyze order grids', command: 'dexbot order', notes: 'Spread, increment, and funds; --export for HTML.' },
|
|
160
161
|
{ title: 'Show live credit positions', command: 'dexbot credit', notes: 'Summed MPA + borrowed-credit positions per bot.' },
|
|
161
162
|
{ title: 'Asset rich list', command: 'dexbot rich <asset> [<asset...>]', notes: 'Top holder(s) per asset from the chain asset holders API.' },
|
|
162
|
-
{ title: 'Chart a bot, pool, or pair', command: 'dexbot tv <bot|pool
|
|
163
|
+
{ title: 'Chart a bot, pool, or pair', command: 'dexbot tv <bot|pool|AssetA/AssetB> --month 3', notes: 'OHLC chart; pool = id (133) or pool token (LP share asset); --feed charts MPA price-feed history.' },
|
|
164
|
+
{ title: 'Liquidity depth chart', command: 'dexbot liquid <bot|pool|AssetA/AssetB>', notes: 'Order-book + AMM pool cumulative depth; pool = id or pool token (aliases: liq, liqu, liquidity).' },
|
|
165
|
+
{ title: 'Asset supply distribution', command: 'dexbot a bts', notes: 'Where BTS sits (collateral, pools, locks, residual) + HTML report. A bare symbol (dexbot a <symbol>) covers an issued asset; canonical: asset.' },
|
|
163
166
|
{ title: 'PnL report', command: 'dexbot pnl <bot|account> --month 3 [--pair BASE/QUOTE]', notes: 'Self-contained HTML PnL report for the resolved bot or chain account.' }
|
|
164
167
|
];
|
|
165
168
|
const STARTUP_COLORS = {
|
|
@@ -207,14 +210,19 @@ function printCLIUsage() {
|
|
|
207
210
|
['default', 'Reset generated settings to defaults.'],
|
|
208
211
|
['update', 'Update DEXBot2 and restart active bots.'],
|
|
209
212
|
]],
|
|
213
|
+
// Ordered by the investigation an operator actually runs: grid state and its
|
|
214
|
+
// data export, then market research, then accounting/chain context. Keep the
|
|
215
|
+
// README "Bot Management" block in the same order so the two cannot drift.
|
|
210
216
|
['Analysis', [
|
|
211
217
|
['order [<bot>]', 'Analyze persisted order grids; --export for HTML.'],
|
|
212
218
|
['export <bot>', 'Export bot trades/settings to CSV/JSON.'],
|
|
213
|
-
['
|
|
214
|
-
['rich <asset...>', 'Per-asset rich list / top holder; --top N, --json.'],
|
|
215
|
-
['tv <target>', 'OHLC chart for <bot|pool-id|AssetA/AssetB>; --month N (default 3), --feed for MPA price-feed history.'],
|
|
219
|
+
['tv <target>', 'OHLC chart for <bot|pool|AssetA/AssetB> (pool = id or pool token); --month N (default 3), --feed for MPA price-feed history.'],
|
|
216
220
|
['dw <target>', 'Dynamic-weight research chart; same targets and flags as tv.'],
|
|
221
|
+
['liquid <target>', 'Liquidity depth chart for <bot|pool|AssetA/AssetB> (pool = id or pool token); --range, --depth, --steps (aliases: liq, liqu, liquidity).'],
|
|
217
222
|
['pnl <account>', 'HTML PnL report for a bot or account; --month N, optional --pair BASE/QUOTE filter.'],
|
|
223
|
+
['credit [<bot>]', 'Show live MPA and borrowed-credit positions.'],
|
|
224
|
+
['asset <bts|symbol>', 'Supply distribution: bts = core asset, bare symbol/id = issued asset; --json, --html (shorthand: a, e.g. dexbot a bts).'],
|
|
225
|
+
['rich <asset...>', 'Per-asset rich list / top holder; --top N, --json.'],
|
|
218
226
|
]],
|
|
219
227
|
['Files', [
|
|
220
228
|
['clear', 'Delete log files. Stop the runtime first.'],
|
|
@@ -265,7 +273,7 @@ if (cliArgs.some(arg => CLI_HELP_FLAGS.includes(arg))) {
|
|
|
265
273
|
// so the script prints its usage. Only scripts with offline help handling
|
|
266
274
|
// belong here — forwarding to a script without it could misinterpret the
|
|
267
275
|
// flag as input (e.g. a bot-name filter triggering live work).
|
|
268
|
-
const HELP_OWNING_COMMANDS = new Set(['credit', 'rich', 'tv', 'dw', 'pnl']);
|
|
276
|
+
const HELP_OWNING_COMMANDS = new Set(['credit', 'rich', 'tv', 'dw', 'liquid', 'pnl', 'asset']);
|
|
269
277
|
const requestedCommand = COMMAND_ALIASES[cliArgs[0]] ?? cliArgs[0];
|
|
270
278
|
if (!HELP_OWNING_COMMANDS.has(requestedCommand)) {
|
|
271
279
|
printCLIUsage();
|
|
@@ -842,9 +850,38 @@ async function exportBotTrades(botName) {
|
|
|
842
850
|
process.exit(1);
|
|
843
851
|
}
|
|
844
852
|
}
|
|
853
|
+
/**
|
|
854
|
+
* Script-backed commands: command name → entry-point segments under the code
|
|
855
|
+
* root. Every entry owns its own argument parsing and usage text (the
|
|
856
|
+
* HELP_OWNING_COMMANDS set forwards `--help` to it), so the CLI only spawns it
|
|
857
|
+
* and mirrors the exit code.
|
|
858
|
+
*/
|
|
859
|
+
const SCRIPT_COMMANDS = {
|
|
860
|
+
order: ['scripts', 'analyze-orders'],
|
|
861
|
+
credit: ['scripts', 'analyze-credit'],
|
|
862
|
+
rich: ['scripts', 'rich_list'],
|
|
863
|
+
git: ['scripts', 'analyze-git'],
|
|
864
|
+
tv: ['scripts', 'tv'],
|
|
865
|
+
dw: ['scripts', 'dw'],
|
|
866
|
+
liquid: ['scripts', 'liquid'],
|
|
867
|
+
pnl: ['scripts', 'pnl'],
|
|
868
|
+
asset: ['scripts', 'asset'],
|
|
869
|
+
};
|
|
870
|
+
/**
|
|
871
|
+
* Spawn a runtime entry point with inherited stdio and exit with its status.
|
|
872
|
+
* `rest` defaults to the CLI arguments after the command.
|
|
873
|
+
*
|
|
874
|
+
* Returns `true` after `process.exit` so a caller whose exit is intercepted
|
|
875
|
+
* (tests) still stops the command instead of falling through the switch.
|
|
876
|
+
*/
|
|
877
|
+
function exitWithRuntimeScript(segments, label, rest = cliArgs.slice(1)) {
|
|
878
|
+
const status = runRuntimeScript(buildRuntimeScriptPath(__dirname, segments), rest, { label, cwd: PATHS.PROJECT_ROOT });
|
|
879
|
+
process.exit(status);
|
|
880
|
+
return true;
|
|
881
|
+
}
|
|
845
882
|
/**
|
|
846
883
|
* Parse and execute CLI commands.
|
|
847
|
-
* Supported commands: test, drystart, reset, default, disable, enable, key, bot, pm2, update, export, order, credit, tv, dw, clear, status, unlock, help
|
|
884
|
+
* Supported commands: test, drystart, reset, default, disable, enable, key, bot, pm2, update, export, order, credit, tv, dw, liquid, pnl, asset, clear, status, unlock, help
|
|
848
885
|
* @returns {Promise<boolean>} True if a command was handled, false otherwise
|
|
849
886
|
*/
|
|
850
887
|
async function handleCLICommands() {
|
|
@@ -942,32 +979,12 @@ async function handleCLICommands() {
|
|
|
942
979
|
}
|
|
943
980
|
process.exit(0);
|
|
944
981
|
return true;
|
|
945
|
-
case 'pm2':
|
|
946
|
-
const { spawnSync } = require('child_process');
|
|
982
|
+
case 'pm2':
|
|
947
983
|
// Forward the remaining CLI args to pm2.js so subcommands work
|
|
948
984
|
// (`dexbot pm2 stop <bot>`, `dexbot pm2 restart all`, `dexbot pm2
|
|
949
|
-
// help`...).
|
|
950
|
-
//
|
|
951
|
-
|
|
952
|
-
// buildRuntimeScriptArgs resolves the pm2 entry point under the
|
|
953
|
-
// dist-only runtime layout (dist/pm2.js); plain node executes
|
|
954
|
-
// compiled entries since the tsx removal.
|
|
955
|
-
const pm2Args = buildRuntimeScriptArgs({
|
|
956
|
-
codeRoot: __dirname,
|
|
957
|
-
scriptSegments: ['pm2'],
|
|
958
|
-
scriptArgs: cliArgs.slice(1),
|
|
959
|
-
});
|
|
960
|
-
const result = spawnSync(Config.EXEC_PATH, pm2Args, {
|
|
961
|
-
cwd: PATHS.PROJECT_ROOT,
|
|
962
|
-
stdio: 'inherit',
|
|
963
|
-
});
|
|
964
|
-
if (result.error) {
|
|
965
|
-
console.error(`pm2: ${result.error.message}`);
|
|
966
|
-
process.exit(1);
|
|
967
|
-
}
|
|
968
|
-
process.exit(result.status ?? 0);
|
|
969
|
-
return true;
|
|
970
|
-
}
|
|
985
|
+
// help`...). A dropped subcommand used to make `dexbot pm2 start X`
|
|
986
|
+
// start ALL bots and `dexbot pm2 stop X` no-op into a full setup.
|
|
987
|
+
return exitWithRuntimeScript(['pm2'], 'pm2');
|
|
971
988
|
case 'update':
|
|
972
989
|
setSuppressConnectionLog(true);
|
|
973
990
|
require('./scripts/update');
|
|
@@ -977,118 +994,24 @@ async function handleCLICommands() {
|
|
|
977
994
|
await exportBotTrades(target);
|
|
978
995
|
process.exit(0);
|
|
979
996
|
return true;
|
|
980
|
-
case 'order':
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
scriptSegments: ['scripts', 'analyze-orders'],
|
|
985
|
-
scriptArgs: cliArgs.slice(1),
|
|
986
|
-
});
|
|
987
|
-
const result = spawnSync(Config.EXEC_PATH, scriptArgs, {
|
|
988
|
-
cwd: PATHS.PROJECT_ROOT,
|
|
989
|
-
stdio: 'inherit',
|
|
990
|
-
});
|
|
991
|
-
if (result.error) {
|
|
992
|
-
console.error(`order: ${result.error.message}`);
|
|
993
|
-
process.exit(1);
|
|
994
|
-
}
|
|
995
|
-
process.exit(result.status ?? 0);
|
|
996
|
-
return true;
|
|
997
|
-
}
|
|
998
|
-
case 'credit': {
|
|
999
|
-
const { spawnSync } = require('child_process');
|
|
1000
|
-
const scriptArgs = buildRuntimeScriptArgs({
|
|
1001
|
-
codeRoot: __dirname,
|
|
1002
|
-
scriptSegments: ['scripts', 'analyze-credit'],
|
|
1003
|
-
scriptArgs: cliArgs.slice(1),
|
|
1004
|
-
});
|
|
1005
|
-
const result = spawnSync(Config.EXEC_PATH, scriptArgs, {
|
|
1006
|
-
cwd: PATHS.PROJECT_ROOT,
|
|
1007
|
-
stdio: 'inherit',
|
|
1008
|
-
});
|
|
1009
|
-
if (result.error) {
|
|
1010
|
-
console.error(`credit: ${result.error.message}`);
|
|
1011
|
-
process.exit(1);
|
|
1012
|
-
}
|
|
1013
|
-
process.exit(result.status ?? 0);
|
|
1014
|
-
return true;
|
|
1015
|
-
}
|
|
1016
|
-
case 'rich': {
|
|
1017
|
-
const { spawnSync } = require('child_process');
|
|
1018
|
-
const scriptArgs = buildRuntimeScriptArgs({
|
|
1019
|
-
codeRoot: __dirname,
|
|
1020
|
-
scriptSegments: ['scripts', 'rich_list'],
|
|
1021
|
-
scriptArgs: cliArgs.slice(1),
|
|
1022
|
-
});
|
|
1023
|
-
const result = spawnSync(Config.EXEC_PATH, scriptArgs, {
|
|
1024
|
-
cwd: PATHS.PROJECT_ROOT,
|
|
1025
|
-
stdio: 'inherit',
|
|
1026
|
-
});
|
|
1027
|
-
if (result.error) {
|
|
1028
|
-
console.error(`rich: ${result.error.message}`);
|
|
1029
|
-
process.exit(1);
|
|
1030
|
-
}
|
|
1031
|
-
process.exit(result.status ?? 0);
|
|
1032
|
-
return true;
|
|
1033
|
-
}
|
|
1034
|
-
case 'git': {
|
|
1035
|
-
// Repository statistics analyzer (scripts/analyze-git.ts): parses
|
|
1036
|
-
// git history and writes analysis/charts/repo-stats.html. Git-only;
|
|
1037
|
-
// it requires a source checkout (.git present).
|
|
1038
|
-
const { spawnSync } = require('child_process');
|
|
1039
|
-
const scriptArgs = buildRuntimeScriptArgs({
|
|
1040
|
-
codeRoot: __dirname,
|
|
1041
|
-
scriptSegments: ['scripts', 'analyze-git'],
|
|
1042
|
-
});
|
|
1043
|
-
const result = spawnSync(Config.EXEC_PATH, scriptArgs, {
|
|
1044
|
-
cwd: PATHS.PROJECT_ROOT,
|
|
1045
|
-
stdio: 'inherit',
|
|
1046
|
-
});
|
|
1047
|
-
if (result.error) {
|
|
1048
|
-
console.error(`git: ${result.error.message}`);
|
|
1049
|
-
process.exit(1);
|
|
1050
|
-
}
|
|
1051
|
-
process.exit(result.status ?? 0);
|
|
1052
|
-
return true;
|
|
1053
|
-
}
|
|
997
|
+
case 'order':
|
|
998
|
+
case 'credit':
|
|
999
|
+
case 'rich':
|
|
1000
|
+
case 'git':
|
|
1054
1001
|
case 'tv':
|
|
1055
1002
|
case 'dw':
|
|
1056
|
-
case '
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
console.error(`${command}: ${result.error.message}`);
|
|
1069
|
-
process.exit(1);
|
|
1070
|
-
}
|
|
1071
|
-
process.exit(result.status ?? 0);
|
|
1072
|
-
return true;
|
|
1073
|
-
}
|
|
1074
|
-
case 'unlock': {
|
|
1075
|
-
const { spawnSync } = require('child_process');
|
|
1076
|
-
// buildRuntimeScriptArgs resolves the unlock entry point for the
|
|
1077
|
-
// active runtime layout: dist/unlock.js when compiled, unlock.ts
|
|
1078
|
-
// in source layouts. A hard-coded dist path silently no-ops
|
|
1079
|
-
// (ENOENT -> exit 0), hiding the launcher.
|
|
1080
|
-
const unlockArgs = buildRuntimeScriptArgs({
|
|
1081
|
-
codeRoot: __dirname,
|
|
1082
|
-
scriptSegments: ['unlock'],
|
|
1083
|
-
scriptArgs: cliArgs.slice(1),
|
|
1084
|
-
});
|
|
1085
|
-
const result = spawnSync(Config.EXEC_PATH, unlockArgs, {
|
|
1086
|
-
cwd: PATHS.PROJECT_ROOT,
|
|
1087
|
-
stdio: 'inherit',
|
|
1088
|
-
});
|
|
1089
|
-
process.exit(result.status ?? 0);
|
|
1090
|
-
return true;
|
|
1091
|
-
}
|
|
1003
|
+
case 'liquid':
|
|
1004
|
+
case 'pnl':
|
|
1005
|
+
case 'asset':
|
|
1006
|
+
// Registered analysis/utility entry points; each one owns its
|
|
1007
|
+
// argument parsing, usage text and `--help` (see
|
|
1008
|
+
// HELP_OWNING_COMMANDS), so the CLI only forwards argv.
|
|
1009
|
+
return exitWithRuntimeScript(SCRIPT_COMMANDS[command], command);
|
|
1010
|
+
case 'unlock':
|
|
1011
|
+
// Resolved through buildRuntimeScriptPath for the active runtime
|
|
1012
|
+
// layout (dist/unlock.js when compiled). A hard-coded dist path used
|
|
1013
|
+
// to no-op silently (ENOENT -> exit 0), hiding the launcher.
|
|
1014
|
+
return exitWithRuntimeScript(['unlock'], 'unlock');
|
|
1092
1015
|
case 'clear':
|
|
1093
1016
|
case 'clear-orders':
|
|
1094
1017
|
case 'clear-market-adapter':
|
|
@@ -1168,7 +1091,6 @@ async function handleCLICommands() {
|
|
|
1168
1091
|
process.exit(code);
|
|
1169
1092
|
return true;
|
|
1170
1093
|
};
|
|
1171
|
-
const { spawnSync } = require('child_process');
|
|
1172
1094
|
// Centralized detection (modules/launcher/runtime_mode.ts), shared
|
|
1173
1095
|
// with the mode-aware help output so the two cannot disagree.
|
|
1174
1096
|
const runtimeInfo = detectRuntimeMode();
|
|
@@ -1176,16 +1098,8 @@ async function handleCLICommands() {
|
|
|
1176
1098
|
// so the report matches the help banner; otherwise a live unlock
|
|
1177
1099
|
// runtime is shown by delegating to `unlock status`.
|
|
1178
1100
|
if (resolveStatusRoute(runtimeInfo) === 'unlock') {
|
|
1179
|
-
const
|
|
1180
|
-
|
|
1181
|
-
scriptSegments: ['unlock'],
|
|
1182
|
-
scriptArgs: ['status', ...(target ? [target] : [])],
|
|
1183
|
-
});
|
|
1184
|
-
const result = spawnSync(Config.EXEC_PATH, unlockArgs, {
|
|
1185
|
-
cwd: PATHS.PROJECT_ROOT,
|
|
1186
|
-
stdio: 'inherit',
|
|
1187
|
-
});
|
|
1188
|
-
return finish(result.status ?? 0);
|
|
1101
|
+
const status = runRuntimeScript(buildRuntimeScriptPath(__dirname, ['unlock']), ['status', ...(target ? [target] : [])], { label: 'unlock', cwd: PATHS.PROJECT_ROOT });
|
|
1102
|
+
return finish(status);
|
|
1189
1103
|
}
|
|
1190
1104
|
// status is whole-runtime on every surface. With no unlock bot
|
|
1191
1105
|
// runtime up, validate and ignore a bot name here so the behavior
|
|
@@ -1262,20 +1176,11 @@ async function handleCLICommands() {
|
|
|
1262
1176
|
case 'delete':
|
|
1263
1177
|
case 'stop':
|
|
1264
1178
|
case 'restart':
|
|
1265
|
-
case 'reload':
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
scriptArgs: [command, ...cliArgs.slice(1)],
|
|
1271
|
-
});
|
|
1272
|
-
const result = spawnSync(Config.EXEC_PATH, unlockArgs, {
|
|
1273
|
-
cwd: PATHS.PROJECT_ROOT,
|
|
1274
|
-
stdio: 'inherit',
|
|
1275
|
-
});
|
|
1276
|
-
process.exit(result.status ?? 0);
|
|
1277
|
-
return true;
|
|
1278
|
-
}
|
|
1179
|
+
case 'reload':
|
|
1180
|
+
// The unlock runtime owns every lifecycle verb (stop/restart/
|
|
1181
|
+
// reload/delete) for both modes, so the CLI forwards the verb plus
|
|
1182
|
+
// the remaining arguments and mirrors the exit code.
|
|
1183
|
+
return exitWithRuntimeScript(['unlock'], command, [command, ...cliArgs.slice(1)]);
|
|
1279
1184
|
case 'help':
|
|
1280
1185
|
printCLIUsage();
|
|
1281
1186
|
process.exit(0);
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** Ids/refs per `get_assets` call; get_assets has no page limit to respect. */
|
|
2
|
+
declare const LOOKUP_BATCH = 250;
|
|
3
|
+
type ChainRead = (method: string, args: unknown[]) => Promise<unknown>;
|
|
4
|
+
interface RawAssetObject {
|
|
5
|
+
id?: string;
|
|
6
|
+
symbol?: string;
|
|
7
|
+
precision?: number;
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
}
|
|
10
|
+
interface AssetLookupResult {
|
|
11
|
+
/** The reference exactly as the caller passed it (for error messages). */
|
|
12
|
+
request: string;
|
|
13
|
+
/** The chain object, or null when the reference does not exist. */
|
|
14
|
+
asset: RawAssetObject | null;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Resolve asset references (symbols in any case, or `1.3.x` ids), preserving
|
|
18
|
+
* the caller's order. Unresolvable references come back with `asset: null`.
|
|
19
|
+
*/
|
|
20
|
+
declare function lookupAssetRefs(read: ChainRead, refs: unknown[]): Promise<AssetLookupResult[]>;
|
|
21
|
+
/** Resolve one asset reference, or null when it does not exist on chain. */
|
|
22
|
+
declare function resolveAssetRef(read: ChainRead, ref: unknown): Promise<RawAssetObject | null>;
|
|
23
|
+
export { LOOKUP_BATCH, lookupAssetRefs, resolveAssetRef };
|
|
24
|
+
export type { ChainRead, RawAssetObject, AssetLookupResult };
|
|
25
|
+
//# sourceMappingURL=asset_lookup.d.ts.map
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* CHAIN ASSET LOOKUP (case-insensitive, one implementation)
|
|
4
|
+
*
|
|
5
|
+
* Every CLI path that takes an asset from a human — `dexbot asset <symbol>`,
|
|
6
|
+
* `dexbot rich <asset...>`, `dexbot liq`/`tv`/`dw` pairs, the liquidity
|
|
7
|
+
* analyzer's `--base/--quote`, pool tokens — resolves it through here.
|
|
8
|
+
*
|
|
9
|
+
* BitShares stores symbols canonically UPPERCASE and `get_assets` /
|
|
10
|
+
* `lookup_asset_symbols` are case-sensitive, so `dexbot asset token.sym`
|
|
11
|
+
* found nothing while `TOKEN.SYM` worked. The reference is therefore
|
|
12
|
+
* normalized with `normalizeAssetSymbol` (modules/utils/asset_symbols.ts) and
|
|
13
|
+
* looked up in ONE batched `get_assets` call, which accepts symbols and
|
|
14
|
+
* `1.3.x` ids alike and returns the extended asset object.
|
|
15
|
+
*
|
|
16
|
+
* Only when the canonical spelling misses is the spelling as typed retried, so
|
|
17
|
+
* a node that really does hold a non-canonical symbol still resolves.
|
|
18
|
+
*
|
|
19
|
+
* The reader is injected, so the module stays browser-safe.
|
|
20
|
+
*/
|
|
21
|
+
import { assetSymbolCandidates } from './utils/asset_symbols.js';
|
|
22
|
+
/** Ids/refs per `get_assets` call; get_assets has no page limit to respect. */
|
|
23
|
+
const LOOKUP_BATCH = 250;
|
|
24
|
+
function chunk(items, size) {
|
|
25
|
+
const out = [];
|
|
26
|
+
for (let i = 0; i < items.length; i += size)
|
|
27
|
+
out.push(items.slice(i, i + size));
|
|
28
|
+
return out;
|
|
29
|
+
}
|
|
30
|
+
async function getAssets(read, refs) {
|
|
31
|
+
const out = [];
|
|
32
|
+
for (const batch of chunk(refs, LOOKUP_BATCH)) {
|
|
33
|
+
const rows = await read('get_assets', [batch]);
|
|
34
|
+
for (let i = 0; i < batch.length; i++) {
|
|
35
|
+
const row = Array.isArray(rows) ? rows[i] : null;
|
|
36
|
+
out.push(row && typeof row.id === 'string' ? row : null);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return out;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Resolve asset references (symbols in any case, or `1.3.x` ids), preserving
|
|
43
|
+
* the caller's order. Unresolvable references come back with `asset: null`.
|
|
44
|
+
*/
|
|
45
|
+
async function lookupAssetRefs(read, refs) {
|
|
46
|
+
const requested = refs.map((ref) => String(ref ?? '').trim());
|
|
47
|
+
// Canonical spelling first (ids pass through), spelling as typed as fallback.
|
|
48
|
+
const candidates = requested.map((ref) => assetSymbolCandidates(ref));
|
|
49
|
+
const primary = candidates.map((list) => list[1] ?? list[0] ?? '');
|
|
50
|
+
// Nothing to look up for empty refs; keep the slots so order is preserved.
|
|
51
|
+
const indexes = requested.map((_, index) => index).filter((index) => primary[index] !== '');
|
|
52
|
+
const resolved = new Map();
|
|
53
|
+
if (indexes.length > 0) {
|
|
54
|
+
const rows = await getAssets(read, indexes.map((index) => primary[index]));
|
|
55
|
+
indexes.forEach((index, offset) => resolved.set(index, rows[offset] ?? null));
|
|
56
|
+
// A node could hold a non-canonical (lowercase) symbol: retry just those
|
|
57
|
+
// refs with the spelling as typed, once, in a single batch.
|
|
58
|
+
const retry = indexes.filter((index) => !resolved.get(index) && (candidates[index][0] ?? '') !== primary[index]);
|
|
59
|
+
if (retry.length > 0) {
|
|
60
|
+
const retried = await getAssets(read, retry.map((index) => candidates[index][0]));
|
|
61
|
+
retry.forEach((index, offset) => {
|
|
62
|
+
if (retried[offset])
|
|
63
|
+
resolved.set(index, retried[offset]);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
return requested.map((request, index) => ({ request, asset: resolved.get(index) ?? null }));
|
|
68
|
+
}
|
|
69
|
+
/** Resolve one asset reference, or null when it does not exist on chain. */
|
|
70
|
+
async function resolveAssetRef(read, ref) {
|
|
71
|
+
const [result] = await lookupAssetRefs(read, [ref]);
|
|
72
|
+
return result?.asset ?? null;
|
|
73
|
+
}
|
|
74
|
+
export { LOOKUP_BATCH, lookupAssetRefs, resolveAssetRef };
|
|
75
|
+
//# sourceMappingURL=asset_lookup.js.map
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CHAIN OBJECT-ID SCAN
|
|
3
|
+
*
|
|
4
|
+
* Some object types have no list API: legacy 1.15.x balance objects and 1.13.x
|
|
5
|
+
* vesting balances can only be enumerated by probing ids with `get_objects`,
|
|
6
|
+
* which answers `null` for holes. Ids are allocated monotonically and never
|
|
7
|
+
* reused, so a range is "dense-ish" — walking from 0 and stopping after `gap`
|
|
8
|
+
* consecutive misses finds every live object without knowing where the range
|
|
9
|
+
* ends.
|
|
10
|
+
*
|
|
11
|
+
* Two details keep that affordable on every report:
|
|
12
|
+
* - one large `get_objects` batch per round trip (1000 ids measurably beats
|
|
13
|
+
* 100 by ~4x because the per-call overhead dominates), with an automatic
|
|
14
|
+
* halving fallback for nodes that refuse big batches, and
|
|
15
|
+
* - no filtering here: callers filter the objects they need (e.g. by
|
|
16
|
+
* `balance.asset_id`), because the node exposes no per-asset index for
|
|
17
|
+
* these types.
|
|
18
|
+
*
|
|
19
|
+
* The module is pure (the reader is injected), so it stays browser-safe.
|
|
20
|
+
*/
|
|
21
|
+
/** Ids per `get_objects` call; all public nodes accept this batch size. */
|
|
22
|
+
declare const DEFAULT_SCAN_BATCH = 1000;
|
|
23
|
+
/** Never fall below this when backing off, so a refusal cannot loop forever. */
|
|
24
|
+
declare const MIN_SCAN_BATCH = 100;
|
|
25
|
+
/**
|
|
26
|
+
* Trailing miss budget for the dense implementation spaces (2.3.x, 2.4.x, 1.3.x,
|
|
27
|
+
* 1.16.x): one object per asset / smart asset, ids never reused, holes measured
|
|
28
|
+
* in single digits. The legacy spaces (1.13.x vesting, 1.15.x balances) have
|
|
29
|
+
* real holes and keep the larger `--gap` default.
|
|
30
|
+
*/
|
|
31
|
+
declare const DENSE_SPACE_GAP = 2000;
|
|
32
|
+
interface ChainScanOptions {
|
|
33
|
+
/** Database reader; `read('get_objects', [ids])` must resolve to `(T|null)[]`. */
|
|
34
|
+
read: (method: string, args: unknown[]) => Promise<unknown>;
|
|
35
|
+
/** Object id prefix, e.g. `'1.15'`. */
|
|
36
|
+
prefix: string;
|
|
37
|
+
/** Highest id to probe (the walk always starts at 0). */
|
|
38
|
+
maxId: number;
|
|
39
|
+
/** Stop after this many consecutive missing ids. */
|
|
40
|
+
gap: number;
|
|
41
|
+
/**
|
|
42
|
+
* Ids per call (default 1000). An explicit smaller value is honoured as-is;
|
|
43
|
+
* a node error halves the batch down to `MIN_SCAN_BATCH`.
|
|
44
|
+
*/
|
|
45
|
+
batchSize?: number;
|
|
46
|
+
/** Called after each batch with the number of ids walked so far. */
|
|
47
|
+
onProgress?: (scanned: number) => void;
|
|
48
|
+
}
|
|
49
|
+
interface ChainScanResult<T> {
|
|
50
|
+
objects: T[];
|
|
51
|
+
/** Number of ids walked (exclusive upper bound of the scanned range). */
|
|
52
|
+
scannedTo: number;
|
|
53
|
+
/** True when the walk stopped at `maxId`, so the range may be truncated. */
|
|
54
|
+
hitLimit: boolean;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Walk `prefix.0 … prefix.maxId` in batches and collect every live object.
|
|
58
|
+
*
|
|
59
|
+
* @throws when `get_objects` keeps failing even at `MIN_SCAN_BATCH`.
|
|
60
|
+
*/
|
|
61
|
+
declare function scanIdRange<T>(options: ChainScanOptions): Promise<ChainScanResult<T>>;
|
|
62
|
+
export { scanIdRange, DEFAULT_SCAN_BATCH, DENSE_SPACE_GAP, MIN_SCAN_BATCH };
|
|
63
|
+
export type { ChainScanOptions, ChainScanResult };
|
|
64
|
+
//# sourceMappingURL=chain_scan.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
/**
|
|
3
|
+
* CHAIN OBJECT-ID SCAN
|
|
4
|
+
*
|
|
5
|
+
* Some object types have no list API: legacy 1.15.x balance objects and 1.13.x
|
|
6
|
+
* vesting balances can only be enumerated by probing ids with `get_objects`,
|
|
7
|
+
* which answers `null` for holes. Ids are allocated monotonically and never
|
|
8
|
+
* reused, so a range is "dense-ish" — walking from 0 and stopping after `gap`
|
|
9
|
+
* consecutive misses finds every live object without knowing where the range
|
|
10
|
+
* ends.
|
|
11
|
+
*
|
|
12
|
+
* Two details keep that affordable on every report:
|
|
13
|
+
* - one large `get_objects` batch per round trip (1000 ids measurably beats
|
|
14
|
+
* 100 by ~4x because the per-call overhead dominates), with an automatic
|
|
15
|
+
* halving fallback for nodes that refuse big batches, and
|
|
16
|
+
* - no filtering here: callers filter the objects they need (e.g. by
|
|
17
|
+
* `balance.asset_id`), because the node exposes no per-asset index for
|
|
18
|
+
* these types.
|
|
19
|
+
*
|
|
20
|
+
* The module is pure (the reader is injected), so it stays browser-safe.
|
|
21
|
+
*/
|
|
22
|
+
/** Ids per `get_objects` call; all public nodes accept this batch size. */
|
|
23
|
+
const DEFAULT_SCAN_BATCH = 1000;
|
|
24
|
+
/** Never fall below this when backing off, so a refusal cannot loop forever. */
|
|
25
|
+
const MIN_SCAN_BATCH = 100;
|
|
26
|
+
/**
|
|
27
|
+
* Trailing miss budget for the dense implementation spaces (2.3.x, 2.4.x, 1.3.x,
|
|
28
|
+
* 1.16.x): one object per asset / smart asset, ids never reused, holes measured
|
|
29
|
+
* in single digits. The legacy spaces (1.13.x vesting, 1.15.x balances) have
|
|
30
|
+
* real holes and keep the larger `--gap` default.
|
|
31
|
+
*/
|
|
32
|
+
const DENSE_SPACE_GAP = 2_000;
|
|
33
|
+
/**
|
|
34
|
+
* Walk `prefix.0 … prefix.maxId` in batches and collect every live object.
|
|
35
|
+
*
|
|
36
|
+
* @throws when `get_objects` keeps failing even at `MIN_SCAN_BATCH`.
|
|
37
|
+
*/
|
|
38
|
+
async function scanIdRange(options) {
|
|
39
|
+
const { read, prefix, maxId, gap, onProgress } = options;
|
|
40
|
+
let batch = Math.max(1, Math.floor(options.batchSize ?? DEFAULT_SCAN_BATCH));
|
|
41
|
+
const objects = [];
|
|
42
|
+
let index = 0;
|
|
43
|
+
let lastSeen = -1;
|
|
44
|
+
// `gap` means exactly "gap consecutive missing ids": after the last live
|
|
45
|
+
// object only ids up to lastSeen+gap are worth probing. Clipping the batch
|
|
46
|
+
// to that bound makes the walk independent of the batch size — without it a
|
|
47
|
+
// larger batch probes (and reports) further than the documented --gap.
|
|
48
|
+
while (index <= maxId) {
|
|
49
|
+
const limit = Math.min(maxId, lastSeen + gap);
|
|
50
|
+
if (index > limit)
|
|
51
|
+
break;
|
|
52
|
+
const count = Math.min(batch, limit - index + 1);
|
|
53
|
+
const ids = Array.from({ length: count }, (_, i) => `${prefix}.${index + i}`);
|
|
54
|
+
let page;
|
|
55
|
+
try {
|
|
56
|
+
page = await read('get_objects', [ids]);
|
|
57
|
+
}
|
|
58
|
+
catch (err) {
|
|
59
|
+
// A node may cap the batch size; retry the same window smaller
|
|
60
|
+
// instead of failing the whole report.
|
|
61
|
+
if (batch > MIN_SCAN_BATCH) {
|
|
62
|
+
batch = Math.max(MIN_SCAN_BATCH, Math.floor(batch / 2));
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
throw err;
|
|
66
|
+
}
|
|
67
|
+
for (let j = 0; j < count; j++) {
|
|
68
|
+
const obj = page?.[j];
|
|
69
|
+
if (obj) {
|
|
70
|
+
lastSeen = index + j;
|
|
71
|
+
objects.push(obj);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
index += count;
|
|
75
|
+
onProgress?.(index);
|
|
76
|
+
}
|
|
77
|
+
return { objects, scannedTo: index, hitLimit: index > maxId };
|
|
78
|
+
}
|
|
79
|
+
export { scanIdRange, DEFAULT_SCAN_BATCH, DENSE_SPACE_GAP, MIN_SCAN_BATCH };
|
|
80
|
+
//# sourceMappingURL=chain_scan.js.map
|
|
@@ -35,4 +35,9 @@ export declare const CLI_COLORS: {
|
|
|
35
35
|
readonly silver: "\u001B[38;5;250m";
|
|
36
36
|
readonly greenBold: "\u001B[1;32m";
|
|
37
37
|
};
|
|
38
|
+
/**
|
|
39
|
+
* Wrap text in one of the {@link CLI_COLORS} codes and reset afterwards —
|
|
40
|
+
* the `c(colors.x, text)` helper each CLI used to declare locally.
|
|
41
|
+
*/
|
|
42
|
+
export declare function colorize(code: string, text: string): string;
|
|
38
43
|
//# sourceMappingURL=cli_colors.d.ts.map
|
|
@@ -39,4 +39,11 @@ export const CLI_COLORS = {
|
|
|
39
39
|
silver: '\x1b[38;5;250m', // light silver grey (bots editor)
|
|
40
40
|
greenBold: '\x1b[1;32m', // bold green (bots editor)
|
|
41
41
|
};
|
|
42
|
+
/**
|
|
43
|
+
* Wrap text in one of the {@link CLI_COLORS} codes and reset afterwards —
|
|
44
|
+
* the `c(colors.x, text)` helper each CLI used to declare locally.
|
|
45
|
+
*/
|
|
46
|
+
export function colorize(code, text) {
|
|
47
|
+
return `${code}${text}${CLI_COLORS.reset}`;
|
|
48
|
+
}
|
|
42
49
|
//# sourceMappingURL=cli_colors.js.map
|