Skip to content

✨ Add DeFindex protocol adaptor#2479

Open
MattPoblete wants to merge 2 commits intoDefiLlama:masterfrom
paltalabs:feat/defindex-adaptor
Open

✨ Add DeFindex protocol adaptor#2479
MattPoblete wants to merge 2 commits intoDefiLlama:masterfrom
paltalabs:feat/defindex-adaptor

Conversation

@MattPoblete
Copy link
Copy Markdown

@MattPoblete MattPoblete commented Mar 13, 2026

Summary

  • Adds yield adaptor for DeFindex, a yield aggregator built on Stellar
  • Fetches vault data from the DeFindex API (/vault/discover?network=mainnet)
  • Computes TVL in USD using DefiLlama's coin price API for Stellar assets
  • Returns APY, TVL, underlying tokens, and pool metadata per vault

Test plan

  • Run npm run test --adapter=defindex and verify vault data is returned
  • Confirm tvlUsd and apyBase are non-zero for active vaults
  • Confirm chain is "Stellar" and pool IDs are unique

Summary by CodeRabbit

  • New Features
    • Added support for Stellar DeFi Defindex vaults—users can now view vault APY, underlying assets (symbols), and TVL (USD) with links to vault details.

Add yield adaptor for DeFindex protocol to retrieve APY and TVL data.
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 13, 2026

📝 Walkthrough

Walkthrough

Adds a new Defindex Stellar adaptor exporting timetravel, apy, and url; it fetches vault discovery data, filters vaults by APY and managed funds, resolves asset prices via coins.llama.fi, and computes per-vault TVL and metadata.

Changes

Cohort / File(s) Summary
Defindex Stellar Adaptor
src/adaptors/defindex/index.js
New adaptor file exporting timetravel: false, apy() and url. Implements vault discovery fetch from Defindex API, filters vaults (non-null APY, non-empty totalManagedFunds), resolves stellar:<asset> prices and token metadata from coins.llama.fi, computes tvlUsd, builds symbol, underlyingTokens, and returns normalized vault objects with pool, chain, project, apyBase, and url.

Sequence Diagram(s)

sequenceDiagram
    actor Caller
    participant Adaptor as Defindex Adaptor
    participant DefindexAPI as Defindex API
    participant PricingAPI as coins.llama.fi

    Caller->>Adaptor: apy()
    Adaptor->>DefindexAPI: GET /vaults/discovery (Stellar mainnet)
    DefindexAPI-->>Adaptor: vault list (apy, assets, funds)
    Adaptor->>Adaptor: filter vaults (apy != null, funds not empty)
    Adaptor->>PricingAPI: GET prices for keys `stellar:<asset>`...
    PricingAPI-->>Adaptor: prices, symbols, decimals
    Adaptor->>Adaptor: compute tvlUsd per vault (amount/decimals * price)
    Adaptor-->>Caller: array of vault objects with tvlUsd, apyBase, symbols, pool, url
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hopped to fetch each Stellar vault so bright,
Prices gathered, amounts summed just right,
Symbols twined and TVLs sung true,
A tiny adaptor, bringing clarity anew! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
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.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main change: adding a new DeFindex protocol adaptor to the codebase.

✏️ 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.

@MattPoblete MattPoblete marked this pull request as ready for review March 25, 2026 17:08
Copilot AI review requested due to automatic review settings March 25, 2026 17:08
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds a new yield adapter for the DeFindex protocol on Stellar, fetching vault discovery data from DeFindex’s API and enriching it with USD TVL from DefiLlama coin prices.

Changes:

  • Added a new defindex adapter that pulls vaults from /vault/discover?network=mainnet.
  • Added DefiLlama coin-price lookup for Stellar assets and computes tvlUsd.
  • Returns per-vault pool objects including apyBase, tvlUsd, underlyingTokens, and metadata.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

