Skip to content

Commit

Permalink
Improved avg liquidation efficiency chart + TODOs
Browse files Browse the repository at this point in the history
  • Loading branch information
Ncookiez committed Oct 27, 2023
1 parent 95e6058 commit 7176871
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { PrizePool } from '@generationsoftware/hyperstructure-client-js'
import {
useBlocksAtTimestamps,
useDrawIds,
useHistoricalTokenPrices,
useLiquidationEvents,
usePrizeTokenData
Expand All @@ -14,7 +15,6 @@ import { Address, formatUnits } from 'viem'
import { QUERY_START_BLOCK } from '@constants/config'
import { useAllDrawsStatus } from '@hooks/useAllDrawsStatus'
import { useHistoricalLiquidationPairTokenOutPrices } from '@hooks/useHistoricalLiquidationPairTokenOutPrices'
import { useRngTxs } from '@hooks/useRngTxs'
import { LineChart } from './LineChart'

interface DrawsAvgLiqEfficiencyChartProps {
Expand All @@ -29,22 +29,20 @@ export const DrawsAvgLiqEfficiencyChart = (props: DrawsAvgLiqEfficiencyChartProp
fromBlock: !!prizePool ? QUERY_START_BLOCK[prizePool.chainId] : undefined
})

const { data: rngTxs } = useRngTxs(prizePool)
const drawIds = rngTxs?.map((txs) => txs.rng.drawId) ?? []
const { data: drawIds } = useDrawIds(prizePool)

const { data: allDrawsStatus } = useAllDrawsStatus(prizePool, drawIds)

const currentTimestamp = useAtomValue(currentTimestampAtom)

const uniqueOpenedAtTimestamps = new Set(allDrawsStatus?.map((draw) => draw.openedAt))
const { data: openedAtBlocksByTimestamp } = useBlocksAtTimestamps(prizePool?.chainId, [
...uniqueOpenedAtTimestamps
])
const { data: openedAtBlocksByTimestamp } = useBlocksAtTimestamps(
prizePool?.chainId,
allDrawsStatus?.map((draw) => draw.openedAt) ?? []
)

const uniqueClosedAtTimestamps = new Set(allDrawsStatus?.map((draw) => draw.closedAt))
const { data: closedAtBlocksByTimestamp } = useBlocksAtTimestamps(
prizePool?.chainId,
[...uniqueClosedAtTimestamps].filter((t) => !!t) as number[]
allDrawsStatus?.map((draw) => draw.closedAt) ?? []
)

// TODO: this assumes the tokenIn is always POOL (and uses mainnet pricing) - not ideal
Expand Down
1 change: 1 addition & 0 deletions apps/analytics/src/hooks/useAllDrawsStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getSecondsSinceEpoch } from '@shared/utilities'
import { useMemo } from 'react'
import { useRngTxs } from './useRngTxs'

// TODO: need to be able to set refetch interval or manual refetch
export const useAllDrawsStatus = (prizePool: PrizePool, drawIds: number[]) => {
const { data: firstDrawOpenedAt, isFetched: isFetchedFirstDrawOpenedAt } =
useFirstDrawOpenedAt(prizePool)
Expand Down
1 change: 1 addition & 0 deletions apps/analytics/src/hooks/useDrawStatus.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { getSecondsSinceEpoch } from '@shared/utilities'
import { useMemo } from 'react'
import { useRngTxs } from './useRngTxs'

// TODO: need to be able to set refetch interval or manual refetch
export const useDrawStatus = (prizePool: PrizePool, drawId: number) => {
const { data: firstDrawOpenedAt, isFetched: isFetchedFirstDrawOpenedAt } =
useFirstDrawOpenedAt(prizePool)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getSecondsSinceEpoch, PrizePool } from '@generationsoftware/hyperstruct
import { useMemo } from 'react'
import { useAllDrawPeriods, useAllFirstDrawOpenedAt } from '..'

// TODO: need to be able to set refetch interval or manual refetch
/**
* Returns any prize pools' draw IDs
* @param prizePool array of instances of the `PrizePool` class
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { getSecondsSinceEpoch, PrizePool } from '@generationsoftware/hyperstruct
import { useMemo } from 'react'
import { useDrawPeriod, useFirstDrawOpenedAt } from '..'

// TODO: need to be able to set refetch interval or manual refetch
/**
* Returns a prize pool's draw IDs
* @param prizePool instance of the `PrizePool` class
Expand Down

0 comments on commit 7176871

Please sign in to comment.