Skip to content

Commit

Permalink
🐛 staking: fix decimals for staking APR
Browse files Browse the repository at this point in the history
  • Loading branch information
franm91 committed Dec 5, 2024
1 parent 93916e5 commit e0839b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 3 additions & 3 deletions components/staking/StakedEXASummary/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function StakedEXASummary() {
<Skeleton variant="text" width={100} height={45} />
) : (
<Typography fontSize={32} fontWeight={500}>
{formatNumber(Number(totalRewardsAPR))}%
{formatNumber(totalRewardsAPR)}%
</Typography>
)}
{rewardsTokens === undefined ? (
Expand Down Expand Up @@ -160,7 +160,7 @@ function StakedEXASummary() {

type RewardData = {
symbol: string;
apr: bigint;
apr: number;
};

const TooltipContent: FC<{ rewardsData?: RewardData[] }> = ({ rewardsData }) => {
Expand All @@ -178,7 +178,7 @@ const TooltipContent: FC<{ rewardsData?: RewardData[] }> = ({ rewardsData }) =>
</Typography>
<Image src={imagePath} alt={symbol} width="24" height="24" />
<Typography fontWeight={400} fontSize={14} ml={0.5} color="grey.900">
{formatNumber(Number(apr))}%
{formatNumber(apr)}%
</Typography>
</Box>
);
Expand Down
7 changes: 3 additions & 4 deletions utils/calculateStakingAPR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ export const calculateStakingRewardsAPR = (

const rewardPrice = symbol === 'EXA' ? exaPrice : getVouchersPrice(accountData, symbol);
const decimals = accountData.find((token) => token.symbol.includes(symbol))?.decimals || 18;
const decimalWAD = 10n ** BigInt(decimals);

const apr = (rate * yearInSeconds * rewardPrice * 100n) / (totalAssets * exaPrice) / decimalWAD;
const apr = Number((rate * yearInSeconds * rewardPrice * 100n) / (totalAssets * exaPrice)) / 10 ** decimals;

return { symbol, apr };
});
};

export const calculateTotalStakingRewardsAPR = (rewardsAPR: Array<{ symbol: string; apr: bigint }>) => {
export const calculateTotalStakingRewardsAPR = (rewardsAPR: Array<{ symbol: string; apr: number }>) => {
if (!rewardsAPR) return 0n;
return rewardsAPR.reduce((acc, { apr }) => acc + apr, 0n);
return rewardsAPR.reduce((acc, { apr }) => acc + apr, 0);
};

0 comments on commit e0839b7

Please sign in to comment.