Skip to content

Commit

Permalink
fix: getApy days
Browse files Browse the repository at this point in the history
  • Loading branch information
LufyCZ committed Apr 14, 2022
1 parent 7b3905e commit ff3cddc
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export function useLegacyLiquidityPositionsBalances({ account, chainId }: Positi
swapFeePercent: 0.3,
twapEnabled: true,
value: (position.liquidityTokenBalance / pair.totalSupply) * pair.reserveUSD,
apy: getApy(pair.volumeUSD - pair1w.volumeUSD, pair.reserveUSD),
apy: getApy({ volume: pair.volumeUSD - pair1w.volumeUSD, liquidity: pair.reserveUSD, days: 7 }),
}
})
: undefined,
Expand Down
14 changes: 4 additions & 10 deletions src/features/analytics/pools/PairList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,7 @@ import { Token } from '@sushiswap/core-sdk'
import DoubleCurrencyLogo from 'app/components/DoubleLogo'
import Table from 'app/components/Table'
import ColoredNumber from 'app/features/analytics/ColoredNumber'
import { formatNumber, formatNumberScale, formatPercent } from 'app/functions'
import { aprToApy } from 'app/functions/convert/apyApr'
import { formatNumber, formatNumberScale, formatPercent, getApy } from 'app/functions'
import { useRouter } from 'next/router'
import React from 'react'

Expand Down Expand Up @@ -84,13 +83,6 @@ function PairListName({ pair }: PairListNameProps): JSX.Element {
)
}

// @ts-ignore TYPE NEEDS FIXING
export const getApy = (volume, liquidity) => {
const apy = aprToApy((((volume / 7) * 365 * 0.0025) / liquidity) * 100, 3650)
if (apy > 1000) return '>10,000%'
return formatPercent(apy)
}

const allColumns = [
{
Header: 'Pair',
Expand All @@ -109,7 +101,9 @@ const allColumns = [
{
Header: 'Annual APY',
// @ts-ignore TYPE NEEDS FIXING
accessor: (row) => <div className="text-high-emphesis">{getApy(row.volume1w, row.liquidity)}</div>,
accessor: (row) => (
<div className="text-high-emphesis">{getApy({ volume: row.volume1w, liquidity: row.liquidity, days: 7 })}</div>
),
align: 'right',
// @ts-ignore TYPE NEEDS FIXING
sortType: (a, b) => a.original.volume1w / a.original.liquidity - b.original.volume1w / b.original.liquidity,
Expand Down
2 changes: 1 addition & 1 deletion src/features/analytics/pools/useTableConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const useTableConfig = (chainId: number) => {
const tx2d = pair1d.txCount - pair2d.txCount
const tx1dChange = (tx1d / tx2d) * 100 - 100

const apy = getApy(volume1d, liquidity)
const apy = getApy({ volume: volume1d, liquidity, days: 1 })

return {
pair: {
Expand Down
12 changes: 7 additions & 5 deletions src/features/trident/pools/useAllPools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ export default function useAllPools({ chainId }: { chainId: number | undefined }
volumeUSD: Number(legacyPool.volumeUSD),
liquidityUSD: Number(legacyPool.reserveUSD),
transactionCount: Number(legacyPool.txCount),
apy: getApy(
legacyPool.volumeUSD -
legacyPools1w?.find((legacyPool1w: any) => legacyPool.id === legacyPool1w.id)?.volumeUSD ?? 0,
legacyPool.reserveUSD
),
apy: getApy({
volume:
legacyPool.volumeUSD -
legacyPools1w?.find((legacyPool1w: any) => legacyPool.id === legacyPool1w.id)?.volumeUSD ?? 0,
liquidity: legacyPool.reserveUSD,
days: 7,
}),
assets: [legacyPool.token0, legacyPool.token1].map(
(token: any) => new Token(chainId!, token.id, Number(token.decimals), token.symbol, token.name)
),
Expand Down
10 changes: 8 additions & 2 deletions src/functions/apy.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { aprToApy } from './convert'
import { formatPercent } from './format'

export const getApy = (volume: number, liquidity: number) => {
const apy = aprToApy((((volume / 7) * 365 * 0.0025) / liquidity) * 100, 3650)
interface getApy {
volume: number
liquidity: number
days: number
}

export const getApy = ({ volume, liquidity, days }: getApy) => {
const apy = aprToApy((((volume / days) * 365 * 0.0025) / liquidity) * 100, 3650)
if (apy > 1000) return '>10,000%'
return formatPercent(apy)
}

0 comments on commit ff3cddc

Please sign in to comment.