@blazephoenix/sdk 1.0.1 → 1.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/README.md +32 -4
- package/dist/index.cjs +21 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +9 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +21 -4
- package/dist/index.js.map +1 -1
- package/llms.txt +8 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -385,6 +385,12 @@ interface RegistryOptions {
|
|
|
385
385
|
* delay a call, and by at most this much; later refreshes run in the
|
|
386
386
|
* background (stale-while-revalidate). */
|
|
387
387
|
timeoutMs?: number;
|
|
388
|
+
/** Route to addresses that only the fetched document supplies (a version
|
|
389
|
+
* released after this SDK). Default false: the document can list them, but
|
|
390
|
+
* resolve() only returns Router/Quoter addresses pinned in this package —
|
|
391
|
+
* the on-chain check of a remote entry reads the entry's own contracts, so
|
|
392
|
+
* it cannot tell a real deployment from a look-alike. */
|
|
393
|
+
remoteVersions?: boolean;
|
|
388
394
|
/** Called for every pin conflict or rejected document — never silently. */
|
|
389
395
|
onWarning?: (msg: string) => void;
|
|
390
396
|
}
|
|
@@ -394,6 +400,7 @@ declare class Registry {
|
|
|
394
400
|
private fetchedAt;
|
|
395
401
|
private lastError?;
|
|
396
402
|
private readonly mode;
|
|
403
|
+
private readonly remoteVersions;
|
|
397
404
|
private readonly url;
|
|
398
405
|
private readonly ttlMs;
|
|
399
406
|
private readonly fetchFn?;
|
|
@@ -422,6 +429,8 @@ declare class Registry {
|
|
|
422
429
|
/** Every deployed version on a chain, newest first. */
|
|
423
430
|
versionsOn(chainId: SupportedChainId): string[];
|
|
424
431
|
resolve(chainId: SupportedChainId, selector?: VersionSelector): ResolvedDeployment;
|
|
432
|
+
/** Router and Quoter both pinned in this package (not filled by a fetched document). */
|
|
433
|
+
private isPinned;
|
|
425
434
|
private latestKnownVersion;
|
|
426
435
|
/** chains × versions table (for dashboards, the MCP, debugging). */
|
|
427
436
|
table(): {
|
package/dist/index.d.ts
CHANGED
|
@@ -385,6 +385,12 @@ interface RegistryOptions {
|
|
|
385
385
|
* delay a call, and by at most this much; later refreshes run in the
|
|
386
386
|
* background (stale-while-revalidate). */
|
|
387
387
|
timeoutMs?: number;
|
|
388
|
+
/** Route to addresses that only the fetched document supplies (a version
|
|
389
|
+
* released after this SDK). Default false: the document can list them, but
|
|
390
|
+
* resolve() only returns Router/Quoter addresses pinned in this package —
|
|
391
|
+
* the on-chain check of a remote entry reads the entry's own contracts, so
|
|
392
|
+
* it cannot tell a real deployment from a look-alike. */
|
|
393
|
+
remoteVersions?: boolean;
|
|
388
394
|
/** Called for every pin conflict or rejected document — never silently. */
|
|
389
395
|
onWarning?: (msg: string) => void;
|
|
390
396
|
}
|
|
@@ -394,6 +400,7 @@ declare class Registry {
|
|
|
394
400
|
private fetchedAt;
|
|
395
401
|
private lastError?;
|
|
396
402
|
private readonly mode;
|
|
403
|
+
private readonly remoteVersions;
|
|
397
404
|
private readonly url;
|
|
398
405
|
private readonly ttlMs;
|
|
399
406
|
private readonly fetchFn?;
|
|
@@ -422,6 +429,8 @@ declare class Registry {
|
|
|
422
429
|
/** Every deployed version on a chain, newest first. */
|
|
423
430
|
versionsOn(chainId: SupportedChainId): string[];
|
|
424
431
|
resolve(chainId: SupportedChainId, selector?: VersionSelector): ResolvedDeployment;
|
|
432
|
+
/** Router and Quoter both pinned in this package (not filled by a fetched document). */
|
|
433
|
+
private isPinned;
|
|
425
434
|
private latestKnownVersion;
|
|
426
435
|
/** chains × versions table (for dashboards, the MCP, debugging). */
|
|
427
436
|
table(): {
|
package/dist/index.js
CHANGED
|
@@ -5354,6 +5354,7 @@ var Registry = class {
|
|
|
5354
5354
|
fetchedAt = 0;
|
|
5355
5355
|
lastError;
|
|
5356
5356
|
mode;
|
|
5357
|
+
remoteVersions;
|
|
5357
5358
|
url;
|
|
5358
5359
|
ttlMs;
|
|
5359
5360
|
fetchFn;
|
|
@@ -5362,6 +5363,7 @@ var Registry = class {
|
|
|
5362
5363
|
overrides = /* @__PURE__ */ new Map();
|
|
5363
5364
|
constructor(opts = {}, overrides) {
|
|
5364
5365
|
this.mode = opts.mode ?? "auto";
|
|
5366
|
+
this.remoteVersions = opts.remoteVersions ?? false;
|
|
5365
5367
|
this.url = opts.url ?? DEPLOYMENTS_URL;
|
|
5366
5368
|
this.ttlMs = opts.ttlMs ?? 10 * 6e4;
|
|
5367
5369
|
this.fetchFn = opts.fetchFn ?? globalThis.fetch;
|
|
@@ -5493,7 +5495,7 @@ var Registry = class {
|
|
|
5493
5495
|
if (!isValidSelector(selector)) throw new BlazeError("bad_request", `bad version selector "${selector}"`);
|
|
5494
5496
|
const ov = this.overrides.get(chainId);
|
|
5495
5497
|
const sel = ov?.version && selector === "latest" ? ov.version : selector;
|
|
5496
|
-
const candidates = this.doc.versions.filter((v) => matchesSelector(v.version, sel) && isDeployed(v.chains[chainId])).sort((a, b) => compareVersions(b.version, a.version));
|
|
5498
|
+
const candidates = this.doc.versions.filter((v) => matchesSelector(v.version, sel) && isDeployed(v.chains[chainId])).filter((v) => this.remoteVersions || this.isPinned(v.version, chainId)).sort((a, b) => compareVersions(b.version, a.version));
|
|
5497
5499
|
const pick = candidates[0];
|
|
5498
5500
|
if (ov && (ov.router || ov.quoter)) {
|
|
5499
5501
|
const base = pick ? { ...pick.chains[chainId] } : {
|
|
@@ -5513,9 +5515,10 @@ var Registry = class {
|
|
|
5513
5515
|
}
|
|
5514
5516
|
if (!pick) {
|
|
5515
5517
|
const deployed = this.versionsOn(chainId);
|
|
5518
|
+
const remoteOnly = this.remoteVersions ? [] : deployed.filter((v) => matchesSelector(v, sel) && !this.isPinned(v, chainId));
|
|
5516
5519
|
throw new BlazeError(
|
|
5517
5520
|
"not_deployed",
|
|
5518
|
-
`no BlazePhoenix deployment matching version "${selector}" on chain ${chainId}` + (deployed.length ? ` (deployed: ${deployed.join(", ")})` : ""),
|
|
5521
|
+
`no BlazePhoenix deployment matching version "${selector}" on chain ${chainId}` + (deployed.length ? ` (deployed: ${deployed.join(", ")})` : "") + (remoteOnly.length ? ` \u2014 ${remoteOnly.join(", ")} is known only from the fetched registry; update the SDK, or set registry.remoteVersions after checking the addresses yourself` : ""),
|
|
5519
5522
|
{ details: { chainId, selector, deployed } }
|
|
5520
5523
|
);
|
|
5521
5524
|
}
|
|
@@ -5524,6 +5527,11 @@ var Registry = class {
|
|
|
5524
5527
|
const source = src("router") === "remote" || src("quoter") === "remote" ? "remote" : "embedded";
|
|
5525
5528
|
return { chainId, version: pick.version, status: pick.status, contracts: { ...set }, source };
|
|
5526
5529
|
}
|
|
5530
|
+
/** Router and Quoter both pinned in this package (not filled by a fetched document). */
|
|
5531
|
+
isPinned(version, chainId) {
|
|
5532
|
+
const src = (k) => this.fieldSource[`${version}|${chainId}|${k}`];
|
|
5533
|
+
return src("router") === "embedded" && src("quoter") === "embedded";
|
|
5534
|
+
}
|
|
5527
5535
|
latestKnownVersion(selector) {
|
|
5528
5536
|
const all = this.doc.versions.map((v) => v.version).sort((a, b) => compareVersions(b, a));
|
|
5529
5537
|
const m = selector ? all.find((v) => matchesSelector(v, selector)) : void 0;
|
|
@@ -5771,16 +5779,19 @@ var BlazePhoenix = class {
|
|
|
5771
5779
|
return { address: c.weth, native: true };
|
|
5772
5780
|
case "WETH":
|
|
5773
5781
|
return { address: c.weth, native: false };
|
|
5782
|
+
// `usdc` holds each chain's one dollar asset: USDG on Robinhood Chain, USDC
|
|
5783
|
+
// elsewhere. The other symbol names a different token there, so it is refused.
|
|
5774
5784
|
case "USDC":
|
|
5775
5785
|
case "USDG":
|
|
5776
|
-
return { address: c.usdc, native: false };
|
|
5786
|
+
if (s.toUpperCase() === (chainId === 4663 ? "USDG" : "USDC")) return { address: c.usdc, native: false };
|
|
5787
|
+
break;
|
|
5777
5788
|
case "BZPX":
|
|
5778
5789
|
if (c.bzpx) return { address: c.bzpx, native: false };
|
|
5779
5790
|
break;
|
|
5780
5791
|
}
|
|
5781
5792
|
throw new BlazeError(
|
|
5782
5793
|
"bad_request",
|
|
5783
|
-
`${side}: "${ref}" is not a 0x address or a built-in symbol (ETH, WETH, USDC, BZPX) on ${c.name} \u2014 pass the token address`
|
|
5794
|
+
`${side}: "${ref}" is not a 0x address or a built-in symbol (ETH, WETH, ${chainId === 4663 ? "USDG" : "USDC"}, BZPX) on ${c.name} \u2014 pass the token address`
|
|
5784
5795
|
);
|
|
5785
5796
|
}
|
|
5786
5797
|
async decimalsOf(client, chainId, t) {
|
|
@@ -6170,6 +6181,12 @@ var BlazePhoenix = class {
|
|
|
6170
6181
|
if (r.status !== "success") throw new BlazeError("reverted", `approval transaction reverted (${approvalHash})`);
|
|
6171
6182
|
}
|
|
6172
6183
|
plan = { ...plan, approval: { ...plan.approval, current: plan.approval.amount } };
|
|
6184
|
+
if (Date.now() - plan.quote.quotedAt > maxAge) {
|
|
6185
|
+
if (!req) {
|
|
6186
|
+
throw new BlazeError("bad_request", `plan went older than ${maxAge}ms while the approval confirmed${approvalHash ? ` (${approvalHash})` : ""} \u2014 the swap was NOT sent; rebuild the plan, or pass \`request\` so it can be rebuilt`);
|
|
6187
|
+
}
|
|
6188
|
+
plan = await this.buildSwap({ ...req, from: req.from ?? account.address });
|
|
6189
|
+
}
|
|
6173
6190
|
}
|
|
6174
6191
|
if (opts.simulate ?? true) {
|
|
6175
6192
|
const sim = await this.simulate(plan, account.address);
|