From 3e4b22c4a57b929c3cea234d3f8940c5afb00295 Mon Sep 17 00:00:00 2001 From: Yaco 0x Date: Fri, 13 Sep 2024 08:03:36 -0300 Subject: [PATCH 1/8] refactor: clean up imports and folder structure --- packages/automated-dispute/src/external.ts | 1 + packages/automated-dispute/src/index.ts | 2 +- packages/automated-dispute/src/providers/index.ts | 1 + .../src/{ => providers}/protocolProvider.ts | 12 ++++++------ .../automated-dispute/src/{ => services}/eboActor.ts | 12 ++++++------ .../src/{ => services}/eboActorsManager.ts | 8 ++++---- .../automated-dispute/src/services/eboProcessor.ts | 4 ++-- packages/automated-dispute/src/services/index.ts | 4 +++- .../automated-dispute/tests/mocks/eboActor.mocks.ts | 10 ++++++---- .../tests/mocks/eboProcessor.mocks.ts | 9 ++++++--- .../tests/services/eboActor.spec.ts | 2 +- .../tests/{ => services}/eboActor/fixtures.ts | 2 +- .../eboActor/onDisputeStatusChanged.spec.ts | 4 ++-- .../eboActor/onLastBlockupdated.spec.ts | 4 ++-- .../{ => services}/eboActor/onRequestCreated.spec.ts | 4 ++-- .../eboActor/onRequestFinalized.spec.ts | 6 +++--- .../eboActor/onResponseDisputed.spec.ts | 6 +++--- .../eboActor/onResponseProposed.spec.ts | 6 +++--- .../tests/{ => services}/eboActorsManager.spec.ts | 8 ++++---- .../eboMemoryRegistry/commands/addDispute.spec.ts | 2 +- .../eboMemoryRegistry/commands/addRequest.spec.ts | 2 +- .../eboMemoryRegistry/commands/addResponse.spec.ts | 2 +- .../commands/finalizeRequest.spec.ts | 2 +- .../commands/updateDisputeStatus.spec.ts | 2 +- .../tests/services/eboProcessor.spec.ts | 4 ++-- .../tests/{ => services}/errorFactory.spec.ts | 12 +++++++----- .../tests/{ => services}/protocolProvider.spec.ts | 12 ++++++------ 27 files changed, 77 insertions(+), 66 deletions(-) create mode 100644 packages/automated-dispute/src/external.ts create mode 100644 packages/automated-dispute/src/providers/index.ts rename packages/automated-dispute/src/{ => providers}/protocolProvider.ts (97%) rename packages/automated-dispute/src/{ => services}/eboActor.ts (98%) rename packages/automated-dispute/src/{ => services}/eboActorsManager.ts (90%) rename packages/automated-dispute/tests/{ => services}/eboActor/fixtures.ts (95%) rename packages/automated-dispute/tests/{ => services}/eboActor/onDisputeStatusChanged.spec.ts (97%) rename packages/automated-dispute/tests/{ => services}/eboActor/onLastBlockupdated.spec.ts (98%) rename packages/automated-dispute/tests/{ => services}/eboActor/onRequestCreated.spec.ts (98%) rename packages/automated-dispute/tests/{ => services}/eboActor/onRequestFinalized.spec.ts (93%) rename packages/automated-dispute/tests/{ => services}/eboActor/onResponseDisputed.spec.ts (96%) rename packages/automated-dispute/tests/{ => services}/eboActor/onResponseProposed.spec.ts (97%) rename packages/automated-dispute/tests/{ => services}/eboActorsManager.spec.ts (94%) rename packages/automated-dispute/tests/{ => services}/errorFactory.spec.ts (73%) rename packages/automated-dispute/tests/{ => services}/protocolProvider.spec.ts (96%) diff --git a/packages/automated-dispute/src/external.ts b/packages/automated-dispute/src/external.ts new file mode 100644 index 0000000..2f6b514 --- /dev/null +++ b/packages/automated-dispute/src/external.ts @@ -0,0 +1 @@ +export { EboProcessor, EboActorsManager } from "./services/index.js"; diff --git a/packages/automated-dispute/src/index.ts b/packages/automated-dispute/src/index.ts index f38655f..a5a2748 100644 --- a/packages/automated-dispute/src/index.ts +++ b/packages/automated-dispute/src/index.ts @@ -1 +1 @@ -export * from "./protocolProvider.js"; +export * from "./external.js"; diff --git a/packages/automated-dispute/src/providers/index.ts b/packages/automated-dispute/src/providers/index.ts new file mode 100644 index 0000000..f38655f --- /dev/null +++ b/packages/automated-dispute/src/providers/index.ts @@ -0,0 +1 @@ +export * from "./protocolProvider.js"; diff --git a/packages/automated-dispute/src/protocolProvider.ts b/packages/automated-dispute/src/providers/protocolProvider.ts similarity index 97% rename from packages/automated-dispute/src/protocolProvider.ts rename to packages/automated-dispute/src/providers/protocolProvider.ts index 90b96c6..b91d5f6 100644 --- a/packages/automated-dispute/src/protocolProvider.ts +++ b/packages/automated-dispute/src/providers/protocolProvider.ts @@ -19,17 +19,17 @@ import { import { privateKeyToAccount } from "viem/accounts"; import { arbitrum } from "viem/chains"; -import type { EboEvent, EboEventName } from "./types/events.js"; -import type { Dispute, Request, Response } from "./types/prophet.js"; -import { eboRequestCreatorAbi, epochManagerAbi, oracleAbi } from "./abis/index.js"; -import { RpcUrlsEmpty } from "./exceptions/rpcUrlsEmpty.exception.js"; +import type { EboEvent, EboEventName } from "../types/events.js"; +import type { Dispute, Request, Response } from "../types/prophet.js"; +import { eboRequestCreatorAbi, epochManagerAbi, oracleAbi } from "../abis/index.js"; +import { RpcUrlsEmpty } from "../exceptions/rpcUrlsEmpty.exception.js"; import { IProtocolProvider, IReadProvider, IWriteProvider, ProtocolContractsAddresses, -} from "./interfaces/index.js"; -import { ErrorFactory } from "./services/errorFactory.js"; +} from "../interfaces/index.js"; +import { ErrorFactory } from "../services/errorFactory.js"; // TODO: these constants should be env vars const TRANSACTION_RECEIPT_CONFIRMATIONS = 1; diff --git a/packages/automated-dispute/src/eboActor.ts b/packages/automated-dispute/src/services/eboActor.ts similarity index 98% rename from packages/automated-dispute/src/eboActor.ts rename to packages/automated-dispute/src/services/eboActor.ts index 4731385..8c3278a 100644 --- a/packages/automated-dispute/src/eboActor.ts +++ b/packages/automated-dispute/src/services/eboActor.ts @@ -5,8 +5,8 @@ import { Mutex } from "async-mutex"; import { Heap } from "heap-js"; import { ContractFunctionRevertedError } from "viem"; -import { DisputeWithoutResponse } from "./exceptions/eboActor/disputeWithoutResponse.exception.js"; import { + DisputeWithoutResponse, EBORequestCreator_ChainNotAdded, EBORequestCreator_InvalidEpoch, EBORequestModule_InvalidRequester, @@ -17,16 +17,16 @@ import { RequestMismatch, ResponseAlreadyProposed, UnknownEvent, -} from "./exceptions/index.js"; -import { EboRegistry, EboRegistryCommand } from "./interfaces/index.js"; -import { ProtocolProvider } from "./protocolProvider.js"; +} from "../exceptions/index.js"; +import { EboRegistry, EboRegistryCommand } from "../interfaces/index.js"; +import { ProtocolProvider } from "../providers/index.js"; import { AddDispute, AddRequest, AddResponse, FinalizeRequest, UpdateDisputeStatus, -} from "./services/index.js"; +} from "../services/index.js"; import { Dispute, DisputeStatus, @@ -36,7 +36,7 @@ import { RequestId, Response, ResponseBody, -} from "./types/index.js"; +} from "../types/index.js"; /** * Compare function to sort events chronologically in ascending order by block number diff --git a/packages/automated-dispute/src/eboActorsManager.ts b/packages/automated-dispute/src/services/eboActorsManager.ts similarity index 90% rename from packages/automated-dispute/src/eboActorsManager.ts rename to packages/automated-dispute/src/services/eboActorsManager.ts index 95361ba..4643343 100644 --- a/packages/automated-dispute/src/eboActorsManager.ts +++ b/packages/automated-dispute/src/services/eboActorsManager.ts @@ -2,11 +2,11 @@ import { BlockNumberService } from "@ebo-agent/blocknumber"; import { Address, ILogger } from "@ebo-agent/shared"; import { Mutex } from "async-mutex"; +import { RequestAlreadyHandled } from "../exceptions/index.js"; +import { ProtocolProvider } from "../providers/protocolProvider.js"; +import { RequestId } from "../types/prophet.js"; import { EboActor } from "./eboActor.js"; -import { RequestAlreadyHandled } from "./exceptions/index.js"; -import { ProtocolProvider } from "./protocolProvider.js"; -import { EboMemoryRegistry } from "./services/eboRegistry/eboMemoryRegistry.js"; -import { RequestId } from "./types/prophet.js"; +import { EboMemoryRegistry } from "./eboRegistry/eboMemoryRegistry.js"; export class EboActorsManager { private readonly requestActorMap: Map; diff --git a/packages/automated-dispute/src/services/eboProcessor.ts b/packages/automated-dispute/src/services/eboProcessor.ts index f192f68..ce18690 100644 --- a/packages/automated-dispute/src/services/eboProcessor.ts +++ b/packages/automated-dispute/src/services/eboProcessor.ts @@ -2,12 +2,12 @@ import { isNativeError } from "util/types"; import { BlockNumberService } from "@ebo-agent/blocknumber"; import { Address, ILogger } from "@ebo-agent/shared"; -import { EboActorsManager } from "../eboActorsManager.js"; import { ProcessorAlreadyStarted } from "../exceptions/index.js"; -import { ProtocolProvider } from "../protocolProvider.js"; +import { ProtocolProvider } from "../providers/protocolProvider.js"; import { alreadyDeletedActorWarning, droppingUnhandledEventsWarning } from "../templates/index.js"; import { EboEvent, EboEventName } from "../types/events.js"; import { RequestId } from "../types/prophet.js"; +import { EboActorsManager } from "./eboActorsManager.js"; const DEFAULT_MS_BETWEEN_CHECKS = 10 * 60 * 1000; // 10 minutes diff --git a/packages/automated-dispute/src/services/index.ts b/packages/automated-dispute/src/services/index.ts index e0aa884..d6885f4 100644 --- a/packages/automated-dispute/src/services/index.ts +++ b/packages/automated-dispute/src/services/index.ts @@ -1,3 +1,5 @@ -export * from "../eboActor.js"; +export * from "./eboActor.js"; +export * from "./eboActorsManager.js"; export * from "./eboProcessor.js"; export * from "./eboRegistry/index.js"; +export * from "./errorFactory.js"; diff --git a/packages/automated-dispute/tests/mocks/eboActor.mocks.ts b/packages/automated-dispute/tests/mocks/eboActor.mocks.ts index 4238c06..a2f698f 100644 --- a/packages/automated-dispute/tests/mocks/eboActor.mocks.ts +++ b/packages/automated-dispute/tests/mocks/eboActor.mocks.ts @@ -3,11 +3,13 @@ import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types"; import { ILogger } from "@ebo-agent/shared"; import { Mutex } from "async-mutex"; -import { EboActor } from "../../src/eboActor.js"; -import { ProtocolProvider } from "../../src/protocolProvider.js"; -import { EboMemoryRegistry } from "../../src/services/index.js"; +import { ProtocolProvider } from "../../src/providers/index.js"; +import { EboActor, EboMemoryRegistry } from "../../src/services/index.js"; import { Dispute, Request, Response } from "../../src/types/index.js"; -import { DEFAULT_MOCKED_PROTOCOL_CONTRACTS, mockedPrivateKey } from "../eboActor/fixtures.js"; +import { + DEFAULT_MOCKED_PROTOCOL_CONTRACTS, + mockedPrivateKey, +} from "../services/eboActor/fixtures.js"; /** * Builds a base `EboActor` scaffolded with all its dependencies. diff --git a/packages/automated-dispute/tests/mocks/eboProcessor.mocks.ts b/packages/automated-dispute/tests/mocks/eboProcessor.mocks.ts index 277c26e..1bca810 100644 --- a/packages/automated-dispute/tests/mocks/eboProcessor.mocks.ts +++ b/packages/automated-dispute/tests/mocks/eboProcessor.mocks.ts @@ -2,10 +2,13 @@ import { BlockNumberService } from "@ebo-agent/blocknumber"; import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types"; import { ILogger } from "@ebo-agent/shared"; -import { EboActorsManager } from "../../src/eboActorsManager"; -import { ProtocolProvider } from "../../src/protocolProvider"; +import { ProtocolProvider } from "../../src/providers/index.js"; import { EboProcessor } from "../../src/services"; -import { DEFAULT_MOCKED_PROTOCOL_CONTRACTS, mockedPrivateKey } from "../eboActor/fixtures"; +import { EboActorsManager } from "../../src/services/index.js"; +import { + DEFAULT_MOCKED_PROTOCOL_CONTRACTS, + mockedPrivateKey, +} from "../services/eboActor/fixtures.js"; export function buildEboProcessor(logger: ILogger) { const protocolProviderRpcUrls = ["http://localhost:8538"]; diff --git a/packages/automated-dispute/tests/services/eboActor.spec.ts b/packages/automated-dispute/tests/services/eboActor.spec.ts index a416ef9..ec4af4e 100644 --- a/packages/automated-dispute/tests/services/eboActor.spec.ts +++ b/packages/automated-dispute/tests/services/eboActor.spec.ts @@ -2,8 +2,8 @@ import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { PastEventEnqueueError, RequestMismatch } from "../../src/exceptions/index.js"; import { EboEvent, Request, RequestId } from "../../src/types/index.js"; -import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../eboActor/fixtures.js"; import mocks from "../mocks/index.js"; +import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../services/eboActor/fixtures.js"; const logger = mocks.mockLogger(); diff --git a/packages/automated-dispute/tests/eboActor/fixtures.ts b/packages/automated-dispute/tests/services/eboActor/fixtures.ts similarity index 95% rename from packages/automated-dispute/tests/eboActor/fixtures.ts rename to packages/automated-dispute/tests/services/eboActor/fixtures.ts index e7c7ab7..a030792 100644 --- a/packages/automated-dispute/tests/eboActor/fixtures.ts +++ b/packages/automated-dispute/tests/services/eboActor/fixtures.ts @@ -1,6 +1,6 @@ import { Address } from "viem"; -import { Request, RequestId } from "../../src/types/prophet"; +import { Request, RequestId } from "../../../src/types/index.js"; export const mockedPrivateKey = "0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80"; diff --git a/packages/automated-dispute/tests/eboActor/onDisputeStatusChanged.spec.ts b/packages/automated-dispute/tests/services/eboActor/onDisputeStatusChanged.spec.ts similarity index 97% rename from packages/automated-dispute/tests/eboActor/onDisputeStatusChanged.spec.ts rename to packages/automated-dispute/tests/services/eboActor/onDisputeStatusChanged.spec.ts index 3849fef..4f80c77 100644 --- a/packages/automated-dispute/tests/eboActor/onDisputeStatusChanged.spec.ts +++ b/packages/automated-dispute/tests/services/eboActor/onDisputeStatusChanged.spec.ts @@ -1,8 +1,8 @@ import { ILogger } from "@ebo-agent/shared"; import { describe, expect, it, vi } from "vitest"; -import { EboEvent } from "../../src/types/events"; -import mocks from "../mocks/index.ts"; +import { EboEvent } from "../../../src/types/index.js"; +import mocks from "../../mocks/index.ts"; import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "./fixtures.ts"; const logger: ILogger = { diff --git a/packages/automated-dispute/tests/eboActor/onLastBlockupdated.spec.ts b/packages/automated-dispute/tests/services/eboActor/onLastBlockupdated.spec.ts similarity index 98% rename from packages/automated-dispute/tests/eboActor/onLastBlockupdated.spec.ts rename to packages/automated-dispute/tests/services/eboActor/onLastBlockupdated.spec.ts index 40f3588..d4f1ccf 100644 --- a/packages/automated-dispute/tests/eboActor/onLastBlockupdated.spec.ts +++ b/packages/automated-dispute/tests/services/eboActor/onLastBlockupdated.spec.ts @@ -1,8 +1,8 @@ import { ContractFunctionRevertedError } from "viem"; import { describe, expect, it, vi } from "vitest"; -import { DisputeWithoutResponse } from "../../src/exceptions/eboActor/disputeWithoutResponse.exception"; -import mocks from "../mocks"; +import { DisputeWithoutResponse } from "../../../src/exceptions/index.js"; +import mocks from "../../mocks"; import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "./fixtures"; const logger = mocks.mockLogger(); diff --git a/packages/automated-dispute/tests/eboActor/onRequestCreated.spec.ts b/packages/automated-dispute/tests/services/eboActor/onRequestCreated.spec.ts similarity index 98% rename from packages/automated-dispute/tests/eboActor/onRequestCreated.spec.ts rename to packages/automated-dispute/tests/services/eboActor/onRequestCreated.spec.ts index bb31d50..efcadd9 100644 --- a/packages/automated-dispute/tests/eboActor/onRequestCreated.spec.ts +++ b/packages/automated-dispute/tests/services/eboActor/onRequestCreated.spec.ts @@ -3,8 +3,8 @@ import { ILogger } from "@ebo-agent/shared"; import { Address } from "viem"; import { describe, expect, it, vi } from "vitest"; -import { EboEvent, Response } from "../../src/types/index.js"; -import mocks from "../mocks/index.js"; +import { EboEvent, Response } from "../../../src/types/index.js"; +import mocks from "../../mocks/index.js"; import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "./fixtures.js"; const logger: ILogger = mocks.mockLogger(); diff --git a/packages/automated-dispute/tests/eboActor/onRequestFinalized.spec.ts b/packages/automated-dispute/tests/services/eboActor/onRequestFinalized.spec.ts similarity index 93% rename from packages/automated-dispute/tests/eboActor/onRequestFinalized.spec.ts rename to packages/automated-dispute/tests/services/eboActor/onRequestFinalized.spec.ts index 68c7d5a..16f8551 100644 --- a/packages/automated-dispute/tests/eboActor/onRequestFinalized.spec.ts +++ b/packages/automated-dispute/tests/services/eboActor/onRequestFinalized.spec.ts @@ -1,9 +1,9 @@ import { ILogger } from "@ebo-agent/shared"; import { describe, expect, it, vi } from "vitest"; -import { FinalizeRequest } from "../../src/services/index.js"; -import { EboEvent } from "../../src/types/index.js"; -import mocks from "../mocks/index.js"; +import { FinalizeRequest } from "../../../src/services/index.js"; +import { EboEvent } from "../../../src/types/index.js"; +import mocks from "../../mocks/index.js"; import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "./fixtures.js"; const logger: ILogger = mocks.mockLogger(); diff --git a/packages/automated-dispute/tests/eboActor/onResponseDisputed.spec.ts b/packages/automated-dispute/tests/services/eboActor/onResponseDisputed.spec.ts similarity index 96% rename from packages/automated-dispute/tests/eboActor/onResponseDisputed.spec.ts rename to packages/automated-dispute/tests/services/eboActor/onResponseDisputed.spec.ts index c3eba6d..df408ed 100644 --- a/packages/automated-dispute/tests/eboActor/onResponseDisputed.spec.ts +++ b/packages/automated-dispute/tests/services/eboActor/onResponseDisputed.spec.ts @@ -1,9 +1,9 @@ import { ILogger } from "@ebo-agent/shared"; import { describe, expect, it, vi } from "vitest"; -import { EboEvent } from "../../src/types/events.js"; -import { Response } from "../../src/types/prophet.js"; -import mocks from "../mocks/index.js"; +import { EboEvent } from "../../../src/types/events.js"; +import { Response } from "../../../src/types/prophet.js"; +import mocks from "../../mocks/index.js"; import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "./fixtures.js"; const logger: ILogger = mocks.mockLogger(); diff --git a/packages/automated-dispute/tests/eboActor/onResponseProposed.spec.ts b/packages/automated-dispute/tests/services/eboActor/onResponseProposed.spec.ts similarity index 97% rename from packages/automated-dispute/tests/eboActor/onResponseProposed.spec.ts rename to packages/automated-dispute/tests/services/eboActor/onResponseProposed.spec.ts index 11da0da..ce2b687 100644 --- a/packages/automated-dispute/tests/eboActor/onResponseProposed.spec.ts +++ b/packages/automated-dispute/tests/services/eboActor/onResponseProposed.spec.ts @@ -1,9 +1,9 @@ import { ILogger } from "@ebo-agent/shared"; import { describe, expect, it, vi } from "vitest"; -import { EboEvent } from "../../src/types/events"; -import mocks from "../mocks/index.ts"; -import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "./fixtures.ts"; +import { EboEvent } from "../../../src/types/index.js"; +import mocks from "../../mocks/index.js"; +import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "./fixtures.js"; const logger: ILogger = mocks.mockLogger(); diff --git a/packages/automated-dispute/tests/eboActorsManager.spec.ts b/packages/automated-dispute/tests/services/eboActorsManager.spec.ts similarity index 94% rename from packages/automated-dispute/tests/eboActorsManager.spec.ts rename to packages/automated-dispute/tests/services/eboActorsManager.spec.ts index 55b9265..8b94a7a 100644 --- a/packages/automated-dispute/tests/eboActorsManager.spec.ts +++ b/packages/automated-dispute/tests/services/eboActorsManager.spec.ts @@ -4,15 +4,15 @@ import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js"; import { ILogger } from "@ebo-agent/shared"; import { describe, expect, it } from "vitest"; -import { EboActorsManager } from "../src/eboActorsManager.js"; -import { RequestAlreadyHandled } from "../src/exceptions/index.js"; -import { ProtocolProvider } from "../src/protocolProvider.js"; +import { RequestAlreadyHandled } from "../../src/exceptions/index.js"; +import { ProtocolProvider } from "../../src/providers/index.js"; +import { EboActorsManager } from "../../src/services/index.js"; +import mocks from "../mocks/index.js"; import { DEFAULT_MOCKED_PROTOCOL_CONTRACTS, DEFAULT_MOCKED_REQUEST_CREATED_DATA, mockedPrivateKey, } from "./eboActor/fixtures.js"; -import mocks from "./mocks/index.js"; const logger: ILogger = mocks.mockLogger(); diff --git a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addDispute.spec.ts b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addDispute.spec.ts index 8789a6d..094e5e7 100644 --- a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addDispute.spec.ts +++ b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addDispute.spec.ts @@ -4,8 +4,8 @@ import { CommandAlreadyRun, CommandNotRun } from "../../../../src/exceptions/ind import { EboRegistry } from "../../../../src/interfaces/index.js"; import { AddDispute } from "../../../../src/services/index.js"; import { EboEvent } from "../../../../src/types/index.js"; -import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../eboActor/fixtures.js"; import mocks from "../../../mocks/index.js"; +import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../services/eboActor/fixtures.js"; describe("AddDispute", () => { let registry: EboRegistry; diff --git a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addRequest.spec.ts b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addRequest.spec.ts index f85f64b..c07c75b 100644 --- a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addRequest.spec.ts +++ b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addRequest.spec.ts @@ -4,7 +4,7 @@ import { CommandAlreadyRun, CommandNotRun } from "../../../../src/exceptions/ind import { EboRegistry } from "../../../../src/interfaces/index.js"; import { AddRequest } from "../../../../src/services/index.js"; import { EboEvent } from "../../../../src/types/index.js"; -import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../eboActor/fixtures.js"; +import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../services/eboActor/fixtures.js"; describe("AddRequest", () => { let registry: EboRegistry; diff --git a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addResponse.spec.ts b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addResponse.spec.ts index 2ba2f21..60d703f 100644 --- a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addResponse.spec.ts +++ b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/addResponse.spec.ts @@ -4,8 +4,8 @@ import { CommandAlreadyRun, CommandNotRun } from "../../../../src/exceptions/ind import { EboRegistry } from "../../../../src/interfaces/index.js"; import { AddResponse } from "../../../../src/services/index.js"; import { EboEvent } from "../../../../src/types/index.js"; -import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../eboActor/fixtures.js"; import mocks from "../../../mocks/index.js"; +import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../services/eboActor/fixtures.js"; describe("AddResponse", () => { let registry: EboRegistry; diff --git a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/finalizeRequest.spec.ts b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/finalizeRequest.spec.ts index b381b43..1072643 100644 --- a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/finalizeRequest.spec.ts +++ b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/finalizeRequest.spec.ts @@ -4,8 +4,8 @@ import { CommandAlreadyRun, CommandNotRun } from "../../../../src/exceptions/ind import { EboRegistry } from "../../../../src/interfaces/index.js"; import { FinalizeRequest } from "../../../../src/services/index.js"; import { EboEvent } from "../../../../src/types/index.js"; -import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../eboActor/fixtures.js"; import mocks from "../../../mocks/index.js"; +import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../services/eboActor/fixtures.js"; describe("FinalizeRequest", () => { let registry: EboRegistry; diff --git a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/updateDisputeStatus.spec.ts b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/updateDisputeStatus.spec.ts index 6f86c60..634d5e9 100644 --- a/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/updateDisputeStatus.spec.ts +++ b/packages/automated-dispute/tests/services/eboMemoryRegistry/commands/updateDisputeStatus.spec.ts @@ -4,8 +4,8 @@ import { CommandAlreadyRun, CommandNotRun } from "../../../../src/exceptions/ind import { EboRegistry } from "../../../../src/interfaces/index.js"; import { UpdateDisputeStatus } from "../../../../src/services/index.js"; import { EboEvent } from "../../../../src/types/index.js"; -import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../eboActor/fixtures.js"; import mocks from "../../../mocks/index.js"; +import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../../../services/eboActor/fixtures.js"; describe("UpdateDisputeStatus", () => { let registry: EboRegistry; diff --git a/packages/automated-dispute/tests/services/eboProcessor.spec.ts b/packages/automated-dispute/tests/services/eboProcessor.spec.ts index e4a5f0b..97a9f35 100644 --- a/packages/automated-dispute/tests/services/eboProcessor.spec.ts +++ b/packages/automated-dispute/tests/services/eboProcessor.spec.ts @@ -3,10 +3,10 @@ import { Caip2ChainId } from "@ebo-agent/blocknumber/dist/types.js"; import { afterEach, beforeEach, describe, expect, it, vi } from "vitest"; import { ProcessorAlreadyStarted } from "../../src/exceptions/index.js"; -import { ProtocolProvider } from "../../src/protocolProvider.js"; +import { ProtocolProvider } from "../../src/providers/index.js"; import { EboEvent, EboEventName, RequestId } from "../../src/types/index.js"; -import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../eboActor/fixtures.js"; import mocks from "../mocks/index.js"; +import { DEFAULT_MOCKED_REQUEST_CREATED_DATA } from "../services/eboActor/fixtures.js"; const logger = mocks.mockLogger(); const msBetweenChecks = 1; diff --git a/packages/automated-dispute/tests/errorFactory.spec.ts b/packages/automated-dispute/tests/services/errorFactory.spec.ts similarity index 73% rename from packages/automated-dispute/tests/errorFactory.spec.ts rename to packages/automated-dispute/tests/services/errorFactory.spec.ts index b82bbe7..d0a09a4 100644 --- a/packages/automated-dispute/tests/errorFactory.spec.ts +++ b/packages/automated-dispute/tests/services/errorFactory.spec.ts @@ -1,10 +1,12 @@ import { describe, expect, it } from "vitest"; -import { EBORequestCreator_ChainNotAdded } from "../src/exceptions/chainNotAdded.exception.js"; -import { EBORequestCreator_InvalidEpoch } from "../src/exceptions/invalidEpoch.exception.js"; -import { Oracle_InvalidRequestBody } from "../src/exceptions/invalidRequestBody.exception.js"; -import { EBORequestModule_InvalidRequester } from "../src/exceptions/invalidRequester.exception.js"; -import { ErrorFactory } from "../src/services/errorFactory.js"; +import { + EBORequestCreator_ChainNotAdded, + EBORequestCreator_InvalidEpoch, + EBORequestModule_InvalidRequester, + Oracle_InvalidRequestBody, +} from "../../src/exceptions/index.js"; +import { ErrorFactory } from "../../src/services/index.js"; describe("ErrorFactory", () => { it("creates EBORequestCreator_InvalidEpoch error", () => { diff --git a/packages/automated-dispute/tests/protocolProvider.spec.ts b/packages/automated-dispute/tests/services/protocolProvider.spec.ts similarity index 96% rename from packages/automated-dispute/tests/protocolProvider.spec.ts rename to packages/automated-dispute/tests/services/protocolProvider.spec.ts index 083d794..9340621 100644 --- a/packages/automated-dispute/tests/protocolProvider.spec.ts +++ b/packages/automated-dispute/tests/services/protocolProvider.spec.ts @@ -2,12 +2,12 @@ import { createPublicClient, createWalletClient, fallback, getContract, http } f 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 { RpcUrlsEmpty } from "../src/exceptions/rpcUrlsEmpty.exception.js"; -import { ProtocolProvider } from "../src/index.js"; -import { ProtocolContractsAddresses } from "../src/types/index.js"; +import { eboRequestCreatorAbi } from "../../src/abis/eboRequestCreator.js"; +import { epochManagerAbi } from "../../src/abis/epochManager.js"; +import { oracleAbi } from "../../src/abis/oracle.js"; +import { RpcUrlsEmpty } from "../../src/exceptions/index.js"; +import { ProtocolProvider } from "../../src/providers/index.js"; +import { ProtocolContractsAddresses } from "../../src/types/index.js"; import { mockedPrivateKey } from "./eboActor/fixtures.js"; vi.mock("viem", async () => { From 588cda6c2bf2fa72863d1988ff075e7feb4939b7 Mon Sep 17 00:00:00 2001 From: Yaco 0x Date: Fri, 13 Sep 2024 08:59:38 -0300 Subject: [PATCH 2/8] feat: agent app base --- apps/agent/package.json | 24 +++++++++ apps/agent/src/index.ts | 65 +++++++++++++++++++++++++ apps/agent/tsconfig.build.json | 8 +++ apps/agent/tsconfig.json | 4 ++ apps/agent/vitest.config.ts | 22 +++++++++ packages/automated-dispute/package.json | 2 +- pnpm-lock.yaml | 2 + pnpm-workspace.yaml | 1 + 8 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 apps/agent/package.json create mode 100644 apps/agent/src/index.ts create mode 100644 apps/agent/tsconfig.build.json create mode 100644 apps/agent/tsconfig.json create mode 100644 apps/agent/vitest.config.ts diff --git a/apps/agent/package.json b/apps/agent/package.json new file mode 100644 index 0000000..52ea226 --- /dev/null +++ b/apps/agent/package.json @@ -0,0 +1,24 @@ +{ + "name": "agent", + "version": "1.0.0", + "description": "", + "main": "dist/index.js", + "type": "module", + "scripts": { + "build": "tsc -p tsconfig.build.json", + "check-types": "tsc --noEmit -p ./tsconfig.json", + "clean": "rm -rf dist", + "format": "prettier --check \"{src,test}/**/*.{js,ts,json}\"", + "format:fix": "prettier --write \"{src,test}/**/*.{js,ts,json}\"", + "lint": "eslint \"{src,test}/**/*.{js,ts,json}\"", + "lint:fix": "pnpm lint --fix", + "start": "node dist/index.js", + "test": "vitest run --config vitest.config.ts --passWithNoTests", + "test:cov": "vitest run --config vitest.config.ts --coverage" + }, + "dependencies": { + "@ebo-agent/automated-dispute": "workspace:*", + "@ebo-agent/blocknumber": "workspace:*", + "@ebo-agent/shared": "workspace:*" + } +} diff --git a/apps/agent/src/index.ts b/apps/agent/src/index.ts new file mode 100644 index 0000000..7675b45 --- /dev/null +++ b/apps/agent/src/index.ts @@ -0,0 +1,65 @@ +import { inspect } from "util"; +import { EboActorsManager, EboProcessor } from "@ebo-agent/automated-dispute"; +import { ProtocolProvider } from "@ebo-agent/automated-dispute/dist/providers/protocolProvider.js"; +import { BlockNumberService } from "@ebo-agent/blocknumber"; +import { Logger } from "@ebo-agent/shared"; + +// TODO: use env vars and validate config schema +const config = { + protocolProvider: { + rpcUrls: ["localhost"], + contracts: { + oracle: "0x00", + epochManager: "0x00", + eboRequestCreator: "0x00", + } as const, + privateKey: "0xsecret" as const, + }, + blockNumberService: { + chainRpcUrls: new Map([["eip155:1" as const, ["localhost"]]]), + }, + processor: { + msBetweenChecks: 1, + }, +}; + +const logger = Logger.getInstance(); + +const main = async (): Promise => { + const protocolProvider = new ProtocolProvider( + config.protocolProvider.rpcUrls, + config.protocolProvider.contracts, + config.protocolProvider.privateKey, + ); + + const blockNumberService = new BlockNumberService( + config.blockNumberService.chainRpcUrls, + logger, + ); + + const actorsManager = new EboActorsManager(); + + const processor = new EboProcessor(protocolProvider, blockNumberService, actorsManager, logger); + + await processor.start(config.processor.msBetweenChecks); +}; + +process.on("unhandledRejection", (reason, p) => { + console.error(`Unhandled Rejection at: \n${inspect(p, undefined, 100)}, \nreason: ${reason}`); + + process.exit(1); +}); + +process.on("uncaughtException", (error: Error) => { + console.error( + `An uncaught exception occurred: ${error}\n` + `Exception origin: ${error.stack}`, + ); + + process.exit(1); +}); + +main().catch((err) => { + logger.error(`Error in main handler: ${err}`); + + process.exit(1); +}); diff --git a/apps/agent/tsconfig.build.json b/apps/agent/tsconfig.build.json new file mode 100644 index 0000000..da6827f --- /dev/null +++ b/apps/agent/tsconfig.build.json @@ -0,0 +1,8 @@ +{ + "extends": "../../tsconfig.build.json", + "compilerOptions": { + "outDir": "dist" + }, + "include": ["src/**/*"], + "exclude": ["node_modules", "dist", "tests"] +} diff --git a/apps/agent/tsconfig.json b/apps/agent/tsconfig.json new file mode 100644 index 0000000..66bb87a --- /dev/null +++ b/apps/agent/tsconfig.json @@ -0,0 +1,4 @@ +{ + "extends": "../../tsconfig.json", + "include": ["src/**/*"] +} diff --git a/apps/agent/vitest.config.ts b/apps/agent/vitest.config.ts new file mode 100644 index 0000000..8e1bbf4 --- /dev/null +++ b/apps/agent/vitest.config.ts @@ -0,0 +1,22 @@ +import path from "path"; +import { configDefaults, defineConfig } from "vitest/config"; + +export default defineConfig({ + test: { + globals: true, // Use Vitest's global API without importing it in each file + environment: "node", // Use the Node.js environment + include: ["test/**/*.spec.ts"], // Include test files + exclude: ["node_modules", "dist"], // Exclude certain directories + coverage: { + provider: "v8", + reporter: ["text", "json", "html"], // Coverage reporters + exclude: ["node_modules", "dist", "src/index.ts", ...configDefaults.exclude], // Files to exclude from coverage + }, + }, + resolve: { + alias: { + // Setup path alias based on tsconfig paths + "@": path.resolve(__dirname, "src"), + }, + }, +}); diff --git a/packages/automated-dispute/package.json b/packages/automated-dispute/package.json index 1a50a4b..9b40fee 100644 --- a/packages/automated-dispute/package.json +++ b/packages/automated-dispute/package.json @@ -2,7 +2,7 @@ "name": "@ebo-agent/automated-dispute", "version": "1.0.0", "description": "", - "main": "index.ts", + "main": "./dist/index.js", "type": "module", "scripts": { "build": "tsc -p tsconfig.build.json", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index c07e656..21ef91f 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,6 +69,8 @@ importers: specifier: 2.0.3 version: 2.0.3(@types/node@20.14.12) + apps/agent: {} + packages/automated-dispute: dependencies: "@ebo-agent/blocknumber": diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index c2c15ad..5327d00 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,2 +1,3 @@ packages: + - "apps/**" - "packages/**" From 42bda7992f2578986cff839cb57e42f5ecc3f438 Mon Sep 17 00:00:00 2001 From: Yaco 0x Date: Fri, 13 Sep 2024 12:12:47 -0300 Subject: [PATCH 3/8] fix: swap console with logger --- apps/agent/src/index.ts | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/apps/agent/src/index.ts b/apps/agent/src/index.ts index 7675b45..fbcdf31 100644 --- a/apps/agent/src/index.ts +++ b/apps/agent/src/index.ts @@ -45,15 +45,13 @@ const main = async (): Promise => { }; process.on("unhandledRejection", (reason, p) => { - console.error(`Unhandled Rejection at: \n${inspect(p, undefined, 100)}, \nreason: ${reason}`); + logger.error(`Unhandled Rejection at: \n${inspect(p, undefined, 100)}, \nreason: ${reason}`); process.exit(1); }); process.on("uncaughtException", (error: Error) => { - console.error( - `An uncaught exception occurred: ${error}\n` + `Exception origin: ${error.stack}`, - ); + logger.error(`An uncaught exception occurred: ${error}\n` + `Exception origin: ${error.stack}`); process.exit(1); }); From 552b0da3028057ae9d92b90810c6ea8e0c829a00 Mon Sep 17 00:00:00 2001 From: Yaco 0x Date: Fri, 13 Sep 2024 12:13:10 -0300 Subject: [PATCH 4/8] fix: include blockmeta config on agent start --- apps/agent/src/index.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/agent/src/index.ts b/apps/agent/src/index.ts index fbcdf31..d5b9778 100644 --- a/apps/agent/src/index.ts +++ b/apps/agent/src/index.ts @@ -17,6 +17,15 @@ const config = { }, blockNumberService: { chainRpcUrls: new Map([["eip155:1" as const, ["localhost"]]]), + blockmetaConfig: { + baseUrl: new URL("localhost:443"), + servicePaths: { + blockByTime: "/sf.blockmeta.v2.BlockByTime", + block: "/sf.blockmeta.v2.Block", + }, + bearerToken: "secret-token", + bearerTokenExpirationWindow: 365 * 24 * 60 * 60 * 1000, // 1 year + }, }, processor: { msBetweenChecks: 1, @@ -34,6 +43,7 @@ const main = async (): Promise => { const blockNumberService = new BlockNumberService( config.blockNumberService.chainRpcUrls, + config.blockNumberService.blockmetaConfig, logger, ); From 9e7e342bf516fa54104a4e6e84ed950b39210156 Mon Sep 17 00:00:00 2001 From: Yaco 0x Date: Fri, 13 Sep 2024 12:18:54 -0300 Subject: [PATCH 5/8] chore: private package configuration --- apps/agent/package.json | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/agent/package.json b/apps/agent/package.json index 52ea226..c2811e0 100644 --- a/apps/agent/package.json +++ b/apps/agent/package.json @@ -4,6 +4,7 @@ "description": "", "main": "dist/index.js", "type": "module", + "private": "true", "scripts": { "build": "tsc -p tsconfig.build.json", "check-types": "tsc --noEmit -p ./tsconfig.json", From aa030135415a261b0a966673fb3ba5d5ded3a293 Mon Sep 17 00:00:00 2001 From: Yaco 0x Date: Fri, 13 Sep 2024 12:23:22 -0300 Subject: [PATCH 6/8] chore: update private packages everywhere --- packages/automated-dispute/package.json | 2 +- packages/blocknumber/package.json | 2 +- packages/shared/package.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/automated-dispute/package.json b/packages/automated-dispute/package.json index 9b40fee..e28a5c1 100644 --- a/packages/automated-dispute/package.json +++ b/packages/automated-dispute/package.json @@ -4,6 +4,7 @@ "description": "", "main": "./dist/index.js", "type": "module", + "private": "true", "scripts": { "build": "tsc -p tsconfig.build.json", "lint": "eslint .", @@ -15,7 +16,6 @@ }, "keywords": [], "author": "", - "license": "ISC", "dependencies": { "@ebo-agent/blocknumber": "workspace:*", "@ebo-agent/shared": "workspace:*", diff --git a/packages/blocknumber/package.json b/packages/blocknumber/package.json index c7ded21..43e2393 100644 --- a/packages/blocknumber/package.json +++ b/packages/blocknumber/package.json @@ -4,6 +4,7 @@ "description": "", "main": "./dist/index.js", "type": "module", + "private": "true", "scripts": { "build": "tsc -p tsconfig.build.json", "lint": "eslint .", @@ -15,7 +16,6 @@ }, "keywords": [], "author": "", - "license": "ISC", "dependencies": { "@ebo-agent/shared": "workspace:*", "axios": "1.7.7", diff --git a/packages/shared/package.json b/packages/shared/package.json index a2616ff..688e4c9 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -4,6 +4,7 @@ "description": "", "main": "./dist/index.js", "type": "module", + "private": "true", "scripts": { "build": "tsc -p tsconfig.build.json", "lint": "eslint .", @@ -15,7 +16,6 @@ }, "keywords": [], "author": "", - "license": "ISC", "dependencies": { "winston": "3.13.1" } From e3ade3112bae5e2eccbd0d68c53f15a50334c03f Mon Sep 17 00:00:00 2001 From: Yaco 0x Date: Fri, 13 Sep 2024 12:23:45 -0300 Subject: [PATCH 7/8] chore: update pnpm-lock.yaml with agent deps --- pnpm-lock.yaml | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 9bb9bf7..503e2aa 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,7 +69,17 @@ importers: specifier: 2.0.3 version: 2.0.3(@types/node@20.14.12) - apps/agent: {} + apps/agent: + dependencies: + "@ebo-agent/automated-dispute": + specifier: workspace:* + version: link:../../packages/automated-dispute + "@ebo-agent/blocknumber": + specifier: workspace:* + version: link:../../packages/blocknumber + "@ebo-agent/shared": + specifier: workspace:* + version: link:../../packages/shared packages/automated-dispute: dependencies: From 7c8979a2e85a15310e981b5c876db9fc1b2ae126 Mon Sep 17 00:00:00 2001 From: Yaco 0x Date: Fri, 13 Sep 2024 13:20:07 -0300 Subject: [PATCH 8/8] chore: add types declaration to package.json in packages --- packages/automated-dispute/package.json | 6 ++++++ packages/blocknumber/package.json | 6 ++++++ packages/shared/package.json | 6 ++++++ 3 files changed, 18 insertions(+) diff --git a/packages/automated-dispute/package.json b/packages/automated-dispute/package.json index e28a5c1..b933d7d 100644 --- a/packages/automated-dispute/package.json +++ b/packages/automated-dispute/package.json @@ -4,6 +4,12 @@ "description": "", "main": "./dist/index.js", "type": "module", + "types": "./dist/index.d.ts", + "files": [ + "dist/*", + "package.json", + "!**/*.tsbuildinfo" + ], "private": "true", "scripts": { "build": "tsc -p tsconfig.build.json", diff --git a/packages/blocknumber/package.json b/packages/blocknumber/package.json index 43e2393..baee2f5 100644 --- a/packages/blocknumber/package.json +++ b/packages/blocknumber/package.json @@ -4,6 +4,12 @@ "description": "", "main": "./dist/index.js", "type": "module", + "types": "./dist/index.d.ts", + "files": [ + "dist/*", + "package.json", + "!**/*.tsbuildinfo" + ], "private": "true", "scripts": { "build": "tsc -p tsconfig.build.json", diff --git a/packages/shared/package.json b/packages/shared/package.json index 688e4c9..98192d1 100644 --- a/packages/shared/package.json +++ b/packages/shared/package.json @@ -4,6 +4,12 @@ "description": "", "main": "./dist/index.js", "type": "module", + "types": "./dist/index.d.ts", + "files": [ + "dist/*", + "package.json", + "!**/*.tsbuildinfo" + ], "private": "true", "scripts": { "build": "tsc -p tsconfig.build.json",