diff --git a/libs/analytics/src/FinancialStatement.generated.ts b/libs/analytics/src/FinancialStatement.generated.ts index 39162283a..590f96524 100644 --- a/libs/analytics/src/FinancialStatement.generated.ts +++ b/libs/analytics/src/FinancialStatement.generated.ts @@ -3,161 +3,130 @@ import { useQuery } from '@tanstack/react-query'; import type * as Types from '@origin/oeth/shared'; import type { UseQueryOptions } from '@tanstack/react-query'; -export type FinancialStatementReportQueryVariables = Types.Exact<{ +export type FinancialStatementQueryVariables = Types.Exact<{ compareDate?: Types.InputMaybe; }>; -export type FinancialStatementReportQuery = { +export type FinancialStatementQuery = { __typename?: 'Query'; - financialStatements: Array<{ - __typename?: 'FinancialStatement'; + oeths: Array<{ + __typename?: 'OETH'; blockNumber: number; timestamp: any; - oeth: { __typename?: 'OETH'; totalSupply: any }; - curveLP: { - __typename?: 'CurveLP'; - eth: any; - ethOwned: any; - oeth: any; - oethOwned: any; - totalSupply: any; - totalSupplyOwned: any; - }; - dripper: { __typename?: 'Dripper'; weth: any }; - fraxStaking: { __typename?: 'FraxStaking'; frxETH: any }; - morphoAave: { __typename?: 'MorphoAave'; weth: any }; - vault: { - __typename?: 'Vault'; - weth: any; - rETH: any; - stETH: any; - frxETH: any; - }; + totalSupply: any; }>; - financialStatementsCompare: Array<{ - __typename?: 'FinancialStatement'; + curveLps: Array<{ + __typename?: 'CurveLP'; blockNumber: number; timestamp: any; - oeth: { __typename?: 'OETH'; totalSupply: any }; - curveLP: { - __typename?: 'CurveLP'; - eth: any; - ethOwned: any; - oeth: any; - oethOwned: any; - totalSupply: any; - totalSupplyOwned: any; - }; - dripper: { __typename?: 'Dripper'; weth: any }; - fraxStaking: { __typename?: 'FraxStaking'; frxETH: any }; - morphoAave: { __typename?: 'MorphoAave'; weth: any }; - vault: { - __typename?: 'Vault'; - weth: any; - rETH: any; - stETH: any; - frxETH: any; - }; + eth: any; + ethOwned: any; + oeth: any; + oethOwned: any; + totalSupply: any; + totalSupplyOwned: any; + }>; + morphoAaves: Array<{ + __typename?: 'MorphoAave'; + blockNumber: number; + timestamp: any; + weth: any; + }>; + fraxStakings: Array<{ + __typename?: 'FraxStaking'; + blockNumber: number; + timestamp: any; + frxETH: any; + }>; + drippers: Array<{ + __typename?: 'Dripper'; + blockNumber: number; + timestamp: any; + weth: any; + }>; + vaults: Array<{ + __typename?: 'Vault'; + blockNumber: number; + timestamp: any; + weth: any; + rETH: any; + stETH: any; + frxETH: any; }>; }; -export const FinancialStatementReportDocument = ` - query FinancialStatementReport($compareDate: DateTime) { - financialStatements(orderBy: id_DESC, limit: 1) { +export const FinancialStatementDocument = ` + query FinancialStatement($compareDate: DateTime) { + oeths(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { + blockNumber + timestamp + totalSupply + } + curveLps(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { blockNumber timestamp - oeth { - totalSupply - } - curveLP { - eth - ethOwned - oeth - oethOwned - totalSupply - totalSupplyOwned - } - dripper { - weth - } - fraxStaking { - frxETH - } - morphoAave { - weth - } - vault { - weth - rETH - stETH - frxETH - } + eth + ethOwned + oeth + oethOwned + totalSupply + totalSupplyOwned } - financialStatementsCompare: financialStatements( - orderBy: id_DESC - limit: 1 - where: {timestamp_lt: $compareDate} - ) { + morphoAaves(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { blockNumber timestamp - oeth { - totalSupply - } - curveLP { - eth - ethOwned - oeth - oethOwned - totalSupply - totalSupplyOwned - } - dripper { - weth - } - fraxStaking { - frxETH - } - morphoAave { - weth - } - vault { - weth - rETH - stETH - frxETH - } + weth + } + fraxStakings(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { + blockNumber + timestamp + frxETH + } + drippers(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { + blockNumber + timestamp + weth + } + vaults(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { + blockNumber + timestamp + weth + rETH + stETH + frxETH } } `; -export const useFinancialStatementReportQuery = < - TData = FinancialStatementReportQuery, +export const useFinancialStatementQuery = < + TData = FinancialStatementQuery, TError = unknown, >( - variables?: FinancialStatementReportQueryVariables, - options?: UseQueryOptions, + variables?: FinancialStatementQueryVariables, + options?: UseQueryOptions, ) => - useQuery( + useQuery( variables === undefined - ? ['FinancialStatementReport'] - : ['FinancialStatementReport', variables], - graphqlClient< - FinancialStatementReportQuery, - FinancialStatementReportQueryVariables - >(FinancialStatementReportDocument, variables), + ? ['FinancialStatement'] + : ['FinancialStatement', variables], + graphqlClient( + FinancialStatementDocument, + variables, + ), options, ); -useFinancialStatementReportQuery.getKey = ( - variables?: FinancialStatementReportQueryVariables, +useFinancialStatementQuery.getKey = ( + variables?: FinancialStatementQueryVariables, ) => variables === undefined - ? ['FinancialStatementReport'] - : ['FinancialStatementReport', variables]; -useFinancialStatementReportQuery.fetcher = ( - variables?: FinancialStatementReportQueryVariables, + ? ['FinancialStatement'] + : ['FinancialStatement', variables]; +useFinancialStatementQuery.fetcher = ( + variables?: FinancialStatementQueryVariables, options?: RequestInit['headers'], ) => - graphqlClient< - FinancialStatementReportQuery, - FinancialStatementReportQueryVariables - >(FinancialStatementReportDocument, variables, options); + graphqlClient( + FinancialStatementDocument, + variables, + options, + ); diff --git a/libs/analytics/src/FinancialStatement.graphql b/libs/analytics/src/FinancialStatement.graphql index 3a7e3bac4..a7d29425a 100644 --- a/libs/analytics/src/FinancialStatement.graphql +++ b/libs/analytics/src/FinancialStatement.graphql @@ -1,62 +1,40 @@ -query FinancialStatementReport($compareDate: DateTime) { - financialStatements(orderBy: id_DESC, limit: 1) { +query FinancialStatement($compareDate: DateTime) { + oeths(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { blockNumber timestamp - oeth { - totalSupply - } - curveLP { - eth - ethOwned - oeth - oethOwned - totalSupply - totalSupplyOwned - } - dripper { - weth - } - fraxStaking { - frxETH - } - morphoAave { - weth - } - vault { - weth - rETH - stETH - frxETH - } + totalSupply } - financialStatementsCompare: financialStatements(orderBy: id_DESC, limit: 1, where: {timestamp_lt: $compareDate}) { + curveLps(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { blockNumber timestamp - oeth { - totalSupply - } - curveLP { - eth - ethOwned - oeth - oethOwned - totalSupply - totalSupplyOwned - } - dripper { - weth - } - fraxStaking { - frxETH - } - morphoAave { - weth - } - vault { - weth - rETH - stETH - frxETH - } + eth + ethOwned + oeth + oethOwned + totalSupply + totalSupplyOwned + } + morphoAaves(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { + blockNumber + timestamp + weth + } + fraxStakings(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { + blockNumber + timestamp + frxETH + } + drippers(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { + blockNumber + timestamp + weth + } + vaults(limit: 1, orderBy: id_DESC, where: {timestamp_lt: $compareDate}) { + blockNumber + timestamp + weth + rETH + stETH + frxETH } } diff --git a/libs/analytics/src/FinancialStatement.tsx b/libs/analytics/src/FinancialStatement.tsx index 3642bcc51..9b7df302d 100644 --- a/libs/analytics/src/FinancialStatement.tsx +++ b/libs/analytics/src/FinancialStatement.tsx @@ -14,7 +14,7 @@ import { useIntl } from 'react-intl'; import { formatEther } from 'viem'; import * as colors from './colors'; -import { useFinancialStatementReportQuery } from './FinancialStatement.generated'; +import { useFinancialStatementQuery } from './FinancialStatement.generated'; dayjs.extend(LocalizedFormat); @@ -37,56 +37,76 @@ const getTotals = (data: Record>) => { }; export const LiveFinancialStatement = () => { + const endOfToday = dayjs().endOf('day').toISOString(); const [sevenDaysAgo] = useState(dayjs().subtract(7, 'days').toISOString()); - const { isLoading, data } = useFinancialStatementReportQuery({ + const { isLoading: fsIsLoading, data: fs } = useFinancialStatementQuery({ + compareDate: endOfToday, + }); + const { isLoading: fsCIsLoading, data: fsC } = useFinancialStatementQuery({ compareDate: sevenDaysAgo, }); - if (isLoading || !data) return null; + if (fsIsLoading || !fs) return null; + if (fsCIsLoading || !fsC) return null; - const fs = data.financialStatements[0]; - const fsC = data.financialStatementsCompare[0]; - const c = (n: string) => Number(formatEther(BigInt(n))); + const c = (n?: string) => Number(formatEther(BigInt(n ?? 0))); - if (!fs) return null; - if (!fsC) return null; + const blockNumber = Math.max( + fs.vaults[0]?.blockNumber, + fs.curveLps[0]?.blockNumber, + fs.morphoAaves[0]?.blockNumber, + fs.drippers[0]?.blockNumber, + fs.oeths[0]?.blockNumber, + fs.fraxStakings[0]?.blockNumber, + ); + const timestamp = Math.max( + fs.vaults[0]?.timestamp, + fs.curveLps[0]?.timestamp, + fs.morphoAaves[0]?.timestamp, + fs.drippers[0]?.timestamp, + fs.oeths[0]?.timestamp, + fs.fraxStakings[0]?.timestamp, + ); return ( >; - OR?: InputMaybe>; - blockNumber_eq?: InputMaybe; - blockNumber_gt?: InputMaybe; - blockNumber_gte?: InputMaybe; - blockNumber_in?: InputMaybe>; - blockNumber_isNull?: InputMaybe; - blockNumber_lt?: InputMaybe; - blockNumber_lte?: InputMaybe; - blockNumber_not_eq?: InputMaybe; - blockNumber_not_in?: InputMaybe>; - curveLP?: InputMaybe; - curveLP_isNull?: InputMaybe; - dripper?: InputMaybe; - dripper_isNull?: InputMaybe; - fraxStaking?: InputMaybe; - fraxStaking_isNull?: InputMaybe; - id_contains?: InputMaybe; - id_containsInsensitive?: InputMaybe; - id_endsWith?: InputMaybe; - id_eq?: InputMaybe; - id_gt?: InputMaybe; - id_gte?: InputMaybe; - id_in?: InputMaybe>; - id_isNull?: InputMaybe; - id_lt?: InputMaybe; - id_lte?: InputMaybe; - id_not_contains?: InputMaybe; - id_not_containsInsensitive?: InputMaybe; - id_not_endsWith?: InputMaybe; - id_not_eq?: InputMaybe; - id_not_in?: InputMaybe>; - id_not_startsWith?: InputMaybe; - id_startsWith?: InputMaybe; - morphoAave?: InputMaybe; - morphoAave_isNull?: InputMaybe; - oeth?: InputMaybe; - oeth_isNull?: InputMaybe; - timestamp_eq?: InputMaybe; - timestamp_gt?: InputMaybe; - timestamp_gte?: InputMaybe; - timestamp_in?: InputMaybe>; - timestamp_isNull?: InputMaybe; - timestamp_lt?: InputMaybe; - timestamp_lte?: InputMaybe; - timestamp_not_eq?: InputMaybe; - timestamp_not_in?: InputMaybe>; - vault?: InputMaybe; - vault_isNull?: InputMaybe; -}; - -export type FinancialStatementsConnection = { - __typename?: 'FinancialStatementsConnection'; - edges: Array; - pageInfo: PageInfo; - totalCount: Scalars['Int']['output']; -}; - export type FraxStaking = { __typename?: 'FraxStaking'; blockNumber: Scalars['Int']['output']; @@ -1269,11 +1048,6 @@ export type Query = { dripperByUniqueInput?: Maybe; drippers: Array; drippersConnection: DrippersConnection; - financialStatementById?: Maybe; - /** @deprecated Use financialStatementById */ - financialStatementByUniqueInput?: Maybe; - financialStatements: Array; - financialStatementsConnection: FinancialStatementsConnection; fraxStakingById?: Maybe; /** @deprecated Use fraxStakingById */ fraxStakingByUniqueInput?: Maybe; @@ -1417,32 +1191,6 @@ export type QueryDrippersConnectionArgs = { }; -export type QueryFinancialStatementByIdArgs = { - id: Scalars['String']['input']; -}; - - -export type QueryFinancialStatementByUniqueInputArgs = { - where: WhereIdInput; -}; - - -export type QueryFinancialStatementsArgs = { - limit?: InputMaybe; - offset?: InputMaybe; - orderBy?: InputMaybe>; - where?: InputMaybe; -}; - - -export type QueryFinancialStatementsConnectionArgs = { - after?: InputMaybe; - first?: InputMaybe; - orderBy: Array; - where?: InputMaybe; -}; - - export type QueryFraxStakingByIdArgs = { id: Scalars['String']['input']; };