Skip to content

Commit

Permalink
Feat: add fenix v3 and v2 pools (#1671)
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

* fix: tvl values

* fix:build
  • Loading branch information
starketh25 authored Dec 31, 2024
1 parent 953e937 commit 411c014
Showing 1 changed file with 112 additions and 0 deletions.
112 changes: 112 additions & 0 deletions src/adaptors/fenix-concentrated-liquidity/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
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-v3-dex/latest/gn';

const FNX_ADDRESS = '0x52f847356b38720B55ee18Cb3e094ca11C85A192';

const swapPairsQuery = (skip) => {
return gql`
query MyQuery {
pools(first: 100, skip: ${skip}, where: {totalValueLockedUSD_gt: 10000}) {
totalValueLockedToken0
totalValueLockedToken1
totalValueLockedUSD
token1 {
id
symbol
}
token0 {
id
symbol
}
id
}
}
`;
};

const getPairs = async () => {
try {
let pools = [];
let index = 0;
let res;

do {
res = await request(SUBGRAPH_URL, swapPairsQuery(index), {});

if (res.pools?.length > 0) {
pools = [...pools, ...res.pools];
}
index += res.pools?.length || 0;
} while (res.pools?.length > 0);

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

const getApy = async () => {
try {
const pairs = await getPairs();

const poolsRes = await axios.get(
`${API_URL}?${pairs.map((pair) => `pools=${pair.id}`).join('&')}`
);
// console.log('Pools rewards sample:', poolsRes.data);

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;

const apyDict = {};
for (const pool of poolsRes.data) {
const pairData = pairs.find(
(p) => p.id.toLowerCase() === pool.pool.toLowerCase()
);

if (pairData) {
const weeklyRewardInFNX = parseFloat(pool.rewardWei) / 1e18;
const annualRewardInFNX = weeklyRewardInFNX * 52;
const annualRewardUSD = annualRewardInFNX * fnxPriceUsd;
const tvl = parseFloat(pairData.totalValueLockedUSD);
apyDict[pool.pool.toLowerCase()] = (annualRewardUSD / tvl) * 100;
}
}

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

const poolData = {
pool: pair.id,
chain: utils.formatChain('blast'),
project: 'fenix-concentrated-liquidity',
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 poolData;
});
return pools;
} catch (error) {
console.error('Error in getApy:', error);
throw error;
}
};

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

0 comments on commit 411c014

Please sign in to comment.