diff --git a/src/adaptors/parallel-protocol-v3/config.js b/src/adaptors/parallel-protocol-v3/config.js new file mode 100644 index 0000000000..76f64c045f --- /dev/null +++ b/src/adaptors/parallel-protocol-v3/config.js @@ -0,0 +1,24 @@ +const config = { + ethereum: { + chainName: 'Ethereum', + USDp: '0x9B3a8f7CEC208e247d97dEE13313690977e24459', + sUSDp: '0x0d45b129dc868963025Db79A9074EA9c9e32Cae4', + }, + base: { + chainName: 'Base', + USDp: ' 0x76A9A0062ec6712b99B4f63bD2b4270185759dd5', + sUSDp: '0x472eD57b376fE400259FB28e5C46eB53f0E3e7E7', + }, + sonic: { + chainName: 'Sonic', + USDp: '0x08417cdb7F52a5021bB4eb6E0deAf3f295c3f182', + sUSDp: '0xe8a3DA6f5ed1cf04c58ac7f6A7383641e877517b', + }, + hyperevm: { + chainName: 'hyperevm', + USDp: '0xBE65F0F410A72BeC163dC65d46c83699e957D588', + sUSDp: '0x9B3a8f7CEC208e247d97dEE13313690977e24459', + }, +}; + +module.exports = { config }; diff --git a/src/adaptors/parallel-protocol-v3/index.js b/src/adaptors/parallel-protocol-v3/index.js new file mode 100644 index 0000000000..2c00e048a4 --- /dev/null +++ b/src/adaptors/parallel-protocol-v3/index.js @@ -0,0 +1,73 @@ +const utils = require('../utils'); +const sdk = require('@defillama/sdk'); +const ethers = require('ethers'); +const { config } = require('./config'); +const BigNumber = require('bignumber.js'); + +// function getEstimatedAPR is misleading, it returns the estimated APY +const getEstimatedAPR = + 'function estimatedAPR() external view returns (uint256)'; +const getTotalAssets = 'function totalAssets() external view returns (uint256)'; + +const getsUSDpData = async (chain, chainConfig) => { + const { chainName, USDp, sUSDp } = chainConfig; + let estimatedAPY; + let totalAssets; + if (chain === 'hyperevm') { + const provider = new ethers.providers.JsonRpcProvider( + 'https://rpc.hyperliquid.xyz/evm' + ); + const abi = [getEstimatedAPR, getTotalAssets]; + const contract = new ethers.Contract(sUSDp, abi, provider); + [estimatedAPY, totalAssets] = await Promise.all([ + contract.estimatedAPR(), + contract.totalAssets(), + ]); + } else { + const api = new sdk.ChainApi({ chain }); + [estimatedAPY, totalAssets] = await Promise.all([ + api.call({ + abi: getEstimatedAPR, + target: sUSDp, + }), + api.call({ + abi: getTotalAssets, + target: sUSDp, + }), + ]); + } + + const tvlUsd = new BigNumber( + ethers.utils.formatUnits(totalAssets, 18) + ).toNumber(); + const apyBase = new BigNumber( + ethers.utils.formatUnits(estimatedAPY, 16) + ).toNumber(); + + return { + pool: `${sUSDp}-parallel-v3`.toLowerCase(), + chain: utils.formatChain(chainName), + project: 'parallel-protocol-v3', + symbol: 'sUSDp', + tvlUsd: tvlUsd, + apyBase: apyBase, + rewardTokens: [USDp], + underlyingTokens: [USDp], + poolMeta: 'saving', + }; +}; + +const main = async () => { + const markets = []; + for (let [chain, data] of Object.entries(config)) { + const result = await getsUSDpData(chain, data); + markets.push(result); + } + return markets; +}; + +module.exports = { + timetravel: false, + apy: main, + url: 'https://app.parallel.best/earn', +};