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

chore: use cursor in subquery tvl #1934

Closed
wants to merge 9 commits into from
Closed
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
32 changes: 16 additions & 16 deletions centrifuge-app/.env-config/.env.development
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
REACT_APP_COLLATOR_WSS_URL=wss://fullnode.development.cntrfg.com
REACT_APP_COLLATOR_WSS_URL=wss://centrifuge-parachain.api.onfinality.io/public-ws
REACT_APP_DEFAULT_UNLIST_POOLS=false
REACT_APP_FAUCET_URL=https://europe-central2-peak-vista-185616.cloudfunctions.net/faucet-api-dev
REACT_APP_FAUCET_URL=
REACT_APP_IPFS_GATEWAY=https://centrifuge.mypinata.cloud/
REACT_APP_IS_DEMO=false
REACT_APP_IS_DEMO=
REACT_APP_NETWORK=centrifuge
REACT_APP_ONBOARDING_API_URL=https://europe-central2-peak-vista-185616.cloudfunctions.net/onboarding-api-dev
REACT_APP_PINNING_API_URL=https://europe-central2-peak-vista-185616.cloudfunctions.net/pinning-api-dev
REACT_APP_POOL_CREATION_TYPE=immediate
REACT_APP_RELAY_WSS_URL=wss://fullnode-relay.development.cntrfg.com
REACT_APP_SUBQUERY_URL=https://api.subquery.network/sq/centrifuge/pools-development
REACT_APP_ONBOARDING_API_URL=https://europe-central2-centrifuge-production-x.cloudfunctions.net/onboarding-api-production
REACT_APP_PINNING_API_URL=https://europe-central2-centrifuge-production-x.cloudfunctions.net/pinning-api-production
REACT_APP_POOL_CREATION_TYPE=propose
REACT_APP_RELAY_WSS_URL=wss://rpc.polkadot.io
REACT_APP_SUBQUERY_URL=https://api.subquery.network/sq/centrifuge/pools-multichain__Y2Vud
REACT_APP_SUBSCAN_URL=https://centrifuge.subscan.io
REACT_APP_TINLAKE_NETWORK=goerli
REACT_APP_INFURA_KEY=8cd8e043ee8d4001b97a1c37e08fd9dd
REACT_APP_ONFINALITY_KEY=0e1c049f-d876-4e77-a45f-b5afdf5739b2
REACT_APP_WHITELISTED_ACCOUNTS=
REACT_APP_TINLAKE_SUBGRAPH_URL=https://api.goldsky.com/api/public/project_clhi43ef5g4rw49zwftsvd2ks/subgraphs/main/prod/gn
REACT_APP_REWARDS_TREE_URL=https://storage.googleapis.com/rad-rewards-trees-kovan-staging/latest.json
REACT_APP_TINLAKE_NETWORK=mainnet
REACT_APP_INFURA_KEY=8ed99a9a115349bbbc01dcf3a24edc96
REACT_APP_ONFINALITY_KEY=84bb59f4-05cc-440b-8fd4-7917623a90c6
REACT_APP_WHITELISTED_ACCOUNTS=''
REACT_APP_REWARDS_TREE_URL=https://storage.googleapis.com/rad-rewards-trees-mainnet-production/latest.json
REACT_APP_MEMBERLIST_ADMIN_PURE_PROXY=kALJqPUHFzDR2VkoQYWefPQyzjGzKznNny2smXGQpSf3aMw19
REACT_APP_WALLETCONNECT_ID=c32fa79350803519804a67fcab0b742a
REACT_APP_MEMBERLIST_ADMIN_PURE_PROXY=kAJ27w29x7gHM75xajP2yXVLjVBaKmmUTxHwgRuCoAcWaoEiz
REACT_APP_TREASURY=kAJkmGxAd6iqX9JjWTdhXgCf2PL1TAphTRYrmEqzBrYhwbXAn
REACT_APP_TINLAKE_SUBGRAPH_URL=https://api.goldsky.com/api/public/project_clhi43ef5g4rw49zwftsvd2ks/subgraphs/main/prod/gn
REACT_APP_TREASURY=4dpEcgqJRyJK3J8Es6v8ZfVntV7c64Ysgcjd4hYwyGoFPWbg
2 changes: 1 addition & 1 deletion centrifuge-app/.env-config/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ REACT_APP_ONBOARDING_API_URL=https://europe-central2-centrifuge-fargate-apps-dev
REACT_APP_PINNING_API_URL=https://europe-central2-peak-vista-185616.cloudfunctions.net/pinningApi
REACT_APP_POOL_CREATION_TYPE=immediate
REACT_APP_RELAY_WSS_URL=wss://fullnode-relay.development.cntrfg.com
REACT_APP_SUBQUERY_URL=https://api.subquery.network/sq/centrifuge/pools-development
REACT_APP_SUBQUERY_URL=https://api.subquery.network/sq/centrifuge/pools-multichain
REACT_APP_SUBSCAN_URL=
REACT_APP_TINLAKE_NETWORK=goerli
REACT_APP_INFURA_KEY=bf808e7d3d924fbeb74672d9341d0550
Expand Down
5 changes: 3 additions & 2 deletions centrifuge-app/src/components/Charts/PoolPerformanceChart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,16 @@ function PoolPerformanceChart() {
const [range, setRange] = React.useState<(typeof rangeFilters)[number]>({ value: 'all', label: 'All' })
const rangeNumber = getRangeNumber(range.value, poolAge) ?? 100

const isSingleTranche = pool?.tranches.length === 1
const data: ChartData[] = React.useMemo(
() =>
truncatedPoolStates?.map((day) => {
const nav = day.poolState.netAssetValue.toDecimal().toNumber()
const price = Object.values(day.tranches).length === 1 ? Object.values(day.tranches)[0].price!.toFloat() : null
const price = (isSingleTranche && Object.values(day.tranches)[0].price?.toFloat()) || null

return { day: new Date(day.timestamp), nav, price }
}) || [],
[truncatedPoolStates]
[truncatedPoolStates, isSingleTranche]
)

const chartData = data.slice(-rangeNumber)
Expand Down
46 changes: 6 additions & 40 deletions centrifuge-app/src/components/Charts/TotalValueLocked.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import Decimal from 'decimal.js-light'
import * as React from 'react'
import { useQuery } from 'react-query'
import { Area, AreaChart, ResponsiveContainer, Tooltip } from 'recharts'
import { getTinlakeSubgraphTVL } from '../../utils/tinlake/getTinlakeSubgraphTVL'
import { useDailyTVL } from '../../utils/usePools'

export type DataPoint = {
Expand All @@ -17,23 +15,24 @@ type TotalValueLockedProps = {

export default function TotalValueLocked({ chainTVL, setHovered }: TotalValueLockedProps) {
const centrifugeTVL = useDailyTVL()
const tinlakeTVL = useDailyTinlakeTVL()
const chartColor = '#ff8c00'

const chartData = React.useMemo(() => {
if (!tinlakeTVL || !centrifugeTVL) {
if (!centrifugeTVL) {
return []
}

const currentTVL = chainTVL
? {
dateInMilliseconds: new Date().setHours(0, 0, 0, 0),
dateInMilliseconds: new Date().setUTCHours(0, 0, 0, 0),
tvl: chainTVL,
}
: undefined

return getMergedData([...tinlakeTVL, ...centrifugeTVL], currentTVL)
}, [tinlakeTVL, centrifugeTVL, chainTVL])
const tvlSnapshots = centrifugeTVL.map((entry) => ({ ...entry, tvl: entry.tvl.toNumber() }))

return [...tvlSnapshots, currentTVL]
}, [centrifugeTVL, chainTVL])

return (
<ResponsiveContainer>
Expand Down Expand Up @@ -69,36 +68,3 @@ export default function TotalValueLocked({ chainTVL, setHovered }: TotalValueLoc
</ResponsiveContainer>
)
}

function useDailyTinlakeTVL() {
const { data } = useQuery('use daily tinlake tvl', getTinlakeSubgraphTVL, {
staleTime: Infinity,
suspense: true,
})

return data
}

function getMergedData(combined: DataPoint[], current?: DataPoint) {
const mergedMap = new Map()

combined.forEach((entry) => {
const { dateInMilliseconds, tvl } = entry

if (mergedMap.has(dateInMilliseconds)) {
mergedMap.set(dateInMilliseconds, mergedMap.get(dateInMilliseconds).add(tvl))
} else {
mergedMap.set(dateInMilliseconds, tvl)
}
})

if (current) {
mergedMap.set(current.dateInMilliseconds, current.tvl)
}

const merged = Array.from(mergedMap, ([dateInMilliseconds, tvl]) => ({ dateInMilliseconds, tvl }))
.sort((a, b) => a.dateInMilliseconds - b.dateInMilliseconds)
.map((entry) => ({ ...entry, tvl: entry.tvl.toNumber() }))

return merged
}
40 changes: 0 additions & 40 deletions centrifuge-app/src/utils/tinlake/getTinlakeSubgraphTVL.ts

This file was deleted.

2 changes: 1 addition & 1 deletion centrifuge-js/src/CentrifugeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const defaultConfig: Config = {
altairWsUrl: 'wss://fullnode.altair.centrifuge.io',
polkadotWsUrl: 'wss://rpc.polkadot.io',
kusamaWsUrl: 'wss://kusama-rpc.polkadot.io',
centrifugeSubqueryUrl: 'https://api.subquery.network/sq/centrifuge/pools',
centrifugeSubqueryUrl: 'https://api.subquery.network/sq/centrifuge/pools-multichain',
altairSubqueryUrl: 'https://api.subquery.network/sq/centrifuge/pools-altair',
metadataHost: 'https://centrifuge.mypinata.cloud',
}
Expand Down
Loading
Loading