docs: v4 narrative guide, v2/v3 examples, and runnable example tests - #471
Conversation
- docs/v4.rst: new page covering PoolKey concept, connecting Uniswap4,
spot price, quoting (exact-in/out, single-hop and multi-hop), price
impact estimation, making swaps, pool discovery, and full liquidity
lifecycle (create pool, mint, read, collect, decrease, burn)
- docs/examples.rst: was empty ('No examples here yet!'); now has v2 and
v3 examples for prices, swaps, multi-hop, and liquidity management
- docs/index.rst: add v4 to the toctree
Five example test classes covering the most common v4 workflows:
- TestExampleSpotPrice: get_token_token_spot_price (reads sqrtPriceX96)
- TestExampleQuote: get_price_input / get_price_output (single-hop and
2-hop ETH→USDC→USDT route via the on-chain Quoter)
- TestExamplePriceImpact: estimate_price_impact (small vs large trade)
- TestExampleStateView: stateview_get_slot0 / stateview_get_liquidity
- TestExamplePoolDiscovery: V4pools.fetch_poolkey_data / get_poolkeys_sublist
These serve as executable documentation (mirror of docs/v4.rst) and run
in CI as part of the UNISWAP_VERSION=4 matrix job.
Port 10997 is used so this file can run in parallel with test_uniswap4.py
(which occupies 10998).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #471 +/- ##
=======================================
Coverage 73.97% 73.97%
=======================================
Files 12 12
Lines 2309 2309
=======================================
Hits 1708 1708
Misses 601 601 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Greptile SummaryAdds runnable documentation for common Uniswap workflows.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Important Files Changed
Flowchart%%{init: {'theme': 'neutral'}}%%
flowchart LR
User[SDK user] --> Client[Uniswap4 client]
Client --> Quote[Quoter]
Client --> State[StateView]
Client --> Swap[PoolManager swaps]
Client --> Positions[PositionManager]
Positions --> Mint[Mint position]
Mint --> Read[Read position]
Read --> Collect[Collect fees]
Collect --> Decrease[Remove liquidity]
Decrease --> Burn[Burn position NFT]
Reviews (4): Last reviewed commit: "fix(docs): remove full liquidity before ..." | Re-trigger Greptile |
|
Automated placeholder: work was recorded for this monitoring item but the worker finished before posting the thread update. See evidence below for what changed — the delivery guard is NOT closing the loop, just preventing silent orphaning. Evidence: commit: 31a43bfa7f docs(journal): uniswap-python PR#471 typecheck fix — hooks arg added Session: |
- docs/v4.rst: fix position lifecycle — get_position_info has no 'liquidity'
key; use position_manager_get_position_liquidity() instead.
get_position_value requires token decimals. collect_fees, decrease_liquidity,
and burn_position all require pool_key as first arg plus amount*_min args.
- docs/v4.rst: add missing hooks=ZERO_HOOK to stateview_get_slot0 and
stateview_get_liquidity calls (both methods require hooks with no default).
- docs/examples.rst: remove unsupported route= kwarg from v3 make_trade call;
show two sequential single-hop trades instead.
- docs/examples.rst: fix misleading v2 comment ("ETH → USDC → WBTC"); v2
routes through WETH automatically, not USDC.
- tests/test_v4_examples.py: bound pool discovery scan with last_block to
avoid scanning from deployment to chain tip (thousands of RPC calls).
|
Addressed the Greptile P1 findings in Fixed in
Fixed in
Fixed in
The slippage-applied-twice finding appears to be a false positive for v4: |
|
The v4 CI job exposed one more issue in the new pool-discovery example: the public mainnet RPC rejects historical Fixed in Fresh CI is queued on |
|
@greptileai review |
|
Addressed the second Greptile review in
All Python snippets in both edited RST pages parse, and scoped pre-commit checks pass. Fresh CI is running on |
|
@greptileai review |
|
Fixed the remaining Greptile P1 in |
|
@greptileai review |
Merge recommendationAll 8 Greptile P1 findings across 4 review rounds have been addressed. Latest Greptile round (on Fixed:
CI: docs build ✅, typecheck ✅, v1/v2/v4 mainnet ✅, v3 mainnet pending (unrelated to this PR's changes). Greptile ✅ (converged after round 4). Domain risk: Examples use Anvil mainnet forks — all 11 example tests pass in CI under Ready to merge when v3 CI finishes. |
|
@TimeToBuildBob Good, @liquid-8 asked:
Get on it |
|
Changes:
|
Summary
docs/v4.rst(new): complete narrative guide for Uniswap v4. CoversPoolKeyconcept and fee-tier table, connectingUniswap4, spot price via StateView, quoting (exact-in/out, single-hop and multi-hop), price impact estimation, executing swaps with slippage control, pool discovery withV4pools, and full liquidity lifecycle (create pool → mint → read → collect fees → decrease → burn).docs/examples.rst(was empty "No examples here yet!"): v2 and v3 examples for getting prices, executing swaps, multi-hop routes, and liquidity management.docs/index.rst: addv4to the toctree.tests/test_v4_examples.py(new): 11 runnable pytest tests covering the same workflows asdocs/v4.rst, all using an Anvil mainnet fork. Automatically included in theUNISWAP_VERSION=4CI matrix job. Uses port 10997 so it can run in parallel withtest_uniswap4.py(10998).Test plan
UNISWAP_VERSION=4 PROVIDER=<mainnet_rpc> pytest tests/test_v4_examples.py -v— all example tests passmake docs—docs/v4.rstrenders without warningsv4 / mainnetjob green