gloomberb 0.20.0 → 0.20.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/patches/electrobun-devkit@2.0.5.patch +268 -8
- package/src/api-client/crypto-markets.ts +20 -2
- package/src/api-client/fund-facts.ts +23 -1
- package/src/api-client/types/filings-and-calls.ts +6 -0
- package/src/app/runtime/plugin-seed.ts +119 -0
- package/src/app/runtime/startup.ts +45 -9
- package/src/app.tsx +1 -0
- package/src/cli/board-coins.ts +38 -5
- package/src/cli/commands/crypto-hints.ts +8 -1
- package/src/cli/commands/market.ts +29 -26
- package/src/cli/commands/overview.ts +13 -6
- package/src/cli/commands/ticker.ts +61 -14
- package/src/cli/company-name-hint.ts +19 -0
- package/src/cli/entry.ts +10 -4
- package/src/cli/glossary.ts +25 -0
- package/src/cli/helpers.ts +4 -2
- package/src/cli/not-a-ticker.ts +26 -1
- package/src/cli/pane-functions/freshness.ts +45 -29
- package/src/cli/pane-functions/market-session.ts +14 -5
- package/src/cli/restore-plugins.ts +164 -51
- package/src/components/chart-table/header.tsx +10 -1
- package/src/components/chart-table/layout.ts +14 -5
- package/src/components/command-bar/panel/index.tsx +13 -0
- package/src/components/command-bar/panel/layout.ts +7 -0
- package/src/components/command-bar/panel/runtime.ts +1 -0
- package/src/components/command-bar/panel/types.ts +2 -0
- package/src/i18n/es.ts +3 -0
- package/src/i18n/ja.ts +3 -0
- package/src/i18n/ko.ts +3 -0
- package/src/i18n/zh-cn.ts +3 -0
- package/src/i18n/zh-tw.ts +3 -0
- package/src/market-data/fund-facts.ts +7 -1
- package/src/market-data/market/change-basis.ts +20 -0
- package/src/market-data/market/format.ts +62 -2
- package/src/market-data/market/futures-week.ts +3 -1
- package/src/plugins/builtin/chart-composer/headless.ts +57 -17
- package/src/plugins/builtin/chart-composer/session-range.ts +82 -3
- package/src/plugins/builtin/correlation/compute.ts +8 -2
- package/src/plugins/builtin/correlation/headless.ts +10 -9
- package/src/plugins/builtin/correlation/history.ts +30 -0
- package/src/plugins/builtin/correlation/matrix/model.ts +10 -10
- package/src/plugins/builtin/correlation/relationship/model.ts +3 -6
- package/src/plugins/builtin/correlation/relationship/pane.tsx +1 -2
- package/src/plugins/builtin/crypto-board/client.ts +6 -1
- package/src/plugins/builtin/crypto-board/defi-view.tsx +12 -1
- package/src/plugins/builtin/crypto-board/defi.ts +44 -7
- package/src/plugins/builtin/crypto-board/headless.ts +83 -12
- package/src/plugins/builtin/crypto-board/model.ts +30 -6
- package/src/plugins/builtin/crypto-board/pane.tsx +13 -2
- package/src/plugins/builtin/perps/headless.ts +8 -2
- package/src/plugins/builtin/risk-factors/index.tsx +2 -28
- package/src/plugins/builtin/risk-factors/lock-note.ts +58 -0
- package/src/plugins/builtin/risk-factors/pane.tsx +10 -3
- package/src/plugins/builtin/scanner/hilo-model.ts +4 -3
- package/src/plugins/builtin/sec/fund-facts.ts +45 -11
- package/src/plugins/builtin/sec/headless.ts +30 -1
- package/src/plugins/builtin/sec/index.tsx +26 -5
- package/src/plugins/builtin/shared/pro-lock-note.ts +5 -1
- package/src/plugins/builtin/ticker-detail/overview/model.ts +14 -6
- package/src/plugins/builtin/time-sales/headless.ts +23 -7
- package/src/plugins/builtin/time-sales/index.tsx +2 -2
- package/src/plugins/extracted-plugins.ts +49 -24
- package/src/plugins/installer.ts +220 -31
- package/src/plugins/running-installs.ts +34 -0
- package/src/plugins/seed-progress.ts +72 -0
- package/src/renderers/electrobun/bun/desktop/backend.ts +14 -0
- package/src/renderers/electrobun/bun/desktop/host-requests.ts +14 -7
- package/src/renderers/electrobun/bun/desktop/initialization.ts +24 -14
- package/src/renderers/electrobun/bun/index.ts +5 -0
- package/src/renderers/electrobun/bun/window/context-menu-thread.ts +84 -0
- package/src/renderers/electrobun/bun/window/native-call-thread.ts +224 -0
- package/src/renderers/electrobun/bun/window/native-timing.ts +10 -0
- package/src/renderers/electrobun/bun/window/script-for-webview.ts +15 -0
- package/src/renderers/electrobun/bun/window/webview-script-thread.ts +82 -0
- package/src/renderers/electrobun/shared/protocol.ts +13 -2
- package/src/renderers/electrobun/view/backend-rpc.ts +7 -0
- package/src/renderers/electrobun/view/cli-pane-shot-frame.tsx +1 -1
- package/src/renderers/electrobun/view/main.tsx +4 -3
- package/src/renderers/opentui/start.tsx +3 -0
- package/src/telemetry/stall-reports.ts +21 -4
- package/src/utils/main-thread-stall.ts +21 -5
- package/src/utils/perf-marks.ts +88 -9
- package/src/utils/reported-money.ts +9 -2
- package/src/utils/sec.ts +34 -3
- package/src/plugins/seed-notice.ts +0 -20
|
@@ -13,7 +13,7 @@ export const MATRIX_CELL_WIDTH = 15;
|
|
|
13
13
|
export const MIN_MATRIX_CELL_WIDTH = 7;
|
|
14
14
|
const MIN_CORRELATION_OBSERVATIONS = 5;
|
|
15
15
|
|
|
16
|
-
export type SeriesStatus = "loading" | "ready" | "insufficient" | "empty" | "error"
|
|
16
|
+
export type SeriesStatus = "loading" | "ready" | "insufficient" | "empty" | "error";
|
|
17
17
|
|
|
18
18
|
export interface CorrelationSeries {
|
|
19
19
|
symbol: string;
|
|
@@ -22,6 +22,7 @@ export interface CorrelationSeries {
|
|
|
22
22
|
basis?: ChangeBasis;
|
|
23
23
|
status: SeriesStatus;
|
|
24
24
|
observationCount: number;
|
|
25
|
+
/** Bars left out because their prices contradict each other, kept as the source reported them. */
|
|
25
26
|
integrity?: PriceHistoryIntegrity[];
|
|
26
27
|
loading?: boolean;
|
|
27
28
|
refreshError?: string;
|
|
@@ -82,14 +83,19 @@ export function getSeriesForEntry(
|
|
|
82
83
|
};
|
|
83
84
|
}
|
|
84
85
|
|
|
86
|
+
/**
|
|
87
|
+
* A ticker's daily closes as `history` reads them: a bar whose prices
|
|
88
|
+
* contradict each other is a gap (dailyCloses), not a reason to drop the
|
|
89
|
+
* whole series, and is kept in `integrity` as the source reported it.
|
|
90
|
+
*/
|
|
85
91
|
export function buildCorrelationSeries(symbol: string, history: readonly PricePoint[]): CorrelationSeries {
|
|
86
92
|
const integrity = history.flatMap((point) => { const issue = pricePointIntegrity(point); return issue ? [issue] : []; });
|
|
87
|
-
if (integrity.length) return { symbol, prices: [], observationCount: 0, status: "invalid", integrity };
|
|
88
93
|
const prices = dailyCloses(history);
|
|
89
94
|
const observationCount = Math.max(0, prices.length - 1);
|
|
90
95
|
return {
|
|
91
96
|
symbol, prices, observationCount,
|
|
92
97
|
status: observationCount < MIN_CORRELATION_OBSERVATIONS ? "insufficient" : "ready",
|
|
98
|
+
...(integrity.length ? { integrity } : {}),
|
|
93
99
|
};
|
|
94
100
|
}
|
|
95
101
|
|
|
@@ -106,7 +112,6 @@ export function rowHeaderColor(status: SeriesStatus): string {
|
|
|
106
112
|
switch (status) {
|
|
107
113
|
case "loading":
|
|
108
114
|
return colors.textDim;
|
|
109
|
-
case "invalid":
|
|
110
115
|
case "error":
|
|
111
116
|
case "empty":
|
|
112
117
|
return colors.negative;
|
|
@@ -142,10 +147,7 @@ export function buildCorrelationMatrix(
|
|
|
142
147
|
results.set(pairKey(rowSym, colSym), result);
|
|
143
148
|
if (rowIndex < colIndex) {
|
|
144
149
|
if (result.sampleSize > 0) sampleSizes.push(result.sampleSize);
|
|
145
|
-
if (
|
|
146
|
-
&& result.correlation == null && result.sampleSize < MIN_CORRELATION_OBSERVATIONS) {
|
|
147
|
-
hasThinPair = true;
|
|
148
|
-
}
|
|
150
|
+
if (result.correlation == null && result.sampleSize < MIN_CORRELATION_OBSERVATIONS) hasThinPair = true;
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
}
|
|
@@ -171,16 +173,14 @@ export function buildStatusSummary(
|
|
|
171
173
|
const loading = symbols.filter((symbol) => seriesBySymbol.get(symbol)?.status === "loading" || seriesBySymbol.get(symbol)?.loading);
|
|
172
174
|
const errors = [...byStatus("error"), ...byStatus("empty")];
|
|
173
175
|
const insufficient = byStatus("insufficient");
|
|
174
|
-
const invalid = byStatus("invalid");
|
|
175
176
|
|
|
176
|
-
if (invalid.length > 0) parts.push(`Inconsistent OHLC: ${formatSeriesSymbolList(invalid, seriesBySymbol)}`);
|
|
177
177
|
if (loading.length > 0) parts.push(`Loading: ${formatSeriesSymbolList(loading, seriesBySymbol)}`);
|
|
178
178
|
if (errors.length > 0) parts.push(`No data: ${formatSeriesSymbolList(errors, seriesBySymbol)}`);
|
|
179
179
|
if (insufficient.length > 0) parts.push(`Need history: ${formatSeriesSymbolList(insufficient, seriesBySymbol, true)}`);
|
|
180
180
|
|
|
181
181
|
if (sampleMin != null && sampleMax != null) {
|
|
182
182
|
parts.push(sampleMin === sampleMax ? `obs ${sampleMin}` : `obs ${sampleMin}-${sampleMax}`);
|
|
183
|
-
} else if (symbols.length >= 2
|
|
183
|
+
} else if (symbols.length >= 2) {
|
|
184
184
|
parts.push("No paired dates yet");
|
|
185
185
|
}
|
|
186
186
|
|
|
@@ -40,8 +40,8 @@ export interface RelationshipRegressionStats {
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export interface RelationshipAnalysis {
|
|
43
|
-
unavailableReason?: string;
|
|
44
43
|
correlationUnavailableReason?: string;
|
|
44
|
+
/** Bars left out of the window because their prices contradict each other, as the source reported them. */
|
|
45
45
|
integrity?: { left: PriceHistoryIntegrity[]; right: PriceHistoryIntegrity[] };
|
|
46
46
|
aligned: RelationshipAlignedPoint[];
|
|
47
47
|
returns: RelationshipReturnPoint[];
|
|
@@ -156,12 +156,8 @@ export function buildRelationshipAnalysis(
|
|
|
156
156
|
const issues = (points: PricePoint[]) => points.flatMap((point) => {
|
|
157
157
|
const issue = pricePointIntegrity(point); return issue ? [issue] : [];
|
|
158
158
|
});
|
|
159
|
+
// Bars whose prices contradict each other are gaps, as history leaves them blank (dailyCloses); kept for the export.
|
|
159
160
|
const integrity = { left: issues(leftPoints), right: issues(rightPoints) };
|
|
160
|
-
if (integrity.left.length || integrity.right.length) return {
|
|
161
|
-
aligned: [], returns: [], ratioPoints: [], correlationPoints: [], scatterPoints: [],
|
|
162
|
-
stats: null, latestRatio: null, latestCorrelation: null, integrity,
|
|
163
|
-
unavailableReason: "Inconsistent OHLC history; relationship calculations are unavailable for this window.",
|
|
164
|
-
};
|
|
165
161
|
const aligned = alignRelationshipPrices(leftPoints, rightPoints);
|
|
166
162
|
const returns = buildRelationshipReturns(aligned);
|
|
167
163
|
const correlationPoints = buildRollingCorrelationPoints(returns, correlationWindow);
|
|
@@ -186,6 +182,7 @@ export function buildRelationshipAnalysis(
|
|
|
186
182
|
latestRatio: aligned.at(-1)?.ratio ?? null,
|
|
187
183
|
latestCorrelation,
|
|
188
184
|
...(correlationUnavailableReason ? { correlationUnavailableReason } : {}),
|
|
185
|
+
...(integrity.left.length || integrity.right.length ? { integrity } : {}),
|
|
189
186
|
};
|
|
190
187
|
}
|
|
191
188
|
|
|
@@ -238,7 +238,6 @@ export function RelationshipGraphPane({ focused, width, height }: PaneProps) {
|
|
|
238
238
|
registrationId: "relationship-warnings", focused,
|
|
239
239
|
notices: [
|
|
240
240
|
...(error ? [`${error}${data && updatedAt ? ` Retained history retrieved ${new Date(updatedAt).toISOString()}.` : ""}`] : []),
|
|
241
|
-
...(analysis?.unavailableReason ? [analysis.unavailableReason] : []),
|
|
242
241
|
...(analysis?.correlationUnavailableReason ? [analysis.correlationUnavailableReason] : []),
|
|
243
242
|
],
|
|
244
243
|
});
|
|
@@ -275,7 +274,7 @@ export function RelationshipGraphPane({ focused, width, height }: PaneProps) {
|
|
|
275
274
|
return (
|
|
276
275
|
<Box flexDirection="column" width={width} height={height}>
|
|
277
276
|
{queryBar}
|
|
278
|
-
<PaneStatusBody loading={loading} error={loading ? null :
|
|
277
|
+
<PaneStatusBody loading={loading} error={loading ? null : error} subject="relationship history" empty emptyTitle="No overlapping price history." />
|
|
279
278
|
</Box>
|
|
280
279
|
);
|
|
281
280
|
}
|
|
@@ -300,6 +300,8 @@ const tvlValue = (value: unknown) => value === null || (isFiniteNumber(value) &&
|
|
|
300
300
|
const changes = (entry: { change7d: unknown; change7dPercent: unknown; change30d: unknown; change30dPercent: unknown }) =>
|
|
301
301
|
[entry.change7d, entry.change7dPercent, entry.change30d, entry.change30dPercent].every(nullableNumber);
|
|
302
302
|
|
|
303
|
+
const INCOME_FIELDS = ["fees24h", "fees7d", "fees30d", "revenue24h", "revenue7d", "revenue30d"] as const;
|
|
304
|
+
|
|
303
305
|
export function validateDefiTvl(data: DefiTvlPayload): DefiTvlPayload {
|
|
304
306
|
const history = data?.history;
|
|
305
307
|
if (
|
|
@@ -323,8 +325,11 @@ export function validateDefiTvl(data: DefiTvlPayload): DefiTvlPayload {
|
|
|
323
325
|
&& isFiniteNumber(protocol.tvl)
|
|
324
326
|
&& protocol.tvl >= 0
|
|
325
327
|
&& nullableNumber(protocol.change1dPercent)
|
|
326
|
-
&& changes(protocol)
|
|
328
|
+
&& changes(protocol)
|
|
329
|
+
// Fees and revenue: absent from servers before them, otherwise USD or null.
|
|
330
|
+
&& INCOME_FIELDS.every((field) => protocol[field] === undefined || (nullableNumber(protocol[field]) && !((protocol[field] ?? 0) < 0))))
|
|
327
331
|
|| !nullableInstant(data.protocolsAsOf)
|
|
332
|
+
|| !(data.incomeAsOf === undefined || nullableInstant(data.incomeAsOf))
|
|
328
333
|
|| !Array.isArray(data.chains)
|
|
329
334
|
|| data.chains.length > 500
|
|
330
335
|
|| !data.chains.every((chain) => !!chain
|
|
@@ -18,6 +18,7 @@ import { formatCompact, formatCompactAmount } from "../../../utils/format";
|
|
|
18
18
|
import { usePluginPaneState } from "../../runtime";
|
|
19
19
|
import {
|
|
20
20
|
buildDefiColumns,
|
|
21
|
+
defiHasIncome,
|
|
21
22
|
buildDefiRows,
|
|
22
23
|
DEFAULT_DEFI_SORT,
|
|
23
24
|
DEFI_LISTS,
|
|
@@ -75,6 +76,15 @@ function renderDefiCell(row: DefiRow, column: DefiColumn): DataTableCell {
|
|
|
75
76
|
return { text: row.share == null ? "—" : `${row.share.toFixed(2)}%`, color: colors.textDim };
|
|
76
77
|
case "chains":
|
|
77
78
|
return { text: row.chains == null ? "—" : String(row.chains), color: colors.textDim };
|
|
79
|
+
case "fees24h":
|
|
80
|
+
case "fees7d":
|
|
81
|
+
case "fees30d":
|
|
82
|
+
case "revenue24h":
|
|
83
|
+
case "revenue7d":
|
|
84
|
+
case "revenue30d": {
|
|
85
|
+
const value = row[column.id];
|
|
86
|
+
return value == null ? { text: "—", color: colors.textDim } : { text: formatTvl(value) };
|
|
87
|
+
}
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
|
|
@@ -118,7 +128,8 @@ export function DefiTvlView({
|
|
|
118
128
|
const [selectedId, setSelectedId] = usePluginPaneState<string | null>("defiSelected", null);
|
|
119
129
|
const [sort, setSort] = useState<DefiSortPreference>(DEFAULT_DEFI_SORT);
|
|
120
130
|
const rows = useMemo(() => sortDefiRows(buildDefiRows(payload, list), sort), [list, payload, sort]);
|
|
121
|
-
const
|
|
131
|
+
const income = defiHasIncome(payload);
|
|
132
|
+
const columns = useMemo(() => buildDefiColumns(width, list, income), [income, list, width]);
|
|
122
133
|
// A chain's figures are the total's day, which its figure dates; protocols are read live, so they say when.
|
|
123
134
|
const listAsOf = list === "protocol" ? defiListAsOf(payload, list) : null;
|
|
124
135
|
|
|
@@ -34,8 +34,17 @@ export interface DefiRow {
|
|
|
34
34
|
share: number | null;
|
|
35
35
|
/** How many chains a protocol is on; null for a chain. */
|
|
36
36
|
chains: number | null;
|
|
37
|
+
/** A protocol's fees and revenue, USD over 24 hours, 7 and 30 days; null for a chain and where the source has none. */
|
|
38
|
+
fees24h: number | null;
|
|
39
|
+
fees7d: number | null;
|
|
40
|
+
fees30d: number | null;
|
|
41
|
+
revenue24h: number | null;
|
|
42
|
+
revenue7d: number | null;
|
|
43
|
+
revenue30d: number | null;
|
|
37
44
|
}
|
|
38
45
|
|
|
46
|
+
const NO_INCOME = { fees24h: null, fees7d: null, fees30d: null, revenue24h: null, revenue7d: null, revenue30d: null } as const;
|
|
47
|
+
|
|
39
48
|
const protocolRow = (protocol: DefiTvlProtocol, index: number): DefiRow => ({
|
|
40
49
|
id: `protocol:${protocol.name}`,
|
|
41
50
|
rank: index + 1,
|
|
@@ -49,6 +58,12 @@ const protocolRow = (protocol: DefiTvlProtocol, index: number): DefiRow => ({
|
|
|
49
58
|
change30dPercent: protocol.change30dPercent,
|
|
50
59
|
share: null,
|
|
51
60
|
chains: protocol.chains,
|
|
61
|
+
fees24h: protocol.fees24h ?? null,
|
|
62
|
+
fees7d: protocol.fees7d ?? null,
|
|
63
|
+
fees30d: protocol.fees30d ?? null,
|
|
64
|
+
revenue24h: protocol.revenue24h ?? null,
|
|
65
|
+
revenue7d: protocol.revenue7d ?? null,
|
|
66
|
+
revenue30d: protocol.revenue30d ?? null,
|
|
52
67
|
});
|
|
53
68
|
|
|
54
69
|
const chainRow = (chain: DefiTvlChain, index: number): DefiRow => ({
|
|
@@ -64,6 +79,7 @@ const chainRow = (chain: DefiTvlChain, index: number): DefiRow => ({
|
|
|
64
79
|
change30dPercent: chain.change30dPercent,
|
|
65
80
|
share: chain.share,
|
|
66
81
|
chains: null,
|
|
82
|
+
...NO_INCOME,
|
|
67
83
|
});
|
|
68
84
|
|
|
69
85
|
const rowsByPayload = new WeakMap<DefiTvlPayload, Record<DefiList, DefiRow[]>>();
|
|
@@ -161,7 +177,13 @@ type DefiColumnId =
|
|
|
161
177
|
| "change30d"
|
|
162
178
|
| "change30dPercent"
|
|
163
179
|
| "share"
|
|
164
|
-
| "chains"
|
|
180
|
+
| "chains"
|
|
181
|
+
| "fees24h"
|
|
182
|
+
| "fees7d"
|
|
183
|
+
| "fees30d"
|
|
184
|
+
| "revenue24h"
|
|
185
|
+
| "revenue7d"
|
|
186
|
+
| "revenue30d";
|
|
165
187
|
|
|
166
188
|
export type DefiColumn = DataTableColumn & { id: DefiColumnId };
|
|
167
189
|
|
|
@@ -201,6 +223,13 @@ const PROTOCOL_COLUMNS: DefiColumnSpec[] = [
|
|
|
201
223
|
{ id: "change30d", label: "30D", width: 8, align: "right", optional: 4 },
|
|
202
224
|
{ id: "change30dPercent", label: "30D%", width: 8, align: "right", optional: 1 },
|
|
203
225
|
{ id: "chains", label: "CHAINS", width: 6, align: "right", optional: 6 },
|
|
226
|
+
// Fees and revenue, USD, in pairs: the 30-day figures stay longest, the 7-day ones leave first.
|
|
227
|
+
{ id: "fees24h", label: "FEES 24H", width: 8, align: "right", optional: 8 },
|
|
228
|
+
{ id: "fees7d", label: "FEES 7D", width: 8, align: "right", optional: 9 },
|
|
229
|
+
{ id: "fees30d", label: "FEES 30D", width: 8, align: "right", optional: 7 },
|
|
230
|
+
{ id: "revenue24h", label: "REV 24H", width: 8, align: "right", optional: 8 },
|
|
231
|
+
{ id: "revenue7d", label: "REV 7D", width: 8, align: "right", optional: 9 },
|
|
232
|
+
{ id: "revenue30d", label: "REV 30D", width: 8, align: "right", optional: 7 },
|
|
204
233
|
];
|
|
205
234
|
|
|
206
235
|
const CHAIN_COLUMNS: DefiColumnSpec[] = [
|
|
@@ -217,14 +246,22 @@ const CHAIN_COLUMNS: DefiColumnSpec[] = [
|
|
|
217
246
|
|
|
218
247
|
const MAX_NAME_WIDTH = 26;
|
|
219
248
|
|
|
249
|
+
const INCOME_COLUMNS = new Set<DefiColumnId>(["fees24h", "fees7d", "fees30d", "revenue24h", "revenue7d", "revenue30d"]);
|
|
250
|
+
|
|
251
|
+
/** Whether the board carries the protocols' fees and revenue: a server before them, or a read that failed, has none to show. */
|
|
252
|
+
export function defiHasIncome(payload: DefiTvlPayload | null | undefined): boolean {
|
|
253
|
+
return !!payload?.incomeAsOf;
|
|
254
|
+
}
|
|
255
|
+
|
|
220
256
|
/**
|
|
221
|
-
* Optional columns leave in a fixed order as the pane narrows
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
257
|
+
* Optional columns leave in a fixed order as the pane narrows: a protocol's
|
|
258
|
+
* fees and revenue first, in pairs (7D, 24H, then 30D), then dollar changes before
|
|
259
|
+
* percents as on the stablecoin list (the chain count and the day's move, the
|
|
260
|
+
* 30D then 7D dollar change, the category, the 30D percent); the name takes
|
|
261
|
+
* what width is left.
|
|
225
262
|
*/
|
|
226
|
-
export function buildDefiColumns(width: number, list: DefiList): DefiColumn[] {
|
|
227
|
-
const specs = list === "chain" ? CHAIN_COLUMNS : PROTOCOL_COLUMNS;
|
|
263
|
+
export function buildDefiColumns(width: number, list: DefiList, income = false): DefiColumn[] {
|
|
264
|
+
const specs = list === "chain" ? CHAIN_COLUMNS : income ? PROTOCOL_COLUMNS : PROTOCOL_COLUMNS.filter((column) => !INCOME_COLUMNS.has(column.id));
|
|
228
265
|
const optional = specs.flatMap((column) => column.optional ?? []).sort((a, b) => b - a);
|
|
229
266
|
const dropped = new Set<number>();
|
|
230
267
|
const visible = () => specs.filter((column) => !column.optional || !dropped.has(column.optional));
|
|
@@ -4,14 +4,16 @@ import type { HeadlessPaneDefinition } from "../../../types/plugin";
|
|
|
4
4
|
import { formatCompact, formatCompactAmount } from "../../../utils/format";
|
|
5
5
|
import { errorMessage } from "../../../utils/errors";
|
|
6
6
|
import { fetchCryptoMarkets, fetchDefiTvl, fetchStablecoinSupply } from "./client";
|
|
7
|
-
import { buildDefiRows, defiHistoryRows, defiHistoryStart, defiSummaryLine, type DefiList, type DefiRow } from "./defi";
|
|
7
|
+
import { buildDefiRows, defiHasIncome, defiHistoryRows, defiHistoryStart, defiSummaryLine, type DefiList, type DefiRow } from "./defi";
|
|
8
8
|
import {
|
|
9
9
|
buildCryptoRows,
|
|
10
10
|
CRYPTO_BOARD_FRESHNESS,
|
|
11
11
|
CRYPTO_CHANGE_BASIS_LABEL,
|
|
12
|
+
CRYPTO_SORT_OPTIONS,
|
|
12
13
|
formatCryptoPercent,
|
|
13
14
|
formatDayRangeTime,
|
|
14
15
|
formatOffPeg,
|
|
16
|
+
sortCryptoRows,
|
|
15
17
|
withCryptoSupply,
|
|
16
18
|
} from "./model";
|
|
17
19
|
import { stackedSupply, supplyByCode, supplyFailure, supplyHistoryRows, supplySummaryLine } from "./supply";
|
|
@@ -104,11 +106,24 @@ function supplyMetadata(payload: StablecoinSupplyPayload) {
|
|
|
104
106
|
};
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
// Every DeFi figure is in US dollars: the text header says so beside TVL, and each exported row names USD.
|
|
110
|
+
const TVL_COLUMN: HeadlessPaneColumn = { key: "tvl", header: "TVL", textHeader: "TVL USD", align: "right", format: compact };
|
|
111
|
+
|
|
112
|
+
/** A protocol's fees and revenue, USD: the 30-day figures stay in a narrow table longest, the 24-hour and 7-day ones only where they fit. */
|
|
113
|
+
const INCOME_COLUMNS: HeadlessPaneColumn[] = [
|
|
114
|
+
{ key: "fees24h", header: "Fees 24h", literalHeader: true, align: "right", format: compact, stackPriority: 6, stackRows: 0 },
|
|
115
|
+
{ key: "fees7d", header: "Fees 7D", literalHeader: true, align: "right", format: compact, stackPriority: 7, stackRows: 0 },
|
|
116
|
+
{ key: "fees30d", header: "Fees 30D", literalHeader: true, align: "right", format: compact, stackPriority: 5, stackRows: 0 },
|
|
117
|
+
{ key: "revenue24h", header: "Revenue 24h", literalHeader: true, align: "right", format: compact, stackPriority: 6, stackRows: 0 },
|
|
118
|
+
{ key: "revenue7d", header: "Revenue 7D", literalHeader: true, align: "right", format: compact, stackPriority: 7, stackRows: 0 },
|
|
119
|
+
{ key: "revenue30d", header: "Revenue 30D", literalHeader: true, align: "right", format: compact, stackPriority: 5, stackRows: 0 },
|
|
120
|
+
];
|
|
121
|
+
|
|
107
122
|
const PROTOCOL_COLUMNS: HeadlessPaneColumn[] = [
|
|
108
123
|
{ key: "rank", header: "#", align: "right" },
|
|
109
124
|
{ key: "name", header: "Protocol" },
|
|
110
125
|
{ key: "category", header: "Category", stackPriority: 2, stackRows: 0 },
|
|
111
|
-
|
|
126
|
+
TVL_COLUMN,
|
|
112
127
|
{ key: "change1dPercent", header: "1D %", align: "right", format: percent, stackPriority: 3, stackRows: 0 },
|
|
113
128
|
{ key: "change7d", header: "7D", align: "right", format: signedCompact, stackPriority: 1, stackRows: 0 },
|
|
114
129
|
{ key: "change7dPercent", header: "7D %", align: "right", format: percent },
|
|
@@ -117,11 +132,13 @@ const PROTOCOL_COLUMNS: HeadlessPaneColumn[] = [
|
|
|
117
132
|
{ key: "chains", header: "Chains", align: "right", stackPriority: 4, stackRows: 0 },
|
|
118
133
|
];
|
|
119
134
|
|
|
135
|
+
const PROTOCOL_INCOME_COLUMNS: HeadlessPaneColumn[] = [...PROTOCOL_COLUMNS, ...INCOME_COLUMNS];
|
|
136
|
+
|
|
120
137
|
const CHAIN_COLUMNS: HeadlessPaneColumn[] = [
|
|
121
138
|
{ key: "rank", header: "#", align: "right" },
|
|
122
139
|
{ key: "name", header: "Chain" },
|
|
123
140
|
{ key: "token", header: "Token", stackPriority: 2, stackRows: 0 },
|
|
124
|
-
|
|
141
|
+
TVL_COLUMN,
|
|
125
142
|
{ key: "change7d", header: "7D", align: "right", format: signedCompact, stackPriority: 1, stackRows: 0 },
|
|
126
143
|
{ key: "change7dPercent", header: "7D %", align: "right", format: percent },
|
|
127
144
|
{ key: "change30d", header: "30D", align: "right", format: signedCompact, stackPriority: 0.5, stackRows: 0 },
|
|
@@ -129,7 +146,7 @@ const CHAIN_COLUMNS: HeadlessPaneColumn[] = [
|
|
|
129
146
|
{ key: "share", header: "Share", align: "right", format: share },
|
|
130
147
|
];
|
|
131
148
|
|
|
132
|
-
function defiRecord(row: DefiRow, list: DefiList) {
|
|
149
|
+
function defiRecord(row: DefiRow, list: DefiList, income: boolean) {
|
|
133
150
|
return {
|
|
134
151
|
rank: row.rank,
|
|
135
152
|
name: row.name,
|
|
@@ -140,16 +157,39 @@ function defiRecord(row: DefiRow, list: DefiList) {
|
|
|
140
157
|
change30d: row.change30d,
|
|
141
158
|
change30dPercent: row.change30dPercent,
|
|
142
159
|
...(list === "chain" ? { share: row.share } : {}),
|
|
160
|
+
...(list === "protocol" && income ? {
|
|
161
|
+
fees24h: row.fees24h, fees7d: row.fees7d, fees30d: row.fees30d,
|
|
162
|
+
revenue24h: row.revenue24h, revenue7d: row.revenue7d, revenue30d: row.revenue30d,
|
|
163
|
+
} : {}),
|
|
164
|
+
unit: "USD",
|
|
143
165
|
};
|
|
144
166
|
}
|
|
145
167
|
|
|
168
|
+
const defiColumns = (list: DefiList, income: boolean) =>
|
|
169
|
+
list === "chain" ? CHAIN_COLUMNS : income ? PROTOCOL_INCOME_COLUMNS : PROTOCOL_COLUMNS;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* The note under a protocol list: one as-of date for the whole list. Read
|
|
173
|
+
* within an hour of the board's day closing (the daily read, 00:00 UTC), the
|
|
174
|
+
* protocols' figures are that day's close and the source line dates them; a
|
|
175
|
+
* later read (a retry) says when it was.
|
|
176
|
+
*/
|
|
177
|
+
function protocolsNote(payload: DefiTvlPayload): string {
|
|
178
|
+
const counted = "Protocols are read at the day's close; their versions are counted together.";
|
|
179
|
+
const read = payload.protocolsAsOf ? Date.parse(payload.protocolsAsOf) : Number.NaN;
|
|
180
|
+
const closed = payload.asOf ? Date.parse(`${payload.asOf}T00:00:00Z`) + 86_400_000 : Number.NaN;
|
|
181
|
+
if (!Number.isFinite(read) || (Number.isFinite(closed) && read >= closed && read - closed <= 3_600_000)) return counted;
|
|
182
|
+
return `Protocols as of ${isoMinute(payload.protocolsAsOf)}, the source's latest; their versions are counted together.`;
|
|
183
|
+
}
|
|
184
|
+
|
|
146
185
|
/** The other list and the total's daily history, for `--csv`: one file carries the whole tab. */
|
|
147
186
|
function defiExportTables(payload: DefiTvlPayload, list: DefiList): HeadlessExportTable[] {
|
|
148
187
|
const other: DefiList = list === "chain" ? "protocol" : "chain";
|
|
149
|
-
const
|
|
188
|
+
const income = defiHasIncome(payload);
|
|
189
|
+
const otherRows = buildDefiRows(payload, other).map((row) => defiRecord(row, other, income));
|
|
150
190
|
const history = defiHistoryRows(payload);
|
|
151
191
|
return [
|
|
152
|
-
...(otherRows.length ? [{ title: other === "chain" ? "DeFi TVL by chain" : "DeFi TVL by protocol", unit: "USD", columns: other
|
|
192
|
+
...(otherRows.length ? [{ title: other === "chain" ? "DeFi TVL by chain" : "DeFi TVL by protocol", unit: "USD", columns: defiColumns(other, income), rows: otherRows }] : []),
|
|
153
193
|
...(history.length ? [{
|
|
154
194
|
title: "Total DeFi TVL",
|
|
155
195
|
unit: "USD",
|
|
@@ -167,15 +207,17 @@ function defiExportTables(payload: DefiTvlPayload, list: DefiList): HeadlessExpo
|
|
|
167
207
|
*/
|
|
168
208
|
async function loadDefi(list: DefiList, ctx: Parameters<HeadlessPaneDefinition<"rows">["load"]>[1]) {
|
|
169
209
|
const payload = await fetchDefiTvl(ctx.apiClient);
|
|
170
|
-
const
|
|
210
|
+
const income = defiHasIncome(payload);
|
|
211
|
+
const rows = buildDefiRows(payload, list).map((row) => defiRecord(row, list, income));
|
|
171
212
|
const summary = defiSummaryLine(payload);
|
|
172
213
|
const exportTables = defiExportTables(payload, list);
|
|
173
214
|
return {
|
|
174
215
|
rows,
|
|
175
|
-
columns: list
|
|
216
|
+
columns: defiColumns(list, income),
|
|
217
|
+
rowUnitKey: "unit",
|
|
176
218
|
...(exportTables.length ? { exportTables } : {}),
|
|
177
219
|
errors: payload.warnings,
|
|
178
|
-
...(list === "protocol" && payload.protocolsAsOf ? { notes: [
|
|
220
|
+
...(list === "protocol" && payload.protocolsAsOf ? { notes: [protocolsNote(payload)] } : {}),
|
|
179
221
|
empty: list === "chain" ? "No chains returned." : "No protocols returned.",
|
|
180
222
|
freshness: {
|
|
181
223
|
source: "Gloom Cloud",
|
|
@@ -192,6 +234,8 @@ async function loadDefi(list: DefiList, ctx: Parameters<HeadlessPaneDefinition<"
|
|
|
192
234
|
asOf: payload.asOf,
|
|
193
235
|
fetchedAt: payload.fetchedAt,
|
|
194
236
|
protocolsAsOf: payload.protocolsAsOf,
|
|
237
|
+
...(payload.incomeAsOf !== undefined ? { incomeAsOf: payload.incomeAsOf } : {}),
|
|
238
|
+
unit: "USD",
|
|
195
239
|
source: payload.source,
|
|
196
240
|
total: payload.total,
|
|
197
241
|
historyStart: defiHistoryStart(payload),
|
|
@@ -226,6 +270,16 @@ export const cryptoBoardHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
226
270
|
],
|
|
227
271
|
example: "--list defi --by chain",
|
|
228
272
|
pluginState: { pluginId: "market-overview", key: "defiList" },
|
|
273
|
+
}, {
|
|
274
|
+
key: "sort",
|
|
275
|
+
// No default: a missing one is the board's market-cap order, which every list keeps.
|
|
276
|
+
description: "Row order: market cap (the default), or offpeg for the stablecoins furthest off their peg first, either way, with --list stablecoin.",
|
|
277
|
+
type: "enum",
|
|
278
|
+
values: [
|
|
279
|
+
{ value: "mcap", aliases: ["cap", "marketcap", "rank"] },
|
|
280
|
+
{ value: "offpeg", aliases: ["off-peg", "peg", "depeg"] },
|
|
281
|
+
],
|
|
282
|
+
example: "--list stablecoin --sort offpeg",
|
|
229
283
|
}],
|
|
230
284
|
columns: COIN_COLUMNS,
|
|
231
285
|
describe: (args) => `Crypto | ${args.options.list === "defi" ? `DeFi TVL by ${args.options.by === "chain" ? "chain" : "protocol"}` : args.options.list === "stablecoin" ? "Stablecoins" : "Coins"}`,
|
|
@@ -233,10 +287,19 @@ export const cryptoBoardHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
233
287
|
aliases: ["CRYP"],
|
|
234
288
|
dataRequirements: ["Gloom Cloud crypto markets"],
|
|
235
289
|
},
|
|
290
|
+
// The pane opens on the order asked for, as its header sorts it.
|
|
291
|
+
shotState: (args, _load, given) => {
|
|
292
|
+
const sort = given.has("sort") ? CRYPTO_SORT_OPTIONS[String(args.options.sort)] : undefined;
|
|
293
|
+
return sort ? { pluginState: { "market-overview": { sort } } } : {};
|
|
294
|
+
},
|
|
236
295
|
// The board as the server read it, at most 15 seconds before; the pane streams, the report does not.
|
|
237
296
|
// Each row keeps the time of its own last trade, so a coin that has not traded lately reads its age.
|
|
238
297
|
freshness: CRYPTO_BOARD_FRESHNESS,
|
|
239
298
|
async load(args, ctx) {
|
|
299
|
+
const offPeg = args.options.sort === "offpeg";
|
|
300
|
+
if (offPeg && args.options.list !== "stablecoin") {
|
|
301
|
+
throw new Error("--sort offpeg orders the stablecoins by how far each is off its peg: add --list stablecoin.");
|
|
302
|
+
}
|
|
240
303
|
if (args.options.list === "defi") return loadDefi(args.options.by === "chain" ? "chain" : "protocol", ctx);
|
|
241
304
|
const kind = args.options.list === "stablecoin" ? "stablecoin" : "coin" satisfies CryptoAssetKind;
|
|
242
305
|
// Supply is its own request: a failure there leaves the prices whole.
|
|
@@ -247,7 +310,8 @@ export const cryptoBoardHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
247
310
|
: null,
|
|
248
311
|
]);
|
|
249
312
|
const supply = supplyResult && "payload" in supplyResult ? supplyResult.payload : null;
|
|
250
|
-
const
|
|
313
|
+
const built = withCryptoSupply(buildCryptoRows(data.assets, kind, NO_QUOTES), supplyByCode(supply));
|
|
314
|
+
const rows = sortCryptoRows(built, CRYPTO_SORT_OPTIONS[String(args.options.sort ?? "mcap")] ?? { columnId: null, direction: "asc" }).map((row) => ({
|
|
251
315
|
rank: row.rank,
|
|
252
316
|
symbol: row.asset.symbol,
|
|
253
317
|
code: row.code,
|
|
@@ -282,12 +346,19 @@ export const cryptoBoardHeadless: HeadlessPaneDefinition<"rows"> = {
|
|
|
282
346
|
pegType: row.pegType,
|
|
283
347
|
} : {}),
|
|
284
348
|
}));
|
|
285
|
-
const metadata = {
|
|
286
|
-
|
|
349
|
+
const metadata = {
|
|
350
|
+
list: kind, status: data.status, asOf: data.asOf, generatedAt: data.generatedAt, changeBasis: CRYPTO_CHANGE_BASIS_LABEL,
|
|
351
|
+
...(data.marketCapBasis ? { marketCapBasis: data.marketCapBasis } : {}),
|
|
352
|
+
...(offPeg ? { sort: "offpeg" } : {}),
|
|
353
|
+
};
|
|
354
|
+
// The source's own market cap can be on another supply (Toncoin's was 1.5 times price by circulating supply): the server's is circulating, and says so.
|
|
355
|
+
const capNote = data.marketCapBasis === "circulating" ? ["Market cap is price times circulating supply."] : [];
|
|
356
|
+
if (kind !== "stablecoin") return { rows, errors: data.warnings, ...(capNote.length ? { notes: capNote } : {}), metadata };
|
|
287
357
|
const summary = supply ? supplySummaryLine(supply) : null;
|
|
288
358
|
const history = supply ? supplyHistoryTable(supply) : null;
|
|
289
359
|
// A supply outage is a caveat, not a failure: the prices are the report, and they are complete.
|
|
290
360
|
const notes = [
|
|
361
|
+
...capNote,
|
|
291
362
|
...(supply?.warnings ?? []),
|
|
292
363
|
...(supplyResult && "error" in supplyResult
|
|
293
364
|
? [`${supplyFailure(errorMessage(supplyResult.error)).replace(/\.$/, "")}; the prices are complete without it.`]
|
|
@@ -88,9 +88,9 @@ export interface CryptoRow extends CryptoRowSupply {
|
|
|
88
88
|
delayed: boolean;
|
|
89
89
|
/** A stablecoin's peg; null for a coin, or a server that does not send it. */
|
|
90
90
|
peg: CryptoPeg | null;
|
|
91
|
-
/** `USD`, `EUR 1.1242` (the target in dollars), `USD yield`; empty without a peg. */
|
|
91
|
+
/** `USD`, `EUR 1.1242` (the target in dollars), `USD yield`, `USD bond`; empty without a peg. */
|
|
92
92
|
pegText: string;
|
|
93
|
-
/** How far the price is off its target, in basis points; null when it accrues yield or the target is unknown. */
|
|
93
|
+
/** How far the price is off its target, in basis points; null when it accrues (yield, a bond) or the target is unknown. */
|
|
94
94
|
offPegBp: number | null;
|
|
95
95
|
/** The 24-hour low and high, the price shown included, and when each traded (epoch ms). */
|
|
96
96
|
low24h: number | null;
|
|
@@ -227,17 +227,18 @@ function buildCryptoRow(
|
|
|
227
227
|
/**
|
|
228
228
|
* What a stablecoin's price is measured against: `USD`; a coin on another
|
|
229
229
|
* currency by its target in dollars, `EUR 1.1242`, so EURC at 1.1234 does not
|
|
230
|
-
* read as a 12% premium; a coin whose yield accrues into its price (USDY)
|
|
231
|
-
*
|
|
230
|
+
* read as a 12% premium; a coin whose yield accrues into its price (USDY) or a
|
|
231
|
+
* bond token priced toward par at maturity (BUSD0) is marked by its kind and
|
|
232
|
+
* has no par to be off.
|
|
232
233
|
*/
|
|
233
234
|
export function formatPegTarget(peg: CryptoPeg | null | undefined): string {
|
|
234
235
|
if (!peg) return "";
|
|
235
|
-
if (peg.accrues) return `${peg.currency} yield`;
|
|
236
|
+
if (peg.accrues) return `${peg.currency} ${peg.kind === "bond" ? "bond" : "yield"}`;
|
|
236
237
|
if (peg.currency === "USD") return "USD";
|
|
237
238
|
return peg.price == null ? peg.currency : `${peg.currency} ${peg.price.toFixed(4)}`;
|
|
238
239
|
}
|
|
239
240
|
|
|
240
|
-
/** Basis points off the peg, to a tenth: (price / target - 1) x 10,000. Null when the coin accrues yield or the target is unknown. */
|
|
241
|
+
/** Basis points off the peg, to a tenth: (price / target - 1) x 10,000. Null when the coin accrues (yield, a bond) or the target is unknown. */
|
|
241
242
|
export function offPegBasisPoints(price: number, peg: CryptoPeg | null | undefined): number | null {
|
|
242
243
|
if (!peg || peg.accrues || peg.price == null || !(peg.price > 0) || !(price > 0)) return null;
|
|
243
244
|
return toBasisPoints((price / peg.price - 1) * 100, 1);
|
|
@@ -409,6 +410,25 @@ export interface CryptoSortPreference {
|
|
|
409
410
|
|
|
410
411
|
export const DEFAULT_CRYPTO_SORT: CryptoSortPreference = { columnId: null, direction: "asc" };
|
|
411
412
|
|
|
413
|
+
/**
|
|
414
|
+
* `--sort` of `fn CRYP` and `shot CRYP` as the pane's header sorts it: the
|
|
415
|
+
* board's market-cap order, or off peg largest first, either side of par.
|
|
416
|
+
*/
|
|
417
|
+
export const CRYPTO_SORT_OPTIONS: Readonly<Record<string, CryptoSortPreference>> = {
|
|
418
|
+
mcap: DEFAULT_CRYPTO_SORT,
|
|
419
|
+
offpeg: { columnId: "offPegBp", direction: "desc" },
|
|
420
|
+
};
|
|
421
|
+
|
|
422
|
+
/** A saved sort as the pane reads it back; anything else is the board's order. */
|
|
423
|
+
export function readCryptoSort(value: unknown): CryptoSortPreference {
|
|
424
|
+
if (!value || typeof value !== "object") return DEFAULT_CRYPTO_SORT;
|
|
425
|
+
const { columnId, direction } = value as Partial<CryptoSortPreference>;
|
|
426
|
+
return (columnId === null || (typeof columnId === "string" && SORTABLE_COLUMNS.has(columnId)))
|
|
427
|
+
&& (direction === "asc" || direction === "desc")
|
|
428
|
+
? { columnId: columnId as CryptoColumnId | null, direction }
|
|
429
|
+
: DEFAULT_CRYPTO_SORT;
|
|
430
|
+
}
|
|
431
|
+
|
|
412
432
|
const TEXT_COLUMNS = new Set<CryptoColumnId>(["rank", "code", "name", "pegText"]);
|
|
413
433
|
|
|
414
434
|
/** Numbers open largest-first (top gainers, biggest caps); names open A-Z. */
|
|
@@ -492,6 +512,10 @@ const STABLECOIN_SUPPLY_COLUMN_SPECS: CryptoColumnSpec[] = [
|
|
|
492
512
|
{ id: "supplyShare", label: "SHARE", width: 7, align: "right", optional: 3.8 },
|
|
493
513
|
];
|
|
494
514
|
|
|
515
|
+
/** Every column a header click sorts by: all but the sparkline. */
|
|
516
|
+
const SORTABLE_COLUMNS = new Set<string>([...COLUMN_SPECS, ...STABLECOIN_COLUMN_SPECS, ...STABLECOIN_SUPPLY_COLUMN_SPECS]
|
|
517
|
+
.map((column) => column.id).filter((id) => id !== "trend"));
|
|
518
|
+
|
|
495
519
|
const MAX_NAME_WIDTH = 24;
|
|
496
520
|
|
|
497
521
|
/**
|
|
@@ -54,6 +54,7 @@ import {
|
|
|
54
54
|
formatOffPeg,
|
|
55
55
|
nextCryptoSort,
|
|
56
56
|
offPegSeverity,
|
|
57
|
+
readCryptoSort,
|
|
57
58
|
sortCryptoRows,
|
|
58
59
|
withCryptoSupply,
|
|
59
60
|
type CryptoColumn,
|
|
@@ -79,6 +80,9 @@ const SUPPLY_REFRESH_MS = 30 * 60_000;
|
|
|
79
80
|
|
|
80
81
|
const SUPPLY_RANGE_OPTIONS = SUPPLY_RANGES.map(({ value, label }) => ({ value, label }));
|
|
81
82
|
|
|
83
|
+
/** The most of the stablecoin tab the supply chart takes, under the rows. */
|
|
84
|
+
const STABLECOIN_SUPPLY_CHART_SHARE = 1 / 3;
|
|
85
|
+
|
|
82
86
|
const cryptoTickerKey = (row: CryptoRow) => publicTickerKey(row.asset.symbol, "CCC");
|
|
83
87
|
|
|
84
88
|
function quoteTargets(
|
|
@@ -190,7 +194,12 @@ export function CryptoBoardPane({ width, height, focused }: PaneProps) {
|
|
|
190
194
|
const liveStreaming = useLiveStreamingSetting();
|
|
191
195
|
const [activeTab, setActiveTab] = usePluginPaneState<CryptoTab>("activeTab", "coin");
|
|
192
196
|
const [selectedId, setSelectedId] = usePluginPaneState<string | null>("selected", null);
|
|
193
|
-
|
|
197
|
+
// Kept with the pane, so `shot CRYP --sort offpeg` opens on the order it asked for.
|
|
198
|
+
const [savedSort, setSavedSort] = usePluginPaneState<unknown>("sort", DEFAULT_CRYPTO_SORT);
|
|
199
|
+
const sort = useMemo(() => readCryptoSort(savedSort), [savedSort]);
|
|
200
|
+
const setSort = useCallback((update: (current: CryptoSortPreference) => CryptoSortPreference) => (
|
|
201
|
+
setSavedSort((current: unknown) => update(readCryptoSort(current)))
|
|
202
|
+
), [setSavedSort]);
|
|
194
203
|
const [visibleRange, setVisibleRange] = useState(INITIAL_STREAM_RANGE);
|
|
195
204
|
const paneVisible = usePaneVisible();
|
|
196
205
|
const reloadBoard = resource.load;
|
|
@@ -395,7 +404,8 @@ export function CryptoBoardPane({ width, height, focused }: PaneProps) {
|
|
|
395
404
|
renderCell={renderCell}
|
|
396
405
|
selectedTextOverridesCellColor
|
|
397
406
|
emptyStateTitle="No crypto assets returned."
|
|
398
|
-
|
|
407
|
+
// The pegs are what the tab is read for: the rows come first, the supply under them in at most a third.
|
|
408
|
+
rootAfter={stablecoins ? (
|
|
399
409
|
<ChartTableHeader
|
|
400
410
|
width={width}
|
|
401
411
|
height={bodyHeight}
|
|
@@ -410,6 +420,7 @@ export function CryptoBoardPane({ width, height, focused }: PaneProps) {
|
|
|
410
420
|
remoteKind: "stablecoin-supply-history",
|
|
411
421
|
loading: supplyResource.loading && !supply,
|
|
412
422
|
empty: supplyError ? "Stablecoin supply is unavailable right now." : "No stablecoin supply history yet.",
|
|
423
|
+
maxShare: STABLECOIN_SUPPLY_CHART_SHARE,
|
|
413
424
|
}}
|
|
414
425
|
/>
|
|
415
426
|
) : undefined}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PerpBoardPayload, PerpBoardRow, PerpDepthRow, PerpLiquidationMarket, PerpLiquidationPrint } from "../../../api-client/perps";
|
|
1
|
+
import type { PerpBoardPayload, PerpBoardRow, PerpDepthRow, PerpLiquidationMarket, PerpLiquidationPrint, PerpLiquidationsPayload } from "../../../api-client/perps";
|
|
2
2
|
import type { HeadlessBundleSection, HeadlessPaneColumn, HeadlessPaneLoadArgs, HeadlessPaneRow } from "../../../types/headless";
|
|
3
3
|
import type { HeadlessPaneDefinition } from "../../../types/plugin";
|
|
4
4
|
import { DEPTH_COLUMN_IDS, depthBandTotals, depthCellText, depthColumnLabel, depthFreshness, depthStaleNote, downStreams, LIQUIDATION_COLUMN_IDS, liquidationCellText, liquidationColumnLabel, liquidationFreshness,
|
|
@@ -108,6 +108,11 @@ const tabOf = (args: HeadlessPaneLoadArgs) => PERP_TABS.find((tab) => tab === ar
|
|
|
108
108
|
const TITLES: Record<typeof PERP_TABS[number], string> = { board: "Perpetual markets", rankings: "Perpetual rankings", compare: "Perpetual contracts across venues",
|
|
109
109
|
liquidations: "Perpetual liquidations across venues", depth: "Perpetual order book depth across venues", history: "Perpetuals", evidence: "Perpetual evidence" };
|
|
110
110
|
const copy = (rows: readonly PerpBoardRow[]) => rows.map((row) => ({ ...row }));
|
|
111
|
+
/** The days the liquidations read back from their time (`from` to `asOf`), as a heading names them: `7 days`; null without both. */
|
|
112
|
+
const windowDays = (data: Pick<PerpLiquidationsPayload, "from" | "asOf">) => {
|
|
113
|
+
const days = Math.round((Date.parse(data.asOf) - Date.parse(data.from)) / 86_400_000);
|
|
114
|
+
return Number.isFinite(days) && days > 0 ? `${days} ${days === 1 ? "day" : "days"}` : null;
|
|
115
|
+
};
|
|
111
116
|
const more = (count: number, noun: string) => `${count.toLocaleString("en-US")} more ${noun} need Gloom Pro`;
|
|
112
117
|
// A table the free view leaves empty is locked: the report leaves it out and its one Pro line says what Pro adds.
|
|
113
118
|
const lockedTable = (locked: unknown) => locked ? { locked: true } : {};
|
|
@@ -206,7 +211,8 @@ export const perpsHeadless: HeadlessPaneDefinition<"bundle"> = {
|
|
|
206
211
|
return { sections: [{ title: "Totals", entries: [...entries, { key: "collectingSince", label: "Collecting since", value: data.collectingSince, formatted: time(data.collectingSince) }] },
|
|
207
212
|
{ title: "By contract", columns: LIQUIDATION_TEXT_COLUMNS, rows: data.markets.map((row) => ({ ...row })) },
|
|
208
213
|
{ title: "Hourly", columns: HOURLY_COLUMNS, rows: data.hourly.map((row) => ({ ...row })), ...locked },
|
|
209
|
-
|
|
214
|
+
// The prints are the window's, not the 24 hours beside them: the heading says which.
|
|
215
|
+
{ title: "Largest prints", textTitle: windowDays(data) ? `Largest prints, ${windowDays(data)}` : "Largest prints", columns: printTextColumns(data.baseAsset), rows: data.largest.map((row) => ({ ...row })) }],
|
|
210
216
|
complete: !data.locked && data.status === "ok" && !downStreams(data).length, notes: data.notes,
|
|
211
217
|
errors: data.locked ? [freePreviewNote({ shows: "liquidation totals and the three largest prints", adds: "the hourly series and the twenty largest prints" })] : [],
|
|
212
218
|
freshness: liquidationFreshness(data),
|