SDK ReferenceTypes & Errors

Types & Errors

TypeScript types and common error handling patterns.

Types

VaultAccount

interface VaultAccount {
  employer: PublicKey;
  vaultAta: PublicKey;
  tokenMint: PublicKey;
  available: BN;
  reserved: BN;
  bump: number;
}

ScheduleAccount

interface ScheduleAccount {
  employer: PublicKey;
  vault: PublicKey;
  status: ScheduleStatus;
  intervalSecs: BN;
  nextExecution: BN;
  reservedAmount: BN;
  perExecutionAmount: BN;
  erJobId: number[];
  merkleRoot: number[];
  totalRecipients: number;
  paidCount: number;
  paidBitmap: number[];
  lastExecutedBatch: BN;
  batchStartTime: BN;
  bump: number;
}

scheduleId is not stored inside ScheduleAccount. It is used to derive the schedule PDA.

ScheduleStatus

enum ScheduleStatus {
  Active = "Active",
  Paused = "Paused",
  Cancelled = "Cancelled",
}

Recipient

interface Recipient {
  address: PublicKey;
  amount: bigint;
}

CreateScheduleParams

interface CreateScheduleParams {
  tokenMint: PublicKey;
  scheduleId: number[];
  intervalSecs: number;
  reservedAmount: BN;
  perExecutionAmount: BN;
  merkleRoot: number[];
  totalRecipients: number;
  erJobId: number[];
}

UpdateScheduleParams

interface UpdateScheduleParams {
  intervalSecs: number;
  reservedAmount: BN;
  perExecutionAmount: BN;
  merkleRoot: number[];
  totalRecipients: number;
}

VeilConfig

interface VeilConfig {
  erAuthority: PublicKey;
  governance: PublicKey;
  paused: boolean;
  whitelistEnabled: boolean;
  maxRecipients: number;
  allowedMints: PublicKey[];
  batchTimeoutSecs: BN;
}

Error Handling

Anchor Errors

try {
  await client.deposit(amount, tokenMint);
} catch (error) {
  if (error.message.includes("InsufficientFunds")) {
    console.log("Not enough tokens");
  } else if (error.message.includes("Paused")) {
    console.log("Protocol is paused");
  } else if (error.message.includes("Unauthorized")) {
    console.log("Not authorized");
  } else if (error.message.includes("ScheduleNotActive")) {
    console.log("Schedule is not active");
  }
}

Common Error Codes

  • InsufficientFunds
  • Paused
  • Unauthorized
  • ScheduleNotActive
  • ScheduleNotPaused
  • InvalidMerkleProof
  • AlreadyPaid
  • InvalidMaxRecipients
  • InvalidMint

Error Checking

import { AnchorError } from "@coral-xyz/anchor";
 
try {
  await client.createSchedule(/* ... */);
} catch (err) {
  if (err instanceof AnchorError) {
    console.log("Error code:", err.error.errorCode.code);
    console.log("Error message:", err.error.errorMessage);
  }
}

Type Exports

All types are exported from the SDK:

import {
  VaultAccount,
  ScheduleAccount,
  ScheduleStatus,
  Recipient,
  CreateScheduleParams,
  UpdateScheduleParams,
  VeilConfig,
} from "@veil-dev/sdk";