Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 52 additions & 0 deletions projects/travessia/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
const abis = {
convertToAssets: 'function convertToAssets(uint256) view returns (uint256)',
asset: 'function asset() view returns (address)',
}

const VAULTS = {
monad: [
'0x8D24B48Cb736addb5B7069565F192A052F42Ba61', // AUSD Tauri
],
ethereum: [
'0x4C18E2bb9942b12b28e780acF2D9EC2DDA126df9', // AUSD Tauri
],
}


function tvl(isBorrowed) {
return async (api) => {
const vaults = VAULTS[api.chain]
if (!vaults.length) return
Comment on lines +18 to +19
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 | 🟡 Minor

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.

Suggested change
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.


const [supplies, underlyings] = await Promise.all([
api.multiCall({ abi: 'erc20:totalSupply', calls: vaults, permitFailure: true }),
api.multiCall({ abi: abis.asset, calls: vaults, permitFailure: true }),
])

const [totalAssets, liquidity] = await Promise.all([
api.multiCall({
abi: abis.convertToAssets,
calls: vaults.map((vault, i) => ({ target: vault, params: [supplies[i] || 0] })),
permitFailure: true,
}),
api.multiCall({ abi: 'erc20:balanceOf', calls: vaults.map((vault, i) => ({ target: underlyings[i], params: vault })), permitFailure: true })
])

vaults.forEach((_, i) => {
if (!underlyings[i] || !totalAssets[i]) return
isBorrowed ? api.add(underlyings[i], totalAssets[i] - liquidity[i]) : api.add(underlyings[i], totalAssets[i])
})
Comment on lines +35 to +38
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

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.

}
}

module.exports = {
methodology: 'TVL converts each vault totalSupply to underlying via convertToAssets().',
monad: {
tvl: tvl(false),
borrowed: tvl(true)
},
ethereum: {
tvl: tvl(false),
borrowed: tvl(true)
},
}
Loading