Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughAdds a new Solana TVL adapter for Anoncoin that paginates a DefiLlama-compatible API to collect and deduplicate pool quote-vault addresses (preferring migrated Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller
participant Cache as Cache Layer
participant Adapter as Anoncoin Adapter
participant API as DubDub API
participant Solana as Solana Chain
Caller->>Adapter: tvl()
Adapter->>Cache: getCache("anoncoin-vaults","solana")
alt Cache hit & valid array
Cache-->>Adapter: solOwners[]
else Cache miss or invalid
Adapter->>API: GET /v1/defillama/tvl?page=1
loop while hasMore and page <= MAX_PAGES
API-->>Adapter: pools[], hasMore
Adapter->>Adapter: choose dammV2QuoteVault if migrated else quoteVault
Adapter->>Adapter: add address to Set (dedupe)
alt hasMore and page < MAX_PAGES
Adapter->>Adapter: sleep(200)
Adapter->>API: GET /v1/defillama/tvl?page=N+1
else hasMore but page >= MAX_PAGES
Adapter-->>Adapter: mark incomplete, stop
end
end
Adapter->>Cache: setCache("anoncoin-vaults", solOwners, "solana") /* if fullFetchCompleted */
end
Adapter->>Solana: sumTokens2({ solOwners })
Solana-->>Adapter: TVL
Adapter-->>Caller: TVL
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ 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 |
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/anoncoin/index.js`:
- Around line 36-41: The current cache usage with getCache(CACHE_KEY, "solana")
only refetches when empty, so new vaults are never discovered; modify the logic
around getCache/setCache (and the CACHE_KEY/solOwners flow) to respect a TTL:
when setting the cache via setCache(CACHE_KEY, "solana", solOwners) also store a
timestamp or expiration, and when calling getCache check that timestamp (or
returned meta) against a configured TTL (e.g., CACHE_TTL_MS) and force solOwners
= await fetchAllVaults() and update setCache when the cache is stale; ensure you
reference getCache, setCache, CACHE_KEY and fetchAllVaults so the refetch
happens both when cache is missing and when its age exceeds the TTL.
- Around line 14-30: The pagination while loop using hasMore and page can run
indefinitely; introduce a MAX_PAGES constant (e.g., MAX_PAGES = 1000) and
enforce it inside the loop that calls get(`${API_BASE}?page=${page}`) and sleep:
if page exceeds MAX_PAGES, break/throw or log an error and stop paging to fail
safely; update the loop around hasMore/page so functions like get, API_BASE,
sleep, and solOwnersSet remain unchanged but the loop exits when page >
MAX_PAGES (or similar) to prevent unbounded looping.
🪄 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: 4c620a1e-2365-406a-a328-5a20226e5e79
📒 Files selected for processing (1)
projects/anoncoin/index.js
db11541 to
8529e26
Compare
There was a problem hiding this comment.
♻️ Duplicate comments (1)
projects/anoncoin/index.js (1)
16-19:⚠️ Potential issue | 🟠 MajorAvoid caching partial data when pagination cap is exceeded.
At Line 16 the code stops pagination with
break, then Line 44-46 caches the partialsolOwnerslist as fresh truth. If the API misbehaves, this silently undercounts TVL and persists the undercount in cache.Suggested fix
- if (page > MAX_PAGES) { - console.error(`anoncoin: exceeded MAX_PAGES (${MAX_PAGES}), stopping pagination`); - break; - } + if (page > MAX_PAGES) { + throw new Error(`anoncoin: exceeded MAX_PAGES (${MAX_PAGES})`); + }Also applies to: 44-46
🤖 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 - 19, The code currently breaks out when page > MAX_PAGES but then proceeds to cache the partially-collected solOwners; change the flow so partial results are never written to cache: add a boolean flag (e.g., fullFetchCompleted) that is false by default, set it to true only when the pagination loop completes normally (not when broken due to MAX_PAGES), and wrap the existing cache write logic (the lines that persist solOwners) so it only runs if fullFetchCompleted is true; alternatively, when the MAX_PAGES cap is hit, throw or return an error/empty result instead of allowing the caching path to run. Ensure references to solOwners, MAX_PAGES and the cache write code are updated accordingly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@projects/anoncoin/index.js`:
- Around line 16-19: The code currently breaks out when page > MAX_PAGES but
then proceeds to cache the partially-collected solOwners; change the flow so
partial results are never written to cache: add a boolean flag (e.g.,
fullFetchCompleted) that is false by default, set it to true only when the
pagination loop completes normally (not when broken due to MAX_PAGES), and wrap
the existing cache write logic (the lines that persist solOwners) so it only
runs if fullFetchCompleted is true; alternatively, when the MAX_PAGES cap is
hit, throw or return an error/empty result instead of allowing the caching path
to run. Ensure references to solOwners, MAX_PAGES and the cache write code are
updated accordingly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: eab7ec87-6c25-438f-88a9-fb7808e9c6ce
📒 Files selected for processing (1)
projects/anoncoin/index.js
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 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/anoncoin/index.js`:
- Around line 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.
🪄 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: ea91a0c7-f566-4984-8fc5-ad6d45ee4eb5
📒 Files selected for processing (1)
projects/anoncoin/index.js
| while (hasMore) { | ||
| if (page > MAX_PAGES) { | ||
| console.error(`anoncoin: exceeded MAX_PAGES (${MAX_PAGES}), stopping pagination`); | ||
| break; | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
♻️ Duplicate comments (1)
projects/anoncoin/index.js (1)
13-17:⚠️ Potential issue | 🟠 MajorFail fast when pagination is truncated; current flow can silently undercount TVL.
At Line 16, hitting
MAX_PAGESexits the loop but still returns partialsolOwners(Line 36), and Line 40 then prices that partial set. This should error out (or use a known-complete fallback), not publish partial TVL.Suggested fix
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; - } + while (hasMore && page <= MAX_PAGES) { const { data } = await get(`${API_BASE}?page=${page}`); const pools = data.pools || []; @@ if (hasMore) await sleep(200); } + if (hasMore) { + throw new Error(`anoncoin: pagination exceeded MAX_PAGES (${MAX_PAGES})`); + } + return { solOwners: [...solOwnersSet] }; }Also applies to: 36-41
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@projects/anoncoin/index.js` around lines 13 - 17, The loop that pages owner data uses hasMore and breaks when page > MAX_PAGES, which allows the function to continue and price a truncated solOwners set; change the behavior so hitting MAX_PAGES signals failure instead of breaking: in the pagination loop (referencing hasMore, MAX_PAGES and solOwners) replace the break with throwing an Error (or returning a specific failure result) so the function does not proceed to the pricing/TVL calculation on partial data; ensure any callers handle the thrown error or failure result to avoid publishing partial TVL.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Duplicate comments:
In `@projects/anoncoin/index.js`:
- Around line 13-17: The loop that pages owner data uses hasMore and breaks when
page > MAX_PAGES, which allows the function to continue and price a truncated
solOwners set; change the behavior so hitting MAX_PAGES signals failure instead
of breaking: in the pagination loop (referencing hasMore, MAX_PAGES and
solOwners) replace the break with throwing an Error (or returning a specific
failure result) so the function does not proceed to the pricing/TVL calculation
on partial data; ensure any callers handle the thrown error or failure result to
avoid publishing partial TVL.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 69e4e0fb-03c0-4d61-96da-8db55196f978
📒 Files selected for processing (1)
projects/anoncoin/index.js
Anoncoin (Solana)
Protocol: anoncoin.it
Category: Liquidity / Bonding Curve
What does the adapter do?
Calculates TVL by summing SOL held across all Anoncoin pool quote vaults on Solana — both DBC (Dynamic Bonding Curve) and DAMM v2 (migrated) pools.
How it works
api.dubdub.tv/v1/defillama/tvl)sumTokens2helper to read on-chain SOL balancesgetCache/setCacheDetails
sumTokens2,getCache,setCache,get,sleep)Summary by CodeRabbit