Skip to content

Commit

Permalink
🪚 Schemas for OApp config (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
janjakubnanista authored Jan 3, 2024
1 parent b74afbe commit 39f08f7
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 26 deletions.
2 changes: 2 additions & 0 deletions packages/devtools/src/omnigraph/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<EndpointId, z.ZodTypeDef, string | number> = z
Expand Down
16 changes: 7 additions & 9 deletions packages/protocol-devtools-evm/src/uln302/schema.ts
Original file line number Diff line number Diff line change
@@ -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<Uln302UlnConfig, z.ZodTypeDef, Uln302UlnConfigInput>

/**
* 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<Uln302ExecutorConfig, z.ZodTypeDef, Uln302ExecutorConfigInput>

/**
Expand Down
1 change: 1 addition & 0 deletions packages/protocol-devtools/src/endpoint/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './config'
export * from './schema'
export * from './types'
8 changes: 8 additions & 0 deletions packages/protocol-devtools/src/endpoint/schema.ts
Original file line number Diff line number Diff line change
@@ -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<Timeout, z.ZodTypeDef, unknown>
10 changes: 9 additions & 1 deletion packages/protocol-devtools/src/endpoint/types.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
1 change: 1 addition & 0 deletions packages/protocol-devtools/src/uln302/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './config'
export * from './schema'
export * from './types'
15 changes: 15 additions & 0 deletions packages/protocol-devtools/src/uln302/schema.ts
Original file line number Diff line number Diff line change
@@ -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<Uln302ExecutorConfig, z.ZodTypeDef, unknown>

export const Uln302UlnConfigSchema = z.object({
confirmations: UIntSchema,
requiredDVNs: z.array(AddressSchema),
optionalDVNs: z.array(AddressSchema),
optionalDVNThreshold: UIntSchema,
}) satisfies z.ZodSchema<Uln302UlnConfig, z.ZodTypeDef, unknown>
2 changes: 1 addition & 1 deletion packages/protocol-devtools/src/uln302/types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion packages/ua-devtools-evm-hardhat/hardhat.config.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
3 changes: 2 additions & 1 deletion packages/ua-devtools-evm-hardhat/src/oapp/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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<OAppOmniGraphHardhat>
5 changes: 3 additions & 2 deletions packages/ua-devtools-evm-hardhat/src/oapp/types.ts
Original file line number Diff line number Diff line change
@@ -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<unknown, unknown>
export type OAppOmniGraphHardhat = OmniGraphHardhat<unknown, OAppEdgeConfig | undefined>
1 change: 1 addition & 0 deletions packages/ua-devtools/src/oapp/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './config'
export * from './schema'
export * from './types'
26 changes: 26 additions & 0 deletions packages/ua-devtools/src/oapp/schema.ts
Original file line number Diff line number Diff line change
@@ -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<OAppReceiveLibraryConfig, z.ZodTypeDef, unknown>

export const OAppSendConfigSchema = z.object({
executorConfig: Uln302ExecutorConfigSchema,
ulnConfig: Uln302UlnConfigSchema,
}) satisfies z.ZodSchema<OAppSendConfig, z.ZodTypeDef, unknown>

export const OAppReceiveConfigSchema = z.object({
ulnConfig: Uln302UlnConfigSchema,
}) satisfies z.ZodSchema<OAppReceiveConfig, z.ZodTypeDef, unknown>

export const OAppEdgeConfigSchema = z.object({
sendLibrary: AddressSchema.optional(),
receiveLibraryConfig: OAppReceiveLibraryConfigSchema.optional(),
receiveLibraryTimeoutConfig: TimeoutSchema.optional(),
sendConfig: OAppSendConfigSchema.optional(),
receiveConfig: OAppReceiveConfigSchema.optional(),
}) satisfies z.ZodSchema<OAppEdgeConfig, z.ZodTypeDef, unknown>
34 changes: 23 additions & 11 deletions packages/ua-devtools/src/oapp/types.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -11,21 +18,26 @@ export interface IOApp extends IOmniSDK {
setPeer(eid: EndpointId, peer: Bytes32 | Address | null | undefined): Promise<OmniTransaction>
}

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<unknown, OAppEdgeConfig | undefined>
Expand Down

0 comments on commit 39f08f7

Please sign in to comment.