Skip to content
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

Hot fix negative apr apy #375

Merged
merged 4 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,9 @@ export const PromotedPoolPopover = ({
<span className={classes.apr}>APR</span>
</Typography>{' '}
<Typography className={classes.whiteText}>
{`${apy > 1000 ? '>1000%' : apy === 0 ? '' : apy.toFixed(2) + '%'}`}
{`${apy > 1000 ? '>1000%' : apy === 0 ? '' : Math.abs(apy).toFixed(2) + '%'}`}
<span className={classes.apr}>
{`${apr > 1000 ? '>1000%' : apr === 0 ? '-' : apr.toFixed(2) + '%'}`}
{`${apr > 1000 ? '>1000%' : apr === 0 ? '-' : Math.abs(apr).toFixed(2) + '%'}`}
</span>
</Typography>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/PopularPools/Card/Card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ const Card: React.FC<ICard> = ({
{apy !== undefined && showAPY && (
<StatsLabel
title='APY'
value={`${convertedApy > 1000 ? '>1000%' : convertedApy === 0 ? '-' : convertedApy.toFixed(2) + '%'}`}
value={`${convertedApy > 1000 ? '>1000%' : convertedApy === 0 ? '-' : Math.abs(convertedApy).toFixed(2) + '%'}`}
/>
)}
<StatsLabel title='Fee' value={fee + '%'} />
Expand Down
4 changes: 2 additions & 2 deletions src/components/Stats/PoolListItem/PoolListItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,11 @@ const PoolListItem: React.FC<IProps> = ({
{!isSmd && showAPY ? (
<Box className={classes.row}>
<Typography>
{`${convertedApr > 1000 ? '>1000%' : convertedApr === 0 ? '-' : convertedApr.toFixed(2) + '%'}`}
{`${convertedApr > 1000 ? '>1000%' : convertedApr === 0 ? '-' : Math.abs(convertedApr).toFixed(2) + '%'}`}
<span
className={
classes.apy
}>{`${convertedApy > 1000 ? '>1000%' : convertedApy === 0 ? '' : convertedApy.toFixed(2) + '%'}`}</span>
}>{`${convertedApy > 1000 ? '>1000%' : convertedApy === 0 ? '' : Math.abs(convertedApy).toFixed(2) + '%'}`}</span>
</Typography>
{isPromoted && (
<>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,11 @@ const PoolListItem: React.FC<IProps> = ({
</Grid>
{!isSm && showAPY ? (
<Typography className={classes.row}>
{`${convertedApr > 1000 ? '>1000%' : convertedApr === 0 ? '-' : convertedApr.toFixed(2) + '%'}`}
{`${convertedApr > 1000 ? '>1000%' : convertedApr === 0 ? '-' : Math.abs(convertedApr).toFixed(2) + '%'}`}
<span
className={
classes.apy
}>{`${convertedApy > 1000 ? '>1000%' : convertedApy === 0 ? '' : convertedApy.toFixed(2) + '%'}`}</span>
}>{`${convertedApy > 1000 ? '>1000%' : convertedApy === 0 ? '' : Math.abs(convertedApy).toFixed(2) + '%'}`}</span>
</Typography>
) : null}
<Typography>{fee}%</Typography>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ export const CustomPoolListItem: React.FC<IProps> = ({
? '>1000%'
: convertedApy === 0
? ''
: convertedApy.toFixed(2) + '%'}
: Math.abs(convertedApy).toFixed(2) + '%'}
</span>
<span
style={{
Expand All @@ -202,7 +202,7 @@ export const CustomPoolListItem: React.FC<IProps> = ({
? '>1000%'
: convertedApr === 0
? ''
: convertedApr.toFixed(2) + '%'}
: Math.abs(convertedApr).toFixed(2) + '%'}
</span>
</Box>
</Box>
Expand Down
2 changes: 1 addition & 1 deletion src/utils/uiUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const shortenAddress = (address: string, chars = 4) =>
address.length > 8 ? `${address.slice(0, chars)}...${address.slice(-chars)}` : address

export const apyToApr = (apy: number) => {
const dailyRate = Math.pow(1 + apy / 100, 1 / 365) - 1
const dailyRate = Math.pow(1 + Math.abs(apy) / 100, 1 / 365) - 1
return dailyRate * 365 * 100
}

Expand Down
6 changes: 3 additions & 3 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1826,17 +1826,17 @@ export const calculateAPYAndAPR = (
tvl?: number
) => {
if (volume === undefined || fee === undefined || tvl === undefined) {
return { convertedApy: apy, convertedApr: apyToApr(apy) }
return { convertedApy: Math.abs(apy), convertedApr: Math.abs(apyToApr(apy)) }
}

if (poolsToRecalculateAPY.includes(poolAddress ?? '')) {
const parsedApr = ((volume * fee) / tvl) * 365

const parsedApy = (Math.pow((volume * fee * 0.01) / tvl + 1, 365) - 1) * 100

return { convertedApy: parsedApy, convertedApr: parsedApr }
return { convertedApy: Math.abs(parsedApy), convertedApr: Math.abs(parsedApr) }
} else {
return { convertedApy: apy, convertedApr: apyToApr(apy) }
return { convertedApy: Math.abs(apy), convertedApr: Math.abs(apyToApr(apy)) }
}
}

Expand Down
Loading