# Neobank (FBO)

Source: https://docs.formance.com/examples/advanced/neobank-fbo

Stack: v3.2

This example shows how to model a neobank built on a single FBO ("For Benefit Of") bank account in Formance using a declarative ledger schema. The neobank holds all customer money commingled in one omnibus account at a sponsor bank, while the ledger tracks each customer's slice as a separate liability balance. Every customer movement — deposits, card spend, peer-to-peer transfers, withdrawals, and early-access advances — flows through the same pooled cash position, and a daily FBO reconciliation proves the ledger's view of pooled cash against the sponsor's reported statement.

**Common use cases:**

- **Neobanks and BaaS programs** operating customer accounts on top of a sponsor-bank FBO
- **Earned-wage / early-access products** that front advances against an expected deposit
- **Card programs** managing authorization holds, captures, and refunds against pooled cash

This is an illustrative example. Adapt the schema to your specific business requirements, regulatory obligations, and financial practices.

## Key Concepts

- **FBO Pooling** — All customer funds sit commingled in one bank account (`platform:banks:sponsor:fbo:settled`). The ledger is the system of record for who owns what inside that pool; the bank only ever sees the aggregate.
- **Per-Customer Liability Balances** — Each customer has an `available` balance plus subtrees for authorization `holds`, in-flight `withdrawals`, and `advances`. These are **liabilities** — the credit balance is what the platform owes that customer.
- **Daily FBO Reconciliation** — The single asset-side account (`platform:banks:sponsor:fbo:settled`) is reconciled every day against the sponsor's reported FBO statement. It runs negative; its absolute value is the ledger's view of settled cash in the pool, and total positive claims against it form an internal solvency check.
- **In-Flight Isolation** — Authorization holds, pending ACH withdrawals, and outstanding advances each get their own per-reference account, so funds that are earmarked, settling, or fronted are never confused with spendable balance.
- **Platform Float Separation** — The platform's own money (the FBO `buffer` and the corporate operating account) lives outside the `customers` root, giving structural proof that platform funds are distinct from customer funds.

## The Complete Schema

This is the full ledger schema for a neobank FBO system. The sections below explain each part.

