From 39f08f720ccb12504ed315961a9757d022e58f89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Jakub=20Nani=C5=A1ta?= Date: Tue, 2 Jan 2024 16:07:43 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=AA=9A=20Schemas=20for=20OApp=20config=20?= =?UTF-8?q?(#141)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/devtools/src/omnigraph/schema.ts | 2 ++ .../src/uln302/schema.ts | 16 ++++----- .../protocol-devtools/src/endpoint/index.ts | 1 + .../protocol-devtools/src/endpoint/schema.ts | 8 +++++ .../protocol-devtools/src/endpoint/types.ts | 10 +++++- .../protocol-devtools/src/uln302/index.ts | 1 + .../protocol-devtools/src/uln302/schema.ts | 15 ++++++++ .../protocol-devtools/src/uln302/types.ts | 2 +- .../ua-devtools-evm-hardhat/hardhat.config.ts | 2 +- .../src/oapp/schema.ts | 3 +- .../ua-devtools-evm-hardhat/src/oapp/types.ts | 5 +-- packages/ua-devtools/src/oapp/index.ts | 1 + packages/ua-devtools/src/oapp/schema.ts | 26 ++++++++++++++ packages/ua-devtools/src/oapp/types.ts | 34 +++++++++++++------ 14 files changed, 100 insertions(+), 26 deletions(-) create mode 100644 packages/protocol-devtools/src/endpoint/schema.ts create mode 100644 packages/protocol-devtools/src/uln302/schema.ts create mode 100644 packages/ua-devtools/src/oapp/schema.ts diff --git a/packages/devtools/src/omnigraph/schema.ts b/packages/devtools/src/omnigraph/schema.ts index 474f9e092..b42fb7d54 100644 --- a/packages/devtools/src/omnigraph/schema.ts +++ b/packages/devtools/src/omnigraph/schema.ts @@ -2,6 +2,8 @@ import { EndpointId } from '@layerzerolabs/lz-definitions' import { z } from 'zod' import type { OmniPoint, OmniNode, OmniVector, OmniEdge, OmniGraph } from './types' +export const UIntSchema = z.coerce.number().nonnegative().int() + export const AddressSchema = z.string() export const EndpointIdSchema: z.ZodSchema = z diff --git a/packages/protocol-devtools-evm/src/uln302/schema.ts b/packages/protocol-devtools-evm/src/uln302/schema.ts index 5b5a8ec31..79883d97b 100644 --- a/packages/protocol-devtools-evm/src/uln302/schema.ts +++ b/packages/protocol-devtools-evm/src/uln302/schema.ts @@ -1,26 +1,24 @@ import { z } from 'zod' -import { AddressSchema } from '@layerzerolabs/devtools' -import { BigNumberishNumberSchema } from '@layerzerolabs/devtools-evm' -import { BigNumberishBigintSchema } from '@layerzerolabs/devtools-evm' +import { BigNumberishBigintSchema, BigNumberishNumberSchema } from '@layerzerolabs/devtools-evm' +import { + Uln302UlnConfigSchema as Uln302UlnConfigSchemaBase, + Uln302ExecutorConfigSchema as Uln302ExecutorConfigSchemaBase, +} from '@layerzerolabs/protocol-devtools' import type { Uln302ExecutorConfig, Uln302UlnConfig } from '@layerzerolabs/protocol-devtools' import type { Uln302ExecutorConfigInput, Uln302UlnConfigInput } from './types' /** * Schema for parsing an ethers-specific UlnConfig into a common format */ -export const Uln302UlnConfigSchema = z.object({ +export const Uln302UlnConfigSchema = Uln302UlnConfigSchemaBase.extend({ confirmations: BigNumberishBigintSchema, - requiredDVNs: z.array(AddressSchema), - optionalDVNs: z.array(AddressSchema), - optionalDVNThreshold: z.coerce.number().int().nonnegative(), }) satisfies z.ZodSchema /** * Schema for parsing an ethers-specific ExecutorConfig into a common format */ -export const Uln302ExecutorConfigSchema = z.object({ +export const Uln302ExecutorConfigSchema = Uln302ExecutorConfigSchemaBase.extend({ maxMessageSize: BigNumberishNumberSchema, - executor: AddressSchema, }) satisfies z.ZodSchema /** diff --git a/packages/protocol-devtools/src/endpoint/index.ts b/packages/protocol-devtools/src/endpoint/index.ts index 39bdac610..1273e8646 100644 --- a/packages/protocol-devtools/src/endpoint/index.ts +++ b/packages/protocol-devtools/src/endpoint/index.ts @@ -1,2 +1,3 @@ export * from './config' +export * from './schema' export * from './types' diff --git a/packages/protocol-devtools/src/endpoint/schema.ts b/packages/protocol-devtools/src/endpoint/schema.ts new file mode 100644 index 000000000..1e0874624 --- /dev/null +++ b/packages/protocol-devtools/src/endpoint/schema.ts @@ -0,0 +1,8 @@ +import { AddressSchema, UIntSchema } from '@layerzerolabs/devtools' +import { z } from 'zod' +import { Timeout } from './types' + +export const TimeoutSchema = z.object({ + lib: AddressSchema, + expiry: UIntSchema, +}) satisfies z.ZodSchema diff --git a/packages/protocol-devtools/src/endpoint/types.ts b/packages/protocol-devtools/src/endpoint/types.ts index d78821137..31ad06321 100644 --- a/packages/protocol-devtools/src/endpoint/types.ts +++ b/packages/protocol-devtools/src/endpoint/types.ts @@ -1,4 +1,12 @@ -import type { Address, Factory, OmniGraph, OmniPoint, OmniTransaction, IOmniSDK, Bytes32 } from '../../../devtools/dist' +import type { + Address, + Factory, + OmniGraph, + OmniPoint, + OmniTransaction, + IOmniSDK, + Bytes32, +} from '@layerzerolabs/devtools' import type { EndpointId } from '@layerzerolabs/lz-definitions' import type { IUln302, Uln302ExecutorConfig, Uln302UlnConfig } from '@/uln302/types' diff --git a/packages/protocol-devtools/src/uln302/index.ts b/packages/protocol-devtools/src/uln302/index.ts index 39bdac610..1273e8646 100644 --- a/packages/protocol-devtools/src/uln302/index.ts +++ b/packages/protocol-devtools/src/uln302/index.ts @@ -1,2 +1,3 @@ export * from './config' +export * from './schema' export * from './types' diff --git a/packages/protocol-devtools/src/uln302/schema.ts b/packages/protocol-devtools/src/uln302/schema.ts new file mode 100644 index 000000000..d3355a852 --- /dev/null +++ b/packages/protocol-devtools/src/uln302/schema.ts @@ -0,0 +1,15 @@ +import { AddressSchema, UIntSchema } from '@layerzerolabs/devtools' +import { z } from 'zod' +import { Uln302ExecutorConfig, Uln302UlnConfig } from './types' + +export const Uln302ExecutorConfigSchema = z.object({ + executor: AddressSchema, + maxMessageSize: UIntSchema, +}) satisfies z.ZodSchema + +export const Uln302UlnConfigSchema = z.object({ + confirmations: UIntSchema, + requiredDVNs: z.array(AddressSchema), + optionalDVNs: z.array(AddressSchema), + optionalDVNThreshold: UIntSchema, +}) satisfies z.ZodSchema diff --git a/packages/protocol-devtools/src/uln302/types.ts b/packages/protocol-devtools/src/uln302/types.ts index 9477b0048..07e498809 100644 --- a/packages/protocol-devtools/src/uln302/types.ts +++ b/packages/protocol-devtools/src/uln302/types.ts @@ -1,4 +1,4 @@ -import type { Address, OmniGraph, Factory, OmniTransaction, IOmniSDK, OmniPoint } from '../../../devtools/dist' +import type { Address, OmniGraph, Factory, OmniTransaction, IOmniSDK, OmniPoint } from '@layerzerolabs/devtools' import type { EndpointId } from '@layerzerolabs/lz-definitions' export interface IUln302 extends IOmniSDK { diff --git a/packages/ua-devtools-evm-hardhat/hardhat.config.ts b/packages/ua-devtools-evm-hardhat/hardhat.config.ts index 5f6c1c3b1..d169f1b1e 100644 --- a/packages/ua-devtools-evm-hardhat/hardhat.config.ts +++ b/packages/ua-devtools-evm-hardhat/hardhat.config.ts @@ -1,5 +1,5 @@ import 'hardhat-deploy' -import '../devtools-evm-hardhat/dist' +import '@layerzerolabs/devtools-evm-hardhat' import { EndpointId } from '@layerzerolabs/lz-definitions' import { HardhatUserConfig } from 'hardhat/types' diff --git a/packages/ua-devtools-evm-hardhat/src/oapp/schema.ts b/packages/ua-devtools-evm-hardhat/src/oapp/schema.ts index 3c74b3404..91d5be962 100644 --- a/packages/ua-devtools-evm-hardhat/src/oapp/schema.ts +++ b/packages/ua-devtools-evm-hardhat/src/oapp/schema.ts @@ -5,6 +5,7 @@ import { } from '@layerzerolabs/devtools-evm-hardhat' import { z } from 'zod' import type { OAppOmniGraphHardhat } from './types' +import { OAppEdgeConfigSchema } from '@layerzerolabs/ua-devtools' /** * Validation schema for OApp configs in hardhat environment. @@ -14,5 +15,5 @@ import type { OAppOmniGraphHardhat } from './types' */ export const OAppOmniGraphHardhatSchema = createOmniGraphHardhatSchema( createOmniNodeHardhatSchema(z.unknown()), - createOmniEdgeHardhatSchema(z.unknown()) + createOmniEdgeHardhatSchema(OAppEdgeConfigSchema.optional()) ) satisfies z.ZodSchema diff --git a/packages/ua-devtools-evm-hardhat/src/oapp/types.ts b/packages/ua-devtools-evm-hardhat/src/oapp/types.ts index 5bc91af65..89019acab 100644 --- a/packages/ua-devtools-evm-hardhat/src/oapp/types.ts +++ b/packages/ua-devtools-evm-hardhat/src/oapp/types.ts @@ -1,3 +1,4 @@ -import { OmniGraphHardhat } from '../../../devtools-evm-hardhat/dist' +import { OmniGraphHardhat } from '@layerzerolabs/devtools-evm-hardhat' +import { OAppEdgeConfig } from '@layerzerolabs/ua-devtools' -export type OAppOmniGraphHardhat = OmniGraphHardhat +export type OAppOmniGraphHardhat = OmniGraphHardhat diff --git a/packages/ua-devtools/src/oapp/index.ts b/packages/ua-devtools/src/oapp/index.ts index 39bdac610..1273e8646 100644 --- a/packages/ua-devtools/src/oapp/index.ts +++ b/packages/ua-devtools/src/oapp/index.ts @@ -1,2 +1,3 @@ export * from './config' +export * from './schema' export * from './types' diff --git a/packages/ua-devtools/src/oapp/schema.ts b/packages/ua-devtools/src/oapp/schema.ts new file mode 100644 index 000000000..33c457e47 --- /dev/null +++ b/packages/ua-devtools/src/oapp/schema.ts @@ -0,0 +1,26 @@ +import { z } from 'zod' +import { AddressSchema, UIntSchema } from '@layerzerolabs/devtools' +import { Uln302ExecutorConfigSchema, Uln302UlnConfigSchema, TimeoutSchema } from '@layerzerolabs/protocol-devtools' +import type { OAppEdgeConfig, OAppReceiveConfig, OAppReceiveLibraryConfig, OAppSendConfig } from './types' + +export const OAppReceiveLibraryConfigSchema = z.object({ + gracePeriod: UIntSchema, + receiveLibrary: AddressSchema, +}) satisfies z.ZodSchema + +export const OAppSendConfigSchema = z.object({ + executorConfig: Uln302ExecutorConfigSchema, + ulnConfig: Uln302UlnConfigSchema, +}) satisfies z.ZodSchema + +export const OAppReceiveConfigSchema = z.object({ + ulnConfig: Uln302UlnConfigSchema, +}) satisfies z.ZodSchema + +export const OAppEdgeConfigSchema = z.object({ + sendLibrary: AddressSchema.optional(), + receiveLibraryConfig: OAppReceiveLibraryConfigSchema.optional(), + receiveLibraryTimeoutConfig: TimeoutSchema.optional(), + sendConfig: OAppSendConfigSchema.optional(), + receiveConfig: OAppReceiveConfigSchema.optional(), +}) satisfies z.ZodSchema diff --git a/packages/ua-devtools/src/oapp/types.ts b/packages/ua-devtools/src/oapp/types.ts index bcfc9d1fa..25a2874fd 100644 --- a/packages/ua-devtools/src/oapp/types.ts +++ b/packages/ua-devtools/src/oapp/types.ts @@ -1,7 +1,14 @@ import type { EndpointId } from '@layerzerolabs/lz-definitions' import type { IEndpoint, Timeout } from '@layerzerolabs/protocol-devtools' -import type { Address, Factory, IOmniSDK, OmniGraph, OmniPoint, OmniTransaction } from '../../../devtools/dist' -import type { Bytes32 } from '../../../devtools/dist' +import type { + Address, + Bytes32, + Factory, + IOmniSDK, + OmniGraph, + OmniPoint, + OmniTransaction, +} from '@layerzerolabs/devtools' import type { Uln302ExecutorConfig, Uln302UlnConfig } from '@layerzerolabs/protocol-devtools' export interface IOApp extends IOmniSDK { @@ -11,21 +18,26 @@ export interface IOApp extends IOmniSDK { setPeer(eid: EndpointId, peer: Bytes32 | Address | null | undefined): Promise } -export interface ReceiveLibraryConfig { +export interface OAppReceiveLibraryConfig { receiveLibrary: string gracePeriod: number } + +export interface OAppSendConfig { + executorConfig: Uln302ExecutorConfig + ulnConfig: Uln302UlnConfig +} + +export interface OAppReceiveConfig { + ulnConfig: Uln302UlnConfig +} + export interface OAppEdgeConfig { sendLibrary?: string - receiveLibraryConfig?: ReceiveLibraryConfig + receiveLibraryConfig?: OAppReceiveLibraryConfig receiveLibraryTimeoutConfig?: Timeout - sendConfig?: { - executorConfig: Uln302ExecutorConfig - ulnConfig: Uln302UlnConfig - } - receiveConfig?: { - ulnConfig: Uln302UlnConfig - } + sendConfig?: OAppSendConfig + receiveConfig?: OAppReceiveConfig } export type OAppOmniGraph = OmniGraph