dexbot 1.6.16 → 1.6.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/analysis/tradingview/README.md +2 -2
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- 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/ama_fitting/analyze_lambda_vs_slow.js +5 -3
- package/dist/analysis/tradingview/grid_reset_sim.js +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +4 -4
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +1 -1
- package/dist/modules/account_bots.d.ts +3 -0
- package/dist/modules/chain_keys.d.ts +1 -1
- package/dist/modules/constants.d.ts +6 -0
- package/dist/modules/constants.js +34 -6
- package/dist/modules/credit_pricing.d.ts +20 -1
- package/dist/modules/credit_pricing.js +23 -1
- package/dist/modules/credit_runtime.js +33 -16
- package/dist/modules/dexbot_class.d.ts +3 -1
- package/dist/modules/dexbot_class.js +5 -2
- package/dist/modules/dexbot_cow_runtime.d.ts +28 -37
- package/dist/modules/dexbot_cow_runtime.js +47 -66
- package/dist/modules/dexbot_maintenance_runtime.js +68 -10
- package/dist/modules/launcher/credential_daemon.d.ts +14 -2
- package/dist/modules/launcher/credential_daemon.js +60 -26
- package/dist/modules/order/grid.d.ts +7 -0
- package/dist/modules/order/grid.js +157 -15
- package/dist/modules/order/index.d.ts +15 -0
- package/dist/modules/order/manager.d.ts +30 -7
- package/dist/modules/order/manager.js +108 -12
- package/dist/modules/order/strategy.d.ts +5 -0
- package/dist/modules/order/strategy.js +23 -2
- package/dist/modules/order/utils/math.d.ts +41 -1
- package/dist/modules/order/utils/math.js +47 -1
- package/dist/modules/order/utils/order.d.ts +13 -0
- package/dist/modules/order/utils/order.js +61 -7
- package/dist/modules/order/utils/system.d.ts +66 -0
- package/dist/modules/order/utils/system.js +135 -0
- package/dist/modules/order/utils/validate.d.ts +3 -1
- package/dist/modules/order/utils/validate.js +5 -1
- package/dist/modules/types.d.ts +35 -2
- package/dist/scripts/analyze-credit.js +64 -23
- package/dist/scripts/bts_distribution.d.ts +66 -0
- package/dist/scripts/bts_distribution.js +2102 -0
- package/dist/scripts/token_distribution.d.ts +45 -0
- package/dist/scripts/token_distribution.js +1870 -0
- package/dist/unlock.js +42 -24
- package/docs/COW_INVARIANTS.md +6 -0
- package/docs/DEXBOT_COMPARISON.md +5 -5
- package/docs/EVOLUTION.md +9 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +3 -1
- package/docs/GRID_PRICE_INVARIANT.md +6 -0
- package/docs/GRID_RECALCULATION.md +3 -3
- package/docs/LOGGING.md +9 -0
- package/docs/MPA_CREDIT_USAGE.md +3 -2
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +117 -0
- package/docs/README.md +1 -1
- package/docs/architecture.md +98 -1
- package/market_adapter/README.md +2 -2
- package/package.json +3 -1
- package/scripts/README.md +85 -148
|
@@ -10,8 +10,11 @@ const require = createRequire(import.meta.url);
|
|
|
10
10
|
* additionally report per-pair and average CR, but only for pairs that are
|
|
11
11
|
* both whitelisted in bots.json (debtPolicy.lending) and listed on the
|
|
12
12
|
* current credit offer (acceptable_collateral) — anything else is reported
|
|
13
|
-
* as ignored/unpriced and excluded from the average.
|
|
14
|
-
*
|
|
13
|
+
* as ignored/unpriced and excluded from the average. LP-share collateral is
|
|
14
|
+
* valued from live pool reserves/supply, not the offer's fixed
|
|
15
|
+
* acceptable_collateral price (a contract haircut); the source tag on each
|
|
16
|
+
* Avar. CR line shows `pool` or `offer`. A borrow-now preview per configured
|
|
17
|
+
* pair shows the rate a fresh borrow would get today.
|
|
15
18
|
*
|
|
16
19
|
* Chain source of truth (see bitshares-core):
|
|
17
20
|
* - MPA positions: database_api::get_margin_positions(account)
|
|
@@ -40,6 +43,8 @@ import { pathToFileURL } from 'node:url';
|
|
|
40
43
|
// `dexbot order` so both analyzers stay visually in lockstep.
|
|
41
44
|
import { CLI_COLORS as colors } from '../modules/cli_colors.js';
|
|
42
45
|
import { muteChainLogs } from '../modules/utils/chain_logs.js';
|
|
46
|
+
import { setGlobalConsoleLevel } from '../modules/order/logger.js';
|
|
47
|
+
import { deriveLiquidityPoolTokenValue } from '../modules/order/utils/system.js';
|
|
43
48
|
const BOTS_FILE = PATHS.PROFILES.BOTS_JSON;
|
|
44
49
|
const CONNECT_TIMEOUT_MS = 30000;
|
|
45
50
|
const PAGE_LIMIT = 300;
|
|
@@ -92,7 +97,7 @@ function hasLending(bot) {
|
|
|
92
97
|
}
|
|
93
98
|
// Credit CR math lives in modules/credit_pricing.ts (single source of truth,
|
|
94
99
|
// shared with the live credit runtime) — no local copies here.
|
|
95
|
-
import { averageCollateralRatio as averageCreditCr, creditDealCollateralRatio as creditDealCr, dailyOfferFeeRate, extractOfferConversionRate, normalizeCollateralMap as normalizeOfferCollateralMap, } from '../modules/credit_pricing.js';
|
|
100
|
+
import { averageCollateralRatio as averageCreditCr, creditDealCollateralRatio as creditDealCr, dailyOfferFeeRate, extractOfferConversionRate, normalizeCollateralMap as normalizeOfferCollateralMap, selectCollateralConversionRate, } from '../modules/credit_pricing.js';
|
|
96
101
|
function lendingAssetsOfType(bot, type) {
|
|
97
102
|
const items = bot.debtPolicy?.lending ?? [];
|
|
98
103
|
return items
|
|
@@ -216,18 +221,36 @@ async function main() {
|
|
|
216
221
|
accountUsers.set(acc, (accountUsers.get(acc) || 0) + 1);
|
|
217
222
|
}
|
|
218
223
|
setSuppressConnectionLog(true);
|
|
224
|
+
// One-shot CLI: keep the analyzer's own console.log output, but silence
|
|
225
|
+
// Logger INFO chatter emitted while valuing LP collateral (e.g.
|
|
226
|
+
// derivePoolPrice). Warnings/errors still surface.
|
|
227
|
+
setGlobalConsoleLevel('warn');
|
|
219
228
|
await waitForConnected(CONNECT_TIMEOUT_MS);
|
|
220
|
-
// Asset metadata cache: id -> { symbol, precision }
|
|
221
229
|
const assetCache = new Map();
|
|
222
230
|
async function assetInfo(assetId) {
|
|
223
231
|
if (assetCache.has(assetId))
|
|
224
232
|
return assetCache.get(assetId);
|
|
225
233
|
const res = await dbCall('get_assets', [[assetId]]);
|
|
226
234
|
const a = Array.isArray(res) ? res[0] : null;
|
|
227
|
-
const info = {
|
|
235
|
+
const info = {
|
|
236
|
+
symbol: String(a?.symbol || assetId),
|
|
237
|
+
precision: Number.isFinite(Number(a?.precision)) ? Number(a.precision) : 5,
|
|
238
|
+
forLiquidityPool: a?.for_liquidity_pool ? String(a.for_liquidity_pool) : null,
|
|
239
|
+
};
|
|
228
240
|
assetCache.set(assetId, info);
|
|
229
241
|
return info;
|
|
230
242
|
}
|
|
243
|
+
// LP-share collateral is valued from pool reserves/supply, not from the
|
|
244
|
+
// credit offer's fixed contract price. Cache per collateral/debt pair.
|
|
245
|
+
const poolValueCache = new Map();
|
|
246
|
+
async function poolValueFor(collateralId, debtId) {
|
|
247
|
+
const key = `${collateralId}:${debtId}`;
|
|
248
|
+
if (poolValueCache.has(key))
|
|
249
|
+
return poolValueCache.get(key);
|
|
250
|
+
const value = await deriveLiquidityPoolTokenValue(BitShares, collateralId, debtId, 'auto', true).catch(() => null);
|
|
251
|
+
poolValueCache.set(key, value);
|
|
252
|
+
return value;
|
|
253
|
+
}
|
|
231
254
|
async function toFloat(raw, assetId) {
|
|
232
255
|
if (!Number.isFinite(raw))
|
|
233
256
|
return null;
|
|
@@ -253,7 +276,11 @@ async function main() {
|
|
|
253
276
|
const res = await dbCall('lookup_asset_symbols', [[s]]);
|
|
254
277
|
const a = Array.isArray(res) ? res[0] : null;
|
|
255
278
|
if (a?.id) {
|
|
256
|
-
assetCache.set(String(a.id), {
|
|
279
|
+
assetCache.set(String(a.id), {
|
|
280
|
+
symbol: String(a.symbol || s),
|
|
281
|
+
precision: Number(a.precision ?? 5),
|
|
282
|
+
forLiquidityPool: a.for_liquidity_pool ? String(a.for_liquidity_pool) : null,
|
|
283
|
+
});
|
|
257
284
|
return { id: String(a.id), symbol: String(a.symbol || s) };
|
|
258
285
|
}
|
|
259
286
|
}
|
|
@@ -275,7 +302,7 @@ async function main() {
|
|
|
275
302
|
}
|
|
276
303
|
}
|
|
277
304
|
}
|
|
278
|
-
catch { /* leave missing;
|
|
305
|
+
catch { /* leave missing; LP-share collateral can still be pool-valued */ }
|
|
279
306
|
}
|
|
280
307
|
return out;
|
|
281
308
|
}
|
|
@@ -523,9 +550,11 @@ async function main() {
|
|
|
523
550
|
resolveLendingRef(String(item.collateralAsset)),
|
|
524
551
|
]);
|
|
525
552
|
const maxCR = Number(item.maxCollateralRatio);
|
|
553
|
+
const collInfo = collR.id ? await assetInfo(collR.id) : null;
|
|
526
554
|
creditPairs.push({
|
|
527
555
|
debtId: debtR.id, debtSym: debtR.symbol,
|
|
528
556
|
collId: collR.id, collSym: collR.symbol,
|
|
557
|
+
collForLiquidityPool: Boolean(collInfo?.forLiquidityPool),
|
|
529
558
|
maxCR: Number.isFinite(maxCR) && maxCR > 0 ? maxCR : null,
|
|
530
559
|
});
|
|
531
560
|
}
|
|
@@ -565,20 +594,22 @@ async function main() {
|
|
|
565
594
|
}
|
|
566
595
|
catch { /* stays false */ }
|
|
567
596
|
}
|
|
568
|
-
// Conversion rate
|
|
569
|
-
// (
|
|
570
|
-
//
|
|
571
|
-
|
|
572
|
-
|
|
597
|
+
// Conversion rate: LP-share collateral is valued from the live pool
|
|
598
|
+
// (reserves/supply), because the offer's fixed acceptable_collateral
|
|
599
|
+
// price is a contract haircut, not the share's market value. Other
|
|
600
|
+
// collateral uses the deal's current credit offer price; if the offer
|
|
601
|
+
// is missing there is no CR.
|
|
573
602
|
const offerId = d?.offer_id != null ? String(d.offer_id) : null;
|
|
574
603
|
const offer = offerId ? offerById.get(offerId) : null;
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
604
|
+
const collInfo = collId ? await assetInfo(collId) : null;
|
|
605
|
+
const isLiquidityPoolShare = Boolean(collInfo?.forLiquidityPool);
|
|
606
|
+
const poolRate = isLiquidityPoolShare && collId && debtId
|
|
607
|
+
? await poolValueFor(collId, debtId)
|
|
608
|
+
: null;
|
|
609
|
+
const offerRate = offer && collId && debtId
|
|
610
|
+
? extractOfferConversionRate(offer?.acceptable_collateral, collId, debtId, precisionOf)
|
|
611
|
+
: null;
|
|
612
|
+
const { rate, source } = selectCollateralConversionRate({ offerRate, poolRate, isLiquidityPoolShare });
|
|
582
613
|
const value = debtFloat != null && collFloat != null && rate !== null ? collFloat * rate : null;
|
|
583
614
|
const cr = debtFloat != null && collFloat != null ? creditDealCr(debtFloat, collFloat, rate) : null;
|
|
584
615
|
crRows.push({
|
|
@@ -687,7 +718,9 @@ async function main() {
|
|
|
687
718
|
const segments = [...collTotals.values()]
|
|
688
719
|
.map((t) => `${formatAmount(t.debt)} ${group.debtSym} ← ${formatAmount(t.coll)} ${t.collSym}`)
|
|
689
720
|
.join(' + ');
|
|
690
|
-
|
|
721
|
+
const sources = [...new Set(group.rows.map((r) => r.source).filter((s) => !!s))];
|
|
722
|
+
const sourceTag = sources.length === 1 ? `, ${sources[0]}` : sources.length > 1 ? ', mixed' : '';
|
|
723
|
+
console.log(` ${colors.orange}${colors.bold}Avar. CR:${colors.reset} ${groupColor}${formatAmount(groupCr)}${colors.reset}, ${segments} ${colors.gray}(x${group.rows.length}${sourceTag})${colors.reset}`);
|
|
691
724
|
}
|
|
692
725
|
}
|
|
693
726
|
else if (supportedRows.length > 0) {
|
|
@@ -719,7 +752,9 @@ async function main() {
|
|
|
719
752
|
let liveOffer = null;
|
|
720
753
|
let liveRate = null;
|
|
721
754
|
let liveOfferId = null;
|
|
722
|
-
|
|
755
|
+
// Select the offer used by the active deals even when the CR rate
|
|
756
|
+
// itself came from the pool (LP-share collateral).
|
|
757
|
+
const offerRows = pairRows.filter((r) => r.rate !== null && r.offerId);
|
|
723
758
|
if (offerRows.length > 0) {
|
|
724
759
|
const ranked = offerRows.map((r) => ({ r, daily: dailyOfferFeeRate(offerById.get(r.offerId), feeDenom) }))
|
|
725
760
|
.sort((a, b) => a.daily - b.daily || String(a.r.offerId).localeCompare(String(b.r.offerId)));
|
|
@@ -763,8 +798,12 @@ async function main() {
|
|
|
763
798
|
// the offer's available funds, i.e. the CR a fresh borrow of the
|
|
764
799
|
// full available amount would land at.
|
|
765
800
|
let displayCr = pairCr;
|
|
766
|
-
if (displayCr === null && walletFloat !== null && walletFloat > 0 &&
|
|
767
|
-
|
|
801
|
+
if (displayCr === null && walletFloat !== null && walletFloat > 0 && avail !== null && avail > 0) {
|
|
802
|
+
const displayRate = pair.collForLiquidityPool && pair.collId && pair.debtId
|
|
803
|
+
? await poolValueFor(pair.collId, pair.debtId)
|
|
804
|
+
: liveRate;
|
|
805
|
+
if (displayRate !== null && displayRate > 0)
|
|
806
|
+
displayCr = (walletFloat * displayRate) / avail;
|
|
768
807
|
}
|
|
769
808
|
// Green at/below the user max (borrow allowed), red above it, white
|
|
770
809
|
// when no max is defined, gray when there is no CR at all.
|
|
@@ -789,6 +828,7 @@ async function main() {
|
|
|
789
828
|
}
|
|
790
829
|
console.log(`${colors.cyan}${'='.repeat(62)}${colors.reset}`);
|
|
791
830
|
console.log(`${colors.cyan}Summary: ${analyzed} bots, ${totalMpa} MPA positions, ${totalDeals} credit deals${colors.reset}\n`);
|
|
831
|
+
setGlobalConsoleLevel(null);
|
|
792
832
|
try {
|
|
793
833
|
disconnectClient();
|
|
794
834
|
}
|
|
@@ -798,6 +838,7 @@ async function main() {
|
|
|
798
838
|
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
799
839
|
main().catch((err) => {
|
|
800
840
|
console.error(`credit: ${getErrorMessage(err) || err}`);
|
|
841
|
+
setGlobalConsoleLevel(null);
|
|
801
842
|
try {
|
|
802
843
|
disconnectClient();
|
|
803
844
|
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* BitShares BTS supply distribution analyzer.
|
|
4
|
+
*
|
|
5
|
+
* Answers the question "where is all the BTS?" by walking the live chain and
|
|
6
|
+
* bucketing the core asset (1.3.0) into the places the protocol can hold it:
|
|
7
|
+
*
|
|
8
|
+
* Collateral / debt
|
|
9
|
+
* - call-order collateral 1.8.x call_order_object
|
|
10
|
+
* - global settlement fund 2.4.x asset_bitasset_data_object.settlement_fund
|
|
11
|
+
* - individual settlement fund 2.4.x asset_bitasset_data_object.individual_settlement_fund
|
|
12
|
+
* (reported with its debt, fund-implied price and force-settle params)
|
|
13
|
+
* - collateral bids after GS 2.17.x collateral_bid_object
|
|
14
|
+
*
|
|
15
|
+
* Governance / long-term locks
|
|
16
|
+
* - tickets (voting/governance) 1.18.x ticket_object (lock_forever, lock_N_days)
|
|
17
|
+
* - vesting balances 1.13.x vesting_balance_object (witness/worker/cashback)
|
|
18
|
+
* - legacy 1.15.x balances 1.15.x balance_object (claimable, not vesting)
|
|
19
|
+
*
|
|
20
|
+
* DeFi / pooled funds
|
|
21
|
+
* - liquidity pools 1.19.x liquidity_pool_object
|
|
22
|
+
* - SameT funds 1.20.x samet_fund_object
|
|
23
|
+
* - credit offers 1.21.x credit_offer_object.current_balance
|
|
24
|
+
* - credit-deal collateral 1.22.x credit_deal_object.collateral_amount
|
|
25
|
+
* - HTLC escrow 1.16.x htlc_object.transfer
|
|
26
|
+
*
|
|
27
|
+
* Protocol-controller accounts
|
|
28
|
+
* - asset fee pools all 2.3.x fee_pool (denominated in core BTS)
|
|
29
|
+
*
|
|
30
|
+
* Everything left over is reported as the liquid residual: account balances
|
|
31
|
+
* (2.5.x), limit-order escrow (1.7.x) and blinded balances (a subset, reported
|
|
32
|
+
* separately). That residual is derived, not enumerated, so it stays cheap:
|
|
33
|
+
* scanning every 2.5.x account balance or every 1.7.x limit order would need
|
|
34
|
+
* millions of object ids.
|
|
35
|
+
*
|
|
36
|
+
* Two extras complete the picture:
|
|
37
|
+
* - the top liquid holders, fetched from asset_api::get_asset_holders (the
|
|
38
|
+
* same source as scripts/rich_list.ts), with a best-effort exchange tag on
|
|
39
|
+
* account names (MEXC, Gate, Huobi, ...) — the tag is a heuristic, not proof;
|
|
40
|
+
* `--holders all` pages the whole list and splits the residual into account
|
|
41
|
+
* balances / blinded balances / order books + other, with a balance histogram;
|
|
42
|
+
* - a closing comparison of every bucket against total supply and against a
|
|
43
|
+
* derived circulating float (supply − identified/dormant). BitShares has no
|
|
44
|
+
* protocol-level circulating field, so the float is derived; an optional
|
|
45
|
+
* --circulating reference can be supplied for an aggregator/exchange figure.
|
|
46
|
+
*
|
|
47
|
+
* Chain source of truth: bitshares-core 7.0.x
|
|
48
|
+
* - libraries/protocol/include/graphene/protocol/types.hpp (object id spaces)
|
|
49
|
+
* - libraries/chain/include/graphene/chain/*_object.hpp (object layouts)
|
|
50
|
+
* - libraries/plugins/api_helper_indexes/ (amount_in_collateral / next ids)
|
|
51
|
+
* - libraries/app/database_api.cpp (list_* endpoints used for pagination)
|
|
52
|
+
*
|
|
53
|
+
* The script is read-only, opens its own ephemeral WebSocket connection (it
|
|
54
|
+
* never touches a running bot's connection) and has no runtime dependencies.
|
|
55
|
+
*
|
|
56
|
+
* Usage:
|
|
57
|
+
* node dist/scripts/bts_distribution.js # terminal + HTML
|
|
58
|
+
* node dist/scripts/bts_distribution.js --json # JSON + HTML
|
|
59
|
+
* node dist/scripts/bts_distribution.js --no-html # terminal only
|
|
60
|
+
* node dist/scripts/bts_distribution.js --detail 20 # bigger tables
|
|
61
|
+
* node dist/scripts/bts_distribution.js --holders 100 # rich-list size
|
|
62
|
+
* node dist/scripts/bts_distribution.js --circulating 2996921386.30283
|
|
63
|
+
* node dist/scripts/bts_distribution.js --node wss://cloud.xbts.io/ws
|
|
64
|
+
*/
|
|
65
|
+
export {};
|
|
66
|
+
//# sourceMappingURL=bts_distribution.d.ts.map
|