Skip to content
Merged
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
25 changes: 21 additions & 4 deletions src/adaptors/flamingo-finance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@ const utils = require('../utils');

const poolsFunction = async () => {
const poolsData = await utils.getData(
'http://api.flamingo.finance/project-info/defillama-yields'
'https://flamingo-us-1.b-cdn.net/flamingo/analytics/flamingo/defillama-yields'
);

return poolsData.pools.reduce((acc, p) => {
const pools = Array.isArray(poolsData) ? poolsData : poolsData.pools;

return pools.reduce((acc, p) => {
Comment on lines +8 to +10
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

🧩 Analysis chain

🏁 Script executed:

cat -n src/adaptors/flamingo-finance/index.js | head -30

Repository: DefiLlama/yield-server

Length of output: 1146


🏁 Script executed:

#!/bin/bash
# Inspect the live CDN payload shape
curl -s https://flamingo-us-1.b-cdn.net/flamingo/analytics/flamingo/defillama-yields | jq 'type, keys? // "is-array"' | head -20

Repository: DefiLlama/yield-server

Length of output: 173


🏁 Script executed:

rg -A 15 'getData\s*=' src/adaptors/utils.js | head -40

Repository: DefiLlama/yield-server

Length of output: 553


🏁 Script executed:

rg -B 5 -A 10 'exports\.getData|function getData' src/adaptors/utils.js

Repository: DefiLlama/yield-server

Length of output: 397


🏁 Script executed:

rg -B 5 -A 25 'poolsFunction|exports' src/adaptors/flamingo-finance/index.js

Repository: DefiLlama/yield-server

Length of output: 1054


🏁 Script executed:

# Check if there's error handling in the adapter index or wrapper
fd index.js src/adaptors/ | head -5 | xargs rg -l 'module.exports|exports' | head -1 | xargs cat -n | tail -20

Repository: DefiLlama/yield-server

Length of output: 676


Guard against null/undefined poolsData and missing pools property to prevent runtime crash.

The current code assumes poolsData.pools exists when poolsData is not an array. If the API returns null, undefined, or an object without a pools property, accessing .pools will throw a TypeError. Add defensive handling with optional chaining and an empty array fallback:

Proposed fix
-  const pools = Array.isArray(poolsData) ? poolsData : poolsData.pools;
+  const pools = Array.isArray(poolsData)
+    ? poolsData
+    : Array.isArray(poolsData?.pools)
+      ? poolsData.pools
+      : [];
🤖 Prompt for AI Agents
In `@src/adaptors/flamingo-finance/index.js` around lines 8 - 10, The code assumes
poolsData is either an array or has a pools property and will crash if poolsData
is null/undefined or lacks pools; update the assignment that creates pools
(currently "const pools = Array.isArray(poolsData) ? poolsData :
poolsData.pools;") to defensively handle these cases by using optional chaining
and an empty-array fallback so pools is always an array before the subsequent
reduce call (reference symbols: poolsData, pools, and the reduce invocation).

if (!acc.some((pool) => pool.pool === p.pool)) {
acc.push(p);
acc.push({
pool: p.pool,
chain: 'Neo',
project: 'flamingo-finance',
symbol: p.symbol,
tvlUsd: p.tvlUsd,
apyBase: p.apyBase || 0,
apyReward: p.apyReward || 0,
rewardTokens: p.rewardTokens
? Array.isArray(p.rewardTokens)
? p.rewardTokens
: [p.rewardTokens]
: [],
underlyingTokens: p.underlyingTokens || [],
poolMeta: p.poolMeta || null,
});
}
return acc;
}, []);
Expand All @@ -16,5 +33,5 @@ const poolsFunction = async () => {
module.exports = {
timetravel: false,
apy: poolsFunction,
url: 'https://flamingo.finance/earn/overview'
url: 'https://flamingo.finance/earn/overview',
};
Loading