Skip to content

Commit

Permalink
Fix staking tvl calculation + revert some changes
Browse files Browse the repository at this point in the history
Only tbtc graph was not working so we don't need to replace the graph for t
network. Replacing it the staking tvl section to show a wrong value.
  • Loading branch information
michalsmiarowski committed Jul 5, 2024
1 parent e9e18c4 commit abdaee9
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 39 deletions.
4 changes: 1 addition & 3 deletions src/config/subgraph.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,4 @@ export const T_NETWORK_SUBGRAPH_URL =
export const T_NETWORK_SUBGRAPH_ID =
"5TJAMbsRwm1avUTV4CofaLT4apfQoAiNcysEit9BWr6R"

export const TBTC_SUBGRAPH_ID = "DETCX5Xm6tJfctRcZAxhQB9q3aK8P4BXLbujHmzEBXYV"

export const SUBGRAPH_GATEWAY_URL = `https://gateway-arbitrum.network.thegraph.com/api/${process.env.SUBGRAPH_API_KEY}/subgraphs/id/`
export const TBTC_SUBGRAPH_URL = `https://gateway-arbitrum.network.thegraph.com/api/${process.env.SUBGRAPH_API_KEY}/subgraphs/id/DETCX5Xm6tJfctRcZAxhQB9q3aK8P4BXLbujHmzEBXYV`
4 changes: 2 additions & 2 deletions src/hooks/tBTC/useTotalMints.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { gql, request } from "graphql-request"
import { TBTC_SUBGRAPH_ID, SUBGRAPH_GATEWAY_URL } from "../../config/subgraph"
import { useEffect, useState } from "react"
import { TBTC_SUBGRAPH_URL } from "../../config/subgraph"

