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: implement get events #50

Merged
merged 14 commits into from
Oct 14, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export class DecodeLogDataFailure extends Error {
constructor(err: unknown) {
super(`Error decoding log data: ${err}`);

this.name = "DecodeLogDataFailure";
}
}
2 changes: 2 additions & 0 deletions packages/automated-dispute/src/exceptions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ export * from "./invalidRequestBody.exception.js";
export * from "./invalidRequester.exception.js";
export * from "./transactionExecutionError.exception.js";
export * from "./invalidAccountOnClient.exception.js";
export * from "./unsupportedEvent.exception.js";
export * from "./decodeLogDataFailure.js";
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export class UnsupportedEvent extends Error {
constructor(message: string) {
super(message);
this.name = "UnsupportedEvent";
}
}
97 changes: 96 additions & 1 deletion packages/automated-dispute/src/interfaces/protocolProvider.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
import { Caip2ChainId } from "@ebo-agent/blocknumber";
import { Address } from "viem";

import type { Dispute, EboEvent, EboEventName, Epoch, Request, Response } from "../types/index.js";
import type {
Dispute,
EboEvent,
EboEventName,
Epoch,
Request,
RequestId,
Response,
} from "../types/index.js";
import { ProtocolContractsNames } from "../constants.js";

export type ProtocolContract = (typeof ProtocolContractsNames)[number];
Expand Down Expand Up @@ -177,3 +186,89 @@ export interface IProtocolProvider {
*/
read: IReadProvider;
}

/**
* @interface DecodedLogArgsMap
* Represents the mapping of event names to their respective argument structures.
*/
export interface DecodedLogArgsMap {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I like this approach, @0xkenj1 what do you think? Should we use this to define events' types instead of our current approach?

type EboEventData<E extends EboEventName> = E extends "RequestCreated"
    ? RequestCreated
    : E extends "ResponseProposed"
    ...

One way or another, we need to use a single approach as right now we have events' internal data types defined here and also defined in types/events.ts

Copy link
Collaborator

Choose a reason for hiding this comment

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

Matt says this: https://www.totaltypescript.com/type-vs-interface-which-should-you-use

tldr; type by default, go for interfaces if you expect to do inheritance

/**
* Event arguments for the RequestCreated event.
* @property {RequestId} requestId - The ID of the request.
* @property {bigint} epoch - The epoch time when the request was created.
* @property {Caip2ChainId} chainId - The chain ID where the request was created.
*/
RequestCreated: {
requestId: RequestId;
epoch: bigint;
chainId: Caip2ChainId;
};

/**
* Event arguments for the ResponseProposed event.
* @property {RequestId} requestId - The ID of the request.
* @property {string} responseId - The ID of the response.
* @property {string} response - The response content.
* @property {bigint} blockNumber - The block number when the response was proposed.
*/
ResponseProposed: {
requestId: RequestId;
responseId: string;
response: string;
blockNumber: bigint;
};

/**
* Event arguments for the ResponseDisputed event.
* @property {string} responseId - The ID of the response.
* @property {string} disputeId - The ID of the dispute.
* @property {string} dispute - The dispute content.
* @property {bigint} blockNumber - The block number when the dispute was raised.
*/
ResponseDisputed: {
responseId: string;
disputeId: string;
dispute: string;
blockNumber: bigint;
};

/**
* Event arguments for the DisputeStatusChanged event.
* @property {string} disputeId - The ID of the dispute.
* @property {string} dispute - The dispute content.
* @property {number} status - The new status of the dispute.
* @property {bigint} blockNumber - The block number when the dispute status changed.
*/
DisputeStatusChanged: {
disputeId: string;
dispute: string;
status: number;
blockNumber: bigint;
};

/**
* Event arguments for the DisputeEscalated event.
* @property {string} caller - The address of the caller who escalated the dispute.
* @property {string} disputeId - The ID of the dispute.
* @property {bigint} blockNumber - The block number when the dispute was escalated.
*/
DisputeEscalated: {
caller: string;
disputeId: string;
blockNumber: bigint;
};

/**
* Event arguments for the RequestFinalized event.
* @property {RequestId} requestId - The ID of the request.
* @property {string} responseId - The ID of the response.
* @property {string} caller - The address of the caller who finalized the request.
* @property {bigint} blockNumber - The block number when the request was finalized.
*/
RequestFinalized: {
requestId: RequestId;
responseId: string;
caller: string;
blockNumber: bigint;
};
}
Loading
Loading