All files / approval-engine-2/dtos ledger-event.dto.ts

100% Statements 4/4
100% Branches 0/0
100% Functions 2/2
100% Lines 4/4

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121                                                                                                                                                                                                                          1x     2x     1x     1x    
import { Book } from "../../tr8-script/domain/ast.js";
import {
  LedgerEvent,
  LedgerEventDlq,
} from "../../tr8-script/domain/ledger-event.js";
 
import type {
  AbsoluteFixedValueDto,
  AmountDto,
  FractionDto,
  RelativeValueDto,
} from "../../commons/dtos/values.dto.js";
 
export type LedgerEventDto = Omit<LedgerEvent, "txs" | "partial_notif_id"> & {
  txs: (LedgerEventAbsRefTxDto | LedgerEventRelRefTxDto)[];
  partial_notif_id?: string | null;
};
 
export type LedgerEventDtoDlq = Omit<
  LedgerEventDlq,
  "txs" | "partial_notif_id"
> & {
  txs: (LedgerEventAbsRefTxDto | LedgerEventRelRefTxDto)[];
  partial_notif_id?: string | null;
};
 
export interface LedgerEventAbsRefTxDto {
  LedgerEventAbsRefTx: {
    id: string;
    asset: string;
    refValue: AbsoluteFixedValueDto;
    sources: LedgerEventAbsRefTxSourceDto[];
    destinations: LedgerEventAbsRefTxDestinationDto[];
  };
}
 
export interface LedgerEventAbsRefTxSourceDto {
  book: Book;
  account: string;
  constraints: SourceConstraintDto[];
  extern: boolean;
  allocationPolicy: {
    amount: AmountDto;
    policy: "max" | "split" | "remaining";
  };
  as?: string;
  mark?: string;
}
 
export interface LedgerEventAbsRefTxDestinationDto {
  book: Book;
  account: string;
  allocationPolicy: {
    amount: AmountDto;
    policy: "split" | "remaining";
  };
  as?: string;
  mark?: string;
}
 
export interface LedgerEventRelRefTxDto {
  LedgerEventRelRefTx: {
    id: string;
    asset: string;
    refValue: RelativeValueDto;
    use?: string;
    sources: LedgerEventRelRefTxSourceDto[];
    destinations: LedgerEventRelRefTxDestinationDto[];
  };
}
 
export interface LedgerEventRelRefTxSourceDto {
  book: Book;
  account: string;
  constraints: SourceConstraintDto[];
  extern: boolean;
  allocationPolicy: {
    amount: FractionDto;
    policy: "max" | "split" | "remaining";
  };
  as?: string;
  mark?: string;
}
 
export interface LedgerEventRelRefTxDestinationDto {
  book: Book;
  account: string;
  allocationPolicy: {
    amount: FractionDto;
    policy: "split" | "remaining";
  };
  as?: string;
  mark?: string;
}
 
export interface SourceConstraintDto {
  amount:
    | {
        AbsoluteFixedValue: AbsoluteFixedValueDto;
      }
    | {
        RelativeValue: RelativeValueDto;
      }
    | {
        UnboundedValue: "unbounded";
      };
  constraint: "overdraft" | "limit" | "keep";
}
 
export const isAbsoluteTxDto = (
  tx: LedgerEventAbsRefTxDto | LedgerEventRelRefTxDto,
): tx is LedgerEventAbsRefTxDto => {
  return "LedgerEventAbsRefTx" in tx;
};
 
export const isRelativeTxDto = (
  tx: LedgerEventAbsRefTxDto | LedgerEventRelRefTxDto,
): tx is LedgerEventRelRefTxDto => {
  return "LedgerEventRelRefTx" in tx;
};