@oracle-agent/oracle 0.9.8 → 0.11.0

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.
Files changed (160) hide show
  1. package/README.md +15 -10
  2. package/bin/oracle-data-mcp.mjs +9 -0
  3. package/docs/architecture.md +3 -1
  4. package/docs/profiles.md +3 -6
  5. package/docs/public-surface.md +133 -0
  6. package/package.json +3 -2
  7. package/public/oracle-splash/assets/cli-chain-hyperliquid.jpg +0 -0
  8. package/public/oracle-splash/brand/aave.webp +0 -0
  9. package/public/oracle-splash/brand/aavev2.webp +0 -0
  10. package/public/oracle-splash/brand/aborean.webp +0 -0
  11. package/public/oracle-splash/brand/across.webp +0 -0
  12. package/public/oracle-splash/brand/aerodrome.webp +0 -0
  13. package/public/oracle-splash/brand/afi.webp +0 -0
  14. package/public/oracle-splash/brand/arcus.webp +0 -0
  15. package/public/oracle-splash/brand/aster.webp +0 -0
  16. package/public/oracle-splash/brand/avant.webp +0 -0
  17. package/public/oracle-splash/brand/balancer.webp +0 -0
  18. package/public/oracle-splash/brand/beefy.webp +0 -0
  19. package/public/oracle-splash/brand/benqi.webp +0 -0
  20. package/public/oracle-splash/brand/bestinslot.ico +0 -0
  21. package/public/oracle-splash/brand/bitfi.webp +0 -0
  22. package/public/oracle-splash/brand/bonkswap.webp +0 -0
  23. package/public/oracle-splash/brand/bouncebit.webp +0 -0
  24. package/public/oracle-splash/brand/camelot.webp +0 -0
  25. package/public/oracle-splash/brand/compound.webp +0 -0
  26. package/public/oracle-splash/brand/concrete.webp +0 -0
  27. package/public/oracle-splash/brand/cow.webp +0 -0
  28. package/public/oracle-splash/brand/curve.webp +0 -0
  29. package/public/oracle-splash/brand/derive.webp +0 -0
  30. package/public/oracle-splash/brand/dolomite.webp +0 -0
  31. package/public/oracle-splash/brand/eigenlayer.webp +0 -0
  32. package/public/oracle-splash/brand/ekubo.webp +0 -0
  33. package/public/oracle-splash/brand/ethena.webp +0 -0
  34. package/public/oracle-splash/brand/etherfi.webp +0 -0
  35. package/public/oracle-splash/brand/etherfiborrow.webp +0 -0
  36. package/public/oracle-splash/brand/felix.webp +0 -0
  37. package/public/oracle-splash/brand/fluid.webp +0 -0
  38. package/public/oracle-splash/brand/fluxbeam.webp +0 -0
  39. package/public/oracle-splash/brand/folks.webp +0 -0
  40. package/public/oracle-splash/brand/fortyacres.webp +0 -0
  41. package/public/oracle-splash/brand/gainsnetwork.webp +0 -0
  42. package/public/oracle-splash/brand/gassss.webp +0 -0
  43. package/public/oracle-splash/brand/gmx.webp +0 -0
  44. package/public/oracle-splash/brand/harmonix.webp +0 -0
  45. package/public/oracle-splash/brand/hlorderbook.webp +0 -0
  46. package/public/oracle-splash/brand/hlp.webp +0 -0
  47. package/public/oracle-splash/brand/hop.webp +0 -0
  48. package/public/oracle-splash/brand/hyperbeat.webp +0 -0
  49. package/public/oracle-splash/brand/hyperlend.webp +0 -0
  50. package/public/oracle-splash/brand/hyperliquid.webp +0 -0
  51. package/public/oracle-splash/brand/hyperliquidhpl.webp +0 -0
  52. package/public/oracle-splash/brand/hyperliquidspot.webp +0 -0
  53. package/public/oracle-splash/brand/hyperswap.webp +0 -0
  54. package/public/oracle-splash/brand/hypha.webp +0 -0
  55. package/public/oracle-splash/brand/joedex.webp +0 -0
  56. package/public/oracle-splash/brand/jupiter.webp +0 -0
  57. package/public/oracle-splash/brand/kelp.webp +0 -0
  58. package/public/oracle-splash/brand/kinetiq.webp +0 -0
  59. package/public/oracle-splash/brand/kmhype.webp +0 -0
  60. package/public/oracle-splash/brand/kona.webp +0 -0
  61. package/public/oracle-splash/brand/konalend.webp +0 -0
  62. package/public/oracle-splash/brand/lfj.webp +0 -0
  63. package/public/oracle-splash/brand/lido.webp +0 -0
  64. package/public/oracle-splash/brand/lifi.webp +0 -0
  65. package/public/oracle-splash/brand/lighter.webp +0 -0
  66. package/public/oracle-splash/brand/lista.webp +0 -0
  67. package/public/oracle-splash/brand/loopedhype.webp +0 -0
  68. package/public/oracle-splash/brand/lorenzo.webp +0 -0
  69. package/public/oracle-splash/brand/magic-eden.webp +0 -0
  70. package/public/oracle-splash/brand/magiceden.webp +0 -0
  71. package/public/oracle-splash/brand/mempool.png +0 -0
  72. package/public/oracle-splash/brand/meteora.webp +0 -0
  73. package/public/oracle-splash/brand/morpho.webp +0 -0
  74. package/public/oracle-splash/brand/myriad.webp +0 -0
  75. package/public/oracle-splash/brand/noxa.webp +0 -0
  76. package/public/oracle-splash/brand/odos.webp +0 -0
  77. package/public/oracle-splash/brand/oneinch.webp +0 -0
  78. package/public/oracle-splash/brand/openbook.webp +0 -0
  79. package/public/oracle-splash/brand/opensea.webp +0 -0
  80. package/public/oracle-splash/brand/orca.webp +0 -0
  81. package/public/oracle-splash/brand/ordinals.png +0 -0
  82. package/public/oracle-splash/brand/ostium.webp +0 -0
  83. package/public/oracle-splash/brand/pancakeswap.webp +0 -0
  84. package/public/oracle-splash/brand/pendle.webp +0 -0
  85. package/public/oracle-splash/brand/perena.webp +0 -0
  86. package/public/oracle-splash/brand/pharaoh.webp +0 -0
  87. package/public/oracle-splash/brand/phoenix.webp +0 -0
  88. package/public/oracle-splash/brand/polymarket.webp +0 -0
  89. package/public/oracle-splash/brand/polynomial.webp +0 -0
  90. package/public/oracle-splash/brand/projectx.webp +0 -0
  91. package/public/oracle-splash/brand/pumpfun.webp +0 -0
  92. package/public/oracle-splash/brand/quickswap.webp +0 -0
  93. package/public/oracle-splash/brand/rain.webp +0 -0
  94. package/public/oracle-splash/brand/raydium.webp +0 -0
  95. package/public/oracle-splash/brand/relay.webp +0 -0
  96. package/public/oracle-splash/brand/rocketpool.webp +0 -0
  97. package/public/oracle-splash/brand/saber.webp +0 -0
  98. package/public/oracle-splash/brand/sakuraswap.webp +0 -0
  99. package/public/oracle-splash/brand/sanctum.webp +0 -0
  100. package/public/oracle-splash/brand/satflow.png +0 -0
  101. package/public/oracle-splash/brand/sierra.webp +0 -0
  102. package/public/oracle-splash/brand/sky.webp +0 -0
  103. package/public/oracle-splash/brand/solv.webp +0 -0
  104. package/public/oracle-splash/brand/spark.webp +0 -0
  105. package/public/oracle-splash/brand/sparksavings.webp +0 -0
  106. package/public/oracle-splash/brand/sphere.webp +0 -0
  107. package/public/oracle-splash/brand/ssv.webp +0 -0
  108. package/public/oracle-splash/brand/stabble.webp +0 -0
  109. package/public/oracle-splash/brand/stableswap.webp +0 -0
  110. package/public/oracle-splash/brand/stakewise.webp +0 -0
  111. package/public/oracle-splash/brand/stargate.webp +0 -0
  112. package/public/oracle-splash/brand/sthype.webp +0 -0
  113. package/public/oracle-splash/brand/sushiswap.webp +0 -0
  114. package/public/oracle-splash/brand/unisat.png +0 -0
  115. package/public/oracle-splash/brand/uniswap.webp +0 -0
  116. package/public/oracle-splash/brand/uniswapv2.webp +0 -0
  117. package/public/oracle-splash/brand/uniswapv4.webp +0 -0
  118. package/public/oracle-splash/brand/unit.webp +0 -0
  119. package/public/oracle-splash/brand/velodrome.webp +0 -0
  120. package/public/oracle-splash/brand/velora.webp +0 -0
  121. package/public/oracle-splash/brand/venus.webp +0 -0
  122. package/public/oracle-splash/brand/wbeth.webp +0 -0
  123. package/public/oracle-splash/brand/xsy.webp +0 -0
  124. package/public/oracle-splash/brand/yieldyak.webp +0 -0
  125. package/public/oracle-splash/brand/zerobase.webp +0 -0
  126. package/public/oracle-splash/brand/zerox.webp +0 -0
  127. package/public/oracle-splash/index.html +337 -197
  128. package/scripts/check-doc-drift.mjs +11 -0
  129. package/scripts/e2e-solana-bitcoin.mjs +1 -1
  130. package/scripts/secret-scan.mjs +1 -1
  131. package/src/action-receipts.mjs +108 -11
  132. package/src/auth/oauth.mjs +672 -0
  133. package/src/cli/commands/auth.mjs +193 -0
  134. package/src/cli/commands/bootstrap.mjs +2 -2
  135. package/src/cli/commands/chat.mjs +97 -75
  136. package/src/cli/commands/data.mjs +3 -1
  137. package/src/cli/commands/doctor.mjs +11 -1
  138. package/src/cli/commands/model.mjs +79 -23
  139. package/src/cli/kernel.mjs +4 -3
  140. package/src/cli/model-config.mjs +70 -0
  141. package/src/data/catalog.mjs +38 -7
  142. package/src/data/desk-data.mjs +12 -0
  143. package/src/data/providers/evm-rpc.mjs +19 -16
  144. package/src/data/providers/jupiter-venues.mjs +119 -0
  145. package/src/data/providers/jupiter.mjs +132 -0
  146. package/src/data/providers/magiceden-sol.mjs +13 -0
  147. package/src/data/providers/morpho.mjs +6 -2
  148. package/src/data/providers/pendle.mjs +3 -2
  149. package/src/data/providers/satflow.mjs +4 -1
  150. package/src/data/providers/signed-material-guard.mjs +108 -0
  151. package/src/data/providers/uniswap-v3.mjs +34 -5
  152. package/src/data/providers/uniswap-v4.mjs +414 -0
  153. package/src/prepare-envelope.mjs +22 -4
  154. package/src/router/prepare-route.mjs +17 -0
  155. package/src/router/route-sources.mjs +35 -0
  156. package/src/tui/app.mjs +18 -7
  157. package/src/tui/backend.mjs +145 -0
  158. package/src/tui/standalone-client.mjs +666 -0
  159. package/src/cards.mjs +0 -369
  160. package/src/cli/__pycache__/oracle-harness.cpython-311.pyc +0 -0
