Skip to content

Commit

Permalink
fix: complete merge
Browse files Browse the repository at this point in the history
  • Loading branch information
jahabeebs committed Sep 13, 2024
2 parents e8976ca + 2d1de10 commit 27e95e8
Show file tree
Hide file tree
Showing 47 changed files with 1,294 additions and 598 deletions.
25 changes: 25 additions & 0 deletions apps/agent/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "agent",
"version": "1.0.0",
"description": "",
"main": "dist/index.js",
"type": "module",
"private": "true",
"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:*"
}
}
73 changes: 73 additions & 0 deletions apps/agent/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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"]]]),
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,
},
};

const logger = Logger.getInstance();

const main = async (): Promise<void> => {
const protocolProvider = new ProtocolProvider(
config.protocolProvider.rpcUrls,
config.protocolProvider.contracts,
config.protocolProvider.privateKey,
);

const blockNumberService = new BlockNumberService(
config.blockNumberService.chainRpcUrls,
config.blockNumberService.blockmetaConfig,
logger,
);

const actorsManager = new EboActorsManager();

const processor = new EboProcessor(protocolProvider, blockNumberService, actorsManager, logger);

await processor.start(config.processor.msBetweenChecks);
};

process.on("unhandledRejection", (reason, p) => {
logger.error(`Unhandled Rejection at: \n${inspect(p, undefined, 100)}, \nreason: ${reason}`);

process.exit(1);
});

process.on("uncaughtException", (error: Error) => {
logger.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);
});
8 changes: 8 additions & 0 deletions apps/agent/tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.build.json",
"compilerOptions": {
"outDir": "dist"
},
"include": ["src/**/*"],
"exclude": ["node_modules", "dist", "tests"]
}
4 changes: 4 additions & 0 deletions apps/agent/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["src/**/*"]
}
22 changes: 22 additions & 0 deletions apps/agent/vitest.config.ts
Original file line number Diff line number Diff line change
@@ -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"),
},
},
});
10 changes: 8 additions & 2 deletions packages/automated-dispute/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@
"name": "@ebo-agent/automated-dispute",
"version": "1.0.0",
"description": "",
"main": "index.ts",
"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",
"lint": "eslint .",
Expand All @@ -15,7 +22,6 @@
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"@ebo-agent/blocknumber": "workspace:*",
"@ebo-agent/shared": "workspace:*",
Expand Down
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";
Loading

0 comments on commit 27e95e8

Please sign in to comment.