Conversation
📝 WalkthroughWalkthroughThe pull request refactors YieldSeeker's TVL calculation by replacing a complex, per-chain agent analytics implementation with a simplified inline function that directly fetches agent data from a central API endpoint and aggregates token balances. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Poem
🚥 Pre-merge checks | ❌ 3❌ Failed checks (2 warnings, 1 inconclusive)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ 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 adapter at projects/yieldseeker exports TVL: |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@projects/yieldseeker/index.js`:
- Around line 12-15: The code currently assumes agentAnalytics from
getConfig('yieldseeker/yield-agents/', API_URL) is an array, but the
destructuring default only covers undefined and will crash if the API returns a
truthy non-array object; after retrieving the config (via getConfig) normalize
agentAnalytics with Array.isArray and fallback to [] before the for...of loop
(e.g., compute a safeAgentAnalytics = Array.isArray(agentAnalytics) ?
agentAnalytics : [] and iterate safeAgentAnalytics) so the loop in the
agentAnalytics handling code is protected against schema drift.
- Around line 14-21: The loop that builds ownerTokens (iterating agentAnalytics
and using normalizeToken, agent.snapshot.tokenBalances) must convert
ERC4626/vault share tokens to their underlying asset amounts before calling
api.sumTokens so we preserve the old yieldAgentsTvl behavior; update the
ownerTokens population to detect vault/share tokens (use or add a helper like
unwrapVaultShares or vaultUnderlyingRate) and for each share token replace it
with the underlying token and convert the share balance to the underlying amount
(or accumulate the underlying amount) before pushing into ownerTokens, then call
api.sumTokens({ ownerTokens, permitFailure: true }) as before.
🪄 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: 0920e707-00aa-46ed-8d18-da27d82939f0
📒 Files selected for processing (2)
projects/yieldseeker/index.jsprojects/yieldseeker/yieldAgents.js
💤 Files with no reviewable changes (1)
- projects/yieldseeker/yieldAgents.js
| const { agentAnalytics = [] } = await getConfig('yieldseeker/yield-agents/', API_URL); | ||
| const ownerTokens = []; | ||
| for (const agent of agentAnalytics) { | ||
| if (!agent?.snapshot?.tokenBalances || typeof agent.snapshot.tokenBalances !== 'object') continue; |
There was a problem hiding this comment.
Harden agentAnalytics before iterating it.
getConfig() can fall back to cached payloads on fetch errors, and the destructuring default here only handles undefined. If the API/cache returns a truthy non-array shape, Line 14 will throw on for...of and take the adapter down. Normalizing with Array.isArray avoids a hard failure on schema drift.
Suggested guard
async function tvl(api) {
- const { agentAnalytics = [] } = await getConfig('yieldseeker/yield-agents/', API_URL);
+ const response = await getConfig('yieldseeker/yield-agents/', API_URL);
+ const agentAnalytics = Array.isArray(response?.agentAnalytics) ? response.agentAnalytics : [];
const ownerTokens = [];📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const { agentAnalytics = [] } = await getConfig('yieldseeker/yield-agents/', API_URL); | |
| const ownerTokens = []; | |
| for (const agent of agentAnalytics) { | |
| if (!agent?.snapshot?.tokenBalances || typeof agent.snapshot.tokenBalances !== 'object') continue; | |
| const response = await getConfig('yieldseeker/yield-agents/', API_URL); | |
| const agentAnalytics = Array.isArray(response?.agentAnalytics) ? response.agentAnalytics : []; | |
| const ownerTokens = []; | |
| for (const agent of agentAnalytics) { | |
| if (!agent?.snapshot?.tokenBalances || typeof agent.snapshot.tokenBalances !== 'object') continue; |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@projects/yieldseeker/index.js` around lines 12 - 15, The code currently
assumes agentAnalytics from getConfig('yieldseeker/yield-agents/', API_URL) is
an array, but the destructuring default only covers undefined and will crash if
the API returns a truthy non-array object; after retrieving the config (via
getConfig) normalize agentAnalytics with Array.isArray and fallback to [] before
the for...of loop (e.g., compute a safeAgentAnalytics =
Array.isArray(agentAnalytics) ? agentAnalytics : [] and iterate
safeAgentAnalytics) so the loop in the agentAnalytics handling code is protected
against schema drift.
| for (const agent of agentAnalytics) { | ||
| if (!agent?.snapshot?.tokenBalances || typeof agent.snapshot.tokenBalances !== 'object') continue; | ||
| const tokens = Object.keys(agent.snapshot.tokenBalances).map(normalizeToken); | ||
| if (tokens.length > 0) { | ||
| ownerTokens.push([tokens, agent.agentWalletAddress]); | ||
| } | ||
| } | ||
| await api.sumTokens({ ownerTokens, permitFailure: true }); |
There was a problem hiding this comment.
Restore the share-to-underlying conversion that was removed here.
This inline replacement no longer preserves the old yieldAgentsTvl behavior that unwrapped ERC4626/vault balances before aggregation. Now any agent wallet holding receipt/share tokens is counted as the share token itself via api.sumTokens, which can materially skew TVL versus the previous adapter output. Please keep the old unwrapping path or inline equivalent share→asset conversion before summing.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@projects/yieldseeker/index.js` around lines 14 - 21, The loop that builds
ownerTokens (iterating agentAnalytics and using normalizeToken,
agent.snapshot.tokenBalances) must convert ERC4626/vault share tokens to their
underlying asset amounts before calling api.sumTokens so we preserve the old
yieldAgentsTvl behavior; update the ownerTokens population to detect vault/share
tokens (use or add a helper like unwrapVaultShares or vaultUnderlyingRate) and
for each share token replace it with the underlying token and convert the share
balance to the underlying amount (or accumulate the underlying amount) before
pushing into ownerTokens, then call api.sumTokens({ ownerTokens, permitFailure:
true }) as before.
Summary by CodeRabbit