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

Include ROI Metrics for Pools #123

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 9 additions & 1 deletion src/components/pools/PoolTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ const ResponsiveGrid = styled.div`
grid-gap: 1em;
align-items: center;

grid-template-columns: 20px 3.5fr repeat(3, 1fr);
grid-template-columns: 20px 3.5fr repeat(4, 1fr);

@media screen and (max-width: 900px) {
grid-template-columns: 20px 1.5fr repeat(2, 1fr);
Expand Down Expand Up @@ -63,6 +63,8 @@ const SORT_FIELD = {
volumeUSD: 'volumeUSD',
tvlUSD: 'tvlUSD',
volumeUSDWeek: 'volumeUSDWeek',
feesUSD: 'feesUSD',
feesUSDChange: 'feesUSDChange',
}

const DataRow = ({ poolData, index }: { poolData: PoolData; index: number }) => {
Expand Down Expand Up @@ -92,6 +94,9 @@ const DataRow = ({ poolData, index }: { poolData: PoolData; index: number }) =>
<Label end={1} fontWeight={400}>
{formatDollarAmount(poolData.volumeUSDWeek)}
</Label>
<Label end={1} fontWeight={400}>
{formatDollarAmount(poolData.feesUSD)}
</Label>
</ResponsiveGrid>
</LinkWrapper>
)
Expand Down Expand Up @@ -172,6 +177,9 @@ export default function PoolTable({ poolDatas, maxItems = MAX_ITEMS }: { poolDat
<ClickableText color={theme.text2} end={1} onClick={() => handleSort(SORT_FIELD.volumeUSDWeek)}>
Volume 7D {arrow(SORT_FIELD.volumeUSDWeek)}
</ClickableText>
<ClickableText color={theme.text2} end={1} onClick={() => handleSort(SORT_FIELD.feesUSD)}>
24H Fees {arrow(SORT_FIELD.feesUSD)}
</ClickableText>
</ResponsiveGrid>
<Break />
{sortedPools.map((poolData, i) => {
Expand Down
5 changes: 5 additions & 0 deletions src/data/pools/chartData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const POOL_CHART = gql`
date
volumeUSD
tvlUSD
feesUSD
}
}
`
Expand All @@ -31,6 +32,7 @@ interface ChartResults {
date: number
volumeUSD: string
tvlUSD: string
feesUSD: string
}[]
}

Expand All @@ -39,6 +41,7 @@ export async function fetchPoolChartData(address: string, client: ApolloClient<N
date: number
volumeUSD: string
tvlUSD: string
feesUSD: string
}[] = []
const startTimestamp = 1619170975
const endTimestamp = dayjs.utc().unix()
Expand Down Expand Up @@ -79,6 +82,7 @@ export async function fetchPoolChartData(address: string, client: ApolloClient<N
date: dayData.date,
volumeUSD: parseFloat(dayData.volumeUSD),
totalValueLockedUSD: parseFloat(dayData.tvlUSD),
feesUSD: parseFloat(dayData.feesUSD),
}
return accum
}, {})
Expand All @@ -96,6 +100,7 @@ export async function fetchPoolChartData(address: string, client: ApolloClient<N
date: nextDay,
volumeUSD: 0,
totalValueLockedUSD: latestTvl,
feesUSD: 0,
}
} else {
latestTvl = formattedExisting[currentDayIndex].totalValueLockedUSD
Expand Down
11 changes: 11 additions & 0 deletions src/data/pools/poolData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export const POOLS_BULK = (block: number | undefined, pools: string[]) => {
totalValueLockedToken0
totalValueLockedToken1
totalValueLockedUSD
feesUSD
}
}
`
Expand Down Expand Up @@ -78,6 +79,7 @@ interface PoolFields {
totalValueLockedToken0: string
totalValueLockedToken1: string
totalValueLockedUSD: string
feesUSD: string
}

