Skip to content

Commit

Permalink
Merge pull request #375 from invariant-labs/hot-fix-negative-apr-apy
Browse files Browse the repository at this point in the history
Hot fix negative apr apy
  • Loading branch information
wojciech-cichocki authored Jan 15, 2025
2 parents c3bb2cb + cefb268 commit be55b7d
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
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

0 comments on commit be55b7d

Please sign in to comment.