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
32 changes: 32 additions & 0 deletions src/adaptors/notional-exponent/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const project = 'notional-exponent';

const main = async () => {
const response = await fetch('https://yields.notional.finance/fetchYields')
if (!response.ok) {
throw new Error(`Failed to fetch yields: ${response.statusText}`);
}
const vaults = await response.json();
if (!vaults || !Array.isArray(vaults)) {
throw new Error('Invalid response format');
}

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,
};
})
};
Comment on lines 3 to 27
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟠 Major

Add error handling for fetch and response validation.

The adapter lacks error handling which could cause failures:

  1. No response.ok check before parsing JSON
  2. No validation that vaults is an array before calling .map()
  3. 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.

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


module.exports = {
timetravel: false,
apy: main,
};
Loading