diff --git a/src/adaptors/rocky/config.js b/src/adaptors/rocky/config.js new file mode 100644 index 0000000000..4fc289b5ad --- /dev/null +++ b/src/adaptors/rocky/config.js @@ -0,0 +1,9 @@ +const config = { + sei: { + chainName: 'sei', + USDr: '0x53fdd705873d8259d6d179901fc3fdcb5339f921', + sUSDr: '0xc0029b98f09c9062056c14c0329d3a114a098617', + }, +}; + +module.exports = { config }; diff --git a/src/adaptors/rocky/index.js b/src/adaptors/rocky/index.js new file mode 100644 index 0000000000..f12964e4ab --- /dev/null +++ b/src/adaptors/rocky/index.js @@ -0,0 +1,61 @@ +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 getsUSDrData = async (chain, chainConfig) => { + const { chainName, USDr, sUSDr } = chainConfig; + let estimatedAPY; + let totalAssets; + const api = new sdk.ChainApi({ chain }); + [estimatedAPY, totalAssets] = await Promise.all([ + api.call({ + abi: getEstimatedAPR, + target: sUSDr, + }), + api.call({ + abi: getTotalAssets, + target: sUSDr, + }), + ]); + + const tvlUsd = new BigNumber( + ethers.utils.formatUnits(totalAssets, 18) + ).toNumber(); + const apyBase = new BigNumber( + ethers.utils.formatUnits(estimatedAPY, 16) + ).toNumber(); + + return { + pool: `${sUSDr}-rocky`.toLowerCase(), + chain: utils.formatChain(chainName), + project: 'rocky', + symbol: 'sUSDr', + tvlUsd: tvlUsd, + apyBase: apyBase, + rewardTokens: [USDr], + underlyingTokens: [USDr], + poolMeta: 'saving', + }; +}; + +const main = async () => { + const markets = []; + for (let [chain, data] of Object.entries(config)) { + const result = await getsUSDrData(chain, data); + markets.push(result); + } + return markets; +}; + +module.exports = { + timetravel: false, + apy: main, + url: 'https://app.rocky.cash/earn', +};