@blockrun/llm 2.13.0 → 3.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 -49
- package/dist/index.cjs +262 -528
- package/dist/index.d.cts +127 -347
- package/dist/index.d.ts +127 -347
- package/dist/index.js +261 -526
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1512,205 +1512,6 @@ var LLMClient = class _LLMClient {
|
|
|
1512
1512
|
}
|
|
1513
1513
|
throw lastError || new Error("All RPCs failed");
|
|
1514
1514
|
}
|
|
1515
|
-
// ============================================================
|
|
1516
|
-
// X/Twitter endpoints (powered by AttentionVC)
|
|
1517
|
-
// ============================================================
|
|
1518
|
-
/**
|
|
1519
|
-
* Look up X/Twitter user profiles by username.
|
|
1520
|
-
*
|
|
1521
|
-
* Powered by AttentionVC. $0.002 per user (min $0.02, max $0.20).
|
|
1522
|
-
*
|
|
1523
|
-
* @param usernames - Single username or array of usernames (without @)
|
|
1524
|
-
*/
|
|
1525
|
-
async xUserLookup(usernames) {
|
|
1526
|
-
const names = Array.isArray(usernames) ? usernames : [usernames];
|
|
1527
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/lookup", { usernames: names });
|
|
1528
|
-
return data;
|
|
1529
|
-
}
|
|
1530
|
-
/**
|
|
1531
|
-
* Get followers of an X/Twitter user.
|
|
1532
|
-
*
|
|
1533
|
-
* Powered by AttentionVC. $0.05 per page (~200 accounts).
|
|
1534
|
-
*
|
|
1535
|
-
* @param username - X/Twitter username (without @)
|
|
1536
|
-
* @param cursor - Pagination cursor from previous response
|
|
1537
|
-
*/
|
|
1538
|
-
async xFollowers(username, cursor) {
|
|
1539
|
-
const body = { username };
|
|
1540
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1541
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/followers", body);
|
|
1542
|
-
return data;
|
|
1543
|
-
}
|
|
1544
|
-
/**
|
|
1545
|
-
* Get accounts an X/Twitter user is following.
|
|
1546
|
-
*
|
|
1547
|
-
* Powered by AttentionVC. $0.05 per page (~200 accounts).
|
|
1548
|
-
*
|
|
1549
|
-
* @param username - X/Twitter username (without @)
|
|
1550
|
-
* @param cursor - Pagination cursor from previous response
|
|
1551
|
-
*/
|
|
1552
|
-
async xFollowings(username, cursor) {
|
|
1553
|
-
const body = { username };
|
|
1554
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1555
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/followings", body);
|
|
1556
|
-
return data;
|
|
1557
|
-
}
|
|
1558
|
-
/**
|
|
1559
|
-
* Get detailed profile info for a single X/Twitter user.
|
|
1560
|
-
*
|
|
1561
|
-
* Powered by AttentionVC. $0.002 per request.
|
|
1562
|
-
*
|
|
1563
|
-
* @param username - X/Twitter username (without @)
|
|
1564
|
-
*/
|
|
1565
|
-
async xUserInfo(username) {
|
|
1566
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/info", { username });
|
|
1567
|
-
return data;
|
|
1568
|
-
}
|
|
1569
|
-
/**
|
|
1570
|
-
* Get verified (blue-check) followers of an X/Twitter user.
|
|
1571
|
-
*
|
|
1572
|
-
* Powered by AttentionVC. $0.048 per page.
|
|
1573
|
-
*
|
|
1574
|
-
* @param userId - X/Twitter user ID (not username)
|
|
1575
|
-
* @param cursor - Pagination cursor from previous response
|
|
1576
|
-
*/
|
|
1577
|
-
async xVerifiedFollowers(userId, cursor) {
|
|
1578
|
-
const body = { userId };
|
|
1579
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1580
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/verified-followers", body);
|
|
1581
|
-
return data;
|
|
1582
|
-
}
|
|
1583
|
-
/**
|
|
1584
|
-
* Get tweets posted by an X/Twitter user.
|
|
1585
|
-
*
|
|
1586
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1587
|
-
*
|
|
1588
|
-
* @param username - X/Twitter username (without @)
|
|
1589
|
-
* @param includeReplies - Include reply tweets (default: false)
|
|
1590
|
-
* @param cursor - Pagination cursor from previous response
|
|
1591
|
-
*/
|
|
1592
|
-
async xUserTweets(username, includeReplies = false, cursor) {
|
|
1593
|
-
const body = { username, includeReplies };
|
|
1594
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1595
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/tweets", body);
|
|
1596
|
-
return data;
|
|
1597
|
-
}
|
|
1598
|
-
/**
|
|
1599
|
-
* Get tweets that mention an X/Twitter user.
|
|
1600
|
-
*
|
|
1601
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1602
|
-
*
|
|
1603
|
-
* @param username - X/Twitter username (without @)
|
|
1604
|
-
* @param sinceTime - Start time filter (ISO8601 or Unix timestamp)
|
|
1605
|
-
* @param untilTime - End time filter (ISO8601 or Unix timestamp)
|
|
1606
|
-
* @param cursor - Pagination cursor from previous response
|
|
1607
|
-
*/
|
|
1608
|
-
async xUserMentions(username, sinceTime, untilTime, cursor) {
|
|
1609
|
-
const body = { username };
|
|
1610
|
-
if (sinceTime !== void 0) body.sinceTime = sinceTime;
|
|
1611
|
-
if (untilTime !== void 0) body.untilTime = untilTime;
|
|
1612
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1613
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/mentions", body);
|
|
1614
|
-
return data;
|
|
1615
|
-
}
|
|
1616
|
-
/**
|
|
1617
|
-
* Fetch full tweet data for up to 200 tweet IDs.
|
|
1618
|
-
*
|
|
1619
|
-
* Powered by AttentionVC. $0.16 per batch.
|
|
1620
|
-
*
|
|
1621
|
-
* @param tweetIds - Single tweet ID or array of tweet IDs (max 200)
|
|
1622
|
-
*/
|
|
1623
|
-
async xTweetLookup(tweetIds) {
|
|
1624
|
-
const ids = Array.isArray(tweetIds) ? tweetIds : [tweetIds];
|
|
1625
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/lookup", { tweet_ids: ids });
|
|
1626
|
-
return data;
|
|
1627
|
-
}
|
|
1628
|
-
/**
|
|
1629
|
-
* Get replies to a specific tweet.
|
|
1630
|
-
*
|
|
1631
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1632
|
-
*
|
|
1633
|
-
* @param tweetId - The tweet ID to get replies for
|
|
1634
|
-
* @param queryType - Sort order: 'Latest' or 'Default'
|
|
1635
|
-
* @param cursor - Pagination cursor from previous response
|
|
1636
|
-
*/
|
|
1637
|
-
async xTweetReplies(tweetId, queryType = "Latest", cursor) {
|
|
1638
|
-
const body = { tweetId, queryType };
|
|
1639
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1640
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/replies", body);
|
|
1641
|
-
return data;
|
|
1642
|
-
}
|
|
1643
|
-
/**
|
|
1644
|
-
* Get the full thread context for a tweet.
|
|
1645
|
-
*
|
|
1646
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1647
|
-
*
|
|
1648
|
-
* @param tweetId - The tweet ID to get thread for
|
|
1649
|
-
* @param cursor - Pagination cursor from previous response
|
|
1650
|
-
*/
|
|
1651
|
-
async xTweetThread(tweetId, cursor) {
|
|
1652
|
-
const body = { tweetId };
|
|
1653
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1654
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/thread", body);
|
|
1655
|
-
return data;
|
|
1656
|
-
}
|
|
1657
|
-
/**
|
|
1658
|
-
* Search X/Twitter with advanced query operators.
|
|
1659
|
-
*
|
|
1660
|
-
* Powered by AttentionVC. $0.032 per page.
|
|
1661
|
-
*
|
|
1662
|
-
* @param query - Search query (supports Twitter search operators)
|
|
1663
|
-
* @param queryType - Sort order: 'Latest', 'Top', or 'Default'
|
|
1664
|
-
* @param cursor - Pagination cursor from previous response
|
|
1665
|
-
*/
|
|
1666
|
-
async xSearch(query, queryType = "Latest", cursor) {
|
|
1667
|
-
const body = { query, queryType };
|
|
1668
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
1669
|
-
const data = await this.requestWithPaymentRaw("/v1/x/search", body);
|
|
1670
|
-
return data;
|
|
1671
|
-
}
|
|
1672
|
-
/**
|
|
1673
|
-
* Get current trending topics on X/Twitter.
|
|
1674
|
-
*
|
|
1675
|
-
* Powered by AttentionVC. $0.002 per request.
|
|
1676
|
-
*/
|
|
1677
|
-
async xTrending() {
|
|
1678
|
-
const data = await this.requestWithPaymentRaw("/v1/x/trending", {});
|
|
1679
|
-
return data;
|
|
1680
|
-
}
|
|
1681
|
-
/**
|
|
1682
|
-
* Get rising/viral articles from X/Twitter.
|
|
1683
|
-
*
|
|
1684
|
-
* Powered by AttentionVC intelligence layer. $0.05 per request.
|
|
1685
|
-
*/
|
|
1686
|
-
async xArticlesRising() {
|
|
1687
|
-
const data = await this.requestWithPaymentRaw("/v1/x/articles/rising", {});
|
|
1688
|
-
return data;
|
|
1689
|
-
}
|
|
1690
|
-
/**
|
|
1691
|
-
* Get author analytics and intelligence metrics for an X/Twitter user.
|
|
1692
|
-
*
|
|
1693
|
-
* Powered by AttentionVC intelligence layer. $0.02 per request.
|
|
1694
|
-
*
|
|
1695
|
-
* @param handle - X/Twitter handle (without @)
|
|
1696
|
-
*/
|
|
1697
|
-
async xAuthorAnalytics(handle) {
|
|
1698
|
-
const data = await this.requestWithPaymentRaw("/v1/x/authors", { handle });
|
|
1699
|
-
return data;
|
|
1700
|
-
}
|
|
1701
|
-
/**
|
|
1702
|
-
* Compare two X/Twitter authors side-by-side with intelligence metrics.
|
|
1703
|
-
*
|
|
1704
|
-
* Powered by AttentionVC intelligence layer. $0.05 per request.
|
|
1705
|
-
*
|
|
1706
|
-
* @param handle1 - First X/Twitter handle (without @)
|
|
1707
|
-
* @param handle2 - Second X/Twitter handle (without @)
|
|
1708
|
-
*/
|
|
1709
|
-
async xCompareAuthors(handle1, handle2) {
|
|
1710
|
-
const data = await this.requestWithPaymentRaw("/v1/x/compare", { handle1, handle2 });
|
|
1711
|
-
return data;
|
|
1712
|
-
}
|
|
1713
|
-
// ── Prediction Markets (Powered by Predexon) ────────────────────────────
|
|
1714
1515
|
/**
|
|
1715
1516
|
* Query Predexon prediction market data (GET endpoints).
|
|
1716
1517
|
*
|
|
@@ -1795,6 +1596,120 @@ var LLMClient = class _LLMClient {
|
|
|
1795
1596
|
async pmWalletCluster(address) {
|
|
1796
1597
|
return this.pm(`polymarket/wallet/${address}/cluster`);
|
|
1797
1598
|
}
|
|
1599
|
+
// ============================================================
|
|
1600
|
+
// DefiLlama (DeFi protocols / TVL / yields / prices)
|
|
1601
|
+
// ============================================================
|
|
1602
|
+
/**
|
|
1603
|
+
* Query DefiLlama DeFi data (GET passthrough). Powered by DefiLlama.
|
|
1604
|
+
* $0.005/call for protocols / protocol/{slug} / chains / yields;
|
|
1605
|
+
* $0.001/call for prices/{coins}.
|
|
1606
|
+
*
|
|
1607
|
+
* @param path - e.g. "protocols", "protocol/aave", "chains", "yields",
|
|
1608
|
+
* "prices/coingecko:bitcoin,base:0x..."
|
|
1609
|
+
* @param params - Query parameters passed through to DefiLlama
|
|
1610
|
+
*/
|
|
1611
|
+
async defi(path5, params) {
|
|
1612
|
+
return this.getWithPaymentRaw(`/v1/defillama/${path5}`, params);
|
|
1613
|
+
}
|
|
1614
|
+
/** All DeFi protocols with TVL ($0.005/call). */
|
|
1615
|
+
async defiProtocols() {
|
|
1616
|
+
return this.defi("protocols");
|
|
1617
|
+
}
|
|
1618
|
+
/** Single protocol details + historical TVL ($0.005/call). */
|
|
1619
|
+
async defiProtocol(slug) {
|
|
1620
|
+
return this.defi(`protocol/${slug}`);
|
|
1621
|
+
}
|
|
1622
|
+
/** Current TVL of every chain ($0.005/call). */
|
|
1623
|
+
async defiChains() {
|
|
1624
|
+
return this.defi("chains");
|
|
1625
|
+
}
|
|
1626
|
+
/** Yield pools with APY/TVL ($0.005/call). */
|
|
1627
|
+
async defiYields(params) {
|
|
1628
|
+
return this.defi("yields", params);
|
|
1629
|
+
}
|
|
1630
|
+
/** Token price lookup ($0.001/call). Coins like "coingecko:bitcoin" or "{chain}:{address}". */
|
|
1631
|
+
async defiPrices(coins) {
|
|
1632
|
+
const joined = Array.isArray(coins) ? coins.join(",") : coins;
|
|
1633
|
+
return this.defi(`prices/${joined}`);
|
|
1634
|
+
}
|
|
1635
|
+
// ============================================================
|
|
1636
|
+
// 0x DEX (swap quotes + gasless) — free passthrough
|
|
1637
|
+
// ============================================================
|
|
1638
|
+
/**
|
|
1639
|
+
* Query the 0x Swap / Gasless APIs (free — no x402 payment; BlockRun
|
|
1640
|
+
* takes an on-chain affiliate fee on executed swaps instead).
|
|
1641
|
+
*
|
|
1642
|
+
* @param path - "price", "quote", "gasless/price", "gasless/quote",
|
|
1643
|
+
* "gasless/submit" (POST), "gasless/status/{hash}",
|
|
1644
|
+
* "gasless/approval-tokens", "gasless/chains", "swap/chains"
|
|
1645
|
+
* @param params - Query params (chainId, sellToken, buyToken, sellAmount, taker, ...)
|
|
1646
|
+
* @param body - JSON body — pass to switch to POST (gasless/submit only)
|
|
1647
|
+
*/
|
|
1648
|
+
async dex(path5, params, body) {
|
|
1649
|
+
if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path5}`, body);
|
|
1650
|
+
return this.getWithPaymentRaw(`/v1/zerox/${path5}`, params);
|
|
1651
|
+
}
|
|
1652
|
+
/** Indicative Permit2 swap price — no commitment (free). */
|
|
1653
|
+
async dexPrice(params) {
|
|
1654
|
+
return this.dex("price", params);
|
|
1655
|
+
}
|
|
1656
|
+
/** Firm Permit2 swap quote with permit2.eip712 + tx data (free). */
|
|
1657
|
+
async dexQuote(params) {
|
|
1658
|
+
return this.dex("quote", params);
|
|
1659
|
+
}
|
|
1660
|
+
/** Gasless indicative price quote (free). */
|
|
1661
|
+
async dexGaslessPrice(params) {
|
|
1662
|
+
return this.dex("gasless/price", params);
|
|
1663
|
+
}
|
|
1664
|
+
/** Gasless firm quote — returns trade.eip712 to sign (free). */
|
|
1665
|
+
async dexGaslessQuote(params) {
|
|
1666
|
+
return this.dex("gasless/quote", params);
|
|
1667
|
+
}
|
|
1668
|
+
/** Submit a signed gasless trade; the 0x relayer pays gas (free). */
|
|
1669
|
+
async dexGaslessSubmit(body) {
|
|
1670
|
+
return this.dex("gasless/submit", void 0, body);
|
|
1671
|
+
}
|
|
1672
|
+
/** Poll a gasless trade's status by tradeHash (free). */
|
|
1673
|
+
async dexGaslessStatus(tradeHash) {
|
|
1674
|
+
return this.dex(`gasless/status/${tradeHash}`);
|
|
1675
|
+
}
|
|
1676
|
+
/** Chains where the Swap API is supported (free). */
|
|
1677
|
+
async dexChains() {
|
|
1678
|
+
return this.dex("swap/chains");
|
|
1679
|
+
}
|
|
1680
|
+
/** Chains where the Gasless API is supported (free). */
|
|
1681
|
+
async dexGaslessChains() {
|
|
1682
|
+
return this.dex("gasless/chains");
|
|
1683
|
+
}
|
|
1684
|
+
// ============================================================
|
|
1685
|
+
// Modal Sandbox (pay-per-call cloud compute)
|
|
1686
|
+
// ============================================================
|
|
1687
|
+
/**
|
|
1688
|
+
* Call the Modal sandbox compute API (POST passthrough).
|
|
1689
|
+
*
|
|
1690
|
+
* @param path - "sandbox/create" ($0.01 CPU / $0.05 GPU), "sandbox/exec",
|
|
1691
|
+
* "sandbox/status", "sandbox/terminate" ($0.001 each)
|
|
1692
|
+
* @param body - JSON body for the endpoint
|
|
1693
|
+
*/
|
|
1694
|
+
async modal(path5, body) {
|
|
1695
|
+
return this.requestWithPaymentRaw(`/v1/modal/${path5}`, body ?? {});
|
|
1696
|
+
}
|
|
1697
|
+
/** Create a sandboxed compute environment ($0.01 CPU / $0.05 GPU). */
|
|
1698
|
+
async modalSandboxCreate(body) {
|
|
1699
|
+
return this.modal("sandbox/create", body);
|
|
1700
|
+
}
|
|
1701
|
+
/** Execute a command in a sandbox; returns stdout/stderr ($0.001). */
|
|
1702
|
+
async modalSandboxExec(sandboxId, command, extra) {
|
|
1703
|
+
return this.modal("sandbox/exec", { sandbox_id: sandboxId, command, ...extra });
|
|
1704
|
+
}
|
|
1705
|
+
/** Check a sandbox's status ($0.001). */
|
|
1706
|
+
async modalSandboxStatus(sandboxId) {
|
|
1707
|
+
return this.modal("sandbox/status", { sandbox_id: sandboxId });
|
|
1708
|
+
}
|
|
1709
|
+
/** Terminate a sandbox ($0.001). */
|
|
1710
|
+
async modalSandboxTerminate(sandboxId) {
|
|
1711
|
+
return this.modal("sandbox/terminate", { sandbox_id: sandboxId });
|
|
1712
|
+
}
|
|
1798
1713
|
/**
|
|
1799
1714
|
* Get current session spending.
|
|
1800
1715
|
*
|
|
@@ -3436,217 +3351,10 @@ var SearchClient = class {
|
|
|
3436
3351
|
}
|
|
3437
3352
|
};
|
|
3438
3353
|
|
|
3439
|
-
// src/
|
|
3354
|
+
// src/price.ts
|
|
3440
3355
|
import { privateKeyToAccount as privateKeyToAccount10 } from "viem/accounts";
|
|
3441
3356
|
var DEFAULT_API_URL10 = "https://blockrun.ai/api";
|
|
3442
|
-
var DEFAULT_TIMEOUT10 =
|
|
3443
|
-
var XClient = class _XClient {
|
|
3444
|
-
account;
|
|
3445
|
-
privateKey;
|
|
3446
|
-
apiUrl;
|
|
3447
|
-
timeout;
|
|
3448
|
-
static deprecationWarned = false;
|
|
3449
|
-
constructor(options = {}) {
|
|
3450
|
-
if (!_XClient.deprecationWarned) {
|
|
3451
|
-
console.warn(
|
|
3452
|
-
"[@blockrun/llm] XClient: BlockRun's /v1/x/* (AttentionVC) integration was removed 2026-04-30. All calls will return HTTP 404 until a replacement X data upstream is reintroduced."
|
|
3453
|
-
);
|
|
3454
|
-
_XClient.deprecationWarned = true;
|
|
3455
|
-
}
|
|
3456
|
-
const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
|
|
3457
|
-
const privateKey = options.privateKey || envKey;
|
|
3458
|
-
if (!privateKey) {
|
|
3459
|
-
throw new Error(
|
|
3460
|
-
"Private key required. Pass privateKey in options or set BLOCKRUN_WALLET_KEY environment variable."
|
|
3461
|
-
);
|
|
3462
|
-
}
|
|
3463
|
-
validatePrivateKey(privateKey);
|
|
3464
|
-
this.privateKey = privateKey;
|
|
3465
|
-
this.account = privateKeyToAccount10(privateKey);
|
|
3466
|
-
const apiUrl = options.apiUrl || DEFAULT_API_URL10;
|
|
3467
|
-
validateApiUrl(apiUrl);
|
|
3468
|
-
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
3469
|
-
this.timeout = options.timeout || DEFAULT_TIMEOUT10;
|
|
3470
|
-
}
|
|
3471
|
-
// ───────── User endpoints ─────────
|
|
3472
|
-
userLookup(usernames) {
|
|
3473
|
-
return this.post("/v1/x/users/lookup", { usernames });
|
|
3474
|
-
}
|
|
3475
|
-
userInfo(username) {
|
|
3476
|
-
return this.post("/v1/x/users/info", { username });
|
|
3477
|
-
}
|
|
3478
|
-
followers(username, cursor) {
|
|
3479
|
-
const body = { username };
|
|
3480
|
-
if (cursor) body.cursor = cursor;
|
|
3481
|
-
return this.post("/v1/x/users/followers", body);
|
|
3482
|
-
}
|
|
3483
|
-
/** `/v1/x/users/following` (singular path variant). */
|
|
3484
|
-
following(username, cursor) {
|
|
3485
|
-
const body = { username };
|
|
3486
|
-
if (cursor) body.cursor = cursor;
|
|
3487
|
-
return this.post("/v1/x/users/following", body);
|
|
3488
|
-
}
|
|
3489
|
-
/** `/v1/x/users/followings` (plural path variant). */
|
|
3490
|
-
followings(username, cursor) {
|
|
3491
|
-
const body = { username };
|
|
3492
|
-
if (cursor) body.cursor = cursor;
|
|
3493
|
-
return this.post("/v1/x/users/followings", body);
|
|
3494
|
-
}
|
|
3495
|
-
verifiedFollowers(userId, cursor) {
|
|
3496
|
-
const body = { userId };
|
|
3497
|
-
if (cursor) body.cursor = cursor;
|
|
3498
|
-
return this.post(
|
|
3499
|
-
"/v1/x/users/verified-followers",
|
|
3500
|
-
body
|
|
3501
|
-
);
|
|
3502
|
-
}
|
|
3503
|
-
userTweets(options) {
|
|
3504
|
-
if (!options.username && !options.userId) {
|
|
3505
|
-
throw new Error("Either username or userId is required");
|
|
3506
|
-
}
|
|
3507
|
-
const body = {};
|
|
3508
|
-
if (options.username) body.username = options.username;
|
|
3509
|
-
if (options.userId) body.userId = options.userId;
|
|
3510
|
-
if (options.cursor) body.cursor = options.cursor;
|
|
3511
|
-
if (options.includeReplies !== void 0) body.includeReplies = options.includeReplies;
|
|
3512
|
-
return this.post("/v1/x/users/tweets", body);
|
|
3513
|
-
}
|
|
3514
|
-
mentions(username, options) {
|
|
3515
|
-
const body = { username };
|
|
3516
|
-
if (options?.sinceTime) body.sinceTime = options.sinceTime;
|
|
3517
|
-
if (options?.untilTime) body.untilTime = options.untilTime;
|
|
3518
|
-
if (options?.cursor) body.cursor = options.cursor;
|
|
3519
|
-
return this.post("/v1/x/users/mentions", body);
|
|
3520
|
-
}
|
|
3521
|
-
// ───────── Tweet endpoints ─────────
|
|
3522
|
-
tweetLookup(tweetIds) {
|
|
3523
|
-
return this.post("/v1/x/tweets/lookup", {
|
|
3524
|
-
tweet_ids: tweetIds
|
|
3525
|
-
});
|
|
3526
|
-
}
|
|
3527
|
-
tweetReplies(tweetId, options) {
|
|
3528
|
-
const body = { tweetId };
|
|
3529
|
-
if (options?.cursor) body.cursor = options.cursor;
|
|
3530
|
-
if (options?.queryType) body.queryType = options.queryType;
|
|
3531
|
-
return this.post("/v1/x/tweets/replies", body);
|
|
3532
|
-
}
|
|
3533
|
-
tweetThread(tweetId, cursor) {
|
|
3534
|
-
const body = { tweetId };
|
|
3535
|
-
if (cursor) body.cursor = cursor;
|
|
3536
|
-
return this.post("/v1/x/tweets/thread", body);
|
|
3537
|
-
}
|
|
3538
|
-
// ───────── Search & discovery ─────────
|
|
3539
|
-
search(query, options) {
|
|
3540
|
-
const body = { query };
|
|
3541
|
-
if (options?.queryType) body.queryType = options.queryType;
|
|
3542
|
-
if (options?.cursor) body.cursor = options.cursor;
|
|
3543
|
-
return this.post("/v1/x/search", body);
|
|
3544
|
-
}
|
|
3545
|
-
trending() {
|
|
3546
|
-
return this.post("/v1/x/trending", {});
|
|
3547
|
-
}
|
|
3548
|
-
articlesRising() {
|
|
3549
|
-
return this.post("/v1/x/articles/rising", {});
|
|
3550
|
-
}
|
|
3551
|
-
// ───────── Internals ─────────
|
|
3552
|
-
async post(endpoint, body) {
|
|
3553
|
-
const url = `${this.apiUrl}${endpoint}`;
|
|
3554
|
-
const response = await this.fetchWithTimeout(url, {
|
|
3555
|
-
method: "POST",
|
|
3556
|
-
headers: { "Content-Type": "application/json" },
|
|
3557
|
-
body: JSON.stringify(body)
|
|
3558
|
-
});
|
|
3559
|
-
if (response.status === 402) {
|
|
3560
|
-
return this.payAndRetry(url, body, response);
|
|
3561
|
-
}
|
|
3562
|
-
if (!response.ok) {
|
|
3563
|
-
let errorBody;
|
|
3564
|
-
try {
|
|
3565
|
-
errorBody = await response.json();
|
|
3566
|
-
} catch {
|
|
3567
|
-
errorBody = { error: "Request failed" };
|
|
3568
|
-
}
|
|
3569
|
-
throw new APIError(
|
|
3570
|
-
`API error: ${response.status}`,
|
|
3571
|
-
response.status,
|
|
3572
|
-
sanitizeErrorResponse(errorBody)
|
|
3573
|
-
);
|
|
3574
|
-
}
|
|
3575
|
-
return response.json();
|
|
3576
|
-
}
|
|
3577
|
-
async payAndRetry(url, body, response) {
|
|
3578
|
-
let paymentHeader = response.headers.get("payment-required");
|
|
3579
|
-
if (!paymentHeader) {
|
|
3580
|
-
try {
|
|
3581
|
-
const respBody = await response.json();
|
|
3582
|
-
if (respBody.x402 || respBody.accepts) {
|
|
3583
|
-
paymentHeader = btoa(JSON.stringify(respBody));
|
|
3584
|
-
}
|
|
3585
|
-
} catch {
|
|
3586
|
-
}
|
|
3587
|
-
}
|
|
3588
|
-
if (!paymentHeader) {
|
|
3589
|
-
throw new PaymentError("402 response but no payment requirements found");
|
|
3590
|
-
}
|
|
3591
|
-
const paymentRequired = parsePaymentRequired(paymentHeader);
|
|
3592
|
-
const details = extractPaymentDetails(paymentRequired);
|
|
3593
|
-
const paymentPayload = await createPaymentPayload(
|
|
3594
|
-
this.privateKey,
|
|
3595
|
-
this.account.address,
|
|
3596
|
-
details.recipient,
|
|
3597
|
-
details.amount,
|
|
3598
|
-
details.network || "eip155:8453",
|
|
3599
|
-
{
|
|
3600
|
-
resourceUrl: details.resource?.url || url,
|
|
3601
|
-
resourceDescription: details.resource?.description || "BlockRun X API",
|
|
3602
|
-
maxTimeoutSeconds: details.maxTimeoutSeconds || 300,
|
|
3603
|
-
extra: details.extra
|
|
3604
|
-
}
|
|
3605
|
-
);
|
|
3606
|
-
const retry = await this.fetchWithTimeout(url, {
|
|
3607
|
-
method: "POST",
|
|
3608
|
-
headers: {
|
|
3609
|
-
"Content-Type": "application/json",
|
|
3610
|
-
"PAYMENT-SIGNATURE": paymentPayload
|
|
3611
|
-
},
|
|
3612
|
-
body: JSON.stringify(body)
|
|
3613
|
-
});
|
|
3614
|
-
if (retry.status === 402) {
|
|
3615
|
-
throw new PaymentError("Payment was rejected. Check your wallet balance.");
|
|
3616
|
-
}
|
|
3617
|
-
if (!retry.ok) {
|
|
3618
|
-
let errorBody;
|
|
3619
|
-
try {
|
|
3620
|
-
errorBody = await retry.json();
|
|
3621
|
-
} catch {
|
|
3622
|
-
errorBody = { error: "Request failed" };
|
|
3623
|
-
}
|
|
3624
|
-
throw new APIError(
|
|
3625
|
-
`API error after payment: ${retry.status}`,
|
|
3626
|
-
retry.status,
|
|
3627
|
-
sanitizeErrorResponse(errorBody)
|
|
3628
|
-
);
|
|
3629
|
-
}
|
|
3630
|
-
return retry.json();
|
|
3631
|
-
}
|
|
3632
|
-
async fetchWithTimeout(url, init) {
|
|
3633
|
-
const controller = new AbortController();
|
|
3634
|
-
const timeoutId = setTimeout(() => controller.abort(), this.timeout);
|
|
3635
|
-
try {
|
|
3636
|
-
return await fetch(url, { ...init, signal: controller.signal });
|
|
3637
|
-
} finally {
|
|
3638
|
-
clearTimeout(timeoutId);
|
|
3639
|
-
}
|
|
3640
|
-
}
|
|
3641
|
-
getWalletAddress() {
|
|
3642
|
-
return this.account.address;
|
|
3643
|
-
}
|
|
3644
|
-
};
|
|
3645
|
-
|
|
3646
|
-
// src/price.ts
|
|
3647
|
-
import { privateKeyToAccount as privateKeyToAccount11 } from "viem/accounts";
|
|
3648
|
-
var DEFAULT_API_URL11 = "https://blockrun.ai/api";
|
|
3649
|
-
var DEFAULT_TIMEOUT11 = 3e4;
|
|
3357
|
+
var DEFAULT_TIMEOUT10 = 3e4;
|
|
3650
3358
|
var PriceClient = class {
|
|
3651
3359
|
account = null;
|
|
3652
3360
|
privateKey = null;
|
|
@@ -3664,12 +3372,12 @@ var PriceClient = class {
|
|
|
3664
3372
|
if (privateKey) {
|
|
3665
3373
|
validatePrivateKey(privateKey);
|
|
3666
3374
|
this.privateKey = privateKey;
|
|
3667
|
-
this.account =
|
|
3375
|
+
this.account = privateKeyToAccount10(privateKey);
|
|
3668
3376
|
}
|
|
3669
|
-
const apiUrl = options.apiUrl ||
|
|
3377
|
+
const apiUrl = options.apiUrl || DEFAULT_API_URL10;
|
|
3670
3378
|
validateApiUrl(apiUrl);
|
|
3671
3379
|
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
3672
|
-
this.timeout = options.timeout ||
|
|
3380
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT10;
|
|
3673
3381
|
}
|
|
3674
3382
|
async price(category, symbol, options) {
|
|
3675
3383
|
if (!symbol) throw new Error("symbol is required");
|
|
@@ -3848,9 +3556,9 @@ function buildUrl(base, query) {
|
|
|
3848
3556
|
}
|
|
3849
3557
|
|
|
3850
3558
|
// src/surf.ts
|
|
3851
|
-
import { privateKeyToAccount as
|
|
3852
|
-
var
|
|
3853
|
-
var
|
|
3559
|
+
import { privateKeyToAccount as privateKeyToAccount11 } from "viem/accounts";
|
|
3560
|
+
var DEFAULT_API_URL11 = "https://blockrun.ai/api";
|
|
3561
|
+
var DEFAULT_TIMEOUT11 = 6e4;
|
|
3854
3562
|
var SURF_PREFIX = "/v1/surf";
|
|
3855
3563
|
var SurfClient = class {
|
|
3856
3564
|
account;
|
|
@@ -3867,11 +3575,11 @@ var SurfClient = class {
|
|
|
3867
3575
|
}
|
|
3868
3576
|
validatePrivateKey(privateKey);
|
|
3869
3577
|
this.privateKey = privateKey;
|
|
3870
|
-
this.account =
|
|
3871
|
-
const apiUrl = options.apiUrl ||
|
|
3578
|
+
this.account = privateKeyToAccount11(privateKey);
|
|
3579
|
+
const apiUrl = options.apiUrl || DEFAULT_API_URL11;
|
|
3872
3580
|
validateApiUrl(apiUrl);
|
|
3873
3581
|
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
3874
|
-
this.timeout = options.timeout ||
|
|
3582
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT11;
|
|
3875
3583
|
}
|
|
3876
3584
|
/**
|
|
3877
3585
|
* GET a Surf endpoint. `path` is everything after `/v1/surf` (a leading
|
|
@@ -4003,9 +3711,9 @@ var SurfClient = class {
|
|
|
4003
3711
|
};
|
|
4004
3712
|
|
|
4005
3713
|
// src/rpc.ts
|
|
4006
|
-
import { privateKeyToAccount as
|
|
4007
|
-
var
|
|
4008
|
-
var
|
|
3714
|
+
import { privateKeyToAccount as privateKeyToAccount12 } from "viem/accounts";
|
|
3715
|
+
var DEFAULT_API_URL12 = "https://blockrun.ai/api";
|
|
3716
|
+
var DEFAULT_TIMEOUT12 = 6e4;
|
|
4009
3717
|
var RPC_PRICE_USD = 2e-3;
|
|
4010
3718
|
var SUPPORTED_NETWORKS = [
|
|
4011
3719
|
// EVM
|
|
@@ -4097,11 +3805,11 @@ var RpcClient = class {
|
|
|
4097
3805
|
}
|
|
4098
3806
|
validatePrivateKey(privateKey);
|
|
4099
3807
|
this.privateKey = privateKey;
|
|
4100
|
-
this.account =
|
|
4101
|
-
const apiUrl = options.apiUrl ||
|
|
3808
|
+
this.account = privateKeyToAccount12(privateKey);
|
|
3809
|
+
const apiUrl = options.apiUrl || DEFAULT_API_URL12;
|
|
4102
3810
|
validateApiUrl(apiUrl);
|
|
4103
3811
|
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
4104
|
-
this.timeout = options.timeout ||
|
|
3812
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT12;
|
|
4105
3813
|
}
|
|
4106
3814
|
/**
|
|
4107
3815
|
* Make a single JSON-RPC 2.0 call. Flat $0.002.
|
|
@@ -4256,9 +3964,9 @@ var RpcClient = class {
|
|
|
4256
3964
|
};
|
|
4257
3965
|
|
|
4258
3966
|
// src/blockrun.ts
|
|
4259
|
-
import { privateKeyToAccount as
|
|
4260
|
-
var
|
|
4261
|
-
var
|
|
3967
|
+
import { privateKeyToAccount as privateKeyToAccount13 } from "viem/accounts";
|
|
3968
|
+
var DEFAULT_API_URL13 = "https://blockrun.ai/api";
|
|
3969
|
+
var DEFAULT_TIMEOUT13 = 6e4;
|
|
4262
3970
|
var DEFAULT_POLL_INTERVAL_MS = 5e3;
|
|
4263
3971
|
var DEFAULT_POLL_BUDGET_MS = 3e5;
|
|
4264
3972
|
var MAX_SIGNED_AUTH_SECONDS = 600;
|
|
@@ -4279,11 +3987,11 @@ var BlockrunClient = class {
|
|
|
4279
3987
|
}
|
|
4280
3988
|
validatePrivateKey(privateKey);
|
|
4281
3989
|
this.privateKey = privateKey;
|
|
4282
|
-
this.account =
|
|
4283
|
-
const apiUrl = options.apiUrl ||
|
|
3990
|
+
this.account = privateKeyToAccount13(privateKey);
|
|
3991
|
+
const apiUrl = options.apiUrl || DEFAULT_API_URL13;
|
|
4284
3992
|
validateApiUrl(apiUrl);
|
|
4285
3993
|
this.apiUrl = apiUrl.replace(/\/$/, "");
|
|
4286
|
-
this.timeout = options.timeout ||
|
|
3994
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT13;
|
|
4287
3995
|
}
|
|
4288
3996
|
/**
|
|
4289
3997
|
* GET a BlockRun endpoint. `path` is everything after `/api` (a leading
|
|
@@ -4634,7 +4342,7 @@ function sleep(ms) {
|
|
|
4634
4342
|
}
|
|
4635
4343
|
|
|
4636
4344
|
// src/wallet.ts
|
|
4637
|
-
import { privateKeyToAccount as
|
|
4345
|
+
import { privateKeyToAccount as privateKeyToAccount14, generatePrivateKey } from "viem/accounts";
|
|
4638
4346
|
import * as fs2 from "fs";
|
|
4639
4347
|
import * as path2 from "path";
|
|
4640
4348
|
import * as os2 from "os";
|
|
@@ -4644,7 +4352,7 @@ var WALLET_DIR = path2.join(os2.homedir(), ".blockrun");
|
|
|
4644
4352
|
var WALLET_FILE = path2.join(WALLET_DIR, ".session");
|
|
4645
4353
|
function createWallet() {
|
|
4646
4354
|
const privateKey = generatePrivateKey();
|
|
4647
|
-
const account =
|
|
4355
|
+
const account = privateKeyToAccount14(privateKey);
|
|
4648
4356
|
return {
|
|
4649
4357
|
address: account.address,
|
|
4650
4358
|
privateKey
|
|
@@ -4700,12 +4408,12 @@ function loadWallet() {
|
|
|
4700
4408
|
function getOrCreateWallet() {
|
|
4701
4409
|
const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
|
|
4702
4410
|
if (envKey) {
|
|
4703
|
-
const account =
|
|
4411
|
+
const account = privateKeyToAccount14(envKey);
|
|
4704
4412
|
return { address: account.address, privateKey: envKey, isNew: false };
|
|
4705
4413
|
}
|
|
4706
4414
|
const fileKey = loadWallet();
|
|
4707
4415
|
if (fileKey) {
|
|
4708
|
-
const account =
|
|
4416
|
+
const account = privateKeyToAccount14(fileKey);
|
|
4709
4417
|
return { address: account.address, privateKey: fileKey, isNew: false };
|
|
4710
4418
|
}
|
|
4711
4419
|
const { address, privateKey } = createWallet();
|
|
@@ -4715,11 +4423,11 @@ function getOrCreateWallet() {
|
|
|
4715
4423
|
function getWalletAddress() {
|
|
4716
4424
|
const envKey = typeof process !== "undefined" && process.env ? process.env.BLOCKRUN_WALLET_KEY || process.env.BASE_CHAIN_WALLET_KEY : void 0;
|
|
4717
4425
|
if (envKey) {
|
|
4718
|
-
return
|
|
4426
|
+
return privateKeyToAccount14(envKey).address;
|
|
4719
4427
|
}
|
|
4720
4428
|
const fileKey = loadWallet();
|
|
4721
4429
|
if (fileKey) {
|
|
4722
|
-
return
|
|
4430
|
+
return privateKeyToAccount14(fileKey).address;
|
|
4723
4431
|
}
|
|
4724
4432
|
return null;
|
|
4725
4433
|
}
|
|
@@ -4899,7 +4607,7 @@ async function getOrCreateSolanaWallet() {
|
|
|
4899
4607
|
// src/solana-client.ts
|
|
4900
4608
|
var SOLANA_API_URL = "https://sol.blockrun.ai/api";
|
|
4901
4609
|
var DEFAULT_MAX_TOKENS2 = 1024;
|
|
4902
|
-
var
|
|
4610
|
+
var DEFAULT_TIMEOUT14 = 6e4;
|
|
4903
4611
|
var SDK_VERSION2 = "0.3.0";
|
|
4904
4612
|
var USER_AGENT2 = `blockrun-ts/${SDK_VERSION2}`;
|
|
4905
4613
|
var DEFAULT_SOLANA_RPC_URL = "https://sol.blockrun.ai/api/v1/solana/rpc";
|
|
@@ -4949,7 +4657,7 @@ var SolanaLLMClient = class {
|
|
|
4949
4657
|
const rpc = resolveRpcConfig(options.rpcUrl, options.rpcHeaders);
|
|
4950
4658
|
this.rpcUrl = rpc.url;
|
|
4951
4659
|
this.rpcHeaders = rpc.headers;
|
|
4952
|
-
this.timeout = options.timeout ||
|
|
4660
|
+
this.timeout = options.timeout || DEFAULT_TIMEOUT14;
|
|
4953
4661
|
}
|
|
4954
4662
|
/** Get Solana wallet address (public key in base58). */
|
|
4955
4663
|
async getWalletAddress() {
|
|
@@ -5049,89 +4757,6 @@ var SolanaLLMClient = class {
|
|
|
5049
4757
|
const data = await this.requestWithPaymentRaw("/v1/search", body);
|
|
5050
4758
|
return data;
|
|
5051
4759
|
}
|
|
5052
|
-
// ============================================================
|
|
5053
|
-
// X/Twitter endpoints (powered by AttentionVC)
|
|
5054
|
-
// ============================================================
|
|
5055
|
-
async xUserLookup(usernames) {
|
|
5056
|
-
const names = Array.isArray(usernames) ? usernames : [usernames];
|
|
5057
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/lookup", { usernames: names });
|
|
5058
|
-
return data;
|
|
5059
|
-
}
|
|
5060
|
-
async xFollowers(username, cursor) {
|
|
5061
|
-
const body = { username };
|
|
5062
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5063
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/followers", body);
|
|
5064
|
-
return data;
|
|
5065
|
-
}
|
|
5066
|
-
async xFollowings(username, cursor) {
|
|
5067
|
-
const body = { username };
|
|
5068
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5069
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/followings", body);
|
|
5070
|
-
return data;
|
|
5071
|
-
}
|
|
5072
|
-
async xUserInfo(username) {
|
|
5073
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/info", { username });
|
|
5074
|
-
return data;
|
|
5075
|
-
}
|
|
5076
|
-
async xVerifiedFollowers(userId, cursor) {
|
|
5077
|
-
const body = { userId };
|
|
5078
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5079
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/verified-followers", body);
|
|
5080
|
-
return data;
|
|
5081
|
-
}
|
|
5082
|
-
async xUserTweets(username, includeReplies = false, cursor) {
|
|
5083
|
-
const body = { username, includeReplies };
|
|
5084
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5085
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/tweets", body);
|
|
5086
|
-
return data;
|
|
5087
|
-
}
|
|
5088
|
-
async xUserMentions(username, sinceTime, untilTime, cursor) {
|
|
5089
|
-
const body = { username };
|
|
5090
|
-
if (sinceTime !== void 0) body.sinceTime = sinceTime;
|
|
5091
|
-
if (untilTime !== void 0) body.untilTime = untilTime;
|
|
5092
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5093
|
-
const data = await this.requestWithPaymentRaw("/v1/x/users/mentions", body);
|
|
5094
|
-
return data;
|
|
5095
|
-
}
|
|
5096
|
-
async xTweetLookup(tweetIds) {
|
|
5097
|
-
const ids = Array.isArray(tweetIds) ? tweetIds : [tweetIds];
|
|
5098
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/lookup", { tweet_ids: ids });
|
|
5099
|
-
return data;
|
|
5100
|
-
}
|
|
5101
|
-
async xTweetReplies(tweetId, queryType = "Latest", cursor) {
|
|
5102
|
-
const body = { tweetId, queryType };
|
|
5103
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5104
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/replies", body);
|
|
5105
|
-
return data;
|
|
5106
|
-
}
|
|
5107
|
-
async xTweetThread(tweetId, cursor) {
|
|
5108
|
-
const body = { tweetId };
|
|
5109
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5110
|
-
const data = await this.requestWithPaymentRaw("/v1/x/tweets/thread", body);
|
|
5111
|
-
return data;
|
|
5112
|
-
}
|
|
5113
|
-
async xSearch(query, queryType = "Latest", cursor) {
|
|
5114
|
-
const body = { query, queryType };
|
|
5115
|
-
if (cursor !== void 0) body.cursor = cursor;
|
|
5116
|
-
const data = await this.requestWithPaymentRaw("/v1/x/search", body);
|
|
5117
|
-
return data;
|
|
5118
|
-
}
|
|
5119
|
-
async xTrending() {
|
|
5120
|
-
const data = await this.requestWithPaymentRaw("/v1/x/trending", {});
|
|
5121
|
-
return data;
|
|
5122
|
-
}
|
|
5123
|
-
async xArticlesRising() {
|
|
5124
|
-
const data = await this.requestWithPaymentRaw("/v1/x/articles/rising", {});
|
|
5125
|
-
return data;
|
|
5126
|
-
}
|
|
5127
|
-
async xAuthorAnalytics(handle) {
|
|
5128
|
-
const data = await this.requestWithPaymentRaw("/v1/x/authors", { handle });
|
|
5129
|
-
return data;
|
|
5130
|
-
}
|
|
5131
|
-
async xCompareAuthors(handle1, handle2) {
|
|
5132
|
-
const data = await this.requestWithPaymentRaw("/v1/x/compare", { handle1, handle2 });
|
|
5133
|
-
return data;
|
|
5134
|
-
}
|
|
5135
4760
|
// ── Prediction Markets (Powered by Predexon) ────────────────────────────
|
|
5136
4761
|
async pm(path5, params) {
|
|
5137
4762
|
return this.getWithPaymentRaw(`/v1/pm/${path5}`, params);
|
|
@@ -5188,6 +4813,120 @@ var SolanaLLMClient = class {
|
|
|
5188
4813
|
async exaAnswer(query, options) {
|
|
5189
4814
|
return this.requestWithPaymentRaw("/v1/exa/answer", { query, ...options });
|
|
5190
4815
|
}
|
|
4816
|
+
// ============================================================
|
|
4817
|
+
// DefiLlama (DeFi protocols / TVL / yields / prices)
|
|
4818
|
+
// ============================================================
|
|
4819
|
+
/**
|
|
4820
|
+
* Query DefiLlama DeFi data (GET passthrough). Powered by DefiLlama.
|
|
4821
|
+
* $0.005/call for protocols / protocol/{slug} / chains / yields;
|
|
4822
|
+
* $0.001/call for prices/{coins}.
|
|
4823
|
+
*
|
|
4824
|
+
* @param path - e.g. "protocols", "protocol/aave", "chains", "yields",
|
|
4825
|
+
* "prices/coingecko:bitcoin,base:0x..."
|
|
4826
|
+
* @param params - Query parameters passed through to DefiLlama
|
|
4827
|
+
*/
|
|
4828
|
+
async defi(path5, params) {
|
|
4829
|
+
return this.getWithPaymentRaw(`/v1/defillama/${path5}`, params);
|
|
4830
|
+
}
|
|
4831
|
+
/** All DeFi protocols with TVL ($0.005/call). */
|
|
4832
|
+
async defiProtocols() {
|
|
4833
|
+
return this.defi("protocols");
|
|
4834
|
+
}
|
|
4835
|
+
/** Single protocol details + historical TVL ($0.005/call). */
|
|
4836
|
+
async defiProtocol(slug) {
|
|
4837
|
+
return this.defi(`protocol/${slug}`);
|
|
4838
|
+
}
|
|
4839
|
+
/** Current TVL of every chain ($0.005/call). */
|
|
4840
|
+
async defiChains() {
|
|
4841
|
+
return this.defi("chains");
|
|
4842
|
+
}
|
|
4843
|
+
/** Yield pools with APY/TVL ($0.005/call). */
|
|
4844
|
+
async defiYields(params) {
|
|
4845
|
+
return this.defi("yields", params);
|
|
4846
|
+
}
|
|
4847
|
+
/** Token price lookup ($0.001/call). Coins like "coingecko:bitcoin" or "{chain}:{address}". */
|
|
4848
|
+
async defiPrices(coins) {
|
|
4849
|
+
const joined = Array.isArray(coins) ? coins.join(",") : coins;
|
|
4850
|
+
return this.defi(`prices/${joined}`);
|
|
4851
|
+
}
|
|
4852
|
+
// ============================================================
|
|
4853
|
+
// 0x DEX (swap quotes + gasless) — free passthrough
|
|
4854
|
+
// ============================================================
|
|
4855
|
+
/**
|
|
4856
|
+
* Query the 0x Swap / Gasless APIs (free — no x402 payment; BlockRun
|
|
4857
|
+
* takes an on-chain affiliate fee on executed swaps instead).
|
|
4858
|
+
*
|
|
4859
|
+
* @param path - "price", "quote", "gasless/price", "gasless/quote",
|
|
4860
|
+
* "gasless/submit" (POST), "gasless/status/{hash}",
|
|
4861
|
+
* "gasless/approval-tokens", "gasless/chains", "swap/chains"
|
|
4862
|
+
* @param params - Query params (chainId, sellToken, buyToken, sellAmount, taker, ...)
|
|
4863
|
+
* @param body - JSON body — pass to switch to POST (gasless/submit only)
|
|
4864
|
+
*/
|
|
4865
|
+
async dex(path5, params, body) {
|
|
4866
|
+
if (body) return this.requestWithPaymentRaw(`/v1/zerox/${path5}`, body);
|
|
4867
|
+
return this.getWithPaymentRaw(`/v1/zerox/${path5}`, params);
|
|
4868
|
+
}
|
|
4869
|
+
/** Indicative Permit2 swap price — no commitment (free). */
|
|
4870
|
+
async dexPrice(params) {
|
|
4871
|
+
return this.dex("price", params);
|
|
4872
|
+
}
|
|
4873
|
+
/** Firm Permit2 swap quote with permit2.eip712 + tx data (free). */
|
|
4874
|
+
async dexQuote(params) {
|
|
4875
|
+
return this.dex("quote", params);
|
|
4876
|
+
}
|
|
4877
|
+
/** Gasless indicative price quote (free). */
|
|
4878
|
+
async dexGaslessPrice(params) {
|
|
4879
|
+
return this.dex("gasless/price", params);
|
|
4880
|
+
}
|
|
4881
|
+
/** Gasless firm quote — returns trade.eip712 to sign (free). */
|
|
4882
|
+
async dexGaslessQuote(params) {
|
|
4883
|
+
return this.dex("gasless/quote", params);
|
|
4884
|
+
}
|
|
4885
|
+
/** Submit a signed gasless trade; the 0x relayer pays gas (free). */
|
|
4886
|
+
async dexGaslessSubmit(body) {
|
|
4887
|
+
return this.dex("gasless/submit", void 0, body);
|
|
4888
|
+
}
|
|
4889
|
+
/** Poll a gasless trade's status by tradeHash (free). */
|
|
4890
|
+
async dexGaslessStatus(tradeHash) {
|
|
4891
|
+
return this.dex(`gasless/status/${tradeHash}`);
|
|
4892
|
+
}
|
|
4893
|
+
/** Chains where the Swap API is supported (free). */
|
|
4894
|
+
async dexChains() {
|
|
4895
|
+
return this.dex("swap/chains");
|
|
4896
|
+
}
|
|
4897
|
+
/** Chains where the Gasless API is supported (free). */
|
|
4898
|
+
async dexGaslessChains() {
|
|
4899
|
+
return this.dex("gasless/chains");
|
|
4900
|
+
}
|
|
4901
|
+
// ============================================================
|
|
4902
|
+
// Modal Sandbox (pay-per-call cloud compute)
|
|
4903
|
+
// ============================================================
|
|
4904
|
+
/**
|
|
4905
|
+
* Call the Modal sandbox compute API (POST passthrough).
|
|
4906
|
+
*
|
|
4907
|
+
* @param path - "sandbox/create" ($0.01 CPU / $0.05 GPU), "sandbox/exec",
|
|
4908
|
+
* "sandbox/status", "sandbox/terminate" ($0.001 each)
|
|
4909
|
+
* @param body - JSON body for the endpoint
|
|
4910
|
+
*/
|
|
4911
|
+
async modal(path5, body) {
|
|
4912
|
+
return this.requestWithPaymentRaw(`/v1/modal/${path5}`, body ?? {});
|
|
4913
|
+
}
|
|
4914
|
+
/** Create a sandboxed compute environment ($0.01 CPU / $0.05 GPU). */
|
|
4915
|
+
async modalSandboxCreate(body) {
|
|
4916
|
+
return this.modal("sandbox/create", body);
|
|
4917
|
+
}
|
|
4918
|
+
/** Execute a command in a sandbox; returns stdout/stderr ($0.001). */
|
|
4919
|
+
async modalSandboxExec(sandboxId, command, extra) {
|
|
4920
|
+
return this.modal("sandbox/exec", { sandbox_id: sandboxId, command, ...extra });
|
|
4921
|
+
}
|
|
4922
|
+
/** Check a sandbox's status ($0.001). */
|
|
4923
|
+
async modalSandboxStatus(sandboxId) {
|
|
4924
|
+
return this.modal("sandbox/status", { sandbox_id: sandboxId });
|
|
4925
|
+
}
|
|
4926
|
+
/** Terminate a sandbox ($0.001). */
|
|
4927
|
+
async modalSandboxTerminate(sandboxId) {
|
|
4928
|
+
return this.modal("sandbox/terminate", { sandbox_id: sandboxId });
|
|
4929
|
+
}
|
|
5191
4930
|
/** Get session spending. */
|
|
5192
4931
|
getSpending() {
|
|
5193
4932
|
return { totalUsd: this.sessionTotalUsd, calls: this.sessionCalls };
|
|
@@ -5495,7 +5234,6 @@ var CACHE_DIR = path4.join(os4.homedir(), ".blockrun", "cache");
|
|
|
5495
5234
|
var DATA_DIR = path4.join(os4.homedir(), ".blockrun", "data");
|
|
5496
5235
|
var COST_LOG_FILE2 = path4.join(os4.homedir(), ".blockrun", "cost_log.jsonl");
|
|
5497
5236
|
var DEFAULT_TTL = {
|
|
5498
|
-
"/v1/x/": 3600 * 1e3,
|
|
5499
5237
|
"/v1/partner/": 3600 * 1e3,
|
|
5500
5238
|
"/v1/pm/": 1800 * 1e3,
|
|
5501
5239
|
"/v1/chat/": 0,
|
|
@@ -5564,8 +5302,6 @@ function readableFilename(endpoint, body) {
|
|
|
5564
5302
|
let ep = endpoint.replace(/\/+$/, "").split("/").pop() || "";
|
|
5565
5303
|
if (endpoint.includes("/v1/chat/")) {
|
|
5566
5304
|
ep = "chat";
|
|
5567
|
-
} else if (endpoint.includes("/v1/x/")) {
|
|
5568
|
-
ep = "x_" + ep;
|
|
5569
5305
|
} else if (endpoint.includes("/v1/search")) {
|
|
5570
5306
|
ep = "search";
|
|
5571
5307
|
} else if (endpoint.includes("/v1/image")) {
|
|
@@ -5863,7 +5599,7 @@ var OpenAI = class {
|
|
|
5863
5599
|
};
|
|
5864
5600
|
|
|
5865
5601
|
// src/anthropic-compat.ts
|
|
5866
|
-
import { privateKeyToAccount as
|
|
5602
|
+
import { privateKeyToAccount as privateKeyToAccount15 } from "viem/accounts";
|
|
5867
5603
|
var AnthropicClient = class {
|
|
5868
5604
|
_client = null;
|
|
5869
5605
|
_clientPromise = null;
|
|
@@ -5876,7 +5612,7 @@ var AnthropicClient = class {
|
|
|
5876
5612
|
const key = options.privateKey ?? wallet.privateKey;
|
|
5877
5613
|
validatePrivateKey(key);
|
|
5878
5614
|
this._privateKey = key;
|
|
5879
|
-
this._account =
|
|
5615
|
+
this._account = privateKeyToAccount15(this._privateKey);
|
|
5880
5616
|
const apiUrl = options.apiUrl ?? "https://blockrun.ai/api";
|
|
5881
5617
|
validateApiUrl(apiUrl);
|
|
5882
5618
|
this._apiUrl = apiUrl.replace(/\/$/, "");
|
|
@@ -6004,7 +5740,6 @@ export {
|
|
|
6004
5740
|
VoiceClient,
|
|
6005
5741
|
WALLET_DIR_PATH,
|
|
6006
5742
|
WALLET_FILE_PATH,
|
|
6007
|
-
XClient,
|
|
6008
5743
|
clearCache,
|
|
6009
5744
|
createPaymentPayload,
|
|
6010
5745
|
createSolanaPaymentPayload,
|