Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 23 additions & 5 deletions projects/yieldseeker/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,29 @@
const { yieldAgentsTvl } = require('./yieldAgents');
const { getConfig } = require('../helper/cache');
const ADDRESSES = require('../helper/coreAssets.json');

const API_URL = 'https://api.yieldseeker.xyz/v1/agent-analytics';

function normalizeToken(token) {
if (token.toLowerCase() === ADDRESSES.GAS_TOKEN_2) return ADDRESSES.null;
return token.toLowerCase();
}

async function tvl(api) {
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;
Comment on lines +12 to +15
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.

const tokens = Object.keys(agent.snapshot.tokenBalances).map(normalizeToken);
if (tokens.length > 0) {
ownerTokens.push([tokens, agent.agentWalletAddress]);
}
}
await api.sumTokens({ ownerTokens, permitFailure: true });
Comment on lines +14 to +21
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.

}

module.exports = {
methodology: 'Counts the tokens held across all YieldSeeker agent wallets. Wallet addresses are obtained from the YieldSeeker API, and token balances are read on-chain.',
// NOTE(krishan711): Can't time travel yet cos the agent list is obtained via API. re-enable once agent list is enumerable onchain
timetravel: false,
doublecounted: true,
base: {
tvl: yieldAgentsTvl,
},
base: { tvl },
};
127 changes: 0 additions & 127 deletions projects/yieldseeker/yieldAgents.js

This file was deleted.

Loading