From cc8cfce26042450359fa58a01c6392ad78635524 Mon Sep 17 00:00:00 2001 From: g1nt0ki <99907941+g1nt0ki@users.noreply.github.com> Date: Tue, 14 Jan 2025 14:56:25 +0100 Subject: [PATCH] Add grow vault TVL calculation and refactor code (#13090) Co-authored-by: irlpotato <166589843+irlpotato@users.noreply.github.com> --- projects/treehouse/index.js | 82 +++++++++++++++++++++++++++++-------- projects/upshift/index.js | 2 +- 2 files changed, 67 insertions(+), 17 deletions(-) diff --git a/projects/treehouse/index.js b/projects/treehouse/index.js index 62478f3126fc..e01dc8495181 100644 --- a/projects/treehouse/index.js +++ b/projects/treehouse/index.js @@ -3,31 +3,81 @@ const { sumTokens2 } = require('../helper/unwrapLPs') async function getInFlightLidoRedemptionNav(api) { - const unStEth = '0x889edc2edab5f40e902b864ad4d7ade8e412f9b1'; - const strategy = '0x60d2D94aCB969CA54e781007eE89F04c1A2e5943'; + const unStEth = '0x889edc2edab5f40e902b864ad4d7ade8e412f9b1'; + const strategy = '0x60d2D94aCB969CA54e781007eE89F04c1A2e5943'; const navHelper = '0xf22Ca896427677507a9EF99D30B261659775ff56'; - const requestIds = await api.call({ - abi: "function getWithdrawalRequests(address _owner) external view returns (uint256[] memory requestsIds)", - target: unStEth, - chain: 'ethereum', - params: [strategy] -}); + const requestIds = await api.call({ + abi: "function getWithdrawalRequests(address _owner) external view returns (uint256[] memory requestsIds)", + target: unStEth, + chain: 'ethereum', + params: [strategy] + }); -// NAV of lido in-flight redemptions in wstETH. -const nav = await api.call({ - abi: 'function getLidoRedemptionsNav(uint[], address) external view returns (uint)', - target: navHelper, - chain: 'ethereum', - params: [requestIds, strategy] -}) + // NAV of lido in-flight redemptions in wstETH. + const nav = await api.call({ + abi: 'function getLidoRedemptionsNav(uint[], address) external view returns (uint)', + target: navHelper, + chain: 'ethereum', + params: [requestIds, strategy] + }) + + api.add(ADDRESSES.ethereum.WSTETH, nav) +} + +// count the value in the grow autovault and exclude the value of tETH in the vault to avoid double counting +async function addGrowAutovaultNav(api) { + const growVault = '0x5Fde59415625401278c4d41C6beFCe3790eb357f' + const dataVault = '0xaD744e7B3ae782b2c6DD6c316332d60ac33D8Db2' + + const tETHwstETHGauge = '0xf697535848B535900c76f70F1e36EC3985D27862' + const tETHwstETHLP = '0x1d13531bf6344c102280ce4c458781fbf14dad14' + const balVault = '0xBA12222222228d8Ba445958a75a0704d566BF2C8' + const tETH = '0xD11c452fc99cF405034ee446803b6F6c1F6d5ED8' + const tETHweWTHcurveLP = '0x394a1e1b934cb4F4a0dC17BDD592ec078741542F' + const tETHwstTHcurveLP = '0xA10d15538E09479186b4D3278BA5c979110dDdB1' + + + await api.sumTokens({ owners: [growVault, dataVault], tokens: [ADDRESSES.ethereum.WSTETH] }) + const [tETHwstETHGaugeBal, tETHweWTHcurveLPBal, tETHwstETHcurveLPBal, tEThwEETHLP_weethBal, tEThwstETHLP_wstethBal] = await api.multiCall({ + abi: 'erc20:balanceOf', calls: [ + { target: tETHwstETHGauge, params: dataVault }, + { target: tETHweWTHcurveLP, params: dataVault }, + { target: tETHwstTHcurveLP, params: dataVault }, + { target: ADDRESSES.ethereum.WEETH, params: tETHweWTHcurveLP }, + { target: ADDRESSES.ethereum.WSTETH, params: tETHwstTHcurveLP }, + ] + }) + + // resolve balancer LP + const balTokenSupply = await api.call({ abi: 'uint256:getActualSupply', target: tETHwstETHLP }) + const poolId = await api.call({ abi: 'function getPoolId() view returns (bytes32)', target: tETHwstETHLP }) + const [tokens, bals] = await api.call({ abi: 'function getPoolTokens(bytes32) view returns (address[], uint256[],uint256)', target: balVault, params: poolId }) + const balLPRatio = tETHwstETHGaugeBal / balTokenSupply + tokens.forEach((v, i) => { + if (v.toLowerCase() === tETHwstETHLP.toLowerCase()) return; + api.add(v, bals[i] * balLPRatio) + }) + + // resolve tETH-weETH curve LP + const tETHweWTHcurveLPSupply = await api.call({ abi: 'uint256:totalSupply', target: tETHweWTHcurveLP }) + const tETHweETHLPRatio = tETHweWTHcurveLPBal / tETHweWTHcurveLPSupply + api.add(ADDRESSES.ethereum.WEETH, tEThwEETHLP_weethBal * tETHweETHLPRatio) -api.add(ADDRESSES.ethereum.WSTETH, nav) + // resolve tETH-wstETH curve LP + const tETHwstETHLPSupply = await api.call({ abi: 'uint256:totalSupply', target: tETHwstTHcurveLP }) + const tETHwstETHLPRatio = tETHwstETHcurveLPBal / tETHwstETHLPSupply + api.add(ADDRESSES.ethereum.WSTETH, tEThwstETHLP_wstethBal * tETHwstETHLPRatio) + + + api.removeTokenBalance(tETH) } async function tvl(api) { + await addGrowAutovaultNav(api) + const vault = '0x551d155760ae96050439ad24ae98a96c765d761b' const tokens = await api.call({ abi: 'address[]:getAllowableAssets', target: vault }) await api.sumTokens({ owner: vault, tokens }) diff --git a/projects/upshift/index.js b/projects/upshift/index.js index 8bec8eecc567..00da92c31e50 100644 --- a/projects/upshift/index.js +++ b/projects/upshift/index.js @@ -1,6 +1,6 @@ const { sumERC4626VaultsExport } = require('../helper/erc4626') const config = { - ethereum: ["0xB7858b66dFA38b9Cb74d00421316116A7851c273", "0x80E1048eDE66ec4c364b4F22C8768fc657FF6A42", "0x18a5a3D575F34e5eBa92ac99B0976dBe26f9F869", "0xEBac5e50003d4B17Be422ff9775043cD61002f7f", "0xd684AF965b1c17D628ee0d77cae94259c41260F4", "0x5Fde59415625401278c4d41C6beFCe3790eb357f"], + ethereum: ["0xB7858b66dFA38b9Cb74d00421316116A7851c273", "0x80E1048eDE66ec4c364b4F22C8768fc657FF6A42", "0x18a5a3D575F34e5eBa92ac99B0976dBe26f9F869", "0xEBac5e50003d4B17Be422ff9775043cD61002f7f", "0xd684AF965b1c17D628ee0d77cae94259c41260F4",], avax: ["0x3408b22d8895753C9A3e14e4222E981d4E9A599E"], base: ["0x4e2D90f0307A93b54ACA31dc606F93FE6b9132d2"] }