Skip to content

feat(x402): stamp BlockRun builder-code service code on payments - #198

Merged
VickyXAI merged 3 commits into
BlockRunAI:mainfrom
KillerQueen-Z:feat/builder-code-service-code
Jul 5, 2026
Merged

VickyXAI merged 3 commits into
BlockRunAI:mainfrom
KillerQueen-Z:feat/builder-code-service-code

Conversation

@KillerQueen-Z

@KillerQueen-Z KillerQueen-Z commented Jul 5, 2026 •

Copy link
Copy Markdown
Collaborator

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

  • New src/builder-code.ts: withBuilderCodeServiceCode() merges s: ["blockrun"] into a payload's builder-code.info, preserving any app code (a) the server echoed back. Pure, non-mutating.
  • In proxy.ts, an onAfterPaymentCreation hook stamps it onto context.paymentPayload.extensions.

Why a hook (and not registerExtension / a dep bump)

The official @x402/extensions BuilderCodeClientExtension only enriches when the server advertises the builder-code key in its 402 (see x402Client.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 @x402 bump.

Safe because the EIP-712 signature covers the TransferWithAuthorization (from/to/value/validAfter/validBefore/nonce), not the extensions — so stamping after creation doesn't invalidate the signature. The CDP facilitator reads builder-code.info.s and does the CBOR/ERC-8021 encoding.

Test

  • src/builder-code.test.ts (4 cases): attaches s; preserves echoed a; preserves unrelated extensions; does not mutate input.
  • Full suite green: 649 passed, typecheck + build (ESM + DTS) clean.

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

  • New Features
    • Automatically stamps BlockRun service code into payment metadata (builder-code.info.s) for EVM networks during the payment creation flow.
    • Preserves any existing builder-code details and keeps unrelated payment extension data intact.
  • Tests
    • Added coverage to verify service code insertion, preservation of existing builder-code data, and non-mutation of inputs.
    • Added assertions for the on-after-payment-creation hook when payment extensions are mutated by reference.

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
@coderabbitai

coderabbitai Bot commented Jul 5, 2026 •

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f9fb061d-7ea9-4f55-b57c-4dbf53add758

📥 Commits

Reviewing files that changed from the base of the PR and between b0436c3 and 16dafda.

📒 Files selected for processing (1)
  • src/builder-code.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/builder-code.ts

📝 Walkthrough

Walkthrough

Adds BLOCKRUN_SERVICE_CODE and withBuilderCodeServiceCode to stamp builder-code attribution into payment extensions without mutating input. The proxy now applies this helper during x402.onAfterPaymentCreation, and tests cover helper behavior plus hook-side stamping.

Changes

Builder-code service attribution

Layer / File(s) Summary
Builder-code constant and helper function
src/builder-code.ts, src/builder-code.test.ts
Adds BLOCKRUN_SERVICE_CODE and withBuilderCodeServiceCode, which preserves existing extension data while setting builder-code.info.s; tests cover undefined input, passthrough, preservation, and non-mutation, plus proxy-hook contract behavior.
Proxy hook integration
src/proxy.ts
Imports the helper and adds an x402.onAfterPaymentCreation callback for EVM networks that stamps context.paymentPayload.extensions before the existing payment creation handling continues.

Estimated code review effort: 2 (Simple) | ~10 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: stamping BlockRun builder-code service code on x402 payments.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 9706b01 and 5a9837f.

📒 Files selected for processing (3)
  • src/builder-code.test.ts
  • src/builder-code.ts
  • src/proxy.ts

Comment thread src/builder-code.test.ts Resolved
Comment thread src/builder-code.ts Resolved
1bcMax added 2 commits July 5, 2026 15:19
…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.
@VickyXAI
VickyXAI merged commit 9ae23c3 into BlockRunAI:main Jul 5, 2026
4 checks passed
VickyXAI pushed a commit that referenced this pull request Jul 10, 2026
…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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants