fix: superstate and switch to stable 30d base w/7day#2281
fix: superstate and switch to stable 30d base w/7day#22810xkr3p merged 1 commit intoDefiLlama:masterfrom
Conversation
📝 WalkthroughWalkthroughThe change modifies the APY calculation logic in the Superstate USCC adaptor to use multi-date windows (7-day and 30-day periods) instead of single-day lookups. It introduces new exchange rate retrievals for these periods, calculates apr7d and apr30d with appropriate scaling factors, and updates the returned pool objects to include apyBase7d while setting apyBase to use the 30-day APR value. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 superstate-uscc adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/adaptors/superstate-uscc/index.js`:
- Around line 64-67: The APR calculations for apr7d and apr30d can produce
Infinity/NaN when exchangeRate7daysAgo or exchangeRate30daysAgo are 0 or
non-finite; update the logic in the apr7d/apr30d computation to first validate
the historic rates (exchangeRate7daysAgo and exchangeRate30daysAgo) using
Number.isFinite(...) and !== 0, and if invalid return the safe fallback expected
downstream (choose null or 0 consistently), otherwise compute the APR as before;
ensure the same guard is applied to both apr7d and apr30d so neither division
can produce Infinity/NaN.
🧹 Nitpick comments (1)
src/adaptors/superstate-uscc/index.js (1)
27-37: Parallelize block lookups and add request timeouts.These three sequential HTTP calls add unnecessary latency and create a single point of failure if the endpoint stalls. Parallelizing with
Promise.alland adding explicit timeouts will keep the function responsive and aligned with existing timeout patterns in the codebase (e.g., 10-second defaults used elsewhere).♻️ Proposed refactor
- const blockNow = ( - await axios.get(`https://coins.llama.fi/block/ethereum/${timestampNow}`) - ).data.height; - - const block7daysAgo = ( - await axios.get(`https://coins.llama.fi/block/ethereum/${timestamp7daysAgo}`) - ).data.height; - - const block30daysAgo = ( - await axios.get(`https://coins.llama.fi/block/ethereum/${timestamp30daysAgo}`) - ).data.height; + const [ + blockNowRes, + block7daysAgoRes, + block30daysAgoRes, + ] = await Promise.all([ + axios.get(`https://coins.llama.fi/block/ethereum/${timestampNow}`, { timeout: 10_000 }), + axios.get(`https://coins.llama.fi/block/ethereum/${timestamp7daysAgo}`, { timeout: 10_000 }), + axios.get(`https://coins.llama.fi/block/ethereum/${timestamp30daysAgo}`, { timeout: 10_000 }), + ]); + + const blockNow = blockNowRes.data.height; + const block7daysAgo = block7daysAgoRes.data.height; + const block30daysAgo = block30daysAgoRes.data.height;
| const apr7d = ((exchangeRateToday - exchangeRate7daysAgo) / exchangeRate7daysAgo) * | ||
| (365 / 7) * 100; | ||
| const apr30d = ((exchangeRateToday - exchangeRate30daysAgo) / exchangeRate30daysAgo) * | ||
| (365 / 30) * 100; |
There was a problem hiding this comment.
Guard against zero/invalid historic rates to prevent Infinity/NaN APRs.
If the oracle returns 0 or a non-finite value (e.g., during downtime), the current math yields spikes or NaNs—exactly what this PR aims to prevent. Add a safety check and return a safe fallback (e.g., null or 0) aligned with downstream expectations.
✅ Proposed safety guard
- const apr7d = ((exchangeRateToday - exchangeRate7daysAgo) / exchangeRate7daysAgo) *
- (365 / 7) * 100;
- const apr30d = ((exchangeRateToday - exchangeRate30daysAgo) / exchangeRate30daysAgo) *
- (365 / 30) * 100;
+ const apr7d =
+ exchangeRate7daysAgo > 0
+ ? ((exchangeRateToday - exchangeRate7daysAgo) / exchangeRate7daysAgo) *
+ (365 / 7) * 100
+ : null;
+ const apr30d =
+ exchangeRate30daysAgo > 0
+ ? ((exchangeRateToday - exchangeRate30daysAgo) / exchangeRate30daysAgo) *
+ (365 / 30) * 100
+ : null;📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| const apr7d = ((exchangeRateToday - exchangeRate7daysAgo) / exchangeRate7daysAgo) * | |
| (365 / 7) * 100; | |
| const apr30d = ((exchangeRateToday - exchangeRate30daysAgo) / exchangeRate30daysAgo) * | |
| (365 / 30) * 100; | |
| const apr7d = | |
| exchangeRate7daysAgo > 0 | |
| ? ((exchangeRateToday - exchangeRate7daysAgo) / exchangeRate7daysAgo) * | |
| (365 / 7) * 100 | |
| : null; | |
| const apr30d = | |
| exchangeRate30daysAgo > 0 | |
| ? ((exchangeRateToday - exchangeRate30daysAgo) / exchangeRate30daysAgo) * | |
| (365 / 30) * 100 | |
| : null; |
🤖 Prompt for AI Agents
In `@src/adaptors/superstate-uscc/index.js` around lines 64 - 67, The APR
calculations for apr7d and apr30d can produce Infinity/NaN when
exchangeRate7daysAgo or exchangeRate30daysAgo are 0 or non-finite; update the
logic in the apr7d/apr30d computation to first validate the historic rates
(exchangeRate7daysAgo and exchangeRate30daysAgo) using Number.isFinite(...) and
!== 0, and if invalid return the safe fallback expected downstream (choose null
or 0 consistently), otherwise compute the APR as before; ensure the same guard
is applied to both apr7d and apr30d so neither division can produce
Infinity/NaN.
superstate oracle downtime is causing spikes in the yield apr. updated to use 30d base and 7d which aligns with their api results:
https://api.superstate.com/v1/funds/2/yieldthis should give a smoother more realistic representation of the yield
Summary by CodeRabbit
Release Notes
apyBase7dfield to display 7-day annual percentage yield.apyBaseto reflect 30-day APR for more stable baseline metrics.✏️ Tip: You can customize this high-level summary in your review settings.