Skip to content

Commit

Permalink
chore: remove unneccesary call in v3 pool
Browse files Browse the repository at this point in the history
  • Loading branch information
starketh25 committed Dec 27, 2024
1 parent 0d1ddfa commit 6d77782
Showing 1 changed file with 6 additions and 46 deletions.
52 changes: 6 additions & 46 deletions src/adaptors/fenix-finance/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,53 +82,13 @@ const getApy = async () => {
}
}

const alreadySeen = [];
for (const pair of pairs) {
const token0Key = 'blast:' + pair.token0.id.toLowerCase();
const token1Key = 'blast:' + pair.token1.id.toLowerCase();

if (!alreadySeen.includes(token0Key)) {
alreadySeen.push(token0Key);
}
if (!alreadySeen.includes(token1Key)) {
alreadySeen.push(token1Key);
}
}

let fullCoin = {};
const chunkSize = 60;
for (let i = 0; i < alreadySeen.length; i += chunkSize) {
const chunk = alreadySeen.slice(i, i + chunkSize);
const { coins } = await utils.getData(
`https://coins.llama.fi/prices/current/${chunk.join(
','
)}?searchWidth=4h`
);
fullCoin = { ...fullCoin, ...coins };
}

const pools = pairs.map((pair) => {
let tvl = 0;

if (
fullCoin['blast:' + pair.token0.id.toLowerCase()] &&
fullCoin['blast:' + pair.token1.id.toLowerCase()]
) {
// Fix: Use pair properties for TVL calculation
const token0Price =
fullCoin['blast:' + pair.token0.id.toLowerCase()].price;
const token1Price =
fullCoin['blast:' + pair.token1.id.toLowerCase()].price;

const token0ValueInReserve =
parseFloat(pair.totalValueLockedToken0) * token0Price;
const token1ValueInReserve =
parseFloat(pair.totalValueLockedToken1) * token1Price;

tvl = token0ValueInReserve + token1ValueInReserve;
} else {
tvl = parseFloat(pair.totalValueLockedUSD);
}
const token0ValueInReserve = parseFloat(pair.totalValueLockedToken0);
const token1ValueInReserve = parseFloat(pair.totalValueLockedToken1);

tvl = token0ValueInReserve + token1ValueInReserve;

const poolData = {
pool: pair.id,
Expand All @@ -143,14 +103,14 @@ const getApy = async () => {

return poolData;
});

console.log(pools);
return pools;
} catch (error) {
console.error('Error in getApy:', error);
throw error;
}
};

getApy();
module.exports = {
timetravel: false,
apy: getApy,
Expand Down

0 comments on commit 6d77782

Please sign in to comment.