```yaml
# yaml-language-server: $schema=https://ds.formance.com/schemas/ledger-schema/extended
meta:
  slug: neobank-fbo
  order: 6
  name: "Neobank (FBO)"
  description: "Omnibus account, per-customer balances, daily FBO recon."
  tags:
    - "neobank"
    - "fbo"
    - "reconciliation"
  docsUrl: "https://docs.formance.com/examples/advanced/neobank-fbo"
chart:
  customers:
    $customer_id:
      .pattern: ^[a-zA-Z0-9_-]+$
      available: {}
      holds:
        $auth_id:
          .pattern: ^[a-zA-Z0-9_-]+$
      withdrawals:
        $withdrawal_id:
          .pattern: ^[a-zA-Z0-9_-]+$
          pending: {}
      advances:
        $advance_id:
          .pattern: ^[a-zA-Z0-9_-]+$
          outstanding: {}
      .self: {}
  platform:
    banks:
      sponsor:
        fbo:
          settled: {}
          buffer: {}
      corporate:
        settled: {}
        operating: {}
    revenue:
      interest: {}
    expense:
      advanceLoss: {}
transactions:
  ACH_DIRECT_DEPOSIT:
    description: >-
      Inbound ACH direct deposit settled into the FBO and credited to the
      customer
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        monetary $amount
        string $deposit_id
        string $originator
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "ach_direct_deposit")
      set_tx_meta("deposit_id", $deposit_id)
      set_tx_meta("originator", $originator)
  INCOMING_WIRE:
    description: Inbound wire settled into the FBO and credited to the customer
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        monetary $amount
        string $wire_id
        string $originator
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "incoming_wire")
      set_tx_meta("wire_id", $wire_id)
      set_tx_meta("originator", $originator)
  ACH_DEPOSIT_RETURN:
    description: Reversal of a settled ACH deposit returned by the originating bank
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        monetary $amount
        string $deposit_id
      }

      send $amount (
        source = @customers:$customer_id:available allowing unbounded overdraft
        destination = @platform:banks:sponsor:fbo:settled
      )

      set_tx_meta("event_type", "ach_deposit_return")
      set_tx_meta("deposit_id", $deposit_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $deposit_id)
  CARD_AUTH:
    description: Debit-card authorization places a hold on the customer's available balance
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $auth_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:available
        destination = @customers:$customer_id:holds:$auth_id
      )

      set_tx_meta("event_type", "card_auth")
      set_tx_meta("auth_id", $auth_id)
  CARD_AUTH_REVERSE:
    description: >-
      Merchant-initiated reversal of a card authorization; hold returns to
      available
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $auth_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:holds:$auth_id
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "card_auth_reverse")
      set_tx_meta("auth_id", $auth_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $auth_id)
  CARD_AUTH_EXPIRE:
    description: Authorization hold expires unused; remaining hold returns to available
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $auth_id
        monetary $hold_balance = balance(@customers:$customer_id:holds:$auth_id, USD/2)
      }

      send $hold_balance (
        source = @customers:$customer_id:holds:$auth_id
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "card_auth_expire")
      set_tx_meta("auth_id", $auth_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $auth_id)
  CARD_CAPTURE:
    description: >-
      Capture against an authorization; captured amount leaves the FBO,
      remainder restored
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $auth_id
        monetary $capture_amount
        monetary $hold_balance = balance(@customers:$customer_id:holds:$auth_id, USD/2)
      }

      send $hold_balance (
        source = @customers:$customer_id:holds:$auth_id
        destination = {
          max $capture_amount to @platform:banks:sponsor:fbo:settled
          remaining to @customers:$customer_id:available
        }
      )

      set_tx_meta("event_type", "card_capture")
      set_tx_meta("auth_id", $auth_id)
  CARD_REFUND:
    description: Merchant refund of a prior capture credited to the customer
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        monetary $amount
        string $refund_id
        string $original_capture_id
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "card_refund")
      set_tx_meta("refund_id", $refund_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $original_capture_id)
  P2P_TRANSFER:
    description: Instant in-ledger transfer between two customers; never touches the bank
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $from_customer_id
        account $to_customer_id
        monetary $amount
        string $transfer_id
      }

      send $amount (
        source = @customers:$from_customer_id:available
        destination = @customers:$to_customer_id:available
      )

      set_tx_meta("event_type", "p2p_transfer")
      set_tx_meta("transfer_id", $transfer_id)
  ACH_WITHDRAWAL_RESERVE:
    description: >-
      Customer-requested outbound ACH withdrawal earmarked from available to
      pending
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $withdrawal_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:available
        destination = @customers:$customer_id:withdrawals:$withdrawal_id:pending
      )

      set_tx_meta("event_type", "ach_withdrawal_reserve")
      set_tx_meta("withdrawal_id", $withdrawal_id)
  ACH_WITHDRAWAL_SETTLE:
    description: Outbound ACH settles; pending funds leave the FBO
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $withdrawal_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:withdrawals:$withdrawal_id:pending
        destination = @platform:banks:sponsor:fbo:settled
      )

      set_tx_meta("event_type", "ach_withdrawal_settle")
      set_tx_meta("withdrawal_id", $withdrawal_id)
  ACH_WITHDRAWAL_RETURN:
    description: Outbound ACH failed or returned; pending funds restored to available
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $withdrawal_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:withdrawals:$withdrawal_id:pending
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "ach_withdrawal_return")
      set_tx_meta("withdrawal_id", $withdrawal_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $withdrawal_id)
  ADVANCE_ORIGINATION:
    description: >-
      Platform fronts an early-access advance; credited to available, booked as
      a receivable
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $advance_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:advances:$advance_id:outstanding allowing unbounded overdraft
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "advance_origination")
      set_tx_meta("advance_id", $advance_id)
  ADVANCE_SETTLEMENT:
    description: Expected deposit settles; repays the advance first, remainder to available
    script: |-
      #![feature("experimental-overdraft-function", "experimental-account-interpolation")]
      vars {
        account $customer_id
        string $advance_id
        monetary $deposit_amount
        monetary $advance_outstanding = overdraft(@customers:$customer_id:advances:$advance_id:outstanding, USD/2)
      }

      send $deposit_amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = {
          max $advance_outstanding to @customers:$customer_id:advances:$advance_id:outstanding
          remaining to @customers:$customer_id:available
        }
      )

      set_tx_meta("event_type", "advance_settlement")
      set_tx_meta("advance_id", $advance_id)
  ADVANCE_WRITEOFF:
    description: >-
      Unrecoverable advance written off to loss; platform funds the FBO from
      corporate
    script: |-
      #![feature("experimental-overdraft-function", "experimental-account-interpolation")]
      vars {
        account $customer_id
        string $advance_id
        monetary $advance_outstanding = overdraft(@customers:$customer_id:advances:$advance_id:outstanding, USD/2)
      }

      send $advance_outstanding (
        source = @platform:expense:advanceLoss allowing unbounded overdraft
        destination = @customers:$customer_id:advances:$advance_id:outstanding
      )

      send $advance_outstanding (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @platform:banks:corporate:settled
      )

      set_tx_meta("event_type", "advance_writeoff")
      set_tx_meta("advance_id", $advance_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $advance_id)
  FBO_INTEREST_SWEEP:
    description: Monthly sponsor interest on the FBO recognized as platform revenue
    script: |-
      vars {
        monetary $amount
        string $period_id
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @platform:revenue:interest
      )

      set_tx_meta("event_type", "fbo_interest_sweep")
      set_tx_meta("period_id", $period_id)
  OPERATING_MOVEMENT_TO_CORPORATE:
    description: Weekly sweep of platform float from the FBO buffer to the corporate bank
    script: |-
      vars {
        monetary $amount
        string $movement_id
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:buffer
        destination = @platform:banks:sponsor:fbo:settled
      )

      send $amount (
        source = @platform:banks:corporate:settled allowing unbounded overdraft
        destination = @platform:banks:corporate:operating
      )

      set_tx_meta("event_type", "operating_movement_to_corporate")
      set_tx_meta("movement_id", $movement_id)
  OPERATING_MOVEMENT_TO_FBO:
    description: >-
      Weekly top-up of platform float from the corporate bank into the FBO
      buffer
    script: |-
      vars {
        monetary $amount
        string $movement_id
      }

      send $amount (
        source = @platform:banks:corporate:operating
        destination = @platform:banks:corporate:settled
      )

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @platform:banks:sponsor:fbo:buffer
      )

      set_tx_meta("event_type", "operating_movement_to_fbo")
      set_tx_meta("movement_id", $movement_id)
queries:
  daily_fbo_reconciliation_invariant_1:
    name: Daily FBO reconciliation (invariant 1)
    description: >-
      The single asset-side account the platform reconciles against the
      sponsor's reported FBO statement every day. The FBO settled account runs
      negative; its absolute value is the ledger's view of settled cash in the
      pooled account.
    resource: accounts
    body:
      $match:
        address: platform:banks:sponsor:fbo:settled
  total_claims_against_the_fbo_internal_solvency_check:
    name: Total claims against the FBO (internal solvency check)
    description: >-
      The sum of every positive claim against the FBO settled cash: all customer
      available, held, and pending-withdrawal balances, the platform's FBO
      float, and FBO interest revenue. Compared internally against the FBO
      backing plus outstanding advances (design.md invariant 1).
    resource: accounts
    body:
      $or:
        - $match:
            address: customers::available
        - $match:
            address: 'customers::holds::'
        - $match:
            address: customers::withdrawals::pending
        - $match:
            address: platform:banks:sponsor:fbo:buffer
        - $match:
            address: platform:revenue:interest
  customer_available_balance:
    name: Customer available balance
    description: >-
      One customer's spendable balance right now. The canonical per-customer
      balance read.
    resource: accounts
    vars:
      customer_id:
        type: string
    body:
      $match:
        address: customers:${customer_id}:available
  customer_total_holds:
    name: Customer total holds
    description: >-
      All current authorization holds for one customer, one row per hold. The
      sum is that customer's on-hold amount; available plus held is the
      customer's gross balance.
    resource: accounts
    vars:
      customer_id:
        type: string
    body:
      $match:
        address: 'customers:${customer_id}:holds:'
  customer_full_position:
    name: Customer full position
    description: >-
      Every account in one customer's subtree (available, each hold, each
      pending withdrawal, each advance) in a single read. Each row is one
      (account, asset, balance) triple.
    resource: accounts
    vars:
      customer_id:
        type: string
    body:
      $match:
        address: 'customers:${customer_id}:'
  total_customer_spendable_and_held_liability:
    name: Total customer spendable and held liability
    description: >-
      Total amount the platform owes customers as spendable plus on-hold funds,
      across every customer. This is the headline platform liability per asset.
    resource: accounts
    body:
      $or:
        - $match:
            address: customers::available
        - $match:
            address: 'customers::holds::'
  total_platform_float:
    name: Total platform float
    description: >-
      The platform's own money, provably separate from customer funds: the float
      held inside the FBO plus the operating float at the corporate bank.
      Neither address sits under the customers root, which is the structural
      proof of separation.
    resource: accounts
    body:
      $or:
        - $match:
            address: platform:banks:sponsor:fbo:buffer
        - $match:
            address: platform:banks:corporate:operating
  outstanding_advances:
    name: Outstanding advances
    description: >-
      Every advance account that still carries a balance. Advance accounts run
      negative while outstanding and drain to zero when the deposit settles, so
      a non-zero balance is an open advance.
    resource: accounts
    body:
      $and:
        - $match:
            address: customers::advances::outstanding
        - $not:
            $match:
              balance[USD/2]: 0
  aging_advances:
    name: Aging advances
    description: >-
      Advances that still carry a balance after the expected-deposit window.
      Combined with an insertion_date upper bound on the API path, this surfaces
      short or unrecovered advances that need clawback or write-off.
    resource: accounts
    body:
      $and:
        - $match:
            address: customers::advances::outstanding
        - $not:
            $match:
              balance[USD/2]: 0
  total_advance_exposure:
    name: Total advance exposure
    description: >-
      The platform's total early-access advance exposure right now: the summed
      magnitude of every outstanding advance receivable.
    resource: accounts
    body:
      $match:
        address: customers::advances::outstanding
  pending_withdrawals_in_flight:
    name: Pending withdrawals in flight
    description: >-
      Every per-withdrawal pending account that still carries a balance:
      outbound ACH funds earmarked but not yet settled or returned. Drains to
      zero on settle or return, so a non-zero balance is in-flight.
    resource: accounts
    body:
      $and:
        - $match:
            address: customers::withdrawals::pending
        - $not:
            $match:
              balance[USD/2]: 0
  card_capture_volume:
    name: Card capture volume
    description: >-
      Capture cash leaving the FBO over a window. Read volume on the settled
      account over the window (use startTime/endTime URL parameters).
    resource: volumes
    body:
      $match:
        address: platform:banks:sponsor:fbo:settled
  p2p_transfer_volume:
    name: P2P transfer volume
    description: >-
      Total peer-to-peer volume moving through customer available balances over
      a window. Read volume on the customer available subtree (use
      startTime/endTime URL parameters).
    resource: volumes
    body:
      $match:
        address: customers::available
  monthly_interest_revenue:
    name: Monthly interest revenue
    description: >-
      FBO interest recognized to platform revenue over the month. Read the
      volume into the interest revenue account over the window (use
      startTime/endTime URL parameters).
    resource: volumes
    body:
      $match:
        address: platform:revenue:interest
  advance_loss_to_date:
    name: Advance loss to date
    description: >-
      Realized loss on unrecovered advances. The advance-loss expense account
      runs negative; its magnitude is the cumulative loss. Read the current
      balance for the running total, or volume for a period figure.
    resource: accounts
    body:
      $match:
        address: platform:expense:advanceLoss
  customer_transaction_audit:
    name: Customer transaction audit
    description: >-
      Every transaction that touched any account in one customer's subtree, in
      either direction. For drill-down and dispute investigation, not for
      balance questions.
    resource: transactions
    vars:
      customer_id:
        type: string
    body:
      $match:
        account: 'customers:${customer_id}:'
  authorization_lifecycle_audit:
    name: Authorization lifecycle audit
    description: >-
      Every transaction for one card authorization (auth, capture, reverse, or
      expire), identified by the per-hold account.
    resource: transactions
    vars:
      customer_id:
        type: string
      auth_id:
        type: string
    body:
      $match:
        account: 'customers:${customer_id}:holds:${auth_id}'
```

