Skip to content

Conversation

@liobrasil
Copy link

@liobrasil liobrasil commented Nov 3, 2025

Fix computation limits in Uniswap V3 connector

Problem

getMaxAmount() was hitting computation limits due to expensive tick bitmap scanning (20-30+ EVM calls per transaction).

Solution

Replaced tick-scanning with lightweight price impact heuristic:

  • 2 EVM calls instead of 20-30 (slot0 + liquidity)
  • Calculates max amount based on configurable price impact (default 5%)
  • 80% safety margin applied

Changes

  • Simplified getMaxAmount() calculation
  • Added configurable maxPriceImpactBps parameter
  • Removed tick bitmap scanning functions
  • All existing APIs unchanged

Trade-off

Less precise but significantly faster. Sufficient for preventing oversized swap requests.​​​​​​​​​​​​​​​​

…Res for brevity and consistency in naming conventions
…t to UFix128 for improved precision in calculations

fix(UniswapV3SwapConnectors.cdc): update calculations to use UFix128 for consistent handling of decimal values in price impact logic
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.

2 participants