From 31df78061240b1278119e2ed3abe6ce0c6fc1b14 Mon Sep 17 00:00:00 2001 From: paweenpit Date: Tue, 28 Oct 2025 01:09:37 +0700 Subject: [PATCH 1/2] feat: infinit --- src/adaptors/infinit/index.js | 105 ++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) create mode 100644 src/adaptors/infinit/index.js diff --git a/src/adaptors/infinit/index.js b/src/adaptors/infinit/index.js new file mode 100644 index 0000000000..672ae4990f --- /dev/null +++ b/src/adaptors/infinit/index.js @@ -0,0 +1,105 @@ +const axios = require('axios'); +const utils = require('../utils'); +const sdk = require('@defillama/sdk'); + +const API_BASE_URL = 'https://api.infinit.tech/nexus/strategy'; +const CHAINS_API_URL = 'https://api.llama.fi/chains'; + +const zeroAddress = '0x0000000000000000000000000000000000000000' + +const fetchChainInfos = async () => { + const response = await axios.get(CHAINS_API_URL); + return response.data; +}; + +const fetchStrategies = async () => { + const response = await axios.get(API_BASE_URL); + const strategies = response.data.strategies.filter((s) => s.status === "ACTIVE"); + return strategies; +}; + +const fetchStrategyDetails = async (strategyId) => { + const response = await axios.get(`${API_BASE_URL}/${strategyId}`); + return response.data; +}; + +const extractApyBase = (yields, strategyId) => { + const apys = yields.filter((y) => y.type === 'APY').map((y) => y.value); + + if (apys.length > 1) { + throw new Error(`Expected 0 or 1 APY base, got ${apys.length}`); + } + + return apys.length > 0 ? apys[0] : 0; +}; + +const getChainInfo = (chainId, chainInfos) => { + const chainInfo = chainInfos.find((c) => c.chainId === chainId); + if (!chainInfo) { + throw new Error(`ChainInfo not found for chainId: ${chainId}`); + } + return chainInfo +}; + + +const getApy = async () => { + const [chainInfos, strategies] = await Promise.all([ + fetchChainInfos(), + fetchStrategies(), + ]); + + const poolPromises = strategies.map(async (strategy) => + { + try { + const strategyId = strategy.strategyId; + const strategyInfo = await fetchStrategyDetails(strategyId); + + if (!strategyInfo) { + throw new Error(`Strategy not found for strategyId: ${strategyId}`); + } + + const apyBase = extractApyBase(strategyInfo.yields, strategyId); + + const userInput = strategyInfo.userInputs.planInput['1'].amount.info; + const chainInfo = getChainInfo(userInput.chainId, chainInfos); + const chain = chainInfo.name.toLowerCase(); + const tokenAddress = userInput.address; + const underlyingTokens = [tokenAddress]; + + // handle bsc chain id for llama sdk + const llamaChain = userInput.chainId === 56 ? 'bsc' : chain + + const symbol = tokenAddress === zeroAddress ? chainInfo.tokenSymbol : (await sdk.api.abi.call({ + target: tokenAddress, + abi: 'erc20:symbol', + chain: llamaChain, + })).output; + + + return { + pool: `${strategyInfo.strategyName} (${strategy.strategyId})`, + project: 'infinit', + symbol, + chain, + tvlUsd: strategyInfo.tvl ?? 0, + apyBase, + underlyingTokens, + url: `${API_BASE_URL}/${strategyId}`, + }; + } catch (error) { + console.error(`Error processing strategy ${strategy.strategyId}:`, error.message); + return null; + } + } + ); + + const pools = await Promise.all(poolPromises); + + // Filter out failed strategies (null values) + return pools.filter((pool) => pool !== null); +}; + +module.exports = { + apy: getApy, + url: 'https://app.infinit.tech', +}; \ No newline at end of file From fe7a84210ded49908726da109ed19f0e709d8dfc Mon Sep 17 00:00:00 2001 From: paweenpit Date: Wed, 29 Oct 2025 15:31:44 +0700 Subject: [PATCH 2/2] fix: update url --- src/adaptors/infinit/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/adaptors/infinit/index.js b/src/adaptors/infinit/index.js index 672ae4990f..fa6c16a492 100644 --- a/src/adaptors/infinit/index.js +++ b/src/adaptors/infinit/index.js @@ -2,6 +2,7 @@ const axios = require('axios'); const utils = require('../utils'); const sdk = require('@defillama/sdk'); +const INFINIT_URL = 'https://app.infinit.tech/en/strategy'; const API_BASE_URL = 'https://api.infinit.tech/nexus/strategy'; const CHAINS_API_URL = 'https://api.llama.fi/chains'; @@ -84,7 +85,7 @@ const getApy = async () => { tvlUsd: strategyInfo.tvl ?? 0, apyBase, underlyingTokens, - url: `${API_BASE_URL}/${strategyId}`, + url: `${INFINIT_URL}/${strategyId}`, }; } catch (error) { console.error(`Error processing strategy ${strategy.strategyId}:`, error.message);