Skip to content

feat(uniswap-v3-core): add shared indexing crate with TxDeltaIndexer trait#981

Draft
kayibal wants to merge 2 commits into
mainfrom
feat/uniswap-v3-core-crate
Draft

feat(uniswap-v3-core): add shared indexing crate with TxDeltaIndexer trait#981
kayibal wants to merge 2 commits into
mainfrom
feat/uniswap-v3-core-crate

Conversation

@kayibal
Copy link
Copy Markdown
Contributor

@kayibal kayibal commented May 5, 2026

Summary

Extracts shared UniswapV3 indexing logic into a new uniswap-v3-core crate that compiles for both native and WASM targets. The substreams handlers in ethereum-uniswap-v3-logs-only become thin wrappers that delegate to it.

Adds a TxDeltaIndexer trait to tycho-common:

  • apply_block(block: &dto::BlockChanges) — hydrates internal state from a finalised block; the first call serves as initialisation from a full snapshot, subsequent calls apply incremental deltas.
  • generate_deltas(txs: &[TxInput]) -> dto::BlockChanges — applies a batch of in-flight transactions against the current state and returns the aggregated protocol state deltas they would produce. Does not mutate state; repeated calls with the same transactions return identical results.

The trait is designed as a native-code substitute for a Substreams package: an Ethereum block builder can feed it finalised BlockChanges from the Tycho client and then call generate_deltas to discover how a candidate transaction bundle would alter DEX state before deciding whether to include it.

UniswapV3Processor implements the trait. It stores chain/extractor metadata, running tick and liquidity maps, and token balances. generate_deltas operates on a clone of internal state so it is safe to call repeatedly.

LogInput and TxInput are defined in tycho-common with private fields and public constructors.

The integration test streams from substreams genesis (block 12_369_621) and compares processor output against substreams ground truth across 2000 blocks using apply_block / generate_deltas — 0 attribute mismatches, 0 balance mismatches across 136 attributes and 98 balances.

Also bumps the ethereum-uniswap-v3 and ethereum-uniswap-v3-logs-only substreams toolchains from 1.83.0 to 1.87.0 — hashbrown 0.17 (via indexmap 2.14) requires edition 2024 which needs Cargo ≥ 1.85.

Copy link
Copy Markdown
Contributor

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

Tip: disable this comment in your organization's Code Review settings.

@github-project-automation github-project-automation Bot moved this to Todo in Tycho May 5, 2026
@kayibal kayibal force-pushed the feat/uniswap-v3-core-crate branch 4 times, most recently from d6293b5 to 640e9d9 Compare May 6, 2026 09:02
@kayibal kayibal marked this pull request as draft May 6, 2026 11:33
@kayibal kayibal changed the title feat(uniswap-v3-core): add shared indexing crate with ProtocolProcessor feat(uniswap-v3-core): add shared indexing crate with TxDeltaIndexer trait May 6, 2026
@kayibal kayibal force-pushed the feat/uniswap-v3-core-crate branch 4 times, most recently from 283bcef to ee2cd7a Compare May 19, 2026 18:09
kayibal and others added 2 commits May 19, 2026 23:12
Adds a native-code indexing abstraction for pending block simulation:
- `TxDeltaIndexer` trait and `TxInput`/`LogInput` in tycho-common
- `PendingBlockProcessor` in tycho-simulation for generating ephemeral
  state updates from unconfirmed transactions
- `apply_deltas_ephemeral` on `TychoStreamDecoder` for read-only delta
  application without touching confirmed state
- `build_with_pending` on `ProtocolStreamBuilder` to wire a processor
  alongside the live feed

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds a native Rust implementation of UniswapV3 as a TxDeltaIndexer:
- `UniswapV3Processor` decodes pool-created, swap, mint, burn, and
  collect events directly from EVM logs without a Substreams package
- Tick and liquidity math ported from the Uniswap V3 reference impl
- Balance tracking for component token balances
- Substreams module updated to use the shared block_storage helper

Builds on the TxDeltaIndexer / PendingBlockProcessor infrastructure
from feat/pending-block-processor.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@kayibal kayibal force-pushed the feat/uniswap-v3-core-crate branch from ee2cd7a to 202d34f Compare May 20, 2026 00:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

1 participant