import { i as isVestingInvariantError, n as VestingInvariantError } from "./errors-8Tiso7LK.js";
import { PostgresTransaction, Querier } from "@platform-modules/db";
//#region src/vesting-schema.d.ts
/** 1:1 opt-in extension of ledgerEntries (entryId → ledgerEntries.id; cross-package, no drizzle relation). */
declare const ledgerEntryVesting: import("drizzle-orm/pg-core").PgTableWithColumns<{
  name: "ledger_entry_vesting";
  schema: undefined;
  columns: {
    entryId: import("drizzle-orm/pg-core").PgColumn<{
      name: "entry_id";
      tableName: "ledger_entry_vesting";
      dataType: "string";
      columnType: "PgUUID";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: true;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    matureAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "mature_at";
      tableName: "ledger_entry_vesting";
      dataType: "date";
      columnType: "PgTimestamp";
      data: Date;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    sweptAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "swept_at";
      tableName: "ledger_entry_vesting";
      dataType: "date";
      columnType: "PgTimestamp";
      data: Date;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    withdrawableAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "withdrawable_at";
      tableName: "ledger_entry_vesting";
      dataType: "date";
      columnType: "PgTimestamp";
      data: Date;
      driverParam: string;
      notNull: false;
      hasDefault: false;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
  };
  dialect: "pg";
}>;
/** 1:1 opt-in extension of walletBalances (ownerId logical-maps to walletBalances.ownerId — NO cross-package FK; plain text PK). */
declare const walletVesting: import("drizzle-orm/pg-core").PgTableWithColumns<{
  name: "wallet_vesting";
  schema: undefined;
  columns: {
    ownerId: import("drizzle-orm/pg-core").PgColumn<{
      name: "owner_id";
      tableName: "wallet_vesting";
      dataType: "string";
      columnType: "PgText";
      data: string;
      driverParam: string;
      notNull: true;
      hasDefault: false;
      isPrimaryKey: true;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: [string, ...string[]];
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    pendingMinor: import("drizzle-orm/pg-core").PgColumn<{
      name: "pending_minor";
      tableName: "wallet_vesting";
      dataType: "bigint";
      columnType: "PgBigInt64";
      data: bigint;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    maturedMinor: import("drizzle-orm/pg-core").PgColumn<{
      name: "matured_minor";
      tableName: "wallet_vesting";
      dataType: "bigint";
      columnType: "PgBigInt64";
      data: bigint;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    carriedDebtMinor: import("drizzle-orm/pg-core").PgColumn<{
      name: "carried_debt_minor";
      tableName: "wallet_vesting";
      dataType: "bigint";
      columnType: "PgBigInt64";
      data: bigint;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    withdrawableMinor: import("drizzle-orm/pg-core").PgColumn<{
      name: "withdrawable_minor";
      tableName: "wallet_vesting";
      dataType: "bigint";
      columnType: "PgBigInt64";
      data: bigint;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    lifetimeEarnedMinor: import("drizzle-orm/pg-core").PgColumn<{
      name: "lifetime_earned_minor";
      tableName: "wallet_vesting";
      dataType: "bigint";
      columnType: "PgBigInt64";
      data: bigint;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
    updatedAt: import("drizzle-orm/pg-core").PgColumn<{
      name: "updated_at";
      tableName: "wallet_vesting";
      dataType: "date";
      columnType: "PgTimestamp";
      data: Date;
      driverParam: string;
      notNull: true;
      hasDefault: true;
      isPrimaryKey: false;
      isAutoincrement: false;
      hasRuntimeDefault: false;
      enumValues: undefined;
      baseColumn: never;
      identity: undefined;
      generated: undefined;
    }, {}, {}>;
  };
  dialect: "pg";
}>;
declare const vestingSchema: {
  ledgerEntryVesting: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "ledger_entry_vesting";
    schema: undefined;
    columns: {
      entryId: import("drizzle-orm/pg-core").PgColumn<{
        name: "entry_id";
        tableName: "ledger_entry_vesting";
        dataType: "string";
        columnType: "PgUUID";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: true;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      matureAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "mature_at";
        tableName: "ledger_entry_vesting";
        dataType: "date";
        columnType: "PgTimestamp";
        data: Date;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      sweptAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "swept_at";
        tableName: "ledger_entry_vesting";
        dataType: "date";
        columnType: "PgTimestamp";
        data: Date;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      withdrawableAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "withdrawable_at";
        tableName: "ledger_entry_vesting";
        dataType: "date";
        columnType: "PgTimestamp";
        data: Date;
        driverParam: string;
        notNull: false;
        hasDefault: false;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
    };
    dialect: "pg";
  }>;
  walletVesting: import("drizzle-orm/pg-core").PgTableWithColumns<{
    name: "wallet_vesting";
    schema: undefined;
    columns: {
      ownerId: import("drizzle-orm/pg-core").PgColumn<{
        name: "owner_id";
        tableName: "wallet_vesting";
        dataType: "string";
        columnType: "PgText";
        data: string;
        driverParam: string;
        notNull: true;
        hasDefault: false;
        isPrimaryKey: true;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: [string, ...string[]];
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      pendingMinor: import("drizzle-orm/pg-core").PgColumn<{
        name: "pending_minor";
        tableName: "wallet_vesting";
        dataType: "bigint";
        columnType: "PgBigInt64";
        data: bigint;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      maturedMinor: import("drizzle-orm/pg-core").PgColumn<{
        name: "matured_minor";
        tableName: "wallet_vesting";
        dataType: "bigint";
        columnType: "PgBigInt64";
        data: bigint;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      carriedDebtMinor: import("drizzle-orm/pg-core").PgColumn<{
        name: "carried_debt_minor";
        tableName: "wallet_vesting";
        dataType: "bigint";
        columnType: "PgBigInt64";
        data: bigint;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      withdrawableMinor: import("drizzle-orm/pg-core").PgColumn<{
        name: "withdrawable_minor";
        tableName: "wallet_vesting";
        dataType: "bigint";
        columnType: "PgBigInt64";
        data: bigint;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      lifetimeEarnedMinor: import("drizzle-orm/pg-core").PgColumn<{
        name: "lifetime_earned_minor";
        tableName: "wallet_vesting";
        dataType: "bigint";
        columnType: "PgBigInt64";
        data: bigint;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
      updatedAt: import("drizzle-orm/pg-core").PgColumn<{
        name: "updated_at";
        tableName: "wallet_vesting";
        dataType: "date";
        columnType: "PgTimestamp";
        data: Date;
        driverParam: string;
        notNull: true;
        hasDefault: true;
        isPrimaryKey: false;
        isAutoincrement: false;
        hasRuntimeDefault: false;
        enumValues: undefined;
        baseColumn: never;
        identity: undefined;
        generated: undefined;
      }, {}, {}>;
    };
    dialect: "pg";
  }>;
};
type VestingSchema = typeof vestingSchema;
type LedgerEntryVesting = typeof ledgerEntryVesting.$inferSelect;
type WalletVesting = typeof walletVesting.$inferSelect;
//#endregion
//#region src/vesting.d.ts
declare function accrueVesting<S extends VestingSchema>(tx: PostgresTransaction<S>, input: {
  ownerId: string;
  entryId: string;
  amountMinor: bigint;
  matureAt: Date;
}): Promise<{
  state: 'pending' | 'matured';
}>;
declare function promoteEntries<S extends VestingSchema>(tx: PostgresTransaction<S>, input: {
  earnEntryIds: {
    entryId: string;
    ownerId: string;
  }[];
  perOwnerDeltas: {
    ownerId: string;
    deltaMinor: bigint;
  }[];
}): Promise<void>;
declare function settleClawback<S extends VestingSchema>(tx: PostgresTransaction<S>, input: {
  ownerId: string;
  amountMinor: bigint;
}): Promise<void>;
/**
 * Recomputes `withdrawableMinor` as max(0, eligible − paid) under the wallet_vesting owner lock.
 *
 * LOCK-THEN-COMPUTE (P5): upsert-then-lock the owner row FIRST, then call `compute()` so the
 * caller reads eligible/paid under the held lock, then write the clamped withdrawable.
 *
 * DEADLOCK-AVOIDANCE: `compute()` MUST read matured `ledger_entry_vesting` rows PLAIN — never
 * FOR UPDATE. Locking entry rows while holding the owner lock reverses lock order vs
 * `promoteEntries`' sweep (entry→owner) and deadlocks. The owner lock alone serializes
 * recompute against the T12 withdrawal debit (which locks the SAME wallet_vesting row first).
 */
declare function recomputeWithdrawable<S extends VestingSchema>(tx: PostgresTransaction<S>, target: {
  ownerId: string;
}, compute: () => Promise<{
  eligibleMinor: bigint;
  paidMinor: bigint;
}>): Promise<void>;
declare function setEntryWithdrawableAt<S extends VestingSchema>(tx: PostgresTransaction<S>, input: {
  entryId: string;
  withdrawableAt: Date | null;
}): Promise<void>;
declare function getVesting<S extends VestingSchema>(tx: Querier<S>, ownerId: string): Promise<{
  pendingMinor: bigint;
  maturedMinor: bigint;
  carriedDebtMinor: bigint;
  netMinor: bigint;
  withdrawableMinor: bigint;
  lifetimeEarnedMinor: bigint;
}>;
//#endregion
export { LedgerEntryVesting, VestingInvariantError, VestingSchema, WalletVesting, accrueVesting, getVesting, isVestingInvariantError, ledgerEntryVesting, promoteEntries, recomputeWithdrawable, setEntryWithdrawableAt, settleClawback, vestingSchema, walletVesting };