Skip to content

Conversation

@fosc19
Copy link
Contributor

@fosc19 fosc19 commented Nov 3, 2025

DefiLlama adapter for tracking x402 payment protocol volume on Base.


What is x402?

x402 is a payment protocol enabling USDC payments to AI agents using Account Abstraction and EIP-3009 (transferWithAuthorization) on Base L2.

Links:


What This Adapter Tracks

Metrics Returned:

{
  dailyVolume: Balances,    // Total USDC transferred via x402 facilitators
  dailyFees: 0,             // Set to 0 (see explanation below)
  dailyRevenue: 0,          // Set to 0 (see explanation below)
}

Coverage: Tracks 36 facilitator addresses across 11 providers (Coinbase, PayAI, Questflow, x402rs, Codenut, Aurracloud, OpenX402, Daydreams, Mogami, Thirdweb, 402104, XEcho) on Base.

Start Date: December 5, 2024 (earliest facilitator)


Why Fees/Revenue = 0?

⚠️ On-chain fees cannot be confirmed:

  • USDC Transfer events show full payment amounts (user → AI agent) with no visible deduction
  • Individual facilitators may charge fees off-chain (subscriptions, wrapped services, etc.)
  • Protocol revenue model is not publicly documented
  • Setting to 0 represents: no on-chain fee deduction visible in these transactions

dailyVolume is accurate: Total USDC transferred through x402 facilitators is precisely measured


Technical Implementation

Detection Method

1. Find AuthorizationUsed events (EIP-3009) on USDC(Base)
   ↓
2. Filter transactions by sender (tx.from) against facilitator allowlist
   ↓
3. Respect per-facilitator start dates (since field)
   ↓
4. Sum all USDC Transfer amounts in matching transactions

Why Track by Sender (tx.from)?

Challenge:

  • AI agent addresses (tx.to) are visible on-chain but lack identity mapping
  • No on-chain registry linking addresses to agent names/identities
  • Volume per address can be measured perfectly, but identifying which agent corresponds to which address requires external data sources

Solution:

  • Track by facilitator addresses (tx.from) - only 36 known addresses
  • Each facilitator processes many agent payments
  • Easy to maintain and update

Alternative Approach (Future Enhancement):

A separate adapter could track individual AI agent volumes by recipient address (tx.to):

  • Volume measurement: Can be calculated perfectly on-chain for each address
  • Identity mapping: Requires external data sources to link addresses to agent names
  • Similar to facilitators: addresses are visible, but entity identification needs cross-referencing
  • Future implementation could integrate external sources (x402scan API, registries, databases) to map addresses to agent identities
  • This would enable "top agents by volume" metrics with identified names

Event Signatures

AuthorizationUsed (EIP-3009):

event AuthorizationUsed(address indexed authorizer, bytes32 indexed nonce)

Transfer (ERC-20):

event Transfer(address indexed from, address indexed to, uint256 value)

Multi-Path Fallback

The adapter uses multiple paths for different RPC capabilities:

  1. Receipts path: Uses getTxReceipts to get full transaction data
  2. Transactions fallback: Uses getTransactions when receipts unavailable
  3. Empty fallback: Returns 0 to avoid false positives

Testing

# Test the adapter
npm test fees x402 2025-10-31

# Expected output
✓ returns dailyVolume
✓ returns dailyFees (0)
✓ returns dailyRevenue (0)

Verified Dates:

  • Recent activity confirmed via on-chain data
  • Processes ~1M+ AuthorizationUsed events/day efficiently

Code Structure

Single file: fees/x402/index.ts (~210 lines)

  • 36 facilitator addresses with start dates
  • Event detection logic
  • Multi-path fallback implementation
  • Methodology documentation

Methodology Statement

Volume: USDC payment volume facilitated through x402 protocol on Base. Tracks transfers from authorized facilitator addresses (36 addresses across 11 providers) using EIP-3009. Respects dateOfFirstTransaction for each facilitator address.

Fees: x402 protocol does not charge user fees on-chain. All payment amounts go directly to recipients. Facilitators may charge fees off-chain.

Revenue: Protocol does not collect direct revenue from transactions. Revenue model is not public.


Data Accuracy

High confidence:

  • ✅ On-chain verified via AuthorizationUsed events
  • ✅ All known facilitator addresses tracked
  • ✅ No false positives (strict sender filtering)

Limitations:

  • ⚠️ New facilitators require manual addition
  • ⚠️ Off-chain fees/revenue not captured
  • ⚠️ Individual AI agent volumes measurable but identities require external data sources

Tracks USDC payment volume through 36 x402 facilitator addresses across 11 providers on Base chain.

- Detects x402 transactions via AuthorizationUsed events (EIP-3009)
- Multi-path fallback for different RPC capabilities
- Respects per-facilitator start dates
- SimpleAdapter v2 compatible
- Start date: 2024-12-05
@llamabutler
Copy link

The x402 adapter exports:

> [email protected] test
> ts-node --transpile-only cli/testAdapter.ts fees x402

🦙 Running X402 adapter 🦙
---------------------------------------------------
Start Date:	Sun, 02 Nov 2025 17:51:13 GMT
End Date:	Mon, 03 Nov 2025 17:51:13 GMT
---------------------------------------------------

getLogs: large cache size detected 3239042 logs size: 1760.7249641418457MB, retaining only the latest 200k logs to limit memory usage target=0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913 topic=0x98de503528ee59b575ef0c0a2576a82497bfc029a5685b209e9ec333479b10a5 fromBlock=37658252 toBlock=37701472

<--- Last few GCs --->

[2216:0x5e551b0]  1387573 ms: Mark-Compact 4061.4 (4142.9) -> 4046.2 (4143.7) MB, 1843.67 / 0.00 ms  (average mu = 0.528, current mu = 0.040) allocation failure; scavenge might not succeed
[2216:0x5e551b0]  1390365 ms: Mark-Compact 4062.1 (4143.7) -> 4047.0 (4144.4) MB, 2642.39 / 0.00 ms  (average mu = 0.332, current mu = 0.054) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
----- Native stack trace -----

 1: 0xb76dc5 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node]
 2: 0xee6020 v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
 3: 0xee6307 v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, v8::OOMDetails const&) [node]
 4: 0x10f7f55  [node]
 5: 0x110fdd8 v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [node]
 6: 0x10e5ef1 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 7: 0x10e7085 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [node]
 8: 0x10c46d6 v8::internal::Factory::NewFillerObject(int, v8::internal::AllocationAlignment, v8::internal::AllocationType, v8::internal::AllocationOrigin) [node]
 9: 0x1520216 v8::internal::Runtime_AllocateInYoungGeneration(int, unsigned long*, v8::internal::Isolate*) [node]
10: 0x7f79e1e99ef6 
Aborted (core dumped)

@noateden noateden self-assigned this Nov 4, 2025
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