fix: d2-finance adapter (dead subgraph, stale vault list)#2786
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughThe D2 Finance adaptor now supports configured vaults across multiple chains, resolves ERC-4626 asset metadata through multicalls, calculates TVL and APY from current and historical conversions, aggregates valid pools, and removes the adaptor from the hardcoded exclusion list. ChangesD2 Finance multi-chain adaptor
Estimated code review effort: 4 (Complex) | ~45 minutes Sequence Diagram(s)sequenceDiagram
participant poolsFunction
participant chainPools
participant multicall
participant ERC20PriceLookup
participant getBlocksByTime
poolsFunction->>chainPools: process configured chains and vault lists
chainPools->>multicall: read totalAssets, asset, symbol, and decimals
chainPools->>ERC20PriceLookup: fetch prices for resolved assets
chainPools->>getBlocksByTime: resolve historical block from LOOKBACK_DAYS
chainPools->>multicall: call convertToAssets at current and historical blocks
chainPools-->>poolsFunction: return calculated pool metrics
poolsFunction-->>poolsFunction: flatten results and keep finite entries
Suggested reviewers: 🚥 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 d2-finance adapter exports pools: Test Suites: 1 passed, 1 total |
| // oldest window in which the vault already existed | ||
| let apyBase = 0; | ||
| const priceNow = Number(ppsNow.output[i].output); | ||
| for (const [w, days] of LOOKBACK_DAYS.map((d, j) => [j, d])) { |
There was a problem hiding this comment.
We stick to shorter windows, between 24-7d is ideal but stretch to 30d in some cases. Also we stick to one time window for consistency. Pls see results from using 7d or if not then 30d max
There was a problem hiding this comment.
switched to a single 30d window. tried 7d first like you said but these are epoch vaults that only settle ~monthly, so a 7d lookback lands in the flat stretch between settlements and reads back near-zero for most of them. 30d lines up with one settlement cycle and gives real numbers, and it's within the 30d cap. done
| apy, | ||
| apyBase, | ||
| poolMeta: | ||
| "Strategy's lock duration is aligned with market opportunities, verifable onchain.", |
There was a problem hiding this comment.
can we remove this pool meta pls
| poolMeta: | ||
| "Strategy's lock duration is aligned with market opportunities, verifable onchain.", | ||
| underlyingTokens: [underlyingAsset], | ||
| underlyingTokens: [asset], |
There was a problem hiding this comment.
added, it's convertToAssets(1 share) normalised by the asset decimals
|
The d2-finance adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/d2-finance/index.js`:
- Around line 139-146: Update the APY calculation near rawNow, rawThen, and
apyBase to detect non-finite converted values, including missing historical
ppsThen data, before calculating or returning APY. When either value is
unavailable, reject the pool or assign the established explicit unavailable
value; do not emit 0% APY. Preserve the existing calculation for finite positive
values.
- Around line 163-166: Update the aggregation around chainPools to use
Promise.allSettled instead of Promise.all, preserving fulfilled results while
isolating rejected chains. Report each rejected chain with its chain identifier
and error, then flatten only the successful results without discarding other
chains.
🪄 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: 4fc381fe-bce1-474d-a139-7808c35a74e0
📒 Files selected for processing (2)
src/adaptors/d2-finance/index.jssrc/utils/exclude.js
💤 Files with no reviewable changes (1)
- src/utils/exclude.js
|
hi @0xshubhs thanks for fast changes, can you take a look at both code rabbit issues pls we should only set apy as 0 if it's genuinely 0 otherwise it can skew avgs over time - thanks |
|
The d2-finance adapter exports pools: Test Suites: 1 passed, 1 total |
|
@coderabbitai review |
✅ Action performedReview finished.
|
| underlyingTokens: [underlyingAsset], | ||
| apyBase, | ||
| underlyingTokens: [asset], | ||
| pricePerShare, |
There was a problem hiding this comment.
added - each pool now links to its vault at d2.finance/strategies/
|
The d2-finance adapter exports pools: Test Suites: 1 passed, 1 total |
|
Always ser @0xkr3p |
Problem
The d2-finance adapter is broken and currently sits in the exclusion list:
https://d2.finance/subgraphs/name/d2, is behind a Cloudflare managed challenge and returns 403 to any non-browser client.Change
Rewrote the adapter to be fully on-chain, no subgraph:
d2financeTVL adapter (41 ERC4626 vaults across ethereum/base/arbitrum/berachain/hyperliquid).totalAssets()priced via the coins API.apyBaseis the trailingconvertToAssets(1 share)change, annualized over the longest lookback window the vault has existed for (365d, then 180/90/30d for younger vaults), with historical values read at the corresponding block heights.<vault>-<chain>format so existing Arbitrum pool history continues.Test
npm run test --adapter=d2-financepasses (245 tests), returning 40 pools, total$27.8M matching the protocol page ($27.9M). Top pools:Summary by CodeRabbit
New Features
Improvements
Bug Fixes