From c8553c12ba8304ee1dfc3d3c203b6d8891709bd2 Mon Sep 17 00:00:00 2001 From: Major Date: Wed, 28 Jun 2023 18:04:09 +0200 Subject: [PATCH 01/62] wip: apy --- apps/common/schemas/yDaemonVaultsSchemas.ts | 26 ++++++++++++++ apps/common/utils/index.tsx | 8 ++--- .../components/details/VaultDetailsHeader.tsx | 4 +-- .../details/actions/QuickActionsTo.tsx | 16 ++++----- .../details/tabs/VaultDetailsAbout.tsx | 34 ++++++++----------- apps/vaults/components/list/VaultsListRow.tsx | 28 +++++++-------- apps/vaults/hooks/useSortVaults.ts | 9 +---- apps/ybal/contexts/useYBal.tsx | 6 ++-- apps/ycrv/contexts/useYCRV.tsx | 2 +- pages/vaults/index.tsx | 2 +- 10 files changed, 73 insertions(+), 62 deletions(-) diff --git a/apps/common/schemas/yDaemonVaultsSchemas.ts b/apps/common/schemas/yDaemonVaultsSchemas.ts index 199ad28a9..48612f7a3 100644 --- a/apps/common/schemas/yDaemonVaultsSchemas.ts +++ b/apps/common/schemas/yDaemonVaultsSchemas.ts @@ -115,6 +115,32 @@ export const yDaemonVaultSchema = z.object({ tvl: z.number(), price: z.number() }), + newApy: z.object({ + type: z.string(), + gross_apr: z.number(), + net_apy: z.number(), + staking_rewards_apr: z.number(), + fees: z.object({ + performance: z.number(), + withdrawal: z.number(), + management: z.number(), + keep_crv: z.number(), + cvx_keep_crv: z.number() + }), + points: z.object({ + week_ago: z.number(), + month_ago: z.number(), + inception: z.number() + }), + composite: z.object({ + boost: z.number(), + pool_apy: z.number(), + boosted_apr: z.number(), + base_apr: z.number(), + cvx_apr: z.number(), + rewards_apr: z.number() + }) + }), apy: z.object({ type: z.string(), gross_apr: z.number(), diff --git a/apps/common/utils/index.tsx b/apps/common/utils/index.tsx index 755847d99..7b68c8b09 100755 --- a/apps/common/utils/index.tsx +++ b/apps/common/utils/index.tsx @@ -26,8 +26,8 @@ export function getVaultAPY(vaults: TDict, vaultAddre return `APY ${formatPercent(0)}`; } - if (vaults?.[toAddress(vaultAddress)]?.apy?.net_apy) { - return `APY ${formatPercent((vaults?.[toAddress(vaultAddress)]?.apy?.net_apy || 0) * 100, 2, 2, 500)}`; + if (vaults?.[toAddress(vaultAddress)]?.newApy?.net_apy) { + return `APY ${formatPercent((vaults?.[toAddress(vaultAddress)]?.newApy?.net_apy || 0) * 100, 2, 2, 500)}`; } return `APY ${formatPercent(0)}`; } @@ -41,8 +41,8 @@ export function getVaultRawAPY(vaults: TDict, vaultAd return 0; } - if (vaults?.[toAddress(vaultAddress)]?.apy?.net_apy) { - return (vaults?.[toAddress(vaultAddress)]?.apy?.net_apy || 0) * 100; + if (vaults?.[toAddress(vaultAddress)]?.newApy?.net_apy) { + return (vaults?.[toAddress(vaultAddress)]?.newApy?.net_apy || 0) * 100; } return 0; diff --git a/apps/vaults/components/details/VaultDetailsHeader.tsx b/apps/vaults/components/details/VaultDetailsHeader.tsx index 252f39152..0889d627c 100755 --- a/apps/vaults/components/details/VaultDetailsHeader.tsx +++ b/apps/vaults/components/details/VaultDetailsHeader.tsx @@ -46,7 +46,7 @@ function VaultHeaderLineItem({label, children, legend}: TVaultHeaderLineItemProp export function VaultDetailsHeader({currentVault}: {currentVault: TYDaemonVault}): ReactElement { const {address: userAddress} = useWeb3(); const {yDaemonBaseUri} = useYDaemonBaseURI({chainID: currentVault.chainID}); - const {address, apy, tvl, decimals, symbol = 'token', token} = currentVault; + const {address, newApy, tvl, decimals, symbol = 'token', token} = currentVault; const {data: earned} = useFetch({ endpoint: address && userAddress ? `${yDaemonBaseUri}/earned/${userAddress}/${currentVault.address}` : null, schema: yDaemonSingleEarnedSchema @@ -91,7 +91,7 @@ export function VaultDetailsHeader({currentVault}: {currentVault: TYDaemonVault} diff --git a/apps/vaults/components/details/actions/QuickActionsTo.tsx b/apps/vaults/components/details/actions/QuickActionsTo.tsx index 1996beaaf..fb9e79709 100644 --- a/apps/vaults/components/details/actions/QuickActionsTo.tsx +++ b/apps/vaults/components/details/actions/QuickActionsTo.tsx @@ -35,11 +35,11 @@ export function VaultDetailsQuickActionsTo(): ReactElement { className={'flex w-full flex-col space-x-0 md:flex-row md:space-x-4'}>
- - - {`APY ${formatPercent(((currentVault?.apy?.net_apy || 0) + (currentVault?.apy?.staking_rewards_apr || 0)) * 100, 2, 2, 500)}`} + + + {`APY ${formatPercent(((currentVault?.newApy?.net_apy || 0) + (currentVault?.newApy?.staking_rewards_apr || 0)) * 100, 2, 2, 500)}`}
-