Skip to content

Commit

Permalink
Add special threshold for clm vaults
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Sep 10, 2024
1 parent 31d71fc commit dfa0062
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ const defaultUnwrapConfig: RpcConfig['unwrap'] = {
const defaultHarvestConfig: RpcConfig['harvest'] = {
enabled: true,
minTvlThresholdUsd: 100,
minClmTvlThresholdUsd: 100,
parallelSimulations: 5,
profitabilityCheck: {
enabled: false,
Expand Down Expand Up @@ -342,6 +343,7 @@ export const RPC_CONFIG: Record<Chain, RpcConfig> = {
harvest: {
...defaultHarvestConfig,
minTvlThresholdUsd: 10_000,
minClmTvlThresholdUsd: 1_000,
profitabilityCheck: {
...defaultHarvestConfig.profitabilityCheck,
enabled: true,
Expand Down
14 changes: 13 additions & 1 deletion src/lib/harvest-chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,19 @@ export async function harvestChain({
};
}

if (item.vault.tvlUsd < rpcConfig.harvest.minTvlThresholdUsd) {
// TVL checks
if (item.vault.isClmVault) {
// clm vaults have a dedicated threshold
if (item.vault.tvlUsd < rpcConfig.harvest.minClmTvlThresholdUsd) {
return {
shouldHarvest: false,
level: 'info',
tvlThresholdUsd: rpcConfig.harvest.minClmTvlThresholdUsd,
vaultTvlUsd: item.vault.tvlUsd,
notHarvestingReason: 'Tvl do not meet minimum threshold',
};
}
} else if (item.vault.tvlUsd < rpcConfig.harvest.minTvlThresholdUsd) {
// make sure to harvest CLMs at least once per 24 hours regardless if $100 or more is in them.
if (!item.vault.isClmManager) {
return {
Expand Down
2 changes: 2 additions & 0 deletions src/lib/rpc-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ export type RpcConfig = {

// We only harvest if the vault tvl is above this threshold
minTvlThresholdUsd: number;
// special threshold for clm
minClmTvlThresholdUsd: number;

// wether we should set the transaction gas limit
setTransactionGasLimit: boolean;
Expand Down
20 changes: 17 additions & 3 deletions src/lib/vault-list.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import axios from 'axios';
import { groupBy, mapValues, uniqBy } from 'lodash';
import { groupBy, keyBy, mapValues, uniqBy } from 'lodash';
import type { Hex } from 'viem';
import { rootLogger } from '../util/logger';
import type { Chain } from './chain';
Expand All @@ -9,18 +9,22 @@ import type { BeefyVault, StrategyTypeId } from './vault';
const logger = rootLogger.child({ module: 'vault-list' });

async function fetchVaults(): Promise<BeefyVault[]> {
type ApiBeefyVaultResponse = {
type ApiBeefyVault = {
id: string;
name: string;
status: 'eol' | 'active' | 'paused';
tokenAddress?: string; // the want address
earnedTokenAddress?: string; // the vault address
strategy: string;
chain: Chain;
platformId: string;
lastHarvest: number;
type?: 'cowcentrated';
strategyTypeId: StrategyTypeId;
// + some other fields we don't care about
}[];
};

type ApiBeefyVaultResponse = ApiBeefyVault[];

type ApiBeefyTvlResponse = {
[key: string]: {
Expand All @@ -33,6 +37,13 @@ async function fetchVaults(): Promise<BeefyVault[]> {
`${BEEFY_API_URL}/harvestable-vaults?_cache_buster=${Date.now()}`
);
const rawVaults = vaultResponse.data;
const rawVaultsByAddress = keyBy(
rawVaults.filter(v => v.earnedTokenAddress),
v => `${v.chain}:${v.earnedTokenAddress?.toLocaleLowerCase()}`
);
const getClmFromVault = (vault: ApiBeefyVault): ApiBeefyVault | null => {
return rawVaultsByAddress[`${vault.chain}:${vault.tokenAddress?.toLocaleLowerCase()}`] ?? null;
};

const tvlResponse = await axios.get<ApiBeefyTvlResponse>(`${BEEFY_API_URL}/tvl?_cache_buster=${Date.now()}`);
const rawTvlByChains = tvlResponse.data;
Expand All @@ -41,6 +52,8 @@ async function fetchVaults(): Promise<BeefyVault[]> {
// map to a simpler format
return rawVaults.map(vault => {
const isClmManager = vault.type === 'cowcentrated';
const isClmVault = getClmFromVault(vault) !== null;

let tvlUsd = rawTvls[vault.id] || 0;
if (ADD_RP_TVL_TO_CLM_TVL && isClmManager) {
const rpVaultId = `${vault.id}-rp`;
Expand All @@ -64,6 +77,7 @@ async function fetchVaults(): Promise<BeefyVault[]> {
lastHarvest: new Date(vault.lastHarvest * 1000),
strategyTypeId: vault.strategyTypeId || null,
isClmManager,
isClmVault,
};
});
}
Expand Down
1 change: 1 addition & 0 deletions src/lib/vault.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ export type BeefyVault = {
lastHarvest: Date | null;
strategyTypeId: StrategyTypeId | null;
isClmManager: boolean;
isClmVault: boolean;
};

0 comments on commit dfa0062

Please sign in to comment.