Skip to content

Commit

Permalink
feat: prep mainnet
Browse files Browse the repository at this point in the history
  • Loading branch information
Majorfi committed Oct 18, 2023
1 parent 6ac94a9 commit 2a8d994
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 82 deletions.
8 changes: 3 additions & 5 deletions apps/common/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ const DropdownOption = (option: TDropdownOption): ReactElement => {
};

const DropdownEmpty = ({isSearching}: {isSearching: boolean}): ReactElement => {
if(isSearching) {
if (!isSearching) {
return (
<div className={'relative flex h-14 flex-col items-center justify-center px-4 text-center'}>
<div className={'flex h-10 items-center justify-center'}>
Expand Down Expand Up @@ -170,10 +170,8 @@ export const Dropdown = ({selected, options, onChange, label, legend, isDisabled
leaveFrom={'transform scale-100 opacity-100'}
leaveTo={'transform scale-95 opacity-0'}
afterLeave={(): void => {
performBatchedUpdates((): void => {
set_isOpen(false);
set_search('');
});
set_isOpen(false);
set_search('');
}}>
<Combobox.Options className={'yearn--dropdown-menu z-50'}>
{filteredOptions.length === 0 ? (
Expand Down
14 changes: 0 additions & 14 deletions apps/common/contexts/useWallet.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,20 +105,6 @@ export const WalletContextApp = memo(function WalletContextApp({children}: {chil
extraTokens.push({token: OPT_YVWUSDRV2_USDC_STAKING_CONTRACT, symbol: 'yvVelo-wUSDRv2-USDC', decimals: 18});
extraTokens.push({token: OPT_YVSTERN_ERN_STAKING_CONTRACT, symbol: 'yvVelo-stERN-ERN', decimals: 18});
}
if (safeChainID === 250) {
extraTokens.push(...[
{token: toAddress('0x28D374F0cdabb327A034BA41B9A2967E2959fb1F')}, //TODO: Remove it - veYFI test
{token: toAddress('0xb8E45b5C3E49A9a4C2A086deAF59f7De19c100cC')}, //TODO: Remove it - veYFI test
{token: toAddress('0x2Cc4b29771fcAA71313dC946a89eDd1AA68292E2')}, //TODO: Remove it - veYFI test
{token: toAddress('0x9Cb511D44930c0C3D3114FFAaBedC3e0876D791a')}, //TODO: Remove it - veYFI test
{token: toAddress('0xC85509a31F218e66A7151A48e218AD98469Cbf4A')}, //TODO: Remove it - veYFI test
{token: toAddress('0x52Ca0fC251e7a28cf8E67357BCD3d771B105eCa9')}, //TODO: Remove it - veYFI test
{token: toAddress('0xbADfbF563C6C85F76e086E7a1915A1A46d683810')}, //TODO: Remove it - veYFI test
{token: toAddress('0xd5947C01dBaEFeFF05186FE34A976b2E28d90542')}, //TODO: Remove it - veYFI test
{token: toAddress('0x2262ef7F5A0171D9dBC16963727249787575cE42')}, //TODO: Remove it - veYFI test
{token: toAddress('0x79a37e400bC591f1B38e4Fe020Ec1f985F670218')} //TODO: Remove it - veYFI test
]);
}
for (const token of extraTokens) {
tokensExists[token.token] = true;
tokens.push(token);
Expand Down
1 change: 0 additions & 1 deletion apps/common/hooks/useTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ type TProps = {
endTime?: TSeconds;
}

// TODO Check if we can use `getTimeUntil` from the web lib for this computation
export function computeTimeLeft({endTime}: {endTime?: TSeconds}): number {
if (!endTime) {
return 0;
Expand Down
11 changes: 0 additions & 11 deletions apps/common/hooks/useTokenPrice.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@

import {useMemo} from 'react';
import {VEYFI_DYFI_ADDRESS} from '@veYFI/utils/constants';
import {ETH_TOKEN_ADDRESS, YFI_ADDRESS} from '@yearn-finance/web-lib/utils/constants';
import {formatToNormalizedValue, toBigInt} from '@yearn-finance/web-lib/utils/format.bigNumber';
import {useYearn} from '@common/contexts/useYearn';

Expand All @@ -11,15 +9,6 @@ export function useTokenPrice(address: TAddress): number {
const {prices} = useYearn();

const tokenPrice = useMemo((): number => {
if (address === YFI_ADDRESS) {
return 5150.96; //TODO: REMOVE
}
if (address === ETH_TOKEN_ADDRESS) {
return 1601.69; //TODO: REMOVE
}
if (address === VEYFI_DYFI_ADDRESS) {
return 4557.85; //TODO: REMOVe
}
return formatToNormalizedValue(toBigInt(prices?.[address] || 0), 6);
}, [address, prices]);

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 @@ -143,7 +143,7 @@ export function GaugesTab(): ReactElement {
vaultDeposited: balances[vaultAddress],
gaugeApy: 0, // TODO: gauge apy calcs
gaugeBoost: positionsMap[address]?.boost ?? 1,
gaugeStaked: positionsMap[address]?.deposit.balance ?? toNormalizedBN(0),
gaugeStaked: positionsMap[address]?.deposit ?? toNormalizedBN(0),
allowance: allowancesMap[allowanceKey(VEYFI_CHAIN_ID, vaultAddress, address, userAddress)],
isApproved: toBigInt(allowancesMap[allowanceKey(VEYFI_CHAIN_ID, vaultAddress, address, userAddress)]?.raw) >= toBigInt(balances[vaultAddress]?.raw),
actions: undefined
Expand Down
4 changes: 2 additions & 2 deletions apps/veyfi/components/RewardsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function RewardsTab(): ReactElement {
const refreshData = useCallback((): unknown => Promise.all([refreshGauges()]), [refreshGauges]);
const [claimStatus, set_claimStatus] = useState(defaultTxStatus);
const selectedGaugeAddress = toAddress(selectedGauge?.id);
const selectedGaugeRewards = toNormalizedBN(toBigInt(positionsMap[selectedGaugeAddress]?.reward?.balance?.raw));
const selectedGaugeRewards = positionsMap[selectedGaugeAddress]?.reward ?? toNormalizedBN(0n);

const onClaim = useCallback(async (): Promise<void> => {
const result = await GaugeActions.claimRewards({
Expand All @@ -39,7 +39,7 @@ export function RewardsTab(): ReactElement {
}
}, [provider, refreshData, selectedGaugeAddress]);

const gaugeOptions = gaugeAddresses.filter((address): boolean => toBigInt(positionsMap[address]?.reward?.balance?.raw) > 0n ?? false)
const gaugeOptions = gaugeAddresses.filter((address): boolean => toBigInt(positionsMap[address]?.reward?.raw) > 0n ?? false)
.map((address): TDropdownOption => {
const gauge = gaugesMap[address];
const vaultAddress = toAddress(gauge?.vaultAddress);
Expand Down
43 changes: 6 additions & 37 deletions apps/veyfi/contexts/useGauge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {createContext, memo, useCallback, useContext, useState} from 'rea
import {FixedNumber} from 'ethers';
import {useDeepCompareMemo} from '@react-hookz/web';
import {VEYFI_GAUGE_ABI} from '@veYFI/utils/abi/veYFIGauge.abi';
import {VEYFI_CHAIN_ID} from '@veYFI/utils/constants';
import {VE_YFI_GAUGES,VEYFI_CHAIN_ID} from '@veYFI/utils/constants';
import {erc20ABI, readContracts} from '@wagmi/core';
import {useWeb3} from '@yearn-finance/web-lib/contexts/useWeb3';
import {allowanceKey, toAddress} from '@yearn-finance/web-lib/utils/address';
Expand All @@ -25,15 +25,10 @@ export type TGauge = {
// apy?: number;
}

export type TPosition = {
balance: TNormalizedBN,
underlyingBalance: TNormalizedBN,
}

export type TGaugePosition = {
address: TAddress,
deposit: TPosition,
reward: TPosition,
deposit: TNormalizedBN,
reward: TNormalizedBN,
boost: number,
}

Expand All @@ -59,27 +54,8 @@ export const GaugeContextApp = memo(function GaugeContextApp({children}: {childr
const [allowancesMap, set_allowancesMap] = useState<TDict<TNormalizedBN>>({});
const [positionsMap, set_positionsMap] = useState<TDict<TGaugePosition>>({});

// const {data: vaultAddresses} = useContractRead({
// address: VEYFI_REGISTRY_ADDRESS,
// abi: VEYFI_REGISTRY_ABI,
// functionName: 'getVaults',
// chainId: VEYFI_CHAIN_ID
// });
// const vaultAddresses = [
// toAddress('0x28D374F0cdabb327A034BA41B9A2967E2959fb1F'),
// toAddress('0xb8E45b5C3E49A9a4C2A086deAF59f7De19c100cC'),
// toAddress('0x2Cc4b29771fcAA71313dC946a89eDd1AA68292E2'),
// toAddress('0x9Cb511D44930c0C3D3114FFAaBedC3e0876D791a')
// ];

const refreshVotingEscrow = useAsyncTrigger(async (): Promise<void> => {
const gaugeAddresses = [
toAddress('0xbADfbF563C6C85F76e086E7a1915A1A46d683810'),
toAddress('0xd5947C01dBaEFeFF05186FE34A976b2E28d90542'),
toAddress('0x2262ef7F5A0171D9dBC16963727249787575cE42'),
toAddress('0x79a37e400bC591f1B38e4Fe020Ec1f985F670218')
];
const gaugePromises = gaugeAddresses.map(async (gaugeAddress): Promise<TGauge> => {
const gaugePromises = VE_YFI_GAUGES.map(async (gaugeAddress): Promise<TGauge> => {
const results = await readContracts({
contracts: [
{address: gaugeAddress, abi: VEYFI_GAUGE_ABI, chainId: VEYFI_CHAIN_ID, functionName: 'asset'},
Expand Down Expand Up @@ -177,15 +153,8 @@ export const GaugeContextApp = memo(function GaugeContextApp({children}: {childr
const earned = decodeAsBigInt(results[1]);
const boostedBalance = decodeAsBigInt(results[2]);
const decimals = Number(decodeAsBigInt(results[3])) || decodeAsNumber(results[3]);
const depositPosition: TPosition = {
balance: toNormalizedBN(balance, decimals),
underlyingBalance: toNormalizedBN(balance, decimals) // TODO: convert to underlying
};

const rewardPosition: TPosition = {
balance: toNormalizedBN(earned, decimals),
underlyingBalance: toNormalizedBN(earned, decimals) // TODO: convert to underlying
};
const depositPosition: TNormalizedBN = toNormalizedBN(balance, decimals);
const rewardPosition: TNormalizedBN = toNormalizedBN(earned, decimals);

const boostRatio = balance > 0n
? FixedNumber.from(boostedBalance).divUnsafe(FixedNumber.from(balance)).toUnsafeFloat()
Expand Down
4 changes: 2 additions & 2 deletions apps/veyfi/contexts/useVotingEscrow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {createContext, memo, useCallback, useContext, useMemo} from 'react';
import {erc20ABI, useContractRead, useContractReads} from 'wagmi';
import {VEYFI_ABI} from '@veYFI/utils/abi/veYFI.abi';
import {VEYFI_POSITION_HELPER_ABI} from '@veYFI/utils/abi/veYFIPositionHelper.abi';
import {VEYFI_CHAIN_ID, YFI_ADDRESS} from '@veYFI/utils/constants';
import {VEYFI_CHAIN_ID} from '@veYFI/utils/constants';
import {useWeb3} from '@yearn-finance/web-lib/contexts/useWeb3';
import {allowanceKey, isZeroAddress, toAddress} from '@yearn-finance/web-lib/utils/address';
import {VEYFI_ADDRESS, VEYFI_POSITION_HELPER_ADDRESS} from '@yearn-finance/web-lib/utils/constants';
import {VEYFI_ADDRESS, VEYFI_POSITION_HELPER_ADDRESS,YFI_ADDRESS} from '@yearn-finance/web-lib/utils/constants';
import {decodeAsBigInt, decodeAsNumber, decodeAsString} from '@yearn-finance/web-lib/utils/decoder';
import {toMilliseconds} from '@yearn-finance/web-lib/utils/time';

Expand Down
1 change: 0 additions & 1 deletion apps/veyfi/utils/abi/veYFIClaimRewardsZap.abi.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
// TODO: update once final version deployed
export const VEYFI_CLAIM_REWARDS_ZAP_ABI = ['function claim(address[] calldata _gauges, bool _lock, bool _claimVeYfi) external'];
1 change: 0 additions & 1 deletion apps/veyfi/utils/abi/veYFIRegistry.abi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// TODO: update once final version deployed
export const VEYFI_REGISTRY_ABI = [
{
'inputs': [
Expand Down
14 changes: 8 additions & 6 deletions apps/veyfi/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import {toAddress} from '@yearn-finance/web-lib/utils/address';
import {YFI_ADDRESS as MAINNET_YFI_ADDRESS} from '@yearn-finance/web-lib/utils/constants';

import type {TAddress} from '@yearn-finance/web-lib/types';
import type {TWeeks} from '@yearn-finance/web-lib/utils/time';

export const VEYFI_CHAIN_ID = 250; //TODO: change it to 1 - veYFI test
export const VEYFI_CHAIN_ID = 1;

export const YFI_ADDRESS = toAddress('0x52Ca0fC251e7a28cf8E67357BCD3d771B105eCa9') || MAINNET_YFI_ADDRESS; // TODO: change to MAINNET_YFI_ADDRESS
export const VEYFI_REGISTRY_ADDRESS: TAddress = toAddress(''); // TODO: update once deployed
export const VEYFI_CLAIM_REWARDS_ZAP_ADDRESS: TAddress = toAddress(''); // TODO: update once deployed
export const VEYFI_OPTIONS_ADDRESS = toAddress('0x16A0cE5957642aDa37F58d5115E38fF3B0C30dc6'); //TODO: change it - veYFI test
export const VEYFI_DYFI_ADDRESS = toAddress('0xC85509a31F218e66A7151A48e218AD98469Cbf4A'); //TODO: change it for prod: 0x41252E8691e964f7DE35156B68493bAb6797a275
export const VEYFI_OPTIONS_ADDRESS = toAddress('0x2fBa208E1B2106d40DaA472Cb7AE0c6C7EFc0224');
export const VEYFI_DYFI_ADDRESS = toAddress('0x41252E8691e964f7DE35156B68493bAb6797a275');

export const SNAPSHOT_DELEGATE_REGISTRY_ADDRESS = toAddress('0x469788fE6E9E9681C6ebF3bF78e7Fd26Fc015446');
export const YEARN_SNAPSHOT_SPACE = 'veyfi.eth';
Expand All @@ -19,3 +16,8 @@ export const MAX_LOCK_TIME: TWeeks = 208;
export const MIN_LOCK_TIME: TWeeks = 1;
export const MIN_LOCK_AMOUNT: TWeeks = 1;

export const VE_YFI_GAUGES = [
toAddress('0x7Fd8Af959B54A677a1D8F92265Bd0714274C56a3'), // YFI/ETH yVault
toAddress('0x107717C98C8125A94D3d2Cc82b86a1b705f3A27C'), // yCRV/CRV yVault
toAddress('0x81d93531720d86f0491DeE7D03f30b3b5aC24e59') // yETH/ETH yVault
];
1 change: 0 additions & 1 deletion apps/veyfi/utils/validations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ export function validateAllowance(props: TValidateAllowanceProps): TValidationRe
}

// TODO: return valid when is native token

const allowance = allowances[allowanceKey(chainID, tokenAddress, spenderAddress, ownerAddress)];
const isApproved = allowance >= amount;

Expand Down

0 comments on commit 2a8d994

Please sign in to comment.