Skip to content

Commit

Permalink
feat: add bond escalation module
Browse files Browse the repository at this point in the history
  • Loading branch information
jahabeebs committed Sep 17, 2024
1 parent 3d049da commit f4a2378
Show file tree
Hide file tree
Showing 6 changed files with 1,764 additions and 11 deletions.
1 change: 1 addition & 0 deletions apps/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const config = {
oracle: "0x00",
epochManager: "0x00",
eboRequestCreator: "0x00",
bondEscalationModule: "0x00",
} as const,
privateKey: "0xsecret" as const,
},
Expand Down
1,710 changes: 1,710 additions & 0 deletions packages/automated-dispute/src/abis/bondEscalationModule.ts

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions packages/automated-dispute/src/abis/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from "./oracle.js";
export * from "./epochManager.js";
export * from "./eboRequestCreator.js";
export * from "./bondEscalationModule.js";
7 changes: 6 additions & 1 deletion packages/automated-dispute/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export const ProtocolContractsNames = ["oracle", "epochManager", "eboRequestCreator"] as const;
export const ProtocolContractsNames = [
"oracle",
"epochManager",
"eboRequestCreator",
"bondEscalationModule",
] as const;
32 changes: 25 additions & 7 deletions packages/automated-dispute/src/providers/protocolProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,12 @@ import { privateKeyToAccount } from "viem/accounts";
import { arbitrum } from "viem/chains";

import type { Dispute, EboEvent, EboEventName, Epoch, Request, Response } from "../types/index.js";
import { eboRequestCreatorAbi, epochManagerAbi, oracleAbi } from "../abis/index.js";
import {
bondEscalationModuleAbi,
eboRequestCreatorAbi,
epochManagerAbi,
oracleAbi,
} from "../abis/index.js";
import {
InvalidAccountOnClient,
RpcUrlsEmpty,
Expand Down Expand Up @@ -56,6 +61,11 @@ export class ProtocolProvider implements IProtocolProvider {
typeof this.writeClient,
Address
>;
private bondEscalationContract: GetContractReturnType<
typeof bondEscalationModuleAbi,
typeof this.writeClient,
Address
>;

/**
* Creates a new ProtocolProvider instance
Expand Down Expand Up @@ -114,6 +124,14 @@ export class ProtocolProvider implements IProtocolProvider {
wallet: this.writeClient,
},
});
this.bondEscalationContract = getContract({
address: contracts.bondEscalationModule,
abi: bondEscalationModuleAbi,
client: {
public: this.readClient,
wallet: this.writeClient,
},
});
}

public write: IWriteProvider = {
Expand Down Expand Up @@ -418,8 +436,8 @@ export class ProtocolProvider implements IProtocolProvider {
): Promise<void> {
try {
const { request: simulatedRequest } = await this.readClient.simulateContract({
address: this.oracleContract.address,
abi: oracleAbi,
address: this.bondEscalationContract.address,
abi: bondEscalationModuleAbi,
functionName: "pledgeForDispute",
args: [request, dispute],
account: this.writeClient.account,
Expand Down Expand Up @@ -464,8 +482,8 @@ export class ProtocolProvider implements IProtocolProvider {
): Promise<void> {
try {
const { request: simulatedRequest } = await this.readClient.simulateContract({
address: this.oracleContract.address,
abi: oracleAbi,
address: this.bondEscalationContract.address,
abi: bondEscalationModuleAbi,
functionName: "pledgeAgainstDispute",
args: [request, dispute],
account: this.writeClient.account,
Expand Down Expand Up @@ -512,8 +530,8 @@ export class ProtocolProvider implements IProtocolProvider {
): Promise<void> {
try {
const { request: simulatedRequest } = await this.readClient.simulateContract({
address: this.oracleContract.address,
abi: oracleAbi,
address: this.bondEscalationContract.address,
abi: bondEscalationModuleAbi,
functionName: "settleBondEscalation",
args: [request, response, dispute],
account: this.writeClient.account,
Expand Down
24 changes: 21 additions & 3 deletions packages/automated-dispute/tests/services/protocolProvider.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@ import { privateKeyToAccount } from "viem/accounts";
import { arbitrum } from "viem/chains";
import { afterEach, beforeEach, describe, expect, it, Mock, vi } from "vitest";

import { eboRequestCreatorAbi } from "../../src/abis/eboRequestCreator.js";
import { epochManagerAbi } from "../../src/abis/epochManager.js";
import { oracleAbi } from "../../src/abis/oracle.js";
import {
bondEscalationModuleAbi,
eboRequestCreatorAbi,
epochManagerAbi,
oracleAbi,
} from "../../src/abis/index.js";
import {
InvalidAccountOnClient,
RpcUrlsEmpty,
Expand Down Expand Up @@ -46,6 +49,7 @@ describe("ProtocolProvider", () => {
oracle: "0x1234567890123456789012345678901234567890",
epochManager: "0x1234567890123456789012345678901234567890",
eboRequestCreator: "0x1234567890123456789012345678901234567890",
bondEscalationModule: "0x1234567890123456789012345678901234567890",
};

beforeEach(() => {
Expand All @@ -71,6 +75,18 @@ describe("ProtocolProvider", () => {
},
};
}
if (
abi === bondEscalationModuleAbi &&
address === mockContractAddress.bondEscalationModule
) {
return {
write: {
pledgeForDispute: vi.fn(),
pledgeAgainstDispute: vi.fn(),
settleDispute: vi.fn(),
},
};
}
throw new Error("Invalid contract address or ABI");
});

Expand Down Expand Up @@ -487,6 +503,7 @@ describe("ProtocolProvider", () => {
oracle: "0x1234567890123456789012345678901234567890",
epochManager: "0x1234567890123456789012345678901234567890",
eboRequestCreator: "0x1234567890123456789012345678901234567890",
bondEscalationModule: "0x1234567890123456789012345678901234567890",
};

it("creates a request successfully", async () => {
Expand Down Expand Up @@ -529,6 +546,7 @@ describe("ProtocolProvider", () => {
oracle: "0x1234567890123456789012345678901234567890",
epochManager: "0x1234567890123456789012345678901234567890",
eboRequestCreator: "0x1234567890123456789012345678901234567890",
bondEscalationModule: "0x1234567890123456789012345678901234567890",
},
mockedPrivateKey,
);
Expand Down

0 comments on commit f4a2378

Please sign in to comment.