export const useTotalMints = () => {
const [totalMints, setTotalMints] = useState<number | undefined>(undefined)
Expand All @@ -25,7 +25,7 @@ export const useTotalMints = () => {
}`

const result: { transactions: { id: string }[] } = await request(
SUBGRAPH_GATEWAY_URL + TBTC_SUBGRAPH_ID,
TBTC_SUBGRAPH_URL,
query
)

Expand Down
8 changes: 5 additions & 3 deletions src/hooks/useQuery.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { SUBGRAPH_GATEWAY_URL } from "../config/subgraph"
import { useEffect, useReducer, useRef, Reducer } from "react"
import { request } from "graphql-request"

Expand Down Expand Up @@ -35,7 +34,10 @@ const fetchReducer = <T>(state: State<T>, action: Action<T>): State<T> => {
}
}

function useQuery<T = unknown>(subgraphId: string, query?: string): State<T> {
function useQuery<T = unknown>(
graphEndpoint: string,
query?: string
): State<T> {
const shouldUpdateState = useRef<boolean>(true)
const initialState: State<T> = {
error: undefined,
Expand All @@ -57,7 +59,7 @@ function useQuery<T = unknown>(subgraphId: string, query?: string): State<T> {
dispatch({ type: Actions.Start })

try {
const response = await request(SUBGRAPH_GATEWAY_URL + subgraphId, query)
const response = await request(graphEndpoint, query)
if (!shouldUpdateState.current) return

dispatch({ type: Actions.Success, payload: response })
Expand Down
5 changes: 2 additions & 3 deletions src/templates/earn-page/btc/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import { Box, Stack, VStack } from "@chakra-ui/react"
import RolePageTemplate from "../RolePageTemplate"
import SectionTemplate from "../../home-page/SectionTemplate"
import { BodyLg, H4, H5 } from "../../../components"
import { LPCardGroup } from "../../../components/LPCard"
import { TBTCStats } from "./TBTCStats"
import { gql } from "graphql-request"
import { TBTC_SUBGRAPH_ID } from "../../../config/subgraph"
import { TBTC_SUBGRAPH_URL } from "../../../config/subgraph"
import useQuery from "../../../hooks/useQuery"
import { LatestMint, LatestMints } from "./LatestMints"
import ExternalButtonLink from "../../../components/Buttons/ExternalButtonLink"
Expand All @@ -32,7 +31,7 @@ const BTCPageTemplate: FC<any> = ({ data }) => {
tbtctoken: { currentTokenHolders: string; totalSupply: string }
transactions: LatestMint[]
}>(
TBTC_SUBGRAPH_ID,
TBTC_SUBGRAPH_URL,
gql`
query {
tbtctoken(id: "TBTCToken") {
Expand Down
28 changes: 12 additions & 16 deletions src/templates/earn-page/staker/NetworkDistribution/index.tsx
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
import { Box, HStack, Icon, SimpleGrid, Stack } from "@chakra-ui/react"
import { Box, HStack, Icon, Stack } from "@chakra-ui/react"
import { gql } from "graphql-request"
import Card from "../../../../components/Card"
import TStakedChart from "./TStakedChart"
import { BodyLg, H2, H3, H5, LabelMd } from "../../../../components"
import useQuery from "../../../../hooks/useQuery"
import { T_NETWORK_SUBGRAPH_ID } from "../../../../config/subgraph"
import { T_NETWORK_SUBGRAPH_URL } from "../../../../config/subgraph"
import {
exchangeAPI,
formatFiatCurrencyAmount,
formatTokenAmount,
formatUnits,
} from "../../../../utils"
import StatBox from "../../../../components/StatBox"
import { useTTokenPrice } from "../../../../contexts/TokenPriceContext"
import {
BsFillInfoCircleFill,
IoInformationCircleOutline,
} from "react-icons/all"
import { BsFillInfoCircleFill } from "react-icons/all"

function NetworkDistribution() {
const { isFetching, data, error } = useQuery<{
daometric: { stakedTotal: string }
epoches: { totalStaked: string }[]
minStakeAmounts: { amount: string }[]
}>(
T_NETWORK_SUBGRAPH_ID,
T_NETWORK_SUBGRAPH_URL,
gql`
query {
daometric(id: "dao-metrics") {
stakedTotal
epoches(orderBy: startTime, orderDirection: desc, first: 1) {
totalStaked
}
minStakeAmounts(first: 1, orderBy: updatedAt, orderDirection: desc) {
amount
}
}
`
)
const { daometric, minStakeAmounts } = data || {
daometric: { stakedTotal: "0" },
const { epoches, minStakeAmounts } = data || {
epoches: [{ totalStaked: "0" }],
minStakeAmounts: [{ amount: "0" }],
}
const stakedTotal = !error ? daometric.stakedTotal : "0"
const forrmattedTotalStaked = formatTokenAmount(stakedTotal)
const totalStaked = !error ? epoches[0].totalStaked : "0"
const forrmattedTotalStaked = formatTokenAmount(totalStaked)
const minStakeAmount = formatTokenAmount(
!error ? minStakeAmounts[0].amount : "0"
)
const tPrice = useTTokenPrice()
const totalValueStakedInUSD = formatFiatCurrencyAmount(
exchangeAPI.toUsdBalance(formatUnits(stakedTotal), tPrice).toString()
exchangeAPI.toUsdBalance(formatUnits(totalStaked), tPrice).toString()
)

return (
Expand Down
4 changes: 2 additions & 2 deletions src/templates/governance-page/ThresholdDaoDataSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { PageSection } from "../../components/PageSection"
import { H2, H3, LabelMd } from "../../components"
import { ExternalLinkHref } from "../../components/Navbar/types"
import { StatBoxGroup } from "../../components/StatBox"
import { T_NETWORK_SUBGRAPH_ID } from "../../config/subgraph"
import { T_NETWORK_SUBGRAPH_URL } from "../../config/subgraph"
import useQuery from "../../hooks/useQuery"
import { formatFiatCurrencyAmount, formatTokenAmount } from "../../utils"
import { useBalanceOfDAOTreasury } from "../../hooks/useBalanceOfDAOTreasury"
Expand All @@ -21,7 +21,7 @@ const ThresholdDaoDataSection = () => {
tokenholderDelegations: { id: string }[]
stakeDelegations: { id: string }[]
}>(
T_NETWORK_SUBGRAPH_ID,
T_NETWORK_SUBGRAPH_URL,
gql`
query {
daometric(id: "dao-metrics") {
Expand Down
20 changes: 10 additions & 10 deletions src/templates/home-page/Hero/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { TrackComponent } from "../../../components/Posthog/TrackComponent"
import { Analytics } from "./Analytics"
import { gql } from "graphql-request"
import {
TBTC_SUBGRAPH_ID,
T_NETWORK_SUBGRAPH_ID,
TBTC_SUBGRAPH_URL,
T_NETWORK_SUBGRAPH_URL,
} from "../../../config/subgraph"
import useQuery from "../../../hooks/useQuery"
import { exchangeAPI, formatUnits } from "../../../utils"
Expand All @@ -33,14 +33,14 @@ const Hero: FC<{
data: totalStakedData,
error: totalStakedError,
} = useQuery<{
daometric: { stakedTotal: string }
epoches: { totalStaked: string }[]
minStakeAmounts: { amount: string }[]
}>(
T_NETWORK_SUBGRAPH_ID,
T_NETWORK_SUBGRAPH_URL,
gql`
query {
daometric(id: "dao-metrics") {
stakedTotal
epoches(orderBy: startTime, orderDirection: desc, first: 1) {
totalStaked
}
}
`
Expand All @@ -49,7 +49,7 @@ const Hero: FC<{
const { isFetching, data, error } = useQuery<{
tbtctoken: { currentTokenHolders: string; totalSupply: string }
}>(
TBTC_SUBGRAPH_ID,
TBTC_SUBGRAPH_URL,
gql`
query {
tbtctoken(id: "TBTCToken") {
Expand All @@ -60,10 +60,10 @@ const Hero: FC<{
`
)

const { daometric } = totalStakedData || {
daometric: { stakedTotal: "0" },
const { epoches } = totalStakedData || {
epoches: [{ totalStaked: "0" }],
}
const totalStaked = !error ? daometric.stakedTotal : "0"
const totalStaked = !totalStakedError ? epoches[0].totalStaked : "0"
const tPrice = useTTokenPrice()
const totalValueStakedInUSD = exchangeAPI
.toUsdBalance(formatUnits(totalStaked), tPrice)
Expand Down

0 comments on commit abdaee9

Please sign in to comment.