From c2fe24aad44ff4b21fb6fc989eaab2657062535d Mon Sep 17 00:00:00 2001 From: t0rbik Date: Mon, 2 Dec 2024 15:39:22 +0100 Subject: [PATCH 1/2] apr for graph needs to be muled by 0.9 --- src/components/vaults/row/VaultInfo.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/vaults/row/VaultInfo.tsx b/src/components/vaults/row/VaultInfo.tsx index d480d2c7..98773619 100644 --- a/src/components/vaults/row/VaultInfo.tsx +++ b/src/components/vaults/row/VaultInfo.tsx @@ -191,7 +191,7 @@ export const VaultInfo = ({ vault }: VaultInfoProps) => { name: values[1], timestamp: parseInt(values[0]), formattedDate: dayjs.unix(parseInt(values[0])).format("MMM D"), - apr: +values[2] * 100, + apr: +values[2] * 100 * 0.9, // 10% fee for Alchemist }; }); return parsedData; From 7dc911e1cca551352ce75e964dc1dba66e94b7ac Mon Sep 17 00:00:00 2001 From: t0rbik Date: Mon, 2 Dec 2024 15:48:37 +0100 Subject: [PATCH 2/2] refactor so that multiplier has a var name --- src/components/vaults/row/VaultInfo.tsx | 3 ++- src/lib/middleware/aave.ts | 10 ++++++---- src/lib/middleware/common.ts | 2 ++ src/lib/middleware/frax.ts | 3 ++- src/lib/middleware/gearbox.ts | 3 ++- src/lib/middleware/jones.ts | 3 ++- src/lib/middleware/lido.ts | 3 ++- src/lib/middleware/rocketPool.ts | 3 ++- src/lib/middleware/vesper.ts | 3 ++- src/lib/middleware/yearn.ts | 3 ++- 10 files changed, 24 insertions(+), 12 deletions(-) create mode 100644 src/lib/middleware/common.ts diff --git a/src/components/vaults/row/VaultInfo.tsx b/src/components/vaults/row/VaultInfo.tsx index 98773619..57574b46 100644 --- a/src/components/vaults/row/VaultInfo.tsx +++ b/src/components/vaults/row/VaultInfo.tsx @@ -23,6 +23,7 @@ import { variants, } from "./motion"; import { AprHistoricalChart } from "./AprHistoricalChart"; +import { ALCHEMIST_FEE_MULTIPLIER } from "@/lib/middleware/common"; interface VaultInfoProps { vault: Vault; @@ -191,7 +192,7 @@ export const VaultInfo = ({ vault }: VaultInfoProps) => { name: values[1], timestamp: parseInt(values[0]), formattedDate: dayjs.unix(parseInt(values[0])).format("MMM D"), - apr: +values[2] * 100 * 0.9, // 10% fee for Alchemist + apr: +values[2] * 100 * ALCHEMIST_FEE_MULTIPLIER, }; }); return parsedData; diff --git a/src/lib/middleware/aave.ts b/src/lib/middleware/aave.ts index 92695591..2106273c 100644 --- a/src/lib/middleware/aave.ts +++ b/src/lib/middleware/aave.ts @@ -1,9 +1,11 @@ -import { AprFn } from "@/lib/config/metadataTypes"; - -import { SupportedChainId } from "@/lib/wagmi/wagmiConfig"; import { arbitrum, fantom, mainnet, optimism } from "viem/chains"; import { gql, request } from "graphql-request"; +import { AprFn } from "@/lib/config/metadataTypes"; +import { SupportedChainId } from "@/lib/wagmi/wagmiConfig"; + +import { ALCHEMIST_FEE_MULTIPLIER } from "./common"; + const aaveApiParams = { [mainnet.id]: { url: `https://gateway-arbitrum.network.thegraph.com/api/${import.meta.env.VITE_SUBGRAPH_API_KEY}/subgraphs/id/8wR23o1zkS4gpLqLNU4kG3JHYVucqGyopL5utGxP2q1N`, @@ -145,7 +147,7 @@ export const processApr = async ({ const ray = 10 ** 27; let a = parseFloat(reserve?.liquidityRate || "1") / ray; - a = a * 0.9; + a = a * ALCHEMIST_FEE_MULTIPLIER; const b = a * 100; return b; }; diff --git a/src/lib/middleware/common.ts b/src/lib/middleware/common.ts new file mode 100644 index 00000000..402324c6 --- /dev/null +++ b/src/lib/middleware/common.ts @@ -0,0 +1,2 @@ +/** Alchemist contract takes a 10% fee at harvest transactions. */ +export const ALCHEMIST_FEE_MULTIPLIER = 0.9; diff --git a/src/lib/middleware/frax.ts b/src/lib/middleware/frax.ts index 3096dc1d..fbe51b5d 100644 --- a/src/lib/middleware/frax.ts +++ b/src/lib/middleware/frax.ts @@ -1,9 +1,10 @@ import { AprFn } from "@/lib/config/metadataTypes"; +import { ALCHEMIST_FEE_MULTIPLIER } from "./common"; const apiUrl = "https://api.frax.finance/v2/frxeth/summary/latest"; export const getFraxApy: AprFn = async () => { const query = await fetch(apiUrl); const data = (await query.json()) as { sfrxethApr: number }; - return data.sfrxethApr * 0.9; + return data.sfrxethApr * ALCHEMIST_FEE_MULTIPLIER; }; diff --git a/src/lib/middleware/gearbox.ts b/src/lib/middleware/gearbox.ts index 4d297f97..db1a0c3c 100644 --- a/src/lib/middleware/gearbox.ts +++ b/src/lib/middleware/gearbox.ts @@ -1,6 +1,7 @@ import { toNumber } from "dnum"; import { AprFn } from "@/lib/config/metadataTypes"; +import { ALCHEMIST_FEE_MULTIPLIER } from "./common"; export const getGearboxApy: AprFn = async ({ vaultAddress, publicClient }) => { const poolContract = { @@ -37,5 +38,5 @@ export const getGearboxApy: AprFn = async ({ vaultAddress, publicClient }) => { functionName: "supplyRate", }); - return toNumber([rateBigInt, 25]); + return toNumber([rateBigInt, 25]) * ALCHEMIST_FEE_MULTIPLIER; }; diff --git a/src/lib/middleware/jones.ts b/src/lib/middleware/jones.ts index fe3c7fb3..819d5dea 100644 --- a/src/lib/middleware/jones.ts +++ b/src/lib/middleware/jones.ts @@ -1,4 +1,5 @@ import { AprFn } from "@/lib/config/metadataTypes"; +import { ALCHEMIST_FEE_MULTIPLIER } from "./common"; export const getJonesApy: AprFn = async () => { const response = await fetch("https://app.jonesdao.io/api/jusdc-apy"); @@ -7,5 +8,5 @@ export const getJonesApy: AprFn = async () => { if (data.jusdcApy === undefined || typeof data.jusdcApy !== "number") throw new Error("Invalid APY data"); - return data.jusdcApy; + return data.jusdcApy * ALCHEMIST_FEE_MULTIPLIER; }; diff --git a/src/lib/middleware/lido.ts b/src/lib/middleware/lido.ts index bb1eace7..562ed6f9 100644 --- a/src/lib/middleware/lido.ts +++ b/src/lib/middleware/lido.ts @@ -1,9 +1,10 @@ // see documentation at https://docs.lido.fi/integrations/api import { AprFn } from "@/lib/config/metadataTypes"; +import { ALCHEMIST_FEE_MULTIPLIER } from "./common"; export const getLidoApy: AprFn = async () => { const api = await fetch("https://eth-api.lido.fi/v1/protocol/steth/apr/last"); const data = await api.json(); - return (data.data.apr * 0.9) as number; + return (data.data.apr as number) * ALCHEMIST_FEE_MULTIPLIER; }; diff --git a/src/lib/middleware/rocketPool.ts b/src/lib/middleware/rocketPool.ts index afbf883b..7f11284b 100644 --- a/src/lib/middleware/rocketPool.ts +++ b/src/lib/middleware/rocketPool.ts @@ -1,4 +1,5 @@ import { AprFn } from "@/lib/config/metadataTypes"; +import { ALCHEMIST_FEE_MULTIPLIER } from "./common"; const apiUrl = "https://api.rocketpool.net/api/mainnet/apr"; @@ -9,6 +10,6 @@ type RocketResponse = { export const getRocketApr: AprFn = async () => { const api = await fetch(apiUrl); const response = (await api.json()) as RocketResponse; - const totalStake = parseFloat(response.yearlyAPR) * 0.9; + const totalStake = parseFloat(response.yearlyAPR) * ALCHEMIST_FEE_MULTIPLIER; return totalStake; }; diff --git a/src/lib/middleware/vesper.ts b/src/lib/middleware/vesper.ts index cd4b02a8..3de04f41 100644 --- a/src/lib/middleware/vesper.ts +++ b/src/lib/middleware/vesper.ts @@ -1,4 +1,5 @@ import { AprFn } from "@/lib/config/metadataTypes"; +import { ALCHEMIST_FEE_MULTIPLIER } from "./common"; interface VesperReserve { address: string; @@ -29,7 +30,7 @@ export const processApr = async ({ let yieldValue = reserve?.actualRates["30"] ?? 0; if (yieldValue < 0) yieldValue = 0; - return yieldValue; + return yieldValue * ALCHEMIST_FEE_MULTIPLIER; }; export const getVesperApr: AprFn = async ({ vaultAddress }) => { diff --git a/src/lib/middleware/yearn.ts b/src/lib/middleware/yearn.ts index 04e37c76..51430f5f 100644 --- a/src/lib/middleware/yearn.ts +++ b/src/lib/middleware/yearn.ts @@ -2,6 +2,7 @@ import { AprFn } from "@/lib/config/metadataTypes"; import { optimism } from "viem/chains"; +import { ALCHEMIST_FEE_MULTIPLIER } from "./common"; export const getYearnApy: AprFn = async ({ yieldTokenOverride, @@ -24,5 +25,5 @@ export const getYearnApy: AprFn = async ({ ? vaultData.apr.netAPR + vaultData.apr.extra.stakingRewardsAPR : vaultData.apr.netAPR; - return value * 100 * 0.9; + return value * 100 * ALCHEMIST_FEE_MULTIPLIER; };