Skip to content

remove termmax bsquared tvl#18709

Open
RohanNero wants to merge 3 commits intoDefiLlama:mainfrom
RohanNero:termmax-refactor
Open

remove termmax bsquared tvl#18709
RohanNero wants to merge 3 commits intoDefiLlama:mainfrom
RohanNero:termmax-refactor

Conversation

@RohanNero
Copy link
Copy Markdown
Contributor

@RohanNero RohanNero commented Apr 9, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Excluded specific bsquared markets from TVL and borrowed-value calculations by introducing a marketplace blacklist applied across market lookups to prevent them from affecting reported totals.
  • Documentation

    • Added comments explaining the exclusion rationale with illustrative examples and traces for clarity.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 9, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: f0f0e041-773c-4305-8311-285a683e19b4

📥 Commits

Reviewing files that changed from the base of the PR and between c590e47 and c8a9d23.

📒 Files selected for processing (1)
  • projects/term-structure/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • projects/term-structure/index.js

📝 Walkthrough

Walkthrough

Introduces a MARKET_BLACKLIST for the bsquared chain and filters blacklisted market addresses out of TVL and borrowed computations; adds a block comment documenting the uBTC/WBTC exclusion with example market traces.

Changes

Cohort / File(s) Summary
Term-structure market filters
projects/term-structure/index.js
Added MARKET_BLACKLIST for bsquared; filtered blacklisted addresses when building V1+V2 market lists in getTermMaxMarketOwnerTokens and before token/config lookups in getTermMaxV2MarketBorrowed; added explanatory block comment with example traces.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 I hop through code, a soft and merry twitch,
I hide the blacklisted crumbs without a glitch,
uBTC and WBTC gently tucked away,
Counts stay tidy as I nibble through the day,
A carrot for clean data — hop, skip, hooray!

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Description check ⚠️ Warning The pull request description is empty, missing all required information including rationale, testing details, and changes explanation outlined in the repository template. Add a comprehensive pull request description explaining why bsquared markets are being excluded, the scope of changes, testing performed, and any relevant context for reviewers.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title 'remove termmax bsquared tvl' is specific and directly related to the main change: excluding blacklisted bsquared markets from TVL calculations in the termmax term structure adapter.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown
Contributor

