Skip to content

feat: Add new channel fund for x402 payments#103

Merged
NicoMolinaOZ merged 8 commits intomainfrom
add-new-channel-fund-x402
Mar 6, 2026
Merged

feat: Add new channel fund for x402 payments#103
NicoMolinaOZ merged 8 commits intomainfrom
add-new-channel-fund-x402

Conversation

@NicoMolinaOZ
Copy link
Contributor

@NicoMolinaOZ NicoMolinaOZ commented Mar 5, 2026

  • Add new channel fund for x402 payments

Summary by CodeRabbit

  • New Features

    • Added x402 Fund Relayer support with optional configuration for fee bumping control
    • Added sequenceOverride parameter to support concurrent transaction execution in tests
  • Documentation

    • Updated README with x402 Fund Relayer configuration and usage examples
  • Tests

    • Added comprehensive test coverage for x402 fund relayer selection and validation logic

@NicoMolinaOZ NicoMolinaOZ requested a review from zeljkoX March 5, 2026 19:07
@coderabbitai
Copy link

coderabbitai bot commented Mar 5, 2026

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f560e713-0be9-4767-91c2-d53bd0697856

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

This PR introduces an optional x402 Fund Relayer feature enabling specialized fee bumping through a separate relayer. Changes include documentation updates, environment variable configuration (X402_FUND_RELAYER_ID), request type extensions, validation logic, conditional fund relayer selection in the handler, concurrency improvements for tests, and comprehensive test coverage.

Changes

Cohort / File(s) Summary
Documentation
README.md
Adds x402 Fund Relayer section with configuration, usage examples, and notes; duplicates x402 references across Overview, API Usage, and Client sections.
Configuration & Type Definitions
src/plugin/config.ts, src/plugin/types.ts
Adds x402FundRelayerId configuration field and environment variable parsing; extends ChannelAccountsRequest variants to include optional x402 boolean field for xdr and func-auth request types.
Client Types
src/client/types.ts
Adds optional x402 boolean field to ChannelsXdrRequest and ChannelsFuncAuthRequest for client-side feature flagging.
Handler Logic
src/plugin/handler.ts
Implements conditional fund relayer selection: routes to x402-specific relayer when request.x402 is true and x402FundRelayerId is configured, otherwise uses default relayer; includes guard against missing x402 configuration.
Validation
src/plugin/validation.ts
Extends parameter validation to accept x402 as boolean in xdr and func-auth request paths; returns x402 field (defaulting to false) in ChannelAccountsRequest output; rejects non-boolean x402 values.
Test Coverage
test/handler.x402.test.ts, test/validation.test.ts
Adds comprehensive test suite covering x402 fund relayer selection scenarios (default vs. x402 relayer, missing configuration error, get-transaction bypass) and validation tests for x402 boolean parsing and defaults.
Concurrency Testing
scripts/smoke.ts
Introduces sequenceOverride parameter to buildSignedSelfPayment and threads it through test execution context; prefetches and computes unique per-run sequence values for xdr-payment tests to ensure non-duplicate transaction hashes under concurrent execution.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant Handler
    participant Config
    participant FundRelayer
    participant DefaultRelayer

    Client->>Handler: ChannelAccountsRequest (x402: true/false)
    Handler->>Config: Load x402FundRelayerId configuration
    Config-->>Handler: x402FundRelayerId or undefined

    alt x402 = true and x402FundRelayerId configured
        Handler->>FundRelayer: Select x402 Fund Relayer
        FundRelayer-->>Handler: x402 relayer instance
        Handler->>FundRelayer: Process transaction (fee bumping)
        FundRelayer-->>Handler: Result
    else x402 = true and x402FundRelayerId missing
        Handler-->>Client: CONFIG_MISSING error
    else x402 = false or get-transaction type
        Handler->>DefaultRelayer: Select default relayer
        DefaultRelayer-->>Handler: default relayer instance
        Handler->>DefaultRelayer: Process transaction
        DefaultRelayer-->>Handler: Result
    end

    Handler-->>Client: Response
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • PR #62: Modifies handler.ts's fund-relayer selection and request type routing logic, directly related to the x402 relayer selection control flow introduced here.

Suggested reviewers

  • zeljkoX
  • tirumerla
  • collins-w

Poem

🐰 A relayer hops in, x402 in hand,
Clever config flags across the land,
Fee bumping flows through relayers true,
When tests run wild, sequences renew! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 14.29% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: Add new channel fund for x402 payments' clearly summarizes the main feature addition: introducing support for x402-specific fund relayer functionality for payments.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-new-channel-fund-x402

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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

@NicoMolinaOZ NicoMolinaOZ requested a review from tirumerla March 5, 2026 19:07
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
README.md (1)

225-225: Unify example relayer IDs across x402 docs.

Line 225 uses x402-channels-fund while Line 321 uses x402-fund. Keeping one consistent example name would reduce setup mistakes.

Also applies to: 321-321

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@README.md` at line 225, The README uses two different example relayer IDs
("x402-channels-fund" at the export X402_FUND_RELAYER_ID line and "x402-fund"
elsewhere); standardize them to a single example name across the doc by
replacing the one at the export (export
X402_FUND_RELAYER_ID="x402-channels-fund") to match the chosen canonical example
(e.g., "x402-fund"), and update the adjacent comment text if needed so all
references to the fund relayer ID (the X402_FUND_RELAYER_ID export and any
mentions later in the document) are identical.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/plugin/handler.ts`:
- Around line 290-291: The error payloads are still using config.fundRelayerId
instead of the computed fundRelayerId when x402 is enabled; update the code
paths that build downstream error details to reference the local fundRelayerId
variable (computed from config.x402FundRelayerId and config.fundRelayerId)
rather than directly reading config.fundRelayerId, and ensure any places that
attach relayer identifiers to errors (where fundRelayer and related error
objects are created) include the selected fundRelayerId so the actual relayer
used is reflected in logged/returned error payloads.

---

Nitpick comments:
In `@README.md`:
- Line 225: The README uses two different example relayer IDs
("x402-channels-fund" at the export X402_FUND_RELAYER_ID line and "x402-fund"
elsewhere); standardize them to a single example name across the doc by
replacing the one at the export (export
X402_FUND_RELAYER_ID="x402-channels-fund") to match the chosen canonical example
(e.g., "x402-fund"), and update the adjacent comment text if needed so all
references to the fund relayer ID (the X402_FUND_RELAYER_ID export and any
mentions later in the document) are identical.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ce2898dd-d50b-419b-ae99-d4ac934136dd

📥 Commits

Reviewing files that changed from the base of the PR and between 7072be3 and f586cd5.

📒 Files selected for processing (9)
  • README.md
  • scripts/smoke.ts
  • src/client/types.ts
  • src/plugin/config.ts
  • src/plugin/handler.ts
  • src/plugin/types.ts
  • src/plugin/validation.ts
  • test/handler.x402.test.ts
  • test/validation.test.ts

Copy link
Contributor

@tirumerla tirumerla left a comment

Choose a reason for hiding this comment

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

Overall lgtm, we should also support get transaction methods for x402 so that they get correct relayerId.

Copy link
Contributor

@zeljkoX zeljkoX left a comment

Choose a reason for hiding this comment

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

Thanks for working on this one.

I think we should just make it generic and not tied to x402.
For example param could be related fundRelayer like fundRelayerId=x402 and not x402=true

This way we are not coupling these two things and users are able to extend it for their needs.

@NicoMolinaOZ NicoMolinaOZ merged commit e3aa99d into main Mar 6, 2026
11 checks passed
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.

3 participants