-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Feat/travessia credit #18695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feat/travessia credit #18695
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| 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 | ||
|
|
||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Borrowed calculation can fail when Line 36 checks 🐛 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 |
||
| } | ||
| } | ||
|
|
||
| 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) | ||
| }, | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.lengththrows a TypeError.🛡️ Proposed fix
return async (api) => { const vaults = VAULTS[api.chain] - if (!vaults.length) return + if (!vaults?.length) return📝 Committable suggestion
🤖 Prompt for AI Agents