Conversation
📝 WalkthroughWalkthroughAdds a new notional-exponent adapter module that fetches yield data from https://yields.notional.finance/fetchYields, validates and transforms vault entries into standardized adapter objects, normalizes chain names, and exports the apy function with timetravel disabled. Changes
Sequence Diagram(s)sequenceDiagram
participant Client as Client/Collector
participant Adapter as Notional-Exponent Adapter
participant API as yields.notional.finance
Client->>Adapter: invoke apy()
Adapter->>API: GET /fetchYields
API-->>Adapter: JSON payload (vaults[])
Adapter->>Adapter: validate & transform entries
Adapter-->>Client: standardized adapter array
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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 |
|
Error while running notional-exponent adapter: Test Suites: 1 failed, 1 total |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@src/adaptors/notional-exponent/index.js`:
- Around line 3-21: The main function should robustly handle network and data
errors: wrap the fetch/parse/map logic in a try/catch, use an AbortController to
add a timeout on the fetch call, check response.ok before calling
response.json() and throw a descriptive error if not ok, validate that the
parsed vaults is an array with Array.isArray(vaults) before calling vaults.map()
(return an empty array or throw a clear error if it’s not), and ensure any
thrown errors are surfaced or logged so callers of main receive a predictable
failure mode; update the function referenced as main, the fetch call, the
response.ok check, and the vaults.map usage accordingly.
| const main = async () => { | ||
| const response = await fetch('https://yields.notional.finance/fetchYields') | ||
| const vaults = await response.json(); | ||
|
|
||
| return vaults.map(({vaultAddress, chain, symbol, apyBase, tvlUSD, underlying, poolMeta, rewardTokens}) => { | ||
| return { | ||
| pool: `${vaultAddress}-${chain}`, | ||
| chain: chain === 'mainnet' ? 'ethereum' : chain, | ||
| project, | ||
| symbol, | ||
| underlyingTokens: underlying, | ||
| poolMeta, | ||
| url: `https://notional.finance/vault/${chain}/${vaultAddress}`, | ||
| tvlUsd: tvlUSD, | ||
| apyBase: apyBase, | ||
| rewardTokens: rewardTokens, | ||
| }; | ||
| }) | ||
| }; |
There was a problem hiding this comment.
Add error handling for fetch and response validation.
The adapter lacks error handling which could cause failures:
- No
response.okcheck before parsing JSON - No validation that
vaultsis an array before calling.map() - No timeout on the fetch request
🛡️ Proposed fix with error handling
const main = async () => {
- const response = await fetch('https://yields.notional.finance/fetchYields')
- const vaults = await response.json();
+ const response = await fetch('https://yields.notional.finance/fetchYields');
+ if (!response.ok) {
+ throw new Error(`Failed to fetch yields: ${response.status}`);
+ }
+ const vaults = await response.json();
+ if (!Array.isArray(vaults)) {
+ throw new Error('Invalid response: expected an array of vaults');
+ }
return vaults.map(({vaultAddress, chain, symbol, apyBase, tvlUSD, underlying, poolMeta, rewardTokens}) => {📝 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 main = async () => { | |
| const response = await fetch('https://yields.notional.finance/fetchYields') | |
| const vaults = await response.json(); | |
| return vaults.map(({vaultAddress, chain, symbol, apyBase, tvlUSD, underlying, poolMeta, rewardTokens}) => { | |
| return { | |
| pool: `${vaultAddress}-${chain}`, | |
| chain: chain === 'mainnet' ? 'ethereum' : chain, | |
| project, | |
| symbol, | |
| underlyingTokens: underlying, | |
| poolMeta, | |
| url: `https://notional.finance/vault/${chain}/${vaultAddress}`, | |
| tvlUsd: tvlUSD, | |
| apyBase: apyBase, | |
| rewardTokens: rewardTokens, | |
| }; | |
| }) | |
| }; | |
| const main = async () => { | |
| const response = await fetch('https://yields.notional.finance/fetchYields'); | |
| if (!response.ok) { | |
| throw new Error(`Failed to fetch yields: ${response.status}`); | |
| } | |
| const vaults = await response.json(); | |
| if (!Array.isArray(vaults)) { | |
| throw new Error('Invalid response: expected an array of vaults'); | |
| } | |
| return vaults.map(({vaultAddress, chain, symbol, apyBase, tvlUSD, underlying, poolMeta, rewardTokens}) => { | |
| return { | |
| pool: `${vaultAddress}-${chain}`, | |
| chain: chain === 'mainnet' ? 'ethereum' : chain, | |
| project, | |
| symbol, | |
| underlyingTokens: underlying, | |
| poolMeta, | |
| url: `https://notional.finance/vault/${chain}/${vaultAddress}`, | |
| tvlUsd: tvlUSD, | |
| apyBase: apyBase, | |
| rewardTokens: rewardTokens, | |
| }; | |
| }) | |
| }; |
🤖 Prompt for AI Agents
In `@src/adaptors/notional-exponent/index.js` around lines 3 - 21, The main
function should robustly handle network and data errors: wrap the
fetch/parse/map logic in a try/catch, use an AbortController to add a timeout on
the fetch call, check response.ok before calling response.json() and throw a
descriptive error if not ok, validate that the parsed vaults is an array with
Array.isArray(vaults) before calling vaults.map() (return an empty array or
throw a clear error if it’s not), and ensure any thrown errors are surfaced or
logged so callers of main receive a predictable failure mode; update the
function referenced as main, the fetch call, the response.ok check, and the
vaults.map usage accordingly.
|
The notional-exponent adapter exports pools: Test Suites: 1 passed, 1 total |
|
The notional-exponent adapter exports pools: Test Suites: 1 passed, 1 total |
|
hi,
|
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.