Conversation
📝 WalkthroughWalkthroughA new module for the Travessia protocol was created to calculate total value locked (TVL) and borrowed amounts across monad and ethereum chains. It queries vault supplies, underlying assets, and liquidity through multi-call queries to derive metrics. Changes
Sequence DiagramsequenceDiagram
participant Chain as Chain Provider
participant Vault as Vault Contracts
participant ERC20 as ERC20 Assets
participant Aggregator as TVL Aggregator
Aggregator->>Chain: Fetch vault totalSupply (multi-call)
Chain-->>Aggregator: supplies[]
Aggregator->>Vault: Call asset() for each vault
Vault-->>Aggregator: underlyingAssets[]
Aggregator->>Vault: Call convertToAssets(supply) for each vault
Vault-->>Aggregator: totalAssets[]
Aggregator->>ERC20: Query balanceOf(vault) for each underlying asset
ERC20-->>Aggregator: liquidityBalances[]
Aggregator->>Aggregator: Calculate TVL or Borrowed<br/>(totalAssets OR totalAssets - liquidity)
Aggregator-->>Chain: Return accumulated value
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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/travessia exports TVL: |
There was a problem hiding this comment.
Actionable comments posted: 2
🤖 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/travessia/index.js`:
- Around line 18-19: The code currently assumes VAULTS[api.chain] exists which
can throw when undefined; update the logic around the const vaults =
VAULTS[api.chain] and the subsequent if check in projects/travessia/index.js
(the vaults variable) to first guard for undefined/null (e.g., if (!vaults ||
!vaults.length) return) so the code returns safely when the chain has no
configuration; ensure you reference and update the vaults variable and the
existing if-check rather than only checking .length.
- Around line 35-38: The loop in vaults.forEach uses liquidity[i] in a
subtraction when isBorrowed is true but doesn’t guard against liquidity being
null/undefined; update the loop (vaults.forEach) to check liquidity[i] before
subtracting (e.g., if (isBorrowed && (liquidity[i] == null)) return/continue to
skip this vault or treat missing liquidity as 0), and only call
api.add(underlyings[i], totalAssets[i] - liquidity[i]) when liquidity[i] is a
valid number; ensure you reference underlyings[i], totalAssets[i], liquidity[i],
isBorrowed, and api.add in the change so the subtraction never produces NaN or
throws.
🪄 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: a18207d2-58b5-4299-bee2-76672f3668ce
📒 Files selected for processing (1)
projects/travessia/index.js
| const vaults = VAULTS[api.chain] | ||
| if (!vaults.length) return |
There was a problem hiding this comment.
Add guard against undefined chain configuration.
If VAULTS[api.chain] is undefined (e.g., a new chain is added to exports but not to VAULTS), accessing .length throws a TypeError.
🛡️ Proposed fix
return async (api) => {
const vaults = VAULTS[api.chain]
- if (!vaults.length) return
+ if (!vaults?.length) return📝 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 vaults = VAULTS[api.chain] | |
| if (!vaults.length) return | |
| const vaults = VAULTS[api.chain] | |
| if (!vaults?.length) return |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@projects/travessia/index.js` around lines 18 - 19, The code currently assumes
VAULTS[api.chain] exists which can throw when undefined; update the logic around
the const vaults = VAULTS[api.chain] and the subsequent if check in
projects/travessia/index.js (the vaults variable) to first guard for
undefined/null (e.g., if (!vaults || !vaults.length) return) so the code returns
safely when the chain has no configuration; ensure you reference and update the
vaults variable and the existing if-check rather than only checking .length.
| vaults.forEach((_, i) => { | ||
| if (!underlyings[i] || !totalAssets[i]) return | ||
| isBorrowed ? api.add(underlyings[i], totalAssets[i] - liquidity[i]) : api.add(underlyings[i], totalAssets[i]) | ||
| }) |
There was a problem hiding this comment.
Borrowed calculation can fail when liquidity[i] is null/undefined.
Line 36 checks underlyings[i] and totalAssets[i] but not liquidity[i]. When the balanceOf call fails (e.g., invalid underlying address), liquidity[i] will be null/undefined due to permitFailure: true. The subtraction totalAssets[i] - liquidity[i] will then produce NaN or throw a TypeError.
🐛 Proposed fix
vaults.forEach((_, i) => {
if (!underlyings[i] || !totalAssets[i]) return
- isBorrowed ? api.add(underlyings[i], totalAssets[i] - liquidity[i]) : api.add(underlyings[i], totalAssets[i])
+ if (isBorrowed) {
+ if (liquidity[i] == null) return
+ api.add(underlyings[i], totalAssets[i] - liquidity[i])
+ } else {
+ api.add(underlyings[i], totalAssets[i])
+ }
})🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@projects/travessia/index.js` around lines 35 - 38, The loop in vaults.forEach
uses liquidity[i] in a subtraction when isBorrowed is true but doesn’t guard
against liquidity being null/undefined; update the loop (vaults.forEach) to
check liquidity[i] before subtracting (e.g., if (isBorrowed && (liquidity[i] ==
null)) return/continue to skip this vault or treat missing liquidity as 0), and
only call api.add(underlyings[i], totalAssets[i] - liquidity[i]) when
liquidity[i] is a valid number; ensure you reference underlyings[i],
totalAssets[i], liquidity[i], isBorrowed, and api.add in the change so the
subtraction never produces NaN or throws.
Name (to be shown on DefiLlama):
Travessia Credit
Twitter Link:
https://x.com/TravessiaCredit
List of audit links if any:
https://docs.travessiacredit.com/pages/security-audits-risk-controls.html
Website Link:
https://www.travessiacredit.com/
Logo (High resolution, will be shown with rounded borders):
https://www.travessiacredit.com/travessia_logo_dark.webp
Current TVL:
$50k
Treasury Addresses (if the protocol has treasury)
Chain:
Monad, Ethereum
Short Description (to be shown on DefiLlama):
On-chain credit infrastructure for real-world assets.
Category (full list at https://defillama.com/categories) *Please choose only one:
RWA Lending
methodology (what is being counted as tvl, how is tvl being calculated):
We work with Accountable Vaults. The contracts are ERC-7540 compliant. We track totalAssets and borrows.
Github org/user (Optional, if your code is open source, we can track activity):
https://github.com/RedVeil
Summary by CodeRabbit