From fbed3f1218d41ce221b20c4c8ad9d5726a28693c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Pr=C3=A9vost?= <998369+prevostc@users.noreply.github.com> Date: Wed, 17 Jul 2024 23:55:38 +0200 Subject: [PATCH] Fix cow vault tvl --- src/lib/config.ts | 3 +++ src/lib/vault-list.ts | 32 +++++++++++++++++++++----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/lib/config.ts b/src/lib/config.ts index 161ad0c..491d46c 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -34,6 +34,9 @@ export const DISABLE_COLLECTOR_FOR_CHAINS: Chain[] = ( ).filter(chain => allChainIds.includes(chain as Chain)) as Chain[]; export const DISCORD_REPORT_WEBHOOK_URL = process.env.DISCORD_REPORT_WEBHOOK_URL || null; export const DISCORD_REPORT_ONLY_FOR_CHAINS: Chain[] = ['fraxtal', 'mode', 'scroll', 'manta']; + +export const ADD_RP_TVL_TO_CLM_TVL = process.env.ADD_RP_TVL_TO_CLM_TVL === 'true'; + export const DISCORD_RATE_LIMIT_MIN_SECONDS_BETWEEN_REQUESTS = Number.parseInt( process.env.DISCORD_RATE_LIMIT_MIN_SECONDS_BETWEEN_REQUESTS || '10', 10 diff --git a/src/lib/vault-list.ts b/src/lib/vault-list.ts index 1c4cb80..3730add 100644 --- a/src/lib/vault-list.ts +++ b/src/lib/vault-list.ts @@ -3,7 +3,7 @@ import { groupBy, mapValues, uniqBy } from 'lodash'; import type { Hex } from 'viem'; import { rootLogger } from '../util/logger'; import type { Chain } from './chain'; -import { BEEFY_API_URL } from './config'; +import { ADD_RP_TVL_TO_CLM_TVL, BEEFY_API_URL } from './config'; import type { BeefyVault, StrategyTypeId } from './vault'; const logger = rootLogger.child({ module: 'vault-list' }); @@ -17,6 +17,7 @@ async function fetchVaults() { chain: Chain; platformId: string; lastHarvest: number; + type?: 'cowcentrated'; strategyTypeId: StrategyTypeId; // + some other fields we don't care about }[]; @@ -36,16 +37,25 @@ async function fetchVaults() { const rawTvls = Object.values(rawTvlByChains).reduce((acc, tvl) => Object.assign({}, acc, tvl), {}); // map to a simpler format - return rawVaults.map(vault => ({ - id: vault.id, - eol: vault.status === 'eol', - chain: vault.chain, - strategyAddress: vault.strategy as Hex, - platformId: vault.platformId, - tvlUsd: rawTvls[vault.id] || 0, - lastHarvest: new Date(vault.lastHarvest * 1000), - strategyTypeId: vault.strategyTypeId || null, - })); + return rawVaults.map(vault => { + let tvlUsd = rawTvls[vault.id] || 0; + if (ADD_RP_TVL_TO_CLM_TVL && vault.type === 'cowcentrated') { + const rpVaultId = `${vault.id}-rp`; + const rpTvl = rawTvls[rpVaultId] || 0; + tvlUsd += rpTvl; + } + + return { + id: vault.id, + eol: vault.status === 'eol', + chain: vault.chain, + strategyAddress: vault.strategy as Hex, + platformId: vault.platformId, + tvlUsd, + lastHarvest: new Date(vault.lastHarvest * 1000), + strategyTypeId: vault.strategyTypeId || null, + }; + }); } export async function getVault(options: {