Skip to content
Open
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
51 changes: 51 additions & 0 deletions projects/anoncoin/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { sumTokens2 } = require("../helper/solana");
const { get } = require("../helper/http");
const { sleep } = require("../helper/utils");

const API_BASE = "https://api.dubdub.tv/v1/defillama/tvl";
const MAX_PAGES = 1000;

async function fetchAllVaults() {
const solOwnersSet = new Set();
let page = 1;
let hasMore = true;

while (hasMore) {
if (page > MAX_PAGES) {
console.error(`anoncoin: exceeded MAX_PAGES (${MAX_PAGES}), stopping pagination`);
break;
}
Comment on lines +13 to +17
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

Avoid using partial owner lists when pagination is truncated.

Line 17 stops pagination with break, but Line 49 still uses partial solOwners. This can silently undercount TVL whenever MAX_PAGES is hit. Prefer cached full data when fullFetchCompleted is false (fallback to partial only if cache is unavailable).

Proposed fix
 async function tvl() {
     let solOwners;
     try {
-        const result = await fetchAllVaults();
-        solOwners = result.solOwners;
-        if (result.fullFetchCompleted) {
-            await setCache(CACHE_KEY, "solana", solOwners);
-        }
+        const result = await fetchAllVaults();
+        if (result.fullFetchCompleted) {
+            solOwners = result.solOwners;
+            await setCache(CACHE_KEY, "solana", solOwners);
+        } else {
+            const cached = await getCache(CACHE_KEY, "solana");
+            solOwners = Array.isArray(cached) && cached.length ? cached : result.solOwners;
+        }
     } catch (e) {
         console.error("anoncoin: API fetch failed, falling back to cache", e.message);
         const cached = await getCache(CACHE_KEY, "solana");
         solOwners = Array.isArray(cached) ? cached : [];
     }

     return sumTokens2({ solOwners });
 }

Also applies to: 47-51

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@projects/anoncoin/index.js` around lines 16 - 20, The loop truncates
pagination when page > MAX_PAGES but then proceeds to use the partial solOwners
list, which can undercount TVL; modify the pagination/aggregation logic (around
hasMore, page, MAX_PAGES) so that when you hit the MAX_PAGES cutoff you set
fullFetchCompleted = false (or a similar flag) and do not use the partial
solOwners for final TVL calculations; instead attempt to load and use a cached
full result (fallback to the partial solOwners only if no cache is available),
and ensure any code that consumes solOwners checks fullFetchCompleted before
relying on it.


const { data } = await get(`${API_BASE}?page=${page}`);
const pools = data.pools || [];

for (const pool of pools) {
if (pool.isMigrated && pool.dammV2QuoteVault) {
solOwnersSet.add(pool.dammV2QuoteVault);
} else if (pool.quoteVault) {
solOwnersSet.add(pool.quoteVault);
}
}

hasMore = data.hasMore === true;
page++;

if (hasMore) await sleep(200);
}

return { solOwners: [...solOwnersSet] };
}

async function tvl() {
const { solOwners } = await fetchAllVaults();
return sumTokens2({ solOwners });
}

module.exports = {
timetravel: false,
methodology:
"TVL is calculated by summing the SOL held in all Anoncoin pool quote vaults (DBC and DAMM v2) on Solana. Only pools with TVL > 0 are included.",
solana: {
tvl,
},
};
Loading