Skip to content

Conversation

@jolestar
Copy link
Contributor

@jolestar jolestar commented Jan 5, 2026

Summary

This PR adds support for SKALE on Base network and fixes a critical bug in facilitator fee calculation where CAIP-2 network identifiers weren't properly matched to token prices.

Changes

Network Configuration

Shared Network Infrastructure

  • ✅ Create contracts/networks.json generation from TypeScript source
    • Script: typescript/packages/extensions/scripts/generate-networks-json.ts
    • Command: pnpm generate:networks
  • ✅ Update contracts/deploy-contract.sh to support CAIP-2 format
    • Accepts both eip155:1187947933 and skale-base
    • Single source of truth for network configuration
  • ✅ Add getNetworkAlias import for proper network name matching

Facilitator Fee Calculation Fix

  • 🐛 Critical Bug Fix: CAIP-2 network IDs weren't matched to token prices
    • eip155:1187947933 didn't match "skale" in price lookup
    • Fell back to GENERIC price ($100) instead of CREDIT price
    • Impact: SKALE facilitator fee was $1.78 instead of ~$0.004
  • ✅ Fix: Convert CAIP-2 to alias before price matching
  • ✅ Add CREDIT token price configuration

Deployed Contracts

SKALE on Base (eip155:1187947933)

  • SettlementRouter: 0x1Ae0E196dC18355aF3a19985faf67354213F833D
  • TransferHook: 0x2f05fe5674aE756E25C26855258B4877E9e021Fd
  • NFTMintHook: 0x73fc659Cd5494E69852bE8D9D23FE05Aab14b29B
  • RandomNFT: 0x081258287F692D61575387ee2a4075f34dd7Aef7
  • RewardHook: 0xC20634ea518985901e32Fbc1bA27fa673D37601A
  • RewardToken: 0x9Fc2c199170B039f093ABCd54008038F0C0a31d6

SKALE Base Sepolia (eip155:324705682)

  • SettlementRouter: 0x1Ae0E196dC18355aF3a19985faf67354213F833D
  • TransferHook: 0x2f05fe5674aE756E25C26855258B4877E9e021Fd
  • NFTMintHook: 0x73fc659Cd5494E69852bE8D9D23FE05Aab14b29B
  • RandomNFT: 0x081258287F692D61575387ee2a4075f34dd7Aef7
  • RewardHook: 0xc20634ea518985901e32fbc1ba27fa673d37601a
  • RewardToken: 0x9fc2c199170b039f093abcd54008038f0c0a31d6

Test Plan

  • Deploy contracts to SKALE on Base
  • Deploy contracts to SKALE Base Sepolia
  • Verify facilitator auto-discovers SKALE networks
  • Verify facilitator fee calculation with correct CREDIT price
  • Test settlement transaction on SKALE on Base
  • Add unit tests for network alias matching
  • Add integration tests for SKALE networks

Related Issues

None

Breaking Changes

None. This is a new network addition and bug fix.

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings January 5, 2026 05:12
@vercel
Copy link

vercel bot commented Jan 5, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
x402x-web Ready Ready Preview, Comment Jan 5, 2026 5:42am

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Jan 5, 2026

Deploying x402-exec with  Cloudflare Pages  Cloudflare Pages

Latest commit: 2c1971f
Status: ✅  Deploy successful!
Preview URL: https://57e9c430.x402-exec.pages.dev
Branch Preview URL: https://feature-skale-base-network.x402-exec.pages.dev

View logs

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds support for the SKALE on Base network and fixes a critical bug in the facilitator fee calculation where CAIP-2 network identifiers weren't properly matched to token prices. Additionally, it establishes a shared network infrastructure by generating networks.json from TypeScript sources for use by shell deployment scripts.

Key Changes:

  • Adds SKALE on Base mainnet (eip155:1187947933) with deployed contracts and USDC token configuration
  • Fixes facilitator fee calculation to convert CAIP-2 IDs to aliases before price matching using getNetworkAlias()
  • Creates generate-networks-json script to generate networks.json from TypeScript configuration as a single source of truth

Reviewed changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
typescript/packages/extensions/src/networks.ts Adds SKALE on Base network configuration with contract addresses
typescript/packages/extensions/src/network-utils.ts Adds SKALE Base network aliases and default USDC asset configuration
typescript/packages/extensions/src/chains.ts Adds SKALE Base chain definition with RPC and explorer URLs
typescript/packages/extensions/scripts/generate-networks-json.ts New script to generate networks.json from TypeScript sources
typescript/packages/extensions/scripts/generate-networks-json.mjs ESM wrapper for the generation script
typescript/packages/extensions/package.json Adds generate-networks-json script and tsx dependency
package.json Adds root-level generate:networks command
facilitator/src/config.ts Fixes fee calculation by converting CAIP-2 to alias with getNetworkAlias
facilitator/src/defaults.ts Adds CREDIT token price constant ($0.25)
contracts/networks.json Generated network configuration for shell scripts
contracts/deploy-contract.sh Refactored to use networks.json and support CAIP-2 format
contracts/verify-usdc-eip712.sh New utility script to verify USDC EIP-712 domain configuration
pnpm-lock.yaml Lock file updates for tsx dependency
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"explorerUrl": "https://base-sepolia-testnet-explorer.skalenodes.com",
"gasModel": "legacy",
"type": "testnet",
"nativeToken": "Credits"
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

