Skip to content

V4 support beta#418

Open
liquid-8 wants to merge 27 commits intomasterfrom
dev/v4-fin
Open

V4 support beta#418
liquid-8 wants to merge 27 commits intomasterfrom
dev/v4-fin

Conversation

@liquid-8
Copy link
Member

Basic functionality, like price fetching, quoting, and making simple swaps etc

@liquid-8 liquid-8 linked an issue Jan 5, 2026 that may be closed by this pull request
Pool manager contract ABI
Liquidity pools list management class added, UniswapV4 improvements.
Copy link
Member

@ErikBjare ErikBjare left a comment

Choose a reason for hiding this comment

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

Generally approved. Haven't checked why CI is failing yet.

Could use some auto-formatting by ruff.

@ErikBjare
Copy link
Member

Ah, I see CI is failing due to outdated actions. I think we can merge this and address the outdated CI and any CI issues related to this PR in follow-up.

@ErikBjare
Copy link
Member

@greptileai review

Copy link
Member

Choose a reason for hiding this comment

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

Maybe move the v4 stuff into e.g. uniswap/v4/uniswap.py for better structure

@greptile-apps
Copy link

greptile-apps bot commented Feb 1, 2026

Greptile Overview

Greptile Summary

This PR adds Uniswap V4 support to the library, introducing new classes for V4 trading operations, pool discovery, and contract interactions across 12+ blockchain networks.

Key additions:

  • Uniswap4 class with price fetching, quoting, and swap execution for V4 pools
  • V4pools class for discovering and caching pool data via event logs
  • Contract ABIs and addresses for V4 router, quoter, stateview, permit2, and poolmanager
  • Support for V4 features including hooks, tick spacing, and Permit2 approvals

Critical issues found:

  • Multiple missing imports (time, logger, InvalidToken, BadFunctionCallOutput, ContractLogicError) will cause runtime errors
  • Hardcoded Windows path separator breaks cross-platform compatibility
  • Swap direction logic (zero_for_one) inconsistent between exact input and exact output swaps, causing incorrect swap execution

Confidence Score: 0/5

  • This PR is NOT safe to merge - contains critical bugs that will cause immediate runtime failures
  • Score reflects multiple critical syntax errors (missing imports for time, logger, exception classes) that will crash at runtime, plus logical errors in swap direction that will cause incorrect trade execution and potential fund loss
  • uniswap/uniswap4.py requires immediate attention - fix all missing imports and verify swap direction logic before any testing

Important Files Changed

Filename Overview
uniswap/uniswap4.py New V4 implementation with critical import errors (time, logger, InvalidToken, BadFunctionCallOutput, ContractLogicError not imported), path handling bug, and swap direction logic inconsistencies
uniswap/init.py Clean exports for new Uniswap4 and V4pools classes
uniswap/v4pools.py Pool discovery and caching via event logs with XML persistence

Sequence Diagram

sequenceDiagram
    participant User
    participant Uniswap4
    participant Permit2
    participant Router
    participant Quoter
    participant StateView
    participant PoolManager
    participant Token

    User->>Uniswap4: initialize with address and provider
    Uniswap4->>Uniswap4: Load contract addresses for chain
    Uniswap4->>Router: Initialize router contract
    Uniswap4->>Quoter: Initialize quoter contract
    Uniswap4->>StateView: Initialize stateview contract
    Uniswap4->>Permit2: Initialize permit2 contract

    User->>Uniswap4: approve token
    Uniswap4->>Token: approve permit2 contract
    Token-->>Uniswap4: transaction hash
    Uniswap4->>Permit2: approve router with amount and expiration
    Permit2-->>Uniswap4: transaction hash

    User->>Uniswap4: get spot price for token pair
    Uniswap4->>StateView: getSlot0 for pool
    StateView-->>Uniswap4: sqrtPriceX96
    Uniswap4-->>User: calculated spot price

    User->>Uniswap4: get quote for exact input
    Uniswap4->>Quoter: quoteExactInputSingle with pool key
    Quoter-->>Uniswap4: output amount
    Uniswap4-->>User: quote amount

    User->>Uniswap4: execute swap with exact input
    Uniswap4->>Uniswap4: Encode V4 SWAP command
    Uniswap4->>Uniswap4: Encode actions for swap settle and take
    Uniswap4->>Router: execute with commands and deadline
    Router->>PoolManager: unlock and execute swap
    PoolManager-->>Router: swap result
    Router-->>Uniswap4: transaction hash
    Uniswap4-->>User: transaction hash
Loading

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

3 files reviewed, 9 comments

Edit Code Review Agent Settings | Greptile

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.

Uniswap v4 support

2 participants