Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/dev' into feat/registry-processor
Browse files Browse the repository at this point in the history
  • Loading branch information
0xkenj1 committed Oct 23, 2024
2 parents 41cd088 + 36e26eb commit 3faf95e
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 39 deletions.
6 changes: 3 additions & 3 deletions packages/processors/src/allo/handlers/poolCreated.handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ export class PoolCreatedHandler implements IEventHandler<"Allo", "PoolCreated">

async handle(): Promise<Changeset[]> {
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;
Expand Down
21 changes: 11 additions & 10 deletions packages/processors/test/allo/handlers/poolCreated.handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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">;
Expand Down Expand Up @@ -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({
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -474,8 +475,8 @@ describe("PoolCreatedHandler", () => {
params: {
amount: fundedAmount,
token: "0x95aD61b0a150d79219dCF64E1E6Cc01f0B64C4cE",
strategyId: "0xunknown",
},
strategyId: "0xunknown",
});

vi.spyOn(mockRoundRepository, "getPendingRoundRoles").mockResolvedValue([]);
Expand Down
5 changes: 2 additions & 3 deletions packages/shared/src/types/events/allo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@ export type AlloEventParams<T extends AlloEvent> = 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];
};
19 changes: 17 additions & 2 deletions packages/shared/src/types/events/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,21 @@ export type ProtocolEvent<T extends ContractName, E extends ContractToEventName<
params: EventParams<T, E>;
srcAddress: Address;
transactionFields: TransactionFields;
};
} & (T extends "Strategy" // strategyId should be defined for Strategy events or PoolCreated events in Allo
? { strategyId: Address }
: T extends "Allo"
? E extends "PoolCreated"
? { strategyId: Address }
: Record<string, never>
: Record<string, never>);

export type AnyProtocolEvent = ProtocolEvent<ContractName, ContractToEventName<ContractName>>;
/**
* 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<ContractName, ContractToEventName<ContractName>>,
"strategyId"
>;
42 changes: 21 additions & 21 deletions pnpm-lock.yaml

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

0 comments on commit 3faf95e

Please sign in to comment.