module.exports = {
timetravel: false,
apy,
url: API_BASE_URL,
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

module.exports.url is a URL object here, but the adapter test harness expects module.url (and/or apy[0].url) to be a string (see src/adaptors/test.js), so this will fail the "link to the pool's page" type check. Export a string URL instead (e.g., API_BASE_URL.toString()/.href, or define API_BASE_URL as a string).

Suggested change
url: API_BASE_URL,
url: API_BASE_URL.toString(),

Copilot uses AI. Check for mistakes.
tvlUsd,
apyBase: vault.apy,
underlyingTokens,
url: `${API_BASE_URL}/vault/${vault.address}`,
Copy link

Copilot AI Mar 25, 2026

Choose a reason for hiding this comment

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

This URL construction will produce a double slash because API_BASE_URL includes a trailing / and the template literal adds another / (e.g. https://api.defindex.io//vault/...). Build the URL without introducing // (e.g., remove the extra / or use new URL('vault/' + vault.address, API_BASE_URL)).

Suggested change
url: `${API_BASE_URL}/vault/${vault.address}`,
url: `${API_BASE_URL}vault/${vault.address}`,

Copilot uses AI. Check for mistakes.
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

🧹 Nitpick comments (1)
src/adaptors/defindex/index.js (1)

32-36: Hardcoded decimals assumption for all Stellar assets.

Using STELLAR_DECIMALS = 7 for all assets is standard for native Stellar assets (stroops), but custom tokens could potentially have different precision. The DefiLlama price API returns a decimals field per coin that's currently being discarded in fetchCoinData.

If all DeFindex vaults only hold standard Stellar assets, this is fine. Otherwise, consider capturing and using the decimals from the price API response.

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

In `@src/adaptors/defindex/index.js` around lines 32 - 36, The TVL calculation
currently assumes a fixed STELLAR_DECIMALS when converting fund.total_amount to
human units; update the logic in the tvlUsd calculation to read a per-asset
decimals value from coinData (the decimals field returned by fetchCoinData) and
use that for the divisor (i.e., divide by 10 ** decimals), falling back to
STELLAR_DECIMALS if decimals is missing; also ensure fetchCoinData stores the
decimals for each coin so tvlUsd (and any other uses) can look up
coinData[asset].decimals instead of always using STELLAR_DECIMALS; reference
tvlUsd, vault.totalManagedFunds, coinData, and fetchCoinData when making the
change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/adaptors/defindex/index.js`:
- Line 50: The generated URL has a double slash because API_BASE_URL already
ends with '/' and the request builds `${API_BASE_URL}/vault/${vault.address}`;
fix by removing the extra slash when composing the URL (e.g., build it as
`${API_BASE_URL}vault/${vault.address}`) or normalize API_BASE_URL by trimming
its trailing slash before use so that the call that uses API_BASE_URL and
vault.address produces a single slash.
- Around line 55-59: The module currently exports url: API_BASE_URL which is a
URL object; change the export to a plain string so consumers can perform string
operations—replace the exported value in module.exports (the url property) with
a string version of API_BASE_URL (e.g., API_BASE_URL.toString() or
API_BASE_URL.href or the literal URL string) while leaving apy and timetravel
unchanged.

---

Nitpick comments:
In `@src/adaptors/defindex/index.js`:
- Around line 32-36: The TVL calculation currently assumes a fixed
STELLAR_DECIMALS when converting fund.total_amount to human units; update the
logic in the tvlUsd calculation to read a per-asset decimals value from coinData
(the decimals field returned by fetchCoinData) and use that for the divisor
(i.e., divide by 10 ** decimals), falling back to STELLAR_DECIMALS if decimals
is missing; also ensure fetchCoinData stores the decimals for each coin so
tvlUsd (and any other uses) can look up coinData[asset].decimals instead of
always using STELLAR_DECIMALS; reference tvlUsd, vault.totalManagedFunds,
coinData, and fetchCoinData when making the change.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 3c3760ba-8b70-4ee8-897c-a8e351277c19

📥 Commits

Reviewing files that changed from the base of the PR and between 2174e93 and 71bb2de.

📒 Files selected for processing (1)
  • src/adaptors/defindex/index.js

- Convert API_BASE_URL from URL object to plain string to fix double-slash
  in vault URLs and ensure module.exports.url is a string
- Store per-asset decimals from coins API response and use them in TVL
  calculation instead of always assuming STELLAR_DECIMALS=7
@llamatester
Copy link
Copy Markdown

The defindex adapter exports pools:

Test Suites: 1 passed, 1 total
Tests: 58 passed, 58 total
Snapshots: 0 total
Time: 0.254 s
Ran all test suites.

Nb of pools: 9
 

Sample pools:
┌─────────┬────────────────────────────────────────────────────────────────────┬───────────┬────────────┬──────────┬────────────────────┬─────────┬────────────────────────────────────────────────────────────────┬──────────────────────────────────────────────────────────────────────────────────────────┐
│ (index) │ pool                                                               │ chain     │ project    │ symbol   │ tvlUsd             │ apyBase │ underlyingTokens                                               │ url                                                                                      │
├─────────┼────────────────────────────────────────────────────────────────────┼───────────┼────────────┼──────────┼────────────────────┼─────────┼────────────────────────────────────────────────────────────────┼──────────────────────────────────────────────────────────────────────────────────────────┤
│ 0       │ 'cbnkcu3hgfkhfof7jtgxqcnke3g3dxs5rdbqukqmiiecykxpiougb2s3-stellar' │ 'Stellar' │ 'defindex' │ 'USDC'   │ 731672.8858105234  │ 8.67    │ [ 'CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75' ] │ 'https://api.defindex.io/vault/CBNKCU3HGFKHFOF7JTGXQCNKE3G3DXS5RDBQUKQMIIECYKXPIOUGB2S3' │
│ 1       │ 'caiz3nmnpen5sqisjv7pd2yy6ni6dipfa4pcrubogde4i7a3dxdlk5oi-stellar' │ 'Stellar' │ 'defindex' │ 'EURC'   │ 181399.8105684247  │ 8.84    │ [ 'CDTKPWPLOURQA2SGTKTUQOWRCBZEORB4BWBOMJ3D3ZTQQSGE5F6JBQLV' ] │ 'https://api.defindex.io/vault/CAIZ3NMNPEN5SQISJV7PD2YY6NI6DIPFA4PCRUBOGDE4I7A3DXDLK5OI' │
│ 2       │ 'ca2fipj7u6bg3n7eozfi74xpjzoeod4tywxfvcio5vdchtvags6f4ukk-stellar' │ 'Stellar' │ 'defindex' │ 'USDC'   │ 91272.0624143639   │ 7.63    │ [ 'CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75' ] │ 'https://api.defindex.io/vault/CA2FIPJ7U6BG3N7EOZFI74XPJZOEOD4TYWXFVCIO5VDCHTVAGS6F4UKK' │
│ 3       │ 'cbujzl5qad5topd7jmcbq3rhr6rzwy34a4qf7uhiltdh2jf2z3vjgy2y-stellar' │ 'Stellar' │ 'defindex' │ 'USDC'   │ 23665.631912939858 │ 7.65    │ [ 'CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75' ] │ 'https://api.defindex.io/vault/CBUJZL5QAD5TOPD7JMCBQ3RHR6RZWY34A4QF7UHILTDH2JF2Z3VJGY2Y' │
│ 4       │ 'ccdrfmz7ch364atq5ysvtej3g3kpnfvm6ttc6n4t5rehwjs6lgvfp7my-stellar' │ 'Stellar' │ 'defindex' │ 'USDC'   │ 16411.269987528747 │ 7.45    │ [ 'CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75' ] │ 'https://api.defindex.io/vault/CCDRFMZ7CH364ATQ5YSVTEJ3G3KPNFVM6TTC6N4T5REHWJS6LGVFP7MY' │
│ 5       │ 'cc767wiu5qgjmxyhddyjajef2ywphoxozdwd3uuazvs4kqprxckpt2yz-stellar' │ 'Stellar' │ 'defindex' │ 'USDC'   │ 10326.144070762239 │ 7.4     │ [ 'CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75' ] │ 'https://api.defindex.io/vault/CC767WIU5QGJMXYHDDYJAJEF2YWPHOXOZDWD3UUAZVS4KQPRXCKPT2YZ' │
│ 6       │ 'cd4jgs6bb5nzvsnkrni43guc6e3obylclbqzjvtzldvhq5kdaohvoiqf-stellar' │ 'Stellar' │ 'defindex' │ 'USDC'   │ 4180.5243064249635 │ -50.35  │ [ 'CCW67TSZV3SSS2HXMBQ5JFGCKJNXKZM7UQUWUZPUTHXSTZLEO7SJMI75' ] │ 'https://api.defindex.io/vault/CD4JGS6BB5NZVSNKRNI43GUC6E3OBYLCLBQZJVTZLDVHQ5KDAOHVOIQF' │
│ 7       │ 'ccktldg6i2mmjckfwxxbxma42lj3xn2iow6m7tk6ewnpjts736etff2n-stellar' │ 'Stellar' │ 'defindex' │ 'EURC'   │ 2080.73584721694   │ -21.14  │ [ 'CDTKPWPLOURQA2SGTKTUQOWRCBZEORB4BWBOMJ3D3ZTQQSGE5F6JBQLV' ] │ 'https://api.defindex.io/vault/CCKTLDG6I2MMJCKFWXXBXMA42LJ3XN2IOW6M7TK6EWNPJTS736ETFF2N' │
│ 8       │ 'cc24oisyjhwxzifzbrjhflvo5cnn3pqskze5bbbzlssi5z23tkc6gqy2-stellar' │ 'Stellar' │ 'defindex' │ 'CAL6ER' │ 0                  │ 0       │ [ 'CAL6ER2TI6CTRAY6BFXWNWA7WTYXUXTQCHUBCIBU5O6KM3HJFG6Z6VXV' ] │ 'https://api.defindex.io/vault/CC24OISYJHWXZIFZBRJHFLVO5CNN3PQSKZE5BBBZLSSI5Z23TKC6GQY2' │
└─────────┴────────────────────────────────────────────────────────────────────┴───────────┴────────────┴──────────┴────────────────────┴─────────┴────────────────────────────────────────────────────────────────┴──────────────────────────────────────────────────────────────────────────────────────────┘
This adapter contains some pools with <10k TVL, these pools won't be shown in DefiLlama

@MattPoblete MattPoblete changed the title feat(defindex): add DeFindex protocol adaptor ✨ Add DeFindex protocol adaptor Mar 27, 2026
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.

3 participants