Skip to content

Alloy UniswapV3Pool bindings - #3662

Merged
squadgazzz merged 60 commits into
jmgd/alloy/conv-fixfrom
UniswapV3Pool
Sep 30, 2025
Merged

Alloy UniswapV3Pool bindings#3662
squadgazzz merged 60 commits into
jmgd/alloy/conv-fixfrom
UniswapV3Pool

Conversation

@squadgazzz

@squadgazzz squadgazzz commented Sep 16, 2025

Copy link
Copy Markdown
Contributor

Description

Migrates UniswapV3Pool SC bindings to alloy.

Tests heavily utilize SC events generated by alloy, but they don't implement Eq, PartialEq and Debug required for proper tests, so I had to implement some wrappers. The issue is opened alloy-rs/core#1009

How to test

Existing test + mainnet shadow.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Comment on lines +44 to +45
// AlloyUniswapV3PoolEvents doesn't derive Clone, so we need this wrapper
#[derive(Clone)]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Given that they are open for PRs and that it's an easy fix we should probably just upstream the needed changes to alloy.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can look into that later. Can we merge this PR as is to start properly testing the liquidity with alloy? Possibly in prod.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We actually need not only Clone, but also PartialEq and Debug.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Sure, but assuming those can be derived on the alloy events that would be a 2 line PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

extra_derives(<paths...>): adds extra #[derive(...)] attributes to all generated types.

https://docs.rs/alloy/latest/alloy/sol_types/macro.sol.html

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sure, but assuming those can be derived on the alloy events that would be a 2 line PR.

I might have missed something, but it is not.

docs.rs/alloy/latest/alloy/sol_types/macro.sol.html

Please read the PR description carefully 🙂

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, I think I found the solution. Will open a PR shortly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I updated the PR to migrate to alloy bindings, but I currently use a dependency to my opened PR alloy-rs/core#1017. I can't reproduce the issue in the alloy repo tests for some reason, but it is easy to reproduce it here for some reason 🤷

Base automatically changed from support-multiple-alloy-sc-events to main September 18, 2025 08:13
# Conflicts:
#	crates/contracts/src/alloy.rs
#	crates/contracts/src/lib.rs
#	crates/shared/src/event_handling.rs

@MartinquaXD MartinquaXD left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It's a bit unfortunate that we need the WithAddress wrapper because alloy events don't contain the address or log index on their own.
If this is useful for other indexing logic we should consider moving this wrapper type into ethrpc/alloy to make it reusable.
Overall just nits.

set.insert(PoolCreated::SIGNATURE_HASH);
Filter::new()
.event_signature(hashset![PoolCreated::SIGNATURE_HASH])
.event_signature(set)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: Does this work? I think event_signatures takes anything that can be converted into a FilterSet. Same comment applies to the other instances of event_signature().

Suggested change
.event_signature(set)
.event_signature([PoolCreated::SIGNATURE_HASH].into_iter())

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For some reason it stopped working when i updated the alloy version.

{
match event.inner() {
UniswapV3PoolEvents::Burn(burn) => {
let tick_lower = BigInt::from(burn.tickLower.as_i32());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Bit surprising that the contract returns int24 but we currently parse the subgraph response via BigInt. Could you check if we can turn the tick_lower field in the subgraph response into an i32 as well?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably yes, but that requires changing types in many places. Worth a separate PR.

Comment thread crates/shared/src/sources/uniswap_v3/event_fetching.rs Outdated
Comment thread crates/shared/src/sources/uniswap_v3/event_fetching.rs Outdated
@squadgazzz

Copy link
Copy Markdown
Contributor Author

That is weird. I can't reproduce locally any of the CI issues. Running on the same rust version...

@squadgazzz
squadgazzz enabled auto-merge (squash) September 25, 2025 17:21
@squadgazzz
squadgazzz changed the base branch from main to jmgd/alloy/conv-fix September 30, 2025 10:28
@squadgazzz
squadgazzz merged commit b793ee5 into jmgd/alloy/conv-fix Sep 30, 2025
9 of 16 checks passed
@squadgazzz
squadgazzz deleted the UniswapV3Pool branch September 30, 2025 10:28
@github-actions github-actions Bot locked and limited conversation to collaborators Sep 30, 2025
@squadgazzz
squadgazzz restored the UniswapV3Pool branch September 30, 2025 10:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants