Skip to content

Commit

Permalink
feat: filter bot programs
Browse files Browse the repository at this point in the history
  • Loading branch information
bhargavaparoksham committed Feb 16, 2024
1 parent d60a18a commit afa7007
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 8 deletions.
9 changes: 7 additions & 2 deletions packages/data-layer/src/data-layer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const mockProjects: v2Project[] = [
nodeId:
"WyJwcm9qZWN0cyIsIjB4OGE3OTI0OWI2MzM5NWMyNWJkMTIxYmE2ZmYyODAxOThjMzk5ZDRmYjNmOTUxZmMzYzQyMTk3YjU0YTZkYjZhNiIsMTExNTUxMTFd",
// note: This is moved to roles also
createdByAddress: "0x0000",
createdAtBlock: "5146499",
updatedAtBlock: "5146499",
projectNumber: null,
Expand Down Expand Up @@ -584,12 +585,16 @@ describe("projects retrieval", () => {
expect(project?.project.id).toEqual(mockProject.id);
expect(project?.project.nodeId).toEqual(mockProject.nodeId);
expect(project?.project.chainId).toEqual(mockProject.chainId);
expect(project?.project.registryAddress).toEqual(mockProject.registryAddress);
expect(project?.project.registryAddress).toEqual(
mockProject.registryAddress,
);
expect(project?.project.projectNumber).toEqual(mockProject.projectNumber);
expect(project?.project.tags).toEqual(mockProject.tags);
expect(project?.project.roles).toEqual(mockProject.roles);
expect(project?.project.name).toEqual(mockProject.name);
expect(project?.project.metadata.description).toEqual(mockProject.metadata.description);
expect(project?.project.metadata.description).toEqual(
mockProject.metadata.description,
);
});

test("can retrieve all projects for a network", async () => {
Expand Down
4 changes: 4 additions & 0 deletions packages/data-layer/src/data.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ export type v2Project = {
* The tags are used to filter the projects based on the version of Allo.
*/
tags: ("allo-v1" | "allo-v2" | "program")[];
/**
* Address which created the project
*/
createdByAddress: string;
/**
* The block the project was created at
*/
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 @@ -22,6 +22,7 @@ export const getProgramByUserAndTag = gql`
metadata
metadataCid
tags
createdByAddress
roles {
address
role
Expand Down Expand Up @@ -53,6 +54,7 @@ export const getProgramByIdAndUser = gql`
metadata
metadataCid
tags
createdByAddress
roles {
address
role
Expand Down
12 changes: 11 additions & 1 deletion packages/round-manager/src/features/api/program.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export async function listPrograms(
throw Error("Unable to fetch programs");
}

const programs: Program[] = [];
let programs: Program[] = [];

for (const program of programsRes.programs) {
programs.push({
Expand All @@ -53,9 +53,19 @@ export async function listPrograms(
name: CHAINS[chainId]?.name,
logo: CHAINS[chainId]?.logo,
},
createdByAddress: program.createdByAddress,
});
}

// Filter out programs where operatorWallets does not include round.createdByAddress.
// This is to filter out spam rounds created by bots
programs = programs.filter((program) => {
return (
program.createdByAddress &&
program.operatorWallets?.includes(program.createdByAddress)
);
});

return programs;
} catch (error) {
datadogLogs.logger.error(`error: listPrograms - ${error}`);
Expand Down
7 changes: 2 additions & 5 deletions packages/round-manager/src/features/api/round.ts
Original file line number Diff line number Diff line change
Expand Up @@ -333,12 +333,9 @@ export async function listRounds(args: {
})
.then((rounds) => rounds.map(indexerV2RoundToRound));

console.log("rounds", rounds);

// filter out rounds operatorWallets does not include round.createdByAddress

// Filter out rounds where operatorWallets does not include round.createdByAddress
// This is to filter out spam rounds created by bots
rounds = rounds.filter((round) => {
// Check if createdByAddress is defined and if operatorWallets array includes createdByAddress
return (
round.createdByAddress &&
round.operatorWallets?.includes(round.createdByAddress)
Expand Down
4 changes: 4 additions & 0 deletions packages/round-manager/src/features/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ export interface Program {
* Addresses of wallets that will have admin privileges to operate the Grant program
*/
operatorWallets: Array<string>;
/**
* Address which created the program
*/
createdByAddress?: string;
/**
* Network Chain Information
*/
Expand Down

0 comments on commit afa7007

Please sign in to comment.