Skip to content

Commit

Permalink
Fix cow vault tvl
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Jul 17, 2024
1 parent 7466b5c commit fbed3f1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 21 additions & 11 deletions src/lib/vault-list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' });
Expand All @@ -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
}[];
Expand All @@ -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: {
Expand Down

0 comments on commit fbed3f1

Please sign in to comment.