From 882b5f3eabc86c82e5526789fd9ddd49a8fde407 Mon Sep 17 00:00:00 2001 From: 0xpeluche <0xpeluche@proton.me> Date: Wed, 11 Dec 2024 09:50:54 +0100 Subject: [PATCH] fix stakewise v2 --- projects/stakewise/index.js | 70 ++++++++++++++++++------------------- 1 file changed, 34 insertions(+), 36 deletions(-) diff --git a/projects/stakewise/index.js b/projects/stakewise/index.js index a02caf992496..c44adcfbbefc 100644 --- a/projects/stakewise/index.js +++ b/projects/stakewise/index.js @@ -1,52 +1,50 @@ const ADDRESSES = require('../helper/coreAssets.json') -const sdk = require('@defillama/sdk'); const { getLogs } = require('../helper/cache/getLogs') -async function tvl(api) { - const lsBals = await api.multiCall({ abi: 'erc20:totalSupply', calls: ['0x20BC832ca081b91433ff6c17f85701B6e92486c5', '0xFe2e637202056d30016725477c5da089Ab0A043A']}) +const CONFIG = { + ethereum: { + rETH2: '0x20BC832ca081b91433ff6c17f85701B6e92486c5', + sETH2: '0xFe2e637202056d30016725477c5da089Ab0A043A', + validator: '0xEadCBA8BF9ACA93F627F31fB05470F5A0686CEca', + factory: '0x3a0008a588772446f6e656133c2d5029cc4fc20e', + blacklist: ['0x09e84205df7c68907e619d07afd90143c5763605'] + }, + xdai: { + GNO: '0x9c58bacc331c9aa871afd802db6379a98e80cedb', + sGNO: '0xA4eF9Da5BA71Cc0D2e5E877a910A37eC43420445' + } +} - const solosValidators = await getLogs({ - target: '0xEadCBA8BF9ACA93F627F31fB05470F5A0686CEca', - topic: 'ValidatorRegistered(bytes32,bytes,uint256,address)', - fromBlock: 11726299, - api - }) +const topic = { + validatorRegistered: 'ValidatorRegistered(bytes32,bytes,uint256,address)', + vaultAdded: 'VaultAdded(address,address)' +} + +const ethTvl = async (api) => { + const { rETH2, sETH2, validator, factory, blacklist } = CONFIG[api.chain] + const lsBals = await api.multiCall({ abi: 'erc20:totalSupply', calls: [rETH2, sETH2]}) + const solosValidators = await getLogs({ api, target: validator, topic: topic.validatorRegistered, fromBlock: 11726299 }) lsBals.push(solosValidators.length * 32e18) - const vaults = await getLogs({ - target: '0x3a0008a588772446f6e656133c2d5029cc4fc20e', - topic: 'VaultAdded(address,address)', - fromBlock: 18470078, - api - }) + const vaults = await getLogs({ api, target: factory, topic: topic.vaultAdded, fromBlock: 18470078 }) + const assets = await api.multiCall({ - calls: vaults.map(v=>({target:"0x"+v.topics[2].slice(26)})), + calls: vaults + .map(v => ({ target: "0x" + v.topics[2].slice(26) })) + .filter(call => !blacklist.includes(call.target.toLowerCase())), abi: "uint256:totalAssets" }) api.add(ADDRESSES.ethereum.WETH, assets.concat(lsBals)) } -async function xdaiTvl(timestamp, ethBlock, { xdai: block }) { - const chain = "xdai" - const supply = await sdk.api.erc20.totalSupply({ - target: '0xA4eF9Da5BA71Cc0D2e5E877a910A37eC43420445', - block, - chain - }) - - return { - [ADDRESSES.ethereum.GNO]: supply.output - } +const xdaiTvl = async (api) => { + const { GNO, sGNO } = CONFIG[api.chain] + const supply = await api.call({ target: sGNO, abi: 'erc20:totalSupply' }) + api.add(GNO, supply) } - - module.exports = { methodology: 'Counts ETH staked', - ethereum: { - tvl, - }, - xdai:{ - tvl: xdaiTvl - } -} + ethereum: { tvl: ethTvl }, + xdai: { tvl: xdaiTvl } +} \ No newline at end of file