Skip to content

fix: add wstETH to apr & tAVAX support#2336

Merged
0xkr3p merged 3 commits intoDefiLlama:masterfrom
0xkr3p:fix/add-wsteth-yield-treehouse
Feb 3, 2026
Merged

fix: add wstETH to apr & tAVAX support#2336
0xkr3p merged 3 commits intoDefiLlama:masterfrom
0xkr3p:fix/add-wsteth-yield-treehouse

Conversation

@0xkr3p
Copy link
Contributor

@0xkr3p 0xkr3p commented Feb 3, 2026

Resolves: #2335

Summary by CodeRabbit

  • Improvements
    • Added chain-specific pools including AVAX support and underlying token handling for correct TVL and pricing.
    • APR/APY reporting enhanced with 7-day lookback metrics (base and composite) and additional protocol APR inputs for richer yield reporting.
    • Data fetching optimized to run in parallel for faster, more timely block and rate retrieval.

@coderabbitai
Copy link

coderabbitai bot commented Feb 3, 2026

📝 Walkthrough

Walkthrough

Adds 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

Cohort / File(s) Summary
Treehouse Protocol adapter
src/adaptors/treehouse-protocol/index.js
Refactored to use chain-specific pool helpers (getTethPool, getTavaxPool); added new chain tokens (tavax, savax, wavax); parallelized block and exchange-rate fetches and extended to 7‑day lookback; added Lido APR fetches and Benqi staking APR for AVAX; computes teth/tavax APR and 7‑day variants, composes final apr/apr7d and exposes apyBase and apyBase7d; removed single symbol = 'teth' export.

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
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Poem

🐰 I hopped through blocks both near and seven days,
I fetched stETH, AVAX, and APR arrays,
I mixed Lido songs with Benqi's tune,
Two pools now dance beneath the moon,
A rabbit cheers: yields in brighter rays! 🥕✨

🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes check ⚠️ Warning The PR introduces additional changes beyond issue #2335's scope: it adds tAVAX pool support with Benqi staking APR and implements 7-day APR metrics, which were not explicitly required by the linked issue. Consider separating tAVAX and 7-day APR features into separate PRs, or clarify if these are intended features within the issue scope.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title 'fix: add wstETH to apr' is partially related to the changeset. While the changes do add wstETH staking yield to APR calculations, the actual implementation adds both Lido APR and Benqi staking APR to multiple pools (tETH and tAVAX), which is broader than just wstETH.
Linked Issues check ✅ Passed The PR successfully addresses issue #2335 by adding Lido APR (wstETH staking yield) to the tETH pool's APY calculation, combining it with the product yield as required.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@llamatester
Copy link

The treehouse-protocol adapter exports pools:

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

Nb of pools: 1
 

Sample pools:
┌─────────┬──────────────────────────────────────────────┬────────────┬──────────────────────┬────────┬──────────────────────────────────────────────────┬────────────────────┬────────────────────┐
│ (index) │ pool                                         │ chain      │ project              │ symbol │ underlyingTokens                                 │ apyBase            │ tvlUsd             │
├─────────┼──────────────────────────────────────────────┼────────────┼──────────────────────┼────────┼──────────────────────────────────────────────────┼────────────────────┼────────────────────┤
│ 0       │ '0xd11c452fc99cf405034ee446803b6f6c1f6d5ed8' │ 'ethereum' │ 'treehouse-protocol' │ 'teth' │ [ '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0' ] │ 2.6850903951134097 │ 160022796.98740992 │
└─────────┴──────────────────────────────────────────────┴────────────┴──────────────────────┴────────┴──────────────────────────────────────────────────┴────────────────────┴────────────────────┘

@llamatester
Copy link

The treehouse-protocol adapter exports pools:

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

Nb of pools: 1
 

Sample pools:
┌─────────┬──────────────────────────────────────────────┬────────────┬──────────────────────┬────────┬──────────────────────────────────────────────────┬────────────────────┬───────────────────┬────────────────────┐
│ (index) │ pool                                         │ chain      │ project              │ symbol │ underlyingTokens                                 │ apyBase            │ apyBase7d         │ tvlUsd             │
├─────────┼──────────────────────────────────────────────┼────────────┼──────────────────────┼────────┼──────────────────────────────────────────────────┼────────────────────┼───────────────────┼────────────────────┤
│ 0       │ '0xd11c452fc99cf405034ee446803b6f6c1f6d5ed8' │ 'ethereum' │ 'treehouse-protocol' │ 'teth' │ [ '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0' ] │ 2.6850903951134097 │ 2.681855226018683 │ 159440732.24415007 │
└─────────┴──────────────────────────────────────────────┴────────────┴──────────────────────┴────────┴──────────────────────────────────────────────────┴────────────────────┴───────────────────┴────────────────────┘

Copy link

@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

🤖 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.

Comment on lines 89 to 91
apyBase: apr,
apyBase7d: apr7d,
tvlUsd: totalPooledBWsteth.output / 1e18 * wstEthPrice,
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

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.

@llamatester
Copy link

The treehouse-protocol adapter exports pools:

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

Nb of pools: 2
 

Sample pools:
┌─────────┬──────────────────────────────────────────────┬────────────┬──────────────────────┬─────────┬──────────────────────────────────────────────────┬────────────────────┬───────────────────┬───────────────────┐
│ (index) │ pool                                         │ chain      │ project              │ symbol  │ underlyingTokens                                 │ apyBase            │ apyBase7d         │ tvlUsd            │
├─────────┼──────────────────────────────────────────────┼────────────┼──────────────────────┼─────────┼──────────────────────────────────────────────────┼────────────────────┼───────────────────┼───────────────────┤
│ 0       │ '0xd11c452fc99cf405034ee446803b6f6c1f6d5ed8' │ 'ethereum' │ 'treehouse-protocol' │ 'tETH'  │ [ '0x7f39c581f595b53c5cb19bd0b3f8da6c935e2ca0' ] │ 2.5871195155921938 │ 2.722952868823154 │ 155646832.5658489 │
│ 1       │ '0x14A84F1a61cCd7D1BE596A6cc11FE33A36Bc1646' │ 'avax'     │ 'treehouse-protocol' │ 'tAVAX' │ [ '0x2b2C81e08f1Af8835a78Bb2A90AE924ACE0eA4bE' ] │ 5.798403661036147  │ 6.661188778138455 │ 644161.9024618426 │
└─────────┴──────────────────────────────────────────────┴────────────┴──────────────────────┴─────────┴──────────────────────────────────────────────────┴────────────────────┴───────────────────┴───────────────────┘

@0xkr3p 0xkr3p changed the title fix: add wstETH to apr fix: add wstETH to apr & tAVAX support Feb 3, 2026
@0xkr3p 0xkr3p merged commit 2739816 into DefiLlama:master Feb 3, 2026
2 checks passed
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.

Update APY for Treeehouse tETH

2 participants