feat(extensions): Add Facilitator Fee Disclosures for Fee-Aware Routing - facilitatorFeeQuote, facilitatorFeeBid, facilitatorFeePaid (draft, addresses #) #6
+3,470
−1,251
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.
Description
Adds an opt-in
facilitatorFeesextension to standardize facilitator fee disclosure, enabling fee-aware multi-facilitator routing.This extension introduces three components:
facilitatorFeeQuote: Facilitator-signed fee disclosure surfaced inPaymentRequiredfacilitatorFeeBid: Client fee constraints/preferences surfaced inPaymentPayloadfacilitatorFeePaid: Actual fee charged surfaced inSettlementResponseMotivation
Facilitators are beginning to charge explicit fees:
Without standardization, clients cannot compare total cost across facilitators, and multi-facilitator routing cannot become a real market.
Changes
Spec:
specs/extensions/facilitator_fees.md— Full extension specificationTypeScript (
@x402/extensions):src/facilitator-fees/types.ts— Type definitionssrc/facilitator-fees/schema.ts— Zod validation schemassrc/facilitator-fees/index.ts— Helper functions and exportstest/facilitator-fees.test.ts— Unit testspackage.json,tsup.config.ts,src/index.tsfor exportsCore Types (
@x402/core):extensions?: Record<string, unknown>toSettleResponseDesign Decisions
extensions, notextra: Facilitator fees are orthogonal to payment schemes and belong in the top-levelextensionsfield (likebazaar)selectedQuoteIdenables client agency while keeping simple cases simpleeip191for EVM,ed25519for SolanaTests
Build:
✅ Build successful
Lint:
cd typescript && pnpm --filter @x402/extensions lint:check✅ No errors
Code validation (all schemas and helpers verified):
Note: Unit tests are written in test/facilitator-fees.test.ts. The repo's vitest config has a pre-existing ESM/CJS compatibility issue (vite-tsconfig-paths module loading error) that affects all tests in @x402/extensions. The test file is correctly structured and will pass once resolved.