interface PoolDataResponse {
Expand Down Expand Up @@ -181,6 +183,13 @@ export function usePoolDatas(
? parseFloat(current.volumeUSD)
: 0

const [feesUSD, feesUSDChange] =
current && oneDay && twoDay
? get2DayChange(current.feesUSD, oneDay.feesUSD, twoDay.feesUSD)
: current
? [parseFloat(current.feesUSD), 0]
: [0, 0]

const tvlUSD = current ? parseFloat(current.totalValueLockedUSD) : 0

const tvlUSDChange =
Expand Down Expand Up @@ -225,6 +234,8 @@ export function usePoolDatas(
tvlUSDChange,
tvlToken0,
tvlToken1,
feesUSD,
feesUSDChange,
}
}

Expand Down
43 changes: 39 additions & 4 deletions src/pages/Pool/PoolPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ExternalLink, Download } from 'react-feather'
import { ExternalLink as StyledExternalLink } from '../../theme/components'
import useTheme from 'hooks/useTheme'
import CurrencyLogo from 'components/CurrencyLogo'
import { formatDollarAmount, formatAmount } from 'utils/numbers'
import { formatDollarAmount, formatAmount, formatPercentAmount } from 'utils/numbers'
import Percent from 'components/Percent'
import { ButtonPrimary, ButtonGray, SavedIcon } from 'components/Button'
import { DarkGreyCard, GreyCard, GreyBadge } from 'components/Card'
Expand Down Expand Up @@ -65,6 +65,7 @@ enum ChartView {
VOL,
PRICE,
DENSITY,
ROL,
}

export default function PoolPage({
Expand Down Expand Up @@ -117,6 +118,19 @@ export default function PoolPage({
}
}, [chartData])

const formattedReturnOnLiqData = useMemo(() => {
if (chartData) {
return chartData.map((day) => {
return {
time: unixToDate(day.date),
value: day.feesUSD / day.totalValueLockedUSD,
}
})
} else {
return []
}
}, [chartData])

//watchlist
const [savedPools, addSavedPool] = useSavedPools()

Expand Down Expand Up @@ -258,9 +272,13 @@ export default function PoolPage({
<TYPE.label fontSize="24px" height="30px">
<MonoSpace>
{latestValue
? formatDollarAmount(latestValue)
? view === ChartView.ROL
? formatPercentAmount(latestValue)
: formatDollarAmount(latestValue)
: view === ChartView.VOL
? formatDollarAmount(formattedVolumeData[formattedVolumeData.length - 1]?.value)
: view === ChartView.ROL
? formatPercentAmount(formattedReturnOnLiqData[formattedReturnOnLiqData.length - 1]?.value)
: view === ChartView.DENSITY
? ''
: formatDollarAmount(formattedTvlData[formattedTvlData.length - 1]?.value)}{' '}
Expand All @@ -270,7 +288,7 @@ export default function PoolPage({
{valueLabel ? <MonoSpace>{valueLabel} (UTC)</MonoSpace> : ''}
</TYPE.main>
</AutoColumn>
<ToggleWrapper width="200px">
<ToggleWrapper width="250px">
<ToggleElementFree
isActive={view === ChartView.VOL}
fontSize="12px"
Expand All @@ -281,10 +299,17 @@ export default function PoolPage({
<ToggleElementFree
isActive={view === ChartView.TVL}
fontSize="12px"
onClick={() => (view === ChartView.TVL ? setView(ChartView.DENSITY) : setView(ChartView.TVL))}
onClick={() => (view === ChartView.TVL ? setView(ChartView.ROL) : setView(ChartView.TVL))}
>
TVL
</ToggleElementFree>
<ToggleElementFree
isActive={view === ChartView.ROL}
fontSize="12px"
onClick={() => (view === ChartView.ROL ? setView(ChartView.DENSITY) : setView(ChartView.ROL))}
>
ROL
</ToggleElementFree>
<ToggleElementFree
isActive={view === ChartView.DENSITY}
fontSize="12px"
Expand Down Expand Up @@ -314,6 +339,16 @@ export default function PoolPage({
value={latestValue}
label={valueLabel}
/>
) : view === ChartView.ROL ? (
<LineChart
data={formattedReturnOnLiqData}
color={backgroundColor}
minHeight={340}
setValue={setLatestValue}
setLabel={setValueLabel}
value={latestValue}
label={valueLabel}
/>
) : (
<DensityChart address={address} />
)}
Expand Down
5 changes: 5 additions & 0 deletions src/state/pools/reducer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ export interface PoolData {
// token amounts
tvlToken0: number
tvlToken1: number

// fees
feesUSD: number
feesUSDChange: number
}

export type PoolChartEntry = {
date: number
volumeUSD: number
totalValueLockedUSD: number
feesUSD: number
}

export interface PoolsState {
Expand Down
18 changes: 18 additions & 0 deletions src/utils/numbers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,21 @@ export const formatAmount = (num: number | undefined, digits = 2) => {
},
})
}

// using a currency library here in case we want to add more in future
export const formatPercentAmount = (num: number | undefined, digits = 2) => {
if (num === 0) return '0.00%'
if (!num) return '-'
if (num < 0.0001) {
return '<0.01%'
}
return numbro(num).format({
average: true,
output: 'percent',
mantissa: num > 1 ? 0 : digits,
abbreviations: {
million: 'M',
billion: 'B',
},
})
}