Skip to content

Checks improvements, small logic fix, multi-hop tests added#434

Merged
liquid-8 merged 1 commit intouniswap-python:dev/v4-finfrom
liquid-8:uniswap4_RC
Mar 31, 2026
Merged

Checks improvements, small logic fix, multi-hop tests added#434
liquid-8 merged 1 commit intouniswap-python:dev/v4-finfrom
liquid-8:uniswap4_RC

Conversation

@liquid-8
Copy link
Copy Markdown
Member

No description provided.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 31, 2026

Codecov Report

❌ Patch coverage is 0% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 58.44%. Comparing base (d32b5dd) to head (9de6a7e).
⚠️ Report is 14 commits behind head on dev/v4-fin.

Files with missing lines Patch % Lines
uniswap/uniswap4.py 0.00% 12 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           dev/v4-fin     #434   +/-   ##
===========================================
  Coverage       58.44%   58.44%           
===========================================
  Files              12       12           
  Lines            1865     1865           
===========================================
  Hits             1090     1090           
  Misses            775      775           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@greptile-apps
Copy link
Copy Markdown

greptile-apps bot commented Mar 31, 2026

Greptile Summary

This PR improves the Uniswap v4 Python library with case-insensitive address comparisons, variable renaming for clarity, multi-hop quoter tests, and minor housekeeping. However, a logic regression in encode_path_keys_input reverses the multi-hop path for exact-input quotes, which needs to be reverted before merging.

Key changes:

  • .lower() comparison fix (correct): All eight token-ordering guards (if token0 > token1) across StateView, quoter, and swap functions are updated to use .lower(). Without this, checksummed addresses (e.g. \"0xA0b8...\") could sort differently than their lowercase equivalents, leading to wrong pool key derivation.
  • encode_path_keys_input regression (P1): encoded_path.append(path_key) was changed to encoded_path.insert(0, path_key). Since this function iterates path in forward order, insert-at-front produces a reversed list. The Uniswap v4 V4Quoter consumes the path in forward order, so a reversed list causes the quoter to look up the wrong pool for the first hop on any 2+ hop path.
  • Multi-hop tests added: New 2-hop get_quote_exact_input and get_quote_exact_output tests are added (ETH → USDC → USDT). The exactInput 2-hop test will fail or produce wrong results due to the regression above.
  • Unused fee parameter removed from make_swap_input / make_swap_output public methods (the fee is already carried by swap_pool_key).
  • Test variable renaming: test_token0/test_token1test_ETH/test_USDC/test_USDT improves readability.

Confidence Score: 4/5

Not safe to merge as-is — a single-line regression in encode_path_keys_input reverses multi-hop exact-input paths and must be reverted.

All other changes (8× .lower() fix, variable renames, removed unused parameter, comment cleanup, new tests) are correct and valuable. The one P1 issue — append replaced by insert(0,...) in encode_path_keys_input — silently breaks any 2+ hop quoteExactInput call. Single-hop paths are unaffected, meaning existing 1-hop tests still pass and the regression can easily go unnoticed. Reverting that single line restores correct behaviour and makes the PR mergeable.

uniswap/uniswap4.py line 1502 (encode_path_keys_input)

Important Files Changed

Filename Overview
uniswap/uniswap4.py Upgrades all token-ordering guards to case-insensitive .lower() comparison (correct fix); introduces a path-reversal regression in encode_path_keys_input (append → insert(0,...)) that breaks multi-hop exact-input quotes; removes stale TODO/FIXME comments and an unused fee parameter from public swap functions.
tests/v4tests.py Renames test_token0/test_token1 to descriptive test_ETH/test_USDC/test_USDT; adds multi-hop get_quote_exact_input and get_quote_exact_output tests; the 2-hop exactInput test will produce wrong results due to the path-reversal bug in encode_path_keys_input.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant get_quote_exact_input
    participant encode_path_keys_input
    participant V4Quoter

    Caller->>get_quote_exact_input: (ETH, qty, [ETH-USDC pool, USDT-USDC pool])
    get_quote_exact_input->>encode_path_keys_input: (path=[ETH-USDC, USDT-USDC], currency_in=ETH)

    Note over encode_path_keys_input: OLD (correct): append<br/>→ [PathKey(USDC,fee1), PathKey(USDT,fee2)]

    Note over encode_path_keys_input: NEW (regression): insert(0,...)<br/>→ [PathKey(USDT,fee2), PathKey(USDC,fee1)] REVERSED

    encode_path_keys_input-->>get_quote_exact_input: encoded_path

    get_quote_exact_input->>V4Quoter: quoteExactInput({ETH, encoded_path, qty})

    Note over V4Quoter: hop[0]: inputCurrency=ETH + PathKey(USDT,fee2)<br/>→ looks for ETH-USDT pool (WRONG)

    V4Quoter-->>get_quote_exact_input: revert / wrong quote
    get_quote_exact_input-->>Caller: error
Loading

Reviews (1): Last reviewed commit: "Checks improvements, small logic fix, mu..." | Re-trigger Greptile

@liquid-8 liquid-8 merged commit 4ae4dcb into uniswap-python:dev/v4-fin Mar 31, 2026
4 of 5 checks passed
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.

1 participant