Skip to content

Commit

Permalink
feat: dispute escalated event (#33)
Browse files Browse the repository at this point in the history
# 🤖 Linear

Closes GRT-118

## Description
Uses `DisputeEscalated` event as there's no `DisputeStatusChanged` event
emitted from Prophet when escalating a dispute. This has already been
reported but due to audits changing Prophet's code to emit the
`DisputeStatusChanged` event while escalating a dispute too is not
feasible.
  • Loading branch information
0xyaco authored Sep 4, 2024
1 parent fe045ff commit 3733332
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 13 deletions.
12 changes: 7 additions & 5 deletions packages/automated-dispute/src/eboActor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,12 @@ export class EboActor {
this.registry,
);

case "DisputeEscalated":
return UpdateDisputeStatus.buildFromEvent(
event as EboEvent<"DisputeEscalated">,
this.registry,
);

case "RequestFinalized":
return Noop.buildFromEvent();

Expand Down Expand Up @@ -711,11 +717,7 @@ export class EboActor {
case "Active": // Case handled by ResponseDisputed
case "Lost": // Relevant during periodic request state checks
case "Won": // Relevant during periodic request state checks
break;

case "Escalated":
await this.onDisputeEscalated(disputeId, request);

case "Escalated": // Case handled by DisputeEscalated
break;

case "NoResolution":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
export * from "./addDispute.js";
export * from "./addRequest.js";
export * from "./addResponse.js";
export * from "./addDispute.js";
export * from "./noop.js";
export * from "./updateDisputeStatus.js";
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { CommandAlreadyRun, CommandNotRun, DisputeNotFound } from "../../../exceptions/index.js";
import { EboRegistry, EboRegistryCommand } from "../../../interfaces/index.js";
import { DisputeStatus, EboEvent } from "../../../types/index.js";
import { DisputeStatus, EboEvent, EboEventName } from "../../../types/index.js";

export class UpdateDisputeStatus implements EboRegistryCommand {
private wasRun: boolean = false;
Expand All @@ -13,15 +13,24 @@ export class UpdateDisputeStatus implements EboRegistryCommand {
) {}

public static buildFromEvent(
event: EboEvent<"DisputeStatusChanged">,
event: EboEvent<"DisputeStatusChanged" | "DisputeEscalated">,
registry: EboRegistry,
): UpdateDisputeStatus {
const disputeId = event.metadata.disputeId;
const status = event.metadata.status;

const status = this.isDisputeStatusChangedEvent(event)
? event.metadata.status
: "Escalated";

return new UpdateDisputeStatus(registry, disputeId, status);
}

private static isDisputeStatusChangedEvent(
event: EboEvent<EboEventName>,
): event is EboEvent<"DisputeStatusChanged"> {
return event.name === "DisputeStatusChanged";
}

run(): void {
if (this.wasRun) throw new CommandAlreadyRun(UpdateDisputeStatus.name);

Expand Down
16 changes: 12 additions & 4 deletions packages/automated-dispute/src/types/events.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js";
import { Log } from "viem";
import { Address, Log } from "viem";

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

Expand Down Expand Up @@ -43,6 +43,12 @@ export interface DisputeStatusChanged {
blockNumber: bigint;
}

export interface DisputeEscalated {
caller: Address;
disputeId: string;
blockNumber: bigint;
}

export interface RequestFinalized {
requestId: string;
responseId: string;
Expand All @@ -60,9 +66,11 @@ export type EboEventData<E extends EboEventName> = E extends "NewEpoch"
? ResponseDisputed
: E extends "DisputeStatusChanged"
? DisputeStatusChanged
: E extends "RequestFinalized"
? RequestFinalized
: never;
: E extends "DisputeEscalated"
? DisputeEscalated
: E extends "RequestFinalized"
? RequestFinalized
: never;

export type EboEvent<T extends EboEventName> = {
name: T;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,27 @@ describe("UpdateDisputeStatus", () => {
);
});

it("escalates when the event is DisputeEscalated", () => {
const escalatedDisputeEvent: EboEvent<"DisputeEscalated"> = {
...event,
name: "DisputeEscalated",
metadata: {
disputeId: "0x01",
blockNumber: event.blockNumber,
caller: "0x01",
},
};

const command = UpdateDisputeStatus.buildFromEvent(escalatedDisputeEvent, registry);

command.run();

expect(registry.updateDisputeStatus).toHaveBeenCalledWith(
event.metadata.disputeId,
"Escalated",
);
});

it("throws if the command was already run", () => {
const command = UpdateDisputeStatus.buildFromEvent(event, registry);

Expand Down

0 comments on commit 3733332

Please sign in to comment.