Skip to content

Commit

Permalink
refactor: clean up imports and folder structure (#40)
Browse files Browse the repository at this point in the history
# 🤖 Linear

Part of GRT-167

## Description
Clean up imports and reorganize old folder structure
  • Loading branch information
0xyaco authored Sep 13, 2024
1 parent 3d7c923 commit 5a21a26
Show file tree
Hide file tree
Showing 27 changed files with 77 additions and 66 deletions.
1 change: 1 addition & 0 deletions packages/automated-dispute/src/external.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { EboProcessor, EboActorsManager } from "./services/index.js";
2 changes: 1 addition & 1 deletion packages/automated-dispute/src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from "./protocolProvider.js";
export * from "./external.js";
1 change: 1 addition & 0 deletions packages/automated-dispute/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from "./protocolProvider.js";
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<RequestId, EboActor>;
Expand Down
4 changes: 2 additions & 2 deletions packages/automated-dispute/src/services/eboProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion packages/automated-dispute/src/services/index.ts
Original file line number Diff line number Diff line change
@@ -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";
10 changes: 6 additions & 4 deletions packages/automated-dispute/tests/mocks/eboActor.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions packages/automated-dispute/tests/mocks/eboProcessor.mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"];
Expand Down
2 changes: 1 addition & 1 deletion packages/automated-dispute/tests/services/eboActor.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down

0 comments on commit 5a21a26

Please sign in to comment.