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: allo pool created type #15

Merged
merged 3 commits into from
Oct 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ describe("EnvioIndexerClient", () => {
srcAddress: "0x1234567890123456789012345678901234567890",
logIndex: 0,
params: { contractAddress: "0x1234" },
transactionFields: { hash: "0x1234", transactionIndex: 0 },
},
];

Expand Down
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: 18 additions & 1 deletion packages/shared/src/types/events/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@ export type ProtocolEvent<T extends ContractName, E extends ContractToEventName<
params: EventParams<T, E>;
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<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"
>;