fix: add wstETH to apr & tAVAX support#2336
Conversation
📝 WalkthroughWalkthroughAdds AVAX pool support and richer APR calculations to the Treehouse Protocol adapter: parallelizes multi-block and rate fetches, introduces chain-specific pools (tETH, tAVAX), adds 1‑day and 7‑day APRs combining protocol rates with Lido and Benqi staking APRs, and returns apyBase and apyBase7d for each pool. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Adapter as TreehouseAdapter
participant RPC as BlockchainRPC
participant Contract as PoolContract
participant LidoAPI as LidoAPI
participant BenqiAPI as BenqiAPI
Client->>Adapter: request apy()
Adapter->>RPC: get blockNow, blockYesterday, block7dAgo (parallel)
par Fetch exchange rates
Adapter->>Contract: exchangeRateAt(blockYesterday)
Adapter->>Contract: exchangeRateAt(blockNow)
Adapter->>Contract: exchangeRateAt(block7dAgo)
end
par External APR fetches
Adapter->>LidoAPI: GET /steth/apr/last & /steth/apr/sma
Adapter->>BenqiAPI: GET /staking/apr (for AVAX pools)
end
Adapter->>Adapter: compute tethApr, tethApr7d, tavaxApr, tavaxApr7d
Adapter->>Adapter: combine with lidoApr/benqiApr -> apr, apr7d
Adapter-->>Client: return pools with apyBase, apyBase7d, apr, apr7d, tvl
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 treehouse-protocol adapter exports pools: Test Suites: 1 passed, 1 total |
|
The treehouse-protocol adapter exports pools: Test Suites: 1 passed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 Fix all issues with AI agents
In `@src/adaptors/treehouse-protocol/index.js`:
- Around line 89-91: tvlUsd calculation can produce NaN if wstEthPrice is
undefined; in the tvl computation where you use wstEthPrice and
totalPooledBWsteth (e.g., in the object setting apyBase, apyBase7d, tvlUsd),
validate or provide a fallback for wstEthPrice (or skip/return early for that
pool) before computing tvlUsd so you only multiply when wstEthPrice is a finite
number; update the logic around wstEthPrice (the optional chaining caller) to
either default to 0 or omit the pool from results when price is unavailable.
- Around line 71-77: The code that assigns lidoAprLast and lidoAprSma is
accessing a non-existent nested property (.data.data) on the Axios responses;
update the Promise.all .then handler to read the values from
responses[0].data.apr and responses[1].data.smaApr instead of
responses[0].data.data.apr and responses[1].data.data.smaApr so lidoAprLast and
lidoAprSma get the actual values returned by the Lido endpoints called via
axios.get.
| apyBase: apr, | ||
| apyBase7d: apr7d, | ||
| tvlUsd: totalPooledBWsteth.output / 1e18 * wstEthPrice, |
There was a problem hiding this comment.
Minor: Guard against undefined wstEthPrice.
If the price API fails or returns an unexpected structure, wstEthPrice will be undefined (line 14 uses optional chaining), causing tvlUsd to be NaN. Consider adding a fallback or validation.
🛡️ Suggested defensive check
+ if (!wstEthPrice) {
+ throw new Error('Failed to fetch wstETH price');
+ }
+
const timestampNow = Math.floor(Date.now() / 1000);Or alternatively, return early / skip the pool if price is unavailable.
🤖 Prompt for AI Agents
In `@src/adaptors/treehouse-protocol/index.js` around lines 89 - 91, tvlUsd
calculation can produce NaN if wstEthPrice is undefined; in the tvl computation
where you use wstEthPrice and totalPooledBWsteth (e.g., in the object setting
apyBase, apyBase7d, tvlUsd), validate or provide a fallback for wstEthPrice (or
skip/return early for that pool) before computing tvlUsd so you only multiply
when wstEthPrice is a finite number; update the logic around wstEthPrice (the
optional chaining caller) to either default to 0 or omit the pool from results
when price is unavailable.
|
The treehouse-protocol adapter exports pools: Test Suites: 1 passed, 1 total |
Resolves: #2335
Summary by CodeRabbit