From ff80ae36b94ca526f3b6fe8c9fbdc9b4f35df0c5 Mon Sep 17 00:00:00 2001 From: Punter Date: Thu, 16 Jul 2026 14:00:00 +0300 Subject: [PATCH] feat: add batch and intent validation utilities --- src/validation.ts | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/validation.ts diff --git a/src/validation.ts b/src/validation.ts new file mode 100644 index 0000000..2f2fb95 --- /dev/null +++ b/src/validation.ts @@ -0,0 +1,18 @@ +import type { DVPIntent } from "./types"; +import { MAX_BATCH_SIZE } from "./constants"; + +export function validateBatchSize(intents: DVPIntent[]): void { + if (intents.length === 0) throw new Error("Empty batch"); + if (intents.length > MAX_BATCH_SIZE) throw new Error(`Batch size ${intents.length} exceeds max ${MAX_BATCH_SIZE}`); +} + +export function validateIntentDeadline(intent: DVPIntent): void { + const now = BigInt(Math.floor(Date.now() / 1000)); + if (intent.deadline <= now) throw new Error("Intent deadline has passed"); +} + +export function validateIntentPair(intent: DVPIntent): void { + if (intent.buyer === intent.seller) throw new Error("Buyer and seller must be different"); + if (intent.amount === 0n) throw new Error("Amount must be non-zero"); + if (intent.price === 0n) throw new Error("Price must be non-zero"); +}