@cfxlabsinc/b2b-services
    Preparing search index...

    Variable bankAccountViewConst

    bankAccountView: PgViewWithSelection<
        "bank_account_view",
        false,
        {
            accountNumber: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            bankId: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            bankName: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            createdAt: PgBuildColumn<
                "bank_account_view",
                SetNotNull<PgTimestampBuilder>,
                {
                    data: Date;
                    dataType: "object date";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: true;
                    tableName: "bank_account_view";
                },
            >;
            credits: PgBuildColumn<
                "bank_account_view",
                PgNumericBuilder,
                {
                    data: string;
                    dataType: "string numeric";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            creditsExInternal: PgBuildColumn<
                "bank_account_view",
                PgNumericBuilder,
                {
                    data: string;
                    dataType: "string numeric";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            currency: PgBuildColumn<
                "bank_account_view",
                SetNotNull<PgTextBuilder<[string, ...string[]]>>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: true;
                    tableName: "bank_account_view";
                },
            >;
            customerId: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            customerName: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            debits: PgBuildColumn<
                "bank_account_view",
                PgNumericBuilder,
                {
                    data: string;
                    dataType: "string numeric";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            debitsExInternal: PgBuildColumn<
                "bank_account_view",
                PgNumericBuilder,
                {
                    data: string;
                    dataType: "string numeric";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            deletedAt: PgBuildColumn<
                "bank_account_view",
                PgTimestampBuilder,
                {
                    data: Date;
                    dataType: "object date";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            entityId: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            entityName: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            entityType: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            firstPostedAt: PgBuildColumn<
                "bank_account_view",
                PgTimestampBuilder,
                {
                    data: Date;
                    dataType: "object date";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            id: PgBuildColumn<
                "bank_account_view",
                SetNotNull<PgTextBuilder<[string, ...string[]]>>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: true;
                    tableName: "bank_account_view";
                },
            >;
            impliedBalance: PgBuildColumn<
                "bank_account_view",
                PgNumericBuilder,
                {
                    data: string;
                    dataType: "string numeric";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            impliedBalanceExInternal: PgBuildColumn<
                "bank_account_view",
                PgNumericBuilder,
                {
                    data: string;
                    dataType: "string numeric";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            key: PgBuildColumn<
                "bank_account_view",
                SetNotNull<PgTextBuilder<[string, ...string[]]>>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: true;
                    tableName: "bank_account_view";
                },
            >;
            keyable: PgBuildColumn<
                "bank_account_view",
                SetNotNull<PgBooleanBuilder>,
                {
                    data: boolean;
                    dataType: "boolean";
                    driverParam: boolean;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: true;
                    tableName: "bank_account_view";
                },
            >;
            lastPostedAt: PgBuildColumn<
                "bank_account_view",
                PgTimestampBuilder,
                {
                    data: Date;
                    dataType: "object date";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            ledgerAccountId: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            memo: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            name: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            parentKey: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            provider: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            providerAccountId: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            routingNumber: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            source: PgBuildColumn<
                "bank_account_view",
                SetNotNull<PgTextBuilder<[string, ...string[]]>>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: true;
                    tableName: "bank_account_view";
                },
            >;
            sourceRecordId: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            status: PgBuildColumn<
                "bank_account_view",
                SetNotNull<PgTextBuilder<[string, ...string[]]>>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: true;
                    tableName: "bank_account_view";
                },
            >;
            transactionCount: PgBuildColumn<
                "bank_account_view",
                PgIntegerBuilder,
                {
                    data: number;
                    dataType: "number int32";
                    driverParam: string
                    | number;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            type: PgBuildColumn<
                "bank_account_view",
                PgTextBuilder<[string, ...string[]]>,
                {
                    data: string;
                    dataType: "string";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: false;
                    tableName: "bank_account_view";
                },
            >;
            updatedAt: PgBuildColumn<
                "bank_account_view",
                SetNotNull<PgTimestampBuilder>,
                {
                    data: Date;
                    dataType: "object date";
                    driverParam: string;
                    enumValues: undefined;
                    generated: undefined;
                    hasDefault: false;
                    hasRuntimeDefault: false;
                    identity: undefined;
                    isAutoincrement: false;
                    isPrimaryKey: false;
                    name: string;
                    notNull: true;
                    tableName: "bank_account_view";
                },
            >;
        },
    > = ...

    One reference view over every CFX bank account: all five *_bank_account_view arms, UNION ALL-ed, unfiltered.

    CFX bank accounts exist in several unrelated representations — two tables with typed columns (victor_account, virtual_account), one JSONB column family (bank's four rail columns), and one implicit set that exists only as strings on bank_transaction rows. Each has a different key shape and a different notion of ownership, so answering "what accounts do we have, who owns them, and what is in them" meant querying several tables, unpacking one JSONB family by hand, and getting the ownership semantics right in each. Nothing anywhere computed a balance.

    MANUAL is the one table this view introduces (manualBankAccountTable) and the primary enumeration: the others cover CFX's own side of the perimeter, because that is all bank_transaction ever recorded, so the counterparty accounts CFX actually trades with appear in none of them. Registering an account there demotes the two inferred arms — BANK_INSTRUCTION and OBSERVED — to backstop for it, via the anti-join ladder in § 4.7.

    There is no DEPOSIT_MEMO arm. A deposit memo is a customer's slice of a shared FBO, and unlike every arm here its balance cannot be measured — only allocated. Money arrives naming the memo, but nothing records which memo a withdrawal drained: a withdrawal transfers to a CFX-owned ledger account and is redeemed from there, so the memo link is gone by the time fiat leaves. Nor is the shortfall small — on prod the memo arm showed $333.5M of credits against $0 of debits, and the one account audited had moved $65.0M out on-chain of which the transfer tables recorded $21.8M. Every arm below reports a figure derived from bank_transaction alone and is checkable against it; a memo row would have been the only one that is not, so it was removed rather than left looking equally authoritative. The deposit_bank_memo table and its services are untouched — the memo is simply not an account. See docs/proposals/BANK_ACCOUNT_VIEW.md § 4.6.

    There is still no producer-written bank_account cache: the five original sources stay authoritative, and manual_bank_account is authoritative only for rows no other source has. Dropping provider-sourced balances is what keeps the rest of it a pure view — reconciling Victor's / RouteFusion's / metcap's authoritative figure against the implied one is the obvious follow-on (§ 4.1, § 4.2).

    Arm pruning is the reason source is a literal in all six arms. A view takes no parameters, so every query plans every arm — unless the planner can constant-fold the predicate. source IN (…) folds to false in the arms that cannot match and they leave the plan entirely; the same filter written against any CASE-derived column would plan all six. That is what lets the whole union live here instead of being reassembled per request.

    Declaration order is the UNION order. It carries no meaning beyond that — every arm projects the same thirty-five columns and callers sort — but the COLUMN order within each arm is load-bearing, because UNION ALL matches by position and most of the contract is text. See bankAccountViewColumns and test/bankAccountViewContract.integration.test.ts.

    securityInvoker is required, not cosmetic. Every arm is itself a securityInvoker view over RLS-enabled tables; without it here the union would run with the owner's row visibility and silently bypass the querying role's policies.

    See docs/proposals/BANK_ACCOUNT_VIEW.md.