@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: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@projects/term-structure/index.js`:
- Around line 325-326: The blacklist membership checks for MARKET_BLACKLIST and
VAULT_BLACKLIST are case-sensitive, so normalize addresses before comparing:
when filtering marketV2Addresses (the .filter using MARKET_BLACKLIST[api.chain])
and where VAULT_BLACKLIST is used (the filter at/near the VAULT handling),
convert the parsed/returned addr to a consistent case (e.g., addr.toLowerCase())
before calling .includes, or ensure the blacklist entries are normalized too;
update the filter predicates that reference MARKET_BLACKLIST and VAULT_BLACKLIST
to compare normalized forms and guard against undefined blacklist entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b0656d57-4c4a-4fe3-b043-d0f6e73a1e35

📥 Commits

Reviewing files that changed from the base of the PR and between fc685ba and c590e47.

📒 Files selected for processing (1)
  • projects/term-structure/index.js

Comment on lines +325 to +326
.concat(marketV2Addresses)
.filter(addr => !MARKET_BLACKLIST[api.chain]?.includes(addr));
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify whether log helpers normalize addresses (which would make current includes() checks fragile).

set -euo pipefail

echo "== Locate getLogs helper =="
fd -i "getLogs.js"

echo
echo "== Inspect helper implementation for normalization =="
sed -n '1,260p' helper/cache/getLogs.js

echo
echo "== Search for lowercase/checksum normalization in log helpers =="
rg -n -C2 "toLowerCase|checksum|lowercase|onlyArgs|map\\(" helper/cache/getLogs.js

echo
echo "== Confirm current blacklist matching callsites in adapter =="
rg -n -C2 "MARKET_BLACKLIST|includes\\(|filter\\(" projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 271


🏁 Script executed:

# Find the correct path to getLogs helper
git ls-files | grep -i getlogs

# Also check the term-structure adapter structure
ls -la projects/term-structure/

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 286


🏁 Script executed:

# Search for getLogs usage in the term-structure adapter
rg -n "getLogs|getLogs2" projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 474


🏁 Script executed:

# Inspect how addresses come from getLogs and what the adapter does with them
rg -n -B5 -A5 "getLogs|getTokens|decodeEventLog" projects/term-structure/index.js | head -100

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 3888


🏁 Script executed:

# Inspect the getLogs helper for address normalization
cat -n projects/helper/cache/getLogs.js | head -150

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 6083


🏁 Script executed:

# Search specifically for toLowerCase or address normalization in getLogs
rg -n "toLowerCase|checksum|normalize|address" projects/helper/cache/getLogs.js | head -50

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 478


🏁 Script executed:

# Check what addresses are returned from the getLogs calls and how they're used
rg -n -A3 "getTermMaxMarketAddresses\|getTermMaxMarketV2Addresses" projects/term-structure/index.js | head -50

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Look at the actual MARKET_BLACKLIST definition and surrounding code
rg -n -B2 -A10 "MARKET_BLACKLIST" projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 1706


🏁 Script executed:

# Check if there's any address normalization in the adapter itself
rg -n "toLowerCase|checksum" projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Verify what ethers Interface.parseLog does with addresses by checking if there are any comments or documentation in the code
head -300 projects/term-structure/index.js | tail -100

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 2654


🏁 Script executed:

# Search for similar blacklist patterns in other adapters
rg -n "BLACKLIST.*includes|filter.*BLACKLIST" --type js projects/ | head -20

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 864


🏁 Script executed:

# Check if ethers.js in this repo has any address normalization utilities or if addresses are documented
rg -n "ethers\..*Address|getAddress|parseLog" projects/helper/ | head -30

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 1929


🏁 Script executed:

# Verify what the actual logs look like by checking the event definitions
rg -n "CreateMarket\|MarketCreated" projects/term-structure/index.js -A 2

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Check if there are any comments or code indicating address format expectations
rg -n -B5 "lowercase|checksum|format" projects/term-structure/index.js | head -40

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Check if ethers.js is used elsewhere in term-structure for clues about address format
rg -n "ethers\|Interface\|parseLog" projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Look for the event ABI definitions in term-structure to understand the field types
rg -n "EVENTS\." projects/term-structure/index.js -A 3 | head -60

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 1551


🏁 Script executed:

# Check what ethers.js version is used and its default behavior
cat package.json | rg -A 5 "ethers"

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 232


🏁 Script executed:

# Find where EVENTS is defined in term-structure
rg -n "const EVENTS\|= {" projects/term-structure/index.js | head -20

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 169


🏁 Script executed:

# Get the EVENTS definition
sed -n '150,280p' projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 3250


🏁 Script executed:

# Find EVENTS definition more carefully
rg -n "const EVENTS" projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 91


🏁 Script executed:

# Get the EVENTS object definition
sed -n '11,150p' projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 5588


🏁 Script executed:

# Check what ethers.js v6 returns from parseLog for addresses
# by looking for any documentation or examples in the repo
rg -n "parseLog\|getAddress" projects/ -A 2 -B 2 | head -50

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Verify if there are any real-world issues with the blacklist checks
# by checking if there are any bug reports or TODOs
rg -n "TODO|FIXME|BUG|blacklist" projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Double-check: does getLogs2 behave differently than getLogs?
sed -n '160,250p' projects/helper/cache/getLogs.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 2667


🏁 Script executed:

# Extract all blacklist addresses and check their format
rg -n "0x[a-fA-F0-9]+" projects/term-structure/index.js | grep -E "BLACKLIST|0x[a-f][a-f0-9]*[A-F]|0x[A-F][a-f0-9]*[A-F]" | head -40

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 1549


🏁 Script executed:

# More precise check: look at the actual blacklist values
sed -n '270,285p' projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 611


🏁 Script executed:

# And check VAULT_BLACKLIST too
sed -n '253,270p' projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 513


🏁 Script executed:

# Check if there are any recent changes or issues related to address casing
git log --oneline -20 projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 113


🏁 Script executed:

# Verify if ethers.js has any address normalization in the contract decode process
# by checking how addresses are handled elsewhere in the codebase
rg -n "\.toLowerCase()" projects/ -B 2 -A 2 | grep -A 2 -B 2 "address\|Address" | head -60

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 3960


🏁 Script executed:

# Check if the same pattern of using .includes() for address matching exists elsewhere
rg -n "\.includes.*0x|includes.*address" projects/ --type js | head -20

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 2556


🏁 Script executed:

# Check the event definitions more carefully - are the addresses indexed or not?
sed -n '32,50p' projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 1829


🏁 Script executed:

# Search for how ethers.js handles address normalization in similar projects
# by checking imports and usage patterns
rg -n "import.*ethers\|require.*ethers" projects/ -A 3 | head -30

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Final verification: check if there's any test or example showing what format addresses come back in
rg -n "market.*=.*0x|collateral.*=.*0x" projects/term-structure/ -B 2 -A 2

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Extract all blacklist addresses and check their exact casing
rg -n "0x[a-fA-F0-9]{40}" projects/term-structure/index.js | grep -A 1 -B 1 "BLACKLIST"

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Get exact blacklist contents with casing preserved
sed -n '253,281p' projects/term-structure/index.js

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 852


🏁 Script executed:

# Final verification: check ethers.js v6 default behavior documentation
# by looking for any ethers usage in tests or examples
find projects/ -name "*.test.js" -o -name "*.spec.js" 2>/dev/null | head -5

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 54


🏁 Script executed:

# Check if there are any comments about address casing in the codebase
rg -n "checksum|EIP-55|case.*sensitive" projects/ -i | head -20

Repository: DefiLlama/DefiLlama-Adapters

Length of output: 1987


Normalize addresses before blacklist checks.

At line 326 and line 549, the blacklist comparison is case-sensitive. Additionally, line 416 has the same issue with VAULT_BLACKLIST. Since ethers.Interface.parseLog() returns checksummed addresses and the ethereum entry in VAULT_BLACKLIST is lowercase (0x5c16d84e998c661d9f6c7cc23e1144e4b7f39759), excluded vaults/markets will not be filtered correctly, causing TVL/borrowed amounts to include blacklisted positions.

Normalize addresses before comparison:

Proposed fix
 const MARKET_BLACKLIST = {
   bsquared: [
     "0x39256Ad46B721F47d48D1e0918a986cAc0c210ed", // B2BTC/uBTC
     "0xe7d99048B6A292CBda8c7C3c0D38eBdaB3999870", // WBTC/uBTC
     "0x5022B6563f6bc9f0D47F407ba32B64e1f438213a", // uBTC/WBTC
   ],
 };

+const MARKET_BLACKLIST_SET = Object.fromEntries(
+  Object.entries(MARKET_BLACKLIST).map(([chain, addrs]) => [
+    chain,
+    new Set(addrs.map((a) => a.toLowerCase())),
+  ])
+);
+
+const VAULT_BLACKLIST_SET = Object.fromEntries(
+  Object.entries(VAULT_BLACKLIST).map(([chain, addrs]) => [
+    chain,
+    new Set(addrs.map((a) => a.toLowerCase())),
+  ])
+);
+
+function isBlacklistedMarket(chain, addr) {
+  return MARKET_BLACKLIST_SET[chain]?.has(addr.toLowerCase());
+}
+
+function isBlacklistedVault(chain, addr) {
+  return VAULT_BLACKLIST_SET[chain]?.has(addr.toLowerCase());
+}
+
 async function getTermMaxMarketOwnerTokens(api) {
   const [marketV1Addresses, marketV2Addresses] = await Promise.all([
     getTermMaxMarketAddresses(api),
     getTermMaxMarketV2Addresses(api),
   ]);
   const marketAddresses = []
     .concat(marketV1Addresses)
     .concat(marketV2Addresses)
-    .filter(addr => !MARKET_BLACKLIST[api.chain]?.includes(addr));
+    .filter(addr => !isBlacklistedMarket(api.chain, addr));
   ...
 }

 async function getTermMaxV2MarketBorrowed(api) {
-  const marketAddresses = (await getTermMaxMarketV2Addresses(api)).filter(addr => !MARKET_BLACKLIST[api.chain]?.includes(addr));
+  const marketAddresses = (await getTermMaxMarketV2Addresses(api))
+    .filter(addr => !isBlacklistedMarket(api.chain, addr));
   ...
 }

 async function getTermMaxVaultTvl(api) {
   ...
-    .filter((address) => !VAULT_BLACKLIST[api.chain]?.includes(address));
+    .filter((address) => !isBlacklistedVault(api.chain, address));
   ...
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@projects/term-structure/index.js` around lines 325 - 326, The blacklist
membership checks for MARKET_BLACKLIST and VAULT_BLACKLIST are case-sensitive,
so normalize addresses before comparing: when filtering marketV2Addresses (the
.filter using MARKET_BLACKLIST[api.chain]) and where VAULT_BLACKLIST is used
(the filter at/near the VAULT handling), convert the parsed/returned addr to a
consistent case (e.g., addr.toLowerCase()) before calling .includes, or ensure
the blacklist entries are normalized too; update the filter predicates that
reference MARKET_BLACKLIST and VAULT_BLACKLIST to compare normalized forms and
guard against undefined blacklist entries.

@llamabutler
Copy link
Copy Markdown

The adapter at projects/term-structure exports TVL:

ethereum                  23.95 M
bsquared                  12.45 M
borrowed                  4.27 M
ethereum-borrowed         4.22 M
bsc                       802.29 k
berachain                 292.28 k
xlayer                    216.00 k
base                      100.75 k
bsc-borrowed              52.16 k
arbitrum                  8.99 k
berachain-borrowed        10.00
base-borrowed             3.00
arbitrum-borrowed         0.00
bsquared-borrowed         0.00
hyperliquid               0.00
hyperliquid-borrowed      0.00
xlayer-borrowed           0.00

total                    37.82 M 

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.

2 participants