From 36e26eb68a49023f3da9dd1946866d98ccd68091 Mon Sep 17 00:00:00 2001 From: nigiri <168690269+0xnigir1@users.noreply.github.com> Date: Wed, 23 Oct 2024 13:00:51 -0300 Subject: [PATCH] fix: allo pool created type (#15) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # 🤖 Linear Closes GIT-112 ## Description - fix `PoolCreatedParams` typing - move `strategyId` field to ProtocolEvent ## Checklist before requesting a review - [x] I have conducted a self-review of my code. - [x] I have conducted a QA. - [x] If it is a core feature, I have included comprehensive tests. --- .../test/unit/envioIndexerClient.spec.ts | 1 + .../src/allo/handlers/poolCreated.handler.ts | 6 +++--- .../allo/handlers/poolCreated.handler.spec.ts | 21 ++++++++++--------- packages/shared/src/types/events/allo.ts | 5 ++--- packages/shared/src/types/events/common.ts | 19 ++++++++++++++++- 5 files changed, 35 insertions(+), 17 deletions(-) diff --git a/packages/indexer-client/test/unit/envioIndexerClient.spec.ts b/packages/indexer-client/test/unit/envioIndexerClient.spec.ts index 1a9abb8..a6d2d90 100644 --- a/packages/indexer-client/test/unit/envioIndexerClient.spec.ts +++ b/packages/indexer-client/test/unit/envioIndexerClient.spec.ts @@ -52,6 +52,7 @@ describe("EnvioIndexerClient", () => { srcAddress: "0x1234567890123456789012345678901234567890", logIndex: 0, params: { contractAddress: "0x1234" }, + transactionFields: { hash: "0x1234", transactionIndex: 0 }, }, ]; diff --git a/packages/processors/src/allo/handlers/poolCreated.handler.ts b/packages/processors/src/allo/handlers/poolCreated.handler.ts index de6a6a8..db79ff8 100644 --- a/packages/processors/src/allo/handlers/poolCreated.handler.ts +++ b/packages/processors/src/allo/handlers/poolCreated.handler.ts @@ -40,15 +40,15 @@ export class PoolCreatedHandler implements IEventHandler<"Allo", "PoolCreated"> async handle(): Promise { const { metadataProvider, evmProvider } = this.dependencies; - const [metadataPointer] = this.event.params.metadata; + const metadataPointer = this.event.params.metadata[1]; const { poolId, - strategyId, token: tokenAddress, - contractAddress: strategyAddress, + strategy: strategyAddress, amount: fundedAmount, } = this.event.params; const { hash: txHash, from: txFrom } = this.event.transactionFields; + const strategyId = this.event.strategyId; const metadata = await metadataProvider.getMetadata<{ round?: unknown; diff --git a/packages/processors/test/allo/handlers/poolCreated.handler.spec.ts b/packages/processors/test/allo/handlers/poolCreated.handler.spec.ts index 26acf4c..89a8061 100644 --- a/packages/processors/test/allo/handlers/poolCreated.handler.spec.ts +++ b/packages/processors/test/allo/handlers/poolCreated.handler.spec.ts @@ -26,19 +26,19 @@ function createMockEvent( logIndex: 221, srcAddress: "0x1133eA7Af70876e64665ecD07C0A0476d09465a1", params: { - contractAddress: "0xD545fbA3f43EcA447CC7FBF41D4A8F0f575F2491", + strategy: "0xD545fbA3f43EcA447CC7FBF41D4A8F0f575F2491", poolId: 10n, profileId: "0xcc3509068dfb6604965939f100e57dde21e9d764d8ce4b34284bbe9364b1f5ed", - strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", amount: 0n, token: "0x4200000000000000000000000000000000000042", - metadata: ["bafkreihrjyu5tney6wia2hmkertc74nzfpsgxw2epvnxm72bxj6ifnd4ku", 1n], + metadata: [1n, "bafkreihrjyu5tney6wia2hmkertc74nzfpsgxw2epvnxm72bxj6ifnd4ku"], }, transactionFields: { hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", transactionIndex: 6, from: "0xcBf407C33d68a55CB594Ffc8f4fD1416Bba39DA5", }, + strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", }; return mergeDeep(defaultEvent, overrides) as ProtocolEvent<"Allo", "PoolCreated">; @@ -75,7 +75,8 @@ describe("PoolCreatedHandler", () => { it("process an event with initial funds", async () => { const fundedAmount = parseUnits("10", 18); const mockEvent = createMockEvent({ - params: { amount: fundedAmount, strategyId: "0xunknown" }, + params: { amount: fundedAmount }, + strategyId: "0xunknown", }); vi.spyOn(mockPricingProvider, "getTokenPrice").mockResolvedValue({ @@ -105,7 +106,7 @@ describe("PoolCreatedHandler", () => { it("process an unknown strategyId", async () => { const mockEvent = createMockEvent({ - params: { strategyId: "0xunknown" }, + strategyId: "0xunknown", }); vi.spyOn(mockMetadataProvider, "getMetadata").mockResolvedValue(undefined); @@ -126,7 +127,7 @@ describe("PoolCreatedHandler", () => { chainId: 10, id: "10", tags: ["allo-v2"], - strategyAddress: mockEvent.params.contractAddress, + strategyAddress: mockEvent.params.strategy, strategyId: "0xunknown", strategyName: "", createdByAddress: mockEvent.transactionFields.from, @@ -214,7 +215,7 @@ describe("PoolCreatedHandler", () => { applicationsEndTime: new Date("2021-01-01T00:00:00.000Z"), donationsStartTime: new Date("2021-01-01T00:00:00.000Z"), donationsEndTime: new Date("2021-01-01T00:00:00.000Z"), - strategyAddress: mockEvent.params.contractAddress, + strategyAddress: mockEvent.params.strategy, strategyId: "0x9fa6890423649187b1f0e8bf4265f0305ce99523c3d11aa36b35a54617bb0ec0", strategyName: "allov2.DonationVotingMerkleDistributionDirectTransferStrategy", createdByAddress: mockEvent.transactionFields.from, @@ -232,7 +233,7 @@ describe("PoolCreatedHandler", () => { it("fetches transaction sender if not present in event", async () => { const mockEvent = createMockEvent({ - params: { strategyId: "0xunknown" }, + strategyId: "0xunknown", transactionFields: { hash: "0xd2352acdcd59e312370831ea927d51a1917654697a72434cd905a60897a5bb8b", from: undefined, @@ -310,7 +311,7 @@ describe("PoolCreatedHandler", () => { }); it("throws an error if token price fetch fails", async () => { - const mockEvent = createMockEvent({ params: { amount: 1n, strategyId: "0xunknown" } }); + const mockEvent = createMockEvent({ params: { amount: 1n }, strategyId: "0xunknown" }); vi.spyOn(mockMetadataProvider, "getMetadata").mockResolvedValue(undefined); @@ -474,8 +475,8 @@ describe("PoolCreatedHandler", () => { params: { amount: fundedAmount, token: "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE", - strategyId: "0xunknown", }, + strategyId: "0xunknown", }); vi.spyOn(mockRoundRepository, "getPendingRoundRoles").mockResolvedValue([]); diff --git a/packages/shared/src/types/events/allo.ts b/packages/shared/src/types/events/allo.ts index 32f5c44..d4b8e57 100644 --- a/packages/shared/src/types/events/allo.ts +++ b/packages/shared/src/types/events/allo.ts @@ -16,11 +16,10 @@ export type AlloEventParams = T extends "PoolCreated" // =============================== Event Parameters ============================ // ============================================================================= export type PoolCreatedParams = { - contractAddress: Address; + strategy: Address; poolId: bigint; profileId: Address; - strategyId: Address; token: Address; amount: bigint; - metadata: [pointer: string, protocol: bigint]; + metadata: [protocol: bigint, pointer: string]; }; diff --git a/packages/shared/src/types/events/common.ts b/packages/shared/src/types/events/common.ts index ad2a38d..0f62eb7 100644 --- a/packages/shared/src/types/events/common.ts +++ b/packages/shared/src/types/events/common.ts @@ -48,6 +48,23 @@ export type ProtocolEvent; srcAddress: Address; transactionFields: TransactionFields; + // strategyId should be defined for Strategy events or PoolCreated events in Allo + strategyId: T extends "Strategy" + ? Address + : T extends "Allo" + ? E extends "PoolCreated" + ? Address + : never + : never; }; -export type AnyProtocolEvent = ProtocolEvent>; +/** + * TODO: This type is currently only used in the EventsFetcher and IndexerClient. + * In the future, we should evaluate if a more decoupled or generic type is needed + * to improve flexibility and reduce dependencies across different parts of the system. + * Consider creating separate event types for different contexts if necessary. + */ +export type AnyProtocolEvent = Omit< + ProtocolEvent>, + "strategyId" +>;