package/src/cards.mjs DELETED
@@ -1,369 +0,0 @@
1
- // Telegram card TEXT renderers.
2
- //
3
- // Implements skills/oracle-chain-graphs-telegram-cards/SKILL.md. That spec has
4
- // existed with no code behind it, so Oracle users were getting raw JSON instead
5
- // of readable alert cards. This module is the text half only: chart/image
6
- // rendering lives elsewhere and MUST NOT be required for a card to send.
7
- //
8
- // Contract for every exported renderer:
9
- // - pure, synchronous, string in / string out
10
- // - NO network, NO signing, NO filesystem, NO env reads, NO mutation of input
11
- // - unknown data renders as the literal string UNKNOWN — never blank, never
12
- // guessed, never interpolated from a neighbouring field
13
- // - the only identifier (contract address / mint / market id) is NEVER
14
- // truncated: a half-address is worse than no address because it still looks
15
- // actionable
16
- // - chart failure is cosmetic: the text card always returns
17
- // - buy/sell affordances only when a valid local grant/session is supplied
18
- //
19
- // Markdown dialect: Telegram *legacy* Markdown. Values are escaped for `_`,
20
- // `*`, `[`, `]` and backtick; card chrome supplies its own markers. We never
21
- // emit `$` at all (the spec calls out repeated `$` spans as a formatting trap)
22
- // — amounts are suffixed with USD instead.
23
-
24
- import { chainById } from "./chains.mjs";
25
-
26
- /** The one and only stand-in for missing data. */
27
- export const UNKNOWN = "UNKNOWN";
28
-
29
- export const CARD_KINDS = Object.freeze(["token", "launch", "hip3", "hip4", "polymarket"]);
30
-
31
- const LEGACY_MD_SPECIALS = /[_*[\]`]/g;
32
-
33
- /**
34
- * Escape Telegram legacy-Markdown control characters in a *value*.
35
- * Card chrome (bold headers) is written unescaped by the renderers themselves.
36
- * @param {unknown} value
37
- * @returns {string} escaped text, or UNKNOWN when there is nothing to show
38
- */
39
- export function escapeMd(value) {
40
- if (!isPresent(value)) return UNKNOWN;
41
- return String(value).replace(LEGACY_MD_SPECIALS, (c) => `\\${c}`);
42
- }
43
-
44
- function isPresent(value) {
45
- if (value === null || value === undefined) return false;
46
- if (typeof value === "number") return Number.isFinite(value);
47
- if (typeof value === "string") return value.trim() !== "";
48
- return true;
49
- }
50
-
51
- /** A value that must survive verbatim (addresses, mints, market ids). */
52
- function code(value) {
53
- if (!isPresent(value)) return UNKNOWN;
54
- // Backticks would close the span; strip rather than truncate the identifier.
55
- const raw = String(value).replace(/`/g, "");
56
- return raw === "" ? UNKNOWN : `\`${raw}\``;
57
- }
58
-
59
- function num(value, { decimals = 2 } = {}) {
60
- if (!isPresent(value)) return UNKNOWN;
61
- const n = typeof value === "bigint" ? Number(value) : Number(value);
62
- if (!Number.isFinite(n)) return UNKNOWN;
63
- return n.toLocaleString("en-US", { minimumFractionDigits: 0, maximumFractionDigits: decimals });
64
- }
65
-
66
- /** Money. Deliberately no `$` — repeated dollar spans break Telegram parsing. */
67
- function usd(value, { decimals = 2 } = {}) {
68
- const n = num(value, { decimals });
69
- return n === UNKNOWN ? UNKNOWN : `${n} USD`;
70
- }
71
-
72
- function pct(value, { decimals = 2 } = {}) {
73
- const n = num(value, { decimals });
74
- return n === UNKNOWN ? UNKNOWN : `${n}%`;
75
- }
76
-
77
- function bps(value) {
78
- const n = num(value, { decimals: 0 });
79
- return n === UNKNOWN ? UNKNOWN : `${n} bps`;
80
- }
81
-
82
- /**
83
- * Exact base-unit -> decimal string. BigInt only: a raw quote like
84
- * 24325001237995579150138 loses precision the moment it touches a float.
85
- */
86
- export function formatUnits(raw, decimals) {
87
- if (!isPresent(raw)) return UNKNOWN;
88
- const d = Number(decimals);
89
- if (!Number.isInteger(d) || d < 0 || d > 77) return UNKNOWN;
90
- let value;
91
- try {
92
- value = BigInt(typeof raw === "string" ? raw.trim() : raw);
93
- } catch {
94
- return UNKNOWN;
95
- }
96
- const neg = value < 0n;
97
- const abs = neg ? -value : value;
98
- const base = 10n ** BigInt(d);
99
- const whole = (abs / base).toString();
100
- const frac = (abs % base).toString().padStart(d, "0").replace(/0+$/, "");
101
- return `${neg ? "-" : ""}${whole}${frac ? `.${frac}` : ""}`;
102
- }
103
-
104
- /** Normalize confidence to a stated band. Every card must state one. */
105
- export function normalizeConfidence(value) {
106
- if (typeof value === "number" && Number.isFinite(value)) {
107
- if (value < 0 || value > 1) return UNKNOWN;
108
- if (value >= 0.75) return "HIGH";
109
- if (value >= 0.4) return "MEDIUM";
110
- return "LOW";
111
- }
112
- if (typeof value === "string") {
113
- const v = value.trim().toUpperCase();
114
- if (v === "HIGH" || v === "MEDIUM" || v === "LOW") return v;
115
- }
116
- return UNKNOWN;
117
- }
118
-
119
- function chainLine(data = {}) {
120
- const id = data.chainId;
121
- if (!isPresent(id) || !Number.isFinite(Number(id))) {
122
- return isPresent(data.chain) ? escapeMd(data.chain) : UNKNOWN;
123
- }
124
- const known = chainById(id);
125
- const name = known?.name || (isPresent(data.chain) ? String(data.chain) : UNKNOWN);
126
- return `${escapeMd(name)} (chainId ${Number(id)})`;
127
- }
128
-
129
- function venueLine(data = {}) {
130
- return escapeMd(data.venue ?? data.dex ?? data.pool?.venue);
131
- }
132
-
133
- /**
134
- * Chart status. A graph is evidence, not a dependency — if the image failed we
135
- * say so and the text card still stands.
136
- */
137
- function chartLine(chart) {
138
- if (chart === null || chart === undefined) return "NONE (text card only)";
139
- if (typeof chart === "string") return chart.trim() ? code(chart) : "NONE (text card only)";
140
- if (chart.error || chart.ok === false || chart.available === false) {
141
- const why = isPresent(chart.error) ? ` — ${escapeMd(chart.error)}` : "";
142
- return `UNAVAILABLE${why} (text card stands)`;
143
- }
144
- if (isPresent(chart.url)) return code(chart.url);
145
- return "NONE (text card only)";
146
- }
147
-
148
- /**
149
- * Buy/sell affordances are gated on a valid LOCAL grant or session. Absent or
150
- * expired grant => prepare-only. This function is the single gate; renderers
151
- * never decide on their own.
152
- * @returns {{ allowed: boolean, reason: string, actions: string[] }}
153
- */
154
- export function cardActions(data = {}, { now = Date.now() } = {}) {
155
- const grant = data.grant ?? data.session ?? null;
156
- if (!grant || typeof grant !== "object") {
157
- return { allowed: false, reason: "no local grant/session", actions: [] };
158
- }
159
- if (grant.local === false) {
160
- return { allowed: false, reason: "grant is not local", actions: [] };
161
- }
162
- if (grant.revoked === true) {
163
- return { allowed: false, reason: "grant revoked", actions: [] };
164
- }
165
- const expiry = grant.expiresAt ?? grant.expiry;
166
- if (isPresent(expiry)) {
167
- const at = typeof expiry === "number" ? expiry : Date.parse(expiry);
168
- if (!Number.isFinite(at)) return { allowed: false, reason: "grant expiry unreadable", actions: [] };
169
- if (at <= now) return { allowed: false, reason: "grant expired", actions: [] };
170
- }
171
- const actions = Array.isArray(grant.actions) && grant.actions.length ? grant.actions.slice() : ["BUY", "SELL"];
172
- return { allowed: true, reason: "valid local grant", actions };
173
- }
174
-
175
- function actionsLine(data) {
176
- const gate = cardActions(data);
177
- return gate.allowed
178
- ? `${gate.actions.map((a) => escapeMd(a)).join(" / ")} (${escapeMd(gate.reason)})`
179
- : `prepare-only — ${escapeMd(gate.reason)}`;
180
- }
181
-
182
- function build(title, rows, data = {}) {
183
- const lines = [`*${title}*`];
184
- for (const [label, value] of rows) {
185
- // Labels are authored here and contain no markdown specials by construction.
186
- lines.push(`${label}: ${value === undefined || value === null || value === "" ? UNKNOWN : value}`);
187
- }
188
- lines.push(`Chart: ${chartLine(data.chart)}`);
189
- lines.push(`Actions: ${actionsLine(data)}`);
190
- if (Array.isArray(data.warnings) && data.warnings.length) {
191
- lines.push(`Warnings: ${data.warnings.map((w) => escapeMd(w)).join("; ")}`);
192
- }
193
- if (isPresent(data.source) || isPresent(data.fetchedAt)) {
194
- lines.push(`Source: ${escapeMd(data.source)} at ${escapeMd(data.fetchedAt)}`);
195
- }
196
- return lines.join("\n");
197
- }
198
-
199
- function confidenceRow(data) {
200
- return ["Confidence", normalizeConfidence(data.confidence)];
201
- }
202
-
203
- function quoteRows(data) {
204
- const q = data.quote;
205
- if (!q || typeof q !== "object") return [];
206
- const human = isPresent(q.decimals) ? formatUnits(q.amountOutRaw ?? q.out ?? q.raw, q.decimals) : UNKNOWN;
207
- return [
208
- ["Quote out (raw)", code(q.amountOutRaw ?? q.out ?? q.raw)],
209
- ["Quote out", human === UNKNOWN ? UNKNOWN : `${escapeMd(human)} ${escapeMd(q.symbol ?? "")}`.trim()],
210
- ];
211
- }
212
-
213
- function slippageRow(data) {
214
- const s = data.autoSlippage;
215
- if (!s || typeof s !== "object") return ["Auto-slippage", UNKNOWN];
216
- const sel = bps(s.selectedBps);
217
- const cap = bps(s.capBps);
218
- return ["Auto-slippage", sel === UNKNOWN && cap === UNKNOWN ? UNKNOWN : `${sel} selected, cap ${cap}`];
219
- }
220
-
221
- /** Per-chain token card: price, volume, liquidity, market cap, age, venue. */
222
- export function renderTokenCard(data = {}) {
223
- const d = data || {};
224
- return build(
225
- `ORACLE TOKEN — ${escapeMd(d.symbol ?? d.token ?? d.name)}`,
226
- [
227
- ["Chain", chainLine(d)],
228
- ["Venue", venueLine(d)],
229
- ["Name", escapeMd(d.name)],
230
- ["Address", code(d.address ?? d.mint ?? d.contract)],
231
- ["Price", usd(d.priceUsd, { decimals: 8 })],
232
- ["Market cap", usd(d.marketCapUsd)],
233
- ["Liquidity", usd(d.liquidityUsd)],
234
- ["Volume 24h", usd(d.volume24hUsd)],
235
- ["Change 24h", pct(d.priceChange24h)],
236
- ["Fee tier", isPresent(d.feeTier) ? `${bps(Number(d.feeTier) / 100)} (${num(d.feeTier, { decimals: 0 })})` : UNKNOWN],
237
- ["Age", escapeMd(d.age)],
238
- ...quoteRows(d),
239
- slippageRow(d),
240
- confidenceRow(d),
241
- ],
242
- d,
243
- );
244
- }
245
-
246
- /** Launch/sniper card: route readiness, sellability, overlap, risk, ticket. */
247
- export function renderLaunchCard(data = {}) {
248
- const d = data || {};
249
- return build(
250
- `ORACLE LAUNCH — ${escapeMd(d.symbol ?? d.token ?? d.name)}`,
251
- [
252
- ["Chain", chainLine(d)],
253
- ["Venue", venueLine(d)],
254
- ["Address", code(d.address ?? d.mint ?? d.contract)],
255
- ["Pool", code(d.pool?.address ?? d.poolAddress ?? d.pool)],
256
- ["Liquidity", usd(d.liquidityUsd)],
257
- ["Route ready", escapeMd(d.routeReady)],
258
- ["Sellable", escapeMd(d.sellable)],
259
- ["Sell sim", escapeMd(d.sellSimulation ?? d.sellSim)],
260
- ["Smart wallets", escapeMd(d.smartWalletOverlap)],
261
- ["Risk", escapeMd(d.risk ?? d.riskStatus)],
262
- ["Prepared ticket", escapeMd(d.preparedTicket ?? d.ticketStatus)],
263
- slippageRow(d),
264
- confidenceRow(d),
265
- ],
266
- d,
267
- );
268
- }
269
-
270
- /** Hyperliquid HIP-3 builder-dex card. Requires perpDexs + metaAndAssetCtxs. */
271
- export function renderHip3Card(data = {}) {
272
- const d = data || {};
273
- return build(
274
- `ORACLE HIP-3 — ${escapeMd(d.market ?? d.coin ?? d.name)}`,
275
- [
276
- ["Venue", `Hyperliquid builder-dex ${escapeMd(d.dex)}`],
277
- ["Market", escapeMd(d.market ?? d.coin)],
278
- ["Mark", usd(d.markPx, { decimals: 6 })],
279
- ["Oracle", usd(d.oraclePx, { decimals: 6 })],
280
- ["Funding", pct(d.funding, { decimals: 6 })],
281
- ["Open interest", usd(d.openInterestUsd)],
282
- ["Depth", escapeMd(d.depth)],
283
- ["Liquidation notes", escapeMd(d.liquidationNotes ?? d.riskNotes)],
284
- ["Account context", escapeMd(d.accountContext)],
285
- confidenceRow(d),
286
- ],
287
- d,
288
- );
289
- }
290
-
291
- /** Hyperliquid HIP-4 outcome-market card. Public reads are keyless. */
292
- export function renderHip4Card(data = {}) {
293
- const d = data || {};
294
- return build(
295
- `ORACLE HIP-4 — ${escapeMd(d.event ?? d.market ?? d.name)}`,
296
- [
297
- ["Venue", `Hyperliquid HIP-4 ${escapeMd(d.dex ?? "outcome")}`],
298
- ["Event", escapeMd(d.event)],
299
- ["Outcome", escapeMd(d.outcome)],
300
- ["Market id", code(d.marketId ?? d.market)],
301
- ["Bid", usd(d.bid, { decimals: 6 })],
302
- ["Ask", usd(d.ask, { decimals: 6 })],
303
- ["Depth", escapeMd(d.depth)],
304
- ["Edge", pct(d.edge)],
305
- ["Position", escapeMd(d.position)],
306
- confidenceRow(d),
307
- ],
308
- d,
309
- );
310
- }
311
-
312
- /** Polymarket card. Public reads keyless; orders stay prepared/user-signed. */
313
- export function renderPolymarketCard(data = {}) {
314
- const d = data || {};
315
- return build(
316
- `ORACLE POLYMARKET — ${escapeMd(d.event ?? d.market ?? d.name)}`,
317
- [
318
- ["Venue", "Polymarket CLOB"],
319
- ["Event", escapeMd(d.event)],
320
- ["Market", escapeMd(d.market)],
321
- ["Market id", code(d.marketId ?? d.conditionId ?? d.tokenId)],
322
- ["Yes", usd(d.yesPrice, { decimals: 4 })],
323
- ["No", usd(d.noPrice, { decimals: 4 })],
324
- ["Best bid / ask", `${usd(d.bestBid, { decimals: 4 })} / ${usd(d.bestAsk, { decimals: 4 })}`],
325
- ["Volume", usd(d.volumeUsd)],
326
- ["Resolution risk", escapeMd(d.resolutionRisk)],
327
- ["Order intent", escapeMd(d.orderIntent)],
328
- confidenceRow(d),
329
- ],
330
- d,
331
- );
332
- }
333
-
334
- const RENDERERS = Object.freeze({
335
- token: renderTokenCard,
336
- launch: renderLaunchCard,
337
- hip3: renderHip3Card,
338
- hip4: renderHip4Card,
339
- polymarket: renderPolymarketCard,
340
- });
341
-
342
- /**
343
- * Dispatch by surface kind.
344
- * @param {"token"|"launch"|"hip3"|"hip4"|"polymarket"} kind
345
- */
346
- export function renderCard(kind, data = {}) {
347
- const fn = RENDERERS[String(kind)];
348
- if (!fn) throw new Error(`unknown card kind: ${kind} (expected one of ${CARD_KINDS.join(", ")})`);
349
- return fn(data);
350
- }
351
-
352
- /**
353
- * Total soft-fail wrapper. An alert that cannot render is still an alert the
354
- * user needs to see, so a malformed payload degrades to a minimal card rather
355
- * than throwing and dropping the notification.
356
- */
357
- export function safeRenderCard(kind, data = {}) {
358
- try {
359
- return renderCard(kind, data);
360
- } catch (error) {
361
- return [
362
- `*ORACLE CARD — DEGRADED*`,
363
- `Kind: ${escapeMd(kind)}`,
364
- `Chain: ${UNKNOWN}`,
365
- `Confidence: ${UNKNOWN}`,
366
- `Render error: ${escapeMd(error?.message)}`,
367
- ].join("\n");
368
- }
369
- }