✨ Add DeFindex protocol adaptor#2479
Conversation
Add yield adaptor for DeFindex protocol to retrieve APY and TVL data.
📝 WalkthroughWalkthroughAdds a new Defindex Stellar adaptor exporting Changes
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
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.
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
defindexadapter 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, |
There was a problem hiding this comment.
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).
| url: API_BASE_URL, | |
| url: API_BASE_URL.toString(), |
| tvlUsd, | ||
| apyBase: vault.apy, | ||
| underlyingTokens, | ||
| url: `${API_BASE_URL}/vault/${vault.address}`, |
There was a problem hiding this comment.
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)).
| url: `${API_BASE_URL}/vault/${vault.address}`, | |
| url: `${API_BASE_URL}vault/${vault.address}`, |
There was a problem hiding this comment.
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 = 7for all assets is standard for native Stellar assets (stroops), but custom tokens could potentially have different precision. The DefiLlama price API returns adecimalsfield per coin that's currently being discarded infetchCoinData.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
📒 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
|
The defindex adapter exports pools: Test Suites: 1 passed, 1 total |
Summary
/vault/discover?network=mainnet)Test plan
npm run test --adapter=defindexand verify vault data is returnedtvlUsdandapyBaseare non-zero for active vaultschainis"Stellar"andpoolIDs are uniqueSummary by CodeRabbit