From 383e19600eb69ead94ef2a131b786144f8304829 Mon Sep 17 00:00:00 2001 From: jaxcoder / Date: Fri, 16 Feb 2024 06:48:47 -0500 Subject: [PATCH] Updated Round Types - Builder, Common, Data-Layer (#2949) * update strategy name/round types * update stats and type in data-layer * clean up --- packages/builder/src/actions/rounds.ts | 48 ++++++------------- .../src/components/grants/ApplicationCard.tsx | 3 +- .../grants/rounds/RoundListItem.tsx | 12 +++-- .../src/components/grants/stats/Stats.tsx | 4 +- packages/common/src/allo/roundIdentifier.ts | 45 ----------------- packages/common/src/index.ts | 18 ++++--- packages/data-layer/src/queries.ts | 1 + 7 files changed, 33 insertions(+), 98 deletions(-) delete mode 100644 packages/common/src/allo/roundIdentifier.ts diff --git a/packages/builder/src/actions/rounds.ts b/packages/builder/src/actions/rounds.ts index 1a07294b67..8444d0030d 100644 --- a/packages/builder/src/actions/rounds.ts +++ b/packages/builder/src/actions/rounds.ts @@ -1,15 +1,15 @@ import { datadogLogs } from "@datadog/browser-logs"; import { datadogRum } from "@datadog/browser-rum"; -import { RoundType, getV2RoundType } from "common"; import { getConfig } from "common/src/config"; import { DataLayer } from "data-layer"; import { ethers } from "ethers"; import { Dispatch } from "redux"; import { Status } from "../reducers/rounds"; import { Round } from "../types"; -import { graphqlFetch } from "../utils/graphql"; import { parseRoundApplicationMetadata } from "../utils/roundApplication"; +export type RoundType = "MERKLE" | "DIRECT"; + export const ROUNDS_LOADING_ROUND = "ROUNDS_LOADING_ROUND"; interface RoundsLoadingRoundAction { type: typeof ROUNDS_LOADING_ROUND; @@ -99,39 +99,19 @@ export const loadRound = projectId: v2Round.roundMetadata.programContractAddress, })) || ""; - // TODO: FETCH FROM INDEXER let roundPayoutStrategy: RoundType; - try { - if (version === "allo-v1") { - const resp = await graphqlFetch( - ` - query GetRoundById($roundId: String) { - rounds(where: { - id: $roundId - }) { - id - payoutStrategy { - id - strategyName - } - } - } - `, - chainId!, - { roundId: roundId.toLowerCase() } - ); - roundPayoutStrategy = resp.data.rounds[0].payoutStrategy - ? resp.data.rounds[0].payoutStrategy.strategyName - : "MERKLE"; - } else { - roundPayoutStrategy = getV2RoundType(v2Round.strategyId); - } - } catch (e) { - datadogRum.addError(e); - datadogLogs.logger.error("sg: error loading round payoutStrategy"); - dispatch(loadingError(roundId, "error loading round payoutStrategy")); - console.error(e); - return; + + switch (v2Round.strategyName) { + case "allov1.QF": + case "allov2.DonationVotingMerkleDistributionDirectTransferStrategy": + roundPayoutStrategy = "MERKLE"; + break; + case "allov1.Direct": + case "allov2.DirectGrantsSimpleStrategy": + roundPayoutStrategy = "DIRECT"; + break; + default: + roundPayoutStrategy = "MERKLE"; } const round = { diff --git a/packages/builder/src/components/grants/ApplicationCard.tsx b/packages/builder/src/components/grants/ApplicationCard.tsx index 30e5b279a5..d1b11241f3 100644 --- a/packages/builder/src/components/grants/ApplicationCard.tsx +++ b/packages/builder/src/components/grants/ApplicationCard.tsx @@ -1,10 +1,9 @@ -import { RoundType } from "common"; import { Badge, Box, Button, Image, Spinner } from "@chakra-ui/react"; import { ApplicationStatus, useDataLayer } from "data-layer"; import { useEffect } from "react"; import { useDispatch, useSelector } from "react-redux"; import { Link } from "react-router-dom"; -import { loadRound } from "../../actions/rounds"; +import { RoundType, loadRound } from "../../actions/rounds"; import { RootState } from "../../reducers"; import { roundApplicationViewPath } from "../../routes"; import { ApplicationCardType, RoundSupport } from "../../types"; diff --git a/packages/builder/src/components/grants/rounds/RoundListItem.tsx b/packages/builder/src/components/grants/rounds/RoundListItem.tsx index 4d842720f9..47f5db097b 100644 --- a/packages/builder/src/components/grants/rounds/RoundListItem.tsx +++ b/packages/builder/src/components/grants/rounds/RoundListItem.tsx @@ -1,9 +1,10 @@ // eslint-disable max-len -import { ApplicationStatus, ProjectApplication } from "data-layer"; import { Badge, Box, Spinner } from "@chakra-ui/react"; -import { useSelector } from "react-redux"; +import { ROUND_PAYOUT_DIRECT } from "common"; +import { ApplicationStatus, ProjectApplication } from "data-layer"; import { useEffect, useState } from "react"; -import { ROUND_PAYOUT_DIRECT, ROUND_PAYOUT_MERKLE, RoundType } from "common"; +import { useSelector } from "react-redux"; +import { RoundType } from "../../../actions/rounds"; import { RootState } from "../../../reducers"; import { roundApplicationPathForProject } from "../../../routes"; import { Round, RoundDisplayType } from "../../../types"; @@ -87,6 +88,7 @@ export default function RoundListItem({ const roundPayoutStrategy = roundData?.payoutStrategy; + // todo: temp fix for rendering badges return ( - {roundPayoutStrategy === ROUND_PAYOUT_MERKLE ? ( + {roundPayoutStrategy === "MERKLE" ? ( Quadratic Funding ) : null} - {roundPayoutStrategy === ROUND_PAYOUT_DIRECT ? ( + {roundPayoutStrategy === "DIRECT" ? ( Direct Grant diff --git a/packages/builder/src/components/grants/stats/Stats.tsx b/packages/builder/src/components/grants/stats/Stats.tsx index 1927c45383..4780c2fac4 100644 --- a/packages/builder/src/components/grants/stats/Stats.tsx +++ b/packages/builder/src/components/grants/stats/Stats.tsx @@ -1,5 +1,5 @@ import { Spinner } from "@chakra-ui/react"; -import { ChainId, ROUND_PAYOUT_MERKLE, RoundPayoutType } from "common"; +import { ChainId, RoundPayoutType } from "common"; import { useEffect, useState } from "react"; import { useDispatch, useSelector } from "react-redux"; import { useParams } from "react-router-dom"; @@ -52,7 +52,7 @@ export default function RoundStats() { applications.forEach((app) => { const roundType = props.rounds[app.roundId]?.round?.payoutStrategy || ""; - if (roundType !== "" && roundType === ROUND_PAYOUT_MERKLE) { + if (roundType !== "" && roundType === "MERKLE") { rounds.push({ roundId: app.roundId, chainId: app.chainId, diff --git a/packages/common/src/allo/roundIdentifier.ts b/packages/common/src/allo/roundIdentifier.ts deleted file mode 100644 index 269aa449c4..0000000000 --- a/packages/common/src/allo/roundIdentifier.ts +++ /dev/null @@ -1,45 +0,0 @@ -export type RoundType = - | "MERKLE" - | "DIRECT" - | "SUPERFLUID" - | "MICROGRANTS" - | "MICROGRANTSGOV" - | "MICROGRANTSHATS" - | "RFPSIMPLE" - | "RFPCOMMITTEE" - | "QVSIMPLE"; - -export const getV2RoundType = (poolId: string): RoundType => { - const lowerCasePoolId = poolId.toLowerCase(); - switch (lowerCasePoolId) { - case "0x6f9291df02b2664139cec5703c124e4ebce32879c74b6297faa1468aa5ff9ebf": // DonationVotingMerkleDistributionDirectTransferStrategyv1.0 - case "0x7e75375f0a7cd9f7ea159c8b065976e4f764f9dcef1edf692f31dd1842f70c87": // DonationVotingMerkleDistributionVaultStrategyv1.0 - case "0x2f46bf157821dc41daa51479e94783bb0c8699eac63bf75ec450508ab03867ce": // DonationVotingMerkleDistributionDirectTransferStrategy v1.1 - case "0x093072375737c0e8872fef36808849aeba7f865e182d495f2b98308115c9ef13": // DonationVotingMerkleDistributionVaultStrategy v1.1 - return "MERKLE"; - - case "0xf8a14294e80ff012e54157ec9d1b2827421f1e7f6bde38c06730b1c031b3f935": // SQFSuperfluidv1 - return "SUPERFLUID"; - - case "0x697f0592ebd05466d2d24454477e11d69c475d7a7c4134f15ddc1ea9811bb16f": // MicroGrantsv1 - return "MICROGRANTS"; - - case "0x741ac1e2f387d83f219f6b5349d35ec34902cf94019d117335e0045d2e0ed912": // MicroGrantsGovv1 - return "MICROGRANTSGOV"; - - case "0x5aa24dcfcd55a1e059a172e987b3456736b4856c71e57aaf52e9a965897318dd": // MicroGrantsHatsv1 - return "MICROGRANTSHATS"; - - case "0x0d459e12d9e91d2b2a8fa12be8c7eb2b4f1c35e74573990c34b436613bc2350f": // RFPSimpleStrategyv1.0 - return "RFPSIMPLE"; - - case "0x7d143166a83c6a8a303ae32a6ccd287e48d79818f5d15d89e185391199909803": // RFPCommitteeStrategyv1.0 - return "RFPCOMMITTEE"; - - case "0x22d006e191d6dc5ff1a25bb0733f47f64a9c34860b6703df88dea7cb3987b4c3": // QVSimpleStrategyv1.0 - return "QVSIMPLE"; - - default: - throw new Error("RoundType: Unknown Identifier"); - } -}; diff --git a/packages/common/src/index.ts b/packages/common/src/index.ts index f8d7ccae62..087522938a 100644 --- a/packages/common/src/index.ts +++ b/packages/common/src/index.ts @@ -1,12 +1,12 @@ +import { Signer } from "@ethersproject/abstract-signer"; +import { Network, Web3Provider } from "@ethersproject/providers"; import { useMemo, useState } from "react"; +import { useParams as useRouterParams } from "react-router"; +import { useOutletContext } from "react-router-dom"; import useSWR from "swr"; import z from "zod"; -import { useOutletContext } from "react-router-dom"; -import { Network, Web3Provider } from "@ethersproject/providers"; -import { Signer } from "@ethersproject/abstract-signer"; -import { graphql_fetch } from "./graphql_fetch"; import { ChainId } from "./chain-ids"; -import { useParams as useRouterParams } from "react-router"; +import { graphql_fetch } from "./graphql_fetch"; export * from "./icons"; export * from "./markdown"; @@ -325,7 +325,7 @@ export { AlloV2 } from "./allo/backends/allo-v2"; export { createWaitForIndexerSyncTo, getCurrentSubgraphBlockNumber, - waitForSubgraphSyncTo, + waitForSubgraphSyncTo } from "./allo/indexer"; export type { WaitUntilIndexerSynced } from "./allo/indexer"; export { createPinataIpfsUploader } from "./allo/ipfs"; @@ -336,7 +336,7 @@ export { createViemTransactionSender, decodeEventFromReceipt, sendRawTransaction, - sendTransaction, + sendTransaction } from "./allo/transaction-sender"; export type AnyJson = @@ -376,6 +376,4 @@ export interface Web3Instance { signer?: Signer; } -export { graphql_fetch, graphQlEndpoints } from "./graphql_fetch"; - -export * from "./allo/roundIdentifier"; +export { graphQlEndpoints, graphql_fetch } from "./graphql_fetch"; diff --git a/packages/data-layer/src/queries.ts b/packages/data-layer/src/queries.ts index 1b737a40dd..c1648709da 100644 --- a/packages/data-layer/src/queries.ts +++ b/packages/data-layer/src/queries.ts @@ -305,6 +305,7 @@ export const getRoundByIdAndChainId = gql` applicationMetadataCid strategyId strategyAddress + strategyName } } `;