feat(solana): add Solana x402 payment support + SDK migration#54
Open
tenequm wants to merge 13 commits intoBlockRunAI:mainfrom
Open
feat(solana): add Solana x402 payment support + SDK migration#54tenequm wants to merge 13 commits intoBlockRunAI:mainfrom
tenequm wants to merge 13 commits intoBlockRunAI:mainfrom
Conversation
- Add Solana USDC payment signing via @x402/svm ExactSvmScheme - Replace hand-rolled x402.ts with official @x402/fetch + @x402/evm SDK - Add BIP-39 mnemonic generation + BIP-44 key derivation (EVM + Solana) - Add SolanaBalanceMonitor for USDC balance checking on Solana - Add SpendControl with per-request, hourly, daily, session limits - Add /wallet setup-solana command for existing EVM-only users - Dual-chain display in wallet status (EVM + Solana balances) - Remove payment-cache.ts and pre-auth optimization (SDK handles retries) - Dynamic Solana module loading (only when Solana key is present)
- Remove unused generatePrivateKey import from auth.ts - Replace manual x402.register() with registerExactSvmScheme() helper which registers solana:* wildcard + V1 compat names - Remove unused solanaRpcUrl from ProxyOptions
- Remove stale "Payment cache" comment from proxy.ts header - Update cost buffer comment (was referencing removed pre-auth) - Convert SolanaBalanceMonitor to dynamic import in index.ts so CLI users don't load @solana/kit at startup
- wallet.test.ts (14 tests): BIP-39 generation, BIP-44 derivation for both EVM and Solana, determinism, Solana signer creation - x402-sdk.test.ts (7 tests): client creation, EVM + Solana scheme registration, wrapFetchWithPayment pass-through, streaming, 402 flow - spend-control.test.ts (23 tests): per-request/hourly/daily/session limits, window expiry, persistence, validation, formatDuration
If a user deletes wallet.key but mnemonic file exists (from setup-solana), generateAndSaveWallet() would silently overwrite the mnemonic, destroying the Solana wallet derived from it. Now refuses to generate and tells the user to restore their EVM key instead.
CLI entry point was not destructuring or forwarding Solana key bytes from resolveOrGenerateWalletKey(), so standalone CLI users would never get Solana payments registered even with a valid mnemonic file.
ProxyOptions.wallet now accepts either a plain key string (EVM-only, backward compat for tests) or the full WalletResolution object from resolveOrGenerateWalletKey(). This prevents callers from accidentally forgetting to forward solanaPrivateKeyBytes. - Export WalletResolution type from auth.ts - Add WalletConfig union type to proxy.ts - Update cli.ts, index.ts, test/integration/setup.ts to pass wallet object - Solana now auto-registers in integration tests (previously missing)
…letKey: 22 occurrences across 12 test files updated to match the new ProxyOptions.wallet interface.
… v0.11.0 - Add x402 onAfterPaymentCreation hook to log which chain (Base/Solana) is used for each payment - Update /wallet export to include mnemonic and Solana address when available, with restore instructions for both chains - Add test/test-solana-e2e.ts validating dual-chain proxy startup, wallet derivation, and 402 flow against real blockrun.ai - Update README with Solana badge, dual-chain payment docs, setup-solana command, and CLAWROUTER_SOLANA_RPC_URL config - Bump version to 0.11.0 for Solana support release
blockrun.ai/api only offers EVM payment options. Solana payments require sol.blockrun.ai/api. Default to Solana endpoint when Solana keys are present.
Tests all wallet scenarios on real disk with temp HOME: - Fresh install: generates mnemonic + both keys, verifies 0o600 permissions - Existing wallet.key only: EVM-only path, no Solana - wallet.key + setup-solana: creates mnemonic, leaves EVM untouched - Edge cases: protective error on missing wallet.key, duplicate setup-solana
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Add Solana x402 payment support alongside existing EVM (Base) payments, and migrate from hand-rolled x402 implementation to official
@x402/fetch,@x402/evm, and@x402/svmSDKs.Key changes:
registerExactEvmScheme+registerExactSvmSchemeCLAWROUTER_SOLANA_RPC_URL)x402.onAfterPaymentCreation()hook/wallet exportnow includes mnemonic + Solana address for full backup/wallet setup-solanacommand for existing EVM-only userswallet.keyis deletedProxyOptionsrefactored to acceptwallet: WalletConfigobject (prevents callers from forgetting to forward Solana keys)Files added:
src/wallet.ts- BIP-39 mnemonic + BIP-44 key derivationsrc/solana-balance.ts- Solana USDC balance checkersrc/spend-control.ts- Time-windowed spending limitssrc/wallet.test.ts(14 tests),src/x402-sdk.test.ts(7 tests),src/spend-control.test.ts(23 tests)test/test-solana-e2e.ts- E2E test against real blockrun.ai with dual-chain proxyFiles removed (replaced by SDK):
src/x402.ts,src/payment-cache.ts,src/x402.test.tsThree wallet scenarios supported:
wallet.keyexists, no mnemonic - EVM-only modewallet.key+mnemonicexist - dual-chain modeTest plan
npx tsc --noEmit)npm run build)npm test)npx tsx test/test-solana-e2e.ts)[ClawRouter] Payment signed on Base (EVM) (eip155:8453)