Skip to content

Conversation

@tvinagre
Copy link
Contributor

Some pools were triggering a decoder panic with the following error:
thread 'tokio-runtime-worker' panicked at src/evm/protocol/utils/uniswap/swap_math.rs:26:24: attempt to subtract with overflow

The reason was bc pools with dynamic fees are initialized with 0x800000 - where the expected value should be 0, together with the 23rd bit as a flag indicating that the pool has dynamic fees.
On decoding, we weren't considering this case, making the fee overflow (since 0x800000 is higher than Uniswap's max fee of 100%).

During this investigation, was also noticed that Uniswap's fee implementation is not correct.
According to https://raw.githubusercontent.com/Uniswap/v4-core/main/src/libraries/ProtocolFeeLibrary.sol - the fee formula is:
// protocolFee + lpFee - (protocolFee * lpFee / 1_000_000)
and our current implementation is
// protocolFee + lpFee

causing a wrong fee calculation, and overflow on protocols where protocolFee + lpFee > 100%.

@github-project-automation github-project-automation bot moved this to Todo in Tycho Nov 11, 2025
@tvinagre tvinagre force-pushed the tl/fix-univ4-dynamic-fee branch 2 times, most recently from 51aa88f to 889b44f Compare November 11, 2025 22:30
Copy link
Collaborator

@dianacarvalho1 dianacarvalho1 left a comment

Choose a reason for hiding this comment

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

aaff thank you for finding and fixing this @tvinagre ! 🙏🏼 great catches!! ✨ this fee logic is a paaiiin

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Tycho Nov 12, 2025
@tvinagre tvinagre enabled auto-merge November 12, 2025 15:23
@tvinagre tvinagre force-pushed the tl/fix-univ4-dynamic-fee branch from 995e263 to 49fe16b Compare November 12, 2025 15:23
@tvinagre tvinagre merged commit 4e2aee7 into main Nov 12, 2025
3 checks passed
@tvinagre tvinagre deleted the tl/fix-univ4-dynamic-fee branch November 12, 2025 15:26
@github-project-automation github-project-automation bot moved this from In Progress to Done in Tycho Nov 12, 2025
@propellerci
Copy link

propellerci bot commented Nov 12, 2025

This PR is included in version 0.196.2 🎉

@propellerci propellerci bot added the true label Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

3 participants