dexbot 1.6.14 → 1.6.15
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 +34 -4
- package/analysis/README.md +6 -6
- package/analysis/tradingview/README.md +2 -1
- package/claw/README.md +7 -7
- 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/tradingview/tradingview_uplot_chart_generator.js +80 -6
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +36 -2
- package/dist/dexbot.js +23 -3
- package/dist/market_adapter/core/strategies/dynamic_weight_series.js +26 -11
- package/dist/modules/account_bots.d.ts +3 -0
- package/dist/modules/account_bots.js +3 -0
- package/dist/modules/bitshares-native/subscriptions.js +1 -1
- package/dist/modules/bot_defaults.d.ts +13 -2
- package/dist/modules/bot_defaults.js +31 -2
- package/dist/modules/bot_settings.js +3 -0
- package/dist/modules/constants.d.ts +6 -0
- package/dist/modules/constants.js +24 -0
- package/dist/modules/credit_runtime.d.ts +35 -5
- package/dist/modules/credit_runtime.js +219 -38
- package/dist/modules/dexbot_class.d.ts +19 -1
- package/dist/modules/dexbot_class.js +58 -20
- package/dist/modules/dexbot_cow_runtime.js +19 -18
- package/dist/modules/dexbot_fill_runtime.d.ts +1 -1
- package/dist/modules/dexbot_fill_runtime.js +4 -7
- package/dist/modules/dexbot_maintenance_runtime.d.ts +7 -2
- package/dist/modules/dexbot_maintenance_runtime.js +52 -7
- package/dist/modules/dexbot_startup_runtime.js +3 -2
- package/dist/modules/dexbot_state_recovery.js +1 -1
- package/dist/modules/order/export.js +2 -2
- package/dist/modules/order/grid.d.ts +118 -1
- package/dist/modules/order/grid.js +292 -50
- package/dist/modules/order/grid_reconcile.js +4 -3
- package/dist/modules/order/grid_reconcile_internal.js +13 -18
- package/dist/modules/order/index.d.ts +3 -1
- package/dist/modules/order/manager.d.ts +1 -0
- package/dist/modules/order/manager.js +5 -14
- package/dist/modules/order/sync_engine.js +18 -9
- package/dist/modules/order/utils/math.d.ts +98 -26
- package/dist/modules/order/utils/math.js +177 -57
- package/dist/modules/order/utils/order.js +16 -4
- package/dist/modules/order/utils/system.js +2 -2
- package/dist/modules/order/utils/validate.d.ts +1 -1
- package/dist/modules/order/utils/validate.js +48 -58
- package/dist/modules/types.d.ts +7 -0
- package/dist/scripts/analyze-credit.js +44 -27
- package/dist/scripts/diagnose-pool-history.js +35 -30
- package/dist/scripts/pnl.js +1 -1
- package/dist/scripts/rich_list.d.ts +18 -0
- package/dist/scripts/rich_list.js +461 -0
- package/dist/scripts/run-tests.js +80 -4
- package/dist/unlock.d.ts +2 -1
- package/dist/unlock.js +4 -3
- package/docs/COW_INVARIANTS.md +6 -0
- package/docs/DEXBOT_COMPARISON.md +6 -6
- package/docs/EVOLUTION.md +10 -9
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +1 -1
- package/docs/LOGGING.md +16 -1
- package/docs/MPA_CREDIT_USAGE.md +10 -5
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +159 -9
- package/docs/README.md +1 -1
- package/docs/WORKFLOW.md +1 -0
- package/docs/architecture.md +56 -2
- package/docs/developer_guide.md +5 -1
- package/market_adapter/README.md +4 -4
- package/modules/README.md +1 -1
- package/package.json +2 -1
- package/scripts/README.md +59 -32
- package/tests/README.md +11 -2
|
@@ -220,7 +220,7 @@ declare function hasExecutableActions(rebalanceResult: unknown): boolean;
|
|
|
220
220
|
* with {chainOrderId, price, size, type} to check beyond the grid
|
|
221
221
|
* @returns {{isValid: boolean, violations: Array<Object>, violatingTargetIds: Set<string>}} Validation result
|
|
222
222
|
*/
|
|
223
|
-
declare function validateCreateTargetSlots(actions: CowAction[], orders: Map<string, ManagedOrder>, _assets?: AssetPair | null, chainOrderCandidates?: UnmatchedChainOrder[]): {
|
|
223
|
+
declare function validateCreateTargetSlots(actions: CowAction[], orders: Map<string, ManagedOrder>, _assets?: AssetPair | null, chainOrderCandidates?: UnmatchedChainOrder[], incrementPercent?: number | null): {
|
|
224
224
|
isValid: boolean;
|
|
225
225
|
violations: CreateTargetViolation[];
|
|
226
226
|
violatingTargetIds: Set<string>;
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
// ===============================================================================
|
|
36
36
|
import * as Format from '../format.js';
|
|
37
37
|
import { ORDER_STATES, ORDER_TYPES, COW_ACTIONS, COW_ORIGINS, GRID_LIMITS } from '../../constants.js';
|
|
38
|
-
import { floatToBlockchainInt, blockchainToFloat, getPrecisionSlack, getPrecisionByOrderType, getDoubleDustThreshold, getSellStartIdx, isSlotIndexInGapBand, isEvacuationRotationAllowed, clamp,
|
|
38
|
+
import { floatToBlockchainInt, blockchainToFloat, getPrecisionSlack, getPrecisionByOrderType, getDoubleDustThreshold, getSellStartIdx, isSlotIndexInGapBand, isEvacuationRotationAllowed, clamp, pricesOnSameLevel, sameGridPrice } from './math.js';
|
|
39
39
|
import { parseSlotIndex } from './slot.js';
|
|
40
40
|
import { isOrderOnChain, isPhantomOrder, convertToSpreadPlaceholder, detectGapEvacuationCandidates, updateGapEvacuationStreaks, isNonBlockingUnmatchedOrder } from './order.js';
|
|
41
41
|
const { isValidNumber, toFiniteNumber } = Format;
|
|
@@ -608,13 +608,15 @@ function optimizeRebalanceActions(actions, masterGrid, options = {}) {
|
|
|
608
608
|
// Explicit null/undefined guard BEFORE Number(): Number(null) === 0 is
|
|
609
609
|
// finite and would turn an absent boundary into a valid slot-0 geometry,
|
|
610
610
|
// stamping a bogus gap-evacuation bypass (undefined already fails open via
|
|
611
|
-
// NaN, so only null was hazardous).
|
|
611
|
+
// NaN, so only null was hazardous). '' is equally hazardous (Number('')
|
|
612
|
+
// === 0) and is guarded here the same way as in
|
|
613
|
+
// stampGapEvacuationRotation.
|
|
612
614
|
const rawOptBoundary = options?.boundaryIdx;
|
|
613
615
|
const rawOptGapSlots = options?.gapSlots;
|
|
614
|
-
const optBoundary = (rawOptBoundary === null || rawOptBoundary === undefined)
|
|
616
|
+
const optBoundary = (rawOptBoundary === null || rawOptBoundary === undefined || rawOptBoundary === '')
|
|
615
617
|
? NaN
|
|
616
618
|
: Number(rawOptBoundary);
|
|
617
|
-
const optGapSlots = (rawOptGapSlots === null || rawOptGapSlots === undefined)
|
|
619
|
+
const optGapSlots = (rawOptGapSlots === null || rawOptGapSlots === undefined || rawOptGapSlots === '')
|
|
618
620
|
? NaN
|
|
619
621
|
: Number(rawOptGapSlots);
|
|
620
622
|
const hasOptGeometry = Number.isFinite(optBoundary) && Number.isFinite(optGapSlots) && optGapSlots >= 0;
|
|
@@ -734,7 +736,7 @@ function hasExecutableActions(rebalanceResult) {
|
|
|
734
736
|
* with {chainOrderId, price, size, type} to check beyond the grid
|
|
735
737
|
* @returns {{isValid: boolean, violations: Array<Object>, violatingTargetIds: Set<string>}} Validation result
|
|
736
738
|
*/
|
|
737
|
-
function validateCreateTargetSlots(actions, orders, _assets = null, chainOrderCandidates = []) {
|
|
739
|
+
function validateCreateTargetSlots(actions, orders, _assets = null, chainOrderCandidates = [], incrementPercent = null) {
|
|
738
740
|
const safeActions = Array.isArray(actions) ? actions : [];
|
|
739
741
|
const orderMap = orders instanceof Map ? orders : new Map();
|
|
740
742
|
const releasedSlotIds = new Set();
|
|
@@ -807,9 +809,9 @@ function validateCreateTargetSlots(actions, orders, _assets = null, chainOrderCa
|
|
|
807
809
|
// set entirely, letting a CREATE collide with a slot-unknown
|
|
808
810
|
// chain order sitting at the same price level (duplicate order).
|
|
809
811
|
if (_assets) {
|
|
810
|
-
//
|
|
811
|
-
//
|
|
812
|
-
//
|
|
812
|
+
// Tolerance-based level check (pricesOnSameLevel); NOT
|
|
813
|
+
// priceSlotEqual at the asset precision, which collapses
|
|
814
|
+
// adjacent grid levels for a low-precision asset.
|
|
813
815
|
const slotlessCandidates = validChainCandidates.filter((u) => !(u.chainSlotId || u.candidateSlotId));
|
|
814
816
|
for (const entry of createEntries) {
|
|
815
817
|
if (violations.some(v => v.targetId === entry.targetId))
|
|
@@ -819,14 +821,10 @@ function validateCreateTargetSlots(actions, orders, _assets = null, chainOrderCa
|
|
|
819
821
|
continue;
|
|
820
822
|
if (u.type && entry.type && u.type !== entry.type)
|
|
821
823
|
continue;
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
violations.push({ targetId: entry.targetId, currentOrderId: u.chainOrderId, currentType: entry.type, currentState: 'CHAIN_ORPHAN', reason: 'chain_orphan_collision' });
|
|
826
|
-
break;
|
|
827
|
-
}
|
|
824
|
+
if (pricesOnSameLevel(Number(u.price), Number(u.size) || 0, u.type, Number(entry.price), Number(entry.size) || 0, entry.type, _assets, incrementPercent)) {
|
|
825
|
+
violations.push({ targetId: entry.targetId, currentOrderId: u.chainOrderId, currentType: entry.type, currentState: 'CHAIN_ORPHAN', reason: 'chain_orphan_collision' });
|
|
826
|
+
break;
|
|
828
827
|
}
|
|
829
|
-
catch { }
|
|
830
828
|
}
|
|
831
829
|
}
|
|
832
830
|
}
|
|
@@ -840,21 +838,24 @@ function validateCreateTargetSlots(actions, orders, _assets = null, chainOrderCa
|
|
|
840
838
|
else
|
|
841
839
|
seen.add(entry.targetId);
|
|
842
840
|
}
|
|
843
|
-
// Same-batch
|
|
841
|
+
// Same-batch duplicate price across DIFFERENT target slots.
|
|
844
842
|
// The genesis-frozen slot mapping gives every slot a distinct price
|
|
845
|
-
// level, so two CREATEs at the
|
|
846
|
-
//
|
|
847
|
-
//
|
|
848
|
-
//
|
|
849
|
-
//
|
|
850
|
-
//
|
|
851
|
-
//
|
|
852
|
-
//
|
|
853
|
-
//
|
|
854
|
-
|
|
843
|
+
// level, so two CREATEs at the same price on different slots indicate a
|
|
844
|
+
// degenerate plan (production incident 2026-08-29: several slots
|
|
845
|
+
// planned at one price; every batch was filtered down to a single op
|
|
846
|
+
// and the grid rebuild crawled at one placement per cycle).
|
|
847
|
+
//
|
|
848
|
+
// Identity is the ladder level, NOT the on-chain integer at the asset
|
|
849
|
+
// precision: a price is not an amount, so a low-precision asset
|
|
850
|
+
// (e.g. precision 4) collapses an entire adjacent band (0.000318 and
|
|
851
|
+
// 0.000343 both -> 3) and would flag every CREATE but the first as a
|
|
852
|
+
// duplicate. sameGridPrice carries 1e-9 relative slack so float noise
|
|
853
|
+
// in a repeated level still matches without merging distinct levels.
|
|
854
|
+
// First target per (type, level) wins; later duplicates are skipped by
|
|
855
|
+
// the caller via violatingTargetIds.
|
|
856
|
+
const invalidPriceTargets = new Set();
|
|
855
857
|
for (const entry of createEntries) {
|
|
856
|
-
|
|
857
|
-
if (!Number.isFinite(priceNum)) {
|
|
858
|
+
if (!Number.isFinite(Number(entry.price))) {
|
|
858
859
|
// Fail closed: an unpriceable CREATE cannot be proven
|
|
859
860
|
// collision-free, so it is rejected, not skipped.
|
|
860
861
|
violations.push({
|
|
@@ -864,37 +865,26 @@ function validateCreateTargetSlots(actions, orders, _assets = null, chainOrderCa
|
|
|
864
865
|
currentState: 'CREATE',
|
|
865
866
|
reason: 'create_price_invalid',
|
|
866
867
|
});
|
|
867
|
-
|
|
868
|
-
}
|
|
869
|
-
// Key on the on-chain integer repr when the side precision is
|
|
870
|
-
// known (bit-exact: prices that quantize to the same chain int
|
|
871
|
-
// ARE the same price on the DEX); float fallback preserves the
|
|
872
|
-
// old behavior for callers without assets context.
|
|
873
|
-
let key;
|
|
874
|
-
let sidePrecision = null;
|
|
875
|
-
try {
|
|
876
|
-
sidePrecision = _assets ? getPrecisionByOrderType(_assets, entry.type) : null;
|
|
877
|
-
}
|
|
878
|
-
catch {
|
|
879
|
-
sidePrecision = null;
|
|
880
|
-
}
|
|
881
|
-
if (Number.isFinite(Number(sidePrecision)) && Number(sidePrecision) > 0) {
|
|
882
|
-
try {
|
|
883
|
-
key = `${String(entry.type)}:i${floatToBlockchainInt(priceNum, Number(sidePrecision))}`;
|
|
884
|
-
}
|
|
885
|
-
catch {
|
|
886
|
-
key = `${String(entry.type)}:${priceNum}`;
|
|
887
|
-
}
|
|
888
|
-
}
|
|
889
|
-
else {
|
|
890
|
-
key = `${String(entry.type)}:${priceNum}`;
|
|
891
|
-
}
|
|
892
|
-
const owner = priceOwner.get(key);
|
|
893
|
-
if (owner === undefined) {
|
|
894
|
-
priceOwner.set(key, entry.targetId);
|
|
868
|
+
invalidPriceTargets.add(entry.targetId);
|
|
895
869
|
}
|
|
896
|
-
|
|
897
|
-
|
|
870
|
+
}
|
|
871
|
+
const duplicateTargets = new Set();
|
|
872
|
+
for (let i = 0; i < createEntries.length; i++) {
|
|
873
|
+
const a = createEntries[i];
|
|
874
|
+
if (invalidPriceTargets.has(a.targetId))
|
|
875
|
+
continue;
|
|
876
|
+
for (let j = i + 1; j < createEntries.length; j++) {
|
|
877
|
+
const b = createEntries[j];
|
|
878
|
+
if (invalidPriceTargets.has(b.targetId))
|
|
879
|
+
continue;
|
|
880
|
+
if (a.targetId === b.targetId || a.type !== b.type)
|
|
881
|
+
continue;
|
|
882
|
+
if (!sameGridPrice(a.price, b.price))
|
|
883
|
+
continue;
|
|
884
|
+
if (duplicateTargets.has(b.targetId))
|
|
885
|
+
continue;
|
|
886
|
+
duplicateTargets.add(b.targetId);
|
|
887
|
+
violations.push({ targetId: b.targetId, currentOrderId: null, currentType: b.type, currentState: 'CREATE', reason: 'same_batch_price_duplicate', duplicateOf: a.targetId });
|
|
898
888
|
}
|
|
899
889
|
}
|
|
900
890
|
}
|
package/dist/modules/types.d.ts
CHANGED
|
@@ -222,6 +222,7 @@ export interface BotLike {
|
|
|
222
222
|
_gridLockHoldWarnAt: number;
|
|
223
223
|
_outOfSpreadSince: number;
|
|
224
224
|
_outOfSpreadStaleWarned: boolean;
|
|
225
|
+
_outOfSpreadTransientCount: number;
|
|
225
226
|
_strandedHoldSince: Map<string, number>;
|
|
226
227
|
_recoverySyncInFlight: number;
|
|
227
228
|
_batchInFlight: number;
|
|
@@ -506,6 +507,12 @@ export interface BotMetrics extends UnknownRecord {
|
|
|
506
507
|
boundaryDriftExceedsWindowCount: number;
|
|
507
508
|
/** Non-spread-correction CREATE/UPDATE destinations inside the gap band (shadow). */
|
|
508
509
|
gapBandPlacementShadowCount: number;
|
|
510
|
+
/** Every spread-correction batch that failed to land (executed !== true), any cause. */
|
|
511
|
+
spreadCorrectionRefusedCount: number;
|
|
512
|
+
/** Spread-correction refusal breakdown keyed by SPREAD_CORRECTION_REFUSAL value (commit-refused, version-mismatch, create-collision, update-target-missing, unmatched-chain-orders, shutdown, batch-not-executed). */
|
|
513
|
+
spreadCorrectionRefusalCauses: Record<string, number>;
|
|
514
|
+
/** Bounded re-plan retries attempted after a transient spread-correction refusal. */
|
|
515
|
+
spreadCorrectionRetryCount: number;
|
|
509
516
|
}
|
|
510
517
|
/** An unmatched chain order surfaced by a sync pass. */
|
|
511
518
|
export interface UnmatchedChainOrder extends UnknownRecord {
|
|
@@ -590,7 +590,6 @@ async function main() {
|
|
|
590
590
|
const ignoredRows = crRows.filter((r) => !r.supported);
|
|
591
591
|
const pricedSupported = supportedRows.filter((r) => r.cr !== null && r.value !== null && r.debtFloat !== null);
|
|
592
592
|
const unpricedSupported = supportedRows.filter((r) => r.cr === null);
|
|
593
|
-
const avgCr = averageCreditCr(pricedSupported.map((r) => ({ debt: r.debtFloat, value: r.value })));
|
|
594
593
|
async function fmtParts(m, showBiggest = false) {
|
|
595
594
|
if (m.size === 0)
|
|
596
595
|
return [];
|
|
@@ -639,39 +638,57 @@ async function main() {
|
|
|
639
638
|
await printAssetLines('Credit coll', creditSumAll.coll, true, colors.buy);
|
|
640
639
|
if (creditPairs.length > 0)
|
|
641
640
|
console.log('');
|
|
642
|
-
// Compact CR summary: one Avar. CR line per
|
|
643
|
-
// line per whitelisted pair. A CR exists only
|
|
644
|
-
// in bots.json and listed on the current
|
|
641
|
+
// Compact CR summary: one Avar. CR line per borrowed credit (debt
|
|
642
|
+
// asset), then one Curr. CR line per whitelisted pair. A CR exists only
|
|
643
|
+
// for pairs both whitelisted in bots.json and listed on the current
|
|
644
|
+
// credit offer.
|
|
645
645
|
const feeDenom = Number(FEE_PARAMETERS?.GRAPHENE_FEE_RATE_DENOM) || 1000000;
|
|
646
646
|
const walletRaw = await fetchWalletRaw(account);
|
|
647
647
|
const matchPair = (pair, r) => (pair.debtId !== null && r.debtId !== null && pair.debtId === r.debtId && pair.collId !== null && r.collId !== null && pair.collId === r.collId) ||
|
|
648
648
|
(isSameAssetSymbol(pair.debtSym, r.debtSym) && isSameAssetSymbol(pair.collSym, r.collSym));
|
|
649
|
-
if (
|
|
650
|
-
//
|
|
651
|
-
//
|
|
652
|
-
//
|
|
653
|
-
const
|
|
649
|
+
if (pricedSupported.length > 0) {
|
|
650
|
+
// Group by borrowed credit (debt asset) so unrelated debt assets are
|
|
651
|
+
// not blended into one figure; each line carries its own
|
|
652
|
+
// value-weighted average CR.
|
|
653
|
+
const debtGroups = new Map();
|
|
654
654
|
for (const r of pricedSupported) {
|
|
655
|
-
const
|
|
656
|
-
if (
|
|
657
|
-
|
|
655
|
+
const key = r.debtId ?? `sym:${normalizeAssetSymbol(r.debtSym)}`;
|
|
656
|
+
if (!debtGroups.has(key))
|
|
657
|
+
debtGroups.set(key, { debtSym: r.debtSym, rows: [] });
|
|
658
|
+
debtGroups.get(key).rows.push(r);
|
|
658
659
|
}
|
|
659
|
-
|
|
660
|
-
const
|
|
661
|
-
|
|
662
|
-
for (const
|
|
663
|
-
const
|
|
664
|
-
if (
|
|
665
|
-
|
|
660
|
+
// Largest borrowed credit first so the biggest exposure leads.
|
|
661
|
+
const debtOrder = [...debtGroups.values()].sort((a, b) => b.rows.reduce((s, r) => s + (r.debtFloat || 0), 0)
|
|
662
|
+
- a.rows.reduce((s, r) => s + (r.debtFloat || 0), 0));
|
|
663
|
+
for (const group of debtOrder) {
|
|
664
|
+
const groupCr = averageCreditCr(group.rows.map((r) => ({ debt: r.debtFloat, value: r.value })));
|
|
665
|
+
if (groupCr === null)
|
|
666
|
+
continue;
|
|
667
|
+
// Label in orange to distinguish from Curr. CR; value keeps the
|
|
668
|
+
// original health color (single shared max → green/red, mixed or
|
|
669
|
+
// undefined max → white).
|
|
670
|
+
const groupMaxSet = new Set();
|
|
671
|
+
for (const r of group.rows) {
|
|
672
|
+
const pair = creditPairs.find((p) => matchPair(p, r));
|
|
673
|
+
if (pair?.maxCR != null)
|
|
674
|
+
groupMaxSet.add(pair.maxCR);
|
|
675
|
+
}
|
|
676
|
+
const groupMax = groupMaxSet.size === 1 ? [...groupMaxSet][0] : null;
|
|
677
|
+
const groupColor = groupMax === null ? colors.white : groupCr > groupMax ? colors.sell : colors.buy;
|
|
678
|
+
const collTotals = new Map();
|
|
679
|
+
for (const r of group.rows) {
|
|
680
|
+
const key = r.collId ?? `sym:${normalizeAssetSymbol(r.collSym)}`;
|
|
681
|
+
if (!collTotals.has(key))
|
|
682
|
+
collTotals.set(key, { collSym: r.collSym, debt: 0, coll: 0 });
|
|
683
|
+
const t = collTotals.get(key);
|
|
684
|
+
t.debt += r.debtFloat || 0;
|
|
685
|
+
t.coll += r.collFloat || 0;
|
|
666
686
|
}
|
|
667
|
-
const
|
|
668
|
-
|
|
669
|
-
|
|
687
|
+
const segments = [...collTotals.values()]
|
|
688
|
+
.map((t) => `${formatAmount(t.debt)} ${group.debtSym} ← ${formatAmount(t.coll)} ${t.collSym}`)
|
|
689
|
+
.join(' + ');
|
|
690
|
+
console.log(` ${colors.orange}${colors.bold}Avar. CR:${colors.reset} ${groupColor}${formatAmount(groupCr)}${colors.reset}, ${segments} ${colors.gray}(x${group.rows.length})${colors.reset}`);
|
|
670
691
|
}
|
|
671
|
-
const segments = [...pairTotals.values()]
|
|
672
|
-
.map((t) => `${formatAmount(t.debt)} ${t.debtSym} ← ${formatAmount(t.coll)} ${t.collSym}`)
|
|
673
|
-
.join(' + ');
|
|
674
|
-
console.log(` ${colors.orange}${colors.bold}Avar. CR:${colors.reset} ${avgColor}${formatAmount(avgCr)}${colors.reset}, ${segments} ${colors.gray}(x${pricedSupported.length})${colors.reset}`);
|
|
675
692
|
}
|
|
676
693
|
else if (supportedRows.length > 0) {
|
|
677
694
|
console.log(` ${colors.orange}${colors.bold}Avar. CR:${colors.reset} n/a (no priced, available credit)`);
|
|
@@ -686,7 +703,7 @@ async function main() {
|
|
|
686
703
|
reasons.push(`${unpriced} no offer price`);
|
|
687
704
|
console.log(` ${colors.gray}Excluded: ${ignored + unpriced} deal${ignored + unpriced === 1 ? '' : 's'} (${reasons.join(', ')})${colors.reset}`);
|
|
688
705
|
}
|
|
689
|
-
if (
|
|
706
|
+
if (supportedRows.length > 0 && creditPairs.length > 0)
|
|
690
707
|
console.log('');
|
|
691
708
|
for (const pair of creditPairs) {
|
|
692
709
|
const pairRows = supportedRows.filter((r) => matchPair(pair, r));
|
|
@@ -3,9 +3,12 @@ import { createRequire } from 'node:module';
|
|
|
3
3
|
const require = createRequire(import.meta.url);
|
|
4
4
|
'use strict';
|
|
5
5
|
/**
|
|
6
|
-
* Diagnostic: Inspect raw BitShares pool history API responses for pool
|
|
6
|
+
* Diagnostic: Inspect raw BitShares pool history API responses for a liquidity pool.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
8
|
+
* The pool ID must be a concrete object ID (e.g. 1.19.133); placeholders such as
|
|
9
|
+
* "1.19.x" are rejected up front because the node cannot parse them as a uint64.
|
|
10
|
+
*
|
|
11
|
+
* Usage: node dist/scripts/diagnose-pool-history.js [--pool <1.19.N>] [--limit <n>] [--hours <n>] [--maxPages <n>]
|
|
9
12
|
*/
|
|
10
13
|
const { BitShares, waitForConnected } = require('../modules/bitshares_client');
|
|
11
14
|
const { getErrorMessage } = require('../modules/utils/errors');
|
|
@@ -23,6 +26,15 @@ const MAX_PAGES = process.argv.includes('--maxPages')
|
|
|
23
26
|
? Number(process.argv[process.argv.indexOf('--maxPages') + 1])
|
|
24
27
|
: 20;
|
|
25
28
|
const LP_OP_TYPE = 63;
|
|
29
|
+
// Fail fast on non-numeric pool IDs: the node parses the instance of a 1.19.N
|
|
30
|
+
// object ID as a uint64, so a placeholder like "1.19.x" surfaces as an opaque
|
|
31
|
+
// remote "Parse Error: Couldn't parse uint64_t".
|
|
32
|
+
if (!/^1\.19\.\d+$/.test(POOL_ID)) {
|
|
33
|
+
console.error(`Invalid pool ID: "${POOL_ID}"`);
|
|
34
|
+
console.error('Expected a numeric liquidity-pool object ID, e.g. 1.19.133 (not "1.19.x").');
|
|
35
|
+
console.error('Usage: node dist/scripts/diagnose-pool-history.js [--pool <1.19.N>] [--limit <n>] [--hours <n>] [--maxPages <n>]');
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
26
38
|
function fmt(obj) {
|
|
27
39
|
try {
|
|
28
40
|
return JSON.stringify(obj);
|
|
@@ -198,43 +210,33 @@ async function main() {
|
|
|
198
210
|
catch (err) {
|
|
199
211
|
console.log(`Could not list methods: ${getErrorMessage(err)}`);
|
|
200
212
|
}
|
|
201
|
-
// ── Test 4:
|
|
202
|
-
|
|
213
|
+
// ── Test 4: get_liquidity_pool_history_by_sequence (pagination) ──
|
|
214
|
+
// Account-history APIs (get_account_history_by_operations,
|
|
215
|
+
// get_relative_account_history) do NOT apply here: a liquidity pool
|
|
216
|
+
// (1.19.N) is not an account (1.2.N). Their object IDs as the start/stop
|
|
217
|
+
// sequence arguments is what produced the old "Couldn't parse uint64_t".
|
|
218
|
+
console.log(`\n\n═══ TEST 4: get_liquidity_pool_history_by_sequence(poolId, startSeq, null, ${LIMIT}, 63) ═══`);
|
|
203
219
|
try {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
rows.slice(0, 3).forEach((r, i) => inspectRow(r, i));
|
|
210
|
-
}
|
|
220
|
+
const firstPage = await BitShares.history.get_liquidity_pool_history(POOL_ID, null, null, LIMIT, LP_OP_TYPE);
|
|
221
|
+
const firstRows = Array.isArray(firstPage) ? firstPage : [];
|
|
222
|
+
const lastSeq = Number(firstRows[firstRows.length - 1]?.sequence);
|
|
223
|
+
if (!Number.isFinite(lastSeq) || lastSeq <= 1) {
|
|
224
|
+
console.log(`No usable sequence to page from (first page length: ${firstRows.length})`);
|
|
211
225
|
}
|
|
212
226
|
else {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
catch (err) {
|
|
217
|
-
console.log(`ERROR: ${getErrorMessage(err)}`);
|
|
218
|
-
}
|
|
219
|
-
// ── Test 5: Try get_relative_account_history ─────────────────
|
|
220
|
-
console.log(`\n\n═══ TEST 5: get_relative_account_history ═══`);
|
|
221
|
-
try {
|
|
222
|
-
if (typeof BitShares.history.get_relative_account_history === 'function') {
|
|
223
|
-
const rows = await BitShares.history.get_relative_account_history(POOL_ID, 0, LIMIT, 0);
|
|
227
|
+
const startSeq = lastSeq - 1;
|
|
228
|
+
const rows = await BitShares.history.get_liquidity_pool_history_by_sequence(POOL_ID, startSeq, null, LIMIT, LP_OP_TYPE);
|
|
224
229
|
console.log(`Result: ${Array.isArray(rows) ? `Array[${rows.length}]` : typeof rows}`);
|
|
225
230
|
if (Array.isArray(rows)) {
|
|
226
|
-
rows.slice(0,
|
|
231
|
+
rows.slice(0, 5).forEach((r, i) => inspectRow(r, i));
|
|
227
232
|
}
|
|
228
233
|
}
|
|
229
|
-
else {
|
|
230
|
-
console.log('get_relative_account_history NOT available');
|
|
231
|
-
}
|
|
232
234
|
}
|
|
233
235
|
catch (err) {
|
|
234
236
|
console.log(`ERROR: ${getErrorMessage(err)}`);
|
|
235
237
|
}
|
|
236
|
-
// ── Test
|
|
237
|
-
console.log(`\n\n═══ TEST
|
|
238
|
+
// ── Test 5: Last 24h of trades — try to query recent only ─────
|
|
239
|
+
console.log(`\n\n═══ TEST 5: Last 100 results with larger limit ═══`);
|
|
238
240
|
try {
|
|
239
241
|
const rows = await BitShares.history.get_liquidity_pool_history(POOL_ID, null, null, 100, LP_OP_TYPE);
|
|
240
242
|
console.log(`Result: ${Array.isArray(rows) ? `Array[${rows.length}]` : typeof rows}`);
|
|
@@ -262,8 +264,8 @@ async function main() {
|
|
|
262
264
|
catch (err) {
|
|
263
265
|
console.log(`ERROR: ${getErrorMessage(err)}`);
|
|
264
266
|
}
|
|
265
|
-
// ── Test
|
|
266
|
-
console.log(`\n\n═══ TEST
|
|
267
|
+
// ── Test 6: Paged recent summary ──────────────────────────────
|
|
268
|
+
console.log(`\n\n═══ TEST 6: Paged LP history summary, last ${HOURS}h ═══`);
|
|
267
269
|
try {
|
|
268
270
|
const sinceMs = Date.now() - (HOURS * 3600 * 1000);
|
|
269
271
|
const collected = await collectRecentPoolHistory(POOL_ID, sinceMs, Math.min(101, LIMIT), MAX_PAGES);
|
|
@@ -290,6 +292,9 @@ async function main() {
|
|
|
290
292
|
if (typeof BitShares.disconnect === 'function') {
|
|
291
293
|
BitShares.disconnect();
|
|
292
294
|
}
|
|
295
|
+
// Force-exit: the native transport keeps reconnect timers alive and exposes
|
|
296
|
+
// no way to disable autoreconnect, so without this the process never exits.
|
|
297
|
+
process.exit(0);
|
|
293
298
|
}
|
|
294
299
|
main().catch(err => {
|
|
295
300
|
console.error(`Fatal: ${getErrorMessage(err)}`);
|
package/dist/scripts/pnl.js
CHANGED
|
@@ -23,7 +23,7 @@ if (invoked) {
|
|
|
23
23
|
// explicit --html/--report untouched so their own handling wins.
|
|
24
24
|
// Append (never prepend) the injected flag: the analyzer treats argv[0] as
|
|
25
25
|
// the account/target positional, so a leading flag would be read as the
|
|
26
|
-
// account name (`dexbot pnl
|
|
26
|
+
// account name (`dexbot pnl <account-name>` would become `--html <account-name>`).
|
|
27
27
|
const hasTarget = args.some(a => !a.startsWith('-'));
|
|
28
28
|
const ownsOutput = args.includes('--html') || args.includes('--report') || args.includes('--help') || args.includes('-h');
|
|
29
29
|
if (hasTarget && !ownsOutput)
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* BitShares per-asset rich list / top-holder reporter.
|
|
4
|
+
*
|
|
5
|
+
* Query one asset, or a list of assets, and print their top holders. Uses the
|
|
6
|
+
* chain's `asset_api` (`get_asset_holders`, `get_asset_holders_count`). Those
|
|
7
|
+
* endpoints are often restricted to allowlisted API users, so this script first
|
|
8
|
+
* tries candidate nodes that expose `asset_api` to anonymous logins.
|
|
9
|
+
*
|
|
10
|
+
* The returned holders are ordered by balance descending server-side (the
|
|
11
|
+
* account_balance_index `by_asset_balance` key sorts balance with
|
|
12
|
+
* `std::greater`), so page 0 is already the rich list.
|
|
13
|
+
*
|
|
14
|
+
* CLI: dexbot rich <ASSET> [ASSET...] [--top N]
|
|
15
|
+
* npm run richlist -- <ASSET> --top 10
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=rich_list.d.ts.map
|