From 5c4f49cbadb327e8499c0f73c02fc7719af961ef Mon Sep 17 00:00:00 2001 From: dhruv035 Date: Tue, 25 Jan 2022 22:25:34 +0530 Subject: [PATCH 1/4] update idle --- projects/idle/abis/IdleCDO.json | 15 ++++++++ projects/idle/index.js | 67 +++++++++++++++++++++++++++++++-- 2 files changed, 79 insertions(+), 3 deletions(-) create mode 100644 projects/idle/abis/IdleCDO.json diff --git a/projects/idle/abis/IdleCDO.json b/projects/idle/abis/IdleCDO.json new file mode 100644 index 00000000..e350e397 --- /dev/null +++ b/projects/idle/abis/IdleCDO.json @@ -0,0 +1,15 @@ +{ + "getContractValue" : { + "inputs": [], + "name": "getContractValue", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + } +} \ No newline at end of file diff --git a/projects/idle/index.js b/projects/idle/index.js index cd64f4b2..4b671a4c 100644 --- a/projects/idle/index.js +++ b/projects/idle/index.js @@ -3,6 +3,7 @@ const BigNumber = require('bignumber.js'); const COMP_abi = require('./abis/COMP.json'); const IdleTokenV4 = require('./abis/IdleTokenV4.json'); const IdleTokenV3 = require('./abis/IdleTokenV3.json'); +const IdleCDO= require('./abis/IdleCDO.json'); const BNify = n => new BigNumber(n); const web3Call = async (block,target,abi,params=null) => { @@ -16,7 +17,36 @@ const web3Call = async (block,target,abi,params=null) => { } // Idle tokens info +const tranches={ + idleDAICDO: { + abi: IdleCDO, + underlyingToken:'DAI', + address: '0xd0DbcD556cA22d3f3c142e9a3220053FD7a247BC' + }, + idleFEICDO: { + abi: IdleCDO, + underlyingToken:'FEI', + address: '0x77648a2661687ef3b05214d824503f6717311596' + }, + +} const contracts = { + + idleWETHYieldV4: { + abi: IdleTokenV4, + underlyingToken: 'WETH', + address: '0xC8E6CA6E96a326dC448307A5fDE90a0b21fd7f80', + }, + idleRAIYieldV4: { + abi: IdleTokenV4, + underlyingToken: 'RAI', + address: '0x5C960a3DCC01BE8a0f49c02A8ceBCAcf5D07fABe', + }, + idleFEIYieldV4: { + abi: IdleTokenV4, + underlyingToken: 'FEI', + address: '0xb2d5CB72A621493fe83C6885E4A776279be595bC', + }, idleDAIYieldV4:{ abi:IdleTokenV4, underlyingToken:'DAI', @@ -111,6 +141,19 @@ const contracts = { // Underlying tokens contracts const underlyingTokens = { + + FEI: { + decimals: 18, + address: '0x956f47f50a910163d8bf957cf5846d573e7f87ca', + }, + RAI: { + decimals: 18, + address: '0x03ab458634910aad20ef5f1c8ee96f1d6ac54919', + }, + WETH: { + decimals: 18, + address: '0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2', + }, DAI: { decimals:18, address:'0x6b175474e89094c44da98b954eedeac495271d0f', @@ -146,6 +189,7 @@ async function tvl(timestamp, block) { const calls = []; Object.keys(contracts).forEach( (contractName) => { + const call = new Promise( async (resolve, reject) => { const tokenBalances = {}; @@ -193,6 +237,23 @@ async function tvl(timestamp, block) { calls.push(call); }); + Object.keys(tranches).forEach((trancheName) => { + const call = new Promise( async (resolve, reject) => { + const tokenBalances={}; + const contractInfo= tranches[trancheName] + const tokenDecimals=underlyingTokens[contractInfo.underlyingToken].decimals; + const underlyingTokenAddr=underlyingTokens[contractInfo.underlyingToken].address; + let contractValue= await web3Call(block,contractInfo.address,contractInfo.abi.getContractValue); + if(contractValue) + { + let tokenTVL=BNify(contractValue); + tokenBalances[underlyingTokenAddr] = tokenTVL; + } + resolve(tokenBalances) + }); + calls.push(call) + }); + const balances = {}; const tokensBalances = await Promise.all(calls); @@ -211,9 +272,9 @@ async function tvl(timestamp, block) { module.exports = { tvl, - token: "IDLE", + token: null, start: 1605817213, name: 'Idle Finance', - category: 'Lending', + category: 'lending', website: 'https://idle.finance' -}; +}; \ No newline at end of file From 415eea19f16a8c9c7922d8ef4c45f8a9a1463948 Mon Sep 17 00:00:00 2001 From: dhruv035 Date: Tue, 25 Jan 2022 22:29:51 +0530 Subject: [PATCH 2/4] token --- projects/idle/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/idle/index.js b/projects/idle/index.js index 4b671a4c..f0302077 100644 --- a/projects/idle/index.js +++ b/projects/idle/index.js @@ -272,7 +272,7 @@ async function tvl(timestamp, block) { module.exports = { tvl, - token: null, + token: "IDLE", start: 1605817213, name: 'Idle Finance', category: 'lending', From 05f7d610e3444a31fab6fd57eacf13c5f2ba5cdf Mon Sep 17 00:00:00 2001 From: Samster91 Date: Wed, 2 Feb 2022 11:54:40 +0100 Subject: [PATCH 3/4] NEW: added tranches --- projects/idle/index.js | 80 ++++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 26 deletions(-) diff --git a/projects/idle/index.js b/projects/idle/index.js index f0302077..72fbbde3 100644 --- a/projects/idle/index.js +++ b/projects/idle/index.js @@ -1,9 +1,9 @@ const sdk = require('../../sdk'); const BigNumber = require('bignumber.js'); const COMP_abi = require('./abis/COMP.json'); +const IdleCDO= require('./abis/IdleCDO.json'); const IdleTokenV4 = require('./abis/IdleTokenV4.json'); const IdleTokenV3 = require('./abis/IdleTokenV3.json'); -const IdleCDO= require('./abis/IdleCDO.json'); const BNify = n => new BigNumber(n); const web3Call = async (block,target,abi,params=null) => { @@ -17,7 +17,7 @@ const web3Call = async (block,target,abi,params=null) => { } // Idle tokens info -const tranches={ +const tranches = { idleDAICDO: { abi: IdleCDO, underlyingToken:'DAI', @@ -28,10 +28,24 @@ const tranches={ underlyingToken:'FEI', address: '0x77648a2661687ef3b05214d824503f6717311596' }, - -} -const contracts = { + idleStEthCDO: { + abi: IdleCDO, + underlyingToken:'STETH', + address: '0x34dcd573c5de4672c8248cd12a99f875ca112ad8' + }, + idleMIMCDO: { + abi: IdleCDO, + underlyingToken:'MIM', + address: '0x151e89e117728ac6c93aae94c621358b0ebd1866' + }, + idleFRAXCDO: { + abi: IdleCDO, + underlyingToken:'FRAX', + address: '0x4ccaf1392a17203edab55a1f2af3079a8ac513e7' + } +}; +const contracts = { idleWETHYieldV4: { abi: IdleTokenV4, underlyingToken: 'WETH', @@ -141,7 +155,18 @@ const contracts = { // Underlying tokens contracts const underlyingTokens = { - + MIM: { + decimals: 18, + address: '0x99d8a9c45b2eca8864373a26d1459e3dff1e17f3', + }, + FRAX: { + decimals: 18, + address: '0x853d955acef822db058eb8505911ed77f175b99e', + }, + STETH: { + decimals: 18, + address: '0xae7ab96520de3a18e5e111b5eaab095312d7fe84', + }, FEI: { decimals: 18, address: '0x956f47f50a910163d8bf957cf5846d573e7f87ca', @@ -211,16 +236,6 @@ async function tvl(timestamp, block) { if (totalSupply && tokenPrice){ let tokenTVL = BNify(totalSupply).div(1e18).times(BNify(tokenPrice).div(`1e${tokenDecimals}`)); - - // Get unlent funds - if (underlyingTokenBalance){ - underlyingTokenBalance = BNify(underlyingTokenBalance); - if (!underlyingTokenBalance.isNaN() && underlyingTokenBalance.gt(0)){ - underlyingTokenBalance = underlyingTokenBalance.div(`1e${tokenDecimals}`); - tokenTVL = tokenTVL.plus(underlyingTokenBalance); - } - } - tokenTVL = tokenTVL.times(`1e${tokenDecimals}`); tokenBalances[underlyingTokenAddr] = tokenTVL; } @@ -239,17 +254,16 @@ async function tvl(timestamp, block) { Object.keys(tranches).forEach((trancheName) => { const call = new Promise( async (resolve, reject) => { - const tokenBalances={}; - const contractInfo= tranches[trancheName] - const tokenDecimals=underlyingTokens[contractInfo.underlyingToken].decimals; - const underlyingTokenAddr=underlyingTokens[contractInfo.underlyingToken].address; - let contractValue= await web3Call(block,contractInfo.address,contractInfo.abi.getContractValue); - if(contractValue) - { - let tokenTVL=BNify(contractValue); + const tokenBalances = {}; + const contractInfo = tranches[trancheName]; + const tokenDecimals = underlyingTokens[contractInfo.underlyingToken].decimals; + const underlyingTokenAddr = underlyingTokens[contractInfo.underlyingToken].address; + let contractValue = await web3Call(block,contractInfo.address,contractInfo.abi.getContractValue); + if(contractValue) { + let tokenTVL = BNify(contractValue); tokenBalances[underlyingTokenAddr] = tokenTVL; } - resolve(tokenBalances) + resolve(tokenBalances); }); calls.push(call) }); @@ -257,7 +271,6 @@ async function tvl(timestamp, block) { const balances = {}; const tokensBalances = await Promise.all(calls); - tokensBalances.forEach( tokenBalances => { Object.keys(tokenBalances).forEach( tokenAddr => { if (!balances[tokenAddr]){ @@ -267,6 +280,21 @@ async function tvl(timestamp, block) { }); }); + /* + let totalBalance = BNify(0); + Object.keys(balances).forEach( tokenAddr => { + const underlyingToken = Object.keys(underlyingTokens).find( uToken => underlyingTokens[uToken].address === tokenAddr ); + if (!underlyingToken){ + return; + } + const tokenConfig = underlyingTokens[underlyingToken]; + const tokenBalance = balances[tokenAddr].div(`1e${tokenConfig.decimals}`); + totalBalance = totalBalance.plus(tokenBalance); + console.log(underlyingToken,tokenBalance.toFixed(5)); + }); + console.log('Total: '+totalBalance.toFixed(5)); + */ + return balances; } From bceddaa8a9b31b3de1652a203347273206cc8f55 Mon Sep 17 00:00:00 2001 From: Samster91 Date: Wed, 2 Feb 2022 11:59:08 +0100 Subject: [PATCH 4/4] FIX: category --- projects/idle/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/projects/idle/index.js b/projects/idle/index.js index 72fbbde3..c55c18ae 100644 --- a/projects/idle/index.js +++ b/projects/idle/index.js @@ -303,6 +303,6 @@ module.exports = { token: "IDLE", start: 1605817213, name: 'Idle Finance', - category: 'lending', + category: 'Lending', website: 'https://idle.finance' }; \ No newline at end of file