Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add fenix v3 and v2 pools #1671

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
118 changes: 118 additions & 0 deletions src/adaptors/fenix-concentrated-liquidity/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
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 = 0;

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

tvl = token0ValueInReserve + token1ValueInReserve;

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;
});
console.log(pools);
return pools;
} catch (error) {
console.error('Error in getApy:', error);
throw error;
}
};
getApy();
module.exports = {
timetravel: false,
apy: getApy,
url: 'https://www.fenixfinance.io/liquidity',
};
Loading