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

v2: builder applyToRound #2926

Merged
merged 12 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from 8 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
1 change: 1 addition & 0 deletions cache/solidity-files-cache.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"_format":"ethers-rs-sol-cache-3","paths":{"artifacts":"out","build_infos":"out/build-info","sources":"src","tests":"test","scripts":"script","libraries":["node_modules"]},"files":{}}
codenamejason marked this conversation as resolved.
Show resolved Hide resolved
2 changes: 1 addition & 1 deletion packages/builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
"dompurify": "^2.4.3",
"ethers": "^5.7.2",
"framer-motion": "^6",
"gitcoin-lit-js-sdk": "^1.2.9",
"gitcoin-lit-js-sdk": "^1.3.1",
"history": "^5.3.0",
"https-browserify": "^1.0.0",
"jest": "^27.0",
Expand Down
12 changes: 8 additions & 4 deletions packages/builder/src/actions/grantsMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { datadogRum } from "@datadog/browser-rum";
import { getConfig } from "common/src/config";
import { AddressAndRole, DataLayer } from "data-layer";
import { ethers } from "ethers";
import { Dispatch } from "redux";
import { Metadata } from "../types";
import { getProjectURIComponents, getV1HashedProjectId } from "../utils/utils";
import { projectOwnersLoaded } from "./projects";
import { projectAnchorsLoaded, projectOwnersLoaded } from "./projects";

export const GRANT_METADATA_LOADING_URI = "GRANT_METADATA_LOADING_URI";
export interface GrantMetadataLoadingURI {
Expand Down Expand Up @@ -117,19 +118,22 @@ export const fetchGrantData =
createdAt: project.metadata.createdAt,
updatedAt: project.metadata.createdAt, // todo: get this value
credentials: project.metadata.credentials,
protocol: 1,
protocol: project.metadata.protocol,
pointer: project.metadataCid,
userGithub: project.metadata.userGithub,
projectGithub: project.metadata.projectGithub,
projectTwitter: project.metadata.projectTwitter,
};

const ownerAddresses = project.roles
const ownerAddresses: `0x${string}`[] = project.roles
.filter((role: AddressAndRole) => role.role === "OWNER")
.map((role) => role.address);
.map((role) => ethers.utils.getAddress(role.address));

dispatch(projectOwnersLoaded(id, ownerAddresses));

const anchorAddress = project.anchorAddress!;
dispatch(projectAnchorsLoaded(id, anchorAddress));

