Skip to content

Commit

Permalink
Merge pull request #279 from prevostc/add-support-for-clm-vaults
Browse files Browse the repository at this point in the history
beefy : yield : Add CLM vault support
  • Loading branch information
0xroll authored Aug 12, 2024
2 parents f746ff0 + 81c1470 commit 963a327
Show file tree
Hide file tree
Showing 5 changed files with 274 additions and 63 deletions.
4 changes: 3 additions & 1 deletion adapters/beefy/hourly_blocks.csv
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@ number,timestamp
4784763,1716398064
5684890,1718771519
5784890,1718972096
6301186,1720005441
6301186,1720005441
7643069,1722689579
7848072,1723099948
4 changes: 3 additions & 1 deletion adapters/beefy/src/config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
export const BEEFY_VAULT_API = "https://api.beefy.finance/harvestable-vaults";
export const BEEFY_MOO_VAULT_API = "https://api.beefy.finance/vaults";
export const BEEFY_COW_VAULT_API = "https://api.beefy.finance/cow-vaults";
export const BEEFY_GOV_API = "https://api.beefy.finance/gov-vaults";
export const BEEFY_BOOST_API = "https://api.beefy.finance/boosts";

// subgraph source: https://github.com/beefyfinance/l2-lxp-liquidity-subgraph
export const BEEFY_SUBGRAPH_URL =
Expand Down
8 changes: 6 additions & 2 deletions adapters/beefy/src/sdk/breakdown/getVaultBreakdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import { BeefyViemClient, getViemClient } from "../viemClient";
import { getSolidlyVaultBreakdown } from "./protocol_type/solidly";
import { getGammaVaultBreakdown } from "./protocol_type/gamma";
import { getMendiVaultBreakdown } from "./protocol_type/mendi";
import { getBeefyClmVaultBreakdown } from "./protocol_type/beefy_clm";
import {
getBeefyClmManagerBreakdown,
getBeefyClmVaultBreakdown,
} from "./protocol_type/beefy_clm";

type BreakdownMethod = (
client: BeefyViemClient,
Expand All @@ -17,7 +20,8 @@ const breakdownMethods: Record<BeefyProtocolType, BreakdownMethod> = {
mendi: getMendiVaultBreakdown,
gamma: getGammaVaultBreakdown,
ichi: getGammaVaultBreakdown,
beefy_clm: getBeefyClmVaultBreakdown,
beefy_clm: getBeefyClmManagerBreakdown,
beefy_clm_vault: getBeefyClmVaultBreakdown,
};

export const getVaultBreakdowns = async (
Expand Down
41 changes: 40 additions & 1 deletion adapters/beefy/src/sdk/breakdown/protocol_type/beefy_clm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import { BeefyViemClient } from "../../viemClient";
import { BeefyVaultBreakdown } from "../types";
import { BeefyVaultConcLiqAbi } from "../../../abi/BeefyVaultConcLiq";
import { BeefyClmStrategyAbi } from "../../../abi/BeefyClmStrategy";
import { BeefyVaultV7Abi } from "../../../abi/BeefyVaultV7Abi";

export const getBeefyClmVaultBreakdown = async (
export const getBeefyClmManagerBreakdown = async (
client: BeefyViemClient,
blockNumber: bigint,
vault: BeefyVault
Expand Down Expand Up @@ -50,3 +51,41 @@ export const getBeefyClmVaultBreakdown = async (
],
};
};

export const getBeefyClmVaultBreakdown = async (
client: BeefyViemClient,
blockNumber: bigint,
vault: BeefyVault
): Promise<BeefyVaultBreakdown> => {
if (vault.protocol_type !== "beefy_clm_vault") {
throw new Error(`Invalid protocol type ${vault.protocol_type}`);
}

const underlyingClmBreakdown = await getBeefyClmManagerBreakdown(
client,
blockNumber,
vault.beefy_clm_manager
);

const vaultContract = getContract({
client,
address: vault.vault_address,
abi: BeefyVaultV7Abi,
});

const [balance, totalSupply] = await Promise.all([
vaultContract.read.balance({ blockNumber }),
vaultContract.read.totalSupply({ blockNumber }),
]);

return {
vault,
blockNumber,
vaultTotalSupply: totalSupply,
isLiquidityEligible: underlyingClmBreakdown.isLiquidityEligible,
balances: underlyingClmBreakdown.balances.map((tokenBalance) => ({
tokenAddress: tokenBalance.tokenAddress,
vaultBalance: (balance * tokenBalance.vaultBalance) / totalSupply,
})),
};
};
Loading

0 comments on commit 963a327

Please sign in to comment.