Inconsistent nativeToken naming between the two SKALE networks. SKALE Base Sepolia uses "Credits" (line 87) while SKALE on Base uses "CREDIT" (line 99). These should be consistent, preferably using "CREDIT" to match the TypeScript configuration and the CREDIT token price constant in the facilitator code.

Suggested change
"nativeToken": "Credits"
"nativeToken": "CREDIT"

Copilot uses AI. Check for mistakes.
Comment on lines 33 to 38
"xlayer-testnet": "eip155:1952", // Legacy alias for backward compatibility
"skale-base-sepolia": "eip155:324705682",
"skale-base": "eip155:1187947933",
base: "eip155:8453",
"x-layer": "eip155:196",
xlayer: "eip155:196", // Legacy alias for backward compatibility
Copy link

Copilot AI Jan 5, 2026

Choose a reason for hiding this comment

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

The addition of legacy aliases "xlayer-testnet" and "xlayer" creates a potential issue. When NETWORK_ALIASES is generated from NETWORK_ALIASES_V1_TO_V2, multiple aliases mapping to the same CAIP-2 ID will cause the last one to overwrite earlier ones. This means "eip155:1952" will map to "xlayer-testnet" instead of the canonical "x-layer-testnet", and "eip155:196" will map to "xlayer" instead of "x-layer". Consider documenting which alias takes precedence or restructuring to ensure the canonical alias is used.

Copilot uses AI. Check for mistakes.
## Network Configuration
- Add SKALE on Base (eip155:1187947933, chainId: 1187947933)
- Add SKALE Base Sepolia (eip155:324705682, chainId: 324705682)
- Configure USDC (Bridged USDC with EIP-712 verification)
- Configure CREDIT token pricing: $0.25 (1 USD = 4 CREDIT)

## Shared Network Configuration
- Create networks.json generation script from TypeScript source
- Update deploy-contract.sh to support CAIP-2 network identifiers
- Add getNetworkAlias import for network name matching

## Facilitator Improvements
- Fix native token price matching for SKALE networks
- Convert CAIP-2 IDs to aliases before price matching
- Add CREDIT token price configuration

## Deployed Contracts (SKALE on Base)
- SettlementRouter: 0x1Ae0E196dC18355aF3a19985faf67354213F833D
- TransferHook: 0x2f05fe5674aE756E25C26855258B4877E9e021Fd
- NFTMintHook: 0x73fc659Cd5494E69852bE8D9D23FE05Aab14b29B
- RandomNFT: 0x081258287F692D61575387ee2a4075f34dd7Aef7
- RewardHook: 0xC20634ea518985901e32Fbc1bA27fa673D37601A
- RewardToken: 0x9Fc2c199170B039f093ABCd54008038F0C0a31d6

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
…ence

## Fix 1: Standardize nativeToken to "CREDIT" for SKALE networks

- Change SKALE Base Sepolia nativeToken from "Credits" to "CREDIT"
- Update chains.ts nativeCurrency.symbol from "sFUEL" to "CREDIT"
- Update networks.ts metadata.nativeToken to "CREDIT"
- Ensure consistency across all SKALE network configurations

## Fix 2: Ensure canonical network aliases take precedence

- Reorder NETWORK_ALIASES_V1_TO_V2 to place canonical aliases after legacy ones
- This ensures "x-layer-testnet" and "x-layer" override "xlayer-testnet" and "xlayer"
- Prevents non-canonical aliases from being returned by getNetworkAlias()

## Impact

These changes ensure:
1. Consistent native token naming across all SKALE networks
2. Reverse mapping (CAIP-2 -> alias) returns canonical aliases
3. Generated networks.json uses correct token symbols

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
## Changes

### Update test expectations for legacy aliases
- Add "skale-base" to EXPECTED_V1_NETWORKS (was missing)
- Add LEGACY_V1_ALIASES constant for backward compatibility aliases
- Create ALL_EXPECTED_ALIASES combining canonical and legacy

### Update test logic to handle non-bijective mappings
- "should have v2 mappings" test: Verify total alias count includes legacy ones
- "should have no duplicate" test: Allow CAIP-2 duplicates for legacy aliases
- "should have bijective relationship" test: Only test canonical aliases
- "toCanonicalNetworkKey" test: Add legacy alias test cases

## Rationale

Legacy aliases (xlayer-testnet, xlayer) are intentionally supported for
backward compatibility. This means v1 names are no longer in a strict
one-to-one relationship with CAIP-2 IDs. Tests now reflect this reality.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@jolestar jolestar merged commit a7e7e3f into main Jan 5, 2026
8 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.

2 participants