Skip to content

Add EVM x402 settlement extraction#250

Open
DenisCarriere wants to merge 9 commits intomainfrom
codex/evm-x402-implementation
Open

Add EVM x402 settlement extraction#250
DenisCarriere wants to merge 9 commits intomainfrom
codex/evm-x402-implementation

Conversation

@DenisCarriere
Copy link
Copy Markdown
Contributor

@DenisCarriere DenisCarriere commented May 7, 2026

Summary

Adds first-pass EVM x402 settlement support scoped in #249.

  • Adds x402/ as the protobuf event package with map_events and packaged spkg/x402-v0.1.0.spkg.
  • Shapes evm.x402.v1.Events like the DEX/ERC event packages: Events -> Transaction -> Log -> payment, including raw log fields and optional call metadata.
  • Adds evm-x402/ as the database-change package that imports x402:map_events and emits x402_payments rows.
  • Detects EIP-3009 settlements by joining AuthorizationUsed, matching ERC-20 Transfer, decoded transferWithAuthorization calldata when traces are available, and facilitator attribution.
  • Detects Permit2 settlements via the canonical x402ExactPermit2Proxy Settled() / SettledWithPermit() events and joins to the immediately preceding ERC-20 transfer.
  • Adds evm-x402/clickhouse/ with generated ClickHouse schema files, blocks/templates, a facilitator-first x402_payments base table, and aggregate materialized views.
  • Adds generated protobuf bindings and packaged .spkg artifacts for all three layers.

Packages

  • x402-v0.1.0.spkg: normalized protobuf events.
  • evm-x402-v0.1.0.spkg: database changes importing x402.
  • evm-clickhouse-x402-v0.1.0.spkg: ClickHouse sink importing evm-x402.

ClickHouse

x402_payments includes block, transaction, log, call, and payment columns. Its sorting key is facilitator-first and recipient-second:

  • ORDER BY (facilitator, recipient, asset, minute, timestamp, block_num, tx_index, log_index)

Aggregate state tables/MVs:

  • state_x402_totals_by_facilitator: totals grouped by facilitator, recipient, asset, method/source/scheme.
  • state_x402_totals_by_recipient: recipient-first totals for recipient-centric queries.
  • state_x402_volume_by_facilitator_recipient: OHLCV-style interval buckets for payment count and volume across 1m, 5m, 10m, 30m, 1h, 4h, 1d, and 1w windows.

Notes

x402:map_events does not accept params and does not apply facilitator filtering. It emits all onchain EIP-3009 settlement candidates into the database so stricter facilitator rules can be applied in ClickHouse queries.

EIP-3009 payments are emitted as confidence=heuristic. Permit2 proxy events are emitted as confidence=high.

Verification

  • make -C proto protogen
  • cargo check -p x402
  • cargo test -p x402
  • cargo check -p db-evm-x402
  • cargo test -p db-evm-x402
  • cargo build -p x402 --target wasm32-unknown-unknown --release
  • cargo build -p db-evm-x402 --target wasm32-unknown-unknown --release
  • make -C evm-x402/clickhouse schema
  • clickhouse-local --multiquery < evm-x402/clickhouse/schema.sql
  • substreams pack x402/substreams.yaml -o spkg/x402-v0.1.0.spkg
  • substreams pack evm-x402/substreams.yaml -o spkg/evm-x402-v0.1.0.spkg
  • make -C evm-x402/clickhouse pack
  • substreams info x402/substreams.yaml
  • substreams info evm-x402/substreams.yaml
  • substreams info evm-x402/clickhouse/substreams.yaml
  • make -C x402 run STOP_BLOCK=+1
  • make -C evm-x402 run STOP_BLOCK=+1
  • substreams-sink-noop base.substreams.pinax.network:443 evm-x402/substreams.yaml db_out -c --state-store /tmp/evm-x402-noop-state.yaml 45690000:+3

Related

@DenisCarriere DenisCarriere force-pushed the codex/evm-x402-implementation branch 3 times, most recently from 36d1231 to bdb80a0 Compare May 7, 2026 19:59
@DenisCarriere DenisCarriere force-pushed the codex/evm-x402-implementation branch from bdb80a0 to 740bec6 Compare May 7, 2026 20:07
@DenisCarriere DenisCarriere force-pushed the codex/evm-x402-implementation branch from 972935e to 83cef42 Compare May 7, 2026 20:34
@DenisCarriere DenisCarriere force-pushed the codex/evm-x402-implementation branch from 83cef42 to 69ed36f Compare May 7, 2026 20:36
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.

Add x402 payment settlement extraction support

1 participant