@oracle-agent/oracle 0.1.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.
- package/CONTRIBUTING.md +98 -0
- package/LICENSE +202 -0
- package/README.md +384 -0
- package/SECURITY.md +89 -0
- package/SETUP.md +235 -0
- package/artifacts/inscription/oracle-was-here-preview.png +0 -0
- package/artifacts/inscription/oracle-was-here.svg +1 -0
- package/artifacts/specialist-packs/oracle-full-crypto.json +273 -0
- package/bin/desk-server.mjs +438 -0
- package/bin/oracle-data-mcp.mjs +603 -0
- package/bin/oracle-init.mjs +423 -0
- package/bin/oracle-public-server.mjs +36 -0
- package/bin/oracle-route.mjs +254 -0
- package/bin/oracle-scan.mjs +192 -0
- package/docs/adding-a-chain.md +229 -0
- package/docs/architecture.md +135 -0
- package/docs/profiles.md +132 -0
- package/examples/add-a-chain.mjs +65 -0
- package/examples/research-a-token.mjs +70 -0
- package/package.json +90 -0
- package/profiles/_template/SOUL.md +47 -0
- package/profiles/_template/profile.json +22 -0
- package/profiles/bitcoin-agent/SOUL.md +31 -0
- package/profiles/bitcoin-agent/profile.json +32 -0
- package/profiles/hyperliquid-agent/SOUL.md +34 -0
- package/profiles/hyperliquid-agent/profile.json +37 -0
- package/profiles/oracle/SOUL.md +65 -0
- package/profiles/oracle/profile.json +35 -0
- package/profiles/polymarket-agent/SOUL.md +35 -0
- package/profiles/polymarket-agent/profile.json +34 -0
- package/profiles/profile.schema.json +90 -0
- package/profiles/protocol-builder/SOUL.md +50 -0
- package/profiles/protocol-builder/profile.json +37 -0
- package/profiles/robinhood-agent/SOUL.md +45 -0
- package/profiles/robinhood-agent/profile.json +39 -0
- package/profiles/solana-agent/SOUL.md +37 -0
- package/profiles/solana-agent/profile.json +37 -0
- package/profiles/stable-agent/SOUL.md +43 -0
- package/profiles/stable-agent/profile.json +37 -0
- package/public/oracle-console/app.js +272 -0
- package/public/oracle-console/bitcoin-wallets.js +206 -0
- package/public/oracle-console/index.html +91 -0
- package/public/oracle-console/styles.css +239 -0
- package/public/oracle-splash/index.html +931 -0
- package/scripts/build-inscription.py +230 -0
- package/scripts/check-test-count.mjs +105 -0
- package/scripts/e2e-hl-markets.mjs +21 -0
- package/scripts/e2e-hl-perps.mjs +48 -0
- package/scripts/e2e-hypercore-staking.mjs +128 -0
- package/scripts/e2e-solana-bitcoin.mjs +183 -0
- package/scripts/public-api-scan.mjs +23 -0
- package/scripts/secret-scan.mjs +181 -0
- package/scripts/verify-v3-venues.mjs +192 -0
- package/skills/oracle-best-execution/SKILL.md +127 -0
- package/skills/oracle-bitcoin/SKILL.md +53 -0
- package/skills/oracle-chain-graphs-telegram-cards/SKILL.md +59 -0
- package/skills/oracle-circuit-breaker/SKILL.md +51 -0
- package/skills/oracle-contract-research/SKILL.md +55 -0
- package/skills/oracle-desk/SKILL.md +58 -0
- package/skills/oracle-dex-launch/SKILL.md +38 -0
- package/skills/oracle-grants/SKILL.md +69 -0
- package/skills/oracle-hypercore-staking/SKILL.md +57 -0
- package/skills/oracle-hyperliquid/SKILL.md +56 -0
- package/skills/oracle-meme-token-sniper/SKILL.md +73 -0
- package/skills/oracle-nft-gacha-launch/SKILL.md +48 -0
- package/skills/oracle-nft-mint-gas-war/SKILL.md +63 -0
- package/skills/oracle-polymarket/SKILL.md +60 -0
- package/skills/oracle-protocol-builder/SKILL.md +38 -0
- package/skills/oracle-protocol-security/SKILL.md +60 -0
- package/skills/oracle-public-product/SKILL.md +44 -0
- package/skills/oracle-receipts/SKILL.md +52 -0
- package/skills/oracle-rfq-tokenized-assets/SKILL.md +69 -0
- package/skills/oracle-smart-wallet-scanner/SKILL.md +49 -0
- package/skills/oracle-solana/SKILL.md +65 -0
- package/skills/oracle-solana-nft/SKILL.md +54 -0
- package/skills/oracle-token-research/SKILL.md +67 -0
- package/src/agent-auth.mjs +191 -0
- package/src/approval-guard.mjs +282 -0
- package/src/attestation-secret.mjs +88 -0
- package/src/audit-log.mjs +196 -0
- package/src/auto-slippage.mjs +378 -0
- package/src/capability-posture.mjs +125 -0
- package/src/chains.mjs +62 -0
- package/src/data/catalog.mjs +495 -0
- package/src/data/desk-data.mjs +623 -0
- package/src/data/http.mjs +200 -0
- package/src/data/provider-endpoint.mjs +94 -0
- package/src/data/providers/aerodrome.mjs +244 -0
- package/src/data/providers/balancer.mjs +208 -0
- package/src/data/providers/bitcoin-esplora.mjs +230 -0
- package/src/data/providers/bitcoin-meta.mjs +378 -0
- package/src/data/providers/blockscout.mjs +14 -0
- package/src/data/providers/bridges.mjs +241 -0
- package/src/data/providers/cowswap.mjs +501 -0
- package/src/data/providers/curve.mjs +200 -0
- package/src/data/providers/defillama.mjs +88 -0
- package/src/data/providers/dexscreener.mjs +43 -0
- package/src/data/providers/evm-rpc.mjs +203 -0
- package/src/data/providers/geckoterminal.mjs +34 -0
- package/src/data/providers/gmx.mjs +495 -0
- package/src/data/providers/hl-info.mjs +102 -0
- package/src/data/providers/hl-markets.mjs +210 -0
- package/src/data/providers/hl-perps.mjs +382 -0
- package/src/data/providers/hl-staking.mjs +352 -0
- package/src/data/providers/hl-ws.mjs +119 -0
- package/src/data/providers/hyperevm-dex.mjs +49 -0
- package/src/data/providers/jupiter.mjs +182 -0
- package/src/data/providers/lifi.mjs +150 -0
- package/src/data/providers/magiceden-sol.mjs +355 -0
- package/src/data/providers/morpho.mjs +173 -0
- package/src/data/providers/odos.mjs +155 -0
- package/src/data/providers/oneinch.mjs +173 -0
- package/src/data/providers/opensea-multichain.mjs +136 -0
- package/src/data/providers/opensea-nft.mjs +99 -0
- package/src/data/providers/paraswap.mjs +117 -0
- package/src/data/providers/pendle.mjs +187 -0
- package/src/data/providers/poly-public.mjs +96 -0
- package/src/data/providers/poly-ws.mjs +103 -0
- package/src/data/providers/rh-agent.mjs +59 -0
- package/src/data/providers/satflow.mjs +336 -0
- package/src/data/providers/solana-rpc.mjs +186 -0
- package/src/data/providers/uniswap-v3.mjs +303 -0
- package/src/data/providers/zerox.mjs +166 -0
- package/src/data/public-api-scan.mjs +61 -0
- package/src/data/quote-placeholder.mjs +31 -0
- package/src/exact-integer.mjs +72 -0
- package/src/exec-policy.mjs +444 -0
- package/src/flags.mjs +15 -0
- package/src/fresh-window.mjs +76 -0
- package/src/gmx-attestation.mjs +175 -0
- package/src/index.mjs +50 -0
- package/src/nft-gas-war-guard.mjs +139 -0
- package/src/onboarding/agent-keys.mjs +157 -0
- package/src/onboarding/index.mjs +18 -0
- package/src/onboarding/tiers.mjs +139 -0
- package/src/oracle-env.mjs +38 -0
- package/src/protocol-execution.mjs +84 -0
- package/src/public-api/buzz-integration.mjs +256 -0
- package/src/public-api/connect-agent.mjs +397 -0
- package/src/public-api/grants.mjs +142 -0
- package/src/public-api/http.mjs +374 -0
- package/src/public-control/aa-adapter.mjs +402 -0
- package/src/public-control/build-registry.mjs +227 -0
- package/src/public-control/bundler-client.mjs +372 -0
- package/src/public-control/grant-indexer.mjs +296 -0
- package/src/public-control/policy-render.mjs +69 -0
- package/src/public-control/policy-schema.mjs +318 -0
- package/src/public-control/runtime-config.mjs +265 -0
- package/src/public-control/session-key-model.mjs +374 -0
- package/src/public-control/session-orchestrator.mjs +412 -0
- package/src/route-attestation.mjs +132 -0
- package/src/router/best-execution.mjs +221 -0
- package/src/router/index.mjs +185 -0
- package/src/router/prepare-bridge.mjs +288 -0
- package/src/router/prepare-route.mjs +341 -0
- package/src/router/proposal.mjs +311 -0
- package/src/router/risk-classifier.mjs +119 -0
- package/src/router/route-sources.mjs +292 -0
- package/src/scanner/chains.config.mjs +381 -0
- package/src/scanner/contract.mjs +270 -0
- package/src/scanner/evm-scanner.mjs +394 -0
- package/src/scanner/index.mjs +9 -0
- package/src/scanner/v2-venue.mjs +335 -0
- package/src/scanner/v3-venue.mjs +290 -0
- package/src/scopes.mjs +44 -0
- package/src/sell-simulation.mjs +167 -0
- package/src/token-transfer-guard.mjs +188 -0
- package/src/vault-attestation.mjs +145 -0
- package/src/venues.mjs +206 -0
|
@@ -0,0 +1,378 @@
|
|
|
1
|
+
// Bitcoin metaprotocol reads (ordinals / runes).
|
|
2
|
+
// Pluggable indexer base. No keys in repo — optional API keys via env.
|
|
3
|
+
//
|
|
4
|
+
// Free keyless tier: ordinals.com recursive ("/r/*") endpoints. Verified live
|
|
5
|
+
// 2026-07: blockheight, blockhash, blockinfo, inscription metadata, children,
|
|
6
|
+
// sat. These are the ord node's own recursive API and need no key.
|
|
7
|
+
//
|
|
8
|
+
// Indexer landscape as probed (do not re-litigate without re-probing):
|
|
9
|
+
// ordinals.com /r/* 200, keyless -> wired below
|
|
10
|
+
// Hiro ordinals/brc20 410 GONE, deprecated -> dead, do not use
|
|
11
|
+
// Ordiscan 402 payment required
|
|
12
|
+
// UniSat open-api 403 without Bearer
|
|
13
|
+
// BestInSlot 301 (moved; needs key)
|
|
14
|
+
// Magic Eden BTC 503 "no healthy upstream" -> dead
|
|
15
|
+
// Satflow 403 without x-api-key -> marketplace, separate provider
|
|
16
|
+
//
|
|
17
|
+
// Known gap: ordinals.com has NO address-indexed endpoint (/r/address 404).
|
|
18
|
+
// Address -> inscriptions/runes REQUIRES a keyed indexer. Keyless mode can
|
|
19
|
+
// answer "what is this inscription" but not "what does this wallet hold".
|
|
20
|
+
|
|
21
|
+
import { btcAddress } from "./bitcoin-esplora.mjs";
|
|
22
|
+
import { resolveProviderEndpoint, credentialedHeaders } from "../provider-endpoint.mjs";
|
|
23
|
+
|
|
24
|
+
export const ORDINALS_RECURSIVE_BASE = "https://ordinals.com";
|
|
25
|
+
|
|
26
|
+
function metaBase(opts = {}) {
|
|
27
|
+
return String(
|
|
28
|
+
opts.baseUrl ||
|
|
29
|
+
process.env.BTC_META_API_URL ||
|
|
30
|
+
process.env.UNISAT_API_URL ||
|
|
31
|
+
""
|
|
32
|
+
)
|
|
33
|
+
.trim()
|
|
34
|
+
.replace(/\/$/, "");
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// This provider has NO fixed default endpoint: the operator points it at their
|
|
38
|
+
// own UniSat / Best-in-Slot deployment. Trust is therefore decided by an
|
|
39
|
+
// explicit host allowlist rather than a built-in default.
|
|
40
|
+
const BTC_META_HOSTS = [
|
|
41
|
+
"open-api.unisat.io",
|
|
42
|
+
"open-api-testnet.unisat.io",
|
|
43
|
+
"api.bestinslot.xyz",
|
|
44
|
+
"api.hiro.so",
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
function metaEndpoint(opts = {}) {
|
|
48
|
+
const url = metaBase(opts);
|
|
49
|
+
if (!url) return { baseUrl: "", trusted: false, host: null };
|
|
50
|
+
return resolveProviderEndpoint({
|
|
51
|
+
provider: "bitcoin-meta",
|
|
52
|
+
defaultUrl: url,
|
|
53
|
+
hosts: BTC_META_HOSTS,
|
|
54
|
+
url,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function headers(opts = {}) {
|
|
59
|
+
const key =
|
|
60
|
+
opts.apiKey ||
|
|
61
|
+
process.env.UNISAT_API_KEY ||
|
|
62
|
+
process.env.BESTINSLOT_API_KEY ||
|
|
63
|
+
process.env.BTC_META_API_KEY ||
|
|
64
|
+
"";
|
|
65
|
+
// An operator-configured base is only credentialed when its host is one of
|
|
66
|
+
// the known indexers; a redirected base gets the request without the key.
|
|
67
|
+
let trusted = false;
|
|
68
|
+
try {
|
|
69
|
+
const url = metaBase(opts);
|
|
70
|
+
if (url) {
|
|
71
|
+
const host = new URL(url).host;
|
|
72
|
+
const proto = new URL(url).protocol;
|
|
73
|
+
const loopback = /^(127\.0\.0\.1|localhost|\[::1\])(:\d+)?$/i.test(host);
|
|
74
|
+
trusted = BTC_META_HOSTS.includes(host) && (proto === "https:" || loopback);
|
|
75
|
+
}
|
|
76
|
+
} catch {
|
|
77
|
+
trusted = false;
|
|
78
|
+
}
|
|
79
|
+
return credentialedHeaders(
|
|
80
|
+
{ accept: "application/json", "user-agent": "oracle-btc-meta/0.1" },
|
|
81
|
+
{ authorization: key ? `Bearer ${key}` : "", "x-api-key": key },
|
|
82
|
+
trusted
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
async function getJson(url, opts = {}) {
|
|
87
|
+
const fetchImpl = opts.fetchImpl || fetch;
|
|
88
|
+
const res = await fetchImpl(url, {
|
|
89
|
+
method: "GET",
|
|
90
|
+
headers: headers(opts),
|
|
91
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? 12_000),
|
|
92
|
+
});
|
|
93
|
+
const text = await res.text();
|
|
94
|
+
let body;
|
|
95
|
+
try {
|
|
96
|
+
body = JSON.parse(text);
|
|
97
|
+
} catch {
|
|
98
|
+
body = text;
|
|
99
|
+
}
|
|
100
|
+
if (!res.ok) {
|
|
101
|
+
throw new Error(`bitcoin-meta GET ${url}: HTTP ${res.status} ${String(text).slice(0, 160)}`);
|
|
102
|
+
}
|
|
103
|
+
return body;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export async function btcMetaHealth(opts = {}) {
|
|
107
|
+
const base = metaBase(opts);
|
|
108
|
+
// Always can hit ordinals.com tip as chain liveness (not full meta)
|
|
109
|
+
let tip = null;
|
|
110
|
+
try {
|
|
111
|
+
const fetchImpl = opts.fetchImpl || fetch;
|
|
112
|
+
const r = await fetchImpl("https://ordinals.com/r/blockheight", {
|
|
113
|
+
signal: AbortSignal.timeout(8000),
|
|
114
|
+
});
|
|
115
|
+
tip = Number(await r.text());
|
|
116
|
+
} catch {
|
|
117
|
+
tip = null;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (!base) {
|
|
121
|
+
return {
|
|
122
|
+
ok: tip != null,
|
|
123
|
+
provider: "bitcoin-meta",
|
|
124
|
+
indexerConfigured: false,
|
|
125
|
+
ordinalsComTip: tip,
|
|
126
|
+
note: "Set BTC_META_API_URL and/or UNISAT_API_KEY / BESTINSLOT_API_KEY for balances. Marketplace = Satflow (SATFLOW_API_KEY). Magic Eden BTC is dead.",
|
|
127
|
+
capabilities: {
|
|
128
|
+
tip: tip != null,
|
|
129
|
+
runeBalances: false,
|
|
130
|
+
inscriptions: false,
|
|
131
|
+
marketplace: false,
|
|
132
|
+
},
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Probe common paths; tolerate 404
|
|
137
|
+
let probe = { ok: false, path: null, status: null };
|
|
138
|
+
for (const path of ["/v1/indexer/brc20/best-height", "/v1/health", "/health", "/"]) {
|
|
139
|
+
try {
|
|
140
|
+
const fetchImpl = opts.fetchImpl || fetch;
|
|
141
|
+
const res = await fetchImpl(`${base}${path}`, {
|
|
142
|
+
headers: headers(opts),
|
|
143
|
+
signal: AbortSignal.timeout(8000),
|
|
144
|
+
});
|
|
145
|
+
probe = { ok: res.status > 0 && res.status < 500, path, status: res.status };
|
|
146
|
+
if (res.ok) break;
|
|
147
|
+
} catch {
|
|
148
|
+
/* try next */
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return {
|
|
153
|
+
ok: probe.ok || tip != null,
|
|
154
|
+
provider: "bitcoin-meta",
|
|
155
|
+
indexerConfigured: true,
|
|
156
|
+
baseUrl: base,
|
|
157
|
+
probe,
|
|
158
|
+
ordinalsComTip: tip,
|
|
159
|
+
apiKeyPresent: Boolean(
|
|
160
|
+
process.env.UNISAT_API_KEY ||
|
|
161
|
+
process.env.BESTINSLOT_API_KEY ||
|
|
162
|
+
process.env.BTC_META_API_KEY
|
|
163
|
+
),
|
|
164
|
+
capabilities: {
|
|
165
|
+
tip: tip != null,
|
|
166
|
+
runeBalances: true,
|
|
167
|
+
inscriptions: true,
|
|
168
|
+
marketplace: Boolean(process.env.SATFLOW_API_KEY),
|
|
169
|
+
},
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* Rune balances for an address. Requires configured indexer.
|
|
175
|
+
* Normalizes heterogeneous API shapes into a common list.
|
|
176
|
+
*/
|
|
177
|
+
export async function btcRuneBalances(args = {}, opts = {}) {
|
|
178
|
+
const address = btcAddress(args.address || args.addr, "address");
|
|
179
|
+
const base = metaBase(opts);
|
|
180
|
+
if (!base) {
|
|
181
|
+
return {
|
|
182
|
+
provider: "bitcoin-meta",
|
|
183
|
+
address,
|
|
184
|
+
ok: false,
|
|
185
|
+
balances: [],
|
|
186
|
+
error: "no indexer configured (set BTC_META_API_URL or vendor API key env)",
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Try UniSat-shaped path first, then generic
|
|
191
|
+
const candidates = [
|
|
192
|
+
`${base}/v1/indexer/address/${address}/runes/balance-list?start=0&limit=100`,
|
|
193
|
+
`${base}/v1/runes/address/${address}`,
|
|
194
|
+
`${base}/runes/balance/${address}`,
|
|
195
|
+
`${base}/address/${address}/runes`,
|
|
196
|
+
];
|
|
197
|
+
|
|
198
|
+
let lastErr = null;
|
|
199
|
+
for (const url of candidates) {
|
|
200
|
+
try {
|
|
201
|
+
const body = await getJson(url, opts);
|
|
202
|
+
const list = normalizeRuneBalances(body);
|
|
203
|
+
return {
|
|
204
|
+
provider: "bitcoin-meta",
|
|
205
|
+
address,
|
|
206
|
+
ok: true,
|
|
207
|
+
count: list.length,
|
|
208
|
+
balances: list,
|
|
209
|
+
source: url,
|
|
210
|
+
};
|
|
211
|
+
} catch (e) {
|
|
212
|
+
lastErr = e;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return {
|
|
216
|
+
provider: "bitcoin-meta",
|
|
217
|
+
address,
|
|
218
|
+
ok: false,
|
|
219
|
+
balances: [],
|
|
220
|
+
error: String(lastErr?.message || lastErr || "all indexer paths failed"),
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function normalizeRuneBalances(body) {
|
|
225
|
+
const raw =
|
|
226
|
+
body?.data?.detail ||
|
|
227
|
+
body?.data?.list ||
|
|
228
|
+
body?.data ||
|
|
229
|
+
body?.balances ||
|
|
230
|
+
body?.results ||
|
|
231
|
+
body?.runes ||
|
|
232
|
+
(Array.isArray(body) ? body : []);
|
|
233
|
+
const arr = Array.isArray(raw) ? raw : [];
|
|
234
|
+
return arr.map((r) => ({
|
|
235
|
+
rune: r.rune || r.runeid || r.runeId || r.spacedRune || r.name || r.ticker || null,
|
|
236
|
+
runeId: r.runeid || r.runeId || r.id || null,
|
|
237
|
+
amount: String(r.amount ?? r.balance ?? r.total ?? r.qty ?? "0"),
|
|
238
|
+
symbol: r.symbol || null,
|
|
239
|
+
divisibility: r.divisibility ?? r.div ?? null,
|
|
240
|
+
raw: r,
|
|
241
|
+
}));
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Inscriptions controlled by an address.
|
|
246
|
+
*
|
|
247
|
+
* NOTE: requires a KEYED indexer. ordinals.com recursive has no address index
|
|
248
|
+
* (verified: /r/address -> 404), so the free tier cannot answer this. We say so
|
|
249
|
+
* explicitly rather than returning an empty list that reads like "you own
|
|
250
|
+
* nothing" — a false negative here can get an inscription spent as fee change.
|
|
251
|
+
*/
|
|
252
|
+
export async function btcInscriptions(args = {}, opts = {}) {
|
|
253
|
+
const address = btcAddress(args.address || args.addr, "address");
|
|
254
|
+
const base = metaBase(opts);
|
|
255
|
+
if (!base) {
|
|
256
|
+
return {
|
|
257
|
+
provider: "bitcoin-meta",
|
|
258
|
+
address,
|
|
259
|
+
ok: false,
|
|
260
|
+
inscriptions: [],
|
|
261
|
+
error:
|
|
262
|
+
"no indexer configured — address-indexed lookups need a keyed indexer " +
|
|
263
|
+
"(BTC_META_API_URL + UNISAT_API_KEY / BESTINSLOT_API_KEY). " +
|
|
264
|
+
"ordinals.com recursive is keyless but has no address index.",
|
|
265
|
+
unknownNotEmpty: true,
|
|
266
|
+
keylessAlternatives: ["btc_inscription_info (by inscription id)", "btc_meta_health"],
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
const limit = Math.min(Number(args.limit || 50), 200);
|
|
270
|
+
const candidates = [
|
|
271
|
+
`${base}/v1/indexer/address/${address}/inscription-data?cursor=0&size=${limit}`,
|
|
272
|
+
`${base}/v1/inscriptions/address/${address}?limit=${limit}`,
|
|
273
|
+
`${base}/address/${address}/inscriptions?limit=${limit}`,
|
|
274
|
+
];
|
|
275
|
+
let lastErr = null;
|
|
276
|
+
for (const url of candidates) {
|
|
277
|
+
try {
|
|
278
|
+
const body = await getJson(url, opts);
|
|
279
|
+
const list = normalizeInscriptions(body);
|
|
280
|
+
return {
|
|
281
|
+
provider: "bitcoin-meta",
|
|
282
|
+
address,
|
|
283
|
+
ok: true,
|
|
284
|
+
count: list.length,
|
|
285
|
+
inscriptions: list,
|
|
286
|
+
source: url,
|
|
287
|
+
};
|
|
288
|
+
} catch (e) {
|
|
289
|
+
lastErr = e;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
provider: "bitcoin-meta",
|
|
294
|
+
address,
|
|
295
|
+
ok: false,
|
|
296
|
+
inscriptions: [],
|
|
297
|
+
error: String(lastErr?.message || lastErr || "all indexer paths failed"),
|
|
298
|
+
};
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
/**
|
|
302
|
+
* Inscription metadata by inscription id — KEYLESS via ordinals.com recursive.
|
|
303
|
+
* Verified live: returns content_type, content_length, height, sat, fee, etc.
|
|
304
|
+
*/
|
|
305
|
+
export async function btcInscriptionInfo(args = {}, opts = {}) {
|
|
306
|
+
const id = String(args.inscriptionId || args.id || "").trim();
|
|
307
|
+
if (!/^[0-9a-f]{64}i\d+$/i.test(id)) {
|
|
308
|
+
throw new Error("bitcoin-meta: inscriptionId must look like <64-hex-txid>i<index>");
|
|
309
|
+
}
|
|
310
|
+
const base = opts.ordinalsBase || ORDINALS_RECURSIVE_BASE;
|
|
311
|
+
const info = await getJson(`${base}/r/inscription/${id}`, opts);
|
|
312
|
+
return {
|
|
313
|
+
provider: "bitcoin-meta",
|
|
314
|
+
source: "ordinals.com/r",
|
|
315
|
+
keyless: true,
|
|
316
|
+
inscriptionId: id,
|
|
317
|
+
info,
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Child inscriptions (collection/parent-child) — KEYLESS via ordinals.com.
|
|
323
|
+
*/
|
|
324
|
+
export async function btcInscriptionChildren(args = {}, opts = {}) {
|
|
325
|
+
const id = String(args.inscriptionId || args.id || "").trim();
|
|
326
|
+
if (!/^[0-9a-f]{64}i\d+$/i.test(id)) {
|
|
327
|
+
throw new Error("bitcoin-meta: inscriptionId must look like <64-hex-txid>i<index>");
|
|
328
|
+
}
|
|
329
|
+
const base = opts.ordinalsBase || ORDINALS_RECURSIVE_BASE;
|
|
330
|
+
const page = Number(args.page || 0);
|
|
331
|
+
const body = await getJson(`${base}/r/children/${id}${page ? `/${page}` : ""}`, opts);
|
|
332
|
+
return {
|
|
333
|
+
provider: "bitcoin-meta",
|
|
334
|
+
source: "ordinals.com/r",
|
|
335
|
+
keyless: true,
|
|
336
|
+
inscriptionId: id,
|
|
337
|
+
page,
|
|
338
|
+
children: Array.isArray(body?.ids) ? body.ids : [],
|
|
339
|
+
more: Boolean(body?.more),
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Block info from the ord node itself — KEYLESS. Useful to confirm the ord
|
|
345
|
+
* indexer is at the same tip as Esplora before trusting any metaprotocol read.
|
|
346
|
+
*/
|
|
347
|
+
export async function btcOrdBlockInfo(args = {}, opts = {}) {
|
|
348
|
+
const base = opts.ordinalsBase || ORDINALS_RECURSIVE_BASE;
|
|
349
|
+
const height = args.height ?? (await getJson(`${base}/r/blockheight`, opts));
|
|
350
|
+
const info = await getJson(`${base}/r/blockinfo/${Number(height)}`, opts);
|
|
351
|
+
return {
|
|
352
|
+
provider: "bitcoin-meta",
|
|
353
|
+
source: "ordinals.com/r",
|
|
354
|
+
keyless: true,
|
|
355
|
+
height: Number(height),
|
|
356
|
+
info,
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
function normalizeInscriptions(body) {
|
|
361
|
+
const raw =
|
|
362
|
+
body?.data?.inscription ||
|
|
363
|
+
body?.data?.detail ||
|
|
364
|
+
body?.data?.list ||
|
|
365
|
+
body?.data ||
|
|
366
|
+
body?.inscriptions ||
|
|
367
|
+
body?.results ||
|
|
368
|
+
(Array.isArray(body) ? body : []);
|
|
369
|
+
const arr = Array.isArray(raw) ? raw : [];
|
|
370
|
+
return arr.map((i) => ({
|
|
371
|
+
id: i.inscriptionId || i.id || i.inscription_id || null,
|
|
372
|
+
number: i.inscriptionNumber ?? i.number ?? null,
|
|
373
|
+
sat: i.sat || i.satoshi || null,
|
|
374
|
+
contentType: i.contentType || i.content_type || null,
|
|
375
|
+
utxo: i.utxo || i.output || (i.txid != null ? `${i.txid}:${i.vout ?? i.n}` : null),
|
|
376
|
+
raw: i,
|
|
377
|
+
}));
|
|
378
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Blockscout REST API v2 — verified public explorer instances, no key.
|
|
2
|
+
import { httpJson } from "../http.mjs";
|
|
3
|
+
export const BLOCKSCOUT_CHAINS=Object.freeze({
|
|
4
|
+
1:"https://eth.blockscout.com",
|
|
5
|
+
10:"https://optimism.blockscout.com",
|
|
6
|
+
137:"https://polygon.blockscout.com",
|
|
7
|
+
42161:"https://arbitrum.blockscout.com",
|
|
8
|
+
8453:"https://base.blockscout.com",
|
|
9
|
+
});
|
|
10
|
+
function base(chainId,o={}) { const id=Number(chainId); const u=o.baseUrl || BLOCKSCOUT_CHAINS[id]; if(!u) throw new Error(`Blockscout not configured for chainId ${id}`); return u.replace(/\/$/,""); }
|
|
11
|
+
export async function blockscoutStats(args={},opts={}) { return httpJson(`${base(args.chainId||1,opts)}/api/v2/stats`,{fetchImpl:opts.fetchImpl,timeoutMs:opts.timeoutMs}); }
|
|
12
|
+
export async function blockscoutAddress(args={},opts={}) { if(!args.address)throw new Error("address required"); return httpJson(`${base(args.chainId||1,opts)}/api/v2/addresses/${encodeURIComponent(args.address)}`,{fetchImpl:opts.fetchImpl,timeoutMs:opts.timeoutMs}); }
|
|
13
|
+
export async function blockscoutToken(args={},opts={}) { if(!args.address && !args.tokenAddress)throw new Error("token address required"); return httpJson(`${base(args.chainId||1,opts)}/api/v2/tokens/${encodeURIComponent(args.address||args.tokenAddress)}`,{fetchImpl:opts.fetchImpl,timeoutMs:opts.timeoutMs}); }
|
|
14
|
+
export async function blockscoutHealth(opts={}) { const data=await blockscoutStats({chainId:8453},opts); return {ok:data?.total_blocks!=null || data?.total_transactions!=null,chainId:8453}; }
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
// Bridge quote pack — Across, Hop, Relay (public, no key).
|
|
2
|
+
|
|
3
|
+
import { httpJson } from "../http.mjs";
|
|
4
|
+
import { attachAutoSlippage, bindAutoSlippageGuardToCall, resolveAutoSlippage } from "../../auto-slippage.mjs";
|
|
5
|
+
import { QUOTE_PLACEHOLDER_ADDRESS, quoteAddress } from "../quote-placeholder.mjs";
|
|
6
|
+
|
|
7
|
+
export const ACROSS_API = "https://across.to/api";
|
|
8
|
+
export const HOP_API = "https://api.hop.exchange/v1";
|
|
9
|
+
export const RELAY_API = "https://api.relay.link";
|
|
10
|
+
|
|
11
|
+
const HOP_CHAIN_IDS = {
|
|
12
|
+
ethereum: 1,
|
|
13
|
+
optimism: 10,
|
|
14
|
+
bsc: 56,
|
|
15
|
+
polygon: 137,
|
|
16
|
+
arbitrum: 42161,
|
|
17
|
+
avalanche: 43114,
|
|
18
|
+
base: 8453,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
// ── Across ──────────────────────────────────────────────────────────────────
|
|
22
|
+
|
|
23
|
+
export async function acrossHealth(opts = {}) {
|
|
24
|
+
try {
|
|
25
|
+
const q = await acrossSuggestedFees(
|
|
26
|
+
{
|
|
27
|
+
token: "0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2",
|
|
28
|
+
destinationToken: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
29
|
+
originChainId: 1,
|
|
30
|
+
destinationChainId: 42161,
|
|
31
|
+
amount: "1000000000000000",
|
|
32
|
+
},
|
|
33
|
+
opts
|
|
34
|
+
);
|
|
35
|
+
return { ok: true, estimatedFillTimeSec: q.estimatedFillTimeSec };
|
|
36
|
+
} catch (e) {
|
|
37
|
+
return { ok: false, error: String(e.message || e).slice(0, 160) };
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function acrossSuggestedFees(q = {}, opts = {}) {
|
|
42
|
+
const {
|
|
43
|
+
token,
|
|
44
|
+
destinationToken = token,
|
|
45
|
+
originChainId,
|
|
46
|
+
destinationChainId,
|
|
47
|
+
amount,
|
|
48
|
+
} = q;
|
|
49
|
+
if (!token || originChainId == null || destinationChainId == null || !amount) {
|
|
50
|
+
throw new Error("acrossSuggestedFees requires token, originChainId, destinationChainId, amount");
|
|
51
|
+
}
|
|
52
|
+
const params = new URLSearchParams({
|
|
53
|
+
token,
|
|
54
|
+
destinationToken,
|
|
55
|
+
originChainId: String(originChainId),
|
|
56
|
+
destinationChainId: String(destinationChainId),
|
|
57
|
+
amount: String(amount),
|
|
58
|
+
});
|
|
59
|
+
const base = (opts.baseUrl || process.env.ACROSS_API_URL || ACROSS_API).replace(/\/$/, "");
|
|
60
|
+
return httpJson(`${base}/suggested-fees?${params}`, {
|
|
61
|
+
fetchImpl: opts.fetchImpl,
|
|
62
|
+
timeoutMs: opts.timeoutMs ?? 15_000,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// ── Hop ─────────────────────────────────────────────────────────────────────
|
|
67
|
+
|
|
68
|
+
export async function hopHealth(opts = {}) {
|
|
69
|
+
try {
|
|
70
|
+
const q = await hopQuote(
|
|
71
|
+
{
|
|
72
|
+
amount: "1000000000000000",
|
|
73
|
+
token: "ETH",
|
|
74
|
+
fromChain: "ethereum",
|
|
75
|
+
toChain: "arbitrum",
|
|
76
|
+
slippage: 0.5,
|
|
77
|
+
},
|
|
78
|
+
opts
|
|
79
|
+
);
|
|
80
|
+
return { ok: true, estimatedRecieved: q.estimatedRecieved || q.estimatedReceived };
|
|
81
|
+
} catch (e) {
|
|
82
|
+
return { ok: false, error: String(e.message || e).slice(0, 160) };
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
export async function hopQuote(q = {}, opts = {}) {
|
|
87
|
+
const {
|
|
88
|
+
amount,
|
|
89
|
+
token = "ETH",
|
|
90
|
+
fromChain = "ethereum",
|
|
91
|
+
toChain = "arbitrum",
|
|
92
|
+
} = q;
|
|
93
|
+
if (!amount) throw new Error("hopQuote requires amount");
|
|
94
|
+
const legacyCap = q.slippage == null ? undefined : Math.round(Number(q.slippage) * 100);
|
|
95
|
+
const selected = resolveAutoSlippage({
|
|
96
|
+
liquidityUsd: q.liquidityUsd,
|
|
97
|
+
priceChange5m: q.priceChange5m,
|
|
98
|
+
crossChain: fromChain !== toChain,
|
|
99
|
+
requestedCapBps: q.maxSlippageBps ?? q.slippageBps ?? legacyCap,
|
|
100
|
+
});
|
|
101
|
+
if (!selected.executable) {
|
|
102
|
+
throw new Error(`hop: route requires ${selected.requiredBps} bps above cap ${selected.capBps}`);
|
|
103
|
+
}
|
|
104
|
+
const params = new URLSearchParams({
|
|
105
|
+
amount: String(amount),
|
|
106
|
+
token,
|
|
107
|
+
fromChain,
|
|
108
|
+
toChain,
|
|
109
|
+
// Hop expresses slippage as percentage points: 0.5 = 50 bps.
|
|
110
|
+
slippage: String(selected.selectedBps / 100),
|
|
111
|
+
});
|
|
112
|
+
const base = (opts.baseUrl || process.env.HOP_API_URL || HOP_API).replace(/\/$/, "");
|
|
113
|
+
const result = await httpJson(`${base}/quote?${params}`, {
|
|
114
|
+
fetchImpl: opts.fetchImpl,
|
|
115
|
+
timeoutMs: opts.timeoutMs ?? 15_000,
|
|
116
|
+
});
|
|
117
|
+
const amountOut = result?.estimatedRecieved || result?.estimatedReceived;
|
|
118
|
+
if (!amountOut) return { ...result, autoSlippagePolicy: selected };
|
|
119
|
+
return attachAutoSlippage(result, {
|
|
120
|
+
chainId: Number(q.originChainId || q.chainId || HOP_CHAIN_IDS[fromChain] || 0),
|
|
121
|
+
venue: result?.tx?.to || "hop",
|
|
122
|
+
amountOut,
|
|
123
|
+
liquidityUsd: q.liquidityUsd,
|
|
124
|
+
priceChange5m: q.priceChange5m,
|
|
125
|
+
crossChain: fromChain !== toChain,
|
|
126
|
+
requestedCapBps: q.maxSlippageBps ?? q.slippageBps ?? legacyCap,
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ── Relay ───────────────────────────────────────────────────────────────────
|
|
131
|
+
|
|
132
|
+
export async function relayHealth(opts = {}) {
|
|
133
|
+
try {
|
|
134
|
+
const q = await relayQuote(
|
|
135
|
+
{
|
|
136
|
+
user: QUOTE_PLACEHOLDER_ADDRESS,
|
|
137
|
+
originChainId: 1,
|
|
138
|
+
destinationChainId: 8453,
|
|
139
|
+
originCurrency: "0x0000000000000000000000000000000000000000",
|
|
140
|
+
destinationCurrency: "0x0000000000000000000000000000000000000000",
|
|
141
|
+
amount: "1000000000000000",
|
|
142
|
+
tradeType: "EXACT_INPUT",
|
|
143
|
+
},
|
|
144
|
+
opts
|
|
145
|
+
);
|
|
146
|
+
return { ok: true, hasSteps: Array.isArray(q.steps), stepCount: q.steps?.length || 0 };
|
|
147
|
+
} catch (e) {
|
|
148
|
+
return { ok: false, error: String(e.message || e).slice(0, 160) };
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
export async function relayQuote(q = {}, opts = {}) {
|
|
153
|
+
const {
|
|
154
|
+
user = QUOTE_PLACEHOLDER_ADDRESS,
|
|
155
|
+
originChainId,
|
|
156
|
+
destinationChainId,
|
|
157
|
+
originCurrency = "0x0000000000000000000000000000000000000000",
|
|
158
|
+
destinationCurrency = "0x0000000000000000000000000000000000000000",
|
|
159
|
+
amount,
|
|
160
|
+
tradeType = "EXACT_INPUT",
|
|
161
|
+
} = q;
|
|
162
|
+
if (originChainId == null || destinationChainId == null || !amount) {
|
|
163
|
+
throw new Error("relayQuote requires originChainId, destinationChainId, amount");
|
|
164
|
+
}
|
|
165
|
+
const selected = resolveAutoSlippage({
|
|
166
|
+
liquidityUsd: q.liquidityUsd,
|
|
167
|
+
priceChange5m: q.priceChange5m,
|
|
168
|
+
crossChain: Number(originChainId) !== Number(destinationChainId),
|
|
169
|
+
requestedCapBps: q.maxSlippageBps ?? q.slippageBps,
|
|
170
|
+
});
|
|
171
|
+
if (!selected.executable) {
|
|
172
|
+
throw new Error(`relay: route requires ${selected.requiredBps} bps above cap ${selected.capBps}`);
|
|
173
|
+
}
|
|
174
|
+
const base = (opts.baseUrl || process.env.RELAY_API_URL || RELAY_API).replace(/\/$/, "");
|
|
175
|
+
const result = await httpJson(`${base}/quote`, {
|
|
176
|
+
method: "POST",
|
|
177
|
+
body: {
|
|
178
|
+
user,
|
|
179
|
+
originChainId: Number(originChainId),
|
|
180
|
+
destinationChainId: Number(destinationChainId),
|
|
181
|
+
originCurrency,
|
|
182
|
+
destinationCurrency,
|
|
183
|
+
amount: String(amount),
|
|
184
|
+
tradeType,
|
|
185
|
+
// Relay expects an integer-string in basis points ("50" = 0.50%).
|
|
186
|
+
slippageTolerance: String(selected.selectedBps),
|
|
187
|
+
},
|
|
188
|
+
fetchImpl: opts.fetchImpl,
|
|
189
|
+
timeoutMs: opts.timeoutMs ?? 20_000,
|
|
190
|
+
});
|
|
191
|
+
const amountOut = result?.details?.currencyOut?.amount;
|
|
192
|
+
if (!amountOut || !/^\d+$/.test(String(amountOut))) {
|
|
193
|
+
return { ...result, autoSlippagePolicy: selected };
|
|
194
|
+
}
|
|
195
|
+
return attachAutoSlippage(result, {
|
|
196
|
+
chainId: Number(originChainId),
|
|
197
|
+
venue: result?.steps?.[0]?.items?.[0]?.data?.to || "relay",
|
|
198
|
+
amountOut,
|
|
199
|
+
liquidityUsd: q.liquidityUsd,
|
|
200
|
+
priceChange5m: q.priceChange5m,
|
|
201
|
+
crossChain: Number(originChainId) !== Number(destinationChainId),
|
|
202
|
+
requestedCapBps: q.maxSlippageBps ?? q.slippageBps,
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
export async function relayPrepare(q = {}, opts = {}) {
|
|
207
|
+
const quote = await relayQuote(q, opts);
|
|
208
|
+
const chainId = Number(q.originChainId);
|
|
209
|
+
const items = (quote.steps || []).flatMap((step) =>
|
|
210
|
+
(step.items || []).filter((item) => item?.data?.to && item?.data?.data).map((item) => ({ stepId: step.id, ...item.data }))
|
|
211
|
+
);
|
|
212
|
+
if (!items.length) throw new Error("relay: quote returned no executable transaction items");
|
|
213
|
+
const venue = String(quote?.autoSlippage?.venue || "").toLowerCase();
|
|
214
|
+
if (items.some((tx) => String(tx.to).toLowerCase() !== venue)) {
|
|
215
|
+
throw new Error("relay: route includes a separate approval/transaction that is not yet safely bound");
|
|
216
|
+
}
|
|
217
|
+
const transactions = items.map((tx) => ({
|
|
218
|
+
chainId,
|
|
219
|
+
from: tx.from || q.user,
|
|
220
|
+
to: tx.to,
|
|
221
|
+
data: tx.data,
|
|
222
|
+
value: tx.value ?? "0x0",
|
|
223
|
+
...(tx.gasLimit != null || tx.gas != null ? { gasLimit: tx.gasLimit ?? tx.gas } : {}),
|
|
224
|
+
slippageGuard: bindAutoSlippageGuardToCall(quote.autoSlippage, { chainId, venue: tx.to, data: tx.data }),
|
|
225
|
+
}));
|
|
226
|
+
return {
|
|
227
|
+
provider: "relay",
|
|
228
|
+
calldataReady: true,
|
|
229
|
+
// NOT executable authority. The bytes are assembled but nothing is signed:
|
|
230
|
+
// the user's wallet is still the only thing that can authorize this. The
|
|
231
|
+
// previous `executionReady: true` read as "cleared to execute" and trained
|
|
232
|
+
// agents to treat a quote as permission.
|
|
233
|
+
requiresUserSignature: true,
|
|
234
|
+
signingReady: false,
|
|
235
|
+
broadcastReady: false,
|
|
236
|
+
chainId,
|
|
237
|
+
quote,
|
|
238
|
+
autoSlippage: quote.autoSlippage,
|
|
239
|
+
transactions,
|
|
240
|
+
};
|
|
241
|
+
}
|