Skip to content

fix yieldseeker#18717

Open
RohanNero wants to merge 2 commits intoDefiLlama:mainfrom
RohanNero:yieldseeker-fix
Open

fix yieldseeker#18717
RohanNero wants to merge 2 commits intoDefiLlama:mainfrom
RohanNero:yieldseeker-fix

Conversation

@RohanNero
Copy link
Copy Markdown
Contributor

@RohanNero RohanNero commented Apr 10, 2026

Summary by CodeRabbit

  • Refactor
    • Streamlined TVL calculation logic for YieldSeeker agent analytics by consolidating implementation and removing ERC4626 vault share conversion. TVL calculations now directly aggregate token balances from agent snapshots without intermediate vault handling conversions.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 10, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Simplified TVL Implementation
projects/yieldseeker/index.js
Replaced imported yieldAgentsTvl with inline tvl(api) function. New implementation fetches agent analytics from https://api.yieldseeker.xyz/v1/agent-analytics, normalizes token addresses (lowercasing, remapping GAS_TOKEN_2), and calls api.sumTokens() to aggregate balances.
Deleted Complex Agent Logic
projects/yieldseeker/yieldAgents.js
Removed yieldAgentsTvl(api) which handled per-chain agent analytics loading, ERC4626 vault share-to-underlying conversions, and multicall operations for fetching vault metadata.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

🐰 A seeker once sought through chains with care,
With vaults and shares floating everywhere.
But wisdom arose with a cleaner way—
One API call to fetch yields today!
Simpler paths lead to harvest so fair. 🌾✨

🚥 Pre-merge checks | ❌ 3

❌ Failed checks (2 warnings, 1 inconclusive)

Check name Status Explanation Resolution
Description check ⚠️ Warning No pull request description was provided by the author, making it impossible to assess compliance with the repository's description template. Add a pull request description explaining the changes made, the motivation for refactoring the TVL logic, and any impacts on existing functionality.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'fix yieldseeker' is vague and generic, using a non-descriptive term 'fix' that doesn't convey meaningful information about the specific changes made. Use a more descriptive title that explains the specific change, such as 'Inline YieldSeeker TVL calculation and remove yieldAgents module' or 'Refactor YieldSeeker TVL implementation'.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@llamabutler
Copy link
Copy Markdown

The adapter at projects/yieldseeker exports TVL:

base                      1.29 M

total                    1.29 M 

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between 93edba3 and fdbba4b.

📒 Files selected for processing (2)
  • projects/yieldseeker/index.js
  • projects/yieldseeker/yieldAgents.js
💤 Files with no reviewable changes (1)
  • projects/yieldseeker/yieldAgents.js

Comment on lines +12 to +15
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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

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.

Suggested change
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.

Comment on lines +14 to +21
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 });
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

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.

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.

2 participants