dexbot 1.6.15 → 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 +52 -0
- package/README.md +4 -4
- package/analysis/tradingview/README.md +2 -2
- package/analysis/trend_detection/DYNAMIC_WEIGHT_RESEARCH.md +1 -1
- package/claw/docs/DEXBOT2_TUNING_CHEAT_SHEET.md +3 -2
- package/claw/modules/chain_queries.ts +3 -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/ama_fitting/analyze_lambda_vs_slow.js +5 -3
- package/dist/analysis/ama_fitting/fetch_lp_candles.js +8 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.d.ts +50 -1
- package/dist/analysis/ama_fitting/optimizer_high_resolution.js +33 -7
- package/dist/analysis/bot_fitting/backtest_bot_fitting.d.ts +8 -6
- package/dist/analysis/bot_fitting/backtest_bot_fitting.js +8 -10
- package/dist/analysis/bot_key_utils.js +9 -7
- package/dist/analysis/chart_utils.d.ts +9 -2
- package/dist/analysis/chart_utils.js +51 -1
- package/dist/analysis/tradingview/grid_reset_sim.js +1 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.d.ts +2 -1
- package/dist/analysis/tradingview/tradingview_uplot_chart_generator.js +23 -9
- package/dist/analysis/trend_detection/backtest_ama_slope_huber.js +1 -1
- package/dist/analysis/trend_detection/dynamic_weight_chart_generator.js +21 -2
- package/dist/analysis/trend_detection/kalman_chart_generator.js +1 -0
- package/dist/analysis/trend_detection/regime_chart_generator.js +1 -1
- package/dist/analysis/trend_detection/volatility_chart_generator.js +1 -0
- package/dist/dexbot.js +89 -138
- package/dist/market_adapter/inputs/fetch_book_data.js +36 -12
- package/dist/market_adapter/inputs/fetch_lp_data.d.ts +6 -0
- package/dist/market_adapter/inputs/fetch_lp_data.js +65 -19
- package/dist/market_adapter/inputs/kibana_feed_source.js +45 -12
- package/dist/market_adapter/inputs/window_cache.d.ts +14 -1
- package/dist/market_adapter/inputs/window_cache.js +53 -17
- package/dist/market_adapter/lp_chart_core.js +1 -0
- package/dist/market_adapter/utils/chain.js +4 -3
- package/dist/market_adapter/utils/pair_orientation.d.ts +60 -0
- package/dist/market_adapter/utils/pair_orientation.js +142 -0
- package/dist/modules/account_bots.d.ts +40 -3
- package/dist/modules/account_bots.js +77 -37
- package/dist/modules/account_orders.d.ts +4 -1
- package/dist/modules/account_orders.js +4 -1
- package/dist/modules/bitshares-native/resolvers.js +3 -3
- package/dist/modules/bitshares_client.d.ts +12 -10
- package/dist/modules/bitshares_client.js +12 -10
- package/dist/modules/bot_settings.js +3 -3
- package/dist/modules/chain_keys.d.ts +6 -2
- package/dist/modules/chain_keys.js +5 -1
- package/dist/modules/chain_orders.d.ts +6 -2
- package/dist/modules/chain_orders.js +6 -2
- package/dist/modules/constants.d.ts +11 -0
- package/dist/modules/constants.js +41 -7
- 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 +6 -2
- package/dist/modules/dexbot_class.js +8 -3
- 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/graceful_shutdown.d.ts +6 -2
- package/dist/modules/graceful_shutdown.js +6 -2
- package/dist/modules/launcher/bot_supervisor.js +4 -0
- package/dist/modules/launcher/credential_daemon.d.ts +14 -2
- package/dist/modules/launcher/credential_daemon.js +60 -26
- package/dist/modules/launcher/launch_modes.js +6 -3
- package/dist/modules/launcher/monolithic_runtime.d.ts +39 -1
- package/dist/modules/launcher/monolithic_runtime.js +60 -1
- package/dist/modules/launcher/runtime_mode.d.ts +79 -0
- package/dist/modules/launcher/runtime_mode.js +223 -0
- package/dist/modules/market_adapter_whitelist.d.ts +8 -0
- package/dist/modules/market_adapter_whitelist.js +8 -0
- package/dist/modules/order/accounting.d.ts +15 -1
- package/dist/modules/order/accounting.js +15 -1
- package/dist/modules/order/async_lock.d.ts +9 -3
- package/dist/modules/order/async_lock.js +9 -3
- package/dist/modules/order/export.d.ts +0 -5
- package/dist/modules/order/export.js +0 -5
- package/dist/modules/order/format.d.ts +6 -4
- package/dist/modules/order/format.js +6 -4
- package/dist/modules/order/grid.d.ts +36 -18
- package/dist/modules/order/grid.js +186 -33
- package/dist/modules/order/index.d.ts +16 -1
- package/dist/modules/order/index.js +1 -1
- package/dist/modules/order/logger_state.d.ts +1 -1
- package/dist/modules/order/logger_state.js +1 -1
- 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/sync_engine.d.ts +26 -11
- package/dist/modules/order/sync_engine.js +26 -11
- package/dist/modules/order/utils/math.d.ts +100 -22
- package/dist/modules/order/utils/math.js +106 -22
- package/dist/modules/order/utils/order.d.ts +77 -20
- package/dist/modules/order/utils/order.js +125 -27
- package/dist/modules/order/utils/system.d.ts +107 -11
- package/dist/modules/order/utils/system.js +176 -11
- package/dist/modules/order/utils/validate.d.ts +8 -3
- package/dist/modules/order/utils/validate.js +10 -3
- package/dist/modules/types.d.ts +35 -2
- package/dist/modules/utils/asset_symbols.d.ts +5 -5
- package/dist/modules/utils/asset_symbols.js +5 -5
- package/dist/modules/utils/errors.d.ts +2 -1
- package/dist/modules/utils/errors.js +2 -1
- 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/rich_list.d.ts +32 -0
- package/dist/scripts/rich_list.js +16 -8
- package/dist/scripts/token_distribution.d.ts +45 -0
- package/dist/scripts/token_distribution.js +1870 -0
- package/dist/unlock.js +91 -42
- package/docs/BITSHARES_ONBOARDING.md +7 -0
- package/docs/COW_INVARIANTS.md +7 -1
- package/docs/DEXBOT_COMPARISON.md +5 -5
- package/docs/EVOLUTION.md +10 -8
- package/docs/FUND_MOVEMENT_AND_ACCOUNTING.md +5 -3
- package/docs/GRID_PRICE_INVARIANT.md +6 -0
- package/docs/GRID_RECALCULATION.md +18 -6
- package/docs/LIFECYCLE.md +8 -8
- package/docs/LOGGING.md +9 -0
- package/docs/MPA_CREDIT_USAGE.md +3 -2
- package/docs/ORDER_ENGINE_POST_1.0_RETROSPECTIVE.md +121 -4
- package/docs/README.md +1 -1
- package/docs/WORKFLOW.md +5 -5
- package/docs/architecture.md +98 -1
- package/market_adapter/README.md +10 -3
- package/package.json +5 -1
- package/scripts/README.md +85 -148
- package/tests/README.md +29 -0
|
@@ -0,0 +1,2102 @@
|
|
|
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
|
+
import fs from 'node:fs';
|
|
66
|
+
import path from 'node:path';
|
|
67
|
+
import { pathToFileURL } from 'node:url';
|
|
68
|
+
import { NODE_MANAGEMENT } from '../modules/constants.js';
|
|
69
|
+
import { PATHS } from '../modules/paths.js';
|
|
70
|
+
import { CLI_COLORS as colors } from '../modules/cli_colors.js';
|
|
71
|
+
// ---------------------------------------------------------------------------
|
|
72
|
+
// Constants
|
|
73
|
+
// ---------------------------------------------------------------------------
|
|
74
|
+
const DB_API = 0; // database_api is registered first
|
|
75
|
+
const LOGIN_API = 1; // login_api is registered second
|
|
76
|
+
const CORE_SYMBOL = 'BTS';
|
|
77
|
+
const CORE_ID_FALLBACK = '1.3.0';
|
|
78
|
+
const OBJECT_BATCH = 100; // get_objects ids per call
|
|
79
|
+
const NAME_BATCH = 50; // get_accounts ids per call
|
|
80
|
+
const DEFAULT_DETAIL = 10;
|
|
81
|
+
const DEFAULT_VESTING_MAX = 200_000;
|
|
82
|
+
const DEFAULT_SCAN_GAP = 20_000;
|
|
83
|
+
const DEFAULT_HTML = path.join(PATHS.ANALYSIS.CHARTS_DIR, 'bts-distribution.html');
|
|
84
|
+
const DEFAULT_HOLDERS = 100;
|
|
85
|
+
const MAX_HOLDERS = 1000;
|
|
86
|
+
// asset_api (get_asset_holders) is allowlisted on only a few public nodes; this
|
|
87
|
+
// list mirrors the one in scripts/rich_list.ts, which solves the same problem.
|
|
88
|
+
const HOLDER_NODES = [
|
|
89
|
+
'wss://dex.iobanker.com/ws',
|
|
90
|
+
'wss://api.dex.trading/',
|
|
91
|
+
];
|
|
92
|
+
// ---------------------------------------------------------------------------
|
|
93
|
+
// CLI parsing
|
|
94
|
+
// ---------------------------------------------------------------------------
|
|
95
|
+
class UsageError extends Error {
|
|
96
|
+
}
|
|
97
|
+
function printHelp() {
|
|
98
|
+
console.log(`BitShares BTS supply distribution.
|
|
99
|
+
|
|
100
|
+
Walks the live chain and reports every place BTS is held: call-order collateral,
|
|
101
|
+
settlement pools, governance tickets, vesting balances, liquidity pools, SameT
|
|
102
|
+
funds, credit offers/deals, HTLC escrow, asset fee pools and the legacy 1.15.x
|
|
103
|
+
balances. The remaining liquid supply (accounts, order books, blinded balances)
|
|
104
|
+
is reported as a derived residual.
|
|
105
|
+
|
|
106
|
+
Usage:
|
|
107
|
+
node dist/scripts/bts_distribution.js [options]
|
|
108
|
+
|
|
109
|
+
Options:
|
|
110
|
+
--node URL Pin a WebSocket node (repeatable; default built-in pool)
|
|
111
|
+
--detail N Rows in detail tables (default ${DEFAULT_DETAIL})
|
|
112
|
+
--holders N|all Liquid holders to fetch via asset_api (default ${DEFAULT_HOLDERS};
|
|
113
|
+
\`all\` pages the whole rich list and splits the residual exactly)
|
|
114
|
+
--circulating N Optional reference circulating supply in BTS (e.g. an exchange/
|
|
115
|
+
aggregator figure) to compare the chain-derived float against
|
|
116
|
+
--vesting-max N Highest 1.13.x object id to probe (default ${DEFAULT_VESTING_MAX})
|
|
117
|
+
--gap N Stop id scans after N consecutive missing ids (default ${DEFAULT_SCAN_GAP})
|
|
118
|
+
--html PATH HTML report path (default ${DEFAULT_HTML})
|
|
119
|
+
--no-html Do not write an HTML report
|
|
120
|
+
--json Print JSON to stdout instead of the terminal table
|
|
121
|
+
-h, --help This help
|
|
122
|
+
|
|
123
|
+
Data sources (bitshares-core 7.0.x):
|
|
124
|
+
database_api::get_assets / list_assets, get_objects, list_tickets,
|
|
125
|
+
list_liquidity_pools, list_samet_funds, list_credit_offers,
|
|
126
|
+
list_credit_deals, list_htlcs, get_collateral_bids.
|
|
127
|
+
Call-order collateral uses the api_helper_indexes extended asset field
|
|
128
|
+
total_in_collateral when the node exposes it (fallback: sum get_call_orders).
|
|
129
|
+
Top liquid holders come from asset_api::get_asset_holders (the same source as
|
|
130
|
+
scripts/rich_list.ts); if the connected node denies asset_api, the script
|
|
131
|
+
retries on a node that exposes it. Known exchange account names are tagged
|
|
132
|
+
(MEXC, Gate, Huobi, ...) but the tag is a name heuristic, not proof.`);
|
|
133
|
+
}
|
|
134
|
+
function parseArgs(argv) {
|
|
135
|
+
const VALUE_FLAGS = new Set(['--node', '--detail', '--holders', '--circulating', '--vesting-max', '--gap', '--html']);
|
|
136
|
+
const args = [];
|
|
137
|
+
for (const a of argv) {
|
|
138
|
+
const eq = a.indexOf('=');
|
|
139
|
+
if (a.startsWith('--') && eq > 0 && VALUE_FLAGS.has(a.slice(0, eq))) {
|
|
140
|
+
args.push(a.slice(0, eq), a.slice(eq + 1));
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
args.push(a);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const opts = {
|
|
147
|
+
nodes: [],
|
|
148
|
+
json: false,
|
|
149
|
+
html: DEFAULT_HTML,
|
|
150
|
+
detail: DEFAULT_DETAIL,
|
|
151
|
+
holders: DEFAULT_HOLDERS,
|
|
152
|
+
circulating: null,
|
|
153
|
+
vestingMax: DEFAULT_VESTING_MAX,
|
|
154
|
+
gap: DEFAULT_SCAN_GAP,
|
|
155
|
+
help: false,
|
|
156
|
+
};
|
|
157
|
+
const positiveInt = (flag, raw) => {
|
|
158
|
+
const n = Number(raw);
|
|
159
|
+
if (!Number.isInteger(n) || n < 1)
|
|
160
|
+
throw new UsageError(`${flag} must be a positive integer`);
|
|
161
|
+
return n;
|
|
162
|
+
};
|
|
163
|
+
for (let i = 0; i < args.length; i++) {
|
|
164
|
+
const a = args[i];
|
|
165
|
+
const next = () => {
|
|
166
|
+
const v = args[++i];
|
|
167
|
+
if (v === undefined)
|
|
168
|
+
throw new UsageError(`Missing value for ${a}`);
|
|
169
|
+
return v;
|
|
170
|
+
};
|
|
171
|
+
if (a === '--node')
|
|
172
|
+
opts.nodes.push(next());
|
|
173
|
+
else if (a === '--detail')
|
|
174
|
+
opts.detail = positiveInt(a, next());
|
|
175
|
+
else if (a === '--holders') {
|
|
176
|
+
const raw = next().toLowerCase();
|
|
177
|
+
opts.holders = raw === 'all' ? 0 : Math.min(positiveInt(a, raw), MAX_HOLDERS);
|
|
178
|
+
}
|
|
179
|
+
else if (a === '--circulating') {
|
|
180
|
+
const raw = next().replace(/,/g, '');
|
|
181
|
+
if (!/^\d+(\.\d+)?$/.test(raw))
|
|
182
|
+
throw new UsageError('--circulating must be a positive BTS amount');
|
|
183
|
+
opts.circulating = raw;
|
|
184
|
+
}
|
|
185
|
+
else if (a === '--vesting-max')
|
|
186
|
+
opts.vestingMax = positiveInt(a, next());
|
|
187
|
+
else if (a === '--gap')
|
|
188
|
+
opts.gap = positiveInt(a, next());
|
|
189
|
+
else if (a === '--html')
|
|
190
|
+
opts.html = path.resolve(next());
|
|
191
|
+
else if (a === '--no-html')
|
|
192
|
+
opts.html = null;
|
|
193
|
+
else if (a === '--json')
|
|
194
|
+
opts.json = true;
|
|
195
|
+
else if (a === '-h' || a === '--help')
|
|
196
|
+
opts.help = true;
|
|
197
|
+
else if (a.startsWith('-'))
|
|
198
|
+
throw new UsageError(`Unknown flag: ${a}`);
|
|
199
|
+
else
|
|
200
|
+
throw new UsageError(`Unexpected argument: ${a}`);
|
|
201
|
+
}
|
|
202
|
+
return opts;
|
|
203
|
+
}
|
|
204
|
+
class RpcClient {
|
|
205
|
+
url;
|
|
206
|
+
_id = 0;
|
|
207
|
+
_pending = new Map();
|
|
208
|
+
_closed = false;
|
|
209
|
+
_ws = null;
|
|
210
|
+
constructor(url) {
|
|
211
|
+
this.url = url;
|
|
212
|
+
}
|
|
213
|
+
connect(timeoutMs = 15000) {
|
|
214
|
+
return new Promise((resolve, reject) => {
|
|
215
|
+
let settled = false;
|
|
216
|
+
const ws = new WebSocket(this.url);
|
|
217
|
+
this._ws = ws;
|
|
218
|
+
const timer = setTimeout(() => {
|
|
219
|
+
if (settled)
|
|
220
|
+
return;
|
|
221
|
+
settled = true;
|
|
222
|
+
try {
|
|
223
|
+
ws.close();
|
|
224
|
+
}
|
|
225
|
+
catch { /* ignore */ }
|
|
226
|
+
reject(new Error(`connect timeout: ${this.url}`));
|
|
227
|
+
}, timeoutMs);
|
|
228
|
+
ws.onopen = () => {
|
|
229
|
+
if (settled)
|
|
230
|
+
return;
|
|
231
|
+
settled = true;
|
|
232
|
+
clearTimeout(timer);
|
|
233
|
+
resolve();
|
|
234
|
+
};
|
|
235
|
+
ws.onerror = () => {
|
|
236
|
+
if (settled)
|
|
237
|
+
return;
|
|
238
|
+
settled = true;
|
|
239
|
+
clearTimeout(timer);
|
|
240
|
+
reject(new Error(`connect error: ${this.url}`));
|
|
241
|
+
};
|
|
242
|
+
ws.onclose = () => {
|
|
243
|
+
this._closed = true;
|
|
244
|
+
for (const { reject: rj } of this._pending.values())
|
|
245
|
+
rj(new Error('connection closed'));
|
|
246
|
+
this._pending.clear();
|
|
247
|
+
};
|
|
248
|
+
ws.onmessage = (ev) => {
|
|
249
|
+
let msg;
|
|
250
|
+
try {
|
|
251
|
+
msg = JSON.parse(typeof ev.data === 'string' ? ev.data : String(ev.data));
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
return;
|
|
255
|
+
}
|
|
256
|
+
const p = this._pending.get(msg.id);
|
|
257
|
+
if (!p)
|
|
258
|
+
return;
|
|
259
|
+
this._pending.delete(msg.id);
|
|
260
|
+
if (msg.error) {
|
|
261
|
+
const text = msg.error.data?.message || msg.error.message || JSON.stringify(msg.error);
|
|
262
|
+
p.reject(new Error(text));
|
|
263
|
+
}
|
|
264
|
+
else {
|
|
265
|
+
p.resolve(msg.result);
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
call(api, method, args, timeoutMs = 60000) {
|
|
271
|
+
if (this._closed)
|
|
272
|
+
return Promise.reject(new Error('connection closed'));
|
|
273
|
+
return new Promise((resolve, reject) => {
|
|
274
|
+
const id = ++this._id;
|
|
275
|
+
const timer = setTimeout(() => {
|
|
276
|
+
if (!this._pending.has(id))
|
|
277
|
+
return;
|
|
278
|
+
this._pending.delete(id);
|
|
279
|
+
reject(new Error(`rpc timeout: ${method}`));
|
|
280
|
+
}, timeoutMs);
|
|
281
|
+
this._pending.set(id, {
|
|
282
|
+
resolve: (v) => { clearTimeout(timer); resolve(v); },
|
|
283
|
+
reject: (e) => { clearTimeout(timer); reject(e); },
|
|
284
|
+
});
|
|
285
|
+
this._ws?.send(JSON.stringify({ jsonrpc: '2.0', id, method: 'call', params: [api, method, args] }));
|
|
286
|
+
});
|
|
287
|
+
}
|
|
288
|
+
close() {
|
|
289
|
+
try {
|
|
290
|
+
this._ws?.close();
|
|
291
|
+
}
|
|
292
|
+
catch { /* ignore */ }
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
async function openSession(nodes) {
|
|
296
|
+
const errors = [];
|
|
297
|
+
for (const url of nodes) {
|
|
298
|
+
const client = new RpcClient(url);
|
|
299
|
+
try {
|
|
300
|
+
await client.connect();
|
|
301
|
+
await client.call(LOGIN_API, 'login', ['', '']);
|
|
302
|
+
const config = await client.call(LOGIN_API, 'get_config', []);
|
|
303
|
+
let assetApi = null;
|
|
304
|
+
try {
|
|
305
|
+
const api = await client.call(LOGIN_API, 'asset', []);
|
|
306
|
+
if (typeof api === 'number')
|
|
307
|
+
assetApi = api;
|
|
308
|
+
}
|
|
309
|
+
catch {
|
|
310
|
+
// Most public nodes deny asset_api; holders are fetched on a
|
|
311
|
+
// dedicated node below when necessary.
|
|
312
|
+
}
|
|
313
|
+
return { client, node: url, config: config || {}, assetApi };
|
|
314
|
+
}
|
|
315
|
+
catch (e) {
|
|
316
|
+
errors.push(`${url}: ${e.message}`);
|
|
317
|
+
client.close();
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
throw new Error(`No reachable BitShares node.\n ${errors.join('\n ')}`);
|
|
321
|
+
}
|
|
322
|
+
/**
|
|
323
|
+
* Find a node that grants anonymous access to asset_api (get_asset_holders).
|
|
324
|
+
* The main database session is left untouched; the caller must close this one.
|
|
325
|
+
*/
|
|
326
|
+
async function openAssetApiSession(excludeNodes) {
|
|
327
|
+
const excluded = new Set(excludeNodes);
|
|
328
|
+
const candidates = [...HOLDER_NODES, ...NODE_MANAGEMENT.DEFAULT_NODES]
|
|
329
|
+
.filter((node, index, all) => all.indexOf(node) === index && !excluded.has(node));
|
|
330
|
+
for (const url of candidates) {
|
|
331
|
+
const client = new RpcClient(url);
|
|
332
|
+
try {
|
|
333
|
+
await client.connect(10000);
|
|
334
|
+
await client.call(LOGIN_API, 'login', ['', '']);
|
|
335
|
+
const config = await client.call(LOGIN_API, 'get_config', []);
|
|
336
|
+
const api = await client.call(LOGIN_API, 'asset', []);
|
|
337
|
+
if (typeof api === 'number') {
|
|
338
|
+
return { client, node: url, config: config || {}, assetApi: api };
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
catch {
|
|
342
|
+
// try the next node
|
|
343
|
+
}
|
|
344
|
+
client.close();
|
|
345
|
+
}
|
|
346
|
+
return null;
|
|
347
|
+
}
|
|
348
|
+
/** Page through the rich-list endpoint (holders come back balance-descending). */
|
|
349
|
+
async function fetchAssetHolders(session, assetId, want, onProgress) {
|
|
350
|
+
if (session.assetApi === null)
|
|
351
|
+
throw new Error('asset_api unavailable on this node');
|
|
352
|
+
const api = session.assetApi;
|
|
353
|
+
const pageSize = Math.max(1, Math.min(session.config.api_limit_get_asset_holders ?? 100, 100));
|
|
354
|
+
const rows = [];
|
|
355
|
+
const unlimited = want <= 0;
|
|
356
|
+
let complete = false;
|
|
357
|
+
let nextProgress = 10000;
|
|
358
|
+
for (let start = 0; unlimited || start < want; start += pageSize) {
|
|
359
|
+
const size = unlimited ? pageSize : Math.min(pageSize, want - start);
|
|
360
|
+
const page = await session.client.call(api, 'get_asset_holders', [assetId, start, size]);
|
|
361
|
+
if (!Array.isArray(page) || page.length === 0) {
|
|
362
|
+
complete = true;
|
|
363
|
+
break;
|
|
364
|
+
}
|
|
365
|
+
rows.push(...page);
|
|
366
|
+
if (rows.length >= nextProgress) {
|
|
367
|
+
onProgress?.(rows.length);
|
|
368
|
+
nextProgress += 10000;
|
|
369
|
+
}
|
|
370
|
+
if (page.length < size) {
|
|
371
|
+
complete = true;
|
|
372
|
+
break;
|
|
373
|
+
}
|
|
374
|
+
if (rows.length >= 2_000_000)
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
let totalCount = null;
|
|
378
|
+
try {
|
|
379
|
+
const count = await session.client.call(api, 'get_asset_holders_count', [assetId]);
|
|
380
|
+
if (typeof count === 'number')
|
|
381
|
+
totalCount = count;
|
|
382
|
+
}
|
|
383
|
+
catch {
|
|
384
|
+
// optional
|
|
385
|
+
}
|
|
386
|
+
return { rows, totalCount, complete };
|
|
387
|
+
}
|
|
388
|
+
/**
|
|
389
|
+
* Best-effort exchange tag from the account name. This is a heuristic: anyone
|
|
390
|
+
* can register a name containing an exchange brand, so the tag is a hint.
|
|
391
|
+
*/
|
|
392
|
+
const CEX_BRANDS = [
|
|
393
|
+
[/mexc|mxccom|\bmxc\b/i, 'MEXC'],
|
|
394
|
+
[/gate-?io|\bgate\b/i, 'Gate'],
|
|
395
|
+
[/poloniex|\bpolo\b/i, 'Poloniex'],
|
|
396
|
+
[/huobi/i, 'Huobi'],
|
|
397
|
+
[/binance/i, 'Binance'],
|
|
398
|
+
[/\bokx\b|\bokex\b/i, 'OKX'],
|
|
399
|
+
[/kucoin/i, 'KuCoin'],
|
|
400
|
+
[/bybit/i, 'Bybit'],
|
|
401
|
+
[/bitget/i, 'Bitget'],
|
|
402
|
+
[/bittrex/i, 'Bittrex'],
|
|
403
|
+
[/upbit/i, 'Upbit'],
|
|
404
|
+
[/bithumb/i, 'Bithumb'],
|
|
405
|
+
[/coinbase/i, 'Coinbase'],
|
|
406
|
+
[/kraken/i, 'Kraken'],
|
|
407
|
+
[/bitfinex/i, 'Bitfinex'],
|
|
408
|
+
[/bitstamp/i, 'Bitstamp'],
|
|
409
|
+
[/bitmart/i, 'BitMart'],
|
|
410
|
+
[/lbank/i, 'LBank'],
|
|
411
|
+
[/probit/i, 'ProBit'],
|
|
412
|
+
[/ascendex|bitmax/i, 'AscendEX'],
|
|
413
|
+
[/coinex/i, 'CoinEx'],
|
|
414
|
+
[/coinspot/i, 'Coinspot'],
|
|
415
|
+
[/hitbtc/i, 'HitBTC'],
|
|
416
|
+
[/\baex\b/i, 'AEX'],
|
|
417
|
+
[/\bexx/i, 'EXX'],
|
|
418
|
+
[/exmo/i, 'EXMO'],
|
|
419
|
+
[/bitso\b/i, 'Bitso'],
|
|
420
|
+
[/wazirx/i, 'WazirX'],
|
|
421
|
+
[/zebpay/i, 'Zebpay'],
|
|
422
|
+
[/gemini/i, 'Gemini'],
|
|
423
|
+
[/bitpanda/i, 'Bitpanda'],
|
|
424
|
+
[/crypto\.?com/i, 'Crypto.com'],
|
|
425
|
+
[/luno/i, 'Luno'],
|
|
426
|
+
[/btcturk/i, 'BTC Turk'],
|
|
427
|
+
[/tokocrypto/i, 'Tokocrypto'],
|
|
428
|
+
[/indodax/i, 'Indodax'],
|
|
429
|
+
[/\bvalr\b/i, 'VALR'],
|
|
430
|
+
];
|
|
431
|
+
const CEX_HINT = /(^|[-_.\s])(exchange|cex|hot-?wallet|cold-?wallet|deposit|withdrawal|payout|transfers?)([-_.\s]|$)/i;
|
|
432
|
+
function detectExchange(name) {
|
|
433
|
+
if (!name)
|
|
434
|
+
return undefined;
|
|
435
|
+
for (const [pattern, label] of CEX_BRANDS) {
|
|
436
|
+
if (pattern.test(name))
|
|
437
|
+
return label;
|
|
438
|
+
}
|
|
439
|
+
if (CEX_HINT.test(name))
|
|
440
|
+
return 'CEX?';
|
|
441
|
+
return undefined;
|
|
442
|
+
}
|
|
443
|
+
// ---------------------------------------------------------------------------
|
|
444
|
+
// Numeric helpers (all on-chain amounts are exact bigints)
|
|
445
|
+
// ---------------------------------------------------------------------------
|
|
446
|
+
function toBig(value) {
|
|
447
|
+
if (value === null || value === undefined)
|
|
448
|
+
return 0n;
|
|
449
|
+
if (typeof value === 'number') {
|
|
450
|
+
if (!Number.isFinite(value))
|
|
451
|
+
return 0n;
|
|
452
|
+
return BigInt(Math.round(value));
|
|
453
|
+
}
|
|
454
|
+
try {
|
|
455
|
+
return BigInt(value);
|
|
456
|
+
}
|
|
457
|
+
catch {
|
|
458
|
+
return 0n;
|
|
459
|
+
}
|
|
460
|
+
}
|
|
461
|
+
function amountOf(amount) {
|
|
462
|
+
return amount ? toBig(amount.amount) : 0n;
|
|
463
|
+
}
|
|
464
|
+
function formatUnits(raw, precision) {
|
|
465
|
+
const negative = raw < 0n;
|
|
466
|
+
const abs = negative ? -raw : raw;
|
|
467
|
+
const divisor = 10n ** BigInt(precision);
|
|
468
|
+
const whole = abs / divisor;
|
|
469
|
+
const frac = precision > 0 ? (abs % divisor).toString().padStart(precision, '0').replace(/0+$/, '') : '';
|
|
470
|
+
return `${negative ? '-' : ''}${formatInteger(whole)}${frac ? `.${frac}` : ''}`;
|
|
471
|
+
}
|
|
472
|
+
/** Parse a human decimal amount (e.g. "2996921386.30283") into chain units. */
|
|
473
|
+
function parseUnits(text, precision) {
|
|
474
|
+
const match = /^(\d+)(?:\.(\d+))?$/.exec(text.trim());
|
|
475
|
+
if (!match)
|
|
476
|
+
throw new Error(`invalid amount: ${text}`);
|
|
477
|
+
const whole = BigInt(match[1]);
|
|
478
|
+
const fraction = (match[2] ?? '').slice(0, precision).padEnd(precision, '0');
|
|
479
|
+
return whole * 10n ** BigInt(precision) + BigInt(fraction || '0');
|
|
480
|
+
}
|
|
481
|
+
function formatInteger(value) {
|
|
482
|
+
const s = value.toString();
|
|
483
|
+
return s.replace(/\B(?=(\d{3})+(?!\d))/g, ',');
|
|
484
|
+
}
|
|
485
|
+
/** Compact human number for chart centres: 2.997B, 890.386M, 26.269M. */
|
|
486
|
+
function compactUnits(raw, precision) {
|
|
487
|
+
const divisor = 10n ** BigInt(precision);
|
|
488
|
+
const whole = raw / divisor;
|
|
489
|
+
const negative = whole < 0n;
|
|
490
|
+
const abs = negative ? -whole : whole;
|
|
491
|
+
const tiers = [
|
|
492
|
+
[10n ** 12n, 'T'],
|
|
493
|
+
[10n ** 9n, 'B'],
|
|
494
|
+
[10n ** 6n, 'M'],
|
|
495
|
+
[10n ** 3n, 'K'],
|
|
496
|
+
];
|
|
497
|
+
for (const [tier, suffix] of tiers) {
|
|
498
|
+
if (abs < tier)
|
|
499
|
+
continue;
|
|
500
|
+
const milli = (abs * 1000n) / tier;
|
|
501
|
+
const intPart = milli / 1000n;
|
|
502
|
+
const frac = (milli % 1000n).toString().padStart(3, '0').replace(/0+$/, '');
|
|
503
|
+
return `${negative ? '-' : ''}${intPart}${frac ? `.${frac}` : ''}${suffix}`;
|
|
504
|
+
}
|
|
505
|
+
return `${negative ? '-' : ''}${abs}`;
|
|
506
|
+
}
|
|
507
|
+
function sharePercent(part, whole, digits = 2) {
|
|
508
|
+
if (whole <= 0n)
|
|
509
|
+
return '—';
|
|
510
|
+
const scaled = Number((part * 1000000n) / whole); // percent * 10^4
|
|
511
|
+
return `${(scaled / 10_000).toFixed(digits)}%`;
|
|
512
|
+
}
|
|
513
|
+
function shareFraction(part, whole) {
|
|
514
|
+
if (whole <= 0n)
|
|
515
|
+
return 0;
|
|
516
|
+
return Number((part * 10000n) / whole) / 10_000;
|
|
517
|
+
}
|
|
518
|
+
function compareDesc(a, b) {
|
|
519
|
+
return a > b ? -1 : a < b ? 1 : 0;
|
|
520
|
+
}
|
|
521
|
+
function sum(values) {
|
|
522
|
+
return values.reduce((acc, v) => acc + v, 0n);
|
|
523
|
+
}
|
|
524
|
+
// ---------------------------------------------------------------------------
|
|
525
|
+
// Chain queries
|
|
526
|
+
// ---------------------------------------------------------------------------
|
|
527
|
+
async function callDb(session, method, args) {
|
|
528
|
+
return session.client.call(DB_API, method, args);
|
|
529
|
+
}
|
|
530
|
+
/** Fetch object ids in chunks; the node returns null for ids that do not exist. */
|
|
531
|
+
async function fetchObjects(session, ids) {
|
|
532
|
+
const out = [];
|
|
533
|
+
for (let i = 0; i < ids.length; i += OBJECT_BATCH) {
|
|
534
|
+
const chunk = ids.slice(i, i + OBJECT_BATCH);
|
|
535
|
+
const page = await callDb(session, 'get_objects', [chunk]);
|
|
536
|
+
for (let j = 0; j < chunk.length; j++)
|
|
537
|
+
out.push(page?.[j] ?? null);
|
|
538
|
+
}
|
|
539
|
+
return out;
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Paginate a `list_*` endpoint whose signature is `(limit, start_id)`.
|
|
543
|
+
* Every page is de-duplicated by id, so an inclusive lower bound cannot loop.
|
|
544
|
+
*/
|
|
545
|
+
async function listPages(session, method, limit, maxPages = 5000) {
|
|
546
|
+
const seen = new Set();
|
|
547
|
+
const out = [];
|
|
548
|
+
let start = null;
|
|
549
|
+
for (let page = 0; page < maxPages; page++) {
|
|
550
|
+
const rows = await callDb(session, method, [limit, start]);
|
|
551
|
+
if (!rows || rows.length === 0)
|
|
552
|
+
break;
|
|
553
|
+
let fresh = 0;
|
|
554
|
+
for (const row of rows) {
|
|
555
|
+
if (!row || typeof row.id !== 'string' || seen.has(row.id))
|
|
556
|
+
continue;
|
|
557
|
+
seen.add(row.id);
|
|
558
|
+
out.push(row);
|
|
559
|
+
fresh++;
|
|
560
|
+
}
|
|
561
|
+
if (rows.length < limit || fresh === 0)
|
|
562
|
+
break;
|
|
563
|
+
start = rows[rows.length - 1].id;
|
|
564
|
+
}
|
|
565
|
+
return out;
|
|
566
|
+
}
|
|
567
|
+
/**
|
|
568
|
+
* Enumerate every asset via `list_assets` (symbol-ordered, inclusive lower
|
|
569
|
+
* bound). Assets are keyed by symbol, so pagination advances on the last
|
|
570
|
+
* symbol and duplicates are ignored.
|
|
571
|
+
*/
|
|
572
|
+
async function listAllAssets(session) {
|
|
573
|
+
const limit = Math.max(1, Math.min(session.config.api_limit_get_assets ?? 100, 1000));
|
|
574
|
+
const seen = new Set();
|
|
575
|
+
const out = [];
|
|
576
|
+
let lower = '';
|
|
577
|
+
for (let page = 0; page < 5000; page++) {
|
|
578
|
+
const rows = await callDb(session, 'list_assets', [lower, limit]);
|
|
579
|
+
if (!Array.isArray(rows) || rows.length === 0)
|
|
580
|
+
break;
|
|
581
|
+
let fresh = 0;
|
|
582
|
+
for (const row of rows) {
|
|
583
|
+
if (!row || seen.has(row.id))
|
|
584
|
+
continue;
|
|
585
|
+
seen.add(row.id);
|
|
586
|
+
out.push(row);
|
|
587
|
+
fresh++;
|
|
588
|
+
}
|
|
589
|
+
if (rows.length < limit)
|
|
590
|
+
break;
|
|
591
|
+
const lastSymbol = rows[rows.length - 1]?.symbol;
|
|
592
|
+
if (typeof lastSymbol !== 'string')
|
|
593
|
+
break;
|
|
594
|
+
if (fresh === 0)
|
|
595
|
+
break;
|
|
596
|
+
lower = lastSymbol;
|
|
597
|
+
}
|
|
598
|
+
return out;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* Scan a dense-ish object id range (`prefix.N`) with a gap tolerance. Object
|
|
602
|
+
* ids are allocated monotonically but are never reused, so a range contains
|
|
603
|
+
* holes; the scan stops once it has walked `gap` ids past the last live object.
|
|
604
|
+
*/
|
|
605
|
+
async function scanIdRange(session, prefix, maxId, gap, onProgress) {
|
|
606
|
+
const objects = [];
|
|
607
|
+
let index = 0;
|
|
608
|
+
let lastSeen = -1;
|
|
609
|
+
while (index <= maxId && index - lastSeen <= gap) {
|
|
610
|
+
const count = Math.min(OBJECT_BATCH, maxId - index + 1);
|
|
611
|
+
const ids = Array.from({ length: count }, (_, i) => `${prefix}.${index + i}`);
|
|
612
|
+
const page = await callDb(session, 'get_objects', [ids]);
|
|
613
|
+
for (let j = 0; j < count; j++) {
|
|
614
|
+
const obj = page?.[j];
|
|
615
|
+
if (obj) {
|
|
616
|
+
lastSeen = index + j;
|
|
617
|
+
objects.push(obj);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
index += count;
|
|
621
|
+
onProgress?.(index);
|
|
622
|
+
}
|
|
623
|
+
return { objects, scannedTo: index, hitLimit: index > maxId && index - lastSeen <= gap };
|
|
624
|
+
}
|
|
625
|
+
async function resolveAccountNames(session, ids) {
|
|
626
|
+
const names = new Map();
|
|
627
|
+
const unique = [...new Set(ids.filter(Boolean))];
|
|
628
|
+
for (let i = 0; i < unique.length; i += NAME_BATCH) {
|
|
629
|
+
const chunk = unique.slice(i, i + NAME_BATCH);
|
|
630
|
+
try {
|
|
631
|
+
const rows = await callDb(session, 'get_accounts', [chunk]);
|
|
632
|
+
for (const row of rows)
|
|
633
|
+
if (row)
|
|
634
|
+
names.set(row.id, row.name);
|
|
635
|
+
}
|
|
636
|
+
catch {
|
|
637
|
+
// Name resolution is cosmetic; ids are still shown.
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
return names;
|
|
641
|
+
}
|
|
642
|
+
/** Fallback when api_helper_indexes is unavailable: sum per-MPA call orders. */
|
|
643
|
+
async function sumCallOrderCollateral(session, mpas) {
|
|
644
|
+
const limit = Math.max(1, Math.min(session.config.api_limit_get_call_orders ?? 100, 1000));
|
|
645
|
+
let total = 0n;
|
|
646
|
+
let truncated = false;
|
|
647
|
+
for (const mpa of mpas) {
|
|
648
|
+
try {
|
|
649
|
+
const rows = await callDb(session, 'get_call_orders', [mpa.id, limit]);
|
|
650
|
+
if (!Array.isArray(rows))
|
|
651
|
+
continue;
|
|
652
|
+
for (const row of rows) {
|
|
653
|
+
if (row.call_price?.base?.asset_id === CORE_ID_FALLBACK)
|
|
654
|
+
total += toBig(row.collateral);
|
|
655
|
+
}
|
|
656
|
+
if (rows.length >= limit)
|
|
657
|
+
truncated = true;
|
|
658
|
+
}
|
|
659
|
+
catch {
|
|
660
|
+
truncated = true;
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
return { total, truncated };
|
|
664
|
+
}
|
|
665
|
+
// ---------------------------------------------------------------------------
|
|
666
|
+
// Collection
|
|
667
|
+
// ---------------------------------------------------------------------------
|
|
668
|
+
function progress(enabled, message) {
|
|
669
|
+
if (!enabled)
|
|
670
|
+
return;
|
|
671
|
+
if (!process.stderr.isTTY)
|
|
672
|
+
return;
|
|
673
|
+
process.stderr.write(`\r\x1b[2K ${message}`);
|
|
674
|
+
}
|
|
675
|
+
function clearProgress(enabled) {
|
|
676
|
+
if (!enabled || !process.stderr.isTTY)
|
|
677
|
+
return;
|
|
678
|
+
process.stderr.write('\r\x1b[2K');
|
|
679
|
+
}
|
|
680
|
+
const COLORS = [
|
|
681
|
+
'#5eb0ef', '#f0883e', '#3fb950', '#db61a2', '#a371f7', '#e3b341',
|
|
682
|
+
'#39c5cf', '#ff7b72', '#7ee787', '#d2a8ff', '#ffa657', '#8b949e',
|
|
683
|
+
'#79c0ff', '#ffd33d', '#56d364', '#f778ba',
|
|
684
|
+
];
|
|
685
|
+
async function collect(session, opts) {
|
|
686
|
+
const showProgress = !opts.json;
|
|
687
|
+
const warnings = [];
|
|
688
|
+
const generatedAt = new Date().toISOString();
|
|
689
|
+
// ---- Core asset + supply ------------------------------------------------
|
|
690
|
+
const found = await callDb(session, 'lookup_asset_symbols', [[CORE_SYMBOL]]);
|
|
691
|
+
const coreStub = found?.[0];
|
|
692
|
+
if (!coreStub)
|
|
693
|
+
throw new Error(`core asset ${CORE_SYMBOL} not found on this node`);
|
|
694
|
+
const coreRows = await callDb(session, 'get_assets', [[coreStub.id]]);
|
|
695
|
+
const core = { ...coreStub, ...(coreRows?.[0] ?? {}) };
|
|
696
|
+
const coreId = core.id || CORE_ID_FALLBACK;
|
|
697
|
+
const dynRows = await fetchObjects(session, [core.dynamic_asset_data_id]);
|
|
698
|
+
const coreDyn = dynRows[0];
|
|
699
|
+
if (!coreDyn)
|
|
700
|
+
throw new Error('core asset dynamic data missing');
|
|
701
|
+
const currentSupply = toBig(coreDyn.current_supply);
|
|
702
|
+
const confidentialSupply = toBig(coreDyn.confidential_supply);
|
|
703
|
+
const global = await callDb(session, 'get_dynamic_global_properties', []);
|
|
704
|
+
// ---- All assets: MPAs, symbols, fee pools -------------------------------
|
|
705
|
+
progress(showProgress, 'enumerating assets ...');
|
|
706
|
+
const assets = await listAllAssets(session);
|
|
707
|
+
const assetById = new Map(assets.map((a) => [a.id, a]));
|
|
708
|
+
const symbolOf = (id) => assetById.get(id)?.symbol ?? id;
|
|
709
|
+
progress(showProgress, `fetching dynamic data for ${assets.length} assets ...`);
|
|
710
|
+
const dynamicIds = assets.map((a) => a.dynamic_asset_data_id).filter(Boolean);
|
|
711
|
+
const dynamicRows = await fetchObjects(session, dynamicIds);
|
|
712
|
+
const dynamicById = new Map();
|
|
713
|
+
for (const dyn of dynamicRows)
|
|
714
|
+
if (dyn)
|
|
715
|
+
dynamicById.set(dyn.id, dyn);
|
|
716
|
+
const mpaAssets = assets.filter((a) => typeof a.bitasset_data_id === 'string' && a.bitasset_data_id);
|
|
717
|
+
const bitassetRows = await fetchObjects(session, mpaAssets.map((a) => a.bitasset_data_id));
|
|
718
|
+
const bitassetById = new Map();
|
|
719
|
+
bitassetRows.forEach((bit) => {
|
|
720
|
+
if (bit)
|
|
721
|
+
bitassetById.set(bit.id, bit);
|
|
722
|
+
});
|
|
723
|
+
const btsBackedMpas = mpaAssets.filter((a) => {
|
|
724
|
+
const bit = a.bitasset_data_id ? bitassetById.get(a.bitasset_data_id) : undefined;
|
|
725
|
+
return bit?.options?.short_backing_asset === coreId;
|
|
726
|
+
});
|
|
727
|
+
// ---- Fee pools (fee_pool is denominated in the core asset) --------------
|
|
728
|
+
let feePoolTotal = 0n;
|
|
729
|
+
const feePoolRows = [];
|
|
730
|
+
for (const dyn of dynamicRows) {
|
|
731
|
+
if (!dyn)
|
|
732
|
+
continue;
|
|
733
|
+
const value = toBig(dyn.fee_pool);
|
|
734
|
+
feePoolTotal += value;
|
|
735
|
+
if (value > 0n) {
|
|
736
|
+
const asset = assetById.get(dyn.id.replace(/^2\.3\./, '1.3.'));
|
|
737
|
+
feePoolRows.push({ symbol: asset?.symbol ?? dyn.id, amount: value });
|
|
738
|
+
}
|
|
739
|
+
}
|
|
740
|
+
feePoolRows.sort((a, b) => compareDesc(a.amount, b.amount));
|
|
741
|
+
// ---- Call-order collateral ---------------------------------------------
|
|
742
|
+
let collateral;
|
|
743
|
+
let collateralFromApi = core.total_in_collateral !== undefined && core.total_in_collateral !== null;
|
|
744
|
+
let collateralTruncated = false;
|
|
745
|
+
if (collateralFromApi) {
|
|
746
|
+
collateral = toBig(core.total_in_collateral);
|
|
747
|
+
}
|
|
748
|
+
else {
|
|
749
|
+
progress(showProgress, 'summing call orders (api_helper_indexes unavailable) ...');
|
|
750
|
+
const fallback = await sumCallOrderCollateral(session, btsBackedMpas);
|
|
751
|
+
collateral = fallback.total;
|
|
752
|
+
collateralTruncated = fallback.truncated;
|
|
753
|
+
collateralFromApi = false;
|
|
754
|
+
warnings.push('Node does not expose api_helper_indexes extended asset fields; '
|
|
755
|
+
+ 'call-order collateral is a per-MPA sum of get_call_orders and may be truncated.');
|
|
756
|
+
}
|
|
757
|
+
// ---- Settlement pools + per-MPA table -----------------------------------
|
|
758
|
+
let settlementFund = 0n;
|
|
759
|
+
let individualSettlementFund = 0n;
|
|
760
|
+
let mpaBackedCollateral = 0n;
|
|
761
|
+
const mpaRows = [];
|
|
762
|
+
const globallySettled = [];
|
|
763
|
+
for (const mpa of btsBackedMpas) {
|
|
764
|
+
const bit = mpa.bitasset_data_id ? bitassetById.get(mpa.bitasset_data_id) : undefined;
|
|
765
|
+
if (!bit)
|
|
766
|
+
continue;
|
|
767
|
+
const sf = toBig(bit.settlement_fund);
|
|
768
|
+
const isf = toBig(bit.individual_settlement_fund);
|
|
769
|
+
const backed = mpa.total_backing_collateral !== undefined && mpa.total_backing_collateral !== null
|
|
770
|
+
? toBig(mpa.total_backing_collateral)
|
|
771
|
+
: 0n;
|
|
772
|
+
settlementFund += sf;
|
|
773
|
+
individualSettlementFund += isf;
|
|
774
|
+
mpaBackedCollateral += backed;
|
|
775
|
+
const settled = amountOf(bit.settlement_price?.base) > 0n;
|
|
776
|
+
if (settled)
|
|
777
|
+
globallySettled.push(mpa);
|
|
778
|
+
if (backed > 0n || sf > 0n || isf > 0n) {
|
|
779
|
+
mpaRows.push({
|
|
780
|
+
assetId: mpa.id,
|
|
781
|
+
symbol: mpa.symbol,
|
|
782
|
+
collateral: backed,
|
|
783
|
+
settlementFund: sf,
|
|
784
|
+
individualSettlementFund: isf,
|
|
785
|
+
settled,
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
}
|
|
789
|
+
mpaRows.sort((a, b) => compareDesc(a.collateral + a.settlementFund + a.individualSettlementFund, b.collateral + b.settlementFund + b.individualSettlementFund));
|
|
790
|
+
// Force-settlement / individual settlement pools. The fund is denominated
|
|
791
|
+
// in BTS (and is part of the bucket above); the debt, max volume and settled
|
|
792
|
+
// volume are denominated in the MPA itself, so they are shown next to it but
|
|
793
|
+
// are NOT added to the BTS totals.
|
|
794
|
+
const settlementRows = [];
|
|
795
|
+
for (const mpa of btsBackedMpas) {
|
|
796
|
+
const bit = mpa.bitasset_data_id ? bitassetById.get(mpa.bitasset_data_id) : undefined;
|
|
797
|
+
if (!bit)
|
|
798
|
+
continue;
|
|
799
|
+
const fund = toBig(bit.individual_settlement_fund);
|
|
800
|
+
const debt = toBig(bit.individual_settlement_debt);
|
|
801
|
+
const settledVolume = toBig(bit.force_settled_volume);
|
|
802
|
+
if (fund === 0n && debt === 0n)
|
|
803
|
+
continue;
|
|
804
|
+
const dyn = dynamicById.get(mpa.dynamic_asset_data_id);
|
|
805
|
+
const supply = dyn ? toBig(dyn.current_supply) : 0n;
|
|
806
|
+
const flag = bit.options.maximum_force_settlement_volume ?? 0;
|
|
807
|
+
let maxVolume = 0n;
|
|
808
|
+
if (flag === 10000)
|
|
809
|
+
maxVolume = supply + settledVolume;
|
|
810
|
+
else if (flag > 0)
|
|
811
|
+
maxVolume = ((supply + settledVolume) * BigInt(flag)) / 10000n;
|
|
812
|
+
const debtHuman = Number(debt) / 10 ** mpa.precision;
|
|
813
|
+
const fundHuman = Number(fund) / 10 ** (core.precision ?? 5);
|
|
814
|
+
const fundPrice = debt > 0n && fundHuman > 0 ? fundHuman / debtHuman : null;
|
|
815
|
+
settlementRows.push({
|
|
816
|
+
assetId: mpa.id,
|
|
817
|
+
symbol: mpa.symbol,
|
|
818
|
+
precision: mpa.precision,
|
|
819
|
+
fund,
|
|
820
|
+
debt,
|
|
821
|
+
fundPrice,
|
|
822
|
+
offsetPercent: bit.options.force_settlement_offset_percent !== undefined
|
|
823
|
+
? bit.options.force_settlement_offset_percent / 100
|
|
824
|
+
: null,
|
|
825
|
+
feePercent: bit.options.extensions?.force_settle_fee_percent !== undefined
|
|
826
|
+
? bit.options.extensions.force_settle_fee_percent / 100
|
|
827
|
+
: null,
|
|
828
|
+
delaySeconds: bit.options.force_settlement_delay_sec ?? null,
|
|
829
|
+
maxVolume,
|
|
830
|
+
settledVolume,
|
|
831
|
+
remainingPercent: maxVolume > 0n
|
|
832
|
+
? Math.max(0, 1 - Number(settledVolume) / Number(maxVolume)) * 100
|
|
833
|
+
: null,
|
|
834
|
+
});
|
|
835
|
+
}
|
|
836
|
+
settlementRows.sort((a, b) => compareDesc(a.fund, b.fund));
|
|
837
|
+
if (!collateralFromApi && mpaBackedCollateral > 0n) {
|
|
838
|
+
// Backing collateral is still additive information even in fallback mode.
|
|
839
|
+
collateral = mpaBackedCollateral;
|
|
840
|
+
}
|
|
841
|
+
if (collateralFromApi && mpaBackedCollateral > 0n && mpaBackedCollateral !== collateral) {
|
|
842
|
+
warnings.push(`total_in_collateral (${formatUnits(collateral, core.precision)}) and the sum of per-MPA `
|
|
843
|
+
+ `total_backing_collateral (${formatUnits(mpaBackedCollateral, core.precision)}) disagree.`);
|
|
844
|
+
}
|
|
845
|
+
// ---- Collateral bids (only meaningful after a global settlement) --------
|
|
846
|
+
let bidCount = 0;
|
|
847
|
+
let bidTotal = 0n;
|
|
848
|
+
for (const mpa of globallySettled) {
|
|
849
|
+
let start = 0;
|
|
850
|
+
for (let page = 0; page < 100; page++) {
|
|
851
|
+
let rows;
|
|
852
|
+
try {
|
|
853
|
+
rows = await callDb(session, 'get_collateral_bids', [mpa.id, 100, start]);
|
|
854
|
+
}
|
|
855
|
+
catch {
|
|
856
|
+
break;
|
|
857
|
+
}
|
|
858
|
+
if (!Array.isArray(rows) || rows.length === 0)
|
|
859
|
+
break;
|
|
860
|
+
for (const row of rows) {
|
|
861
|
+
if (row.inv_swan_price?.base?.asset_id !== coreId)
|
|
862
|
+
continue;
|
|
863
|
+
bidCount++;
|
|
864
|
+
bidTotal += amountOf(row.inv_swan_price.base);
|
|
865
|
+
}
|
|
866
|
+
start += rows.length;
|
|
867
|
+
if (rows.length < 100)
|
|
868
|
+
break;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
// ---- Tickets (voting / governance locks) --------------------------------
|
|
872
|
+
progress(showProgress, 'listing governance tickets ...');
|
|
873
|
+
const ticketLimit = Math.max(1, Math.min(session.config.api_limit_get_tickets ?? 100, 1000));
|
|
874
|
+
const tickets = await listPages(session, 'list_tickets', ticketLimit);
|
|
875
|
+
let ticketTotal = 0n;
|
|
876
|
+
const ticketByType = new Map();
|
|
877
|
+
const ticketByStatus = new Map();
|
|
878
|
+
const ticketByAccount = new Map();
|
|
879
|
+
let ticketCount = 0;
|
|
880
|
+
for (const ticket of tickets) {
|
|
881
|
+
if (ticket.amount?.asset_id !== coreId)
|
|
882
|
+
continue;
|
|
883
|
+
ticketCount++;
|
|
884
|
+
const value = amountOf(ticket.amount);
|
|
885
|
+
ticketTotal += value;
|
|
886
|
+
const typeKey = ticket.current_type || 'unknown';
|
|
887
|
+
const typeRow = ticketByType.get(typeKey) ?? { type: typeKey, amount: 0n, count: 0 };
|
|
888
|
+
typeRow.amount += value;
|
|
889
|
+
typeRow.count++;
|
|
890
|
+
ticketByType.set(typeKey, typeRow);
|
|
891
|
+
const statusRow = ticketByStatus.get(ticket.status) ?? { type: ticket.status || 'unknown', amount: 0n, count: 0 };
|
|
892
|
+
statusRow.amount += value;
|
|
893
|
+
statusRow.count++;
|
|
894
|
+
ticketByStatus.set(ticket.status, statusRow);
|
|
895
|
+
ticketByAccount.set(ticket.account, (ticketByAccount.get(ticket.account) ?? 0n) + value);
|
|
896
|
+
}
|
|
897
|
+
const ticketTop = [...ticketByAccount.entries()]
|
|
898
|
+
.map(([id, amount]) => ({ id, amount }))
|
|
899
|
+
.sort((a, b) => compareDesc(a.amount, b.amount))
|
|
900
|
+
.slice(0, opts.detail);
|
|
901
|
+
// ---- Vesting balances (1.13.x) ------------------------------------------
|
|
902
|
+
progress(showProgress, 'scanning vesting balances (1.13.x) ...');
|
|
903
|
+
const vestingScan = await scanIdRange(session, '1.13', opts.vestingMax, opts.gap, (n) => progress(showProgress, `scanning vesting balances (1.13.x) ... ${n}`));
|
|
904
|
+
let vestingTotal = 0n;
|
|
905
|
+
const vestingByType = new Map();
|
|
906
|
+
const vestingByOwner = new Map();
|
|
907
|
+
let vestingCount = 0;
|
|
908
|
+
for (const vesting of vestingScan.objects) {
|
|
909
|
+
if (vesting.balance?.asset_id !== coreId)
|
|
910
|
+
continue;
|
|
911
|
+
vestingCount++;
|
|
912
|
+
const value = amountOf(vesting.balance);
|
|
913
|
+
vestingTotal += value;
|
|
914
|
+
const typeKey = vesting.balance_type || 'unspecified';
|
|
915
|
+
const row = vestingByType.get(typeKey) ?? { type: typeKey, amount: 0n, count: 0 };
|
|
916
|
+
row.amount += value;
|
|
917
|
+
row.count++;
|
|
918
|
+
vestingByType.set(typeKey, row);
|
|
919
|
+
vestingByOwner.set(vesting.owner, (vestingByOwner.get(vesting.owner) ?? 0n) + value);
|
|
920
|
+
}
|
|
921
|
+
const vestingTop = [...vestingByOwner.entries()]
|
|
922
|
+
.map(([id, amount]) => ({ id, amount }))
|
|
923
|
+
.sort((a, b) => compareDesc(a.amount, b.amount))
|
|
924
|
+
.slice(0, opts.detail);
|
|
925
|
+
// ---- Legacy 1.15.x balance objects --------------------------------------
|
|
926
|
+
progress(showProgress, 'scanning legacy balances (1.15.x) ...');
|
|
927
|
+
const genesisScan = await scanIdRange(session, '1.15', 200_000, opts.gap);
|
|
928
|
+
if (genesisScan.hitLimit) {
|
|
929
|
+
warnings.push('Legacy 1.15.x scan hit its 200,000-id probe limit; the legacy bucket may be incomplete.');
|
|
930
|
+
}
|
|
931
|
+
let genesisTotal = 0n;
|
|
932
|
+
let genesisCount = 0;
|
|
933
|
+
let genesisVesting = 0;
|
|
934
|
+
let genesisClaimable = 0;
|
|
935
|
+
for (const balance of genesisScan.objects) {
|
|
936
|
+
if (balance.balance?.asset_id !== coreId)
|
|
937
|
+
continue;
|
|
938
|
+
genesisCount++;
|
|
939
|
+
genesisTotal += amountOf(balance.balance);
|
|
940
|
+
if (balance.vesting_policy)
|
|
941
|
+
genesisVesting++;
|
|
942
|
+
else
|
|
943
|
+
genesisClaimable++;
|
|
944
|
+
}
|
|
945
|
+
// ---- Liquidity pools (1.19.x) -------------------------------------------
|
|
946
|
+
progress(showProgress, 'listing liquidity pools ...');
|
|
947
|
+
const poolLimit = Math.max(1, Math.min(session.config.api_limit_get_liquidity_pools ?? 100, 1000));
|
|
948
|
+
const pools = await listPages(session, 'list_liquidity_pools', poolLimit);
|
|
949
|
+
let poolTotal = 0n;
|
|
950
|
+
let poolsWithBts = 0;
|
|
951
|
+
const poolRows = [];
|
|
952
|
+
for (const pool of pools) {
|
|
953
|
+
let bts = 0n;
|
|
954
|
+
if (pool.asset_a === coreId)
|
|
955
|
+
bts += toBig(pool.balance_a);
|
|
956
|
+
if (pool.asset_b === coreId)
|
|
957
|
+
bts += toBig(pool.balance_b);
|
|
958
|
+
if (bts <= 0n)
|
|
959
|
+
continue;
|
|
960
|
+
poolsWithBts++;
|
|
961
|
+
poolTotal += bts;
|
|
962
|
+
poolRows.push({
|
|
963
|
+
id: pool.id,
|
|
964
|
+
pair: `${symbolOf(pool.asset_a)} / ${symbolOf(pool.asset_b)}`,
|
|
965
|
+
bts,
|
|
966
|
+
});
|
|
967
|
+
}
|
|
968
|
+
poolRows.sort((a, b) => compareDesc(a.bts, b.bts));
|
|
969
|
+
// ---- SameT funds (1.20.x) -----------------------------------------------
|
|
970
|
+
progress(showProgress, 'listing SameT funds ...');
|
|
971
|
+
const sametLimit = Math.max(1, Math.min(session.config.api_limit_get_samet_funds ?? 100, 1000));
|
|
972
|
+
const sametFunds = await listPages(session, 'list_samet_funds', sametLimit);
|
|
973
|
+
let sametTotal = 0n;
|
|
974
|
+
let sametBtsCount = 0;
|
|
975
|
+
const sametRows = [];
|
|
976
|
+
for (const fund of sametFunds) {
|
|
977
|
+
if (fund.asset_type !== coreId)
|
|
978
|
+
continue;
|
|
979
|
+
sametBtsCount++;
|
|
980
|
+
const value = toBig(fund.balance);
|
|
981
|
+
sametTotal += value;
|
|
982
|
+
sametRows.push({ id: fund.id, owner: fund.owner_account, amount: value });
|
|
983
|
+
}
|
|
984
|
+
sametRows.sort((a, b) => compareDesc(a.amount, b.amount));
|
|
985
|
+
// ---- Credit offers / deals (1.21.x / 1.22.x) ----------------------------
|
|
986
|
+
progress(showProgress, 'listing credit offers and deals ...');
|
|
987
|
+
const creditLimit = Math.max(1, Math.min(session.config.api_limit_get_credit_offers ?? 100, 1000));
|
|
988
|
+
const offers = await listPages(session, 'list_credit_offers', creditLimit);
|
|
989
|
+
let offerTotal = 0n;
|
|
990
|
+
let btsOfferCount = 0;
|
|
991
|
+
for (const offer of offers) {
|
|
992
|
+
if (offer.asset_type !== coreId)
|
|
993
|
+
continue;
|
|
994
|
+
btsOfferCount++;
|
|
995
|
+
offerTotal += toBig(offer.current_balance);
|
|
996
|
+
}
|
|
997
|
+
const deals = await listPages(session, 'list_credit_deals', creditLimit);
|
|
998
|
+
let dealTotal = 0n;
|
|
999
|
+
let btsDealCount = 0;
|
|
1000
|
+
for (const deal of deals) {
|
|
1001
|
+
if (deal.collateral_asset !== coreId)
|
|
1002
|
+
continue;
|
|
1003
|
+
btsDealCount++;
|
|
1004
|
+
dealTotal += toBig(deal.collateral_amount);
|
|
1005
|
+
}
|
|
1006
|
+
// ---- HTLC escrow (1.16.x) -----------------------------------------------
|
|
1007
|
+
progress(showProgress, 'listing HTLCs ...');
|
|
1008
|
+
let htlcTotal = 0n;
|
|
1009
|
+
let htlcCount = 0;
|
|
1010
|
+
for (let index = 0; index < 100_000; index += OBJECT_BATCH) {
|
|
1011
|
+
const ids = Array.from({ length: OBJECT_BATCH }, (_, i) => `1.16.${index + i}`);
|
|
1012
|
+
const rows = await fetchObjects(session, ids);
|
|
1013
|
+
const live = rows.filter((r) => !!r);
|
|
1014
|
+
for (const row of live) {
|
|
1015
|
+
htlcCount++;
|
|
1016
|
+
if (row.transfer?.asset_id === coreId)
|
|
1017
|
+
htlcTotal += toBig(row.transfer.amount);
|
|
1018
|
+
}
|
|
1019
|
+
if (live.length === 0)
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
// ---- Build buckets ------------------------------------------------------
|
|
1023
|
+
const named = (id, fallback) => {
|
|
1024
|
+
const name = symbolOf(id);
|
|
1025
|
+
return name === id ? fallback : name;
|
|
1026
|
+
};
|
|
1027
|
+
const buckets = [
|
|
1028
|
+
{
|
|
1029
|
+
key: 'collateral',
|
|
1030
|
+
label: 'Call-order collateral (MPAs)',
|
|
1031
|
+
amount: collateral,
|
|
1032
|
+
color: COLORS[0],
|
|
1033
|
+
note: `${btsBackedMpas.length} BTS-backed smart assets`,
|
|
1034
|
+
},
|
|
1035
|
+
{
|
|
1036
|
+
key: 'settlementFund',
|
|
1037
|
+
label: 'Global settlement fund',
|
|
1038
|
+
amount: settlementFund,
|
|
1039
|
+
color: COLORS[1],
|
|
1040
|
+
note: 'Collateral collected when an MPA globally settles',
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
key: 'individualSettlementFund',
|
|
1044
|
+
label: 'Individual settlement fund',
|
|
1045
|
+
amount: individualSettlementFund,
|
|
1046
|
+
color: COLORS[2],
|
|
1047
|
+
note: 'Per-order settlement pools (BSIP-74 / individual settlement)',
|
|
1048
|
+
},
|
|
1049
|
+
{
|
|
1050
|
+
key: 'collateralBids',
|
|
1051
|
+
label: 'Collateral bids (post-settlement)',
|
|
1052
|
+
amount: bidTotal,
|
|
1053
|
+
color: COLORS[3],
|
|
1054
|
+
note: `${bidCount} bid(s) for debt after global settlement`,
|
|
1055
|
+
},
|
|
1056
|
+
{
|
|
1057
|
+
key: 'tickets',
|
|
1058
|
+
label: 'Governance tickets (voting locks)',
|
|
1059
|
+
amount: ticketTotal,
|
|
1060
|
+
color: COLORS[4],
|
|
1061
|
+
note: `${ticketCount} ticket(s): lock_forever / lock_N_days`,
|
|
1062
|
+
},
|
|
1063
|
+
{
|
|
1064
|
+
key: 'vesting',
|
|
1065
|
+
label: 'Vesting balances',
|
|
1066
|
+
amount: vestingTotal,
|
|
1067
|
+
color: COLORS[5],
|
|
1068
|
+
note: `${vestingCount} vesting balance(s): witness / worker / cashback`,
|
|
1069
|
+
},
|
|
1070
|
+
{
|
|
1071
|
+
key: 'genesis',
|
|
1072
|
+
label: 'Legacy balances (1.15.x)',
|
|
1073
|
+
amount: genesisTotal,
|
|
1074
|
+
color: COLORS[6],
|
|
1075
|
+
note: `${genesisCount} claimable balance object(s) from the 2.0 migration`,
|
|
1076
|
+
},
|
|
1077
|
+
{
|
|
1078
|
+
key: 'liquidityPools',
|
|
1079
|
+
label: 'Liquidity pools',
|
|
1080
|
+
amount: poolTotal,
|
|
1081
|
+
color: COLORS[7],
|
|
1082
|
+
note: `${poolsWithBts} of ${pools.length} pools hold ${named(coreId, CORE_SYMBOL)}`,
|
|
1083
|
+
},
|
|
1084
|
+
{
|
|
1085
|
+
key: 'sametFunds',
|
|
1086
|
+
label: 'SameT funds',
|
|
1087
|
+
amount: sametTotal,
|
|
1088
|
+
color: COLORS[8],
|
|
1089
|
+
note: `${sametBtsCount} fund(s) denominated in ${named(coreId, CORE_SYMBOL)}`,
|
|
1090
|
+
},
|
|
1091
|
+
{
|
|
1092
|
+
key: 'creditOffers',
|
|
1093
|
+
label: 'Credit offer funds',
|
|
1094
|
+
amount: offerTotal,
|
|
1095
|
+
color: COLORS[9],
|
|
1096
|
+
note: `${btsOfferCount} offer(s) with ${named(coreId, CORE_SYMBOL)} available`,
|
|
1097
|
+
},
|
|
1098
|
+
{
|
|
1099
|
+
key: 'creditCollateral',
|
|
1100
|
+
label: 'Credit-deal collateral',
|
|
1101
|
+
amount: dealTotal,
|
|
1102
|
+
color: COLORS[10],
|
|
1103
|
+
note: `${btsDealCount} active deal(s) collateralised in ${named(coreId, CORE_SYMBOL)}`,
|
|
1104
|
+
},
|
|
1105
|
+
{
|
|
1106
|
+
key: 'htlc',
|
|
1107
|
+
label: 'HTLC escrow',
|
|
1108
|
+
amount: htlcTotal,
|
|
1109
|
+
color: COLORS[11],
|
|
1110
|
+
note: `${htlcCount} hash/time-locked contract(s)`,
|
|
1111
|
+
},
|
|
1112
|
+
{
|
|
1113
|
+
key: 'feePools',
|
|
1114
|
+
label: 'Asset fee pools',
|
|
1115
|
+
amount: feePoolTotal,
|
|
1116
|
+
color: COLORS[12],
|
|
1117
|
+
note: 'fee_pool of every asset is denominated in core BTS',
|
|
1118
|
+
},
|
|
1119
|
+
];
|
|
1120
|
+
const identified = sum(buckets.map((b) => b.amount));
|
|
1121
|
+
let residual = currentSupply - identified;
|
|
1122
|
+
if (residual < 0n) {
|
|
1123
|
+
warnings.push(`Identified holdings (${formatUnits(identified, core.precision)}) exceed current supply `
|
|
1124
|
+
+ `(${formatUnits(currentSupply, core.precision)}); residual clamped to 0.`);
|
|
1125
|
+
residual = 0n;
|
|
1126
|
+
}
|
|
1127
|
+
if (confidentialSupply > residual) {
|
|
1128
|
+
warnings.push('Blinded supply is larger than the computed residual; check node data.');
|
|
1129
|
+
}
|
|
1130
|
+
// ---- Circulating float comparison --------------------------------------
|
|
1131
|
+
// BitShares only exposes current_supply (coins in existence); there is no
|
|
1132
|
+
// protocol-level "circulating" field. We derive it by removing everything
|
|
1133
|
+
// this report could identify as protocol-held or dormant.
|
|
1134
|
+
const circulatingDerived = residual;
|
|
1135
|
+
const circulatingIncludingLegacy = residual + genesisTotal;
|
|
1136
|
+
const reference = opts.circulating
|
|
1137
|
+
? parseUnits(opts.circulating, core.precision)
|
|
1138
|
+
: null;
|
|
1139
|
+
const lockedPerCirculating = circulatingDerived > 0n
|
|
1140
|
+
? Number((identified * 10000n) / circulatingDerived) / 10_000
|
|
1141
|
+
: 0;
|
|
1142
|
+
for (const bucket of buckets) {
|
|
1143
|
+
bucket.shareOfSupply = sharePercent(bucket.amount, currentSupply);
|
|
1144
|
+
bucket.shareOfCirculating = sharePercent(bucket.amount, circulatingDerived);
|
|
1145
|
+
}
|
|
1146
|
+
// ---- Top liquid holders (rich list via asset_api) ----------------------
|
|
1147
|
+
progress(showProgress, 'fetching the liquid rich list (asset_api) ...');
|
|
1148
|
+
let holderSession = session;
|
|
1149
|
+
let closeHolderSession = false;
|
|
1150
|
+
if (session.assetApi === null) {
|
|
1151
|
+
holderSession = await openAssetApiSession([session.node]);
|
|
1152
|
+
closeHolderSession = true;
|
|
1153
|
+
}
|
|
1154
|
+
let holderSource = null;
|
|
1155
|
+
let holderCount = 0;
|
|
1156
|
+
let holderTotalCount = null;
|
|
1157
|
+
let holderTotal = 0n;
|
|
1158
|
+
let holderComplete = false;
|
|
1159
|
+
let holderAmounts = [];
|
|
1160
|
+
const holderTop = [];
|
|
1161
|
+
const exchangeAgg = new Map();
|
|
1162
|
+
const concentration = [];
|
|
1163
|
+
const histogram = [];
|
|
1164
|
+
let holderMedian = null;
|
|
1165
|
+
let holderMean = null;
|
|
1166
|
+
if (holderSession?.assetApi !== null && holderSession?.assetApi !== undefined) {
|
|
1167
|
+
holderSource = holderSession.node;
|
|
1168
|
+
try {
|
|
1169
|
+
const fetched = await fetchAssetHolders(holderSession, coreId, opts.holders, (n) => progress(showProgress, `fetching the rich list ... ${formatInteger(BigInt(n))} accounts`));
|
|
1170
|
+
holderCount = fetched.rows.length;
|
|
1171
|
+
holderTotalCount = fetched.totalCount;
|
|
1172
|
+
holderComplete = fetched.complete;
|
|
1173
|
+
fetched.rows.forEach((holder, index) => {
|
|
1174
|
+
const amount = toBig(holder.amount);
|
|
1175
|
+
const exchange = detectExchange(holder.name);
|
|
1176
|
+
holderTotal += amount;
|
|
1177
|
+
holderAmounts.push(amount);
|
|
1178
|
+
if (exchange) {
|
|
1179
|
+
const agg = exchangeAgg.get(exchange) ?? { label: exchange, amount: 0n, count: 0 };
|
|
1180
|
+
agg.amount += amount;
|
|
1181
|
+
agg.count++;
|
|
1182
|
+
exchangeAgg.set(exchange, agg);
|
|
1183
|
+
}
|
|
1184
|
+
if (index < opts.detail) {
|
|
1185
|
+
holderTop.push({
|
|
1186
|
+
rank: index + 1,
|
|
1187
|
+
id: holder.account_id,
|
|
1188
|
+
name: holder.name,
|
|
1189
|
+
amount,
|
|
1190
|
+
exchange,
|
|
1191
|
+
});
|
|
1192
|
+
}
|
|
1193
|
+
});
|
|
1194
|
+
// Holders arrive balance-descending, but sort defensively before
|
|
1195
|
+
// publishing concentration numbers.
|
|
1196
|
+
holderAmounts = [...holderAmounts].sort((a, b) => compareDesc(a, b));
|
|
1197
|
+
for (const top of [10, 100, 1000, 10000]) {
|
|
1198
|
+
if (holderAmounts.length < top)
|
|
1199
|
+
continue;
|
|
1200
|
+
concentration.push({ top, count: top, amount: sum(holderAmounts.slice(0, top)) });
|
|
1201
|
+
}
|
|
1202
|
+
if (holderComplete && holderAmounts.length > 0) {
|
|
1203
|
+
const unit = 10n ** BigInt(core.precision ?? 5);
|
|
1204
|
+
const specs = [
|
|
1205
|
+
['< 0.001 BTS', 0n, unit / 1000n],
|
|
1206
|
+
['0.001 – 0.01 BTS', unit / 1000n, unit / 100n],
|
|
1207
|
+
['0.01 – 0.1 BTS', unit / 100n, unit / 10n],
|
|
1208
|
+
['0.1 – 1 BTS', unit / 10n, unit],
|
|
1209
|
+
['1 – 10 BTS', unit, 10n * unit],
|
|
1210
|
+
['10 – 100 BTS', 10n * unit, 100n * unit],
|
|
1211
|
+
['100 – 1,000 BTS', 100n * unit, 1000n * unit],
|
|
1212
|
+
['1,000 – 1,000,000 BTS', 1000n * unit, 1000000n * unit],
|
|
1213
|
+
['≥ 1,000,000 BTS', 1000000n * unit, null],
|
|
1214
|
+
];
|
|
1215
|
+
for (const [label, low, high] of specs) {
|
|
1216
|
+
let count = 0;
|
|
1217
|
+
let amount = 0n;
|
|
1218
|
+
for (const value of holderAmounts) {
|
|
1219
|
+
if (value < low)
|
|
1220
|
+
continue;
|
|
1221
|
+
if (high !== null && value >= high)
|
|
1222
|
+
continue;
|
|
1223
|
+
count++;
|
|
1224
|
+
amount += value;
|
|
1225
|
+
}
|
|
1226
|
+
if (count > 0)
|
|
1227
|
+
histogram.push({ label, count, amount });
|
|
1228
|
+
}
|
|
1229
|
+
const ascending = [...holderAmounts].sort((a, b) => (a < b ? -1 : a > b ? 1 : 0));
|
|
1230
|
+
holderMedian = ascending[Math.floor(ascending.length / 2)];
|
|
1231
|
+
holderMean = holderTotal / BigInt(holderAmounts.length);
|
|
1232
|
+
}
|
|
1233
|
+
}
|
|
1234
|
+
catch (e) {
|
|
1235
|
+
warnings.push(`Top liquid holders unavailable: ${e.message}`);
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
else {
|
|
1239
|
+
warnings.push('No reachable node exposes asset_api::get_asset_holders; top liquid holders unavailable.');
|
|
1240
|
+
}
|
|
1241
|
+
if (closeHolderSession)
|
|
1242
|
+
holderSession?.client.close();
|
|
1243
|
+
const untrackedLiquid = holderComplete ? residual - holderTotal : null;
|
|
1244
|
+
const orderBookAndOther = holderComplete
|
|
1245
|
+
? residual - holderTotal - confidentialSupply
|
|
1246
|
+
: null;
|
|
1247
|
+
if (orderBookAndOther !== null && orderBookAndOther < 0n) {
|
|
1248
|
+
warnings.push('Account balances plus blinded supply exceed the derived residual; check node data.');
|
|
1249
|
+
}
|
|
1250
|
+
// ---- Resolve human names for top holders -------------------------------
|
|
1251
|
+
const nameMap = await resolveAccountNames(session, [
|
|
1252
|
+
...ticketTop.map((r) => r.id),
|
|
1253
|
+
...vestingTop.map((r) => r.id),
|
|
1254
|
+
...sametRows.slice(0, opts.detail).map((r) => r.owner),
|
|
1255
|
+
]);
|
|
1256
|
+
for (const row of ticketTop) {
|
|
1257
|
+
row.name = nameMap.get(row.id);
|
|
1258
|
+
row.exchange = detectExchange(row.name);
|
|
1259
|
+
}
|
|
1260
|
+
for (const row of vestingTop) {
|
|
1261
|
+
row.name = nameMap.get(row.id);
|
|
1262
|
+
row.exchange = detectExchange(row.name);
|
|
1263
|
+
}
|
|
1264
|
+
for (const row of sametRows) {
|
|
1265
|
+
row.name = nameMap.get(row.owner);
|
|
1266
|
+
row.exchange = detectExchange(row.name);
|
|
1267
|
+
}
|
|
1268
|
+
clearProgress(showProgress);
|
|
1269
|
+
return {
|
|
1270
|
+
node: session.node,
|
|
1271
|
+
blockNum: global.head_block_number,
|
|
1272
|
+
blockTime: global.time,
|
|
1273
|
+
generatedAt,
|
|
1274
|
+
asset: {
|
|
1275
|
+
id: coreId,
|
|
1276
|
+
symbol: core.symbol || CORE_SYMBOL,
|
|
1277
|
+
precision: core.precision ?? 5,
|
|
1278
|
+
maxSupply: core.options?.max_supply ? toBig(core.options.max_supply) : null,
|
|
1279
|
+
},
|
|
1280
|
+
supply: { current: currentSupply, confidential: confidentialSupply },
|
|
1281
|
+
buckets,
|
|
1282
|
+
identified,
|
|
1283
|
+
residual,
|
|
1284
|
+
circulating: {
|
|
1285
|
+
derived: circulatingDerived,
|
|
1286
|
+
includingLegacy: circulatingIncludingLegacy,
|
|
1287
|
+
reference,
|
|
1288
|
+
lockedPerCirculating,
|
|
1289
|
+
},
|
|
1290
|
+
details: {
|
|
1291
|
+
assetCount: assets.length,
|
|
1292
|
+
mpaCount: btsBackedMpas.length,
|
|
1293
|
+
mpaBackedCollateral,
|
|
1294
|
+
collateralFromApi,
|
|
1295
|
+
collateralTruncated,
|
|
1296
|
+
mpas: mpaRows.slice(0, opts.detail),
|
|
1297
|
+
settlementCount: settlementRows.length,
|
|
1298
|
+
settlements: settlementRows.slice(0, Math.max(opts.detail, 10)),
|
|
1299
|
+
collateralBids: { count: bidCount, total: bidTotal },
|
|
1300
|
+
tickets: {
|
|
1301
|
+
count: ticketCount,
|
|
1302
|
+
total: ticketTotal,
|
|
1303
|
+
byType: [...ticketByType.values()].sort((a, b) => compareDesc(a.amount, b.amount)),
|
|
1304
|
+
byStatus: [...ticketByStatus.values()].sort((a, b) => compareDesc(a.amount, b.amount)),
|
|
1305
|
+
top: ticketTop,
|
|
1306
|
+
},
|
|
1307
|
+
vesting: {
|
|
1308
|
+
count: vestingCount,
|
|
1309
|
+
total: vestingTotal,
|
|
1310
|
+
byType: [...vestingByType.values()].sort((a, b) => compareDesc(a.amount, b.amount)),
|
|
1311
|
+
top: vestingTop,
|
|
1312
|
+
scannedTo: vestingScan.scannedTo,
|
|
1313
|
+
hitLimit: vestingScan.hitLimit,
|
|
1314
|
+
},
|
|
1315
|
+
genesis: { count: genesisCount, total: genesisTotal, vestingCount: genesisVesting, claimableCount: genesisClaimable },
|
|
1316
|
+
pools: { count: pools.length, withBts: poolsWithBts, total: poolTotal, top: poolRows.slice(0, opts.detail) },
|
|
1317
|
+
samet: { count: sametFunds.length, total: sametTotal, btsCount: sametBtsCount, top: sametRows.slice(0, opts.detail) },
|
|
1318
|
+
credit: {
|
|
1319
|
+
offerCount: offers.length,
|
|
1320
|
+
btsOfferCount,
|
|
1321
|
+
offerTotal,
|
|
1322
|
+
dealCount: deals.length,
|
|
1323
|
+
btsDealCount,
|
|
1324
|
+
dealTotal,
|
|
1325
|
+
},
|
|
1326
|
+
htlcs: { count: htlcCount, total: htlcTotal },
|
|
1327
|
+
feePools: { total: feePoolTotal, top: feePoolRows.slice(0, opts.detail) },
|
|
1328
|
+
holders: {
|
|
1329
|
+
sourceNode: holderSource,
|
|
1330
|
+
count: holderCount,
|
|
1331
|
+
totalCount: holderTotalCount,
|
|
1332
|
+
total: holderTotal,
|
|
1333
|
+
complete: holderComplete,
|
|
1334
|
+
untrackedLiquid,
|
|
1335
|
+
orderBookAndOther,
|
|
1336
|
+
median: holderMedian,
|
|
1337
|
+
mean: holderMean,
|
|
1338
|
+
top: holderTop,
|
|
1339
|
+
exchanges: [...exchangeAgg.values()].sort((a, b) => compareDesc(a.amount, b.amount)),
|
|
1340
|
+
concentration,
|
|
1341
|
+
histogram,
|
|
1342
|
+
},
|
|
1343
|
+
warnings,
|
|
1344
|
+
},
|
|
1345
|
+
};
|
|
1346
|
+
}
|
|
1347
|
+
// ---------------------------------------------------------------------------
|
|
1348
|
+
// Terminal rendering
|
|
1349
|
+
// ---------------------------------------------------------------------------
|
|
1350
|
+
function bar(value, whole, width = 26) {
|
|
1351
|
+
if (whole <= 0n)
|
|
1352
|
+
return '';
|
|
1353
|
+
const filled = Math.round(shareFraction(value, whole) * width);
|
|
1354
|
+
if (filled <= 0)
|
|
1355
|
+
return '·';
|
|
1356
|
+
return '█'.repeat(Math.min(filled, width));
|
|
1357
|
+
}
|
|
1358
|
+
function padEnd(text, width) {
|
|
1359
|
+
return text.length >= width ? text : text + ' '.repeat(width - text.length);
|
|
1360
|
+
}
|
|
1361
|
+
function padStart(text, width) {
|
|
1362
|
+
return text.length >= width ? text : ' '.repeat(width - text.length) + text;
|
|
1363
|
+
}
|
|
1364
|
+
function renderTerminal(report, opts) {
|
|
1365
|
+
const useColor = !!process.stdout.isTTY && !process.env.NO_COLOR;
|
|
1366
|
+
const c = (code, text) => (useColor ? `${code}${text}${colors.reset}` : text);
|
|
1367
|
+
const p = report.asset.precision;
|
|
1368
|
+
const money = (v) => formatUnits(v, p);
|
|
1369
|
+
const supply = report.supply.current;
|
|
1370
|
+
const labelWidth = Math.min(46, report.buckets.reduce((m, b) => Math.max(m, b.label.length), 0) + 2);
|
|
1371
|
+
const amountWidth = 22;
|
|
1372
|
+
const pctWidth = 8;
|
|
1373
|
+
console.log();
|
|
1374
|
+
console.log(c(colors.bold + colors.yellow, ' BitShares · BTS supply distribution'));
|
|
1375
|
+
console.log(c(colors.gray, ` block ${formatInteger(BigInt(report.blockNum))} · ${report.blockTime} UTC · ${report.node}`));
|
|
1376
|
+
console.log(c(colors.gray, ` ${report.asset.symbol} (${report.asset.id}) · precision ${p} · total supply ${money(supply)}`
|
|
1377
|
+
+ (report.asset.maxSupply ? ` · max ${money(report.asset.maxSupply)}` : '')));
|
|
1378
|
+
console.log();
|
|
1379
|
+
const maxBucket = report.buckets.reduce((m, b) => (b.amount > m ? b.amount : m), 0n);
|
|
1380
|
+
const header = ` ${padEnd('CATEGORY', labelWidth)} ${padStart('BTS', amountWidth)} ${padStart('SHARE', pctWidth)}`;
|
|
1381
|
+
console.log(c(colors.bold, header));
|
|
1382
|
+
console.log(c(colors.gray, ` ${'─'.repeat(labelWidth + amountWidth + pctWidth + 2)}`));
|
|
1383
|
+
for (const bucket of report.buckets) {
|
|
1384
|
+
if (bucket.amount === 0n)
|
|
1385
|
+
continue;
|
|
1386
|
+
const pct = sharePercent(bucket.amount, supply);
|
|
1387
|
+
const label = padEnd(bucket.label.slice(0, labelWidth - 2), labelWidth);
|
|
1388
|
+
const line = ` ${c(colors.cyan, label)} ${padStart(money(bucket.amount), amountWidth)} `
|
|
1389
|
+
+ `${c(colors.spread, padStart(pct, pctWidth))} ${c(colors.gray, '▕')}`
|
|
1390
|
+
+ c(colors.blue, bar(bucket.amount, maxBucket)) + c(colors.gray, '▏');
|
|
1391
|
+
console.log(line);
|
|
1392
|
+
}
|
|
1393
|
+
console.log(c(colors.gray, ` ${'─'.repeat(labelWidth + amountWidth + pctWidth + 2)}`));
|
|
1394
|
+
console.log(` ${c(colors.bold, padEnd('Identified / dormant', labelWidth))} `
|
|
1395
|
+
+ `${c(colors.bold, padStart(money(report.identified), amountWidth))} `
|
|
1396
|
+
+ `${c(colors.bold + colors.spread, padStart(sharePercent(report.identified, supply), pctWidth))}`);
|
|
1397
|
+
console.log(` ${c(colors.bold, padEnd('Liquid residual', labelWidth))} `
|
|
1398
|
+
+ `${c(colors.bold, padStart(money(report.residual), amountWidth))} `
|
|
1399
|
+
+ `${c(colors.bold + colors.spread, padStart(sharePercent(report.residual, supply), pctWidth))}`
|
|
1400
|
+
+ c(colors.gray, ' accounts · order books · blinded'));
|
|
1401
|
+
console.log(c(colors.gray, ` of which blinded balances: ${money(report.supply.confidential)} `
|
|
1402
|
+
+ `(${sharePercent(report.supply.confidential, supply)}) — part of the residual, not additive`));
|
|
1403
|
+
console.log(c(colors.gray, ` bars are scaled to the largest bucket; check the reconcile: `
|
|
1404
|
+
+ `${money(report.identified + report.residual)} = supply`));
|
|
1405
|
+
// ---- Detail sections ----------------------------------------------------
|
|
1406
|
+
const section = (title) => {
|
|
1407
|
+
console.log();
|
|
1408
|
+
console.log(c(colors.bold + colors.yellow, ` ── ${title} ${'─'.repeat(Math.max(0, 66 - title.length))}`));
|
|
1409
|
+
};
|
|
1410
|
+
section(`Settlement pools (${report.details.mpaCount} BTS-backed MPAs)`);
|
|
1411
|
+
console.log(c(colors.gray, ' Global: ' + money(report.buckets.find((b) => b.key === 'settlementFund')?.amount ?? 0n))
|
|
1412
|
+
+ c(colors.gray, ' · Individual: ')
|
|
1413
|
+
+ c(colors.white, money(report.buckets.find((b) => b.key === 'individualSettlementFund')?.amount ?? 0n)));
|
|
1414
|
+
printMpaTable(report, opts.detail, money, c);
|
|
1415
|
+
printSettlementTable(report, money, c);
|
|
1416
|
+
section('Governance tickets by lock type');
|
|
1417
|
+
printTypeTable(report.details.tickets.byType, supply, money, c);
|
|
1418
|
+
section('Vesting balances by balance type');
|
|
1419
|
+
printTypeTable(report.details.vesting.byType, supply, money, c);
|
|
1420
|
+
if (report.details.vesting.hitLimit) {
|
|
1421
|
+
console.log(c(colors.sell, ` warning: vesting scan reached --vesting-max ${opts.vestingMax}; totals may be incomplete`));
|
|
1422
|
+
}
|
|
1423
|
+
section('Top governance ticket holders');
|
|
1424
|
+
printHolderTable(report.details.tickets.top, money, c);
|
|
1425
|
+
section('Top vesting balance owners');
|
|
1426
|
+
printHolderTable(report.details.vesting.top, money, c);
|
|
1427
|
+
section('Liquidity pools with BTS');
|
|
1428
|
+
printPoolTable(report, opts.detail, money, c);
|
|
1429
|
+
section(`Top liquid holders (rich list, ${report.details.holders.count} fetched)`);
|
|
1430
|
+
const holders = report.details.holders;
|
|
1431
|
+
if (holders.top.length === 0) {
|
|
1432
|
+
console.log(c(colors.gray, ' (asset_api unavailable — no holder data)'));
|
|
1433
|
+
}
|
|
1434
|
+
else {
|
|
1435
|
+
console.log(c(colors.gray, ` ${holders.complete ? `${holders.count} account balances` : `top ${holders.count} account balances`} = `
|
|
1436
|
+
+ `${money(holders.total)} BTS `
|
|
1437
|
+
+ `(${sharePercent(holders.total, supply)} of supply, `
|
|
1438
|
+
+ `${sharePercent(holders.total, report.residual)} of the residual)`
|
|
1439
|
+
+ (holders.totalCount !== null ? ` · ${holders.totalCount} holder rows on-chain` : '')));
|
|
1440
|
+
if (holders.complete && holders.untrackedLiquid !== null && holders.orderBookAndOther !== null) {
|
|
1441
|
+
console.log(c(colors.gray, ` residual split: accounts ${money(holders.total)} `
|
|
1442
|
+
+ `(${sharePercent(holders.total, report.residual)}) · blinded ${money(report.supply.confidential)} · `
|
|
1443
|
+
+ `order books + other ${money(holders.orderBookAndOther)} `
|
|
1444
|
+
+ `(${sharePercent(holders.orderBookAndOther, report.residual)})`));
|
|
1445
|
+
}
|
|
1446
|
+
for (const row of holders.top) {
|
|
1447
|
+
const tag = row.exchange ? c(colors.spread, ` [${row.exchange}]`) : '';
|
|
1448
|
+
console.log(` #${String(row.rank ?? 0).padStart(3)} ${padEnd((row.name ?? row.id).slice(0, 30), 30)} `
|
|
1449
|
+
+ `${padStart(money(row.amount), 20)} ${padStart(sharePercent(row.amount, supply), 8)}${tag}`);
|
|
1450
|
+
}
|
|
1451
|
+
if (holders.exchanges.length > 0) {
|
|
1452
|
+
console.log(c(colors.gray, ' exchange-linked holdings in the fetched set:'));
|
|
1453
|
+
for (const agg of holders.exchanges) {
|
|
1454
|
+
console.log(` ${padEnd(agg.label.slice(0, 14), 14)} ${padStart(money(agg.amount), 18)} `
|
|
1455
|
+
+ `${padStart(sharePercent(agg.amount, supply), 8)} `
|
|
1456
|
+
+ c(colors.gray, `${agg.count} account(s)`));
|
|
1457
|
+
}
|
|
1458
|
+
}
|
|
1459
|
+
if (holders.concentration.length > 0) {
|
|
1460
|
+
console.log(c(colors.gray, ' concentration of the liquid residual:'));
|
|
1461
|
+
for (const row of holders.concentration) {
|
|
1462
|
+
console.log(` top ${String(row.top).padStart(6)} accounts ${padStart(money(row.amount), 18)} `
|
|
1463
|
+
+ `${padStart(sharePercent(row.amount, report.residual), 8)} of the residual`);
|
|
1464
|
+
}
|
|
1465
|
+
}
|
|
1466
|
+
if (holders.median !== null && holders.mean !== null) {
|
|
1467
|
+
console.log(c(colors.gray, ` median balance ${money(holders.median)} BTS · mean ${money(holders.mean)} BTS`));
|
|
1468
|
+
}
|
|
1469
|
+
if (holders.histogram.length > 0) {
|
|
1470
|
+
console.log(c(colors.gray, ' balance distribution across all holder accounts:'));
|
|
1471
|
+
for (const row of holders.histogram) {
|
|
1472
|
+
console.log(` ${padEnd(row.label, 24)} ${String(row.count).padStart(8)} accounts `
|
|
1473
|
+
+ `${padStart(money(row.amount), 18)} `
|
|
1474
|
+
+ `${padStart(sharePercent(row.amount, report.residual), 8)} of residual`);
|
|
1475
|
+
}
|
|
1476
|
+
}
|
|
1477
|
+
}
|
|
1478
|
+
section('Credit & SameT');
|
|
1479
|
+
const credit = report.details.credit;
|
|
1480
|
+
console.log(` credit offers ${padStart(money(credit.offerTotal), 20)} ${c(colors.gray, `${credit.btsOfferCount}/${credit.offerCount} offers in ${report.asset.symbol}`)}`);
|
|
1481
|
+
console.log(` credit collateral ${padStart(money(credit.dealTotal), 20)} ${c(colors.gray, `${credit.btsDealCount}/${credit.dealCount} deals collateralised in ${report.asset.symbol}`)}`);
|
|
1482
|
+
console.log(` SameT funds ${padStart(money(report.details.samet.total), 20)} ${c(colors.gray, `${report.details.samet.btsCount}/${report.details.samet.count} funds in ${report.asset.symbol}`)}`);
|
|
1483
|
+
section('Asset fee pools (held in BTS)');
|
|
1484
|
+
console.log(` total ${padStart(money(report.details.feePools.total), 20)}`);
|
|
1485
|
+
for (const row of report.details.feePools.top) {
|
|
1486
|
+
console.log(` ${padEnd(row.symbol.slice(0, 22), 22)} ${padStart(money(row.amount), 20)}`);
|
|
1487
|
+
}
|
|
1488
|
+
section('Legacy 1.15.x balances');
|
|
1489
|
+
console.log(` claimable objects ${padStart(money(report.details.genesis.total), 20)} ${c(colors.gray, `${report.details.genesis.count} object(s), ${report.details.genesis.claimableCount} without vesting policy`)}`);
|
|
1490
|
+
// ---- Final comparison against circulating supply ----------------------
|
|
1491
|
+
section('Circulating supply comparison');
|
|
1492
|
+
const circ = report.circulating;
|
|
1493
|
+
const circWidth = 24;
|
|
1494
|
+
console.log(` ${padEnd('Total supply (current_supply)', 36)} ${padStart(money(supply), circWidth)} `
|
|
1495
|
+
+ `${padStart('100.00%', pctWidth)}`);
|
|
1496
|
+
console.log(` ${padEnd('− identified / dormant', 36)} ${padStart(money(report.identified), circWidth)} `
|
|
1497
|
+
+ `${padStart(sharePercent(report.identified, supply), pctWidth)}`);
|
|
1498
|
+
console.log(` ${c(colors.bold, padEnd('= circulating float (derived)', 36))} `
|
|
1499
|
+
+ `${c(colors.bold, padStart(money(circ.derived), circWidth))} `
|
|
1500
|
+
+ `${c(colors.bold + colors.spread, padStart(sharePercent(circ.derived, supply), pctWidth))}`);
|
|
1501
|
+
console.log(c(colors.gray, ` blinded balances inside the float: ${money(report.supply.confidential)} `
|
|
1502
|
+
+ `(${sharePercent(report.supply.confidential, circ.derived)} of the float)`));
|
|
1503
|
+
console.log(c(colors.gray, ` legacy 1.15.x treated as circulating instead: ${money(circ.includingLegacy)} `
|
|
1504
|
+
+ `(${sharePercent(circ.includingLegacy, supply)} of supply)`));
|
|
1505
|
+
console.log(` ${padEnd('Locked per 1 circulating BTS', 36)} ${padStart(circ.lockedPerCirculating.toFixed(4), circWidth)}`);
|
|
1506
|
+
if (circ.reference !== null) {
|
|
1507
|
+
const delta = circ.derived - circ.reference;
|
|
1508
|
+
const relative = circ.reference > 0n
|
|
1509
|
+
? `${delta >= 0n ? '+' : ''}${(Number((delta * 10000n) / circ.reference) / 100).toFixed(2)}%`
|
|
1510
|
+
: '—';
|
|
1511
|
+
console.log(` ${padEnd('Reference circulating (--circulating)', 36)} ${padStart(money(circ.reference), circWidth)}`);
|
|
1512
|
+
console.log(` ${padEnd('Chain float − reference', 36)} ${padStart(money(delta), circWidth)} `
|
|
1513
|
+
+ c(colors.gray, ` ${relative}`));
|
|
1514
|
+
}
|
|
1515
|
+
console.log();
|
|
1516
|
+
console.log(c(colors.bold, ` ${padEnd('CATEGORY', labelWidth)} ${padStart('BTS', amountWidth)} `
|
|
1517
|
+
+ `${padStart('% SUPPLY', pctWidth)} ${padStart('% FLOAT', pctWidth)}`));
|
|
1518
|
+
console.log(c(colors.gray, ` ${'─'.repeat(labelWidth + amountWidth + pctWidth * 2 + 3)}`));
|
|
1519
|
+
for (const bucket of report.buckets) {
|
|
1520
|
+
if (bucket.amount === 0n)
|
|
1521
|
+
continue;
|
|
1522
|
+
console.log(` ${padEnd(bucket.label.slice(0, labelWidth - 2), labelWidth)} `
|
|
1523
|
+
+ `${padStart(money(bucket.amount), amountWidth)} `
|
|
1524
|
+
+ `${padStart(sharePercent(bucket.amount, supply), pctWidth)} `
|
|
1525
|
+
+ `${padStart(sharePercent(bucket.amount, circ.derived), pctWidth)}`);
|
|
1526
|
+
}
|
|
1527
|
+
console.log(c(colors.gray, ` ${'─'.repeat(labelWidth + amountWidth + pctWidth * 2 + 3)}`));
|
|
1528
|
+
console.log(c(colors.gray, ' Float = supply − identified/dormant. BitShares has no protocol-level '
|
|
1529
|
+
+ '"circulating" field; this is a derived float.'));
|
|
1530
|
+
if (report.details.warnings.length > 0) {
|
|
1531
|
+
section('Warnings');
|
|
1532
|
+
for (const warning of report.details.warnings)
|
|
1533
|
+
console.log(c(colors.sell, ` ! ${warning}`));
|
|
1534
|
+
}
|
|
1535
|
+
console.log();
|
|
1536
|
+
if (opts.html)
|
|
1537
|
+
console.log(c(colors.brightGreen, ` HTML report: ${opts.html}`));
|
|
1538
|
+
console.log(c(colors.gray, ' Collateral: api_helper_indexes total_in_collateral; rest via list_* / get_objects scans.'));
|
|
1539
|
+
console.log();
|
|
1540
|
+
}
|
|
1541
|
+
function printMpaTable(report, detail, money, c) {
|
|
1542
|
+
const rows = report.details.mpas.slice(0, detail);
|
|
1543
|
+
if (rows.length === 0) {
|
|
1544
|
+
console.log(c(colors.gray, ' (none)'));
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
console.log(c(colors.gray, ` ${padEnd('MPA', 14)} ${padStart('COLLATERAL', 18)} ${padStart('SETTLE FUND', 16)} ${padStart('INDIV. FUND', 16)}`));
|
|
1548
|
+
for (const row of rows) {
|
|
1549
|
+
const flags = row.settled ? ' [settled]' : '';
|
|
1550
|
+
console.log(` ${padEnd(row.symbol.slice(0, 14), 14)} ${padStart(money(row.collateral), 18)} `
|
|
1551
|
+
+ `${padStart(money(row.settlementFund), 16)} ${padStart(money(row.individualSettlementFund), 16)}`
|
|
1552
|
+
+ c(colors.gray, flags));
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
function formatDelay(seconds) {
|
|
1556
|
+
if (seconds === null)
|
|
1557
|
+
return '—';
|
|
1558
|
+
if (seconds >= 86400)
|
|
1559
|
+
return `${(seconds / 86400).toFixed(seconds % 86400 === 0 ? 0 : 1)}d`;
|
|
1560
|
+
if (seconds >= 3600)
|
|
1561
|
+
return `${(seconds / 3600).toFixed(seconds % 3600 === 0 ? 0 : 1)}h`;
|
|
1562
|
+
if (seconds >= 60)
|
|
1563
|
+
return `${(seconds / 60).toFixed(seconds % 60 === 0 ? 0 : 1)}m`;
|
|
1564
|
+
return `${seconds}s`;
|
|
1565
|
+
}
|
|
1566
|
+
function printSettlementTable(report, money, c) {
|
|
1567
|
+
const rows = report.details.settlements;
|
|
1568
|
+
if (rows.length === 0)
|
|
1569
|
+
return;
|
|
1570
|
+
console.log();
|
|
1571
|
+
console.log(c(colors.gray, ' Individual settlement pools: the fund is BTS (already counted above);'));
|
|
1572
|
+
console.log(c(colors.gray, ' debt / max / settled volumes are in each MPA\'s own units and are not BTS.'));
|
|
1573
|
+
console.log(c(colors.gray, ` ${padEnd('MPA', 12)} ${padStart('FUND (BTS)', 18)} ${padStart('INDIV. DEBT', 18)} `
|
|
1574
|
+
+ `${padStart('FUND PRICE', 16)} ${padStart('OFF', 6)} ${padStart('FEE', 6)} ${padStart('DELAY', 7)} `
|
|
1575
|
+
+ `${padStart('MAX/PERIOD', 14)} ${padStart('SETTLED', 12)} ${padStart('REMAIN', 7)}`));
|
|
1576
|
+
for (const row of rows) {
|
|
1577
|
+
const debt = formatUnits(row.debt, row.precision);
|
|
1578
|
+
const maxVolume = formatUnits(row.maxVolume, row.precision);
|
|
1579
|
+
const settled = formatUnits(row.settledVolume, row.precision);
|
|
1580
|
+
const price = row.fundPrice !== null ? `${row.fundPrice.toFixed(4)}` : '—';
|
|
1581
|
+
console.log(` ${padEnd(row.symbol.slice(0, 12), 12)} ${padStart(money(row.fund), 18)} ${padStart(debt, 18)} `
|
|
1582
|
+
+ `${padStart(price, 16)} ${padStart(row.offsetPercent !== null ? `${row.offsetPercent.toFixed(1)}%` : '—', 6)} `
|
|
1583
|
+
+ `${padStart(row.feePercent !== null ? `${row.feePercent.toFixed(1)}%` : '—', 6)} `
|
|
1584
|
+
+ `${padStart(formatDelay(row.delaySeconds), 7)} ${padStart(maxVolume, 14)} ${padStart(settled, 12)} `
|
|
1585
|
+
+ `${padStart(row.remainingPercent !== null ? `${row.remainingPercent.toFixed(1)}%` : '—', 7)}`);
|
|
1586
|
+
}
|
|
1587
|
+
console.log(c(colors.gray, ' fund price = individual settlement fund (BTS) / individual settlement debt (MPA units).'));
|
|
1588
|
+
}
|
|
1589
|
+
function printTypeTable(rows, supply, money, c) {
|
|
1590
|
+
if (rows.length === 0) {
|
|
1591
|
+
console.log(c(colors.gray, ' (none)'));
|
|
1592
|
+
return;
|
|
1593
|
+
}
|
|
1594
|
+
for (const row of rows) {
|
|
1595
|
+
console.log(` ${padEnd(row.type.slice(0, 18), 18)} ${padStart(money(row.amount), 20)} `
|
|
1596
|
+
+ `${padStart(sharePercent(row.amount, supply), 8)} ${c(colors.gray, `${row.count} object(s)`)}`);
|
|
1597
|
+
}
|
|
1598
|
+
}
|
|
1599
|
+
function printHolderTable(rows, money, c) {
|
|
1600
|
+
if (rows.length === 0) {
|
|
1601
|
+
console.log(c(colors.gray, ' (none)'));
|
|
1602
|
+
return;
|
|
1603
|
+
}
|
|
1604
|
+
for (const row of rows) {
|
|
1605
|
+
const name = row.name ? `${row.name} (${row.id})` : row.id;
|
|
1606
|
+
const tag = row.exchange ? ` [${row.exchange}]` : '';
|
|
1607
|
+
console.log(` ${padEnd(name.slice(0, 32), 32)} ${padStart(money(row.amount), 20)}${tag}`);
|
|
1608
|
+
}
|
|
1609
|
+
}
|
|
1610
|
+
function printPoolTable(report, detail, money, c) {
|
|
1611
|
+
const rows = report.details.pools.top.slice(0, detail);
|
|
1612
|
+
if (rows.length === 0) {
|
|
1613
|
+
console.log(c(colors.gray, ' (none)'));
|
|
1614
|
+
return;
|
|
1615
|
+
}
|
|
1616
|
+
console.log(c(colors.gray, ` ${padEnd('POOL', 12)} ${padEnd('PAIR', 24)} ${padStart('BTS', 18)}`));
|
|
1617
|
+
for (const row of rows) {
|
|
1618
|
+
console.log(` ${padEnd(row.id, 12)} ${padEnd(row.pair.slice(0, 24), 24)} ${padStart(money(row.bts), 18)}`);
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
// ---------------------------------------------------------------------------
|
|
1622
|
+
// HTML report
|
|
1623
|
+
// ---------------------------------------------------------------------------
|
|
1624
|
+
function esc(value) {
|
|
1625
|
+
return value
|
|
1626
|
+
.replace(/&/g, '&')
|
|
1627
|
+
.replace(/</g, '<')
|
|
1628
|
+
.replace(/>/g, '>')
|
|
1629
|
+
.replace(/"/g, '"')
|
|
1630
|
+
.replace(/'/g, ''');
|
|
1631
|
+
}
|
|
1632
|
+
/** Fold hairline slices into a single "Other" wedge so the donut stays readable. */
|
|
1633
|
+
function groupSlices(slices, total, minShare = 0.004) {
|
|
1634
|
+
const kept = [];
|
|
1635
|
+
let other = 0n;
|
|
1636
|
+
for (const slice of slices) {
|
|
1637
|
+
if (slice.value === 0n)
|
|
1638
|
+
continue;
|
|
1639
|
+
if (shareFraction(slice.value, total) < minShare)
|
|
1640
|
+
other += slice.value;
|
|
1641
|
+
else
|
|
1642
|
+
kept.push(slice);
|
|
1643
|
+
}
|
|
1644
|
+
if (other > 0n)
|
|
1645
|
+
kept.push({ label: 'Other (smaller buckets)', value: other, color: '#6e7681' });
|
|
1646
|
+
return kept;
|
|
1647
|
+
}
|
|
1648
|
+
function donutSvg(slices, total, centerLabel, centerValue, precision) {
|
|
1649
|
+
const radius = 42;
|
|
1650
|
+
const circumference = 2 * Math.PI * radius;
|
|
1651
|
+
let offset = 0;
|
|
1652
|
+
const parts = [];
|
|
1653
|
+
for (const slice of slices) {
|
|
1654
|
+
const length = circumference * shareFraction(slice.value, total);
|
|
1655
|
+
const pct = sharePercent(slice.value, total);
|
|
1656
|
+
parts.push(`<circle cx="50" cy="50" r="${radius}" fill="none" stroke="${slice.color}" stroke-width="15"`
|
|
1657
|
+
+ ` stroke-dasharray="${length.toFixed(3)} ${(circumference - length).toFixed(3)}"`
|
|
1658
|
+
+ ` stroke-dashoffset="${(-offset).toFixed(3)}" transform="rotate(-90 50 50)">`
|
|
1659
|
+
+ `<title>${esc(slice.label)}: ${esc(formatUnits(slice.value, precision))} BTS (${pct})</title>`
|
|
1660
|
+
+ '</circle>');
|
|
1661
|
+
offset += length;
|
|
1662
|
+
}
|
|
1663
|
+
return `<svg viewBox="0 0 100 100" role="img" aria-label="BTS supply composition" class="donut">
|
|
1664
|
+
<circle cx="50" cy="50" r="${radius}" fill="none" stroke="#21262d" stroke-width="15"/>
|
|
1665
|
+
${parts.join('')}
|
|
1666
|
+
<text x="50" y="44.5" text-anchor="middle" class="donut-kicker">${esc(centerLabel)}</text>
|
|
1667
|
+
<text x="50" y="55" text-anchor="middle" class="donut-value">${esc(centerValue)}</text>
|
|
1668
|
+
<text x="50" y="62" text-anchor="middle" class="donut-unit">BTS</text>
|
|
1669
|
+
</svg>`;
|
|
1670
|
+
}
|
|
1671
|
+
function htmlTable(headers, rows, numericFrom = 1) {
|
|
1672
|
+
if (rows.length === 0)
|
|
1673
|
+
return '<p class="muted">No data.</p>';
|
|
1674
|
+
const head = headers.map((h, i) => `<th class="${i >= numericFrom ? 'num' : ''}">${esc(h)}</th>`).join('');
|
|
1675
|
+
const body = rows.map((row) => `<tr>${row.map((cell, i) => `<td class="${i >= numericFrom ? 'num' : ''}">${cell}</td>`).join('')}</tr>`).join('');
|
|
1676
|
+
return `<div class="table-wrap"><table><thead><tr>${head}</tr></thead><tbody>${body}</tbody></table></div>`;
|
|
1677
|
+
}
|
|
1678
|
+
function renderHtml(report) {
|
|
1679
|
+
const p = report.asset.precision;
|
|
1680
|
+
const supply = report.supply.current;
|
|
1681
|
+
const money = (v) => formatUnits(v, p);
|
|
1682
|
+
const pct = (v) => sharePercent(v, supply);
|
|
1683
|
+
const allSlices = [
|
|
1684
|
+
...report.buckets.map((b) => ({ label: b.label, value: b.amount, color: b.color })),
|
|
1685
|
+
{ label: 'Liquid residual', value: report.residual, color: '#4b5563' },
|
|
1686
|
+
];
|
|
1687
|
+
const slices = groupSlices(allSlices, supply);
|
|
1688
|
+
const lockedSlices = groupSlices(report.buckets.map((b) => ({ label: b.label, value: b.amount, color: b.color })), report.identified > 0n ? report.identified : 1n);
|
|
1689
|
+
const legend = slices
|
|
1690
|
+
.map((s) => `<li>
|
|
1691
|
+
<span class="dot" style="background:${s.color}"></span>
|
|
1692
|
+
<span class="legend-label">${esc(s.label)}</span>
|
|
1693
|
+
<span class="legend-value">${money(s.value)}</span>
|
|
1694
|
+
<span class="legend-share">${pct(s.value)}</span>
|
|
1695
|
+
</li>`)
|
|
1696
|
+
.join('');
|
|
1697
|
+
const maxBucket = report.buckets.reduce((m, b) => (b.amount > m ? b.amount : m), 0n);
|
|
1698
|
+
const bars = report.buckets
|
|
1699
|
+
.filter((b) => b.amount > 0n)
|
|
1700
|
+
.map((b) => `<div class="bar-row">
|
|
1701
|
+
<span class="bar-label"><span class="dot" style="background:${b.color}"></span>${esc(b.label)}</span>
|
|
1702
|
+
<span class="bar-track"><span class="bar-fill" style="width:${(shareFraction(b.amount, maxBucket) * 100).toFixed(4)}%;background:${b.color}"></span></span>
|
|
1703
|
+
<span class="bar-amount">${money(b.amount)}</span>
|
|
1704
|
+
<span class="bar-share">${pct(b.amount)}</span>
|
|
1705
|
+
</div>`)
|
|
1706
|
+
.join('');
|
|
1707
|
+
const mpaRows = report.details.mpas.map((row) => [
|
|
1708
|
+
`${esc(row.symbol)}${row.settled ? ' <span class="tag">settled</span>' : ''}`,
|
|
1709
|
+
esc(row.assetId),
|
|
1710
|
+
money(row.collateral),
|
|
1711
|
+
money(row.settlementFund),
|
|
1712
|
+
money(row.individualSettlementFund),
|
|
1713
|
+
]);
|
|
1714
|
+
const ticketTypeRows = report.details.tickets.byType.map((row) => [esc(row.type), String(row.count), money(row.amount), pct(row.amount)]);
|
|
1715
|
+
const vestingRows = report.details.vesting.byType.map((row) => [esc(row.type), String(row.count), money(row.amount), pct(row.amount)]);
|
|
1716
|
+
const holderBadge = (row) => `${esc(row.name ?? row.id)}${row.exchange ? ` <span class="tag cex">${esc(row.exchange)}</span>` : ''}`;
|
|
1717
|
+
const ticketTopRows = report.details.tickets.top.map((row) => [
|
|
1718
|
+
holderBadge(row),
|
|
1719
|
+
esc(row.id),
|
|
1720
|
+
money(row.amount),
|
|
1721
|
+
pct(row.amount),
|
|
1722
|
+
]);
|
|
1723
|
+
const vestingTopRows = report.details.vesting.top.map((row) => [
|
|
1724
|
+
holderBadge(row),
|
|
1725
|
+
esc(row.id),
|
|
1726
|
+
money(row.amount),
|
|
1727
|
+
pct(row.amount),
|
|
1728
|
+
]);
|
|
1729
|
+
const settlementRows = report.details.settlements.map((row) => [
|
|
1730
|
+
esc(row.symbol),
|
|
1731
|
+
money(row.fund),
|
|
1732
|
+
formatUnits(row.debt, row.precision),
|
|
1733
|
+
row.fundPrice !== null ? `${row.fundPrice.toFixed(4)} BTS/${esc(row.symbol)}` : '—',
|
|
1734
|
+
row.offsetPercent !== null ? `${row.offsetPercent.toFixed(1)}%` : '—',
|
|
1735
|
+
row.feePercent !== null ? `${row.feePercent.toFixed(1)}%` : '—',
|
|
1736
|
+
formatDelay(row.delaySeconds),
|
|
1737
|
+
formatUnits(row.maxVolume, row.precision),
|
|
1738
|
+
formatUnits(row.settledVolume, row.precision),
|
|
1739
|
+
row.remainingPercent !== null ? `${row.remainingPercent.toFixed(1)}%` : '—',
|
|
1740
|
+
]);
|
|
1741
|
+
const settlementCard = `<section class="card">
|
|
1742
|
+
<div class="head-row"><h2>Force settlement / individual pools</h2><span class="hint">${report.details.settlementCount} MPA(s) with individual settlement pools</span></div>
|
|
1743
|
+
<p class="muted" style="margin:0 0 10px">
|
|
1744
|
+
The fund column is BTS and is exactly what the <em>Individual settlement fund</em> bucket sums.
|
|
1745
|
+
Debt, max-volume and settled-volume columns are denominated in each MPA and are not added to the BTS totals.
|
|
1746
|
+
Fund price is <code>fund / debt</code> (the UI's "Force Settlement Price (offset included)" is feed-based; this is the pool-implied price).
|
|
1747
|
+
</p>
|
|
1748
|
+
${htmlTable(['MPA', 'Individual fund (BTS)', 'Individual debt', 'Fund price', 'Offset', 'Fee', 'Delay', 'Max / period', 'Already settled', 'Remaining'], settlementRows, 1)}
|
|
1749
|
+
<p class="muted" style="margin-top:10px">
|
|
1750
|
+
The settlement fund is held by the protocol and only moves when the MPA is force-settled, so it is
|
|
1751
|
+
reported as locked BTS even though the debt side is denominated in the MPA.
|
|
1752
|
+
</p>
|
|
1753
|
+
</section>`;
|
|
1754
|
+
const holders = report.details.holders;
|
|
1755
|
+
const holderRows = holders.top.map((row) => [
|
|
1756
|
+
String(row.rank ?? ''),
|
|
1757
|
+
holderBadge(row),
|
|
1758
|
+
esc(row.id),
|
|
1759
|
+
money(row.amount),
|
|
1760
|
+
pct(row.amount),
|
|
1761
|
+
]);
|
|
1762
|
+
const exchangeRows = holders.exchanges.map((row) => [
|
|
1763
|
+
`<span class="tag cex">${esc(row.label)}</span>`,
|
|
1764
|
+
String(row.count),
|
|
1765
|
+
money(row.amount),
|
|
1766
|
+
pct(row.amount),
|
|
1767
|
+
]);
|
|
1768
|
+
const concentrationRows = holders.concentration.map((row) => [
|
|
1769
|
+
`Top ${row.top}`,
|
|
1770
|
+
String(row.count),
|
|
1771
|
+
money(row.amount),
|
|
1772
|
+
sharePercent(row.amount, report.residual),
|
|
1773
|
+
]);
|
|
1774
|
+
const histogramRows = holders.histogram.map((row) => [
|
|
1775
|
+
esc(row.label),
|
|
1776
|
+
String(row.count),
|
|
1777
|
+
money(row.amount),
|
|
1778
|
+
sharePercent(row.amount, report.residual),
|
|
1779
|
+
]);
|
|
1780
|
+
const poolRows = report.details.pools.top.map((row) => [esc(row.id), esc(row.pair), money(row.bts), pct(row.bts)]);
|
|
1781
|
+
const sametRows = report.details.samet.top.map((row) => [esc(row.name ?? row.owner), esc(row.id), money(row.amount), pct(row.amount)]);
|
|
1782
|
+
const feeRows = report.details.feePools.top.map((row) => [esc(row.symbol), money(row.amount), pct(row.amount)]);
|
|
1783
|
+
const warningHtml = report.details.warnings.length > 0
|
|
1784
|
+
? `<section class="card warn"><h2>Warnings</h2><ul>${report.details.warnings.map((w) => `<li>${esc(w)}</li>`).join('')}</ul></section>`
|
|
1785
|
+
: '';
|
|
1786
|
+
const credit = report.details.credit;
|
|
1787
|
+
const circ = report.circulating;
|
|
1788
|
+
const lockedWidth = (shareFraction(report.identified, supply) * 100).toFixed(3);
|
|
1789
|
+
const floatWidth = (shareFraction(circ.derived, supply) * 100).toFixed(3);
|
|
1790
|
+
const comparisonRows = report.buckets
|
|
1791
|
+
.filter((b) => b.amount > 0n)
|
|
1792
|
+
.map((b) => [esc(b.label), money(b.amount), pct(b.amount), sharePercent(b.amount, circ.derived)]);
|
|
1793
|
+
const referenceHtml = circ.reference !== null
|
|
1794
|
+
? (() => {
|
|
1795
|
+
const delta = circ.derived - circ.reference;
|
|
1796
|
+
const relative = circ.reference > 0n
|
|
1797
|
+
? `${delta >= 0n ? '+' : ''}${(Number((delta * 10000n) / circ.reference) / 100).toFixed(2)}%`
|
|
1798
|
+
: '—';
|
|
1799
|
+
return `<p class="muted" style="margin-top:12px">
|
|
1800
|
+
Reference circulating (<code>--circulating</code>): <strong>${money(circ.reference)}</strong> BTS ·
|
|
1801
|
+
chain float − reference: <strong>${money(delta)}</strong> BTS (${relative})
|
|
1802
|
+
</p>`;
|
|
1803
|
+
})()
|
|
1804
|
+
: '';
|
|
1805
|
+
const circulatingCard = `<section class="card">
|
|
1806
|
+
<div class="head-row"><h2>Circulating supply comparison</h2><span class="hint">float = current supply − identified / dormant</span></div>
|
|
1807
|
+
<div class="kpis" style="margin-bottom:16px">
|
|
1808
|
+
<div class="kpi"><div class="k">Total supply</div><div class="v">${money(supply)}</div><div class="s">current_supply · 100%</div></div>
|
|
1809
|
+
<div class="kpi"><div class="k">Identified / dormant</div><div class="v">${money(report.identified)}</div><div class="s">${pct(report.identified)} of supply</div></div>
|
|
1810
|
+
<div class="kpi"><div class="k">Circulating float</div><div class="v">${money(circ.derived)}</div><div class="s">${pct(circ.derived)} of supply</div></div>
|
|
1811
|
+
<div class="kpi"><div class="k">Locked per 1 float</div><div class="v">${circ.lockedPerCirculating.toFixed(4)}</div><div class="s">BTS held per BTS circulating</div></div>
|
|
1812
|
+
</div>
|
|
1813
|
+
<div class="flow-bar">
|
|
1814
|
+
<span class="flow-locked" style="width:${lockedWidth}%">locked ${pct(report.identified)}</span>
|
|
1815
|
+
<span class="flow-float" style="width:${floatWidth}%">float ${pct(circ.derived)}</span>
|
|
1816
|
+
</div>
|
|
1817
|
+
${htmlTable(['Bucket', 'BTS', '% of supply', '% of float'], comparisonRows, 1)}
|
|
1818
|
+
<p class="muted" style="margin-top:12px">
|
|
1819
|
+
BitShares exposes only <code>current_supply</code> (coins in existence); there is no protocol-level
|
|
1820
|
+
circulating field. The float above removes every bucket this report can identify, including
|
|
1821
|
+
pre-migration balances and order-book escrow implicit in the residual.
|
|
1822
|
+
If legacy 1.15.x balances are treated as circulating, the float becomes
|
|
1823
|
+
<strong>${money(circ.includingLegacy)}</strong> BTS (${pct(circ.includingLegacy)} of supply).
|
|
1824
|
+
Blinded balances inside the float: ${money(report.supply.confidential)} BTS
|
|
1825
|
+
(${sharePercent(report.supply.confidential, circ.derived)} of the float).
|
|
1826
|
+
</p>
|
|
1827
|
+
${referenceHtml}
|
|
1828
|
+
</section>`;
|
|
1829
|
+
return `<!DOCTYPE html>
|
|
1830
|
+
<html lang="en">
|
|
1831
|
+
<head>
|
|
1832
|
+
<meta charset="utf-8"/>
|
|
1833
|
+
<meta name="viewport" content="width=device-width, initial-scale=1"/>
|
|
1834
|
+
<title>BTS distribution · block ${formatInteger(BigInt(report.blockNum))}</title>
|
|
1835
|
+
<style>
|
|
1836
|
+
:root{
|
|
1837
|
+
--bg:#0b0e14; --panel:#11161d; --panel-2:#161b22; --border:#242c38;
|
|
1838
|
+
--text:#d1d5db; --muted:#8b949e; --bright:#f0f6fc; --accent:#5eb0ef; --warn:#f0883e;
|
|
1839
|
+
}
|
|
1840
|
+
*{box-sizing:border-box}
|
|
1841
|
+
html,body{margin:0;padding:0;background:var(--bg);color:var(--text);font-family:'Segoe UI',system-ui,-apple-system,sans-serif}
|
|
1842
|
+
body{padding:28px 22px 52px;max-width:1320px;margin:0 auto;line-height:1.45}
|
|
1843
|
+
h1,h2,h3{margin:0;font-weight:600;color:var(--bright)}
|
|
1844
|
+
h1{font-size:26px;letter-spacing:.2px}
|
|
1845
|
+
h2{font-size:15px;text-transform:uppercase;letter-spacing:1.3px;color:var(--muted);margin-bottom:14px}
|
|
1846
|
+
a{color:var(--accent)}
|
|
1847
|
+
.sub{color:var(--muted);font-size:13px;margin-top:6px;font-variant-numeric:tabular-nums}
|
|
1848
|
+
.hero{display:flex;justify-content:space-between;align-items:flex-end;gap:18px;flex-wrap:wrap;margin-bottom:22px}
|
|
1849
|
+
.badge{display:inline-block;padding:3px 9px;border:1px solid var(--border);border-radius:999px;font-size:11px;color:var(--muted);background:var(--panel)}
|
|
1850
|
+
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(210px,1fr));gap:14px;margin-bottom:22px}
|
|
1851
|
+
.kpi{background:linear-gradient(180deg,var(--panel-2),var(--panel));border:1px solid var(--border);border-radius:12px;padding:16px 18px}
|
|
1852
|
+
.kpi .k{font-size:11px;text-transform:uppercase;letter-spacing:1.1px;color:var(--muted)}
|
|
1853
|
+
.kpi .v{font-size:23px;font-weight:600;color:var(--bright);margin-top:5px;font-variant-numeric:tabular-nums;word-break:break-all}
|
|
1854
|
+
.kpi .s{font-size:12px;color:var(--muted);margin-top:2px}
|
|
1855
|
+
.grid{display:grid;grid-template-columns:minmax(320px,420px) 1fr;gap:18px;margin-bottom:18px}
|
|
1856
|
+
@media(max-width:900px){.grid{grid-template-columns:1fr}}
|
|
1857
|
+
.card{background:var(--panel);border:1px solid var(--border);border-radius:14px;padding:20px 22px}
|
|
1858
|
+
.card.warn{border-color:#5c3a12;background:#1a1207;margin-bottom:18px}
|
|
1859
|
+
.card.warn h2{color:var(--warn)}
|
|
1860
|
+
.card.warn li{color:#f3c99a}
|
|
1861
|
+
.donut{width:100%;height:auto;max-height:380px;display:block}
|
|
1862
|
+
.donut-kicker{fill:var(--muted);font-size:4.4px;text-transform:uppercase;letter-spacing:.9px}
|
|
1863
|
+
.donut-value{fill:var(--bright);font-size:9px;font-weight:600;font-variant-numeric:tabular-nums}
|
|
1864
|
+
.donut-unit{fill:var(--muted);font-size:4.2px;letter-spacing:1px}
|
|
1865
|
+
.legend{list-style:none;margin:18px 0 0;padding:0;font-size:12.5px}
|
|
1866
|
+
.legend li{display:grid;grid-template-columns:12px 1fr auto 62px;gap:8px;align-items:center;padding:5px 0;border-top:1px solid #1c222b}
|
|
1867
|
+
.legend li:first-child{border-top:0}
|
|
1868
|
+
.dot{width:10px;height:10px;border-radius:3px;display:inline-block;flex:none}
|
|
1869
|
+
.legend-label{color:var(--text)}
|
|
1870
|
+
.legend-value{font-variant-numeric:tabular-nums;color:var(--bright)}
|
|
1871
|
+
.legend-share{text-align:right;color:var(--muted);font-variant-numeric:tabular-nums}
|
|
1872
|
+
.bars{display:flex;flex-direction:column;gap:9px}
|
|
1873
|
+
.bar-row{display:grid;grid-template-columns:minmax(190px,270px) 1fr 150px 62px;gap:12px;align-items:center;font-size:12.5px}
|
|
1874
|
+
.bar-label{display:flex;align-items:center;gap:8px;min-width:0;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
|
1875
|
+
.bar-track{height:13px;background:#1b212b;border-radius:7px;overflow:hidden;border:1px solid #222b37}
|
|
1876
|
+
.bar-fill{display:block;height:100%;border-radius:7px;min-width:2px}
|
|
1877
|
+
.bar-amount{text-align:right;font-variant-numeric:tabular-nums;color:var(--bright)}
|
|
1878
|
+
.bar-share{text-align:right;font-variant-numeric:tabular-nums;color:var(--muted)}
|
|
1879
|
+
@media(max-width:760px){.bar-row{grid-template-columns:1fr 90px 54px}.bar-track{display:none}}
|
|
1880
|
+
.table-wrap{overflow-x:auto}
|
|
1881
|
+
table{width:100%;border-collapse:collapse;font-size:12.5px}
|
|
1882
|
+
th,td{text-align:left;padding:7px 10px;border-bottom:1px solid #1c222b;white-space:nowrap}
|
|
1883
|
+
th{font-size:10.5px;text-transform:uppercase;letter-spacing:.9px;color:var(--muted);font-weight:600}
|
|
1884
|
+
td.num,th.num{text-align:right;font-variant-numeric:tabular-nums}
|
|
1885
|
+
tbody tr:hover{background:#151b23}
|
|
1886
|
+
.tag{display:inline-block;padding:1px 6px;margin-left:6px;border-radius:999px;font-size:10px;background:#3b2a12;color:#f0b46d;border:1px solid #64401a}
|
|
1887
|
+
.tag.cex{background:#10263a;color:#7cc4ff;border-color:#245273}
|
|
1888
|
+
.muted{color:var(--muted);font-size:12.5px}
|
|
1889
|
+
footer{margin-top:24px;color:var(--muted);font-size:11.5px;border-top:1px solid var(--border);padding-top:14px}
|
|
1890
|
+
footer p{margin:4px 0}
|
|
1891
|
+
.split{display:grid;grid-template-columns:1fr 1fr;gap:18px}
|
|
1892
|
+
@media(max-width:900px){.split{grid-template-columns:1fr}}
|
|
1893
|
+
.stack{display:grid;gap:18px}
|
|
1894
|
+
.head-row{display:flex;justify-content:space-between;gap:12px;align-items:baseline;margin-bottom:10px}
|
|
1895
|
+
.head-row .hint{font-size:11.5px;color:var(--muted)}
|
|
1896
|
+
.flow-bar{display:flex;height:30px;border-radius:8px;overflow:hidden;border:1px solid var(--border);margin:8px 0 14px;font-size:11.5px}
|
|
1897
|
+
.flow-bar span{display:flex;align-items:center;justify-content:center;white-space:nowrap;font-weight:600;min-width:2px}
|
|
1898
|
+
.flow-locked{background:#f0883e;color:#1a1207}
|
|
1899
|
+
.flow-float{background:#4b5563;color:#e6edf3}
|
|
1900
|
+
</style>
|
|
1901
|
+
</head>
|
|
1902
|
+
<body>
|
|
1903
|
+
<div class="hero">
|
|
1904
|
+
<div>
|
|
1905
|
+
<h1>BTS supply distribution</h1>
|
|
1906
|
+
<div class="sub">block ${esc(formatInteger(BigInt(report.blockNum)))} · ${esc(report.blockTime)} · ${esc(report.node)}</div>
|
|
1907
|
+
<div class="sub">${esc(report.asset.symbol)} (${esc(report.asset.id)}) · precision ${p} · total supply ${money(supply)}${report.asset.maxSupply ? ` · max ${money(report.asset.maxSupply)}` : ''}</div>
|
|
1908
|
+
</div>
|
|
1909
|
+
<div><span class="badge">generated ${esc(report.generatedAt)}</span> <span class="badge">${report.details.assetCount} assets scanned</span></div>
|
|
1910
|
+
</div>
|
|
1911
|
+
|
|
1912
|
+
<div class="kpis">
|
|
1913
|
+
<div class="kpi"><div class="k">Total supply</div><div class="v">${money(supply)}</div><div class="s">${esc(report.asset.symbol)} in existence</div></div>
|
|
1914
|
+
<div class="kpi"><div class="k">Identified / dormant</div><div class="v">${money(report.identified)}</div><div class="s">${pct(report.identified)} of supply</div></div>
|
|
1915
|
+
<div class="kpi"><div class="k">Liquid residual</div><div class="v">${money(report.residual)}</div><div class="s">${pct(report.residual)} of supply</div></div>
|
|
1916
|
+
<div class="kpi"><div class="k">Blinded balances</div><div class="v">${money(report.supply.confidential)}</div><div class="s">${pct(report.supply.confidential)} · part of the residual</div></div>
|
|
1917
|
+
<div class="kpi"><div class="k">Top ${holders.count} liquid holders</div><div class="v">${money(holders.total)}</div><div class="s">${pct(holders.total)} of supply · rich list via asset_api</div></div>
|
|
1918
|
+
</div>
|
|
1919
|
+
|
|
1920
|
+
<div class="grid">
|
|
1921
|
+
<section class="card">
|
|
1922
|
+
<h2>Where the BTS is</h2>
|
|
1923
|
+
${donutSvg(slices, supply, 'total supply', compactUnits(supply, p), p)}
|
|
1924
|
+
<ul class="legend">${legend}</ul>
|
|
1925
|
+
</section>
|
|
1926
|
+
<section class="card">
|
|
1927
|
+
<div class="head-row"><h2>Identified supply composition</h2><span class="hint">residual excluded · bars scaled to largest bucket</span></div>
|
|
1928
|
+
${donutSvg(lockedSlices, report.identified > 0n ? report.identified : 1n, 'identified', compactUnits(report.identified, p), p)}
|
|
1929
|
+
<div class="bars" style="margin-top:22px">${bars}</div>
|
|
1930
|
+
</section>
|
|
1931
|
+
</div>
|
|
1932
|
+
|
|
1933
|
+
<div class="stack">
|
|
1934
|
+
<section class="card">
|
|
1935
|
+
<h2>Category breakdown</h2>
|
|
1936
|
+
${htmlTable(['Category', 'BTS', 'Share of supply', 'What it is'], report.buckets.map((b) => [
|
|
1937
|
+
`<span class="dot" style="background:${b.color};margin-right:8px"></span>${esc(b.label)}`,
|
|
1938
|
+
money(b.amount),
|
|
1939
|
+
pct(b.amount),
|
|
1940
|
+
`<span class="muted">${esc(b.note)}</span>`,
|
|
1941
|
+
]), 1)}
|
|
1942
|
+
</section>
|
|
1943
|
+
|
|
1944
|
+
<section class="card">
|
|
1945
|
+
<div class="head-row"><h2>Top liquid holders (rich list)</h2><span class="hint">account balances only · asset_api${holders.sourceNode ? ` · ${esc(holders.sourceNode)}` : ''}</span></div>
|
|
1946
|
+
<p class="muted" style="margin:0 0 10px">
|
|
1947
|
+
Top ${holders.count}${holders.totalCount !== null ? ` of ${holders.totalCount}` : ''} accounts hold
|
|
1948
|
+
<strong>${money(holders.total)}</strong> BTS — ${pct(holders.total)} of supply and
|
|
1949
|
+
${sharePercent(holders.total, report.residual)} of the liquid residual.
|
|
1950
|
+
Exchange tags come from a name heuristic (anyone can register a brand-like name), so treat them as hints.
|
|
1951
|
+
</p>
|
|
1952
|
+
${htmlTable(['#', 'Account', 'Id', 'BTS', 'Share of supply'], holderRows, 3)}
|
|
1953
|
+
${holders.complete && holders.untrackedLiquid !== null && holders.orderBookAndOther !== null ? `
|
|
1954
|
+
<p class="muted" style="margin:14px 0 0">
|
|
1955
|
+
<strong>Residual split:</strong> account balances ${money(holders.total)} BTS
|
|
1956
|
+
(${sharePercent(holders.total, report.residual)} of the residual) ·
|
|
1957
|
+
blinded balances ${money(report.supply.confidential)} BTS ·
|
|
1958
|
+
order books + other ${money(holders.orderBookAndOther)} BTS
|
|
1959
|
+
(${sharePercent(holders.orderBookAndOther, report.residual)} of the residual).
|
|
1960
|
+
${holders.median !== null && holders.mean !== null
|
|
1961
|
+
? `Median account balance ${money(holders.median)} BTS · mean ${money(holders.mean)} BTS.`
|
|
1962
|
+
: ''}
|
|
1963
|
+
</p>` : ''}
|
|
1964
|
+
<h3 style="margin:18px 0 10px;font-size:13px">Exchange-linked holdings in the fetched set</h3>
|
|
1965
|
+
${htmlTable(['Exchange', 'Accounts', 'BTS', 'Share of supply'], exchangeRows, 1)}
|
|
1966
|
+
${concentrationRows.length > 0 ? `
|
|
1967
|
+
<h3 style="margin:18px 0 10px;font-size:13px">Concentration of the liquid residual</h3>
|
|
1968
|
+
${htmlTable(['Accounts', 'Count', 'BTS', 'Share of residual'], concentrationRows, 1)}` : ''}
|
|
1969
|
+
${histogramRows.length > 0 ? `
|
|
1970
|
+
<h3 style="margin:18px 0 10px;font-size:13px">Balance distribution across all holder accounts</h3>
|
|
1971
|
+
${htmlTable(['Balance band', 'Accounts', 'BTS', 'Share of residual'], histogramRows, 1)}` : ''}
|
|
1972
|
+
</section>
|
|
1973
|
+
|
|
1974
|
+
<section class="card">
|
|
1975
|
+
<div class="head-row"><h2>Collateral & settlement pools</h2><span class="hint">${report.details.mpaCount} BTS-backed MPAs</span></div>
|
|
1976
|
+
${htmlTable(['MPA', 'Asset id', 'Collateral (BTS)', 'Global settlement fund', 'Individual settlement fund'], mpaRows, 2)}
|
|
1977
|
+
<p class="muted" style="margin-top:10px">Call-order collateral total: <strong>${money(report.buckets.find((b) => b.key === 'collateral')?.amount ?? 0n)}</strong> BTS${report.details.collateralFromApi ? ' (api_helper_indexes total_in_collateral)' : ' (fallback: summed per-MPA call orders)'}${report.details.collateralTruncated ? ' — truncated by node limits' : ''}.</p>
|
|
1978
|
+
</section>
|
|
1979
|
+
|
|
1980
|
+
${settlementCard}
|
|
1981
|
+
|
|
1982
|
+
<div class="split">
|
|
1983
|
+
<section class="card">
|
|
1984
|
+
<h2>Governance tickets</h2>
|
|
1985
|
+
${htmlTable(['Lock type', 'Tickets', 'BTS locked', 'Share'], ticketTypeRows, 1)}
|
|
1986
|
+
<p class="muted" style="margin-top:12px">Status: ${report.details.tickets.byStatus.map((s) => `${esc(s.type)} ${money(s.amount)}`).join(' · ') || 'none'}</p>
|
|
1987
|
+
<h3 style="margin:16px 0 10px;font-size:13px">Top holders</h3>
|
|
1988
|
+
${htmlTable(['Account', 'Id', 'BTS', 'Share'], ticketTopRows, 2)}
|
|
1989
|
+
</section>
|
|
1990
|
+
<section class="card">
|
|
1991
|
+
<h2>Vesting balances</h2>
|
|
1992
|
+
${htmlTable(['Balance type', 'Objects', 'BTS', 'Share'], vestingRows, 1)}
|
|
1993
|
+
<p class="muted" style="margin-top:12px">Scanned 1.13.0–1.13.${report.details.vesting.scannedTo}${report.details.vesting.hitLimit ? ' (scan hit --vesting-max, totals may be incomplete)' : ''}.</p>
|
|
1994
|
+
<h3 style="margin:16px 0 10px;font-size:13px">Top owners</h3>
|
|
1995
|
+
${htmlTable(['Account', 'Id', 'BTS', 'Share'], vestingTopRows, 2)}
|
|
1996
|
+
</section>
|
|
1997
|
+
</div>
|
|
1998
|
+
|
|
1999
|
+
<div class="split">
|
|
2000
|
+
<section class="card">
|
|
2001
|
+
<h2>Liquidity pools with BTS</h2>
|
|
2002
|
+
<p class="muted" style="margin:0 0 10px">${report.details.pools.withBts} of ${report.details.pools.count} pools hold BTS · ${money(report.details.pools.total)} BTS pooled.</p>
|
|
2003
|
+
${htmlTable(['Pool', 'Pair', 'BTS', 'Share'], poolRows, 2)}
|
|
2004
|
+
</section>
|
|
2005
|
+
<section class="card">
|
|
2006
|
+
<h2>DeFi lending</h2>
|
|
2007
|
+
${htmlTable(['Bucket', 'BTS', 'Share', 'Objects'], [
|
|
2008
|
+
['Credit offer funds', money(credit.offerTotal), pct(credit.offerTotal), `${credit.btsOfferCount} / ${credit.offerCount}`],
|
|
2009
|
+
['Credit-deal collateral', money(credit.dealTotal), pct(credit.dealTotal), `${credit.btsDealCount} / ${credit.dealCount}`],
|
|
2010
|
+
['SameT funds', money(report.details.samet.total), pct(report.details.samet.total), `${report.details.samet.btsCount} / ${report.details.samet.count}`],
|
|
2011
|
+
['HTLC escrow', money(report.details.htlcs.total), pct(report.details.htlcs.total), String(report.details.htlcs.count)],
|
|
2012
|
+
['Collateral bids', money(report.details.collateralBids.total), pct(report.details.collateralBids.total), String(report.details.collateralBids.count)],
|
|
2013
|
+
], 1)}
|
|
2014
|
+
<h3 style="margin:16px 0 10px;font-size:13px">SameT funds</h3>
|
|
2015
|
+
${htmlTable(['Owner', 'Fund', 'BTS', 'Share'], sametRows, 2)}
|
|
2016
|
+
</section>
|
|
2017
|
+
</div>
|
|
2018
|
+
|
|
2019
|
+
<div class="split">
|
|
2020
|
+
<section class="card">
|
|
2021
|
+
<h2>Asset fee pools (BTS)</h2>
|
|
2022
|
+
<p class="muted" style="margin:0 0 10px">Every asset's <code>fee_pool</code> is denominated in core BTS. Total ${money(report.details.feePools.total)} BTS.</p>
|
|
2023
|
+
${htmlTable(['Asset', 'BTS', 'Share'], feeRows, 1)}
|
|
2024
|
+
</section>
|
|
2025
|
+
<section class="card">
|
|
2026
|
+
<h2>Legacy balances</h2>
|
|
2027
|
+
${htmlTable(['Metric', 'Value'], [
|
|
2028
|
+
['1.15.x balance objects', String(report.details.genesis.count)],
|
|
2029
|
+
['Claimable without vesting policy', String(report.details.genesis.claimableCount)],
|
|
2030
|
+
['With linear vesting policy', String(report.details.genesis.vestingCount)],
|
|
2031
|
+
['Total BTS', money(report.details.genesis.total)],
|
|
2032
|
+
], 1)}
|
|
2033
|
+
<h2 style="margin-top:20px">Reconciliation</h2>
|
|
2034
|
+
${htmlTable(['Line', 'BTS', 'Share'], [
|
|
2035
|
+
['Identified / dormant', money(report.identified), pct(report.identified)],
|
|
2036
|
+
['Liquid residual', money(report.residual), pct(report.residual)],
|
|
2037
|
+
['Current supply', money(supply), '100.00%'],
|
|
2038
|
+
], 1)}
|
|
2039
|
+
</section>
|
|
2040
|
+
</div>
|
|
2041
|
+
|
|
2042
|
+
${circulatingCard}
|
|
2043
|
+
</div>
|
|
2044
|
+
|
|
2045
|
+
${warningHtml}
|
|
2046
|
+
|
|
2047
|
+
<footer>
|
|
2048
|
+
<p><strong>Residual</strong> = current supply − all identified holdings. It contains account balances (2.5.x), limit-order escrow (1.7.x), blinded balances (${money(report.supply.confidential)} BTS) and any object type not listed above. It is derived, not enumerated.</p>
|
|
2049
|
+
<p>Sources: bitshares-core 7.0.x database_api — <code>list_assets</code>, <code>get_objects</code>, <code>list_tickets</code>, <code>list_liquidity_pools</code>, <code>list_samet_funds</code>, <code>list_credit_offers</code>, <code>list_credit_deals</code>, <code>list_htlcs</code>, <code>get_collateral_bids</code>${report.details.collateralFromApi ? ', <code>total_in_collateral</code>' : ''}${holders.sourceNode ? ', <code>asset_api::get_asset_holders</code>' : ''}. Read-only; no keys, no transactions. Exchange tags are name heuristics, not verified identities.</p>
|
|
2050
|
+
<p>Generated by <code>scripts/bts_distribution.ts</code> · block ${esc(formatInteger(BigInt(report.blockNum)))} · ${esc(report.blockTime)} UTC.</p>
|
|
2051
|
+
</footer>
|
|
2052
|
+
</body>
|
|
2053
|
+
</html>`;
|
|
2054
|
+
}
|
|
2055
|
+
// ---------------------------------------------------------------------------
|
|
2056
|
+
// Main
|
|
2057
|
+
// ---------------------------------------------------------------------------
|
|
2058
|
+
async function main() {
|
|
2059
|
+
let opts;
|
|
2060
|
+
try {
|
|
2061
|
+
opts = parseArgs(process.argv.slice(2));
|
|
2062
|
+
}
|
|
2063
|
+
catch (e) {
|
|
2064
|
+
if (e instanceof UsageError) {
|
|
2065
|
+
console.error(`Error: ${e.message}\n`);
|
|
2066
|
+
printHelp();
|
|
2067
|
+
process.exit(2);
|
|
2068
|
+
}
|
|
2069
|
+
throw e;
|
|
2070
|
+
}
|
|
2071
|
+
if (opts.help) {
|
|
2072
|
+
printHelp();
|
|
2073
|
+
return;
|
|
2074
|
+
}
|
|
2075
|
+
const nodes = opts.nodes.length > 0 ? opts.nodes : [...NODE_MANAGEMENT.DEFAULT_NODES];
|
|
2076
|
+
const session = await openSession(nodes);
|
|
2077
|
+
try {
|
|
2078
|
+
const report = await collect(session, opts);
|
|
2079
|
+
if (opts.html) {
|
|
2080
|
+
fs.mkdirSync(path.dirname(opts.html), { recursive: true });
|
|
2081
|
+
fs.writeFileSync(opts.html, renderHtml(report), 'utf8');
|
|
2082
|
+
}
|
|
2083
|
+
if (opts.json) {
|
|
2084
|
+
console.log(JSON.stringify({ ...report, html: opts.html }, (_key, value) => {
|
|
2085
|
+
return typeof value === 'bigint' ? value.toString() : value;
|
|
2086
|
+
}, 2));
|
|
2087
|
+
}
|
|
2088
|
+
else {
|
|
2089
|
+
renderTerminal(report, opts);
|
|
2090
|
+
}
|
|
2091
|
+
}
|
|
2092
|
+
finally {
|
|
2093
|
+
session.client.close();
|
|
2094
|
+
}
|
|
2095
|
+
}
|
|
2096
|
+
if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
|
|
2097
|
+
main().catch((e) => {
|
|
2098
|
+
console.error(`\nError: ${e.message}`);
|
|
2099
|
+
process.exit(1);
|
|
2100
|
+
});
|
|
2101
|
+
}
|
|
2102
|
+
//# sourceMappingURL=bts_distribution.js.map
|