[Open in Studio](https://studio.formance.com/ledger-schemas/editor?template=neobank-fbo\&utm_source=docs\&utm_campaign=ledger-schema-cookbook\&utm_template=neobank-fbo)

Edit this template in the Formance Studio editor.

## Chart of Accounts

The `chart` section defines two top-level groups: `customers` (the per-customer liability subtree) and `platform` (banks, revenue, and expense accounts the platform controls).

### Customers

```yaml
chart:
  customers:
    $customer_id:
      .pattern: ^[a-zA-Z0-9_-]+$
      available: {}
      holds:
        $auth_id:
          .pattern: ^[a-zA-Z0-9_-]+$
      withdrawals:
        $withdrawal_id:
          .pattern: ^[a-zA-Z0-9_-]+$
          pending: {}
      advances:
        $advance_id:
          .pattern: ^[a-zA-Z0-9_-]+$
          outstanding: {}
      .self: {}
```

**Normal credit accounts** — these represent your liabilities to customers. Each `$customer_id` has an `available` balance (spendable funds), a `holds` subtree (one account per card authorization, by `$auth_id`), a `withdrawals` subtree (one `pending` account per outbound ACH, by `$withdrawal_id`), and an `advances` subtree (one `outstanding` receivable per advance, by `$advance_id`). The advance `outstanding` accounts run negative while open — they are receivables the platform fronts — and drain to zero when the expected deposit settles.

### Platform

```yaml
chart:
  platform:
    banks:
      sponsor:
        fbo:
          settled: {}
          buffer: {}
      corporate:
        settled: {}
        operating: {}
    revenue:
      interest: {}
    expense:
      advanceLoss: {}
```

**Mixed nature accounts** controlled by the platform. The sponsor FBO `settled` account is the asset/nostro position: it represents the pooled cash held at the sponsor bank and runs negative as the ledger books credits to customers ahead of bank settlement. The FBO `buffer` and corporate `operating`/`settled` accounts hold platform float. `revenue:interest` captures FBO interest recognized as platform revenue, and `expense:advanceLoss` absorbs unrecoverable advances.

## Deposit Flow

Inbound funds settle into the FBO and are credited to the customer's available balance. The `allowing unbounded overdraft` clause on the FBO settled account lets it go negative — this is intentional, reflecting that the ledger books the customer credit before bank reconciliation.

ACH Direct Deposit

`ACH_DIRECT_DEPOSIT` settles an inbound ACH direct deposit into the FBO and credits the customer's available balance.

```yaml
transactions:
  ACH_DIRECT_DEPOSIT:
    description: Inbound ACH direct deposit settled into the FBO and credited to the customer
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        monetary $amount
        string $deposit_id
        string $originator
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "ach_direct_deposit")
      set_tx_meta("deposit_id", $deposit_id)
      set_tx_meta("originator", $originator)
```

Incoming Wire

`INCOMING_WIRE` does the same for an inbound wire — funds settle into the FBO and credit the customer.

```yaml
transactions:
  INCOMING_WIRE:
    description: Inbound wire settled into the FBO and credited to the customer
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        monetary $amount
        string $wire_id
        string $originator
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "incoming_wire")
      set_tx_meta("wire_id", $wire_id)
      set_tx_meta("originator", $originator)
```

Deposit Return

`ACH_DEPOSIT_RETURN` reverses a settled ACH deposit returned by the originating bank, debiting the customer's available balance back to the FBO.

```yaml
transactions:
  ACH_DEPOSIT_RETURN:
    description: Reversal of a settled ACH deposit returned by the originating bank
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        monetary $amount
        string $deposit_id
      }

      send $amount (
        source = @customers:$customer_id:available allowing unbounded overdraft
        destination = @platform:banks:sponsor:fbo:settled
      )

      set_tx_meta("event_type", "ach_deposit_return")
      set_tx_meta("deposit_id", $deposit_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $deposit_id)
```

## Card Flow

Card spend follows the authorization-then-capture lifecycle. An authorization places a hold on available balance; the hold is later captured, reversed, or expired.

Authorization

`CARD_AUTH` places a hold on the customer's available balance, moving funds into a per-authorization `holds:$auth_id` account.

```yaml
transactions:
  CARD_AUTH:
    description: Debit-card authorization places a hold on the customer's available balance
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $auth_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:available
        destination = @customers:$customer_id:holds:$auth_id
      )

      set_tx_meta("event_type", "card_auth")
      set_tx_meta("auth_id", $auth_id)
```

Capture

`CARD_CAPTURE` settles against an authorization: the captured amount leaves the FBO and the remainder of the hold is restored to available.

```yaml
transactions:
  CARD_CAPTURE:
    description: Capture against an authorization; captured amount leaves the FBO, remainder restored
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $auth_id
        monetary $capture_amount
        monetary $hold_balance = balance(@customers:$customer_id:holds:$auth_id, USD/2)
      }

      send $hold_balance (
        source = @customers:$customer_id:holds:$auth_id
        destination = {
          max $capture_amount to @platform:banks:sponsor:fbo:settled
          remaining to @customers:$customer_id:available
        }
      )

      set_tx_meta("event_type", "card_capture")
      set_tx_meta("auth_id", $auth_id)
```

Reversal

`CARD_AUTH_REVERSE` is a merchant-initiated reversal of an authorization — the hold returns to available.

```yaml
transactions:
  CARD_AUTH_REVERSE:
    description: Merchant-initiated reversal of a card authorization; hold returns to available
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $auth_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:holds:$auth_id
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "card_auth_reverse")
      set_tx_meta("auth_id", $auth_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $auth_id)
```

Expiry

`CARD_AUTH_EXPIRE` releases an unused authorization: the remaining hold balance returns to available.

```yaml
transactions:
  CARD_AUTH_EXPIRE:
    description: Authorization hold expires unused; remaining hold returns to available
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $auth_id
        monetary $hold_balance = balance(@customers:$customer_id:holds:$auth_id, USD/2)
      }

      send $hold_balance (
        source = @customers:$customer_id:holds:$auth_id
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "card_auth_expire")
      set_tx_meta("auth_id", $auth_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $auth_id)
```

A merchant refund of a prior capture is credited back through `CARD_REFUND`, restoring funds from the FBO to the customer.

```yaml
transactions:
  CARD_REFUND:
    description: Merchant refund of a prior capture credited to the customer
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        monetary $amount
        string $refund_id
        string $original_capture_id
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "card_refund")
      set_tx_meta("refund_id", $refund_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $original_capture_id)
```

## Peer-to-Peer Transfer

`P2P_TRANSFER` moves funds instantly between two customers' available balances. Because both customers share the same FBO pool, the transfer is purely in-ledger and never touches the bank.

```yaml
transactions:
  P2P_TRANSFER:
    description: Instant in-ledger transfer between two customers; never touches the bank
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $from_customer_id
        account $to_customer_id
        monetary $amount
        string $transfer_id
      }

      send $amount (
        source = @customers:$from_customer_id:available
        destination = @customers:$to_customer_id:available
      )

      set_tx_meta("event_type", "p2p_transfer")
      set_tx_meta("transfer_id", $transfer_id)
```

## Withdrawal Flow

Outbound ACH withdrawals are a two-step process so that funds being withdrawn can't be spent while in flight.

Reserve

`ACH_WITHDRAWAL_RESERVE` earmarks funds from the customer's available balance into a per-withdrawal `withdrawals:$withdrawal_id:pending` account.

```yaml
transactions:
  ACH_WITHDRAWAL_RESERVE:
    description: Customer-requested outbound ACH withdrawal earmarked from available to pending
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $withdrawal_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:available
        destination = @customers:$customer_id:withdrawals:$withdrawal_id:pending
      )

      set_tx_meta("event_type", "ach_withdrawal_reserve")
      set_tx_meta("withdrawal_id", $withdrawal_id)
```

Settle

`ACH_WITHDRAWAL_SETTLE` completes the cycle once the outbound ACH settles — pending funds leave the FBO.

```yaml
transactions:
  ACH_WITHDRAWAL_SETTLE:
    description: Outbound ACH settles; pending funds leave the FBO
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $withdrawal_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:withdrawals:$withdrawal_id:pending
        destination = @platform:banks:sponsor:fbo:settled
      )

      set_tx_meta("event_type", "ach_withdrawal_settle")
      set_tx_meta("withdrawal_id", $withdrawal_id)
```

If the outbound ACH fails or is returned, `ACH_WITHDRAWAL_RETURN` restores the pending funds to the customer's available balance.

```yaml
transactions:
  ACH_WITHDRAWAL_RETURN:
    description: Outbound ACH failed or returned; pending funds restored to available
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $withdrawal_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:withdrawals:$withdrawal_id:pending
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "ach_withdrawal_return")
      set_tx_meta("withdrawal_id", $withdrawal_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $withdrawal_id)
```

## Advance Flow

Early-access advances let the platform front money against an expected deposit, booked as a receivable on a per-advance `advances:$advance_id:outstanding` account.

Origination

`ADVANCE_ORIGINATION` fronts the advance: the outstanding receivable goes negative and the customer's available balance is credited.

```yaml
transactions:
  ADVANCE_ORIGINATION:
    description: Platform fronts an early-access advance; credited to available, booked as a receivable
    script: |-
      #![feature("experimental-account-interpolation")]
      vars {
        account $customer_id
        string $advance_id
        monetary $amount
      }

      send $amount (
        source = @customers:$customer_id:advances:$advance_id:outstanding allowing unbounded overdraft
        destination = @customers:$customer_id:available
      )

      set_tx_meta("event_type", "advance_origination")
      set_tx_meta("advance_id", $advance_id)
```

Settlement

`ADVANCE_SETTLEMENT` applies the expected deposit when it settles, repaying the advance first and crediting any remainder to available.

```yaml
transactions:
  ADVANCE_SETTLEMENT:
    description: Expected deposit settles; repays the advance first, remainder to available
    script: |-
      #![feature("experimental-overdraft-function", "experimental-account-interpolation")]
      vars {
        account $customer_id
        string $advance_id
        monetary $deposit_amount
        monetary $advance_outstanding = overdraft(@customers:$customer_id:advances:$advance_id:outstanding, USD/2)
      }

      send $deposit_amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = {
          max $advance_outstanding to @customers:$customer_id:advances:$advance_id:outstanding
          remaining to @customers:$customer_id:available
        }
      )

      set_tx_meta("event_type", "advance_settlement")
      set_tx_meta("advance_id", $advance_id)
```

Write-Off

`ADVANCE_WRITEOFF` recognizes an unrecoverable advance as a loss against `platform:expense:advanceLoss` and funds the FBO from the corporate bank.

```yaml
transactions:
  ADVANCE_WRITEOFF:
    description: Unrecoverable advance written off to loss; platform funds the FBO from corporate
    script: |-
      #![feature("experimental-overdraft-function", "experimental-account-interpolation")]
      vars {
        account $customer_id
        string $advance_id
        monetary $advance_outstanding = overdraft(@customers:$customer_id:advances:$advance_id:outstanding, USD/2)
      }

      send $advance_outstanding (
        source = @platform:expense:advanceLoss allowing unbounded overdraft
        destination = @customers:$customer_id:advances:$advance_id:outstanding
      )

      send $advance_outstanding (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @platform:banks:corporate:settled
      )

      set_tx_meta("event_type", "advance_writeoff")
      set_tx_meta("advance_id", $advance_id)
      set_tx_meta("adjustment_flag", "true")
      set_tx_meta("adjusted_posting_event_id", $advance_id)
```

## Platform Operations

Two recurring platform movements run on a machine interpreter. `FBO_INTEREST_SWEEP` recognizes monthly sponsor interest on the FBO as platform revenue.

```yaml
transactions:
  FBO_INTEREST_SWEEP:
    description: Monthly sponsor interest on the FBO recognized as platform revenue
    script: |-
      vars {
        monetary $amount
        string $period_id
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @platform:revenue:interest
      )

      set_tx_meta("event_type", "fbo_interest_sweep")
      set_tx_meta("period_id", $period_id)
```

`OPERATING_MOVEMENT_TO_CORPORATE` and `OPERATING_MOVEMENT_TO_FBO` sweep platform float between the FBO buffer and the corporate bank, keeping operating cash topped up in either direction.

```yaml
transactions:
  OPERATING_MOVEMENT_TO_CORPORATE:
    description: Weekly sweep of platform float from the FBO buffer to the corporate bank
    script: |-
      vars {
        monetary $amount
        string $movement_id
      }

      send $amount (
        source = @platform:banks:sponsor:fbo:buffer
        destination = @platform:banks:sponsor:fbo:settled
      )

      send $amount (
        source = @platform:banks:corporate:settled allowing unbounded overdraft
        destination = @platform:banks:corporate:operating
      )

      set_tx_meta("event_type", "operating_movement_to_corporate")
      set_tx_meta("movement_id", $movement_id)
```

```yaml
transactions:
  OPERATING_MOVEMENT_TO_FBO:
    description: Weekly top-up of platform float from the corporate bank into the FBO buffer
    script: |-
      vars {
        monetary $amount
        string $movement_id
      }

      send $amount (
        source = @platform:banks:corporate:operating
        destination = @platform:banks:corporate:settled
      )

      send $amount (
        source = @platform:banks:sponsor:fbo:settled allowing unbounded overdraft
        destination = @platform:banks:sponsor:fbo:buffer
      )

      set_tx_meta("event_type", "operating_movement_to_fbo")
      set_tx_meta("movement_id", $movement_id)
```

## The Daily FBO Reconciliation

The FBO settled account is the heart of the model. Because the ledger books customer credits before the bank confirms settlement, `platform:banks:sponsor:fbo:settled` runs negative — its absolute value is the ledger's view of settled cash in the pool. Reconciliation compares two figures every day:

- The **asset side** — the magnitude of the FBO settled account, matched against the sponsor's reported FBO statement balance.
- The **claims side** — the sum of every positive claim against that cash: all customer available, held, and pending-withdrawal balances, plus the platform's FBO float and accrued interest.

The claims against the FBO, plus outstanding advances, should equal the FBO backing. A mismatch signals an unreconciled movement or a missing posting — making the FBO settled account a key health indicator to monitor daily.

## Queries

The `queries` section defines reusable lookups for reconciliation, per-customer reads, and operational monitoring:

**Reconciliation and solvency**

- `daily_fbo_reconciliation_invariant_1` — the FBO settled account to reconcile against the sponsor statement
- `total_claims_against_the_fbo_internal_solvency_check` — every positive claim against FBO cash, for the internal solvency check

**Per-customer reads**

- `customer_available_balance` — one customer's spendable balance right now
- `customer_total_holds` — all current authorization holds for one customer
- `customer_full_position` — every account in one customer's subtree in a single read

**Platform liability and float**

- `total_customer_spendable_and_held_liability` — the headline platform liability across all customers
- `total_platform_float` — the platform's own money, provably separate from customer funds

**Advances**

- `outstanding_advances` — every advance still carrying a balance
- `aging_advances` — advances still open after the expected-deposit window
- `total_advance_exposure` — the platform's total early-access advance exposure

**In-flight and volumes**

- `pending_withdrawals_in_flight` — outbound ACH earmarked but not yet settled or returned
- `card_capture_volume` — capture cash leaving the FBO over a window
- `p2p_transfer_volume` — peer-to-peer volume through customer available balances over a window
- `monthly_interest_revenue` — FBO interest recognized to revenue over the month
- `advance_loss_to_date` — realized loss on unrecovered advances

**Audit**

- `customer_transaction_audit` — every transaction touching a customer's subtree, for drill-down
- `authorization_lifecycle_audit` — every transaction for one card authorization

These leverage the hierarchical account structure — filtering on `customers::available` matches every customer's spendable balance, and `customers::advances::outstanding` matches every advance receivable.