dispatch(grantMetadataFetched(item));
} catch (e) {
datadogRum.addError(e);
Expand Down
21 changes: 20 additions & 1 deletion packages/builder/src/actions/projects.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@ interface ProjectStatsLoadedAction {
stats: ProjectStats[];
}

export const PROJECT_ANCHORS_LOADED = "PROJECT_ANCHORS_LOADED";

interface ProjectAnchorsLoadedAction {
type: typeof PROJECT_ANCHORS_LOADED;
payload: {
projectID: string;
anchor: string;
};
}

/** Actions */

/** Project Action Types */
Expand All @@ -134,7 +144,8 @@ export type ProjectsActions =
| ProjectApplicationUpdatedAction
| ProjectOwnersLoadedAction
| ProjectStatsLoadingAction
| ProjectStatsLoadedAction;
| ProjectStatsLoadedAction
| ProjectAnchorsLoadedAction;

/** Action Creators */
export const projectsLoading = (chainID: ChainId): ProjectsLoadingAction => ({
Expand Down Expand Up @@ -165,6 +176,14 @@ export const projectOwnersLoaded = (projectID: string, owners: string[]) => ({
},
});

export const projectAnchorsLoaded = (projectID: string, anchor: string) => ({
type: PROJECT_ANCHORS_LOADED,
payload: {
projectID,
anchor,
},
});

/**
* Load projects for a given chain
*
Expand Down
52 changes: 28 additions & 24 deletions packages/builder/src/actions/roundApplication.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,21 +145,22 @@ export function chainIdToChainName(chainId: number): string {
}

export const submitApplication =
(roundAddress: string, formInputs: RoundApplicationAnswers, allo: Allo) =>
(roundId: string, formInputs: RoundApplicationAnswers, allo: Allo) =>
async (dispatch: Dispatch, getState: () => RootState) => {
const state = getState();
const roundState = state.rounds[roundAddress];
const roundState = state.rounds[roundId];
const isV2 = getConfig().allo.version === "allo-v2";

dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundAddress: roundId, // todo: roundAddress is misleading
status: Status.BuildingApplication,
});

if (roundState === undefined) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot load round data",
Status.BuildingApplication
);
Expand All @@ -170,7 +171,7 @@ export const submitApplication =
if (roundApplicationMetadata === undefined) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot load round application metadata",
Status.BuildingApplication
);
Expand All @@ -185,7 +186,7 @@ export const submitApplication =
if (!projectQuestion) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot find project question id",
Status.BuildingApplication
);
Expand All @@ -204,7 +205,7 @@ export const submitApplication =
if (projectMetadata === undefined) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot find selected project metadata",
Status.BuildingApplication
);
Expand All @@ -217,7 +218,7 @@ export const submitApplication =
if (chainID === undefined) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"cannot find chain id",
Status.BuildingApplication
);
Expand All @@ -227,14 +228,16 @@ export const submitApplication =

dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundId,
status: Status.LitAuthentication,
});

let application: RoundApplication;
let deterministicApplication: string;

try {
const roundAddress = roundState.round!.address;

const builder = new RoundApplicationBuilder(
true,
project,
Expand All @@ -249,7 +252,7 @@ export const submitApplication =
} catch (error) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"error building round application",
Status.LitAuthentication
);
Expand All @@ -265,7 +268,7 @@ export const submitApplication =

dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundId,
status: Status.SigningApplication,
});

Expand All @@ -275,7 +278,7 @@ export const submitApplication =
} catch (e) {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"error signing round application",
Status.SigningApplication
);
Expand All @@ -287,31 +290,32 @@ export const submitApplication =
application,
};

const projectUniqueID = generateUniqueRoundApplicationID(
Number(projectChainId),
projectNumber,
projectRegistryAddress
) as Hex;
const projectUniqueID = isV2
? (state.projects.anchor![projectID] as Hex)
: (generateUniqueRoundApplicationID(
Number(projectChainId),
projectNumber,
projectRegistryAddress
) as Hex);

dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundAddress: roundId,
status: Status.UploadingMetadata,
});

const result = allo.applyToRound({
projectId: projectUniqueID,
roundId: roundAddress as Hex,
roundId: isV2 ? Number(roundId) : (roundId as Hex),
metadata: signedApplication as unknown as AnyJson,
});

await result
.on("ipfs", (res) => {
if (res.type === "success") {
console.log("IPFS CID", res.value);
dispatch({
type: ROUND_APPLICATION_LOADING,
roundAddress,
roundAddress: roundId,
status: Status.SendingTx,
});
} else {
Expand All @@ -320,7 +324,7 @@ export const submitApplication =
datadogLogs.logger.error("ipfs: error uploading metadata");
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"error uploading round application metadata",
Status.UploadingMetadata
);
Expand All @@ -340,13 +344,13 @@ export const submitApplication =
if (res.type === "success") {
dispatch({
type: ROUND_APPLICATION_LOADED,
roundAddress,
roundAddress: roundId,
projectId: projectID,
});
} else {
dispatchAndLogApplicationError(
dispatch,
roundAddress,
roundId,
"error calling applyToRound",
Status.SendingTx
);
Expand Down
37 changes: 25 additions & 12 deletions packages/builder/src/actions/rounds.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
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 { PayoutStrategy, Status } from "../reducers/rounds";
import { Status } from "../reducers/rounds";
import { Round } from "../types";
import { graphqlFetch } from "../utils/graphql";
import { parseRoundApplicationMetadata } from "../utils/roundApplication";
Expand Down Expand Up @@ -61,9 +63,15 @@ export const unloadRounds = () => roundsUnloaded();
export const loadRound =
(roundId: string, dataLayer: DataLayer, chainId: number) =>
async (dispatch: Dispatch) => {
const { version } = getConfig().allo;

try {
// address validation
ethers.utils.getAddress(roundId);
if (version === "allo-v1") {
ethers.utils.getAddress(roundId);
} else if (roundId.includes("0x")) {
throw new Error(`Invalid roundId ${roundId}`);
}
} catch (e) {
datadogRum.addError(e);
datadogLogs.logger.warn(`invalid address or address checksum ${roundId}`);
Expand Down Expand Up @@ -92,10 +100,11 @@ export const loadRound =
})) || "";

// TODO: FETCH FROM INDEXER
let roundPayoutStrategy: PayoutStrategy;
let roundPayoutStrategy: RoundType;
try {
const resp = await graphqlFetch(
`
if (version === "allo-v1") {
const resp = await graphqlFetch(
`
query GetRoundById($roundId: String) {
rounds(where: {
id: $roundId
Expand All @@ -108,12 +117,15 @@ export const loadRound =
}
}
`,
chainId!,
{ roundId: roundId.toLowerCase() }
);
roundPayoutStrategy = resp.data.rounds[0].payoutStrategy
? resp.data.rounds[0].payoutStrategy.strategyName
: "MERKLE";
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");
Expand All @@ -123,7 +135,8 @@ export const loadRound =
}

const round = {
address: roundId,
id: version === "allo-v1" ? roundId : v2Round.id,
address: version === "allo-v1" ? roundId : v2Round.strategyAddress,
applicationsStartTime:
Date.parse(`${v2Round.applicationsStartTime}Z`) / 1000,
applicationsEndTime: Date.parse(`${v2Round.applicationsEndTime}Z`) / 1000,
Expand Down
3 changes: 2 additions & 1 deletion packages/builder/src/components/application/Form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ export default function Form({
const { chainID } = state.web3;

return {
anchors: state.projects.anchor,
projectIDs: state.projects.ids,
allProjectMetadata,
chainID,
Expand Down Expand Up @@ -848,7 +849,7 @@ export default function Form({
open={showErrorModal}
onClose={closeErrorModal}
onRetry={handleSubmitApplicationRetry}
title="Round Application Period Closed"
title="Round Application Error"
>
{round.applicationsEndTime < now ? (
<div className="my-2">
Expand Down
7 changes: 3 additions & 4 deletions packages/builder/src/components/application/FullPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Metadata } from "../../types";
import Button, { ButtonVariants } from "../base/Button";
import { AboutProject } from "./AboutProject";
import { ProjectTitle } from "./ProjectTitle";
import { getFileUrl } from "../../utils/components";

export function FullPreview(props: {
project: Metadata;
Expand All @@ -31,8 +32,6 @@ export function FullPreview(props: {
disableSubmit,
chainId,
} = props;
const ipfsPrefix = `${process.env.REACT_APP_PINATA_GATEWAY!}/ipfs/`;

useEffect(() => {
document.getElementById("root")!.scrollTo(0, 0);
}, []);
Expand All @@ -56,7 +55,7 @@ export function FullPreview(props: {
className="h-32 w-full object-cover lg:h-80 rounded"
src={`${
project.bannerImg
? ipfsPrefix + project.bannerImg
? getFileUrl(project.bannerImg)
: DefaultProjectBanner
}?img-height=320`}
alt="Project Banner"
Expand All @@ -72,7 +71,7 @@ export function FullPreview(props: {
className="h-16 w-16 rounded-full ring-4 ring-white bg-white"
src={
project.logoImg
? ipfsPrefix + project.logoImg
? getFileUrl(project.logoImg)
: DefaultProjectLogo
}
alt="Project Logo"
Expand Down
Loading
Loading