Skip to content

Commit ee79204

Browse files
committed
v0.12.140: fix doctor to respect Solana payment chain
Doctor was hardcoding EVM signer + blockrun.ai endpoint regardless of the user's configured payment chain. On Solana users, it showed a misleading "Payment verification failed" error with an EVM payer that didn't match their actual Solana wallet. - Register Solana scheme when paymentChain=solana - Route to sol.blockrun.ai when on Solana chain
1 parent de8683e commit ee79204

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@blockrun/clawrouter",
3-
"version": "0.12.139",
3+
"version": "0.12.140",
44
"description": "Smart LLM router — save 85% on inference costs. 55+ models (11 free), one wallet, x402 micropayments.",
55
"type": "module",
66
"main": "dist/index.js",

src/doctor.ts

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,13 @@ import { privateKeyToAccount } from "viem/accounts";
1212
import { wrapFetchWithPayment, x402Client } from "@x402/fetch";
1313
import { registerExactEvmScheme } from "@x402/evm/exact/client";
1414
import { toClientEvmSigner } from "@x402/evm";
15-
import { resolveOrGenerateWalletKey, resolvePaymentChain, WALLET_FILE } from "./auth.js";
15+
import { existsSync, readFileSync } from "node:fs";
16+
import {
17+
resolveOrGenerateWalletKey,
18+
resolvePaymentChain,
19+
WALLET_FILE,
20+
MNEMONIC_FILE,
21+
} from "./auth.js";
1622
import { BalanceMonitor } from "./balance.js";
1723
import { getSolanaAddress } from "./wallet.js";
1824
import { getStats } from "./stats.js";
@@ -402,9 +408,37 @@ async function analyzeWithAI(
402408
const evmSigner = toClientEvmSigner(account, publicClient);
403409
const x402 = new x402Client();
404410
registerExactEvmScheme(x402, { signer: evmSigner });
411+
412+
// Register Solana scheme if user is on Solana chain
413+
const paymentChain = diagnostics.wallet.paymentChain;
414+
if (paymentChain === "solana") {
415+
try {
416+
if (!existsSync(MNEMONIC_FILE)) {
417+
throw new Error(`mnemonic file missing at ${MNEMONIC_FILE}`);
418+
}
419+
const mnemonic = readFileSync(MNEMONIC_FILE, "utf8").trim();
420+
if (!mnemonic) throw new Error("mnemonic file empty");
421+
const { deriveSolanaKeyBytes } = await import("./wallet.js");
422+
const { registerExactSvmScheme } = await import("@x402/svm/exact/client");
423+
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
424+
const solanaKeyBytes = deriveSolanaKeyBytes(mnemonic);
425+
const solanaSigner = await createKeyPairSignerFromPrivateKeyBytes(solanaKeyBytes);
426+
registerExactSvmScheme(x402, { signer: solanaSigner });
427+
} catch (err) {
428+
console.log(
429+
` ⚠ Could not register Solana signer: ${err instanceof Error ? err.message : String(err)}`,
430+
);
431+
console.log(` ⚠ Falling back to Base (EVM) — doctor request may fail on Solana chain\n`);
432+
}
433+
}
434+
405435
const paymentFetch = wrapFetchWithPayment(fetch, x402);
436+
const apiUrl =
437+
paymentChain === "solana"
438+
? "https://sol.blockrun.ai/api/v1/chat/completions"
439+
: "https://blockrun.ai/api/v1/chat/completions";
406440

407-
const response = await paymentFetch("https://blockrun.ai/api/v1/chat/completions", {
441+
const response = await paymentFetch(apiUrl, {
408442
method: "POST",
409443
headers: { "Content-Type": "application/json" },
410444
body: JSON.stringify({

0 commit comments

Comments
 (0)