2Branches0Tags
GL
glucryptoSync production with master template updates
dc969c112 days ago54Commits
typescript
import { z } from "zod"; export const TEMPLATE_CONFIG_SCHEMA = { type: "object", "x-budget": { modeField: "allocationMode", defaultMode: "target_notional", title: "Budget & allocation", description: "Core exposure settings are shown first.", modes: { target_notional: { fields: ["targetNotionalUsd", "hedgeRatio"], }, }, }, required: [ "platform", "allocationMode", "spotAsset", "perpAsset", "targetNotionalUsd", "hedgeRatio", "slippageBps", "expectedCarryHours", "deltaDriftPct", "environment", "schedule", ], properties: { configVersion: { type: "number", title: "Config version", description: "Internal version for delta-neutral config defaults.", readOnly: true, "x-hidden": true, "x-section": "Meta", "x-order": 1000, }, platform: { type: "string", enum: ["hyperliquid"], title: "Platform", description: "Execution venue for spot + perps.", readOnly: true, "x-section": "Execution", "x-order": 1, }, allocationMode: { type: "string", enum: ["target_notional"], title: "Allocation mode", description: "Canonical sizing mode for delta-neutral templates.", readOnly: true, "x-hidden": true, "x-section": "Meta", "x-order": 1001, }, spotAsset: { type: "string", title: "Spot asset", description: "Spot leg asset for the delta-neutral position (example: BTC).", "x-format": "asset", "x-section": "Strategy", "x-order": 1, }, perpAsset: { type: "string", title: "Perp asset", description: "Perp hedge leg asset for the delta-neutral position (example: BTC).", "x-format": "asset", "x-section": "Strategy", "x-order": 2, }, targetNotionalUsd: { type: "number", title: "Target notional", description: "Total USD notional for each leg.", minimum: 1, "x-unit": "USD", "x-format": "currency", "x-step": 1, "x-section": "Strategy", "x-order": 3, }, hedgeRatio: { type: "number", title: "Hedge ratio", description: "Multiplier for the hedge leg notional.", minimum: 0.01, "x-unit": "x", "x-step": 0.01, "x-section": "Strategy", "x-order": 4, }, perpLeverage: { type: "number", title: "Perp leverage", description: "Target leverage for the perp hedge leg.", minimum: 1, maximum: 40, "x-unit": "x", "x-step": 1, "x-section": "Execution", "x-order": 3, }, perpLeverageMode: { type: "string", enum: ["cross", "isolated"], title: "Perp leverage mode", description: "Margin mode for the perp hedge leg.", "x-enumLabels": ["Cross", "Isolated"], "x-section": "Execution", "x-order": 4, }, slippageBps: { type: "number", title: "Slippage", description: "Maximum slippage for marketable orders.", minimum: 0, maximum: 5000, "x-unit": "bps", "x-format": "bps", "x-step": 1, "x-section": "Risk limits", "x-order": 1, }, expectedCarryHours: { type: "number", title: "Carry horizon", description: "Hours of funding carry to underwrite before opening the hedge.", minimum: 1, maximum: 8760, "x-unit": "hours", "x-format": "duration", "x-step": 1, "x-section": "Strategy", "x-order": 5, }, deltaDriftPct: { type: "number", title: "Delta drift", description: "Percent of target notional before rebalancing.", minimum: 0.1, maximum: 50, "x-unit": "%", "x-format": "percent", "x-step": 0.1, "x-section": "Risk limits", "x-order": 2, }, basisMaxBps: { type: "number", title: "Max basis", description: "Max basis spread in bps before skipping trades.", minimum: 0, "x-unit": "bps", "x-format": "bps", "x-step": 1, "x-section": "Risk limits", "x-order": 5, }, fundingMinBps: { type: "number", title: "Min funding", description: "Minimum funding rate in bps to keep the position open.", minimum: 0, "x-unit": "bps", "x-format": "bps", "x-step": 0.01, "x-section": "Risk limits", "x-order": 6, }, environment: { type: "string", enum: ["mainnet", "testnet"], title: "Environment", description: "Hyperliquid environment for execution.", "x-enumLabels": ["Mainnet", "Testnet"], "x-section": "Execution", "x-order": 2, }, schedule: { type: "object", title: "Schedule", description: "Cron schedule for rebalancing runs.", "x-section": "Schedule", properties: { cron: { type: "string", title: "Cron expression", description: "Standard cron expression for the run schedule.", "x-order": 1, }, enabled: { type: "boolean", title: "Enabled", description: "Enable the scheduled rebalance.", "x-order": 2, }, notifyEmail: { type: "boolean", title: "Notify email", description: "Send an email after each scheduled run.", "x-order": 3, }, }, }, }, } as const; export const scheduleSchema = z .object({ cron: z.string().min(1).optional(), enabled: z.boolean().optional(), notifyEmail: z.boolean().optional(), }) .optional(); export const configSchema = z.object({ platform: z.literal("hyperliquid").optional(), allocationMode: z.literal("target_notional").optional(), spotAsset: z.string().min(1).optional(), perpAsset: z.string().min(1).optional(), targetNotionalUsd: z.number().positive().optional(), hedgeRatio: z.number().positive().optional(), perpLeverage: z.number().positive().optional(), perpLeverageMode: z.enum(["cross", "isolated"]).optional(), slippageBps: z.number().int().min(0).max(5000).optional(), expectedCarryHours: z.number().int().min(1).max(8760).optional(), deltaDriftPct: z.number().positive().max(100).optional(), basisMaxBps: z.number().int().min(0).optional(), fundingMinBps: z.number().min(0).optional(), environment: z.enum(["mainnet", "testnet"]).optional(), schedule: scheduleSchema, });