Skip to content

Commit

Permalink
🪲Updating Enforced Options Schema (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
sirarthurmoney authored Feb 1, 2024
1 parent ae1319d commit e2fcf96
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
5 changes: 5 additions & 0 deletions .changeset/little-jobs-pump.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@layerzerolabs/ua-devtools": patch
---

Updating Enforced Options Schema
49 changes: 44 additions & 5 deletions packages/ua-devtools/src/oapp/schema.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,19 @@
import { z } from 'zod'
import { AddressSchema, UIntBigIntSchema } from '@layerzerolabs/devtools'
import { AddressSchema, UIntBigIntSchema, UIntNumberSchema } from '@layerzerolabs/devtools'
import { Uln302ExecutorConfigSchema, Uln302UlnConfigSchema, TimeoutSchema } from '@layerzerolabs/protocol-devtools'
import {
EndcodedOption,
ExecutorComposeOption,
ExecutorLzReceiveOption,
ExecutorNativeDropOption,
ExecutorOrderedExecutionOption,
OAppEdgeConfig,
OAppEnforcedOptionConfig,
OAppReceiveConfig,
OAppReceiveLibraryConfig,
OAppSendConfig,
} from './types'
import { ExecutorOptionType } from '@layerzerolabs/lz-v2-utilities'

export const OAppReceiveLibraryConfigSchema = z.object({
gracePeriod: UIntBigIntSchema,
Expand All @@ -23,12 +29,45 @@ export const OAppReceiveConfigSchema = z.object({
ulnConfig: Uln302UlnConfigSchema,
}) satisfies z.ZodSchema<OAppReceiveConfig, z.ZodTypeDef, unknown>

export const OAppEnforcedOptionSchema = z.object({
msgType: z.number(),
const ExecutorOptionTypeSchema = z.nativeEnum(ExecutorOptionType)

export const EncodedOptionSchema = z.object({
msgType: ExecutorOptionTypeSchema,
options: z.string(),
}) satisfies z.ZodSchema<OAppEnforcedOptionConfig, z.ZodTypeDef, unknown>
}) satisfies z.ZodSchema<EndcodedOption, z.ZodTypeDef, unknown>

export const ExecutorLzReceiveOptionSchema = z.object({
msgType: z.literal(ExecutorOptionType.LZ_RECEIVE),
gas: UIntNumberSchema,
value: UIntNumberSchema,
}) satisfies z.ZodSchema<ExecutorLzReceiveOption, z.ZodTypeDef, unknown>

export const ExecutorNativeDropOptionSchema = z.object({
msgType: z.literal(ExecutorOptionType.NATIVE_DROP),
amount: UIntNumberSchema,
receiver: AddressSchema,
}) satisfies z.ZodSchema<ExecutorNativeDropOption, z.ZodTypeDef, unknown>

export const ExecutorComposeOptionSchema = z.object({
msgType: z.literal(ExecutorOptionType.COMPOSE),
index: UIntNumberSchema,
gas: UIntNumberSchema,
value: UIntNumberSchema,
}) satisfies z.ZodSchema<ExecutorComposeOption, z.ZodTypeDef, unknown>

export const ExecutorOrderedExecutionOptionSchema = z.object({
msgType: z.literal(ExecutorOptionType.ORDERED),
}) satisfies z.ZodSchema<ExecutorOrderedExecutionOption, z.ZodTypeDef, unknown>

export const OAppEnforcedOptionConfigSchema = z.union([
EncodedOptionSchema,
ExecutorLzReceiveOptionSchema,
ExecutorNativeDropOptionSchema,
ExecutorComposeOptionSchema,
ExecutorOrderedExecutionOptionSchema,
]) satisfies z.ZodSchema<OAppEnforcedOptionConfig, z.ZodTypeDef, unknown>

export const OAppEnforcedOptionsSchema = z.array(OAppEnforcedOptionSchema) satisfies z.ZodSchema<
export const OAppEnforcedOptionsSchema = z.array(OAppEnforcedOptionConfigSchema) satisfies z.ZodSchema<
OAppEnforcedOptionConfig[],
z.ZodTypeDef,
unknown
Expand Down
12 changes: 6 additions & 6 deletions packages/ua-devtools/src/oapp/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,34 +50,34 @@ export interface OAppEdgeConfig {
enforcedOptions?: OAppEnforcedOptionConfig[]
}

interface BaseExecutorOption {
export interface BaseExecutorOption {
msgType: ExecutorOptionType
}

interface EndcodedOption extends BaseExecutorOption {
export interface EndcodedOption extends BaseExecutorOption {
options: string
}

interface ExecutorLzReceiveOption extends BaseExecutorOption {
export interface ExecutorLzReceiveOption extends BaseExecutorOption {
msgType: ExecutorOptionType.LZ_RECEIVE
gas: string | number
value: string | number
}

interface ExecutorNativeDropOption extends BaseExecutorOption {
export interface ExecutorNativeDropOption extends BaseExecutorOption {
msgType: ExecutorOptionType.NATIVE_DROP
amount: string | number
receiver: string
}

interface ExecutorComposeOption extends BaseExecutorOption {
export interface ExecutorComposeOption extends BaseExecutorOption {
msgType: ExecutorOptionType.COMPOSE
index: number
gas: string | number
value: string | number
}

interface ExecutorOrderedExecutionOption extends BaseExecutorOption {
export interface ExecutorOrderedExecutionOption extends BaseExecutorOption {
msgType: ExecutorOptionType.ORDERED
}

Expand Down

0 comments on commit e2fcf96

Please sign in to comment.