Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: base for agent app #41

Merged
merged 9 commits into from
Sep 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions apps/agent/package.json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you need a dev script for running it with hot reload? tsx is the one we used in chainhub

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I'll see how the development goes with this particular app. We'll probably end up needing it during some debugging sessions and such.

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "agent",
"version": "1.0.0",
"description": "",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

some other things we could add here would be license: MIT and private: true (though we should add these on our other packages as well to avoid accidental publishing)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the private property, need to ask for The Graph team about licensing.

"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",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"private": "true",
"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
8 changes: 7 additions & 1 deletion packages/blocknumber/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"description": "",
"main": "./dist/index.js",
"type": "module",
"types": "./dist/index.d.ts",
"files": [
"dist/*",
"package.json",
"!**/*.tsbuildinfo"
],
"private": "true",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"private": "true",
"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/shared": "workspace:*",
"axios": "1.7.7",
Expand Down
8 changes: 7 additions & 1 deletion packages/shared/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
"description": "",
"main": "./dist/index.js",
"type": "module",
"types": "./dist/index.d.ts",
"files": [
"dist/*",
"package.json",
"!**/*.tsbuildinfo"
],
"private": "true",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"private": "true",
"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": {
"winston": "3.13.1"
}
Expand Down
12 changes: 12 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pnpm-workspace.yaml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
packages:
- "apps/**"
- "packages/**"