From 50df1caeb0f5c5be0f254069878cbfdbef074cac Mon Sep 17 00:00:00 2001 From: Shahul Hameed <10547529+shahthepro@users.noreply.github.com> Date: Fri, 26 May 2023 12:56:31 +0400 Subject: [PATCH 1/2] Add OETH --- src/adaptors/origin-ether/index.js | 31 ++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/adaptors/origin-ether/index.js diff --git a/src/adaptors/origin-ether/index.js b/src/adaptors/origin-ether/index.js new file mode 100644 index 0000000000..83b085fa17 --- /dev/null +++ b/src/adaptors/origin-ether/index.js @@ -0,0 +1,31 @@ +const utils = require('../utils'); + +const poolsFunction = async () => { + const apyData = await utils.getData( + 'https://analytics.ousd.com/api/v2/oeth/apr/trailing' + ); + const dataTvl = await utils.getData('https://api.llama.fi/tvl/origin-ether'); + + const oeth = { + pool: 'origin-ether', + chain: 'Ethereum', + project: 'origin-ether', + symbol: 'OETH', + tvlUsd: dataTvl, + apy: Number(apyData.apy), + underlyingTokens: [ + '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH + '0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84', // stETH + '0xae78736Cd615f374D3085123A210448E74Fc6393', // rETH + '0x5e8422345238f34275888049021821e8e08caa1f', // frxETH + ], + }; + + return [oeth]; +}; + +module.exports = { + timetravel: false, + apy: poolsFunction, + url: 'https://oeth.com', +}; From bed7d3f2089aef43c8ae734e033cd036a47463bb Mon Sep 17 00:00:00 2001 From: Shahul Hameed <10547529+shahthepro@users.noreply.github.com> Date: Fri, 26 May 2023 20:00:50 +0400 Subject: [PATCH 2/2] Read TVL from contract --- src/adaptors/origin-ether/index.js | 31 ++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/adaptors/origin-ether/index.js b/src/adaptors/origin-ether/index.js index 83b085fa17..a68a3cfbca 100644 --- a/src/adaptors/origin-ether/index.js +++ b/src/adaptors/origin-ether/index.js @@ -1,17 +1,40 @@ +const { ethers, Contract, BigNumber } = require('ethers'); const utils = require('../utils'); +const PROVIDER_URL = process.env.ALCHEMY_CONNECTION_ETHEREUM; + +const vaultABI = [ + 'function totalValue() view returns (uint256)', + 'function priceUnitRedeem(address asset) view returns (uint256)', +] + +const vaultAddress = '0x39254033945AA2E4809Cc2977E7087BEE48bd7Ab' + const poolsFunction = async () => { + const provider = new ethers.providers.JsonRpcProvider(PROVIDER_URL); + const vault = new Contract(vaultAddress, vaultABI, provider); + const apyData = await utils.getData( 'https://analytics.ousd.com/api/v2/oeth/apr/trailing' ); - const dataTvl = await utils.getData('https://api.llama.fi/tvl/origin-ether'); + const totalValueEth = await vault.totalValue(); + + const priceData = await utils.getData( + 'https://coins.llama.fi/prices/current/coingecko:ethereum?searchWidth=4h' + ); + const ethPrice = priceData.coins['coingecko:ethereum'].price + + const tvlUsd = totalValueEth + .mul(ethers.utils.parseEther(ethPrice.toString())) + .div(BigNumber.from('10').pow(36 - 8)) + .toNumber() / 10**8 - const oeth = { + const oethData = { pool: 'origin-ether', chain: 'Ethereum', project: 'origin-ether', symbol: 'OETH', - tvlUsd: dataTvl, + tvlUsd, apy: Number(apyData.apy), underlyingTokens: [ '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', // WETH @@ -21,7 +44,7 @@ const poolsFunction = async () => { ], }; - return [oeth]; + return [oethData]; }; module.exports = {