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: update RPC abis and behavior #94

Merged
merged 16 commits into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from 14 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
2 changes: 1 addition & 1 deletion apps/agent/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ BLOCK_NUMBER_BLOCKMETA_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuaWNlIjoidH
EBO_AGENT_CONFIG_FILE_PATH="./config.example.yml"

# Discord webhook notifications
DISCORD_WEBHOOK=YOUR_DISCORD_WEBHOOK
DISCORD_WEBHOOK=YOUR_DISCORD_WEBHOOK
2 changes: 2 additions & 0 deletions apps/agent/config.example.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ protocolProvider:
eboRequestCreator: "0x1234567890123456789012345678901234567890" # EBO Request Creator contract
bondEscalationModule: "0x1234567890123456789012345678901234567890" # Bond Escalation Module contract
horizonAccountingExtension: "0x1234567890123456789012345678901234567890" # Accounting extension contract
accessControl:
serviceProviderAddress: "0x1234567890123456789012345678901234567890" # Service Provider Address

blockNumberService:
blockmetaConfig:
Expand Down
11 changes: 11 additions & 0 deletions apps/agent/src/config/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const envSchema = z.object({
});

const addressSchema = z.string().refine((address) => isAddress(address));

const rpcConfigSchema = z.object({
chainId: z
.string()
Expand All @@ -43,6 +44,15 @@ const rpcConfigSchema = z.object({
retryInterval: z.number().int().positive(),
});

export const accessControlSchema = z.object({
serviceProviderAddress: z
.string()
.refine((val) => isAddress(val), {
message: "serviceProviderAddress must be a valid blockchain address",
})
.optional(),
});

const protocolProviderConfigSchema = z.object({
rpcsConfig: z.object({
l1: rpcConfigSchema,
Expand All @@ -55,6 +65,7 @@ const protocolProviderConfigSchema = z.object({
bondEscalationModule: addressSchema,
horizonAccountingExtension: addressSchema,
}),
accessControl: accessControlSchema.optional(),
});

const blockNumberServiceSchema = z.object({
Expand Down
1 change: 1 addition & 0 deletions apps/agent/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ const main = async (): Promise<void> => {
config.protocolProvider.rpcsConfig,
config.protocolProvider.contracts,
config.protocolProvider.privateKey,
config.protocolProvider.accessControl?.serviceProviderAddress,
logger,
blockNumberService,
);
Expand Down
16 changes: 14 additions & 2 deletions apps/scripts/utilities/approveAccountingModules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ProtocolProvider } from "@ebo-agent/automated-dispute/src/index.js";
import { mockLogger } from "@ebo-agent/automated-dispute/tests/mocks/logger.mocks.js";
import { Caip2ChainId } from "@ebo-agent/shared";
import * as dotenv from "dotenv";
import { Address, Hex, isHex } from "viem";
import { Address, Hex, isAddress, isHex } from "viem";
import { z } from "zod";

dotenv.config();
Expand Down Expand Up @@ -70,6 +70,12 @@ const envSchema = z.object({
CONTRACTS_ADDRESSES: stringToJSONSchema.pipe(contractsAddressesSchema),
BONDED_RESPONSE_MODULE_ADDRESS: z.string().min(1, "BONDED_RESPONSE_MODULE_ADDRESS is required"),
BOND_ESCALATION_MODULE_ADDRESS: z.string().min(1, "BOND_ESCALATION_MODULE_ADDRESS is required"),
SERVICE_PROVIDER_ADDRESS: z
.string()
.refine((val) => isAddress(val), {
message: "SERVICE_PROVIDER_ADDRESS must be a valid blockchain address",
})
.optional(),
});

const envResult = envSchema.safeParse(process.env);
Expand Down Expand Up @@ -103,7 +109,13 @@ const rpcConfig = {

const contracts = env.CONTRACTS_ADDRESSES;

const provider = new ProtocolProvider(rpcConfig, contracts, env.PRIVATE_KEY as Hex, mockLogger());
const provider = new ProtocolProvider(
rpcConfig,
contracts,
env.PRIVATE_KEY as Hex,
env.SERVICE_PROVIDER_ADDRESS,
mockLogger(),
);

/**
* Approves the necessary modules by calling approveModule on ProtocolProvider.
Expand Down
Loading