-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Add Anoncoin adapter #18718
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
akhil-onjuno
wants to merge
4
commits into
DefiLlama:main
Choose a base branch
from
akhil-onjuno:add-anoncoin
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+51
−0
Open
Add Anoncoin adapter #18718
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
852ac3b
Add Anoncoin adapter (Solana TVL)
akhil-onjuno 8529e26
Simplify cache: always fetch fresh, fallback on error; add MAX_PAGES …
akhil-onjuno 95d3923
Prevent partial results from overwriting cache on MAX_PAGES hit
akhil-onjuno 4433354
Simplify adapter: remove cache, direct fetch and sum
akhil-onjuno File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
|
|
||
| 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); | ||
| } | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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, | ||
| }, | ||
| }; | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid using partial owner lists when pagination is truncated.
Line 17 stops pagination with
break, but Line 49 still uses partialsolOwners. This can silently undercount TVL wheneverMAX_PAGESis hit. Prefer cached full data whenfullFetchCompletedis 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