Skip to content

Added multi-hop quotes support#433

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

Added multi-hop quotes support#433
liquid-8 merged 3 commits 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 29.26829% with 29 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (dev/v4-fin@b070366). Learn more about missing BASE report.

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

☔ 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 adds multi-hop quote support to the Uniswap V4 Python SDK by introducing a PathKey dataclass and four new methods: encode_path_keys_input, encode_path_keys_output, get_quote_exact_input, and get_quote_exact_output. It also relocates the existing get_quote_exact_input_single into a cleaner "Quoter methods" section and fixes a pre-existing duplicate price = ( statement. While the overall design aligns with the Uniswap V4 quoter ABI, two P1 runtime bugs need to be resolved before merging:

  • Wrong path order in encode_path_keys_output: The method iterates reversed(path) and then calls encoded_path.insert(0, path_key). Inserting at index 0 during a reversed loop cancels the reversal, leaving elements in forward order — the opposite of what quoteExactOutput requires. The fix is to replace insert(0, ...) with append(...).
  • Missing astuple() conversion: Every other contract call in uniswap4.py wraps dataclass instances with astuple() before passing them to web3.py. The new get_quote_exact_input and get_quote_exact_output methods pass raw PathKey dataclass objects in the path array; since @dataclass objects are not iterable, eth_abi cannot serialize them and both calls will raise a TypeError at runtime. The fix is [astuple(pk) for pk in encoded_path] at the call site.

Confidence Score: 3/5

Not safe to merge — both new multi-hop quote methods will fail at runtime due to missing astuple() conversion, and exact-output quotes will produce wrong results due to incorrect path ordering.

Two independent P1 bugs affect every code path introduced by this PR: (1) PathKey instances are passed directly to web3.py without astuple(), raising a TypeError on the first call; and (2) encode_path_keys_output emits the path in forward order instead of backward order, causing quoteExactOutput to route incorrectly or revert on-chain. Neither issue is speculative — both are present defects that prevent the new functionality from working.

uniswap/uniswap4.py — specifically encode_path_keys_output (line 1515) and both multi-hop contract call sites (lines 1555–1561, 1604–1610).

Important Files Changed

Filename Overview
uniswap/types.py Adds the PathKey dataclass with fields matching the Uniswap V4 ABI PathKey struct; straightforward and correct.
uniswap/uniswap4.py Adds multi-hop quote methods and path-encoding helpers; contains two P1 bugs: encode_path_keys_output builds the path in the wrong order due to insert(0,…) while iterating reversed(), and PathKey dataclass instances are passed directly to web3.py without astuple() conversion, raising a TypeError at runtime.

Sequence Diagram

sequenceDiagram
    participant Caller
    participant Uniswap4
    participant QuoterContract

    Note over Caller,QuoterContract: Multi-hop Exact Input (A to B to C)
    Caller->>Uniswap4: get_quote_exact_input(token0=A, token1=C, qty, path)
    Uniswap4->>Uniswap4: encode_path_keys_input(path, currency_in=A)
    Note right of Uniswap4: Produces [PathKey(B), PathKey(C)] correct order
    Uniswap4->>QuoterContract: quoteExactInput((A, [PathKey(B), PathKey(C)], qty))
    Note right of Uniswap4: PathKey instances not astuple()-converted, TypeError
    QuoterContract-->>Caller: amountOut

    Note over Caller,QuoterContract: Multi-hop Exact Output (A to B to C)
    Caller->>Uniswap4: get_quote_exact_output(token0=A, token1=C, qty, path)
    Uniswap4->>Uniswap4: encode_path_keys_output(path, currency_out=C)
    Note right of Uniswap4: BUG insert(0) while reversed yields [PathKey(A), PathKey(B)] wrong
    Note right of Uniswap4: Expected [PathKey(B), PathKey(A)] correct
    Uniswap4->>QuoterContract: quoteExactOutput((C, [PathKey(A), PathKey(B)], qty))
    Note right of Uniswap4: Wrong order and no astuple, incorrect result
    QuoterContract-->>Caller: amountIn wrong
Loading

Reviews (1): Last reviewed commit: "Added multi-hop quotes support" | Re-trigger Greptile

@liquid-8 liquid-8 merged commit 7608442 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