Add Uniswap v3 and v4 on Monad#2812
Conversation
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughUniswap V3 adds Monad support, chunked token pricing, TVL filtering, and concurrent swap scanning. Uniswap V4 adds day-data processing, shared pool formatting, historical volume aggregation, and parallel standard/day-data processing. ChangesUniswap V3 onchain scanning
Uniswap V4 day-data processing
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)Uniswap V3 pool scansequenceDiagram
participant getPools
participant getPricesChunked
participant scanPool
getPools->>getPricesChunked: Fetch token prices in chunks
getPools->>scanPool: Scan priced pools concurrently
scanPool-->>getPools: Return USD fees, volume, and APY
Uniswap V4 day-data flowsequenceDiagram
participant main
participant topLvlDayData
participant Subgraph
participant formatPool
main->>topLvlDayData: Process day-data chains
topLvlDayData->>Subgraph: Fetch pools and poolDayDatas
Subgraph-->>topLvlDayData: Return TVL, metadata, and seven-day volumes
topLvlDayData->>formatPool: Build normalized APY and volume outputs
formatPool-->>main: Return formatted pools
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
The uniswap-v3 adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (3)
src/adaptors/uniswap-v3/onchain.js (3)
60-71: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick winChunks are fetched sequentially; consider parallelizing.
getPricesChunkedawaits each 100-token chunk in aforloop. For chains with many tokens (Monad's high pool-creation throughput makes this likely), fetching chunks withPromise.allwould meaningfully cut latency without changing the merge logic.♻️ Proposed refactor
const getPricesChunked = async (tokens, chain) => { - const pricesByAddress = {}; - const pricesBySymbol = {}; - - for (let start = 0; start < tokens.length; start += 100) { - const prices = await utils.getPrices(tokens.slice(start, start + 100), chain); - Object.assign(pricesByAddress, prices.pricesByAddress); - Object.assign(pricesBySymbol, prices.pricesBySymbol); - } - - return { pricesByAddress, pricesBySymbol }; + const chunks = []; + for (let start = 0; start < tokens.length; start += 100) { + chunks.push(tokens.slice(start, start + 100)); + } + const results = await Promise.all( + chunks.map((chunk) => utils.getPrices(chunk, chain)) + ); + return results.reduce( + (acc, prices) => ({ + pricesByAddress: { ...acc.pricesByAddress, ...prices.pricesByAddress }, + pricesBySymbol: { ...acc.pricesBySymbol, ...prices.pricesBySymbol }, + }), + { pricesByAddress: {}, pricesBySymbol: {} } + ); };🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/adaptors/uniswap-v3/onchain.js` around lines 60 - 71, Update getPricesChunked to initiate all 100-token utils.getPrices requests in parallel and await them with Promise.all, then merge each returned pricesByAddress and pricesBySymbol into the existing accumulators. Preserve the current chunking and returned object shape.
212-217: 🚀 Performance & Scalability | 🔵 Trivial | 💤 Low valueMinor:
scanQueue.shift()is O(n) per call.For very large pool counts this becomes O(n²) across all workers. An index-based cursor would avoid the repeated array re-indexing, though at typical pool counts this is unlikely to matter in practice.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/adaptors/uniswap-v3/onchain.js` around lines 212 - 217, Update the scanQueue consumption in runScanWorker to use a shared index-based cursor instead of scanQueue.shift(), incrementing the cursor as each worker claims a pool and preserving the existing scanPool and dataPools behavior.
28-58: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value
toUsdconversion logic is duplicated with thetvl0/tvl1calc below (lines ~160-167).Both places compute
amount * 10**(18-decimals) * price / 1e18. Extracting a single shared helper (e.g.toUsd(amount, token, tokenDecimals, prices)) would remove this duplication and reduce the risk of the two copies drifting.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@src/adaptors/uniswap-v3/onchain.js` around lines 28 - 58, The toUsd conversion logic is duplicated between sumSwapUsd and the tvl0/tvl1 calculation. Extract one shared helper using the existing amount, token, tokenDecimals, and prices inputs, then update both sumSwapUsd and the TVL calculation to reuse it while preserving the current conversion behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/adaptors/uniswap-v4/index.js`:
- Around line 204-214: Remove the hard-coded skip limit from both fetchers,
fetchLatestPools and the sibling day-volume helper. Continue requesting pages by
PAGE_SIZE until the returned batch is shorter than PAGE_SIZE or absent, so
complete pool and volume results are collected without truncation.
---
Nitpick comments:
In `@src/adaptors/uniswap-v3/onchain.js`:
- Around line 60-71: Update getPricesChunked to initiate all 100-token
utils.getPrices requests in parallel and await them with Promise.all, then merge
each returned pricesByAddress and pricesBySymbol into the existing accumulators.
Preserve the current chunking and returned object shape.
- Around line 212-217: Update the scanQueue consumption in runScanWorker to use
a shared index-based cursor instead of scanQueue.shift(), incrementing the
cursor as each worker claims a pool and preserving the existing scanPool and
dataPools behavior.
- Around line 28-58: The toUsd conversion logic is duplicated between sumSwapUsd
and the tvl0/tvl1 calculation. Extract one shared helper using the existing
amount, token, tokenDecimals, and prices inputs, then update both sumSwapUsd and
the TVL calculation to reuse it while preserving the current conversion
behavior.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 749b584c-b052-481b-8a08-8a288bd3987f
📒 Files selected for processing (3)
src/adaptors/uniswap-v3/index.jssrc/adaptors/uniswap-v3/onchain.jssrc/adaptors/uniswap-v4/index.js
0xkr3p
left a comment
There was a problem hiding this comment.
thanks for the PR @iamvukasin one minor comment to resolve pls
|
The uniswap-v3 adapter exports pools: Test Suites: 1 passed, 1 total |
|
The uniswap-v3 adapter exports pools: Test Suites: 1 passed, 1 total |
Summary by CodeRabbit
New Features
Bug Fixes / Improvements