@oracle-agent/oracle 0.9.6 → 0.9.8
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/public/oracle-splash/index.html +105 -1
- package/src/cards.mjs +369 -0
- package/src/cli/__pycache__/oracle-harness.cpython-311.pyc +0 -0
- package/src/cli/commands/chat.mjs +31 -2
- package/src/cli/oracle-harness.py +29 -8
- package/src/router/best-execution.mjs +105 -0
- package/src/router/index.mjs +42 -1
- package/src/router/prepare-route.mjs +17 -1
- package/src/tui/app.mjs +427 -0
- package/src/tui/format.mjs +272 -0
- package/src/tui/gateway-client.mjs +177 -0
- package/src/tui/input.mjs +501 -0
- package/src/tui/renderer.mjs +443 -0
- package/src/tui/theme.mjs +81 -0
- package/protocols/templates/safe-erc20/README.md +0 -9
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oracle-agent/oracle",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.8",
|
|
4
4
|
"description": "Oracle: prepare-only multichain agent control plane. Policy-bounded intents for a user-signed wallet. Self-custody by default — the public package never takes your key. Built for Hermes; no model key required.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -401,6 +401,18 @@ main{position:relative;z-index:2;padding-top:84px}
|
|
|
401
401
|
}
|
|
402
402
|
.evolve-pill.on{border-color:rgba(124,196,255,.35);color:var(--blue2)}
|
|
403
403
|
|
|
404
|
+
.venue-rail-head{
|
|
405
|
+
font-family:var(--mono);font-size:10px;letter-spacing:.14em;text-transform:uppercase;
|
|
406
|
+
color:var(--cool);text-align:center;padding:14px 16px 0;opacity:.75;
|
|
407
|
+
}
|
|
408
|
+
.venue-rail-head b{color:var(--blue2);font-weight:600}
|
|
409
|
+
.venue-rail{padding:10px 16px 4px;max-height:96px;overflow:hidden;position:relative}
|
|
410
|
+
.venue-rail .evolve-pill{font-size:9px;padding:6px 10px;opacity:.9}
|
|
411
|
+
.venue-rail::after{
|
|
412
|
+
content:"";position:absolute;left:0;right:0;bottom:0;height:34px;pointer-events:none;
|
|
413
|
+
background:linear-gradient(to bottom,transparent,var(--bg));
|
|
414
|
+
}
|
|
415
|
+
|
|
404
416
|
.wires{height:40px;position:relative}
|
|
405
417
|
.wires svg{width:100%;height:100%;display:block;overflow:visible}
|
|
406
418
|
.wires path{
|
|
@@ -735,6 +747,98 @@ footer{margin-top:clamp(72px,12vh,120px);border-top:1px solid var(--line);paddin
|
|
|
735
747
|
<span class="evolve-pill on">more chains</span>
|
|
736
748
|
</div>
|
|
737
749
|
|
|
750
|
+
<div class="venue-rail-head">solana venues routed · <b id="sol-count">101</b> programs verified on-chain · 88 venues</div>
|
|
751
|
+
<div class="evolve-rail venue-rail" id="sol-venue-rail">
|
|
752
|
+
<span class="evolve-pill on">1DEX</span>
|
|
753
|
+
<span class="evolve-pill on">Aldrin</span>
|
|
754
|
+
<span class="evolve-pill on">AlphaQ</span>
|
|
755
|
+
<span class="evolve-pill on">Aquifer</span>
|
|
756
|
+
<span class="evolve-pill on">BinaryFi</span>
|
|
757
|
+
<span class="evolve-pill on">BisonFi</span>
|
|
758
|
+
<span class="evolve-pill on">Bonkswap</span>
|
|
759
|
+
<span class="evolve-pill on">Boop.fun</span>
|
|
760
|
+
<span class="evolve-pill on">Byreal</span>
|
|
761
|
+
<span class="evolve-pill on">Carrot</span>
|
|
762
|
+
<span class="evolve-pill on">Crema</span>
|
|
763
|
+
<span class="evolve-pill on">Cropper</span>
|
|
764
|
+
<span class="evolve-pill on">DefiTuna</span>
|
|
765
|
+
<span class="evolve-pill on">Denali</span>
|
|
766
|
+
<span class="evolve-pill on">Deriverse</span>
|
|
767
|
+
<span class="evolve-pill on">DexLab</span>
|
|
768
|
+
<span class="evolve-pill on">Dynamic Bonding Curve</span>
|
|
769
|
+
<span class="evolve-pill on">Flint</span>
|
|
770
|
+
<span class="evolve-pill on">Flux</span>
|
|
771
|
+
<span class="evolve-pill on">FluxBeam</span>
|
|
772
|
+
<span class="evolve-pill on">GatorSwap</span>
|
|
773
|
+
<span class="evolve-pill on">Gavel</span>
|
|
774
|
+
<span class="evolve-pill on">GoonFi</span>
|
|
775
|
+
<span class="evolve-pill on">GooseFX GAMMA</span>
|
|
776
|
+
<span class="evolve-pill on">Guacswap</span>
|
|
777
|
+
<span class="evolve-pill on">Hadron</span>
|
|
778
|
+
<span class="evolve-pill on">Heaven</span>
|
|
779
|
+
<span class="evolve-pill on">Helium Network</span>
|
|
780
|
+
<span class="evolve-pill on">Huma</span>
|
|
781
|
+
<span class="evolve-pill on">HumidiFi</span>
|
|
782
|
+
<span class="evolve-pill on">Hylo Exchange</span>
|
|
783
|
+
<span class="evolve-pill on">Hylo Stability</span>
|
|
784
|
+
<span class="evolve-pill on">Invariant</span>
|
|
785
|
+
<span class="evolve-pill on">Jupiter Lend</span>
|
|
786
|
+
<span class="evolve-pill on">JupiterRfqV2</span>
|
|
787
|
+
<span class="evolve-pill on">JupLend</span>
|
|
788
|
+
<span class="evolve-pill on">Kipseli</span>
|
|
789
|
+
<span class="evolve-pill on">LemmingsFi</span>
|
|
790
|
+
<span class="evolve-pill on">M Swap</span>
|
|
791
|
+
<span class="evolve-pill on">Manifest</span>
|
|
792
|
+
<span class="evolve-pill on">Mercurial</span>
|
|
793
|
+
<span class="evolve-pill on">MetaDAO</span>
|
|
794
|
+
<span class="evolve-pill on">Meteora</span>
|
|
795
|
+
<span class="evolve-pill on">Meteora DAMM</span>
|
|
796
|
+
<span class="evolve-pill on">Metric</span>
|
|
797
|
+
<span class="evolve-pill on">Moonit</span>
|
|
798
|
+
<span class="evolve-pill on">Obric</span>
|
|
799
|
+
<span class="evolve-pill on">Obsidian</span>
|
|
800
|
+
<span class="evolve-pill on">Omnipair</span>
|
|
801
|
+
<span class="evolve-pill on">OpenBook</span>
|
|
802
|
+
<span class="evolve-pill on">Orca</span>
|
|
803
|
+
<span class="evolve-pill on">PancakeSwap</span>
|
|
804
|
+
<span class="evolve-pill on">Penguin</span>
|
|
805
|
+
<span class="evolve-pill on">Perena</span>
|
|
806
|
+
<span class="evolve-pill on">Perena Star</span>
|
|
807
|
+
<span class="evolve-pill on">Perps</span>
|
|
808
|
+
<span class="evolve-pill on">Phoenix</span>
|
|
809
|
+
<span class="evolve-pill on">Pump.fun</span>
|
|
810
|
+
<span class="evolve-pill on">Quantum</span>
|
|
811
|
+
<span class="evolve-pill on">Raydium</span>
|
|
812
|
+
<span class="evolve-pill on">Riptide</span>
|
|
813
|
+
<span class="evolve-pill on">RunnerRodeo</span>
|
|
814
|
+
<span class="evolve-pill on">Saber</span>
|
|
815
|
+
<span class="evolve-pill on">Saber (Decimals)</span>
|
|
816
|
+
<span class="evolve-pill on">Sanctum</span>
|
|
817
|
+
<span class="evolve-pill on">Sanctum Infinity</span>
|
|
818
|
+
<span class="evolve-pill on">Saros</span>
|
|
819
|
+
<span class="evolve-pill on">Scale</span>
|
|
820
|
+
<span class="evolve-pill on">Scale Vmm</span>
|
|
821
|
+
<span class="evolve-pill on">Scorch</span>
|
|
822
|
+
<span class="evolve-pill on">Solayer</span>
|
|
823
|
+
<span class="evolve-pill on">SolFi</span>
|
|
824
|
+
<span class="evolve-pill on">Stabble</span>
|
|
825
|
+
<span class="evolve-pill on">Stabble Stable Swap</span>
|
|
826
|
+
<span class="evolve-pill on">Stabble Weighted Swap</span>
|
|
827
|
+
<span class="evolve-pill on">StepN</span>
|
|
828
|
+
<span class="evolve-pill on">TaurusFi</span>
|
|
829
|
+
<span class="evolve-pill on">TesseraV</span>
|
|
830
|
+
<span class="evolve-pill on">Token Swap</span>
|
|
831
|
+
<span class="evolve-pill on">Trends</span>
|
|
832
|
+
<span class="evolve-pill on">VaultLiquidUnstake</span>
|
|
833
|
+
<span class="evolve-pill on">Virtuals</span>
|
|
834
|
+
<span class="evolve-pill on">Voltr</span>
|
|
835
|
+
<span class="evolve-pill on">WhaleStreet</span>
|
|
836
|
+
<span class="evolve-pill on">Whirlpool</span>
|
|
837
|
+
<span class="evolve-pill on">Woofi</span>
|
|
838
|
+
<span class="evolve-pill on">XOrca</span>
|
|
839
|
+
<span class="evolve-pill on">ZeroFi</span>
|
|
840
|
+
</div>
|
|
841
|
+
|
|
738
842
|
<div class="graph-canvas">
|
|
739
843
|
<div class="orch" aria-label="Oracle multi-profile graph">
|
|
740
844
|
<div class="row">
|
|
@@ -807,7 +911,7 @@ footer{margin-top:clamp(72px,12vh,120px);border-top:1px solid var(--line);paddin
|
|
|
807
911
|
<div class="tag">profile</div>
|
|
808
912
|
<div class="name">solana agent</div>
|
|
809
913
|
<div class="sub">jup · nfts · dexs</div>
|
|
810
|
-
<div class="chains"><span class="ch">Solana <img src="https://icons.llamao.fi/icons/chains/rsz_solana?w=24&h=24" alt="" loading="lazy"></span></div>
|
|
914
|
+
<div class="chains"><span class="ch">Solana <img src="https://icons.llamao.fi/icons/chains/rsz_solana?w=24&h=24" alt="" loading="lazy"></span><span class="ch" id="sol-venue-count">88 venues routed</span></div>
|
|
811
915
|
</div>
|
|
812
916
|
<div class="node route p-btc">
|
|
813
917
|
<div class="tag">profile</div>
|
package/src/cards.mjs
ADDED
|
@@ -0,0 +1,369 @@
|
|
|
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
|
+
}
|
|
Binary file
|
|
@@ -5,6 +5,7 @@ import { PACKAGE_ROOT, hermesRoot, ensureDir } from "../paths.mjs";
|
|
|
5
5
|
import { activeChainEnv } from "../chain-state.mjs";
|
|
6
6
|
import { spawnChild } from "../spawn-child.mjs";
|
|
7
7
|
import { installManagedHermes, resolveHermes } from "../runtime.mjs";
|
|
8
|
+
import { runOracleTui } from "../../tui/app.mjs";
|
|
8
9
|
|
|
9
10
|
const PROFILE = "oracle";
|
|
10
11
|
const SKIN_NAME = "oracle";
|
|
@@ -241,7 +242,7 @@ function modelReady(profile = PROFILE) {
|
|
|
241
242
|
|
|
242
243
|
function usage() {
|
|
243
244
|
return [
|
|
244
|
-
"oracle chat
|
|
245
|
+
"oracle chat, filled lowercase oracle chat",
|
|
245
246
|
"",
|
|
246
247
|
" oracle chat open interactive oracle chat",
|
|
247
248
|
" oracle chat -q \"...\" one-shot query",
|
|
@@ -257,6 +258,23 @@ function usage() {
|
|
|
257
258
|
].join("\n");
|
|
258
259
|
}
|
|
259
260
|
|
|
261
|
+
function terminalColumns() {
|
|
262
|
+
const columns = Number(process.stdout?.columns || process.env.COLUMNS || 80);
|
|
263
|
+
return Number.isFinite(columns) && columns > 0 ? Math.floor(columns) : 80;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
function visibleWidth(text) {
|
|
267
|
+
return Array.from(String(text)).length;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
function centerBlock(lines, width) {
|
|
271
|
+
const clean = lines.map((line) => line.trimEnd());
|
|
272
|
+
const blockWidth = Math.max(0, ...clean.map((line) => visibleWidth(line)));
|
|
273
|
+
const left = Math.max(0, Math.floor((width - blockWidth) / 2));
|
|
274
|
+
const pad = " ".repeat(left);
|
|
275
|
+
return clean.map((line) => (line ? `${pad}${line}` : ""));
|
|
276
|
+
}
|
|
277
|
+
|
|
260
278
|
function printBanner() {
|
|
261
279
|
const lines = [
|
|
262
280
|
"",
|
|
@@ -270,7 +288,7 @@ function printBanner() {
|
|
|
270
288
|
" ░░░░░░ ░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░ ░░░░░░",
|
|
271
289
|
"",
|
|
272
290
|
];
|
|
273
|
-
process.stdout.write(lines.join("\n") + "\n");
|
|
291
|
+
process.stdout.write(centerBlock(lines, terminalColumns()).join("\n") + "\n");
|
|
274
292
|
}
|
|
275
293
|
|
|
276
294
|
export default {
|
|
@@ -368,6 +386,17 @@ export default {
|
|
|
368
386
|
ORACLE_CLI_ENTRY: path.join(PACKAGE_ROOT, "bin", "oracle.mjs"),
|
|
369
387
|
});
|
|
370
388
|
|
|
389
|
+
const hermesPython = resolveHermesPython(hermes);
|
|
390
|
+
const native = await runOracleTui({
|
|
391
|
+
hermesPython,
|
|
392
|
+
args,
|
|
393
|
+
env: cleanEnv,
|
|
394
|
+
cwd: process.cwd(),
|
|
395
|
+
stdin: process.stdin,
|
|
396
|
+
stdout: process.stdout,
|
|
397
|
+
});
|
|
398
|
+
if (native.native) return native.code;
|
|
399
|
+
|
|
371
400
|
const launch = oracleHarnessInvocation(hermes, [...hermesArgs, ...pass]);
|
|
372
401
|
|
|
373
402
|
return spawnChild(
|
|
@@ -109,13 +109,25 @@ def patch_cli(module):
|
|
|
109
109
|
from rich.align import Align
|
|
110
110
|
from rich.console import Group
|
|
111
111
|
from rich.panel import Panel
|
|
112
|
-
from rich.table import Table
|
|
113
112
|
from rich.text import Text
|
|
114
113
|
from rich import box
|
|
115
114
|
|
|
116
115
|
self.console.clear()
|
|
117
116
|
width = shutil.get_terminal_size((100, 28)).columns
|
|
117
|
+
|
|
118
|
+
panel_width = max(36, min(width - 4, 76))
|
|
119
|
+
panel_left = (width - panel_width) // 2
|
|
120
|
+
content_left = panel_left + 3
|
|
121
|
+
inner = panel_width - 6
|
|
122
|
+
|
|
123
|
+
def pad_for(ink_width, ink_offset=0):
|
|
124
|
+
target = int(round((width - ink_width) / 2.0))
|
|
125
|
+
pad = target - ink_offset - content_left
|
|
126
|
+
return max(0, min(max(0, inner - ink_width - ink_offset), pad))
|
|
127
|
+
|
|
118
128
|
content = []
|
|
129
|
+
tagline = "THE FUTURE IS AGENTIC / by DEMI"
|
|
130
|
+
|
|
119
131
|
if width >= 72:
|
|
120
132
|
colors = (
|
|
121
133
|
"#B8F0FF",
|
|
@@ -125,18 +137,27 @@ def patch_cli(module):
|
|
|
125
137
|
"#9FCBDD",
|
|
126
138
|
"#B8F0FF",
|
|
127
139
|
)
|
|
128
|
-
|
|
129
|
-
|
|
140
|
+
span = max(len(row) for row in WORDMARK)
|
|
141
|
+
ink_cols = [
|
|
142
|
+
index
|
|
143
|
+
for index in range(span)
|
|
144
|
+
if any(index < len(row) and row[index] != " " for row in WORDMARK)
|
|
145
|
+
]
|
|
146
|
+
ink_offset = ink_cols[0]
|
|
147
|
+
ink_width = ink_cols[-1] - ink_cols[0] + 1
|
|
148
|
+
pad = " " * pad_for(ink_width, ink_offset)
|
|
130
149
|
for index, line in enumerate(WORDMARK):
|
|
131
|
-
|
|
132
|
-
|
|
150
|
+
content.append(
|
|
151
|
+
Text(pad + line.rstrip(), style=f"bold {colors[index]}", no_wrap=True)
|
|
152
|
+
)
|
|
133
153
|
else:
|
|
134
|
-
content.append(
|
|
154
|
+
content.append(Text(" " * pad_for(6) + "oracle", style="bold #B8F0FF"))
|
|
135
155
|
|
|
136
156
|
content.append(Text(""))
|
|
137
|
-
content.append(
|
|
157
|
+
content.append(
|
|
158
|
+
Text(" " * pad_for(len(tagline)) + tagline, style="bold #EAF2F8", no_wrap=True)
|
|
159
|
+
)
|
|
138
160
|
|
|
139
|
-
panel_width = max(36, min(width - 4, 76))
|
|
140
161
|
panel = Panel(
|
|
141
162
|
Group(*content),
|
|
142
163
|
width=panel_width,
|