diff --git a/.example.env b/.example.env index 621a452eb3..ca2d6f22bf 100644 --- a/.example.env +++ b/.example.env @@ -17,7 +17,7 @@ NEXT_PUBLIC_SUBGRAPH_URL= SUBGRAPH_URL= # wallet connect -NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID +NEXT_PUBLIC_WALLET_CONNECT_PROJECT_ID= ##### Variables for complete functionality ##### diff --git a/src/components/VolumeChart/hooks/useProjectTimeline.ts b/src/components/VolumeChart/hooks/useProjectTimeline.ts index 55520a1c32..cc8fea805e 100644 --- a/src/components/VolumeChart/hooks/useProjectTimeline.ts +++ b/src/components/VolumeChart/hooks/useProjectTimeline.ts @@ -1,8 +1,12 @@ import { useQuery } from '@tanstack/react-query' -import { PV_V4 } from 'constants/pv' +import { PV_V2, PV_V4 } from 'constants/pv' import { readProvider } from 'constants/readProvider' import EthDater from 'ethereum-block-by-date' -import { ProjectTlQuery, useProjectTlQuery } from 'generated/graphql' +import { + ProjectTlQuery, + useProjectsQuery, + useProjectTlQuery, +} from 'generated/graphql' import { client } from 'lib/apollo/client' import { PV } from 'models/pv' import { ProjectTlDocument } from 'packages/v4/graphql/client/graphql' @@ -11,6 +15,8 @@ import { useMemo } from 'react' import { wadToFloat } from 'utils/format/formatNumber' import { getSubgraphIdForProject } from 'utils/graph' import { daysToMS, minutesToMS } from 'utils/units' +import { RomanStormVariables } from 'constants/romanStorm' + import { ProjectTimelinePoint, ProjectTimelineRange } from '../types' const COUNT = 30 @@ -24,6 +30,25 @@ export function useProjectTimeline({ pv: PV range: ProjectTimelineRange }) { + const exceptionTimestamp = useMemo(() => { + return RomanStormVariables.PROJECT_ID === projectId + ? RomanStormVariables.SNAPSHOT_TIMESTAMP + : null + }, [projectId]) + + const { data: romanStormData } = useProjectsQuery({ + client, + fetchPolicy: 'no-cache', + skip: projectId !== RomanStormVariables.PROJECT_ID, + variables: { + where: { + projectId, + pv: PV_V2, + }, + block: { number: RomanStormVariables.SNAPSHOT_BLOCK }, + }, + }) + const { data: blockData, isLoading: isLoadingBlockNumbers } = useQuery({ queryKey: ['block-numbers', range], queryFn: async () => { @@ -70,22 +95,23 @@ export function useProjectTimeline({ return { blocks, timestamps } }, [blockData]) - const { data: v1v2v3QueryResult, loading: isLoadingQuery } = useProjectTlQuery({ - client, - variables: { - id: blocks ? getSubgraphIdForProject(pv, projectId) : '', - ...blocks, - }, - skip: pv === PV_V4 - }) + const { data: v1v2v3QueryResult, loading: isLoadingQuery } = + useProjectTlQuery({ + client, + variables: { + id: blocks ? getSubgraphIdForProject(pv, projectId) : '', + ...blocks, + }, + skip: pv === PV_V4, + }) const { data: v4QueryResult } = useSubgraphQuery({ - document: ProjectTlDocument, + document: ProjectTlDocument, variables: { id: blocks ? projectId.toString() : '', ...blocks, }, - enabled: pv === PV_V4 + enabled: pv === PV_V4, }) const points = useMemo(() => { @@ -95,16 +121,31 @@ export function useProjectTimeline({ const points: ProjectTimelinePoint[] = [] for (let i = 0; i < COUNT; i++) { - const point = (queryResult as ProjectTlQuery)[`p${i}` as keyof typeof queryResult] + const point = (queryResult as ProjectTlQuery)[ + `p${i}` as keyof typeof queryResult + ] if (!point) continue - - points.push({ - timestamp: timestamps[i], - trendingScore: wadToFloat(point.trendingScore), - balance: wadToFloat(point.currentBalance), - volume: wadToFloat(point.volume), - }) + if (exceptionTimestamp && exceptionTimestamp > timestamps[i]) { + points.push({ + timestamp: timestamps[i], + trendingScore: 0, + balance: 0, + volume: 0, + }) + } else { + const volume = + projectId === RomanStormVariables.PROJECT_ID + ? point.volume.sub(romanStormData?.projects[0].volume || 0) + : point.volume + + points.push({ + timestamp: timestamps[i], + trendingScore: wadToFloat(point.trendingScore), + balance: wadToFloat(point.currentBalance), + volume: wadToFloat(volume), + }) + } } return points diff --git a/src/constants/romanStorm.ts b/src/constants/romanStorm.ts new file mode 100644 index 0000000000..d067a47dc7 --- /dev/null +++ b/src/constants/romanStorm.ts @@ -0,0 +1,9 @@ +const PROJECT_ID = 618 +const SNAPSHOT_BLOCK = 20229376 +const SNAPSHOT_TIMESTAMP = 1720050599 + +export const RomanStormVariables = { + PROJECT_ID, + SNAPSHOT_BLOCK, + SNAPSHOT_TIMESTAMP, +} diff --git a/src/graphql/projects/projects.graphql b/src/graphql/projects/projects.graphql index 6b00dd7e74..2a7da8fcd3 100644 --- a/src/graphql/projects/projects.graphql +++ b/src/graphql/projects/projects.graphql @@ -4,8 +4,9 @@ query Projects( $skip: Int, $orderBy: Project_orderBy $orderDirection: OrderDirection + $block: Block_height ) { - projects(where: $where, first: $first, skip: $skip) { + projects(where: $where, first: $first, skip: $skip, block: $block) { id projectId metadataUri diff --git a/src/graphql/projects/trendingProjects.graphql b/src/graphql/projects/trendingProjects.graphql index 2849dd9520..c4f6ca5dfa 100644 --- a/src/graphql/projects/trendingProjects.graphql +++ b/src/graphql/projects/trendingProjects.graphql @@ -4,6 +4,7 @@ query TrendingProjects( $skip: Int $orderBy: Project_orderBy $orderDirection: OrderDirection + $block: Block_height ) { projects( where: $where @@ -11,6 +12,7 @@ query TrendingProjects( skip: $skip orderBy: $orderBy orderDirection: desc + block: $block ) { id projectId diff --git a/src/hooks/useProjectEvents.ts b/src/hooks/useProjectEvents.ts index 2a00370fa9..2af206d853 100644 --- a/src/hooks/useProjectEvents.ts +++ b/src/hooks/useProjectEvents.ts @@ -1,10 +1,13 @@ +import { useMemo } from 'react' + import { OrderDirection, ProjectEvent_OrderBy, - useProjectEventsQuery + useProjectEventsQuery, } from 'generated/graphql' import { client } from 'lib/apollo/client' import { ProjectEventsQueryArgs } from 'models/projectEvents' +import { RomanStormVariables } from 'constants/romanStorm' export function useProjectEvents({ filter, @@ -14,6 +17,13 @@ export function useProjectEvents({ first, skip, }: ProjectEventsQueryArgs) { + const projectSnapshotTimestamp = useMemo(() => { + if (projectId === RomanStormVariables.PROJECT_ID) { + return RomanStormVariables.SNAPSHOT_TIMESTAMP + } + return null + }, [projectId]) + return useProjectEventsQuery({ client, variables: { @@ -27,6 +37,9 @@ export function useProjectEvents({ where: { ...(pv ? { pv } : {}), ...(projectId ? { projectId } : {}), + ...(projectSnapshotTimestamp + ? { timestamp_gt: projectSnapshotTimestamp } + : {}), ...(from ? { // subgraph needs addresses to be lowercased diff --git a/src/packages/v2v3/contexts/Project/useV2V3ProjectState.ts b/src/packages/v2v3/contexts/Project/useV2V3ProjectState.ts index 93176fa669..70a19c2e17 100644 --- a/src/packages/v2v3/contexts/Project/useV2V3ProjectState.ts +++ b/src/packages/v2v3/contexts/Project/useV2V3ProjectState.ts @@ -1,4 +1,5 @@ import { PV_V2 } from 'constants/pv' +import { RomanStormVariables } from 'constants/romanStorm' import { ETH_PAYOUT_SPLIT_GROUP, RESERVED_TOKEN_SPLIT_GROUP, @@ -95,14 +96,35 @@ export function useV2V3ProjectState({ projectId }: { projectId: number }) { }, }) - const projects = data?.projects - const projectStatsData = first(projects) - const { - createdAt, - volume: totalVolume, - trendingVolume, - paymentsCount, - } = projectStatsData ?? {} + const { data: romanStormData } = useProjectsQuery({ + client, + fetchPolicy: 'no-cache', + skip: projectId !== RomanStormVariables.PROJECT_ID, + variables: { + where: { + projectId, + pv: PV_V2, + }, + block: { number: RomanStormVariables.SNAPSHOT_BLOCK }, + }, + }) + + const projectStatsData = first(data?.projects) + const projectRomanStormStatsData = first(romanStormData?.projects) + + let totalVolume = projectStatsData?.volume + let paymentsCount = projectStatsData?.paymentsCount ?? 0 + + if (projectId === RomanStormVariables.PROJECT_ID && projectStatsData) { + const BIG_ZERO = BigNumber.from(0) + + totalVolume = (totalVolume || BIG_ZERO).sub( + projectRomanStormStatsData?.volume || BIG_ZERO, + ) + paymentsCount -= projectRomanStormStatsData?.paymentsCount ?? 0 + } + + const { createdAt, trendingVolume } = projectStatsData ?? {} /** * Load funding cycle data diff --git a/src/packages/v4/graphql/queries/project.graphql b/src/packages/v4/graphql/queries/project.graphql index 8cecf55ed8..0c51032449 100644 --- a/src/packages/v4/graphql/queries/project.graphql +++ b/src/packages/v4/graphql/queries/project.graphql @@ -1,5 +1,5 @@ -query Projects($where: Project_filter, $first: Int, $skip: Int) { - projects(where: $where, first: $first, skip: $skip) { +query Projects($where: Project_filter, $first: Int, $skip: Int, $block: Block_height) { + projects(where: $where, first: $first, skip: $skip, block: $block) { projectId metadata handle diff --git a/src/packages/v4/views/V4ProjectSettings/EditCyclePage/DetailsSection/CycleDeadlineDropdown.tsx b/src/packages/v4/views/V4ProjectSettings/EditCyclePage/DetailsSection/CycleDeadlineDropdown.tsx index 41a10cd449..de0fe54563 100644 --- a/src/packages/v4/views/V4ProjectSettings/EditCyclePage/DetailsSection/CycleDeadlineDropdown.tsx +++ b/src/packages/v4/views/V4ProjectSettings/EditCyclePage/DetailsSection/CycleDeadlineDropdown.tsx @@ -11,11 +11,13 @@ export default function CycleDeadlineDropdown({ return (