Skip to content
Merged
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
40 changes: 20 additions & 20 deletions src/adaptors/harmonix-finance/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const axios = require('axios');
const sdk = require('@defillama/sdk');
const ethers = require('ethers');
const utils = require('../utils')

// ABI for totalValueLocked function
Expand Down Expand Up @@ -70,28 +69,26 @@ const getApy = async () => {
});

const pools = await Promise.all(response.data.map(async vault => {
return Promise.all(vault.vaults.map(async v => {
return Promise.allSettled(vault.vaults.map(async v => {
const chainId = chains[v.network_chain];
let tvlUsd = 0

if (chainId === 'hyperliquid') {
const provider = new ethers.providers.JsonRpcProvider("https://rpc.hyperliquid.xyz/evm");

const contractAddress = "0xe9d69CdD6Fe41e7B621B4A688C5D1a68cB5c8ADc";
const abi = [
"function getPriceUnsafe(bytes32) view returns (tuple(int64, uint64, int32, uint256))"
];

const priceFeed = "0x4279e31cc369bbcc2faf022b382b080e32a8e689ff20fbc530d2a603eb6cd98b";


const contract = new ethers.Contract(contractAddress, abi, provider);
const [price, conf, expo, timestamp] = await contract.getPriceUnsafe(priceFeed);
const normalizedPrice = Number(price) * 10 ** expo;


tvlUsd = normalizedPrice * v.tvl;

const token = assets[chainId]?.[v.vault_currency?.toLowerCase()];
if (!token)
throw new Error(
`harmonix-finance: no ${v.vault_currency} address on ${chainId}`
);
const tokenKey = `${chainId}:${token}`;
const priceData = await axios.get(
utils.getPriceApiUrl(`/prices/current/${tokenKey}`)
);
const tokenPrice = priceData.data.coins[tokenKey]?.price;
if (!tokenPrice)
throw new Error(
`harmonix-finance: no price for ${v.vault_currency} on ${chainId}`
);
tvlUsd = v.tvl * tokenPrice;
}
else {
const tvl = await getTvl(v.contract_address, chainId);
Expand Down Expand Up @@ -137,7 +134,10 @@ const getApy = async () => {
}));
}));

return pools.flat(); // flatten the array of pools
return pools.flat().flatMap(({ value, reason }) => {
if (reason) console.error(`harmonix-finance: skipping vault: ${reason}`);
return value ?? [];
});
};

module.exports = {
Expand Down
Loading