Skip to content

Commit

Permalink
Feat/fenix standard pools (#1672)
Browse files Browse the repository at this point in the history
* Feat: add fenix v3 and v2 pools

* fix: add 10k tvl check

* chore: remove unneccesary call in v3 pool

* fix: slug name as folder

* fix: remove v2 to add in seperate pr

* feat: add v2 pools to yeild server

* fix: build

* fix: tvl values
  • Loading branch information
starketh25 authored Dec 31, 2024
1 parent 8c1abb8 commit 953e937
Showing 1 changed file with 101 additions and 0 deletions.
101 changes: 101 additions & 0 deletions src/adaptors/fenix-standard-pools/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
const sdk = require('@defillama/sdk');
const axios = require('axios');
const utils = require('../utils');
const { request, gql } = require('graphql-request');

const API_URL = `https://blaze.prod.fenix.aegas.it/liquidity/rewards`;

const SUBGRAPH_URL =
'https://api.goldsky.com/api/public/project_clxadvm41bujy01ui2qalezdn/subgraphs/fenix-v2-subgraph/latest/gn';

const FNX_ADDRESS = '0x52f847356b38720B55ee18Cb3e094ca11C85A192';

const swapPairsQuery = (skip) => {
return gql`
query MyQuery {
pairs(first: 100, skip: ${skip}, where: {reserveUSD_gt: 10000}) {
reserve0
reserve1
token1 {
id
symbol
}
token0 {
id
symbol
}
reserveUSD
id
}
}
`;
};

const getPairs = async () => {
let pairs = [];
let index = 0;
let res;
do {
res = await request(SUBGRAPH_URL, swapPairsQuery(index), {});
if (res.pairs.length > 0) {
pairs = [...pairs, ...res.pairs];
}
index += res.pairs.length;
} while (res.pairs.length > 0);
return pairs;
};

const getApy = async () => {
const pairs = await getPairs();
const poolsRes = await axios.get(
`${API_URL}?${pairs.map((pair) => `pools=${pair.id}`).join('&')}`
);

// First get FNX price from DeFiLlama
const { coins: fnxPrice } = await utils.getData(
`https://coins.llama.fi/prices/current/blast:${FNX_ADDRESS}?searchWidth=4h`
);

const fnxPriceUsd = fnxPrice[`blast:${FNX_ADDRESS}`]?.price || 0;

// Create apyDict by calculating (rewards/tvl) * 100 * 52 for each pool
const apyDict = {};
for (const pool of poolsRes.data) {
const pairData = pairs.find(
(p) => p.id.toLowerCase() === pool.pool.toLowerCase()
);

if (pairData) {
// Convert reward to annual value (weekly * 52) and from Wei to FNX
const annualReward = (parseFloat(pool.rewardWei) * 52) / 1e18;
// Convert to USD using FNX price
const annualRewardUSD = annualReward * fnxPriceUsd;
// Get TVL
const tvl = parseFloat(pairData.reserveUSD);
// Calculate APY: (annual reward in USD / TVL) * 100
apyDict[pool.pool.toLowerCase()] = (annualRewardUSD / tvl) * 100;
}
}

const pools = pairs.map((pair) => {
tvl = parseFloat(pair.reserveUSD);
return {
pool: pair.id,
chain: utils.formatChain('blast'),
project: 'fenix-standard-pools',
symbol: `${pair.token0.symbol}-${pair.token1.symbol}`,
tvlUsd: tvl,
apyReward: parseFloat(apyDict[pair.id.toLowerCase()] || 0),
underlyingTokens: [pair.token0.id, pair.token1.id],
rewardTokens: [FNX_ADDRESS],
};
});

return pools;
};
getApy();
module.exports = {
timetravel: false,
apy: getApy,
url: 'https://www.fenixfinance.io/liquidity',
};

0 comments on commit 953e937

Please sign in to comment.