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

feat: all remaining event handlers for DVMD strategy #30

Merged
merged 5 commits into from
Nov 13, 2024

Conversation

0xnigir1
Copy link
Collaborator

@0xnigir1 0xnigir1 commented Nov 12, 2024

🤖 Linear

Closes GIT-170 GIT-155 GIT-156 GIT-160 GIT-167

Description

  • adds remaining Event Handlers for DVMD Direct Transfer Strategy
    • TimestampsUpdated
    • DistributionUpdated (common to all strategies)
    • FundsDistributed (common to all strategies)
    • RecipientStatusUpdated (common to all strategies)
    • UpdatedRegistration

Checklist before requesting a review

  • I have conducted a self-review of my code.
  • I have conducted a QA.
  • If it is a core feature, I have included comprehensive tests.

Copy link
Collaborator

@0xkenj1 0xkenj1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a smoll comments. Huge work here, sir! 👏💎

Comment on lines 47 to 51
if (!rawDistribution) {
logger.warn(`No matching distribution found for pointer: ${pointer}`);

throw new MetadataNotFound(`No matching distribution found for pointer: ${pointer}`);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should MetadataProvider be responsible for throwing a "not found" error instead of having the handler doing it?

private readonly chainId: ChainId,
private readonly dependencies: Dependencies,
) {
this.bitmap = new StatusesBitmap(256n, 4n);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

values to build StatusesBitmap are always the same ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, i followed original implementation. are constants values

Comment on lines 3 to 9
/**
* Checks if an application status index is valid (between 1 and 3)
* @see ApplicationStatus
*/
export function isValidApplicationStatus(status: number): boolean {
return status >= 1 && status <= 3;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't like this hardcoding that much. But it is something that probably won't change.

What about using Object.keys(ApplicationStatus).length ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

didn't follow exactly your idea, you mean to use the length as the upper bound limit?

Comment on lines 106 to 145
// it("correctly convert timestamps to Date objects", async () => {
// const timestamps = {
// registrationStartTime: 1704067200n, // 2024-01-01 00:00:00
// registrationEndTime: 1704153600n, // 2024-01-02 00:00:00
// allocationStartTime: 1704240000n, // 2024-01-03 00:00:00
// allocationEndTime: 1704326400n, // 2024-01-04 00:00:00
// };

// mockEvent = createMockEvent({
// params: timestamps,
// });
// const mockRound = { id: "round1" } as Round;

// vi.spyOn(mockRoundRepository, "getRoundByStrategyAddress").mockResolvedValue(mockRound);

// handler = new DVMDTimestampsUpdatedHandler(mockEvent, chainId, {
// roundRepository: mockRoundRepository,
// });

// const result = await handler.handle();

// expect(result.length).toBe(1);
// const changeset = result[0] as {
// type: "UpdateRound";
// args: { chainId: ChainId; roundId: string; round: PartialRound };
// };

// expect(changeset.type).toBe("UpdateRound");
// expect(changeset.args.chainId).toBe(chainId);
// expect(changeset.args.roundId).toBe("round1");
// expect(changeset.args.round).toBeDefined();

// const partialRound = changeset.args.round;

// expect(partialRound.applicationsStartTime).toEqual(new Date("2024-01-01T00:00:00.000Z"));
// expect(partialRound.applicationsEndTime).toEqual(new Date("2024-01-02T00:00:00.000Z"));
// expect(partialRound.donationsStartTime).toEqual(new Date("2024-01-03T00:00:00.000Z"));
// expect(partialRound.donationsEndTime).toEqual(new Date("2024-01-04T00:00:00.000Z"));
// });
});
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why is this commented?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my bad

Comment on lines 56 to 61
const timestamps = {
registrationStartTime: 1704067200n, // 2024-01-01 00:00:00
registrationEndTime: 1704153600n, // 2024-01-02 00:00:00
allocationStartTime: 1704240000n, // 2024-01-03 00:00:00
allocationEndTime: 1704326400n, // 2024-01-04 00:00:00
};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

may we check if envio is actually returning this params of the event as string or number ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right here, it's string. should we treat as string or have the indexer-client parse it and coerce to bigint?


export type MatchingDistribution = z.infer<typeof MatchingDistributionSchema>;

// handle ethers bigint serialization
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean viem?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just copy-pasted the comment, will delete it

projectPayoutAddress: z.string(),
projectId: z.string(),
projectName: z.string(),
matchPoolPercentage: z.coerce.number(),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will coerce empty strings to 0 rather than fail validation--just checking if you're ok with this. If you'd prefer to fail validation you can check out this: colinhacks/zod#2461 (comment)

Copy link
Collaborator Author

@0xnigir1 0xnigir1 Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

interesting 👀 , have to say that '' being 0 is kinda unexpected

private readonly dependencies: Dependencies,
) {}

async handle(): Promise<Changeset[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inheritdoc?


type ApplicationUpdate = {
application: Application;
status: number;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the status can only be a number between 1-3 maybe we should validate it rather than just typing it as number

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's kinda a weird thing because the original implementation expected more statutes but currently only 3 of the status flow are in production. however the status on Index 0 is not one of them so I rather keep this as it is for now

private readonly dependencies: Dependencies,
) {}

async handle(): Promise<Changeset[]> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inherit doc?

);
});

it("should handle empty matching distribution array", async () => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should

@@ -40,7 +40,7 @@ export type Round = {
strategyId: string;
strategyName: string;
readyForPayoutTransaction: string | null;
matchingDistribution: MatchingDistribution | null;
matchingDistribution: MatchingDistribution[] | null;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe should be called matchingDistributions if it's an array now

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was always an array, i forgot the [ ], however i'll keep the field name so we don't break the current DB schema and we have the same name across all the app

0xkenj1
0xkenj1 previously approved these changes Nov 13, 2024
jahabeebs
jahabeebs previously approved these changes Nov 13, 2024
@0xnigir1 0xnigir1 dismissed stale reviews from jahabeebs and 0xkenj1 via b0d96ab November 13, 2024 21:44
@0xnigir1 0xnigir1 merged commit bd5be45 into dev Nov 13, 2024
6 checks passed
@0xnigir1 0xnigir1 deleted the feat/dvmd-remaining-handlers branch November 13, 2024 22:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants