feat(kasu): add XDC chain (AUDD + USDC deployments) with on-chain TVL reads#18754
feat(kasu): add XDC chain (AUDD + USDC deployments) with on-chain TVL reads#18754kivanov82 wants to merge 12 commits intoDefiLlama:mainfrom
Conversation
- Add XDC chain support with Goldsky subgraph and ExternalTVL - Switch from subgraph balance reads to on-chain totalSupply() for accurate historic data when DefiLlama backfills - Subgraph now used only for pool address discovery - Add ExternalTVL support for XDC (same pattern as Base) - Update Base subgraph to v1.0.13 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Adds the second XDC deployment (USDC) alongside the existing AUDD deployment, and corrects the AUDD pool to be denominated in AUDD (was mis-attributed to USDC.e). Refactors CONFIG to support multiple deployments per chain.
📝 WalkthroughWalkthroughThe pull request refactors the Kasu project's configuration structure from single objects per chain to arrays of deployment objects, enabling multiple subgraph deployments under the same chain. It introduces per-deployment cache keys and updates the TVL computation flow to iterate through all configured deployments. The XDC chain configuration is expanded to support two distinct deployments for AUDD and USDC assets. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 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 |
|
The adapter at projects/kasu exports TVL: |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
projects/kasu/index.js (1)
44-46: Potential precision loss when converting large token amounts to Number.
Number()can only safely represent integers up to 2^53-1. For tokens with 18 decimals, pools with >9M USD equivalent could lose precision. The DefiLlama SDK'sapi.add()handles arrays of BigInt strings natively without this issue.♻️ Suggested simplification that avoids precision loss
- const supplies = await api.multiCall({ abi: 'function totalSupply() view returns (uint256)', calls: poolAddresses, permitFailure: true }); - const poolTvl = supplies.reduce((sum, s) => sum + Number(s || 0), 0); - api.addTokens(asset, poolTvl) + const supplies = await api.multiCall({ abi: 'function totalSupply() view returns (uint256)', calls: poolAddresses, permitFailure: true }); + api.add(asset, supplies)This lets the SDK handle summation internally, preserving BigInt precision and simplifying the code.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@projects/kasu/index.js` around lines 44 - 46, The current code converts multiCall results to JS Numbers (supplies -> Number(s || 0)) causing precision loss for large token amounts; instead pass the raw string/BigInt values to the SDK so it can sum precisely—replace the manual reduce that builds poolTvl with a direct call to the SDK aggregation method (use api.add or api.addTokens with the supplies array) and stop using Number() conversion; locate the multiCall result variable supplies, the reduce that creates poolTvl, and the api.addTokens call and change the flow so the SDK receives the supplies array (or strings) directly for accurate big-int summation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@projects/kasu/index.js`:
- Around line 44-46: The current code converts multiCall results to JS Numbers
(supplies -> Number(s || 0)) causing precision loss for large token amounts;
instead pass the raw string/BigInt values to the SDK so it can sum
precisely—replace the manual reduce that builds poolTvl with a direct call to
the SDK aggregation method (use api.add or api.addTokens with the supplies
array) and stop using Number() conversion; locate the multiCall result variable
supplies, the reduce that creates poolTvl, and the api.addTokens call and change
the flow so the SDK receives the supplies array (or strings) directly for
accurate big-int summation.
Summary
totalSupply()per pool) plus an external TVL registry (externalTVLOfPool(address)) for off-balance-sheet exposure.CONFIGto support multiple deployments per chain.Test plan
node test.js projects/kasu/index.jscompletes successfully acrossbase,xdc, andplume_mainnet.Summary by CodeRabbit
New Features
Refactor