Skip to content

Commit

Permalink
feat: working on APY
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 5, 2023
1 parent 7f12e7b commit a13dea6
Show file tree
Hide file tree
Showing 12 changed files with 33 additions and 124 deletions.
4 changes: 2 additions & 2 deletions apps/common/contexts/useYearn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const YearnContextApp = memo(function YearnContextApp({children}: { child
});

const {data: vaults, isLoading: isLoadingVaultList, mutate: mutateVaultList} = useFetch<TYDaemonVaults>({
endpoint: `${yDaemonBaseUri}/vaults/all?${new URLSearchParams({
endpoint: `${yDaemonBaseUri}/vaults?${new URLSearchParams({
hideAlways: 'true',
orderBy: 'apr.netAPR',
orderDirection: 'desc',
Expand All @@ -103,7 +103,7 @@ export const YearnContextApp = memo(function YearnContextApp({children}: { child
});

const {data: vaultsMigrations} = useFetch<TYDaemonVaults>({
endpoint: `${yDaemonBaseUri}/vaults/all?${new URLSearchParams({migratable: 'nodust'})}`,
endpoint: `${yDaemonBaseUri}/vaults?${new URLSearchParams({migratable: 'nodust'})}`,
schema: yDaemonVaultsSchema
});

Expand Down
84 changes: 2 additions & 82 deletions apps/common/schemas/yDaemonVaultsSchemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -96,41 +63,23 @@ 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()
});

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)
}),
Expand Down Expand Up @@ -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()
})
});

Expand All @@ -216,13 +141,8 @@ export const yDaemonVaultHarvestSchema = z.object({
export const yDaemonVaultHarvestsSchema = z.array(yDaemonVaultHarvestSchema);

export type TYDaemonVault = z.infer<typeof yDaemonVaultSchema>;

export type TYDaemonVaultStrategy = z.infer<typeof yDaemonVaultStrategySchema>;

export type TYDaemonVaults = z.infer<typeof yDaemonVaultsSchema>;

export type TYDaemonVaultHarvest = z.infer<typeof yDaemonVaultHarvestSchema>;

export type TYDaemonVaultHarvests = z.infer<typeof yDaemonVaultHarvestsSchema>;

export type TYDaemonVaultTokenSchema = z.infer<typeof yDaemonVaultTokenSchema>;
2 changes: 1 addition & 1 deletion apps/common/utils/getYDaemonBaseURI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
2 changes: 1 addition & 1 deletion apps/common/utils/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
}
Expand Down
10 changes: 5 additions & 5 deletions apps/vaults/components/details/VaultActionsTabsWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<boolean>('yearn.fi/ledger-plugin-banner', true);
Expand All @@ -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]);
Expand All @@ -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;

Expand Down Expand Up @@ -131,7 +131,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
)}


