Repository navigation
feat(x402): stamp BlockRun builder-code service code on payments - #198
Conversation
Tag every x402 payment ClawRouter signs with the ERC-8021 Schema 2 service code s: ["blockrun"] so BlockRun-originated traffic is attributed on-chain. An onAfterPaymentCreation hook stamps builder-code.info.s onto the payload, preserving any app code (a) the server echoed back. This mirrors @x402/extensions' BuilderCodeClientExtension but fires unconditionally (independent of the server advertising the extension) and needs no @x402 upgrade. The EIP-712 signature covers the authorization, not the extensions, so stamping after creation is safe. Encoding into settlement calldata is done by the CDP facilitator. Docs: https://docs.cdp.coinbase.com/x402/core-concepts/builder-codes
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughAdds ChangesBuilder-code service attribution
Estimated code review effort: 2 (Simple) | ~10 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/builder-code.test.ts`:
- Line 7: The test assertions in builder-code.test.ts are using explicit any
casts that violate `@typescript-eslint/no-explicit-any`. Replace the
(ext["builder-code"] as any) access in the affected assertions with a minimal
typed shape or narrow interface that exposes the info.s property used by the
test, so the same checks can be performed without any. Update both builder-code
assertions consistently where the cast appears.
In `@src/builder-code.ts`:
- Around line 1-32: The file formatting is failing Prettier checks, so update
the code style in withBuilderCodeServiceCode and the related
BLOCKRUN_SERVICE_CODE declaration to match the repository’s formatting rules.
Run Prettier on this module and keep the existing behavior unchanged while
adjusting whitespace, wrapping, and spacing to satisfy CI.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 99995bbd-0df2-402e-bd1f-8829ca69b200
📒 Files selected for processing (3)
src/builder-code.test.tssrc/builder-code.tssrc/proxy.ts
…ok test - Gate the builder-code service-code hook to EVM (eip155:*) — ERC-8021 is Ethereum-only, so stamping it onto Solana payloads risked attaching a field the SVM facilitator never expects. - Run Prettier on builder-code.ts (fixes failing Lint & Typecheck CI check). - Replace 'as any' casts in tests with a typed BuilderCodeExtension shape (satisfies @typescript-eslint/no-explicit-any). - Add a hook-contract test guarding the reference-mutation assumption the proxy relies on.
…tion The prior value "blockrun" was a placeholder label, not the registered builder code. The facilitator credits the exact `s` string on-chain, so the real CDP-registered code must be used or no attribution lands.
…200) + picker order fix (#201) - Stamp BlockRun's CDP builder code (bc_5hucoh0l) on every x402 payment (#198, thanks @KillerQueen-Z) - Preserve pre-existing ERC-8021 service codes when stamping (#199/#200, thanks @steipete) - /model picker now follows top-models.json order (#201, thanks @0xCheetah1)
What
Tags every x402 payment ClawRouter signs with the ERC-8021 Schema 2 service code
s: ["blockrun"], so payments routed through ClawRouter are attributed to BlockRun on-chain.Reference: CDP Builder Codes
How
src/builder-code.ts:withBuilderCodeServiceCode()mergess: ["blockrun"]into a payload'sbuilder-code.info, preserving any app code (a) the server echoed back. Pure, non-mutating.proxy.ts, anonAfterPaymentCreationhook stamps it ontocontext.paymentPayload.extensions.Why a hook (and not
registerExtension/ a dep bump)The official
@x402/extensionsBuilderCodeClientExtensiononly enriches when the server advertises thebuilder-codekey in its 402 (seex402Client.enrichPaymentPayloadWithExtensions), and it would require bumping@x402/*from 2.11 → 2.17. The hook mirrors that extension's exact output but fires unconditionally, needs no dependency change, and is trivial to swap for the official extension after a future@x402bump.Safe because the EIP-712 signature covers the
TransferWithAuthorization(from/to/value/validAfter/validBefore/nonce), not theextensions— so stamping after creation doesn't invalidate the signature. The CDP facilitator readsbuilder-code.info.sand does the CBOR/ERC-8021 encoding.Test
src/builder-code.test.ts(4 cases): attachess; preserves echoeda; preserves unrelated extensions; does not mutate input.Related
Part of the builder-code adoption tracked in BlockRunAI/blockrun#199. Sibling PRs: blockrun-llm-ts#9, blockrun-llm#21, blockrun-llm-go#2.
Summary by CodeRabbit
builder-code.info.s) for EVM networks during the payment creation flow.