Skip to content

feat: display correct symbol #645

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 27, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions apps/vaults-v3/components/details/RewardsTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import {Fragment, useCallback, useEffect, useMemo, useState} from 'react';
import Image from 'next/image';
import Link from 'next/link';
import {useRouter} from 'next/router';
import {useReadContract} from 'wagmi';
import {useWeb3} from '@builtbymom/web3/contexts/useWeb3';
import {
cl,
Expand All @@ -14,7 +13,6 @@ import {
toBigInt
} from '@builtbymom/web3/utils';
import {approveERC20, defaultTxStatus} from '@builtbymom/web3/utils/wagmi';
import {VEYFI_GAUGE_ABI} from '@vaults/utils/abi/veYFIGauge.abi';
import {
claim as claimAction,
stake as stakeAction,
Expand Down Expand Up @@ -343,12 +341,6 @@ export function RewardsTab(props: {
const shouldForceUnstake = !!DISABLED_VEYFI_GAUGES_VAULTS_LIST.find(
vault => vault.address === props.currentVault.address
);
const {data: symbol} = useReadContract({
address: vaultData.address,
abi: VEYFI_GAUGE_ABI,
functionName: 'symbol',
chainId: props.currentVault.chainID
});

/**********************************************************************************************
** The refreshData function will be called when the user interacts with the stake, unstake, or
Expand Down Expand Up @@ -537,7 +529,7 @@ export function RewardsTab(props: {
className={'w-full'}
legend={
<div className={'flex items-center justify-between'}>
<p>{`${formatAmount(vaultData.stakedBalanceOf.normalized, 6)} ${symbol || props.currentVault.symbol} staked`}</p>
<p>{`${formatAmount(vaultData.stakedBalanceOf.normalized, 6)} ${vaultData.stakedGaugeSymbol || props.currentVault.symbol} staked`}</p>
<p>{`${formatCounterValue(vaultData.stakedBalanceOf.normalized, vaultTokenPrice.normalized)}`}</p>
</div>
}
Expand Down Expand Up @@ -659,7 +651,7 @@ export function RewardsTab(props: {
className={`mt-1 pl-0.5 text-xs text-neutral-600 opacity-70 md:mr-0`}
suppressHydrationWarning>
<div className={'flex items-center justify-between'}>
<p>{`${formatAmount(vaultData.stakedBalanceOf.normalized, 6)} ${symbol || props.currentVault.symbol} staked`}</p>
<p>{`${formatAmount(vaultData.stakedBalanceOf.normalized, 6)} ${vaultData.stakedGaugeSymbol || props.currentVault.symbol} staked`}</p>
<p>{`${formatCounterValue(vaultData.stakedBalanceOf.normalized, vaultTokenPrice.normalized)}`}</p>
</div>
</legend>
Expand Down
12 changes: 11 additions & 1 deletion apps/vaults-v3/components/details/actions/QuickActionsTo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ export function VaultDetailsQuickActionsTo(props: {
const {isActive} = useWeb3();
const {currentVault, possibleOptionsTo, actionParams, onUpdateSelectedOptionTo, isDepositing, hasVeYFIBalance} =
useActionFlow();
const {isAutoStakingEnabled} = useYearn();

const {expectedOut, isLoadingExpectedOut} = useSolver();
const {pathname} = useRouter();
const isV3Page = pathname.startsWith(`/v3`);
Expand All @@ -161,6 +163,14 @@ export function VaultDetailsQuickActionsTo(props: {
address: toAddress(actionParams?.selectedOptionTo?.value),
chainID: Number(actionParams?.selectedOptionTo?.chainID)
});
console.log(currentVault);
const selectedOptionToSymbol = useMemo(() => {
if (isAutoStakingEnabled) {
return props.vaultData.stakedGaugeSymbol;
}

return actionParams?.selectedOptionTo?.symbol;
}, [actionParams?.selectedOptionTo?.symbol, isAutoStakingEnabled, props.vaultData.stakedGaugeSymbol]);

const currentVaultBoost = useMemo(
() =>
Expand Down Expand Up @@ -237,7 +247,7 @@ export function VaultDetailsQuickActionsTo(props: {
className={
'truncate whitespace-nowrap pl-2 font-normal text-neutral-900 scrollbar-none'
}>
{actionParams?.selectedOptionTo?.symbol}
{selectedOptionToSymbol}
</p>
</div>
</div>
Expand Down
167 changes: 107 additions & 60 deletions apps/vaults/hooks/useVaultStakingData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
decodeAsAddress,
decodeAsBigInt,
decodeAsNumber,
decodeAsString,
isZeroAddress,
toAddress,
toBigInt,
Expand All @@ -27,6 +28,7 @@ import type {TAddress, TNormalizedBN} from '@builtbymom/web3/types';
export type TStakingInfo = {
address: TAddress;
stakingToken: TAddress;
stakedGaugeSymbol: string;
rewardsToken: TAddress;
rewardDecimals: number | undefined;
stakingDecimals: number | undefined;
Expand Down Expand Up @@ -58,6 +60,7 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
: toAddress(foundVaultWithDisabledStaking),
stakingToken: toAddress(''),
rewardsToken: toAddress(''),
stakedGaugeSymbol: '',
rewardDecimals: undefined,
stakingDecimals: undefined,
totalStaked: zeroNormalizedBN,
Expand All @@ -77,7 +80,7 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
}

const stakingAddress = foundVaultWithDisabledStaking
? toAddress(foundVaultWithDisabledStaking)
? toAddress(foundVaultWithDisabledStaking || zeroAddress)
: toAddress(props.currentVault.staking.address);

let stakingToken: TAddress = zeroAddress;
Expand All @@ -87,9 +90,11 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
let earned = 0n;
let allowance = 0n;
let vaultBalanceOf = 0n;
let stakedGaugeSymbol = '';
/******************************************************************************************
** To have the most up-to-date data, we fetch a few informations directly onChain, such as:
** - the staking token
** - the staking token symbol
** - the rewards token
** - the total staked amount in the staking contract
** - the user's balance in the staking contract
Expand All @@ -98,63 +103,96 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
** - the user's balance in the vault contract
******************************************************************************************/
if (stakingType === 'OP Boost' || stakingType === 'VeYFI' || foundVaultWithDisabledStaking) {
const contracts = [
{
key: 'stakingToken',
address: toAddress(stakingAddress),
chainId: props.currentVault.chainID,
abi: stakingType === 'OP Boost' ? STAKING_REWARDS_ABI : VEYFI_GAUGE_ABI,
functionName: stakingType === 'OP Boost' ? 'stakingToken' : 'asset'
},
{
key: 'rewardsToken',
address: toAddress(stakingAddress),
chainId: props.currentVault.chainID,
abi: stakingType === 'OP Boost' ? STAKING_REWARDS_ABI : VEYFI_GAUGE_ABI,
functionName: stakingType === 'OP Boost' ? 'rewardsToken' : 'REWARD_TOKEN'
},
{
key: 'stakedGaugeSymbol',
address: toAddress(stakingAddress),
chainId: props.currentVault.chainID,
abi: VEYFI_GAUGE_ABI,
functionName: 'symbol'
},
{
key: 'totalStaked',
address: toAddress(stakingAddress),
abi: STAKING_REWARDS_ABI,
chainId: props.currentVault.chainID,
functionName: 'totalSupply'
},
{
key: 'balanceOf',
address: toAddress(stakingAddress),
abi: STAKING_REWARDS_ABI,
chainId: props.currentVault.chainID,
functionName: 'balanceOf',
args: [toAddress(address)]
},
{
key: 'earned',
address: toAddress(stakingAddress),
abi: STAKING_REWARDS_ABI,
chainId: props.currentVault.chainID,
functionName: 'earned',
args: [toAddress(address)]
},
{
key: 'allowance',
address: toAddress(stakingAddress),
abi: erc20Abi,
chainId: props.currentVault.chainID,
functionName: 'allowance',
args: [toAddress(address), toAddress(stakingAddress)]
},
{
key: 'vaultBalanceOf',
address: toAddress(props.currentVault.address),
abi: erc20Abi,
chainId: props.currentVault.chainID,
functionName: 'balanceOf',
args: [toAddress(address)]
}
];

/* eslint-disable @typescript-eslint/no-unused-vars */
const calls = contracts.map(({key: _key, ...rest}) => rest) as Parameters<
typeof readContracts
>[1]['contracts'];
/* eslint-enable @typescript-eslint/no-unused-vars */

const data = await readContracts(retrieveConfig(), {
contracts: [
{
address: toAddress(stakingAddress),
chainId: props.currentVault.chainID,
abi: stakingType === 'OP Boost' ? STAKING_REWARDS_ABI : VEYFI_GAUGE_ABI,
functionName: stakingType === 'OP Boost' ? 'stakingToken' : 'asset'
},
{
address: toAddress(stakingAddress),
chainId: props.currentVault.chainID,
abi: stakingType === 'OP Boost' ? STAKING_REWARDS_ABI : VEYFI_GAUGE_ABI,
functionName: stakingType === 'OP Boost' ? 'rewardsToken' : 'REWARD_TOKEN'
},
{
address: toAddress(stakingAddress),
abi: STAKING_REWARDS_ABI,
chainId: props.currentVault.chainID,
functionName: 'totalSupply'
},
{
address: toAddress(stakingAddress),
abi: STAKING_REWARDS_ABI,
chainId: props.currentVault.chainID,
functionName: 'balanceOf',
args: [toAddress(address)]
},
{
address: toAddress(stakingAddress),
abi: STAKING_REWARDS_ABI,
chainId: props.currentVault.chainID,
functionName: 'earned',
args: [toAddress(address)]
},
{
address: toAddress(stakingAddress),
abi: erc20Abi,
chainId: props.currentVault.chainID,
functionName: 'allowance',
args: [toAddress(address), toAddress(stakingAddress)]
},
{
address: toAddress(props.currentVault.address),
abi: erc20Abi,
chainId: props.currentVault.chainID,
functionName: 'balanceOf',
args: [toAddress(address)]
}
]
contracts: calls
});
stakingToken = decodeAsAddress(data[0]);
rewardsToken = decodeAsAddress(data[1]);
totalStaked = decodeAsBigInt(data[2]);
balanceOf = isZeroAddress(address) ? 0n : decodeAsBigInt(data[3]);
earned = isZeroAddress(address) ? 0n : decodeAsBigInt(data[4]);
allowance = isZeroAddress(address) ? 0n : decodeAsBigInt(data[5]);
vaultBalanceOf = isZeroAddress(address) ? 0n : decodeAsBigInt(data[6]);

// Map results to keys
const resultMap = contracts.reduce(
(acc, contract, idx) => {
acc[contract.key] = data[idx];
return acc;
},
{} as {[key: string]: any}
);

stakingToken = decodeAsAddress(resultMap.stakingToken);
rewardsToken = decodeAsAddress(resultMap.rewardsToken);
stakedGaugeSymbol = decodeAsString(resultMap.stakedGaugeSymbol);
totalStaked = decodeAsBigInt(resultMap.totalStaked);
balanceOf = isZeroAddress(address) ? 0n : decodeAsBigInt(resultMap.balanceOf);
earned = isZeroAddress(address) ? 0n : decodeAsBigInt(resultMap.earned);
allowance = isZeroAddress(address) ? 0n : decodeAsBigInt(resultMap.allowance);
vaultBalanceOf = isZeroAddress(address) ? 0n : decodeAsBigInt(resultMap.vaultBalanceOf);
} else if (stakingType === 'Juiced') {
const data = await readContracts(retrieveConfig(), {
contracts: [
Expand All @@ -171,6 +209,7 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
functionName: 'rewardTokens',
args: [0n]
},

{
address: toAddress(props.currentVault.staking.address),
abi: JUICED_STAKING_REWARDS_ABI,
Expand Down Expand Up @@ -247,6 +286,12 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
chainId: props.currentVault.chainID,
functionName: 'totalSupply'
},
{
address: toAddress(props.currentVault.staking.address),
abi: V3_STAKING_REWARDS_ABI,
chainId: props.currentVault.chainID,
functionName: 'symbol'
},
{
address: toAddress(props.currentVault.staking.address),
abi: V3_STAKING_REWARDS_ABI,
Expand All @@ -273,10 +318,11 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
});
stakingToken = decodeAsAddress(data[0]);
totalStaked = decodeAsBigInt(data[1]);
balanceOf = isZeroAddress(address) ? 0n : decodeAsBigInt(data[2]);
allowance = isZeroAddress(address) ? 0n : decodeAsBigInt(data[3]);
vaultBalanceOf = isZeroAddress(address) ? 0n : decodeAsBigInt(data[4]);
rewardsToken = decodeAsAddress(data[5]);
stakedGaugeSymbol = decodeAsString(data[2]);
balanceOf = isZeroAddress(address) ? 0n : decodeAsBigInt(data[3]);
allowance = isZeroAddress(address) ? 0n : decodeAsBigInt(data[4]);
vaultBalanceOf = isZeroAddress(address) ? 0n : decodeAsBigInt(data[5]);
rewardsToken = decodeAsAddress(data[6]);

const earnedRaw = await readContract(retrieveConfig(), {
address: toAddress(props.currentVault.staking.address),
Expand Down Expand Up @@ -318,6 +364,7 @@ export function useVaultStakingData(props: {currentVault: TYDaemonVault}): {
rewardsToken,
rewardDecimals,
stakingDecimals,
stakedGaugeSymbol,
totalStaked: toNormalizedBN(totalStaked, stakingDecimals),
stakedBalanceOf: toNormalizedBN(balanceOf, stakingDecimals),
stakedEarned: toNormalizedBN(earned, rewardDecimals),
Expand Down
Loading