Skip to content

Commit

Permalink
load strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
boudra committed Feb 13, 2024
1 parent 77c12fd commit bdb21ac
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 115 deletions.
2 changes: 2 additions & 0 deletions packages/data-layer/src/data.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ export type V2Round = {
applicationMetadata: RoundApplicationMetadata;
applicationMetadataCid: string;
projectId: string;
strategyAddress: string;
strategyName: string;
};

export type V2RoundWithRoles = V2Round & {
Expand Down
2 changes: 2 additions & 0 deletions packages/data-layer/src/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,8 @@ export const getRoundsByProgramIdAndUserAddress = gql`
roundMetadataCid
applicationMetadata
applicationMetadataCid
strategyAddress
strategyName
roles {
role
address
Expand Down
9 changes: 5 additions & 4 deletions packages/round-manager/src/context/round/RoundContext.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { ProgressStatus, Round } from "../../features/api/types";
import React, { createContext, useContext, useEffect, useReducer } from "react";
import { useWallet } from "../../features/common/Auth";
import { getRoundById, listRounds } from "../../features/api/round";
import { getRoundById } from "../../features/api/round";
import { Web3Provider } from "@ethersproject/providers";
import { datadogLogs } from "@datadog/browser-logs";
import { DataLayer, V2Round, V2RoundWithRoles, useDataLayer } from "data-layer";
import { DataLayer, V2RoundWithRoles, useDataLayer } from "data-layer";
import { maxDateForUint256 } from "../../constants";

export interface RoundState {
Expand Down Expand Up @@ -59,9 +59,10 @@ function indexerV2RoundToRound(round: V2RoundWithRoles): Round {
token: round.matchTokenAddress,
votingStrategy: "unknown",
payoutStrategy: {
id: "0x0",
id: round.strategyAddress,
isReadyForPayout: false,
strategyName: "unknown",
strategyName:
round.strategyName === "allov1.Direct" ? "DIRECT" : "MERKLE",
},
ownedBy: round.projectId,
operatorWallets: operatorWallets,
Expand Down
111 changes: 0 additions & 111 deletions packages/round-manager/src/features/api/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,117 +277,6 @@ export async function getRoundById(
}
}

/**
* Fetch a list of rounds
* @param address - a valid round operator
* @param signerOrProvider - provider
* @param programId - the ID of the program the round belongs to
* @param roundId - the ID of a specific round for detail
*/
export async function listRounds(
address: string,
signerOrProvider: Web3Provider,
programId: string,
roundId?: string
): Promise<{ rounds: Round[] }> {
try {
// fetch chain id
const { chainId } = await signerOrProvider.getNetwork();

// query the subgraph for all rounds by the given address in the given program
const res = await graphql_fetch(
`
query GetRounds($address: String, $programId: String, $roundId: String) {
rounds(where: {
${address ? `accounts_: { address: $address } ` : ``}
${programId ? `program: $programId` : ``}
${roundId ? `id: $roundId` : ``}
}) {
id
program {
id
}
payoutStrategy {
id
strategyName
}
roundMetaPtr {
protocol
pointer
}
applicationMetaPtr {
protocol
pointer
}
applicationsStartTime
applicationsEndTime
roundStartTime
roundEndTime
roles(where: {
role: "0xec61da14b5abbac5c5fda6f1d57642a264ebd5d0674f35852829746dfb8174a5"
}) {
accounts {
address
}
}
}
}
`,
chainId,
{ address: address?.toLowerCase(), programId, roundId }
);

const rounds: Round[] = [];

for (const round of res.data.rounds) {
// fetch round and application metadata from IPFS
const [roundMetadata, applicationMetadata] = await Promise.all([
fetchFromIPFS(round.roundMetaPtr.pointer),
fetchFromIPFS(round.applicationMetaPtr.pointer),
]);

if (round.roles.length === 0) {
continue;
}

const operatorWallets = round.roles[0].accounts.map(
(account: { address: string }) => account.address
);

rounds.push({
id: round.id,
roundMetadata,
applicationMetadata,
applicationsStartTime: new Date(round.applicationsStartTime * 1000),
applicationsEndTime:
round.applicationsEndTime === ethers.constants.MaxUint256.toString()
? maxDateForUint256
: new Date(round.applicationsEndTime * 1000),
roundStartTime: new Date(round.roundStartTime * 1000),
roundEndTime:
round.roundEndTime === ethers.constants.MaxUint256.toString()
? maxDateForUint256
: new Date(round.roundEndTime * 1000),
token: round.token,
votingStrategy: round.votingStrategy,
payoutStrategy: {
id: round.payoutStrategy?.id || "",
isReadyForPayout: false,
strategyName: round.payoutStrategy?.strategyName || "unknown",
},
ownedBy: round.program.id,
operatorWallets: operatorWallets,
finalized: false,
});
}

return { rounds };
} catch (error) {
console.error("listRounds", error);
throw new Error("Unable to fetch rounds");
}
}

/**
* Deploys a round by invoking the create funciton on RoundFactory
*
Expand Down

0 comments on commit bdb21ac

Please sign in to comment.