-
Notifications
You must be signed in to change notification settings - Fork 831
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add fenix v3 and v2 pools (#1671)
* 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
1 parent
953e937
commit 411c014
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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', | ||
}; |