{(!currentVault?.migration.available && currentVault?.details?.retired) && (
{(!currentVault?.migration.available && currentVault?.retired) && (
<div aria-label={'Deprecation Warning'} className={'col-span-12 mt-10'}>
<div className={'w-full bg-neutral-900 p-6 text-neutral-0'}>
<b className={'text-lg'}>{'This Vault is no longer supported (oh no).'}</b>
Expand All @@ -140,7 +140,7 @@ export function VaultActionsTabsWrapper({currentVault}: {currentVault: TYDaemonV
</div>
)}

<nav className={`mb-2 w-full ${(isLedgerPluginVisible || currentVault?.details?.retired) ? 'mt-1 md:mt-4' : 'mt-10 md:mt-20'}`}>
<nav className={`mb-2 w-full ${(isLedgerPluginVisible || currentVault?.retired) ? 'mt-1 md:mt-4' : 'mt-10 md:mt-20'}`}>
<Link href={'/vaults'}>
<p className={'yearn--header-nav-item w-full whitespace-nowrap opacity-30'}>
{'Back to vaults'}
Expand Down
6 changes: 3 additions & 3 deletions apps/vaults/components/details/tabs/VaultDetailsAbout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ function YearnFeesLineItem({children, label, tooltip}: TYearnFeesLineItem): Reac

export function VaultDetailsAbout({currentVault, harvestData}: { currentVault: TYDaemonVault, harvestData: TGraphData[] }): ReactElement {
const isMounted = useIsMounted();
const {token, apr, details} = currentVault;
const {token, apr} = currentVault;

function getVaultDescription(): string {
if (token.description) {
Expand Down Expand Up @@ -126,12 +126,12 @@ export function VaultDetailsAbout({currentVault, harvestData}: { currentVault: T
</YearnFeesLineItem>
<YearnFeesLineItem label={'Management fee'}>
<b className={'font-number text-xl text-neutral-900'}>
{formatPercent((details.managementFee || 0) / 100, 0)}
{formatPercent((apr.fees.management || 0) / 100, 0)}
</b>
</YearnFeesLineItem>
<YearnFeesLineItem label={'Performance fee'}>
<b className={'font-number text-xl text-neutral-500'}>
{formatPercent((details.performanceFee || 0) / 100, 0)}
{formatPercent((apr.fees.performance || 0) / 100, 0)}
</b>
</YearnFeesLineItem>
{currentVault.category === 'Velodrome' || currentVault.category === 'Aerodrome' ? (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ export function VaultDetailsTabsWrapper({currentVault}: {currentVault: TYDaemonV
currentVault.address,
currentVault.symbol,
currentVault.decimals,
currentVault.icon
`https://assets.smold.app/api/token/${currentVault.chainID}/${currentVault.address}/logo-128.png`
);
}
}>
Expand Down
20 changes: 10 additions & 10 deletions apps/vaults/contexts/useActionFlow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,15 @@ export function ActionFlowContextApp({children, currentVault}: {children: ReactN


const vaultUnderlying = setZapOption({
name: currentVault?.token?.display_name || currentVault?.token?.name,
name: currentVault?.token?.name,
symbol: currentVault?.token?.symbol,
address: toAddress(currentVault.token.address),
chainID: currentVault?.chainID === 1337 ? safeChainID : currentVault?.chainID,
decimals: currentVault?.token?.decimals || 18
});
const vaultToken = setZapOption({
name: currentVault?.display_name || currentVault?.name || currentVault.formated_name,
symbol: currentVault?.display_symbol || currentVault.symbol,
name: currentVault?.name,
symbol: currentVault?.symbol,
address: toAddress(currentVault.address),
chainID: currentVault?.chainID === 1337 ? safeChainID : currentVault?.chainID,
decimals: currentVault?.decimals || 18
Expand Down Expand Up @@ -342,7 +342,7 @@ export function ActionFlowContextApp({children, currentVault}: {children: ReactN
const userBalance = toBigInt(balances?.[toAddress(_selectedFrom?.value)]?.raw);
let _amount = toNormalizedBN(userBalance, _selectedFrom?.decimals || currentVault?.token?.decimals || 18);
if (isDepositing) {
const vaultDepositLimit = toBigInt(currentVault?.details?.depositLimit);
const vaultDepositLimit = toBigInt(currentVault?.depositLimit);
if (_selectedFrom?.value === currentVault?.token?.address) {
if (userBalance > vaultDepositLimit) {
_amount = toNormalizedBN(vaultDepositLimit, currentVault.token.decimals);
Expand All @@ -358,7 +358,7 @@ export function ActionFlowContextApp({children, currentVault}: {children: ReactN
amount: _amount
}
});
}, [balances, currentVault.details.depositLimit, currentVault.token?.address, currentVault.token.decimals, isDepositing]);
}, [balances, currentVault.depositLimit, currentVault.token?.address, currentVault.token.decimals, isDepositing]);

/* 🔵 - Yearn Finance **************************************************************************
** FLOW: Init the possibleOptionsFrom and possibleOptionsTo arrays and the selectedOptionFrom
Expand Down Expand Up @@ -395,7 +395,7 @@ export function ActionFlowContextApp({children, currentVault}: {children: ReactN
} else {
payloadFrom.push(
setZapOption({
name: currentVault?.token?.display_name || currentVault?.token?.name,
name: currentVault?.token?.name,
symbol: currentVault?.token?.symbol,
address: toAddress(currentVault.token.address),
chainID: currentVault?.chainID === 1337 ? safeChainID : currentVault?.chainID,
Expand All @@ -404,7 +404,7 @@ export function ActionFlowContextApp({children, currentVault}: {children: ReactN
);
payloadTo.push(
setZapOption({
name: currentVault?.display_name || currentVault?.name,
name: currentVault?.name,
symbol: currentVault?.symbol,
address: toAddress(currentVault.address),
chainID: currentVault?.chainID === 1337 ? safeChainID : currentVault?.chainID,
Expand All @@ -417,15 +417,15 @@ export function ActionFlowContextApp({children, currentVault}: {children: ReactN
** Init selectedFrom and selectedTo as default, aka underlyingToken to vaultToken.
******************************************************************************************/
const _selectedFrom = setZapOption({
name: currentVault?.token?.display_name || currentVault?.token?.name,
name: currentVault?.token?.name,
symbol: currentVault?.token?.symbol,
address: toAddress(currentVault.token.address),
chainID: currentVault?.chainID === 1337 ? safeChainID : currentVault?.chainID,
decimals: currentVault?.token?.decimals || 18
});
const _selectedTo = setZapOption({
name: currentVault?.display_name || currentVault?.name || currentVault.formated_name,
symbol: currentVault?.display_symbol || currentVault.symbol,
name: currentVault?.name,
symbol: currentVault.symbol,
address: toAddress(currentVault.address),
chainID: currentVault?.chainID === 1337 ? safeChainID : currentVault?.chainID,
decimals: currentVault?.decimals || 18
Expand Down
2 changes: 1 addition & 1 deletion apps/veyfi/components/GaugesTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function GaugesTab(): ReactElement {
vaultAddress,
decimals: gauge?.decimals ?? 18,
vaultIcon: `${process.env.BASE_YEARN_ASSETS_URI}/1/${vaultAddress}/logo-128.png`,
vaultName: vault?.display_name ?? '',
vaultName: vault?.name ?? '',
vaultApy: vault?.apr.netAPR ?? 0,
vaultDeposited: toBigInt(formatBigNumberAsAmount(balances[vaultAddress]?.raw)),
gaugeApy: 0, // TODO: gauge apy calcs
Expand Down
2 changes: 1 addition & 1 deletion apps/veyfi/components/RewardsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export function RewardsTab(): ReactElement {

return {
id: address,
label: vault?.display_name ?? '',
label: vault?.name ?? '',
icon: `${process.env.BASE_YEARN_ASSETS_URI}/1/${vaultAddress}/logo-128.png`
};
});
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@
"swr": "2.1.5",
"telegraf": "^4.13.1",
"viem": "1.10.9",
"vite": "4.4.9",
"vite": "^4.4.11",
"wagmi": "1.4.1",
"wido": "0.4.1",
"zod": "^3.22.2"
"zod": "^3.22.4"
},
"devDependencies": {
"@next/bundle-analyzer": "^13.4.19",
Expand Down Expand Up @@ -79,7 +79,7 @@
"tailwindcss": "^3.3.3",
"ts-loader": "^9.4.4",
"typescript": "^5.2.2",
"vitest": "^0.34.3",
"vitest": "^0.34.6",
"webpack": "^5.88.2"
},
"resolutions": {
Expand Down
Loading

0 comments on commit a13dea6

Please sign in to comment.