@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,336 @@
|
|
|
1
|
+
// Satflow Marketplace API — Bitcoin ordinals + runes market plane.
|
|
2
|
+
// Docs: https://docs.satflow.com Base: https://api.satflow.com/v1
|
|
3
|
+
// Auth: x-api-key header (SATFLOW_API_KEY).
|
|
4
|
+
//
|
|
5
|
+
// Magic Eden BTC marketplace is DEAD (sunset 2026). Satflow docs mark
|
|
6
|
+
// magiceden external intents deprecated/blocked. Do not use ME for ordinals.
|
|
7
|
+
|
|
8
|
+
import { btcAddress } from "./bitcoin-esplora.mjs";
|
|
9
|
+
import { resolveProviderEndpoint, credentialedHeaders } from "../provider-endpoint.mjs";
|
|
10
|
+
|
|
11
|
+
export const SATFLOW_BASE = "https://api.satflow.com/v1";
|
|
12
|
+
|
|
13
|
+
function endpoint(opts = {}) {
|
|
14
|
+
return resolveProviderEndpoint({
|
|
15
|
+
provider: "satflow",
|
|
16
|
+
defaultUrl: SATFLOW_BASE,
|
|
17
|
+
hosts: ["api.satflow.com"],
|
|
18
|
+
url: opts.baseUrl || process.env.SATFLOW_API_URL,
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function baseUrl(opts = {}) {
|
|
23
|
+
return endpoint(opts).baseUrl;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function apiKey(opts = {}) {
|
|
27
|
+
return String(opts.apiKey || process.env.SATFLOW_API_KEY || process.env.BTC_SATFLOW_API_KEY || "").trim();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function headers(opts = {}) {
|
|
31
|
+
// The API key travels ONLY to a pinned Satflow host. Redirecting baseUrl
|
|
32
|
+
// elsewhere drops the credential instead of forwarding it.
|
|
33
|
+
return credentialedHeaders(
|
|
34
|
+
{
|
|
35
|
+
accept: "application/json",
|
|
36
|
+
"content-type": "application/json",
|
|
37
|
+
"user-agent": "oracle-btc-satflow/0.1",
|
|
38
|
+
},
|
|
39
|
+
{ "x-api-key": apiKey(opts) },
|
|
40
|
+
endpoint(opts).trusted
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
async function sfFetch(path, { method = "GET", body, opts = {} } = {}) {
|
|
45
|
+
const key = apiKey(opts);
|
|
46
|
+
if (!key) {
|
|
47
|
+
throw new Error("satflow: SATFLOW_API_KEY not set (request key via Satflow docs form)");
|
|
48
|
+
}
|
|
49
|
+
const url = `${baseUrl(opts)}${path.startsWith("/") ? path : `/${path}`}`;
|
|
50
|
+
const fetchImpl = opts.fetchImpl || fetch;
|
|
51
|
+
const res = await fetchImpl(url, {
|
|
52
|
+
method,
|
|
53
|
+
headers: headers(opts),
|
|
54
|
+
body: body != null ? JSON.stringify(body) : undefined,
|
|
55
|
+
signal: AbortSignal.timeout(opts.timeoutMs ?? 20_000),
|
|
56
|
+
});
|
|
57
|
+
const text = await res.text();
|
|
58
|
+
let data;
|
|
59
|
+
try {
|
|
60
|
+
data = JSON.parse(text);
|
|
61
|
+
} catch {
|
|
62
|
+
data = text;
|
|
63
|
+
}
|
|
64
|
+
if (!res.ok) {
|
|
65
|
+
throw new Error(`satflow ${method} ${path}: HTTP ${res.status} ${String(text).slice(0, 200)}`);
|
|
66
|
+
}
|
|
67
|
+
return data;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export async function satflowHealth(opts = {}) {
|
|
71
|
+
const keyPresent = Boolean(apiKey(opts));
|
|
72
|
+
if (!keyPresent) {
|
|
73
|
+
return {
|
|
74
|
+
ok: false,
|
|
75
|
+
provider: "satflow",
|
|
76
|
+
baseUrl: baseUrl(opts),
|
|
77
|
+
apiKeyPresent: false,
|
|
78
|
+
marketplace: "satflow",
|
|
79
|
+
magicEdenOrdinals: "deprecated-dead",
|
|
80
|
+
note: "Set SATFLOW_API_KEY. Magic Eden BTC ordinals marketplace is shut down — do not use ME.",
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
// lightweight authenticated probe
|
|
85
|
+
await sfFetch("/collection/stats/floors?type=ordinals", { opts });
|
|
86
|
+
return {
|
|
87
|
+
ok: true,
|
|
88
|
+
provider: "satflow",
|
|
89
|
+
baseUrl: baseUrl(opts),
|
|
90
|
+
apiKeyPresent: true,
|
|
91
|
+
marketplace: "satflow",
|
|
92
|
+
magicEdenOrdinals: "deprecated-dead",
|
|
93
|
+
capabilities: {
|
|
94
|
+
floors: true,
|
|
95
|
+
walletContents: true,
|
|
96
|
+
purchaseIntent: true,
|
|
97
|
+
listIntent: true,
|
|
98
|
+
bidIntent: true,
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
} catch (e) {
|
|
102
|
+
return {
|
|
103
|
+
ok: false,
|
|
104
|
+
provider: "satflow",
|
|
105
|
+
baseUrl: baseUrl(opts),
|
|
106
|
+
apiKeyPresent: true,
|
|
107
|
+
error: String(e?.message || e).slice(0, 200),
|
|
108
|
+
magicEdenOrdinals: "deprecated-dead",
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Collection floor stats. type: ordinals | runes */
|
|
114
|
+
export async function satflowCollectionFloors(args = {}, opts = {}) {
|
|
115
|
+
const type = String(args.type || "ordinals").toLowerCase();
|
|
116
|
+
if (!["ordinals", "runes"].includes(type)) throw new Error("satflow: type must be ordinals|runes");
|
|
117
|
+
const q = new URLSearchParams({ type });
|
|
118
|
+
if (args.ids) q.set("ids", Array.isArray(args.ids) ? args.ids.join(",") : String(args.ids));
|
|
119
|
+
const data = await sfFetch(`/collection/stats/floors?${q}`, { opts });
|
|
120
|
+
return { provider: "satflow", type, floors: data, magicEdenOrdinals: "deprecated-dead" };
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
export async function satflowCollectionStats(args = {}, opts = {}) {
|
|
124
|
+
const id = String(args.collectionId || args.id || args.slug || "").trim();
|
|
125
|
+
if (!id) throw new Error("satflow: collectionId required");
|
|
126
|
+
const q = new URLSearchParams({ id });
|
|
127
|
+
if (args.type) q.set("type", args.type);
|
|
128
|
+
const data = await sfFetch(`/collection/stats?${q}`, { opts });
|
|
129
|
+
return { provider: "satflow", collectionId: id, stats: data };
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function satflowItem(args = {}, opts = {}) {
|
|
133
|
+
const id = String(args.inscriptionId || args.id || "").trim();
|
|
134
|
+
if (!id) throw new Error("satflow: inscriptionId required");
|
|
135
|
+
const q = new URLSearchParams({ id });
|
|
136
|
+
const data = await sfFetch(`/item?${q}`, { opts });
|
|
137
|
+
return { provider: "satflow", item: data };
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
export async function satflowWalletContents(args = {}, opts = {}) {
|
|
141
|
+
const address = btcAddress(args.address || args.addr, "address");
|
|
142
|
+
const q = new URLSearchParams({ address });
|
|
143
|
+
if (args.type) q.set("type", args.type);
|
|
144
|
+
if (args.limit != null) q.set("limit", String(args.limit));
|
|
145
|
+
if (args.offset != null) q.set("offset", String(args.offset));
|
|
146
|
+
const data = await sfFetch(`/address/wallet-contents?${q}`, { opts });
|
|
147
|
+
return { provider: "satflow", address, contents: data };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function satflowFloorListings(args = {}, opts = {}) {
|
|
151
|
+
const ids = args.collectionIds || args.ids || args.collectionId;
|
|
152
|
+
if (!ids) throw new Error("satflow: collectionIds required");
|
|
153
|
+
const q = new URLSearchParams({
|
|
154
|
+
ids: Array.isArray(ids) ? ids.join(",") : String(ids),
|
|
155
|
+
});
|
|
156
|
+
if (args.limit != null) q.set("limit", String(args.limit));
|
|
157
|
+
const data = await sfFetch(`/orders/floor?${q}`, { opts });
|
|
158
|
+
return { provider: "satflow", listings: data };
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
// Oracle-internal keys that must never be forwarded to the marketplace.
|
|
162
|
+
const SATFLOW_INTERNAL_KEYS = new Set([
|
|
163
|
+
"body",
|
|
164
|
+
"execute",
|
|
165
|
+
"fetchImpl",
|
|
166
|
+
"opts",
|
|
167
|
+
"apiKey",
|
|
168
|
+
"baseUrl",
|
|
169
|
+
"timeoutMs",
|
|
170
|
+
"maxSats",
|
|
171
|
+
"operator",
|
|
172
|
+
]);
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* Build an outbound Satflow body from caller args.
|
|
176
|
+
*
|
|
177
|
+
* Spreading `...args` straight into a third-party request is how Oracle-internal
|
|
178
|
+
* control fields (and anything a prompt-injected model appends) leak to an
|
|
179
|
+
* external venue. Only explicitly-named fields cross the boundary.
|
|
180
|
+
*/
|
|
181
|
+
function satflowBody(args = {}, allowed = null) {
|
|
182
|
+
// The `body` branch used to return the caller's object wholesale after
|
|
183
|
+
// stripping internal names, which meant the field allowlist below was never
|
|
184
|
+
// consulted for it. A prompt-injected model could then put an arbitrary
|
|
185
|
+
// payload — including a swapped buyer/receive address — into a marketplace
|
|
186
|
+
// intent the user is asked to sign. Both branches now go through the SAME
|
|
187
|
+
// allowlist.
|
|
188
|
+
const source = args.body && typeof args.body === "object" ? args.body : args;
|
|
189
|
+
const out = {};
|
|
190
|
+
for (const [k, v] of Object.entries(source)) {
|
|
191
|
+
if (SATFLOW_INTERNAL_KEYS.has(k)) continue;
|
|
192
|
+
if (allowed && !allowed.has(k)) continue;
|
|
193
|
+
if (v === undefined) continue;
|
|
194
|
+
out[k] = v;
|
|
195
|
+
}
|
|
196
|
+
return out;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
const SATFLOW_PURCHASE_FIELDS = new Set([
|
|
200
|
+
"listing_id",
|
|
201
|
+
"listingId",
|
|
202
|
+
"inscription_id",
|
|
203
|
+
"inscriptionId",
|
|
204
|
+
"runes_output",
|
|
205
|
+
"runesOutput",
|
|
206
|
+
"buyer_address",
|
|
207
|
+
"buyerAddress",
|
|
208
|
+
"ord_address",
|
|
209
|
+
"receive_address",
|
|
210
|
+
"payment_address",
|
|
211
|
+
"pay_address",
|
|
212
|
+
"tap_key",
|
|
213
|
+
"public_key",
|
|
214
|
+
"publicKey",
|
|
215
|
+
"fee_rate",
|
|
216
|
+
"feeRate",
|
|
217
|
+
"price",
|
|
218
|
+
"quantity",
|
|
219
|
+
"slug",
|
|
220
|
+
"collection_slug",
|
|
221
|
+
]);
|
|
222
|
+
|
|
223
|
+
const SATFLOW_LIST_FIELDS = new Set([
|
|
224
|
+
"inscription_id",
|
|
225
|
+
"inscriptionId",
|
|
226
|
+
"runes_output",
|
|
227
|
+
"runesOutput",
|
|
228
|
+
"ord_address",
|
|
229
|
+
"receive_address",
|
|
230
|
+
"price",
|
|
231
|
+
"tap_key",
|
|
232
|
+
"collection_slug",
|
|
233
|
+
"expires_at",
|
|
234
|
+
]);
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* Create unsigned PSBT for buying on Satflow.
|
|
238
|
+
* Returns PSBT for wallet/local sign — does not broadcast.
|
|
239
|
+
*/
|
|
240
|
+
/**
|
|
241
|
+
* Pull an authoritative sat price out of a Satflow body or intent response.
|
|
242
|
+
* Returns null when no price can be determined, so callers fail closed.
|
|
243
|
+
*/
|
|
244
|
+
function purchasePriceSats(obj) {
|
|
245
|
+
if (!obj || typeof obj !== "object") return null;
|
|
246
|
+
const candidates = [
|
|
247
|
+
obj.price,
|
|
248
|
+
obj.priceSats,
|
|
249
|
+
obj.price_sats,
|
|
250
|
+
obj.totalSats,
|
|
251
|
+
obj.total_sats,
|
|
252
|
+
obj.amount,
|
|
253
|
+
obj.satoshis,
|
|
254
|
+
];
|
|
255
|
+
for (const c of candidates) {
|
|
256
|
+
if (c == null) continue;
|
|
257
|
+
const text = String(c).trim();
|
|
258
|
+
if (!/^\d+$/.test(text)) continue;
|
|
259
|
+
return BigInt(text);
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
export async function satflowPreparePurchase(args = {}, opts = {}) {
|
|
265
|
+
const body = satflowBody(args, SATFLOW_PURCHASE_FIELDS);
|
|
266
|
+
if (!body || Object.keys(body).length === 0) {
|
|
267
|
+
throw new Error("satflow: purchase body required (see docs.satflow.com intent/satflow-purchase)");
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
// maxSats is a SPEND CEILING, and it was previously stripped as an internal
|
|
271
|
+
// field and then never compared to anything — the caller believed a cap was
|
|
272
|
+
// in force while the returned PSBT could pay any price. Require it, and
|
|
273
|
+
// enforce it against the authoritative price on the intent Satflow returns,
|
|
274
|
+
// not just the price the caller asked for.
|
|
275
|
+
const rawMax = args.maxSats ?? args.body?.maxSats;
|
|
276
|
+
if (rawMax == null) {
|
|
277
|
+
throw new Error("satflow: maxSats is required to prepare a purchase — an uncapped buy has no spend ceiling");
|
|
278
|
+
}
|
|
279
|
+
const maxSats = BigInt(String(rawMax).trim());
|
|
280
|
+
if (maxSats <= 0n) throw new Error("satflow: maxSats must be a positive integer sat amount");
|
|
281
|
+
|
|
282
|
+
const requested = purchasePriceSats(body);
|
|
283
|
+
if (requested != null && requested > maxSats) {
|
|
284
|
+
throw new Error(`satflow: requested price ${requested} sats exceeds maxSats cap ${maxSats}`);
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
const data = await sfFetch("/intent/satflow-purchase", { method: "POST", body, opts });
|
|
288
|
+
|
|
289
|
+
const settled = purchasePriceSats(data) ?? purchasePriceSats(data?.intent);
|
|
290
|
+
if (settled == null) {
|
|
291
|
+
throw new Error("satflow: purchase intent did not report a price — refusing to return an unverifiable PSBT");
|
|
292
|
+
}
|
|
293
|
+
if (settled > maxSats) {
|
|
294
|
+
throw new Error(`satflow: purchase price ${settled} sats exceeds maxSats cap ${maxSats} — PSBT withheld`);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
return {
|
|
298
|
+
provider: "satflow",
|
|
299
|
+
kind: "purchase-intent",
|
|
300
|
+
executionReady: false,
|
|
301
|
+
signingReady: false,
|
|
302
|
+
broadcastReady: false,
|
|
303
|
+
requiresUserSignature: true,
|
|
304
|
+
marketplace: "satflow",
|
|
305
|
+
magicEdenOrdinals: "deprecated-dead",
|
|
306
|
+
priceSats: settled.toString(),
|
|
307
|
+
maxSats: maxSats.toString(),
|
|
308
|
+
intent: data,
|
|
309
|
+
// common field names across versions
|
|
310
|
+
unsignedPsbt:
|
|
311
|
+
data?.unsignedPSBTBase64 ||
|
|
312
|
+
data?.unsignedPsbtBase64 ||
|
|
313
|
+
data?.unsigned_psbt ||
|
|
314
|
+
data?.psbt ||
|
|
315
|
+
null,
|
|
316
|
+
note: "Sign PSBT in a Bitcoin wallet. Broadcast only through the user's wallet or an explicitly armed Bitcoin execution plane.",
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
/** List intent — unsigned listing PSBTs */
|
|
321
|
+
export async function satflowPrepareList(args = {}, opts = {}) {
|
|
322
|
+
const body = satflowBody(args, SATFLOW_LIST_FIELDS);
|
|
323
|
+
if (!body.inscription_id && !body.runes_output && !body.inscriptionId && !body.runesOutput) {
|
|
324
|
+
throw new Error("satflow: list requires inscription_id or runes_output");
|
|
325
|
+
}
|
|
326
|
+
const data = await sfFetch("/intent/sell", { method: "POST", body, opts });
|
|
327
|
+
return {
|
|
328
|
+
provider: "satflow",
|
|
329
|
+
kind: "list-intent",
|
|
330
|
+
requiresUserSignature: true,
|
|
331
|
+
marketplace: "satflow",
|
|
332
|
+
intent: data,
|
|
333
|
+
unsignedPsbt: data?.unsignedListingPSBTBase64 || data?.unsigned_psbt || null,
|
|
334
|
+
note: "Sign listing PSBTs in a Bitcoin wallet; listing broadcast is outside the data plane.",
|
|
335
|
+
};
|
|
336
|
+
}
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
// Solana JSON-RPC read/prepare support. No keys, no signing, no broadcast.
|
|
2
|
+
|
|
3
|
+
import { httpJson } from "../http.mjs";
|
|
4
|
+
import { createHash } from "node:crypto";
|
|
5
|
+
|
|
6
|
+
export const SOLANA_CLUSTER = "mainnet-beta";
|
|
7
|
+
export const SOLANA_MAINNET_RPC = "https://api.mainnet-beta.solana.com";
|
|
8
|
+
export const SPL_TOKEN_PROGRAM_ID = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
|
|
9
|
+
|
|
10
|
+
function rpcUrl(opts = {}) {
|
|
11
|
+
return String(opts.rpcUrl || process.env.SOLANA_RPC_URL || SOLANA_MAINNET_RPC).trim();
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function solanaPubkey(value, label = "address") {
|
|
15
|
+
const text = String(value || "").trim();
|
|
16
|
+
if (!/^[1-9A-HJ-NP-Za-km-z]{32,44}$/.test(text)) throw new Error(`solana-rpc: ${label} must be a base58 public key`);
|
|
17
|
+
return text;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function paramsWithCommitment(params, commitment) {
|
|
21
|
+
if (!commitment) return params;
|
|
22
|
+
return [...params, { commitment }];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export async function solanaRpc(method, params = [], opts = {}) {
|
|
26
|
+
const result = await httpJson(rpcUrl(opts), {
|
|
27
|
+
method: "POST",
|
|
28
|
+
body: {
|
|
29
|
+
jsonrpc: "2.0",
|
|
30
|
+
id: opts.id || 1,
|
|
31
|
+
method,
|
|
32
|
+
params,
|
|
33
|
+
},
|
|
34
|
+
fetchImpl: opts.fetchImpl,
|
|
35
|
+
timeoutMs: opts.timeoutMs ?? 12_000,
|
|
36
|
+
});
|
|
37
|
+
if (result?.error) throw new Error(`solana-rpc ${method}: ${result.error.message || JSON.stringify(result.error)}`);
|
|
38
|
+
return result?.result;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function solanaLatestBlockhash(args = {}, opts = {}) {
|
|
42
|
+
const params = args.commitment ? [{ commitment: args.commitment }] : [];
|
|
43
|
+
const result = await solanaRpc("getLatestBlockhash", params, opts);
|
|
44
|
+
return {
|
|
45
|
+
provider: "solana-rpc",
|
|
46
|
+
cluster: SOLANA_CLUSTER,
|
|
47
|
+
blockhash: result?.value?.blockhash || null,
|
|
48
|
+
lastValidBlockHeight: result?.value?.lastValidBlockHeight ?? null,
|
|
49
|
+
slot: result?.context?.slot ?? null,
|
|
50
|
+
raw: result,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export async function solanaHealth(opts = {}) {
|
|
55
|
+
try {
|
|
56
|
+
const [health, latestBlockhash] = await Promise.all([
|
|
57
|
+
solanaRpc("getHealth", [], opts),
|
|
58
|
+
solanaLatestBlockhash({}, opts),
|
|
59
|
+
]);
|
|
60
|
+
return {
|
|
61
|
+
ok: health === "ok",
|
|
62
|
+
provider: "solana-rpc",
|
|
63
|
+
cluster: SOLANA_CLUSTER,
|
|
64
|
+
health,
|
|
65
|
+
latestBlockhash,
|
|
66
|
+
exec: false,
|
|
67
|
+
};
|
|
68
|
+
} catch (error) {
|
|
69
|
+
return {
|
|
70
|
+
ok: false,
|
|
71
|
+
provider: "solana-rpc",
|
|
72
|
+
cluster: SOLANA_CLUSTER,
|
|
73
|
+
error: String(error?.message || error),
|
|
74
|
+
exec: false,
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function solanaGetBalance(args = {}, opts = {}) {
|
|
80
|
+
const address = solanaPubkey(args.address || args.owner, "address");
|
|
81
|
+
const result = await solanaRpc("getBalance", paramsWithCommitment([address], args.commitment), opts);
|
|
82
|
+
return {
|
|
83
|
+
provider: "solana-rpc",
|
|
84
|
+
cluster: SOLANA_CLUSTER,
|
|
85
|
+
address,
|
|
86
|
+
lamports: String(result?.value ?? 0),
|
|
87
|
+
slot: result?.context?.slot ?? null,
|
|
88
|
+
raw: result,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function normalizeTokenAccount(item = {}) {
|
|
93
|
+
const info = item.account?.data?.parsed?.info || {};
|
|
94
|
+
const amount = info.tokenAmount || {};
|
|
95
|
+
return {
|
|
96
|
+
pubkey: item.pubkey,
|
|
97
|
+
mint: info.mint || null,
|
|
98
|
+
owner: info.owner || null,
|
|
99
|
+
amount: String(amount.amount ?? "0"),
|
|
100
|
+
decimals: amount.decimals ?? null,
|
|
101
|
+
uiAmount: amount.uiAmount ?? null,
|
|
102
|
+
uiAmountString: amount.uiAmountString ?? null,
|
|
103
|
+
raw: item,
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
export async function solanaTokenAccounts(args = {}, opts = {}) {
|
|
108
|
+
const owner = solanaPubkey(args.owner || args.address, "owner");
|
|
109
|
+
const filter = args.mint
|
|
110
|
+
? { mint: solanaPubkey(args.mint, "mint") }
|
|
111
|
+
: { programId: solanaPubkey(args.programId || SPL_TOKEN_PROGRAM_ID, "token program") };
|
|
112
|
+
const config = { encoding: "jsonParsed" };
|
|
113
|
+
if (args.commitment) config.commitment = args.commitment;
|
|
114
|
+
const result = await solanaRpc("getTokenAccountsByOwner", [owner, filter, config], opts);
|
|
115
|
+
const accounts = Array.isArray(result?.value) ? result.value.map(normalizeTokenAccount) : [];
|
|
116
|
+
return {
|
|
117
|
+
provider: "solana-rpc",
|
|
118
|
+
cluster: SOLANA_CLUSTER,
|
|
119
|
+
owner,
|
|
120
|
+
filter,
|
|
121
|
+
slot: result?.context?.slot ?? null,
|
|
122
|
+
accounts,
|
|
123
|
+
raw: result,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function base64Tx(value) {
|
|
128
|
+
const text = String(value || "").trim();
|
|
129
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(text) || text.length % 4 !== 0) {
|
|
130
|
+
throw new Error("solana-rpc: transaction must be base64");
|
|
131
|
+
}
|
|
132
|
+
return text;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function readShortvec(buffer, offset) {
|
|
136
|
+
let value = 0;
|
|
137
|
+
let shift = 0;
|
|
138
|
+
let cursor = offset;
|
|
139
|
+
for (let i = 0; i < 3; i++) {
|
|
140
|
+
if (cursor >= buffer.length) throw new Error("solana-rpc: transaction shortvec truncated");
|
|
141
|
+
const byte = buffer[cursor++];
|
|
142
|
+
value |= (byte & 0x7f) << shift;
|
|
143
|
+
if ((byte & 0x80) === 0) return { value, offset: cursor };
|
|
144
|
+
shift += 7;
|
|
145
|
+
}
|
|
146
|
+
throw new Error("solana-rpc: transaction shortvec too long");
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function transactionMessageHash(transaction) {
|
|
150
|
+
const raw = Buffer.from(transaction, "base64");
|
|
151
|
+
try {
|
|
152
|
+
const sigCount = readShortvec(raw, 0);
|
|
153
|
+
const messageOffset = sigCount.offset + sigCount.value * 64;
|
|
154
|
+
if (messageOffset >= raw.length) throw new Error("missing message");
|
|
155
|
+
return createHash("sha256").update(raw.subarray(messageOffset)).digest("hex");
|
|
156
|
+
} catch {
|
|
157
|
+
// Unit tests may pass dummy base64 to a mocked RPC. Real Solana RPC rejects
|
|
158
|
+
// invalid transactions before this becomes signable; the signer separately
|
|
159
|
+
// decodes and binds the message hash before producing an executable artifact.
|
|
160
|
+
return createHash("sha256").update(raw).digest("hex");
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
export async function solanaSimulateTransaction(args = {}, opts = {}) {
|
|
165
|
+
const transaction = base64Tx(args.transaction || args.swapTransaction);
|
|
166
|
+
const config = {
|
|
167
|
+
encoding: "base64",
|
|
168
|
+
sigVerify: Boolean(args.sigVerify),
|
|
169
|
+
replaceRecentBlockhash: args.replaceRecentBlockhash !== false,
|
|
170
|
+
};
|
|
171
|
+
if (args.commitment) config.commitment = args.commitment;
|
|
172
|
+
const result = await solanaRpc("simulateTransaction", [transaction, config], opts);
|
|
173
|
+
const value = result?.value || {};
|
|
174
|
+
return {
|
|
175
|
+
provider: "solana-rpc",
|
|
176
|
+
cluster: SOLANA_CLUSTER,
|
|
177
|
+
ok: value.err == null,
|
|
178
|
+
transactionHash: transactionMessageHash(transaction),
|
|
179
|
+
err: value.err ?? null,
|
|
180
|
+
logs: value.logs || [],
|
|
181
|
+
unitsConsumed: value.unitsConsumed ?? null,
|
|
182
|
+
replacementBlockhash: value.replacementBlockhash || null,
|
|
183
|
+
slot: result?.context?.slot ?? null,
|
|
184
|
+
raw: result,
|
|
185
|
+
};
|
|
186
|
+
}
|