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

refactor: generic ebo events #17

Merged
merged 41 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
06ef8af
build: separate tsconfig for build stage
0xyaco Jul 18, 2024
9802a89
feat: set up blocknumber module tests
0xyaco Jul 18, 2024
546d76e
chore: set up blocknumber module linting
0xyaco Jul 18, 2024
5b57a2d
Merge remote-tracking branch 'origin/dev' into chore/blocknumber-setup
0xyaco Jul 18, 2024
f291b45
style: remove total-typescript on non-base tsconfig
0xyaco Jul 18, 2024
0e8fc5a
build: set up build script
0xyaco Jul 18, 2024
baa144a
fix: blocknumber module package config
0xyaco Jul 19, 2024
9965c35
fix: dummy class import module
0xyaco Jul 19, 2024
6215697
chore: add coverage script and tasks
0xyaco Jul 19, 2024
2748ca2
chore: remove dummy classes
0xyaco Jul 19, 2024
ab869a4
feat: implement caip-2 compliant chain ids
0xyaco Jul 19, 2024
212960a
refactor: create exceptions/ folder
0xyaco Jul 24, 2024
21f025b
Merge remote-tracking branch 'origin/dev' into feat/bn-service
0xyaco Jul 24, 2024
ecd91e9
feat: search block by timestamp with binsearch
0xyaco Jul 23, 2024
4a38c03
fix: fixed winston dependency version
0xyaco Jul 24, 2024
711216d
refactor: rename evmProvider to evmBlockNumberProvider
0xyaco Jul 24, 2024
c7a9035
refactor: client and search params in evm provider constructor
0xyaco Jul 25, 2024
18d537a
Merge remote-tracking branch 'origin/dev' into feat/evm-block-search
0xyaco Jul 25, 2024
5ad1369
fix: pnpm dependecies mismatch
0xyaco Jul 25, 2024
6875aea
fix: throw InvalidTimestamp for timestamps prior first block
0xyaco Jul 25, 2024
80da90d
chore: remove dummy classes
0xyaco Jul 25, 2024
9a60076
refactor: move and redefine caip2 chain id
0xyaco Jul 26, 2024
60a57e1
feat: implements BlockNumberService
0xyaco Jul 26, 2024
841dc96
Merge remote-tracking branch 'origin/dev' into feat/bn-service
0xyaco Jul 26, 2024
cc0a6f0
chore: fix vitest tests location config
0xyaco Jul 26, 2024
0b44abe
feat: build provider based on chain namespace only
0xyaco Jul 30, 2024
32a49b7
Merge remote-tracking branch 'origin/dev' into feat/bn-service
0xyaco Jul 30, 2024
557a073
chore: remove old logger class
0xyaco Jul 30, 2024
163669b
fix: remove references from old logger
0xyaco Jul 31, 2024
776ba42
refactor: use shared chains
0xyaco Jul 31, 2024
ea13674
chore: fix turbo config
0xyaco Jul 31, 2024
0c01a4b
refactor: use logger with dependency injection
0xyaco Jul 31, 2024
472dab2
refactor: rename Caip2 to Caip2Utils
0xyaco Jul 31, 2024
0954b57
refactor: created BlockNumberProviderFactory
0xyaco Jul 31, 2024
7f0fa3a
feat: add single-chain getEpochBlockNumber
0xyaco Jul 31, 2024
e97d367
refactor: reorganize chains config structure and values
0xyaco Jul 31, 2024
d0171b2
chore: base EboActor implementation
0xyaco Jul 31, 2024
b11f993
Merge remote-tracking branch 'origin/dev' into feat/base-ebo-actor
0xyaco Aug 2, 2024
fdaa4bb
refactor: generic ebo events
0xyaco Jul 31, 2024
c07b536
refactor: improve generic event type
0xyaco Aug 1, 2024
589f4e0
Merge remote-tracking branch 'origin/dev' into feat/generic-ebo-events
0xyaco Aug 5, 2024
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
20 changes: 8 additions & 12 deletions packages/automated-dispute/src/eboActor.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
import { BlockNumberService } from "@ebo-agent/blocknumber";

import { ProtocolProvider } from "./protocolProvider.js";
import {
DisputeStatusChanged,
RequestCreated,
RequestFinalizable,
ResponseDisputed,
} from "./types/events.js";
import { EboEvent } from "./types/events.js";
import { Dispute, Response } from "./types/prophet.js";

