|
| 1 | +const utils = require('../utils'); |
| 2 | +const sdk = require('@defillama/sdk'); |
| 3 | +const ethers = require('ethers'); |
| 4 | +const { config } = require('./config'); |
| 5 | +const BigNumber = require('bignumber.js'); |
| 6 | + |
| 7 | +// function getEstimatedAPR is misleading, it returns the estimated APY |
| 8 | +const getEstimatedAPR = |
| 9 | + 'function estimatedAPR() external view returns (uint256)'; |
| 10 | +const getTotalAssets = 'function totalAssets() external view returns (uint256)'; |
| 11 | + |
| 12 | +const getsUSDpData = async (chain, chainConfig) => { |
| 13 | + const { chainName, USDp, sUSDp } = chainConfig; |
| 14 | + let estimatedAPY; |
| 15 | + let totalAssets; |
| 16 | + if (chain === 'hyperevm') { |
| 17 | + const provider = new ethers.providers.JsonRpcProvider( |
| 18 | + 'https://rpc.hyperliquid.xyz/evm' |
| 19 | + ); |
| 20 | + const abi = [getEstimatedAPR, getTotalAssets]; |
| 21 | + const contract = new ethers.Contract(sUSDp, abi, provider); |
| 22 | + [estimatedAPY, totalAssets] = await Promise.all([ |
| 23 | + contract.estimatedAPR(), |
| 24 | + contract.totalAssets(), |
| 25 | + ]); |
| 26 | + } else { |
| 27 | + const api = new sdk.ChainApi({ chain }); |
| 28 | + [estimatedAPY, totalAssets] = await Promise.all([ |
| 29 | + api.call({ |
| 30 | + abi: getEstimatedAPR, |
| 31 | + target: sUSDp, |
| 32 | + }), |
| 33 | + api.call({ |
| 34 | + abi: getTotalAssets, |
| 35 | + target: sUSDp, |
| 36 | + }), |
| 37 | + ]); |
| 38 | + } |
| 39 | + |
| 40 | + const tvlUsd = new BigNumber( |
| 41 | + ethers.utils.formatUnits(totalAssets, 18) |
| 42 | + ).toNumber(); |
| 43 | + const apyBase = new BigNumber( |
| 44 | + ethers.utils.formatUnits(estimatedAPY, 16) |
| 45 | + ).toNumber(); |
| 46 | + |
| 47 | + return { |
| 48 | + pool: `${sUSDp}-parallel-v3`.toLowerCase(), |
| 49 | + chain: utils.formatChain(chainName), |
| 50 | + project: 'parallel-protocol-v3', |
| 51 | + symbol: 'sUSDp', |
| 52 | + tvlUsd: tvlUsd, |
| 53 | + apyBase: apyBase, |
| 54 | + rewardTokens: [USDp], |
| 55 | + underlyingTokens: [USDp], |
| 56 | + poolMeta: 'saving', |
| 57 | + }; |
| 58 | +}; |
| 59 | + |
| 60 | +const main = async () => { |
| 61 | + const markets = []; |
| 62 | + for (let [chain, data] of Object.entries(config)) { |
| 63 | + const result = await getsUSDpData(chain, data); |
| 64 | + markets.push(result); |
| 65 | + } |
| 66 | + return markets; |
| 67 | +}; |
| 68 | + |
| 69 | +module.exports = { |
| 70 | + timetravel: false, |
| 71 | + apy: main, |
| 72 | + url: 'https://app.parallel.best/earn', |
| 73 | +}; |
0 commit comments