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

fix: events name following Envio declared names #25

Merged
merged 1 commit into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
21 changes: 5 additions & 16 deletions apps/indexer/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions packages/data-flow/test/unit/eventsProcessor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ describe("EventsProcessor", () => {
];
const mockEvent = {
contractName: "Strategy",
eventName: "Distributed",
eventName: "DistributedWithRecipientAddress",
args: {},
} as unknown as ProcessorEvent<"Strategy", "Distributed">;
} as unknown as ProcessorEvent<"Strategy", "DistributedWithRecipientAddress">;

vi.spyOn(mockStrategyProcessor, "process").mockResolvedValue(mockChangeset);

Expand All @@ -105,7 +105,7 @@ describe("EventsProcessor", () => {
sender: "0x0",
recipientAddress: "0x0",
recipientId: "0x0",
amount: 1,
amount: 1n,
},
transactionFields: {
hash: "0x0",
Expand Down
4 changes: 2 additions & 2 deletions packages/data-flow/test/unit/eventsRegistry.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ describe("InMemoryEventsRegistry", () => {
},
};

const secondEvent: ProcessorEvent<"Strategy", "Registered"> = {
const secondEvent: ProcessorEvent<"Strategy", "RegisteredWithSender"> = {
contractName: "Strategy",
eventName: "Registered",
eventName: "RegisteredWithSender",
blockNumber: 1,
blockTimestamp: 1234567890,
chainId: 1 as ChainId,
Expand Down
11 changes: 7 additions & 4 deletions packages/data-flow/test/unit/orchestrator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,10 +254,13 @@ describe("Orchestrator", { sequential: true }, () => {
});

const strategyEvents: Record<StrategyEvent, string> = {
Registered: "",
Distributed: "",
RegisteredWithSender: "",
DistributedWithRecipientAddress: "",
TimestampsUpdated: "",
AllocatedWithToken: "",
RegisteredWithData: "",
DistributedWithData: "",
DistributedWithFlowRate: "",
};

for (const event of Object.keys(strategyEvents) as StrategyEvent[]) {
Expand Down Expand Up @@ -319,7 +322,7 @@ describe("Orchestrator", { sequential: true }, () => {
const strategyAddress = "0x123" as Address;
const mockEvent = createMockEvent(
"Strategy",
"Registered",
"RegisteredWithSender",
1,
undefined,
strategyAddress,
Expand Down Expand Up @@ -363,7 +366,7 @@ describe("Orchestrator", { sequential: true }, () => {
});
const registeredEvent = createMockEvent(
"Strategy",
"Registered",
"RegisteredWithSender",
2,
{
recipientId: "0x123",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ type Dependencies = Pick<ProcessorDependencies, "roundRepository">;
*
*/

export class BaseDistributedHandler implements IEventHandler<"Strategy", "Distributed"> {
export class BaseDistributedHandler
implements IEventHandler<"Strategy", "DistributedWithRecipientAddress">
{
constructor(
readonly event: ProcessorEvent<"Strategy", "Distributed">,
readonly event: ProcessorEvent<"Strategy", "DistributedWithRecipientAddress">,
private readonly chainId: ChainId,
private readonly dependencies: Dependencies,
) {}
Expand All @@ -46,7 +48,7 @@ export class BaseDistributedHandler implements IEventHandler<"Strategy", "Distri
args: {
chainId: this.chainId,
roundId: round.id,
amount: BigInt(this.event.params.amount),
amount: this.event.params.amount,
},
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,15 @@ export class DVMDDirectTransferStrategyHandler extends BaseStrategyHandler {
/** @inheritdoc */
async handle(event: ProcessorEvent<"Strategy", StrategyEvent>): Promise<Changeset[]> {
switch (event.eventName) {
case "Registered":
case "RegisteredWithSender":
return new DVMDRegisteredHandler(
event as ProcessorEvent<"Strategy", "Registered">,
event as ProcessorEvent<"Strategy", "RegisteredWithSender">,
this.chainId,
this.dependencies,
).handle();
case "Distributed":
case "DistributedWithRecipientAddress":
return new BaseDistributedHandler(
event as ProcessorEvent<"Strategy", "Distributed">,
event as ProcessorEvent<"Strategy", "DistributedWithRecipientAddress">,
this.chainId,
this.dependencies,
).handle();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ type Dependencies = Pick<
* - Links the application to both the project and round
*/

export class DVMDRegisteredHandler implements IEventHandler<"Strategy", "Registered"> {
export class DVMDRegisteredHandler implements IEventHandler<"Strategy", "RegisteredWithSender"> {
constructor(
readonly event: ProcessorEvent<"Strategy", "Registered">,
readonly event: ProcessorEvent<"Strategy", "RegisteredWithSender">,
private readonly chainId: ChainId,
private readonly dependencies: Dependencies,
) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import { ChainId, ProcessorEvent } from "@grants-stack-indexer/shared";
import { BaseDistributedHandler } from "../../../src/strategy/common/baseDistributed.handler.js";

function createMockEvent(
overrides: Partial<ProcessorEvent<"Strategy", "Distributed">> = {},
): ProcessorEvent<"Strategy", "Distributed"> {
const defaultEvent: ProcessorEvent<"Strategy", "Distributed"> = {
overrides: Partial<ProcessorEvent<"Strategy", "DistributedWithRecipientAddress">> = {},
): ProcessorEvent<"Strategy", "DistributedWithRecipientAddress"> {
const defaultEvent: ProcessorEvent<"Strategy", "DistributedWithRecipientAddress"> = {
params: {
amount: 1000,
amount: 1000n,
recipientAddress: "0x1234567890123456789012345678901234567890",
recipientId: "0x1234567890123456789012345678901234567890",
sender: "0x1234567890123456789012345678901234567890",
},
eventName: "Distributed",
eventName: "DistributedWithRecipientAddress",
srcAddress: "0x1234567890123456789012345678901234567890",
blockNumber: 12345,
blockTimestamp: 1000000000,
Expand All @@ -36,7 +36,7 @@ function createMockEvent(
describe("BaseDistributedHandler", () => {
let handler: BaseDistributedHandler;
let mockRoundRepository: IRoundReadRepository;
let mockEvent: ProcessorEvent<"Strategy", "Distributed">;
let mockEvent: ProcessorEvent<"Strategy", "DistributedWithRecipientAddress">;
const chainId = 10 as ChainId;

beforeEach(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ describe("DVMDDirectTransferHandler", () => {

it("calls RegisteredHandler for Registered event", async () => {
const mockEvent = {
eventName: "Registered",
} as ProcessorEvent<"Strategy", "Registered">;
eventName: "RegisteredWithSender",
} as ProcessorEvent<"Strategy", "RegisteredWithSender">;

vi.spyOn(DVMDRegisteredHandler.prototype, "handle").mockResolvedValue([]);

Expand All @@ -101,8 +101,8 @@ describe("DVMDDirectTransferHandler", () => {

it("calls DistributedHandler for Distributed event", async () => {
const mockEvent = {
eventName: "Distributed",
} as ProcessorEvent<"Strategy", "Distributed">;
eventName: "DistributedWithRecipientAddress",
} as ProcessorEvent<"Strategy", "DistributedWithRecipientAddress">;

vi.spyOn(BaseDistributedHandler.prototype, "handle").mockResolvedValue([]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ import { ProjectNotFound, RoundNotFound } from "../../../../src/exceptions/index
import { DVMDRegisteredHandler } from "../../../../src/strategy/donationVotingMerkleDistributionDirectTransfer/handlers/index.js";

function createMockEvent(
overrides: DeepPartial<ProcessorEvent<"Strategy", "Registered">> = {},
): ProcessorEvent<"Strategy", "Registered"> {
const defaultEvent: ProcessorEvent<"Strategy", "Registered"> = {
overrides: DeepPartial<ProcessorEvent<"Strategy", "RegisteredWithSender">> = {},
): ProcessorEvent<"Strategy", "RegisteredWithSender"> {
const defaultEvent: ProcessorEvent<"Strategy", "RegisteredWithSender"> = {
params: {
recipientId: "0x1234567890123456789012345678901234567890",
sender: "0x0987654321098765432109876543210987654321",
data: "0x0000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000002c7296a5ec0539f0a018c7176c97c92a9c44e2b4000000000000000000000000e7eb5d2b5b188777df902e89c54570e7ef4f59ce000000000000000000000000000000000000000000000000000000000000006000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000000000040000000000000000000000000000000000000000000000000000000000000003b6261666b72656967796334336366696e786c6e6168713561617773676869626574763675737273376b6b78663776786d7a626a79726f37366977790000000000",
},
eventName: "Registered",
eventName: "RegisteredWithSender",
srcAddress: "0x1234567890123456789012345678901234567890",
blockNumber: 12345,
blockTimestamp: 1000000000,
Expand All @@ -37,15 +37,15 @@ function createMockEvent(
strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0",
};

return mergeDeep(defaultEvent, overrides) as ProcessorEvent<"Strategy", "Registered">;
return mergeDeep(defaultEvent, overrides) as ProcessorEvent<"Strategy", "RegisteredWithSender">;
}

describe("DVMDRegisteredHandler", () => {
let handler: DVMDRegisteredHandler;
let mockRoundRepository: IRoundReadRepository;
let mockProjectRepository: IProjectReadRepository;
let mockMetadataProvider: IMetadataProvider;
let mockEvent: ProcessorEvent<"Strategy", "Registered">;
let mockEvent: ProcessorEvent<"Strategy", "RegisteredWithSender">;
const chainId = 10 as ChainId;

beforeEach(() => {
Expand Down
58 changes: 44 additions & 14 deletions packages/shared/src/types/events/strategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@ import { Address, AnyEvent, ContractName, ProcessorEvent } from "../../internal.
* This array is used to represent all Strategy events.
*/
const StrategyEventArray = [
"Registered",
"Distributed",
"RegisteredWithSender",
"RegisteredWithData",
"DistributedWithRecipientAddress",
"DistributedWithData",
"DistributedWithFlowRate",
"TimestampsUpdated",
"AllocatedWithToken",
] as const;
Expand All @@ -20,37 +23,64 @@ export type StrategyEvent = (typeof StrategyEventArray)[number];
/**
* This type maps Strategy events to their respective parameters.
*/
export type StrategyEventParams<T extends StrategyEvent> = T extends "Registered"
? RegisteredParams
: T extends "Distributed"
? DistributedParams
: T extends "TimestampsUpdated"
? TimestampsUpdatedParams
: T extends "AllocatedWithToken"
? AllocatedWithTokenParams
: never;
export type StrategyEventParams<T extends StrategyEvent> = T extends "RegisteredWithSender"
? RegisteredWithSenderParams
: T extends "RegisteredWithData"
? RegisteredWithDataParams
: T extends "DistributedWithRecipientAddress"
? DistributedWithRecipientAddressParams
: T extends "DistributedWithData"
? DistributedWithDataParams
: T extends "DistributedWithFlowRate"
? DistributedWithFlowRateParams
: T extends "TimestampsUpdated"
? TimestampsUpdatedParams
: T extends "AllocatedWithToken"
? AllocatedWithTokenParams
: never;

// =============================================================================
// =============================== Event Parameters ============================
// =============================================================================
export type RegisteredParams = {

// ======================= Registered =======================
export type RegisteredWithSenderParams = {
recipientId: Address;
data: Hex;
sender: Address;
};

export type DistributedParams = {
export type RegisteredWithDataParams = {
recipient: Address;
data: Hex;
};

// ======================= Distributed =======================
export type DistributedWithRecipientAddressParams = {
recipientAddress: Address;
recipientId: Address;
sender: Address;
amount: number;
amount: bigint;
};

export type DistributedWithDataParams = {
data: Hex;
sender: Address;
};

export type DistributedWithFlowRateParams = {
flowRate: bigint;
sender: Address;
};

// ======================= TimestampsUpdated =======================

export type TimestampsUpdatedParams = {
contractAddress: Address;
timestamp: number;
};

// ======================= Allocated =======================
export type AllocatedWithTokenParams = {
contractAddress: Address;
tokenAddress: Address;
Expand Down