export class EboActor {
Expand All @@ -20,17 +15,17 @@ export class EboActor {
this.requestActivity = [];
}

public async onRequestCreated(_event: RequestCreated): Promise<void> {
public async onRequestCreated(_event: EboEvent<"RequestCreated">): Promise<void> {
// TODO: implement
return;
}

public async onResponseProposed(_event: ResponseDisputed): Promise<void> {
public async onResponseProposed(_event: EboEvent<"ResponseDisputed">): Promise<void> {
// TODO: implement
return;
}

public async onResponseDisputed(_event: ResponseDisputed): Promise<void> {
public async onResponseDisputed(_event: EboEvent<"ResponseDisputed">): Promise<void> {
// TODO: implement
return;
}
Expand All @@ -50,17 +45,18 @@ export class EboActor {
return true;
}

public async onFinalizeRequest(_event: RequestFinalizable): Promise<void> {
public async onFinalizeRequest(_event: EboEvent<"RequestFinalizable">): Promise<void> {
// TODO: implement
return;
}

public async onDisputeStatusChanged(_event: DisputeStatusChanged): Promise<void> {
public async onDisputeStatusChanged(_event: EboEvent<"DisputeStatusChanged">): Promise<void> {
// TODO: implement
return;
}

public async onDisputeEscalated(_event: Dispute): Promise<void> {
public async onDisputeEscalated(_event: EboEvent<"DisputeEscalated">): Promise<void> {
// TODO: implement
return;
}
}
20 changes: 7 additions & 13 deletions packages/automated-dispute/src/protocolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ import {
} from "viem";
import { arbitrum } from "viem/chains";

import type {
DisputeStatusChanged,
EboEvent,
RequestCreated,
ResponseDisputed,
ResponseProposed,
} from "./types/events.js";
import type { EboEvent, EboEventName } from "./types/events.js";
import type { Dispute, Request, Response } from "./types/prophet.js";
import { epochManagerAbi, oracleAbi } from "./abis/index.js";
import { RpcUrlsEmpty } from "./exceptions/rpcUrlsEmpty.exception.js";
Expand Down Expand Up @@ -73,7 +67,7 @@ export class ProtocolProvider {
};
}

async getEvents(_fromBlock: bigint, _toBlock: bigint): Promise<EboEvent[]> {
async getEvents(_fromBlock: bigint, _toBlock: bigint): Promise<EboEvent<EboEventName>[]> {
// TODO: implement actual method.
//
// We should decode events using the corresponding ABI and also "fabricate" new events
Expand All @@ -94,7 +88,7 @@ export class ProtocolProvider {
finalityModule: "0x12345678901234567890123456789012",
},
},
} as RequestCreated,
} as EboEvent<"RequestCreated">,
];

const oracleEvents = [
Expand All @@ -111,7 +105,7 @@ export class ProtocolProvider {
response: "0x01234",
},
},
} as ResponseProposed,
} as EboEvent<"ResponseProposed">,
{
name: "ResponseDisputed",
blockNumber: 3n,
Expand All @@ -127,13 +121,13 @@ export class ProtocolProvider {
requestId: "0x01",
},
},
} as ResponseDisputed,
} as EboEvent<"ResponseDisputed">,
{
name: "DisputeStatusChanged",
blockNumber: 4n,
logIndex: 20,
metadata: { disputeId: "0x03", status: "Won", blockNumber: 4n },
} as DisputeStatusChanged,
} as EboEvent<"DisputeStatusChanged">,
];

return this.mergeEventStreams(eboRequestCreatorEvents, oracleEvents);
Expand All @@ -147,7 +141,7 @@ export class ProtocolProvider {
* @returns the EboEvent[] arrays merged in a single array and sorted by ascending blockNumber
* and logIndex
*/
private mergeEventStreams(...streams: EboEvent[][]) {
private mergeEventStreams(...streams: EboEvent<EboEventName>[][]) {
return streams
.reduce((acc, curr) => acc.concat(curr), [])
.sort((a, b) => {
Expand Down
105 changes: 71 additions & 34 deletions packages/automated-dispute/src/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,46 +1,83 @@
import { Log } from "viem";

import { Dispute, Request, Response } from "./prophet.js";
import { Dispute, Request } from "./prophet.js";

export type BaseEvent = {
name: string;
blockNumber: bigint;
logIndex: number;
rawLog?: Log;
metadata: unknown;
};
export type EboEventName =
| "NewEpoch"
| "RequestCreated"
| "ResponseProposed"
| "ResponseDisputed"
| "DisputeStatusChanged"
| "DisputeEscalated"
| "RequestFinalizable"
| "RequestFinalized";

export type NewEpoch = BaseEvent & { metadata: { epoch: bigint; epochBlockNumber: bigint } };
export interface NewEpoch {
epoch: bigint;
epochBlockNumber: bigint;
}

export type RequestCreated = BaseEvent & { metadata: { requestId: string; request: Request } };
export interface ResponseCreated {
requestId: string;
request: Request;
}

export type ResponseProposed = BaseEvent & {
metadata: { requestId: string; responseId: string; response: Response };
};
export interface RequestCreated {
requestId: string;
request: Request;
}

export type ResponseDisputed = BaseEvent & {
metadata: { requestId: string; responseId: string; dispute: Dispute };
};
export interface ResponseDisputed {
requestId: string;
responseId: string;
dispute: Dispute;
}

export type DisputeStatusChanged = BaseEvent & {
metadata: { disputeId: string; status: string; blockNumber: bigint };
};
export interface DisputeStatusChanged {
disputeId: string;
status: string;
blockNumber: bigint;
}

export type DisputeEscalated = BaseEvent & {
metadata: { caller: string; disputeId: string; blockNumber: bigint };
};
export interface DisputeEscalated {
caller: string;
disputeId: string;
blockNumber: bigint;
}

export type RequestFinalizable = BaseEvent & {
metadata: { requestId: string };
};
export interface RequestFinalizable {
requestId: string;
}

export type RequestFinalized = BaseEvent & {
metadata: { requestId: string; responseId: string; caller: string; blockNumber: bigint };
};
export interface RequestFinalized {
requestId: string;
responseId: string;
caller: string;
blockNumber: bigint;
}

export type EboEventData<E extends EboEventName> = E extends "NewEpoch"
? NewEpoch
: E extends "RequestCreated"
? RequestCreated
: E extends "ResponseCreated"
? ResponseCreated
: E extends "ResponseDisputed"
? ResponseDisputed
: E extends "DisputeStatusChanged"
? DisputeStatusChanged
: E extends "DisputeEscalated"
? DisputeEscalated
: E extends "RequestFinalizable"
? RequestFinalizable
: E extends "RequestFinalized"
? RequestFinalized
: never;

export type EboEvent =
| NewEpoch
| RequestCreated
| ResponseProposed
| ResponseDisputed
| DisputeStatusChanged;
export type EboEvent<T extends EboEventName> = {
name: T;
blockNumber: bigint;
logIndex: number;
rawLog?: Log;
metadata: EboEventData<T>;
};