From a13dea6577581d2fc376e38b623effa9bc323e03 Mon Sep 17 00:00:00 2001 From: Majorfi Date: Thu, 5 Oct 2023 15:29:33 +0200 Subject: [PATCH] feat: working on APY --- apps/common/contexts/useYearn.tsx | 4 +- apps/common/schemas/yDaemonVaultsSchemas.ts | 84 +------------------ apps/common/utils/getYDaemonBaseURI.ts | 2 +- apps/common/utils/index.tsx | 2 +- .../details/VaultActionsTabsWrapper.tsx | 10 +-- .../details/tabs/VaultDetailsAbout.tsx | 6 +- .../details/tabs/VaultDetailsTabsWrapper.tsx | 2 +- apps/vaults/contexts/useActionFlow.tsx | 20 ++--- apps/veyfi/components/GaugesTab.tsx | 2 +- apps/veyfi/components/RewardsTab.tsx | 2 +- package.json | 6 +- yarn.lock | 17 +--- 12 files changed, 33 insertions(+), 124 deletions(-) diff --git a/apps/common/contexts/useYearn.tsx b/apps/common/contexts/useYearn.tsx index e6670000c..591f40f6b 100755 --- a/apps/common/contexts/useYearn.tsx +++ b/apps/common/contexts/useYearn.tsx @@ -91,7 +91,7 @@ export const YearnContextApp = memo(function YearnContextApp({children}: { child }); const {data: vaults, isLoading: isLoadingVaultList, mutate: mutateVaultList} = useFetch({ - endpoint: `${yDaemonBaseUri}/vaults/all?${new URLSearchParams({ + endpoint: `${yDaemonBaseUri}/vaults?${new URLSearchParams({ hideAlways: 'true', orderBy: 'apr.netAPR', orderDirection: 'desc', @@ -103,7 +103,7 @@ export const YearnContextApp = memo(function YearnContextApp({children}: { child }); const {data: vaultsMigrations} = useFetch({ - endpoint: `${yDaemonBaseUri}/vaults/all?${new URLSearchParams({migratable: 'nodust'})}`, + endpoint: `${yDaemonBaseUri}/vaults?${new URLSearchParams({migratable: 'nodust'})}`, schema: yDaemonVaultsSchema }); diff --git a/apps/common/schemas/yDaemonVaultsSchemas.ts b/apps/common/schemas/yDaemonVaultsSchemas.ts index 21d9e9299..52fa12922 100644 --- a/apps/common/schemas/yDaemonVaultsSchemas.ts +++ b/apps/common/schemas/yDaemonVaultsSchemas.ts @@ -2,39 +2,6 @@ import {z} from 'zod'; import {toBigInt} from '@yearn-finance/web-lib/utils/format.bigNumber'; import {addressSchema} from '@yearn-finance/web-lib/utils/schemas/addressSchema'; -const zodDefaultAPR = { - type: 'unknown', - netAPR: 0, - fees: { - performance: 0, - withdrawal: 0, - management: 0, - keepCRV: 0, - keepVelo: 0, - cvxKeepCRV: 0 - }, - extra: { - stakingRewardsAPR: 0 - }, - points: { - weekAgo: 0, - monthAgo: 0, - inception: 0 - }, - forwardAPR: { - type: 'unknown', - netAPR: 0, - composite: { - boost: 0, - poolAPY: 0, - boostedAPR: 0, - baseAPR: 0, - cvxAPR: 0, - rewardsAPR: 0 - } - } -}; - const yDaemonVaultStrategySchema = z.object({ address: addressSchema, name: z.string(), @@ -96,14 +63,9 @@ const yDaemonVaultStrategySchema = z.object({ export const yDaemonVaultTokenSchema = z.object({ address: addressSchema, - underlyingTokensAddresses: z.array(addressSchema), name: z.string(), symbol: z.string(), - type: z.string(), - display_name: z.string(), - display_symbol: z.string(), description: z.string(), - icon: z.string(), decimals: z.number() }); @@ -111,26 +73,13 @@ export const yDaemonVaultSchema = z.object({ address: addressSchema, type: z.literal('Automated').or(z.literal('Standard').or(z.literal('Experimental'))), symbol: z.string(), - display_symbol: z.string(), - formated_symbol: z.string(), name: z.string(), - display_name: z.string(), - formated_name: z.string(), - icon: z.string(), - version: z.string(), category: z.literal('Curve').or(z.literal('Volatile').or(z.literal('Balancer')).or(z.literal('Stablecoin'))).or(z.literal('Velodrome')).or(z.literal('Boosted')).or(z.literal('Aerodrome')), - inception: z.number(), decimals: z.number(), chainID: z.number(), - riskScore: z.number(), - endorsed: z.boolean(), - emergency_shutdown: z.boolean(), token: yDaemonVaultTokenSchema, tvl: z.object({ total_assets: z.string().transform((val): bigint => toBigInt(val)), - total_delegated_assets: z.string().transform((val): bigint => toBigInt(val)), - tvl_deposited: z.number().default(0).catch(0), - tvl_delegated: z.number().default(0).catch(0), tvl: z.number().default(0).catch(0), price: z.number().default(0).catch(0) }), @@ -166,37 +115,13 @@ export const yDaemonVaultSchema = z.object({ }).default({}) }).default({}) }), - details: z.object({ - management: addressSchema, - governance: addressSchema, - guardian: addressSchema, - rewards: addressSchema, - depositLimit: z.string(), - availableDepositLimit: z.string(), - comment: z.string(), - apyTypeOverride: z.string(), - apyOverride: z.number(), - order: z.number(), - performanceFee: z.number(), - managementFee: z.number(), - depositsDisabled: z.boolean(), - withdrawalsDisabled: z.boolean(), - allowZapIn: z.boolean(), - allowZapOut: z.boolean(), - retired: z.boolean(), - hideAlways: z.boolean() - }), + retired: z.boolean().default(false).catch(false), + depositLimit: z.string(), strategies: z.array(yDaemonVaultStrategySchema), migration: z.object({ available: z.boolean(), address: addressSchema, contract: addressSchema - }), - staking: z.object({ - available: z.boolean(), - address: addressSchema, - tvl: z.number(), - risk: z.number() }) }); @@ -216,13 +141,8 @@ export const yDaemonVaultHarvestSchema = z.object({ export const yDaemonVaultHarvestsSchema = z.array(yDaemonVaultHarvestSchema); export type TYDaemonVault = z.infer; - export type TYDaemonVaultStrategy = z.infer; - export type TYDaemonVaults = z.infer; - export type TYDaemonVaultHarvest = z.infer; - export type TYDaemonVaultHarvests = z.infer; - export type TYDaemonVaultTokenSchema = z.infer; diff --git a/apps/common/utils/getYDaemonBaseURI.ts b/apps/common/utils/getYDaemonBaseURI.ts index c630bb8c3..09c861e0a 100644 --- a/apps/common/utils/getYDaemonBaseURI.ts +++ b/apps/common/utils/getYDaemonBaseURI.ts @@ -10,7 +10,7 @@ export function useYDaemonBaseURI({chainID}: TProps): { // eslint-disable-next-line @typescript-eslint/naming-convention const {settings} = useSettings(); - const baseUri = settings.yDaemonBaseURI || process.env.YDAEMON_BASE_URI; + const baseUri = 'http://localhost:8080' || settings.yDaemonBaseURI || process.env.YDAEMON_BASE_URI; if (!baseUri) { throw new Error('YDAEMON_BASE_URI is not defined'); diff --git a/apps/common/utils/index.tsx b/apps/common/utils/index.tsx index 9c9b9ad2c..77a2eeb30 100755 --- a/apps/common/utils/index.tsx +++ b/apps/common/utils/index.tsx @@ -50,7 +50,7 @@ export function getAmountWithSlippage(from: string, to: string, value: bigint, s } export function getVaultName(vault: TYDaemonVault): string { - const baseName = vault.display_name || vault.name || vault.formated_name || 'unknown'; + const baseName = vault.name; if (baseName.includes(' yVault')) { return baseName.replace(' yVault', ''); } diff --git a/apps/vaults/components/details/VaultActionsTabsWrapper.tsx b/apps/vaults/components/details/VaultActionsTabsWrapper.tsx index 7f230204a..99f29f331 100755 --- a/apps/vaults/components/details/VaultActionsTabsWrapper.tsx +++ b/apps/vaults/components/details/VaultActionsTabsWrapper.tsx @@ -64,7 +64,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV getCurrentTab({ isDepositing, hasMigration: currentVault?.migration?.available, - isRetired: currentVault?.details?.retired + isRetired: currentVault?.retired }) ); const [shouldShowLedgerPluginBanner, set_shouldShowLedgerPluginBanner] = useLocalStorage('yearn.fi/ledger-plugin-banner', true); @@ -87,7 +87,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV set_currentTab(tabs[2]); onSwitchSelectedOptions(Flow.Migrate); }); - } else if (currentVault?.details?.retired && actionParams.isReady) { + } else if (currentVault?.retired && actionParams.isReady) { performBatchedUpdates((): void => { set_possibleTabs([tabs[1]]); set_currentTab(tabs[1]); @@ -100,7 +100,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV set_possibleTabs([tabs[0], tabs[1], tabs[3]]); }); } - }, [currentVault?.migration?.available, currentVault?.details?.retired, actionParams.isReady, hasStakingRewards]); + }, [currentVault?.migration?.available, currentVault?.retired, actionParams.isReady, hasStakingRewards]); const isLedgerPluginVisible = isWalletLedger && shouldShowLedgerPluginBanner; @@ -131,7 +131,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV )} - {(!currentVault?.migration.available && currentVault?.details?.retired) && ( + {(!currentVault?.migration.available && currentVault?.retired) && (
{'This Vault is no longer supported (oh no).'} @@ -140,7 +140,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
)} -