Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions src/validation.ts
Original file line number Diff line number Diff line change
@@ -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");
}
Loading