dexbot 1.4.25 → 1.5.1
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 +54 -0
- package/README.md +6 -2
- package/analysis/README.md +14 -7
- package/analysis/ama_fitting/package.json +1 -1
- package/analysis/analyze_derivatives.ts +1 -1
- package/analysis/bot_key_utils.ts +272 -3
- package/analysis/bot_usage/discover_bot_accounts.ts +64 -9
- package/analysis/bot_usage/kibana_bot_queries.ts +40 -1
- package/analysis/chart_utils.ts +6 -3
- package/analysis/grid_correction_check.ts +56 -20
- package/analysis/resolve_bot_accounts.ts +199 -0
- package/analysis/trade_profitability.ts +36 -8
- package/analysis/tradingview/README.md +25 -0
- package/analysis/tradingview/analyze_tradingview.ts +2 -2
- package/analysis/trend_detection/package.json +1 -1
- package/claw/modules/claw_launcher.ts +5 -4
- package/claw/modules/credit_runtime_adapter.ts +2 -1
- package/claw/modules/dexbot_profiles.ts +4 -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/claw/tests/test_claw_mcp_transport.ts +2 -2
- package/dist/analysis/analyze_derivatives.js +1 -1
- package/dist/analysis/bot_key_utils.d.ts +28 -1
- package/dist/analysis/bot_key_utils.d.ts.map +1 -1
- package/dist/analysis/bot_key_utils.js +385 -3
- package/dist/analysis/bot_key_utils.js.map +1 -1
- package/dist/analysis/bot_usage/discover_bot_accounts.js +60 -10
- package/dist/analysis/bot_usage/discover_bot_accounts.js.map +1 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts +45 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.d.ts.map +1 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js +39 -1
- package/dist/analysis/bot_usage/kibana_bot_queries.js.map +1 -1
- package/dist/analysis/chart_utils.d.ts +2 -1
- package/dist/analysis/chart_utils.d.ts.map +1 -1
- package/dist/analysis/chart_utils.js +4 -1
- package/dist/analysis/chart_utils.js.map +1 -1
- package/dist/analysis/grid_correction_check.d.ts.map +1 -1
- package/dist/analysis/grid_correction_check.js +60 -20
- package/dist/analysis/grid_correction_check.js.map +1 -1
- package/dist/analysis/resolve_bot_accounts.d.ts +3 -0
- package/dist/analysis/resolve_bot_accounts.d.ts.map +1 -0
- package/dist/analysis/resolve_bot_accounts.js +216 -0
- package/dist/analysis/resolve_bot_accounts.js.map +1 -0
- package/dist/analysis/trade_profitability.d.ts.map +1 -1
- package/dist/analysis/trade_profitability.js +40 -8
- package/dist/analysis/trade_profitability.js.map +1 -1
- package/dist/analysis/tradingview/analyze_tradingview.js +2 -2
- package/dist/analysis/tradingview/analyze_tradingview.js.map +1 -1
- package/dist/bot.d.ts.map +1 -1
- package/dist/bot.js +2 -1
- package/dist/bot.js.map +1 -1
- package/dist/dexbot.d.ts.map +1 -1
- package/dist/dexbot.js +73 -17
- package/dist/dexbot.js.map +1 -1
- package/dist/market_adapter/ama_signal_runner.js +2 -2
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js +2 -1
- package/dist/market_adapter/inputs/fetch_cex_synthetic_data.js.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +4 -1
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts.map +1 -1
- package/dist/market_adapter/inputs/fetch_lp_data.js +3 -2
- package/dist/market_adapter/inputs/fetch_lp_data.js.map +1 -1
- package/dist/modules/account_bots.d.ts +42 -1
- package/dist/modules/account_bots.d.ts.map +1 -1
- package/dist/modules/account_bots.js +168 -17
- package/dist/modules/account_bots.js.map +1 -1
- package/dist/modules/account_orders.d.ts +7 -1
- package/dist/modules/account_orders.d.ts.map +1 -1
- package/dist/modules/account_orders.js +34 -1
- package/dist/modules/account_orders.js.map +1 -1
- package/dist/modules/bitshares_client.d.ts +4 -1
- package/dist/modules/bitshares_client.d.ts.map +1 -1
- package/dist/modules/bitshares_client.js +12 -4
- package/dist/modules/bitshares_client.js.map +1 -1
- package/dist/modules/bot_settings.d.ts.map +1 -1
- package/dist/modules/bot_settings.js +2 -1
- package/dist/modules/bot_settings.js.map +1 -1
- package/dist/modules/cli_colors.d.ts +39 -0
- package/dist/modules/cli_colors.d.ts.map +1 -0
- package/dist/modules/cli_colors.js +42 -0
- package/dist/modules/cli_colors.js.map +1 -0
- package/dist/modules/constants.d.ts +2 -0
- package/dist/modules/constants.d.ts.map +1 -1
- package/dist/modules/constants.js +27 -11
- package/dist/modules/constants.js.map +1 -1
- package/dist/modules/credit_pricing.d.ts +61 -0
- package/dist/modules/credit_pricing.d.ts.map +1 -0
- package/dist/modules/credit_pricing.js +237 -0
- package/dist/modules/credit_pricing.js.map +1 -0
- package/dist/modules/credit_runtime.d.ts +1 -0
- package/dist/modules/credit_runtime.d.ts.map +1 -1
- package/dist/modules/credit_runtime.js +49 -107
- package/dist/modules/credit_runtime.js.map +1 -1
- package/dist/modules/dexbot_class.d.ts +3 -1
- package/dist/modules/dexbot_class.d.ts.map +1 -1
- package/dist/modules/dexbot_class.js +22 -6
- package/dist/modules/dexbot_class.js.map +1 -1
- package/dist/modules/dexbot_cow_runtime.d.ts +36 -2
- package/dist/modules/dexbot_cow_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_cow_runtime.js +434 -20
- package/dist/modules/dexbot_cow_runtime.js.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.d.ts +15 -16
- package/dist/modules/dexbot_maintenance_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_maintenance_runtime.js +69 -42
- package/dist/modules/dexbot_maintenance_runtime.js.map +1 -1
- package/dist/modules/dexbot_startup_runtime.d.ts +1 -0
- package/dist/modules/dexbot_startup_runtime.d.ts.map +1 -1
- package/dist/modules/dexbot_startup_runtime.js +12 -1
- package/dist/modules/dexbot_startup_runtime.js.map +1 -1
- package/dist/modules/dexbot_state_recovery.d.ts.map +1 -1
- package/dist/modules/dexbot_state_recovery.js +7 -0
- package/dist/modules/dexbot_state_recovery.js.map +1 -1
- package/dist/modules/fund_registry.d.ts +1 -1
- package/dist/modules/fund_registry.js +1 -1
- package/dist/modules/launcher/adapter_requirement.d.ts +38 -0
- package/dist/modules/launcher/adapter_requirement.d.ts.map +1 -0
- package/dist/modules/launcher/adapter_requirement.js +141 -0
- package/dist/modules/launcher/adapter_requirement.js.map +1 -0
- package/dist/modules/launcher/bot_supervisor.d.ts +2 -2
- package/dist/modules/launcher/bot_supervisor.d.ts.map +1 -1
- package/dist/modules/launcher/bot_supervisor.js +32 -3
- package/dist/modules/launcher/bot_supervisor.js.map +1 -1
- package/dist/modules/launcher/launch_modes.d.ts.map +1 -1
- package/dist/modules/launcher/launch_modes.js +5 -4
- package/dist/modules/launcher/launch_modes.js.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts +1 -1
- package/dist/modules/launcher/monolithic_runtime.d.ts.map +1 -1
- package/dist/modules/launcher/monolithic_runtime.js +12 -8
- package/dist/modules/launcher/monolithic_runtime.js.map +1 -1
- package/dist/modules/launcher/status_reporting.d.ts +6 -6
- package/dist/modules/launcher/status_reporting.d.ts.map +1 -1
- package/dist/modules/launcher/status_reporting.js +9 -6
- package/dist/modules/launcher/status_reporting.js.map +1 -1
- package/dist/modules/order/accounting.d.ts +34 -0
- package/dist/modules/order/accounting.d.ts.map +1 -1
- package/dist/modules/order/accounting.js +182 -5
- package/dist/modules/order/accounting.js.map +1 -1
- package/dist/modules/order/export.d.ts +1 -1
- package/dist/modules/order/export.js +1 -1
- package/dist/modules/order/grid.d.ts.map +1 -1
- package/dist/modules/order/grid.js +68 -28
- package/dist/modules/order/grid.js.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.d.ts.map +1 -1
- package/dist/modules/order/grid_reconcile_internal.js +72 -0
- package/dist/modules/order/grid_reconcile_internal.js.map +1 -1
- package/dist/modules/order/logger.d.ts +23 -1
- package/dist/modules/order/logger.d.ts.map +1 -1
- package/dist/modules/order/logger.js +60 -17
- package/dist/modules/order/logger.js.map +1 -1
- package/dist/modules/order/manager.d.ts +41 -1
- package/dist/modules/order/manager.d.ts.map +1 -1
- package/dist/modules/order/manager.js +186 -17
- package/dist/modules/order/manager.js.map +1 -1
- package/dist/modules/order/strategy.d.ts.map +1 -1
- package/dist/modules/order/strategy.js +17 -2
- package/dist/modules/order/strategy.js.map +1 -1
- package/dist/modules/order/sync_engine.d.ts.map +1 -1
- package/dist/modules/order/sync_engine.js +59 -9
- package/dist/modules/order/sync_engine.js.map +1 -1
- package/dist/modules/order/utils/math.d.ts +42 -1
- package/dist/modules/order/utils/math.d.ts.map +1 -1
- package/dist/modules/order/utils/math.js +91 -1
- package/dist/modules/order/utils/math.js.map +1 -1
- package/dist/modules/order/utils/order.d.ts +52 -1
- package/dist/modules/order/utils/order.d.ts.map +1 -1
- package/dist/modules/order/utils/order.js +137 -7
- package/dist/modules/order/utils/order.js.map +1 -1
- package/dist/modules/order/utils/system.d.ts +66 -4
- package/dist/modules/order/utils/system.d.ts.map +1 -1
- package/dist/modules/order/utils/system.js +156 -16
- package/dist/modules/order/utils/system.js.map +1 -1
- package/dist/modules/order/utils/validate.d.ts +30 -3
- package/dist/modules/order/utils/validate.d.ts.map +1 -1
- package/dist/modules/order/utils/validate.js +206 -11
- package/dist/modules/order/utils/validate.js.map +1 -1
- package/dist/modules/utils/chain_logs.d.ts +11 -0
- package/dist/modules/utils/chain_logs.d.ts.map +1 -0
- package/dist/modules/utils/chain_logs.js +23 -0
- package/dist/modules/utils/chain_logs.js.map +1 -0
- package/dist/modules/utils/sanitize_key.d.ts +7 -0
- package/dist/modules/utils/sanitize_key.d.ts.map +1 -1
- package/dist/modules/utils/sanitize_key.js +15 -0
- package/dist/modules/utils/sanitize_key.js.map +1 -1
- package/dist/pm2.d.ts +11 -1
- package/dist/pm2.d.ts.map +1 -1
- package/dist/pm2.js +66 -15
- package/dist/pm2.js.map +1 -1
- package/dist/scripts/analyze-credit.d.ts +4 -0
- package/dist/scripts/analyze-credit.d.ts.map +1 -0
- package/dist/scripts/analyze-credit.js +760 -0
- package/dist/scripts/analyze-credit.js.map +1 -0
- package/dist/scripts/analyze-orders.d.ts +1 -10
- package/dist/scripts/analyze-orders.d.ts.map +1 -1
- package/dist/scripts/analyze-orders.js +11 -34
- package/dist/scripts/analyze-orders.js.map +1 -1
- package/dist/scripts/test-credit-renewal.d.ts.map +1 -1
- package/dist/scripts/test-credit-renewal.js +37 -5
- package/dist/scripts/test-credit-renewal.js.map +1 -1
- package/dist/scripts/tv.d.ts +11 -0
- package/dist/scripts/tv.d.ts.map +1 -0
- package/dist/scripts/tv.js +357 -0
- package/dist/scripts/tv.js.map +1 -0
- package/dist/scripts/update.js +77 -10
- package/dist/scripts/update.js.map +1 -1
- package/dist/unlock.d.ts.map +1 -1
- package/dist/unlock.js +20 -8
- package/dist/unlock.js.map +1 -1
- package/docs/DEXBOT_COMPARISON.md +3 -3
- package/docs/EVOLUTION.md +8 -6
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +3 -1
- package/docs/GRID_RECONCILE.md +1 -0
- package/docs/LOGGING.md +3 -0
- package/docs/MPA_CREDIT_USAGE.md +3 -1
- package/docs/README.md +2 -2
- package/docs/WORKFLOW.md +3 -1
- package/package.json +2 -1
- package/scripts/README.md +12 -0
|
@@ -18,12 +18,16 @@ const { writeJSON } = getStorage();
|
|
|
18
18
|
* Q1 — top 100 accounts by limit_order_create count
|
|
19
19
|
* Q2 — top 100 accounts by limit_order_cancel count
|
|
20
20
|
* Q3 — top 100 accounts by fill_order count
|
|
21
|
+
* Q4 — top 200 accounts by limit_order_update count (op 77, DEXBot2 fingerprint)
|
|
21
22
|
* 2. Merge & pre-filter:
|
|
22
23
|
* creates ≥ MIN_CREATES (grid analysis determines DEXBot candidacy)
|
|
23
24
|
* 3. Grid analysis (parallel, batches of 5):
|
|
24
25
|
* Fetch 200 raw orders per candidate → per-session geometric spacing test
|
|
25
26
|
* 4. BitShares: resolve account IDs → names (batch db.get_objects call)
|
|
26
|
-
* 5. Rank by DEX score and print table
|
|
27
|
+
* 5. Rank by DEX score and print table.
|
|
28
|
+
* HIGH tier (80+) is split by op-77 usage:
|
|
29
|
+
* updates ≥ 1 → DEXBot2 (native limit_order_update in-place re-price)
|
|
30
|
+
* updates = 0 → DEXBot1-style (cancel-only, cancel + recreate)
|
|
27
31
|
*
|
|
28
32
|
* Usage:
|
|
29
33
|
* node dist/analysis/bot_usage/discover_bot_accounts.js
|
|
@@ -51,6 +55,7 @@ import {
|
|
|
51
55
|
buildTopSellerAccountsQuery,
|
|
52
56
|
buildTopCancellerAccountsQuery,
|
|
53
57
|
buildTopFilledAccountsQuery,
|
|
58
|
+
buildTopUpdaterAccountsQuery,
|
|
54
59
|
DEFAULT_CONFIG,
|
|
55
60
|
} from './kibana_bot_queries.js';
|
|
56
61
|
import { NODE_MANAGEMENT } from '../../modules/constants.js';
|
|
@@ -61,6 +66,7 @@ interface AccountCounts {
|
|
|
61
66
|
creates: number;
|
|
62
67
|
cancels: number;
|
|
63
68
|
fills: number;
|
|
69
|
+
updates: number;
|
|
64
70
|
}
|
|
65
71
|
|
|
66
72
|
interface CandidateInfo {
|
|
@@ -68,6 +74,8 @@ interface CandidateInfo {
|
|
|
68
74
|
creates: number;
|
|
69
75
|
cancels: number;
|
|
70
76
|
fills: number;
|
|
77
|
+
updates: number;
|
|
78
|
+
flavor: 'DEXBot2' | 'DEXBot1' | '';
|
|
71
79
|
cancelRatio: number;
|
|
72
80
|
fillRate: number;
|
|
73
81
|
gridScore: number;
|
|
@@ -323,18 +331,21 @@ async function run() {
|
|
|
323
331
|
|
|
324
332
|
console.log('Phase 1: Querying Kibana for top active accounts...');
|
|
325
333
|
|
|
326
|
-
const [createRes, cancelRes, fillRes]: any[] = await Promise.all([
|
|
334
|
+
const [createRes, cancelRes, fillRes, updateRes]: any[] = await Promise.all([
|
|
327
335
|
withRetry(() => kibanaSearch(KIBANA_CFG, buildTopSellerAccountsQuery(lookbackH, 200, opts.minCreates)),
|
|
328
336
|
'top-seller query'),
|
|
329
337
|
withRetry(() => kibanaSearch(KIBANA_CFG, buildTopCancellerAccountsQuery(lookbackH, 200, 5)),
|
|
330
338
|
'top-canceller query'),
|
|
331
339
|
withRetry(() => kibanaSearch(KIBANA_CFG, buildTopFilledAccountsQuery(lookbackH, 200, 3)),
|
|
332
340
|
'top-fills query'),
|
|
341
|
+
withRetry(() => kibanaSearch(KIBANA_CFG, buildTopUpdaterAccountsQuery(lookbackH, 200, 1)),
|
|
342
|
+
'top-updater query'),
|
|
333
343
|
]);
|
|
334
344
|
|
|
335
345
|
const createBuckets = createRes?.aggregations?.by_account?.buckets ?? [];
|
|
336
346
|
const cancelBuckets = cancelRes?.aggregations?.by_account?.buckets ?? [];
|
|
337
347
|
const fillBuckets = fillRes?.aggregations?.by_account?.buckets ?? [];
|
|
348
|
+
const updateBuckets = updateRes?.aggregations?.by_account?.buckets ?? [];
|
|
338
349
|
|
|
339
350
|
if (opts.verbose) {
|
|
340
351
|
console.log(` [verbose] createRes keys: ${Object.keys(createRes ?? {}).join(', ')}`);
|
|
@@ -344,6 +355,7 @@ async function run() {
|
|
|
344
355
|
console.log(` Creates: ${createBuckets.length} accounts with ≥${opts.minCreates} creates`);
|
|
345
356
|
console.log(` Cancels: ${cancelBuckets.length} accounts with ≥5 cancels`);
|
|
346
357
|
console.log(` Fills: ${fillBuckets.length} accounts with ≥3 fills`);
|
|
358
|
+
console.log(` Updates: ${updateBuckets.length} accounts with ≥1 limit_order_update (op 77)`);
|
|
347
359
|
|
|
348
360
|
if (createBuckets.length === 0) {
|
|
349
361
|
console.log('');
|
|
@@ -360,17 +372,23 @@ async function run() {
|
|
|
360
372
|
console.log('\nPhase 2: Merging and filtering candidates...');
|
|
361
373
|
|
|
362
374
|
const accounts: Record<string, AccountCounts> = {};
|
|
363
|
-
for (const b of createBuckets) accounts[b.key] = { creates: b.doc_count, cancels: 0, fills: 0 };
|
|
375
|
+
for (const b of createBuckets) accounts[b.key] = { creates: b.doc_count, cancels: 0, fills: 0, updates: 0 };
|
|
364
376
|
for (const b of cancelBuckets) {
|
|
365
|
-
if (!accounts[b.key]) accounts[b.key] = { creates: 0, cancels: 0, fills: 0 };
|
|
377
|
+
if (!accounts[b.key]) accounts[b.key] = { creates: 0, cancels: 0, fills: 0, updates: 0 };
|
|
366
378
|
accounts[b.key].cancels = b.doc_count;
|
|
367
379
|
}
|
|
368
380
|
for (const b of fillBuckets) {
|
|
369
|
-
if (!accounts[b.key]) accounts[b.key] = { creates: 0, cancels: 0, fills: 0 };
|
|
381
|
+
if (!accounts[b.key]) accounts[b.key] = { creates: 0, cancels: 0, fills: 0, updates: 0 };
|
|
370
382
|
accounts[b.key].fills = b.doc_count;
|
|
371
383
|
}
|
|
384
|
+
for (const b of updateBuckets) {
|
|
385
|
+
if (!accounts[b.key]) accounts[b.key] = { creates: 0, cancels: 0, fills: 0, updates: 0 };
|
|
386
|
+
accounts[b.key].updates = b.doc_count;
|
|
387
|
+
}
|
|
372
388
|
|
|
373
389
|
// Pre-filter: must have creates ≥ minCreates (grid analysis determines DEXBot candidacy)
|
|
390
|
+
// Flavor: any limit_order_update (op 77) in-window → DEXBot2 (native in-place
|
|
391
|
+
// re-price); zero updates → DEXBot1-style (cancel-only: cancel + recreate).
|
|
374
392
|
const candidates: CandidateInfo[] = (Object.entries(accounts) as [string, AccountCounts][])
|
|
375
393
|
.filter(([, s]) => s.creates >= opts.minCreates)
|
|
376
394
|
.map(([id, s]) => ({
|
|
@@ -378,6 +396,8 @@ async function run() {
|
|
|
378
396
|
creates: s.creates,
|
|
379
397
|
cancels: s.cancels,
|
|
380
398
|
fills: s.fills,
|
|
399
|
+
updates: s.updates,
|
|
400
|
+
flavor: (s.updates >= 1 ? 'DEXBot2' : 'DEXBot1') as 'DEXBot2' | 'DEXBot1',
|
|
381
401
|
cancelRatio: s.cancels / Math.max(s.creates, 1),
|
|
382
402
|
fillRate: s.creates > 0 ? (s.fills / s.creates * 100) : 0,
|
|
383
403
|
} as CandidateInfo))
|
|
@@ -492,9 +512,41 @@ async function run() {
|
|
|
492
512
|
console.log('════════════════════════════════════════════════════════════════════════════════════');
|
|
493
513
|
console.log('');
|
|
494
514
|
|
|
495
|
-
// Print by DEX score tier
|
|
515
|
+
// Print by DEX score tier. HIGH tier (80+) splits by update-order usage:
|
|
516
|
+
// DEXBot2 — broadcast limit_order_update (op 77) in-window (in-place re-price)
|
|
517
|
+
// DEXBot1-style — cancel-only, no op 77 (cancel + recreate)
|
|
518
|
+
const highV2 = results.filter(r => r.dexScore >= 80 && r.updates >= 1);
|
|
519
|
+
const highV1 = results.filter(r => r.dexScore >= 80 && r.updates < 1);
|
|
520
|
+
|
|
521
|
+
const hdrHigh = ' # Name ID Creates Fills Cancel Fill% C/C MaxBatch Incr% Grid DEX Updates';
|
|
522
|
+
function printHighGroup(label: string, rows: CandidateInfo[]) {
|
|
523
|
+
if (!rows.length) return;
|
|
524
|
+
console.log(` ── ${label}`);
|
|
525
|
+
console.log('');
|
|
526
|
+
console.log(hdrHigh);
|
|
527
|
+
console.log(' ' + '─'.repeat(hdrHigh.length - 1));
|
|
528
|
+
for (const r of rows) {
|
|
529
|
+
const rank = String(results.indexOf(r) + 1).padStart(2);
|
|
530
|
+
const name = r.name.padEnd(22).slice(0, 22);
|
|
531
|
+
const id = r.id.padEnd(14);
|
|
532
|
+
const creates = String(r.creates).padStart(7);
|
|
533
|
+
const fills = String(r.fills).padStart(6);
|
|
534
|
+
const cancels = String(r.cancels).padStart(7);
|
|
535
|
+
const fr = (r.fillRate.toFixed(1) + '%').padStart(5);
|
|
536
|
+
const cr = r.cancelRatio.toFixed(2).padStart(4);
|
|
537
|
+
const batch = String(r.maxBatch || '-').padStart(9);
|
|
538
|
+
const inc = (r.impliedInc != null ? r.impliedInc.toFixed(2) + '%' : 'n/a').padStart(6);
|
|
539
|
+
const grid = String(r.gridScore).padStart(5);
|
|
540
|
+
const dex = String(r.dexScore).padStart(4);
|
|
541
|
+
const upd = String(r.updates).padStart(7);
|
|
542
|
+
console.log(` ${rank} ${name} ${id} ${creates} ${fills} ${cancels} ${fr} ${cr} ${batch} ${inc} ${grid} ${dex} ${upd}`);
|
|
543
|
+
}
|
|
544
|
+
console.log('');
|
|
545
|
+
}
|
|
546
|
+
printHighGroup('HIGH confidence — DEXBot2 (80+, uses limit_order_update op 77)', highV2);
|
|
547
|
+
printHighGroup('HIGH confidence — DEXBot1-style (80+, cancel-only, no op 77)', highV1);
|
|
548
|
+
|
|
496
549
|
const tiers = [
|
|
497
|
-
{ label: 'HIGH confidence (80+) — almost certainly DEXBot/DEXBot2', min: 80, max: 101 },
|
|
498
550
|
{ label: 'MEDIUM confidence (50–79) — likely a grid bot', min: 50, max: 80 },
|
|
499
551
|
{ label: 'LOW confidence (25–49) — some automation detected', min: 25, max: 50 },
|
|
500
552
|
{ label: 'WEAK signal (<25) — create/cancel pattern, no grid', min: 0, max: 25 },
|
|
@@ -531,13 +583,13 @@ async function run() {
|
|
|
531
583
|
|
|
532
584
|
// ── Summary ───────────────────────────────────────────────────────────────
|
|
533
585
|
|
|
534
|
-
const high =
|
|
586
|
+
const high = highV2.length + highV1.length;
|
|
535
587
|
const medium = results.filter(r => r.dexScore >= 50 && r.dexScore < 80).length;
|
|
536
588
|
const low = results.filter(r => r.dexScore >= 25 && r.dexScore < 50).length;
|
|
537
589
|
|
|
538
590
|
console.log('════════════════════════════════════════════════════════════════════════════════════');
|
|
539
591
|
console.log(` Total candidates scanned: ${results.length}`);
|
|
540
|
-
console.log(` HIGH (80+): ${high} accounts —
|
|
592
|
+
console.log(` HIGH (80+): ${high} accounts — DEXBot2: ${highV2.length} (op 77 updates) / DEXBot1-style: ${highV1.length} (cancel-only)`);
|
|
541
593
|
console.log(` MEDIUM (50+): ${medium} accounts — likely grid bots`);
|
|
542
594
|
console.log(` LOW (25+): ${low} accounts — weak signal`);
|
|
543
595
|
console.log('');
|
|
@@ -545,6 +597,7 @@ async function run() {
|
|
|
545
597
|
console.log(' C/C = cancel/create ratio (grid bots: ~1.0)');
|
|
546
598
|
console.log(' Incr% = implied grid increment from price spacing');
|
|
547
599
|
console.log(' Grid = grid quality 0-100 | DEX = DEXBot confidence 0-100');
|
|
600
|
+
console.log(' Updates = limit_order_update (op 77) count — DEXBot2 only; 0 = cancel-only (DEXBot1-style)');
|
|
548
601
|
console.log('');
|
|
549
602
|
|
|
550
603
|
// ── Export JSON ────────────────────────────────────────────────────────────
|
|
@@ -553,9 +606,11 @@ async function run() {
|
|
|
553
606
|
const exportData = results.map(r => ({
|
|
554
607
|
id: r.id,
|
|
555
608
|
name: r.name,
|
|
609
|
+
flavor: r.flavor,
|
|
556
610
|
creates: r.creates,
|
|
557
611
|
fills: r.fills,
|
|
558
612
|
cancels: r.cancels,
|
|
613
|
+
updates: r.updates,
|
|
559
614
|
fillPct: r.fillRate,
|
|
560
615
|
cancelRatio: r.cancelRatio,
|
|
561
616
|
maxBatch: r.maxBatch,
|
|
@@ -32,6 +32,10 @@
|
|
|
32
32
|
* limit_order_cancel:
|
|
33
33
|
* op_object.fee_paying_account — account that cancelled
|
|
34
34
|
* op_object.order — the order ID cancelled
|
|
35
|
+
*
|
|
36
|
+
* limit_order_update (op 77, DEXBot2-only — native in-place re-price):
|
|
37
|
+
* op_object.seller — account that updated the order
|
|
38
|
+
* op_object.order — the limit order ID updated
|
|
35
39
|
*/
|
|
36
40
|
|
|
37
41
|
|
|
@@ -42,6 +46,11 @@ import { kibanaSearch, DEFAULT_CONFIG as BASE_CONFIG } from '../../market_adapte
|
|
|
42
46
|
const OP_LIMIT_ORDER_CREATE = 1;
|
|
43
47
|
const OP_LIMIT_ORDER_CANCEL = 2;
|
|
44
48
|
const OP_FILL_ORDER = 4;
|
|
49
|
+
// Native in-place order re-price. Only DEXBot2 broadcasts this (COW UPDATE
|
|
50
|
+
// actions via buildUpdateOrderOp); DEXBot1 (Python staggered_orders) predates
|
|
51
|
+
// it and can only cancel + recreate. Presence of op 77 on an account is the
|
|
52
|
+
// DEXBot2 fingerprint; absence means cancel-only (DEXBot1-style).
|
|
53
|
+
const OP_LIMIT_ORDER_UPDATE = 77;
|
|
45
54
|
|
|
46
55
|
const DEFAULT_CONFIG = {
|
|
47
56
|
...BASE_CONFIG,
|
|
@@ -166,7 +175,37 @@ function buildTopFilledAccountsQuery(lookbackHours: number, topN: number = 100,
|
|
|
166
175
|
};
|
|
167
176
|
}
|
|
168
177
|
|
|
178
|
+
/**
|
|
179
|
+
* Top N accounts by limit_order_update count (seller field, op 77).
|
|
180
|
+
* DEXBot2 fingerprint: only DEXBot2 broadcasts native in-place re-prices
|
|
181
|
+
* (COW UPDATE actions). DEXBot1-style bots never emit op 77 — they cancel
|
|
182
|
+
* (op 2) and recreate (op 1) instead.
|
|
183
|
+
*/
|
|
184
|
+
function buildTopUpdaterAccountsQuery(lookbackHours: number, topN: number = 200, minUpdates: number = 1) {
|
|
185
|
+
return {
|
|
186
|
+
size: 0,
|
|
187
|
+
query: {
|
|
188
|
+
bool: {
|
|
189
|
+
filter: [
|
|
190
|
+
{ term: { operation_type: OP_LIMIT_ORDER_UPDATE } },
|
|
191
|
+
{ range: { 'block_data.block_time': { gte: `now-${lookbackHours}h`, lte: 'now' } } },
|
|
192
|
+
],
|
|
193
|
+
},
|
|
194
|
+
},
|
|
195
|
+
aggs: {
|
|
196
|
+
by_account: {
|
|
197
|
+
terms: {
|
|
198
|
+
field: 'operation_history.op_object.seller.keyword',
|
|
199
|
+
size: topN,
|
|
200
|
+
min_doc_count: minUpdates,
|
|
201
|
+
order: { _count: 'desc' },
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
},
|
|
205
|
+
};
|
|
206
|
+
}
|
|
207
|
+
|
|
169
208
|
// ─── Exports ──────────────────────────────────────────────────────────────────
|
|
170
209
|
|
|
171
|
-
export { DEFAULT_CONFIG, kibanaSearch, buildOrderPriceQuery, buildTopSellerAccountsQuery, buildTopCancellerAccountsQuery, buildTopFilledAccountsQuery }
|
|
210
|
+
export { DEFAULT_CONFIG, kibanaSearch, buildOrderPriceQuery, buildTopSellerAccountsQuery, buildTopCancellerAccountsQuery, buildTopFilledAccountsQuery, buildTopUpdaterAccountsQuery, OP_LIMIT_ORDER_UPDATE }
|
|
172
211
|
|
package/analysis/chart_utils.ts
CHANGED
|
@@ -54,8 +54,11 @@ function toEpochSeconds(ts: any, fallbackIdx: any) {
|
|
|
54
54
|
return fallbackIdx * 3600;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
function
|
|
58
|
-
|
|
57
|
+
function toFileUrl(filePath: any): string {
|
|
58
|
+
return `file://${path.resolve(String(filePath))}`;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function writeChartFile(filePath: any, html: any) { const chartDir = path.dirname(filePath);
|
|
59
62
|
if (!fs.existsSync(chartDir)) ensureDir(chartDir);
|
|
60
63
|
ensureSiblingUplotAssets(chartDir);
|
|
61
64
|
// Atomic write (tmp + rename, matching the production storage adapter
|
|
@@ -190,5 +193,5 @@ function bindPan(chart) {
|
|
|
190
193
|
}
|
|
191
194
|
`;
|
|
192
195
|
|
|
193
|
-
export { escapeHtml, serializeJsonForScript, toEpochSeconds, writeChartFile, embedFunctionSources, UPLOT_SHARED_SCRIPT }
|
|
196
|
+
export { escapeHtml, serializeJsonForScript, toEpochSeconds, writeChartFile, toFileUrl, embedFunctionSources, UPLOT_SHARED_SCRIPT }
|
|
194
197
|
|
|
@@ -37,7 +37,7 @@ import fs from 'node:fs';
|
|
|
37
37
|
import { pathToFileURL } from 'node:url';
|
|
38
38
|
import * as KC from '../market_adapter/core/kibana_client.js';
|
|
39
39
|
import * as C from '../modules/constants.js';
|
|
40
|
-
import { loadBotMeta, loadBotSettings, computeBotKey } from './bot_key_utils.js';
|
|
40
|
+
import { loadBotMeta, loadBotSettings, computeBotKey, persistBotAccountId } from './bot_key_utils.js';
|
|
41
41
|
|
|
42
42
|
const { kibanaSearch, DEFAULT_CONFIG: BASE_CONFIG } = KC;
|
|
43
43
|
|
|
@@ -221,8 +221,11 @@ Time range (one of):
|
|
|
221
221
|
|
|
222
222
|
Options:
|
|
223
223
|
--account <id> Override account ID (default: from bot preferredAccount)
|
|
224
|
-
--lookup
|
|
225
|
-
--
|
|
224
|
+
--lookup Legacy: account names always resolve via BitShares node
|
|
225
|
+
--refresh-account Force re-resolution of preferredAccount and update the
|
|
226
|
+
stored accountId when it changed (default: reuse the
|
|
227
|
+
stored accountId with no chain lookup)
|
|
228
|
+
--node <url> BitShares node URL for account / precision resolution
|
|
226
229
|
--increment <pct> Grid increment percent (default: from bot config or ${Number((C as any)?.DEFAULT_CONFIG?.incrementPercent ?? 0.5)})
|
|
227
230
|
--tolerance <pct> Deprecated alias for --increment (kept for compat, prefer --increment)
|
|
228
231
|
--per-fill Check at fill granularity (default: per-order aggregated)
|
|
@@ -262,6 +265,7 @@ function parseArgs() {
|
|
|
262
265
|
end: null,
|
|
263
266
|
account: null,
|
|
264
267
|
lookup: false,
|
|
268
|
+
refreshAccount: false,
|
|
265
269
|
node: C.NODE_MANAGEMENT.DEFAULT_NODES[0],
|
|
266
270
|
perFill: false,
|
|
267
271
|
includeCrossPair: false,
|
|
@@ -279,6 +283,7 @@ function parseArgs() {
|
|
|
279
283
|
case '--end': opts.end = args[++i]; break;
|
|
280
284
|
case '--account': opts.account = args[++i]; break;
|
|
281
285
|
case '--lookup': opts.lookup = true; break;
|
|
286
|
+
case '--refresh-account': opts.refreshAccount = true; break;
|
|
282
287
|
case '--node': opts.node = args[++i]; break;
|
|
283
288
|
case '--per-fill': opts.perFill = true; break;
|
|
284
289
|
case '--include-cross-pair': opts.includeCrossPair = true; break;
|
|
@@ -356,32 +361,63 @@ async function resolveAccountId(name: string, nodeUrl: string): Promise<string |
|
|
|
356
361
|
}
|
|
357
362
|
}
|
|
358
363
|
|
|
359
|
-
async function resolveAccountForBot(botKey: string, overrideAccount: string | null, nodeUrl: string,
|
|
364
|
+
async function resolveAccountForBot(botKey: string, overrideAccount: string | null, nodeUrl: string, doRefresh: boolean): Promise<{ accountId: string; botMeta: any }> {
|
|
360
365
|
const botMeta = loadBotMeta(botKey);
|
|
361
366
|
if (!botMeta && !overrideAccount) {
|
|
362
367
|
console.error(`Error: bot key '${botKey}' not found in profiles/bots.json and no --account provided.`);
|
|
363
368
|
console.error(`Use --list-bots to see available keys, or pass --account <1.2.x> explicitly.`);
|
|
364
369
|
process.exit(1);
|
|
365
370
|
}
|
|
366
|
-
|
|
367
|
-
if (
|
|
371
|
+
// An explicit --account always wins and is never persisted.
|
|
372
|
+
if (overrideAccount) {
|
|
373
|
+
if (/^1\.2\.\d+$/.test(String(overrideAccount))) {
|
|
374
|
+
return { accountId: String(overrideAccount), botMeta };
|
|
375
|
+
}
|
|
376
|
+
console.log(` Resolving account name '${overrideAccount}'...`);
|
|
377
|
+
const resolvedOverride = await resolveAccountId(String(overrideAccount), nodeUrl);
|
|
378
|
+
if (!resolvedOverride) {
|
|
379
|
+
console.error(`Error: failed to resolve --account '${overrideAccount}' to 1.2.x`);
|
|
380
|
+
process.exit(1);
|
|
381
|
+
}
|
|
382
|
+
console.log(` → ${resolvedOverride}`);
|
|
383
|
+
return { accountId: String(resolvedOverride), botMeta };
|
|
384
|
+
}
|
|
385
|
+
const prefRaw = botMeta?.preferredAccount != null ? String(botMeta.preferredAccount) : null;
|
|
386
|
+
const prefIsId = !!prefRaw && /^1\.2\.\d+$/.test(prefRaw);
|
|
387
|
+
const storedId = /^1\.2\.\d+$/.test(String(botMeta?.accountId ?? '')) ? String(botMeta.accountId) : null;
|
|
388
|
+
// An explicit 1.2.x preferredAccount is authoritative: the stored accountId
|
|
389
|
+
// is a derived cache and must never override it. Self-heal the cache.
|
|
390
|
+
if (prefIsId) {
|
|
391
|
+
if (storedId && storedId !== prefRaw && persistBotAccountId(botKey, prefRaw as string)) {
|
|
392
|
+
console.log(` Updated stale stored accountId ${storedId} → ${prefRaw} from preferredAccount`);
|
|
393
|
+
}
|
|
394
|
+
return { accountId: prefRaw as string, botMeta };
|
|
395
|
+
}
|
|
396
|
+
if (!prefRaw) {
|
|
368
397
|
console.error(`Error: bot '${botKey}' has no preferredAccount and no --account provided.`);
|
|
369
398
|
process.exit(1);
|
|
370
399
|
}
|
|
371
|
-
//
|
|
372
|
-
if (
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
400
|
+
// Name + fresh-enough cache + no refresh requested: offline-friendly fast path.
|
|
401
|
+
if (storedId && !doRefresh) {
|
|
402
|
+
console.log(` Using stored accountId ${storedId} from profiles/bots.json (no lookup needed; pass --refresh-account to re-verify)`);
|
|
403
|
+
return { accountId: storedId, botMeta };
|
|
404
|
+
}
|
|
405
|
+
// No cache, or --refresh-account: resolve the name on-chain.
|
|
406
|
+
console.log(` Resolving account name '${prefRaw}'...`);
|
|
407
|
+
const resolved = await resolveAccountId(prefRaw, nodeUrl);
|
|
408
|
+
if (!resolved) {
|
|
409
|
+
console.error(`Error: failed to resolve account name '${prefRaw}' to 1.2.x`);
|
|
410
|
+
process.exit(1);
|
|
411
|
+
}
|
|
412
|
+
console.log(` → ${resolved}`);
|
|
413
|
+
if (!storedId && persistBotAccountId(botKey, resolved)) {
|
|
414
|
+
console.log(` Stored accountId ${resolved} in profiles/bots.json for '${botKey}'`);
|
|
415
|
+
} else if (storedId && storedId !== resolved && persistBotAccountId(botKey, resolved)) {
|
|
416
|
+
console.log(` Updated stored accountId ${storedId} → ${resolved} in profiles/bots.json for '${botKey}'`);
|
|
417
|
+
} else if (storedId === resolved) {
|
|
418
|
+
console.log(` Stored accountId ${resolved} confirmed up to date`);
|
|
383
419
|
}
|
|
384
|
-
return { accountId: String(
|
|
420
|
+
return { accountId: String(resolved), botMeta };
|
|
385
421
|
}
|
|
386
422
|
|
|
387
423
|
// ─── Asset precision resolution ───────────────────────────────────────────────
|
|
@@ -829,7 +865,7 @@ async function main() {
|
|
|
829
865
|
console.log(`\nGrid correction check — bot-key: ${opts.botKey}`);
|
|
830
866
|
console.log(`Range: ${label}`);
|
|
831
867
|
|
|
832
|
-
const { accountId, botMeta } = await resolveAccountForBot(opts.botKey, opts.account, opts.node, opts.
|
|
868
|
+
const { accountId, botMeta } = await resolveAccountForBot(opts.botKey, opts.account, opts.node, opts.refreshAccount);
|
|
833
869
|
console.log(`Account: ${accountId}${botMeta ? ` (${botMeta.assetA}/${botMeta.assetB})` : ''}`);
|
|
834
870
|
const incrementPercent = resolveIncrementPercent(botMeta, opts.incrementPercent);
|
|
835
871
|
console.log(`Increment: ${incrementPercent}% (halfInc ${incrementPercent/2}%)${opts.incrementPercent == null && botMeta?.incrementPercent != null ? ' — from bot config' : opts.incrementPercent != null ? ' — from --increment' : ' — default'}`);
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* BOT ACCOUNT-ID BACKFILL
|
|
6
|
+
*
|
|
7
|
+
* Resolves every bot's preferredAccount name to its chain account ID and
|
|
8
|
+
* stamps `accountId` next to `preferredAccount` in profiles/bots.json, so
|
|
9
|
+
* analysis tools and scripts can skip the chain lookup on later runs.
|
|
10
|
+
* Nothing is ever written by hand — all IDs in the file come from this
|
|
11
|
+
* script, the bot editor, or the analysis tools themselves.
|
|
12
|
+
*
|
|
13
|
+
* Usage:
|
|
14
|
+
* node dist/analysis/resolve_bot_accounts.js [--bot-key <key>] [--refresh]
|
|
15
|
+
* [--timeout-ms <n>] [--dry-run] [--json]
|
|
16
|
+
*
|
|
17
|
+
* Exit code 0 = all bot accounts resolved (or nothing to do),
|
|
18
|
+
* 1 = one or more resolutions failed.
|
|
19
|
+
*
|
|
20
|
+
* Short-lived batch tool: suppresses chain INFO logging and disconnects the
|
|
21
|
+
* shared client on exit. Run standalone only — never import/call from a
|
|
22
|
+
* long-running process holding a live connection.
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
import { loadBotSettings, computeBotKey, persistBotAccountId } from './bot_key_utils.js';
|
|
26
|
+
import { setGlobalConsoleLevel, getGlobalConsoleLevel } from '../modules/order/logger.js';
|
|
27
|
+
import { sleep } from '../modules/order/utils/system.js';
|
|
28
|
+
import { getErrorMessage } from '../modules/utils/errors.js';
|
|
29
|
+
|
|
30
|
+
const DEFAULT_TIMEOUT_MS = 20000;
|
|
31
|
+
|
|
32
|
+
function printHelp() {
|
|
33
|
+
console.log(`\
|
|
34
|
+
Usage: node dist/analysis/resolve_bot_accounts.js [options]
|
|
35
|
+
|
|
36
|
+
Resolve bot preferredAccount names to chain IDs and store them as accountId
|
|
37
|
+
in profiles/bots.json (byte-preserving; comments and formatting survive).
|
|
38
|
+
|
|
39
|
+
Options:
|
|
40
|
+
--bot-key <key> Only process this bot key or bot name (default: all bots)
|
|
41
|
+
--refresh Re-resolve even when a stored accountId exists
|
|
42
|
+
--timeout-ms <n> Per-account chain lookup timeout (default: ${DEFAULT_TIMEOUT_MS})
|
|
43
|
+
--dry-run Report what would change without writing anything
|
|
44
|
+
--json Append a machine-readable summary
|
|
45
|
+
--help, -h Show this help
|
|
46
|
+
`);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function parseArgs() {
|
|
50
|
+
const args = process.argv.slice(2);
|
|
51
|
+
if (args.includes('--help') || args.includes('-h')) { printHelp(); process.exit(0); }
|
|
52
|
+
const opts: any = {
|
|
53
|
+
botKey: null,
|
|
54
|
+
refresh: false,
|
|
55
|
+
timeoutMs: DEFAULT_TIMEOUT_MS,
|
|
56
|
+
dryRun: false,
|
|
57
|
+
json: false,
|
|
58
|
+
};
|
|
59
|
+
for (let i = 0; i < args.length; i++) {
|
|
60
|
+
switch (args[i]) {
|
|
61
|
+
case '--bot-key': opts.botKey = args[++i]; break;
|
|
62
|
+
case '--refresh': opts.refresh = true; break;
|
|
63
|
+
case '--timeout-ms': opts.timeoutMs = parseInt(args[++i], 10); break;
|
|
64
|
+
case '--dry-run': opts.dryRun = true; break;
|
|
65
|
+
case '--json': opts.json = true; break;
|
|
66
|
+
default:
|
|
67
|
+
console.error(`Unknown option: ${args[i]}`);
|
|
68
|
+
process.exit(1);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (!Number.isFinite(opts.timeoutMs) || opts.timeoutMs <= 0) {
|
|
72
|
+
console.error('Error: --timeout-ms must be a positive number.');
|
|
73
|
+
process.exit(1);
|
|
74
|
+
}
|
|
75
|
+
return opts;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function resolveWithTimeout(chainOrders: any, ref: string, timeoutMs: number): Promise<{ id: string | null; reason: string }> {
|
|
79
|
+
const timeoutErr: any = new Error(`lookup timed out after ${timeoutMs}ms`);
|
|
80
|
+
timeoutErr.code = 'ACCOUNT_LOOKUP_TIMEOUT';
|
|
81
|
+
try {
|
|
82
|
+
const id = await Promise.race([
|
|
83
|
+
chainOrders.resolveAccountId(ref),
|
|
84
|
+
sleep(timeoutMs).then(() => { throw timeoutErr; }),
|
|
85
|
+
]);
|
|
86
|
+
if (id && /^1\.2\.\d+$/.test(String(id))) return { id: String(id), reason: 'resolved' };
|
|
87
|
+
return { id: null, reason: 'not-found' };
|
|
88
|
+
} catch (err: any) {
|
|
89
|
+
return { id: null, reason: err && err.code === 'ACCOUNT_LOOKUP_TIMEOUT' ? 'timeout' : 'error' };
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
async function main() {
|
|
94
|
+
const opts = parseArgs();
|
|
95
|
+
const settings = loadBotSettings();
|
|
96
|
+
const entries = Array.isArray(settings?.bots) ? settings.bots : [];
|
|
97
|
+
if (!entries.length) {
|
|
98
|
+
console.log('No bots in profiles/bots.json — nothing to do.');
|
|
99
|
+
process.exit(0);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
let targets = entries.map((bot: any, index: number) => ({ bot, index, key: computeBotKey(bot, index) }));
|
|
103
|
+
if (opts.botKey) {
|
|
104
|
+
const want = String(opts.botKey).toLowerCase();
|
|
105
|
+
targets = targets.filter((t: any) => t.key === want || String(t.bot?.name ?? '').toLowerCase() === want);
|
|
106
|
+
if (!targets.length) {
|
|
107
|
+
console.error(`Error: bot '${opts.botKey}' not found in profiles/bots.json.`);
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Suppress chain INFO spam for the whole batch; restored in finally.
|
|
113
|
+
// (setSuppressConnectionLog is read lazily so this file never drags the
|
|
114
|
+
// chain stack in when it cannot be loaded.)
|
|
115
|
+
let chainClient: any = null;
|
|
116
|
+
let prevSuppress = false;
|
|
117
|
+
let prevGlobalLevel: string | null = null;
|
|
118
|
+
let suppressionArmed = false;
|
|
119
|
+
let chainOrders: any = null;
|
|
120
|
+
try {
|
|
121
|
+
chainClient = await import('../modules/bitshares_client.js');
|
|
122
|
+
prevSuppress = chainClient.isSuppressConnectionLog();
|
|
123
|
+
prevGlobalLevel = getGlobalConsoleLevel();
|
|
124
|
+
suppressionArmed = true;
|
|
125
|
+
chainClient.setSuppressConnectionLog(true);
|
|
126
|
+
setGlobalConsoleLevel('warn');
|
|
127
|
+
chainOrders = await import('../modules/chain_orders.js');
|
|
128
|
+
} catch (err: any) {
|
|
129
|
+
console.error(`Error: could not load the chain stack (${getErrorMessage(err)}).`);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const results: any[] = [];
|
|
134
|
+
try {
|
|
135
|
+
for (const t of targets) {
|
|
136
|
+
const name = t.bot?.name ?? t.key;
|
|
137
|
+
const prefRaw = t.bot?.preferredAccount != null ? String(t.bot.preferredAccount) : '';
|
|
138
|
+
const stored = /^1\.2\.\d+$/.test(String(t.bot?.accountId ?? '')) ? String(t.bot.accountId) : null;
|
|
139
|
+
if (!prefRaw) {
|
|
140
|
+
results.push({ key: t.key, name, status: 'skipped', detail: 'no preferredAccount' });
|
|
141
|
+
console.log(`- ${t.key}: skipped (no preferredAccount)`);
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
if (/^1\.2\.\d+$/.test(prefRaw)) {
|
|
145
|
+
if (stored !== prefRaw) {
|
|
146
|
+
const wrote = opts.dryRun ? true : persistBotAccountId(t.key, prefRaw);
|
|
147
|
+
const status = !wrote ? 'failed' : (opts.dryRun ? 'would-update' : 'updated');
|
|
148
|
+
results.push({ key: t.key, name, status, detail: wrote ? `preferredAccount is authoritative (${prefRaw})` : 'could not write profiles/bots.json' });
|
|
149
|
+
console.log(`- ${t.key}: ${!wrote ? 'FAILED to write' : (opts.dryRun ? 'would update' : 'updated')} stored accountId → ${prefRaw} (preferredAccount is authoritative)`);
|
|
150
|
+
} else {
|
|
151
|
+
results.push({ key: t.key, name, status: 'cached', detail: prefRaw });
|
|
152
|
+
console.log(`- ${t.key}: cached (${prefRaw})`);
|
|
153
|
+
}
|
|
154
|
+
continue;
|
|
155
|
+
}
|
|
156
|
+
if (stored && !opts.refresh) {
|
|
157
|
+
results.push({ key: t.key, name, status: 'cached', detail: stored });
|
|
158
|
+
console.log(`- ${t.key}: cached (${stored})`);
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
const r = await resolveWithTimeout(chainOrders, prefRaw, opts.timeoutMs);
|
|
162
|
+
if (r.id) {
|
|
163
|
+
const changed = stored !== r.id;
|
|
164
|
+
const wrote = !changed || opts.dryRun ? true : persistBotAccountId(t.key, r.id);
|
|
165
|
+
const status = !wrote ? 'failed' : (opts.dryRun ? (changed ? 'would-update' : 'unchanged') : (changed ? (stored ? 'updated' : 'stored') : 'unchanged'));
|
|
166
|
+
results.push({ key: t.key, name, status, detail: wrote ? r.id : 'could not write profiles/bots.json' });
|
|
167
|
+
console.log(`- ${t.key}: '${prefRaw}' → ${r.id}${!wrote ? ' (FAILED to store)' : (changed ? (opts.dryRun ? ' (would store)' : (stored ? ' (updated)' : ' (stored)')) : ' (unchanged)')}`);
|
|
168
|
+
} else {
|
|
169
|
+
const why = r.reason === 'timeout' ? `nodes unreachable (timed out after ${opts.timeoutMs}ms)` : 'not found on the blockchain';
|
|
170
|
+
results.push({ key: t.key, name, status: 'failed', detail: why });
|
|
171
|
+
console.log(`- ${t.key}: FAILED to resolve '${prefRaw}' (${why})`);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
} finally {
|
|
175
|
+
if (chainClient) {
|
|
176
|
+
try { await chainClient.disconnectClient(); } catch (_) { /* best-effort cleanup */ }
|
|
177
|
+
if (suppressionArmed) {
|
|
178
|
+
try { chainClient.setSuppressConnectionLog(prevSuppress); } catch (_) { /* restore-only */ }
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (suppressionArmed) {
|
|
182
|
+
try { setGlobalConsoleLevel(prevGlobalLevel); } catch (_) { /* restore-only */ }
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const failed = results.filter((r: any) => r.status === 'failed');
|
|
187
|
+
const skipped = results.filter((r: any) => r.status === 'skipped').length;
|
|
188
|
+
const ok = results.length - failed.length - skipped;
|
|
189
|
+
console.log(`\nDone: ${ok} resolved, ${skipped} skipped, ${failed.length} failed${opts.dryRun ? ' (dry run, nothing written)' : ''}.`);
|
|
190
|
+
if (opts.json) {
|
|
191
|
+
console.log(JSON.stringify({ dryRun: opts.dryRun, results }, null, 2));
|
|
192
|
+
}
|
|
193
|
+
process.exit(failed.length ? 1 : 0);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
main().catch((err: any) => {
|
|
197
|
+
console.error('Fatal:', getErrorMessage(err));
|
|
198
|
+
process.exit(1);
|
|
199
|
+
});
|